ai-cli-online 3.0.12 → 3.0.13

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.
@@ -20,6 +20,10 @@ RUN_HOME=$(eval echo "~${RUN_USER}")
20
20
 
21
21
  # Node.js 路径
22
22
  NODE_BIN=$(su - "$RUN_USER" -c "which node" 2>/dev/null || true)
23
+ # Fallback: source nvm if plain login shell didn't find node
24
+ if [[ -z "$NODE_BIN" ]]; then
25
+ NODE_BIN=$(su - "$RUN_USER" -c "source ~/.nvm/nvm.sh 2>/dev/null; which node" 2>/dev/null || true)
26
+ fi
23
27
  if [[ -z "$NODE_BIN" ]]; then
24
28
  echo "[错误] 未找到 node,请先安装 Node.js >= 18"
25
29
  exit 1
@@ -28,6 +32,9 @@ NODE_DIR=$(dirname "$NODE_BIN")
28
32
  NODE_VERSION=$("$NODE_BIN" --version)
29
33
 
30
34
  NPM_BIN=$(su - "$RUN_USER" -c "which npm" 2>/dev/null || true)
35
+ if [[ -z "$NPM_BIN" ]]; then
36
+ NPM_BIN=$(su - "$RUN_USER" -c "source ~/.nvm/nvm.sh 2>/dev/null; which npm" 2>/dev/null || true)
37
+ fi
31
38
  if [[ -z "$NPM_BIN" ]]; then
32
39
  echo "[错误] 未找到 npm"
33
40
  exit 1
@@ -81,7 +88,7 @@ Restart=on-failure
81
88
  RestartSec=5
82
89
 
83
90
  # 进程管理
84
- KillMode=mixed
91
+ KillMode=process
85
92
  KillSignal=SIGTERM
86
93
  TimeoutStopSec=10
87
94
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-cli-online",
3
- "version": "3.0.12",
3
+ "version": "3.0.13",
4
4
  "description": "AI-Cli Online - Web Terminal for Claude Code via xterm.js + tmux",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-cli-online-server",
3
- "version": "3.0.12",
3
+ "version": "3.0.13",
4
4
  "description": "CLI-Online Backend Server",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-cli-online-shared",
3
- "version": "3.0.12",
3
+ "version": "3.0.13",
4
4
  "description": "Shared types for CLI-Online",
5
5
  "type": "module",
6
6
  "main": "dist/types.js",
@@ -29,4 +29,4 @@ var Kn=Object.defineProperty;var Jn=(t,e,n)=>e in t?Kn(t,e,{enumerable:!0,config
29
29
  `),[e]),U=a.useMemo(()=>ys(e),[e]),H=a.useMemo(()=>{const m=new Map,x=new Map;return G.forEach((M,R)=>{if(M.type==="heading"){const ae=Mn(M.text||""),te=Ln(ae,x);m.set(R,te)}}),m},[G]),V=a.useRef(new Set),ne=a.useRef(!1),[K,se]=a.useState(()=>{try{const m=localStorage.getItem(qe(r,n)),x=m?JSON.parse(m):jt;return V.current=lt(x),x.replacements||(x.replacements=[]),x.comments||(x.comments=[]),x}catch{return jt}});xs({sessionId:r,filePath:n,token:s,annotations:K,annLoadedRef:ne,setAnnotations:se,baselineIdsRef:V});const[we,ye]=a.useState(0),De=a.useMemo(()=>{const m=V.current,x=K.additions.length+K.deletions.length+K.replacements.length+K.comments.length;let M=0;return K.additions.forEach(R=>{m.has(R.id)&&M++}),K.deletions.forEach(R=>{m.has(R.id)&&M++}),K.replacements.forEach(R=>{m.has(R.id)&&M++}),K.comments.forEach(R=>{m.has(R.id)&&M++}),{total:x,sent:M,unsent:x-M}},[K,we]),[A,W]=a.useState(null),[X,Z]=a.useState(""),q=a.useRef(null),[Q,be]=a.useState(null),[Ee,je]=a.useState(""),Ae=a.useRef(null),[le,Se]=a.useState(null),ue=a.useRef(null),He=a.useRef(0),_e=a.useRef(null);a.useEffect(()=>{const m=ue.current;if(!m)return;let x;const M=()=>{clearTimeout(x),x=setTimeout(()=>{const R=Zt(r,n);if(m.scrollTop>0)try{localStorage.setItem(R,String(m.scrollTop))}catch{}else localStorage.removeItem(R)},50)};return m.addEventListener("scroll",M,{passive:!0}),()=>{clearTimeout(x),m.removeEventListener("scroll",M)}},[r,n]),a.useEffect(()=>{if(!G.length)return;const m=localStorage.getItem(Zt(r,n));if(!m)return;const x=Number(m),M=ue.current;if(!M||(M.scrollTop=x,M.scrollTop>=x-10))return;let R;const ae=()=>{M.scrollTop=x,te.disconnect()},te=new MutationObserver(()=>{clearTimeout(R),R=setTimeout(ae,80)});te.observe(M,{childList:!0,subtree:!0});const ie=setTimeout(ae,500);return()=>{clearTimeout(R),clearTimeout(ie),te.disconnect()}},[r,n,G.length]),a.useEffect(()=>{A!=null&&requestAnimationFrame(()=>{var m;return(m=q.current)==null?void 0:m.focus()})},[A]),a.useEffect(()=>{Q&&requestAnimationFrame(()=>{var m;return(m=Ae.current)==null?void 0:m.focus()})},[Q]);const Oe=a.useRef({annotations:K,activeInsert:A,insertText:X,pendingAction:Q,pendingText:Ee,tokens:G,filePath:n,sessionId:r,token:s});Oe.current={annotations:K,activeInsert:A,insertText:X,pendingAction:Q,pendingText:Ee,tokens:G,filePath:n,sessionId:r,token:s},a.useEffect(()=>()=>{const m=Oe.current;let x=m.annotations,M=!1;if(m.activeInsert!=null&&m.insertText.trim()){const R=tt(m.tokens,m.activeInsert+1);x={...x,additions:[...x.additions,{id:Te(),afterTokenIndex:m.activeInsert,sourceLine:R,content:m.insertText.trim()}]},M=!0}if(m.pendingAction&&m.pendingText.trim()){const R=m.pendingAction,ae=m.pendingText.trim();R.type==="replace"?x={...x,replacements:[...x.replacements,{id:Te(),tokenIndices:R.tokenIndices,startLine:R.startLine,endLine:R.endLine,selectedText:R.text,content:ae}]}:x={...x,comments:[...x.comments,{id:Te(),tokenIndices:R.tokenIndices,startLine:R.startLine,endLine:R.endLine,selectedText:R.text,content:ae}]},M=!0}if(M){const R=JSON.stringify(x);try{localStorage.setItem(qe(m.sessionId,m.filePath),R)}catch{}Nn(m.token,m.sessionId,m.filePath,R,Date.now()).catch(()=>{})}},[]);const Ne=a.useCallback(m=>{if(!X.trim()){W(null),Z("");return}const x=tt(G,m+1);se(M=>({...M,additions:[...M.additions,{id:Te(),afterTokenIndex:m,sourceLine:x,content:X.trim()}]})),W(null),Z("")},[X,G]),Le=a.useCallback(m=>{se(x=>({...x,additions:x.additions.filter(M=>M.id!==m)}))},[]),Ye=a.useCallback((m,x)=>{se(M=>({...M,additions:M.additions.map(R=>R.id===m?{...R,id:Te(),content:x}:R)}))},[]),pt=a.useCallback(()=>{var m;le&&(se(x=>({...x,deletions:[...x.deletions,{id:Te(),tokenIndices:le.tokenIndices,startLine:le.startLine,endLine:le.endLine,selectedText:le.text.slice(0,80)}]})),Se(null),(m=window.getSelection())==null||m.removeAllRanges())},[le]),y=a.useCallback(m=>{var x;le&&(be({type:m,tokenIndices:le.tokenIndices,startLine:le.startLine,endLine:le.endLine,text:le.text.slice(0,80)}),je(""),Se(null),(x=window.getSelection())==null||x.removeAllRanges())},[le]),E=a.useCallback(()=>{if(!Q)return;const m=Ee.trim();if(!m){be(null),je("");return}Q.type==="replace"?se(x=>({...x,replacements:[...x.replacements,{id:Te(),tokenIndices:Q.tokenIndices,startLine:Q.startLine,endLine:Q.endLine,selectedText:Q.text,content:m}]})):se(x=>({...x,comments:[...x.comments,{id:Te(),tokenIndices:Q.tokenIndices,startLine:Q.startLine,endLine:Q.endLine,selectedText:Q.text,content:m}]})),be(null),je("")},[Q,Ee]),J=a.useCallback(m=>{se(x=>({...x,replacements:x.replacements.filter(M=>M.id!==m)}))},[]),re=a.useCallback((m,x)=>{se(M=>({...M,replacements:M.replacements.map(R=>R.id===m?{...R,id:Te(),content:x}:R)}))},[]),oe=a.useCallback(m=>{se(x=>({...x,comments:x.comments.filter(M=>M.id!==m)}))},[]),ke=a.useCallback((m,x)=>{se(M=>({...M,comments:M.comments.map(R=>R.id===m?{...R,id:Te(),content:x}:R)}))},[]),ce=a.useCallback(m=>{se(x=>({...x,deletions:x.deletions.filter(M=>M.id!==m)}))},[]),he=a.useCallback((m,x)=>{se(M=>({...M,deletions:M.deletions.map(R=>R.id===m?{...R,id:Te(),selectedText:x}:R)}))},[]),pe=a.useCallback(m=>{let x=m instanceof Element?m:m.parentElement;for(;x&&x!==ue.current;){if(x.hasAttribute("data-token-index"))return x;x=x.parentElement}return null},[]),de=a.useCallback(()=>{const m=window.getSelection();if(!m||m.isCollapsed||!ue.current){Se(null);return}const x=m.toString().trim();if(!x){Se(null);return}const M=m.getRangeAt(0);if(!ue.current.contains(M.commonAncestorContainer)){Se(null);return}const R=pe(M.startContainer),ae=pe(M.endContainer);if(!R||!ae){Se(null);return}const te=parseInt(R.getAttribute("data-token-index")||"0",10),ie=parseInt(ae.getAttribute("data-token-index")||"0",10),Mt=[];for(let bt=Math.min(te,ie);bt<=Math.max(te,ie);bt++)Mt.push(bt);const Un=tt(G,Math.min(te,ie)),Hn=tt(G,Math.max(te,ie)+1),Dt=M.getBoundingClientRect(),gt=ue.current,At=gt.getBoundingClientRect();navigator.clipboard.writeText(x).catch(()=>{});const Xe=_e.current,zt=Xe&&Date.now()-Xe.time<500;He.current=Date.now(),Se({x:(zt?Xe.x:Dt.right)-At.left+gt.scrollLeft+6,y:(zt?Xe.y:Dt.top)-At.top+gt.scrollTop-44,tokenIndices:Mt,startLine:Un,endLine:Hn,text:x})},[G,pe]),ve=a.useRef(void 0);a.useEffect(()=>{const m=()=>{ve.current&&clearTimeout(ve.current),ve.current=setTimeout(()=>{const x=window.getSelection();if(!x||x.isCollapsed||!ue.current){if(Date.now()-He.current<300)return;Se(null);return}const M=x.anchorNode;M&&ue.current.contains(M)&&de()},120)};return document.addEventListener("selectionchange",m),()=>{document.removeEventListener("selectionchange",m),ve.current&&clearTimeout(ve.current)}},[de]);const Ke=D(m=>m.theme);ms(ue,G,Ke);const Fe=a.useCallback(()=>{const m=V.current;return{additions:K.additions.filter(x=>!m.has(x.id)),deletions:K.deletions.filter(x=>!m.has(x.id)),replacements:K.replacements.filter(x=>!m.has(x.id)),comments:K.comments.filter(x=>!m.has(x.id))}},[K]),mt=a.useCallback(async()=>{const m=Fe();if(!en(m))return;const x=Qt(m,$),M=rn(n);try{const{path:R}=await Xt(s,r,M,x),ae=nn(n,R);i(ae),V.current=lt(K),ye(ie=>ie+1);const te=m.additions.length+m.deletions.length+m.replacements.length+m.comments.length;C("ok",`Sent ${te} annotation(s)`)}catch(R){const ae=R instanceof Error?R.message:"Failed to send";C("err",ae)}},[Fe,K,$,i,n,s,r,C]),Be=a.useCallback(async(m,x)=>{if(!l)return;const M={additions:[],deletions:[],replacements:[],comments:[]};if(x==="add"){const te=K.additions.find(ie=>ie.id===m);if(!te)return;M.additions.push(te)}else if(x==="del"){const te=K.deletions.find(ie=>ie.id===m);if(!te)return;M.deletions.push(te)}else if(x==="rep"){const te=K.replacements.find(ie=>ie.id===m);if(!te)return;M.replacements.push(te)}else{const te=K.comments.find(ie=>ie.id===m);if(!te)return;M.comments.push(te)}const R=Qt(M,$),ae=rn(n);try{const{path:te}=await Xt(s,r,ae,R);l(nn(n,te)),V.current.add(m),ye(ie=>ie+1),C("ok","Sent 1 annotation")}catch(te){const ie=te instanceof Error?te.message:"Failed to send";C("err",ie)}},[l,n,K,$,s,r,C]),Fn=a.useCallback((m,x)=>{x==="add"?Le(m):x==="del"?ce(m):x==="rep"?J(m):oe(m)},[Le,ce,J,oe]);a.useImperativeHandle(h,()=>({getSummary:()=>{const m=Fe();return en(m)?"[pending annotations]":""},handleEscape:()=>v?(Y(),!0):Q?(E(),!0):A!=null?(Ne(A),!0):!1,getScrollTop:()=>{var m;return((m=ue.current)==null?void 0:m.scrollTop)??0},setScrollTop:m=>{requestAnimationFrame(()=>{ue.current&&(ue.current.scrollTop=m)})}}),[Fe,v,Y,A,Ne,Q,E]);const Bn=a.useMemo(()=>{const m=new Set;return K.deletions.forEach(x=>x.tokenIndices.forEach(M=>m.add(M))),m},[K.deletions]),Pn=a.useMemo(()=>{const m=new Set;return K.replacements.forEach(x=>x.tokenIndices.forEach(M=>m.add(M))),m},[K.replacements]),Wn=a.useMemo(()=>{const m=new Set;return K.comments.forEach(x=>x.tokenIndices.forEach(M=>m.add(M))),m},[K.comments]),Nt=a.useMemo(()=>{const m=new Map;return K.additions.forEach(x=>{const M=m.get(x.afterTokenIndex)||[];M.push(x),m.set(x.afterTokenIndex,M)}),m},[K.additions]),Lt=De.unsent>0,ht=a.useCallback(m=>V.current.has(m),[]);return o.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[o.jsxs("div",{className:"plan-anno-toolbar",children:[o.jsx("span",{style:{fontSize:"11px",color:"var(--text-secondary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},title:n,children:n.split("/").pop()||n}),b&&o.jsx("span",{style:{fontSize:"10px",color:b.type==="ok"?"var(--accent-green)":"var(--accent-red)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:160,cursor:b.type==="err"?"pointer":void 0},title:b.type==="err"?"Click to copy":b.msg,onClick:b.type==="err"?()=>{navigator.clipboard.writeText(b.msg).catch(()=>{}),C("ok","Copied")}:void 0,children:b.msg}),v?o.jsxs(o.Fragment,{children:[o.jsx("button",{className:"pane-btn",onClick:P,disabled:z,style:{color:"var(--accent-green)"},title:"Save (Ctrl+S)",children:z?"Saving...":"Save"}),o.jsx("button",{className:"pane-btn",onClick:Y,disabled:z,title:"Cancel (Esc)",children:"Cancel"})]}):o.jsxs(o.Fragment,{children:[d&&o.jsx("button",{className:"pane-btn",onClick:d,title:"Refresh current file",children:"↻"}),!u&&o.jsx("button",{className:"pane-btn",onClick:ee,title:"Edit file (double-click content)",children:"Edit"}),o.jsx("button",{className:"pane-btn",onClick:mt,disabled:!Lt,title:"Send all annotations",style:Lt?{color:"var(--accent-green)"}:{opacity:.4},children:"Send"}),o.jsx(Ts,{annotations:K,annCounts:De,isSent:ht,onSendAll:mt,onSendSingle:Be,onDelete:Fn}),p&&o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:async()=>{await mt(),p()},title:"Send annotations & close file",children:"×"})]})]}),o.jsxs("div",{style:{display:"flex",flex:1,minHeight:0},children:[v?o.jsx("textarea",{ref:B,className:"plan-edit-textarea",style:{fontSize:`${g}px`},value:T,onChange:m=>L(m.target.value),onKeyDown:m=>{if(m.key==="s"&&(m.ctrlKey||m.metaKey)){m.preventDefault(),P();return}if(m.key==="Escape"){m.preventDefault(),Y();return}},spellCheck:!1}):o.jsxs("div",{ref:ue,className:`plan-anno-content md-preview${A!=null?" plan-anno-content--editing":""}`,style:{flex:1,overflow:"auto",padding:"8px 12px",position:"relative",fontSize:`${g}px`,minWidth:0},onMouseUp:m=>{_e.current={x:m.clientX,y:m.clientY,time:Date.now()},de()},onDoubleClick:m=>{u||m.target.closest("textarea, button, .plan-annotation-card, .plan-insert-btn, .plan-selection-float")||ee()},children:[!u&&o.jsx(on,{index:-1,active:A===-1,additions:Nt.get(-1),onOpen:()=>{W(-1),Z("")},onSubmit:()=>Ne(-1),onRemoveAddition:Le,onEditAddition:Ye,onSendSingle:l?m=>Be(m,"add"):void 0,isSent:ht,insertText:X,setInsertText:Z,textareaRef:A===-1?q:void 0,expanded:f,alwaysShow:G.length===0,fontSize:g}),G.map((m,x)=>{const M=bs(m);return o.jsxs("div",{children:[o.jsx("div",{"data-token-index":x,id:H.get(x),className:Bn.has(x)?"plan-block--deleted":Pn.has(x)?"plan-block--replaced":Wn.has(x)?"plan-block--commented":void 0,dangerouslySetInnerHTML:{__html:M}}),K.deletions.filter(R=>R.tokenIndices[0]===x).map(R=>o.jsx(vt,{type:"del",annotation:R,fontSize:g,onEdit:he,onRemove:ce,onSend:l?ae=>Be(ae,"del"):void 0,isSent:V.current.has(R.id)},R.id)),K.replacements.filter(R=>R.tokenIndices[0]===x).map(R=>o.jsx(vt,{type:"rep",annotation:R,fontSize:g,onEdit:re,onRemove:J,onSend:l?ae=>Be(ae,"rep"):void 0,isSent:V.current.has(R.id)},R.id)),K.comments.filter(R=>R.tokenIndices[0]===x).map(R=>o.jsx(vt,{type:"com",annotation:R,fontSize:g,onEdit:ke,onRemove:oe,onSend:l?ae=>Be(ae,"com"):void 0,isSent:V.current.has(R.id)},R.id)),Q&&Q.tokenIndices[0]===x&&o.jsxs("div",{className:Q.type==="replace"?"plan-replace-card":"plan-comment-card",style:{padding:"4px 8px"},children:[o.jsx("span",{style:{color:Q.type==="replace"?"var(--accent-blue)":"var(--accent-green)",flexShrink:0},children:Q.type==="replace"?"⇄":"?"}),o.jsx("textarea",{ref:Ae,className:"plan-annotation-textarea",value:Ee,onChange:R=>je(R.target.value),onKeyDown:R=>{if(R.key==="Enter"&&(R.ctrlKey||R.metaKey)){R.preventDefault(),E();return}if(R.key==="Escape"){R.preventDefault(),E();return}},onBlur:E,placeholder:Q.type==="replace"?"Replace with... (Ctrl+Enter to save)":"Comment... (Ctrl+Enter to save)",rows:it(Ee),style:{fontSize:`${g}px`,flex:1}})]}),!u&&o.jsx(on,{index:x,active:A===x,additions:Nt.get(x),onOpen:()=>{W(x),Z("")},onSubmit:()=>Ne(x),onRemoveAddition:Le,onEditAddition:Ye,onSendSingle:l?R=>Be(R,"add"):void 0,isSent:ht,insertText:X,setInsertText:Z,textareaRef:A===x?q:void 0,expanded:f,fontSize:g})]},x)}),!u&&le&&o.jsx(Es,{x:le.x,y:le.y,onDelete:pt,onReplace:()=>y("replace"),onComment:()=>y("comment")})]}),!v&&o.jsx(Ss,{headings:U,scrollRef:ue})]})]})});function on({index:t,active:e,additions:n,onOpen:r,onSubmit:s,onRemoveAddition:i,onEditAddition:l,onSendSingle:d,isSent:p,insertText:c,setInsertText:f,textareaRef:u,expanded:h,alwaysShow:g,fontSize:b=14}){const[j,k]=a.useState(null),[C,v]=a.useState(""),I=a.useRef(null),T=Ct(),L=Ct();a.useEffect(()=>{j&&(T.clearUndo(),requestAnimationFrame(()=>{const N=I.current;N&&(N.focus(),N.selectionStart=N.selectionEnd=N.value.length)}))},[j]),a.useEffect(()=>{e&&L.clearUndo()},[e]);const z=a.useCallback(N=>{v(S=>(T.pushUndo(S),N))},[T]),_=a.useCallback(N=>{L.pushUndo(c),f(N)},[c,f,L]),B=a.useCallback(N=>{k(N.id),v(N.content)},[]),F=a.useCallback(()=>{if(!j)return;const N=C.trim();N?l(j,N):i(j),k(null),v("")},[j,C,l,i]),O=a.useCallback(()=>{k(null),v("")},[]);return o.jsxs("div",{className:`plan-insert-zone${g?" plan-insert-zone--empty":""}`,"data-zone-index":t,children:[n==null?void 0:n.map(N=>o.jsx("div",{className:"plan-annotation-card",children:j===N.id?o.jsx("textarea",{ref:I,className:"plan-annotation-textarea",value:C,onChange:S=>z(S.target.value),onKeyDown:S=>{if(S.key==="Enter"&&(S.ctrlKey||S.metaKey)){S.preventDefault(),F();return}if(S.key==="Escape"){S.preventDefault(),O();return}if(S.key==="Tab"){Et(S,z);return}},onBlur:F,rows:it(C),style:{fontSize:`${b}px`,flex:1,...h?{minWidth:300}:void 0}}):o.jsxs(o.Fragment,{children:[o.jsx("span",{style:{flex:1,fontSize:`${b}px`,color:"var(--accent-yellow)",whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>B(N),title:"Double-click to edit",children:N.content}),d&&(()=>{const S=(p==null?void 0:p(N.id))??!1;return o.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!S&&d(N.id),disabled:S,title:S?"Already sent":"Send to terminal",style:S?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),o.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>B(N),style:{color:"var(--accent-blue)"},title:"Edit annotation",children:"✎"}),o.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>i(N.id),children:"×"})]})},N.id)),e?o.jsx("div",{className:"plan-annotation-card plan-annotation-card--editing",children:o.jsx("textarea",{ref:u,className:"plan-annotation-textarea",value:c,onChange:N=>_(N.target.value),onKeyDown:N=>{if(N.key==="Enter"&&(N.ctrlKey||N.metaKey)){N.preventDefault(),s();return}if(N.key==="Escape"){N.preventDefault(),s();return}if(N.key==="Tab"){Et(N,_);return}},onBlur:s,placeholder:"Add annotation... (Ctrl+Enter or Esc to save)",rows:it(c),style:{fontSize:`${b}px`,...h?{minWidth:300}:void 0}})}):g&&!(n!=null&&n.length)?o.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."}):o.jsx("button",{className:"plan-insert-btn",onClick:r,title:"Add annotation here",children:"+"})]})}async function Re(t,e,n){const r=n?{path:n}:void 0;return ge.get(t,e,"files",r)}function Is(t,e,n,r){return new Promise((s,i)=>{const l=new FormData;for(const p of n)l.append("files",p);const d=new XMLHttpRequest;d.open("POST",`${Me}/api/sessions/${encodeURIComponent(e)}/upload`),d.setRequestHeader("Authorization",`Bearer ${t}`),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?s():i(new Error(`Upload failed: ${d.status}`))}),d.addEventListener("error",()=>i(new Error("Upload network error"))),d.addEventListener("abort",()=>i(new Error("Upload aborted"))),d.send(l)})}async function ln(t,e){return(await ge.get(t,e,"cwd")).cwd}async function Rs(t,e,n){return ge.post(t,e,"touch",{name:n})}async function Ns(t,e,n){return ge.post(t,e,"mkdir",{path:n})}async function Ls(t,e,n){return ge.del(t,e,"rm",{path:n})}async function Ms(t,e){const n=await ge.getBlob(t,e,"download-cwd"),r=await n.blob(),s=URL.createObjectURL(r),i=document.createElement("a");i.href=s;const l=n.headers.get("Content-Disposition"),d=l==null?void 0:l.match(/filename="(.+)"/);i.download=d?decodeURIComponent(d[1]):"cwd.tar.gz",document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(s)}async function Ds(t,e,n){const s=await(await ge.getBlob(t,e,"download",{path:n})).blob(),i=URL.createObjectURL(s),l=document.createElement("a");l.href=i,l.download=n.split("/").pop()||"download",document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(i)}function Dn(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function As(t,e){if(e==="directory")return"📁";const n=t.slice(t.lastIndexOf(".")).toLowerCase();return n===".pdf"?"📕":n===".html"||n===".htm"?"🌐":n===".md"?"📝":"📄"}function An(t){const e=new Date(t*1e3),n=r=>String(r).padStart(2,"0");return`${n(e.getMonth()+1)}-${n(e.getDate())} ${n(e.getHours())}:${n(e.getMinutes())}`}function zs({sessionId:t,token:e,planDir:n,selectedFile:r,onSelectFile:s,onCreateFile:i,onDeleteFile:l}){const[d,p]=a.useState([]),[c,f]=a.useState(!0),[u,h]=a.useState(""),[g,b]=a.useState(!1),j=a.useRef(null),[k,C]=a.useState(()=>{if(r&&r.startsWith(n+"/")){const w=r.substring(0,r.lastIndexOf("/"));if(w.startsWith(n))return w}return n});a.useEffect(()=>{if(r&&r.startsWith(n+"/")){const w=r.substring(0,r.lastIndexOf("/"));if(w.startsWith(n)){C(w);return}}C(n)},[r,n]);const v=a.useCallback(async()=>{if(!(!e||!k)){f(!0);try{const ee=(await Re(e,t,k)).files.filter(Y=>Y.type==="file"&&(Y.name.toLowerCase().endsWith(".md")||Y.name===".index.json")||Y.type==="directory").sort((Y,P)=>{const G=Y.type==="file"&&Y.name===".index.json",$=P.type==="file"&&P.name===".index.json";return G&&!$?-1:!G&&$?1:Y.type==="directory"&&P.type!=="directory"?-1:Y.type!=="directory"&&P.type==="directory"?1:Y.name.localeCompare(P.name)});p(ee)}catch{p([])}finally{f(!1)}}},[e,t,k]);a.useEffect(()=>{v()},[v]),a.useEffect(()=>{const w=setInterval(v,5e3);return()=>clearInterval(w)},[v]);const I=a.useCallback(()=>{const w=n.substring(0,n.lastIndexOf("/")+1);return k.startsWith(w)?k.substring(w.length):k},[n,k]),T=a.useCallback(async()=>{const w=u.trim();if(!w)return;const ee=w.endsWith(".md")?w:`${w}.md`;b(!0);try{const Y=await Rs(e,t,`${I()}/${ee}`);Y.ok&&(h(""),await v(),i(Y.path))}catch{}finally{b(!1)}},[u,e,t,I,v,i]),L=a.useCallback(async()=>{const w=u.trim().replace(/\/+$/,"");if(w){b(!0);try{await Ns(e,t,`${I()}/${w}`),h(""),await v()}catch{}finally{b(!1)}}},[u,e,t,I,v]),z=a.useCallback(async w=>{const ee=`${k}/${w.name}`,Y=w.type==="directory"?`folder "${w.name}" and all its contents`:`"${w.name}"`;if(window.confirm(`Delete ${Y}?`))try{await Ls(e,t,ee),l==null||l(ee),await v()}catch{}},[e,t,k,v,l]),_=a.useCallback(w=>{C(ee=>`${ee}/${w}`)},[]),B=a.useCallback(()=>{k!==n&&C(w=>w.substring(0,w.lastIndexOf("/")))},[k,n]),F=n.split("/").pop()||"AiTasks",O=(()=>{const w=n.split("/");return w.length>=2?w[w.length-2]+"/":""})(),N=k===n?O+F+"/":O+F+"/"+k.substring(n.length+1)+"/",S=r?r.split("/").pop():null;return o.jsxs("div",{className:"plan-file-browser",children:[o.jsxs("div",{className:"plan-file-browser__header",children:[o.jsx("span",{className:"plan-file-browser__title",title:N,children:N}),o.jsx("button",{className:"pane-btn pane-btn--sm",onClick:v,title:"Refresh file list",style:{fontSize:12},children:"↻"})]}),o.jsxs("div",{className:"plan-file-browser__create",children:[o.jsx("input",{ref:j,className:"plan-file-browser__input",value:u,onChange:w=>h(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),T())},placeholder:"name",disabled:g}),o.jsx("button",{className:"pane-btn pane-btn--sm",onClick:T,disabled:g||!u.trim(),title:"Create new .md file",style:u.trim()?{color:"var(--accent-green)",fontWeight:700,fontSize:14}:{opacity:.4,fontWeight:700,fontSize:14},children:"+"}),o.jsx("button",{className:"pane-btn pane-btn--sm",onClick:L,disabled:g||!u.trim(),title:"Create new folder",style:u.trim()?{color:"var(--accent-blue)"}:{opacity:.4},children:"📁"})]}),o.jsxs("div",{className:"plan-file-browser__list",children:[c&&d.length===0&&o.jsx("div",{className:"plan-file-browser__status",children:"Loading..."}),!c&&d.length===0&&o.jsx("div",{className:"plan-file-browser__status",children:"No .md files"}),k!==n&&o.jsxs("div",{className:"plan-file-browser__item",onClick:B,title:"Go up to parent directory",style:{cursor:"pointer"},children:[o.jsx("span",{className:"plan-file-browser__icon",style:{color:"var(--accent-blue)"},children:"←"}),o.jsx("span",{className:"plan-file-browser__name",style:{color:"var(--accent-blue)"},children:".."})]}),d.map(w=>{const ee=`${k}/${w.name}`,Y=w.type==="file"&&w.name===S,P=w.type==="directory";return o.jsxs("div",{className:`plan-file-browser__item${Y?" plan-file-browser__item--active":""}`,onClick:()=>P?_(w.name):s(ee),title:P?`Open folder ${w.name}`:w.name,style:{cursor:"pointer"},children:[o.jsx("span",{className:"plan-file-browser__icon",children:P?"📁":w.name===".index.json"?"🔒":"□"}),o.jsxs("span",{className:"plan-file-browser__name",children:[w.name,P?"/":""]}),!P&&o.jsx("span",{className:"plan-file-browser__size",children:Dn(w.size)}),!w.name.startsWith(".")&&o.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm plan-file-browser__delete",onClick:G=>{G.stopPropagation(),z(w)},title:`Delete ${w.name}`,children:"×"})]},w.name)})]})]})}const wt={status:"idle",mode:"lines",lines:[],content:"",buffer:null,totalSize:0,receivedBytes:0,mtime:0,error:null},$s=200;function _s(){const[t,e]=a.useState(wt),n=a.useRef("lines"),r=a.useRef([]),s=a.useRef(""),i=a.useRef(""),l=a.useRef([]),d=a.useRef(0),p=a.useRef(0),c=a.useRef(null),f=a.useRef(null),u=a.useCallback(()=>{const C=n.current;e(v=>({...v,receivedBytes:d.current,...C==="lines"?{lines:[...r.current]}:{},...C==="content"?{content:i.current}:{}}))},[]),h=a.useCallback(()=>{c.current===null&&(c.current=window.setTimeout(()=>{c.current=null,u()},$s))},[u]),g=a.useCallback(C=>{n.current=C,r.current=[],s.current="",i.current="",l.current=[],d.current=0,p.current=0,f.current=new TextDecoder,c.current!==null&&(clearTimeout(c.current),c.current=null),e({...wt,mode:C,status:"streaming"})},[]),b=a.useCallback(C=>{d.current+=C.length;const v=n.current;if(v==="lines"){const T=f.current.decode(C,{stream:!0}).split(`
30
30
  `);T[0]=s.current+T[0],s.current=T.pop(),T.length>0&&r.current.push(...T)}else if(v==="content"){const I=f.current.decode(C,{stream:!0});i.current+=I}else l.current.push(new Uint8Array(C));h()},[h]),j=a.useCallback(C=>{switch(C.type){case"file-stream-start":p.current=C.size,e(v=>({...v,totalSize:C.size,mtime:C.mtime}));break;case"file-stream-end":{c.current!==null&&(clearTimeout(c.current),c.current=null);const v=n.current;let I=r.current,T=i.current,L=null;if(v==="lines"){const z=f.current.decode(),_=s.current+z;_&&(I=[...I,_],r.current=I),s.current=""}else if(v==="content"){const z=f.current.decode();T=i.current+z,i.current=T}else{const z=l.current.reduce((B,F)=>B+F.length,0);L=new Uint8Array(z);let _=0;for(const B of l.current)L.set(B,_),_+=B.length;l.current=[]}e({status:"complete",mode:v,lines:v==="lines"?[...I]:[],content:v==="content"?T:"",buffer:v==="binary"?L:null,totalSize:p.current,receivedBytes:d.current,mtime:0,error:null});break}case"file-stream-error":c.current!==null&&(clearTimeout(c.current),c.current=null),e(v=>({...v,status:"error",error:C.error}));break}},[]),k=a.useCallback(()=>{c.current!==null&&(clearTimeout(c.current),c.current=null),r.current=[],s.current="",i.current="",l.current=[],d.current=0,p.current=0,f.current=null,e(wt)},[]);return{state:t,startStream:g,handleChunk:b,handleControl:j,reset:k}}function cn({label:t,percent:e}){return o.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:8},children:[o.jsx("span",{style:{color:"var(--text-secondary)",fontSize:13},children:t}),e!=null&&o.jsxs("div",{style:{width:120,display:"flex",alignItems:"center",gap:6},children:[o.jsx("div",{style:{flex:1,height:4,backgroundColor:"var(--border)",borderRadius:2,overflow:"hidden"},children:o.jsx("div",{style:{height:"100%",width:`${e}%`,backgroundColor:"var(--accent-blue)",transition:"width 0.2s"}})}),o.jsxs("span",{style:{fontSize:10,color:"var(--text-secondary)",whiteSpace:"nowrap"},children:[e,"%"]})]})]})}function Os({sessionId:t,token:e,connected:n,onRequestFileStream:r,onSendToTerminal:s}){const i=_s(),[l,d]=a.useState(!1),[p,c]=a.useState(null),[f,u]=a.useState(null),[h,g]=a.useState(""),[b,j]=a.useState(!1),[k,C]=a.useState(!1),v=a.useRef(null),I="plan-selected-file",T=a.useRef(void 0);a.useEffect(()=>{if(f)return clearTimeout(T.current),T.current=setTimeout(()=>{try{localStorage.setItem(I,f)}catch{}},50),()=>clearTimeout(T.current)},[f]);const L=a.useRef(null);a.useEffect(()=>{L.current=null;let A=!1;return j(!0),C(!1),(async()=>{let W="";try{const X=await Re(e,t);if(A)return;if(W=X.home||"",X.files.find(q=>q.name==="AiTasks"&&q.type==="directory")){const q=X.cwd+"/AiTasks";c(q);const Q=localStorage.getItem(I);Q&&Q.startsWith(q+"/")&&u(Q)}else c(null),u(null),C(!0)}catch{c(null)}finally{A||j(!1)}try{if(A)return;if(W){const X=`${W}/.claude/plugins/installed_plugins.json`,Z=await rt(e,t,X,0);if(!A&&Z)try{const q=JSON.parse(Z.content);"ai-cli-task@moonview"in(q.plugins||q)||d(!0)}catch{d(!0)}}}catch{}})(),()=>{A=!0}},[t,e]),a.useEffect(()=>{if(!k||!n)return;const A=setInterval(async()=>{try{const W=await Re(e,t);if(W.files.find(Z=>Z.name==="AiTasks"&&Z.type==="directory")){const Z=W.cwd+"/AiTasks";c(Z),C(!1);const q=localStorage.getItem(I);q&&q.startsWith(Z+"/")&&u(q)}}catch{}},3e3);return()=>clearInterval(A)},[k,n,e,t,I]),a.useEffect(()=>(Wr(t,i.handleChunk,i.handleControl),()=>Ur(t)),[t,i.handleChunk,i.handleControl]),a.useEffect(()=>{!f||!n||L.current===f&&h||(L.current=f,i.reset(),i.startStream("content"),r==null||r(f))},[f,n]);const z=a.useRef(0);a.useEffect(()=>{i.state.status==="complete"&&f&&(g(i.state.content),z.current=Date.now())},[i.state.status,i.state.content,f]),a.useEffect(()=>{if(!f||!n||!h)return;const A=setInterval(async()=>{if(z.current)try{const W=await rt(e,t,f,z.current);W&&(g(W.content),z.current=W.mtime)}catch{}},3e3);return()=>clearInterval(A)},[f,n,h,e,t]);const _=a.useRef(new Map),B=a.useCallback(()=>{var W,X;if(!f)return;const A=((X=(W=v.current)==null?void 0:W.getScrollTop)==null?void 0:X.call(W))??0;A>0&&_.current.set(f,A)},[f]);a.useEffect(()=>{if(!f||!h)return;const A=_.current.get(f);A!=null&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{var W,X;(X=(W=v.current)==null?void 0:W.setScrollTop)==null||X.call(W,A)})})},[f,h]);const F=a.useCallback(A=>{A!==f&&(B(),u(A),g(""),L.current=null)},[f,B]),O=a.useCallback(A=>{f&&(f===A||f.startsWith(A+"/"))&&(u(null),g(""),L.current=null)},[f]),N=a.useCallback(A=>{u(A),g(""),L.current=null},[]),S=a.useCallback(A=>{A&&(s==null||s(A))},[s]),w=a.useCallback((A,W)=>{g(A),z.current=W},[]),ee=a.useCallback(()=>{B(),u(null),g(""),L.current=null},[B]),Y=a.useCallback(()=>{!f||!n||(L.current=null,g(""),i.reset(),i.startStream("content"),r==null||r(f),L.current=f)},[f,n,i,r]),[P,G]=a.useState(()=>{const A=localStorage.getItem(`plan-fb-width-${t}`);if(A){const W=Number(A);if(Number.isFinite(W)&&W>=60&&W<=300)return W}return 130}),$=a.useRef(P);if(P!==$.current){$.current=P;try{localStorage.setItem(`plan-fb-width-${t}`,String(Math.round(P)))}catch{}}const U=a.useCallback(A=>{A.preventDefault();const W=A.clientX,X=P;document.body.classList.add("resizing-panes");const Z=Q=>{const be=Q.clientX-W;G(Math.min(300,Math.max(60,X+be)))},q=()=>{document.body.classList.remove("resizing-panes"),document.removeEventListener("mousemove",Z),document.removeEventListener("mouseup",q)};document.addEventListener("mousemove",Z),document.addEventListener("mouseup",q)},[P]),H=a.useMemo(()=>{if(!p||!f||!f.startsWith(p+"/"))return null;const A=f.substring(p.length+1),W=A.indexOf("/");if(W<0)return null;const X=A.substring(0,W);return!X||X.startsWith(".")?null:{name:X,dir:`${p}/${X}`}},[p,f]),V=H==null?void 0:H.dir,[ne,K]=a.useState(null),se=a.useRef(0);a.useEffect(()=>{K(null),se.current=0},[V]),a.useEffect(()=>{if(!V||!n)return;let A=!1;const W=async()=>{try{const Z=await rt(e,t,`${V}/.index.json`,se.current||void 0);if(A)return;if(Z){se.current=Z.mtime;try{const q=JSON.parse(Z.content);K({status:q.status||"draft",phase:q.phase||"",type:q.type||"",completed_steps:q.completed_steps||0,title:q.title||""})}catch{}}}catch{}};W();const X=setInterval(W,3e3);return()=>{A=!0,clearInterval(X)}},[V,n,e,t]);const[we,ye]=a.useState(null);a.useEffect(()=>{ye(null)},[V]),a.useEffect(()=>{if(!V||!n)return;let A=!1;const W=async()=>{try{const Z=await rt(e,t,`${V}/.auto-signal`);if(A)return;if(Z)try{const q=JSON.parse(Z.content);ye({step:q.step,result:q.result,next:q.next,iteration:q.iteration})}catch{ye(null)}}catch{A||ye(null)}};W();const X=setInterval(W,2e3);return()=>{A=!0,clearInterval(X)}},[V,n,e,t]);const De=a.useCallback(()=>{!H||!s||s(`/ai-cli-task:auto AiTasks/${H.name}`)},[H,s]);return o.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[l&&o.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:[o.jsx("span",{style:{color:"var(--accent-yellow)",flex:1},children:"ai-cli-task plugin not installed"}),o.jsx("button",{className:"pane-btn",style:{color:"var(--accent-green)",fontSize:11},onClick:()=>{s&&s("/plugin marketplace add huacheng/moonview && /plugin install ai-cli-task@moonview"),d(!1)},children:"Install"}),o.jsx("button",{className:"pane-btn",style:{fontSize:11},onClick:()=>d(!1),children:"×"})]}),o.jsxs("div",{className:"plan-overlay-body",children:[p&&o.jsxs(o.Fragment,{children:[o.jsx("div",{style:{width:P,flexShrink:0,overflow:"hidden"},children:o.jsx(zs,{sessionId:t,token:e,planDir:p,selectedFile:f,onSelectFile:F,onCreateFile:N,onDeleteFile:O})}),o.jsx("div",{onMouseDown:U,style:{width:2,flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:A=>{A.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:A=>{A.currentTarget.style.backgroundColor="var(--border)"}})]}),o.jsx("div",{className:"plan-overlay-center",children:b?o.jsx(cn,{label:"Loading AiTasks/..."}):k?o.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:12,padding:"0 20px"},children:[o.jsx("span",{style:{color:"var(--text-secondary)",fontSize:14},children:"AiTasks/ directory not found"}),o.jsxs("span",{style:{color:"var(--text-secondary)",fontSize:12,textAlign:"center"},children:["Run ",o.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"]})]}):f&&!h&&(i.state.status==="streaming"||i.state.status==="idle")?o.jsx(cn,{label:`Loading ${f.split("/").pop()}...`,percent:i.state.totalSize>0?Math.round(i.state.receivedBytes/i.state.totalSize*100):void 0}):f?o.jsx(js,{ref:v,markdown:h,filePath:f,sessionId:t,token:e,onExecute:S,onSend:s,onRefresh:Y,onClose:ee,onContentSaved:w,readOnly:f.endsWith("/.index.json")}):o.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:8},children:o.jsx("span",{style:{color:"var(--text-secondary)",fontSize:13,fontStyle:"italic"},children:"Select a file from the left panel"})})})]}),H&&ne&&o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"2px 8px",backgroundColor:"var(--bg-secondary)",borderTop:"1px solid var(--border)",fontSize:11,flexShrink:0,minHeight:22},children:[o.jsx("span",{style:{color:"var(--text-primary)",fontWeight:500},title:ne.title,children:H.name}),o.jsx("span",{style:{color:ne.status==="complete"?"var(--accent-green)":ne.status==="executing"||ne.status==="review"?"var(--accent-blue)":ne.status==="blocked"?"var(--accent-red)":ne.status==="cancelled"?"var(--text-secondary)":"var(--accent-yellow)",fontWeight:500},children:ne.status}),ne.phase&&o.jsxs("span",{style:{color:"var(--text-secondary)"},children:["(",ne.phase,")"]}),we?o.jsxs("span",{style:{color:"var(--accent-yellow)"},children:[we.step,":",we.result," → ",we.next,we.iteration!=null&&` #${we.iteration}`]}):o.jsx("button",{className:"pane-btn",onClick:De,disabled:!n||ne.status==="complete"||ne.status==="cancelled",style:{color:"var(--accent-green)",fontWeight:500,fontSize:11,...!n||ne.status==="complete"||ne.status==="cancelled"?{opacity:.4}:{}},title:"Start auto mode for this task",children:"Auto ▶"}),ne.completed_steps>0&&o.jsxs("span",{style:{color:"var(--text-secondary)",marginLeft:"auto"},children:["step ",ne.completed_steps]})]})]})}async function Fs(t,e){try{return(await ge.get(t,e,"draft")).content??""}catch{return""}}async function dn(t,e,n){try{await ge.put(t,e,"draft",{content:n})}catch{}}const Rt="chat-history",un=50;function zn(){try{const t=localStorage.getItem(Rt);return t?JSON.parse(t):[]}catch{return[]}}function Bs(t){const n=zn().filter(r=>r.text!==t);n.unshift({text:t,ts:Date.now()}),n.length>un&&(n.length=un),localStorage.setItem(Rt,JSON.stringify(n))}const fn=[{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:"/ai-cli-task:ai-cli-task",desc:"Task lifecycle management (13 skills)"},{cmd:"/ai-cli-task:init",desc:"Initialize task module + branch"},{cmd:"/ai-cli-task:plan",desc:"Generate implementation plan"},{cmd:"/ai-cli-task:research",desc:"Collect external references"},{cmd:"/ai-cli-task:check",desc:"Check feasibility (post-plan/mid/post-exec)"},{cmd:"/ai-cli-task:verify",desc:"Run domain-adapted tests"},{cmd:"/ai-cli-task:exec",desc:"Execute implementation plan"},{cmd:"/ai-cli-task:merge",desc:"Merge task branch to main"},{cmd:"/ai-cli-task:report",desc:"Generate completion report"},{cmd:"/ai-cli-task:auto",desc:"Autonomous full lifecycle loop"},{cmd:"/ai-cli-task:cancel",desc:"Cancel task + optional cleanup"},{cmd:"/ai-cli-task:list",desc:"Query task status (read-only)"},{cmd:"/ai-cli-task:annotate",desc:"Process Plan panel annotations"},{cmd:"/ai-cli-task:summarize",desc:"Regenerate context summary"}],Ps=a.forwardRef(function({onSend:e,onContentChange:n,sessionId:r,token:s},i){const l=D(y=>y.fontSize),[d,p]=a.useState(""),c=a.useRef(null),f=a.useRef(void 0),u=a.useRef(!1),h=a.useRef(!1),{pushUndo:g,popUndo:b}=Ct(),j=a.useRef(d);j.current=d;const k=a.useCallback(()=>g(j.current),[g]),[C,v]=a.useState(!1),[I,T]=a.useState(""),[L,z]=a.useState(0),[_,B]=a.useState(!1),[F,O]=a.useState([]),[N,S]=a.useState(0),[w,ee]=a.useState(""),Y=a.useRef(null),P=a.useMemo(()=>{if(!w)return F;const y=w.toLowerCase();return F.filter(E=>E.text.toLowerCase().includes(y))},[F,w]),[G,$]=a.useState(!1),[U,H]=a.useState(""),[V,ne]=a.useState(""),[K,se]=a.useState(0),[we,ye]=a.useState([]),[De,A]=a.useState(!1),W=a.useRef(""),X=a.useRef(null),Z=a.useMemo(()=>{if(!I)return fn;const y=I.toLowerCase();return fn.filter(E=>E.cmd.toLowerCase().includes(y)||E.desc.toLowerCase().includes(y))},[I]),q=a.useMemo(()=>{let y=we;if(U){const E=U.toLowerCase();y=y.filter(J=>J.name.toLowerCase().includes(E))}return[...y].sort((E,J)=>E.type==="directory"&&J.type!=="directory"?-1:E.type!=="directory"&&J.type==="directory"?1:E.name.localeCompare(J.name))},[we,U]),Q=D(y=>y.latency),be=`chat-draft-${r}`,Ee=a.useRef(!1),je=a.useRef(void 0);a.useEffect(()=>{try{const E=localStorage.getItem(be);E&&!h.current&&p(E)}catch{}let y=!1;return Fs(s,r).then(E=>{if(y||h.current){u.current=!0;return}if(E){p(E);try{localStorage.setItem(be,E)}catch{}}u.current=!0}).catch(()=>{u.current=!0}),()=>{y=!0}},[s,r,be]),a.useEffect(()=>{if(!u.current)return;f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{try{localStorage.setItem(be,d)}catch{}},50),je.current&&clearTimeout(je.current);const y=Math.max(200,(Q??30)*3);return je.current=setTimeout(()=>{Ee.current||(Ee.current=!0,dn(s,r,d).catch(()=>{}).finally(()=>{Ee.current=!1}))},y),()=>{f.current&&clearTimeout(f.current),je.current&&clearTimeout(je.current)}},[d,s,r,Q,be]),a.useEffect(()=>{var y;(y=c.current)==null||y.focus()},[]),a.useEffect(()=>{if(!G)return;let y=!1;return A(!0),(async()=>{try{if(V){if(!W.current){const re=await Re(s,r);if(y)return;W.current=re.cwd}const E=`${W.current}/${V.replace(/\/$/,"")}`,J=await Re(s,r,E);if(y)return;ye(J.files)}else{const E=await Re(s,r);if(y)return;W.current=E.cwd,ye(E.files)}A(!1)}catch{if(y)return;ye([]),A(!1)}})(),()=>{y=!0}},[G,V,s,r]),a.useEffect(()=>{if(!G||!X.current)return;const y=X.current.querySelector(".file-item--active");y==null||y.scrollIntoView({block:"nearest"})},[K,G]);const Ae=a.useCallback(()=>{const y=j.current.trim();if(y){Bs(y),e(y),p("");try{localStorage.removeItem(be)}catch{}dn(s,r,"").catch(()=>{})}},[e,s,r,be]),le=a.useCallback(y=>{k(),p(y),h.current=!0},[k]),Se=a.useCallback(y=>{const E=c.current;k();const J=j.current;if(E){const re=E.selectionStart,oe=E.selectionEnd,ke=J.slice(0,re)+y+J.slice(oe);p(ke);const ce=re+y.length;requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=ce,E.focus()})}else p(J+y)},[k]);a.useImperativeHandle(i,()=>({send:Ae,fillContent:le,insertAtCursor:Se}),[Ae,le,Se]),a.useEffect(()=>{n==null||n(d.trim().length>0)},[d,n]);const ue=a.useCallback(()=>{const y=c.current;if(!y)return;const{selectionStart:E,selectionEnd:J}=y;if(E!==J){const re=y.value.substring(E,J);re&&navigator.clipboard.writeText(re).catch(()=>{})}},[]),He=a.useCallback(()=>{const y=zn();v(!1),T("");const E=c.current;if(E){const J=E.selectionStart,re=d.slice(0,J),oe=d.slice(J),ke=re.match(/(?:^|\s)(\/history)\s*$/);if(ke){const ce=re.length-ke[1].length;p(d.slice(0,ce)+oe)}}y.length!==0&&(O(y),S(0),ee(""),B(!0))},[d]),_e=a.useCallback(y=>{k(),p(y.text),B(!1),requestAnimationFrame(()=>{const E=c.current;E&&(E.selectionStart=E.selectionEnd=y.text.length,E.focus())})},[k]),Oe=a.useCallback(y=>{const E=P[y];if(!E)return;const J=F.filter(oe=>oe.ts!==E.ts||oe.text!==E.text);O(J),localStorage.setItem(Rt,JSON.stringify(J));const re=w?J.filter(oe=>oe.text.toLowerCase().includes(w.toLowerCase())):J;N>=re.length&&S(Math.max(0,re.length-1))},[P,F,N,w]);a.useEffect(()=>{if(!_||!Y.current)return;const y=Y.current.querySelector(".history-item--active");y==null||y.scrollIntoView({block:"nearest"})},[N,_]);const Ne=a.useCallback(y=>{if(y==="/history"){He();return}const E=c.current;if(!E)return;k();const J=E.selectionStart,re=d.slice(0,J),oe=d.slice(J),ce=re.lastIndexOf(`
31
31
  `)+1,pe=re.slice(ce).match(/\/[a-zA-Z:-]*$/);if(pe){const de=ce+(pe.index??0),ve=y+" ",Ke=d.slice(0,de)+ve+oe;p(Ke);const Fe=de+ve.length;requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=Fe,E.focus()})}else{const de=re+y+oe;p(de);const ve=J+y.length;requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=ve,E.focus()})}v(!1),T(""),z(0)},[d,k,He]),Le=a.useCallback(y=>{const E=c.current;if(!E)return;k();const J=E.selectionStart,re=d.slice(0,J),oe=d.slice(J),ke=re.match(/@([a-zA-Z0-9_.\-/]*)$/);if(!ke)return;const ce=re.length-ke[0].length;if(y.type==="directory"){const he="@"+V+y.name+"/",pe=d.slice(0,ce)+he+oe;p(pe);const de=ce+he.length;ne(V+y.name+"/"),H(""),se(0),requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=de,E.focus()})}else{const he=y.name+" ",pe=d.slice(0,ce)+he+oe;p(pe);const de=ce+he.length;$(!1),H(""),ne(""),se(0),ye([]),W.current="",requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=de,E.focus()})}},[d,V,k]),Ye=a.useCallback(y=>{const E=y.target.value;if(p(E),_){const he=E.trim();he?(ee(he),S(0)):ee("");return}const J=y.target.selectionStart,re=E.slice(0,J),oe=re.lastIndexOf(`
32
- `),ce=re.slice(oe+1).match(/(?:^|\s)\/([a-zA-Z:-]*)$/);if(ce)v(!0),T(ce[1]),z(0),$(!1);else{v(!1);const he=re.match(/@([a-zA-Z0-9_.\-/]*)$/);if(he){const pe=he[1],de=pe.lastIndexOf("/"),ve=de>=0?pe.slice(0,de+1):"",Ke=de>=0?pe.slice(de+1):pe;H(Ke),se(0),ne(ve),$(!0)}else $(!1)}},[_]),pt=a.useCallback(y=>{if(C&&Z.length>0){if(y.key==="ArrowDown"){y.preventDefault(),z(E=>(E+1)%Z.length);return}if(y.key==="ArrowUp"){y.preventDefault(),z(E=>(E-1+Z.length)%Z.length);return}if(y.key==="Enter"||y.key==="Tab"){y.preventDefault(),Ne(Z[L].cmd);return}if(y.key==="Escape"){y.preventDefault(),v(!1);return}}if(G&&q.length>0){if(y.key==="ArrowDown"){y.preventDefault(),se(E=>(E+1)%q.length);return}if(y.key==="ArrowUp"){y.preventDefault(),se(E=>(E-1+q.length)%q.length);return}if(y.key==="Tab"||y.key==="Enter"){y.preventDefault(),Le(q[K]);return}if(y.key==="Escape"){y.preventDefault(),$(!1);return}}if(_&&P.length>0){if(y.key==="ArrowDown"){y.preventDefault(),S(E=>(E+1)%P.length);return}if(y.key==="ArrowUp"){y.preventDefault(),S(E=>(E-1+P.length)%P.length);return}if(y.key==="Enter"){y.preventDefault(),_e(P[N]);return}if(y.key==="Delete"||y.key==="Backspace"&&(y.ctrlKey||y.metaKey)){y.preventDefault(),Oe(N);return}if(y.key==="Escape"){y.preventDefault(),B(!1);return}}if(y.key==="Tab"){Et(y,p,g);return}y.key==="Enter"&&(y.ctrlKey||y.metaKey)&&(y.preventDefault(),Ae())},[Ae,C,Z,L,Ne,G,q,K,Le,g,b,_,P,N,_e,Oe]);return o.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[C&&Z.length>0&&o.jsx("div",{className:"slash-dropdown",children:Z.map((y,E)=>o.jsxs("div",{className:`slash-item${E===L?" slash-item--active":""}`,onMouseDown:J=>{J.preventDefault(),Ne(y.cmd)},onMouseEnter:()=>z(E),children:[o.jsx("span",{className:"slash-cmd",children:y.cmd}),o.jsx("span",{className:"slash-desc",children:y.desc})]},y.cmd))}),G&&(De||q.length>0)&&o.jsx("div",{className:"file-dropdown",ref:X,children:De?o.jsx("div",{className:"file-item file-loading",children:"Loading..."}):q.map((y,E)=>o.jsxs("div",{className:`file-item${E===K?" file-item--active":""}`,onMouseDown:J=>{J.preventDefault(),Le(y)},onMouseEnter:()=>se(E),children:[o.jsx("span",{className:"file-icon",children:y.type==="directory"?"📁":"📄"}),o.jsx("span",{className:"file-name",children:y.name})]},y.name))}),_&&o.jsx("div",{className:"history-dropdown",ref:Y,children:P.length===0?o.jsx("div",{className:"history-item history-empty",children:"No history yet"}):P.map((y,E)=>o.jsxs("div",{className:`history-item${E===N?" history-item--active":""}`,onMouseDown:J=>{J.preventDefault(),_e(y)},onMouseEnter:()=>S(E),children:[o.jsx("span",{className:"history-text",children:y.text.length>120?y.text.slice(0,120)+"...":y.text}),o.jsx("span",{className:"history-time",children:new Date(y.ts).toLocaleString()}),o.jsx("button",{className:"history-delete",onMouseDown:J=>{J.preventDefault(),J.stopPropagation(),Oe(E)},title:"Delete (Del key)",children:"×"})]},`${y.ts}-${E}`))}),o.jsx("textarea",{ref:c,className:"md-editor-textarea",value:d,onChange:Ye,onKeyDown:pt,onMouseUp:ue,placeholder:"Type / for commands, @ for files, Ctrl+Enter to send",spellCheck:!1,style:{flex:1,fontSize:`${l}px`}})]})});function Ws({token:t,sessionId:e,onClose:n}){const[r,s]=a.useState([]),[i,l]=a.useState(""),[d,p]=a.useState([]),[c,f]=a.useState(!0),[u,h]=a.useState(!1),g=a.useRef(null);a.useEffect(()=>{let v=!1;return(async()=>{try{const I=await Re(t,e);v||(l(I.cwd),s(I.files))}catch{v||n()}finally{v||f(!1)}})(),()=>{v=!0}},[t,e,n]),a.useEffect(()=>{const v=L=>{L.key==="Escape"&&n()},I=L=>{g.current&&!g.current.contains(L.target)&&n()};document.addEventListener("keydown",v);const T=setTimeout(()=>document.addEventListener("mousedown",I),50);return()=>{document.removeEventListener("keydown",v),document.removeEventListener("mousedown",I),clearTimeout(T)}},[n]);const b=a.useCallback(async v=>{f(!0);try{const I=await Re(t,e,v);p(T=>[...T,i]),l(v),s(I.files)}catch{}finally{f(!1)}},[t,e,i]),j=a.useCallback(async()=>{if(d.length===0)return;const v=d[d.length-1];f(!0);try{const I=await Re(t,e,v);p(T=>T.slice(0,-1)),l(v),s(I.files)}catch{}finally{f(!1)}},[t,e,d]),k=a.useCallback(async v=>{try{await Ds(t,e,v)}catch(I){alert(`Download failed: ${I instanceof Error?I.message:"Unknown error"}`)}},[t,e]),C=a.useCallback(async()=>{h(!0),n();try{await Ms(t,e)}catch(v){alert(`Download failed: ${v instanceof Error?v.message:"Unknown error"}`)}finally{h(!1)}},[t,e,n]);return o.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:[o.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&&o.jsx("button",{className:"pane-btn",onClick:j,disabled:c,style:{fontSize:11,flexShrink:0},title:"Go back",children:".."}),o.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",flex:1},children:i.split("/").slice(-2).join("/")||i}),o.jsx("button",{className:"pane-btn",onClick:n,style:{fontSize:11,flexShrink:0},title:"Close",children:"×"})]}),o.jsx("div",{style:{flex:1,overflowY:"auto",padding:"2px 0"},children:c?o.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12},children:"Loading..."}):r.length===0?o.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12,fontStyle:"italic"},children:"Empty directory"}):r.map(v=>o.jsxs("div",{onClick:()=>{const I=i+"/"+v.name;v.type==="directory"?b(I):k(I)},style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",cursor:"pointer",fontSize:12,color:"var(--text-primary)",transition:"background-color 0.1s"},onMouseEnter:I=>{I.currentTarget.style.backgroundColor="var(--bg-secondary)"},onMouseLeave:I=>{I.currentTarget.style.backgroundColor="transparent"},children:[o.jsx("span",{style:{flexShrink:0,fontSize:13},children:v.type==="directory"?"📁":As(v.name,v.type)}),o.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.name}),v.type==="directory"?o.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:"›"}):v.size!=null?o.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:Dn(v.size)}):null]},v.name))}),o.jsx("div",{style:{borderTop:"1px solid var(--border)",padding:"6px 8px",flexShrink:0,backgroundColor:"var(--bg-secondary)"},children:o.jsx("button",{className:"pane-btn",onClick:C,disabled:u,style:{fontSize:11,color:"var(--accent-blue)",width:"100%",textAlign:"center"},title:"Download entire CWD as tar.gz",children:u?"Downloading...":"Download All (tar.gz)"})})]})}function pn(t,e,{containerRef:n,axis:r,offset:s=0,min:i,max:l,invert:d=!1,bodyClass:p}){const[c,f]=a.useState(()=>{const g=localStorage.getItem(t);if(g){const b=Number(g);if(Number.isFinite(b)&&b>=i&&b<=l)return b}return e}),u=a.useRef(c);if(c!==u.current){u.current=c;try{localStorage.setItem(t,String(Math.round(c)))}catch{}}const h=a.useCallback(g=>{g.preventDefault();const b=n.current;if(!b)return;const j=b.getBoundingClientRect(),k=r==="x"?j.width:j.height-s,C=r==="x"?j.left:j.top+s;document.body.classList.add(p);const v=T=>{let z=((r==="x"?T.clientX:T.clientY)-C)/k*100;d&&(z=100-z),f(Math.min(l,Math.max(i,z)))},I=()=>{document.body.classList.remove(p),document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",I)};document.addEventListener("mousemove",v),document.addEventListener("mouseup",I)},[n,r,s,i,l,d,p]);return[c,h]}const Us=600,We=typeof window<"u"?window.matchMedia(`(max-width: ${Us-1}px)`):null;function Hs(){const[t,e]=a.useState(()=>(We==null?void 0:We.matches)??!1);return a.useEffect(()=>{if(!We)return;const n=r=>e(r.matches);return We.addEventListener("change",n),()=>We.removeEventListener("change",n)},[]),t}const Ks=a.memo(function({terminal:e}){const n=Hs(),r=D($=>$.splitTerminal),s=D($=>$.token),i=D($=>$.toggleChat),l=D($=>$.togglePlan),{chatOpen:d,planOpen:p}=e.panels,c=a.useRef(null),f=a.useRef(null),u=a.useRef(null),h=a.useRef(null),g=a.useRef(null),[b,j]=pn(`plan-width-${e.id}`,50,{containerRef:f,axis:"x",min:20,max:80,bodyClass:"resizing-panes"}),[k,C]=pn(`doc-height-${e.id}`,35,{containerRef:c,axis:"y",offset:24,min:15,max:60,invert:!0,bodyClass:"resizing-panes-v"}),[v,I]=a.useState("");a.useEffect(()=>{if(!s||!e.connected)return;let $=!1;const U=async()=>{try{const V=await ln(s,e.id);$||I(V)}catch{}};U();const H=setInterval(U,5e3);return()=>{$=!0,clearInterval(H)}},[s,e.id,e.connected]);const T=a.useCallback(async $=>{let U;if(s)try{U=await ln(s,e.id)}catch{}r(e.id,$,U)},[s,e.id,r]),[L,z]=a.useState(!1),[_,B]=a.useState(0),[F,O]=a.useState(!1),[N,S]=a.useState(!1),w=async $=>{const U=$.target.files;if(!(!U||U.length===0||!s)){z(!0),B(0);try{await Is(s,e.id,U,H=>{B(H)})}catch(H){alert(`Upload failed: ${H instanceof Error?H.message:"Unknown error"}`)}finally{z(!1),B(0),u.current&&(u.current.value="")}}},ee=a.useRef(void 0),Y=a.useCallback($=>{if(h.current){const U=$.replace(/\r?\n/g," ").trimEnd();h.current.sendInput(U),ee.current=window.setTimeout(()=>{var H;return(H=h.current)==null?void 0:H.sendInput("\r")},50)}},[]);a.useEffect(()=>()=>{ee.current&&clearTimeout(ee.current)},[]);const P=a.useCallback($=>{if(h.current){const U=$.replace(/\r?\n/g," ").trimEnd();h.current.sendInput(U),setTimeout(()=>{var H;return(H=h.current)==null?void 0:H.sendInput("\r")},50)}},[]),G=a.useCallback(()=>S(!1),[]);return o.jsxs("div",{ref:c,style:{display:"flex",flexDirection:"column",height:"100%",minWidth:0,minHeight:0},children:[o.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:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"5px",minWidth:0,flex:1,overflow:"hidden"},children:[o.jsx("span",{style:{display:"inline-block",width:"6px",height:"6px",borderRadius:"50%",backgroundColor:e.connected?"var(--accent-green)":"var(--accent-red)",flexShrink:0}}),o.jsxs("span",{style:{fontSize:"12px",color:"var(--text-secondary)",flexShrink:0},children:[e.id,e.connected?e.sessionResumed?" (resumed)":"":" (disconnected)"]}),v&&o.jsx("span",{style:{fontSize:"11px",color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",minWidth:0},title:v,children:v})]}),o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[o.jsx("input",{ref:u,type:"file",multiple:!0,style:{display:"none"},onChange:w}),o.jsx("button",{className:"pane-btn",onClick:()=>{var $;return($=u.current)==null?void 0:$.click()},disabled:L,style:L?{color:"var(--accent-yellow)"}:void 0,title:L?`Uploading ${_}%`:"Upload files","aria-label":"Upload files",children:L?`${_}%`:"↑"}),o.jsxs("div",{style:{position:"relative"},children:[o.jsx("button",{className:"pane-btn",onClick:()=>S(!0),title:"Download files","aria-label":"Download files",children:"↓"}),N&&s&&o.jsx(Ws,{token:s,sessionId:e.id,onClose:G})]}),o.jsx("button",{className:`pane-btn${d?" pane-btn--active":""}`,onClick:()=>i(e.id),title:"Toggle Chat panel","aria-label":"Toggle Chat panel",children:"Chat"}),o.jsx("button",{className:`pane-btn${p?" pane-btn--active":""}`,onClick:()=>l(e.id),title:"Toggle Task annotation panel","aria-label":"Toggle Task annotation panel",children:"Task"}),o.jsx("button",{className:"pane-btn",onClick:()=>T(n?"vertical":"horizontal"),title:n?"Split vertical (screen too narrow for horizontal)":"Split horizontal (left/right)","aria-label":"Split horizontal",children:"|"}),o.jsx("button",{className:"pane-btn",onClick:()=>T("vertical"),title:"Split vertical (top/bottom)","aria-label":"Split vertical",children:"─"})]})]}),o.jsxs("div",{ref:f,style:{flex:1,display:"flex",flexDirection:"row",overflow:"hidden",minHeight:0},children:[p&&o.jsxs(o.Fragment,{children:[o.jsx("div",{style:{width:`${b}%`,minWidth:200,flexShrink:0,overflow:"hidden"},children:o.jsx(Os,{sessionId:e.id,token:s||"",connected:e.connected,onRequestFileStream:$=>{var U;return(U=h.current)==null?void 0:U.requestFileStream($)},onSendToTerminal:P})}),o.jsx("div",{className:"md-editor-divider-h",onMouseDown:j,style:{width:"3px",flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:$=>{$.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:$=>{$.currentTarget.style.backgroundColor="var(--border)"}})]}),o.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[o.jsxs("div",{style:{flex:1,overflow:"hidden",position:"relative",minWidth:80},children:[o.jsx(os,{ref:h,sessionId:e.id}),!e.connected&&o.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"var(--bg-secondary)",opacity:.85,zIndex:2,pointerEvents:"none"},children:o.jsx("span",{style:{color:"var(--text-secondary)",fontSize:"13px",fontStyle:"italic"},children:"Connecting..."})})]}),d&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"md-editor-divider",onMouseDown:C}),o.jsxs("div",{style:{height:`${k}%`,minHeight:80,flexShrink:0,overflow:"hidden",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[o.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:o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[o.jsx("span",{style:{fontSize:"11px",color:"var(--accent-blue)",fontWeight:500},children:"Chat"}),o.jsx("button",{className:"pane-btn",onClick:()=>{var $;return($=g.current)==null?void 0:$.send()},disabled:!F,title:"Send to terminal (Ctrl+Enter)",style:F?{color:"var(--accent-green)"}:{opacity:.4,cursor:"default"},children:"Send"}),o.jsx("span",{style:{fontSize:"9px",color:"var(--text-secondary)"},children:"Ctrl+Enter"})]})}),o.jsx("div",{style:{flex:1,overflow:"hidden"},children:o.jsx(Ps,{ref:g,onSend:Y,onContentChange:O,sessionId:e.id,token:s||""})})]})]})]})]}),e.error&&o.jsx("div",{style:{padding:"2px 8px",backgroundColor:"var(--bg-secondary)",borderTop:"1px solid var(--accent-red)",color:"var(--accent-red)",fontSize:"11px",flexShrink:0},children:e.error})]})});class $n extends a.Component{constructor(){super(...arguments);$t(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?o.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:[o.jsx("div",{style:{fontSize:"14px",color:"var(--accent-red)"},children:"Pane crashed"}),o.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"}),o.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"})]}):o.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:[o.jsx("div",{style:{fontSize:"18px",color:"var(--accent-red)"},children:"Something went wrong"}),o.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"}),o.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 Js=4,mn=10;function Vs(){const t=D(s=>s.layout),e=D(s=>s.terminalIds.length),n=D(s=>s.addTerminal);if(!t)return o.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)"},children:o.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=e>1;return o.jsx("div",{style:{height:"100%",width:"100%",overflow:"hidden"},children:o.jsx(_n,{node:t,canClose:r})})}const _n=a.memo(function({node:e,canClose:n}){return e.type==="leaf"?o.jsx(Gs,{terminalId:e.terminalId,canClose:n}):o.jsx(qs,{node:e,canClose:n})}),Gs=a.memo(function({terminalId:e,canClose:n}){const r=D(i=>i.terminalsMap[e]),s=D(i=>i.reconnectTerminal);return r?o.jsx($n,{inline:!0,children:o.jsx(Ks,{terminal:r,canClose:n})}):o.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)",border:"1px dashed var(--border)"},children:o.jsxs("button",{onClick:()=>s(e),style:{background:"none",border:"1px solid var(--accent-blue)",color:"var(--accent-blue)",padding:"8px 16px",borderRadius:"6px",cursor:"pointer",fontSize:"13px"},children:["↻ Reconnect ",e]})})}),qs=a.memo(function({node:e,canClose:n}){const r=D(c=>c.setSplitSizes),s=a.useRef(null),i=e.direction==="horizontal",l=a.useRef(e.sizes);l.current=e.sizes;const d=a.useCallback((c,f)=>{f.preventDefault();const u=i?"resizing-panes":"resizing-panes-v";document.body.classList.add(u);const h=i?f.clientX:f.clientY,g=[...l.current],b=s.current,j=i?(b==null?void 0:b.clientWidth)||1:(b==null?void 0:b.clientHeight)||1;let k=null;const C=I=>{k||(k=requestAnimationFrame(()=>{k=null;const z=((i?I.clientX:I.clientY)-h)/j*100,_=g[c]+z,B=g[c+1]-z;if(_>=mn&&B>=mn){const F=[...g];F[c]=_,F[c+1]=B,r(e.id,F)}}))},v=()=>{k&&cancelAnimationFrame(k),document.body.classList.remove(u),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",v)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",v)},[i,e.id,r]),p=[];return e.children.forEach((c,f)=>{const u=c.type==="leaf"?c.terminalId:c.id;p.push(o.jsx("div",{style:{flex:`${e.sizes[f]} 0 0`,minWidth:0,minHeight:0,overflow:"hidden"},children:o.jsx(_n,{node:c,canClose:n})},u)),f<e.children.length-1&&p.push(o.jsx("div",{onMouseDown:h=>d(f,h),style:{flex:`0 0 ${Js}px`,cursor:i?"col-resize":"row-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:h=>{h.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="var(--border)"}},`divider-${e.id}-${f}`))}),o.jsx("div",{ref:s,style:{display:"flex",flexDirection:i?"row":"column",height:"100%",width:"100%",overflow:"hidden"},children:p})});function Ys({tabId:t}){const e=D(S=>S.tabs.find(w=>w.id===t)),n=D(S=>S.activeTabId),r=D(S=>S.switchTab),s=D(S=>S.closeTab),i=D(S=>S.reopenTab),l=D(S=>S.deleteTab),d=D(S=>S.renameTab),p=D(S=>e?e.terminalIds.map(w=>{const ee=S.terminalsMap[w];return ee?{id:w,connected:ee.connected,active:!0}:{id:w,connected:!1,active:!1}}):[]),c=D(S=>S.disconnectTerminal),f=D(S=>S.reconnectTerminal),u=D(S=>S.killServerSession),[h,g]=a.useState(!1),[b,j]=a.useState(""),[k,C]=a.useState(!1),v=a.useRef(null);if(!e)return null;const I=n===t,T=e.status==="open",L=()=>{T&&r(t)},z=S=>{T&&(S.stopPropagation(),j(e.name),g(!0),setTimeout(()=>{var w;return(w=v.current)==null?void 0:w.focus()},0))},_=()=>{const S=b.trim();S&&d(t,S),g(!1)},B=S=>{S.stopPropagation(),i(t)},F=S=>{S.stopPropagation(),s(t)},O=async S=>{S.stopPropagation(),window.confirm(`Delete tab "${e.name}"? This will kill all tmux sessions in this tab.`)&&await l(t)},N=S=>{S.stopPropagation(),C(!k)};return o.jsxs("div",{children:[o.jsxs("div",{onClick:L,style:{padding:"8px 12px",cursor:T?"pointer":"default",borderLeft:I?"3px solid var(--accent-blue)":"3px solid transparent",backgroundColor:I?"rgba(122, 162, 247, 0.08)":"transparent",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s",opacity:T?1:.5},onMouseEnter:S=>{T&&!I&&(S.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)")},onMouseLeave:S=>{I||(S.currentTarget.style.backgroundColor="transparent")},children:[T&&e.terminalIds.length>0&&o.jsx("button",{onClick:N,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:k?"▼":"▶"}),o.jsxs("div",{style:{flex:1,minWidth:0},children:[h?o.jsx("input",{ref:v,value:b,onChange:S=>j(S.target.value),onBlur:_,onKeyDown:S=>{S.key==="Enter"&&_(),S.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"}}):o.jsx("div",{onDoubleClick:z,style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:T?"Double-click to rename":e.name,children:e.name}),o.jsxs("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:[e.terminalIds.length," terminal",e.terminalIds.length!==1?"s":""," · ",An(Math.floor(e.createdAt/1e3))]})]}),T?o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:F,style:{flexShrink:0},title:"Close tab",children:"×"}):o.jsxs("div",{style:{display:"flex",gap:"4px",flexShrink:0},children:[o.jsx("button",{className:"pane-btn",onClick:B,title:"Reopen tab",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:O,title:"Delete tab",children:"×"})]})]}),T&&k&&p.length>0&&o.jsx("div",{style:{paddingLeft:"28px",backgroundColor:"rgba(0, 0, 0, 0.2)"},children:p.map(S=>o.jsxs("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--text-secondary)",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center"},title:`Connected: ${S.connected}`,children:[o.jsx("span",{style:{fontFamily:"monospace"},children:S.id}),o.jsx("span",{style:{marginLeft:"8px",color:S.active?S.connected?"var(--accent-green)":"var(--accent-yellow)":"var(--text-secondary)"},children:S.active?S.connected?"●":"◐":"○"}),S.active?o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:w=>{w.stopPropagation(),c(S.id)},style:{marginLeft:"auto",flexShrink:0},title:"Disconnect terminal (keeps session alive)",children:"×"}):o.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:"4px",flexShrink:0},children:[o.jsx("button",{className:"pane-btn",onClick:w=>{w.stopPropagation(),f(S.id)},title:"Reconnect terminal",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:w=>{w.stopPropagation(),window.confirm(`Kill terminal "${S.id}"? This will destroy the tmux session.`)&&u(S.id)},title:"Kill session",children:"×"})]})]},S.id))})]})}function Xs({sessionId:t,active:e,createdAt:n}){const r=D(d=>d.addTerminal),s=D(d=>d.killServerSession),i=()=>{r("horizontal",t)},l=d=>{d.stopPropagation(),window.confirm(`Delete orphaned session "${t}"? This will kill the tmux session.`)&&s(t)};return o.jsxs("div",{onClick:i,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:[o.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:e?"var(--accent-green)":"var(--text-secondary)",flexShrink:0}}),o.jsxs("div",{style:{flex:1,minWidth:0},children:[o.jsx("div",{style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}),o.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:An(n)})]}),o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:l,style:{flexShrink:0},title:"Delete session",children:"×"})]})}function Zs(){const t=D(c=>c.sidebarOpen),e=D(c=>c.toggleSidebar),n=D(c=>c.fetchSessions),r=D(c=>t?c.serverSessions:[]),s=D(c=>t?c.tabs:[]),i=D(c=>c.terminalIds.length),l=D(c=>c.tabsLoading),d=new Set(s.flatMap(c=>c.terminalIds)),p=r.filter(c=>!d.has(c.sessionId));return a.useEffect(()=>{if(!t)return;n();let c=setInterval(n,5e3);const f=()=>{document.hidden?c&&(clearInterval(c),c=null):(n(),c||(c=setInterval(n,5e3)))};return document.addEventListener("visibilitychange",f),()=>{c&&clearInterval(c),document.removeEventListener("visibilitychange",f)}},[t,n]),a.useEffect(()=>{if(!t)return;const c=setTimeout(n,800);return()=>clearTimeout(c)},[i,t,n]),o.jsxs("div",{className:"session-sidebar",style:{width:t?280:0,height:"100%",backgroundColor:"var(--bg-secondary)",borderLeft:t?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,overflow:"hidden",transition:"width 0.2s ease"},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[o.jsx("span",{style:{color:"var(--accent-blue)",fontSize:"14px",fontWeight:"bold"},children:"Tabs & Terminals"}),o.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"16px",padding:"0 4px",lineHeight:1},title:"Close sidebar",children:"×"})]}),o.jsxs("div",{style:{flex:1,overflowY:"auto"},children:[o.jsxs("div",{children:[o.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"}),s.length===0?o.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"14px",textAlign:"center",padding:"12px"},children:"No tabs"}):s.map(c=>o.jsx(Ys,{tabId:c.id},c.id))]}),!l&&p.length>0&&o.jsxs("div",{style:{marginTop:"16px"},children:[o.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(c=>o.jsx(Xs,{sessionId:c.sessionId,active:c.active,createdAt:c.createdAt},c.sessionId))]})]})]})}const On=It.memo(()=>{const t=D(T=>T.tabs),e=D(T=>T.activeTabId),n=D(T=>T.addTab),r=D(T=>T.switchTab),s=D(T=>T.closeTab),i=D(T=>T.renameTab),[l,d]=a.useState(null),[p,c]=a.useState(""),f=a.useRef(null),u=t.filter(T=>T.status==="open");a.useEffect(()=>{l&&f.current&&(f.current.focus(),f.current.select())},[l]);const h=T=>{d(T.id),c(T.name)},g=()=>{l&&p.trim()&&i(l,p.trim()),d(null),c("")},b=()=>{d(null),c("")},j=T=>{T.key==="Enter"?g():T.key==="Escape"&&b()},k=T=>{l||r(T)},C=(T,L)=>{T.stopPropagation(),s(L)},v=(T,L)=>{T.button===1&&(T.preventDefault(),s(L))},I=u.length>1;return o.jsxs("div",{className:"tab-bar",children:[u.map(T=>{const L=T.id===e,z=l===T.id,_=T.terminalIds.length;return o.jsx("div",{className:`tab-item ${L?"tab-item--active":""}`,onClick:()=>k(T.id),onDoubleClick:()=>h(T),onMouseDown:B=>v(B,T.id),children:z?o.jsx("input",{ref:f,type:"text",value:p,onChange:B=>c(B.target.value),onBlur:g,onKeyDown:j,className:"tab-item__rename-input"}):o.jsxs(o.Fragment,{children:[o.jsxs("span",{className:"tab-item__name",children:[T.name," ",_>0&&`(${_})`]}),I&&o.jsx("button",{className:"tab-item__close",onClick:B=>C(B,T.id),title:"Close tab","aria-label":"Close tab",children:"×"})]})},T.id)}),o.jsx("button",{className:"tab-bar-add",onClick:()=>n(),title:"New tab","aria-label":"Add new tab",children:"+"})]})});On.displayName="TabBar";function Qs(){return localStorage.getItem("ai-cli-online-token")}function ea(){const t=D(f=>f.token),e=D(f=>f.setToken),n=D(f=>f.tabs),r=D(f=>f.addTab),s=D(f=>f.toggleSidebar),i=D(f=>f.fontSize),l=D(f=>f.setFontSize),d=D(f=>f.tabsLoading),p=D(f=>f.theme),c=D(f=>f.toggleTheme);return a.useEffect(()=>{const f=Qs();f&&!t&&e(f)},[]),a.useEffect(()=>{t&&!d&&n.filter(f=>f.status==="open").length===0&&r("Default")},[t,d]),t?o.jsxs("div",{style:{height:"100vh",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[o.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:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[o.jsx("span",{style:{fontSize:"15px",fontWeight:"bold",color:"var(--accent-blue)",letterSpacing:"0.5px"},children:"AI-Cli Online"}),o.jsxs("span",{style:{fontSize:"11px",color:"var(--text-secondary)",fontWeight:400},children:["v","3.0.11"]})]}),o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[o.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"1px 4px",borderRadius:"6px",backgroundColor:"rgba(0,0,0,0.2)"},children:[o.jsx("button",{className:"header-btn",onClick:()=>l(i-1),disabled:i<=10,title:"Decrease font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A−"}),o.jsx("span",{style:{fontSize:"11px",color:"var(--text-primary)",minWidth:"20px",textAlign:"center"},children:i}),o.jsx("button",{className:"header-btn",onClick:()=>l(i+1),disabled:i>=24,title:"Increase font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A+"})]}),o.jsx(na,{}),o.jsx("button",{className:"header-btn",onClick:c,title:`Switch to ${p==="dark"?"light":"dark"} mode`,"aria-label":"Toggle theme",children:p==="dark"?"☀":"🌙"}),o.jsx("button",{className:"header-btn",onClick:s,title:"Toggle Tabs & Terminals Sidebar","aria-label":"Toggle sidebar",children:"☰"}),o.jsx("button",{className:"header-btn header-btn--muted",onClick:()=>{window.confirm("Logout will close all terminals. Continue?")&&e(null)},children:"Logout"})]})]}),o.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[o.jsx("main",{style:{flex:1,overflow:"hidden"},children:o.jsx(Vs,{})}),o.jsx(Zs,{})]}),o.jsx(On,{})]}):o.jsx(Pr,{})}const ta=[1,2,3,4];function na(){const t=D(r=>r.latency);if(t===null)return o.jsx("span",{style:{fontSize:"10px",color:"var(--scrollbar-thumb-hover)"},title:"Measuring latency...",children:"--ms"});let e,n;return t<50?(e="var(--accent-green)",n=4):t<150?(e="var(--accent-yellow)",n=3):t<300?(e="var(--accent-orange)",n=2):(e="var(--accent-red)",n=1),o.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: ${t}ms`,children:[ta.map(r=>o.jsx("span",{style:{display:"inline-block",width:"2.5px",height:`${3+r*2}px`,backgroundColor:r<=n?e:"var(--border)",borderRadius:"1px",transition:"background-color 0.3s ease"}},r)),o.jsxs("span",{style:{fontSize:"10px",color:e,marginLeft:"4px",fontWeight:500},children:[t,"ms"]})]})}kt.createRoot(document.getElementById("root")).render(o.jsx(It.StrictMode,{children:o.jsx($n,{children:o.jsx(ea,{})})}));
32
+ `),ce=re.slice(oe+1).match(/(?:^|\s)\/([a-zA-Z:-]*)$/);if(ce)v(!0),T(ce[1]),z(0),$(!1);else{v(!1);const he=re.match(/@([a-zA-Z0-9_.\-/]*)$/);if(he){const pe=he[1],de=pe.lastIndexOf("/"),ve=de>=0?pe.slice(0,de+1):"",Ke=de>=0?pe.slice(de+1):pe;H(Ke),se(0),ne(ve),$(!0)}else $(!1)}},[_]),pt=a.useCallback(y=>{if(C&&Z.length>0){if(y.key==="ArrowDown"){y.preventDefault(),z(E=>(E+1)%Z.length);return}if(y.key==="ArrowUp"){y.preventDefault(),z(E=>(E-1+Z.length)%Z.length);return}if(y.key==="Enter"||y.key==="Tab"){y.preventDefault(),Ne(Z[L].cmd);return}if(y.key==="Escape"){y.preventDefault(),v(!1);return}}if(G&&q.length>0){if(y.key==="ArrowDown"){y.preventDefault(),se(E=>(E+1)%q.length);return}if(y.key==="ArrowUp"){y.preventDefault(),se(E=>(E-1+q.length)%q.length);return}if(y.key==="Tab"||y.key==="Enter"){y.preventDefault(),Le(q[K]);return}if(y.key==="Escape"){y.preventDefault(),$(!1);return}}if(_&&P.length>0){if(y.key==="ArrowDown"){y.preventDefault(),S(E=>(E+1)%P.length);return}if(y.key==="ArrowUp"){y.preventDefault(),S(E=>(E-1+P.length)%P.length);return}if(y.key==="Enter"){y.preventDefault(),_e(P[N]);return}if(y.key==="Delete"||y.key==="Backspace"&&(y.ctrlKey||y.metaKey)){y.preventDefault(),Oe(N);return}if(y.key==="Escape"){y.preventDefault(),B(!1);return}}if(y.key==="Tab"){Et(y,p,g);return}y.key==="Enter"&&(y.ctrlKey||y.metaKey)&&(y.preventDefault(),Ae())},[Ae,C,Z,L,Ne,G,q,K,Le,g,b,_,P,N,_e,Oe]);return o.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[C&&Z.length>0&&o.jsx("div",{className:"slash-dropdown",children:Z.map((y,E)=>o.jsxs("div",{className:`slash-item${E===L?" slash-item--active":""}`,onMouseDown:J=>{J.preventDefault(),Ne(y.cmd)},onMouseEnter:()=>z(E),children:[o.jsx("span",{className:"slash-cmd",children:y.cmd}),o.jsx("span",{className:"slash-desc",children:y.desc})]},y.cmd))}),G&&(De||q.length>0)&&o.jsx("div",{className:"file-dropdown",ref:X,children:De?o.jsx("div",{className:"file-item file-loading",children:"Loading..."}):q.map((y,E)=>o.jsxs("div",{className:`file-item${E===K?" file-item--active":""}`,onMouseDown:J=>{J.preventDefault(),Le(y)},onMouseEnter:()=>se(E),children:[o.jsx("span",{className:"file-icon",children:y.type==="directory"?"📁":"📄"}),o.jsx("span",{className:"file-name",children:y.name})]},y.name))}),_&&o.jsx("div",{className:"history-dropdown",ref:Y,children:P.length===0?o.jsx("div",{className:"history-item history-empty",children:"No history yet"}):P.map((y,E)=>o.jsxs("div",{className:`history-item${E===N?" history-item--active":""}`,onMouseDown:J=>{J.preventDefault(),_e(y)},onMouseEnter:()=>S(E),children:[o.jsx("span",{className:"history-text",children:y.text.length>120?y.text.slice(0,120)+"...":y.text}),o.jsx("span",{className:"history-time",children:new Date(y.ts).toLocaleString()}),o.jsx("button",{className:"history-delete",onMouseDown:J=>{J.preventDefault(),J.stopPropagation(),Oe(E)},title:"Delete (Del key)",children:"×"})]},`${y.ts}-${E}`))}),o.jsx("textarea",{ref:c,className:"md-editor-textarea",value:d,onChange:Ye,onKeyDown:pt,onMouseUp:ue,placeholder:"Type / for commands, @ for files, Ctrl+Enter to send",spellCheck:!1,style:{flex:1,fontSize:`${l}px`}})]})});function Ws({token:t,sessionId:e,onClose:n}){const[r,s]=a.useState([]),[i,l]=a.useState(""),[d,p]=a.useState([]),[c,f]=a.useState(!0),[u,h]=a.useState(!1),g=a.useRef(null);a.useEffect(()=>{let v=!1;return(async()=>{try{const I=await Re(t,e);v||(l(I.cwd),s(I.files))}catch{v||n()}finally{v||f(!1)}})(),()=>{v=!0}},[t,e,n]),a.useEffect(()=>{const v=L=>{L.key==="Escape"&&n()},I=L=>{g.current&&!g.current.contains(L.target)&&n()};document.addEventListener("keydown",v);const T=setTimeout(()=>document.addEventListener("mousedown",I),50);return()=>{document.removeEventListener("keydown",v),document.removeEventListener("mousedown",I),clearTimeout(T)}},[n]);const b=a.useCallback(async v=>{f(!0);try{const I=await Re(t,e,v);p(T=>[...T,i]),l(v),s(I.files)}catch{}finally{f(!1)}},[t,e,i]),j=a.useCallback(async()=>{if(d.length===0)return;const v=d[d.length-1];f(!0);try{const I=await Re(t,e,v);p(T=>T.slice(0,-1)),l(v),s(I.files)}catch{}finally{f(!1)}},[t,e,d]),k=a.useCallback(async v=>{try{await Ds(t,e,v)}catch(I){alert(`Download failed: ${I instanceof Error?I.message:"Unknown error"}`)}},[t,e]),C=a.useCallback(async()=>{h(!0),n();try{await Ms(t,e)}catch(v){alert(`Download failed: ${v instanceof Error?v.message:"Unknown error"}`)}finally{h(!1)}},[t,e,n]);return o.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:[o.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&&o.jsx("button",{className:"pane-btn",onClick:j,disabled:c,style:{fontSize:11,flexShrink:0},title:"Go back",children:".."}),o.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",flex:1},children:i.split("/").slice(-2).join("/")||i}),o.jsx("button",{className:"pane-btn",onClick:n,style:{fontSize:11,flexShrink:0},title:"Close",children:"×"})]}),o.jsx("div",{style:{flex:1,overflowY:"auto",padding:"2px 0"},children:c?o.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12},children:"Loading..."}):r.length===0?o.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12,fontStyle:"italic"},children:"Empty directory"}):r.map(v=>o.jsxs("div",{onClick:()=>{const I=i+"/"+v.name;v.type==="directory"?b(I):k(I)},style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",cursor:"pointer",fontSize:12,color:"var(--text-primary)",transition:"background-color 0.1s"},onMouseEnter:I=>{I.currentTarget.style.backgroundColor="var(--bg-secondary)"},onMouseLeave:I=>{I.currentTarget.style.backgroundColor="transparent"},children:[o.jsx("span",{style:{flexShrink:0,fontSize:13},children:v.type==="directory"?"📁":As(v.name,v.type)}),o.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.name}),v.type==="directory"?o.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:"›"}):v.size!=null?o.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:Dn(v.size)}):null]},v.name))}),o.jsx("div",{style:{borderTop:"1px solid var(--border)",padding:"6px 8px",flexShrink:0,backgroundColor:"var(--bg-secondary)"},children:o.jsx("button",{className:"pane-btn",onClick:C,disabled:u,style:{fontSize:11,color:"var(--accent-blue)",width:"100%",textAlign:"center"},title:"Download entire CWD as tar.gz",children:u?"Downloading...":"Download All (tar.gz)"})})]})}function pn(t,e,{containerRef:n,axis:r,offset:s=0,min:i,max:l,invert:d=!1,bodyClass:p}){const[c,f]=a.useState(()=>{const g=localStorage.getItem(t);if(g){const b=Number(g);if(Number.isFinite(b)&&b>=i&&b<=l)return b}return e}),u=a.useRef(c);if(c!==u.current){u.current=c;try{localStorage.setItem(t,String(Math.round(c)))}catch{}}const h=a.useCallback(g=>{g.preventDefault();const b=n.current;if(!b)return;const j=b.getBoundingClientRect(),k=r==="x"?j.width:j.height-s,C=r==="x"?j.left:j.top+s;document.body.classList.add(p);const v=T=>{let z=((r==="x"?T.clientX:T.clientY)-C)/k*100;d&&(z=100-z),f(Math.min(l,Math.max(i,z)))},I=()=>{document.body.classList.remove(p),document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",I)};document.addEventListener("mousemove",v),document.addEventListener("mouseup",I)},[n,r,s,i,l,d,p]);return[c,h]}const Us=600,We=typeof window<"u"?window.matchMedia(`(max-width: ${Us-1}px)`):null;function Hs(){const[t,e]=a.useState(()=>(We==null?void 0:We.matches)??!1);return a.useEffect(()=>{if(!We)return;const n=r=>e(r.matches);return We.addEventListener("change",n),()=>We.removeEventListener("change",n)},[]),t}const Ks=a.memo(function({terminal:e}){const n=Hs(),r=D($=>$.splitTerminal),s=D($=>$.token),i=D($=>$.toggleChat),l=D($=>$.togglePlan),{chatOpen:d,planOpen:p}=e.panels,c=a.useRef(null),f=a.useRef(null),u=a.useRef(null),h=a.useRef(null),g=a.useRef(null),[b,j]=pn(`plan-width-${e.id}`,50,{containerRef:f,axis:"x",min:20,max:80,bodyClass:"resizing-panes"}),[k,C]=pn(`doc-height-${e.id}`,35,{containerRef:c,axis:"y",offset:24,min:15,max:60,invert:!0,bodyClass:"resizing-panes-v"}),[v,I]=a.useState("");a.useEffect(()=>{if(!s||!e.connected)return;let $=!1;const U=async()=>{try{const V=await ln(s,e.id);$||I(V)}catch{}};U();const H=setInterval(U,5e3);return()=>{$=!0,clearInterval(H)}},[s,e.id,e.connected]);const T=a.useCallback(async $=>{let U;if(s)try{U=await ln(s,e.id)}catch{}r(e.id,$,U)},[s,e.id,r]),[L,z]=a.useState(!1),[_,B]=a.useState(0),[F,O]=a.useState(!1),[N,S]=a.useState(!1),w=async $=>{const U=$.target.files;if(!(!U||U.length===0||!s)){z(!0),B(0);try{await Is(s,e.id,U,H=>{B(H)})}catch(H){alert(`Upload failed: ${H instanceof Error?H.message:"Unknown error"}`)}finally{z(!1),B(0),u.current&&(u.current.value="")}}},ee=a.useRef(void 0),Y=a.useCallback($=>{if(h.current){const U=$.replace(/\r?\n/g," ").trimEnd();h.current.sendInput(U),ee.current=window.setTimeout(()=>{var H;return(H=h.current)==null?void 0:H.sendInput("\r")},50)}},[]);a.useEffect(()=>()=>{ee.current&&clearTimeout(ee.current)},[]);const P=a.useCallback($=>{if(h.current){const U=$.replace(/\r?\n/g," ").trimEnd();h.current.sendInput(U),setTimeout(()=>{var H;return(H=h.current)==null?void 0:H.sendInput("\r")},50)}},[]),G=a.useCallback(()=>S(!1),[]);return o.jsxs("div",{ref:c,style:{display:"flex",flexDirection:"column",height:"100%",minWidth:0,minHeight:0},children:[o.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:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"5px",minWidth:0,flex:1,overflow:"hidden"},children:[o.jsx("span",{style:{display:"inline-block",width:"6px",height:"6px",borderRadius:"50%",backgroundColor:e.connected?"var(--accent-green)":"var(--accent-red)",flexShrink:0}}),o.jsxs("span",{style:{fontSize:"12px",color:"var(--text-secondary)",flexShrink:0},children:[e.id,e.connected?e.sessionResumed?" (resumed)":"":" (disconnected)"]}),v&&o.jsx("span",{style:{fontSize:"11px",color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",minWidth:0},title:v,children:v})]}),o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[o.jsx("input",{ref:u,type:"file",multiple:!0,style:{display:"none"},onChange:w}),o.jsx("button",{className:"pane-btn",onClick:()=>{var $;return($=u.current)==null?void 0:$.click()},disabled:L,style:L?{color:"var(--accent-yellow)"}:void 0,title:L?`Uploading ${_}%`:"Upload files","aria-label":"Upload files",children:L?`${_}%`:"↑"}),o.jsxs("div",{style:{position:"relative"},children:[o.jsx("button",{className:"pane-btn",onClick:()=>S(!0),title:"Download files","aria-label":"Download files",children:"↓"}),N&&s&&o.jsx(Ws,{token:s,sessionId:e.id,onClose:G})]}),o.jsx("button",{className:`pane-btn${d?" pane-btn--active":""}`,onClick:()=>i(e.id),title:"Toggle Chat panel","aria-label":"Toggle Chat panel",children:"Chat"}),o.jsx("button",{className:`pane-btn${p?" pane-btn--active":""}`,onClick:()=>l(e.id),title:"Toggle Task annotation panel","aria-label":"Toggle Task annotation panel",children:"Task"}),o.jsx("button",{className:"pane-btn",onClick:()=>T(n?"vertical":"horizontal"),title:n?"Split vertical (screen too narrow for horizontal)":"Split horizontal (left/right)","aria-label":"Split horizontal",children:"|"}),o.jsx("button",{className:"pane-btn",onClick:()=>T("vertical"),title:"Split vertical (top/bottom)","aria-label":"Split vertical",children:"─"})]})]}),o.jsxs("div",{ref:f,style:{flex:1,display:"flex",flexDirection:"row",overflow:"hidden",minHeight:0},children:[p&&o.jsxs(o.Fragment,{children:[o.jsx("div",{style:{width:`${b}%`,minWidth:200,flexShrink:0,overflow:"hidden"},children:o.jsx(Os,{sessionId:e.id,token:s||"",connected:e.connected,onRequestFileStream:$=>{var U;return(U=h.current)==null?void 0:U.requestFileStream($)},onSendToTerminal:P})}),o.jsx("div",{className:"md-editor-divider-h",onMouseDown:j,style:{width:"3px",flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:$=>{$.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:$=>{$.currentTarget.style.backgroundColor="var(--border)"}})]}),o.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[o.jsxs("div",{style:{flex:1,overflow:"hidden",position:"relative",minWidth:80},children:[o.jsx(os,{ref:h,sessionId:e.id}),!e.connected&&o.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"var(--bg-secondary)",opacity:.85,zIndex:2,pointerEvents:"none"},children:o.jsx("span",{style:{color:"var(--text-secondary)",fontSize:"13px",fontStyle:"italic"},children:"Connecting..."})})]}),d&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"md-editor-divider",onMouseDown:C}),o.jsxs("div",{style:{height:`${k}%`,minHeight:80,flexShrink:0,overflow:"hidden",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[o.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:o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[o.jsx("span",{style:{fontSize:"11px",color:"var(--accent-blue)",fontWeight:500},children:"Chat"}),o.jsx("button",{className:"pane-btn",onClick:()=>{var $;return($=g.current)==null?void 0:$.send()},disabled:!F,title:"Send to terminal (Ctrl+Enter)",style:F?{color:"var(--accent-green)"}:{opacity:.4,cursor:"default"},children:"Send"}),o.jsx("span",{style:{fontSize:"9px",color:"var(--text-secondary)"},children:"Ctrl+Enter"})]})}),o.jsx("div",{style:{flex:1,overflow:"hidden"},children:o.jsx(Ps,{ref:g,onSend:Y,onContentChange:O,sessionId:e.id,token:s||""})})]})]})]})]}),e.error&&o.jsx("div",{style:{padding:"2px 8px",backgroundColor:"var(--bg-secondary)",borderTop:"1px solid var(--accent-red)",color:"var(--accent-red)",fontSize:"11px",flexShrink:0},children:e.error})]})});class $n extends a.Component{constructor(){super(...arguments);$t(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?o.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:[o.jsx("div",{style:{fontSize:"14px",color:"var(--accent-red)"},children:"Pane crashed"}),o.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"}),o.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"})]}):o.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:[o.jsx("div",{style:{fontSize:"18px",color:"var(--accent-red)"},children:"Something went wrong"}),o.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"}),o.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 Js=4,mn=10;function Vs(){const t=D(s=>s.layout),e=D(s=>s.terminalIds.length),n=D(s=>s.addTerminal);if(!t)return o.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)"},children:o.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=e>1;return o.jsx("div",{style:{height:"100%",width:"100%",overflow:"hidden"},children:o.jsx(_n,{node:t,canClose:r})})}const _n=a.memo(function({node:e,canClose:n}){return e.type==="leaf"?o.jsx(Gs,{terminalId:e.terminalId,canClose:n}):o.jsx(qs,{node:e,canClose:n})}),Gs=a.memo(function({terminalId:e,canClose:n}){const r=D(i=>i.terminalsMap[e]),s=D(i=>i.reconnectTerminal);return r?o.jsx($n,{inline:!0,children:o.jsx(Ks,{terminal:r,canClose:n})}):o.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)",border:"1px dashed var(--border)"},children:o.jsxs("button",{onClick:()=>s(e),style:{background:"none",border:"1px solid var(--accent-blue)",color:"var(--accent-blue)",padding:"8px 16px",borderRadius:"6px",cursor:"pointer",fontSize:"13px"},children:["↻ Reconnect ",e]})})}),qs=a.memo(function({node:e,canClose:n}){const r=D(c=>c.setSplitSizes),s=a.useRef(null),i=e.direction==="horizontal",l=a.useRef(e.sizes);l.current=e.sizes;const d=a.useCallback((c,f)=>{f.preventDefault();const u=i?"resizing-panes":"resizing-panes-v";document.body.classList.add(u);const h=i?f.clientX:f.clientY,g=[...l.current],b=s.current,j=i?(b==null?void 0:b.clientWidth)||1:(b==null?void 0:b.clientHeight)||1;let k=null;const C=I=>{k||(k=requestAnimationFrame(()=>{k=null;const z=((i?I.clientX:I.clientY)-h)/j*100,_=g[c]+z,B=g[c+1]-z;if(_>=mn&&B>=mn){const F=[...g];F[c]=_,F[c+1]=B,r(e.id,F)}}))},v=()=>{k&&cancelAnimationFrame(k),document.body.classList.remove(u),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",v)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",v)},[i,e.id,r]),p=[];return e.children.forEach((c,f)=>{const u=c.type==="leaf"?c.terminalId:c.id;p.push(o.jsx("div",{style:{flex:`${e.sizes[f]} 0 0`,minWidth:0,minHeight:0,overflow:"hidden"},children:o.jsx(_n,{node:c,canClose:n})},u)),f<e.children.length-1&&p.push(o.jsx("div",{onMouseDown:h=>d(f,h),style:{flex:`0 0 ${Js}px`,cursor:i?"col-resize":"row-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:h=>{h.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="var(--border)"}},`divider-${e.id}-${f}`))}),o.jsx("div",{ref:s,style:{display:"flex",flexDirection:i?"row":"column",height:"100%",width:"100%",overflow:"hidden"},children:p})});function Ys({tabId:t}){const e=D(S=>S.tabs.find(w=>w.id===t)),n=D(S=>S.activeTabId),r=D(S=>S.switchTab),s=D(S=>S.closeTab),i=D(S=>S.reopenTab),l=D(S=>S.deleteTab),d=D(S=>S.renameTab),p=D(S=>e?e.terminalIds.map(w=>{const ee=S.terminalsMap[w];return ee?{id:w,connected:ee.connected,active:!0}:{id:w,connected:!1,active:!1}}):[]),c=D(S=>S.disconnectTerminal),f=D(S=>S.reconnectTerminal),u=D(S=>S.killServerSession),[h,g]=a.useState(!1),[b,j]=a.useState(""),[k,C]=a.useState(!1),v=a.useRef(null);if(!e)return null;const I=n===t,T=e.status==="open",L=()=>{T&&r(t)},z=S=>{T&&(S.stopPropagation(),j(e.name),g(!0),setTimeout(()=>{var w;return(w=v.current)==null?void 0:w.focus()},0))},_=()=>{const S=b.trim();S&&d(t,S),g(!1)},B=S=>{S.stopPropagation(),i(t)},F=S=>{S.stopPropagation(),s(t)},O=async S=>{S.stopPropagation(),window.confirm(`Delete tab "${e.name}"? This will kill all tmux sessions in this tab.`)&&await l(t)},N=S=>{S.stopPropagation(),C(!k)};return o.jsxs("div",{children:[o.jsxs("div",{onClick:L,style:{padding:"8px 12px",cursor:T?"pointer":"default",borderLeft:I?"3px solid var(--accent-blue)":"3px solid transparent",backgroundColor:I?"rgba(122, 162, 247, 0.08)":"transparent",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s",opacity:T?1:.5},onMouseEnter:S=>{T&&!I&&(S.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)")},onMouseLeave:S=>{I||(S.currentTarget.style.backgroundColor="transparent")},children:[T&&e.terminalIds.length>0&&o.jsx("button",{onClick:N,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:k?"▼":"▶"}),o.jsxs("div",{style:{flex:1,minWidth:0},children:[h?o.jsx("input",{ref:v,value:b,onChange:S=>j(S.target.value),onBlur:_,onKeyDown:S=>{S.key==="Enter"&&_(),S.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"}}):o.jsx("div",{onDoubleClick:z,style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:T?"Double-click to rename":e.name,children:e.name}),o.jsxs("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:[e.terminalIds.length," terminal",e.terminalIds.length!==1?"s":""," · ",An(Math.floor(e.createdAt/1e3))]})]}),T?o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:F,style:{flexShrink:0},title:"Close tab",children:"×"}):o.jsxs("div",{style:{display:"flex",gap:"4px",flexShrink:0},children:[o.jsx("button",{className:"pane-btn",onClick:B,title:"Reopen tab",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:O,title:"Delete tab",children:"×"})]})]}),T&&k&&p.length>0&&o.jsx("div",{style:{paddingLeft:"28px",backgroundColor:"rgba(0, 0, 0, 0.2)"},children:p.map(S=>o.jsxs("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--text-secondary)",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center"},title:`Connected: ${S.connected}`,children:[o.jsx("span",{style:{fontFamily:"monospace"},children:S.id}),o.jsx("span",{style:{marginLeft:"8px",color:S.active?S.connected?"var(--accent-green)":"var(--accent-yellow)":"var(--text-secondary)"},children:S.active?S.connected?"●":"◐":"○"}),S.active?o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:w=>{w.stopPropagation(),c(S.id)},style:{marginLeft:"auto",flexShrink:0},title:"Disconnect terminal (keeps session alive)",children:"×"}):o.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:"4px",flexShrink:0},children:[o.jsx("button",{className:"pane-btn",onClick:w=>{w.stopPropagation(),f(S.id)},title:"Reconnect terminal",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:w=>{w.stopPropagation(),window.confirm(`Kill terminal "${S.id}"? This will destroy the tmux session.`)&&u(S.id)},title:"Kill session",children:"×"})]})]},S.id))})]})}function Xs({sessionId:t,active:e,createdAt:n}){const r=D(d=>d.addTerminal),s=D(d=>d.killServerSession),i=()=>{r("horizontal",t)},l=d=>{d.stopPropagation(),window.confirm(`Delete orphaned session "${t}"? This will kill the tmux session.`)&&s(t)};return o.jsxs("div",{onClick:i,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:[o.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:e?"var(--accent-green)":"var(--text-secondary)",flexShrink:0}}),o.jsxs("div",{style:{flex:1,minWidth:0},children:[o.jsx("div",{style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}),o.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:An(n)})]}),o.jsx("button",{className:"pane-btn pane-btn--danger",onClick:l,style:{flexShrink:0},title:"Delete session",children:"×"})]})}function Zs(){const t=D(c=>c.sidebarOpen),e=D(c=>c.toggleSidebar),n=D(c=>c.fetchSessions),r=D(c=>t?c.serverSessions:[]),s=D(c=>t?c.tabs:[]),i=D(c=>c.terminalIds.length),l=D(c=>c.tabsLoading),d=new Set(s.flatMap(c=>c.terminalIds)),p=r.filter(c=>!d.has(c.sessionId));return a.useEffect(()=>{if(!t)return;n();let c=setInterval(n,5e3);const f=()=>{document.hidden?c&&(clearInterval(c),c=null):(n(),c||(c=setInterval(n,5e3)))};return document.addEventListener("visibilitychange",f),()=>{c&&clearInterval(c),document.removeEventListener("visibilitychange",f)}},[t,n]),a.useEffect(()=>{if(!t)return;const c=setTimeout(n,800);return()=>clearTimeout(c)},[i,t,n]),o.jsxs("div",{className:"session-sidebar",style:{width:t?280:0,height:"100%",backgroundColor:"var(--bg-secondary)",borderLeft:t?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,overflow:"hidden",transition:"width 0.2s ease"},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[o.jsx("span",{style:{color:"var(--accent-blue)",fontSize:"14px",fontWeight:"bold"},children:"Tabs & Terminals"}),o.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"16px",padding:"0 4px",lineHeight:1},title:"Close sidebar",children:"×"})]}),o.jsxs("div",{style:{flex:1,overflowY:"auto"},children:[o.jsxs("div",{children:[o.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"}),s.length===0?o.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"14px",textAlign:"center",padding:"12px"},children:"No tabs"}):s.map(c=>o.jsx(Ys,{tabId:c.id},c.id))]}),!l&&p.length>0&&o.jsxs("div",{style:{marginTop:"16px"},children:[o.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(c=>o.jsx(Xs,{sessionId:c.sessionId,active:c.active,createdAt:c.createdAt},c.sessionId))]})]})]})}const On=It.memo(()=>{const t=D(T=>T.tabs),e=D(T=>T.activeTabId),n=D(T=>T.addTab),r=D(T=>T.switchTab),s=D(T=>T.closeTab),i=D(T=>T.renameTab),[l,d]=a.useState(null),[p,c]=a.useState(""),f=a.useRef(null),u=t.filter(T=>T.status==="open");a.useEffect(()=>{l&&f.current&&(f.current.focus(),f.current.select())},[l]);const h=T=>{d(T.id),c(T.name)},g=()=>{l&&p.trim()&&i(l,p.trim()),d(null),c("")},b=()=>{d(null),c("")},j=T=>{T.key==="Enter"?g():T.key==="Escape"&&b()},k=T=>{l||r(T)},C=(T,L)=>{T.stopPropagation(),s(L)},v=(T,L)=>{T.button===1&&(T.preventDefault(),s(L))},I=u.length>1;return o.jsxs("div",{className:"tab-bar",children:[u.map(T=>{const L=T.id===e,z=l===T.id,_=T.terminalIds.length;return o.jsx("div",{className:`tab-item ${L?"tab-item--active":""}`,onClick:()=>k(T.id),onDoubleClick:()=>h(T),onMouseDown:B=>v(B,T.id),children:z?o.jsx("input",{ref:f,type:"text",value:p,onChange:B=>c(B.target.value),onBlur:g,onKeyDown:j,className:"tab-item__rename-input"}):o.jsxs(o.Fragment,{children:[o.jsxs("span",{className:"tab-item__name",children:[T.name," ",_>0&&`(${_})`]}),I&&o.jsx("button",{className:"tab-item__close",onClick:B=>C(B,T.id),title:"Close tab","aria-label":"Close tab",children:"×"})]})},T.id)}),o.jsx("button",{className:"tab-bar-add",onClick:()=>n(),title:"New tab","aria-label":"Add new tab",children:"+"})]})});On.displayName="TabBar";function Qs(){return localStorage.getItem("ai-cli-online-token")}function ea(){const t=D(f=>f.token),e=D(f=>f.setToken),n=D(f=>f.tabs),r=D(f=>f.addTab),s=D(f=>f.toggleSidebar),i=D(f=>f.fontSize),l=D(f=>f.setFontSize),d=D(f=>f.tabsLoading),p=D(f=>f.theme),c=D(f=>f.toggleTheme);return a.useEffect(()=>{const f=Qs();f&&!t&&e(f)},[]),a.useEffect(()=>{t&&!d&&n.filter(f=>f.status==="open").length===0&&r("Default")},[t,d]),t?o.jsxs("div",{style:{height:"100vh",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[o.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:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[o.jsx("span",{style:{fontSize:"15px",fontWeight:"bold",color:"var(--accent-blue)",letterSpacing:"0.5px"},children:"AI-Cli Online"}),o.jsxs("span",{style:{fontSize:"11px",color:"var(--text-secondary)",fontWeight:400},children:["v","3.0.13"]})]}),o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[o.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"1px 4px",borderRadius:"6px",backgroundColor:"rgba(0,0,0,0.2)"},children:[o.jsx("button",{className:"header-btn",onClick:()=>l(i-1),disabled:i<=10,title:"Decrease font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A−"}),o.jsx("span",{style:{fontSize:"11px",color:"var(--text-primary)",minWidth:"20px",textAlign:"center"},children:i}),o.jsx("button",{className:"header-btn",onClick:()=>l(i+1),disabled:i>=24,title:"Increase font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A+"})]}),o.jsx(na,{}),o.jsx("button",{className:"header-btn",onClick:c,title:`Switch to ${p==="dark"?"light":"dark"} mode`,"aria-label":"Toggle theme",children:p==="dark"?"☀":"🌙"}),o.jsx("button",{className:"header-btn",onClick:s,title:"Toggle Tabs & Terminals Sidebar","aria-label":"Toggle sidebar",children:"☰"}),o.jsx("button",{className:"header-btn header-btn--muted",onClick:()=>{window.confirm("Logout will close all terminals. Continue?")&&e(null)},children:"Logout"})]})]}),o.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[o.jsx("main",{style:{flex:1,overflow:"hidden"},children:o.jsx(Vs,{})}),o.jsx(Zs,{})]}),o.jsx(On,{})]}):o.jsx(Pr,{})}const ta=[1,2,3,4];function na(){const t=D(r=>r.latency);if(t===null)return o.jsx("span",{style:{fontSize:"10px",color:"var(--scrollbar-thumb-hover)"},title:"Measuring latency...",children:"--ms"});let e,n;return t<50?(e="var(--accent-green)",n=4):t<150?(e="var(--accent-yellow)",n=3):t<300?(e="var(--accent-orange)",n=2):(e="var(--accent-red)",n=1),o.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: ${t}ms`,children:[ta.map(r=>o.jsx("span",{style:{display:"inline-block",width:"2.5px",height:`${3+r*2}px`,backgroundColor:r<=n?e:"var(--border)",borderRadius:"1px",transition:"background-color 0.3s ease"}},r)),o.jsxs("span",{style:{fontSize:"10px",color:e,marginLeft:"4px",fontWeight:500},children:[t,"ms"]})]})}kt.createRoot(document.getElementById("root")).render(o.jsx(It.StrictMode,{children:o.jsx($n,{children:o.jsx(ea,{})})}));
@@ -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-BHAsZRWj.js"></script>
13
+ <script type="module" crossorigin src="/assets/index-DtWYEMhe.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">
package/web/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-cli-online-web",
3
- "version": "3.0.12",
3
+ "version": "3.0.13",
4
4
  "description": "CLI-Online Web Frontend",
5
5
  "type": "module",
6
6
  "scripts": {