ai-cli-online 3.0.1 → 3.0.2
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/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
An AI-powered development environment that runs in your browser. Persistent terminal sessions, structured task lifecycle, and autonomous execution — all through a single Node.js process.
|
|
8
8
|
|
|
9
|
-
Built for running Claude Code, Codex, or any AI
|
|
9
|
+
Built for running Claude Code, Codex CLI, Gemini CLI, or any other AI CLI over unstable networks. tmux keeps everything alive when connections drop; the browser UI provides planning, annotation, and chat panels alongside the terminal.
|
|
10
10
|
|
|
11
11
|
**npm:** https://www.npmjs.com/package/ai-cli-online | **GitHub:** https://github.com/huacheng/ai-cli-online
|
|
12
12
|
|
package/README.zh-CN.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
在浏览器中运行的 AI 开发环境。持久化终端会话、结构化任务生命周期、自主执行 — 单个 Node.js 进程即可运行。
|
|
8
8
|
|
|
9
|
-
专为在不稳定网络下运行 Claude Code、Codex 或任意 AI
|
|
9
|
+
专为在不稳定网络下运行 Claude Code、Codex CLI、Gemini CLI 或任意 AI CLI 而构建。tmux 保证断网后进程存活;浏览器 UI 在终端旁提供规划、批注和对话面板。
|
|
10
10
|
|
|
11
11
|
**npm:** https://www.npmjs.com/package/ai-cli-online | **GitHub:** https://github.com/huacheng/ai-cli-online
|
|
12
12
|
|
package/package.json
CHANGED
package/server/package.json
CHANGED
package/shared/package.json
CHANGED
|
@@ -29,4 +29,4 @@ var Tn=Object.defineProperty;var Cn=(e,t,n)=>t in e?Tn(e,t,{enumerable:!0,config
|
|
|
29
29
|
`),[t]),R=a.useMemo(()=>Zr(t),[t]),C=a.useMemo(()=>{const m=new Map,b=new Map;return g.forEach((N,E)=>{if(N.type==="heading"){const J=bn(N.text||""),K=gn(J,b);m.set(E,K)}}),m},[g]),j=a.useRef(new Set),S=a.useRef(!1),[w,k]=a.useState(()=>{try{const m=localStorage.getItem(_e(r,n)),b=m?JSON.parse(m):gt;return j.current=Qe(b),b.replacements||(b.replacements=[]),b.comments||(b.comments=[]),b}catch{return gt}});Xr({sessionId:r,filePath:n,token:o,annotations:w,annLoadedRef:S,setAnnotations:k,baselineIdsRef:j});const[A,P]=a.useState(0),B=a.useMemo(()=>{const m=j.current,b=w.additions.length+w.deletions.length+w.replacements.length+w.comments.length;let N=0;return w.additions.forEach(E=>{m.has(E.id)&&N++}),w.deletions.forEach(E=>{m.has(E.id)&&N++}),w.replacements.forEach(E=>{m.has(E.id)&&N++}),w.comments.forEach(E=>{m.has(E.id)&&N++}),{total:b,sent:N,unsent:b-N}},[w,A]),[$,F]=a.useState(null),[O,D]=a.useState(""),T=a.useRef(null),[y,G]=a.useState(null),[W,U]=a.useState(""),V=a.useRef(null),[z,L]=a.useState(null),M=a.useRef(null),H=a.useRef(0),X=a.useRef(null);a.useEffect(()=>{const m=M.current;if(!m)return;let b;const N=()=>{clearTimeout(b),b=setTimeout(()=>{const E=$t(r,n);if(m.scrollTop>0)try{localStorage.setItem(E,String(m.scrollTop))}catch{}else localStorage.removeItem(E)},50)};return m.addEventListener("scroll",N,{passive:!0}),()=>{clearTimeout(b),m.removeEventListener("scroll",N)}},[r,n]),a.useEffect(()=>{if(!g.length)return;const m=localStorage.getItem($t(r,n));if(!m)return;const b=Number(m),N=M.current;if(!N||(N.scrollTop=b,N.scrollTop>=b-10))return;let E;const J=()=>{N.scrollTop=b,K.disconnect()},K=new MutationObserver(()=>{clearTimeout(E),E=setTimeout(J,80)});K.observe(N,{childList:!0,subtree:!0});const q=setTimeout(J,500);return()=>{clearTimeout(E),clearTimeout(q),K.disconnect()}},[r,n,g.length]),a.useEffect(()=>{$!=null&&requestAnimationFrame(()=>{var m;return(m=T.current)==null?void 0:m.focus()})},[$]),a.useEffect(()=>{y&&requestAnimationFrame(()=>{var m;return(m=V.current)==null?void 0:m.focus()})},[y]);const Y=a.useRef({annotations:w,activeInsert:$,insertText:O,pendingAction:y,pendingText:W,tokens:g,filePath:n,sessionId:r,token:o});Y.current={annotations:w,activeInsert:$,insertText:O,pendingAction:y,pendingText:W,tokens:g,filePath:n,sessionId:r,token:o},a.useEffect(()=>()=>{const m=Y.current;let b=m.annotations,N=!1;if(m.activeInsert!=null&&m.insertText.trim()){const E=Je(m.tokens,m.activeInsert+1);b={...b,additions:[...b.additions,{id:ce(),afterTokenIndex:m.activeInsert,sourceLine:E,content:m.insertText.trim()}]},N=!0}if(m.pendingAction&&m.pendingText.trim()){const E=m.pendingAction,J=m.pendingText.trim();E.type==="replace"?b={...b,replacements:[...b.replacements,{id:ce(),tokenIndices:E.tokenIndices,startLine:E.startLine,endLine:E.endLine,selectedText:E.text,content:J}]}:b={...b,comments:[...b.comments,{id:ce(),tokenIndices:E.tokenIndices,startLine:E.startLine,endLine:E.endLine,selectedText:E.text,content:J}]},N=!0}if(N){const E=JSON.stringify(b);try{localStorage.setItem(_e(m.sessionId,m.filePath),E)}catch{}hn(m.token,m.sessionId,m.filePath,E,Date.now()).catch(()=>{})}},[]);const Z=a.useCallback(m=>{if(!O.trim()){F(null),D("");return}const b=Je(g,m+1);k(N=>({...N,additions:[...N.additions,{id:ce(),afterTokenIndex:m,sourceLine:b,content:O.trim()}]})),F(null),D("")},[O,g]),ue=a.useCallback(m=>{k(b=>({...b,additions:b.additions.filter(N=>N.id!==m)}))},[]),ye=a.useCallback((m,b)=>{k(N=>({...N,additions:N.additions.map(E=>E.id===m?{...E,id:ce(),content:b}:E)}))},[]),$e=a.useCallback(()=>{var m;z&&(k(b=>({...b,deletions:[...b.deletions,{id:ce(),tokenIndices:z.tokenIndices,startLine:z.startLine,endLine:z.endLine,selectedText:z.text.slice(0,80)}]})),L(null),(m=window.getSelection())==null||m.removeAllRanges())},[z]),Se=a.useCallback(m=>{var b;z&&(G({type:m,tokenIndices:z.tokenIndices,startLine:z.startLine,endLine:z.endLine,text:z.text.slice(0,80)}),U(""),L(null),(b=window.getSelection())==null||b.removeAllRanges())},[z]),se=a.useCallback(()=>{if(!y)return;const m=W.trim();if(!m){G(null),U("");return}y.type==="replace"?k(b=>({...b,replacements:[...b.replacements,{id:ce(),tokenIndices:y.tokenIndices,startLine:y.startLine,endLine:y.endLine,selectedText:y.text,content:m}]})):k(b=>({...b,comments:[...b.comments,{id:ce(),tokenIndices:y.tokenIndices,startLine:y.startLine,endLine:y.endLine,selectedText:y.text,content:m}]})),G(null),U("")},[y,W]),ve=a.useCallback(m=>{k(b=>({...b,replacements:b.replacements.filter(N=>N.id!==m)}))},[]),le=a.useCallback((m,b)=>{k(N=>({...N,replacements:N.replacements.map(E=>E.id===m?{...E,id:ce(),content:b}:E)}))},[]),re=a.useCallback(m=>{k(b=>({...b,comments:b.comments.filter(N=>N.id!==m)}))},[]),Oe=a.useCallback((m,b)=>{k(N=>({...N,comments:N.comments.map(E=>E.id===m?{...E,id:ce(),content:b}:E)}))},[]),ae=a.useCallback(m=>{k(b=>({...b,deletions:b.deletions.filter(N=>N.id!==m)}))},[]),Re=a.useCallback((m,b)=>{k(N=>({...N,deletions:N.deletions.map(E=>E.id===m?{...E,id:ce(),selectedText:b}:E)}))},[]),fe=a.useCallback(m=>{let b=m instanceof Element?m:m.parentElement;for(;b&&b!==M.current;){if(b.hasAttribute("data-token-index"))return b;b=b.parentElement}return null},[]),me=a.useCallback(()=>{const m=window.getSelection();if(!m||m.isCollapsed||!M.current){L(null);return}const b=m.toString().trim();if(!b){L(null);return}const N=m.getRangeAt(0);if(!M.current.contains(N.commonAncestorContainer)){L(null);return}const E=fe(N.startContainer),J=fe(N.endContainer);if(!E||!J){L(null);return}const K=parseInt(E.getAttribute("data-token-index")||"0",10),q=parseInt(J.getAttribute("data-token-index")||"0",10),Q=[];for(let at=Math.min(K,q);at<=Math.max(K,q);at++)Q.push(at);const ge=Je(g,Math.min(K,q)),Me=Je(g,Math.max(K,q)+1),Be=N.getBoundingClientRect(),st=M.current,yt=st.getBoundingClientRect();navigator.clipboard.writeText(b).catch(()=>{});const Ue=X.current,vt=Ue&&Date.now()-Ue.time<500;H.current=Date.now(),L({x:(vt?Ue.x:Be.right)-yt.left+st.scrollLeft+6,y:(vt?Ue.y:Be.top)-yt.top+st.scrollTop-44,tokenIndices:Q,startLine:ge,endLine:Me,text:b})},[g,fe]),he=a.useRef(void 0);a.useEffect(()=>{const m=()=>{he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{const b=window.getSelection();if(!b||b.isCollapsed||!M.current){if(Date.now()-H.current<300)return;L(null);return}const N=b.anchorNode;N&&M.current.contains(N)&&me()},120)};return document.addEventListener("selectionchange",m),()=>{document.removeEventListener("selectionchange",m),he.current&&clearTimeout(he.current)}},[me]);const Pe=_(m=>m.theme);Gr(M,g,Pe);const ke=a.useCallback(()=>{const m=j.current;return{additions:w.additions.filter(b=>!m.has(b.id)),deletions:w.deletions.filter(b=>!m.has(b.id)),replacements:w.replacements.filter(b=>!m.has(b.id)),comments:w.comments.filter(b=>!m.has(b.id))}},[w]),Te=a.useCallback(async()=>{const m=ke();if(!Pt(m))return;const b=Ot(m,x),N=Ut(n);try{const{path:E}=await _t(o,r,N,b),J=Bt(n,E);c(J),j.current=Qe(w),P(K=>K+1)}catch{}},[ke,w,x,c,n,o,r]),de=a.useCallback(async(m,b)=>{if(!i)return;const N={additions:[],deletions:[],replacements:[],comments:[]};if(b==="add"){const K=w.additions.find(q=>q.id===m);if(!K)return;N.additions.push(K)}else if(b==="del"){const K=w.deletions.find(q=>q.id===m);if(!K)return;N.deletions.push(K)}else if(b==="rep"){const K=w.replacements.find(q=>q.id===m);if(!K)return;N.replacements.push(K)}else{const K=w.comments.find(q=>q.id===m);if(!K)return;N.comments.push(K)}const E=Ot(N,x),J=Ut(n);try{const{path:K}=await _t(o,r,J,E);i(Bt(n,K)),j.current.add(m),P(q=>q+1)}catch{}},[i,n,w,x,o,r]),Ne=a.useCallback((m,b)=>{b==="add"?ue(m):b==="del"?ae(m):b==="rep"?ve(m):re(m)},[ue,ae,ve,re]);a.useImperativeHandle(f,()=>({getSummary:()=>{const m=ke();return Pt(m)?"[pending annotations]":""},handleEscape:()=>y?(se(),!0):$!=null?(Z($),!0):!1,getScrollTop:()=>{var m;return((m=M.current)==null?void 0:m.scrollTop)??0},setScrollTop:m=>{requestAnimationFrame(()=>{M.current&&(M.current.scrollTop=m)})}}),[ke,$,Z,y,se]);const Le=a.useMemo(()=>{const m=new Set;return w.deletions.forEach(b=>b.tokenIndices.forEach(N=>m.add(N))),m},[w.deletions]),De=a.useMemo(()=>{const m=new Set;return w.replacements.forEach(b=>b.tokenIndices.forEach(N=>m.add(N))),m},[w.replacements]),ot=a.useMemo(()=>{const m=new Set;return w.comments.forEach(b=>b.tokenIndices.forEach(N=>m.add(N))),m},[w.comments]),Fe=a.useMemo(()=>{const m=new Map;return w.additions.forEach(b=>{const N=m.get(b.afterTokenIndex)||[];N.push(b),m.set(b.afterTokenIndex,N)}),m},[w.additions]),v=B.unsent>0,I=a.useCallback(m=>j.current.has(m),[]);return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[s.jsxs("div",{className:"plan-anno-toolbar",children:[s.jsx("span",{style:{fontSize:"11px",color:"var(--text-secondary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},title:n,children:n.split("/").pop()||n}),d&&s.jsx("button",{className:"pane-btn",onClick:d,title:"Refresh current file",children:"↻"}),s.jsx("button",{className:"pane-btn",onClick:Te,disabled:!v,title:"Send all annotations",style:v?{color:"var(--accent-green)"}:{opacity:.4},children:"Send"}),s.jsx(ro,{annotations:w,annCounts:B,isSent:I,onSendAll:Te,onSendSingle:de,onDelete:Ne}),p&&s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:async()=>{await Te(),p()},title:"Send annotations & close file",children:"×"})]}),s.jsxs("div",{style:{display:"flex",flex:1,minHeight:0},children:[s.jsxs("div",{ref:M,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:m=>{X.current={x:m.clientX,y:m.clientY,time:Date.now()},me()},children:[!u&&s.jsx(Ht,{index:-1,active:$===-1,additions:Fe.get(-1),onOpen:()=>{F(-1),D("")},onSubmit:()=>Z(-1),onRemoveAddition:ue,onEditAddition:ye,onSendSingle:i?m=>de(m,"add"):void 0,isSent:I,insertText:O,setInsertText:D,textareaRef:$===-1?T:void 0,expanded:l,alwaysShow:g.length===0,fontSize:h}),g.map((m,b)=>{const N=Yr(m);return s.jsxs("div",{children:[s.jsx("div",{"data-token-index":b,id:C.get(b),className:Le.has(b)?"plan-block--deleted":De.has(b)?"plan-block--replaced":ot.has(b)?"plan-block--commented":void 0,dangerouslySetInnerHTML:{__html:N}}),w.deletions.filter(E=>E.tokenIndices[0]===b).map(E=>s.jsx(lt,{type:"del",annotation:E,fontSize:h,onEdit:Re,onRemove:ae,onSend:i?J=>de(J,"del"):void 0,isSent:j.current.has(E.id)},E.id)),w.replacements.filter(E=>E.tokenIndices[0]===b).map(E=>s.jsx(lt,{type:"rep",annotation:E,fontSize:h,onEdit:le,onRemove:ve,onSend:i?J=>de(J,"rep"):void 0,isSent:j.current.has(E.id)},E.id)),w.comments.filter(E=>E.tokenIndices[0]===b).map(E=>s.jsx(lt,{type:"com",annotation:E,fontSize:h,onEdit:Oe,onRemove:re,onSend:i?J=>de(J,"com"):void 0,isSent:j.current.has(E.id)},E.id)),y&&y.tokenIndices[0]===b&&s.jsxs("div",{className:y.type==="replace"?"plan-replace-card":"plan-comment-card",style:{padding:"4px 8px"},children:[s.jsx("span",{style:{color:y.type==="replace"?"var(--accent-blue)":"var(--accent-green)",flexShrink:0},children:y.type==="replace"?"⇄":"?"}),s.jsx("textarea",{ref:V,className:"plan-annotation-textarea",value:W,onChange:E=>U(E.target.value),onKeyDown:E=>{if(E.key==="Enter"&&(E.ctrlKey||E.metaKey)){E.preventDefault(),se();return}if(E.key==="Escape"){E.preventDefault(),se();return}},onBlur:se,placeholder:y.type==="replace"?"Replace with... (Ctrl+Enter to save)":"Comment... (Ctrl+Enter to save)",rows:Ze(W),style:{fontSize:`${h}px`,flex:1}})]}),!u&&s.jsx(Ht,{index:b,active:$===b,additions:Fe.get(b),onOpen:()=>{F(b),D("")},onSubmit:()=>Z(b),onRemoveAddition:ue,onEditAddition:ye,onSendSingle:i?E=>de(E,"add"):void 0,isSent:I,insertText:O,setInsertText:D,textareaRef:$===b?T:void 0,expanded:l,fontSize:h})]},b)}),!u&&z&&s.jsx(so,{x:z.x,y:z.y,onDelete:$e,onReplace:()=>Se("replace"),onComment:()=>Se("comment")})]}),s.jsx(to,{headings:R,scrollRef:M})]})]})});function Ht({index:e,active:t,additions:n,onOpen:r,onSubmit:o,onRemoveAddition:c,onEditAddition:i,onSendSingle:d,isSent:p,insertText:l,setInsertText:u,textareaRef:f,expanded:h,alwaysShow:g,fontSize:x=14}){const[R,C]=a.useState(null),[j,S]=a.useState(""),w=a.useRef(null),k=mt(),A=mt();a.useEffect(()=>{R&&(k.clearUndo(),requestAnimationFrame(()=>{const D=w.current;D&&(D.focus(),D.selectionStart=D.selectionEnd=D.value.length)}))},[R]),a.useEffect(()=>{t&&A.clearUndo()},[t]);const P=a.useCallback(D=>{S(T=>(k.pushUndo(T),D))},[k]),B=a.useCallback(D=>{A.pushUndo(l),u(D)},[l,u,A]),$=a.useCallback(D=>{C(D.id),S(D.content)},[]),F=a.useCallback(()=>{if(!R)return;const D=j.trim();D?i(R,D):c(R),C(null),S("")},[R,j,i,c]),O=a.useCallback(()=>{C(null),S("")},[]);return s.jsxs("div",{className:`plan-insert-zone${g?" plan-insert-zone--empty":""}`,"data-zone-index":e,children:[n==null?void 0:n.map(D=>s.jsx("div",{className:"plan-annotation-card",children:R===D.id?s.jsx("textarea",{ref:w,className:"plan-annotation-textarea",value:j,onChange:T=>P(T.target.value),onKeyDown:T=>{if(T.key==="Enter"&&(T.ctrlKey||T.metaKey)){T.preventDefault(),F();return}if(T.key==="Escape"){T.preventDefault(),O();return}if(T.key==="Tab"){ht(T,P);return}},onBlur:F,rows:Ze(j),style:{fontSize:`${x}px`,flex:1,...h?{minWidth:300}:void 0}}):s.jsxs(s.Fragment,{children:[s.jsx("span",{style:{flex:1,fontSize:`${x}px`,color:"var(--accent-yellow)",whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>$(D),title:"Double-click to edit",children:D.content}),d&&(()=>{const T=(p==null?void 0:p(D.id))??!1;return s.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!T&&d(D.id),disabled:T,title:T?"Already sent":"Send to terminal",style:T?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),s.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>$(D),style:{color:"var(--accent-blue)"},title:"Edit annotation",children:"✎"}),s.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>c(D.id),children:"×"})]})},D.id)),t?s.jsx("div",{className:"plan-annotation-card plan-annotation-card--editing",children:s.jsx("textarea",{ref:f,className:"plan-annotation-textarea",value:l,onChange:D=>B(D.target.value),onKeyDown:D=>{if(D.key==="Enter"&&(D.ctrlKey||D.metaKey)){D.preventDefault(),o();return}if(D.key==="Escape"){D.preventDefault(),o();return}if(D.key==="Tab"){ht(D,B);return}},onBlur:o,placeholder:"Add annotation... (Ctrl+Enter or Esc to save)",rows:Ze(l),style:{fontSize:`${x}px`,...h?{minWidth:300}:void 0}})}):g&&!(n!=null&&n.length)?s.jsx("div",{className:"plan-empty-placeholder",onDoubleClick:r,title:"Double-click or Ctrl+Enter to edit",children:"Write down your plans here. Double-click or Ctrl+Enter to edit."}):s.jsx("button",{className:"plan-insert-btn",onClick:r,title:"Add annotation here",children:"+"})]})}async function be(e,t,n){const r=n?{path:n}:void 0;return ne.get(e,t,"files",r)}function co(e,t,n,r){return new Promise((o,c)=>{const i=new FormData;for(const p of n)i.append("files",p);const d=new XMLHttpRequest;d.open("POST",`${xe}/api/sessions/${encodeURIComponent(t)}/upload`),d.setRequestHeader("Authorization",`Bearer ${e}`),d.upload.addEventListener("progress",p=>{p.lengthComputable&&r&&r(Math.round(p.loaded/p.total*100))}),d.addEventListener("load",()=>{d.status>=200&&d.status<300?o():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 Kt(e,t){return(await ne.get(e,t,"cwd")).cwd}async function io(e,t,n){return ne.post(e,t,"touch",{name:n})}async function lo(e,t,n){return ne.post(e,t,"mkdir",{path:n})}async function uo(e,t,n){return ne.del(e,t,"rm",{path:n})}async function fo(e,t){const n=await ne.getBlob(e,t,"download-cwd"),r=await n.blob(),o=URL.createObjectURL(r),c=document.createElement("a");c.href=o;const i=n.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(o)}async function po(e,t,n){const o=await(await ne.getBlob(e,t,"download",{path:n})).blob(),c=URL.createObjectURL(o),i=document.createElement("a");i.href=c,i.download=n.split("/").pop()||"download",document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(c)}function xn(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(1)} GB`}function mo(e,t){if(t==="directory")return"📁";const n=e.slice(e.lastIndexOf(".")).toLowerCase();return n===".pdf"?"📕":n===".html"||n===".htm"?"🌐":n===".md"?"📝":"📄"}function yn(e){const t=new Date(e*1e3),n=r=>String(r).padStart(2,"0");return`${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function ho({sessionId:e,token:t,planDir:n,selectedFile:r,onSelectFile:o,onCreateFile:c,onDeleteFile:i}){const[d,p]=a.useState([]),[l,u]=a.useState(!0),[f,h]=a.useState(""),[g,x]=a.useState(!1),R=a.useRef(null),[C,j]=a.useState(n),S=a.useCallback(async()=>{if(!(!t||!C)){u(!0);try{const G=(await be(t,e,C)).files.filter(W=>W.type==="file"&&W.name.toLowerCase().endsWith(".md")||W.type==="directory").sort((W,U)=>{const V=W.type==="file"&&W.name===".index.md",z=U.type==="file"&&U.name===".index.md";return V&&!z?-1:!V&&z?1:W.type==="directory"&&U.type!=="directory"?-1:W.type!=="directory"&&U.type==="directory"?1:W.name.localeCompare(U.name)});p(G)}catch{p([])}finally{u(!1)}}},[t,e,C]);a.useEffect(()=>{S()},[S]),a.useEffect(()=>{const y=setInterval(S,5e3);return()=>clearInterval(y)},[S]);const w=a.useCallback(()=>{const y=n.substring(0,n.lastIndexOf("/")+1);return C.startsWith(y)?C.substring(y.length):C},[n,C]),k=a.useCallback(async()=>{const y=f.trim();if(!y)return;const G=y.endsWith(".md")?y:`${y}.md`;x(!0);try{const W=await io(t,e,`${w()}/${G}`);W.ok&&(h(""),await S(),c(W.path))}catch{}finally{x(!1)}},[f,t,e,w,S,c]),A=a.useCallback(async()=>{const y=f.trim().replace(/\/+$/,"");if(y){x(!0);try{await lo(t,e,`${w()}/${y}`),h(""),await S()}catch{}finally{x(!1)}}},[f,t,e,w,S]),P=a.useCallback(async y=>{const G=`${C}/${y.name}`,W=y.type==="directory"?`folder "${y.name}" and all its contents`:`"${y.name}"`;if(window.confirm(`Delete ${W}?`))try{await uo(t,e,G),i==null||i(G),await S()}catch{}},[t,e,C,S,i]),B=a.useCallback(y=>{j(G=>`${G}/${y}`)},[]),$=a.useCallback(()=>{C!==n&&j(y=>y.substring(0,y.lastIndexOf("/")))},[C,n]),F=n.split("/").pop()||"AiTasks",O=(()=>{const y=n.split("/");return y.length>=2?y[y.length-2]+"/":""})(),D=C===n?O+F+"/":O+F+"/"+C.substring(n.length+1)+"/",T=r?r.split("/").pop():null;return s.jsxs("div",{className:"plan-file-browser",children:[s.jsxs("div",{className:"plan-file-browser__header",children:[s.jsx("span",{className:"plan-file-browser__title",title:D,children:D}),s.jsx("button",{className:"pane-btn pane-btn--sm",onClick:S,title:"Refresh file list",style:{fontSize:12},children:"↻"})]}),s.jsxs("div",{className:"plan-file-browser__create",children:[s.jsx("input",{ref:R,className:"plan-file-browser__input",value:f,onChange:y=>h(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),k())},placeholder:"name",disabled:g}),s.jsx("button",{className:"pane-btn pane-btn--sm",onClick:k,disabled:g||!f.trim(),title:"Create new .md file",style:f.trim()?{color:"var(--accent-green)",fontWeight:700,fontSize:14}:{opacity:.4,fontWeight:700,fontSize:14},children:"+"}),s.jsx("button",{className:"pane-btn pane-btn--sm",onClick:A,disabled:g||!f.trim(),title:"Create new folder",style:f.trim()?{color:"var(--accent-blue)"}:{opacity:.4},children:"📁"})]}),s.jsxs("div",{className:"plan-file-browser__list",children:[l&&d.length===0&&s.jsx("div",{className:"plan-file-browser__status",children:"Loading..."}),!l&&d.length===0&&s.jsx("div",{className:"plan-file-browser__status",children:"No .md files"}),C!==n&&s.jsxs("div",{className:"plan-file-browser__item",onClick:$,title:"Go up to parent directory",style:{cursor:"pointer"},children:[s.jsx("span",{className:"plan-file-browser__icon",style:{color:"var(--accent-blue)"},children:"←"}),s.jsx("span",{className:"plan-file-browser__name",style:{color:"var(--accent-blue)"},children:".."})]}),d.map(y=>{const G=`${C}/${y.name}`,W=y.type==="file"&&y.name===T,U=y.type==="directory";return s.jsxs("div",{className:`plan-file-browser__item${W?" plan-file-browser__item--active":""}`,onClick:()=>U?B(y.name):o(G),title:U?`Open folder ${y.name}`:y.name,style:{cursor:"pointer"},children:[s.jsx("span",{className:"plan-file-browser__icon",children:U?"📁":y.name===".index.md"?"🔒":"□"}),s.jsxs("span",{className:"plan-file-browser__name",children:[y.name,U?"/":""]}),!U&&s.jsx("span",{className:"plan-file-browser__size",children:xn(y.size)}),y.name!==".index.md"&&s.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm plan-file-browser__delete",onClick:V=>{V.stopPropagation(),P(y)},title:`Delete ${y.name}`,children:"×"})]},y.name)})]})]})}const dt={status:"idle",mode:"lines",lines:[],content:"",buffer:null,totalSize:0,receivedBytes:0,mtime:0,error:null},go=200;function bo(){const[e,t]=a.useState(dt),n=a.useRef("lines"),r=a.useRef([]),o=a.useRef(""),c=a.useRef(""),i=a.useRef([]),d=a.useRef(0),p=a.useRef(0),l=a.useRef(null),u=a.useRef(null),f=a.useCallback(()=>{const j=n.current;t(S=>({...S,receivedBytes:d.current,...j==="lines"?{lines:[...r.current]}:{},...j==="content"?{content:c.current}:{}}))},[]),h=a.useCallback(()=>{l.current===null&&(l.current=window.setTimeout(()=>{l.current=null,f()},go))},[f]),g=a.useCallback(j=>{n.current=j,r.current=[],o.current="",c.current="",i.current=[],d.current=0,p.current=0,u.current=new TextDecoder,l.current!==null&&(clearTimeout(l.current),l.current=null),t({...dt,mode:j,status:"streaming"})},[]),x=a.useCallback(j=>{d.current+=j.length;const S=n.current;if(S==="lines"){const k=u.current.decode(j,{stream:!0}).split(`
|
|
30
30
|
`);k[0]=o.current+k[0],o.current=k.pop(),k.length>0&&r.current.push(...k)}else if(S==="content"){const w=u.current.decode(j,{stream:!0});c.current+=w}else i.current.push(new Uint8Array(j));h()},[h]),R=a.useCallback(j=>{switch(j.type){case"file-stream-start":p.current=j.size,t(S=>({...S,totalSize:j.size,mtime:j.mtime}));break;case"file-stream-end":{l.current!==null&&(clearTimeout(l.current),l.current=null);const S=n.current;let w=r.current,k=c.current,A=null;if(S==="lines"){const P=u.current.decode(),B=o.current+P;B&&(w=[...w,B],r.current=w),o.current=""}else if(S==="content"){const P=u.current.decode();k=c.current+P,c.current=k}else{const P=i.current.reduce(($,F)=>$+F.length,0);A=new Uint8Array(P);let B=0;for(const $ of i.current)A.set($,B),B+=$.length;i.current=[]}t({status:"complete",mode:S,lines:S==="lines"?[...w]:[],content:S==="content"?k:"",buffer:S==="binary"?A:null,totalSize:p.current,receivedBytes:d.current,mtime:0,error:null});break}case"file-stream-error":l.current!==null&&(clearTimeout(l.current),l.current=null),t(S=>({...S,status:"error",error:j.error}));break}},[]),C=a.useCallback(()=>{l.current!==null&&(clearTimeout(l.current),l.current=null),r.current=[],o.current="",c.current="",i.current=[],d.current=0,p.current=0,u.current=null,t(dt)},[]);return{state:e,startStream:g,handleChunk:x,handleControl:R,reset:C}}async function Jt(e,t,n,r){const o={path:n};return r&&(o.since=String(r)),ne.getOptional(e,t,"file-content",o)}function Gt({label:e,percent:t}){return s.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:8},children:[s.jsx("span",{style:{color:"var(--text-secondary)",fontSize:13},children:e}),t!=null&&s.jsxs("div",{style:{width:120,display:"flex",alignItems:"center",gap:6},children:[s.jsx("div",{style:{flex:1,height:4,backgroundColor:"var(--border)",borderRadius:2,overflow:"hidden"},children:s.jsx("div",{style:{height:"100%",width:`${t}%`,backgroundColor:"var(--accent-blue)",transition:"width 0.2s"}})}),s.jsxs("span",{style:{fontSize:10,color:"var(--text-secondary)",whiteSpace:"nowrap"},children:[t,"%"]})]})]})}function xo({sessionId:e,token:t,connected:n,onRequestFileStream:r,onSendToTerminal:o}){const c=bo(),[i,d]=a.useState(!1),[p,l]=a.useState(null),[u,f]=a.useState(null),[h,g]=a.useState(""),[x,R]=a.useState(!1),[C,j]=a.useState(!1),S=a.useRef(null),w=`plan-selected-file-${e}`,k=a.useRef(void 0);a.useEffect(()=>{if(u)return clearTimeout(k.current),k.current=setTimeout(()=>{try{localStorage.setItem(w,u)}catch{}},50),()=>clearTimeout(k.current)},[u,w]);const A=a.useRef(null);a.useEffect(()=>{A.current=null;let L=!1;return R(!0),j(!1),(async()=>{let M="";try{const H=await be(t,e);if(L)return;if(M=H.home||"",H.files.find(Y=>Y.name==="AiTasks"&&Y.type==="directory")){const Y=H.cwd+"/AiTasks";l(Y);const Z=localStorage.getItem(w);Z&&Z.startsWith(Y+"/")&&f(Z)}else l(null),f(null),j(!0)}catch{l(null)}finally{L||R(!1)}try{if(L)return;if(M){const H=`${M}/.claude/plugins/installed_plugins.json`,X=await Jt(t,e,H,0);if(!L&&X)try{const Y=JSON.parse(X.content);"ai-cli-task@moonview"in(Y.plugins||Y)||d(!0)}catch{d(!0)}}}catch{}})(),()=>{L=!0}},[e,t]),a.useEffect(()=>(wr(e,c.handleChunk,c.handleControl),()=>Sr(e)),[e,c.handleChunk,c.handleControl]),a.useEffect(()=>{!u||!n||A.current===u&&h||(A.current=u,c.reset(),c.startStream("content"),r==null||r(u))},[u,n]);const P=a.useRef(0);a.useEffect(()=>{c.state.status==="complete"&&u&&(g(c.state.content),P.current=Date.now())},[c.state.status,c.state.content,u]),a.useEffect(()=>{if(!u||!n||!h)return;const L=setInterval(async()=>{if(P.current)try{const M=await Jt(t,e,u,P.current);M&&(g(M.content),P.current=M.mtime)}catch{}},3e3);return()=>clearInterval(L)},[u,n,h,t,e]);const B=a.useRef(new Map),$=a.useCallback(()=>{var M,H;if(!u)return;const L=((H=(M=S.current)==null?void 0:M.getScrollTop)==null?void 0:H.call(M))??0;L>0&&B.current.set(u,L)},[u]);a.useEffect(()=>{if(!u||!h)return;const L=B.current.get(u);L!=null&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{var M,H;(H=(M=S.current)==null?void 0:M.setScrollTop)==null||H.call(M,L)})})},[u,h]);const F=a.useCallback(L=>{L!==u&&($(),f(L),g(""),A.current=null)},[u,$]),O=a.useCallback(L=>{u&&(u===L||u.startsWith(L+"/"))&&(f(null),g(""),A.current=null)},[u]),D=a.useCallback(L=>{f(L),g(""),A.current=null},[]),T=a.useCallback(L=>{L&&(o==null||o(L))},[o]),y=a.useCallback(()=>{$(),f(null),g(""),A.current=null},[$]),G=a.useCallback(()=>{!u||!n||(A.current=null,g(""),c.reset(),c.startStream("content"),r==null||r(u),A.current=u)},[u,n,c,r]),[W,U]=a.useState(()=>{const L=localStorage.getItem(`plan-fb-width-${e}`);if(L){const M=Number(L);if(Number.isFinite(M)&&M>=60&&M<=300)return M}return 130}),V=a.useRef(W);if(W!==V.current){V.current=W;try{localStorage.setItem(`plan-fb-width-${e}`,String(Math.round(W)))}catch{}}const z=a.useCallback(L=>{L.preventDefault();const M=L.clientX,H=W;document.body.classList.add("resizing-panes");const X=Z=>{const ue=Z.clientX-M;U(Math.min(300,Math.max(60,H+ue)))},Y=()=>{document.body.classList.remove("resizing-panes"),document.removeEventListener("mousemove",X),document.removeEventListener("mouseup",Y)};document.addEventListener("mousemove",X),document.addEventListener("mouseup",Y)},[W]);return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[i&&s.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:[s.jsx("span",{style:{color:"var(--accent-yellow)",flex:1},children:"ai-cli-task plugin not installed"}),s.jsx("button",{className:"pane-btn",style:{color:"var(--accent-green)",fontSize:11},onClick:()=>{o&&o("/plugin marketplace add huacheng/moonview && /plugin install ai-cli-task@moonview"),d(!1)},children:"Install"}),s.jsx("button",{className:"pane-btn",style:{fontSize:11},onClick:()=>d(!1),children:"×"})]}),s.jsxs("div",{className:"plan-overlay-body",children:[p&&s.jsxs(s.Fragment,{children:[s.jsx("div",{style:{width:W,flexShrink:0,overflow:"hidden"},children:s.jsx(ho,{sessionId:e,token:t,planDir:p,selectedFile:u,onSelectFile:F,onCreateFile:D,onDeleteFile:O})}),s.jsx("div",{onMouseDown:z,style:{width:2,flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:L=>{L.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:L=>{L.currentTarget.style.backgroundColor="var(--border)"}})]}),s.jsx("div",{className:"plan-overlay-center",children:x?s.jsx(Gt,{label:"Loading AiTasks/..."}):C?s.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:12,padding:"0 20px"},children:[s.jsx("span",{style:{color:"var(--text-secondary)",fontSize:14},children:"AiTasks/ directory not found"}),s.jsxs("span",{style:{color:"var(--text-secondary)",fontSize:12,textAlign:"center"},children:["Run ",s.jsx("code",{style:{color:"var(--accent-blue)",backgroundColor:"var(--bg-secondary)",padding:"2px 6px",borderRadius:3},children:"/ai-cli-task init <name>"})," in the terminal to create a task"]})]}):u&&!h&&(c.state.status==="streaming"||c.state.status==="idle")?s.jsx(Gt,{label:`Loading ${u.split("/").pop()}...`,percent:c.state.totalSize>0?Math.round(c.state.receivedBytes/c.state.totalSize*100):void 0}):u?s.jsx(ao,{ref:S,markdown:h,filePath:u,sessionId:e,token:t,onExecute:T,onSend:o,onRefresh:G,onClose:y,readOnly:u.endsWith("/.index.md")}):s.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:8},children:s.jsx("span",{style:{color:"var(--text-secondary)",fontSize:13,fontStyle:"italic"},children:"Select a file from the left panel"})})})]})]})}async function yo(e,t){try{return(await ne.get(e,t,"draft")).content??""}catch{return""}}async function Vt(e,t,n){try{await ne.put(e,t,"draft",{content:n})}catch{}}const xt="chat-history",qt=50;function vn(){try{const e=localStorage.getItem(xt);return e?JSON.parse(e):[]}catch{return[]}}function vo(e){const n=vn().filter(r=>r.text!==e);n.unshift({text:e,ts:Date.now()}),n.length>qt&&(n.length=qt),localStorage.setItem(xt,JSON.stringify(n))}const Yt=[{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"}],wo=a.forwardRef(function({onSend:t,onContentChange:n,sessionId:r,token:o},c){const i=_(v=>v.fontSize),[d,p]=a.useState(""),l=a.useRef(null),u=a.useRef(void 0),f=a.useRef(!1),h=a.useRef(!1),{pushUndo:g,popUndo:x}=mt(),R=a.useRef(d);R.current=d;const C=a.useCallback(()=>g(R.current),[g]),[j,S]=a.useState(!1),[w,k]=a.useState(""),[A,P]=a.useState(0),[B,$]=a.useState(!1),[F,O]=a.useState([]),[D,T]=a.useState(0),[y,G]=a.useState(""),W=a.useRef(null),U=a.useMemo(()=>{if(!y)return F;const v=y.toLowerCase();return F.filter(I=>I.text.toLowerCase().includes(v))},[F,y]),[V,z]=a.useState(!1),[L,M]=a.useState(""),[H,X]=a.useState(""),[Y,Z]=a.useState(0),[ue,ye]=a.useState([]),[$e,Se]=a.useState(!1),se=a.useRef(""),ve=a.useRef(null),le=a.useMemo(()=>{if(!w)return Yt;const v=w.toLowerCase();return Yt.filter(I=>I.cmd.toLowerCase().includes(v)||I.desc.toLowerCase().includes(v))},[w]),re=a.useMemo(()=>{let v=ue;if(L){const I=L.toLowerCase();v=v.filter(m=>m.name.toLowerCase().includes(I))}return[...v].sort((I,m)=>I.type==="directory"&&m.type!=="directory"?-1:I.type!=="directory"&&m.type==="directory"?1:I.name.localeCompare(m.name))},[ue,L]),Oe=_(v=>v.latency),ae=`chat-draft-${r}`,Re=a.useRef(!1),fe=a.useRef(void 0);a.useEffect(()=>{try{const I=localStorage.getItem(ae);I&&!h.current&&p(I)}catch{}let v=!1;return yo(o,r).then(I=>{if(v||h.current){f.current=!0;return}if(I){p(I);try{localStorage.setItem(ae,I)}catch{}}f.current=!0}).catch(()=>{f.current=!0}),()=>{v=!0}},[o,r,ae]),a.useEffect(()=>{if(!f.current)return;u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{try{localStorage.setItem(ae,d)}catch{}},50),fe.current&&clearTimeout(fe.current);const v=Math.max(200,(Oe??30)*3);return fe.current=setTimeout(()=>{Re.current||(Re.current=!0,Vt(o,r,d).catch(()=>{}).finally(()=>{Re.current=!1}))},v),()=>{u.current&&clearTimeout(u.current),fe.current&&clearTimeout(fe.current)}},[d,o,r,Oe,ae]),a.useEffect(()=>{var v;(v=l.current)==null||v.focus()},[]),a.useEffect(()=>{if(!V)return;let v=!1;return Se(!0),(async()=>{try{if(H){if(!se.current){const b=await be(o,r);if(v)return;se.current=b.cwd}const I=`${se.current}/${H.replace(/\/$/,"")}`,m=await be(o,r,I);if(v)return;ye(m.files)}else{const I=await be(o,r);if(v)return;se.current=I.cwd,ye(I.files)}Se(!1)}catch{if(v)return;ye([]),Se(!1)}})(),()=>{v=!0}},[V,H,o,r]),a.useEffect(()=>{if(!V||!ve.current)return;const v=ve.current.querySelector(".file-item--active");v==null||v.scrollIntoView({block:"nearest"})},[Y,V]);const me=a.useCallback(()=>{const v=R.current.trim();if(v){vo(v),t(v),p("");try{localStorage.removeItem(ae)}catch{}Vt(o,r,"").catch(()=>{})}},[t,o,r,ae]),he=a.useCallback(v=>{C(),p(v),h.current=!0},[C]),Pe=a.useCallback(v=>{const I=l.current;C();const m=R.current;if(I){const b=I.selectionStart,N=I.selectionEnd,E=m.slice(0,b)+v+m.slice(N);p(E);const J=b+v.length;requestAnimationFrame(()=>{I.selectionStart=I.selectionEnd=J,I.focus()})}else p(m+v)},[C]);a.useImperativeHandle(c,()=>({send:me,fillContent:he,insertAtCursor:Pe}),[me,he,Pe]),a.useEffect(()=>{n==null||n(d.trim().length>0)},[d,n]);const ke=a.useCallback(()=>{const v=l.current;if(!v)return;const{selectionStart:I,selectionEnd:m}=v;if(I!==m){const b=v.value.substring(I,m);b&&navigator.clipboard.writeText(b).catch(()=>{})}},[]),Te=a.useCallback(()=>{const v=vn();S(!1),k("");const I=l.current;if(I){const m=I.selectionStart,b=d.slice(0,m),N=d.slice(m),E=b.match(/(?:^|\s)(\/history)\s*$/);if(E){const J=b.length-E[1].length;p(d.slice(0,J)+N)}}v.length!==0&&(O(v),T(0),G(""),$(!0))},[d]),de=a.useCallback(v=>{C(),p(v.text),$(!1),requestAnimationFrame(()=>{const I=l.current;I&&(I.selectionStart=I.selectionEnd=v.text.length,I.focus())})},[C]),Ne=a.useCallback(v=>{const I=U[v];if(!I)return;const m=F.filter(N=>N.ts!==I.ts||N.text!==I.text);O(m),localStorage.setItem(xt,JSON.stringify(m));const b=y?m.filter(N=>N.text.toLowerCase().includes(y.toLowerCase())):m;D>=b.length&&T(Math.max(0,b.length-1))},[U,F,D,y]);a.useEffect(()=>{if(!B||!W.current)return;const v=W.current.querySelector(".history-item--active");v==null||v.scrollIntoView({block:"nearest"})},[D,B]);const Le=a.useCallback(v=>{if(v==="/history"){Te();return}const I=l.current;if(!I)return;C();const m=I.selectionStart,b=d.slice(0,m),N=d.slice(m),J=b.lastIndexOf(`
|
|
31
31
|
`)+1,q=b.slice(J).match(/\/[a-zA-Z:-]*$/);if(q){const Q=J+(q.index??0),ge=v+" ",Me=d.slice(0,Q)+ge+N;p(Me);const Be=Q+ge.length;requestAnimationFrame(()=>{I.selectionStart=I.selectionEnd=Be,I.focus()})}else{const Q=b+v+N;p(Q);const ge=m+v.length;requestAnimationFrame(()=>{I.selectionStart=I.selectionEnd=ge,I.focus()})}S(!1),k(""),P(0)},[d,C,Te]),De=a.useCallback(v=>{const I=l.current;if(!I)return;C();const m=I.selectionStart,b=d.slice(0,m),N=d.slice(m),E=b.match(/@([a-zA-Z0-9_.\-/]*)$/);if(!E)return;const J=b.length-E[0].length;if(v.type==="directory"){const K="@"+H+v.name+"/",q=d.slice(0,J)+K+N;p(q);const Q=J+K.length;X(H+v.name+"/"),M(""),Z(0),requestAnimationFrame(()=>{I.selectionStart=I.selectionEnd=Q,I.focus()})}else{const K=v.name+" ",q=d.slice(0,J)+K+N;p(q);const Q=J+K.length;z(!1),M(""),X(""),Z(0),ye([]),se.current="",requestAnimationFrame(()=>{I.selectionStart=I.selectionEnd=Q,I.focus()})}},[d,H,C]),ot=a.useCallback(v=>{const I=v.target.value;if(p(I),B){const K=I.trim();K?(G(K),T(0)):G("");return}const m=v.target.selectionStart,b=I.slice(0,m),N=b.lastIndexOf(`
|
|
32
|
-
`),J=b.slice(N+1).match(/(?:^|\s)\/([a-zA-Z:-]*)$/);if(J)S(!0),k(J[1]),P(0),z(!1);else{S(!1);const K=b.match(/@([a-zA-Z0-9_.\-/]*)$/);if(K){const q=K[1],Q=q.lastIndexOf("/"),ge=Q>=0?q.slice(0,Q+1):"",Me=Q>=0?q.slice(Q+1):q;M(Me),Z(0),X(ge),z(!0)}else z(!1)}},[B]),Fe=a.useCallback(v=>{if(j&&le.length>0){if(v.key==="ArrowDown"){v.preventDefault(),P(I=>(I+1)%le.length);return}if(v.key==="ArrowUp"){v.preventDefault(),P(I=>(I-1+le.length)%le.length);return}if(v.key==="Enter"||v.key==="Tab"){v.preventDefault(),Le(le[A].cmd);return}if(v.key==="Escape"){v.preventDefault(),S(!1);return}}if(V&&re.length>0){if(v.key==="ArrowDown"){v.preventDefault(),Z(I=>(I+1)%re.length);return}if(v.key==="ArrowUp"){v.preventDefault(),Z(I=>(I-1+re.length)%re.length);return}if(v.key==="Tab"||v.key==="Enter"){v.preventDefault(),De(re[Y]);return}if(v.key==="Escape"){v.preventDefault(),z(!1);return}}if(B&&U.length>0){if(v.key==="ArrowDown"){v.preventDefault(),T(I=>(I+1)%U.length);return}if(v.key==="ArrowUp"){v.preventDefault(),T(I=>(I-1+U.length)%U.length);return}if(v.key==="Enter"){v.preventDefault(),de(U[D]);return}if(v.key==="Delete"||v.key==="Backspace"&&(v.ctrlKey||v.metaKey)){v.preventDefault(),Ne(D);return}if(v.key==="Escape"){v.preventDefault(),$(!1);return}}if(v.key==="Tab"){ht(v,p,g);return}v.key==="Enter"&&(v.ctrlKey||v.metaKey)&&(v.preventDefault(),me())},[me,j,le,A,Le,V,re,Y,De,g,x,B,U,D,de,Ne]);return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[j&&le.length>0&&s.jsx("div",{className:"slash-dropdown",children:le.map((v,I)=>s.jsxs("div",{className:`slash-item${I===A?" slash-item--active":""}`,onMouseDown:m=>{m.preventDefault(),Le(v.cmd)},onMouseEnter:()=>P(I),children:[s.jsx("span",{className:"slash-cmd",children:v.cmd}),s.jsx("span",{className:"slash-desc",children:v.desc})]},v.cmd))}),V&&($e||re.length>0)&&s.jsx("div",{className:"file-dropdown",ref:ve,children:$e?s.jsx("div",{className:"file-item file-loading",children:"Loading..."}):re.map((v,I)=>s.jsxs("div",{className:`file-item${I===Y?" file-item--active":""}`,onMouseDown:m=>{m.preventDefault(),De(v)},onMouseEnter:()=>Z(I),children:[s.jsx("span",{className:"file-icon",children:v.type==="directory"?"📁":"📄"}),s.jsx("span",{className:"file-name",children:v.name})]},v.name))}),B&&s.jsx("div",{className:"history-dropdown",ref:W,children:U.length===0?s.jsx("div",{className:"history-item history-empty",children:"No history yet"}):U.map((v,I)=>s.jsxs("div",{className:`history-item${I===D?" history-item--active":""}`,onMouseDown:m=>{m.preventDefault(),de(v)},onMouseEnter:()=>T(I),children:[s.jsx("span",{className:"history-text",children:v.text.length>120?v.text.slice(0,120)+"...":v.text}),s.jsx("span",{className:"history-time",children:new Date(v.ts).toLocaleString()}),s.jsx("button",{className:"history-delete",onMouseDown:m=>{m.preventDefault(),m.stopPropagation(),Ne(I)},title:"Delete (Del key)",children:"×"})]},`${v.ts}-${I}`))}),s.jsx("textarea",{ref:l,className:"md-editor-textarea",value:d,onChange:ot,onKeyDown:Fe,onMouseUp:ke,placeholder:"Type / for commands, @ for files, Ctrl+Enter to send",spellCheck:!1,style:{flex:1,fontSize:`${i}px`}})]})});function So({token:e,sessionId:t,onClose:n}){const[r,o]=a.useState([]),[c,i]=a.useState(""),[d,p]=a.useState([]),[l,u]=a.useState(!0),[f,h]=a.useState(!1),g=a.useRef(null);a.useEffect(()=>{let S=!1;return(async()=>{try{const w=await be(e,t);S||(i(w.cwd),o(w.files))}catch{S||n()}finally{S||u(!1)}})(),()=>{S=!0}},[e,t,n]),a.useEffect(()=>{const S=A=>{A.key==="Escape"&&n()},w=A=>{g.current&&!g.current.contains(A.target)&&n()};document.addEventListener("keydown",S);const k=setTimeout(()=>document.addEventListener("mousedown",w),50);return()=>{document.removeEventListener("keydown",S),document.removeEventListener("mousedown",w),clearTimeout(k)}},[n]);const x=a.useCallback(async S=>{u(!0);try{const w=await be(e,t,S);p(k=>[...k,c]),i(S),o(w.files)}catch{}finally{u(!1)}},[e,t,c]),R=a.useCallback(async()=>{if(d.length===0)return;const S=d[d.length-1];u(!0);try{const w=await be(e,t,S);p(k=>k.slice(0,-1)),i(S),o(w.files)}catch{}finally{u(!1)}},[e,t,d]),C=a.useCallback(async S=>{try{await po(e,t,S)}catch(w){alert(`Download failed: ${w instanceof Error?w.message:"Unknown error"}`)}},[e,t]),j=a.useCallback(async()=>{h(!0),n();try{await fo(e,t)}catch(S){alert(`Download failed: ${S instanceof Error?S.message:"Unknown error"}`)}finally{h(!1)}},[e,t,n]);return s.jsxs("div",{ref:g,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:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"6px 8px",borderBottom:"1px solid var(--border)",backgroundColor:"var(--bg-secondary)",flexShrink:0},children:[d.length>0&&s.jsx("button",{className:"pane-btn",onClick:R,disabled:l,style:{fontSize:11,flexShrink:0},title:"Go back",children:".."}),s.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",flex:1},children:c.split("/").slice(-2).join("/")||c}),s.jsx("button",{className:"pane-btn",onClick:n,style:{fontSize:11,flexShrink:0},title:"Close",children:"×"})]}),s.jsx("div",{style:{flex:1,overflowY:"auto",padding:"2px 0"},children:l?s.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12},children:"Loading..."}):r.length===0?s.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12,fontStyle:"italic"},children:"Empty directory"}):r.map(S=>s.jsxs("div",{onClick:()=>{const w=c+"/"+S.name;S.type==="directory"?x(w):C(w)},style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",cursor:"pointer",fontSize:12,color:"var(--text-primary)",transition:"background-color 0.1s"},onMouseEnter:w=>{w.currentTarget.style.backgroundColor="var(--bg-secondary)"},onMouseLeave:w=>{w.currentTarget.style.backgroundColor="transparent"},children:[s.jsx("span",{style:{flexShrink:0,fontSize:13},children:S.type==="directory"?"📁":mo(S.name,S.type)}),s.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:S.name}),S.type==="directory"?s.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:"›"}):S.size!=null?s.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:xn(S.size)}):null]},S.name))}),s.jsx("div",{style:{borderTop:"1px solid var(--border)",padding:"6px 8px",flexShrink:0,backgroundColor:"var(--bg-secondary)"},children:s.jsx("button",{className:"pane-btn",onClick:j,disabled:f,style:{fontSize:11,color:"var(--accent-blue)",width:"100%",textAlign:"center"},title:"Download entire CWD as tar.gz",children:f?"Downloading...":"Download All (tar.gz)"})})]})}function Xt(e,t,{containerRef:n,axis:r,offset:o=0,min:c,max:i,invert:d=!1,bodyClass:p}){const[l,u]=a.useState(()=>{const g=localStorage.getItem(e);if(g){const x=Number(g);if(Number.isFinite(x)&&x>=c&&x<=i)return x}return t}),f=a.useRef(l);if(l!==f.current){f.current=l;try{localStorage.setItem(e,String(Math.round(l)))}catch{}}const h=a.useCallback(g=>{g.preventDefault();const x=n.current;if(!x)return;const R=x.getBoundingClientRect(),C=r==="x"?R.width:R.height-o,j=r==="x"?R.left:R.top+o;document.body.classList.add(p);const S=k=>{let P=((r==="x"?k.clientX:k.clientY)-j)/C*100;d&&(P=100-P),u(Math.min(i,Math.max(c,P)))},w=()=>{document.body.classList.remove(p),document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",w)};document.addEventListener("mousemove",S),document.addEventListener("mouseup",w)},[n,r,o,c,i,d,p]);return[l,h]}const ko=600,Ie=typeof window<"u"?window.matchMedia(`(max-width: ${ko-1}px)`):null;function To(){const[e,t]=a.useState(()=>(Ie==null?void 0:Ie.matches)??!1);return a.useEffect(()=>{if(!Ie)return;const n=r=>t(r.matches);return Ie.addEventListener("change",n),()=>Ie.removeEventListener("change",n)},[]),e}const Co=a.memo(function({terminal:t}){const n=To(),r=_(z=>z.splitTerminal),o=_(z=>z.token),c=_(z=>z.toggleChat),i=_(z=>z.togglePlan),{chatOpen:d,planOpen:p}=t.panels,l=a.useRef(null),u=a.useRef(null),f=a.useRef(null),h=a.useRef(null),g=a.useRef(null),[x,R]=Xt(`plan-width-${t.id}`,50,{containerRef:u,axis:"x",min:20,max:80,bodyClass:"resizing-panes"}),[C,j]=Xt(`doc-height-${t.id}`,35,{containerRef:l,axis:"y",offset:24,min:15,max:60,invert:!0,bodyClass:"resizing-panes-v"}),[S,w]=a.useState("");a.useEffect(()=>{if(!o||!t.connected)return;let z=!1;const L=async()=>{try{const H=await Kt(o,t.id);z||w(H)}catch{}};L();const M=setInterval(L,5e3);return()=>{z=!0,clearInterval(M)}},[o,t.id,t.connected]);const k=a.useCallback(async z=>{let L;if(o)try{L=await Kt(o,t.id)}catch{}r(t.id,z,L)},[o,t.id,r]),[A,P]=a.useState(!1),[B,$]=a.useState(0),[F,O]=a.useState(!1),[D,T]=a.useState(!1),y=async z=>{const L=z.target.files;if(!(!L||L.length===0||!o)){P(!0),$(0);try{await co(o,t.id,L,M=>{$(M)})}catch(M){alert(`Upload failed: ${M instanceof Error?M.message:"Unknown error"}`)}finally{P(!1),$(0),f.current&&(f.current.value="")}}},G=a.useRef(void 0),W=a.useCallback(z=>{if(h.current){const L=z.replace(/\r?\n/g," ").trimEnd();h.current.sendInput(L),G.current=window.setTimeout(()=>{var M;return(M=h.current)==null?void 0:M.sendInput("\r")},50)}},[]);a.useEffect(()=>()=>{G.current&&clearTimeout(G.current)},[]);const U=a.useCallback(z=>{if(h.current){const L=z.replace(/\r?\n/g," ").trimEnd();h.current.sendInput(L),setTimeout(()=>{var M;return(M=h.current)==null?void 0:M.sendInput("\r")},50)}},[]),V=a.useCallback(()=>T(!1),[]);return s.jsxs("div",{ref:l,style:{display:"flex",flexDirection:"column",height:"100%",minWidth:0,minHeight:0},children:[s.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:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"5px",minWidth:0,flex:1,overflow:"hidden"},children:[s.jsx("span",{style:{display:"inline-block",width:"6px",height:"6px",borderRadius:"50%",backgroundColor:t.connected?"var(--accent-green)":"var(--accent-red)",flexShrink:0}}),s.jsxs("span",{style:{fontSize:"12px",color:"var(--text-secondary)",flexShrink:0},children:[t.id,t.connected?t.sessionResumed?" (resumed)":"":" (disconnected)"]}),S&&s.jsx("span",{style:{fontSize:"11px",color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",minWidth:0},title:S,children:S})]}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[s.jsx("input",{ref:f,type:"file",multiple:!0,style:{display:"none"},onChange:y}),s.jsx("button",{className:"pane-btn",onClick:()=>{var z;return(z=f.current)==null?void 0:z.click()},disabled:A,style:A?{color:"var(--accent-yellow)"}:void 0,title:A?`Uploading ${B}%`:"Upload files","aria-label":"Upload files",children:A?`${B}%`:"↑"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("button",{className:"pane-btn",onClick:()=>T(!0),title:"Download files","aria-label":"Download files",children:"↓"}),D&&o&&s.jsx(So,{token:o,sessionId:t.id,onClose:V})]}),s.jsx("button",{className:`pane-btn${d?" pane-btn--active":""}`,onClick:()=>c(t.id),title:"Toggle Chat panel","aria-label":"Toggle Chat panel",children:"Chat"}),s.jsx("button",{className:`pane-btn${p?" pane-btn--active":""}`,onClick:()=>i(t.id),title:"Toggle Task annotation panel","aria-label":"Toggle Task annotation panel",children:"Task"}),s.jsx("button",{className:"pane-btn",onClick:()=>k(n?"vertical":"horizontal"),title:n?"Split vertical (screen too narrow for horizontal)":"Split horizontal (left/right)","aria-label":"Split horizontal",children:"|"}),s.jsx("button",{className:"pane-btn",onClick:()=>k("vertical"),title:"Split vertical (top/bottom)","aria-label":"Split vertical",children:"─"})]})]}),s.jsxs("div",{ref:u,style:{flex:1,display:"flex",flexDirection:"row",overflow:"hidden",minHeight:0},children:[p&&s.jsxs(s.Fragment,{children:[s.jsx("div",{style:{width:`${x}%`,minWidth:200,flexShrink:0,overflow:"hidden"},children:s.jsx(xo,{sessionId:t.id,token:o||"",connected:t.connected,onRequestFileStream:z=>{var L;return(L=h.current)==null?void 0:L.requestFileStream(z)},onSendToTerminal:U})}),s.jsx("div",{className:"md-editor-divider-h",onMouseDown:R,style:{width:"2px",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)"}})]}),s.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[s.jsxs("div",{style:{flex:1,overflow:"hidden",position:"relative",minWidth:80},children:[s.jsx(Pr,{ref:h,sessionId:t.id}),!t.connected&&s.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"var(--bg-secondary)",opacity:.85,zIndex:2,pointerEvents:"none"},children:s.jsx("span",{style:{color:"var(--text-secondary)",fontSize:"13px",fontStyle:"italic"},children:"Connecting..."})})]}),d&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"md-editor-divider",onMouseDown:j}),s.jsxs("div",{style:{height:`${C}%`,minHeight:80,flexShrink:0,overflow:"hidden",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[s.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:s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[s.jsx("span",{style:{fontSize:"11px",color:"var(--accent-blue)",fontWeight:500},children:"Chat"}),s.jsx("button",{className:"pane-btn",onClick:()=>{var z;return(z=g.current)==null?void 0:z.send()},disabled:!F,title:"Send to terminal (Ctrl+Enter)",style:F?{color:"var(--accent-green)"}:{opacity:.4,cursor:"default"},children:"Send"}),s.jsx("span",{style:{fontSize:"9px",color:"var(--text-secondary)"},children:"Ctrl+Enter"})]})}),s.jsx("div",{style:{flex:1,overflow:"hidden"},children:s.jsx(wo,{ref:g,onSend:W,onContentChange:O,sessionId:t.id,token:o||""})})]})]})]})]}),t.error&&s.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:t.error})]})});class wn extends a.Component{constructor(){super(...arguments);wt(this,"state",{hasError:!1,error:null})}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,r){}render(){var n,r;return this.state.hasError?this.props.inline?s.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:[s.jsx("div",{style:{fontSize:"14px",color:"var(--accent-red)"},children:"Pane crashed"}),s.jsx("div",{style:{fontSize:"12px",color:"var(--text-secondary)",textAlign:"center"},children:((n=this.state.error)==null?void 0:n.message)||"An unexpected error occurred"}),s.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"})]}):s.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:[s.jsx("div",{style:{fontSize:"18px",color:"var(--accent-red)"},children:"Something went wrong"}),s.jsx("div",{style:{fontSize:"13px",color:"var(--text-secondary)",maxWidth:"500px",textAlign:"center"},children:((r=this.state.error)==null?void 0:r.message)||"An unexpected error occurred"}),s.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 Eo=4,Zt=10;function Io(){const e=_(o=>o.layout),t=_(o=>o.terminalIds.length),n=_(o=>o.addTerminal);if(!e)return s.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)"},children:s.jsx("button",{onClick:()=>n(),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 r=t>1;return s.jsx("div",{style:{height:"100%",width:"100%",overflow:"hidden"},children:s.jsx(Sn,{node:e,canClose:r})})}const Sn=a.memo(function({node:t,canClose:n}){return t.type==="leaf"?s.jsx(jo,{terminalId:t.terminalId,canClose:n}):s.jsx(Ro,{node:t,canClose:n})}),jo=a.memo(function({terminalId:t,canClose:n}){const r=_(c=>c.terminalsMap[t]),o=_(c=>c.reconnectTerminal);return r?s.jsx(wn,{inline:!0,children:s.jsx(Co,{terminal:r,canClose:n})}):s.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)",border:"1px dashed var(--border)"},children:s.jsxs("button",{onClick:()=>o(t),style:{background:"none",border:"1px solid var(--accent-blue)",color:"var(--accent-blue)",padding:"8px 16px",borderRadius:"6px",cursor:"pointer",fontSize:"13px"},children:["↻ Reconnect ",t]})})}),Ro=a.memo(function({node:t,canClose:n}){const r=_(l=>l.setSplitSizes),o=a.useRef(null),c=t.direction==="horizontal",i=a.useRef(t.sizes);i.current=t.sizes;const d=a.useCallback((l,u)=>{u.preventDefault();const f=c?"resizing-panes":"resizing-panes-v";document.body.classList.add(f);const h=c?u.clientX:u.clientY,g=[...i.current],x=o.current,R=c?(x==null?void 0:x.clientWidth)||1:(x==null?void 0:x.clientHeight)||1;let C=null;const j=w=>{C||(C=requestAnimationFrame(()=>{C=null;const P=((c?w.clientX:w.clientY)-h)/R*100,B=g[l]+P,$=g[l+1]-P;if(B>=Zt&&$>=Zt){const F=[...g];F[l]=B,F[l+1]=$,r(t.id,F)}}))},S=()=>{C&&cancelAnimationFrame(C),document.body.classList.remove(f),document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",S)};document.addEventListener("mousemove",j),document.addEventListener("mouseup",S)},[c,t.id,r]),p=[];return t.children.forEach((l,u)=>{const f=l.type==="leaf"?l.terminalId:l.id;p.push(s.jsx("div",{style:{flex:`${t.sizes[u]} 0 0`,minWidth:0,minHeight:0,overflow:"hidden"},children:s.jsx(Sn,{node:l,canClose:n})},f)),u<t.children.length-1&&p.push(s.jsx("div",{onMouseDown:h=>d(u,h),style:{flex:`0 0 ${Eo}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-${t.id}-${u}`))}),s.jsx("div",{ref:o,style:{display:"flex",flexDirection:c?"row":"column",height:"100%",width:"100%",overflow:"hidden"},children:p})});function No({tabId:e}){const t=_(T=>T.tabs.find(y=>y.id===e)),n=_(T=>T.activeTabId),r=_(T=>T.switchTab),o=_(T=>T.closeTab),c=_(T=>T.reopenTab),i=_(T=>T.deleteTab),d=_(T=>T.renameTab),p=_(T=>t?t.terminalIds.map(y=>{const G=T.terminalsMap[y];return G?{id:y,connected:G.connected,active:!0}:{id:y,connected:!1,active:!1}}):[]),l=_(T=>T.disconnectTerminal),u=_(T=>T.reconnectTerminal),f=_(T=>T.killServerSession),[h,g]=a.useState(!1),[x,R]=a.useState(""),[C,j]=a.useState(!1),S=a.useRef(null);if(!t)return null;const w=n===e,k=t.status==="open",A=()=>{k&&r(e)},P=T=>{k&&(T.stopPropagation(),R(t.name),g(!0),setTimeout(()=>{var y;return(y=S.current)==null?void 0:y.focus()},0))},B=()=>{const T=x.trim();T&&d(e,T),g(!1)},$=T=>{T.stopPropagation(),c(e)},F=T=>{T.stopPropagation(),o(e)},O=async T=>{T.stopPropagation(),window.confirm(`Delete tab "${t.name}"? This will kill all tmux sessions in this tab.`)&&await i(e)},D=T=>{T.stopPropagation(),j(!C)};return s.jsxs("div",{children:[s.jsxs("div",{onClick:A,style:{padding:"8px 12px",cursor:k?"pointer":"default",borderLeft:w?"3px solid var(--accent-blue)":"3px solid transparent",backgroundColor:w?"rgba(122, 162, 247, 0.08)":"transparent",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s",opacity:k?1:.5},onMouseEnter:T=>{k&&!w&&(T.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)")},onMouseLeave:T=>{w||(T.currentTarget.style.backgroundColor="transparent")},children:[k&&t.terminalIds.length>0&&s.jsx("button",{onClick:D,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?"▼":"▶"}),s.jsxs("div",{style:{flex:1,minWidth:0},children:[h?s.jsx("input",{ref:S,value:x,onChange:T=>R(T.target.value),onBlur:B,onKeyDown:T=>{T.key==="Enter"&&B(),T.key==="Escape"&&g(!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"}}):s.jsx("div",{onDoubleClick:P,style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:k?"Double-click to rename":t.name,children:t.name}),s.jsxs("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:[t.terminalIds.length," terminal",t.terminalIds.length!==1?"s":""," · ",yn(Math.floor(t.createdAt/1e3))]})]}),k?s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:F,style:{flexShrink:0},title:"Close tab",children:"×"}):s.jsxs("div",{style:{display:"flex",gap:"4px",flexShrink:0},children:[s.jsx("button",{className:"pane-btn",onClick:$,title:"Reopen tab",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:O,title:"Delete tab",children:"×"})]})]}),k&&C&&p.length>0&&s.jsx("div",{style:{paddingLeft:"28px",backgroundColor:"rgba(0, 0, 0, 0.2)"},children:p.map(T=>s.jsxs("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--text-secondary)",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center"},title:`Connected: ${T.connected}`,children:[s.jsx("span",{style:{fontFamily:"monospace"},children:T.id}),s.jsx("span",{style:{marginLeft:"8px",color:T.active?T.connected?"var(--accent-green)":"var(--accent-yellow)":"var(--text-secondary)"},children:T.active?T.connected?"●":"◐":"○"}),T.active?s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:y=>{y.stopPropagation(),l(T.id)},style:{marginLeft:"auto",flexShrink:0},title:"Disconnect terminal (keeps session alive)",children:"×"}):s.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:"4px",flexShrink:0},children:[s.jsx("button",{className:"pane-btn",onClick:y=>{y.stopPropagation(),u(T.id)},title:"Reconnect terminal",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:y=>{y.stopPropagation(),window.confirm(`Kill terminal "${T.id}"? This will destroy the tmux session.`)&&f(T.id)},title:"Kill session",children:"×"})]})]},T.id))})]})}function Lo({sessionId:e,active:t,createdAt:n}){const r=_(d=>d.addTerminal),o=_(d=>d.killServerSession),c=()=>{r("horizontal",e)},i=d=>{d.stopPropagation(),window.confirm(`Delete orphaned session "${e}"? This will kill the tmux session.`)&&o(e)};return s.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:[s.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:t?"var(--accent-green)":"var(--text-secondary)",flexShrink:0}}),s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsx("div",{style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e}),s.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:yn(n)})]}),s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:i,style:{flexShrink:0},title:"Delete session",children:"×"})]})}function Do(){const e=_(l=>l.sidebarOpen),t=_(l=>l.toggleSidebar),n=_(l=>l.fetchSessions),r=_(l=>e?l.serverSessions:[]),o=_(l=>e?l.tabs:[]),c=_(l=>l.terminalIds.length),i=_(l=>l.tabsLoading),d=new Set(o.flatMap(l=>l.terminalIds)),p=r.filter(l=>!d.has(l.sessionId));return a.useEffect(()=>{if(!e)return;n();let l=setInterval(n,5e3);const u=()=>{document.hidden?l&&(clearInterval(l),l=null):(n(),l||(l=setInterval(n,5e3)))};return document.addEventListener("visibilitychange",u),()=>{l&&clearInterval(l),document.removeEventListener("visibilitychange",u)}},[e,n]),a.useEffect(()=>{if(!e)return;const l=setTimeout(n,800);return()=>clearTimeout(l)},[c,e,n]),s.jsxs("div",{className:"session-sidebar",style:{width:e?280:0,height:"100%",backgroundColor:"var(--bg-secondary)",borderLeft:e?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,overflow:"hidden",transition:"width 0.2s ease"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[s.jsx("span",{style:{color:"var(--accent-blue)",fontSize:"14px",fontWeight:"bold"},children:"Tabs & Terminals"}),s.jsx("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"16px",padding:"0 4px",lineHeight:1},title:"Close sidebar",children:"×"})]}),s.jsxs("div",{style:{flex:1,overflowY:"auto"},children:[s.jsxs("div",{children:[s.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"}),o.length===0?s.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"14px",textAlign:"center",padding:"12px"},children:"No tabs"}):o.map(l=>s.jsx(No,{tabId:l.id},l.id))]}),!i&&p.length>0&&s.jsxs("div",{style:{marginTop:"16px"},children:[s.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"}),p.map(l=>s.jsx(Lo,{sessionId:l.sessionId,active:l.active,createdAt:l.createdAt},l.sessionId))]})]})]})}const kn=bt.memo(()=>{const e=_(k=>k.tabs),t=_(k=>k.activeTabId),n=_(k=>k.addTab),r=_(k=>k.switchTab),o=_(k=>k.closeTab),c=_(k=>k.renameTab),[i,d]=a.useState(null),[p,l]=a.useState(""),u=a.useRef(null),f=e.filter(k=>k.status==="open");a.useEffect(()=>{i&&u.current&&(u.current.focus(),u.current.select())},[i]);const h=k=>{d(k.id),l(k.name)},g=()=>{i&&p.trim()&&c(i,p.trim()),d(null),l("")},x=()=>{d(null),l("")},R=k=>{k.key==="Enter"?g():k.key==="Escape"&&x()},C=k=>{i||r(k)},j=(k,A)=>{k.stopPropagation(),o(A)},S=(k,A)=>{k.button===1&&(k.preventDefault(),o(A))},w=f.length>1;return s.jsxs("div",{className:"tab-bar",children:[f.map(k=>{const A=k.id===t,P=i===k.id,B=k.terminalIds.length;return s.jsx("div",{className:`tab-item ${A?"tab-item--active":""}`,onClick:()=>C(k.id),onDoubleClick:()=>h(k),onMouseDown:$=>S($,k.id),children:P?s.jsx("input",{ref:u,type:"text",value:p,onChange:$=>l($.target.value),onBlur:g,onKeyDown:R,className:"tab-item__rename-input"}):s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"tab-item__name",children:[k.name," ",B>0&&`(${B})`]}),w&&s.jsx("button",{className:"tab-item__close",onClick:$=>j($,k.id),title:"Close tab","aria-label":"Close tab",children:"×"})]})},k.id)}),s.jsx("button",{className:"tab-bar-add",onClick:()=>n(),title:"New tab","aria-label":"Add new tab",children:"+"})]})});kn.displayName="TabBar";function Mo(){return localStorage.getItem("ai-cli-online-token")}function Ao(){const e=_(u=>u.token),t=_(u=>u.setToken),n=_(u=>u.tabs),r=_(u=>u.addTab),o=_(u=>u.toggleSidebar),c=_(u=>u.fontSize),i=_(u=>u.setFontSize),d=_(u=>u.tabsLoading),p=_(u=>u.theme),l=_(u=>u.toggleTheme);return a.useEffect(()=>{const u=Mo();u&&!e&&t(u)},[]),a.useEffect(()=>{e&&!d&&n.filter(u=>u.status==="open").length===0&&r("Default")},[e,d]),e?s.jsxs("div",{style:{height:"100vh",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[s.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:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[s.jsx("span",{style:{fontSize:"15px",fontWeight:"bold",color:"var(--accent-blue)",letterSpacing:"0.5px"},children:"AI-Cli Online"}),s.jsxs("span",{style:{fontSize:"11px",color:"var(--text-secondary)",fontWeight:400},children:["v","3.0.1"]})]}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[s.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"1px 4px",borderRadius:"6px",backgroundColor:"rgba(0,0,0,0.2)"},children:[s.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−"}),s.jsx("span",{style:{fontSize:"11px",color:"var(--text-primary)",minWidth:"20px",textAlign:"center"},children:c}),s.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+"})]}),s.jsx(_o,{}),s.jsx("button",{className:"header-btn",onClick:l,title:`Switch to ${p==="dark"?"light":"dark"} mode`,"aria-label":"Toggle theme",children:p==="dark"?"☀":"🌙"}),s.jsx("button",{className:"header-btn",onClick:o,title:"Toggle Tabs & Terminals Sidebar","aria-label":"Toggle sidebar",children:"☰"}),s.jsx("button",{className:"header-btn header-btn--muted",onClick:()=>{window.confirm("Logout will close all terminals. Continue?")&&t(null)},children:"Logout"})]})]}),s.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[s.jsx("main",{style:{flex:1,overflow:"hidden"},children:s.jsx(Io,{})}),s.jsx(Do,{})]}),s.jsx(kn,{})]}):s.jsx(vr,{})}const zo=[1,2,3,4];function _o(){const e=_(r=>r.latency);if(e===null)return s.jsx("span",{style:{fontSize:"10px",color:"var(--scrollbar-thumb-hover)"},title:"Measuring latency...",children:"--ms"});let t,n;return e<50?(t="var(--accent-green)",n=4):e<150?(t="var(--accent-yellow)",n=3):e<300?(t="var(--accent-orange)",n=2):(t="var(--accent-red)",n=1),s.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: ${e}ms`,children:[zo.map(r=>s.jsx("span",{style:{display:"inline-block",width:"2.5px",height:`${3+r*2}px`,backgroundColor:r<=n?t:"var(--border)",borderRadius:"1px",transition:"background-color 0.3s ease"}},r)),s.jsxs("span",{style:{fontSize:"10px",color:t,marginLeft:"4px",fontWeight:500},children:[e,"ms"]})]})}ft.createRoot(document.getElementById("root")).render(s.jsx(bt.StrictMode,{children:s.jsx(wn,{children:s.jsx(Ao,{})})}));
|
|
32
|
+
`),J=b.slice(N+1).match(/(?:^|\s)\/([a-zA-Z:-]*)$/);if(J)S(!0),k(J[1]),P(0),z(!1);else{S(!1);const K=b.match(/@([a-zA-Z0-9_.\-/]*)$/);if(K){const q=K[1],Q=q.lastIndexOf("/"),ge=Q>=0?q.slice(0,Q+1):"",Me=Q>=0?q.slice(Q+1):q;M(Me),Z(0),X(ge),z(!0)}else z(!1)}},[B]),Fe=a.useCallback(v=>{if(j&&le.length>0){if(v.key==="ArrowDown"){v.preventDefault(),P(I=>(I+1)%le.length);return}if(v.key==="ArrowUp"){v.preventDefault(),P(I=>(I-1+le.length)%le.length);return}if(v.key==="Enter"||v.key==="Tab"){v.preventDefault(),Le(le[A].cmd);return}if(v.key==="Escape"){v.preventDefault(),S(!1);return}}if(V&&re.length>0){if(v.key==="ArrowDown"){v.preventDefault(),Z(I=>(I+1)%re.length);return}if(v.key==="ArrowUp"){v.preventDefault(),Z(I=>(I-1+re.length)%re.length);return}if(v.key==="Tab"||v.key==="Enter"){v.preventDefault(),De(re[Y]);return}if(v.key==="Escape"){v.preventDefault(),z(!1);return}}if(B&&U.length>0){if(v.key==="ArrowDown"){v.preventDefault(),T(I=>(I+1)%U.length);return}if(v.key==="ArrowUp"){v.preventDefault(),T(I=>(I-1+U.length)%U.length);return}if(v.key==="Enter"){v.preventDefault(),de(U[D]);return}if(v.key==="Delete"||v.key==="Backspace"&&(v.ctrlKey||v.metaKey)){v.preventDefault(),Ne(D);return}if(v.key==="Escape"){v.preventDefault(),$(!1);return}}if(v.key==="Tab"){ht(v,p,g);return}v.key==="Enter"&&(v.ctrlKey||v.metaKey)&&(v.preventDefault(),me())},[me,j,le,A,Le,V,re,Y,De,g,x,B,U,D,de,Ne]);return s.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[j&&le.length>0&&s.jsx("div",{className:"slash-dropdown",children:le.map((v,I)=>s.jsxs("div",{className:`slash-item${I===A?" slash-item--active":""}`,onMouseDown:m=>{m.preventDefault(),Le(v.cmd)},onMouseEnter:()=>P(I),children:[s.jsx("span",{className:"slash-cmd",children:v.cmd}),s.jsx("span",{className:"slash-desc",children:v.desc})]},v.cmd))}),V&&($e||re.length>0)&&s.jsx("div",{className:"file-dropdown",ref:ve,children:$e?s.jsx("div",{className:"file-item file-loading",children:"Loading..."}):re.map((v,I)=>s.jsxs("div",{className:`file-item${I===Y?" file-item--active":""}`,onMouseDown:m=>{m.preventDefault(),De(v)},onMouseEnter:()=>Z(I),children:[s.jsx("span",{className:"file-icon",children:v.type==="directory"?"📁":"📄"}),s.jsx("span",{className:"file-name",children:v.name})]},v.name))}),B&&s.jsx("div",{className:"history-dropdown",ref:W,children:U.length===0?s.jsx("div",{className:"history-item history-empty",children:"No history yet"}):U.map((v,I)=>s.jsxs("div",{className:`history-item${I===D?" history-item--active":""}`,onMouseDown:m=>{m.preventDefault(),de(v)},onMouseEnter:()=>T(I),children:[s.jsx("span",{className:"history-text",children:v.text.length>120?v.text.slice(0,120)+"...":v.text}),s.jsx("span",{className:"history-time",children:new Date(v.ts).toLocaleString()}),s.jsx("button",{className:"history-delete",onMouseDown:m=>{m.preventDefault(),m.stopPropagation(),Ne(I)},title:"Delete (Del key)",children:"×"})]},`${v.ts}-${I}`))}),s.jsx("textarea",{ref:l,className:"md-editor-textarea",value:d,onChange:ot,onKeyDown:Fe,onMouseUp:ke,placeholder:"Type / for commands, @ for files, Ctrl+Enter to send",spellCheck:!1,style:{flex:1,fontSize:`${i}px`}})]})});function So({token:e,sessionId:t,onClose:n}){const[r,o]=a.useState([]),[c,i]=a.useState(""),[d,p]=a.useState([]),[l,u]=a.useState(!0),[f,h]=a.useState(!1),g=a.useRef(null);a.useEffect(()=>{let S=!1;return(async()=>{try{const w=await be(e,t);S||(i(w.cwd),o(w.files))}catch{S||n()}finally{S||u(!1)}})(),()=>{S=!0}},[e,t,n]),a.useEffect(()=>{const S=A=>{A.key==="Escape"&&n()},w=A=>{g.current&&!g.current.contains(A.target)&&n()};document.addEventListener("keydown",S);const k=setTimeout(()=>document.addEventListener("mousedown",w),50);return()=>{document.removeEventListener("keydown",S),document.removeEventListener("mousedown",w),clearTimeout(k)}},[n]);const x=a.useCallback(async S=>{u(!0);try{const w=await be(e,t,S);p(k=>[...k,c]),i(S),o(w.files)}catch{}finally{u(!1)}},[e,t,c]),R=a.useCallback(async()=>{if(d.length===0)return;const S=d[d.length-1];u(!0);try{const w=await be(e,t,S);p(k=>k.slice(0,-1)),i(S),o(w.files)}catch{}finally{u(!1)}},[e,t,d]),C=a.useCallback(async S=>{try{await po(e,t,S)}catch(w){alert(`Download failed: ${w instanceof Error?w.message:"Unknown error"}`)}},[e,t]),j=a.useCallback(async()=>{h(!0),n();try{await fo(e,t)}catch(S){alert(`Download failed: ${S instanceof Error?S.message:"Unknown error"}`)}finally{h(!1)}},[e,t,n]);return s.jsxs("div",{ref:g,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:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"6px 8px",borderBottom:"1px solid var(--border)",backgroundColor:"var(--bg-secondary)",flexShrink:0},children:[d.length>0&&s.jsx("button",{className:"pane-btn",onClick:R,disabled:l,style:{fontSize:11,flexShrink:0},title:"Go back",children:".."}),s.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",flex:1},children:c.split("/").slice(-2).join("/")||c}),s.jsx("button",{className:"pane-btn",onClick:n,style:{fontSize:11,flexShrink:0},title:"Close",children:"×"})]}),s.jsx("div",{style:{flex:1,overflowY:"auto",padding:"2px 0"},children:l?s.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12},children:"Loading..."}):r.length===0?s.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12,fontStyle:"italic"},children:"Empty directory"}):r.map(S=>s.jsxs("div",{onClick:()=>{const w=c+"/"+S.name;S.type==="directory"?x(w):C(w)},style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",cursor:"pointer",fontSize:12,color:"var(--text-primary)",transition:"background-color 0.1s"},onMouseEnter:w=>{w.currentTarget.style.backgroundColor="var(--bg-secondary)"},onMouseLeave:w=>{w.currentTarget.style.backgroundColor="transparent"},children:[s.jsx("span",{style:{flexShrink:0,fontSize:13},children:S.type==="directory"?"📁":mo(S.name,S.type)}),s.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:S.name}),S.type==="directory"?s.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:"›"}):S.size!=null?s.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:xn(S.size)}):null]},S.name))}),s.jsx("div",{style:{borderTop:"1px solid var(--border)",padding:"6px 8px",flexShrink:0,backgroundColor:"var(--bg-secondary)"},children:s.jsx("button",{className:"pane-btn",onClick:j,disabled:f,style:{fontSize:11,color:"var(--accent-blue)",width:"100%",textAlign:"center"},title:"Download entire CWD as tar.gz",children:f?"Downloading...":"Download All (tar.gz)"})})]})}function Xt(e,t,{containerRef:n,axis:r,offset:o=0,min:c,max:i,invert:d=!1,bodyClass:p}){const[l,u]=a.useState(()=>{const g=localStorage.getItem(e);if(g){const x=Number(g);if(Number.isFinite(x)&&x>=c&&x<=i)return x}return t}),f=a.useRef(l);if(l!==f.current){f.current=l;try{localStorage.setItem(e,String(Math.round(l)))}catch{}}const h=a.useCallback(g=>{g.preventDefault();const x=n.current;if(!x)return;const R=x.getBoundingClientRect(),C=r==="x"?R.width:R.height-o,j=r==="x"?R.left:R.top+o;document.body.classList.add(p);const S=k=>{let P=((r==="x"?k.clientX:k.clientY)-j)/C*100;d&&(P=100-P),u(Math.min(i,Math.max(c,P)))},w=()=>{document.body.classList.remove(p),document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",w)};document.addEventListener("mousemove",S),document.addEventListener("mouseup",w)},[n,r,o,c,i,d,p]);return[l,h]}const ko=600,Ie=typeof window<"u"?window.matchMedia(`(max-width: ${ko-1}px)`):null;function To(){const[e,t]=a.useState(()=>(Ie==null?void 0:Ie.matches)??!1);return a.useEffect(()=>{if(!Ie)return;const n=r=>t(r.matches);return Ie.addEventListener("change",n),()=>Ie.removeEventListener("change",n)},[]),e}const Co=a.memo(function({terminal:t}){const n=To(),r=_(z=>z.splitTerminal),o=_(z=>z.token),c=_(z=>z.toggleChat),i=_(z=>z.togglePlan),{chatOpen:d,planOpen:p}=t.panels,l=a.useRef(null),u=a.useRef(null),f=a.useRef(null),h=a.useRef(null),g=a.useRef(null),[x,R]=Xt(`plan-width-${t.id}`,50,{containerRef:u,axis:"x",min:20,max:80,bodyClass:"resizing-panes"}),[C,j]=Xt(`doc-height-${t.id}`,35,{containerRef:l,axis:"y",offset:24,min:15,max:60,invert:!0,bodyClass:"resizing-panes-v"}),[S,w]=a.useState("");a.useEffect(()=>{if(!o||!t.connected)return;let z=!1;const L=async()=>{try{const H=await Kt(o,t.id);z||w(H)}catch{}};L();const M=setInterval(L,5e3);return()=>{z=!0,clearInterval(M)}},[o,t.id,t.connected]);const k=a.useCallback(async z=>{let L;if(o)try{L=await Kt(o,t.id)}catch{}r(t.id,z,L)},[o,t.id,r]),[A,P]=a.useState(!1),[B,$]=a.useState(0),[F,O]=a.useState(!1),[D,T]=a.useState(!1),y=async z=>{const L=z.target.files;if(!(!L||L.length===0||!o)){P(!0),$(0);try{await co(o,t.id,L,M=>{$(M)})}catch(M){alert(`Upload failed: ${M instanceof Error?M.message:"Unknown error"}`)}finally{P(!1),$(0),f.current&&(f.current.value="")}}},G=a.useRef(void 0),W=a.useCallback(z=>{if(h.current){const L=z.replace(/\r?\n/g," ").trimEnd();h.current.sendInput(L),G.current=window.setTimeout(()=>{var M;return(M=h.current)==null?void 0:M.sendInput("\r")},50)}},[]);a.useEffect(()=>()=>{G.current&&clearTimeout(G.current)},[]);const U=a.useCallback(z=>{if(h.current){const L=z.replace(/\r?\n/g," ").trimEnd();h.current.sendInput(L),setTimeout(()=>{var M;return(M=h.current)==null?void 0:M.sendInput("\r")},50)}},[]),V=a.useCallback(()=>T(!1),[]);return s.jsxs("div",{ref:l,style:{display:"flex",flexDirection:"column",height:"100%",minWidth:0,minHeight:0},children:[s.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:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"5px",minWidth:0,flex:1,overflow:"hidden"},children:[s.jsx("span",{style:{display:"inline-block",width:"6px",height:"6px",borderRadius:"50%",backgroundColor:t.connected?"var(--accent-green)":"var(--accent-red)",flexShrink:0}}),s.jsxs("span",{style:{fontSize:"12px",color:"var(--text-secondary)",flexShrink:0},children:[t.id,t.connected?t.sessionResumed?" (resumed)":"":" (disconnected)"]}),S&&s.jsx("span",{style:{fontSize:"11px",color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",minWidth:0},title:S,children:S})]}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[s.jsx("input",{ref:f,type:"file",multiple:!0,style:{display:"none"},onChange:y}),s.jsx("button",{className:"pane-btn",onClick:()=>{var z;return(z=f.current)==null?void 0:z.click()},disabled:A,style:A?{color:"var(--accent-yellow)"}:void 0,title:A?`Uploading ${B}%`:"Upload files","aria-label":"Upload files",children:A?`${B}%`:"↑"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("button",{className:"pane-btn",onClick:()=>T(!0),title:"Download files","aria-label":"Download files",children:"↓"}),D&&o&&s.jsx(So,{token:o,sessionId:t.id,onClose:V})]}),s.jsx("button",{className:`pane-btn${d?" pane-btn--active":""}`,onClick:()=>c(t.id),title:"Toggle Chat panel","aria-label":"Toggle Chat panel",children:"Chat"}),s.jsx("button",{className:`pane-btn${p?" pane-btn--active":""}`,onClick:()=>i(t.id),title:"Toggle Task annotation panel","aria-label":"Toggle Task annotation panel",children:"Task"}),s.jsx("button",{className:"pane-btn",onClick:()=>k(n?"vertical":"horizontal"),title:n?"Split vertical (screen too narrow for horizontal)":"Split horizontal (left/right)","aria-label":"Split horizontal",children:"|"}),s.jsx("button",{className:"pane-btn",onClick:()=>k("vertical"),title:"Split vertical (top/bottom)","aria-label":"Split vertical",children:"─"})]})]}),s.jsxs("div",{ref:u,style:{flex:1,display:"flex",flexDirection:"row",overflow:"hidden",minHeight:0},children:[p&&s.jsxs(s.Fragment,{children:[s.jsx("div",{style:{width:`${x}%`,minWidth:200,flexShrink:0,overflow:"hidden"},children:s.jsx(xo,{sessionId:t.id,token:o||"",connected:t.connected,onRequestFileStream:z=>{var L;return(L=h.current)==null?void 0:L.requestFileStream(z)},onSendToTerminal:U})}),s.jsx("div",{className:"md-editor-divider-h",onMouseDown:R,style:{width:"2px",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)"}})]}),s.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[s.jsxs("div",{style:{flex:1,overflow:"hidden",position:"relative",minWidth:80},children:[s.jsx(Pr,{ref:h,sessionId:t.id}),!t.connected&&s.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"var(--bg-secondary)",opacity:.85,zIndex:2,pointerEvents:"none"},children:s.jsx("span",{style:{color:"var(--text-secondary)",fontSize:"13px",fontStyle:"italic"},children:"Connecting..."})})]}),d&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"md-editor-divider",onMouseDown:j}),s.jsxs("div",{style:{height:`${C}%`,minHeight:80,flexShrink:0,overflow:"hidden",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[s.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:s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[s.jsx("span",{style:{fontSize:"11px",color:"var(--accent-blue)",fontWeight:500},children:"Chat"}),s.jsx("button",{className:"pane-btn",onClick:()=>{var z;return(z=g.current)==null?void 0:z.send()},disabled:!F,title:"Send to terminal (Ctrl+Enter)",style:F?{color:"var(--accent-green)"}:{opacity:.4,cursor:"default"},children:"Send"}),s.jsx("span",{style:{fontSize:"9px",color:"var(--text-secondary)"},children:"Ctrl+Enter"})]})}),s.jsx("div",{style:{flex:1,overflow:"hidden"},children:s.jsx(wo,{ref:g,onSend:W,onContentChange:O,sessionId:t.id,token:o||""})})]})]})]})]}),t.error&&s.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:t.error})]})});class wn extends a.Component{constructor(){super(...arguments);wt(this,"state",{hasError:!1,error:null})}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,r){}render(){var n,r;return this.state.hasError?this.props.inline?s.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:[s.jsx("div",{style:{fontSize:"14px",color:"var(--accent-red)"},children:"Pane crashed"}),s.jsx("div",{style:{fontSize:"12px",color:"var(--text-secondary)",textAlign:"center"},children:((n=this.state.error)==null?void 0:n.message)||"An unexpected error occurred"}),s.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"})]}):s.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:[s.jsx("div",{style:{fontSize:"18px",color:"var(--accent-red)"},children:"Something went wrong"}),s.jsx("div",{style:{fontSize:"13px",color:"var(--text-secondary)",maxWidth:"500px",textAlign:"center"},children:((r=this.state.error)==null?void 0:r.message)||"An unexpected error occurred"}),s.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 Eo=4,Zt=10;function Io(){const e=_(o=>o.layout),t=_(o=>o.terminalIds.length),n=_(o=>o.addTerminal);if(!e)return s.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)"},children:s.jsx("button",{onClick:()=>n(),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 r=t>1;return s.jsx("div",{style:{height:"100%",width:"100%",overflow:"hidden"},children:s.jsx(Sn,{node:e,canClose:r})})}const Sn=a.memo(function({node:t,canClose:n}){return t.type==="leaf"?s.jsx(jo,{terminalId:t.terminalId,canClose:n}):s.jsx(Ro,{node:t,canClose:n})}),jo=a.memo(function({terminalId:t,canClose:n}){const r=_(c=>c.terminalsMap[t]),o=_(c=>c.reconnectTerminal);return r?s.jsx(wn,{inline:!0,children:s.jsx(Co,{terminal:r,canClose:n})}):s.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)",border:"1px dashed var(--border)"},children:s.jsxs("button",{onClick:()=>o(t),style:{background:"none",border:"1px solid var(--accent-blue)",color:"var(--accent-blue)",padding:"8px 16px",borderRadius:"6px",cursor:"pointer",fontSize:"13px"},children:["↻ Reconnect ",t]})})}),Ro=a.memo(function({node:t,canClose:n}){const r=_(l=>l.setSplitSizes),o=a.useRef(null),c=t.direction==="horizontal",i=a.useRef(t.sizes);i.current=t.sizes;const d=a.useCallback((l,u)=>{u.preventDefault();const f=c?"resizing-panes":"resizing-panes-v";document.body.classList.add(f);const h=c?u.clientX:u.clientY,g=[...i.current],x=o.current,R=c?(x==null?void 0:x.clientWidth)||1:(x==null?void 0:x.clientHeight)||1;let C=null;const j=w=>{C||(C=requestAnimationFrame(()=>{C=null;const P=((c?w.clientX:w.clientY)-h)/R*100,B=g[l]+P,$=g[l+1]-P;if(B>=Zt&&$>=Zt){const F=[...g];F[l]=B,F[l+1]=$,r(t.id,F)}}))},S=()=>{C&&cancelAnimationFrame(C),document.body.classList.remove(f),document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",S)};document.addEventListener("mousemove",j),document.addEventListener("mouseup",S)},[c,t.id,r]),p=[];return t.children.forEach((l,u)=>{const f=l.type==="leaf"?l.terminalId:l.id;p.push(s.jsx("div",{style:{flex:`${t.sizes[u]} 0 0`,minWidth:0,minHeight:0,overflow:"hidden"},children:s.jsx(Sn,{node:l,canClose:n})},f)),u<t.children.length-1&&p.push(s.jsx("div",{onMouseDown:h=>d(u,h),style:{flex:`0 0 ${Eo}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-${t.id}-${u}`))}),s.jsx("div",{ref:o,style:{display:"flex",flexDirection:c?"row":"column",height:"100%",width:"100%",overflow:"hidden"},children:p})});function No({tabId:e}){const t=_(T=>T.tabs.find(y=>y.id===e)),n=_(T=>T.activeTabId),r=_(T=>T.switchTab),o=_(T=>T.closeTab),c=_(T=>T.reopenTab),i=_(T=>T.deleteTab),d=_(T=>T.renameTab),p=_(T=>t?t.terminalIds.map(y=>{const G=T.terminalsMap[y];return G?{id:y,connected:G.connected,active:!0}:{id:y,connected:!1,active:!1}}):[]),l=_(T=>T.disconnectTerminal),u=_(T=>T.reconnectTerminal),f=_(T=>T.killServerSession),[h,g]=a.useState(!1),[x,R]=a.useState(""),[C,j]=a.useState(!1),S=a.useRef(null);if(!t)return null;const w=n===e,k=t.status==="open",A=()=>{k&&r(e)},P=T=>{k&&(T.stopPropagation(),R(t.name),g(!0),setTimeout(()=>{var y;return(y=S.current)==null?void 0:y.focus()},0))},B=()=>{const T=x.trim();T&&d(e,T),g(!1)},$=T=>{T.stopPropagation(),c(e)},F=T=>{T.stopPropagation(),o(e)},O=async T=>{T.stopPropagation(),window.confirm(`Delete tab "${t.name}"? This will kill all tmux sessions in this tab.`)&&await i(e)},D=T=>{T.stopPropagation(),j(!C)};return s.jsxs("div",{children:[s.jsxs("div",{onClick:A,style:{padding:"8px 12px",cursor:k?"pointer":"default",borderLeft:w?"3px solid var(--accent-blue)":"3px solid transparent",backgroundColor:w?"rgba(122, 162, 247, 0.08)":"transparent",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s",opacity:k?1:.5},onMouseEnter:T=>{k&&!w&&(T.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)")},onMouseLeave:T=>{w||(T.currentTarget.style.backgroundColor="transparent")},children:[k&&t.terminalIds.length>0&&s.jsx("button",{onClick:D,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?"▼":"▶"}),s.jsxs("div",{style:{flex:1,minWidth:0},children:[h?s.jsx("input",{ref:S,value:x,onChange:T=>R(T.target.value),onBlur:B,onKeyDown:T=>{T.key==="Enter"&&B(),T.key==="Escape"&&g(!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"}}):s.jsx("div",{onDoubleClick:P,style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:k?"Double-click to rename":t.name,children:t.name}),s.jsxs("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:[t.terminalIds.length," terminal",t.terminalIds.length!==1?"s":""," · ",yn(Math.floor(t.createdAt/1e3))]})]}),k?s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:F,style:{flexShrink:0},title:"Close tab",children:"×"}):s.jsxs("div",{style:{display:"flex",gap:"4px",flexShrink:0},children:[s.jsx("button",{className:"pane-btn",onClick:$,title:"Reopen tab",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:O,title:"Delete tab",children:"×"})]})]}),k&&C&&p.length>0&&s.jsx("div",{style:{paddingLeft:"28px",backgroundColor:"rgba(0, 0, 0, 0.2)"},children:p.map(T=>s.jsxs("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--text-secondary)",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center"},title:`Connected: ${T.connected}`,children:[s.jsx("span",{style:{fontFamily:"monospace"},children:T.id}),s.jsx("span",{style:{marginLeft:"8px",color:T.active?T.connected?"var(--accent-green)":"var(--accent-yellow)":"var(--text-secondary)"},children:T.active?T.connected?"●":"◐":"○"}),T.active?s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:y=>{y.stopPropagation(),l(T.id)},style:{marginLeft:"auto",flexShrink:0},title:"Disconnect terminal (keeps session alive)",children:"×"}):s.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:"4px",flexShrink:0},children:[s.jsx("button",{className:"pane-btn",onClick:y=>{y.stopPropagation(),u(T.id)},title:"Reconnect terminal",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:y=>{y.stopPropagation(),window.confirm(`Kill terminal "${T.id}"? This will destroy the tmux session.`)&&f(T.id)},title:"Kill session",children:"×"})]})]},T.id))})]})}function Lo({sessionId:e,active:t,createdAt:n}){const r=_(d=>d.addTerminal),o=_(d=>d.killServerSession),c=()=>{r("horizontal",e)},i=d=>{d.stopPropagation(),window.confirm(`Delete orphaned session "${e}"? This will kill the tmux session.`)&&o(e)};return s.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:[s.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:t?"var(--accent-green)":"var(--text-secondary)",flexShrink:0}}),s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsx("div",{style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e}),s.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:yn(n)})]}),s.jsx("button",{className:"pane-btn pane-btn--danger",onClick:i,style:{flexShrink:0},title:"Delete session",children:"×"})]})}function Do(){const e=_(l=>l.sidebarOpen),t=_(l=>l.toggleSidebar),n=_(l=>l.fetchSessions),r=_(l=>e?l.serverSessions:[]),o=_(l=>e?l.tabs:[]),c=_(l=>l.terminalIds.length),i=_(l=>l.tabsLoading),d=new Set(o.flatMap(l=>l.terminalIds)),p=r.filter(l=>!d.has(l.sessionId));return a.useEffect(()=>{if(!e)return;n();let l=setInterval(n,5e3);const u=()=>{document.hidden?l&&(clearInterval(l),l=null):(n(),l||(l=setInterval(n,5e3)))};return document.addEventListener("visibilitychange",u),()=>{l&&clearInterval(l),document.removeEventListener("visibilitychange",u)}},[e,n]),a.useEffect(()=>{if(!e)return;const l=setTimeout(n,800);return()=>clearTimeout(l)},[c,e,n]),s.jsxs("div",{className:"session-sidebar",style:{width:e?280:0,height:"100%",backgroundColor:"var(--bg-secondary)",borderLeft:e?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,overflow:"hidden",transition:"width 0.2s ease"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[s.jsx("span",{style:{color:"var(--accent-blue)",fontSize:"14px",fontWeight:"bold"},children:"Tabs & Terminals"}),s.jsx("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"16px",padding:"0 4px",lineHeight:1},title:"Close sidebar",children:"×"})]}),s.jsxs("div",{style:{flex:1,overflowY:"auto"},children:[s.jsxs("div",{children:[s.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"}),o.length===0?s.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"14px",textAlign:"center",padding:"12px"},children:"No tabs"}):o.map(l=>s.jsx(No,{tabId:l.id},l.id))]}),!i&&p.length>0&&s.jsxs("div",{style:{marginTop:"16px"},children:[s.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"}),p.map(l=>s.jsx(Lo,{sessionId:l.sessionId,active:l.active,createdAt:l.createdAt},l.sessionId))]})]})]})}const kn=bt.memo(()=>{const e=_(k=>k.tabs),t=_(k=>k.activeTabId),n=_(k=>k.addTab),r=_(k=>k.switchTab),o=_(k=>k.closeTab),c=_(k=>k.renameTab),[i,d]=a.useState(null),[p,l]=a.useState(""),u=a.useRef(null),f=e.filter(k=>k.status==="open");a.useEffect(()=>{i&&u.current&&(u.current.focus(),u.current.select())},[i]);const h=k=>{d(k.id),l(k.name)},g=()=>{i&&p.trim()&&c(i,p.trim()),d(null),l("")},x=()=>{d(null),l("")},R=k=>{k.key==="Enter"?g():k.key==="Escape"&&x()},C=k=>{i||r(k)},j=(k,A)=>{k.stopPropagation(),o(A)},S=(k,A)=>{k.button===1&&(k.preventDefault(),o(A))},w=f.length>1;return s.jsxs("div",{className:"tab-bar",children:[f.map(k=>{const A=k.id===t,P=i===k.id,B=k.terminalIds.length;return s.jsx("div",{className:`tab-item ${A?"tab-item--active":""}`,onClick:()=>C(k.id),onDoubleClick:()=>h(k),onMouseDown:$=>S($,k.id),children:P?s.jsx("input",{ref:u,type:"text",value:p,onChange:$=>l($.target.value),onBlur:g,onKeyDown:R,className:"tab-item__rename-input"}):s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"tab-item__name",children:[k.name," ",B>0&&`(${B})`]}),w&&s.jsx("button",{className:"tab-item__close",onClick:$=>j($,k.id),title:"Close tab","aria-label":"Close tab",children:"×"})]})},k.id)}),s.jsx("button",{className:"tab-bar-add",onClick:()=>n(),title:"New tab","aria-label":"Add new tab",children:"+"})]})});kn.displayName="TabBar";function Mo(){return localStorage.getItem("ai-cli-online-token")}function Ao(){const e=_(u=>u.token),t=_(u=>u.setToken),n=_(u=>u.tabs),r=_(u=>u.addTab),o=_(u=>u.toggleSidebar),c=_(u=>u.fontSize),i=_(u=>u.setFontSize),d=_(u=>u.tabsLoading),p=_(u=>u.theme),l=_(u=>u.toggleTheme);return a.useEffect(()=>{const u=Mo();u&&!e&&t(u)},[]),a.useEffect(()=>{e&&!d&&n.filter(u=>u.status==="open").length===0&&r("Default")},[e,d]),e?s.jsxs("div",{style:{height:"100vh",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[s.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:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[s.jsx("span",{style:{fontSize:"15px",fontWeight:"bold",color:"var(--accent-blue)",letterSpacing:"0.5px"},children:"AI-Cli Online"}),s.jsxs("span",{style:{fontSize:"11px",color:"var(--text-secondary)",fontWeight:400},children:["v","3.0.2"]})]}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[s.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"1px 4px",borderRadius:"6px",backgroundColor:"rgba(0,0,0,0.2)"},children:[s.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−"}),s.jsx("span",{style:{fontSize:"11px",color:"var(--text-primary)",minWidth:"20px",textAlign:"center"},children:c}),s.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+"})]}),s.jsx(_o,{}),s.jsx("button",{className:"header-btn",onClick:l,title:`Switch to ${p==="dark"?"light":"dark"} mode`,"aria-label":"Toggle theme",children:p==="dark"?"☀":"🌙"}),s.jsx("button",{className:"header-btn",onClick:o,title:"Toggle Tabs & Terminals Sidebar","aria-label":"Toggle sidebar",children:"☰"}),s.jsx("button",{className:"header-btn header-btn--muted",onClick:()=>{window.confirm("Logout will close all terminals. Continue?")&&t(null)},children:"Logout"})]})]}),s.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[s.jsx("main",{style:{flex:1,overflow:"hidden"},children:s.jsx(Io,{})}),s.jsx(Do,{})]}),s.jsx(kn,{})]}):s.jsx(vr,{})}const zo=[1,2,3,4];function _o(){const e=_(r=>r.latency);if(e===null)return s.jsx("span",{style:{fontSize:"10px",color:"var(--scrollbar-thumb-hover)"},title:"Measuring latency...",children:"--ms"});let t,n;return e<50?(t="var(--accent-green)",n=4):e<150?(t="var(--accent-yellow)",n=3):e<300?(t="var(--accent-orange)",n=2):(t="var(--accent-red)",n=1),s.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: ${e}ms`,children:[zo.map(r=>s.jsx("span",{style:{display:"inline-block",width:"2.5px",height:`${3+r*2}px`,backgroundColor:r<=n?t:"var(--border)",borderRadius:"1px",transition:"background-color 0.3s ease"}},r)),s.jsxs("span",{style:{fontSize:"10px",color:t,marginLeft:"4px",fontWeight:500},children:[e,"ms"]})]})}ft.createRoot(document.getElementById("root")).render(s.jsx(bt.StrictMode,{children:s.jsx(wn,{children:s.jsx(Ao,{})})}));
|
package/web/dist/index.html
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
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-9ElcUlG3.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">
|