ai-cli-online 2.9.1 → 2.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/package.json +1 -1
- package/shared/package.json +1 -1
- package/web/dist/assets/{index-BdGwxTX2.js → index-C0ECf3pB.js} +6 -6
- package/web/dist/assets/index-CLEFVTX4.css +32 -0
- package/web/dist/index.html +2 -2
- package/web/package.json +1 -1
- package/web/dist/assets/index-CuElHGZV.css +0 -32
package/package.json
CHANGED
package/server/package.json
CHANGED
package/shared/package.json
CHANGED
|
@@ -22,10 +22,10 @@ var yn=Object.defineProperty;var vn=(n,e,t)=>e in n?yn(n,e,{enumerable:!0,config
|
|
|
22
22
|
*
|
|
23
23
|
* This source code is licensed under the MIT license found in the
|
|
24
24
|
* LICENSE file in the root directory of this source tree.
|
|
25
|
-
*/var ot=s,Un=Bn;function Wn(n,e){return n===e&&(n!==0||1/n===1/e)||n!==n&&e!==e}var Hn=typeof Object.is=="function"?Object.is:Wn,Kn=Un.useSyncExternalStore,qn=ot.useRef,Jn=ot.useEffect,Vn=ot.useMemo,Yn=ot.useDebugValue;Xt.useSyncExternalStoreWithSelector=function(n,e,t,o,a){var c=qn(null);if(c.current===null){var i={hasValue:!1,value:null};c.current=i}else i=c.current;c=Vn(function(){function l(v){if(!f){if(f=!0,m=v,v=o(v),a!==void 0&&i.hasValue){var C=i.value;if(a(C,v))return p=C}return p=v}if(C=p,Hn(m,v))return C;var _=o(v);return a!==void 0&&a(C,_)?(m=v,C):(m=v,p=_)}var f=!1,m,p,h=t===void 0?null:t;return[function(){return l(e())},h===null?void 0:function(){return l(h())}]},[e,t,o,a]);var d=Kn(n,c[0],c[1]);return Jn(function(){i.hasValue=!0,i.value=d},[d]),Yn(d),d};Gt.exports=Xt;var Gn=Gt.exports;const Xn=Sn(Gn),en={},{useDebugValue:Zn}=gt,{useSyncExternalStoreWithSelector:Qn}=Xn;let jt=!1;const er=n=>n;function tr(n,e=er,t){(en?"production":void 0)!=="production"&&t&&!jt&&(jt=!0);const o=Qn(n.subscribe,n.getState,n.getServerState||n.getInitialState,e,t);return Zn(o),o}const It=n=>{const e=typeof n=="function"?Dn(n):n,t=(o,a)=>tr(e,o,a);return Object.assign(t,e),t},nr=n=>n?It(n):It,re="";function ie(n){return{Authorization:`Bearer ${n}`}}async function rr(n){try{const e=await fetch(`${re}/api/settings/font-size`,{headers:ie(n)});return e.ok?(await e.json()).fontSize:14}catch{return 14}}async function or(n,e){try{await fetch(`${re}/api/settings/font-size`,{method:"PUT",headers:{...ie(n),"Content-Type":"application/json"},body:JSON.stringify({fontSize:e})})}catch{}}async function sr(n){try{const e=await fetch(`${re}/api/settings/tabs-layout`,{headers:ie(n)});return e.ok?(await e.json()).layout:null}catch{return null}}async function ar(n,e){try{await fetch(`${re}/api/settings/tabs-layout`,{method:"PUT",headers:{...ie(n),"Content-Type":"application/json"},body:JSON.stringify({layout:e})})}catch{}}function Rt(n,e){try{const t=`${re}/api/settings/tabs-layout`,o=JSON.stringify({layout:e,token:n});navigator.sendBeacon(t,new Blob([o],{type:"application/json"}))}catch{}}const Qe="ai-cli-online-tabs",Nt="ai-cli-online-layout",Dt="ai-cli-online-session-names";function et(n,e){if(n.type==="leaf")return n.terminalId===e?null:n;const t=[],o=[];for(let i=0;i<n.children.length;i++){const d=et(n.children[i],e);d!==null&&(t.push(d),o.push(n.sizes[i]))}if(t.length===0)return null;if(t.length===1)return t[0];const a=o.reduce((i,d)=>i+d,0),c=o.map(i=>i/a*100);return{...n,children:t,sizes:c}}function tn(n,e,t,o,a){return n.type==="leaf"?n.terminalId===e?{id:a,type:"split",direction:t,children:[n,o],sizes:[50,50]}:n:{...n,children:n.children.map(c=>tn(c,e,t,o,a))}}function nn(n,e,t){return n.type==="leaf"?n:n.id===e?{...n,sizes:t}:{...n,children:n.children.map(o=>nn(o,e,t))}}function ct(n){return n.tabs.find(e=>e.id===n.activeTabId)}function Me(n,e,t){return n.map(o=>o.id===e?t(o):o)}function pe(n){const e={version:2,activeTabId:n.activeTabId,nextId:n.nextId,nextSplitId:n.nextSplitId,nextTabId:n.nextTabId,tabs:n.tabs};try{localStorage.setItem(Qe,JSON.stringify(e))}catch{}ir(e)}let Ye=null,Ge=null,Pe=null,qe=null;function ir(n){qe=n,Pe&&clearTimeout(Pe),Pe=setTimeout(()=>{Pe=null,qe=null;const e=A.getState().token;e&&ar(e,n)},2e3)}function lr(n){Ye&&clearTimeout(Ye),Ye=setTimeout(()=>{Ye=null,pe(n)},500)}function cr(){try{const n=localStorage.getItem(Qe);if(n){const e=JSON.parse(n);if(e.version===2)return e}}catch{}try{const n=localStorage.getItem(Nt);if(n){const e=JSON.parse(n);let t="Default";try{const c=localStorage.getItem(Dt);if(c){const i=JSON.parse(c),d=Object.values(i)[0];d&&(t=d)}}catch{}const o={id:"tab1",name:t,status:"open",terminalIds:e.terminalIds,layout:e.layout,createdAt:Date.now()},a={version:2,activeTabId:"tab1",nextId:e.nextId,nextSplitId:e.nextSplitId,nextTabId:2,tabs:[o]};try{localStorage.setItem(Qe,JSON.stringify(a))}catch{}return localStorage.removeItem(Nt),localStorage.removeItem(Dt),a}}catch{}return null}function ue(n){return{tabs:n.tabs,activeTabId:n.activeTabId,nextId:n.nextId,nextSplitId:n.nextSplitId,nextTabId:n.nextTabId}}function dr(n,e){const t=new Set(e.map(i=>i.sessionId)),o=[];for(const i of n.tabs){if(i.status!=="open"){const f=i.terminalIds.filter(m=>t.has(m));if(f.length>0){let m=i.layout;for(const p of i.terminalIds)!t.has(p)&&m&&(m=et(m,p));o.push({...i,terminalIds:f,layout:m})}continue}const d=i.terminalIds.filter(f=>t.has(f));if(d.length===0)continue;let l=i.layout;for(const f of i.terminalIds)!t.has(f)&&l&&(l=et(l,f));o.push({...i,terminalIds:d,layout:l})}if(o.filter(i=>i.status==="open").length===0)return null;let a=n.activeTabId;if(!o.find(i=>i.id===a&&i.status==="open")){const i=o.find(d=>d.status==="open");a=(i==null?void 0:i.id)||""}return{...n,activeTabId:a,tabs:o}}typeof window<"u"&&window.addEventListener("beforeunload",()=>{var e,t;const n=(t=(e=A==null?void 0:A.getState)==null?void 0:e.call(A))==null?void 0:t.token;if(n)if(qe)Pe&&(clearTimeout(Pe),Pe=null),Rt(n,qe),qe=null;else{const o=A.getState();o.tabs.length>0&&Rt(n,ue(o))}});function Lt(n,e){const t=n.tabs.find(f=>f.terminalIds.includes(e));if(!t){const{[e]:f,...m}=n.terminalsMap;return{terminalsMap:m}}const o=t.terminalIds.filter(f=>f!==e),a=t.layout?et(t.layout,e):null,c=Me(n.tabs,t.id,f=>({...f,terminalIds:o,layout:a})),{[e]:i,...d}=n.terminalsMap,l={terminalsMap:d,tabs:c};return t.id===n.activeTabId&&(l.terminalIds=o,l.layout=a),l}const A=nr((n,e)=>({token:null,tabsLoading:!1,setToken:t=>{var o;if(t){try{localStorage.setItem("ai-cli-online-token",t)}catch{}rr(t).then(c=>{e().token===t&&n({fontSize:c})});const a=cr();if(a&&a.tabs.length>0){const c={};for(const l of a.tabs)if(l.status==="open")for(const f of l.terminalIds)c[f]={id:f,connected:!1,sessionResumed:!1,error:null,panels:((o=l.panelStates)==null?void 0:o[f])||{chatOpen:!1,planOpen:!1}};const i=a.tabs.find(l=>l.id===a.activeTabId&&l.status==="open")||a.tabs.find(l=>l.status==="open"),d=(i==null?void 0:i.id)||"";n({token:t,tabsLoading:!0,terminalsMap:c,tabs:a.tabs,activeTabId:d,nextId:a.nextId,nextSplitId:a.nextSplitId,nextTabId:a.nextTabId,terminalIds:(i==null?void 0:i.terminalIds)||[],layout:(i==null?void 0:i.layout)||null})}else n({token:t,tabsLoading:!0,terminalsMap:{},tabs:[],activeTabId:"",nextId:1,nextSplitId:1,nextTabId:1,terminalIds:[],layout:null});ur(t,a);return}localStorage.removeItem("ai-cli-online-token"),localStorage.removeItem(Qe),n({token:t,tabsLoading:!1,terminalsMap:{},tabs:[],activeTabId:"",nextId:1,nextSplitId:1,nextTabId:1,terminalIds:[],layout:null})},terminalsMap:{},terminalIds:[],layout:null,nextId:1,nextSplitId:1,tabs:[],activeTabId:"",nextTabId:1,addTab:t=>{const o=e(),a=`tab${o.nextTabId}`,c=`t${o.nextId}`,i={id:c,connected:!1,sessionResumed:!1,error:null,panels:{chatOpen:!1,planOpen:!1}},d={type:"leaf",terminalId:c},l={id:a,name:t||`Tab ${o.nextTabId}`,status:"open",terminalIds:[c],layout:d,createdAt:Date.now()};return n({tabs:[...o.tabs,l],activeTabId:a,nextTabId:o.nextTabId+1,nextId:o.nextId+1,terminalsMap:{...o.terminalsMap,[c]:i},terminalIds:l.terminalIds,layout:l.layout}),pe(ue(e())),a},switchTab:t=>{const a=e().tabs.find(c=>c.id===t);!a||a.status!=="open"||(n({activeTabId:t,terminalIds:a.terminalIds,layout:a.layout}),pe(ue(e())))},closeTab:t=>{const o=e(),a=o.tabs.find(p=>p.id===t);if(!a||a.status!=="open"||o.tabs.filter(p=>p.status==="open").length<=1)return;const i={...o.terminalsMap};for(const p of a.terminalIds)delete i[p];const d=Me(o.tabs,t,p=>({...p,status:"closed"}));let l=o.activeTabId,f=o.terminalIds,m=o.layout;if(o.activeTabId===t){const p=o.tabs.findIndex(C=>C.id===t),h=d.filter(C=>C.status==="open"),v=h.find(C=>d.findIndex(D=>D.id===C.id)>p)||h[h.length-1];v&&(l=v.id,f=v.terminalIds,m=v.layout)}n({tabs:d,activeTabId:l,terminalsMap:i,terminalIds:f,layout:m}),pe(ue(e()))},reopenTab:t=>{var d;const o=e(),a=o.tabs.find(l=>l.id===t);if(!a||a.status!=="closed")return;const c={...o.terminalsMap};for(const l of a.terminalIds)c[l]={id:l,connected:!1,sessionResumed:!1,error:null,panels:((d=a.panelStates)==null?void 0:d[l])||{chatOpen:!1,planOpen:!1}};const i=Me(o.tabs,t,l=>({...l,status:"open"}));n({tabs:i,activeTabId:t,terminalsMap:c,terminalIds:a.terminalIds,layout:a.layout}),pe(ue(e()))},deleteTab:async t=>{const o=e(),a=o.tabs.find(v=>v.id===t);if(!a)return;const c=o.token;c&&await Promise.all(a.terminalIds.map(v=>fetch(`${re}/api/sessions/${encodeURIComponent(v)}`,{method:"DELETE",headers:ie(c)}).catch(()=>{})));const i=e(),d=i.tabs.find(v=>v.id===t);if(!d)return;const l={...i.terminalsMap};for(const v of d.terminalIds)delete l[v];const f=i.tabs.filter(v=>v.id!==t);let m=i.activeTabId,p=i.terminalIds,h=i.layout;if(i.activeTabId===t){const v=f.find(C=>C.status==="open");v?(m=v.id,p=v.terminalIds,h=v.layout):(m="",p=[],h=null)}n({tabs:f,activeTabId:m,terminalsMap:l,terminalIds:p,layout:h}),pe(ue(e())),setTimeout(()=>e().fetchSessions(),500)},renameTab:(t,o)=>{const a=Me(e().tabs,t,c=>({...c,name:o}));n({tabs:a}),pe(ue(e()))},addTerminal:(t,o)=>{const a=e();if(o&&a.terminalsMap[o])return o;const c=ct(a);if(!c){const U=`tab${a.nextTabId}`,L=o||`t${a.nextId}`;let B=a.nextId;const W=L.match(/^t(\d+)$/);W&&(B=Math.max(B,parseInt(W[1],10)+1));const F=o?B:B+1,j={id:L,connected:!1,sessionResumed:!1,error:null,panels:{chatOpen:!1,planOpen:!1}},S={type:"leaf",terminalId:L},O={id:U,name:`Tab ${a.nextTabId}`,status:"open",terminalIds:[L],layout:S,createdAt:Date.now()};return n({tabs:[...a.tabs,O],activeTabId:U,nextTabId:a.nextTabId+1,nextId:F,terminalsMap:{...a.terminalsMap,[L]:j},terminalIds:[L],layout:S}),pe(ue(e())),L}const{nextId:i,nextSplitId:d,terminalsMap:l}=a,{terminalIds:f,layout:m}=c,p=o||`t${i}`;let h=i;const v=p.match(/^t(\d+)$/);v&&(h=Math.max(h,parseInt(v[1],10)+1));const C={id:p,connected:!1,sessionResumed:!1,error:null,panels:{chatOpen:!1,planOpen:!1}},_={type:"leaf",terminalId:p};let D,T=d;if(!m)D=_;else if(m.type==="leaf"){const U=t||"horizontal";D={id:`s${T}`,type:"split",direction:U,children:[m,_],sizes:[50,50]},T++}else if(m.direction===(t||"horizontal")){const L=100/(m.children.length+1),B=(100-L)/100,W=[...m.sizes.map(F=>F*B),L];D={...m,children:[...m.children,_],sizes:W}}else{const U=t||"horizontal";D={id:`s${T}`,type:"split",direction:U,children:[m,_],sizes:[50,50]},T++}const g=[...f,p],$=o?h:h+1,R=Me(a.tabs,c.id,U=>({...U,terminalIds:g,layout:D}));return n({terminalsMap:{...l,[p]:C},terminalIds:g,layout:D,tabs:R,nextId:$,nextSplitId:T}),pe(ue(e())),p},splitTerminal:(t,o,a)=>{const c=e(),i=ct(c);if(!i||!i.layout)return"";const{nextId:d,nextSplitId:l,terminalsMap:f}=c,m=`t${d}`,p={id:m,connected:!1,sessionResumed:!1,error:null,panels:{chatOpen:!1,planOpen:!1},...a?{startCwd:a}:{}},h={type:"leaf",terminalId:m},v=`s${l}`,C=tn(i.layout,t,o,h,v),_=[...i.terminalIds,m],D=d+1,T=l+1,g=Me(c.tabs,i.id,$=>({...$,terminalIds:_,layout:C}));return n({terminalsMap:{...f,[m]:p},terminalIds:_,layout:C,tabs:g,nextId:D,nextSplitId:T}),pe(ue(e())),m},removeTerminal:t=>{const o=Lt(e(),t);o&&(n(o),pe(ue(e())))},setTerminalConnected:(t,o)=>{n(a=>{const c=a.terminalsMap[t];return!c||c.connected===o?a:{terminalsMap:{...a.terminalsMap,[t]:{...c,connected:o}}}})},setTerminalResumed:(t,o)=>{n(a=>{const c=a.terminalsMap[t];return!c||c.sessionResumed===o?a:{terminalsMap:{...a.terminalsMap,[t]:{...c,sessionResumed:o}}}})},setTerminalError:(t,o)=>{n(a=>{const c=a.terminalsMap[t];return!c||c.error===o?a:{terminalsMap:{...a.terminalsMap,[t]:{...c,error:o}}}})},toggleChat:t=>{const o=e(),a=o.terminalsMap[t];if(!a)return;const c={...a.panels,chatOpen:!a.panels.chatOpen},i={...o.terminalsMap,[t]:{...a,panels:c}},d=o.tabs.find(f=>f.terminalIds.includes(t));let l=o.tabs;if(d){const f={...d.panelStates,[t]:c};l=Me(o.tabs,d.id,m=>({...m,panelStates:f}))}n({terminalsMap:i,tabs:l}),pe(ue(e()))},togglePlan:t=>{const o=e(),a=o.terminalsMap[t];if(!a)return;const c={...a.panels,planOpen:!a.panels.planOpen},i={...o.terminalsMap,[t]:{...a,panels:c}},d=o.tabs.find(f=>f.terminalIds.includes(t));let l=o.tabs;if(d){const f={...d.panelStates,[t]:c};l=Me(o.tabs,d.id,m=>({...m,panelStates:f}))}n({terminalsMap:i,tabs:l}),pe(ue(e()))},setSplitSizes:(t,o)=>{const a=e(),c=ct(a);if(!c||!c.layout)return;const i=nn(c.layout,t,o),d=Me(a.tabs,c.id,l=>({...l,layout:i}));n({layout:i,tabs:d}),lr(ue(e()))},fontSize:14,setFontSize:t=>{const o=Math.max(10,Math.min(24,t));n({fontSize:o}),Ge&&clearTimeout(Ge),Ge=setTimeout(()=>{Ge=null;const a=e().token;a&&or(a,o)},500)},latency:null,setLatency:t=>n({latency:t}),theme:(()=>{try{const t=localStorage.getItem("ai-cli-online-theme");if(t==="light"||t==="dark")return t}catch{}return"dark"})(),setTheme:t=>{n({theme:t});try{localStorage.setItem("ai-cli-online-theme",t)}catch{}document.documentElement.setAttribute("data-theme",t)},toggleTheme:()=>{const t=e().theme==="dark"?"light":"dark";e().setTheme(t)},sidebarOpen:!1,toggleSidebar:()=>n(t=>({sidebarOpen:!t.sidebarOpen})),serverSessions:[],fetchSessions:async()=>{const t=e().token;if(t)try{const o=await fetch(`${re}/api/sessions`,{headers:ie(t)});if(!o.ok)return;const a=await o.json();n({serverSessions:a})}catch{}},killServerSession:async t=>{const o=e().token;if(!o)return;try{await fetch(`${re}/api/sessions/${encodeURIComponent(t)}`,{method:"DELETE",headers:ie(o)})}catch{}const a=Lt(e(),t);a&&(n(a),pe(ue(e()))),setTimeout(()=>e().fetchSessions(),500)}}));typeof document<"u"&&document.documentElement.setAttribute("data-theme",A.getState().theme);async function ur(n,e){var a,c;const{setState:t,getState:o}=A;try{const[i,d]=await Promise.all([sr(n),fetch(`${re}/api/sessions`,{headers:ie(n)}).then(C=>C.ok?C.json():[]).catch(()=>[])]);if(o().token!==n)return;const l=i&&((a=i.tabs)==null?void 0:a.length)>0?i:e;if(!l||l.tabs.length===0){t({tabsLoading:!1});return}const f=dr(l,d);if(!f){t({tabsLoading:!1,terminalsMap:{},tabs:[],activeTabId:"",nextId:l.nextId,nextSplitId:l.nextSplitId,nextTabId:l.nextTabId,terminalIds:[],layout:null});return}const m=o().terminalsMap,p={};for(const C of f.tabs)if(C.status==="open")for(const _ of C.terminalIds)p[_]=m[_]||{id:_,connected:!1,sessionResumed:!1,error:null,panels:((c=C.panelStates)==null?void 0:c[_])||{chatOpen:!1,planOpen:!1}};const h=f.tabs.find(C=>C.id===f.activeTabId&&C.status==="open")||f.tabs.find(C=>C.status==="open"),v=(h==null?void 0:h.id)||"";t({tabsLoading:!1,terminalsMap:p,tabs:f.tabs,activeTabId:v,nextId:f.nextId,nextSplitId:f.nextSplitId,nextTabId:f.nextTabId,terminalIds:(h==null?void 0:h.terminalIds)||[],layout:(h==null?void 0:h.layout)||null}),pe(ue(o()))}catch{o().token===n&&t({tabsLoading:!1})}}function fr(){const[n,e]=s.useState(""),t=A(a=>a.setToken),o=a=>{a.preventDefault(),n.trim()&&t(n.trim())};return r.jsx("div",{style:{minHeight:"100vh",backgroundColor:"var(--bg-primary)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px",background:"radial-gradient(ellipse at 50% 0%, rgba(122, 162, 247, 0.08) 0%, var(--bg-primary) 70%)"},children:r.jsxs("div",{className:"login-card",style:{backgroundColor:"var(--bg-tertiary)",borderRadius:"12px",padding:"40px 36px",width:"100%",maxWidth:"400px",border:"1px solid var(--border)"},children:[r.jsxs("div",{style:{textAlign:"center",marginBottom:"36px"},children:[r.jsx("div",{style:{width:"56px",height:"56px",margin:"0 auto 16px",borderRadius:"14px",background:"linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-purple) 100%)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"24px",color:"var(--bg-primary)",fontWeight:"bold",boxShadow:"0 4px 16px rgba(122, 162, 247, 0.3)"},children:">_"}),r.jsx("h1",{style:{fontSize:"22px",fontWeight:"bold",color:"var(--text-bright)",marginBottom:"6px",letterSpacing:"0.5px"},children:"AI-Cli Online"}),r.jsx("p",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Terminal in your browser"})]}),r.jsxs("form",{onSubmit:o,children:[r.jsxs("div",{style:{marginBottom:"20px"},children:[r.jsx("label",{htmlFor:"token",style:{display:"block",fontSize:"12px",color:"var(--accent-blue)",marginBottom:"8px",fontWeight:500,textTransform:"uppercase",letterSpacing:"0.5px"},children:"Auth Token"}),r.jsx("input",{type:"password",id:"token",className:"login-input",value:n,onChange:a=>e(a.target.value),placeholder:"Enter your AUTH_TOKEN",autoFocus:!0,autoComplete:"current-password",style:{width:"100%",padding:"11px 14px",backgroundColor:"var(--bg-primary)",color:"var(--text-bright)",border:"1px solid var(--border)",borderRadius:"8px",fontSize:"14px",outline:"none"}})]}),r.jsx("button",{type:"submit",className:"login-submit",disabled:!n.trim(),style:{width:"100%",padding:"11px",background:n.trim()?"linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-cyan) 100%)":"var(--bg-hover)",color:n.trim()?"var(--bg-primary)":"var(--text-secondary)",border:"none",borderRadius:"8px",fontSize:"14px",fontWeight:600,cursor:n.trim()?"pointer":"not-allowed",letterSpacing:"0.3px"},children:"Connect"})]}),r.jsx("div",{style:{marginTop:"28px",textAlign:"center",color:"var(--scrollbar-thumb-hover)",fontSize:"11px"},children:r.jsxs("p",{children:["Token is configured in"," ",r.jsx("code",{style:{backgroundColor:"var(--bg-primary)",padding:"2px 6px",borderRadius:"4px",border:"1px solid var(--border)",fontSize:"11px"},children:"server/.env"})]})})]})})}const st=new Map;function pr(n,e,t){st.set(n,{onChunk:e,onControl:t})}function mr(n){st.delete(n)}function hr(n,e){var t;(t=st.get(n))==null||t.onChunk(e)}function br(n,e){var t;(t=st.get(n))==null||t.onControl(e)}const xr=1,Mt=2,gr=3,yr=4,vr=5,wr=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`,Xe=500,Sr=8e3,kr=1e4,At=4e3,Cr=5e3,Tr=10,Er=64*1024,jr=new TextDecoder,Ir=new TextEncoder;function zt(n,e){const t=Ir.encode(e),o=new Uint8Array(1+t.length);return o[0]=n,o.set(t,1),o.buffer}function Rr(n,e,t){const o=s.useRef(null),a=s.useRef(Xe),c=s.useRef(null),i=s.useRef(null),d=s.useRef(null),l=s.useRef(null),f=s.useRef(!1),m=s.useRef(t),p=s.useRef(!1),h=s.useRef(0),v=s.useRef(!0),C=s.useRef(!navigator.onLine),_=s.useRef(""),D=s.useRef(null),T=s.useRef("");m.current=t;const g=s.useCallback(()=>{i.current&&(clearInterval(i.current),i.current=null),d.current&&(clearTimeout(d.current),d.current=null),c.current&&(clearTimeout(c.current),c.current=null),l.current&&(clearTimeout(l.current),l.current=null),D.current&&(clearTimeout(D.current),D.current=null)},[]),$=s.useCallback(()=>{var V;const{token:F,setTerminalError:j}=A.getState();if(!F||f.current)return;if(o.current){const K=o.current.readyState;if(K===WebSocket.OPEN||K===WebSocket.CONNECTING)return}p.current=!1;const S=(V=A.getState().terminalsMap[e])==null?void 0:V.startCwd;let O=`${wr}?sessionId=${encodeURIComponent(e)}`;S&&(O+=`&cwd=${encodeURIComponent(S)}`);const k=new WebSocket(O);k.binaryType="arraybuffer",l.current=window.setTimeout(()=>{k.readyState===WebSocket.CONNECTING&&k.close()},Cr);const X=()=>{k.readyState===WebSocket.OPEN&&(h.current=performance.now(),k.send(JSON.stringify({type:"ping"})),d.current=window.setTimeout(()=>{h.current>0&&(h.current=0,k.close())},At))};k.onopen=()=>{l.current&&(clearTimeout(l.current),l.current=null),k.send(JSON.stringify({type:"auth",token:F})),j(e,null),a.current=Xe,v.current=!0},k.onclose=K=>{const{setTerminalConnected:z,setTerminalError:M,setToken:G}=A.getState();if(z(e,!1),g(),p.current)return;if(K.code===4001){f.current=!0,M(e,"Authentication failed"),G(null),localStorage.removeItem("ai-cli-online-token");return}if(K.code===4002)return;if(K.code===4005){M(e,"Connection limit reached");return}if(!navigator.onLine){C.current=!0;return}if(v.current){v.current=!1,c.current=window.setTimeout(()=>$(),50);return}const J=a.current;a.current=Math.min(J*2,Sr);const Y=Math.round(J*(.5+Math.random()));c.current=window.setTimeout(()=>{$()},Y)},k.onerror=()=>{},k.onmessage=K=>{var z;try{const M=n.current;if(K.data instanceof ArrayBuffer){const J=new Uint8Array(K.data);if(J.length<1)return;const Y=J[0],le=J.subarray(1);switch(Y){case xr:M==null||M.write(le);break;case gr:M==null||M.write(le);break;case yr:{(z=m.current)==null||z.call(m,jr.decode(le));break}case vr:{hr(e,le);break}}return}const G=JSON.parse(K.data);switch(G.type){case"connected":{const J=A.getState();J.setTerminalConnected(e,!0),J.setTerminalResumed(e,G.resumed);const Y=n.current;Y&&k.readyState===WebSocket.OPEN&&k.send(JSON.stringify({type:"resize",cols:Y.cols,rows:Y.rows})),T.current&&(k.send(zt(Mt,T.current)),T.current=""),X(),i.current=window.setInterval(X,kr);break}case"error":A.getState().setTerminalError(e,G.error);break;case"pong":{if(d.current&&(clearTimeout(d.current),d.current=null),h.current>0){const J=Math.round(performance.now()-h.current),Y=A.getState();(Y.terminalIds.length===0||Y.terminalIds[0]===e)&&Y.setLatency(J),h.current=0}break}case"file-stream-start":case"file-stream-end":case"file-stream-error":br(e,G);break}}catch{}},o.current=k},[e,n,g]),R=s.useCallback(F=>{const j=o.current;if(!j||j.readyState!==WebSocket.OPEN){T.current.length<Er&&(T.current+=F);return}_.current+=F,D.current||(D.current=window.setTimeout(()=>{const S=_.current;_.current="",D.current=null,S&&j.readyState===WebSocket.OPEN&&j.send(zt(Mt,S))},Tr))},[]),U=s.useCallback((F,j)=>{var S;((S=o.current)==null?void 0:S.readyState)===WebSocket.OPEN&&o.current.send(JSON.stringify({type:"resize",cols:F,rows:j}))},[]),L=s.useCallback(()=>{var F;((F=o.current)==null?void 0:F.readyState)===WebSocket.OPEN&&o.current.send(JSON.stringify({type:"capture-scrollback"}))},[]),B=s.useCallback(F=>{var j;((j=o.current)==null?void 0:j.readyState)===WebSocket.OPEN&&o.current.send(JSON.stringify({type:"stream-file",path:F}))},[]),W=s.useCallback(()=>{var F;((F=o.current)==null?void 0:F.readyState)===WebSocket.OPEN&&o.current.send(JSON.stringify({type:"cancel-stream"}))},[]);return s.useEffect(()=>{A.getState().token&&(f.current=!1,$());const j=()=>{C.current=!1,a.current=Xe,v.current=!0;const k=o.current;(!k||k.readyState===WebSocket.CLOSED||k.readyState===WebSocket.CLOSING)&&$()},S=()=>{C.current=!0},O=()=>{if(document.visibilityState!=="visible")return;const k=o.current;if(!k||k.readyState!==WebSocket.OPEN){!C.current&&!p.current&&(a.current=Xe,v.current=!0,$());return}h.current=performance.now(),k.send(JSON.stringify({type:"ping"})),d.current&&clearTimeout(d.current),d.current=window.setTimeout(()=>{h.current>0&&(h.current=0,k.close())},At)};return window.addEventListener("online",j),window.addEventListener("offline",S),document.addEventListener("visibilitychange",O),()=>{p.current=!0,g(),window.removeEventListener("online",j),window.removeEventListener("offline",S),document.removeEventListener("visibilitychange",O),o.current&&(o.current.close(),o.current=null)}},[$,g,e]),{sendInput:R,sendResize:U,requestScrollback:L,requestFileStream:B,cancelFileStream:W}}function Nr(n){const e=s.useRef(null),t=s.useRef(null),o=s.useRef(n);o.current=n;const a=s.useCallback(()=>{t.current&&(clearTimeout(t.current),t.current=null),e.current&&(e.current.remove(),e.current=null)},[]),c=s.useCallback((i,d)=>{a();const l=document.createElement("div");l.style.cssText=`position:fixed;left:${i}px;top:${d}px;z-index:1000;display:flex;align-items:center;gap:4px;padding:4px 6px;background:var(--bg-tertiary);border:1px solid var(--border);border-radius:4px;box-shadow:0 2px 8px rgba(0,0,0,0.4);font-family:inherit;`;const f=document.createElement("textarea");f.style.cssText="width:90px;height:22px;resize:none;border:1px solid var(--border);border-radius:3px;background:var(--bg-primary);color:var(--text-primary);font-size:11px;font-family:inherit;padding:2px 4px;outline:none;",f.placeholder="Ctrl+V",f.addEventListener("paste",m=>{var h;m.preventDefault();const p=(h=m.clipboardData)==null?void 0:h.getData("text/plain");p&&o.current(p),a()}),f.addEventListener("keydown",m=>{m.key==="Escape"&&a()}),l.appendChild(f),document.body.appendChild(l),e.current=l,requestAnimationFrame(()=>{const m=l.getBoundingClientRect();m.right>window.innerWidth&&(l.style.left=`${window.innerWidth-m.width-8}px`),m.bottom>window.innerHeight&&(l.style.top=`${window.innerHeight-m.height-8}px`),f.focus()}),t.current=setTimeout(a,8e3)},[a]);return s.useEffect(()=>{const i=()=>{e.current&&a()};return document.addEventListener("click",i),()=>{document.removeEventListener("click",i),a()}},[a]),{showPasteFloat:c,removePasteFloat:a}}const tt={background:"#000000",foreground:"#cccccc",cursor:"#aeafad",selectionBackground:"rgba(38, 79, 120, 0.5)",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#e5e5e5"},nt={background:"#faf8f4",foreground:"#3b3b3b",cursor:"#1e1e1e",selectionBackground:"rgba(173, 214, 255, 0.5)",black:"#000000",red:"#cd3131",green:"#00bc00",yellow:"#949800",blue:"#0451a5",magenta:"#bc05bc",cyan:"#0598bc",white:"#555555",brightBlack:"#666666",brightRed:"#cd3131",brightGreen:"#14ce14",brightYellow:"#b5ba00",brightBlue:"#0451a5",brightMagenta:"#bc05bc",brightCyan:"#0598bc",brightWhite:"#a5a5a5"},rn="'JetBrains Mono', 'LXGW WenKai Mono', Menlo, Monaco, 'Courier New', monospace",Dr=s.forwardRef(function({sessionId:e},t){const o=s.useRef(null),a=s.useRef(null),c=s.useRef(null),[i,d]=s.useState(!1),[l,f]=s.useState(""),m=A(L=>L.fontSize),p=A(L=>L.theme),h=s.useCallback(L=>{f(L),d(!0)},[]),{sendInput:v,sendResize:C,requestScrollback:_,requestFileStream:D,cancelFileStream:T}=Rr(a,e,h);s.useImperativeHandle(t,()=>({sendInput:v,requestFileStream:D,cancelFileStream:T}),[v,D,T]);const g=s.useRef(v),$=s.useRef(C);g.current=v,$.current=C;const{showPasteFloat:R,removePasteFloat:U}=Nr(L=>g.current(L));return s.useEffect(()=>{if(!o.current)return;let L=!1,B=null,W=null,F=null,j=null;if(L||!o.current)return;const S=new Wt({cursorBlink:!0,scrollback:1e4,fontSize:A.getState().fontSize,fontFamily:rn,theme:A.getState().theme==="dark"?tt:nt,allowProposedApi:!0}),O=new Ht;S.loadAddon(O),S.loadAddon(new kn((M,G)=>{window.open(G,"_blank","noopener,noreferrer")})),S.open(o.current);try{const M=new Kt;M.onContextLoss(()=>{M.dispose()}),S.loadAddon(M)}catch{}a.current=S,c.current=O,S.onSelectionChange(()=>{const M=S.getSelection();M&&navigator.clipboard.writeText(M).catch(()=>{})});const k=S.element,X=M=>{var G;if(M.preventDefault(),U(),!((G=navigator.clipboard)!=null&&G.readText)){R(M.clientX,M.clientY);return}navigator.clipboard.readText().then(J=>{J&&g.current(J)}).catch(()=>{R(M.clientX,M.clientY)})};k&&k.addEventListener("contextmenu",X);const V=()=>{try{const M=o.current;if(M&&M.clientWidth>0&&M.clientHeight>0)return O.fit(),$.current(S.cols,S.rows),!0}catch{}return!1};requestAnimationFrame(()=>V());let K=0;B=setInterval(()=>{K++,(V()||K>=10)&&(clearInterval(B),B=null)},100),document.fonts.ready.then(()=>{if(!L)try{O.fit(),$.current(S.cols,S.rows)}catch{}}),S.onData(M=>{g.current(M)});let z=!1;return j=new ResizeObserver(()=>{if(document.body.classList.contains("resizing-panes")||document.body.classList.contains("resizing-panes-v")){if(!z){z=!0;const G=()=>{document.removeEventListener("mouseup",G),z=!1,requestAnimationFrame(()=>{try{O.fit(),$.current(S.cols,S.rows)}catch{}})};document.addEventListener("mouseup",G)}return}W||(W=requestAnimationFrame(()=>{W=null;try{O.fit(),F&&clearTimeout(F),F=setTimeout(()=>{F=null,$.current(S.cols,S.rows)},50)}catch{}}))}),j.observe(o.current),()=>{L=!0,B&&clearInterval(B),W&&cancelAnimationFrame(W),F&&clearTimeout(F),j&&j.disconnect(),U(),k&&k.removeEventListener("contextmenu",X),a.current&&(a.current.dispose(),a.current=null),c.current=null}},[e]),s.useEffect(()=>{const L=a.current,B=c.current;if(!(!L||!B)&&L.options.fontSize!==m){L.options.fontSize=m;try{B.fit()}catch{}$.current(L.cols,L.rows)}},[m]),s.useEffect(()=>{a.current&&(a.current.options.theme=p==="dark"?tt:nt)},[p]),r.jsxs("div",{style:{width:"100%",height:"100%",position:"relative"},children:[r.jsx("div",{ref:o,style:{width:"100%",height:"100%",backgroundColor:"var(--bg-primary)",contain:"strict",willChange:"transform",isolation:"isolate"}}),r.jsx("button",{tabIndex:-1,onClick:L=>{L.currentTarget.blur(),i?(d(!1),f("")):_()},title:"Toggle scrollback history",style:{position:"absolute",top:4,right:4,zIndex:10,background:i?"var(--accent-blue)":"rgba(65, 72, 104, 0.7)",color:"var(--text-bright)",border:"none",borderRadius:4,padding:"2px 8px",fontSize:14,cursor:"pointer",opacity:.8,lineHeight:"20px"},onMouseEnter:L=>{L.currentTarget.style.opacity="1"},onMouseLeave:L=>{L.currentTarget.style.opacity="0.8"},children:i?"✕":r.jsx("span",{style:{fontSize:14},children:"👁"})}),i&&r.jsx(Lr,{data:l,onClose:()=>{d(!1),f("")}})]})});function Lr({data:n,onClose:e}){const t=s.useRef(null),o=s.useRef(e);o.current=e;const a=A(f=>f.fontSize),c=A(f=>f.theme),i=s.useRef(null),d=s.useRef(null);s.useEffect(()=>{if(!t.current)return;const f=new Wt({cursorBlink:!1,disableStdin:!0,scrollback:5e4,fontSize:a,fontFamily:rn,theme:c==="dark"?tt:nt});i.current=f;const m=new Ht;d.current=m,f.loadAddon(m),f.open(t.current);let p=null;try{p=new Kt,p.onContextLoss(()=>{p==null||p.dispose(),p=null}),f.loadAddon(p)}catch{p=null}f.onSelectionChange(()=>{const T=f.getSelection();T&&navigator.clipboard.writeText(T).catch(()=>{})}),f.attachCustomKeyEventHandler(T=>(T.key==="Escape"&&o.current(),!1)),f.write(n);let h=null;const v=()=>{const T=t.current;if(!T||T.clientWidth<=0||T.clientHeight<=0)return!1;try{return m.fit(),f.scrollToBottom(),!0}catch{return!1}};requestAnimationFrame(()=>{if(!v()){let T=0;h=setInterval(()=>{T++,(v()||T>=30)&&(clearInterval(h),h=null)},50)}});let C=null;const _=new ResizeObserver(()=>{C||(C=requestAnimationFrame(()=>{C=null,v()}))});_.observe(t.current);const D=T=>{T.key==="Escape"&&o.current()};return document.addEventListener("keydown",D),()=>{if(h&&clearInterval(h),C&&cancelAnimationFrame(C),document.removeEventListener("keydown",D),_.disconnect(),p){try{p.dispose()}catch{}p=null}f.dispose(),i.current=null,d.current=null}},[n]),s.useEffect(()=>{var f;if(i.current){i.current.options.fontSize=a;try{(f=d.current)==null||f.fit()}catch{}}},[a]),s.useEffect(()=>{i.current&&(i.current.options.theme=c==="dark"?tt:nt)},[c]);const l=28;return r.jsxs("div",{style:{position:"absolute",inset:0,zIndex:5,backgroundColor:"var(--bg-primary)"},children:[r.jsx("div",{style:{height:l,boxSizing:"border-box",padding:"0 12px",background:"var(--bg-tertiary)",color:"var(--accent-blue)",fontSize:12,borderBottom:"1px solid var(--scrollbar-thumb-hover)",display:"flex",alignItems:"center"},children:r.jsx("span",{children:"Scrollback History (mouse wheel to scroll, ESC to close)"})}),r.jsx("div",{ref:t,style:{position:"absolute",top:l,left:0,right:0,bottom:0,overflow:"hidden"}})]})}const Mr=50;function ht(){const n=s.useRef([]),e=s.useCallback(a=>{n.current.push(a),n.current.length>Mr&&n.current.shift()},[]),t=s.useCallback(()=>n.current.pop(),[]),o=s.useCallback(()=>{n.current=[]},[]);return s.useMemo(()=>({pushUndo:e,popUndo:t,clearUndo:o}),[e,t,o])}function bt(n,e,t){n.preventDefault();const o=n.currentTarget,a=o.selectionStart,c=o.selectionEnd,i=o.value;t==null||t(i);const d=i.slice(0,a)+" "+i.slice(c);e(d),requestAnimationFrame(()=>{o.selectionStart=o.selectionEnd=a+2})}function We(n,e=10){var t;return Math.min(e,Math.max(1,(((t=n.match(/\n/g))==null?void 0:t.length)??0)+1))}let Ke=null;const Ar=["https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs","https://unpkg.com/mermaid@11/dist/mermaid.esm.min.mjs"];function zr(n){return n.initialize({startOnLoad:!1,theme:"dark",themeVariables:{primaryColor:"#7aa2f7",primaryTextColor:"#c0caf5",primaryBorderColor:"#414868",lineColor:"#565f89",secondaryColor:"#bb9af7",tertiaryColor:"#24283b",background:"#1a1b26",mainBkg:"#24283b",nodeBorder:"#414868",clusterBkg:"#1e2030",titleColor:"#c0caf5",edgeLabelBackground:"#1e2030",gridColor:"#292e42",doneTaskBkgColor:"#9ece6a",doneTaskBorderColor:"#73a942",activeTaskBkgColor:"#7aa2f7",activeTaskBorderColor:"#5d87d6",critBkgColor:"#f7768e",critBorderColor:"#d35d72",taskBkgColor:"#414868",taskBorderColor:"#565f89",taskTextColor:"#c0caf5",taskTextDarkColor:"#1a1b26",sectionBkgColor:"#1e2030",sectionBkgColor2:"#24283b",altSectionBkgColor:"#1e2030",todayLineColor:"#e0af68"},gantt:{titleTopMargin:15,barHeight:24,barGap:6,topPadding:40,numberSectionStyles:4,useWidth:800}}),n}function $r(){return Ke||(Ke=(async()=>{for(const n of Ar)try{const e=await import(n);return zr(e.default)}catch{}throw Ke=null,new Error("All mermaid CDN sources failed")})(),Ke)}let _r=0;function Or(n,e){s.useEffect(()=>{const t=n.current;if(!t)return;const o=t.querySelectorAll("code.language-mermaid, code.language-gantt");if(o.length===0)return;let a=!1;return(async()=>{let c;try{c=await $r()}catch{if(a)return;for(const d of o){const l=d.parentElement;if(!l||l.tagName!=="PRE")continue;l.classList.add("mermaid-error");const f=document.createElement("div");f.className="mermaid-error__msg",f.textContent="Failed to load Mermaid library",l.appendChild(f)}return}if(!a)for(const i of o){if(a)break;const d=i.parentElement;if(!d||d.tagName!=="PRE")continue;const l=i.textContent||"";if(!l.trim())continue;const f=`mermaid-${++_r}`;try{const{svg:m}=await c.render(f,l);if(a)break;const p=document.createElement("div");p.className="mermaid-diagram",p.innerHTML=qt.sanitize(m,{USE_PROFILES:{svg:!0,svgFilters:!0},ADD_TAGS:["foreignObject"]}),d.replaceWith(p)}catch{if(a)break;d.classList.add("mermaid-error");const m=document.createElement("div");m.className="mermaid-error__msg",m.textContent="Mermaid syntax error",d.appendChild(m)}}})(),()=>{a=!0}},[e])}async function Fr(n,e,t){const o=await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/annotations?path=${encodeURIComponent(t)}`,{headers:ie(n)});if(!o.ok)throw new Error("Failed to fetch annotation");const a=await o.json();return a.content?{content:a.content,updatedAt:a.updatedAt}:null}async function Pr(n,e,t,o,a){if(!(await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/annotations`,{method:"PUT",headers:{...ie(n),"Content-Type":"application/json"},body:JSON.stringify({path:t,content:o,updatedAt:a})})).ok)throw new Error("Failed to save annotation")}function on(n,e){let t=n.replace(/<[^>]*>/g,"").trim().toLowerCase().replace(/\s+/g,"-").replace(/[&<>"'`]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"");t||(t="heading");const o=e.get(t)||0;return o>0&&(t=`${t}-${o}`),e.set(t,o+1),t}function sn(n){return n.replace(/\*\*(.+?)\*\*/g,"$1").replace(/__(.+?)__/g,"$1").replace(/\*(.+?)\*/g,"$1").replace(/_(.+?)_/g,"$1").replace(/~~(.+?)~~/g,"$1").replace(/`(.+?)`/g,"$1").replace(/\[(.+?)\]\(.*?\)/g,"$1").trim()}function Br(n){if(!n)return[];const e=[],t=new Map,o=n.split(`
|
|
26
|
-
`);let a=!1;for(const c of o){if(/^```/.test(c.trim())){a=!a;continue}if(a)continue;const i=c.match(/^(#{1,6})\s+(.+?)(?:\s+#+)?\s*$/);if(i){const d=i[1].length,l=sn(i[2]),f=on(l,t);e.push({id:f,text:l,level:d})}}return e}const Ur=160,Wr=22;function Hr({headings:n,scrollRef:e}){const[t,o]=s.useState(null),[a,c]=s.useState(()=>localStorage.getItem("md-toc-collapsed")==="true"),i=s.useRef(null),d=s.useRef(!1),l=s.useMemo(()=>Math.min(...n.map(p=>p.level)),[n]),f=s.useCallback(()=>{c(p=>{const h=!p;try{localStorage.setItem("md-toc-collapsed",String(h))}catch{}return h})},[]);s.useEffect(()=>{const p=e.current;if(!p||n.length===0)return;const h=()=>{d.current=!1;const C=p.scrollTop
|
|
25
|
+
*/var ot=s,Un=Bn;function Wn(n,e){return n===e&&(n!==0||1/n===1/e)||n!==n&&e!==e}var Hn=typeof Object.is=="function"?Object.is:Wn,Kn=Un.useSyncExternalStore,qn=ot.useRef,Jn=ot.useEffect,Vn=ot.useMemo,Yn=ot.useDebugValue;Xt.useSyncExternalStoreWithSelector=function(n,e,t,o,a){var c=qn(null);if(c.current===null){var i={hasValue:!1,value:null};c.current=i}else i=c.current;c=Vn(function(){function l(v){if(!f){if(f=!0,m=v,v=o(v),a!==void 0&&i.hasValue){var C=i.value;if(a(C,v))return p=C}return p=v}if(C=p,Hn(m,v))return C;var $=o(v);return a!==void 0&&a(C,$)?(m=v,C):(m=v,p=$)}var f=!1,m,p,h=t===void 0?null:t;return[function(){return l(e())},h===null?void 0:function(){return l(h())}]},[e,t,o,a]);var d=Kn(n,c[0],c[1]);return Jn(function(){i.hasValue=!0,i.value=d},[d]),Yn(d),d};Gt.exports=Xt;var Gn=Gt.exports;const Xn=Sn(Gn),en={},{useDebugValue:Zn}=gt,{useSyncExternalStoreWithSelector:Qn}=Xn;let jt=!1;const er=n=>n;function tr(n,e=er,t){(en?"production":void 0)!=="production"&&t&&!jt&&(jt=!0);const o=Qn(n.subscribe,n.getState,n.getServerState||n.getInitialState,e,t);return Zn(o),o}const It=n=>{const e=typeof n=="function"?Dn(n):n,t=(o,a)=>tr(e,o,a);return Object.assign(t,e),t},nr=n=>n?It(n):It,oe="";function le(n){return{Authorization:`Bearer ${n}`}}async function rr(n){try{const e=await fetch(`${oe}/api/settings/font-size`,{headers:le(n)});return e.ok?(await e.json()).fontSize:14}catch{return 14}}async function or(n,e){try{await fetch(`${oe}/api/settings/font-size`,{method:"PUT",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({fontSize:e})})}catch{}}async function sr(n){try{const e=await fetch(`${oe}/api/settings/tabs-layout`,{headers:le(n)});return e.ok?(await e.json()).layout:null}catch{return null}}async function ar(n,e){try{await fetch(`${oe}/api/settings/tabs-layout`,{method:"PUT",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({layout:e})})}catch{}}function Rt(n,e){try{const t=`${oe}/api/settings/tabs-layout`,o=JSON.stringify({layout:e,token:n});navigator.sendBeacon(t,new Blob([o],{type:"application/json"}))}catch{}}const Qe="ai-cli-online-tabs",Nt="ai-cli-online-layout",Dt="ai-cli-online-session-names";function et(n,e){if(n.type==="leaf")return n.terminalId===e?null:n;const t=[],o=[];for(let i=0;i<n.children.length;i++){const d=et(n.children[i],e);d!==null&&(t.push(d),o.push(n.sizes[i]))}if(t.length===0)return null;if(t.length===1)return t[0];const a=o.reduce((i,d)=>i+d,0),c=o.map(i=>i/a*100);return{...n,children:t,sizes:c}}function tn(n,e,t,o,a){return n.type==="leaf"?n.terminalId===e?{id:a,type:"split",direction:t,children:[n,o],sizes:[50,50]}:n:{...n,children:n.children.map(c=>tn(c,e,t,o,a))}}function nn(n,e,t){return n.type==="leaf"?n:n.id===e?{...n,sizes:t}:{...n,children:n.children.map(o=>nn(o,e,t))}}function ct(n){return n.tabs.find(e=>e.id===n.activeTabId)}function Me(n,e,t){return n.map(o=>o.id===e?t(o):o)}function pe(n){const e={version:2,activeTabId:n.activeTabId,nextId:n.nextId,nextSplitId:n.nextSplitId,nextTabId:n.nextTabId,tabs:n.tabs};try{localStorage.setItem(Qe,JSON.stringify(e))}catch{}ir(e)}let Ye=null,Ge=null,Pe=null,qe=null;function ir(n){qe=n,Pe&&clearTimeout(Pe),Pe=setTimeout(()=>{Pe=null,qe=null;const e=A.getState().token;e&&ar(e,n)},2e3)}function lr(n){Ye&&clearTimeout(Ye),Ye=setTimeout(()=>{Ye=null,pe(n)},500)}function cr(){try{const n=localStorage.getItem(Qe);if(n){const e=JSON.parse(n);if(e.version===2)return e}}catch{}try{const n=localStorage.getItem(Nt);if(n){const e=JSON.parse(n);let t="Default";try{const c=localStorage.getItem(Dt);if(c){const i=JSON.parse(c),d=Object.values(i)[0];d&&(t=d)}}catch{}const o={id:"tab1",name:t,status:"open",terminalIds:e.terminalIds,layout:e.layout,createdAt:Date.now()},a={version:2,activeTabId:"tab1",nextId:e.nextId,nextSplitId:e.nextSplitId,nextTabId:2,tabs:[o]};try{localStorage.setItem(Qe,JSON.stringify(a))}catch{}return localStorage.removeItem(Nt),localStorage.removeItem(Dt),a}}catch{}return null}function ue(n){return{tabs:n.tabs,activeTabId:n.activeTabId,nextId:n.nextId,nextSplitId:n.nextSplitId,nextTabId:n.nextTabId}}function dr(n,e){const t=new Set(e.map(i=>i.sessionId)),o=[];for(const i of n.tabs){if(i.status!=="open"){const f=i.terminalIds.filter(m=>t.has(m));if(f.length>0){let m=i.layout;for(const p of i.terminalIds)!t.has(p)&&m&&(m=et(m,p));o.push({...i,terminalIds:f,layout:m})}continue}const d=i.terminalIds.filter(f=>t.has(f));if(d.length===0)continue;let l=i.layout;for(const f of i.terminalIds)!t.has(f)&&l&&(l=et(l,f));o.push({...i,terminalIds:d,layout:l})}if(o.filter(i=>i.status==="open").length===0)return null;let a=n.activeTabId;if(!o.find(i=>i.id===a&&i.status==="open")){const i=o.find(d=>d.status==="open");a=(i==null?void 0:i.id)||""}return{...n,activeTabId:a,tabs:o}}typeof window<"u"&&window.addEventListener("beforeunload",()=>{var e,t;const n=(t=(e=A==null?void 0:A.getState)==null?void 0:e.call(A))==null?void 0:t.token;if(n)if(qe)Pe&&(clearTimeout(Pe),Pe=null),Rt(n,qe),qe=null;else{const o=A.getState();o.tabs.length>0&&Rt(n,ue(o))}});function Lt(n,e){const t=n.tabs.find(f=>f.terminalIds.includes(e));if(!t){const{[e]:f,...m}=n.terminalsMap;return{terminalsMap:m}}const o=t.terminalIds.filter(f=>f!==e),a=t.layout?et(t.layout,e):null,c=Me(n.tabs,t.id,f=>({...f,terminalIds:o,layout:a})),{[e]:i,...d}=n.terminalsMap,l={terminalsMap:d,tabs:c};return t.id===n.activeTabId&&(l.terminalIds=o,l.layout=a),l}const A=nr((n,e)=>({token:null,tabsLoading:!1,setToken:t=>{var o;if(t){try{localStorage.setItem("ai-cli-online-token",t)}catch{}rr(t).then(c=>{e().token===t&&n({fontSize:c})});const a=cr();if(a&&a.tabs.length>0){const c={};for(const l of a.tabs)if(l.status==="open")for(const f of l.terminalIds)c[f]={id:f,connected:!1,sessionResumed:!1,error:null,panels:((o=l.panelStates)==null?void 0:o[f])||{chatOpen:!1,planOpen:!1}};const i=a.tabs.find(l=>l.id===a.activeTabId&&l.status==="open")||a.tabs.find(l=>l.status==="open"),d=(i==null?void 0:i.id)||"";n({token:t,tabsLoading:!0,terminalsMap:c,tabs:a.tabs,activeTabId:d,nextId:a.nextId,nextSplitId:a.nextSplitId,nextTabId:a.nextTabId,terminalIds:(i==null?void 0:i.terminalIds)||[],layout:(i==null?void 0:i.layout)||null})}else n({token:t,tabsLoading:!0,terminalsMap:{},tabs:[],activeTabId:"",nextId:1,nextSplitId:1,nextTabId:1,terminalIds:[],layout:null});ur(t,a);return}localStorage.removeItem("ai-cli-online-token"),localStorage.removeItem(Qe),n({token:t,tabsLoading:!1,terminalsMap:{},tabs:[],activeTabId:"",nextId:1,nextSplitId:1,nextTabId:1,terminalIds:[],layout:null})},terminalsMap:{},terminalIds:[],layout:null,nextId:1,nextSplitId:1,tabs:[],activeTabId:"",nextTabId:1,addTab:t=>{const o=e(),a=`tab${o.nextTabId}`,c=`t${o.nextId}`,i={id:c,connected:!1,sessionResumed:!1,error:null,panels:{chatOpen:!1,planOpen:!1}},d={type:"leaf",terminalId:c},l={id:a,name:t||`Tab ${o.nextTabId}`,status:"open",terminalIds:[c],layout:d,createdAt:Date.now()};return n({tabs:[...o.tabs,l],activeTabId:a,nextTabId:o.nextTabId+1,nextId:o.nextId+1,terminalsMap:{...o.terminalsMap,[c]:i},terminalIds:l.terminalIds,layout:l.layout}),pe(ue(e())),a},switchTab:t=>{const a=e().tabs.find(c=>c.id===t);!a||a.status!=="open"||(n({activeTabId:t,terminalIds:a.terminalIds,layout:a.layout}),pe(ue(e())))},closeTab:t=>{const o=e(),a=o.tabs.find(p=>p.id===t);if(!a||a.status!=="open"||o.tabs.filter(p=>p.status==="open").length<=1)return;const i={...o.terminalsMap};for(const p of a.terminalIds)delete i[p];const d=Me(o.tabs,t,p=>({...p,status:"closed"}));let l=o.activeTabId,f=o.terminalIds,m=o.layout;if(o.activeTabId===t){const p=o.tabs.findIndex(C=>C.id===t),h=d.filter(C=>C.status==="open"),v=h.find(C=>d.findIndex(L=>L.id===C.id)>p)||h[h.length-1];v&&(l=v.id,f=v.terminalIds,m=v.layout)}n({tabs:d,activeTabId:l,terminalsMap:i,terminalIds:f,layout:m}),pe(ue(e()))},reopenTab:t=>{var d;const o=e(),a=o.tabs.find(l=>l.id===t);if(!a||a.status!=="closed")return;const c={...o.terminalsMap};for(const l of a.terminalIds)c[l]={id:l,connected:!1,sessionResumed:!1,error:null,panels:((d=a.panelStates)==null?void 0:d[l])||{chatOpen:!1,planOpen:!1}};const i=Me(o.tabs,t,l=>({...l,status:"open"}));n({tabs:i,activeTabId:t,terminalsMap:c,terminalIds:a.terminalIds,layout:a.layout}),pe(ue(e()))},deleteTab:async t=>{const o=e(),a=o.tabs.find(v=>v.id===t);if(!a)return;const c=o.token;c&&await Promise.all(a.terminalIds.map(v=>fetch(`${oe}/api/sessions/${encodeURIComponent(v)}`,{method:"DELETE",headers:le(c)}).catch(()=>{})));const i=e(),d=i.tabs.find(v=>v.id===t);if(!d)return;const l={...i.terminalsMap};for(const v of d.terminalIds)delete l[v];const f=i.tabs.filter(v=>v.id!==t);let m=i.activeTabId,p=i.terminalIds,h=i.layout;if(i.activeTabId===t){const v=f.find(C=>C.status==="open");v?(m=v.id,p=v.terminalIds,h=v.layout):(m="",p=[],h=null)}n({tabs:f,activeTabId:m,terminalsMap:l,terminalIds:p,layout:h}),pe(ue(e())),setTimeout(()=>e().fetchSessions(),500)},renameTab:(t,o)=>{const a=Me(e().tabs,t,c=>({...c,name:o}));n({tabs:a}),pe(ue(e()))},addTerminal:(t,o)=>{const a=e();if(o&&a.terminalsMap[o])return o;const c=ct(a);if(!c){const W=`tab${a.nextTabId}`,D=o||`t${a.nextId}`;let U=a.nextId;const H=D.match(/^t(\d+)$/);H&&(U=Math.max(U,parseInt(H[1],10)+1));const F=o?U:U+1,j={id:D,connected:!1,sessionResumed:!1,error:null,panels:{chatOpen:!1,planOpen:!1}},S={type:"leaf",terminalId:D},_={id:W,name:`Tab ${a.nextTabId}`,status:"open",terminalIds:[D],layout:S,createdAt:Date.now()};return n({tabs:[...a.tabs,_],activeTabId:W,nextTabId:a.nextTabId+1,nextId:F,terminalsMap:{...a.terminalsMap,[D]:j},terminalIds:[D],layout:S}),pe(ue(e())),D}const{nextId:i,nextSplitId:d,terminalsMap:l}=a,{terminalIds:f,layout:m}=c,p=o||`t${i}`;let h=i;const v=p.match(/^t(\d+)$/);v&&(h=Math.max(h,parseInt(v[1],10)+1));const C={id:p,connected:!1,sessionResumed:!1,error:null,panels:{chatOpen:!1,planOpen:!1}},$={type:"leaf",terminalId:p};let L,T=d;if(!m)L=$;else if(m.type==="leaf"){const W=t||"horizontal";L={id:`s${T}`,type:"split",direction:W,children:[m,$],sizes:[50,50]},T++}else if(m.direction===(t||"horizontal")){const D=100/(m.children.length+1),U=(100-D)/100,H=[...m.sizes.map(F=>F*U),D];L={...m,children:[...m.children,$],sizes:H}}else{const W=t||"horizontal";L={id:`s${T}`,type:"split",direction:W,children:[m,$],sizes:[50,50]},T++}const g=[...f,p],z=o?h:h+1,R=Me(a.tabs,c.id,W=>({...W,terminalIds:g,layout:L}));return n({terminalsMap:{...l,[p]:C},terminalIds:g,layout:L,tabs:R,nextId:z,nextSplitId:T}),pe(ue(e())),p},splitTerminal:(t,o,a)=>{const c=e(),i=ct(c);if(!i||!i.layout)return"";const{nextId:d,nextSplitId:l,terminalsMap:f}=c,m=`t${d}`,p={id:m,connected:!1,sessionResumed:!1,error:null,panels:{chatOpen:!1,planOpen:!1},...a?{startCwd:a}:{}},h={type:"leaf",terminalId:m},v=`s${l}`,C=tn(i.layout,t,o,h,v),$=[...i.terminalIds,m],L=d+1,T=l+1,g=Me(c.tabs,i.id,z=>({...z,terminalIds:$,layout:C}));return n({terminalsMap:{...f,[m]:p},terminalIds:$,layout:C,tabs:g,nextId:L,nextSplitId:T}),pe(ue(e())),m},removeTerminal:t=>{const o=Lt(e(),t);o&&(n(o),pe(ue(e())))},setTerminalConnected:(t,o)=>{n(a=>{const c=a.terminalsMap[t];return!c||c.connected===o?a:{terminalsMap:{...a.terminalsMap,[t]:{...c,connected:o}}}})},setTerminalResumed:(t,o)=>{n(a=>{const c=a.terminalsMap[t];return!c||c.sessionResumed===o?a:{terminalsMap:{...a.terminalsMap,[t]:{...c,sessionResumed:o}}}})},setTerminalError:(t,o)=>{n(a=>{const c=a.terminalsMap[t];return!c||c.error===o?a:{terminalsMap:{...a.terminalsMap,[t]:{...c,error:o}}}})},toggleChat:t=>{const o=e(),a=o.terminalsMap[t];if(!a)return;const c={...a.panels,chatOpen:!a.panels.chatOpen},i={...o.terminalsMap,[t]:{...a,panels:c}},d=o.tabs.find(f=>f.terminalIds.includes(t));let l=o.tabs;if(d){const f={...d.panelStates,[t]:c};l=Me(o.tabs,d.id,m=>({...m,panelStates:f}))}n({terminalsMap:i,tabs:l}),pe(ue(e()))},togglePlan:t=>{const o=e(),a=o.terminalsMap[t];if(!a)return;const c={...a.panels,planOpen:!a.panels.planOpen},i={...o.terminalsMap,[t]:{...a,panels:c}},d=o.tabs.find(f=>f.terminalIds.includes(t));let l=o.tabs;if(d){const f={...d.panelStates,[t]:c};l=Me(o.tabs,d.id,m=>({...m,panelStates:f}))}n({terminalsMap:i,tabs:l}),pe(ue(e()))},setSplitSizes:(t,o)=>{const a=e(),c=ct(a);if(!c||!c.layout)return;const i=nn(c.layout,t,o),d=Me(a.tabs,c.id,l=>({...l,layout:i}));n({layout:i,tabs:d}),lr(ue(e()))},fontSize:14,setFontSize:t=>{const o=Math.max(10,Math.min(24,t));n({fontSize:o}),Ge&&clearTimeout(Ge),Ge=setTimeout(()=>{Ge=null;const a=e().token;a&&or(a,o)},500)},latency:null,setLatency:t=>n({latency:t}),theme:(()=>{try{const t=localStorage.getItem("ai-cli-online-theme");if(t==="light"||t==="dark")return t}catch{}return"dark"})(),setTheme:t=>{n({theme:t});try{localStorage.setItem("ai-cli-online-theme",t)}catch{}document.documentElement.setAttribute("data-theme",t)},toggleTheme:()=>{const t=e().theme==="dark"?"light":"dark";e().setTheme(t)},sidebarOpen:!1,toggleSidebar:()=>n(t=>({sidebarOpen:!t.sidebarOpen})),serverSessions:[],fetchSessions:async()=>{const t=e().token;if(t)try{const o=await fetch(`${oe}/api/sessions`,{headers:le(t)});if(!o.ok)return;const a=await o.json();n({serverSessions:a})}catch{}},killServerSession:async t=>{const o=e().token;if(!o)return;try{await fetch(`${oe}/api/sessions/${encodeURIComponent(t)}`,{method:"DELETE",headers:le(o)})}catch{}const a=Lt(e(),t);a&&(n(a),pe(ue(e()))),setTimeout(()=>e().fetchSessions(),500)}}));typeof document<"u"&&document.documentElement.setAttribute("data-theme",A.getState().theme);async function ur(n,e){var a,c;const{setState:t,getState:o}=A;try{const[i,d]=await Promise.all([sr(n),fetch(`${oe}/api/sessions`,{headers:le(n)}).then(C=>C.ok?C.json():[]).catch(()=>[])]);if(o().token!==n)return;const l=i&&((a=i.tabs)==null?void 0:a.length)>0?i:e;if(!l||l.tabs.length===0){t({tabsLoading:!1});return}const f=dr(l,d);if(!f){t({tabsLoading:!1,terminalsMap:{},tabs:[],activeTabId:"",nextId:l.nextId,nextSplitId:l.nextSplitId,nextTabId:l.nextTabId,terminalIds:[],layout:null});return}const m=o().terminalsMap,p={};for(const C of f.tabs)if(C.status==="open")for(const $ of C.terminalIds)p[$]=m[$]||{id:$,connected:!1,sessionResumed:!1,error:null,panels:((c=C.panelStates)==null?void 0:c[$])||{chatOpen:!1,planOpen:!1}};const h=f.tabs.find(C=>C.id===f.activeTabId&&C.status==="open")||f.tabs.find(C=>C.status==="open"),v=(h==null?void 0:h.id)||"";t({tabsLoading:!1,terminalsMap:p,tabs:f.tabs,activeTabId:v,nextId:f.nextId,nextSplitId:f.nextSplitId,nextTabId:f.nextTabId,terminalIds:(h==null?void 0:h.terminalIds)||[],layout:(h==null?void 0:h.layout)||null}),pe(ue(o()))}catch{o().token===n&&t({tabsLoading:!1})}}function fr(){const[n,e]=s.useState(""),t=A(a=>a.setToken),o=a=>{a.preventDefault(),n.trim()&&t(n.trim())};return r.jsx("div",{style:{minHeight:"100vh",backgroundColor:"var(--bg-primary)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px",background:"radial-gradient(ellipse at 50% 0%, rgba(122, 162, 247, 0.08) 0%, var(--bg-primary) 70%)"},children:r.jsxs("div",{className:"login-card",style:{backgroundColor:"var(--bg-tertiary)",borderRadius:"12px",padding:"40px 36px",width:"100%",maxWidth:"400px",border:"1px solid var(--border)"},children:[r.jsxs("div",{style:{textAlign:"center",marginBottom:"36px"},children:[r.jsx("div",{style:{width:"56px",height:"56px",margin:"0 auto 16px",borderRadius:"14px",background:"linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-purple) 100%)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"24px",color:"var(--bg-primary)",fontWeight:"bold",boxShadow:"0 4px 16px rgba(122, 162, 247, 0.3)"},children:">_"}),r.jsx("h1",{style:{fontSize:"22px",fontWeight:"bold",color:"var(--text-bright)",marginBottom:"6px",letterSpacing:"0.5px"},children:"AI-Cli Online"}),r.jsx("p",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Terminal in your browser"})]}),r.jsxs("form",{onSubmit:o,children:[r.jsxs("div",{style:{marginBottom:"20px"},children:[r.jsx("label",{htmlFor:"token",style:{display:"block",fontSize:"12px",color:"var(--accent-blue)",marginBottom:"8px",fontWeight:500,textTransform:"uppercase",letterSpacing:"0.5px"},children:"Auth Token"}),r.jsx("input",{type:"password",id:"token",className:"login-input",value:n,onChange:a=>e(a.target.value),placeholder:"Enter your AUTH_TOKEN",autoFocus:!0,autoComplete:"current-password",style:{width:"100%",padding:"11px 14px",backgroundColor:"var(--bg-primary)",color:"var(--text-bright)",border:"1px solid var(--border)",borderRadius:"8px",fontSize:"14px",outline:"none"}})]}),r.jsx("button",{type:"submit",className:"login-submit",disabled:!n.trim(),style:{width:"100%",padding:"11px",background:n.trim()?"linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-cyan) 100%)":"var(--bg-hover)",color:n.trim()?"var(--bg-primary)":"var(--text-secondary)",border:"none",borderRadius:"8px",fontSize:"14px",fontWeight:600,cursor:n.trim()?"pointer":"not-allowed",letterSpacing:"0.3px"},children:"Connect"})]}),r.jsx("div",{style:{marginTop:"28px",textAlign:"center",color:"var(--scrollbar-thumb-hover)",fontSize:"11px"},children:r.jsxs("p",{children:["Token is configured in"," ",r.jsx("code",{style:{backgroundColor:"var(--bg-primary)",padding:"2px 6px",borderRadius:"4px",border:"1px solid var(--border)",fontSize:"11px"},children:"server/.env"})]})})]})})}const st=new Map;function pr(n,e,t){st.set(n,{onChunk:e,onControl:t})}function mr(n){st.delete(n)}function hr(n,e){var t;(t=st.get(n))==null||t.onChunk(e)}function br(n,e){var t;(t=st.get(n))==null||t.onControl(e)}const xr=1,Mt=2,gr=3,yr=4,vr=5,wr=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`,Xe=500,Sr=8e3,kr=1e4,At=4e3,Cr=5e3,Tr=10,Er=64*1024,jr=new TextDecoder,Ir=new TextEncoder;function zt(n,e){const t=Ir.encode(e),o=new Uint8Array(1+t.length);return o[0]=n,o.set(t,1),o.buffer}function Rr(n,e,t){const o=s.useRef(null),a=s.useRef(Xe),c=s.useRef(null),i=s.useRef(null),d=s.useRef(null),l=s.useRef(null),f=s.useRef(!1),m=s.useRef(t),p=s.useRef(!1),h=s.useRef(0),v=s.useRef(!0),C=s.useRef(!navigator.onLine),$=s.useRef(""),L=s.useRef(null),T=s.useRef("");m.current=t;const g=s.useCallback(()=>{i.current&&(clearInterval(i.current),i.current=null),d.current&&(clearTimeout(d.current),d.current=null),c.current&&(clearTimeout(c.current),c.current=null),l.current&&(clearTimeout(l.current),l.current=null),L.current&&(clearTimeout(L.current),L.current=null)},[]),z=s.useCallback(()=>{var Y;const{token:F,setTerminalError:j}=A.getState();if(!F||f.current)return;if(o.current){const J=o.current.readyState;if(J===WebSocket.OPEN||J===WebSocket.CONNECTING)return}p.current=!1;const S=(Y=A.getState().terminalsMap[e])==null?void 0:Y.startCwd;let _=`${wr}?sessionId=${encodeURIComponent(e)}`;S&&(_+=`&cwd=${encodeURIComponent(S)}`);const k=new WebSocket(_);k.binaryType="arraybuffer",l.current=window.setTimeout(()=>{k.readyState===WebSocket.CONNECTING&&k.close()},Cr);const G=()=>{k.readyState===WebSocket.OPEN&&(h.current=performance.now(),k.send(JSON.stringify({type:"ping"})),d.current=window.setTimeout(()=>{h.current>0&&(h.current=0,k.close())},At))};k.onopen=()=>{l.current&&(clearTimeout(l.current),l.current=null),k.send(JSON.stringify({type:"auth",token:F})),j(e,null),a.current=Xe,v.current=!0},k.onclose=J=>{const{setTerminalConnected:M,setTerminalError:B,setToken:X}=A.getState();if(M(e,!1),g(),p.current)return;if(J.code===4001){f.current=!0,B(e,"Authentication failed"),X(null),localStorage.removeItem("ai-cli-online-token");return}if(J.code===4002)return;if(J.code===4005){B(e,"Connection limit reached");return}if(!navigator.onLine){C.current=!0;return}if(v.current){v.current=!1,c.current=window.setTimeout(()=>z(),50);return}const O=a.current;a.current=Math.min(O*2,Sr);const K=Math.round(O*(.5+Math.random()));c.current=window.setTimeout(()=>{z()},K)},k.onerror=()=>{},k.onmessage=J=>{var M;try{const B=n.current;if(J.data instanceof ArrayBuffer){const O=new Uint8Array(J.data);if(O.length<1)return;const K=O[0],re=O.subarray(1);switch(K){case xr:B==null||B.write(re);break;case gr:B==null||B.write(re);break;case yr:{(M=m.current)==null||M.call(m,jr.decode(re));break}case vr:{hr(e,re);break}}return}const X=JSON.parse(J.data);switch(X.type){case"connected":{const O=A.getState();O.setTerminalConnected(e,!0),O.setTerminalResumed(e,X.resumed);const K=n.current;K&&k.readyState===WebSocket.OPEN&&k.send(JSON.stringify({type:"resize",cols:K.cols,rows:K.rows})),T.current&&(k.send(zt(Mt,T.current)),T.current=""),G(),i.current=window.setInterval(G,kr);break}case"error":A.getState().setTerminalError(e,X.error);break;case"pong":{if(d.current&&(clearTimeout(d.current),d.current=null),h.current>0){const O=Math.round(performance.now()-h.current),K=A.getState();(K.terminalIds.length===0||K.terminalIds[0]===e)&&K.setLatency(O),h.current=0}break}case"file-stream-start":case"file-stream-end":case"file-stream-error":br(e,X);break}}catch{}},o.current=k},[e,n,g]),R=s.useCallback(F=>{const j=o.current;if(!j||j.readyState!==WebSocket.OPEN){T.current.length<Er&&(T.current+=F);return}$.current+=F,L.current||(L.current=window.setTimeout(()=>{const S=$.current;$.current="",L.current=null,S&&j.readyState===WebSocket.OPEN&&j.send(zt(Mt,S))},Tr))},[]),W=s.useCallback((F,j)=>{var S;((S=o.current)==null?void 0:S.readyState)===WebSocket.OPEN&&o.current.send(JSON.stringify({type:"resize",cols:F,rows:j}))},[]),D=s.useCallback(()=>{var F;((F=o.current)==null?void 0:F.readyState)===WebSocket.OPEN&&o.current.send(JSON.stringify({type:"capture-scrollback"}))},[]),U=s.useCallback(F=>{var j;((j=o.current)==null?void 0:j.readyState)===WebSocket.OPEN&&o.current.send(JSON.stringify({type:"stream-file",path:F}))},[]),H=s.useCallback(()=>{var F;((F=o.current)==null?void 0:F.readyState)===WebSocket.OPEN&&o.current.send(JSON.stringify({type:"cancel-stream"}))},[]);return s.useEffect(()=>{A.getState().token&&(f.current=!1,z());const j=()=>{C.current=!1,a.current=Xe,v.current=!0;const k=o.current;(!k||k.readyState===WebSocket.CLOSED||k.readyState===WebSocket.CLOSING)&&z()},S=()=>{C.current=!0},_=()=>{if(document.visibilityState!=="visible")return;const k=o.current;if(!k||k.readyState!==WebSocket.OPEN){!C.current&&!p.current&&(a.current=Xe,v.current=!0,z());return}h.current=performance.now(),k.send(JSON.stringify({type:"ping"})),d.current&&clearTimeout(d.current),d.current=window.setTimeout(()=>{h.current>0&&(h.current=0,k.close())},At)};return window.addEventListener("online",j),window.addEventListener("offline",S),document.addEventListener("visibilitychange",_),()=>{p.current=!0,g(),window.removeEventListener("online",j),window.removeEventListener("offline",S),document.removeEventListener("visibilitychange",_),o.current&&(o.current.close(),o.current=null)}},[z,g,e]),{sendInput:R,sendResize:W,requestScrollback:D,requestFileStream:U,cancelFileStream:H}}function Nr(n){const e=s.useRef(null),t=s.useRef(null),o=s.useRef(n);o.current=n;const a=s.useCallback(()=>{t.current&&(clearTimeout(t.current),t.current=null),e.current&&(e.current.remove(),e.current=null)},[]),c=s.useCallback((i,d)=>{a();const l=document.createElement("div");l.style.cssText=`position:fixed;left:${i}px;top:${d}px;z-index:1000;display:flex;align-items:center;gap:4px;padding:4px 6px;background:var(--bg-tertiary);border:1px solid var(--border);border-radius:4px;box-shadow:0 2px 8px rgba(0,0,0,0.4);font-family:inherit;`;const f=document.createElement("textarea");f.style.cssText="width:90px;height:22px;resize:none;border:1px solid var(--border);border-radius:3px;background:var(--bg-primary);color:var(--text-primary);font-size:11px;font-family:inherit;padding:2px 4px;outline:none;",f.placeholder="Ctrl+V",f.addEventListener("paste",m=>{var h;m.preventDefault();const p=(h=m.clipboardData)==null?void 0:h.getData("text/plain");p&&o.current(p),a()}),f.addEventListener("keydown",m=>{m.key==="Escape"&&a()}),l.appendChild(f),document.body.appendChild(l),e.current=l,requestAnimationFrame(()=>{const m=l.getBoundingClientRect();m.right>window.innerWidth&&(l.style.left=`${window.innerWidth-m.width-8}px`),m.bottom>window.innerHeight&&(l.style.top=`${window.innerHeight-m.height-8}px`),f.focus()}),t.current=setTimeout(a,8e3)},[a]);return s.useEffect(()=>{const i=()=>{e.current&&a()};return document.addEventListener("click",i),()=>{document.removeEventListener("click",i),a()}},[a]),{showPasteFloat:c,removePasteFloat:a}}const tt={background:"#000000",foreground:"#cccccc",cursor:"#aeafad",selectionBackground:"rgba(38, 79, 120, 0.5)",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#e5e5e5"},nt={background:"#ffffff",foreground:"#1f2328",cursor:"#0969da",selectionBackground:"rgba(9, 105, 218, 0.2)",black:"#24292f",red:"#cf222e",green:"#1a7f37",yellow:"#9a6700",blue:"#0969da",magenta:"#8250df",cyan:"#1b7c83",white:"#6e7781",brightBlack:"#57606a",brightRed:"#a40e26",brightGreen:"#2da44e",brightYellow:"#bf8803",brightBlue:"#218bff",brightMagenta:"#a475f9",brightCyan:"#3192aa",brightWhite:"#8c959f"},rn="'JetBrains Mono', 'LXGW WenKai Mono', Menlo, Monaco, 'Courier New', monospace",Dr=s.forwardRef(function({sessionId:e},t){const o=s.useRef(null),a=s.useRef(null),c=s.useRef(null),[i,d]=s.useState(!1),[l,f]=s.useState(""),m=A(D=>D.fontSize),p=A(D=>D.theme),h=s.useCallback(D=>{f(D),d(!0)},[]),{sendInput:v,sendResize:C,requestScrollback:$,requestFileStream:L,cancelFileStream:T}=Rr(a,e,h);s.useImperativeHandle(t,()=>({sendInput:v,requestFileStream:L,cancelFileStream:T}),[v,L,T]);const g=s.useRef(v),z=s.useRef(C);g.current=v,z.current=C;const{showPasteFloat:R,removePasteFloat:W}=Nr(D=>g.current(D));return s.useEffect(()=>{if(!o.current)return;let D=!1,U=null,H=null,F=null,j=null;if(D||!o.current)return;const S=new Wt({cursorBlink:!0,scrollback:1e4,fontSize:A.getState().fontSize,fontFamily:rn,theme:A.getState().theme==="dark"?tt:nt,allowProposedApi:!0}),_=new Ht;S.loadAddon(_),S.loadAddon(new kn((O,K)=>{window.open(K,"_blank","noopener,noreferrer")})),S.open(o.current);try{const O=new Kt;O.onContextLoss(()=>{O.dispose()}),S.loadAddon(O)}catch{}a.current=S,c.current=_,S.onSelectionChange(()=>{const O=S.getSelection();O&&navigator.clipboard.writeText(O).catch(()=>{})});const k=S.element,G=O=>{var K;if(O.preventDefault(),W(),!((K=navigator.clipboard)!=null&&K.readText)){R(O.clientX,O.clientY);return}navigator.clipboard.readText().then(re=>{re&&g.current(re)}).catch(()=>{R(O.clientX,O.clientY)})};k&&k.addEventListener("contextmenu",G);const Y=()=>{try{const O=o.current;if(O&&O.clientWidth>0&&O.clientHeight>0)return _.fit(),z.current(S.cols,S.rows),!0}catch{}return!1};requestAnimationFrame(()=>Y());let J=0;U=setInterval(()=>{J++,(Y()||J>=10)&&(clearInterval(U),U=null)},100),document.fonts.ready.then(()=>{if(!D)try{_.fit(),z.current(S.cols,S.rows)}catch{}});let M=null;const B=()=>{D||(M&&clearTimeout(M),M=setTimeout(()=>{if(!D)try{_.fit(),z.current(S.cols,S.rows)}catch{}},100))};document.fonts.addEventListener("loadingdone",B),S.onData(O=>{g.current(O)});let X=!1;return j=new ResizeObserver(()=>{if(document.body.classList.contains("resizing-panes")||document.body.classList.contains("resizing-panes-v")){if(!X){X=!0;const K=()=>{document.removeEventListener("mouseup",K),X=!1,requestAnimationFrame(()=>{try{_.fit(),z.current(S.cols,S.rows)}catch{}})};document.addEventListener("mouseup",K)}return}H||(H=requestAnimationFrame(()=>{H=null;try{_.fit(),F&&clearTimeout(F),F=setTimeout(()=>{F=null,z.current(S.cols,S.rows)},50)}catch{}}))}),j.observe(o.current),()=>{D=!0,U&&clearInterval(U),H&&cancelAnimationFrame(H),F&&clearTimeout(F),M&&clearTimeout(M),document.fonts.removeEventListener("loadingdone",B),j&&j.disconnect(),W(),k&&k.removeEventListener("contextmenu",G),a.current&&(a.current.dispose(),a.current=null),c.current=null}},[e]),s.useEffect(()=>{const D=a.current,U=c.current;if(!(!D||!U)&&D.options.fontSize!==m){D.options.fontSize=m;try{U.fit()}catch{}z.current(D.cols,D.rows)}},[m]),s.useEffect(()=>{a.current&&(a.current.options.theme=p==="dark"?tt:nt)},[p]),r.jsxs("div",{style:{width:"100%",height:"100%",position:"relative"},children:[r.jsx("div",{ref:o,style:{width:"100%",height:"100%",backgroundColor:"var(--bg-primary)",contain:"strict",willChange:"transform",isolation:"isolate"}}),r.jsx("button",{tabIndex:-1,onClick:D=>{D.currentTarget.blur(),i?(d(!1),f("")):$()},title:"Toggle scrollback history",style:{position:"absolute",top:4,right:4,zIndex:10,background:i?"var(--accent-blue)":"var(--bg-hover)",color:"var(--text-bright)",border:"none",borderRadius:4,padding:"2px 8px",fontSize:14,cursor:"pointer",opacity:.8,lineHeight:"20px"},onMouseEnter:D=>{D.currentTarget.style.opacity="1"},onMouseLeave:D=>{D.currentTarget.style.opacity="0.8"},children:i?"✕":r.jsx("span",{style:{fontSize:14},children:"👁"})}),i&&r.jsx(Lr,{data:l,onClose:()=>{d(!1),f("")}})]})});function Lr({data:n,onClose:e}){const t=s.useRef(null),o=s.useRef(e);o.current=e;const a=A(f=>f.fontSize),c=A(f=>f.theme),i=s.useRef(null),d=s.useRef(null);s.useEffect(()=>{if(!t.current)return;const f=new Wt({cursorBlink:!1,disableStdin:!0,scrollback:5e4,fontSize:a,fontFamily:rn,theme:c==="dark"?tt:nt});i.current=f;const m=new Ht;d.current=m,f.loadAddon(m),f.open(t.current);let p=null;try{p=new Kt,p.onContextLoss(()=>{p==null||p.dispose(),p=null}),f.loadAddon(p)}catch{p=null}f.onSelectionChange(()=>{const T=f.getSelection();T&&navigator.clipboard.writeText(T).catch(()=>{})}),f.attachCustomKeyEventHandler(T=>(T.key==="Escape"&&o.current(),!1)),f.write(n);let h=null;const v=()=>{const T=t.current;if(!T||T.clientWidth<=0||T.clientHeight<=0)return!1;try{return m.fit(),f.scrollToBottom(),!0}catch{return!1}};requestAnimationFrame(()=>{if(!v()){let T=0;h=setInterval(()=>{T++,(v()||T>=30)&&(clearInterval(h),h=null)},50)}});let C=null;const $=new ResizeObserver(()=>{C||(C=requestAnimationFrame(()=>{C=null,v()}))});$.observe(t.current);const L=T=>{T.key==="Escape"&&o.current()};return document.addEventListener("keydown",L),()=>{if(h&&clearInterval(h),C&&cancelAnimationFrame(C),document.removeEventListener("keydown",L),$.disconnect(),p){try{p.dispose()}catch{}p=null}f.dispose(),i.current=null,d.current=null}},[n]),s.useEffect(()=>{var f;if(i.current){i.current.options.fontSize=a;try{(f=d.current)==null||f.fit()}catch{}}},[a]),s.useEffect(()=>{i.current&&(i.current.options.theme=c==="dark"?tt:nt)},[c]);const l=28;return r.jsxs("div",{style:{position:"absolute",inset:0,zIndex:5,backgroundColor:"var(--bg-primary)"},children:[r.jsx("div",{style:{height:l,boxSizing:"border-box",padding:"0 12px",background:"var(--bg-tertiary)",color:"var(--accent-blue)",fontSize:12,borderBottom:"1px solid var(--scrollbar-thumb-hover)",display:"flex",alignItems:"center"},children:r.jsx("span",{children:"Scrollback History (mouse wheel to scroll, ESC to close)"})}),r.jsx("div",{ref:t,style:{position:"absolute",top:l,left:0,right:0,bottom:0,overflow:"hidden"}})]})}const Mr=50;function ht(){const n=s.useRef([]),e=s.useCallback(a=>{n.current.push(a),n.current.length>Mr&&n.current.shift()},[]),t=s.useCallback(()=>n.current.pop(),[]),o=s.useCallback(()=>{n.current=[]},[]);return s.useMemo(()=>({pushUndo:e,popUndo:t,clearUndo:o}),[e,t,o])}function bt(n,e,t){n.preventDefault();const o=n.currentTarget,a=o.selectionStart,c=o.selectionEnd,i=o.value;t==null||t(i);const d=i.slice(0,a)+" "+i.slice(c);e(d),requestAnimationFrame(()=>{o.selectionStart=o.selectionEnd=a+2})}function We(n,e=10){var t;return Math.min(e,Math.max(1,(((t=n.match(/\n/g))==null?void 0:t.length)??0)+1))}let Ke=null;const Ar=["https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs","https://unpkg.com/mermaid@11/dist/mermaid.esm.min.mjs"];function zr(n){return n.initialize({startOnLoad:!1,theme:"dark",themeVariables:{primaryColor:"#7aa2f7",primaryTextColor:"#c0caf5",primaryBorderColor:"#414868",lineColor:"#565f89",secondaryColor:"#bb9af7",tertiaryColor:"#24283b",background:"#1a1b26",mainBkg:"#24283b",nodeBorder:"#414868",clusterBkg:"#1e2030",titleColor:"#c0caf5",edgeLabelBackground:"#1e2030",gridColor:"#292e42",doneTaskBkgColor:"#9ece6a",doneTaskBorderColor:"#73a942",activeTaskBkgColor:"#7aa2f7",activeTaskBorderColor:"#5d87d6",critBkgColor:"#f7768e",critBorderColor:"#d35d72",taskBkgColor:"#414868",taskBorderColor:"#565f89",taskTextColor:"#c0caf5",taskTextDarkColor:"#1a1b26",sectionBkgColor:"#1e2030",sectionBkgColor2:"#24283b",altSectionBkgColor:"#1e2030",todayLineColor:"#e0af68"},gantt:{titleTopMargin:15,barHeight:24,barGap:6,topPadding:40,numberSectionStyles:4,useWidth:800}}),n}function $r(){return Ke||(Ke=(async()=>{for(const n of Ar)try{const e=await import(n);return zr(e.default)}catch{}throw Ke=null,new Error("All mermaid CDN sources failed")})(),Ke)}let _r=0;function Or(n,e){s.useEffect(()=>{const t=n.current;if(!t)return;const o=t.querySelectorAll("code.language-mermaid, code.language-gantt");if(o.length===0)return;let a=!1;return(async()=>{let c;try{c=await $r()}catch{if(a)return;for(const d of o){const l=d.parentElement;if(!l||l.tagName!=="PRE")continue;l.classList.add("mermaid-error");const f=document.createElement("div");f.className="mermaid-error__msg",f.textContent="Failed to load Mermaid library",l.appendChild(f)}return}if(!a)for(const i of o){if(a)break;const d=i.parentElement;if(!d||d.tagName!=="PRE")continue;const l=i.textContent||"";if(!l.trim())continue;const f=`mermaid-${++_r}`;try{const{svg:m}=await c.render(f,l);if(a)break;const p=document.createElement("div");p.className="mermaid-diagram",p.innerHTML=qt.sanitize(m,{USE_PROFILES:{svg:!0,svgFilters:!0},ADD_TAGS:["foreignObject"]}),d.replaceWith(p)}catch{if(a)break;d.classList.add("mermaid-error");const m=document.createElement("div");m.className="mermaid-error__msg",m.textContent="Mermaid syntax error",d.appendChild(m)}}})(),()=>{a=!0}},[e])}async function Fr(n,e,t){const o=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/annotations?path=${encodeURIComponent(t)}`,{headers:le(n)});if(!o.ok)throw new Error("Failed to fetch annotation");const a=await o.json();return a.content?{content:a.content,updatedAt:a.updatedAt}:null}async function Pr(n,e,t,o,a){if(!(await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/annotations`,{method:"PUT",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({path:t,content:o,updatedAt:a})})).ok)throw new Error("Failed to save annotation")}function on(n,e){let t=n.replace(/<[^>]*>/g,"").trim().toLowerCase().replace(/\s+/g,"-").replace(/[&<>"'`]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"");t||(t="heading");const o=e.get(t)||0;return o>0&&(t=`${t}-${o}`),e.set(t,o+1),t}function sn(n){return n.replace(/\*\*(.+?)\*\*/g,"$1").replace(/__(.+?)__/g,"$1").replace(/\*(.+?)\*/g,"$1").replace(/_(.+?)_/g,"$1").replace(/~~(.+?)~~/g,"$1").replace(/`(.+?)`/g,"$1").replace(/\[(.+?)\]\(.*?\)/g,"$1").trim()}function Br(n){if(!n)return[];const e=[],t=new Map,o=n.split(`
|
|
26
|
+
`);let a=!1;for(const c of o){if(/^```/.test(c.trim())){a=!a;continue}if(a)continue;const i=c.match(/^(#{1,6})\s+(.+?)(?:\s+#+)?\s*$/);if(i){const d=i[1].length,l=sn(i[2]),f=on(l,t);e.push({id:f,text:l,level:d})}}return e}const Ur=160,Wr=22;function Hr({headings:n,scrollRef:e}){const[t,o]=s.useState(null),[a,c]=s.useState(()=>localStorage.getItem("md-toc-collapsed")==="true"),i=s.useRef(null),d=s.useRef(!1),l=s.useMemo(()=>Math.min(...n.map(p=>p.level)),[n]),f=s.useCallback(()=>{c(p=>{const h=!p;try{localStorage.setItem("md-toc-collapsed",String(h))}catch{}return h})},[]);s.useEffect(()=>{const p=e.current;if(!p||n.length===0)return;const h=()=>{d.current=!1;const C=p.scrollTop,$=50;let L=null;for(const T of n){const g=p.querySelector(`[id="${CSS.escape(T.id)}"]`);g&&g.offsetTop<=C+$&&(L=T.id)}o(L)},v=()=>{d.current||(d.current=!0,requestAnimationFrame(h))};return h(),p.addEventListener("scroll",v,{passive:!0}),()=>p.removeEventListener("scroll",v)},[n,e]);const m=s.useCallback(p=>{const h=e.current;if(!h)return;const v=h.querySelector(`[id="${CSS.escape(p)}"]`);v&&(v.scrollIntoView({behavior:"smooth",block:"start"}),o(p))},[e]);return s.useEffect(()=>{if(!t||a)return;const p=i.current;if(!p)return;const h=p.querySelector(`[data-toc-id="${CSS.escape(t)}"]`);if(h){const v=h.offsetTop-p.offsetTop,C=v+h.offsetHeight;(v<p.scrollTop||C>p.scrollTop+p.clientHeight)&&h.scrollIntoView({block:"nearest"})}},[t,a]),n.length<2?null:a?r.jsx("div",{style:{width:Wr,flexShrink:0,display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:4,borderLeft:"1px solid var(--border)",backgroundColor:"var(--bg-secondary)"},children:r.jsx("button",{onClick:f,title:"Show table of contents",style:{background:"none",border:"none",color:"var(--text-secondary)",fontSize:13,cursor:"pointer",padding:"2px",lineHeight:1},onMouseEnter:p=>{p.currentTarget.style.color="var(--accent-blue)"},onMouseLeave:p=>{p.currentTarget.style.color="var(--text-secondary)"},children:"☰"})}):r.jsxs("div",{ref:i,style:{width:Ur,flexShrink:0,borderLeft:"1px solid var(--border)",backgroundColor:"var(--bg-secondary)",overflowY:"auto",overflowX:"hidden",display:"flex",flexDirection:"column"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 6px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[r.jsx("span",{style:{fontSize:10,color:"var(--border)",textTransform:"uppercase",letterSpacing:"0.5px"},children:"Contents"}),r.jsx("button",{onClick:f,title:"Hide table of contents",style:{background:"none",border:"none",color:"var(--text-secondary)",fontSize:12,cursor:"pointer",padding:"0 2px",lineHeight:1},onMouseEnter:p=>{p.currentTarget.style.color="var(--accent-blue)"},onMouseLeave:p=>{p.currentTarget.style.color="var(--text-secondary)"},children:"»"})]}),r.jsx("div",{style:{flex:1,overflowY:"auto",padding:"4px 0"},children:n.map((p,h)=>r.jsx("div",{"data-toc-id":p.id,onClick:()=>m(p.id),style:{padding:`2px 6px 2px ${(p.level-l)*10+6}px`,fontSize:11,lineHeight:1.5,color:t===p.id?"var(--accent-blue)":"var(--text-secondary)",cursor:"pointer",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",borderLeft:t===p.id?"2px solid var(--accent-blue)":"2px solid transparent",fontWeight:p.level<=2?500:400,transition:"color 0.1s"},title:p.text,onMouseEnter:v=>{t!==p.id&&(v.currentTarget.style.color="var(--text-primary)"),v.currentTarget.style.backgroundColor="var(--bg-tertiary)"},onMouseLeave:v=>{t!==p.id&&(v.currentTarget.style.color="var(--text-secondary)"),v.currentTarget.style.backgroundColor="transparent"},children:p.text},`${p.id}-${h}`))})]})}const dt={additions:[],deletions:[],replacements:[],comments:[]};let Kr=0;function $e(){return`ann_${++Kr}_${Date.now()}`}function Ze(n,e){return`plan-annotations-${n}-${e}`}function $t(n,e){return`plan-scroll-${n}-${e}`}function qr(n){const e=String(Jt.parser([n],{async:!1}));return qt.sanitize(e,{ADD_TAGS:["img"],ADD_ATTR:["src","alt","title","width","height"]})}function ut(n,e){let t=1;for(let o=0;o<e&&o<n.length;o++){const a=n[o].raw??"";for(const c of a)c===`
|
|
27
27
|
`&&t++}return t}function _e(n){if(!n)return"";const e=n.trim();return e.length<=40?e:e.slice(0,20)+"..."+e.slice(-20)}function Jr(n,e){const t=[],o=[],a=[],c=[];for(const i of n.additions){const d=e[i.sourceLine-1]??"",l=e[i.sourceLine]??"";t.push([`${i.sourceLine}: ${_e(d)}`,i.content,_e(l)])}for(const i of n.deletions){const d=e[i.startLine-2]??"",l=e[i.endLine]??"";o.push([`${i.startLine}: ${_e(d)}`,i.selectedText,_e(l)])}for(const i of n.replacements){const d=e[i.startLine-2]??"",l=e[i.endLine]??"";a.push([`${i.startLine}: ${_e(d)}`,i.selectedText,i.content,_e(l)])}for(const i of n.comments){const d=e[i.startLine-2]??"",l=e[i.endLine]??"";c.push([`${i.startLine}: ${_e(d)}`,i.selectedText,i.content,_e(l)])}return{"Insert Annotations":t,"Delete Annotations":o,"Replace Annotations":a,"Comment Annotations":c}}function ft(n,e,t){if(e.additions.length===0&&e.deletions.length===0&&e.replacements.length===0&&e.comments.length===0)return"";const o=JSON.stringify(Jr(e,t));return`/aicli-task-review ${n} ${o}`}const Vr=s.forwardRef(function({markdown:e,filePath:t,sessionId:o,token:a,onExecute:c,onSend:i,onRefresh:d,onClose:l,expanded:f,readOnly:m},p){const h=A(u=>u.fontSize),v=s.useMemo(()=>e?Jt.lexer(e):[],[e]),C=s.useMemo(()=>e.split(`
|
|
28
|
-
`),[e]),_=s.useMemo(()=>Br(e),[e]),D=s.useMemo(()=>{const u=new Map,b=new Map;return v.forEach((I,w)=>{if(I.type==="heading"){const y=sn(I.text||""),Z=on(y,b);u.set(w,Z)}}),u},[v]),T=s.useRef(new Set),[g,$]=s.useState(()=>{try{const u=localStorage.getItem(Ze(o,t)),b=u?JSON.parse(u):dt,I=new Set;return b.additions.forEach(w=>I.add(w.id)),b.deletions.forEach(w=>I.add(w.id)),(b.replacements??[]).forEach(w=>I.add(w.id)),(b.comments??[]).forEach(w=>I.add(w.id)),T.current=I,b.replacements||(b.replacements=[]),b.comments||(b.comments=[]),b}catch{return dt}}),R=A(u=>u.latency),U=s.useRef(void 0),L=s.useRef(void 0),B=s.useRef(!1),W=s.useRef(!1);s.useEffect(()=>{if(!W.current)return;const u=Ze(o,t),b=JSON.stringify(g);U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{try{localStorage.setItem(u,b)}catch{}},50),L.current&&clearTimeout(L.current);const I=Math.max(200,(R??30)*3);return L.current=setTimeout(()=>{B.current||(B.current=!0,Pr(a,o,t,b,Date.now()).catch(()=>{}).finally(()=>{B.current=!1}))},I),()=>{U.current&&clearTimeout(U.current),L.current&&clearTimeout(L.current)}},[g,o,t,a,R]),s.useEffect(()=>{W.current=!1;let u=dt,b=0;try{const y=localStorage.getItem(Ze(o,t));y&&(u=JSON.parse(y),b=Date.now())}catch{}u.replacements||(u.replacements=[]),u.comments||(u.comments=[]),$(u);const I=new Set;u.additions.forEach(y=>I.add(y.id)),u.deletions.forEach(y=>I.add(y.id)),u.replacements.forEach(y=>I.add(y.id)),u.comments.forEach(y=>I.add(y.id)),T.current=I;let w=!1;return Fr(a,o,t).then(y=>{if(!w&&y&&y.updatedAt>b)try{const Z=JSON.parse(y.content);Z.replacements||(Z.replacements=[]),Z.comments||(Z.comments=[]),$(Z);try{localStorage.setItem(Ze(o,t),y.content)}catch{}const Ee=new Set;Z.additions.forEach(je=>Ee.add(je.id)),Z.deletions.forEach(je=>Ee.add(je.id)),Z.replacements.forEach(je=>Ee.add(je.id)),Z.comments.forEach(je=>Ee.add(je.id)),T.current=Ee}catch{}}).catch(()=>{}).finally(()=>{W.current=!0}),W.current=!0,()=>{w=!0}},[o,t,a]);const[F,j]=s.useState(0),S=s.useMemo(()=>{const u=T.current,b=g.additions.length+g.deletions.length+g.replacements.length+g.comments.length;let I=0;return g.additions.forEach(w=>{u.has(w.id)&&I++}),g.deletions.forEach(w=>{u.has(w.id)&&I++}),g.replacements.forEach(w=>{u.has(w.id)&&I++}),g.comments.forEach(w=>{u.has(w.id)&&I++}),{total:b,sent:I,unsent:b-I}},[g,F]),[O,k]=s.useState(null),[X,V]=s.useState(""),K=s.useRef(null),[z,M]=s.useState(null),[G,J]=s.useState(""),Y=s.useRef(null),[le,ne]=s.useState(null),[be,Ce]=s.useState(""),Te=s.useRef(null),[Be,ve]=s.useState(null),[ge,Ie]=s.useState(""),me=s.useRef(null),[Q,Ae]=s.useState(null),[he,N]=s.useState(""),P=s.useRef(null),[q,ae]=s.useState(null),te=s.useRef(null);s.useEffect(()=>()=>{const u=te.current;u&&u.scrollTop>0&&localStorage.setItem($t(o,t),String(u.scrollTop))},[o,t]),s.useEffect(()=>{if(!v.length)return;const u=localStorage.getItem($t(o,t));u&&requestAnimationFrame(()=>{const b=te.current;b&&(b.scrollTop=Number(u))})},[o,t,v.length]),s.useEffect(()=>{O!=null&&requestAnimationFrame(()=>{var u;return(u=K.current)==null?void 0:u.focus()})},[O]),s.useEffect(()=>{Q&&requestAnimationFrame(()=>{var u;return(u=P.current)==null?void 0:u.focus()})},[Q]);const ye=s.useCallback(u=>{if(!X.trim()){k(null),V("");return}const b=ut(v,u+1);$(I=>({...I,additions:[...I.additions,{id:$e(),afterTokenIndex:u,sourceLine:b,content:X.trim()}]})),k(null),V("")},[X,v]),we=s.useCallback(u=>{$(b=>({...b,additions:b.additions.filter(I=>I.id!==u)}))},[]),Re=s.useCallback((u,b)=>{$(I=>({...I,additions:I.additions.map(w=>w.id===u?{...w,id:$e(),content:b}:w)}))},[]),Ne=s.useCallback(()=>{var u;q&&($(b=>({...b,deletions:[...b.deletions,{id:$e(),tokenIndices:q.tokenIndices,startLine:q.startLine,endLine:q.endLine,selectedText:q.text.slice(0,80)}]})),ae(null),(u=window.getSelection())==null||u.removeAllRanges())},[q]),ze=s.useCallback(u=>{var b;q&&(Ae({type:u,tokenIndices:q.tokenIndices,startLine:q.startLine,endLine:q.endLine,text:q.text.slice(0,80)}),N(""),ae(null),(b=window.getSelection())==null||b.removeAllRanges())},[q]),De=s.useCallback(()=>{if(!Q)return;const u=he.trim();if(!u){Ae(null),N("");return}Q.type==="replace"?$(b=>({...b,replacements:[...b.replacements,{id:$e(),tokenIndices:Q.tokenIndices,startLine:Q.startLine,endLine:Q.endLine,selectedText:Q.text,content:u}]})):$(b=>({...b,comments:[...b.comments,{id:$e(),tokenIndices:Q.tokenIndices,startLine:Q.startLine,endLine:Q.endLine,selectedText:Q.text,content:u}]})),Ae(null),N("")},[Q,he]),Oe=s.useCallback(u=>{$(b=>({...b,replacements:b.replacements.filter(I=>I.id!==u)}))},[]),Je=s.useCallback((u,b)=>{$(I=>({...I,replacements:I.replacements.map(w=>w.id===u?{...w,id:$e(),content:b}:w)}))},[]),x=s.useCallback(u=>{$(b=>({...b,comments:b.comments.filter(I=>I.id!==u)}))},[]),E=s.useCallback((u,b)=>{$(I=>({...I,comments:I.comments.map(w=>w.id===u?{...w,id:$e(),content:b}:w)}))},[]),H=s.useCallback(u=>{$(b=>({...b,deletions:b.deletions.filter(I=>I.id!==u)}))},[]),ee=s.useCallback((u,b)=>{$(I=>({...I,deletions:I.deletions.map(w=>w.id===u?{...w,id:$e(),selectedText:b}:w)}))},[]),oe=s.useCallback(u=>{let b=u instanceof Element?u:u.parentElement;for(;b&&b!==te.current;){if(b.hasAttribute("data-token-index"))return b;b=b.parentElement}return null},[]),xe=s.useCallback(()=>{const u=window.getSelection();if(!u||u.isCollapsed||!te.current){ae(null);return}const b=u.toString().trim();if(!b){ae(null);return}const I=u.getRangeAt(0);if(!te.current.contains(I.commonAncestorContainer)){ae(null);return}const w=oe(I.startContainer),y=oe(I.endContainer);if(!w||!y){ae(null);return}const Z=parseInt(w.getAttribute("data-token-index")||"0",10),Ee=parseInt(y.getAttribute("data-token-index")||"0",10),je=[];for(let it=Math.min(Z,Ee);it<=Math.max(Z,Ee);it++)je.push(it);const xn=ut(v,Math.min(Z,Ee)),gn=ut(v,Math.max(Z,Ee)+1),St=I.getBoundingClientRect(),at=te.current,kt=at.getBoundingClientRect();navigator.clipboard.writeText(b).catch(()=>{}),ae({x:St.right-kt.left+at.scrollLeft+6,y:St.top-kt.top+at.scrollTop-2,tokenIndices:je,startLine:xn,endLine:gn,text:b})},[v,oe]),se=s.useRef(void 0);s.useEffect(()=>{const u=()=>{se.current&&clearTimeout(se.current),se.current=setTimeout(()=>{const b=window.getSelection();if(!b||b.isCollapsed||!te.current){ae(null);return}const I=b.anchorNode;I&&te.current.contains(I)&&xe()},120)};return document.addEventListener("selectionchange",u),()=>{document.removeEventListener("selectionchange",u),se.current&&clearTimeout(se.current)}},[xe]),Or(te,v);const de=s.useCallback(()=>{const u=T.current;return{additions:g.additions.filter(b=>!u.has(b.id)),deletions:g.deletions.filter(b=>!u.has(b.id)),replacements:g.replacements.filter(b=>!u.has(b.id)),comments:g.comments.filter(b=>!u.has(b.id))}},[g]),fe=s.useCallback(()=>{const u=ft(t,de(),C);if(u){c(u);const b=new Set;g.additions.forEach(I=>b.add(I.id)),g.deletions.forEach(I=>b.add(I.id)),g.replacements.forEach(I=>b.add(I.id)),g.comments.forEach(I=>b.add(I.id)),T.current=b,j(I=>I+1)}},[de,g,C,c,t]);s.useImperativeHandle(p,()=>({getSummary:()=>ft(t,de(),C),handleEscape:()=>Q?(De(),!0):O!=null?(ye(O),!0):!1,getScrollTop:()=>{var u;return((u=te.current)==null?void 0:u.scrollTop)??0},setScrollTop:u=>{requestAnimationFrame(()=>{te.current&&(te.current.scrollTop=u)})}}),[de,C,t,O,ye,Q,De]);const[ce,Le]=s.useState(!1),Fe=s.useRef(null);s.useEffect(()=>{if(!ce)return;const u=b=>{Fe.current&&!Fe.current.contains(b.target)&&Le(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[ce]);const Se=s.useCallback((u,b)=>{if(!i)return;const I={additions:[],deletions:[],replacements:[],comments:[]};if(b==="add"){const y=g.additions.find(Z=>Z.id===u);if(!y)return;I.additions.push(y)}else if(b==="del"){const y=g.deletions.find(Z=>Z.id===u);if(!y)return;I.deletions.push(y)}else if(b==="rep"){const y=g.replacements.find(Z=>Z.id===u);if(!y)return;I.replacements.push(y)}else{const y=g.comments.find(Z=>Z.id===u);if(!y)return;I.comments.push(y)}const w=ft(t,I,C);w&&i(w),T.current.add(u),j(y=>y+1)},[i,t,g,C]),Ve=s.useCallback((u,b)=>{b==="add"?we(u):b==="del"?H(u):b==="rep"?Oe(u):x(u)},[we,H,Oe,x]),mn=s.useMemo(()=>{const u=new Set;return g.deletions.forEach(b=>b.tokenIndices.forEach(I=>u.add(I))),u},[g.deletions]),hn=s.useMemo(()=>{const u=new Set;return g.replacements.forEach(b=>b.tokenIndices.forEach(I=>u.add(I))),u},[g.replacements]),bn=s.useMemo(()=>{const u=new Set;return g.comments.forEach(b=>b.tokenIndices.forEach(I=>u.add(I))),u},[g.comments]),vt=s.useMemo(()=>{const u=new Map;return g.additions.forEach(b=>{const I=u.get(b.afterTokenIndex)||[];I.push(b),u.set(b.afterTokenIndex,I)}),u},[g.additions]),wt=g.additions.length>0||g.deletions.length>0||g.replacements.length>0||g.comments.length>0;return r.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[r.jsxs("div",{className:"plan-anno-toolbar",children:[r.jsx("span",{style:{fontSize:"11px",color:"var(--text-secondary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},title:t,children:t.split("/").pop()||t}),d&&r.jsx("button",{className:"pane-btn",onClick:d,title:"Refresh current file",children:"↻"}),r.jsx("button",{className:"pane-btn",onClick:fe,disabled:!wt,title:"Send all annotations to Chat editor",style:wt?{color:"var(--accent-green)"}:{opacity:.4},children:"Send"}),r.jsxs("div",{ref:Fe,style:{position:"relative",flex:1,minWidth:0},children:[r.jsxs("div",{className:`plan-anno-dropdown-trigger${ce?" plan-anno-dropdown-trigger--active":""}`,onClick:()=>Le(u=>!u),title:S.total>0?`${S.total} annotations (${S.unsent} unsent)`:"No annotations",children:[r.jsx("span",{className:"plan-anno-dropdown-trigger__text",children:(()=>{const u=g.additions[0],b=g.deletions[0],I=g.replacements[0],w=g.comments[0],y=u?u.content:b?b.selectedText:I?I.content:w?w.content:"";return y?y.slice(0,40)+(y.length>40?"...":""):""})()}),r.jsx("span",{className:"plan-anno-dropdown-trigger__arrow",children:"▼"})]}),ce&&r.jsxs("div",{className:"plan-anno-dropdown",children:[S.unsent>0&&r.jsx("div",{className:"plan-anno-dropdown__header",children:r.jsxs("button",{className:"pane-btn",onClick:fe,style:{color:"var(--accent-blue)",fontSize:11},children:["Send All Unsent (",S.unsent,")"]})}),r.jsxs("div",{className:"plan-anno-dropdown__list",children:[g.additions.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--add",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-yellow)"},children:"+"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.content.slice(0,60),u.content.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"add"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"add"),title:"Delete",children:"×"})]},u.id)}),g.deletions.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--del",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-red)"},children:"−"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.selectedText.slice(0,60),u.selectedText.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"del"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"del"),title:"Delete",children:"×"})]},u.id)}),g.replacements.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--rep",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-blue)"},children:"⇄"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.content.slice(0,60),u.content.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"rep"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"rep"),title:"Delete",children:"×"})]},u.id)}),g.comments.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--com",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-green)"},children:"?"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.content.slice(0,60),u.content.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"com"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"com"),title:"Delete",children:"×"})]},u.id)}),S.total===0&&r.jsx("div",{className:"plan-anno-dropdown__empty",children:"No annotations"})]})]})]}),l&&r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:()=>{fe(),l()},title:"Send annotations & close file",children:"×"})]}),r.jsxs("div",{style:{display:"flex",flex:1,minHeight:0},children:[r.jsxs("div",{ref:te,className:`plan-anno-content md-preview${O!=null?" plan-anno-content--editing":""}`,style:{flex:1,overflow:"auto",padding:"8px 12px",position:"relative",fontSize:`${h}px`,minWidth:0},onMouseUp:xe,children:[!m&&r.jsx(_t,{index:-1,active:O===-1,additions:vt.get(-1),onOpen:()=>{k(-1),V("")},onSubmit:()=>ye(-1),onRemoveAddition:we,onEditAddition:Re,onSendSingle:i?u=>Se(u,"add"):void 0,isSent:u=>T.current.has(u),insertText:X,setInsertText:V,textareaRef:O===-1?K:void 0,expanded:f,alwaysShow:v.length===0,fontSize:h}),v.map((u,b)=>{const I=qr(u);return r.jsxs("div",{children:[r.jsx("div",{"data-token-index":b,id:D.get(b),className:mn.has(b)?"plan-block--deleted":hn.has(b)?"plan-block--replaced":bn.has(b)?"plan-block--commented":void 0,dangerouslySetInnerHTML:{__html:I}}),g.deletions.filter(w=>w.tokenIndices.includes(b)&&w.tokenIndices[0]===b).map(w=>r.jsx("div",{className:"plan-deletion-card",children:z===w.id?r.jsx("textarea",{ref:Y,className:"plan-annotation-textarea",value:G,onChange:y=>J(y.target.value),onKeyDown:y=>{if(y.key==="Enter"&&(y.ctrlKey||y.metaKey)){y.preventDefault();const Z=G.trim();Z?ee(w.id,Z):H(w.id),M(null)}y.key==="Escape"&&(y.preventDefault(),M(null))},onBlur:()=>{const y=G.trim();y?ee(w.id,y):H(w.id),M(null)},rows:We(G),style:{fontSize:`${h}px`,flex:1}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{flex:1,fontSize:`${h}px`,color:"var(--accent-red)",whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>{M(w.id),J(w.selectedText),requestAnimationFrame(()=>{const y=Y.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},title:"Double-click to edit",children:w.selectedText}),i&&(()=>{const y=T.current.has(w.id);return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!y&&Se(w.id,"del"),disabled:y,title:y?"Already sent":"Send to terminal",style:y?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>{M(w.id),J(w.selectedText),requestAnimationFrame(()=>{const y=Y.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},style:{color:"var(--accent-blue)"},title:"Edit deletion annotation",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>H(w.id),title:"Remove deletion",children:"×"})]})},w.id)),g.replacements.filter(w=>w.tokenIndices.includes(b)&&w.tokenIndices[0]===b).map(w=>r.jsx("div",{className:"plan-replace-card",children:le===w.id?r.jsx("textarea",{ref:Te,className:"plan-annotation-textarea",value:be,onChange:y=>Ce(y.target.value),onKeyDown:y=>{if(y.key==="Enter"&&(y.ctrlKey||y.metaKey)){y.preventDefault();const Z=be.trim();Z?Je(w.id,Z):Oe(w.id),ne(null)}y.key==="Escape"&&(y.preventDefault(),ne(null))},onBlur:()=>{const y=be.trim();y?Je(w.id,y):Oe(w.id),ne(null)},rows:We(be),style:{fontSize:`${h}px`,flex:1}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{color:"var(--accent-blue)",flexShrink:0},children:"⇄"}),r.jsxs("span",{style:{flex:1,fontSize:`${h}px`,whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>{ne(w.id),Ce(w.content),requestAnimationFrame(()=>{const y=Te.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},title:"Double-click to edit",children:[r.jsx("span",{style:{color:"var(--accent-red)",textDecoration:"line-through"},children:w.selectedText}),r.jsx("span",{style:{color:"var(--text-secondary)"},children:" → "}),r.jsx("span",{style:{color:"var(--accent-blue)"},children:w.content})]}),i&&(()=>{const y=T.current.has(w.id);return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!y&&Se(w.id,"rep"),disabled:y,title:y?"Already sent":"Send to terminal",style:y?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>{ne(w.id),Ce(w.content),requestAnimationFrame(()=>{const y=Te.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},style:{color:"var(--accent-blue)"},title:"Edit replacement",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Oe(w.id),title:"Remove replacement",children:"×"})]})},w.id)),g.comments.filter(w=>w.tokenIndices.includes(b)&&w.tokenIndices[0]===b).map(w=>r.jsx("div",{className:"plan-comment-card",children:Be===w.id?r.jsx("textarea",{ref:me,className:"plan-annotation-textarea",value:ge,onChange:y=>Ie(y.target.value),onKeyDown:y=>{if(y.key==="Enter"&&(y.ctrlKey||y.metaKey)){y.preventDefault();const Z=ge.trim();Z?E(w.id,Z):x(w.id),ve(null)}y.key==="Escape"&&(y.preventDefault(),ve(null))},onBlur:()=>{const y=ge.trim();y?E(w.id,y):x(w.id),ve(null)},rows:We(ge),style:{fontSize:`${h}px`,flex:1}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{color:"var(--accent-green)",flexShrink:0},children:"?"}),r.jsxs("span",{style:{flex:1,fontSize:`${h}px`,whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>{ve(w.id),Ie(w.content),requestAnimationFrame(()=>{const y=me.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},title:"Double-click to edit",children:[r.jsxs("span",{style:{color:"var(--text-secondary)",fontStyle:"italic"},children:['"',w.selectedText,'"']}),r.jsx("span",{style:{color:"var(--text-secondary)"},children:": "}),r.jsx("span",{style:{color:"var(--accent-green)"},children:w.content})]}),i&&(()=>{const y=T.current.has(w.id);return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!y&&Se(w.id,"com"),disabled:y,title:y?"Already sent":"Send to terminal",style:y?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>{ve(w.id),Ie(w.content),requestAnimationFrame(()=>{const y=me.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},style:{color:"var(--accent-blue)"},title:"Edit comment",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>x(w.id),title:"Remove comment",children:"×"})]})},w.id)),Q&&Q.tokenIndices[0]===b&&r.jsxs("div",{className:Q.type==="replace"?"plan-replace-card":"plan-comment-card",style:{padding:"4px 8px"},children:[r.jsx("span",{style:{color:Q.type==="replace"?"var(--accent-blue)":"var(--accent-green)",flexShrink:0},children:Q.type==="replace"?"⇄":"?"}),r.jsx("textarea",{ref:P,className:"plan-annotation-textarea",value:he,onChange:w=>N(w.target.value),onKeyDown:w=>{if(w.key==="Enter"&&(w.ctrlKey||w.metaKey)){w.preventDefault(),De();return}if(w.key==="Escape"){w.preventDefault(),De();return}},onBlur:De,placeholder:Q.type==="replace"?"Replace with... (Ctrl+Enter to save)":"Comment... (Ctrl+Enter to save)",rows:We(he),style:{fontSize:`${h}px`,flex:1}})]}),!m&&r.jsx(_t,{index:b,active:O===b,additions:vt.get(b),onOpen:()=>{k(b),V("")},onSubmit:()=>ye(b),onRemoveAddition:we,onEditAddition:Re,onSendSingle:i?w=>Se(w,"add"):void 0,isSent:w=>T.current.has(w),insertText:X,setInsertText:V,textareaRef:O===b?K:void 0,expanded:f,fontSize:h})]},b)}),!m&&q&&r.jsxs("div",{className:"plan-selection-float",style:{top:q.y,left:q.x},children:[r.jsx("button",{className:"plan-selection-float__delete",onMouseDown:u=>{u.preventDefault(),Ne()},title:"Delete selection",children:"−"}),r.jsx("button",{className:"plan-selection-float__replace",onMouseDown:u=>{u.preventDefault(),ze("replace")},title:"Replace selection",children:"⇄"}),r.jsx("button",{className:"plan-selection-float__comment",onMouseDown:u=>{u.preventDefault(),ze("comment")},title:"Comment on selection",children:"?"})]})]}),r.jsx(Hr,{headings:_,scrollRef:te})]})]})});function _t({index:n,active:e,additions:t,onOpen:o,onSubmit:a,onRemoveAddition:c,onEditAddition:i,onSendSingle:d,isSent:l,insertText:f,setInsertText:m,textareaRef:p,expanded:h,alwaysShow:v,fontSize:C=14}){const[_,D]=s.useState(null),[T,g]=s.useState(""),$=s.useRef(null),R=ht(),U=ht();s.useEffect(()=>{_&&(R.clearUndo(),requestAnimationFrame(()=>{const S=$.current;S&&(S.focus(),S.selectionStart=S.selectionEnd=S.value.length)}))},[_]),s.useEffect(()=>{e&&U.clearUndo()},[e]);const L=s.useCallback(S=>{g(O=>(R.pushUndo(O),S))},[R]),B=s.useCallback(S=>{U.pushUndo(f),m(S)},[f,m,U]),W=s.useCallback(S=>{D(S.id),g(S.content)},[]),F=s.useCallback(()=>{if(!_)return;const S=T.trim();S?i(_,S):c(_),D(null),g("")},[_,T,i,c]),j=s.useCallback(()=>{D(null),g("")},[]);return r.jsxs("div",{className:`plan-insert-zone${v?" plan-insert-zone--empty":""}`,"data-zone-index":n,children:[t==null?void 0:t.map(S=>r.jsx("div",{className:"plan-annotation-card",children:_===S.id?r.jsx("textarea",{ref:$,className:"plan-annotation-textarea",value:T,onChange:O=>L(O.target.value),onKeyDown:O=>{if(O.key==="Enter"&&(O.ctrlKey||O.metaKey)){O.preventDefault(),F();return}if(O.key==="Escape"){O.preventDefault(),j();return}if(O.key==="Tab"){bt(O,L);return}},onBlur:F,rows:We(T),style:{fontSize:`${C}px`,flex:1,...h?{minWidth:300}:void 0}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{flex:1,fontSize:`${C}px`,color:"var(--accent-yellow)",whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>W(S),title:"Double-click to edit",children:S.content}),d&&(()=>{const O=(l==null?void 0:l(S.id))??!1;return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!O&&d(S.id),disabled:O,title:O?"Already sent":"Send to terminal",style:O?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>W(S),style:{color:"var(--accent-blue)"},title:"Edit annotation",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>c(S.id),children:"×"})]})},S.id)),e?r.jsx("div",{className:"plan-annotation-card plan-annotation-card--editing",children:r.jsx("textarea",{ref:p,className:"plan-annotation-textarea",value:f,onChange:S=>B(S.target.value),onKeyDown:S=>{if(S.key==="Enter"&&(S.ctrlKey||S.metaKey)){S.preventDefault(),a();return}if(S.key==="Escape"){S.preventDefault(),a();return}if(S.key==="Tab"){bt(S,B);return}},placeholder:"Add annotation... (Ctrl+Enter or Esc to save)",rows:We(f),style:{fontSize:`${C}px`,...h?{minWidth:300}:void 0}})}):v&&!(t!=null&&t.length)?r.jsx("div",{className:"plan-empty-placeholder",onDoubleClick:o,title:"Double-click or Ctrl+Enter to edit",children:"Write down your plans here. Double-click or Ctrl+Enter to edit."}):r.jsx("button",{className:"plan-insert-btn",onClick:o,title:"Add annotation here",children:"+"})]})}async function ke(n,e,t){const o=t?`?path=${encodeURIComponent(t)}`:"",a=await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/files${o}`,{headers:ie(n)});if(!a.ok)throw new Error("Failed to list files");return a.json()}function Yr(n,e,t,o){return new Promise((a,c)=>{const i=new FormData;for(const l of t)i.append("files",l);const d=new XMLHttpRequest;d.open("POST",`${re}/api/sessions/${encodeURIComponent(e)}/upload`),d.setRequestHeader("Authorization",`Bearer ${n}`),d.upload.addEventListener("progress",l=>{l.lengthComputable&&o&&o(Math.round(l.loaded/l.total*100))}),d.addEventListener("load",()=>{d.status>=200&&d.status<300?a():c(new Error(`Upload failed: ${d.status}`))}),d.addEventListener("error",()=>c(new Error("Upload network error"))),d.addEventListener("abort",()=>c(new Error("Upload aborted"))),d.send(i)})}async function Gr(n,e){const t=await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/cwd`,{headers:ie(n)});if(!t.ok)throw new Error("Failed to fetch cwd");return(await t.json()).cwd}async function xt(n,e,t){const o=await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/touch`,{method:"POST",headers:{...ie(n),"Content-Type":"application/json"},body:JSON.stringify({name:t})});if(!o.ok)throw new Error("Failed to create file");return o.json()}async function an(n,e,t){const o=await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/mkdir`,{method:"POST",headers:{...ie(n),"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!o.ok)throw new Error("Failed to create directory");return o.json()}async function Xr(n,e,t){if(!(await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/rm`,{method:"DELETE",headers:{...ie(n),"Content-Type":"application/json"},body:JSON.stringify({path:t})})).ok)throw new Error("Failed to delete")}async function Zr(n,e){const t=await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/download-cwd`,{headers:ie(n)});if(!t.ok)throw new Error("Download failed");const o=await t.blob(),a=URL.createObjectURL(o),c=document.createElement("a");c.href=a;const i=t.headers.get("Content-Disposition"),d=i==null?void 0:i.match(/filename="(.+)"/);c.download=d?decodeURIComponent(d[1]):"cwd.tar.gz",document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(a)}async function Qr(n,e,t){const o=await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/download?path=${encodeURIComponent(t)}`,{headers:ie(n)});if(!o.ok)throw new Error("Download failed");const a=await o.blob(),c=URL.createObjectURL(a),i=document.createElement("a");i.href=c,i.download=t.split("/").pop()||"download",document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(c)}function ln(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:n<1024*1024*1024?`${(n/(1024*1024)).toFixed(1)} MB`:`${(n/(1024*1024*1024)).toFixed(1)} GB`}function eo(n,e){if(e==="directory")return"📁";const t=n.slice(n.lastIndexOf(".")).toLowerCase();return t===".pdf"?"📕":t===".html"||t===".htm"?"🌐":t===".md"?"📝":"📄"}function cn(n){const e=new Date(n*1e3),t=o=>String(o).padStart(2,"0");return`${t(e.getMonth()+1)}-${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}`}function to({sessionId:n,token:e,planDir:t,selectedFile:o,onSelectFile:a,onCreateFile:c,onDeleteFile:i}){const[d,l]=s.useState([]),[f,m]=s.useState(!0),[p,h]=s.useState(""),[v,C]=s.useState(!1),_=s.useRef(null),[D,T]=s.useState(t),g=s.useCallback(async()=>{if(!(!e||!D)){m(!0);try{const X=(await ke(e,n,D)).files.filter(V=>V.type==="file"&&V.name.toLowerCase().endsWith(".md")||V.type==="directory").sort((V,K)=>{const z=V.type==="file"&&V.name===".index.md",M=K.type==="file"&&K.name===".index.md";return z&&!M?-1:!z&&M?1:V.type==="directory"&&K.type!=="directory"?-1:V.type!=="directory"&&K.type==="directory"?1:V.name.localeCompare(K.name)});l(X)}catch{l([])}finally{m(!1)}}},[e,n,D]);s.useEffect(()=>{g()},[g]),s.useEffect(()=>{const k=setInterval(g,5e3);return()=>clearInterval(k)},[g]);const $=s.useCallback(()=>{const k=t.substring(0,t.lastIndexOf("/")+1);return D.startsWith(k)?D.substring(k.length):D},[t,D]),R=s.useCallback(async()=>{const k=p.trim();if(!k)return;const X=k.endsWith(".md")?k:`${k}.md`;C(!0);try{const V=await xt(e,n,`${$()}/${X}`);V.ok&&(h(""),await g(),c(V.path))}catch{}finally{C(!1)}},[p,e,n,$,g,c]),U=s.useCallback(async()=>{const k=p.trim().replace(/\/+$/,"");if(k){C(!0);try{await an(e,n,`${$()}/${k}`),h(""),await g()}catch{}finally{C(!1)}}},[p,e,n,$,g]),L=s.useCallback(async k=>{const X=`${D}/${k.name}`,V=k.type==="directory"?`folder "${k.name}" and all its contents`:`"${k.name}"`;if(window.confirm(`Delete ${V}?`))try{await Xr(e,n,X),i==null||i(X),await g()}catch{}},[e,n,D,g,i]),B=s.useCallback(k=>{T(X=>`${X}/${k}`)},[]),W=s.useCallback(()=>{D!==t&&T(k=>k.substring(0,k.lastIndexOf("/")))},[D,t]),F=t.split("/").pop()||"TASK",j=(()=>{const k=t.split("/");return k.length>=2?k[k.length-2]+"/":""})(),S=D===t?j+F+"/":j+F+"/"+D.substring(t.length+1)+"/",O=o?o.split("/").pop():null;return r.jsxs("div",{className:"plan-file-browser",children:[r.jsxs("div",{className:"plan-file-browser__header",children:[r.jsx("span",{className:"plan-file-browser__title",title:S,children:S}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:g,title:"Refresh file list",style:{fontSize:12},children:"↻"})]}),r.jsxs("div",{className:"plan-file-browser__create",children:[r.jsx("input",{ref:_,className:"plan-file-browser__input",value:p,onChange:k=>h(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),R())},placeholder:"name",disabled:v}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:R,disabled:v||!p.trim(),title:"Create new .md file",style:p.trim()?{color:"var(--accent-green)",fontWeight:700,fontSize:14}:{opacity:.4,fontWeight:700,fontSize:14},children:"+"}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:U,disabled:v||!p.trim(),title:"Create new folder",style:p.trim()?{color:"var(--accent-blue)"}:{opacity:.4},children:"📁"})]}),r.jsxs("div",{className:"plan-file-browser__list",children:[f&&d.length===0&&r.jsx("div",{className:"plan-file-browser__status",children:"Loading..."}),!f&&d.length===0&&r.jsx("div",{className:"plan-file-browser__status",children:"No .md files"}),D!==t&&r.jsxs("div",{className:"plan-file-browser__item",onClick:W,title:"Go up to parent directory",style:{cursor:"pointer"},children:[r.jsx("span",{className:"plan-file-browser__icon",style:{color:"var(--accent-blue)"},children:"←"}),r.jsx("span",{className:"plan-file-browser__name",style:{color:"var(--accent-blue)"},children:".."})]}),d.map(k=>{const X=`${D}/${k.name}`,V=k.type==="file"&&k.name===O,K=k.type==="directory";return r.jsxs("div",{className:`plan-file-browser__item${V?" plan-file-browser__item--active":""}`,onClick:()=>K?B(k.name):a(X),title:K?`Open folder ${k.name}`:k.name,style:{cursor:"pointer"},children:[r.jsx("span",{className:"plan-file-browser__icon",children:K?"📁":k.name===".index.md"?"🔒":"□"}),r.jsxs("span",{className:"plan-file-browser__name",children:[k.name,K?"/":""]}),!K&&r.jsx("span",{className:"plan-file-browser__size",children:ln(k.size)}),k.name!==".index.md"&&r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm plan-file-browser__delete",onClick:z=>{z.stopPropagation(),L(k)},title:`Delete ${k.name}`,children:"×"})]},k.name)})]})]})}const pt={status:"idle",mode:"lines",lines:[],content:"",buffer:null,totalSize:0,receivedBytes:0,mtime:0,error:null},no=200;function ro(){const[n,e]=s.useState(pt),t=s.useRef("lines"),o=s.useRef([]),a=s.useRef(""),c=s.useRef(""),i=s.useRef([]),d=s.useRef(0),l=s.useRef(0),f=s.useRef(null),m=s.useRef(null),p=s.useCallback(()=>{const T=t.current;e(g=>({...g,receivedBytes:d.current,...T==="lines"?{lines:[...o.current]}:{},...T==="content"?{content:c.current}:{}}))},[]),h=s.useCallback(()=>{f.current===null&&(f.current=window.setTimeout(()=>{f.current=null,p()},no))},[p]),v=s.useCallback(T=>{t.current=T,o.current=[],a.current="",c.current="",i.current=[],d.current=0,l.current=0,m.current=new TextDecoder,f.current!==null&&(clearTimeout(f.current),f.current=null),e({...pt,mode:T,status:"streaming"})},[]),C=s.useCallback(T=>{d.current+=T.length;const g=t.current;if(g==="lines"){const R=m.current.decode(T,{stream:!0}).split(`
|
|
29
|
-
`);R[0]=a.current+R[0],a.current=R.pop(),R.length>0&&o.current.push(...R)}else if(g==="content"){const $=m.current.decode(T,{stream:!0});c.current+=$}else i.current.push(new Uint8Array(T));h()},[h]),_=s.useCallback(T=>{switch(T.type){case"file-stream-start":l.current=T.size,e(g=>({...g,totalSize:T.size,mtime:T.mtime}));break;case"file-stream-end":{f.current!==null&&(clearTimeout(f.current),f.current=null);const g=t.current;let $=o.current,R=c.current,U=null;if(g==="lines"){const L=m.current.decode(),B=a.current+L;B&&($=[...$,B],o.current=$),a.current=""}else if(g==="content"){const L=m.current.decode();R=c.current+L,c.current=R}else{const L=i.current.reduce((W,F)=>W+F.length,0);U=new Uint8Array(L);let B=0;for(const W of i.current)U.set(W,B),B+=W.length;i.current=[]}e({status:"complete",mode:g,lines:g==="lines"?[...$]:[],content:g==="content"?R:"",buffer:g==="binary"?U:null,totalSize:l.current,receivedBytes:d.current,mtime:0,error:null});break}case"file-stream-error":f.current!==null&&(clearTimeout(f.current),f.current=null),e(g=>({...g,status:"error",error:T.error}));break}},[]),D=s.useCallback(()=>{f.current!==null&&(clearTimeout(f.current),f.current=null),o.current=[],a.current="",c.current="",i.current=[],d.current=0,l.current=0,m.current=null,e(pt)},[]);return{state:n,startStream:v,handleChunk:C,handleControl:_,reset:D}}function Ot({label:n,percent:e}){return r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:8},children:[r.jsx("span",{style:{color:"var(--text-secondary)",fontSize:13},children:n}),e!=null&&r.jsxs("div",{style:{width:120,display:"flex",alignItems:"center",gap:6},children:[r.jsx("div",{style:{flex:1,height:4,backgroundColor:"var(--border)",borderRadius:2,overflow:"hidden"},children:r.jsx("div",{style:{height:"100%",width:`${e}%`,backgroundColor:"var(--accent-blue)",transition:"width 0.2s"}})}),r.jsxs("span",{style:{fontSize:10,color:"var(--text-secondary)",whiteSpace:"nowrap"},children:[e,"%"]})]})]})}function oo({sessionId:n,token:e,connected:t,onRequestFileStream:o,onForwardToChat:a,onSendToTerminal:c}){const i=ro(),[d,l]=s.useState(!1),f=s.useRef(""),[m,p]=s.useState(null),[h,v]=s.useState(null),[C,_]=s.useState(""),[D,T]=s.useState(!1),g=s.useRef(new Map),$=s.useRef(null),R=s.useRef(null);s.useEffect(()=>{R.current=null;let z=!1;return T(!0),(async()=>{try{const M=await ke(e,n);if(z)return;if(M.files.find(J=>J.name==="TASK"&&J.type==="directory")){const J=M.cwd+"/TASK",Y=await ke(e,n,J);if(z)return;const le=Y.files.find(ne=>ne.name===".index.md");if(le)p(J),v(J+"/"+le.name);else try{const ne=await xt(e,n,"TASK/.index.md");if(z)return;p(J),ne.ok&&v(ne.path)}catch{p(J)}}else try{const J=await an(e,n,"TASK");if(z)return;p(J.path);const Y=await xt(e,n,"TASK/.index.md");if(z)return;Y.ok&&v(Y.path)}catch{p(null),v(null)}}catch{p(null)}finally{z||T(!1)}try{const M=await ke(e,n);if(z)return;const G=M.home||"";if(f.current=M.cwd,G){const J=`${G}/.claude/commands`;try{const Y=await ke(e,n,J);if(z)return;Y.files.some(ne=>ne.name==="aicli-task-review.md")||l(!0)}catch{z||l(!0)}}}catch{}})(),()=>{z=!0}},[n,e]),s.useEffect(()=>(pr(n,i.handleChunk,i.handleControl),()=>mr(n)),[n,i.handleChunk,i.handleControl]),s.useEffect(()=>{!h||!t||R.current===h&&C||(R.current=h,i.reset(),i.startStream("content"),o==null||o(h))},[h,t]),s.useEffect(()=>{i.state.status==="complete"&&h&&(_(i.state.content),g.current.set(h,i.state.content))},[i.state.status,i.state.content,h]);const U=s.useRef(new Map),L=s.useCallback(()=>{var M,G;if(!h)return;const z=((G=(M=$.current)==null?void 0:M.getScrollTop)==null?void 0:G.call(M))??0;z>0&&U.current.set(h,z)},[h]);s.useEffect(()=>{if(!h||!C)return;const z=U.current.get(h);z!=null&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{var M,G;(G=(M=$.current)==null?void 0:M.setScrollTop)==null||G.call(M,z)})})},[h,C]);const B=s.useCallback(z=>{z!==h&&(L(),h&&C&&g.current.set(h,C),v(z),_(""),R.current=null)},[h,C,L]),W=s.useCallback(z=>{h&&(h===z||h.startsWith(z+"/"))&&(v(null),_(""),R.current=null),g.current.delete(z)},[h]),F=s.useCallback(z=>{v(z),_(""),R.current=null},[]),j=s.useCallback(z=>{z&&(a==null||a(z))},[a]),S=s.useCallback(()=>{L(),h&&C&&g.current.set(h,C),v(null),_(""),R.current=null},[h,C,L]),O=s.useCallback(()=>{!h||!t||(R.current=null,_(""),i.reset(),i.startStream("content"),o==null||o(h),R.current=h)},[h,t,i,o]),[k,X]=s.useState(()=>{const z=localStorage.getItem(`plan-fb-width-${n}`);if(z){const M=Number(z);if(Number.isFinite(M)&&M>=60&&M<=300)return M}return 130}),V=s.useRef(k);if(k!==V.current){V.current=k;try{localStorage.setItem(`plan-fb-width-${n}`,String(Math.round(k)))}catch{}}const K=s.useCallback(z=>{z.preventDefault();const M=z.clientX,G=k;document.body.classList.add("resizing-panes");const J=le=>{const ne=le.clientX-M;X(Math.min(300,Math.max(60,G+ne)))},Y=()=>{document.body.classList.remove("resizing-panes"),document.removeEventListener("mousemove",J),document.removeEventListener("mouseup",Y)};document.addEventListener("mousemove",J),document.addEventListener("mouseup",Y)},[k]);return r.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[d&&r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 10px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",fontSize:12,flexShrink:0},children:[r.jsx("span",{style:{color:"var(--accent-yellow)",flex:1},children:"/aicli-task-review command not installed"}),r.jsx("button",{className:"pane-btn",style:{color:"var(--accent-green)",fontSize:11},onClick:()=>{const z=f.current;z&&c&&c(`mkdir -p ~/.claude/commands && cp ${z}/.commands/*.md ~/.claude/commands/`),l(!1)},children:"Install"}),r.jsx("button",{className:"pane-btn",style:{fontSize:11},onClick:()=>l(!1),children:"×"})]}),r.jsxs("div",{className:"plan-overlay-body",children:[m&&r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{width:k,flexShrink:0,overflow:"hidden"},children:r.jsx(to,{sessionId:n,token:e,planDir:m,selectedFile:h,onSelectFile:B,onCreateFile:F,onDeleteFile:W})}),r.jsx("div",{onMouseDown:K,style:{width:2,flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:z=>{z.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:z=>{z.currentTarget.style.backgroundColor="var(--border)"}})]}),r.jsx("div",{className:"plan-overlay-center",children:D?r.jsx(Ot,{label:"Loading TASK/..."}):h&&!C&&(i.state.status==="streaming"||i.state.status==="idle")?r.jsx(Ot,{label:`Loading ${h.split("/").pop()}...`,percent:i.state.totalSize>0?Math.round(i.state.receivedBytes/i.state.totalSize*100):void 0}):h?r.jsx(Vr,{ref:$,markdown:C,filePath:h,sessionId:n,token:e,onExecute:j,onSend:c,onRefresh:O,onClose:S,readOnly:h.endsWith("/.index.md")}):r.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:8},children:r.jsx("span",{style:{color:"var(--text-secondary)",fontSize:13,fontStyle:"italic"},children:"Select a file from the left panel"})})})]})]})}async function so(n,e){try{const t=await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/draft`,{headers:ie(n)});return t.ok?(await t.json()).content??"":""}catch{return""}}async function Ft(n,e,t){try{await fetch(`${re}/api/sessions/${encodeURIComponent(e)}/draft`,{method:"PUT",headers:{...ie(n),"Content-Type":"application/json"},body:JSON.stringify({content:t})})}catch{}}const yt="chat-history",Pt=50;function dn(){try{const n=localStorage.getItem(yt);return n?JSON.parse(n):[]}catch{return[]}}function ao(n){const t=dn().filter(o=>o.text!==n);t.unshift({text:n,ts:Date.now()}),t.length>Pt&&(t.length=Pt),localStorage.setItem(yt,JSON.stringify(t))}const Bt=[{cmd:"/history",desc:"Browse sent message history"},{cmd:"/plan",desc:"Enter plan mode"},{cmd:"/help",desc:"Get help"},{cmd:"/compact",desc:"Compact conversation"},{cmd:"/clear",desc:"Clear conversation"},{cmd:"/model",desc:"Switch model"},{cmd:"/cost",desc:"Show token usage"},{cmd:"/status",desc:"Show status"},{cmd:"/init",desc:"Initialize project CLAUDE.md"},{cmd:"/memory",desc:"Edit memory files"},{cmd:"/review",desc:"Review code"},{cmd:"/bug",desc:"Report a bug"},{cmd:"/login",desc:"Login to Anthropic"},{cmd:"/doctor",desc:"Run diagnostics"},{cmd:"/permissions",desc:"Manage permissions"},{cmd:"/mcp",desc:"MCP server management"},{cmd:"/terminal-setup",desc:"Configure terminal"},{cmd:"/vim",desc:"Toggle vim mode"},{cmd:"/oh-my-claudecode:autopilot",desc:"Full autonomous execution"},{cmd:"/oh-my-claudecode:ralph",desc:"Persistence loop until done"},{cmd:"/oh-my-claudecode:ultrawork",desc:"Max parallel execution"},{cmd:"/oh-my-claudecode:ecomode",desc:"Token-efficient execution"},{cmd:"/oh-my-claudecode:plan",desc:"Strategic planning session"},{cmd:"/oh-my-claudecode:ralplan",desc:"Iterative planning consensus"},{cmd:"/oh-my-claudecode:ultrapilot",desc:"Parallel autopilot (3-5x faster)"},{cmd:"/oh-my-claudecode:analyze",desc:"Deep analysis/investigation"},{cmd:"/oh-my-claudecode:deepsearch",desc:"Thorough codebase search"},{cmd:"/oh-my-claudecode:deepinit",desc:"Generate AGENTS.md hierarchy"},{cmd:"/oh-my-claudecode:ultraqa",desc:"QA cycling: test/fix/repeat"},{cmd:"/oh-my-claudecode:tdd",desc:"Test-driven development"},{cmd:"/oh-my-claudecode:code-review",desc:"Comprehensive code review"},{cmd:"/oh-my-claudecode:security-review",desc:"Security vulnerability review"},{cmd:"/oh-my-claudecode:build-fix",desc:"Fix build/TypeScript errors"},{cmd:"/oh-my-claudecode:research",desc:"Parallel research orchestration"},{cmd:"/oh-my-claudecode:swarm",desc:"N coordinated agents"},{cmd:"/oh-my-claudecode:pipeline",desc:"Sequential agent chaining"},{cmd:"/oh-my-claudecode:learner",desc:"Extract skill from session"},{cmd:"/oh-my-claudecode:note",desc:"Save notes to notepad"},{cmd:"/oh-my-claudecode:cancel",desc:"Cancel active OMC mode"},{cmd:"/oh-my-claudecode:help",desc:"OMC usage guide"},{cmd:"/oh-my-claudecode:doctor",desc:"Diagnose OMC issues"},{cmd:"/oh-my-claudecode:omc-setup",desc:"One-time OMC setup"},{cmd:"/oh-my-claudecode:hud",desc:"Configure HUD statusline"},{cmd:"/oh-my-claudecode:release",desc:"Automated release workflow"},{cmd:"/oh-my-claudecode:ralph-init",desc:"Initialize PRD for ralph"},{cmd:"/oh-my-claudecode:review",desc:"Review plan with Critic"},{cmd:"/oh-my-claudecode:git-master",desc:"Git expert for commits"},{cmd:"/oh-my-claudecode:mcp-setup",desc:"Configure MCP servers"},{cmd:"/oh-my-claudecode:skill",desc:"Manage local skills"},{cmd:"/oh-my-claudecode:writer-memory",desc:"Writer memory system"},{cmd:"/oh-my-claudecode:psm",desc:"Project session manager"},{cmd:"/oh-my-claudecode:trace",desc:"Agent flow trace timeline"},{cmd:"/plan-analyzer",desc:"Task complexity grading & token routing"}],io=s.forwardRef(function({onSend:e,onContentChange:t,sessionId:o,token:a},c){const i=A(x=>x.fontSize),[d,l]=s.useState(""),f=s.useRef(null),m=s.useRef(void 0),p=s.useRef(!1),h=s.useRef(!1),{pushUndo:v,popUndo:C}=ht(),_=s.useRef(d);_.current=d;const D=s.useCallback(()=>v(_.current),[v]),[T,g]=s.useState(!1),[$,R]=s.useState(""),[U,L]=s.useState(0),[B,W]=s.useState(!1),[F,j]=s.useState([]),[S,O]=s.useState(0),[k,X]=s.useState(""),V=s.useRef(null),K=s.useMemo(()=>{if(!k)return F;const x=k.toLowerCase();return F.filter(E=>E.text.toLowerCase().includes(x))},[F,k]),[z,M]=s.useState(!1),[G,J]=s.useState(""),[Y,le]=s.useState(""),[ne,be]=s.useState(0),[Ce,Te]=s.useState([]),[Be,ve]=s.useState(!1),ge=s.useRef(""),Ie=s.useRef(null),me=s.useMemo(()=>{if(!$)return Bt;const x=$.toLowerCase();return Bt.filter(E=>E.cmd.toLowerCase().includes(x)||E.desc.toLowerCase().includes(x))},[$]),Q=s.useMemo(()=>{let x=Ce;if(G){const E=G.toLowerCase();x=x.filter(H=>H.name.toLowerCase().includes(E))}return[...x].sort((E,H)=>E.type==="directory"&&H.type!=="directory"?-1:E.type!=="directory"&&H.type==="directory"?1:E.name.localeCompare(H.name))},[Ce,G]),Ae=A(x=>x.latency),he=`chat-draft-${o}`,N=s.useRef(!1),P=s.useRef(void 0);s.useEffect(()=>{try{const E=localStorage.getItem(he);E&&!h.current&&l(E)}catch{}let x=!1;return so(a,o).then(E=>{if(x||h.current){p.current=!0;return}if(E){l(E);try{localStorage.setItem(he,E)}catch{}}p.current=!0}).catch(()=>{p.current=!0}),()=>{x=!0}},[a,o,he]),s.useEffect(()=>{if(!p.current)return;m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{try{localStorage.setItem(he,d)}catch{}},50),P.current&&clearTimeout(P.current);const x=Math.max(200,(Ae??30)*3);return P.current=setTimeout(()=>{N.current||(N.current=!0,Ft(a,o,d).catch(()=>{}).finally(()=>{N.current=!1}))},x),()=>{m.current&&clearTimeout(m.current),P.current&&clearTimeout(P.current)}},[d,a,o,Ae,he]),s.useEffect(()=>{var x;(x=f.current)==null||x.focus()},[]),s.useEffect(()=>{if(!z)return;let x=!1;return ve(!0),(async()=>{try{if(Y){if(!ge.current){const ee=await ke(a,o);if(x)return;ge.current=ee.cwd}const E=`${ge.current}/${Y.replace(/\/$/,"")}`,H=await ke(a,o,E);if(x)return;Te(H.files)}else{const E=await ke(a,o);if(x)return;ge.current=E.cwd,Te(E.files)}ve(!1)}catch{if(x)return;Te([]),ve(!1)}})(),()=>{x=!0}},[z,Y,a,o]),s.useEffect(()=>{if(!z||!Ie.current)return;const x=Ie.current.querySelector(".file-item--active");x==null||x.scrollIntoView({block:"nearest"})},[ne,z]);const q=s.useCallback(()=>{const x=_.current.trim();if(x){ao(x),e(x),l("");try{localStorage.removeItem(he)}catch{}Ft(a,o,"").catch(()=>{})}},[e,a,o,he]),ae=s.useCallback(x=>{D(),l(x),h.current=!0},[D]),te=s.useCallback(x=>{const E=f.current;D();const H=_.current;if(E){const ee=E.selectionStart,oe=E.selectionEnd,xe=H.slice(0,ee)+x+H.slice(oe);l(xe);const se=ee+x.length;requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=se,E.focus()})}else l(H+x)},[D]);s.useImperativeHandle(c,()=>({send:q,fillContent:ae,insertAtCursor:te}),[q,ae,te]),s.useEffect(()=>{t==null||t(d.trim().length>0)},[d,t]);const ye=s.useCallback(()=>{const x=f.current;if(!x)return;const{selectionStart:E,selectionEnd:H}=x;if(E!==H){const ee=x.value.substring(E,H);ee&&navigator.clipboard.writeText(ee).catch(()=>{})}},[]),we=s.useCallback(()=>{const x=dn();g(!1),R("");const E=f.current;if(E){const H=E.selectionStart,ee=d.slice(0,H),oe=d.slice(H),xe=ee.match(/(?:^|\s)(\/history)\s*$/);if(xe){const se=ee.length-xe[1].length;l(d.slice(0,se)+oe)}}x.length!==0&&(j(x),O(0),X(""),W(!0))},[d]),Re=s.useCallback(x=>{D(),l(x.text),W(!1),requestAnimationFrame(()=>{const E=f.current;E&&(E.selectionStart=E.selectionEnd=x.text.length,E.focus())})},[D]),Ne=s.useCallback(x=>{const E=K[x];if(!E)return;const H=F.filter(oe=>oe.ts!==E.ts||oe.text!==E.text);j(H),localStorage.setItem(yt,JSON.stringify(H));const ee=k?H.filter(oe=>oe.text.toLowerCase().includes(k.toLowerCase())):H;S>=ee.length&&O(Math.max(0,ee.length-1))},[K,F,S,k]);s.useEffect(()=>{if(!B||!V.current)return;const x=V.current.querySelector(".history-item--active");x==null||x.scrollIntoView({block:"nearest"})},[S,B]);const ze=s.useCallback(x=>{if(x==="/history"){we();return}const E=f.current;if(!E)return;D();const H=E.selectionStart,ee=d.slice(0,H),oe=d.slice(H),se=ee.lastIndexOf(`
|
|
30
|
-
`)+1,fe=ee.slice(
|
|
31
|
-
`),se=ee.slice(oe+1).match(/(?:^|\s)\/([a-zA-Z:-]*)$/);if(se)g(!0),R(se[1]),L(0),M(!1);else{g(!1);const de=ee.match(/@([a-zA-Z0-9_.\-/]*)$/);if(de){const fe=de[1],ce=fe.lastIndexOf("/"),Le=ce>=0?fe.slice(0,ce+1):"",Fe=ce>=0?fe.slice(ce+1):fe;J(Fe),be(0),le(Le),M(!0)}else M(!1)}},[B]),Je=s.useCallback(x=>{if(T&&me.length>0){if(x.key==="ArrowDown"){x.preventDefault(),L(E=>(E+1)%me.length);return}if(x.key==="ArrowUp"){x.preventDefault(),L(E=>(E-1+me.length)%me.length);return}if(x.key==="Enter"||x.key==="Tab"){x.preventDefault(),ze(me[U].cmd);return}if(x.key==="Escape"){x.preventDefault(),g(!1);return}}if(z&&Q.length>0){if(x.key==="ArrowDown"){x.preventDefault(),be(E=>(E+1)%Q.length);return}if(x.key==="ArrowUp"){x.preventDefault(),be(E=>(E-1+Q.length)%Q.length);return}if(x.key==="Tab"||x.key==="Enter"){x.preventDefault(),De(Q[ne]);return}if(x.key==="Escape"){x.preventDefault(),M(!1);return}}if(B&&K.length>0){if(x.key==="ArrowDown"){x.preventDefault(),O(E=>(E+1)%K.length);return}if(x.key==="ArrowUp"){x.preventDefault(),O(E=>(E-1+K.length)%K.length);return}if(x.key==="Enter"){x.preventDefault(),Re(K[S]);return}if(x.key==="Delete"||x.key==="Backspace"&&(x.ctrlKey||x.metaKey)){x.preventDefault(),Ne(S);return}if(x.key==="Escape"){x.preventDefault(),W(!1);return}}if(x.key==="Tab"){bt(x,l,v);return}x.key==="Enter"&&(x.ctrlKey||x.metaKey)&&(x.preventDefault(),q())},[q,T,me,U,ze,z,Q,ne,De,v,C,B,K,S,Re,Ne]);return r.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[T&&me.length>0&&r.jsx("div",{className:"slash-dropdown",children:me.map((x,E)=>r.jsxs("div",{className:`slash-item${E===U?" slash-item--active":""}`,onMouseDown:H=>{H.preventDefault(),ze(x.cmd)},onMouseEnter:()=>L(E),children:[r.jsx("span",{className:"slash-cmd",children:x.cmd}),r.jsx("span",{className:"slash-desc",children:x.desc})]},x.cmd))}),z&&(Be||Q.length>0)&&r.jsx("div",{className:"file-dropdown",ref:Ie,children:Be?r.jsx("div",{className:"file-item file-loading",children:"Loading..."}):Q.map((x,E)=>r.jsxs("div",{className:`file-item${E===ne?" file-item--active":""}`,onMouseDown:H=>{H.preventDefault(),De(x)},onMouseEnter:()=>be(E),children:[r.jsx("span",{className:"file-icon",children:x.type==="directory"?"📁":"📄"}),r.jsx("span",{className:"file-name",children:x.name})]},x.name))}),B&&r.jsx("div",{className:"history-dropdown",ref:V,children:K.length===0?r.jsx("div",{className:"history-item history-empty",children:"No history yet"}):K.map((x,E)=>r.jsxs("div",{className:`history-item${E===S?" history-item--active":""}`,onMouseDown:H=>{H.preventDefault(),Re(x)},onMouseEnter:()=>O(E),children:[r.jsx("span",{className:"history-text",children:x.text.length>120?x.text.slice(0,120)+"...":x.text}),r.jsx("span",{className:"history-time",children:new Date(x.ts).toLocaleString()}),r.jsx("button",{className:"history-delete",onMouseDown:H=>{H.preventDefault(),H.stopPropagation(),Ne(E)},title:"Delete (Del key)",children:"×"})]},`${x.ts}-${E}`))}),r.jsx("textarea",{ref:f,className:"md-editor-textarea",value:d,onChange:Oe,onKeyDown:Je,onMouseUp:ye,placeholder:"Type / for commands, @ for files, Ctrl+Enter to send",spellCheck:!1,style:{flex:1,fontSize:`${i}px`}})]})}),lo=600,Ue=typeof window<"u"?window.matchMedia(`(max-width: ${lo-1}px)`):null;function co(){const[n,e]=s.useState(()=>(Ue==null?void 0:Ue.matches)??!1);return s.useEffect(()=>{if(!Ue)return;const t=o=>e(o.matches);return Ue.addEventListener("change",t),()=>Ue.removeEventListener("change",t)},[]),n}const uo=s.memo(function({terminal:e}){const t=co(),o=A(N=>N.splitTerminal),a=A(N=>N.token),c=A(N=>N.toggleChat),i=A(N=>N.togglePlan),{chatOpen:d,planOpen:l}=e.panels,f=s.useCallback(async N=>{let P;if(a)try{P=await Gr(a,e.id)}catch{}o(e.id,N,P)},[a,e.id,o]),m=s.useRef(null),p=s.useRef(null),h=s.useRef(null),[v,C]=s.useState(!1),[_,D]=s.useState(0),[T,g]=s.useState(!1),[$,R]=s.useState(!1),[U,L]=s.useState(!1),[B,W]=s.useState([]),[F,j]=s.useState(""),[S,O]=s.useState([]),[k,X]=s.useState(!1),V=s.useRef(null),K=s.useRef(null),z=s.useRef(null),[M,G]=s.useState(()=>{const N=localStorage.getItem(`plan-width-${e.id}`);if(N){const P=Number(N);if(Number.isFinite(P)&&P>=20&&P<=80)return P}return 50}),J=s.useRef(M);if(M!==J.current){J.current=M;try{localStorage.setItem(`plan-width-${e.id}`,String(Math.round(M)))}catch{}}const[Y,le]=s.useState(()=>{const N=localStorage.getItem(`doc-height-${e.id}`);if(N){const P=Number(N);if(Number.isFinite(P)&&P>=15&&P<=60)return P}return 35}),ne=s.useRef(Y);if(Y!==ne.current){ne.current=Y;try{localStorage.setItem(`doc-height-${e.id}`,String(Math.round(Y)))}catch{}}const be=async N=>{const P=N.target.files;if(!(!P||P.length===0||!a)){C(!0),D(0);try{await Yr(a,e.id,P,q=>{D(q)})}catch(q){alert(`Upload failed: ${q instanceof Error?q.message:"Unknown error"}`)}finally{C(!1),D(0),m.current&&(m.current.value="")}}},Ce=s.useRef(void 0),Te=s.useCallback(N=>{if(p.current){const P=N.replace(/\r?\n/g," ").trimEnd();p.current.sendInput(P),Ce.current=window.setTimeout(()=>{var q;return(q=p.current)==null?void 0:q.sendInput("\r")},50)}},[]);s.useEffect(()=>()=>{Ce.current&&clearTimeout(Ce.current)},[]);const Be=s.useCallback(async()=>{if(a){X(!0),L(!0);try{const N=await ke(a,e.id);j(N.cwd),W(N.files),O([])}catch{L(!1)}finally{X(!1)}}},[a,e.id]),ve=s.useCallback(async N=>{if(a){X(!0);try{const P=await ke(a,e.id,N);O(q=>[...q,F]),j(N),W(P.files)}catch{}finally{X(!1)}}},[a,e.id,F]),ge=s.useCallback(async()=>{if(!a||S.length===0)return;const N=S[S.length-1];X(!0);try{const P=await ke(a,e.id,N);O(q=>q.slice(0,-1)),j(N),W(P.files)}catch{}finally{X(!1)}},[a,e.id,S]),Ie=s.useCallback(async N=>{if(a)try{await Qr(a,e.id,N)}catch(P){alert(`Download failed: ${P instanceof Error?P.message:"Unknown error"}`)}},[a,e.id]);s.useEffect(()=>{if(!U)return;const N=ae=>{ae.key==="Escape"&&L(!1)},P=ae=>{V.current&&!V.current.contains(ae.target)&&L(!1)};document.addEventListener("keydown",N);const q=setTimeout(()=>document.addEventListener("mousedown",P),50);return()=>{document.removeEventListener("keydown",N),document.removeEventListener("mousedown",P),clearTimeout(q)}},[U]);const me=s.useCallback(N=>{if(p.current){const P=N.replace(/\r?\n/g," ").trimEnd();p.current.sendInput(P),setTimeout(()=>{var q;return(q=p.current)==null?void 0:q.sendInput("\r")},50)}},[]),Q=s.useCallback(N=>{N&&h.current&&h.current.fillContent(N)},[]),Ae=s.useCallback(N=>{N.preventDefault();const P=K.current;if(!P)return;const q=P.getBoundingClientRect(),ae=q.height-24;document.body.classList.add("resizing-panes-v");const te=we=>{const Ne=(we.clientY-q.top-24)/ae*100,ze=Math.min(85,Math.max(40,Ne));le(100-ze)},ye=()=>{document.body.classList.remove("resizing-panes-v"),document.removeEventListener("mousemove",te),document.removeEventListener("mouseup",ye)};document.addEventListener("mousemove",te),document.addEventListener("mouseup",ye)},[]),he=s.useCallback(N=>{N.preventDefault();const P=z.current;if(!P)return;const q=P.getBoundingClientRect(),ae=q.width;document.body.classList.add("resizing-panes");const te=we=>{const Re=(we.clientX-q.left)/ae*100,Ne=Math.min(80,Math.max(20,Re));G(Ne)},ye=()=>{document.body.classList.remove("resizing-panes"),document.removeEventListener("mousemove",te),document.removeEventListener("mouseup",ye)};document.addEventListener("mousemove",te),document.addEventListener("mouseup",ye)},[]);return r.jsxs("div",{ref:K,style:{display:"flex",flexDirection:"column",height:"100%",minWidth:0,minHeight:0},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"3px 10px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",flexShrink:0,height:"24px"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"5px"},children:[r.jsx("span",{style:{display:"inline-block",width:"6px",height:"6px",borderRadius:"50%",backgroundColor:e.connected?"var(--accent-green)":"var(--accent-red)"}}),r.jsxs("span",{style:{fontSize:"12px",color:"var(--text-secondary)"},children:[e.id,e.connected?e.sessionResumed?" (resumed)":"":" (disconnected)"]})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[r.jsx("input",{ref:m,type:"file",multiple:!0,style:{display:"none"},onChange:be}),r.jsx("button",{className:"pane-btn",onClick:()=>{var N;return(N=m.current)==null?void 0:N.click()},disabled:v,style:v?{color:"var(--accent-yellow)"}:void 0,title:v?`Uploading ${_}%`:"Upload files","aria-label":"Upload files",children:v?`${_}%`:"↑"}),r.jsxs("div",{style:{position:"relative"},children:[r.jsx("button",{className:"pane-btn",onClick:Be,disabled:T,style:T?{color:"var(--accent-yellow)"}:void 0,title:T?"Downloading...":"Download files","aria-label":"Download files",children:T?"...":"↓"}),U&&r.jsxs("div",{ref:V,style:{position:"absolute",top:"100%",right:0,marginTop:4,width:300,maxHeight:360,backgroundColor:"var(--bg-primary)",border:"1px solid var(--border)",borderRadius:6,boxShadow:"0 4px 16px rgba(0,0,0,0.3)",zIndex:100,display:"flex",flexDirection:"column",overflow:"hidden"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"6px 8px",borderBottom:"1px solid var(--border)",backgroundColor:"var(--bg-secondary)",flexShrink:0},children:[S.length>0&&r.jsx("button",{className:"pane-btn",onClick:ge,disabled:k,style:{fontSize:11,flexShrink:0},title:"Go back",children:".."}),r.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",flex:1},children:F.split("/").slice(-2).join("/")||F}),r.jsx("button",{className:"pane-btn",onClick:()=>L(!1),style:{fontSize:11,flexShrink:0},title:"Close",children:"×"})]}),r.jsx("div",{style:{flex:1,overflowY:"auto",padding:"2px 0"},children:k?r.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12},children:"Loading..."}):B.length===0?r.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12,fontStyle:"italic"},children:"Empty directory"}):B.map(N=>r.jsxs("div",{onClick:()=>{const P=F+"/"+N.name;N.type==="directory"?ve(P):Ie(P)},style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",cursor:"pointer",fontSize:12,color:"var(--text-primary)",transition:"background-color 0.1s"},onMouseEnter:P=>{P.currentTarget.style.backgroundColor="var(--bg-secondary)"},onMouseLeave:P=>{P.currentTarget.style.backgroundColor="transparent"},children:[r.jsx("span",{style:{flexShrink:0,fontSize:13},children:N.type==="directory"?"📁":eo(N.name,N.type)}),r.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.name}),N.type==="directory"?r.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:"›"}):N.size!=null?r.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:ln(N.size)}):null]},N.name))}),r.jsx("div",{style:{borderTop:"1px solid var(--border)",padding:"6px 8px",flexShrink:0,backgroundColor:"var(--bg-secondary)"},children:r.jsx("button",{className:"pane-btn",onClick:async()=>{g(!0),L(!1);try{await Zr(a||"",e.id)}catch(N){alert(`Download failed: ${N instanceof Error?N.message:"Unknown error"}`)}finally{g(!1)}},style:{fontSize:11,color:"var(--accent-blue)",width:"100%",textAlign:"center"},title:"Download entire CWD as tar.gz",children:"Download All (tar.gz)"})})]})]}),r.jsx("button",{className:`pane-btn${d?" pane-btn--active":""}`,onClick:()=>c(e.id),title:"Toggle Chat panel","aria-label":"Toggle Chat panel",children:"Chat"}),r.jsx("button",{className:`pane-btn${l?" pane-btn--active":""}`,onClick:()=>i(e.id),title:"Toggle Task annotation panel","aria-label":"Toggle Task annotation panel",children:"Task"}),r.jsx("button",{className:"pane-btn",onClick:()=>f(t?"vertical":"horizontal"),title:t?"Split vertical (screen too narrow for horizontal)":"Split horizontal (left/right)","aria-label":"Split horizontal",children:"|"}),r.jsx("button",{className:"pane-btn",onClick:()=>f("vertical"),title:"Split vertical (top/bottom)","aria-label":"Split vertical",children:"─"})]})]}),r.jsxs("div",{ref:z,style:{flex:1,display:"flex",flexDirection:"row",overflow:"hidden",minHeight:0},children:[l&&r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{width:`${M}%`,minWidth:200,flexShrink:0,overflow:"hidden"},children:r.jsx(oo,{sessionId:e.id,token:a||"",connected:e.connected,onRequestFileStream:N=>{var P;return(P=p.current)==null?void 0:P.requestFileStream(N)},onCancelFileStream:()=>{var N;return(N=p.current)==null?void 0:N.cancelFileStream()},onForwardToChat:Q,onSendToTerminal:me})}),r.jsx("div",{className:"md-editor-divider-h",onMouseDown:he,style:{width:"2px",flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:N=>{N.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:N=>{N.currentTarget.style.backgroundColor="var(--border)"}})]}),r.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[r.jsxs("div",{style:{flex:1,overflow:"hidden",position:"relative",minWidth:80},children:[r.jsx(Dr,{ref:p,sessionId:e.id}),!e.connected&&r.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"var(--bg-secondary)",opacity:.85,zIndex:2,pointerEvents:"none"},children:r.jsx("span",{style:{color:"var(--text-secondary)",fontSize:"13px",fontStyle:"italic"},children:"Connecting..."})})]}),d&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"md-editor-divider",onMouseDown:Ae}),r.jsxs("div",{style:{height:`${Y}%`,minHeight:80,flexShrink:0,overflow:"hidden",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[r.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 8px",height:"22px",flexShrink:0,backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)"},children:r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[r.jsx("span",{style:{fontSize:"11px",color:"var(--accent-blue)",fontWeight:500},children:"Chat"}),r.jsx("button",{className:"pane-btn",onClick:()=>{var N;return(N=h.current)==null?void 0:N.send()},disabled:!$,title:"Send to terminal (Ctrl+Enter)",style:$?{color:"var(--accent-green)"}:{opacity:.4,cursor:"default"},children:"Send"}),r.jsx("span",{style:{fontSize:"9px",color:"var(--text-secondary)"},children:"Ctrl+Enter"})]})}),r.jsx("div",{style:{flex:1,overflow:"hidden"},children:r.jsx(io,{ref:h,onSend:Te,onContentChange:R,sessionId:e.id,token:a||""})})]})]})]})]}),e.error&&r.jsx("div",{style:{padding:"2px 8px",backgroundColor:"var(--bg-secondary)",borderTop:"1px solid var(--accent-red)",color:"var(--accent-red)",fontSize:"11px",flexShrink:0},children:e.error})]})});class un extends s.Component{constructor(){super(...arguments);Ct(this,"state",{hasError:!1,error:null})}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,o){}render(){var t,o;return this.state.hasError?this.props.inline?r.jsxs("div",{style:{height:"100%",backgroundColor:"var(--bg-primary)",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:"8px",color:"var(--text-bright)",fontFamily:"monospace",padding:"16px"},children:[r.jsx("div",{style:{fontSize:"14px",color:"var(--accent-red)"},children:"Pane crashed"}),r.jsx("div",{style:{fontSize:"12px",color:"var(--text-secondary)",textAlign:"center"},children:((t=this.state.error)==null?void 0:t.message)||"An unexpected error occurred"}),r.jsx("button",{onClick:()=>this.setState({hasError:!1,error:null}),style:{background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-bright)",padding:"4px 12px",borderRadius:"4px",cursor:"pointer",fontSize:"12px"},children:"Retry"})]}):r.jsxs("div",{style:{minHeight:"100vh",backgroundColor:"var(--bg-primary)",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:"16px",color:"var(--text-bright)",fontFamily:"monospace"},children:[r.jsx("div",{style:{fontSize:"18px",color:"var(--accent-red)"},children:"Something went wrong"}),r.jsx("div",{style:{fontSize:"13px",color:"var(--text-secondary)",maxWidth:"500px",textAlign:"center"},children:((o=this.state.error)==null?void 0:o.message)||"An unexpected error occurred"}),r.jsx("button",{onClick:()=>window.location.reload(),style:{background:"linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-purple) 100%)",border:"none",color:"var(--bg-primary)",padding:"8px 24px",borderRadius:"6px",cursor:"pointer",fontSize:"14px",fontWeight:"bold"},children:"Reload"})]}):this.props.children}}const fo=4,Ut=10;function po(){const n=A(a=>a.layout),e=A(a=>a.terminalIds.length),t=A(a=>a.addTerminal);if(!n)return r.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)"},children:r.jsx("button",{onClick:()=>t(),style:{background:"none",border:"1px dashed var(--border)",color:"var(--text-secondary)",padding:"16px 32px",borderRadius:"8px",cursor:"pointer",fontSize:"14px"},children:"+ Add Terminal"})});const o=e>1;return r.jsx("div",{style:{height:"100%",width:"100%",overflow:"hidden"},children:r.jsx(fn,{node:n,canClose:o})})}const fn=s.memo(function({node:e,canClose:t}){return e.type==="leaf"?r.jsx(mo,{terminalId:e.terminalId,canClose:t}):r.jsx(ho,{node:e,canClose:t})}),mo=s.memo(function({terminalId:e,canClose:t}){const o=A(a=>a.terminalsMap[e]);return o?r.jsx(un,{inline:!0,children:r.jsx(uo,{terminal:o,canClose:t})}):null}),ho=s.memo(function({node:e,canClose:t}){const o=A(f=>f.setSplitSizes),a=s.useRef(null),c=e.direction==="horizontal",i=s.useRef(e.sizes);i.current=e.sizes;const d=s.useCallback((f,m)=>{m.preventDefault();const p=c?"resizing-panes":"resizing-panes-v";document.body.classList.add(p);const h=c?m.clientX:m.clientY,v=[...i.current],C=a.current,_=c?(C==null?void 0:C.clientWidth)||1:(C==null?void 0:C.clientHeight)||1;let D=null;const T=$=>{D||(D=requestAnimationFrame(()=>{D=null;const L=((c?$.clientX:$.clientY)-h)/_*100,B=v[f]+L,W=v[f+1]-L;if(B>=Ut&&W>=Ut){const F=[...v];F[f]=B,F[f+1]=W,o(e.id,F)}}))},g=()=>{D&&cancelAnimationFrame(D),document.body.classList.remove(p),document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",g)};document.addEventListener("mousemove",T),document.addEventListener("mouseup",g)},[c,e.id,o]),l=[];return e.children.forEach((f,m)=>{const p=f.type==="leaf"?f.terminalId:f.id;l.push(r.jsx("div",{style:{flex:`${e.sizes[m]} 0 0`,minWidth:0,minHeight:0,overflow:"hidden"},children:r.jsx(fn,{node:f,canClose:t})},p)),m<e.children.length-1&&l.push(r.jsx("div",{onMouseDown:h=>d(m,h),style:{flex:`0 0 ${fo}px`,cursor:c?"col-resize":"row-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:h=>{h.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="var(--border)"}},`divider-${e.id}-${m}`))}),r.jsx("div",{ref:a,style:{display:"flex",flexDirection:c?"row":"column",height:"100%",width:"100%",overflow:"hidden"},children:l})});function bo({tabId:n}){const e=A(j=>j.tabs.find(S=>S.id===n)),t=A(j=>j.activeTabId),o=A(j=>j.switchTab),a=A(j=>j.closeTab),c=A(j=>j.reopenTab),i=A(j=>j.deleteTab),d=A(j=>j.renameTab),l=A(j=>e?e.terminalIds.map(S=>{const O=j.terminalsMap[S];return O?{id:S,connected:O.connected}:{id:S,connected:!1}}):[]),f=A(j=>j.killServerSession),[m,p]=s.useState(!1),[h,v]=s.useState(""),[C,_]=s.useState(!1),D=s.useRef(null);if(!e)return null;const T=t===n,g=e.status==="open",$=()=>{g&&o(n)},R=j=>{g&&(j.stopPropagation(),v(e.name),p(!0),setTimeout(()=>{var S;return(S=D.current)==null?void 0:S.focus()},0))},U=()=>{const j=h.trim();j&&d(n,j),p(!1)},L=j=>{j.stopPropagation(),c(n)},B=j=>{j.stopPropagation(),a(n)},W=async j=>{j.stopPropagation(),window.confirm(`Delete tab "${e.name}"? This will kill all tmux sessions in this tab.`)&&await i(n)},F=j=>{j.stopPropagation(),_(!C)};return r.jsxs("div",{children:[r.jsxs("div",{onClick:$,style:{padding:"8px 12px",cursor:g?"pointer":"default",borderLeft:T?"3px solid var(--accent-blue)":"3px solid transparent",backgroundColor:T?"rgba(122, 162, 247, 0.08)":"transparent",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s",opacity:g?1:.5},onMouseEnter:j=>{g&&!T&&(j.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)")},onMouseLeave:j=>{T||(j.currentTarget.style.backgroundColor="transparent")},children:[g&&e.terminalIds.length>0&&r.jsx("button",{onClick:F,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"10px",padding:0,width:14,height:14,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:C?"▼":"▶"}),r.jsxs("div",{style:{flex:1,minWidth:0},children:[m?r.jsx("input",{ref:D,value:h,onChange:j=>v(j.target.value),onBlur:U,onKeyDown:j=>{j.key==="Enter"&&U(),j.key==="Escape"&&p(!1)},style:{width:"100%",background:"var(--bg-primary)",border:"1px solid var(--accent-blue)",color:"var(--text-bright)",borderRadius:"3px",padding:"1px 4px",fontSize:"14px",outline:"none"}}):r.jsx("div",{onDoubleClick:R,style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:g?"Double-click to rename":e.name,children:e.name}),r.jsxs("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:[e.terminalIds.length," terminal",e.terminalIds.length!==1?"s":""," · ",cn(Math.floor(e.createdAt/1e3))]})]}),g?r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:B,style:{flexShrink:0},title:"Close tab",children:"×"}):r.jsxs("div",{style:{display:"flex",gap:"4px",flexShrink:0},children:[r.jsx("button",{className:"pane-btn",onClick:L,title:"Reopen tab",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:W,title:"Delete tab",children:"×"})]})]}),g&&C&&l.length>0&&r.jsx("div",{style:{paddingLeft:"28px",backgroundColor:"rgba(0, 0, 0, 0.2)"},children:l.map(j=>r.jsxs("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--text-secondary)",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center"},title:`Connected: ${j.connected}`,children:[r.jsx("span",{style:{fontFamily:"monospace"},children:j.id}),r.jsx("span",{style:{marginLeft:"8px",color:j.connected?"var(--accent-green)":"var(--accent-red)"},children:j.connected?"●":"○"}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:S=>{S.stopPropagation(),window.confirm(`Close terminal "${j.id}"?`)&&f(j.id)},style:{marginLeft:"auto",flexShrink:0},title:"Close terminal",children:"×"})]},j.id))})]})}function xo({sessionId:n,active:e,createdAt:t}){const o=A(d=>d.addTerminal),a=A(d=>d.killServerSession),c=()=>{o("horizontal",n)},i=d=>{d.stopPropagation(),window.confirm(`Delete orphaned session "${n}"? This will kill the tmux session.`)&&a(n)};return r.jsxs("div",{onClick:c,style:{padding:"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)"},onMouseLeave:d=>{d.currentTarget.style.backgroundColor="transparent"},children:[r.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:e?"var(--accent-green)":"var(--text-secondary)",flexShrink:0}}),r.jsxs("div",{style:{flex:1,minWidth:0},children:[r.jsx("div",{style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n}),r.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:cn(t)})]}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:i,style:{flexShrink:0},title:"Delete session",children:"×"})]})}function go(){const n=A(l=>l.sidebarOpen),e=A(l=>l.toggleSidebar),t=A(l=>l.fetchSessions),o=A(l=>n?l.serverSessions:[]),a=A(l=>n?l.tabs:[]),c=A(l=>l.terminalIds.length),i=new Set(a.flatMap(l=>l.terminalIds)),d=o.filter(l=>!i.has(l.sessionId));return s.useEffect(()=>{if(!n)return;t();let l=setInterval(t,5e3);const f=()=>{document.hidden?l&&(clearInterval(l),l=null):(t(),l||(l=setInterval(t,5e3)))};return document.addEventListener("visibilitychange",f),()=>{l&&clearInterval(l),document.removeEventListener("visibilitychange",f)}},[n,t]),s.useEffect(()=>{if(!n)return;const l=setTimeout(t,800);return()=>clearTimeout(l)},[c,n,t]),r.jsxs("div",{className:"session-sidebar",style:{width:n?280:0,height:"100%",backgroundColor:"var(--bg-secondary)",borderLeft:n?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,overflow:"hidden",transition:"width 0.2s ease"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[r.jsx("span",{style:{color:"var(--accent-blue)",fontSize:"14px",fontWeight:"bold"},children:"Tabs & Sessions"}),r.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"16px",padding:"0 4px",lineHeight:1},title:"Close sidebar",children:"×"})]}),r.jsxs("div",{style:{flex:1,overflowY:"auto"},children:[r.jsxs("div",{children:[r.jsx("div",{style:{padding:"8px 12px",color:"var(--accent-blue)",fontSize:"12px",fontWeight:"bold",backgroundColor:"rgba(122, 162, 247, 0.05)",borderBottom:"1px solid var(--border)"},children:"TABS"}),a.length===0?r.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"14px",textAlign:"center",padding:"12px"},children:"No tabs"}):a.map(l=>r.jsx(bo,{tabId:l.id},l.id))]}),d.length>0&&r.jsxs("div",{style:{marginTop:"16px"},children:[r.jsx("div",{style:{padding:"8px 12px",color:"var(--accent-yellow)",fontSize:"12px",fontWeight:"bold",backgroundColor:"rgba(224, 175, 104, 0.05)",borderBottom:"1px solid var(--border)"},children:"ORPHANED SESSIONS"}),d.map(l=>r.jsx(xo,{sessionId:l.sessionId,active:l.active,createdAt:l.createdAt},l.sessionId))]})]})]})}const pn=gt.memo(()=>{const n=A(R=>R.tabs),e=A(R=>R.activeTabId),t=A(R=>R.addTab),o=A(R=>R.switchTab),a=A(R=>R.closeTab),c=A(R=>R.renameTab),[i,d]=s.useState(null),[l,f]=s.useState(""),m=s.useRef(null),p=n.filter(R=>R.status==="open");s.useEffect(()=>{i&&m.current&&(m.current.focus(),m.current.select())},[i]);const h=R=>{d(R.id),f(R.name)},v=()=>{i&&l.trim()&&c(i,l.trim()),d(null),f("")},C=()=>{d(null),f("")},_=R=>{R.key==="Enter"?v():R.key==="Escape"&&C()},D=R=>{i||o(R)},T=(R,U)=>{R.stopPropagation(),a(U)},g=(R,U)=>{R.button===1&&(R.preventDefault(),a(U))},$=p.length>1;return r.jsxs("div",{className:"tab-bar",children:[p.map(R=>{const U=R.id===e,L=i===R.id,B=R.terminalIds.length;return r.jsx("div",{className:`tab-item ${U?"tab-item--active":""}`,onClick:()=>D(R.id),onDoubleClick:()=>h(R),onMouseDown:W=>g(W,R.id),children:L?r.jsx("input",{ref:m,type:"text",value:l,onChange:W=>f(W.target.value),onBlur:v,onKeyDown:_,className:"tab-item__rename-input"}):r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"tab-item__name",children:[R.name," ",B>0&&`(${B})`]}),$&&r.jsx("button",{className:"tab-item__close",onClick:W=>T(W,R.id),title:"Close tab","aria-label":"Close tab",children:"×"})]})},R.id)}),r.jsx("button",{className:"tab-bar-add",onClick:()=>t(),title:"New tab","aria-label":"Add new tab",children:"+"})]})});pn.displayName="TabBar";function yo(){return localStorage.getItem("ai-cli-online-token")}function vo(){const n=A(m=>m.token),e=A(m=>m.setToken),t=A(m=>m.tabs),o=A(m=>m.addTab),a=A(m=>m.toggleSidebar),c=A(m=>m.fontSize),i=A(m=>m.setFontSize),d=A(m=>m.tabsLoading),l=A(m=>m.theme),f=A(m=>m.toggleTheme);return s.useEffect(()=>{const m=yo();m&&!n&&e(m)},[]),s.useEffect(()=>{n&&!d&&t.filter(m=>m.status==="open").length===0&&o("Default")},[n,d]),n?r.jsxs("div",{style:{height:"100vh",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[r.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 16px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",flexShrink:0},children:[r.jsx("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:r.jsx("span",{style:{fontSize:"15px",fontWeight:"bold",color:"var(--accent-blue)",letterSpacing:"0.5px"},children:"AI-Cli Online"})}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"1px 4px",borderRadius:"6px",backgroundColor:"rgba(0,0,0,0.2)"},children:[r.jsx("button",{className:"header-btn",onClick:()=>i(c-1),disabled:c<=10,title:"Decrease font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A−"}),r.jsx("span",{style:{fontSize:"11px",color:"var(--text-primary)",minWidth:"20px",textAlign:"center"},children:c}),r.jsx("button",{className:"header-btn",onClick:()=>i(c+1),disabled:c>=24,title:"Increase font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A+"})]}),r.jsx(So,{}),r.jsx("button",{className:"header-btn",onClick:f,title:`Switch to ${l==="dark"?"light":"dark"} mode`,"aria-label":"Toggle theme",children:l==="dark"?"☀":"🌙"}),r.jsx("button",{className:"header-btn",onClick:a,title:"Toggle Tabs & Sessions Sidebar","aria-label":"Toggle sidebar",children:"☰"}),r.jsx("button",{className:"header-btn header-btn--muted",onClick:()=>{window.confirm("Logout will close all terminals. Continue?")&&e(null)},children:"Logout"})]})]}),r.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[r.jsx("main",{style:{flex:1,overflow:"hidden"},children:r.jsx(po,{})}),r.jsx(go,{})]}),r.jsx(pn,{})]}):r.jsx(fr,{})}const wo=[1,2,3,4];function So(){const n=A(o=>o.latency);if(n===null)return r.jsx("span",{style:{fontSize:"10px",color:"var(--scrollbar-thumb-hover)"},title:"Measuring latency...",children:"--ms"});let e,t;return n<50?(e="var(--accent-green)",t=4):n<150?(e="var(--accent-yellow)",t=3):n<300?(e="var(--accent-orange)",t=2):(e="var(--accent-red)",t=1),r.jsxs("span",{style:{display:"inline-flex",alignItems:"end",gap:"1.5px",padding:"2px 8px",borderRadius:"10px",backgroundColor:"rgba(0,0,0,0.2)"},title:`Latency: ${n}ms`,children:[wo.map(o=>r.jsx("span",{style:{display:"inline-block",width:"2.5px",height:`${3+o*2}px`,backgroundColor:o<=t?e:"var(--border)",borderRadius:"1px",transition:"background-color 0.3s ease"}},o)),r.jsxs("span",{style:{fontSize:"10px",color:e,marginLeft:"4px",fontWeight:500},children:[n,"ms"]})]})}mt.createRoot(document.getElementById("root")).render(r.jsx(gt.StrictMode,{children:r.jsx(un,{children:r.jsx(vo,{})})}));
|
|
28
|
+
`),[e]),$=s.useMemo(()=>Br(e),[e]),L=s.useMemo(()=>{const u=new Map,b=new Map;return v.forEach((I,w)=>{if(I.type==="heading"){const y=sn(I.text||""),Z=on(y,b);u.set(w,Z)}}),u},[v]),T=s.useRef(new Set),[g,z]=s.useState(()=>{try{const u=localStorage.getItem(Ze(o,t)),b=u?JSON.parse(u):dt,I=new Set;return b.additions.forEach(w=>I.add(w.id)),b.deletions.forEach(w=>I.add(w.id)),(b.replacements??[]).forEach(w=>I.add(w.id)),(b.comments??[]).forEach(w=>I.add(w.id)),T.current=I,b.replacements||(b.replacements=[]),b.comments||(b.comments=[]),b}catch{return dt}}),R=A(u=>u.latency),W=s.useRef(void 0),D=s.useRef(void 0),U=s.useRef(!1),H=s.useRef(!1);s.useEffect(()=>{if(!H.current)return;const u=Ze(o,t),b=JSON.stringify(g);W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{try{localStorage.setItem(u,b)}catch{}},50),D.current&&clearTimeout(D.current);const I=Math.max(200,(R??30)*3);return D.current=setTimeout(()=>{U.current||(U.current=!0,Pr(a,o,t,b,Date.now()).catch(()=>{}).finally(()=>{U.current=!1}))},I),()=>{W.current&&clearTimeout(W.current),D.current&&clearTimeout(D.current)}},[g,o,t,a,R]),s.useEffect(()=>{H.current=!1;let u=dt,b=0;try{const y=localStorage.getItem(Ze(o,t));y&&(u=JSON.parse(y),b=Date.now())}catch{}u.replacements||(u.replacements=[]),u.comments||(u.comments=[]),z(u);const I=new Set;u.additions.forEach(y=>I.add(y.id)),u.deletions.forEach(y=>I.add(y.id)),u.replacements.forEach(y=>I.add(y.id)),u.comments.forEach(y=>I.add(y.id)),T.current=I;let w=!1;return Fr(a,o,t).then(y=>{if(!w&&y&&y.updatedAt>b)try{const Z=JSON.parse(y.content);Z.replacements||(Z.replacements=[]),Z.comments||(Z.comments=[]),z(Z);try{localStorage.setItem(Ze(o,t),y.content)}catch{}const Ee=new Set;Z.additions.forEach(je=>Ee.add(je.id)),Z.deletions.forEach(je=>Ee.add(je.id)),Z.replacements.forEach(je=>Ee.add(je.id)),Z.comments.forEach(je=>Ee.add(je.id)),T.current=Ee}catch{}}).catch(()=>{}).finally(()=>{H.current=!0}),H.current=!0,()=>{w=!0}},[o,t,a]);const[F,j]=s.useState(0),S=s.useMemo(()=>{const u=T.current,b=g.additions.length+g.deletions.length+g.replacements.length+g.comments.length;let I=0;return g.additions.forEach(w=>{u.has(w.id)&&I++}),g.deletions.forEach(w=>{u.has(w.id)&&I++}),g.replacements.forEach(w=>{u.has(w.id)&&I++}),g.comments.forEach(w=>{u.has(w.id)&&I++}),{total:b,sent:I,unsent:b-I}},[g,F]),[_,k]=s.useState(null),[G,Y]=s.useState(""),J=s.useRef(null),[M,B]=s.useState(null),[X,O]=s.useState(""),K=s.useRef(null),[re,ne]=s.useState(null),[be,Ce]=s.useState(""),Te=s.useRef(null),[Be,ve]=s.useState(null),[ge,Ie]=s.useState(""),me=s.useRef(null),[Q,Ae]=s.useState(null),[he,N]=s.useState(""),P=s.useRef(null),[V,ie]=s.useState(null),te=s.useRef(null);s.useEffect(()=>()=>{const u=te.current;u&&u.scrollTop>0&&localStorage.setItem($t(o,t),String(u.scrollTop))},[o,t]),s.useEffect(()=>{if(!v.length)return;const u=localStorage.getItem($t(o,t));u&&requestAnimationFrame(()=>{const b=te.current;b&&(b.scrollTop=Number(u))})},[o,t,v.length]),s.useEffect(()=>{_!=null&&requestAnimationFrame(()=>{var u;return(u=J.current)==null?void 0:u.focus()})},[_]),s.useEffect(()=>{Q&&requestAnimationFrame(()=>{var u;return(u=P.current)==null?void 0:u.focus()})},[Q]);const ye=s.useCallback(u=>{if(!G.trim()){k(null),Y("");return}const b=ut(v,u+1);z(I=>({...I,additions:[...I.additions,{id:$e(),afterTokenIndex:u,sourceLine:b,content:G.trim()}]})),k(null),Y("")},[G,v]),we=s.useCallback(u=>{z(b=>({...b,additions:b.additions.filter(I=>I.id!==u)}))},[]),Re=s.useCallback((u,b)=>{z(I=>({...I,additions:I.additions.map(w=>w.id===u?{...w,id:$e(),content:b}:w)}))},[]),Ne=s.useCallback(()=>{var u;V&&(z(b=>({...b,deletions:[...b.deletions,{id:$e(),tokenIndices:V.tokenIndices,startLine:V.startLine,endLine:V.endLine,selectedText:V.text.slice(0,80)}]})),ie(null),(u=window.getSelection())==null||u.removeAllRanges())},[V]),ze=s.useCallback(u=>{var b;V&&(Ae({type:u,tokenIndices:V.tokenIndices,startLine:V.startLine,endLine:V.endLine,text:V.text.slice(0,80)}),N(""),ie(null),(b=window.getSelection())==null||b.removeAllRanges())},[V]),De=s.useCallback(()=>{if(!Q)return;const u=he.trim();if(!u){Ae(null),N("");return}Q.type==="replace"?z(b=>({...b,replacements:[...b.replacements,{id:$e(),tokenIndices:Q.tokenIndices,startLine:Q.startLine,endLine:Q.endLine,selectedText:Q.text,content:u}]})):z(b=>({...b,comments:[...b.comments,{id:$e(),tokenIndices:Q.tokenIndices,startLine:Q.startLine,endLine:Q.endLine,selectedText:Q.text,content:u}]})),Ae(null),N("")},[Q,he]),Oe=s.useCallback(u=>{z(b=>({...b,replacements:b.replacements.filter(I=>I.id!==u)}))},[]),Je=s.useCallback((u,b)=>{z(I=>({...I,replacements:I.replacements.map(w=>w.id===u?{...w,id:$e(),content:b}:w)}))},[]),x=s.useCallback(u=>{z(b=>({...b,comments:b.comments.filter(I=>I.id!==u)}))},[]),E=s.useCallback((u,b)=>{z(I=>({...I,comments:I.comments.map(w=>w.id===u?{...w,id:$e(),content:b}:w)}))},[]),q=s.useCallback(u=>{z(b=>({...b,deletions:b.deletions.filter(I=>I.id!==u)}))},[]),ee=s.useCallback((u,b)=>{z(I=>({...I,deletions:I.deletions.map(w=>w.id===u?{...w,id:$e(),selectedText:b}:w)}))},[]),se=s.useCallback(u=>{let b=u instanceof Element?u:u.parentElement;for(;b&&b!==te.current;){if(b.hasAttribute("data-token-index"))return b;b=b.parentElement}return null},[]),xe=s.useCallback(()=>{const u=window.getSelection();if(!u||u.isCollapsed||!te.current){ie(null);return}const b=u.toString().trim();if(!b){ie(null);return}const I=u.getRangeAt(0);if(!te.current.contains(I.commonAncestorContainer)){ie(null);return}const w=se(I.startContainer),y=se(I.endContainer);if(!w||!y){ie(null);return}const Z=parseInt(w.getAttribute("data-token-index")||"0",10),Ee=parseInt(y.getAttribute("data-token-index")||"0",10),je=[];for(let it=Math.min(Z,Ee);it<=Math.max(Z,Ee);it++)je.push(it);const xn=ut(v,Math.min(Z,Ee)),gn=ut(v,Math.max(Z,Ee)+1),St=I.getBoundingClientRect(),at=te.current,kt=at.getBoundingClientRect();navigator.clipboard.writeText(b).catch(()=>{}),ie({x:St.right-kt.left+at.scrollLeft+6,y:St.top-kt.top+at.scrollTop-2,tokenIndices:je,startLine:xn,endLine:gn,text:b})},[v,se]),ae=s.useRef(void 0);s.useEffect(()=>{const u=()=>{ae.current&&clearTimeout(ae.current),ae.current=setTimeout(()=>{const b=window.getSelection();if(!b||b.isCollapsed||!te.current){ie(null);return}const I=b.anchorNode;I&&te.current.contains(I)&&xe()},120)};return document.addEventListener("selectionchange",u),()=>{document.removeEventListener("selectionchange",u),ae.current&&clearTimeout(ae.current)}},[xe]),Or(te,v);const de=s.useCallback(()=>{const u=T.current;return{additions:g.additions.filter(b=>!u.has(b.id)),deletions:g.deletions.filter(b=>!u.has(b.id)),replacements:g.replacements.filter(b=>!u.has(b.id)),comments:g.comments.filter(b=>!u.has(b.id))}},[g]),fe=s.useCallback(()=>{const u=ft(t,de(),C);if(u){c(u);const b=new Set;g.additions.forEach(I=>b.add(I.id)),g.deletions.forEach(I=>b.add(I.id)),g.replacements.forEach(I=>b.add(I.id)),g.comments.forEach(I=>b.add(I.id)),T.current=b,j(I=>I+1)}},[de,g,C,c,t]);s.useImperativeHandle(p,()=>({getSummary:()=>ft(t,de(),C),handleEscape:()=>Q?(De(),!0):_!=null?(ye(_),!0):!1,getScrollTop:()=>{var u;return((u=te.current)==null?void 0:u.scrollTop)??0},setScrollTop:u=>{requestAnimationFrame(()=>{te.current&&(te.current.scrollTop=u)})}}),[de,C,t,_,ye,Q,De]);const[ce,Le]=s.useState(!1),Fe=s.useRef(null);s.useEffect(()=>{if(!ce)return;const u=b=>{Fe.current&&!Fe.current.contains(b.target)&&Le(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[ce]);const Se=s.useCallback((u,b)=>{if(!i)return;const I={additions:[],deletions:[],replacements:[],comments:[]};if(b==="add"){const y=g.additions.find(Z=>Z.id===u);if(!y)return;I.additions.push(y)}else if(b==="del"){const y=g.deletions.find(Z=>Z.id===u);if(!y)return;I.deletions.push(y)}else if(b==="rep"){const y=g.replacements.find(Z=>Z.id===u);if(!y)return;I.replacements.push(y)}else{const y=g.comments.find(Z=>Z.id===u);if(!y)return;I.comments.push(y)}const w=ft(t,I,C);w&&i(w),T.current.add(u),j(y=>y+1)},[i,t,g,C]),Ve=s.useCallback((u,b)=>{b==="add"?we(u):b==="del"?q(u):b==="rep"?Oe(u):x(u)},[we,q,Oe,x]),mn=s.useMemo(()=>{const u=new Set;return g.deletions.forEach(b=>b.tokenIndices.forEach(I=>u.add(I))),u},[g.deletions]),hn=s.useMemo(()=>{const u=new Set;return g.replacements.forEach(b=>b.tokenIndices.forEach(I=>u.add(I))),u},[g.replacements]),bn=s.useMemo(()=>{const u=new Set;return g.comments.forEach(b=>b.tokenIndices.forEach(I=>u.add(I))),u},[g.comments]),vt=s.useMemo(()=>{const u=new Map;return g.additions.forEach(b=>{const I=u.get(b.afterTokenIndex)||[];I.push(b),u.set(b.afterTokenIndex,I)}),u},[g.additions]),wt=g.additions.length>0||g.deletions.length>0||g.replacements.length>0||g.comments.length>0;return r.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[r.jsxs("div",{className:"plan-anno-toolbar",children:[r.jsx("span",{style:{fontSize:"11px",color:"var(--text-secondary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},title:t,children:t.split("/").pop()||t}),d&&r.jsx("button",{className:"pane-btn",onClick:d,title:"Refresh current file",children:"↻"}),r.jsx("button",{className:"pane-btn",onClick:fe,disabled:!wt,title:"Send all annotations to Chat editor",style:wt?{color:"var(--accent-green)"}:{opacity:.4},children:"Send"}),r.jsxs("div",{ref:Fe,style:{position:"relative",flex:1,minWidth:0},children:[r.jsxs("div",{className:`plan-anno-dropdown-trigger${ce?" plan-anno-dropdown-trigger--active":""}`,onClick:()=>Le(u=>!u),title:S.total>0?`${S.total} annotations (${S.unsent} unsent)`:"No annotations",children:[r.jsx("span",{className:"plan-anno-dropdown-trigger__text",children:(()=>{const u=g.additions[0],b=g.deletions[0],I=g.replacements[0],w=g.comments[0],y=u?u.content:b?b.selectedText:I?I.content:w?w.content:"";return y?y.slice(0,40)+(y.length>40?"...":""):""})()}),r.jsx("span",{className:"plan-anno-dropdown-trigger__arrow",children:"▼"})]}),ce&&r.jsxs("div",{className:"plan-anno-dropdown",children:[S.unsent>0&&r.jsx("div",{className:"plan-anno-dropdown__header",children:r.jsxs("button",{className:"pane-btn",onClick:fe,style:{color:"var(--accent-blue)",fontSize:11},children:["Send All Unsent (",S.unsent,")"]})}),r.jsxs("div",{className:"plan-anno-dropdown__list",children:[g.additions.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--add",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-yellow)"},children:"+"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.content.slice(0,60),u.content.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"add"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"add"),title:"Delete",children:"×"})]},u.id)}),g.deletions.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--del",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-red)"},children:"−"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.selectedText.slice(0,60),u.selectedText.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"del"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"del"),title:"Delete",children:"×"})]},u.id)}),g.replacements.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--rep",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-blue)"},children:"⇄"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.content.slice(0,60),u.content.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"rep"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"rep"),title:"Delete",children:"×"})]},u.id)}),g.comments.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--com",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-green)"},children:"?"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.content.slice(0,60),u.content.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"com"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"com"),title:"Delete",children:"×"})]},u.id)}),S.total===0&&r.jsx("div",{className:"plan-anno-dropdown__empty",children:"No annotations"})]})]})]}),l&&r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:()=>{fe(),l()},title:"Send annotations & close file",children:"×"})]}),r.jsxs("div",{style:{display:"flex",flex:1,minHeight:0},children:[r.jsxs("div",{ref:te,className:`plan-anno-content md-preview${_!=null?" plan-anno-content--editing":""}`,style:{flex:1,overflow:"auto",padding:"8px 12px",position:"relative",fontSize:`${h}px`,minWidth:0},onMouseUp:xe,children:[!m&&r.jsx(_t,{index:-1,active:_===-1,additions:vt.get(-1),onOpen:()=>{k(-1),Y("")},onSubmit:()=>ye(-1),onRemoveAddition:we,onEditAddition:Re,onSendSingle:i?u=>Se(u,"add"):void 0,isSent:u=>T.current.has(u),insertText:G,setInsertText:Y,textareaRef:_===-1?J:void 0,expanded:f,alwaysShow:v.length===0,fontSize:h}),v.map((u,b)=>{const I=qr(u);return r.jsxs("div",{children:[r.jsx("div",{"data-token-index":b,id:L.get(b),className:mn.has(b)?"plan-block--deleted":hn.has(b)?"plan-block--replaced":bn.has(b)?"plan-block--commented":void 0,dangerouslySetInnerHTML:{__html:I}}),g.deletions.filter(w=>w.tokenIndices.includes(b)&&w.tokenIndices[0]===b).map(w=>r.jsx("div",{className:"plan-deletion-card",children:M===w.id?r.jsx("textarea",{ref:K,className:"plan-annotation-textarea",value:X,onChange:y=>O(y.target.value),onKeyDown:y=>{if(y.key==="Enter"&&(y.ctrlKey||y.metaKey)){y.preventDefault();const Z=X.trim();Z?ee(w.id,Z):q(w.id),B(null)}y.key==="Escape"&&(y.preventDefault(),B(null))},onBlur:()=>{const y=X.trim();y?ee(w.id,y):q(w.id),B(null)},rows:We(X),style:{fontSize:`${h}px`,flex:1}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{flex:1,fontSize:`${h}px`,color:"var(--accent-red)",whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>{B(w.id),O(w.selectedText),requestAnimationFrame(()=>{const y=K.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},title:"Double-click to edit",children:w.selectedText}),i&&(()=>{const y=T.current.has(w.id);return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!y&&Se(w.id,"del"),disabled:y,title:y?"Already sent":"Send to terminal",style:y?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>{B(w.id),O(w.selectedText),requestAnimationFrame(()=>{const y=K.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},style:{color:"var(--accent-blue)"},title:"Edit deletion annotation",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>q(w.id),title:"Remove deletion",children:"×"})]})},w.id)),g.replacements.filter(w=>w.tokenIndices.includes(b)&&w.tokenIndices[0]===b).map(w=>r.jsx("div",{className:"plan-replace-card",children:re===w.id?r.jsx("textarea",{ref:Te,className:"plan-annotation-textarea",value:be,onChange:y=>Ce(y.target.value),onKeyDown:y=>{if(y.key==="Enter"&&(y.ctrlKey||y.metaKey)){y.preventDefault();const Z=be.trim();Z?Je(w.id,Z):Oe(w.id),ne(null)}y.key==="Escape"&&(y.preventDefault(),ne(null))},onBlur:()=>{const y=be.trim();y?Je(w.id,y):Oe(w.id),ne(null)},rows:We(be),style:{fontSize:`${h}px`,flex:1}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{color:"var(--accent-blue)",flexShrink:0},children:"⇄"}),r.jsxs("span",{style:{flex:1,fontSize:`${h}px`,whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>{ne(w.id),Ce(w.content),requestAnimationFrame(()=>{const y=Te.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},title:"Double-click to edit",children:[r.jsx("span",{style:{color:"var(--accent-red)",textDecoration:"line-through"},children:w.selectedText}),r.jsx("span",{style:{color:"var(--text-secondary)"},children:" → "}),r.jsx("span",{style:{color:"var(--accent-blue)"},children:w.content})]}),i&&(()=>{const y=T.current.has(w.id);return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!y&&Se(w.id,"rep"),disabled:y,title:y?"Already sent":"Send to terminal",style:y?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>{ne(w.id),Ce(w.content),requestAnimationFrame(()=>{const y=Te.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},style:{color:"var(--accent-blue)"},title:"Edit replacement",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Oe(w.id),title:"Remove replacement",children:"×"})]})},w.id)),g.comments.filter(w=>w.tokenIndices.includes(b)&&w.tokenIndices[0]===b).map(w=>r.jsx("div",{className:"plan-comment-card",children:Be===w.id?r.jsx("textarea",{ref:me,className:"plan-annotation-textarea",value:ge,onChange:y=>Ie(y.target.value),onKeyDown:y=>{if(y.key==="Enter"&&(y.ctrlKey||y.metaKey)){y.preventDefault();const Z=ge.trim();Z?E(w.id,Z):x(w.id),ve(null)}y.key==="Escape"&&(y.preventDefault(),ve(null))},onBlur:()=>{const y=ge.trim();y?E(w.id,y):x(w.id),ve(null)},rows:We(ge),style:{fontSize:`${h}px`,flex:1}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{color:"var(--accent-green)",flexShrink:0},children:"?"}),r.jsxs("span",{style:{flex:1,fontSize:`${h}px`,whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>{ve(w.id),Ie(w.content),requestAnimationFrame(()=>{const y=me.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},title:"Double-click to edit",children:[r.jsxs("span",{style:{color:"var(--text-secondary)",fontStyle:"italic"},children:['"',w.selectedText,'"']}),r.jsx("span",{style:{color:"var(--text-secondary)"},children:": "}),r.jsx("span",{style:{color:"var(--accent-green)"},children:w.content})]}),i&&(()=>{const y=T.current.has(w.id);return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!y&&Se(w.id,"com"),disabled:y,title:y?"Already sent":"Send to terminal",style:y?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>{ve(w.id),Ie(w.content),requestAnimationFrame(()=>{const y=me.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},style:{color:"var(--accent-blue)"},title:"Edit comment",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>x(w.id),title:"Remove comment",children:"×"})]})},w.id)),Q&&Q.tokenIndices[0]===b&&r.jsxs("div",{className:Q.type==="replace"?"plan-replace-card":"plan-comment-card",style:{padding:"4px 8px"},children:[r.jsx("span",{style:{color:Q.type==="replace"?"var(--accent-blue)":"var(--accent-green)",flexShrink:0},children:Q.type==="replace"?"⇄":"?"}),r.jsx("textarea",{ref:P,className:"plan-annotation-textarea",value:he,onChange:w=>N(w.target.value),onKeyDown:w=>{if(w.key==="Enter"&&(w.ctrlKey||w.metaKey)){w.preventDefault(),De();return}if(w.key==="Escape"){w.preventDefault(),De();return}},onBlur:De,placeholder:Q.type==="replace"?"Replace with... (Ctrl+Enter to save)":"Comment... (Ctrl+Enter to save)",rows:We(he),style:{fontSize:`${h}px`,flex:1}})]}),!m&&r.jsx(_t,{index:b,active:_===b,additions:vt.get(b),onOpen:()=>{k(b),Y("")},onSubmit:()=>ye(b),onRemoveAddition:we,onEditAddition:Re,onSendSingle:i?w=>Se(w,"add"):void 0,isSent:w=>T.current.has(w),insertText:G,setInsertText:Y,textareaRef:_===b?J:void 0,expanded:f,fontSize:h})]},b)}),!m&&V&&r.jsxs("div",{className:"plan-selection-float",style:{top:V.y,left:V.x},children:[r.jsx("button",{className:"plan-selection-float__delete",onMouseDown:u=>{u.preventDefault(),Ne()},title:"Delete selection",children:"−"}),r.jsx("button",{className:"plan-selection-float__replace",onMouseDown:u=>{u.preventDefault(),ze("replace")},title:"Replace selection",children:"⇄"}),r.jsx("button",{className:"plan-selection-float__comment",onMouseDown:u=>{u.preventDefault(),ze("comment")},title:"Comment on selection",children:"?"})]})]}),r.jsx(Hr,{headings:$,scrollRef:te})]})]})});function _t({index:n,active:e,additions:t,onOpen:o,onSubmit:a,onRemoveAddition:c,onEditAddition:i,onSendSingle:d,isSent:l,insertText:f,setInsertText:m,textareaRef:p,expanded:h,alwaysShow:v,fontSize:C=14}){const[$,L]=s.useState(null),[T,g]=s.useState(""),z=s.useRef(null),R=ht(),W=ht();s.useEffect(()=>{$&&(R.clearUndo(),requestAnimationFrame(()=>{const S=z.current;S&&(S.focus(),S.selectionStart=S.selectionEnd=S.value.length)}))},[$]),s.useEffect(()=>{e&&W.clearUndo()},[e]);const D=s.useCallback(S=>{g(_=>(R.pushUndo(_),S))},[R]),U=s.useCallback(S=>{W.pushUndo(f),m(S)},[f,m,W]),H=s.useCallback(S=>{L(S.id),g(S.content)},[]),F=s.useCallback(()=>{if(!$)return;const S=T.trim();S?i($,S):c($),L(null),g("")},[$,T,i,c]),j=s.useCallback(()=>{L(null),g("")},[]);return r.jsxs("div",{className:`plan-insert-zone${v?" plan-insert-zone--empty":""}`,"data-zone-index":n,children:[t==null?void 0:t.map(S=>r.jsx("div",{className:"plan-annotation-card",children:$===S.id?r.jsx("textarea",{ref:z,className:"plan-annotation-textarea",value:T,onChange:_=>D(_.target.value),onKeyDown:_=>{if(_.key==="Enter"&&(_.ctrlKey||_.metaKey)){_.preventDefault(),F();return}if(_.key==="Escape"){_.preventDefault(),j();return}if(_.key==="Tab"){bt(_,D);return}},onBlur:F,rows:We(T),style:{fontSize:`${C}px`,flex:1,...h?{minWidth:300}:void 0}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{flex:1,fontSize:`${C}px`,color:"var(--accent-yellow)",whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>H(S),title:"Double-click to edit",children:S.content}),d&&(()=>{const _=(l==null?void 0:l(S.id))??!1;return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!_&&d(S.id),disabled:_,title:_?"Already sent":"Send to terminal",style:_?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>H(S),style:{color:"var(--accent-blue)"},title:"Edit annotation",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>c(S.id),children:"×"})]})},S.id)),e?r.jsx("div",{className:"plan-annotation-card plan-annotation-card--editing",children:r.jsx("textarea",{ref:p,className:"plan-annotation-textarea",value:f,onChange:S=>U(S.target.value),onKeyDown:S=>{if(S.key==="Enter"&&(S.ctrlKey||S.metaKey)){S.preventDefault(),a();return}if(S.key==="Escape"){S.preventDefault(),a();return}if(S.key==="Tab"){bt(S,U);return}},placeholder:"Add annotation... (Ctrl+Enter or Esc to save)",rows:We(f),style:{fontSize:`${C}px`,...h?{minWidth:300}:void 0}})}):v&&!(t!=null&&t.length)?r.jsx("div",{className:"plan-empty-placeholder",onDoubleClick:o,title:"Double-click or Ctrl+Enter to edit",children:"Write down your plans here. Double-click or Ctrl+Enter to edit."}):r.jsx("button",{className:"plan-insert-btn",onClick:o,title:"Add annotation here",children:"+"})]})}async function ke(n,e,t){const o=t?`?path=${encodeURIComponent(t)}`:"",a=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/files${o}`,{headers:le(n)});if(!a.ok)throw new Error("Failed to list files");return a.json()}function Yr(n,e,t,o){return new Promise((a,c)=>{const i=new FormData;for(const l of t)i.append("files",l);const d=new XMLHttpRequest;d.open("POST",`${oe}/api/sessions/${encodeURIComponent(e)}/upload`),d.setRequestHeader("Authorization",`Bearer ${n}`),d.upload.addEventListener("progress",l=>{l.lengthComputable&&o&&o(Math.round(l.loaded/l.total*100))}),d.addEventListener("load",()=>{d.status>=200&&d.status<300?a():c(new Error(`Upload failed: ${d.status}`))}),d.addEventListener("error",()=>c(new Error("Upload network error"))),d.addEventListener("abort",()=>c(new Error("Upload aborted"))),d.send(i)})}async function Gr(n,e){const t=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/cwd`,{headers:le(n)});if(!t.ok)throw new Error("Failed to fetch cwd");return(await t.json()).cwd}async function xt(n,e,t){const o=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/touch`,{method:"POST",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({name:t})});if(!o.ok)throw new Error("Failed to create file");return o.json()}async function an(n,e,t){const o=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/mkdir`,{method:"POST",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!o.ok)throw new Error("Failed to create directory");return o.json()}async function Xr(n,e,t){if(!(await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/rm`,{method:"DELETE",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({path:t})})).ok)throw new Error("Failed to delete")}async function Zr(n,e){const t=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/download-cwd`,{headers:le(n)});if(!t.ok)throw new Error("Download failed");const o=await t.blob(),a=URL.createObjectURL(o),c=document.createElement("a");c.href=a;const i=t.headers.get("Content-Disposition"),d=i==null?void 0:i.match(/filename="(.+)"/);c.download=d?decodeURIComponent(d[1]):"cwd.tar.gz",document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(a)}async function Qr(n,e,t){const o=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/download?path=${encodeURIComponent(t)}`,{headers:le(n)});if(!o.ok)throw new Error("Download failed");const a=await o.blob(),c=URL.createObjectURL(a),i=document.createElement("a");i.href=c,i.download=t.split("/").pop()||"download",document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(c)}function ln(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:n<1024*1024*1024?`${(n/(1024*1024)).toFixed(1)} MB`:`${(n/(1024*1024*1024)).toFixed(1)} GB`}function eo(n,e){if(e==="directory")return"📁";const t=n.slice(n.lastIndexOf(".")).toLowerCase();return t===".pdf"?"📕":t===".html"||t===".htm"?"🌐":t===".md"?"📝":"📄"}function cn(n){const e=new Date(n*1e3),t=o=>String(o).padStart(2,"0");return`${t(e.getMonth()+1)}-${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}`}function to({sessionId:n,token:e,planDir:t,selectedFile:o,onSelectFile:a,onCreateFile:c,onDeleteFile:i}){const[d,l]=s.useState([]),[f,m]=s.useState(!0),[p,h]=s.useState(""),[v,C]=s.useState(!1),$=s.useRef(null),[L,T]=s.useState(t),g=s.useCallback(async()=>{if(!(!e||!L)){m(!0);try{const G=(await ke(e,n,L)).files.filter(Y=>Y.type==="file"&&Y.name.toLowerCase().endsWith(".md")||Y.type==="directory").sort((Y,J)=>{const M=Y.type==="file"&&Y.name===".index.md",B=J.type==="file"&&J.name===".index.md";return M&&!B?-1:!M&&B?1:Y.type==="directory"&&J.type!=="directory"?-1:Y.type!=="directory"&&J.type==="directory"?1:Y.name.localeCompare(J.name)});l(G)}catch{l([])}finally{m(!1)}}},[e,n,L]);s.useEffect(()=>{g()},[g]),s.useEffect(()=>{const k=setInterval(g,5e3);return()=>clearInterval(k)},[g]);const z=s.useCallback(()=>{const k=t.substring(0,t.lastIndexOf("/")+1);return L.startsWith(k)?L.substring(k.length):L},[t,L]),R=s.useCallback(async()=>{const k=p.trim();if(!k)return;const G=k.endsWith(".md")?k:`${k}.md`;C(!0);try{const Y=await xt(e,n,`${z()}/${G}`);Y.ok&&(h(""),await g(),c(Y.path))}catch{}finally{C(!1)}},[p,e,n,z,g,c]),W=s.useCallback(async()=>{const k=p.trim().replace(/\/+$/,"");if(k){C(!0);try{await an(e,n,`${z()}/${k}`),h(""),await g()}catch{}finally{C(!1)}}},[p,e,n,z,g]),D=s.useCallback(async k=>{const G=`${L}/${k.name}`,Y=k.type==="directory"?`folder "${k.name}" and all its contents`:`"${k.name}"`;if(window.confirm(`Delete ${Y}?`))try{await Xr(e,n,G),i==null||i(G),await g()}catch{}},[e,n,L,g,i]),U=s.useCallback(k=>{T(G=>`${G}/${k}`)},[]),H=s.useCallback(()=>{L!==t&&T(k=>k.substring(0,k.lastIndexOf("/")))},[L,t]),F=t.split("/").pop()||"TASK",j=(()=>{const k=t.split("/");return k.length>=2?k[k.length-2]+"/":""})(),S=L===t?j+F+"/":j+F+"/"+L.substring(t.length+1)+"/",_=o?o.split("/").pop():null;return r.jsxs("div",{className:"plan-file-browser",children:[r.jsxs("div",{className:"plan-file-browser__header",children:[r.jsx("span",{className:"plan-file-browser__title",title:S,children:S}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:g,title:"Refresh file list",style:{fontSize:12},children:"↻"})]}),r.jsxs("div",{className:"plan-file-browser__create",children:[r.jsx("input",{ref:$,className:"plan-file-browser__input",value:p,onChange:k=>h(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),R())},placeholder:"name",disabled:v}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:R,disabled:v||!p.trim(),title:"Create new .md file",style:p.trim()?{color:"var(--accent-green)",fontWeight:700,fontSize:14}:{opacity:.4,fontWeight:700,fontSize:14},children:"+"}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:W,disabled:v||!p.trim(),title:"Create new folder",style:p.trim()?{color:"var(--accent-blue)"}:{opacity:.4},children:"📁"})]}),r.jsxs("div",{className:"plan-file-browser__list",children:[f&&d.length===0&&r.jsx("div",{className:"plan-file-browser__status",children:"Loading..."}),!f&&d.length===0&&r.jsx("div",{className:"plan-file-browser__status",children:"No .md files"}),L!==t&&r.jsxs("div",{className:"plan-file-browser__item",onClick:H,title:"Go up to parent directory",style:{cursor:"pointer"},children:[r.jsx("span",{className:"plan-file-browser__icon",style:{color:"var(--accent-blue)"},children:"←"}),r.jsx("span",{className:"plan-file-browser__name",style:{color:"var(--accent-blue)"},children:".."})]}),d.map(k=>{const G=`${L}/${k.name}`,Y=k.type==="file"&&k.name===_,J=k.type==="directory";return r.jsxs("div",{className:`plan-file-browser__item${Y?" plan-file-browser__item--active":""}`,onClick:()=>J?U(k.name):a(G),title:J?`Open folder ${k.name}`:k.name,style:{cursor:"pointer"},children:[r.jsx("span",{className:"plan-file-browser__icon",children:J?"📁":k.name===".index.md"?"🔒":"□"}),r.jsxs("span",{className:"plan-file-browser__name",children:[k.name,J?"/":""]}),!J&&r.jsx("span",{className:"plan-file-browser__size",children:ln(k.size)}),k.name!==".index.md"&&r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm plan-file-browser__delete",onClick:M=>{M.stopPropagation(),D(k)},title:`Delete ${k.name}`,children:"×"})]},k.name)})]})]})}const pt={status:"idle",mode:"lines",lines:[],content:"",buffer:null,totalSize:0,receivedBytes:0,mtime:0,error:null},no=200;function ro(){const[n,e]=s.useState(pt),t=s.useRef("lines"),o=s.useRef([]),a=s.useRef(""),c=s.useRef(""),i=s.useRef([]),d=s.useRef(0),l=s.useRef(0),f=s.useRef(null),m=s.useRef(null),p=s.useCallback(()=>{const T=t.current;e(g=>({...g,receivedBytes:d.current,...T==="lines"?{lines:[...o.current]}:{},...T==="content"?{content:c.current}:{}}))},[]),h=s.useCallback(()=>{f.current===null&&(f.current=window.setTimeout(()=>{f.current=null,p()},no))},[p]),v=s.useCallback(T=>{t.current=T,o.current=[],a.current="",c.current="",i.current=[],d.current=0,l.current=0,m.current=new TextDecoder,f.current!==null&&(clearTimeout(f.current),f.current=null),e({...pt,mode:T,status:"streaming"})},[]),C=s.useCallback(T=>{d.current+=T.length;const g=t.current;if(g==="lines"){const R=m.current.decode(T,{stream:!0}).split(`
|
|
29
|
+
`);R[0]=a.current+R[0],a.current=R.pop(),R.length>0&&o.current.push(...R)}else if(g==="content"){const z=m.current.decode(T,{stream:!0});c.current+=z}else i.current.push(new Uint8Array(T));h()},[h]),$=s.useCallback(T=>{switch(T.type){case"file-stream-start":l.current=T.size,e(g=>({...g,totalSize:T.size,mtime:T.mtime}));break;case"file-stream-end":{f.current!==null&&(clearTimeout(f.current),f.current=null);const g=t.current;let z=o.current,R=c.current,W=null;if(g==="lines"){const D=m.current.decode(),U=a.current+D;U&&(z=[...z,U],o.current=z),a.current=""}else if(g==="content"){const D=m.current.decode();R=c.current+D,c.current=R}else{const D=i.current.reduce((H,F)=>H+F.length,0);W=new Uint8Array(D);let U=0;for(const H of i.current)W.set(H,U),U+=H.length;i.current=[]}e({status:"complete",mode:g,lines:g==="lines"?[...z]:[],content:g==="content"?R:"",buffer:g==="binary"?W:null,totalSize:l.current,receivedBytes:d.current,mtime:0,error:null});break}case"file-stream-error":f.current!==null&&(clearTimeout(f.current),f.current=null),e(g=>({...g,status:"error",error:T.error}));break}},[]),L=s.useCallback(()=>{f.current!==null&&(clearTimeout(f.current),f.current=null),o.current=[],a.current="",c.current="",i.current=[],d.current=0,l.current=0,m.current=null,e(pt)},[]);return{state:n,startStream:v,handleChunk:C,handleControl:$,reset:L}}function Ot({label:n,percent:e}){return r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:8},children:[r.jsx("span",{style:{color:"var(--text-secondary)",fontSize:13},children:n}),e!=null&&r.jsxs("div",{style:{width:120,display:"flex",alignItems:"center",gap:6},children:[r.jsx("div",{style:{flex:1,height:4,backgroundColor:"var(--border)",borderRadius:2,overflow:"hidden"},children:r.jsx("div",{style:{height:"100%",width:`${e}%`,backgroundColor:"var(--accent-blue)",transition:"width 0.2s"}})}),r.jsxs("span",{style:{fontSize:10,color:"var(--text-secondary)",whiteSpace:"nowrap"},children:[e,"%"]})]})]})}function oo({sessionId:n,token:e,connected:t,onRequestFileStream:o,onForwardToChat:a,onSendToTerminal:c}){const i=ro(),[d,l]=s.useState(!1),f=s.useRef(""),[m,p]=s.useState(null),[h,v]=s.useState(null),[C,$]=s.useState(""),[L,T]=s.useState(!1),g=s.useRef(new Map),z=s.useRef(null),R=s.useRef(null);s.useEffect(()=>{R.current=null;let M=!1;return T(!0),(async()=>{try{const B=await ke(e,n);if(M)return;if(B.files.find(O=>O.name==="TASK"&&O.type==="directory")){const O=B.cwd+"/TASK",K=await ke(e,n,O);if(M)return;const re=K.files.find(ne=>ne.name===".index.md");if(re)p(O),v(O+"/"+re.name);else try{const ne=await xt(e,n,"TASK/.index.md");if(M)return;p(O),ne.ok&&v(ne.path)}catch{p(O)}}else try{const O=await an(e,n,"TASK");if(M)return;p(O.path);const K=await xt(e,n,"TASK/.index.md");if(M)return;K.ok&&v(K.path)}catch{p(null),v(null)}}catch{p(null)}finally{M||T(!1)}try{const B=await ke(e,n);if(M)return;const X=B.home||"";if(f.current=B.cwd,X){const O=`${X}/.claude/commands`;try{const K=await ke(e,n,O);if(M)return;K.files.some(ne=>ne.name==="aicli-task-review.md")||l(!0)}catch{M||l(!0)}}}catch{}})(),()=>{M=!0}},[n,e]),s.useEffect(()=>(pr(n,i.handleChunk,i.handleControl),()=>mr(n)),[n,i.handleChunk,i.handleControl]),s.useEffect(()=>{!h||!t||R.current===h&&C||(R.current=h,i.reset(),i.startStream("content"),o==null||o(h))},[h,t]),s.useEffect(()=>{i.state.status==="complete"&&h&&($(i.state.content),g.current.set(h,i.state.content))},[i.state.status,i.state.content,h]);const W=s.useRef(new Map),D=s.useCallback(()=>{var B,X;if(!h)return;const M=((X=(B=z.current)==null?void 0:B.getScrollTop)==null?void 0:X.call(B))??0;M>0&&W.current.set(h,M)},[h]);s.useEffect(()=>{if(!h||!C)return;const M=W.current.get(h);M!=null&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{var B,X;(X=(B=z.current)==null?void 0:B.setScrollTop)==null||X.call(B,M)})})},[h,C]);const U=s.useCallback(M=>{M!==h&&(D(),h&&C&&g.current.set(h,C),v(M),$(""),R.current=null)},[h,C,D]),H=s.useCallback(M=>{h&&(h===M||h.startsWith(M+"/"))&&(v(null),$(""),R.current=null),g.current.delete(M)},[h]),F=s.useCallback(M=>{v(M),$(""),R.current=null},[]),j=s.useCallback(M=>{M&&(a==null||a(M))},[a]),S=s.useCallback(()=>{D(),h&&C&&g.current.set(h,C),v(null),$(""),R.current=null},[h,C,D]),_=s.useCallback(()=>{!h||!t||(R.current=null,$(""),i.reset(),i.startStream("content"),o==null||o(h),R.current=h)},[h,t,i,o]),[k,G]=s.useState(()=>{const M=localStorage.getItem(`plan-fb-width-${n}`);if(M){const B=Number(M);if(Number.isFinite(B)&&B>=60&&B<=300)return B}return 130}),Y=s.useRef(k);if(k!==Y.current){Y.current=k;try{localStorage.setItem(`plan-fb-width-${n}`,String(Math.round(k)))}catch{}}const J=s.useCallback(M=>{M.preventDefault();const B=M.clientX,X=k;document.body.classList.add("resizing-panes");const O=re=>{const ne=re.clientX-B;G(Math.min(300,Math.max(60,X+ne)))},K=()=>{document.body.classList.remove("resizing-panes"),document.removeEventListener("mousemove",O),document.removeEventListener("mouseup",K)};document.addEventListener("mousemove",O),document.addEventListener("mouseup",K)},[k]);return r.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[d&&r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 10px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",fontSize:12,flexShrink:0},children:[r.jsx("span",{style:{color:"var(--accent-yellow)",flex:1},children:"/aicli-task-review command not installed"}),r.jsx("button",{className:"pane-btn",style:{color:"var(--accent-green)",fontSize:11},onClick:()=>{const M=f.current;M&&c&&c(`mkdir -p ~/.claude/commands && cp ${M}/.commands/*.md ~/.claude/commands/`),l(!1)},children:"Install"}),r.jsx("button",{className:"pane-btn",style:{fontSize:11},onClick:()=>l(!1),children:"×"})]}),r.jsxs("div",{className:"plan-overlay-body",children:[m&&r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{width:k,flexShrink:0,overflow:"hidden"},children:r.jsx(to,{sessionId:n,token:e,planDir:m,selectedFile:h,onSelectFile:U,onCreateFile:F,onDeleteFile:H})}),r.jsx("div",{onMouseDown:J,style:{width:2,flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:M=>{M.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:M=>{M.currentTarget.style.backgroundColor="var(--border)"}})]}),r.jsx("div",{className:"plan-overlay-center",children:L?r.jsx(Ot,{label:"Loading TASK/..."}):h&&!C&&(i.state.status==="streaming"||i.state.status==="idle")?r.jsx(Ot,{label:`Loading ${h.split("/").pop()}...`,percent:i.state.totalSize>0?Math.round(i.state.receivedBytes/i.state.totalSize*100):void 0}):h?r.jsx(Vr,{ref:z,markdown:C,filePath:h,sessionId:n,token:e,onExecute:j,onSend:c,onRefresh:_,onClose:S,readOnly:h.endsWith("/.index.md")}):r.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:8},children:r.jsx("span",{style:{color:"var(--text-secondary)",fontSize:13,fontStyle:"italic"},children:"Select a file from the left panel"})})})]})]})}async function so(n,e){try{const t=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/draft`,{headers:le(n)});return t.ok?(await t.json()).content??"":""}catch{return""}}async function Ft(n,e,t){try{await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/draft`,{method:"PUT",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({content:t})})}catch{}}const yt="chat-history",Pt=50;function dn(){try{const n=localStorage.getItem(yt);return n?JSON.parse(n):[]}catch{return[]}}function ao(n){const t=dn().filter(o=>o.text!==n);t.unshift({text:n,ts:Date.now()}),t.length>Pt&&(t.length=Pt),localStorage.setItem(yt,JSON.stringify(t))}const Bt=[{cmd:"/history",desc:"Browse sent message history"},{cmd:"/plan",desc:"Enter plan mode"},{cmd:"/help",desc:"Get help"},{cmd:"/compact",desc:"Compact conversation"},{cmd:"/clear",desc:"Clear conversation"},{cmd:"/model",desc:"Switch model"},{cmd:"/cost",desc:"Show token usage"},{cmd:"/status",desc:"Show status"},{cmd:"/init",desc:"Initialize project CLAUDE.md"},{cmd:"/memory",desc:"Edit memory files"},{cmd:"/review",desc:"Review code"},{cmd:"/bug",desc:"Report a bug"},{cmd:"/login",desc:"Login to Anthropic"},{cmd:"/doctor",desc:"Run diagnostics"},{cmd:"/permissions",desc:"Manage permissions"},{cmd:"/mcp",desc:"MCP server management"},{cmd:"/terminal-setup",desc:"Configure terminal"},{cmd:"/vim",desc:"Toggle vim mode"},{cmd:"/oh-my-claudecode:autopilot",desc:"Full autonomous execution"},{cmd:"/oh-my-claudecode:ralph",desc:"Persistence loop until done"},{cmd:"/oh-my-claudecode:ultrawork",desc:"Max parallel execution"},{cmd:"/oh-my-claudecode:ecomode",desc:"Token-efficient execution"},{cmd:"/oh-my-claudecode:plan",desc:"Strategic planning session"},{cmd:"/oh-my-claudecode:ralplan",desc:"Iterative planning consensus"},{cmd:"/oh-my-claudecode:ultrapilot",desc:"Parallel autopilot (3-5x faster)"},{cmd:"/oh-my-claudecode:analyze",desc:"Deep analysis/investigation"},{cmd:"/oh-my-claudecode:deepsearch",desc:"Thorough codebase search"},{cmd:"/oh-my-claudecode:deepinit",desc:"Generate AGENTS.md hierarchy"},{cmd:"/oh-my-claudecode:ultraqa",desc:"QA cycling: test/fix/repeat"},{cmd:"/oh-my-claudecode:tdd",desc:"Test-driven development"},{cmd:"/oh-my-claudecode:code-review",desc:"Comprehensive code review"},{cmd:"/oh-my-claudecode:security-review",desc:"Security vulnerability review"},{cmd:"/oh-my-claudecode:build-fix",desc:"Fix build/TypeScript errors"},{cmd:"/oh-my-claudecode:research",desc:"Parallel research orchestration"},{cmd:"/oh-my-claudecode:swarm",desc:"N coordinated agents"},{cmd:"/oh-my-claudecode:pipeline",desc:"Sequential agent chaining"},{cmd:"/oh-my-claudecode:learner",desc:"Extract skill from session"},{cmd:"/oh-my-claudecode:note",desc:"Save notes to notepad"},{cmd:"/oh-my-claudecode:cancel",desc:"Cancel active OMC mode"},{cmd:"/oh-my-claudecode:help",desc:"OMC usage guide"},{cmd:"/oh-my-claudecode:doctor",desc:"Diagnose OMC issues"},{cmd:"/oh-my-claudecode:omc-setup",desc:"One-time OMC setup"},{cmd:"/oh-my-claudecode:hud",desc:"Configure HUD statusline"},{cmd:"/oh-my-claudecode:release",desc:"Automated release workflow"},{cmd:"/oh-my-claudecode:ralph-init",desc:"Initialize PRD for ralph"},{cmd:"/oh-my-claudecode:review",desc:"Review plan with Critic"},{cmd:"/oh-my-claudecode:git-master",desc:"Git expert for commits"},{cmd:"/oh-my-claudecode:mcp-setup",desc:"Configure MCP servers"},{cmd:"/oh-my-claudecode:skill",desc:"Manage local skills"},{cmd:"/oh-my-claudecode:writer-memory",desc:"Writer memory system"},{cmd:"/oh-my-claudecode:psm",desc:"Project session manager"},{cmd:"/oh-my-claudecode:trace",desc:"Agent flow trace timeline"},{cmd:"/plan-analyzer",desc:"Task complexity grading & token routing"}],io=s.forwardRef(function({onSend:e,onContentChange:t,sessionId:o,token:a},c){const i=A(x=>x.fontSize),[d,l]=s.useState(""),f=s.useRef(null),m=s.useRef(void 0),p=s.useRef(!1),h=s.useRef(!1),{pushUndo:v,popUndo:C}=ht(),$=s.useRef(d);$.current=d;const L=s.useCallback(()=>v($.current),[v]),[T,g]=s.useState(!1),[z,R]=s.useState(""),[W,D]=s.useState(0),[U,H]=s.useState(!1),[F,j]=s.useState([]),[S,_]=s.useState(0),[k,G]=s.useState(""),Y=s.useRef(null),J=s.useMemo(()=>{if(!k)return F;const x=k.toLowerCase();return F.filter(E=>E.text.toLowerCase().includes(x))},[F,k]),[M,B]=s.useState(!1),[X,O]=s.useState(""),[K,re]=s.useState(""),[ne,be]=s.useState(0),[Ce,Te]=s.useState([]),[Be,ve]=s.useState(!1),ge=s.useRef(""),Ie=s.useRef(null),me=s.useMemo(()=>{if(!z)return Bt;const x=z.toLowerCase();return Bt.filter(E=>E.cmd.toLowerCase().includes(x)||E.desc.toLowerCase().includes(x))},[z]),Q=s.useMemo(()=>{let x=Ce;if(X){const E=X.toLowerCase();x=x.filter(q=>q.name.toLowerCase().includes(E))}return[...x].sort((E,q)=>E.type==="directory"&&q.type!=="directory"?-1:E.type!=="directory"&&q.type==="directory"?1:E.name.localeCompare(q.name))},[Ce,X]),Ae=A(x=>x.latency),he=`chat-draft-${o}`,N=s.useRef(!1),P=s.useRef(void 0);s.useEffect(()=>{try{const E=localStorage.getItem(he);E&&!h.current&&l(E)}catch{}let x=!1;return so(a,o).then(E=>{if(x||h.current){p.current=!0;return}if(E){l(E);try{localStorage.setItem(he,E)}catch{}}p.current=!0}).catch(()=>{p.current=!0}),()=>{x=!0}},[a,o,he]),s.useEffect(()=>{if(!p.current)return;m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{try{localStorage.setItem(he,d)}catch{}},50),P.current&&clearTimeout(P.current);const x=Math.max(200,(Ae??30)*3);return P.current=setTimeout(()=>{N.current||(N.current=!0,Ft(a,o,d).catch(()=>{}).finally(()=>{N.current=!1}))},x),()=>{m.current&&clearTimeout(m.current),P.current&&clearTimeout(P.current)}},[d,a,o,Ae,he]),s.useEffect(()=>{var x;(x=f.current)==null||x.focus()},[]),s.useEffect(()=>{if(!M)return;let x=!1;return ve(!0),(async()=>{try{if(K){if(!ge.current){const ee=await ke(a,o);if(x)return;ge.current=ee.cwd}const E=`${ge.current}/${K.replace(/\/$/,"")}`,q=await ke(a,o,E);if(x)return;Te(q.files)}else{const E=await ke(a,o);if(x)return;ge.current=E.cwd,Te(E.files)}ve(!1)}catch{if(x)return;Te([]),ve(!1)}})(),()=>{x=!0}},[M,K,a,o]),s.useEffect(()=>{if(!M||!Ie.current)return;const x=Ie.current.querySelector(".file-item--active");x==null||x.scrollIntoView({block:"nearest"})},[ne,M]);const V=s.useCallback(()=>{const x=$.current.trim();if(x){ao(x),e(x),l("");try{localStorage.removeItem(he)}catch{}Ft(a,o,"").catch(()=>{})}},[e,a,o,he]),ie=s.useCallback(x=>{L(),l(x),h.current=!0},[L]),te=s.useCallback(x=>{const E=f.current;L();const q=$.current;if(E){const ee=E.selectionStart,se=E.selectionEnd,xe=q.slice(0,ee)+x+q.slice(se);l(xe);const ae=ee+x.length;requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=ae,E.focus()})}else l(q+x)},[L]);s.useImperativeHandle(c,()=>({send:V,fillContent:ie,insertAtCursor:te}),[V,ie,te]),s.useEffect(()=>{t==null||t(d.trim().length>0)},[d,t]);const ye=s.useCallback(()=>{const x=f.current;if(!x)return;const{selectionStart:E,selectionEnd:q}=x;if(E!==q){const ee=x.value.substring(E,q);ee&&navigator.clipboard.writeText(ee).catch(()=>{})}},[]),we=s.useCallback(()=>{const x=dn();g(!1),R("");const E=f.current;if(E){const q=E.selectionStart,ee=d.slice(0,q),se=d.slice(q),xe=ee.match(/(?:^|\s)(\/history)\s*$/);if(xe){const ae=ee.length-xe[1].length;l(d.slice(0,ae)+se)}}x.length!==0&&(j(x),_(0),G(""),H(!0))},[d]),Re=s.useCallback(x=>{L(),l(x.text),H(!1),requestAnimationFrame(()=>{const E=f.current;E&&(E.selectionStart=E.selectionEnd=x.text.length,E.focus())})},[L]),Ne=s.useCallback(x=>{const E=J[x];if(!E)return;const q=F.filter(se=>se.ts!==E.ts||se.text!==E.text);j(q),localStorage.setItem(yt,JSON.stringify(q));const ee=k?q.filter(se=>se.text.toLowerCase().includes(k.toLowerCase())):q;S>=ee.length&&_(Math.max(0,ee.length-1))},[J,F,S,k]);s.useEffect(()=>{if(!U||!Y.current)return;const x=Y.current.querySelector(".history-item--active");x==null||x.scrollIntoView({block:"nearest"})},[S,U]);const ze=s.useCallback(x=>{if(x==="/history"){we();return}const E=f.current;if(!E)return;L();const q=E.selectionStart,ee=d.slice(0,q),se=d.slice(q),ae=ee.lastIndexOf(`
|
|
30
|
+
`)+1,fe=ee.slice(ae).match(/\/[a-zA-Z:-]*$/);if(fe){const ce=ae+(fe.index??0),Le=x+" ",Fe=d.slice(0,ce)+Le+se;l(Fe);const Se=ce+Le.length;requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=Se,E.focus()})}else{const ce=ee+x+se;l(ce);const Le=q+x.length;requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=Le,E.focus()})}g(!1),R(""),D(0)},[d,L,we]),De=s.useCallback(x=>{const E=f.current;if(!E)return;L();const q=E.selectionStart,ee=d.slice(0,q),se=d.slice(q),xe=ee.match(/@([a-zA-Z0-9_.\-/]*)$/);if(!xe)return;const ae=ee.length-xe[0].length;if(x.type==="directory"){const de="@"+K+x.name+"/",fe=d.slice(0,ae)+de+se;l(fe);const ce=ae+de.length;re(K+x.name+"/"),O(""),be(0),requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=ce,E.focus()})}else{const de=x.name+" ",fe=d.slice(0,ae)+de+se;l(fe);const ce=ae+de.length;B(!1),O(""),re(""),be(0),Te([]),ge.current="",requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=ce,E.focus()})}},[d,K,L]),Oe=s.useCallback(x=>{const E=x.target.value;if(l(E),U){const de=E.trim();de?(G(de),_(0)):G("");return}const q=x.target.selectionStart,ee=E.slice(0,q),se=ee.lastIndexOf(`
|
|
31
|
+
`),ae=ee.slice(se+1).match(/(?:^|\s)\/([a-zA-Z:-]*)$/);if(ae)g(!0),R(ae[1]),D(0),B(!1);else{g(!1);const de=ee.match(/@([a-zA-Z0-9_.\-/]*)$/);if(de){const fe=de[1],ce=fe.lastIndexOf("/"),Le=ce>=0?fe.slice(0,ce+1):"",Fe=ce>=0?fe.slice(ce+1):fe;O(Fe),be(0),re(Le),B(!0)}else B(!1)}},[U]),Je=s.useCallback(x=>{if(T&&me.length>0){if(x.key==="ArrowDown"){x.preventDefault(),D(E=>(E+1)%me.length);return}if(x.key==="ArrowUp"){x.preventDefault(),D(E=>(E-1+me.length)%me.length);return}if(x.key==="Enter"||x.key==="Tab"){x.preventDefault(),ze(me[W].cmd);return}if(x.key==="Escape"){x.preventDefault(),g(!1);return}}if(M&&Q.length>0){if(x.key==="ArrowDown"){x.preventDefault(),be(E=>(E+1)%Q.length);return}if(x.key==="ArrowUp"){x.preventDefault(),be(E=>(E-1+Q.length)%Q.length);return}if(x.key==="Tab"||x.key==="Enter"){x.preventDefault(),De(Q[ne]);return}if(x.key==="Escape"){x.preventDefault(),B(!1);return}}if(U&&J.length>0){if(x.key==="ArrowDown"){x.preventDefault(),_(E=>(E+1)%J.length);return}if(x.key==="ArrowUp"){x.preventDefault(),_(E=>(E-1+J.length)%J.length);return}if(x.key==="Enter"){x.preventDefault(),Re(J[S]);return}if(x.key==="Delete"||x.key==="Backspace"&&(x.ctrlKey||x.metaKey)){x.preventDefault(),Ne(S);return}if(x.key==="Escape"){x.preventDefault(),H(!1);return}}if(x.key==="Tab"){bt(x,l,v);return}x.key==="Enter"&&(x.ctrlKey||x.metaKey)&&(x.preventDefault(),V())},[V,T,me,W,ze,M,Q,ne,De,v,C,U,J,S,Re,Ne]);return r.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[T&&me.length>0&&r.jsx("div",{className:"slash-dropdown",children:me.map((x,E)=>r.jsxs("div",{className:`slash-item${E===W?" slash-item--active":""}`,onMouseDown:q=>{q.preventDefault(),ze(x.cmd)},onMouseEnter:()=>D(E),children:[r.jsx("span",{className:"slash-cmd",children:x.cmd}),r.jsx("span",{className:"slash-desc",children:x.desc})]},x.cmd))}),M&&(Be||Q.length>0)&&r.jsx("div",{className:"file-dropdown",ref:Ie,children:Be?r.jsx("div",{className:"file-item file-loading",children:"Loading..."}):Q.map((x,E)=>r.jsxs("div",{className:`file-item${E===ne?" file-item--active":""}`,onMouseDown:q=>{q.preventDefault(),De(x)},onMouseEnter:()=>be(E),children:[r.jsx("span",{className:"file-icon",children:x.type==="directory"?"📁":"📄"}),r.jsx("span",{className:"file-name",children:x.name})]},x.name))}),U&&r.jsx("div",{className:"history-dropdown",ref:Y,children:J.length===0?r.jsx("div",{className:"history-item history-empty",children:"No history yet"}):J.map((x,E)=>r.jsxs("div",{className:`history-item${E===S?" history-item--active":""}`,onMouseDown:q=>{q.preventDefault(),Re(x)},onMouseEnter:()=>_(E),children:[r.jsx("span",{className:"history-text",children:x.text.length>120?x.text.slice(0,120)+"...":x.text}),r.jsx("span",{className:"history-time",children:new Date(x.ts).toLocaleString()}),r.jsx("button",{className:"history-delete",onMouseDown:q=>{q.preventDefault(),q.stopPropagation(),Ne(E)},title:"Delete (Del key)",children:"×"})]},`${x.ts}-${E}`))}),r.jsx("textarea",{ref:f,className:"md-editor-textarea",value:d,onChange:Oe,onKeyDown:Je,onMouseUp:ye,placeholder:"Type / for commands, @ for files, Ctrl+Enter to send",spellCheck:!1,style:{flex:1,fontSize:`${i}px`}})]})}),lo=600,Ue=typeof window<"u"?window.matchMedia(`(max-width: ${lo-1}px)`):null;function co(){const[n,e]=s.useState(()=>(Ue==null?void 0:Ue.matches)??!1);return s.useEffect(()=>{if(!Ue)return;const t=o=>e(o.matches);return Ue.addEventListener("change",t),()=>Ue.removeEventListener("change",t)},[]),n}const uo=s.memo(function({terminal:e}){const t=co(),o=A(N=>N.splitTerminal),a=A(N=>N.token),c=A(N=>N.toggleChat),i=A(N=>N.togglePlan),{chatOpen:d,planOpen:l}=e.panels,f=s.useCallback(async N=>{let P;if(a)try{P=await Gr(a,e.id)}catch{}o(e.id,N,P)},[a,e.id,o]),m=s.useRef(null),p=s.useRef(null),h=s.useRef(null),[v,C]=s.useState(!1),[$,L]=s.useState(0),[T,g]=s.useState(!1),[z,R]=s.useState(!1),[W,D]=s.useState(!1),[U,H]=s.useState([]),[F,j]=s.useState(""),[S,_]=s.useState([]),[k,G]=s.useState(!1),Y=s.useRef(null),J=s.useRef(null),M=s.useRef(null),[B,X]=s.useState(()=>{const N=localStorage.getItem(`plan-width-${e.id}`);if(N){const P=Number(N);if(Number.isFinite(P)&&P>=20&&P<=80)return P}return 50}),O=s.useRef(B);if(B!==O.current){O.current=B;try{localStorage.setItem(`plan-width-${e.id}`,String(Math.round(B)))}catch{}}const[K,re]=s.useState(()=>{const N=localStorage.getItem(`doc-height-${e.id}`);if(N){const P=Number(N);if(Number.isFinite(P)&&P>=15&&P<=60)return P}return 35}),ne=s.useRef(K);if(K!==ne.current){ne.current=K;try{localStorage.setItem(`doc-height-${e.id}`,String(Math.round(K)))}catch{}}const be=async N=>{const P=N.target.files;if(!(!P||P.length===0||!a)){C(!0),L(0);try{await Yr(a,e.id,P,V=>{L(V)})}catch(V){alert(`Upload failed: ${V instanceof Error?V.message:"Unknown error"}`)}finally{C(!1),L(0),m.current&&(m.current.value="")}}},Ce=s.useRef(void 0),Te=s.useCallback(N=>{if(p.current){const P=N.replace(/\r?\n/g," ").trimEnd();p.current.sendInput(P),Ce.current=window.setTimeout(()=>{var V;return(V=p.current)==null?void 0:V.sendInput("\r")},50)}},[]);s.useEffect(()=>()=>{Ce.current&&clearTimeout(Ce.current)},[]);const Be=s.useCallback(async()=>{if(a){G(!0),D(!0);try{const N=await ke(a,e.id);j(N.cwd),H(N.files),_([])}catch{D(!1)}finally{G(!1)}}},[a,e.id]),ve=s.useCallback(async N=>{if(a){G(!0);try{const P=await ke(a,e.id,N);_(V=>[...V,F]),j(N),H(P.files)}catch{}finally{G(!1)}}},[a,e.id,F]),ge=s.useCallback(async()=>{if(!a||S.length===0)return;const N=S[S.length-1];G(!0);try{const P=await ke(a,e.id,N);_(V=>V.slice(0,-1)),j(N),H(P.files)}catch{}finally{G(!1)}},[a,e.id,S]),Ie=s.useCallback(async N=>{if(a)try{await Qr(a,e.id,N)}catch(P){alert(`Download failed: ${P instanceof Error?P.message:"Unknown error"}`)}},[a,e.id]);s.useEffect(()=>{if(!W)return;const N=ie=>{ie.key==="Escape"&&D(!1)},P=ie=>{Y.current&&!Y.current.contains(ie.target)&&D(!1)};document.addEventListener("keydown",N);const V=setTimeout(()=>document.addEventListener("mousedown",P),50);return()=>{document.removeEventListener("keydown",N),document.removeEventListener("mousedown",P),clearTimeout(V)}},[W]);const me=s.useCallback(N=>{if(p.current){const P=N.replace(/\r?\n/g," ").trimEnd();p.current.sendInput(P),setTimeout(()=>{var V;return(V=p.current)==null?void 0:V.sendInput("\r")},50)}},[]),Q=s.useCallback(N=>{N&&h.current&&h.current.fillContent(N)},[]),Ae=s.useCallback(N=>{N.preventDefault();const P=J.current;if(!P)return;const V=P.getBoundingClientRect(),ie=V.height-24;document.body.classList.add("resizing-panes-v");const te=we=>{const Ne=(we.clientY-V.top-24)/ie*100,ze=Math.min(85,Math.max(40,Ne));re(100-ze)},ye=()=>{document.body.classList.remove("resizing-panes-v"),document.removeEventListener("mousemove",te),document.removeEventListener("mouseup",ye)};document.addEventListener("mousemove",te),document.addEventListener("mouseup",ye)},[]),he=s.useCallback(N=>{N.preventDefault();const P=M.current;if(!P)return;const V=P.getBoundingClientRect(),ie=V.width;document.body.classList.add("resizing-panes");const te=we=>{const Re=(we.clientX-V.left)/ie*100,Ne=Math.min(80,Math.max(20,Re));X(Ne)},ye=()=>{document.body.classList.remove("resizing-panes"),document.removeEventListener("mousemove",te),document.removeEventListener("mouseup",ye)};document.addEventListener("mousemove",te),document.addEventListener("mouseup",ye)},[]);return r.jsxs("div",{ref:J,style:{display:"flex",flexDirection:"column",height:"100%",minWidth:0,minHeight:0},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"3px 10px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",flexShrink:0,height:"24px"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"5px"},children:[r.jsx("span",{style:{display:"inline-block",width:"6px",height:"6px",borderRadius:"50%",backgroundColor:e.connected?"var(--accent-green)":"var(--accent-red)"}}),r.jsxs("span",{style:{fontSize:"12px",color:"var(--text-secondary)"},children:[e.id,e.connected?e.sessionResumed?" (resumed)":"":" (disconnected)"]})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[r.jsx("input",{ref:m,type:"file",multiple:!0,style:{display:"none"},onChange:be}),r.jsx("button",{className:"pane-btn",onClick:()=>{var N;return(N=m.current)==null?void 0:N.click()},disabled:v,style:v?{color:"var(--accent-yellow)"}:void 0,title:v?`Uploading ${$}%`:"Upload files","aria-label":"Upload files",children:v?`${$}%`:"↑"}),r.jsxs("div",{style:{position:"relative"},children:[r.jsx("button",{className:"pane-btn",onClick:Be,disabled:T,style:T?{color:"var(--accent-yellow)"}:void 0,title:T?"Downloading...":"Download files","aria-label":"Download files",children:T?"...":"↓"}),W&&r.jsxs("div",{ref:Y,style:{position:"absolute",top:"100%",right:0,marginTop:4,width:300,maxHeight:360,backgroundColor:"var(--bg-primary)",border:"1px solid var(--border)",borderRadius:6,boxShadow:"0 4px 16px rgba(0,0,0,0.3)",zIndex:100,display:"flex",flexDirection:"column",overflow:"hidden"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"6px 8px",borderBottom:"1px solid var(--border)",backgroundColor:"var(--bg-secondary)",flexShrink:0},children:[S.length>0&&r.jsx("button",{className:"pane-btn",onClick:ge,disabled:k,style:{fontSize:11,flexShrink:0},title:"Go back",children:".."}),r.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",flex:1},children:F.split("/").slice(-2).join("/")||F}),r.jsx("button",{className:"pane-btn",onClick:()=>D(!1),style:{fontSize:11,flexShrink:0},title:"Close",children:"×"})]}),r.jsx("div",{style:{flex:1,overflowY:"auto",padding:"2px 0"},children:k?r.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12},children:"Loading..."}):U.length===0?r.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12,fontStyle:"italic"},children:"Empty directory"}):U.map(N=>r.jsxs("div",{onClick:()=>{const P=F+"/"+N.name;N.type==="directory"?ve(P):Ie(P)},style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",cursor:"pointer",fontSize:12,color:"var(--text-primary)",transition:"background-color 0.1s"},onMouseEnter:P=>{P.currentTarget.style.backgroundColor="var(--bg-secondary)"},onMouseLeave:P=>{P.currentTarget.style.backgroundColor="transparent"},children:[r.jsx("span",{style:{flexShrink:0,fontSize:13},children:N.type==="directory"?"📁":eo(N.name,N.type)}),r.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.name}),N.type==="directory"?r.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:"›"}):N.size!=null?r.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:ln(N.size)}):null]},N.name))}),r.jsx("div",{style:{borderTop:"1px solid var(--border)",padding:"6px 8px",flexShrink:0,backgroundColor:"var(--bg-secondary)"},children:r.jsx("button",{className:"pane-btn",onClick:async()=>{g(!0),D(!1);try{await Zr(a||"",e.id)}catch(N){alert(`Download failed: ${N instanceof Error?N.message:"Unknown error"}`)}finally{g(!1)}},style:{fontSize:11,color:"var(--accent-blue)",width:"100%",textAlign:"center"},title:"Download entire CWD as tar.gz",children:"Download All (tar.gz)"})})]})]}),r.jsx("button",{className:`pane-btn${d?" pane-btn--active":""}`,onClick:()=>c(e.id),title:"Toggle Chat panel","aria-label":"Toggle Chat panel",children:"Chat"}),r.jsx("button",{className:`pane-btn${l?" pane-btn--active":""}`,onClick:()=>i(e.id),title:"Toggle Task annotation panel","aria-label":"Toggle Task annotation panel",children:"Task"}),r.jsx("button",{className:"pane-btn",onClick:()=>f(t?"vertical":"horizontal"),title:t?"Split vertical (screen too narrow for horizontal)":"Split horizontal (left/right)","aria-label":"Split horizontal",children:"|"}),r.jsx("button",{className:"pane-btn",onClick:()=>f("vertical"),title:"Split vertical (top/bottom)","aria-label":"Split vertical",children:"─"})]})]}),r.jsxs("div",{ref:M,style:{flex:1,display:"flex",flexDirection:"row",overflow:"hidden",minHeight:0},children:[l&&r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{width:`${B}%`,minWidth:200,flexShrink:0,overflow:"hidden"},children:r.jsx(oo,{sessionId:e.id,token:a||"",connected:e.connected,onRequestFileStream:N=>{var P;return(P=p.current)==null?void 0:P.requestFileStream(N)},onCancelFileStream:()=>{var N;return(N=p.current)==null?void 0:N.cancelFileStream()},onForwardToChat:Q,onSendToTerminal:me})}),r.jsx("div",{className:"md-editor-divider-h",onMouseDown:he,style:{width:"2px",flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:N=>{N.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:N=>{N.currentTarget.style.backgroundColor="var(--border)"}})]}),r.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[r.jsxs("div",{style:{flex:1,overflow:"hidden",position:"relative",minWidth:80},children:[r.jsx(Dr,{ref:p,sessionId:e.id}),!e.connected&&r.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"var(--bg-secondary)",opacity:.85,zIndex:2,pointerEvents:"none"},children:r.jsx("span",{style:{color:"var(--text-secondary)",fontSize:"13px",fontStyle:"italic"},children:"Connecting..."})})]}),d&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"md-editor-divider",onMouseDown:Ae}),r.jsxs("div",{style:{height:`${K}%`,minHeight:80,flexShrink:0,overflow:"hidden",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[r.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 8px",height:"22px",flexShrink:0,backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)"},children:r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[r.jsx("span",{style:{fontSize:"11px",color:"var(--accent-blue)",fontWeight:500},children:"Chat"}),r.jsx("button",{className:"pane-btn",onClick:()=>{var N;return(N=h.current)==null?void 0:N.send()},disabled:!z,title:"Send to terminal (Ctrl+Enter)",style:z?{color:"var(--accent-green)"}:{opacity:.4,cursor:"default"},children:"Send"}),r.jsx("span",{style:{fontSize:"9px",color:"var(--text-secondary)"},children:"Ctrl+Enter"})]})}),r.jsx("div",{style:{flex:1,overflow:"hidden"},children:r.jsx(io,{ref:h,onSend:Te,onContentChange:R,sessionId:e.id,token:a||""})})]})]})]})]}),e.error&&r.jsx("div",{style:{padding:"2px 8px",backgroundColor:"var(--bg-secondary)",borderTop:"1px solid var(--accent-red)",color:"var(--accent-red)",fontSize:"11px",flexShrink:0},children:e.error})]})});class un extends s.Component{constructor(){super(...arguments);Ct(this,"state",{hasError:!1,error:null})}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,o){}render(){var t,o;return this.state.hasError?this.props.inline?r.jsxs("div",{style:{height:"100%",backgroundColor:"var(--bg-primary)",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:"8px",color:"var(--text-bright)",fontFamily:"monospace",padding:"16px"},children:[r.jsx("div",{style:{fontSize:"14px",color:"var(--accent-red)"},children:"Pane crashed"}),r.jsx("div",{style:{fontSize:"12px",color:"var(--text-secondary)",textAlign:"center"},children:((t=this.state.error)==null?void 0:t.message)||"An unexpected error occurred"}),r.jsx("button",{onClick:()=>this.setState({hasError:!1,error:null}),style:{background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-bright)",padding:"4px 12px",borderRadius:"4px",cursor:"pointer",fontSize:"12px"},children:"Retry"})]}):r.jsxs("div",{style:{minHeight:"100vh",backgroundColor:"var(--bg-primary)",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:"16px",color:"var(--text-bright)",fontFamily:"monospace"},children:[r.jsx("div",{style:{fontSize:"18px",color:"var(--accent-red)"},children:"Something went wrong"}),r.jsx("div",{style:{fontSize:"13px",color:"var(--text-secondary)",maxWidth:"500px",textAlign:"center"},children:((o=this.state.error)==null?void 0:o.message)||"An unexpected error occurred"}),r.jsx("button",{onClick:()=>window.location.reload(),style:{background:"linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-purple) 100%)",border:"none",color:"var(--bg-primary)",padding:"8px 24px",borderRadius:"6px",cursor:"pointer",fontSize:"14px",fontWeight:"bold"},children:"Reload"})]}):this.props.children}}const fo=4,Ut=10;function po(){const n=A(a=>a.layout),e=A(a=>a.terminalIds.length),t=A(a=>a.addTerminal);if(!n)return r.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)"},children:r.jsx("button",{onClick:()=>t(),style:{background:"none",border:"1px dashed var(--border)",color:"var(--text-secondary)",padding:"16px 32px",borderRadius:"8px",cursor:"pointer",fontSize:"14px"},children:"+ Add Terminal"})});const o=e>1;return r.jsx("div",{style:{height:"100%",width:"100%",overflow:"hidden"},children:r.jsx(fn,{node:n,canClose:o})})}const fn=s.memo(function({node:e,canClose:t}){return e.type==="leaf"?r.jsx(mo,{terminalId:e.terminalId,canClose:t}):r.jsx(ho,{node:e,canClose:t})}),mo=s.memo(function({terminalId:e,canClose:t}){const o=A(a=>a.terminalsMap[e]);return o?r.jsx(un,{inline:!0,children:r.jsx(uo,{terminal:o,canClose:t})}):null}),ho=s.memo(function({node:e,canClose:t}){const o=A(f=>f.setSplitSizes),a=s.useRef(null),c=e.direction==="horizontal",i=s.useRef(e.sizes);i.current=e.sizes;const d=s.useCallback((f,m)=>{m.preventDefault();const p=c?"resizing-panes":"resizing-panes-v";document.body.classList.add(p);const h=c?m.clientX:m.clientY,v=[...i.current],C=a.current,$=c?(C==null?void 0:C.clientWidth)||1:(C==null?void 0:C.clientHeight)||1;let L=null;const T=z=>{L||(L=requestAnimationFrame(()=>{L=null;const D=((c?z.clientX:z.clientY)-h)/$*100,U=v[f]+D,H=v[f+1]-D;if(U>=Ut&&H>=Ut){const F=[...v];F[f]=U,F[f+1]=H,o(e.id,F)}}))},g=()=>{L&&cancelAnimationFrame(L),document.body.classList.remove(p),document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",g)};document.addEventListener("mousemove",T),document.addEventListener("mouseup",g)},[c,e.id,o]),l=[];return e.children.forEach((f,m)=>{const p=f.type==="leaf"?f.terminalId:f.id;l.push(r.jsx("div",{style:{flex:`${e.sizes[m]} 0 0`,minWidth:0,minHeight:0,overflow:"hidden"},children:r.jsx(fn,{node:f,canClose:t})},p)),m<e.children.length-1&&l.push(r.jsx("div",{onMouseDown:h=>d(m,h),style:{flex:`0 0 ${fo}px`,cursor:c?"col-resize":"row-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:h=>{h.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="var(--border)"}},`divider-${e.id}-${m}`))}),r.jsx("div",{ref:a,style:{display:"flex",flexDirection:c?"row":"column",height:"100%",width:"100%",overflow:"hidden"},children:l})});function bo({tabId:n}){const e=A(j=>j.tabs.find(S=>S.id===n)),t=A(j=>j.activeTabId),o=A(j=>j.switchTab),a=A(j=>j.closeTab),c=A(j=>j.reopenTab),i=A(j=>j.deleteTab),d=A(j=>j.renameTab),l=A(j=>e?e.terminalIds.map(S=>{const _=j.terminalsMap[S];return _?{id:S,connected:_.connected}:{id:S,connected:!1}}):[]),f=A(j=>j.killServerSession),[m,p]=s.useState(!1),[h,v]=s.useState(""),[C,$]=s.useState(!1),L=s.useRef(null);if(!e)return null;const T=t===n,g=e.status==="open",z=()=>{g&&o(n)},R=j=>{g&&(j.stopPropagation(),v(e.name),p(!0),setTimeout(()=>{var S;return(S=L.current)==null?void 0:S.focus()},0))},W=()=>{const j=h.trim();j&&d(n,j),p(!1)},D=j=>{j.stopPropagation(),c(n)},U=j=>{j.stopPropagation(),a(n)},H=async j=>{j.stopPropagation(),window.confirm(`Delete tab "${e.name}"? This will kill all tmux sessions in this tab.`)&&await i(n)},F=j=>{j.stopPropagation(),$(!C)};return r.jsxs("div",{children:[r.jsxs("div",{onClick:z,style:{padding:"8px 12px",cursor:g?"pointer":"default",borderLeft:T?"3px solid var(--accent-blue)":"3px solid transparent",backgroundColor:T?"rgba(122, 162, 247, 0.08)":"transparent",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s",opacity:g?1:.5},onMouseEnter:j=>{g&&!T&&(j.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)")},onMouseLeave:j=>{T||(j.currentTarget.style.backgroundColor="transparent")},children:[g&&e.terminalIds.length>0&&r.jsx("button",{onClick:F,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"10px",padding:0,width:14,height:14,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:C?"▼":"▶"}),r.jsxs("div",{style:{flex:1,minWidth:0},children:[m?r.jsx("input",{ref:L,value:h,onChange:j=>v(j.target.value),onBlur:W,onKeyDown:j=>{j.key==="Enter"&&W(),j.key==="Escape"&&p(!1)},style:{width:"100%",background:"var(--bg-primary)",border:"1px solid var(--accent-blue)",color:"var(--text-bright)",borderRadius:"3px",padding:"1px 4px",fontSize:"14px",outline:"none"}}):r.jsx("div",{onDoubleClick:R,style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:g?"Double-click to rename":e.name,children:e.name}),r.jsxs("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:[e.terminalIds.length," terminal",e.terminalIds.length!==1?"s":""," · ",cn(Math.floor(e.createdAt/1e3))]})]}),g?r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:U,style:{flexShrink:0},title:"Close tab",children:"×"}):r.jsxs("div",{style:{display:"flex",gap:"4px",flexShrink:0},children:[r.jsx("button",{className:"pane-btn",onClick:D,title:"Reopen tab",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:H,title:"Delete tab",children:"×"})]})]}),g&&C&&l.length>0&&r.jsx("div",{style:{paddingLeft:"28px",backgroundColor:"rgba(0, 0, 0, 0.2)"},children:l.map(j=>r.jsxs("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--text-secondary)",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center"},title:`Connected: ${j.connected}`,children:[r.jsx("span",{style:{fontFamily:"monospace"},children:j.id}),r.jsx("span",{style:{marginLeft:"8px",color:j.connected?"var(--accent-green)":"var(--accent-red)"},children:j.connected?"●":"○"}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:S=>{S.stopPropagation(),window.confirm(`Close terminal "${j.id}"?`)&&f(j.id)},style:{marginLeft:"auto",flexShrink:0},title:"Close terminal",children:"×"})]},j.id))})]})}function xo({sessionId:n,active:e,createdAt:t}){const o=A(d=>d.addTerminal),a=A(d=>d.killServerSession),c=()=>{o("horizontal",n)},i=d=>{d.stopPropagation(),window.confirm(`Delete orphaned session "${n}"? This will kill the tmux session.`)&&a(n)};return r.jsxs("div",{onClick:c,style:{padding:"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)"},onMouseLeave:d=>{d.currentTarget.style.backgroundColor="transparent"},children:[r.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:e?"var(--accent-green)":"var(--text-secondary)",flexShrink:0}}),r.jsxs("div",{style:{flex:1,minWidth:0},children:[r.jsx("div",{style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n}),r.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:cn(t)})]}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:i,style:{flexShrink:0},title:"Delete session",children:"×"})]})}function go(){const n=A(l=>l.sidebarOpen),e=A(l=>l.toggleSidebar),t=A(l=>l.fetchSessions),o=A(l=>n?l.serverSessions:[]),a=A(l=>n?l.tabs:[]),c=A(l=>l.terminalIds.length),i=new Set(a.flatMap(l=>l.terminalIds)),d=o.filter(l=>!i.has(l.sessionId));return s.useEffect(()=>{if(!n)return;t();let l=setInterval(t,5e3);const f=()=>{document.hidden?l&&(clearInterval(l),l=null):(t(),l||(l=setInterval(t,5e3)))};return document.addEventListener("visibilitychange",f),()=>{l&&clearInterval(l),document.removeEventListener("visibilitychange",f)}},[n,t]),s.useEffect(()=>{if(!n)return;const l=setTimeout(t,800);return()=>clearTimeout(l)},[c,n,t]),r.jsxs("div",{className:"session-sidebar",style:{width:n?280:0,height:"100%",backgroundColor:"var(--bg-secondary)",borderLeft:n?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,overflow:"hidden",transition:"width 0.2s ease"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[r.jsx("span",{style:{color:"var(--accent-blue)",fontSize:"14px",fontWeight:"bold"},children:"Tabs & Terminals"}),r.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"16px",padding:"0 4px",lineHeight:1},title:"Close sidebar",children:"×"})]}),r.jsxs("div",{style:{flex:1,overflowY:"auto"},children:[r.jsxs("div",{children:[r.jsx("div",{style:{padding:"8px 12px",color:"var(--accent-blue)",fontSize:"12px",fontWeight:"bold",backgroundColor:"rgba(122, 162, 247, 0.05)",borderBottom:"1px solid var(--border)"},children:"Tabs"}),a.length===0?r.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"14px",textAlign:"center",padding:"12px"},children:"No tabs"}):a.map(l=>r.jsx(bo,{tabId:l.id},l.id))]}),d.length>0&&r.jsxs("div",{style:{marginTop:"16px"},children:[r.jsx("div",{style:{padding:"8px 12px",color:"var(--accent-yellow)",fontSize:"12px",fontWeight:"bold",backgroundColor:"rgba(224, 175, 104, 0.05)",borderBottom:"1px solid var(--border)"},children:"ORPHANED SESSIONS"}),d.map(l=>r.jsx(xo,{sessionId:l.sessionId,active:l.active,createdAt:l.createdAt},l.sessionId))]})]})]})}const pn=gt.memo(()=>{const n=A(R=>R.tabs),e=A(R=>R.activeTabId),t=A(R=>R.addTab),o=A(R=>R.switchTab),a=A(R=>R.closeTab),c=A(R=>R.renameTab),[i,d]=s.useState(null),[l,f]=s.useState(""),m=s.useRef(null),p=n.filter(R=>R.status==="open");s.useEffect(()=>{i&&m.current&&(m.current.focus(),m.current.select())},[i]);const h=R=>{d(R.id),f(R.name)},v=()=>{i&&l.trim()&&c(i,l.trim()),d(null),f("")},C=()=>{d(null),f("")},$=R=>{R.key==="Enter"?v():R.key==="Escape"&&C()},L=R=>{i||o(R)},T=(R,W)=>{R.stopPropagation(),a(W)},g=(R,W)=>{R.button===1&&(R.preventDefault(),a(W))},z=p.length>1;return r.jsxs("div",{className:"tab-bar",children:[p.map(R=>{const W=R.id===e,D=i===R.id,U=R.terminalIds.length;return r.jsx("div",{className:`tab-item ${W?"tab-item--active":""}`,onClick:()=>L(R.id),onDoubleClick:()=>h(R),onMouseDown:H=>g(H,R.id),children:D?r.jsx("input",{ref:m,type:"text",value:l,onChange:H=>f(H.target.value),onBlur:v,onKeyDown:$,className:"tab-item__rename-input"}):r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"tab-item__name",children:[R.name," ",U>0&&`(${U})`]}),z&&r.jsx("button",{className:"tab-item__close",onClick:H=>T(H,R.id),title:"Close tab","aria-label":"Close tab",children:"×"})]})},R.id)}),r.jsx("button",{className:"tab-bar-add",onClick:()=>t(),title:"New tab","aria-label":"Add new tab",children:"+"})]})});pn.displayName="TabBar";function yo(){return localStorage.getItem("ai-cli-online-token")}function vo(){const n=A(m=>m.token),e=A(m=>m.setToken),t=A(m=>m.tabs),o=A(m=>m.addTab),a=A(m=>m.toggleSidebar),c=A(m=>m.fontSize),i=A(m=>m.setFontSize),d=A(m=>m.tabsLoading),l=A(m=>m.theme),f=A(m=>m.toggleTheme);return s.useEffect(()=>{const m=yo();m&&!n&&e(m)},[]),s.useEffect(()=>{n&&!d&&t.filter(m=>m.status==="open").length===0&&o("Default")},[n,d]),n?r.jsxs("div",{style:{height:"100vh",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[r.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 16px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",flexShrink:0},children:[r.jsx("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:r.jsx("span",{style:{fontSize:"15px",fontWeight:"bold",color:"var(--accent-blue)",letterSpacing:"0.5px"},children:"AI-Cli Online"})}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"1px 4px",borderRadius:"6px",backgroundColor:"rgba(0,0,0,0.2)"},children:[r.jsx("button",{className:"header-btn",onClick:()=>i(c-1),disabled:c<=10,title:"Decrease font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A−"}),r.jsx("span",{style:{fontSize:"11px",color:"var(--text-primary)",minWidth:"20px",textAlign:"center"},children:c}),r.jsx("button",{className:"header-btn",onClick:()=>i(c+1),disabled:c>=24,title:"Increase font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A+"})]}),r.jsx(So,{}),r.jsx("button",{className:"header-btn",onClick:f,title:`Switch to ${l==="dark"?"light":"dark"} mode`,"aria-label":"Toggle theme",children:l==="dark"?"☀":"🌙"}),r.jsx("button",{className:"header-btn",onClick:a,title:"Toggle Tabs & Terminals Sidebar","aria-label":"Toggle sidebar",children:"☰"}),r.jsx("button",{className:"header-btn header-btn--muted",onClick:()=>{window.confirm("Logout will close all terminals. Continue?")&&e(null)},children:"Logout"})]})]}),r.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[r.jsx("main",{style:{flex:1,overflow:"hidden"},children:r.jsx(po,{})}),r.jsx(go,{})]}),r.jsx(pn,{})]}):r.jsx(fr,{})}const wo=[1,2,3,4];function So(){const n=A(o=>o.latency);if(n===null)return r.jsx("span",{style:{fontSize:"10px",color:"var(--scrollbar-thumb-hover)"},title:"Measuring latency...",children:"--ms"});let e,t;return n<50?(e="var(--accent-green)",t=4):n<150?(e="var(--accent-yellow)",t=3):n<300?(e="var(--accent-orange)",t=2):(e="var(--accent-red)",t=1),r.jsxs("span",{style:{display:"inline-flex",alignItems:"end",gap:"1.5px",padding:"2px 8px",borderRadius:"10px",backgroundColor:"rgba(0,0,0,0.2)"},title:`Latency: ${n}ms`,children:[wo.map(o=>r.jsx("span",{style:{display:"inline-block",width:"2.5px",height:`${3+o*2}px`,backgroundColor:o<=t?e:"var(--border)",borderRadius:"1px",transition:"background-color 0.3s ease"}},o)),r.jsxs("span",{style:{fontSize:"10px",color:e,marginLeft:"4px",fontWeight:500},children:[n,"ms"]})]})}mt.createRoot(document.getElementById("root")).render(r.jsx(gt.StrictMode,{children:r.jsx(un,{children:r.jsx(vo,{})})}));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2014 The xterm.js authors. All rights reserved.
|
|
3
|
+
* Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
|
|
4
|
+
* https://github.com/chjj/term.js
|
|
5
|
+
* @license MIT
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
|
15
|
+
* all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
* THE SOFTWARE.
|
|
24
|
+
*
|
|
25
|
+
* Originally forked from (with the author's permission):
|
|
26
|
+
* Fabrice Bellard's javascript vt100 for jslinux:
|
|
27
|
+
* http://bellard.org/jslinux/
|
|
28
|
+
* Copyright (c) 2011 Fabrice Bellard
|
|
29
|
+
* The original design remains. The terminal itself
|
|
30
|
+
* has been extended to include xterm CSI codes, among
|
|
31
|
+
* other features.
|
|
32
|
+
*/.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{padding:0;border:0;margin:0;position:absolute;opacity:0;left:-9999em;top:0;width:0;height:0;z-index:-5;white-space:nowrap;overflow:hidden;resize:none}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;overflow-y:scroll;cursor:default;position:absolute;right:0;left:0;top:0;bottom:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;left:0;top:0}.xterm-char-measure-element{display:inline-block;visibility:hidden;position:absolute;top:0;left:-9999em;line-height:normal}.xterm.enable-mouse-events{cursor:default}.xterm.xterm-cursor-pointer,.xterm .xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{position:absolute;left:0;top:0;bottom:0;right:0;z-index:10;color:transparent;pointer-events:none}.xterm .xterm-accessibility-tree:not(.debug) *::selection{color:transparent}.xterm .xterm-accessibility-tree{font-family:monospace;-webkit-user-select:text;user-select:text;white-space:pre}.xterm .xterm-accessibility-tree>div{transform-origin:left;width:fit-content}.xterm .live-region{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;position:absolute;top:0;right:0;pointer-events:none}.xterm-decoration-top{z-index:2;position:relative}.xterm .xterm-scrollable-element>.scrollbar{cursor:default}.xterm .xterm-scrollable-element>.scrollbar>.scra{cursor:pointer;font-size:11px!important}.xterm .xterm-scrollable-element>.visible{opacity:1;background:#0000;transition:opacity .1s linear;z-index:11}.xterm .xterm-scrollable-element>.invisible{opacity:0;pointer-events:none}.xterm .xterm-scrollable-element>.invisible.fade{transition:opacity .8s linear}.xterm .xterm-scrollable-element>.shadow{position:absolute;display:none}.xterm .xterm-scrollable-element>.shadow.top{display:block;top:0;left:3px;height:3px;width:100%;box-shadow:var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.left{display:block;top:3px;left:0;height:100%;width:3px;box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.top-left-corner{display:block;top:0;left:0;height:3px;width:3px}.xterm .xterm-scrollable-element>.shadow.top.left{box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}@font-face{font-family:JetBrains Mono;src:url(/fonts/JetBrainsMono-Regular.woff2) format("woff2");font-weight:400;font-style:normal;font-display:swap}@font-face{font-family:JetBrains Mono;src:url(/fonts/JetBrainsMono-Bold.woff2) format("woff2");font-weight:700;font-style:normal;font-display:swap}:root,[data-theme=dark]{--bg-primary: #000000;--bg-secondary: #0c0c0c;--bg-tertiary: #171717;--bg-hover: #1c1c1c;--border: #2d2d2d;--text-primary: #cccccc;--text-secondary: #858585;--text-bright: #e8e8e8;--accent-blue: #569cd6;--accent-purple: #c586c0;--accent-cyan: #4ec9b0;--accent-green: #89d185;--accent-yellow: #cca700;--accent-red: #f44747;--accent-orange: #ce9178;--scrollbar-thumb: rgba(121, 121, 121, .4);--scrollbar-thumb-hover: rgba(121, 121, 121, .7);--selection-bg: rgba(38, 79, 120, .5)}[data-theme=light]{--bg-primary: #ffffff;--bg-secondary: #f6f8fa;--bg-tertiary: #ffffff;--bg-hover: #eff2f5;--border: #d1d9e0;--text-primary: #1f2328;--text-secondary: #59636e;--text-bright: #1f2328;--accent-blue: #0969da;--accent-purple: #8250df;--accent-cyan: #1b7c83;--accent-green: #1a7f37;--accent-yellow: #9a6700;--accent-red: #d1242f;--accent-orange: #bc4c00;--scrollbar-thumb: rgba(31, 35, 40, .15);--scrollbar-thumb-hover: rgba(31, 35, 40, .3);--selection-bg: rgba(9, 105, 218, .2)}*{margin:0;padding:0;box-sizing:border-box}html,body,#root{width:100%;height:100%;overflow:hidden;background-color:var(--bg-primary);font-family:JetBrains Mono,LXGW WenKai Mono,Menlo,Monaco,Courier New,monospace;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility}body.resizing-panes,body.resizing-panes *{cursor:col-resize!important;-webkit-user-select:none!important;user-select:none!important}.session-sidebar{transition:width .2s ease;overflow:hidden;flex-shrink:0;z-index:10;position:relative}body.resizing-panes-v,body.resizing-panes-v *{cursor:row-resize!important;-webkit-user-select:none!important;user-select:none!important}button{transition:all .15s ease;font-family:inherit}button:hover{filter:brightness(1.2)}button:active{transform:scale(.97)}::-webkit-scrollbar{width:6px;height:6px}::-webkit-scrollbar-track{background:transparent}::-webkit-scrollbar-thumb{background:var(--scrollbar-thumb);border-radius:3px}::-webkit-scrollbar-thumb:hover{background:var(--scrollbar-thumb-hover)}::selection{background:var(--selection-bg);color:var(--text-bright)}input:focus-visible,button:focus-visible{outline:1px solid var(--accent-blue);outline-offset:1px}.header-btn{background:none;border:1px solid var(--border);color:var(--accent-blue);padding:3px 10px;border-radius:5px;cursor:pointer;font-size:13px;line-height:1.4;transition:all .15s ease}.header-btn:hover{background:#7aa2f71f;border-color:var(--accent-blue);box-shadow:0 0 8px #7aa2f726}.header-btn--muted{color:var(--text-secondary);font-size:12px}.header-btn--muted:hover{color:var(--text-primary);border-color:var(--text-secondary);background:#565f891a}.pane-btn{background:none;border:none;color:var(--text-secondary);cursor:pointer;font-size:12px;line-height:1;padding:2px 5px;border-radius:4px;transition:all .15s ease}.pane-btn:hover{color:var(--accent-blue);background:#7aa2f71f}.pane-btn--danger:hover{color:var(--accent-red);background:#f7768e1f}.login-input{transition:border-color .2s ease,box-shadow .2s ease}.login-input:focus{border-color:var(--accent-blue)!important;box-shadow:0 0 0 3px #7aa2f726}.login-card{box-shadow:0 8px 32px #0006,0 0 0 1px #7aa2f714;transition:box-shadow .3s ease}.login-submit{transition:all .2s ease}.login-submit:not(:disabled):hover{filter:brightness(1.1);box-shadow:0 4px 12px #7aa2f74d}.md-editor-textarea{flex:1;min-width:0;resize:none;border:none;outline:none;padding:8px 12px;font-family:JetBrains Mono,LXGW WenKai Mono,Menlo,Monaco,Courier New,monospace;font-size:13px;line-height:1.5;color:var(--text-primary);background-color:var(--bg-primary);-moz-tab-size:2;tab-size:2}.md-editor-textarea::placeholder{color:var(--scrollbar-thumb-hover);font-style:italic}.md-editor-divider{height:2px;background:var(--border);cursor:row-resize;flex-shrink:0;transition:background .15s ease,box-shadow .15s ease}.md-editor-divider:hover{background:var(--accent-blue);box-shadow:0 0 6px #7aa2f766}.pane-btn--active{color:var(--accent-blue)}.plan-panel-body{display:flex;flex-direction:row;flex:1;min-height:0;overflow:hidden}.plan-renderer{position:relative;overflow:hidden;padding:0;min-width:0;-webkit-user-select:text;user-select:text}.plan-divider-h{width:2px;background:var(--border);cursor:col-resize;flex-shrink:0;transition:background .15s ease,box-shadow .15s ease}.plan-divider-h:hover{background:var(--accent-blue);box-shadow:0 0 6px #7aa2f766}.plan-editor-wrap{flex:1;display:flex;flex-direction:column;min-width:0;overflow:hidden}.plan-filename-input{background:var(--bg-primary);border:1px solid var(--border);color:var(--text-primary);padding:2px 6px;border-radius:3px;font-family:inherit;font-size:11px;width:120px;outline:none;transition:border-color .15s ease}.plan-filename-input:focus{border-color:var(--accent-blue)}body.resizing-panes-h,body.resizing-panes-h *{cursor:col-resize!important;-webkit-user-select:none!important;user-select:none!important}.md-preview{color:var(--text-primary);font-size:13px;line-height:1.6;word-wrap:break-word}.md-preview h1{color:var(--accent-blue);font-size:1.4em;margin:.6em 0 .3em;padding-bottom:.2em;border-bottom:1px solid var(--border)}.md-preview h2{color:var(--accent-purple);font-size:1.2em;margin:.5em 0 .3em}.md-preview h3{color:var(--accent-cyan);font-size:1.05em;margin:.4em 0 .2em}.md-preview p{margin:.4em 0}.md-preview code{background:var(--bg-tertiary);color:var(--text-bright);padding:1px 4px;border-radius:3px;font-size:.9em;font-family:JetBrains Mono,LXGW WenKai Mono,monospace}.md-preview pre{background:var(--bg-tertiary);border:1px solid var(--border);border-radius:4px;padding:10px 12px;overflow-x:auto;margin:.5em 0}.md-preview pre code{background:none;padding:0;border-radius:0}.md-preview blockquote{border-left:3px solid var(--accent-blue);padding:2px 12px;margin:.4em 0;color:var(--text-secondary)}.md-preview ul,.md-preview ol{padding-left:1.5em;margin:.3em 0}.md-preview li{margin:.15em 0}.md-preview table{border-collapse:collapse;width:100%;margin:.5em 0;font-size:12px}.md-preview th,.md-preview td{border:1px solid var(--border);padding:4px 8px;text-align:left}.md-preview th{background:var(--bg-tertiary);color:var(--accent-blue);font-weight:600}.md-preview a{color:var(--accent-blue);text-decoration:none}.md-preview a:hover{text-decoration:underline}.md-preview hr{border:none;border-top:1px solid var(--border);margin:.6em 0}.slash-dropdown{flex-shrink:0;max-height:200px;overflow-y:auto;background:var(--bg-secondary);border-bottom:1px solid var(--border);z-index:10;font-size:13px}.slash-item{display:flex;align-items:center;gap:10px;padding:6px 12px;cursor:pointer;transition:background .12s ease}.slash-item:hover,.slash-item--active{background:var(--bg-hover)}.slash-cmd{color:var(--accent-blue);font-weight:600;min-width:120px;font-family:JetBrains Mono,LXGW WenKai Mono,monospace}.slash-desc{color:var(--accent-purple);font-size:11px}.file-dropdown{flex-shrink:0;max-height:180px;overflow-y:auto;background:var(--bg-secondary);border-bottom:1px solid var(--border);z-index:10;font-size:12px}.file-item{display:flex;align-items:center;gap:8px;padding:5px 10px;cursor:pointer;transition:background .1s ease}.file-item:hover,.file-item--active{background:var(--bg-hover)}.file-loading{color:var(--text-secondary);cursor:default}.file-icon{flex-shrink:0;width:16px;text-align:center;font-size:13px}.file-name{color:var(--text-bright);font-family:JetBrains Mono,LXGW WenKai Mono,monospace;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.history-dropdown{flex-shrink:0;max-height:260px;overflow-y:auto;background:var(--bg-secondary);border-bottom:1px solid var(--border);z-index:10;font-size:12px}.history-item{display:flex;align-items:flex-start;gap:8px;padding:6px 10px;cursor:pointer;transition:background .1s ease;position:relative}.history-item:hover,.history-item--active{background:var(--bg-hover)}.history-empty{color:var(--text-secondary);cursor:default;justify-content:center;padding:12px}.history-text{flex:1;color:var(--text-bright);font-family:JetBrains Mono,LXGW WenKai Mono,monospace;white-space:pre-wrap;overflow-wrap:break-word;line-height:1.4}.history-time{flex-shrink:0;color:var(--text-secondary);font-size:10px;white-space:nowrap;margin-top:2px}.history-delete{flex-shrink:0;background:none;border:none;color:var(--text-secondary);cursor:pointer;font-size:14px;padding:0 2px;line-height:1;opacity:0;transition:opacity .1s ease,color .1s ease}.history-item:hover .history-delete,.history-item--active .history-delete{opacity:1}.history-delete:hover{color:var(--accent-red)}.tab-bar{display:flex;align-items:center;padding:0 10px;height:32px;background:var(--bg-secondary);border-top:1px solid var(--border);flex-shrink:0;overflow-x:auto;gap:3px}.tab-bar::-webkit-scrollbar{height:0}.tab-item{display:flex;align-items:center;gap:6px;padding:4px 12px;font-size:13px;color:var(--text-secondary);cursor:pointer;border-bottom:2px solid transparent;white-space:nowrap;transition:color .15s ease,border-color .15s ease,background .15s ease,box-shadow .15s ease;border-radius:5px 5px 0 0;-webkit-user-select:none;user-select:none;flex-shrink:0}.tab-item:hover{color:var(--text-primary);background:#7aa2f70f}.tab-item--active{color:var(--text-bright);border-bottom-color:var(--accent-blue);background:#7aa2f71a;box-shadow:inset 0 -1px 0 var(--accent-blue)}.tab-item__name{max-width:150px;overflow:hidden;text-overflow:ellipsis}.tab-item__count{font-size:10px;color:var(--scrollbar-thumb-hover)}.tab-item__close{font-size:14px;line-height:1;color:inherit;opacity:0;background:none;border:none;cursor:pointer;padding:0 2px;border-radius:3px;transition:opacity .1s ease}.tab-item:hover .tab-item__close{opacity:.5}.tab-item__close:hover{opacity:1!important;color:var(--accent-red);background:#f7768e1a}.tab-item__rename-input{background:transparent;border:1px solid var(--accent-blue);color:var(--text-bright);font-size:13px;font-family:inherit;padding:0 6px;border-radius:3px;outline:none;width:100px}.tab-bar-add{background:none;border:1px solid transparent;color:var(--text-secondary);font-size:18px;line-height:1;padding:2px 8px;border-radius:5px;cursor:pointer;margin-left:4px;flex-shrink:0}.tab-bar-add:hover{color:var(--accent-blue);border-color:var(--border);background:#7aa2f71a}.md-editor-actions{display:flex;align-items:center;gap:8px;padding:4px 8px;flex-shrink:0;background:var(--bg-secondary);border-top:1px solid var(--border)}.plan-anno-toolbar{display:flex;align-items:center;gap:6px;padding:3px 10px;height:28px;flex-shrink:0;background:var(--bg-secondary);border-bottom:1px solid var(--border)}.plan-anno-content{-webkit-user-select:text;user-select:text}.plan-insert-zone{position:relative;min-height:12px}.plan-insert-btn{display:none;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:20px;height:20px;border-radius:50%;border:1px solid var(--scrollbar-thumb-hover);background:var(--bg-secondary);color:var(--accent-blue);font-size:15px;line-height:1;cursor:pointer;padding:0 0 1px;z-index:2;transition:background .12s ease,border-color .12s ease,transform .12s ease;align-items:center;justify-content:center}.plan-insert-zone:hover .plan-insert-btn{display:flex}.plan-anno-content--editing .plan-insert-zone:hover .plan-insert-btn{display:none}.plan-empty-placeholder{display:flex;align-items:center;justify-content:center;min-height:120px;color:var(--text-secondary);font-size:13px;font-style:italic;cursor:pointer;-webkit-user-select:none;user-select:none;text-align:center;padding:16px}.plan-empty-placeholder:hover{color:var(--accent-blue)}.plan-insert-btn:hover{background:var(--bg-hover);border-color:var(--accent-blue);transform:translate(-50%,-50%) scale(1.15)}.plan-annotation-card{display:flex;align-items:flex-start;gap:6px;padding:6px 10px;margin:4px 0;background:#e0af681f;border-left:3px solid var(--accent-yellow);border-radius:0 4px 4px 0}.plan-annotation-card--editing{border-left-color:var(--accent-blue);background:#7aa2f70f}.plan-annotation-textarea{flex:1;min-height:36px;resize:vertical;border:1px solid var(--border);border-radius:3px;background:var(--bg-primary);color:var(--text-primary);font-family:JetBrains Mono,LXGW WenKai Mono,monospace;font-size:12px;padding:4px 6px;outline:none;transition:border-color .15s ease}.plan-annotation-textarea:focus{border-color:var(--accent-blue)}.plan-annotation-textarea::placeholder{color:var(--scrollbar-thumb-hover);font-style:italic}.plan-deletion-card{display:flex;align-items:center;gap:6px;padding:2px 8px;margin:2px 0;background:#f7768e0f;border-left:3px solid var(--accent-red);border-radius:0 4px 4px 0;font-size:11px}.plan-selection-float{position:absolute;z-index:1000;display:flex;flex-direction:column;gap:2px;background:var(--bg-secondary);border:1px solid var(--border);border-radius:6px;padding:2px;box-shadow:0 2px 8px #0000004d}.plan-selection-float button{width:24px;height:24px;border-radius:4px;border:none;cursor:pointer;font-size:14px;display:flex;align-items:center;justify-content:center;background:transparent;transition:background .15s,transform .1s}.plan-selection-float button:hover{transform:scale(1.1)}.plan-selection-float__delete{color:var(--accent-red)}.plan-selection-float__delete:hover{background:#f7768e33}.plan-selection-float__replace{color:var(--accent-blue)}.plan-selection-float__replace:hover{background:#7aa2f733}.plan-selection-float__comment{color:var(--accent-green)}.plan-selection-float__comment:hover{background:#9ece6a33}.plan-replace-card{display:flex;align-items:flex-start;gap:6px;padding:2px 8px;margin:2px 0;border-left:3px solid rgba(122,162,247,.6);background:#7aa2f70a;border-radius:0 4px 4px 0;font-size:11px}.plan-comment-card{display:flex;align-items:flex-start;gap:6px;padding:2px 8px;margin:2px 0;border-left:3px solid rgba(158,206,106,.6);background:#9ece6a0a;border-radius:0 4px 4px 0;font-size:11px}.plan-block--deleted{border-left:3px solid rgba(247,118,142,.5);padding-left:8px;border-radius:2px;position:relative}.plan-block--replaced{border-left:3px solid rgba(122,162,247,.5);padding-left:8px;border-radius:2px;position:relative}.plan-block--commented{border-left:3px solid rgba(158,206,106,.5);padding-left:8px;border-radius:2px;position:relative}.mermaid-diagram{margin:8px 0;padding:12px;background:var(--bg-secondary);border:1px solid var(--border);border-radius:6px;overflow-x:auto}.mermaid-diagram svg{display:block;margin:0 auto;max-width:100%;height:auto}.mermaid-error{border-left:3px solid var(--accent-red);padding-left:8px}.mermaid-error__msg{color:var(--accent-red);font-size:11px;margin-top:4px}.pane-btn--sm{font-size:11px;flex-shrink:0}.plan-file-browser{display:flex;flex-direction:column;height:100%;width:100%;background:var(--bg-secondary);overflow:hidden}.plan-file-browser__header{display:flex;align-items:center;justify-content:space-between;padding:4px 8px;height:28px;flex-shrink:0;border-bottom:1px solid var(--border)}.plan-file-browser__title{font-size:11px;color:var(--accent-blue);font-weight:600;letter-spacing:.3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;direction:rtl;text-align:left}.plan-file-browser__list{flex:1;overflow-y:auto;overflow-x:hidden;padding:2px 0}.plan-file-browser__status{padding:8px 10px;font-size:11px;color:var(--text-secondary);font-style:italic}.plan-file-browser__item{display:flex;align-items:center;padding:3px 8px;font-size:12px;cursor:pointer;gap:5px;transition:background .1s ease;border-left:2px solid transparent}.plan-file-browser__item:hover{background:var(--bg-tertiary)}.plan-file-browser__item--active{background:#7aa2f71a;border-left-color:var(--accent-blue)}.plan-file-browser__item--active .plan-file-browser__name{color:var(--text-bright)}.plan-file-browser__icon{flex-shrink:0;width:14px;font-size:10px;color:var(--text-secondary);text-align:center}.plan-file-browser__name{flex:1;color:var(--text-primary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.plan-file-browser__size{flex-shrink:0;font-size:9px;color:var(--scrollbar-thumb-hover);white-space:nowrap}.plan-file-browser__create{display:flex;align-items:center;gap:4px;padding:4px 6px;border-top:1px solid var(--border);flex-shrink:0}.plan-file-browser__input{flex:1;min-width:0;background:var(--bg-primary);border:1px solid var(--border);color:var(--text-primary);padding:2px 6px;border-radius:3px;font-family:inherit;font-size:11px;outline:none;transition:border-color .15s ease}.plan-file-browser__input:focus{border-color:var(--accent-blue)}.plan-file-browser__input::placeholder{color:var(--scrollbar-thumb-hover);font-style:italic}.plan-overlay-body{display:flex;flex:1;min-height:0;overflow:hidden}.plan-overlay-center{flex:1;min-width:0;overflow:hidden}.plan-anno-counts{display:inline-flex;align-items:center;gap:4px;font-size:10px;margin-left:4px}.plan-anno-counts__unsent{color:var(--accent-yellow)}.plan-anno-counts__sent{color:var(--accent-green)}.plan-anno-dropdown-trigger{display:flex;align-items:center;gap:4px;padding:2px 6px;border:1px solid var(--border);border-radius:3px;cursor:pointer;background:var(--bg-primary);transition:border-color .15s ease,background .15s ease;min-width:0}.plan-anno-dropdown-trigger:hover,.plan-anno-dropdown-trigger--active{border-color:var(--accent-blue);background:var(--bg-hover)}.plan-anno-dropdown-trigger__text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px;color:var(--text-secondary)}.plan-anno-dropdown-trigger__arrow{flex-shrink:0;font-size:9px;color:var(--text-secondary);transition:transform .15s ease}.plan-anno-dropdown-trigger--active .plan-anno-dropdown-trigger__arrow{transform:rotate(180deg)}.plan-anno-dropdown{position:absolute;top:100%;right:0;z-index:100;width:320px;max-height:300px;display:flex;flex-direction:column;background:var(--bg-secondary);border:1px solid var(--border);border-radius:4px;box-shadow:0 4px 12px #0000004d;overflow:hidden}.plan-anno-dropdown__header{display:flex;align-items:center;justify-content:center;padding:4px 6px;border-bottom:1px solid var(--border);flex-shrink:0}.plan-anno-dropdown__list{flex:1;overflow-y:auto;padding:2px 0}.plan-anno-dropdown__item{display:flex;align-items:center;gap:4px;padding:3px 6px;font-size:11px;border-bottom:1px solid var(--border-subtle, rgba(128,128,128,.1))}.plan-anno-dropdown__item:last-child{border-bottom:none}.plan-anno-dropdown__item--add{border-left:2px solid var(--accent-yellow)}.plan-anno-dropdown__item--del{border-left:2px solid var(--accent-red)}.plan-anno-dropdown__item--rep{border-left:2px solid var(--accent-blue)}.plan-anno-dropdown__item--com{border-left:2px solid var(--accent-green)}.plan-anno-dropdown__type{flex-shrink:0;width:14px;font-weight:700;text-align:center}.plan-anno-dropdown__text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--text-primary)}.plan-anno-dropdown__badge{flex-shrink:0;font-size:9px;padding:0 4px;border-radius:3px;background:var(--accent-green);color:var(--bg-primary)}.plan-anno-dropdown__empty{padding:8px;text-align:center;font-size:11px;color:var(--text-secondary);font-style:italic}
|
package/web/dist/index.html
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
<!-- LXGW WenKai Mono (中文等宽字体, CDN unicode-range 按需加载) -->
|
|
11
11
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lxgw-wenkai-webfont@1.7.0/lxgwwenkaimono-regular.css" />
|
|
12
12
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lxgw-wenkai-webfont@1.7.0/lxgwwenkaimono-bold.css" />
|
|
13
|
-
<script type="module" crossorigin src="/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/assets/index-C0ECf3pB.js"></script>
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/assets/react-vendor-BCIvbQoU.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/assets/terminal-DnNpv9tw.js">
|
|
16
16
|
<link rel="modulepreload" crossorigin href="/assets/markdown-CU76q5qk.js">
|
|
17
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
17
|
+
<link rel="stylesheet" crossorigin href="/assets/index-CLEFVTX4.css">
|
|
18
18
|
</head>
|
|
19
19
|
<body>
|
|
20
20
|
<div id="root"></div>
|
package/web/package.json
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2014 The xterm.js authors. All rights reserved.
|
|
3
|
-
* Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
|
|
4
|
-
* https://github.com/chjj/term.js
|
|
5
|
-
* @license MIT
|
|
6
|
-
*
|
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
* furnished to do so, subject to the following conditions:
|
|
13
|
-
*
|
|
14
|
-
* The above copyright notice and this permission notice shall be included in
|
|
15
|
-
* all copies or substantial portions of the Software.
|
|
16
|
-
*
|
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
-
* THE SOFTWARE.
|
|
24
|
-
*
|
|
25
|
-
* Originally forked from (with the author's permission):
|
|
26
|
-
* Fabrice Bellard's javascript vt100 for jslinux:
|
|
27
|
-
* http://bellard.org/jslinux/
|
|
28
|
-
* Copyright (c) 2011 Fabrice Bellard
|
|
29
|
-
* The original design remains. The terminal itself
|
|
30
|
-
* has been extended to include xterm CSI codes, among
|
|
31
|
-
* other features.
|
|
32
|
-
*/.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{padding:0;border:0;margin:0;position:absolute;opacity:0;left:-9999em;top:0;width:0;height:0;z-index:-5;white-space:nowrap;overflow:hidden;resize:none}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;overflow-y:scroll;cursor:default;position:absolute;right:0;left:0;top:0;bottom:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;left:0;top:0}.xterm-char-measure-element{display:inline-block;visibility:hidden;position:absolute;top:0;left:-9999em;line-height:normal}.xterm.enable-mouse-events{cursor:default}.xterm.xterm-cursor-pointer,.xterm .xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{position:absolute;left:0;top:0;bottom:0;right:0;z-index:10;color:transparent;pointer-events:none}.xterm .xterm-accessibility-tree:not(.debug) *::selection{color:transparent}.xterm .xterm-accessibility-tree{font-family:monospace;-webkit-user-select:text;user-select:text;white-space:pre}.xterm .xterm-accessibility-tree>div{transform-origin:left;width:fit-content}.xterm .live-region{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;position:absolute;top:0;right:0;pointer-events:none}.xterm-decoration-top{z-index:2;position:relative}.xterm .xterm-scrollable-element>.scrollbar{cursor:default}.xterm .xterm-scrollable-element>.scrollbar>.scra{cursor:pointer;font-size:11px!important}.xterm .xterm-scrollable-element>.visible{opacity:1;background:#0000;transition:opacity .1s linear;z-index:11}.xterm .xterm-scrollable-element>.invisible{opacity:0;pointer-events:none}.xterm .xterm-scrollable-element>.invisible.fade{transition:opacity .8s linear}.xterm .xterm-scrollable-element>.shadow{position:absolute;display:none}.xterm .xterm-scrollable-element>.shadow.top{display:block;top:0;left:3px;height:3px;width:100%;box-shadow:var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.left{display:block;top:3px;left:0;height:100%;width:3px;box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.top-left-corner{display:block;top:0;left:0;height:3px;width:3px}.xterm .xterm-scrollable-element>.shadow.top.left{box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}@font-face{font-family:JetBrains Mono;src:url(/fonts/JetBrainsMono-Regular.woff2) format("woff2");font-weight:400;font-style:normal;font-display:swap}@font-face{font-family:JetBrains Mono;src:url(/fonts/JetBrainsMono-Bold.woff2) format("woff2");font-weight:700;font-style:normal;font-display:swap}:root,[data-theme=dark]{--bg-primary: #000000;--bg-secondary: #0c0c0c;--bg-tertiary: #171717;--bg-hover: #1c1c1c;--border: #2d2d2d;--text-primary: #cccccc;--text-secondary: #858585;--text-bright: #e8e8e8;--accent-blue: #569cd6;--accent-purple: #c586c0;--accent-cyan: #4ec9b0;--accent-green: #89d185;--accent-yellow: #cca700;--accent-red: #f44747;--accent-orange: #ce9178;--scrollbar-thumb: rgba(121, 121, 121, .4);--scrollbar-thumb-hover: rgba(121, 121, 121, .7);--selection-bg: rgba(38, 79, 120, .5)}[data-theme=light]{--bg-primary: #faf8f4;--bg-secondary: #f0eee9;--bg-tertiary: #fdfcfa;--bg-hover: #e8e5e0;--border: #d8d4cd;--text-primary: #3b3b3b;--text-secondary: #848484;--text-bright: #1e1e1e;--accent-blue: #005fb8;--accent-purple: #af00db;--accent-cyan: #0e7490;--accent-green: #388a34;--accent-yellow: #bf8803;--accent-red: #cd3131;--accent-orange: #c27d2e;--scrollbar-thumb: rgba(100, 100, 100, .3);--scrollbar-thumb-hover: rgba(100, 100, 100, .5);--selection-bg: rgba(173, 214, 255, .5)}*{margin:0;padding:0;box-sizing:border-box}html,body,#root{width:100%;height:100%;overflow:hidden;background-color:var(--bg-primary);font-family:JetBrains Mono,LXGW WenKai Mono,Menlo,Monaco,Courier New,monospace;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility}body.resizing-panes,body.resizing-panes *{cursor:col-resize!important;-webkit-user-select:none!important;user-select:none!important}.session-sidebar{transition:width .2s ease;overflow:hidden;flex-shrink:0;z-index:10;position:relative}body.resizing-panes-v,body.resizing-panes-v *{cursor:row-resize!important;-webkit-user-select:none!important;user-select:none!important}button{transition:all .15s ease;font-family:inherit}button:hover{filter:brightness(1.2)}button:active{transform:scale(.97)}::-webkit-scrollbar{width:6px;height:6px}::-webkit-scrollbar-track{background:transparent}::-webkit-scrollbar-thumb{background:var(--scrollbar-thumb);border-radius:3px}::-webkit-scrollbar-thumb:hover{background:var(--scrollbar-thumb-hover)}::selection{background:var(--selection-bg);color:var(--text-bright)}input:focus-visible,button:focus-visible{outline:1px solid var(--accent-blue);outline-offset:1px}.header-btn{background:none;border:1px solid var(--border);color:var(--accent-blue);padding:3px 10px;border-radius:5px;cursor:pointer;font-size:13px;line-height:1.4;transition:all .15s ease}.header-btn:hover{background:#7aa2f71f;border-color:var(--accent-blue);box-shadow:0 0 8px #7aa2f726}.header-btn--muted{color:var(--text-secondary);font-size:12px}.header-btn--muted:hover{color:var(--text-primary);border-color:var(--text-secondary);background:#565f891a}.pane-btn{background:none;border:none;color:var(--text-secondary);cursor:pointer;font-size:12px;line-height:1;padding:2px 5px;border-radius:4px;transition:all .15s ease}.pane-btn:hover{color:var(--accent-blue);background:#7aa2f71f}.pane-btn--danger:hover{color:var(--accent-red);background:#f7768e1f}.login-input{transition:border-color .2s ease,box-shadow .2s ease}.login-input:focus{border-color:var(--accent-blue)!important;box-shadow:0 0 0 3px #7aa2f726}.login-card{box-shadow:0 8px 32px #0006,0 0 0 1px #7aa2f714;transition:box-shadow .3s ease}.login-submit{transition:all .2s ease}.login-submit:not(:disabled):hover{filter:brightness(1.1);box-shadow:0 4px 12px #7aa2f74d}.md-editor-textarea{flex:1;min-width:0;resize:none;border:none;outline:none;padding:8px 12px;font-family:JetBrains Mono,LXGW WenKai Mono,Menlo,Monaco,Courier New,monospace;font-size:13px;line-height:1.5;color:var(--text-primary);background-color:var(--bg-primary);-moz-tab-size:2;tab-size:2}.md-editor-textarea::placeholder{color:var(--scrollbar-thumb-hover);font-style:italic}.md-editor-divider{height:2px;background:var(--border);cursor:row-resize;flex-shrink:0;transition:background .15s ease,box-shadow .15s ease}.md-editor-divider:hover{background:var(--accent-blue);box-shadow:0 0 6px #7aa2f766}.pane-btn--active{color:var(--accent-blue)}.plan-panel-body{display:flex;flex-direction:row;flex:1;min-height:0;overflow:hidden}.plan-renderer{position:relative;overflow:hidden;padding:0;min-width:0;-webkit-user-select:text;user-select:text}.plan-divider-h{width:2px;background:var(--border);cursor:col-resize;flex-shrink:0;transition:background .15s ease,box-shadow .15s ease}.plan-divider-h:hover{background:var(--accent-blue);box-shadow:0 0 6px #7aa2f766}.plan-editor-wrap{flex:1;display:flex;flex-direction:column;min-width:0;overflow:hidden}.plan-filename-input{background:var(--bg-primary);border:1px solid var(--border);color:var(--text-primary);padding:2px 6px;border-radius:3px;font-family:inherit;font-size:11px;width:120px;outline:none;transition:border-color .15s ease}.plan-filename-input:focus{border-color:var(--accent-blue)}body.resizing-panes-h,body.resizing-panes-h *{cursor:col-resize!important;-webkit-user-select:none!important;user-select:none!important}.md-preview{color:var(--text-primary);font-size:13px;line-height:1.6;word-wrap:break-word}.md-preview h1{color:var(--accent-blue);font-size:1.4em;margin:.6em 0 .3em;padding-bottom:.2em;border-bottom:1px solid var(--border)}.md-preview h2{color:var(--accent-purple);font-size:1.2em;margin:.5em 0 .3em}.md-preview h3{color:var(--accent-cyan);font-size:1.05em;margin:.4em 0 .2em}.md-preview p{margin:.4em 0}.md-preview code{background:var(--bg-tertiary);color:var(--text-bright);padding:1px 4px;border-radius:3px;font-size:.9em;font-family:JetBrains Mono,LXGW WenKai Mono,monospace}.md-preview pre{background:var(--bg-tertiary);border:1px solid var(--border);border-radius:4px;padding:10px 12px;overflow-x:auto;margin:.5em 0}.md-preview pre code{background:none;padding:0;border-radius:0}.md-preview blockquote{border-left:3px solid var(--accent-blue);padding:2px 12px;margin:.4em 0;color:var(--text-secondary)}.md-preview ul,.md-preview ol{padding-left:1.5em;margin:.3em 0}.md-preview li{margin:.15em 0}.md-preview table{border-collapse:collapse;width:100%;margin:.5em 0;font-size:12px}.md-preview th,.md-preview td{border:1px solid var(--border);padding:4px 8px;text-align:left}.md-preview th{background:var(--bg-tertiary);color:var(--accent-blue);font-weight:600}.md-preview a{color:var(--accent-blue);text-decoration:none}.md-preview a:hover{text-decoration:underline}.md-preview hr{border:none;border-top:1px solid var(--border);margin:.6em 0}.slash-dropdown{flex-shrink:0;max-height:200px;overflow-y:auto;background:var(--bg-secondary);border-bottom:1px solid var(--border);z-index:10;font-size:13px}.slash-item{display:flex;align-items:center;gap:10px;padding:6px 12px;cursor:pointer;transition:background .12s ease}.slash-item:hover,.slash-item--active{background:var(--bg-hover)}.slash-cmd{color:var(--accent-blue);font-weight:600;min-width:120px;font-family:JetBrains Mono,LXGW WenKai Mono,monospace}.slash-desc{color:var(--accent-purple);font-size:11px}.file-dropdown{flex-shrink:0;max-height:180px;overflow-y:auto;background:var(--bg-secondary);border-bottom:1px solid var(--border);z-index:10;font-size:12px}.file-item{display:flex;align-items:center;gap:8px;padding:5px 10px;cursor:pointer;transition:background .1s ease}.file-item:hover,.file-item--active{background:var(--bg-hover)}.file-loading{color:var(--text-secondary);cursor:default}.file-icon{flex-shrink:0;width:16px;text-align:center;font-size:13px}.file-name{color:var(--text-bright);font-family:JetBrains Mono,LXGW WenKai Mono,monospace;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.history-dropdown{flex-shrink:0;max-height:260px;overflow-y:auto;background:var(--bg-secondary);border-bottom:1px solid var(--border);z-index:10;font-size:12px}.history-item{display:flex;align-items:flex-start;gap:8px;padding:6px 10px;cursor:pointer;transition:background .1s ease;position:relative}.history-item:hover,.history-item--active{background:var(--bg-hover)}.history-empty{color:var(--text-secondary);cursor:default;justify-content:center;padding:12px}.history-text{flex:1;color:var(--text-bright);font-family:JetBrains Mono,LXGW WenKai Mono,monospace;white-space:pre-wrap;overflow-wrap:break-word;line-height:1.4}.history-time{flex-shrink:0;color:var(--text-secondary);font-size:10px;white-space:nowrap;margin-top:2px}.history-delete{flex-shrink:0;background:none;border:none;color:var(--text-secondary);cursor:pointer;font-size:14px;padding:0 2px;line-height:1;opacity:0;transition:opacity .1s ease,color .1s ease}.history-item:hover .history-delete,.history-item--active .history-delete{opacity:1}.history-delete:hover{color:var(--accent-red)}.tab-bar{display:flex;align-items:center;padding:0 10px;height:32px;background:var(--bg-secondary);border-top:1px solid var(--border);flex-shrink:0;overflow-x:auto;gap:3px}.tab-bar::-webkit-scrollbar{height:0}.tab-item{display:flex;align-items:center;gap:6px;padding:4px 12px;font-size:13px;color:var(--text-secondary);cursor:pointer;border-bottom:2px solid transparent;white-space:nowrap;transition:color .15s ease,border-color .15s ease,background .15s ease,box-shadow .15s ease;border-radius:5px 5px 0 0;-webkit-user-select:none;user-select:none;flex-shrink:0}.tab-item:hover{color:var(--text-primary);background:#7aa2f70f}.tab-item--active{color:var(--text-bright);border-bottom-color:var(--accent-blue);background:#7aa2f71a;box-shadow:inset 0 -1px 0 var(--accent-blue)}.tab-item__name{max-width:150px;overflow:hidden;text-overflow:ellipsis}.tab-item__count{font-size:10px;color:var(--scrollbar-thumb-hover)}.tab-item__close{font-size:14px;line-height:1;color:inherit;opacity:0;background:none;border:none;cursor:pointer;padding:0 2px;border-radius:3px;transition:opacity .1s ease}.tab-item:hover .tab-item__close{opacity:.5}.tab-item__close:hover{opacity:1!important;color:var(--accent-red);background:#f7768e1a}.tab-item__rename-input{background:transparent;border:1px solid var(--accent-blue);color:var(--text-bright);font-size:13px;font-family:inherit;padding:0 6px;border-radius:3px;outline:none;width:100px}.tab-bar-add{background:none;border:1px solid transparent;color:var(--text-secondary);font-size:18px;line-height:1;padding:2px 8px;border-radius:5px;cursor:pointer;margin-left:4px;flex-shrink:0}.tab-bar-add:hover{color:var(--accent-blue);border-color:var(--border);background:#7aa2f71a}.md-editor-actions{display:flex;align-items:center;gap:8px;padding:4px 8px;flex-shrink:0;background:var(--bg-secondary);border-top:1px solid var(--border)}.plan-anno-toolbar{display:flex;align-items:center;gap:6px;padding:3px 10px;height:28px;flex-shrink:0;background:var(--bg-secondary);border-bottom:1px solid var(--border)}.plan-anno-content{-webkit-user-select:text;user-select:text}.plan-insert-zone{position:relative;min-height:12px}.plan-insert-btn{display:none;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:20px;height:20px;border-radius:50%;border:1px solid var(--scrollbar-thumb-hover);background:var(--bg-secondary);color:var(--accent-blue);font-size:15px;line-height:1;cursor:pointer;padding:0 0 1px;z-index:2;transition:background .12s ease,border-color .12s ease,transform .12s ease;align-items:center;justify-content:center}.plan-insert-zone:hover .plan-insert-btn{display:flex}.plan-anno-content--editing .plan-insert-zone:hover .plan-insert-btn{display:none}.plan-empty-placeholder{display:flex;align-items:center;justify-content:center;min-height:120px;color:var(--text-secondary);font-size:13px;font-style:italic;cursor:pointer;-webkit-user-select:none;user-select:none;text-align:center;padding:16px}.plan-empty-placeholder:hover{color:var(--accent-blue)}.plan-insert-btn:hover{background:var(--bg-hover);border-color:var(--accent-blue);transform:translate(-50%,-50%) scale(1.15)}.plan-annotation-card{display:flex;align-items:flex-start;gap:6px;padding:6px 10px;margin:4px 0;background:#e0af681f;border-left:3px solid var(--accent-yellow);border-radius:0 4px 4px 0}.plan-annotation-card--editing{border-left-color:var(--accent-blue);background:#7aa2f70f}.plan-annotation-textarea{flex:1;min-height:36px;resize:vertical;border:1px solid var(--border);border-radius:3px;background:var(--bg-primary);color:var(--text-primary);font-family:JetBrains Mono,LXGW WenKai Mono,monospace;font-size:12px;padding:4px 6px;outline:none;transition:border-color .15s ease}.plan-annotation-textarea:focus{border-color:var(--accent-blue)}.plan-annotation-textarea::placeholder{color:var(--scrollbar-thumb-hover);font-style:italic}.plan-deletion-card{display:flex;align-items:center;gap:6px;padding:2px 8px;margin:2px 0;background:#f7768e0f;border-left:3px solid var(--accent-red);border-radius:0 4px 4px 0;font-size:11px}.plan-selection-float{position:absolute;z-index:1000;display:flex;flex-direction:column;gap:2px;background:var(--bg-secondary);border:1px solid var(--border);border-radius:6px;padding:2px;box-shadow:0 2px 8px #0000004d}.plan-selection-float button{width:24px;height:24px;border-radius:4px;border:none;cursor:pointer;font-size:14px;display:flex;align-items:center;justify-content:center;background:transparent;transition:background .15s,transform .1s}.plan-selection-float button:hover{transform:scale(1.1)}.plan-selection-float__delete{color:var(--accent-red)}.plan-selection-float__delete:hover{background:#f7768e33}.plan-selection-float__replace{color:var(--accent-blue)}.plan-selection-float__replace:hover{background:#7aa2f733}.plan-selection-float__comment{color:var(--accent-green)}.plan-selection-float__comment:hover{background:#9ece6a33}.plan-replace-card{display:flex;align-items:flex-start;gap:6px;padding:2px 8px;margin:2px 0;border-left:3px solid rgba(122,162,247,.6);background:#7aa2f70a;border-radius:0 4px 4px 0;font-size:11px}.plan-comment-card{display:flex;align-items:flex-start;gap:6px;padding:2px 8px;margin:2px 0;border-left:3px solid rgba(158,206,106,.6);background:#9ece6a0a;border-radius:0 4px 4px 0;font-size:11px}.plan-block--deleted{border-left:3px solid rgba(247,118,142,.5);padding-left:8px;border-radius:2px;position:relative}.plan-block--replaced{border-left:3px solid rgba(122,162,247,.5);padding-left:8px;border-radius:2px;position:relative}.plan-block--commented{border-left:3px solid rgba(158,206,106,.5);padding-left:8px;border-radius:2px;position:relative}.mermaid-diagram{margin:8px 0;padding:12px;background:var(--bg-secondary);border:1px solid var(--border);border-radius:6px;overflow-x:auto}.mermaid-diagram svg{display:block;margin:0 auto;max-width:100%;height:auto}.mermaid-error{border-left:3px solid var(--accent-red);padding-left:8px}.mermaid-error__msg{color:var(--accent-red);font-size:11px;margin-top:4px}.pane-btn--sm{font-size:11px;flex-shrink:0}.plan-file-browser{display:flex;flex-direction:column;height:100%;width:100%;background:var(--bg-secondary);overflow:hidden}.plan-file-browser__header{display:flex;align-items:center;justify-content:space-between;padding:4px 8px;height:28px;flex-shrink:0;border-bottom:1px solid var(--border)}.plan-file-browser__title{font-size:11px;color:var(--accent-blue);font-weight:600;letter-spacing:.3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;direction:rtl;text-align:left}.plan-file-browser__list{flex:1;overflow-y:auto;overflow-x:hidden;padding:2px 0}.plan-file-browser__status{padding:8px 10px;font-size:11px;color:var(--text-secondary);font-style:italic}.plan-file-browser__item{display:flex;align-items:center;padding:3px 8px;font-size:12px;cursor:pointer;gap:5px;transition:background .1s ease;border-left:2px solid transparent}.plan-file-browser__item:hover{background:var(--bg-tertiary)}.plan-file-browser__item--active{background:#7aa2f71a;border-left-color:var(--accent-blue)}.plan-file-browser__item--active .plan-file-browser__name{color:var(--text-bright)}.plan-file-browser__icon{flex-shrink:0;width:14px;font-size:10px;color:var(--text-secondary);text-align:center}.plan-file-browser__name{flex:1;color:var(--text-primary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.plan-file-browser__size{flex-shrink:0;font-size:9px;color:var(--scrollbar-thumb-hover);white-space:nowrap}.plan-file-browser__create{display:flex;align-items:center;gap:4px;padding:4px 6px;border-top:1px solid var(--border);flex-shrink:0}.plan-file-browser__input{flex:1;min-width:0;background:var(--bg-primary);border:1px solid var(--border);color:var(--text-primary);padding:2px 6px;border-radius:3px;font-family:inherit;font-size:11px;outline:none;transition:border-color .15s ease}.plan-file-browser__input:focus{border-color:var(--accent-blue)}.plan-file-browser__input::placeholder{color:var(--scrollbar-thumb-hover);font-style:italic}.plan-overlay-body{display:flex;flex:1;min-height:0;overflow:hidden}.plan-overlay-center{flex:1;min-width:0;overflow:hidden}.plan-anno-counts{display:inline-flex;align-items:center;gap:4px;font-size:10px;margin-left:4px}.plan-anno-counts__unsent{color:var(--accent-yellow)}.plan-anno-counts__sent{color:var(--accent-green)}.plan-anno-dropdown-trigger{display:flex;align-items:center;gap:4px;padding:2px 6px;border:1px solid var(--border);border-radius:3px;cursor:pointer;background:var(--bg-primary);transition:border-color .15s ease,background .15s ease;min-width:0}.plan-anno-dropdown-trigger:hover,.plan-anno-dropdown-trigger--active{border-color:var(--accent-blue);background:var(--bg-hover)}.plan-anno-dropdown-trigger__text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px;color:var(--text-secondary)}.plan-anno-dropdown-trigger__arrow{flex-shrink:0;font-size:9px;color:var(--text-secondary);transition:transform .15s ease}.plan-anno-dropdown-trigger--active .plan-anno-dropdown-trigger__arrow{transform:rotate(180deg)}.plan-anno-dropdown{position:absolute;top:100%;right:0;z-index:100;width:320px;max-height:300px;display:flex;flex-direction:column;background:var(--bg-secondary);border:1px solid var(--border);border-radius:4px;box-shadow:0 4px 12px #0000004d;overflow:hidden}.plan-anno-dropdown__header{display:flex;align-items:center;justify-content:center;padding:4px 6px;border-bottom:1px solid var(--border);flex-shrink:0}.plan-anno-dropdown__list{flex:1;overflow-y:auto;padding:2px 0}.plan-anno-dropdown__item{display:flex;align-items:center;gap:4px;padding:3px 6px;font-size:11px;border-bottom:1px solid var(--border-subtle, rgba(128,128,128,.1))}.plan-anno-dropdown__item:last-child{border-bottom:none}.plan-anno-dropdown__item--add{border-left:2px solid var(--accent-yellow)}.plan-anno-dropdown__item--del{border-left:2px solid var(--accent-red)}.plan-anno-dropdown__item--rep{border-left:2px solid var(--accent-blue)}.plan-anno-dropdown__item--com{border-left:2px solid var(--accent-green)}.plan-anno-dropdown__type{flex-shrink:0;width:14px;font-weight:700;text-align:center}.plan-anno-dropdown__text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--text-primary)}.plan-anno-dropdown__badge{flex-shrink:0;font-size:9px;padding:0 4px;border-radius:3px;background:var(--accent-green);color:var(--bg-primary)}.plan-anno-dropdown__empty{padding:8px;text-align:center;font-size:11px;color:var(--text-secondary);font-style:italic}
|