ai-cli-online 2.9.3 → 2.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/server/package.json
CHANGED
package/shared/package.json
CHANGED
|
@@ -28,4 +28,4 @@ var yn=Object.defineProperty;var vn=(n,e,t)=>e in n?yn(n,e,{enumerable:!0,config
|
|
|
28
28
|
`),[e]),$=s.useMemo(()=>Br(e),[e]),L=s.useMemo(()=>{const u=new Map,b=new Map;return v.forEach((I,w)=>{if(I.type==="heading"){const y=sn(I.text||""),Z=on(y,b);u.set(w,Z)}}),u},[v]),T=s.useRef(new Set),[g,z]=s.useState(()=>{try{const u=localStorage.getItem(Ze(o,t)),b=u?JSON.parse(u):dt,I=new Set;return b.additions.forEach(w=>I.add(w.id)),b.deletions.forEach(w=>I.add(w.id)),(b.replacements??[]).forEach(w=>I.add(w.id)),(b.comments??[]).forEach(w=>I.add(w.id)),T.current=I,b.replacements||(b.replacements=[]),b.comments||(b.comments=[]),b}catch{return dt}}),R=A(u=>u.latency),W=s.useRef(void 0),D=s.useRef(void 0),U=s.useRef(!1),H=s.useRef(!1);s.useEffect(()=>{if(!H.current)return;const u=Ze(o,t),b=JSON.stringify(g);W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{try{localStorage.setItem(u,b)}catch{}},50),D.current&&clearTimeout(D.current);const I=Math.max(200,(R??30)*3);return D.current=setTimeout(()=>{U.current||(U.current=!0,Pr(a,o,t,b,Date.now()).catch(()=>{}).finally(()=>{U.current=!1}))},I),()=>{W.current&&clearTimeout(W.current),D.current&&clearTimeout(D.current)}},[g,o,t,a,R]),s.useEffect(()=>{H.current=!1;let u=dt,b=0;try{const y=localStorage.getItem(Ze(o,t));y&&(u=JSON.parse(y),b=Date.now())}catch{}u.replacements||(u.replacements=[]),u.comments||(u.comments=[]),z(u);const I=new Set;u.additions.forEach(y=>I.add(y.id)),u.deletions.forEach(y=>I.add(y.id)),u.replacements.forEach(y=>I.add(y.id)),u.comments.forEach(y=>I.add(y.id)),T.current=I;let w=!1;return Fr(a,o,t).then(y=>{if(!w&&y&&y.updatedAt>b)try{const Z=JSON.parse(y.content);Z.replacements||(Z.replacements=[]),Z.comments||(Z.comments=[]),z(Z);try{localStorage.setItem(Ze(o,t),y.content)}catch{}const Ee=new Set;Z.additions.forEach(je=>Ee.add(je.id)),Z.deletions.forEach(je=>Ee.add(je.id)),Z.replacements.forEach(je=>Ee.add(je.id)),Z.comments.forEach(je=>Ee.add(je.id)),T.current=Ee}catch{}}).catch(()=>{}).finally(()=>{H.current=!0}),H.current=!0,()=>{w=!0}},[o,t,a]);const[F,j]=s.useState(0),S=s.useMemo(()=>{const u=T.current,b=g.additions.length+g.deletions.length+g.replacements.length+g.comments.length;let I=0;return g.additions.forEach(w=>{u.has(w.id)&&I++}),g.deletions.forEach(w=>{u.has(w.id)&&I++}),g.replacements.forEach(w=>{u.has(w.id)&&I++}),g.comments.forEach(w=>{u.has(w.id)&&I++}),{total:b,sent:I,unsent:b-I}},[g,F]),[_,k]=s.useState(null),[G,Y]=s.useState(""),J=s.useRef(null),[M,B]=s.useState(null),[X,O]=s.useState(""),K=s.useRef(null),[re,ne]=s.useState(null),[be,Ce]=s.useState(""),Te=s.useRef(null),[Be,ve]=s.useState(null),[ge,Ie]=s.useState(""),me=s.useRef(null),[Q,Ae]=s.useState(null),[he,N]=s.useState(""),P=s.useRef(null),[V,ie]=s.useState(null),te=s.useRef(null);s.useEffect(()=>()=>{const u=te.current;u&&u.scrollTop>0&&localStorage.setItem($t(o,t),String(u.scrollTop))},[o,t]),s.useEffect(()=>{if(!v.length)return;const u=localStorage.getItem($t(o,t));u&&requestAnimationFrame(()=>{const b=te.current;b&&(b.scrollTop=Number(u))})},[o,t,v.length]),s.useEffect(()=>{_!=null&&requestAnimationFrame(()=>{var u;return(u=J.current)==null?void 0:u.focus()})},[_]),s.useEffect(()=>{Q&&requestAnimationFrame(()=>{var u;return(u=P.current)==null?void 0:u.focus()})},[Q]);const ye=s.useCallback(u=>{if(!G.trim()){k(null),Y("");return}const b=ut(v,u+1);z(I=>({...I,additions:[...I.additions,{id:$e(),afterTokenIndex:u,sourceLine:b,content:G.trim()}]})),k(null),Y("")},[G,v]),we=s.useCallback(u=>{z(b=>({...b,additions:b.additions.filter(I=>I.id!==u)}))},[]),Re=s.useCallback((u,b)=>{z(I=>({...I,additions:I.additions.map(w=>w.id===u?{...w,id:$e(),content:b}:w)}))},[]),Ne=s.useCallback(()=>{var u;V&&(z(b=>({...b,deletions:[...b.deletions,{id:$e(),tokenIndices:V.tokenIndices,startLine:V.startLine,endLine:V.endLine,selectedText:V.text.slice(0,80)}]})),ie(null),(u=window.getSelection())==null||u.removeAllRanges())},[V]),ze=s.useCallback(u=>{var b;V&&(Ae({type:u,tokenIndices:V.tokenIndices,startLine:V.startLine,endLine:V.endLine,text:V.text.slice(0,80)}),N(""),ie(null),(b=window.getSelection())==null||b.removeAllRanges())},[V]),De=s.useCallback(()=>{if(!Q)return;const u=he.trim();if(!u){Ae(null),N("");return}Q.type==="replace"?z(b=>({...b,replacements:[...b.replacements,{id:$e(),tokenIndices:Q.tokenIndices,startLine:Q.startLine,endLine:Q.endLine,selectedText:Q.text,content:u}]})):z(b=>({...b,comments:[...b.comments,{id:$e(),tokenIndices:Q.tokenIndices,startLine:Q.startLine,endLine:Q.endLine,selectedText:Q.text,content:u}]})),Ae(null),N("")},[Q,he]),Oe=s.useCallback(u=>{z(b=>({...b,replacements:b.replacements.filter(I=>I.id!==u)}))},[]),Je=s.useCallback((u,b)=>{z(I=>({...I,replacements:I.replacements.map(w=>w.id===u?{...w,id:$e(),content:b}:w)}))},[]),x=s.useCallback(u=>{z(b=>({...b,comments:b.comments.filter(I=>I.id!==u)}))},[]),E=s.useCallback((u,b)=>{z(I=>({...I,comments:I.comments.map(w=>w.id===u?{...w,id:$e(),content:b}:w)}))},[]),q=s.useCallback(u=>{z(b=>({...b,deletions:b.deletions.filter(I=>I.id!==u)}))},[]),ee=s.useCallback((u,b)=>{z(I=>({...I,deletions:I.deletions.map(w=>w.id===u?{...w,id:$e(),selectedText:b}:w)}))},[]),se=s.useCallback(u=>{let b=u instanceof Element?u:u.parentElement;for(;b&&b!==te.current;){if(b.hasAttribute("data-token-index"))return b;b=b.parentElement}return null},[]),xe=s.useCallback(()=>{const u=window.getSelection();if(!u||u.isCollapsed||!te.current){ie(null);return}const b=u.toString().trim();if(!b){ie(null);return}const I=u.getRangeAt(0);if(!te.current.contains(I.commonAncestorContainer)){ie(null);return}const w=se(I.startContainer),y=se(I.endContainer);if(!w||!y){ie(null);return}const Z=parseInt(w.getAttribute("data-token-index")||"0",10),Ee=parseInt(y.getAttribute("data-token-index")||"0",10),je=[];for(let it=Math.min(Z,Ee);it<=Math.max(Z,Ee);it++)je.push(it);const xn=ut(v,Math.min(Z,Ee)),gn=ut(v,Math.max(Z,Ee)+1),St=I.getBoundingClientRect(),at=te.current,kt=at.getBoundingClientRect();navigator.clipboard.writeText(b).catch(()=>{}),ie({x:St.right-kt.left+at.scrollLeft+6,y:St.top-kt.top+at.scrollTop-2,tokenIndices:je,startLine:xn,endLine:gn,text:b})},[v,se]),ae=s.useRef(void 0);s.useEffect(()=>{const u=()=>{ae.current&&clearTimeout(ae.current),ae.current=setTimeout(()=>{const b=window.getSelection();if(!b||b.isCollapsed||!te.current){ie(null);return}const I=b.anchorNode;I&&te.current.contains(I)&&xe()},120)};return document.addEventListener("selectionchange",u),()=>{document.removeEventListener("selectionchange",u),ae.current&&clearTimeout(ae.current)}},[xe]),Or(te,v);const de=s.useCallback(()=>{const u=T.current;return{additions:g.additions.filter(b=>!u.has(b.id)),deletions:g.deletions.filter(b=>!u.has(b.id)),replacements:g.replacements.filter(b=>!u.has(b.id)),comments:g.comments.filter(b=>!u.has(b.id))}},[g]),fe=s.useCallback(()=>{const u=ft(t,de(),C);if(u){c(u);const b=new Set;g.additions.forEach(I=>b.add(I.id)),g.deletions.forEach(I=>b.add(I.id)),g.replacements.forEach(I=>b.add(I.id)),g.comments.forEach(I=>b.add(I.id)),T.current=b,j(I=>I+1)}},[de,g,C,c,t]);s.useImperativeHandle(p,()=>({getSummary:()=>ft(t,de(),C),handleEscape:()=>Q?(De(),!0):_!=null?(ye(_),!0):!1,getScrollTop:()=>{var u;return((u=te.current)==null?void 0:u.scrollTop)??0},setScrollTop:u=>{requestAnimationFrame(()=>{te.current&&(te.current.scrollTop=u)})}}),[de,C,t,_,ye,Q,De]);const[ce,Le]=s.useState(!1),Fe=s.useRef(null);s.useEffect(()=>{if(!ce)return;const u=b=>{Fe.current&&!Fe.current.contains(b.target)&&Le(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[ce]);const Se=s.useCallback((u,b)=>{if(!i)return;const I={additions:[],deletions:[],replacements:[],comments:[]};if(b==="add"){const y=g.additions.find(Z=>Z.id===u);if(!y)return;I.additions.push(y)}else if(b==="del"){const y=g.deletions.find(Z=>Z.id===u);if(!y)return;I.deletions.push(y)}else if(b==="rep"){const y=g.replacements.find(Z=>Z.id===u);if(!y)return;I.replacements.push(y)}else{const y=g.comments.find(Z=>Z.id===u);if(!y)return;I.comments.push(y)}const w=ft(t,I,C);w&&i(w),T.current.add(u),j(y=>y+1)},[i,t,g,C]),Ve=s.useCallback((u,b)=>{b==="add"?we(u):b==="del"?q(u):b==="rep"?Oe(u):x(u)},[we,q,Oe,x]),mn=s.useMemo(()=>{const u=new Set;return g.deletions.forEach(b=>b.tokenIndices.forEach(I=>u.add(I))),u},[g.deletions]),hn=s.useMemo(()=>{const u=new Set;return g.replacements.forEach(b=>b.tokenIndices.forEach(I=>u.add(I))),u},[g.replacements]),bn=s.useMemo(()=>{const u=new Set;return g.comments.forEach(b=>b.tokenIndices.forEach(I=>u.add(I))),u},[g.comments]),vt=s.useMemo(()=>{const u=new Map;return g.additions.forEach(b=>{const I=u.get(b.afterTokenIndex)||[];I.push(b),u.set(b.afterTokenIndex,I)}),u},[g.additions]),wt=g.additions.length>0||g.deletions.length>0||g.replacements.length>0||g.comments.length>0;return r.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[r.jsxs("div",{className:"plan-anno-toolbar",children:[r.jsx("span",{style:{fontSize:"11px",color:"var(--text-secondary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},title:t,children:t.split("/").pop()||t}),d&&r.jsx("button",{className:"pane-btn",onClick:d,title:"Refresh current file",children:"↻"}),r.jsx("button",{className:"pane-btn",onClick:fe,disabled:!wt,title:"Send all annotations to Chat editor",style:wt?{color:"var(--accent-green)"}:{opacity:.4},children:"Send"}),r.jsxs("div",{ref:Fe,style:{position:"relative",flex:1,minWidth:0},children:[r.jsxs("div",{className:`plan-anno-dropdown-trigger${ce?" plan-anno-dropdown-trigger--active":""}`,onClick:()=>Le(u=>!u),title:S.total>0?`${S.total} annotations (${S.unsent} unsent)`:"No annotations",children:[r.jsx("span",{className:"plan-anno-dropdown-trigger__text",children:(()=>{const u=g.additions[0],b=g.deletions[0],I=g.replacements[0],w=g.comments[0],y=u?u.content:b?b.selectedText:I?I.content:w?w.content:"";return y?y.slice(0,40)+(y.length>40?"...":""):""})()}),r.jsx("span",{className:"plan-anno-dropdown-trigger__arrow",children:"▼"})]}),ce&&r.jsxs("div",{className:"plan-anno-dropdown",children:[S.unsent>0&&r.jsx("div",{className:"plan-anno-dropdown__header",children:r.jsxs("button",{className:"pane-btn",onClick:fe,style:{color:"var(--accent-blue)",fontSize:11},children:["Send All Unsent (",S.unsent,")"]})}),r.jsxs("div",{className:"plan-anno-dropdown__list",children:[g.additions.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--add",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-yellow)"},children:"+"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.content.slice(0,60),u.content.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"add"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"add"),title:"Delete",children:"×"})]},u.id)}),g.deletions.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--del",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-red)"},children:"−"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.selectedText.slice(0,60),u.selectedText.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"del"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"del"),title:"Delete",children:"×"})]},u.id)}),g.replacements.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--rep",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-blue)"},children:"⇄"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.content.slice(0,60),u.content.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"rep"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"rep"),title:"Delete",children:"×"})]},u.id)}),g.comments.map(u=>{const b=T.current.has(u.id);return r.jsxs("div",{className:"plan-anno-dropdown__item plan-anno-dropdown__item--com",children:[r.jsx("span",{className:"plan-anno-dropdown__type",style:{color:"var(--accent-green)"},children:"?"}),r.jsxs("span",{className:"plan-anno-dropdown__text",children:[u.content.slice(0,60),u.content.length>60?"...":""]}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!b&&Se(u.id,"com"),disabled:b,title:b?"Already sent":"Send to terminal",style:b?{opacity:.3}:{color:"var(--accent-blue)"},children:"Send"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Ve(u.id,"com"),title:"Delete",children:"×"})]},u.id)}),S.total===0&&r.jsx("div",{className:"plan-anno-dropdown__empty",children:"No annotations"})]})]})]}),l&&r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:()=>{fe(),l()},title:"Send annotations & close file",children:"×"})]}),r.jsxs("div",{style:{display:"flex",flex:1,minHeight:0},children:[r.jsxs("div",{ref:te,className:`plan-anno-content md-preview${_!=null?" plan-anno-content--editing":""}`,style:{flex:1,overflow:"auto",padding:"8px 12px",position:"relative",fontSize:`${h}px`,minWidth:0},onMouseUp:xe,children:[!m&&r.jsx(_t,{index:-1,active:_===-1,additions:vt.get(-1),onOpen:()=>{k(-1),Y("")},onSubmit:()=>ye(-1),onRemoveAddition:we,onEditAddition:Re,onSendSingle:i?u=>Se(u,"add"):void 0,isSent:u=>T.current.has(u),insertText:G,setInsertText:Y,textareaRef:_===-1?J:void 0,expanded:f,alwaysShow:v.length===0,fontSize:h}),v.map((u,b)=>{const I=qr(u);return r.jsxs("div",{children:[r.jsx("div",{"data-token-index":b,id:L.get(b),className:mn.has(b)?"plan-block--deleted":hn.has(b)?"plan-block--replaced":bn.has(b)?"plan-block--commented":void 0,dangerouslySetInnerHTML:{__html:I}}),g.deletions.filter(w=>w.tokenIndices.includes(b)&&w.tokenIndices[0]===b).map(w=>r.jsx("div",{className:"plan-deletion-card",children:M===w.id?r.jsx("textarea",{ref:K,className:"plan-annotation-textarea",value:X,onChange:y=>O(y.target.value),onKeyDown:y=>{if(y.key==="Enter"&&(y.ctrlKey||y.metaKey)){y.preventDefault();const Z=X.trim();Z?ee(w.id,Z):q(w.id),B(null)}y.key==="Escape"&&(y.preventDefault(),B(null))},onBlur:()=>{const y=X.trim();y?ee(w.id,y):q(w.id),B(null)},rows:We(X),style:{fontSize:`${h}px`,flex:1}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{flex:1,fontSize:`${h}px`,color:"var(--accent-red)",whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>{B(w.id),O(w.selectedText),requestAnimationFrame(()=>{const y=K.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},title:"Double-click to edit",children:w.selectedText}),i&&(()=>{const y=T.current.has(w.id);return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!y&&Se(w.id,"del"),disabled:y,title:y?"Already sent":"Send to terminal",style:y?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>{B(w.id),O(w.selectedText),requestAnimationFrame(()=>{const y=K.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},style:{color:"var(--accent-blue)"},title:"Edit deletion annotation",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>q(w.id),title:"Remove deletion",children:"×"})]})},w.id)),g.replacements.filter(w=>w.tokenIndices.includes(b)&&w.tokenIndices[0]===b).map(w=>r.jsx("div",{className:"plan-replace-card",children:re===w.id?r.jsx("textarea",{ref:Te,className:"plan-annotation-textarea",value:be,onChange:y=>Ce(y.target.value),onKeyDown:y=>{if(y.key==="Enter"&&(y.ctrlKey||y.metaKey)){y.preventDefault();const Z=be.trim();Z?Je(w.id,Z):Oe(w.id),ne(null)}y.key==="Escape"&&(y.preventDefault(),ne(null))},onBlur:()=>{const y=be.trim();y?Je(w.id,y):Oe(w.id),ne(null)},rows:We(be),style:{fontSize:`${h}px`,flex:1}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{color:"var(--accent-blue)",flexShrink:0},children:"⇄"}),r.jsxs("span",{style:{flex:1,fontSize:`${h}px`,whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>{ne(w.id),Ce(w.content),requestAnimationFrame(()=>{const y=Te.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},title:"Double-click to edit",children:[r.jsx("span",{style:{color:"var(--accent-red)",textDecoration:"line-through"},children:w.selectedText}),r.jsx("span",{style:{color:"var(--text-secondary)"},children:" → "}),r.jsx("span",{style:{color:"var(--accent-blue)"},children:w.content})]}),i&&(()=>{const y=T.current.has(w.id);return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!y&&Se(w.id,"rep"),disabled:y,title:y?"Already sent":"Send to terminal",style:y?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>{ne(w.id),Ce(w.content),requestAnimationFrame(()=>{const y=Te.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},style:{color:"var(--accent-blue)"},title:"Edit replacement",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>Oe(w.id),title:"Remove replacement",children:"×"})]})},w.id)),g.comments.filter(w=>w.tokenIndices.includes(b)&&w.tokenIndices[0]===b).map(w=>r.jsx("div",{className:"plan-comment-card",children:Be===w.id?r.jsx("textarea",{ref:me,className:"plan-annotation-textarea",value:ge,onChange:y=>Ie(y.target.value),onKeyDown:y=>{if(y.key==="Enter"&&(y.ctrlKey||y.metaKey)){y.preventDefault();const Z=ge.trim();Z?E(w.id,Z):x(w.id),ve(null)}y.key==="Escape"&&(y.preventDefault(),ve(null))},onBlur:()=>{const y=ge.trim();y?E(w.id,y):x(w.id),ve(null)},rows:We(ge),style:{fontSize:`${h}px`,flex:1}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{color:"var(--accent-green)",flexShrink:0},children:"?"}),r.jsxs("span",{style:{flex:1,fontSize:`${h}px`,whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>{ve(w.id),Ie(w.content),requestAnimationFrame(()=>{const y=me.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},title:"Double-click to edit",children:[r.jsxs("span",{style:{color:"var(--text-secondary)",fontStyle:"italic"},children:['"',w.selectedText,'"']}),r.jsx("span",{style:{color:"var(--text-secondary)"},children:": "}),r.jsx("span",{style:{color:"var(--accent-green)"},children:w.content})]}),i&&(()=>{const y=T.current.has(w.id);return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!y&&Se(w.id,"com"),disabled:y,title:y?"Already sent":"Send to terminal",style:y?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>{ve(w.id),Ie(w.content),requestAnimationFrame(()=>{const y=me.current;y&&(y.focus(),y.selectionStart=y.selectionEnd=y.value.length)})},style:{color:"var(--accent-blue)"},title:"Edit comment",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>x(w.id),title:"Remove comment",children:"×"})]})},w.id)),Q&&Q.tokenIndices[0]===b&&r.jsxs("div",{className:Q.type==="replace"?"plan-replace-card":"plan-comment-card",style:{padding:"4px 8px"},children:[r.jsx("span",{style:{color:Q.type==="replace"?"var(--accent-blue)":"var(--accent-green)",flexShrink:0},children:Q.type==="replace"?"⇄":"?"}),r.jsx("textarea",{ref:P,className:"plan-annotation-textarea",value:he,onChange:w=>N(w.target.value),onKeyDown:w=>{if(w.key==="Enter"&&(w.ctrlKey||w.metaKey)){w.preventDefault(),De();return}if(w.key==="Escape"){w.preventDefault(),De();return}},onBlur:De,placeholder:Q.type==="replace"?"Replace with... (Ctrl+Enter to save)":"Comment... (Ctrl+Enter to save)",rows:We(he),style:{fontSize:`${h}px`,flex:1}})]}),!m&&r.jsx(_t,{index:b,active:_===b,additions:vt.get(b),onOpen:()=>{k(b),Y("")},onSubmit:()=>ye(b),onRemoveAddition:we,onEditAddition:Re,onSendSingle:i?w=>Se(w,"add"):void 0,isSent:w=>T.current.has(w),insertText:G,setInsertText:Y,textareaRef:_===b?J:void 0,expanded:f,fontSize:h})]},b)}),!m&&V&&r.jsxs("div",{className:"plan-selection-float",style:{top:V.y,left:V.x},children:[r.jsx("button",{className:"plan-selection-float__delete",onMouseDown:u=>{u.preventDefault(),Ne()},title:"Delete selection",children:"−"}),r.jsx("button",{className:"plan-selection-float__replace",onMouseDown:u=>{u.preventDefault(),ze("replace")},title:"Replace selection",children:"⇄"}),r.jsx("button",{className:"plan-selection-float__comment",onMouseDown:u=>{u.preventDefault(),ze("comment")},title:"Comment on selection",children:"?"})]})]}),r.jsx(Hr,{headings:$,scrollRef:te})]})]})});function _t({index:n,active:e,additions:t,onOpen:o,onSubmit:a,onRemoveAddition:c,onEditAddition:i,onSendSingle:d,isSent:l,insertText:f,setInsertText:m,textareaRef:p,expanded:h,alwaysShow:v,fontSize:C=14}){const[$,L]=s.useState(null),[T,g]=s.useState(""),z=s.useRef(null),R=ht(),W=ht();s.useEffect(()=>{$&&(R.clearUndo(),requestAnimationFrame(()=>{const S=z.current;S&&(S.focus(),S.selectionStart=S.selectionEnd=S.value.length)}))},[$]),s.useEffect(()=>{e&&W.clearUndo()},[e]);const D=s.useCallback(S=>{g(_=>(R.pushUndo(_),S))},[R]),U=s.useCallback(S=>{W.pushUndo(f),m(S)},[f,m,W]),H=s.useCallback(S=>{L(S.id),g(S.content)},[]),F=s.useCallback(()=>{if(!$)return;const S=T.trim();S?i($,S):c($),L(null),g("")},[$,T,i,c]),j=s.useCallback(()=>{L(null),g("")},[]);return r.jsxs("div",{className:`plan-insert-zone${v?" plan-insert-zone--empty":""}`,"data-zone-index":n,children:[t==null?void 0:t.map(S=>r.jsx("div",{className:"plan-annotation-card",children:$===S.id?r.jsx("textarea",{ref:z,className:"plan-annotation-textarea",value:T,onChange:_=>D(_.target.value),onKeyDown:_=>{if(_.key==="Enter"&&(_.ctrlKey||_.metaKey)){_.preventDefault(),F();return}if(_.key==="Escape"){_.preventDefault(),j();return}if(_.key==="Tab"){bt(_,D);return}},onBlur:F,rows:We(T),style:{fontSize:`${C}px`,flex:1,...h?{minWidth:300}:void 0}}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{flex:1,fontSize:`${C}px`,color:"var(--accent-yellow)",whiteSpace:"pre-wrap",cursor:"text"},onDoubleClick:()=>H(S),title:"Double-click to edit",children:S.content}),d&&(()=>{const _=(l==null?void 0:l(S.id))??!1;return r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>!_&&d(S.id),disabled:_,title:_?"Already sent":"Send to terminal",style:_?{opacity:.3}:{color:"var(--accent-green)"},children:"Send"})})(),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:()=>H(S),style:{color:"var(--accent-blue)"},title:"Edit annotation",children:"✎"}),r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm",onClick:()=>c(S.id),children:"×"})]})},S.id)),e?r.jsx("div",{className:"plan-annotation-card plan-annotation-card--editing",children:r.jsx("textarea",{ref:p,className:"plan-annotation-textarea",value:f,onChange:S=>U(S.target.value),onKeyDown:S=>{if(S.key==="Enter"&&(S.ctrlKey||S.metaKey)){S.preventDefault(),a();return}if(S.key==="Escape"){S.preventDefault(),a();return}if(S.key==="Tab"){bt(S,U);return}},placeholder:"Add annotation... (Ctrl+Enter or Esc to save)",rows:We(f),style:{fontSize:`${C}px`,...h?{minWidth:300}:void 0}})}):v&&!(t!=null&&t.length)?r.jsx("div",{className:"plan-empty-placeholder",onDoubleClick:o,title:"Double-click or Ctrl+Enter to edit",children:"Write down your plans here. Double-click or Ctrl+Enter to edit."}):r.jsx("button",{className:"plan-insert-btn",onClick:o,title:"Add annotation here",children:"+"})]})}async function ke(n,e,t){const o=t?`?path=${encodeURIComponent(t)}`:"",a=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/files${o}`,{headers:le(n)});if(!a.ok)throw new Error("Failed to list files");return a.json()}function Yr(n,e,t,o){return new Promise((a,c)=>{const i=new FormData;for(const l of t)i.append("files",l);const d=new XMLHttpRequest;d.open("POST",`${oe}/api/sessions/${encodeURIComponent(e)}/upload`),d.setRequestHeader("Authorization",`Bearer ${n}`),d.upload.addEventListener("progress",l=>{l.lengthComputable&&o&&o(Math.round(l.loaded/l.total*100))}),d.addEventListener("load",()=>{d.status>=200&&d.status<300?a():c(new Error(`Upload failed: ${d.status}`))}),d.addEventListener("error",()=>c(new Error("Upload network error"))),d.addEventListener("abort",()=>c(new Error("Upload aborted"))),d.send(i)})}async function Gr(n,e){const t=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/cwd`,{headers:le(n)});if(!t.ok)throw new Error("Failed to fetch cwd");return(await t.json()).cwd}async function xt(n,e,t){const o=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/touch`,{method:"POST",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({name:t})});if(!o.ok)throw new Error("Failed to create file");return o.json()}async function an(n,e,t){const o=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/mkdir`,{method:"POST",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!o.ok)throw new Error("Failed to create directory");return o.json()}async function Xr(n,e,t){if(!(await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/rm`,{method:"DELETE",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({path:t})})).ok)throw new Error("Failed to delete")}async function Zr(n,e){const t=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/download-cwd`,{headers:le(n)});if(!t.ok)throw new Error("Download failed");const o=await t.blob(),a=URL.createObjectURL(o),c=document.createElement("a");c.href=a;const i=t.headers.get("Content-Disposition"),d=i==null?void 0:i.match(/filename="(.+)"/);c.download=d?decodeURIComponent(d[1]):"cwd.tar.gz",document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(a)}async function Qr(n,e,t){const o=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/download?path=${encodeURIComponent(t)}`,{headers:le(n)});if(!o.ok)throw new Error("Download failed");const a=await o.blob(),c=URL.createObjectURL(a),i=document.createElement("a");i.href=c,i.download=t.split("/").pop()||"download",document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(c)}function ln(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:n<1024*1024*1024?`${(n/(1024*1024)).toFixed(1)} MB`:`${(n/(1024*1024*1024)).toFixed(1)} GB`}function eo(n,e){if(e==="directory")return"📁";const t=n.slice(n.lastIndexOf(".")).toLowerCase();return t===".pdf"?"📕":t===".html"||t===".htm"?"🌐":t===".md"?"📝":"📄"}function cn(n){const e=new Date(n*1e3),t=o=>String(o).padStart(2,"0");return`${t(e.getMonth()+1)}-${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}`}function to({sessionId:n,token:e,planDir:t,selectedFile:o,onSelectFile:a,onCreateFile:c,onDeleteFile:i}){const[d,l]=s.useState([]),[f,m]=s.useState(!0),[p,h]=s.useState(""),[v,C]=s.useState(!1),$=s.useRef(null),[L,T]=s.useState(t),g=s.useCallback(async()=>{if(!(!e||!L)){m(!0);try{const G=(await ke(e,n,L)).files.filter(Y=>Y.type==="file"&&Y.name.toLowerCase().endsWith(".md")||Y.type==="directory").sort((Y,J)=>{const M=Y.type==="file"&&Y.name===".index.md",B=J.type==="file"&&J.name===".index.md";return M&&!B?-1:!M&&B?1:Y.type==="directory"&&J.type!=="directory"?-1:Y.type!=="directory"&&J.type==="directory"?1:Y.name.localeCompare(J.name)});l(G)}catch{l([])}finally{m(!1)}}},[e,n,L]);s.useEffect(()=>{g()},[g]),s.useEffect(()=>{const k=setInterval(g,5e3);return()=>clearInterval(k)},[g]);const z=s.useCallback(()=>{const k=t.substring(0,t.lastIndexOf("/")+1);return L.startsWith(k)?L.substring(k.length):L},[t,L]),R=s.useCallback(async()=>{const k=p.trim();if(!k)return;const G=k.endsWith(".md")?k:`${k}.md`;C(!0);try{const Y=await xt(e,n,`${z()}/${G}`);Y.ok&&(h(""),await g(),c(Y.path))}catch{}finally{C(!1)}},[p,e,n,z,g,c]),W=s.useCallback(async()=>{const k=p.trim().replace(/\/+$/,"");if(k){C(!0);try{await an(e,n,`${z()}/${k}`),h(""),await g()}catch{}finally{C(!1)}}},[p,e,n,z,g]),D=s.useCallback(async k=>{const G=`${L}/${k.name}`,Y=k.type==="directory"?`folder "${k.name}" and all its contents`:`"${k.name}"`;if(window.confirm(`Delete ${Y}?`))try{await Xr(e,n,G),i==null||i(G),await g()}catch{}},[e,n,L,g,i]),U=s.useCallback(k=>{T(G=>`${G}/${k}`)},[]),H=s.useCallback(()=>{L!==t&&T(k=>k.substring(0,k.lastIndexOf("/")))},[L,t]),F=t.split("/").pop()||"TASK",j=(()=>{const k=t.split("/");return k.length>=2?k[k.length-2]+"/":""})(),S=L===t?j+F+"/":j+F+"/"+L.substring(t.length+1)+"/",_=o?o.split("/").pop():null;return r.jsxs("div",{className:"plan-file-browser",children:[r.jsxs("div",{className:"plan-file-browser__header",children:[r.jsx("span",{className:"plan-file-browser__title",title:S,children:S}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:g,title:"Refresh file list",style:{fontSize:12},children:"↻"})]}),r.jsxs("div",{className:"plan-file-browser__create",children:[r.jsx("input",{ref:$,className:"plan-file-browser__input",value:p,onChange:k=>h(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),R())},placeholder:"name",disabled:v}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:R,disabled:v||!p.trim(),title:"Create new .md file",style:p.trim()?{color:"var(--accent-green)",fontWeight:700,fontSize:14}:{opacity:.4,fontWeight:700,fontSize:14},children:"+"}),r.jsx("button",{className:"pane-btn pane-btn--sm",onClick:W,disabled:v||!p.trim(),title:"Create new folder",style:p.trim()?{color:"var(--accent-blue)"}:{opacity:.4},children:"📁"})]}),r.jsxs("div",{className:"plan-file-browser__list",children:[f&&d.length===0&&r.jsx("div",{className:"plan-file-browser__status",children:"Loading..."}),!f&&d.length===0&&r.jsx("div",{className:"plan-file-browser__status",children:"No .md files"}),L!==t&&r.jsxs("div",{className:"plan-file-browser__item",onClick:H,title:"Go up to parent directory",style:{cursor:"pointer"},children:[r.jsx("span",{className:"plan-file-browser__icon",style:{color:"var(--accent-blue)"},children:"←"}),r.jsx("span",{className:"plan-file-browser__name",style:{color:"var(--accent-blue)"},children:".."})]}),d.map(k=>{const G=`${L}/${k.name}`,Y=k.type==="file"&&k.name===_,J=k.type==="directory";return r.jsxs("div",{className:`plan-file-browser__item${Y?" plan-file-browser__item--active":""}`,onClick:()=>J?U(k.name):a(G),title:J?`Open folder ${k.name}`:k.name,style:{cursor:"pointer"},children:[r.jsx("span",{className:"plan-file-browser__icon",children:J?"📁":k.name===".index.md"?"🔒":"□"}),r.jsxs("span",{className:"plan-file-browser__name",children:[k.name,J?"/":""]}),!J&&r.jsx("span",{className:"plan-file-browser__size",children:ln(k.size)}),k.name!==".index.md"&&r.jsx("button",{className:"pane-btn pane-btn--danger pane-btn--sm plan-file-browser__delete",onClick:M=>{M.stopPropagation(),D(k)},title:`Delete ${k.name}`,children:"×"})]},k.name)})]})]})}const pt={status:"idle",mode:"lines",lines:[],content:"",buffer:null,totalSize:0,receivedBytes:0,mtime:0,error:null},no=200;function ro(){const[n,e]=s.useState(pt),t=s.useRef("lines"),o=s.useRef([]),a=s.useRef(""),c=s.useRef(""),i=s.useRef([]),d=s.useRef(0),l=s.useRef(0),f=s.useRef(null),m=s.useRef(null),p=s.useCallback(()=>{const T=t.current;e(g=>({...g,receivedBytes:d.current,...T==="lines"?{lines:[...o.current]}:{},...T==="content"?{content:c.current}:{}}))},[]),h=s.useCallback(()=>{f.current===null&&(f.current=window.setTimeout(()=>{f.current=null,p()},no))},[p]),v=s.useCallback(T=>{t.current=T,o.current=[],a.current="",c.current="",i.current=[],d.current=0,l.current=0,m.current=new TextDecoder,f.current!==null&&(clearTimeout(f.current),f.current=null),e({...pt,mode:T,status:"streaming"})},[]),C=s.useCallback(T=>{d.current+=T.length;const g=t.current;if(g==="lines"){const R=m.current.decode(T,{stream:!0}).split(`
|
|
29
29
|
`);R[0]=a.current+R[0],a.current=R.pop(),R.length>0&&o.current.push(...R)}else if(g==="content"){const z=m.current.decode(T,{stream:!0});c.current+=z}else i.current.push(new Uint8Array(T));h()},[h]),$=s.useCallback(T=>{switch(T.type){case"file-stream-start":l.current=T.size,e(g=>({...g,totalSize:T.size,mtime:T.mtime}));break;case"file-stream-end":{f.current!==null&&(clearTimeout(f.current),f.current=null);const g=t.current;let z=o.current,R=c.current,W=null;if(g==="lines"){const D=m.current.decode(),U=a.current+D;U&&(z=[...z,U],o.current=z),a.current=""}else if(g==="content"){const D=m.current.decode();R=c.current+D,c.current=R}else{const D=i.current.reduce((H,F)=>H+F.length,0);W=new Uint8Array(D);let U=0;for(const H of i.current)W.set(H,U),U+=H.length;i.current=[]}e({status:"complete",mode:g,lines:g==="lines"?[...z]:[],content:g==="content"?R:"",buffer:g==="binary"?W:null,totalSize:l.current,receivedBytes:d.current,mtime:0,error:null});break}case"file-stream-error":f.current!==null&&(clearTimeout(f.current),f.current=null),e(g=>({...g,status:"error",error:T.error}));break}},[]),L=s.useCallback(()=>{f.current!==null&&(clearTimeout(f.current),f.current=null),o.current=[],a.current="",c.current="",i.current=[],d.current=0,l.current=0,m.current=null,e(pt)},[]);return{state:n,startStream:v,handleChunk:C,handleControl:$,reset:L}}function Ot({label:n,percent:e}){return r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:8},children:[r.jsx("span",{style:{color:"var(--text-secondary)",fontSize:13},children:n}),e!=null&&r.jsxs("div",{style:{width:120,display:"flex",alignItems:"center",gap:6},children:[r.jsx("div",{style:{flex:1,height:4,backgroundColor:"var(--border)",borderRadius:2,overflow:"hidden"},children:r.jsx("div",{style:{height:"100%",width:`${e}%`,backgroundColor:"var(--accent-blue)",transition:"width 0.2s"}})}),r.jsxs("span",{style:{fontSize:10,color:"var(--text-secondary)",whiteSpace:"nowrap"},children:[e,"%"]})]})]})}function oo({sessionId:n,token:e,connected:t,onRequestFileStream:o,onForwardToChat:a,onSendToTerminal:c}){const i=ro(),[d,l]=s.useState(!1),f=s.useRef(""),[m,p]=s.useState(null),[h,v]=s.useState(null),[C,$]=s.useState(""),[L,T]=s.useState(!1),g=s.useRef(new Map),z=s.useRef(null),R=s.useRef(null);s.useEffect(()=>{R.current=null;let M=!1;return T(!0),(async()=>{try{const B=await ke(e,n);if(M)return;if(B.files.find(O=>O.name==="TASK"&&O.type==="directory")){const O=B.cwd+"/TASK",K=await ke(e,n,O);if(M)return;const re=K.files.find(ne=>ne.name===".index.md");if(re)p(O),v(O+"/"+re.name);else try{const ne=await xt(e,n,"TASK/.index.md");if(M)return;p(O),ne.ok&&v(ne.path)}catch{p(O)}}else try{const O=await an(e,n,"TASK");if(M)return;p(O.path);const K=await xt(e,n,"TASK/.index.md");if(M)return;K.ok&&v(K.path)}catch{p(null),v(null)}}catch{p(null)}finally{M||T(!1)}try{const B=await ke(e,n);if(M)return;const X=B.home||"";if(f.current=B.cwd,X){const O=`${X}/.claude/commands`;try{const K=await ke(e,n,O);if(M)return;K.files.some(ne=>ne.name==="aicli-task-review.md")||l(!0)}catch{M||l(!0)}}}catch{}})(),()=>{M=!0}},[n,e]),s.useEffect(()=>(pr(n,i.handleChunk,i.handleControl),()=>mr(n)),[n,i.handleChunk,i.handleControl]),s.useEffect(()=>{!h||!t||R.current===h&&C||(R.current=h,i.reset(),i.startStream("content"),o==null||o(h))},[h,t]),s.useEffect(()=>{i.state.status==="complete"&&h&&($(i.state.content),g.current.set(h,i.state.content))},[i.state.status,i.state.content,h]);const W=s.useRef(new Map),D=s.useCallback(()=>{var B,X;if(!h)return;const M=((X=(B=z.current)==null?void 0:B.getScrollTop)==null?void 0:X.call(B))??0;M>0&&W.current.set(h,M)},[h]);s.useEffect(()=>{if(!h||!C)return;const M=W.current.get(h);M!=null&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{var B,X;(X=(B=z.current)==null?void 0:B.setScrollTop)==null||X.call(B,M)})})},[h,C]);const U=s.useCallback(M=>{M!==h&&(D(),h&&C&&g.current.set(h,C),v(M),$(""),R.current=null)},[h,C,D]),H=s.useCallback(M=>{h&&(h===M||h.startsWith(M+"/"))&&(v(null),$(""),R.current=null),g.current.delete(M)},[h]),F=s.useCallback(M=>{v(M),$(""),R.current=null},[]),j=s.useCallback(M=>{M&&(a==null||a(M))},[a]),S=s.useCallback(()=>{D(),h&&C&&g.current.set(h,C),v(null),$(""),R.current=null},[h,C,D]),_=s.useCallback(()=>{!h||!t||(R.current=null,$(""),i.reset(),i.startStream("content"),o==null||o(h),R.current=h)},[h,t,i,o]),[k,G]=s.useState(()=>{const M=localStorage.getItem(`plan-fb-width-${n}`);if(M){const B=Number(M);if(Number.isFinite(B)&&B>=60&&B<=300)return B}return 130}),Y=s.useRef(k);if(k!==Y.current){Y.current=k;try{localStorage.setItem(`plan-fb-width-${n}`,String(Math.round(k)))}catch{}}const J=s.useCallback(M=>{M.preventDefault();const B=M.clientX,X=k;document.body.classList.add("resizing-panes");const O=re=>{const ne=re.clientX-B;G(Math.min(300,Math.max(60,X+ne)))},K=()=>{document.body.classList.remove("resizing-panes"),document.removeEventListener("mousemove",O),document.removeEventListener("mouseup",K)};document.addEventListener("mousemove",O),document.addEventListener("mouseup",K)},[k]);return r.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[d&&r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 10px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",fontSize:12,flexShrink:0},children:[r.jsx("span",{style:{color:"var(--accent-yellow)",flex:1},children:"/aicli-task-review command not installed"}),r.jsx("button",{className:"pane-btn",style:{color:"var(--accent-green)",fontSize:11},onClick:()=>{const M=f.current;M&&c&&c(`mkdir -p ~/.claude/commands && cp ${M}/.commands/*.md ~/.claude/commands/`),l(!1)},children:"Install"}),r.jsx("button",{className:"pane-btn",style:{fontSize:11},onClick:()=>l(!1),children:"×"})]}),r.jsxs("div",{className:"plan-overlay-body",children:[m&&r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{width:k,flexShrink:0,overflow:"hidden"},children:r.jsx(to,{sessionId:n,token:e,planDir:m,selectedFile:h,onSelectFile:U,onCreateFile:F,onDeleteFile:H})}),r.jsx("div",{onMouseDown:J,style:{width:2,flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:M=>{M.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:M=>{M.currentTarget.style.backgroundColor="var(--border)"}})]}),r.jsx("div",{className:"plan-overlay-center",children:L?r.jsx(Ot,{label:"Loading TASK/..."}):h&&!C&&(i.state.status==="streaming"||i.state.status==="idle")?r.jsx(Ot,{label:`Loading ${h.split("/").pop()}...`,percent:i.state.totalSize>0?Math.round(i.state.receivedBytes/i.state.totalSize*100):void 0}):h?r.jsx(Vr,{ref:z,markdown:C,filePath:h,sessionId:n,token:e,onExecute:j,onSend:c,onRefresh:_,onClose:S,readOnly:h.endsWith("/.index.md")}):r.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:8},children:r.jsx("span",{style:{color:"var(--text-secondary)",fontSize:13,fontStyle:"italic"},children:"Select a file from the left panel"})})})]})]})}async function so(n,e){try{const t=await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/draft`,{headers:le(n)});return t.ok?(await t.json()).content??"":""}catch{return""}}async function Ft(n,e,t){try{await fetch(`${oe}/api/sessions/${encodeURIComponent(e)}/draft`,{method:"PUT",headers:{...le(n),"Content-Type":"application/json"},body:JSON.stringify({content:t})})}catch{}}const yt="chat-history",Pt=50;function dn(){try{const n=localStorage.getItem(yt);return n?JSON.parse(n):[]}catch{return[]}}function ao(n){const t=dn().filter(o=>o.text!==n);t.unshift({text:n,ts:Date.now()}),t.length>Pt&&(t.length=Pt),localStorage.setItem(yt,JSON.stringify(t))}const Bt=[{cmd:"/history",desc:"Browse sent message history"},{cmd:"/plan",desc:"Enter plan mode"},{cmd:"/help",desc:"Get help"},{cmd:"/compact",desc:"Compact conversation"},{cmd:"/clear",desc:"Clear conversation"},{cmd:"/model",desc:"Switch model"},{cmd:"/cost",desc:"Show token usage"},{cmd:"/status",desc:"Show status"},{cmd:"/init",desc:"Initialize project CLAUDE.md"},{cmd:"/memory",desc:"Edit memory files"},{cmd:"/review",desc:"Review code"},{cmd:"/bug",desc:"Report a bug"},{cmd:"/login",desc:"Login to Anthropic"},{cmd:"/doctor",desc:"Run diagnostics"},{cmd:"/permissions",desc:"Manage permissions"},{cmd:"/mcp",desc:"MCP server management"},{cmd:"/terminal-setup",desc:"Configure terminal"},{cmd:"/vim",desc:"Toggle vim mode"},{cmd:"/oh-my-claudecode:autopilot",desc:"Full autonomous execution"},{cmd:"/oh-my-claudecode:ralph",desc:"Persistence loop until done"},{cmd:"/oh-my-claudecode:ultrawork",desc:"Max parallel execution"},{cmd:"/oh-my-claudecode:ecomode",desc:"Token-efficient execution"},{cmd:"/oh-my-claudecode:plan",desc:"Strategic planning session"},{cmd:"/oh-my-claudecode:ralplan",desc:"Iterative planning consensus"},{cmd:"/oh-my-claudecode:ultrapilot",desc:"Parallel autopilot (3-5x faster)"},{cmd:"/oh-my-claudecode:analyze",desc:"Deep analysis/investigation"},{cmd:"/oh-my-claudecode:deepsearch",desc:"Thorough codebase search"},{cmd:"/oh-my-claudecode:deepinit",desc:"Generate AGENTS.md hierarchy"},{cmd:"/oh-my-claudecode:ultraqa",desc:"QA cycling: test/fix/repeat"},{cmd:"/oh-my-claudecode:tdd",desc:"Test-driven development"},{cmd:"/oh-my-claudecode:code-review",desc:"Comprehensive code review"},{cmd:"/oh-my-claudecode:security-review",desc:"Security vulnerability review"},{cmd:"/oh-my-claudecode:build-fix",desc:"Fix build/TypeScript errors"},{cmd:"/oh-my-claudecode:research",desc:"Parallel research orchestration"},{cmd:"/oh-my-claudecode:swarm",desc:"N coordinated agents"},{cmd:"/oh-my-claudecode:pipeline",desc:"Sequential agent chaining"},{cmd:"/oh-my-claudecode:learner",desc:"Extract skill from session"},{cmd:"/oh-my-claudecode:note",desc:"Save notes to notepad"},{cmd:"/oh-my-claudecode:cancel",desc:"Cancel active OMC mode"},{cmd:"/oh-my-claudecode:help",desc:"OMC usage guide"},{cmd:"/oh-my-claudecode:doctor",desc:"Diagnose OMC issues"},{cmd:"/oh-my-claudecode:omc-setup",desc:"One-time OMC setup"},{cmd:"/oh-my-claudecode:hud",desc:"Configure HUD statusline"},{cmd:"/oh-my-claudecode:release",desc:"Automated release workflow"},{cmd:"/oh-my-claudecode:ralph-init",desc:"Initialize PRD for ralph"},{cmd:"/oh-my-claudecode:review",desc:"Review plan with Critic"},{cmd:"/oh-my-claudecode:git-master",desc:"Git expert for commits"},{cmd:"/oh-my-claudecode:mcp-setup",desc:"Configure MCP servers"},{cmd:"/oh-my-claudecode:skill",desc:"Manage local skills"},{cmd:"/oh-my-claudecode:writer-memory",desc:"Writer memory system"},{cmd:"/oh-my-claudecode:psm",desc:"Project session manager"},{cmd:"/oh-my-claudecode:trace",desc:"Agent flow trace timeline"},{cmd:"/plan-analyzer",desc:"Task complexity grading & token routing"}],io=s.forwardRef(function({onSend:e,onContentChange:t,sessionId:o,token:a},c){const i=A(x=>x.fontSize),[d,l]=s.useState(""),f=s.useRef(null),m=s.useRef(void 0),p=s.useRef(!1),h=s.useRef(!1),{pushUndo:v,popUndo:C}=ht(),$=s.useRef(d);$.current=d;const L=s.useCallback(()=>v($.current),[v]),[T,g]=s.useState(!1),[z,R]=s.useState(""),[W,D]=s.useState(0),[U,H]=s.useState(!1),[F,j]=s.useState([]),[S,_]=s.useState(0),[k,G]=s.useState(""),Y=s.useRef(null),J=s.useMemo(()=>{if(!k)return F;const x=k.toLowerCase();return F.filter(E=>E.text.toLowerCase().includes(x))},[F,k]),[M,B]=s.useState(!1),[X,O]=s.useState(""),[K,re]=s.useState(""),[ne,be]=s.useState(0),[Ce,Te]=s.useState([]),[Be,ve]=s.useState(!1),ge=s.useRef(""),Ie=s.useRef(null),me=s.useMemo(()=>{if(!z)return Bt;const x=z.toLowerCase();return Bt.filter(E=>E.cmd.toLowerCase().includes(x)||E.desc.toLowerCase().includes(x))},[z]),Q=s.useMemo(()=>{let x=Ce;if(X){const E=X.toLowerCase();x=x.filter(q=>q.name.toLowerCase().includes(E))}return[...x].sort((E,q)=>E.type==="directory"&&q.type!=="directory"?-1:E.type!=="directory"&&q.type==="directory"?1:E.name.localeCompare(q.name))},[Ce,X]),Ae=A(x=>x.latency),he=`chat-draft-${o}`,N=s.useRef(!1),P=s.useRef(void 0);s.useEffect(()=>{try{const E=localStorage.getItem(he);E&&!h.current&&l(E)}catch{}let x=!1;return so(a,o).then(E=>{if(x||h.current){p.current=!0;return}if(E){l(E);try{localStorage.setItem(he,E)}catch{}}p.current=!0}).catch(()=>{p.current=!0}),()=>{x=!0}},[a,o,he]),s.useEffect(()=>{if(!p.current)return;m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{try{localStorage.setItem(he,d)}catch{}},50),P.current&&clearTimeout(P.current);const x=Math.max(200,(Ae??30)*3);return P.current=setTimeout(()=>{N.current||(N.current=!0,Ft(a,o,d).catch(()=>{}).finally(()=>{N.current=!1}))},x),()=>{m.current&&clearTimeout(m.current),P.current&&clearTimeout(P.current)}},[d,a,o,Ae,he]),s.useEffect(()=>{var x;(x=f.current)==null||x.focus()},[]),s.useEffect(()=>{if(!M)return;let x=!1;return ve(!0),(async()=>{try{if(K){if(!ge.current){const ee=await ke(a,o);if(x)return;ge.current=ee.cwd}const E=`${ge.current}/${K.replace(/\/$/,"")}`,q=await ke(a,o,E);if(x)return;Te(q.files)}else{const E=await ke(a,o);if(x)return;ge.current=E.cwd,Te(E.files)}ve(!1)}catch{if(x)return;Te([]),ve(!1)}})(),()=>{x=!0}},[M,K,a,o]),s.useEffect(()=>{if(!M||!Ie.current)return;const x=Ie.current.querySelector(".file-item--active");x==null||x.scrollIntoView({block:"nearest"})},[ne,M]);const V=s.useCallback(()=>{const x=$.current.trim();if(x){ao(x),e(x),l("");try{localStorage.removeItem(he)}catch{}Ft(a,o,"").catch(()=>{})}},[e,a,o,he]),ie=s.useCallback(x=>{L(),l(x),h.current=!0},[L]),te=s.useCallback(x=>{const E=f.current;L();const q=$.current;if(E){const ee=E.selectionStart,se=E.selectionEnd,xe=q.slice(0,ee)+x+q.slice(se);l(xe);const ae=ee+x.length;requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=ae,E.focus()})}else l(q+x)},[L]);s.useImperativeHandle(c,()=>({send:V,fillContent:ie,insertAtCursor:te}),[V,ie,te]),s.useEffect(()=>{t==null||t(d.trim().length>0)},[d,t]);const ye=s.useCallback(()=>{const x=f.current;if(!x)return;const{selectionStart:E,selectionEnd:q}=x;if(E!==q){const ee=x.value.substring(E,q);ee&&navigator.clipboard.writeText(ee).catch(()=>{})}},[]),we=s.useCallback(()=>{const x=dn();g(!1),R("");const E=f.current;if(E){const q=E.selectionStart,ee=d.slice(0,q),se=d.slice(q),xe=ee.match(/(?:^|\s)(\/history)\s*$/);if(xe){const ae=ee.length-xe[1].length;l(d.slice(0,ae)+se)}}x.length!==0&&(j(x),_(0),G(""),H(!0))},[d]),Re=s.useCallback(x=>{L(),l(x.text),H(!1),requestAnimationFrame(()=>{const E=f.current;E&&(E.selectionStart=E.selectionEnd=x.text.length,E.focus())})},[L]),Ne=s.useCallback(x=>{const E=J[x];if(!E)return;const q=F.filter(se=>se.ts!==E.ts||se.text!==E.text);j(q),localStorage.setItem(yt,JSON.stringify(q));const ee=k?q.filter(se=>se.text.toLowerCase().includes(k.toLowerCase())):q;S>=ee.length&&_(Math.max(0,ee.length-1))},[J,F,S,k]);s.useEffect(()=>{if(!U||!Y.current)return;const x=Y.current.querySelector(".history-item--active");x==null||x.scrollIntoView({block:"nearest"})},[S,U]);const ze=s.useCallback(x=>{if(x==="/history"){we();return}const E=f.current;if(!E)return;L();const q=E.selectionStart,ee=d.slice(0,q),se=d.slice(q),ae=ee.lastIndexOf(`
|
|
30
30
|
`)+1,fe=ee.slice(ae).match(/\/[a-zA-Z:-]*$/);if(fe){const ce=ae+(fe.index??0),Le=x+" ",Fe=d.slice(0,ce)+Le+se;l(Fe);const Se=ce+Le.length;requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=Se,E.focus()})}else{const ce=ee+x+se;l(ce);const Le=q+x.length;requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=Le,E.focus()})}g(!1),R(""),D(0)},[d,L,we]),De=s.useCallback(x=>{const E=f.current;if(!E)return;L();const q=E.selectionStart,ee=d.slice(0,q),se=d.slice(q),xe=ee.match(/@([a-zA-Z0-9_.\-/]*)$/);if(!xe)return;const ae=ee.length-xe[0].length;if(x.type==="directory"){const de="@"+K+x.name+"/",fe=d.slice(0,ae)+de+se;l(fe);const ce=ae+de.length;re(K+x.name+"/"),O(""),be(0),requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=ce,E.focus()})}else{const de=x.name+" ",fe=d.slice(0,ae)+de+se;l(fe);const ce=ae+de.length;B(!1),O(""),re(""),be(0),Te([]),ge.current="",requestAnimationFrame(()=>{E.selectionStart=E.selectionEnd=ce,E.focus()})}},[d,K,L]),Oe=s.useCallback(x=>{const E=x.target.value;if(l(E),U){const de=E.trim();de?(G(de),_(0)):G("");return}const q=x.target.selectionStart,ee=E.slice(0,q),se=ee.lastIndexOf(`
|
|
31
|
-
`),ae=ee.slice(se+1).match(/(?:^|\s)\/([a-zA-Z:-]*)$/);if(ae)g(!0),R(ae[1]),D(0),B(!1);else{g(!1);const de=ee.match(/@([a-zA-Z0-9_.\-/]*)$/);if(de){const fe=de[1],ce=fe.lastIndexOf("/"),Le=ce>=0?fe.slice(0,ce+1):"",Fe=ce>=0?fe.slice(ce+1):fe;O(Fe),be(0),re(Le),B(!0)}else B(!1)}},[U]),Je=s.useCallback(x=>{if(T&&me.length>0){if(x.key==="ArrowDown"){x.preventDefault(),D(E=>(E+1)%me.length);return}if(x.key==="ArrowUp"){x.preventDefault(),D(E=>(E-1+me.length)%me.length);return}if(x.key==="Enter"||x.key==="Tab"){x.preventDefault(),ze(me[W].cmd);return}if(x.key==="Escape"){x.preventDefault(),g(!1);return}}if(M&&Q.length>0){if(x.key==="ArrowDown"){x.preventDefault(),be(E=>(E+1)%Q.length);return}if(x.key==="ArrowUp"){x.preventDefault(),be(E=>(E-1+Q.length)%Q.length);return}if(x.key==="Tab"||x.key==="Enter"){x.preventDefault(),De(Q[ne]);return}if(x.key==="Escape"){x.preventDefault(),B(!1);return}}if(U&&J.length>0){if(x.key==="ArrowDown"){x.preventDefault(),_(E=>(E+1)%J.length);return}if(x.key==="ArrowUp"){x.preventDefault(),_(E=>(E-1+J.length)%J.length);return}if(x.key==="Enter"){x.preventDefault(),Re(J[S]);return}if(x.key==="Delete"||x.key==="Backspace"&&(x.ctrlKey||x.metaKey)){x.preventDefault(),Ne(S);return}if(x.key==="Escape"){x.preventDefault(),H(!1);return}}if(x.key==="Tab"){bt(x,l,v);return}x.key==="Enter"&&(x.ctrlKey||x.metaKey)&&(x.preventDefault(),V())},[V,T,me,W,ze,M,Q,ne,De,v,C,U,J,S,Re,Ne]);return r.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[T&&me.length>0&&r.jsx("div",{className:"slash-dropdown",children:me.map((x,E)=>r.jsxs("div",{className:`slash-item${E===W?" slash-item--active":""}`,onMouseDown:q=>{q.preventDefault(),ze(x.cmd)},onMouseEnter:()=>D(E),children:[r.jsx("span",{className:"slash-cmd",children:x.cmd}),r.jsx("span",{className:"slash-desc",children:x.desc})]},x.cmd))}),M&&(Be||Q.length>0)&&r.jsx("div",{className:"file-dropdown",ref:Ie,children:Be?r.jsx("div",{className:"file-item file-loading",children:"Loading..."}):Q.map((x,E)=>r.jsxs("div",{className:`file-item${E===ne?" file-item--active":""}`,onMouseDown:q=>{q.preventDefault(),De(x)},onMouseEnter:()=>be(E),children:[r.jsx("span",{className:"file-icon",children:x.type==="directory"?"📁":"📄"}),r.jsx("span",{className:"file-name",children:x.name})]},x.name))}),U&&r.jsx("div",{className:"history-dropdown",ref:Y,children:J.length===0?r.jsx("div",{className:"history-item history-empty",children:"No history yet"}):J.map((x,E)=>r.jsxs("div",{className:`history-item${E===S?" history-item--active":""}`,onMouseDown:q=>{q.preventDefault(),Re(x)},onMouseEnter:()=>_(E),children:[r.jsx("span",{className:"history-text",children:x.text.length>120?x.text.slice(0,120)+"...":x.text}),r.jsx("span",{className:"history-time",children:new Date(x.ts).toLocaleString()}),r.jsx("button",{className:"history-delete",onMouseDown:q=>{q.preventDefault(),q.stopPropagation(),Ne(E)},title:"Delete (Del key)",children:"×"})]},`${x.ts}-${E}`))}),r.jsx("textarea",{ref:f,className:"md-editor-textarea",value:d,onChange:Oe,onKeyDown:Je,onMouseUp:ye,placeholder:"Type / for commands, @ for files, Ctrl+Enter to send",spellCheck:!1,style:{flex:1,fontSize:`${i}px`}})]})}),lo=600,Ue=typeof window<"u"?window.matchMedia(`(max-width: ${lo-1}px)`):null;function co(){const[n,e]=s.useState(()=>(Ue==null?void 0:Ue.matches)??!1);return s.useEffect(()=>{if(!Ue)return;const t=o=>e(o.matches);return Ue.addEventListener("change",t),()=>Ue.removeEventListener("change",t)},[]),n}const uo=s.memo(function({terminal:e}){const t=co(),o=A(N=>N.splitTerminal),a=A(N=>N.token),c=A(N=>N.toggleChat),i=A(N=>N.togglePlan),{chatOpen:d,planOpen:l}=e.panels,f=s.useCallback(async N=>{let P;if(a)try{P=await Gr(a,e.id)}catch{}o(e.id,N,P)},[a,e.id,o]),m=s.useRef(null),p=s.useRef(null),h=s.useRef(null),[v,C]=s.useState(!1),[$,L]=s.useState(0),[T,g]=s.useState(!1),[z,R]=s.useState(!1),[W,D]=s.useState(!1),[U,H]=s.useState([]),[F,j]=s.useState(""),[S,_]=s.useState([]),[k,G]=s.useState(!1),Y=s.useRef(null),J=s.useRef(null),M=s.useRef(null),[B,X]=s.useState(()=>{const N=localStorage.getItem(`plan-width-${e.id}`);if(N){const P=Number(N);if(Number.isFinite(P)&&P>=20&&P<=80)return P}return 50}),O=s.useRef(B);if(B!==O.current){O.current=B;try{localStorage.setItem(`plan-width-${e.id}`,String(Math.round(B)))}catch{}}const[K,re]=s.useState(()=>{const N=localStorage.getItem(`doc-height-${e.id}`);if(N){const P=Number(N);if(Number.isFinite(P)&&P>=15&&P<=60)return P}return 35}),ne=s.useRef(K);if(K!==ne.current){ne.current=K;try{localStorage.setItem(`doc-height-${e.id}`,String(Math.round(K)))}catch{}}const be=async N=>{const P=N.target.files;if(!(!P||P.length===0||!a)){C(!0),L(0);try{await Yr(a,e.id,P,V=>{L(V)})}catch(V){alert(`Upload failed: ${V instanceof Error?V.message:"Unknown error"}`)}finally{C(!1),L(0),m.current&&(m.current.value="")}}},Ce=s.useRef(void 0),Te=s.useCallback(N=>{if(p.current){const P=N.replace(/\r?\n/g," ").trimEnd();p.current.sendInput(P),Ce.current=window.setTimeout(()=>{var V;return(V=p.current)==null?void 0:V.sendInput("\r")},50)}},[]);s.useEffect(()=>()=>{Ce.current&&clearTimeout(Ce.current)},[]);const Be=s.useCallback(async()=>{if(a){G(!0),D(!0);try{const N=await ke(a,e.id);j(N.cwd),H(N.files),_([])}catch{D(!1)}finally{G(!1)}}},[a,e.id]),ve=s.useCallback(async N=>{if(a){G(!0);try{const P=await ke(a,e.id,N);_(V=>[...V,F]),j(N),H(P.files)}catch{}finally{G(!1)}}},[a,e.id,F]),ge=s.useCallback(async()=>{if(!a||S.length===0)return;const N=S[S.length-1];G(!0);try{const P=await ke(a,e.id,N);_(V=>V.slice(0,-1)),j(N),H(P.files)}catch{}finally{G(!1)}},[a,e.id,S]),Ie=s.useCallback(async N=>{if(a)try{await Qr(a,e.id,N)}catch(P){alert(`Download failed: ${P instanceof Error?P.message:"Unknown error"}`)}},[a,e.id]);s.useEffect(()=>{if(!W)return;const N=ie=>{ie.key==="Escape"&&D(!1)},P=ie=>{Y.current&&!Y.current.contains(ie.target)&&D(!1)};document.addEventListener("keydown",N);const V=setTimeout(()=>document.addEventListener("mousedown",P),50);return()=>{document.removeEventListener("keydown",N),document.removeEventListener("mousedown",P),clearTimeout(V)}},[W]);const me=s.useCallback(N=>{if(p.current){const P=N.replace(/\r?\n/g," ").trimEnd();p.current.sendInput(P),setTimeout(()=>{var V;return(V=p.current)==null?void 0:V.sendInput("\r")},50)}},[]),Q=s.useCallback(N=>{N&&h.current&&h.current.fillContent(N)},[]),Ae=s.useCallback(N=>{N.preventDefault();const P=J.current;if(!P)return;const V=P.getBoundingClientRect(),ie=V.height-24;document.body.classList.add("resizing-panes-v");const te=we=>{const Ne=(we.clientY-V.top-24)/ie*100,ze=Math.min(85,Math.max(40,Ne));re(100-ze)},ye=()=>{document.body.classList.remove("resizing-panes-v"),document.removeEventListener("mousemove",te),document.removeEventListener("mouseup",ye)};document.addEventListener("mousemove",te),document.addEventListener("mouseup",ye)},[]),he=s.useCallback(N=>{N.preventDefault();const P=M.current;if(!P)return;const V=P.getBoundingClientRect(),ie=V.width;document.body.classList.add("resizing-panes");const te=we=>{const Re=(we.clientX-V.left)/ie*100,Ne=Math.min(80,Math.max(20,Re));X(Ne)},ye=()=>{document.body.classList.remove("resizing-panes"),document.removeEventListener("mousemove",te),document.removeEventListener("mouseup",ye)};document.addEventListener("mousemove",te),document.addEventListener("mouseup",ye)},[]);return r.jsxs("div",{ref:J,style:{display:"flex",flexDirection:"column",height:"100%",minWidth:0,minHeight:0},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"3px 10px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",flexShrink:0,height:"24px"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"5px"},children:[r.jsx("span",{style:{display:"inline-block",width:"6px",height:"6px",borderRadius:"50%",backgroundColor:e.connected?"var(--accent-green)":"var(--accent-red)"}}),r.jsxs("span",{style:{fontSize:"12px",color:"var(--text-secondary)"},children:[e.id,e.connected?e.sessionResumed?" (resumed)":"":" (disconnected)"]})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[r.jsx("input",{ref:m,type:"file",multiple:!0,style:{display:"none"},onChange:be}),r.jsx("button",{className:"pane-btn",onClick:()=>{var N;return(N=m.current)==null?void 0:N.click()},disabled:v,style:v?{color:"var(--accent-yellow)"}:void 0,title:v?`Uploading ${$}%`:"Upload files","aria-label":"Upload files",children:v?`${$}%`:"↑"}),r.jsxs("div",{style:{position:"relative"},children:[r.jsx("button",{className:"pane-btn",onClick:Be,disabled:T,style:T?{color:"var(--accent-yellow)"}:void 0,title:T?"Downloading...":"Download files","aria-label":"Download files",children:T?"...":"↓"}),W&&r.jsxs("div",{ref:Y,style:{position:"absolute",top:"100%",right:0,marginTop:4,width:300,maxHeight:360,backgroundColor:"var(--bg-primary)",border:"1px solid var(--border)",borderRadius:6,boxShadow:"0 4px 16px rgba(0,0,0,0.3)",zIndex:100,display:"flex",flexDirection:"column",overflow:"hidden"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"6px 8px",borderBottom:"1px solid var(--border)",backgroundColor:"var(--bg-secondary)",flexShrink:0},children:[S.length>0&&r.jsx("button",{className:"pane-btn",onClick:ge,disabled:k,style:{fontSize:11,flexShrink:0},title:"Go back",children:".."}),r.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",flex:1},children:F.split("/").slice(-2).join("/")||F}),r.jsx("button",{className:"pane-btn",onClick:()=>D(!1),style:{fontSize:11,flexShrink:0},title:"Close",children:"×"})]}),r.jsx("div",{style:{flex:1,overflowY:"auto",padding:"2px 0"},children:k?r.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12},children:"Loading..."}):U.length===0?r.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12,fontStyle:"italic"},children:"Empty directory"}):U.map(N=>r.jsxs("div",{onClick:()=>{const P=F+"/"+N.name;N.type==="directory"?ve(P):Ie(P)},style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",cursor:"pointer",fontSize:12,color:"var(--text-primary)",transition:"background-color 0.1s"},onMouseEnter:P=>{P.currentTarget.style.backgroundColor="var(--bg-secondary)"},onMouseLeave:P=>{P.currentTarget.style.backgroundColor="transparent"},children:[r.jsx("span",{style:{flexShrink:0,fontSize:13},children:N.type==="directory"?"📁":eo(N.name,N.type)}),r.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.name}),N.type==="directory"?r.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:"›"}):N.size!=null?r.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:ln(N.size)}):null]},N.name))}),r.jsx("div",{style:{borderTop:"1px solid var(--border)",padding:"6px 8px",flexShrink:0,backgroundColor:"var(--bg-secondary)"},children:r.jsx("button",{className:"pane-btn",onClick:async()=>{g(!0),D(!1);try{await Zr(a||"",e.id)}catch(N){alert(`Download failed: ${N instanceof Error?N.message:"Unknown error"}`)}finally{g(!1)}},style:{fontSize:11,color:"var(--accent-blue)",width:"100%",textAlign:"center"},title:"Download entire CWD as tar.gz",children:"Download All (tar.gz)"})})]})]}),r.jsx("button",{className:`pane-btn${d?" pane-btn--active":""}`,onClick:()=>c(e.id),title:"Toggle Chat panel","aria-label":"Toggle Chat panel",children:"Chat"}),r.jsx("button",{className:`pane-btn${l?" pane-btn--active":""}`,onClick:()=>i(e.id),title:"Toggle Task annotation panel","aria-label":"Toggle Task annotation panel",children:"Task"}),r.jsx("button",{className:"pane-btn",onClick:()=>f(t?"vertical":"horizontal"),title:t?"Split vertical (screen too narrow for horizontal)":"Split horizontal (left/right)","aria-label":"Split horizontal",children:"|"}),r.jsx("button",{className:"pane-btn",onClick:()=>f("vertical"),title:"Split vertical (top/bottom)","aria-label":"Split vertical",children:"─"})]})]}),r.jsxs("div",{ref:M,style:{flex:1,display:"flex",flexDirection:"row",overflow:"hidden",minHeight:0},children:[l&&r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{width:`${B}%`,minWidth:200,flexShrink:0,overflow:"hidden"},children:r.jsx(oo,{sessionId:e.id,token:a||"",connected:e.connected,onRequestFileStream:N=>{var P;return(P=p.current)==null?void 0:P.requestFileStream(N)},onCancelFileStream:()=>{var N;return(N=p.current)==null?void 0:N.cancelFileStream()},onForwardToChat:Q,onSendToTerminal:me})}),r.jsx("div",{className:"md-editor-divider-h",onMouseDown:he,style:{width:"2px",flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:N=>{N.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:N=>{N.currentTarget.style.backgroundColor="var(--border)"}})]}),r.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[r.jsxs("div",{style:{flex:1,overflow:"hidden",position:"relative",minWidth:80},children:[r.jsx(Dr,{ref:p,sessionId:e.id}),!e.connected&&r.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"var(--bg-secondary)",opacity:.85,zIndex:2,pointerEvents:"none"},children:r.jsx("span",{style:{color:"var(--text-secondary)",fontSize:"13px",fontStyle:"italic"},children:"Connecting..."})})]}),d&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"md-editor-divider",onMouseDown:Ae}),r.jsxs("div",{style:{height:`${K}%`,minHeight:80,flexShrink:0,overflow:"hidden",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[r.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 8px",height:"22px",flexShrink:0,backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)"},children:r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[r.jsx("span",{style:{fontSize:"11px",color:"var(--accent-blue)",fontWeight:500},children:"Chat"}),r.jsx("button",{className:"pane-btn",onClick:()=>{var N;return(N=h.current)==null?void 0:N.send()},disabled:!z,title:"Send to terminal (Ctrl+Enter)",style:z?{color:"var(--accent-green)"}:{opacity:.4,cursor:"default"},children:"Send"}),r.jsx("span",{style:{fontSize:"9px",color:"var(--text-secondary)"},children:"Ctrl+Enter"})]})}),r.jsx("div",{style:{flex:1,overflow:"hidden"},children:r.jsx(io,{ref:h,onSend:Te,onContentChange:R,sessionId:e.id,token:a||""})})]})]})]})]}),e.error&&r.jsx("div",{style:{padding:"2px 8px",backgroundColor:"var(--bg-secondary)",borderTop:"1px solid var(--accent-red)",color:"var(--accent-red)",fontSize:"11px",flexShrink:0},children:e.error})]})});class un extends s.Component{constructor(){super(...arguments);Ct(this,"state",{hasError:!1,error:null})}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,o){}render(){var t,o;return this.state.hasError?this.props.inline?r.jsxs("div",{style:{height:"100%",backgroundColor:"var(--bg-primary)",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:"8px",color:"var(--text-bright)",fontFamily:"monospace",padding:"16px"},children:[r.jsx("div",{style:{fontSize:"14px",color:"var(--accent-red)"},children:"Pane crashed"}),r.jsx("div",{style:{fontSize:"12px",color:"var(--text-secondary)",textAlign:"center"},children:((t=this.state.error)==null?void 0:t.message)||"An unexpected error occurred"}),r.jsx("button",{onClick:()=>this.setState({hasError:!1,error:null}),style:{background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-bright)",padding:"4px 12px",borderRadius:"4px",cursor:"pointer",fontSize:"12px"},children:"Retry"})]}):r.jsxs("div",{style:{minHeight:"100vh",backgroundColor:"var(--bg-primary)",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:"16px",color:"var(--text-bright)",fontFamily:"monospace"},children:[r.jsx("div",{style:{fontSize:"18px",color:"var(--accent-red)"},children:"Something went wrong"}),r.jsx("div",{style:{fontSize:"13px",color:"var(--text-secondary)",maxWidth:"500px",textAlign:"center"},children:((o=this.state.error)==null?void 0:o.message)||"An unexpected error occurred"}),r.jsx("button",{onClick:()=>window.location.reload(),style:{background:"linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-purple) 100%)",border:"none",color:"var(--bg-primary)",padding:"8px 24px",borderRadius:"6px",cursor:"pointer",fontSize:"14px",fontWeight:"bold"},children:"Reload"})]}):this.props.children}}const fo=4,Ut=10;function po(){const n=A(a=>a.layout),e=A(a=>a.terminalIds.length),t=A(a=>a.addTerminal);if(!n)return r.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)"},children:r.jsx("button",{onClick:()=>t(),style:{background:"none",border:"1px dashed var(--border)",color:"var(--text-secondary)",padding:"16px 32px",borderRadius:"8px",cursor:"pointer",fontSize:"14px"},children:"+ Add Terminal"})});const o=e>1;return r.jsx("div",{style:{height:"100%",width:"100%",overflow:"hidden"},children:r.jsx(fn,{node:n,canClose:o})})}const fn=s.memo(function({node:e,canClose:t}){return e.type==="leaf"?r.jsx(mo,{terminalId:e.terminalId,canClose:t}):r.jsx(ho,{node:e,canClose:t})}),mo=s.memo(function({terminalId:e,canClose:t}){const o=A(a=>a.terminalsMap[e]);return o?r.jsx(un,{inline:!0,children:r.jsx(uo,{terminal:o,canClose:t})}):null}),ho=s.memo(function({node:e,canClose:t}){const o=A(f=>f.setSplitSizes),a=s.useRef(null),c=e.direction==="horizontal",i=s.useRef(e.sizes);i.current=e.sizes;const d=s.useCallback((f,m)=>{m.preventDefault();const p=c?"resizing-panes":"resizing-panes-v";document.body.classList.add(p);const h=c?m.clientX:m.clientY,v=[...i.current],C=a.current,$=c?(C==null?void 0:C.clientWidth)||1:(C==null?void 0:C.clientHeight)||1;let L=null;const T=z=>{L||(L=requestAnimationFrame(()=>{L=null;const D=((c?z.clientX:z.clientY)-h)/$*100,U=v[f]+D,H=v[f+1]-D;if(U>=Ut&&H>=Ut){const F=[...v];F[f]=U,F[f+1]=H,o(e.id,F)}}))},g=()=>{L&&cancelAnimationFrame(L),document.body.classList.remove(p),document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",g)};document.addEventListener("mousemove",T),document.addEventListener("mouseup",g)},[c,e.id,o]),l=[];return e.children.forEach((f,m)=>{const p=f.type==="leaf"?f.terminalId:f.id;l.push(r.jsx("div",{style:{flex:`${e.sizes[m]} 0 0`,minWidth:0,minHeight:0,overflow:"hidden"},children:r.jsx(fn,{node:f,canClose:t})},p)),m<e.children.length-1&&l.push(r.jsx("div",{onMouseDown:h=>d(m,h),style:{flex:`0 0 ${fo}px`,cursor:c?"col-resize":"row-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:h=>{h.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="var(--border)"}},`divider-${e.id}-${m}`))}),r.jsx("div",{ref:a,style:{display:"flex",flexDirection:c?"row":"column",height:"100%",width:"100%",overflow:"hidden"},children:l})});function bo({tabId:n}){const e=A(j=>j.tabs.find(S=>S.id===n)),t=A(j=>j.activeTabId),o=A(j=>j.switchTab),a=A(j=>j.closeTab),c=A(j=>j.reopenTab),i=A(j=>j.deleteTab),d=A(j=>j.renameTab),l=A(j=>e?e.terminalIds.map(S=>{const _=j.terminalsMap[S];return _?{id:S,connected:_.connected}:{id:S,connected:!1}}):[]),f=A(j=>j.killServerSession),[m,p]=s.useState(!1),[h,v]=s.useState(""),[C,$]=s.useState(!1),L=s.useRef(null);if(!e)return null;const T=t===n,g=e.status==="open",z=()=>{g&&o(n)},R=j=>{g&&(j.stopPropagation(),v(e.name),p(!0),setTimeout(()=>{var S;return(S=L.current)==null?void 0:S.focus()},0))},W=()=>{const j=h.trim();j&&d(n,j),p(!1)},D=j=>{j.stopPropagation(),c(n)},U=j=>{j.stopPropagation(),a(n)},H=async j=>{j.stopPropagation(),window.confirm(`Delete tab "${e.name}"? This will kill all tmux sessions in this tab.`)&&await i(n)},F=j=>{j.stopPropagation(),$(!C)};return r.jsxs("div",{children:[r.jsxs("div",{onClick:z,style:{padding:"8px 12px",cursor:g?"pointer":"default",borderLeft:T?"3px solid var(--accent-blue)":"3px solid transparent",backgroundColor:T?"rgba(122, 162, 247, 0.08)":"transparent",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s",opacity:g?1:.5},onMouseEnter:j=>{g&&!T&&(j.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)")},onMouseLeave:j=>{T||(j.currentTarget.style.backgroundColor="transparent")},children:[g&&e.terminalIds.length>0&&r.jsx("button",{onClick:F,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"10px",padding:0,width:14,height:14,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:C?"▼":"▶"}),r.jsxs("div",{style:{flex:1,minWidth:0},children:[m?r.jsx("input",{ref:L,value:h,onChange:j=>v(j.target.value),onBlur:W,onKeyDown:j=>{j.key==="Enter"&&W(),j.key==="Escape"&&p(!1)},style:{width:"100%",background:"var(--bg-primary)",border:"1px solid var(--accent-blue)",color:"var(--text-bright)",borderRadius:"3px",padding:"1px 4px",fontSize:"14px",outline:"none"}}):r.jsx("div",{onDoubleClick:R,style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:g?"Double-click to rename":e.name,children:e.name}),r.jsxs("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:[e.terminalIds.length," terminal",e.terminalIds.length!==1?"s":""," · ",cn(Math.floor(e.createdAt/1e3))]})]}),g?r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:U,style:{flexShrink:0},title:"Close tab",children:"×"}):r.jsxs("div",{style:{display:"flex",gap:"4px",flexShrink:0},children:[r.jsx("button",{className:"pane-btn",onClick:D,title:"Reopen tab",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:H,title:"Delete tab",children:"×"})]})]}),g&&C&&l.length>0&&r.jsx("div",{style:{paddingLeft:"28px",backgroundColor:"rgba(0, 0, 0, 0.2)"},children:l.map(j=>r.jsxs("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--text-secondary)",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center"},title:`Connected: ${j.connected}`,children:[r.jsx("span",{style:{fontFamily:"monospace"},children:j.id}),r.jsx("span",{style:{marginLeft:"8px",color:j.connected?"var(--accent-green)":"var(--accent-red)"},children:j.connected?"●":"○"}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:S=>{S.stopPropagation(),window.confirm(`Close terminal "${j.id}"?`)&&f(j.id)},style:{marginLeft:"auto",flexShrink:0},title:"Close terminal",children:"×"})]},j.id))})]})}function xo({sessionId:n,active:e,createdAt:t}){const o=A(d=>d.addTerminal),a=A(d=>d.killServerSession),c=()=>{o("horizontal",n)},i=d=>{d.stopPropagation(),window.confirm(`Delete orphaned session "${n}"? This will kill the tmux session.`)&&a(n)};return r.jsxs("div",{onClick:c,style:{padding:"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)"},onMouseLeave:d=>{d.currentTarget.style.backgroundColor="transparent"},children:[r.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:e?"var(--accent-green)":"var(--text-secondary)",flexShrink:0}}),r.jsxs("div",{style:{flex:1,minWidth:0},children:[r.jsx("div",{style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n}),r.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:cn(t)})]}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:i,style:{flexShrink:0},title:"Delete session",children:"×"})]})}function go(){const n=A(l=>l.sidebarOpen),e=A(l=>l.toggleSidebar),t=A(l=>l.fetchSessions),o=A(l=>n?l.serverSessions:[]),a=A(l=>n?l.tabs:[]),c=A(l=>l.terminalIds.length),i=new Set(a.flatMap(l=>l.terminalIds)),d=o.filter(l=>!i.has(l.sessionId));return s.useEffect(()=>{if(!n)return;t();let l=setInterval(t,5e3);const f=()=>{document.hidden?l&&(clearInterval(l),l=null):(t(),l||(l=setInterval(t,5e3)))};return document.addEventListener("visibilitychange",f),()=>{l&&clearInterval(l),document.removeEventListener("visibilitychange",f)}},[n,t]),s.useEffect(()=>{if(!n)return;const l=setTimeout(t,800);return()=>clearTimeout(l)},[c,n,t]),r.jsxs("div",{className:"session-sidebar",style:{width:n?280:0,height:"100%",backgroundColor:"var(--bg-secondary)",borderLeft:n?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,overflow:"hidden",transition:"width 0.2s ease"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[r.jsx("span",{style:{color:"var(--accent-blue)",fontSize:"14px",fontWeight:"bold"},children:"Tabs & Terminals"}),r.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"16px",padding:"0 4px",lineHeight:1},title:"Close sidebar",children:"×"})]}),r.jsxs("div",{style:{flex:1,overflowY:"auto"},children:[r.jsxs("div",{children:[r.jsx("div",{style:{padding:"8px 12px",color:"var(--accent-blue)",fontSize:"12px",fontWeight:"bold",backgroundColor:"rgba(122, 162, 247, 0.05)",borderBottom:"1px solid var(--border)"},children:"Tabs"}),a.length===0?r.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"14px",textAlign:"center",padding:"12px"},children:"No tabs"}):a.map(l=>r.jsx(bo,{tabId:l.id},l.id))]}),d.length>0&&r.jsxs("div",{style:{marginTop:"16px"},children:[r.jsx("div",{style:{padding:"8px 12px",color:"var(--accent-yellow)",fontSize:"12px",fontWeight:"bold",backgroundColor:"rgba(224, 175, 104, 0.05)",borderBottom:"1px solid var(--border)"},children:"ORPHANED SESSIONS"}),d.map(l=>r.jsx(xo,{sessionId:l.sessionId,active:l.active,createdAt:l.createdAt},l.sessionId))]})]})]})}const pn=gt.memo(()=>{const n=A(R=>R.tabs),e=A(R=>R.activeTabId),t=A(R=>R.addTab),o=A(R=>R.switchTab),a=A(R=>R.closeTab),c=A(R=>R.renameTab),[i,d]=s.useState(null),[l,f]=s.useState(""),m=s.useRef(null),p=n.filter(R=>R.status==="open");s.useEffect(()=>{i&&m.current&&(m.current.focus(),m.current.select())},[i]);const h=R=>{d(R.id),f(R.name)},v=()=>{i&&l.trim()&&c(i,l.trim()),d(null),f("")},C=()=>{d(null),f("")},$=R=>{R.key==="Enter"?v():R.key==="Escape"&&C()},L=R=>{i||o(R)},T=(R,W)=>{R.stopPropagation(),a(W)},g=(R,W)=>{R.button===1&&(R.preventDefault(),a(W))},z=p.length>1;return r.jsxs("div",{className:"tab-bar",children:[p.map(R=>{const W=R.id===e,D=i===R.id,U=R.terminalIds.length;return r.jsx("div",{className:`tab-item ${W?"tab-item--active":""}`,onClick:()=>L(R.id),onDoubleClick:()=>h(R),onMouseDown:H=>g(H,R.id),children:D?r.jsx("input",{ref:m,type:"text",value:l,onChange:H=>f(H.target.value),onBlur:v,onKeyDown:$,className:"tab-item__rename-input"}):r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"tab-item__name",children:[R.name," ",U>0&&`(${U})`]}),z&&r.jsx("button",{className:"tab-item__close",onClick:H=>T(H,R.id),title:"Close tab","aria-label":"Close tab",children:"×"})]})},R.id)}),r.jsx("button",{className:"tab-bar-add",onClick:()=>t(),title:"New tab","aria-label":"Add new tab",children:"+"})]})});pn.displayName="TabBar";function yo(){return localStorage.getItem("ai-cli-online-token")}function vo(){const n=A(m=>m.token),e=A(m=>m.setToken),t=A(m=>m.tabs),o=A(m=>m.addTab),a=A(m=>m.toggleSidebar),c=A(m=>m.fontSize),i=A(m=>m.setFontSize),d=A(m=>m.tabsLoading),l=A(m=>m.theme),f=A(m=>m.toggleTheme);return s.useEffect(()=>{const m=yo();m&&!n&&e(m)},[]),s.useEffect(()=>{n&&!d&&t.filter(m=>m.status==="open").length===0&&o("Default")},[n,d]),n?r.jsxs("div",{style:{height:"100vh",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[r.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 16px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",flexShrink:0},children:[r.jsx("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:r.jsx("span",{style:{fontSize:"15px",fontWeight:"bold",color:"var(--accent-blue)",letterSpacing:"0.5px"},children:"AI-Cli Online"})}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"1px 4px",borderRadius:"6px",backgroundColor:"rgba(0,0,0,0.2)"},children:[r.jsx("button",{className:"header-btn",onClick:()=>i(c-1),disabled:c<=10,title:"Decrease font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A−"}),r.jsx("span",{style:{fontSize:"11px",color:"var(--text-primary)",minWidth:"20px",textAlign:"center"},children:c}),r.jsx("button",{className:"header-btn",onClick:()=>i(c+1),disabled:c>=24,title:"Increase font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A+"})]}),r.jsx(So,{}),r.jsx("button",{className:"header-btn",onClick:f,title:`Switch to ${l==="dark"?"light":"dark"} mode`,"aria-label":"Toggle theme",children:l==="dark"?"☀":"🌙"}),r.jsx("button",{className:"header-btn",onClick:a,title:"Toggle Tabs & Terminals Sidebar","aria-label":"Toggle sidebar",children:"☰"}),r.jsx("button",{className:"header-btn header-btn--muted",onClick:()=>{window.confirm("Logout will close all terminals. Continue?")&&e(null)},children:"Logout"})]})]}),r.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[r.jsx("main",{style:{flex:1,overflow:"hidden"},children:r.jsx(po,{})}),r.jsx(go,{})]}),r.jsx(pn,{})]}):r.jsx(fr,{})}const wo=[1,2,3,4];function So(){const n=A(o=>o.latency);if(n===null)return r.jsx("span",{style:{fontSize:"10px",color:"var(--scrollbar-thumb-hover)"},title:"Measuring latency...",children:"--ms"});let e,t;return n<50?(e="var(--accent-green)",t=4):n<150?(e="var(--accent-yellow)",t=3):n<300?(e="var(--accent-orange)",t=2):(e="var(--accent-red)",t=1),r.jsxs("span",{style:{display:"inline-flex",alignItems:"end",gap:"1.5px",padding:"2px 8px",borderRadius:"10px",backgroundColor:"rgba(0,0,0,0.2)"},title:`Latency: ${n}ms`,children:[wo.map(o=>r.jsx("span",{style:{display:"inline-block",width:"2.5px",height:`${3+o*2}px`,backgroundColor:o<=t?e:"var(--border)",borderRadius:"1px",transition:"background-color 0.3s ease"}},o)),r.jsxs("span",{style:{fontSize:"10px",color:e,marginLeft:"4px",fontWeight:500},children:[n,"ms"]})]})}mt.createRoot(document.getElementById("root")).render(r.jsx(gt.StrictMode,{children:r.jsx(un,{children:r.jsx(vo,{})})}));
|
|
31
|
+
`),ae=ee.slice(se+1).match(/(?:^|\s)\/([a-zA-Z:-]*)$/);if(ae)g(!0),R(ae[1]),D(0),B(!1);else{g(!1);const de=ee.match(/@([a-zA-Z0-9_.\-/]*)$/);if(de){const fe=de[1],ce=fe.lastIndexOf("/"),Le=ce>=0?fe.slice(0,ce+1):"",Fe=ce>=0?fe.slice(ce+1):fe;O(Fe),be(0),re(Le),B(!0)}else B(!1)}},[U]),Je=s.useCallback(x=>{if(T&&me.length>0){if(x.key==="ArrowDown"){x.preventDefault(),D(E=>(E+1)%me.length);return}if(x.key==="ArrowUp"){x.preventDefault(),D(E=>(E-1+me.length)%me.length);return}if(x.key==="Enter"||x.key==="Tab"){x.preventDefault(),ze(me[W].cmd);return}if(x.key==="Escape"){x.preventDefault(),g(!1);return}}if(M&&Q.length>0){if(x.key==="ArrowDown"){x.preventDefault(),be(E=>(E+1)%Q.length);return}if(x.key==="ArrowUp"){x.preventDefault(),be(E=>(E-1+Q.length)%Q.length);return}if(x.key==="Tab"||x.key==="Enter"){x.preventDefault(),De(Q[ne]);return}if(x.key==="Escape"){x.preventDefault(),B(!1);return}}if(U&&J.length>0){if(x.key==="ArrowDown"){x.preventDefault(),_(E=>(E+1)%J.length);return}if(x.key==="ArrowUp"){x.preventDefault(),_(E=>(E-1+J.length)%J.length);return}if(x.key==="Enter"){x.preventDefault(),Re(J[S]);return}if(x.key==="Delete"||x.key==="Backspace"&&(x.ctrlKey||x.metaKey)){x.preventDefault(),Ne(S);return}if(x.key==="Escape"){x.preventDefault(),H(!1);return}}if(x.key==="Tab"){bt(x,l,v);return}x.key==="Enter"&&(x.ctrlKey||x.metaKey)&&(x.preventDefault(),V())},[V,T,me,W,ze,M,Q,ne,De,v,C,U,J,S,Re,Ne]);return r.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",backgroundColor:"var(--bg-primary)",overflow:"hidden"},children:[T&&me.length>0&&r.jsx("div",{className:"slash-dropdown",children:me.map((x,E)=>r.jsxs("div",{className:`slash-item${E===W?" slash-item--active":""}`,onMouseDown:q=>{q.preventDefault(),ze(x.cmd)},onMouseEnter:()=>D(E),children:[r.jsx("span",{className:"slash-cmd",children:x.cmd}),r.jsx("span",{className:"slash-desc",children:x.desc})]},x.cmd))}),M&&(Be||Q.length>0)&&r.jsx("div",{className:"file-dropdown",ref:Ie,children:Be?r.jsx("div",{className:"file-item file-loading",children:"Loading..."}):Q.map((x,E)=>r.jsxs("div",{className:`file-item${E===ne?" file-item--active":""}`,onMouseDown:q=>{q.preventDefault(),De(x)},onMouseEnter:()=>be(E),children:[r.jsx("span",{className:"file-icon",children:x.type==="directory"?"📁":"📄"}),r.jsx("span",{className:"file-name",children:x.name})]},x.name))}),U&&r.jsx("div",{className:"history-dropdown",ref:Y,children:J.length===0?r.jsx("div",{className:"history-item history-empty",children:"No history yet"}):J.map((x,E)=>r.jsxs("div",{className:`history-item${E===S?" history-item--active":""}`,onMouseDown:q=>{q.preventDefault(),Re(x)},onMouseEnter:()=>_(E),children:[r.jsx("span",{className:"history-text",children:x.text.length>120?x.text.slice(0,120)+"...":x.text}),r.jsx("span",{className:"history-time",children:new Date(x.ts).toLocaleString()}),r.jsx("button",{className:"history-delete",onMouseDown:q=>{q.preventDefault(),q.stopPropagation(),Ne(E)},title:"Delete (Del key)",children:"×"})]},`${x.ts}-${E}`))}),r.jsx("textarea",{ref:f,className:"md-editor-textarea",value:d,onChange:Oe,onKeyDown:Je,onMouseUp:ye,placeholder:"Type / for commands, @ for files, Ctrl+Enter to send",spellCheck:!1,style:{flex:1,fontSize:`${i}px`}})]})}),lo=600,Ue=typeof window<"u"?window.matchMedia(`(max-width: ${lo-1}px)`):null;function co(){const[n,e]=s.useState(()=>(Ue==null?void 0:Ue.matches)??!1);return s.useEffect(()=>{if(!Ue)return;const t=o=>e(o.matches);return Ue.addEventListener("change",t),()=>Ue.removeEventListener("change",t)},[]),n}const uo=s.memo(function({terminal:e}){const t=co(),o=A(N=>N.splitTerminal),a=A(N=>N.token),c=A(N=>N.toggleChat),i=A(N=>N.togglePlan),{chatOpen:d,planOpen:l}=e.panels,f=s.useCallback(async N=>{let P;if(a)try{P=await Gr(a,e.id)}catch{}o(e.id,N,P)},[a,e.id,o]),m=s.useRef(null),p=s.useRef(null),h=s.useRef(null),[v,C]=s.useState(!1),[$,L]=s.useState(0),[T,g]=s.useState(!1),[z,R]=s.useState(!1),[W,D]=s.useState(!1),[U,H]=s.useState([]),[F,j]=s.useState(""),[S,_]=s.useState([]),[k,G]=s.useState(!1),Y=s.useRef(null),J=s.useRef(null),M=s.useRef(null),[B,X]=s.useState(()=>{const N=localStorage.getItem(`plan-width-${e.id}`);if(N){const P=Number(N);if(Number.isFinite(P)&&P>=20&&P<=80)return P}return 50}),O=s.useRef(B);if(B!==O.current){O.current=B;try{localStorage.setItem(`plan-width-${e.id}`,String(Math.round(B)))}catch{}}const[K,re]=s.useState(()=>{const N=localStorage.getItem(`doc-height-${e.id}`);if(N){const P=Number(N);if(Number.isFinite(P)&&P>=15&&P<=60)return P}return 35}),ne=s.useRef(K);if(K!==ne.current){ne.current=K;try{localStorage.setItem(`doc-height-${e.id}`,String(Math.round(K)))}catch{}}const be=async N=>{const P=N.target.files;if(!(!P||P.length===0||!a)){C(!0),L(0);try{await Yr(a,e.id,P,V=>{L(V)})}catch(V){alert(`Upload failed: ${V instanceof Error?V.message:"Unknown error"}`)}finally{C(!1),L(0),m.current&&(m.current.value="")}}},Ce=s.useRef(void 0),Te=s.useCallback(N=>{if(p.current){const P=N.replace(/\r?\n/g," ").trimEnd();p.current.sendInput(P),Ce.current=window.setTimeout(()=>{var V;return(V=p.current)==null?void 0:V.sendInput("\r")},50)}},[]);s.useEffect(()=>()=>{Ce.current&&clearTimeout(Ce.current)},[]);const Be=s.useCallback(async()=>{if(a){G(!0),D(!0);try{const N=await ke(a,e.id);j(N.cwd),H(N.files),_([])}catch{D(!1)}finally{G(!1)}}},[a,e.id]),ve=s.useCallback(async N=>{if(a){G(!0);try{const P=await ke(a,e.id,N);_(V=>[...V,F]),j(N),H(P.files)}catch{}finally{G(!1)}}},[a,e.id,F]),ge=s.useCallback(async()=>{if(!a||S.length===0)return;const N=S[S.length-1];G(!0);try{const P=await ke(a,e.id,N);_(V=>V.slice(0,-1)),j(N),H(P.files)}catch{}finally{G(!1)}},[a,e.id,S]),Ie=s.useCallback(async N=>{if(a)try{await Qr(a,e.id,N)}catch(P){alert(`Download failed: ${P instanceof Error?P.message:"Unknown error"}`)}},[a,e.id]);s.useEffect(()=>{if(!W)return;const N=ie=>{ie.key==="Escape"&&D(!1)},P=ie=>{Y.current&&!Y.current.contains(ie.target)&&D(!1)};document.addEventListener("keydown",N);const V=setTimeout(()=>document.addEventListener("mousedown",P),50);return()=>{document.removeEventListener("keydown",N),document.removeEventListener("mousedown",P),clearTimeout(V)}},[W]);const me=s.useCallback(N=>{if(p.current){const P=N.replace(/\r?\n/g," ").trimEnd();p.current.sendInput(P),setTimeout(()=>{var V;return(V=p.current)==null?void 0:V.sendInput("\r")},50)}},[]),Q=s.useCallback(N=>{N&&h.current&&h.current.fillContent(N)},[]),Ae=s.useCallback(N=>{N.preventDefault();const P=J.current;if(!P)return;const V=P.getBoundingClientRect(),ie=V.height-24;document.body.classList.add("resizing-panes-v");const te=we=>{const Ne=(we.clientY-V.top-24)/ie*100,ze=Math.min(85,Math.max(40,Ne));re(100-ze)},ye=()=>{document.body.classList.remove("resizing-panes-v"),document.removeEventListener("mousemove",te),document.removeEventListener("mouseup",ye)};document.addEventListener("mousemove",te),document.addEventListener("mouseup",ye)},[]),he=s.useCallback(N=>{N.preventDefault();const P=M.current;if(!P)return;const V=P.getBoundingClientRect(),ie=V.width;document.body.classList.add("resizing-panes");const te=we=>{const Re=(we.clientX-V.left)/ie*100,Ne=Math.min(80,Math.max(20,Re));X(Ne)},ye=()=>{document.body.classList.remove("resizing-panes"),document.removeEventListener("mousemove",te),document.removeEventListener("mouseup",ye)};document.addEventListener("mousemove",te),document.addEventListener("mouseup",ye)},[]);return r.jsxs("div",{ref:J,style:{display:"flex",flexDirection:"column",height:"100%",minWidth:0,minHeight:0},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"3px 10px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",flexShrink:0,height:"24px"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"5px"},children:[r.jsx("span",{style:{display:"inline-block",width:"6px",height:"6px",borderRadius:"50%",backgroundColor:e.connected?"var(--accent-green)":"var(--accent-red)"}}),r.jsxs("span",{style:{fontSize:"12px",color:"var(--text-secondary)"},children:[e.id,e.connected?e.sessionResumed?" (resumed)":"":" (disconnected)"]})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[r.jsx("input",{ref:m,type:"file",multiple:!0,style:{display:"none"},onChange:be}),r.jsx("button",{className:"pane-btn",onClick:()=>{var N;return(N=m.current)==null?void 0:N.click()},disabled:v,style:v?{color:"var(--accent-yellow)"}:void 0,title:v?`Uploading ${$}%`:"Upload files","aria-label":"Upload files",children:v?`${$}%`:"↑"}),r.jsxs("div",{style:{position:"relative"},children:[r.jsx("button",{className:"pane-btn",onClick:Be,disabled:T,style:T?{color:"var(--accent-yellow)"}:void 0,title:T?"Downloading...":"Download files","aria-label":"Download files",children:T?"...":"↓"}),W&&r.jsxs("div",{ref:Y,style:{position:"absolute",top:"100%",right:0,marginTop:4,width:300,maxHeight:360,backgroundColor:"var(--bg-primary)",border:"1px solid var(--border)",borderRadius:6,boxShadow:"0 4px 16px rgba(0,0,0,0.3)",zIndex:100,display:"flex",flexDirection:"column",overflow:"hidden"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"6px 8px",borderBottom:"1px solid var(--border)",backgroundColor:"var(--bg-secondary)",flexShrink:0},children:[S.length>0&&r.jsx("button",{className:"pane-btn",onClick:ge,disabled:k,style:{fontSize:11,flexShrink:0},title:"Go back",children:".."}),r.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left",flex:1},children:F.split("/").slice(-2).join("/")||F}),r.jsx("button",{className:"pane-btn",onClick:()=>D(!1),style:{fontSize:11,flexShrink:0},title:"Close",children:"×"})]}),r.jsx("div",{style:{flex:1,overflowY:"auto",padding:"2px 0"},children:k?r.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12},children:"Loading..."}):U.length===0?r.jsx("div",{style:{padding:"12px",textAlign:"center",color:"var(--text-secondary)",fontSize:12,fontStyle:"italic"},children:"Empty directory"}):U.map(N=>r.jsxs("div",{onClick:()=>{const P=F+"/"+N.name;N.type==="directory"?ve(P):Ie(P)},style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",cursor:"pointer",fontSize:12,color:"var(--text-primary)",transition:"background-color 0.1s"},onMouseEnter:P=>{P.currentTarget.style.backgroundColor="var(--bg-secondary)"},onMouseLeave:P=>{P.currentTarget.style.backgroundColor="transparent"},children:[r.jsx("span",{style:{flexShrink:0,fontSize:13},children:N.type==="directory"?"📁":eo(N.name,N.type)}),r.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.name}),N.type==="directory"?r.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:"›"}):N.size!=null?r.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",flexShrink:0},children:ln(N.size)}):null]},N.name))}),r.jsx("div",{style:{borderTop:"1px solid var(--border)",padding:"6px 8px",flexShrink:0,backgroundColor:"var(--bg-secondary)"},children:r.jsx("button",{className:"pane-btn",onClick:async()=>{g(!0),D(!1);try{await Zr(a||"",e.id)}catch(N){alert(`Download failed: ${N instanceof Error?N.message:"Unknown error"}`)}finally{g(!1)}},style:{fontSize:11,color:"var(--accent-blue)",width:"100%",textAlign:"center"},title:"Download entire CWD as tar.gz",children:"Download All (tar.gz)"})})]})]}),r.jsx("button",{className:`pane-btn${d?" pane-btn--active":""}`,onClick:()=>c(e.id),title:"Toggle Chat panel","aria-label":"Toggle Chat panel",children:"Chat"}),r.jsx("button",{className:`pane-btn${l?" pane-btn--active":""}`,onClick:()=>i(e.id),title:"Toggle Task annotation panel","aria-label":"Toggle Task annotation panel",children:"Task"}),r.jsx("button",{className:"pane-btn",onClick:()=>f(t?"vertical":"horizontal"),title:t?"Split vertical (screen too narrow for horizontal)":"Split horizontal (left/right)","aria-label":"Split horizontal",children:"|"}),r.jsx("button",{className:"pane-btn",onClick:()=>f("vertical"),title:"Split vertical (top/bottom)","aria-label":"Split vertical",children:"─"})]})]}),r.jsxs("div",{ref:M,style:{flex:1,display:"flex",flexDirection:"row",overflow:"hidden",minHeight:0},children:[l&&r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{width:`${B}%`,minWidth:200,flexShrink:0,overflow:"hidden"},children:r.jsx(oo,{sessionId:e.id,token:a||"",connected:e.connected,onRequestFileStream:N=>{var P;return(P=p.current)==null?void 0:P.requestFileStream(N)},onCancelFileStream:()=>{var N;return(N=p.current)==null?void 0:N.cancelFileStream()},onForwardToChat:Q,onSendToTerminal:me})}),r.jsx("div",{className:"md-editor-divider-h",onMouseDown:he,style:{width:"2px",flexShrink:0,cursor:"col-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:N=>{N.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:N=>{N.currentTarget.style.backgroundColor="var(--border)"}})]}),r.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[r.jsxs("div",{style:{flex:1,overflow:"hidden",position:"relative",minWidth:80},children:[r.jsx(Dr,{ref:p,sessionId:e.id}),!e.connected&&r.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"var(--bg-secondary)",opacity:.85,zIndex:2,pointerEvents:"none"},children:r.jsx("span",{style:{color:"var(--text-secondary)",fontSize:"13px",fontStyle:"italic"},children:"Connecting..."})})]}),d&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"md-editor-divider",onMouseDown:Ae}),r.jsxs("div",{style:{height:`${K}%`,minHeight:80,flexShrink:0,overflow:"hidden",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[r.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 8px",height:"22px",flexShrink:0,backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)"},children:r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[r.jsx("span",{style:{fontSize:"11px",color:"var(--accent-blue)",fontWeight:500},children:"Chat"}),r.jsx("button",{className:"pane-btn",onClick:()=>{var N;return(N=h.current)==null?void 0:N.send()},disabled:!z,title:"Send to terminal (Ctrl+Enter)",style:z?{color:"var(--accent-green)"}:{opacity:.4,cursor:"default"},children:"Send"}),r.jsx("span",{style:{fontSize:"9px",color:"var(--text-secondary)"},children:"Ctrl+Enter"})]})}),r.jsx("div",{style:{flex:1,overflow:"hidden"},children:r.jsx(io,{ref:h,onSend:Te,onContentChange:R,sessionId:e.id,token:a||""})})]})]})]})]}),e.error&&r.jsx("div",{style:{padding:"2px 8px",backgroundColor:"var(--bg-secondary)",borderTop:"1px solid var(--accent-red)",color:"var(--accent-red)",fontSize:"11px",flexShrink:0},children:e.error})]})});class un extends s.Component{constructor(){super(...arguments);Ct(this,"state",{hasError:!1,error:null})}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,o){}render(){var t,o;return this.state.hasError?this.props.inline?r.jsxs("div",{style:{height:"100%",backgroundColor:"var(--bg-primary)",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:"8px",color:"var(--text-bright)",fontFamily:"monospace",padding:"16px"},children:[r.jsx("div",{style:{fontSize:"14px",color:"var(--accent-red)"},children:"Pane crashed"}),r.jsx("div",{style:{fontSize:"12px",color:"var(--text-secondary)",textAlign:"center"},children:((t=this.state.error)==null?void 0:t.message)||"An unexpected error occurred"}),r.jsx("button",{onClick:()=>this.setState({hasError:!1,error:null}),style:{background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-bright)",padding:"4px 12px",borderRadius:"4px",cursor:"pointer",fontSize:"12px"},children:"Retry"})]}):r.jsxs("div",{style:{minHeight:"100vh",backgroundColor:"var(--bg-primary)",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:"16px",color:"var(--text-bright)",fontFamily:"monospace"},children:[r.jsx("div",{style:{fontSize:"18px",color:"var(--accent-red)"},children:"Something went wrong"}),r.jsx("div",{style:{fontSize:"13px",color:"var(--text-secondary)",maxWidth:"500px",textAlign:"center"},children:((o=this.state.error)==null?void 0:o.message)||"An unexpected error occurred"}),r.jsx("button",{onClick:()=>window.location.reload(),style:{background:"linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-purple) 100%)",border:"none",color:"var(--bg-primary)",padding:"8px 24px",borderRadius:"6px",cursor:"pointer",fontSize:"14px",fontWeight:"bold"},children:"Reload"})]}):this.props.children}}const fo=4,Ut=10;function po(){const n=A(a=>a.layout),e=A(a=>a.terminalIds.length),t=A(a=>a.addTerminal);if(!n)return r.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",backgroundColor:"var(--bg-primary)"},children:r.jsx("button",{onClick:()=>t(),style:{background:"none",border:"1px dashed var(--border)",color:"var(--text-secondary)",padding:"16px 32px",borderRadius:"8px",cursor:"pointer",fontSize:"14px"},children:"+ Add Terminal"})});const o=e>1;return r.jsx("div",{style:{height:"100%",width:"100%",overflow:"hidden"},children:r.jsx(fn,{node:n,canClose:o})})}const fn=s.memo(function({node:e,canClose:t}){return e.type==="leaf"?r.jsx(mo,{terminalId:e.terminalId,canClose:t}):r.jsx(ho,{node:e,canClose:t})}),mo=s.memo(function({terminalId:e,canClose:t}){const o=A(a=>a.terminalsMap[e]);return o?r.jsx(un,{inline:!0,children:r.jsx(uo,{terminal:o,canClose:t})}):null}),ho=s.memo(function({node:e,canClose:t}){const o=A(f=>f.setSplitSizes),a=s.useRef(null),c=e.direction==="horizontal",i=s.useRef(e.sizes);i.current=e.sizes;const d=s.useCallback((f,m)=>{m.preventDefault();const p=c?"resizing-panes":"resizing-panes-v";document.body.classList.add(p);const h=c?m.clientX:m.clientY,v=[...i.current],C=a.current,$=c?(C==null?void 0:C.clientWidth)||1:(C==null?void 0:C.clientHeight)||1;let L=null;const T=z=>{L||(L=requestAnimationFrame(()=>{L=null;const D=((c?z.clientX:z.clientY)-h)/$*100,U=v[f]+D,H=v[f+1]-D;if(U>=Ut&&H>=Ut){const F=[...v];F[f]=U,F[f+1]=H,o(e.id,F)}}))},g=()=>{L&&cancelAnimationFrame(L),document.body.classList.remove(p),document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",g)};document.addEventListener("mousemove",T),document.addEventListener("mouseup",g)},[c,e.id,o]),l=[];return e.children.forEach((f,m)=>{const p=f.type==="leaf"?f.terminalId:f.id;l.push(r.jsx("div",{style:{flex:`${e.sizes[m]} 0 0`,minWidth:0,minHeight:0,overflow:"hidden"},children:r.jsx(fn,{node:f,canClose:t})},p)),m<e.children.length-1&&l.push(r.jsx("div",{onMouseDown:h=>d(m,h),style:{flex:`0 0 ${fo}px`,cursor:c?"col-resize":"row-resize",backgroundColor:"var(--border)",transition:"background-color 0.15s"},onMouseEnter:h=>{h.currentTarget.style.backgroundColor="var(--accent-blue)"},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="var(--border)"}},`divider-${e.id}-${m}`))}),r.jsx("div",{ref:a,style:{display:"flex",flexDirection:c?"row":"column",height:"100%",width:"100%",overflow:"hidden"},children:l})});function bo({tabId:n}){const e=A(j=>j.tabs.find(S=>S.id===n)),t=A(j=>j.activeTabId),o=A(j=>j.switchTab),a=A(j=>j.closeTab),c=A(j=>j.reopenTab),i=A(j=>j.deleteTab),d=A(j=>j.renameTab),l=A(j=>e?e.terminalIds.map(S=>{const _=j.terminalsMap[S];return _?{id:S,connected:_.connected}:{id:S,connected:!1}}):[]),f=A(j=>j.killServerSession),[m,p]=s.useState(!1),[h,v]=s.useState(""),[C,$]=s.useState(!1),L=s.useRef(null);if(!e)return null;const T=t===n,g=e.status==="open",z=()=>{g&&o(n)},R=j=>{g&&(j.stopPropagation(),v(e.name),p(!0),setTimeout(()=>{var S;return(S=L.current)==null?void 0:S.focus()},0))},W=()=>{const j=h.trim();j&&d(n,j),p(!1)},D=j=>{j.stopPropagation(),c(n)},U=j=>{j.stopPropagation(),a(n)},H=async j=>{j.stopPropagation(),window.confirm(`Delete tab "${e.name}"? This will kill all tmux sessions in this tab.`)&&await i(n)},F=j=>{j.stopPropagation(),$(!C)};return r.jsxs("div",{children:[r.jsxs("div",{onClick:z,style:{padding:"8px 12px",cursor:g?"pointer":"default",borderLeft:T?"3px solid var(--accent-blue)":"3px solid transparent",backgroundColor:T?"rgba(122, 162, 247, 0.08)":"transparent",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s",opacity:g?1:.5},onMouseEnter:j=>{g&&!T&&(j.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)")},onMouseLeave:j=>{T||(j.currentTarget.style.backgroundColor="transparent")},children:[g&&e.terminalIds.length>0&&r.jsx("button",{onClick:F,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"10px",padding:0,width:14,height:14,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:C?"▼":"▶"}),r.jsxs("div",{style:{flex:1,minWidth:0},children:[m?r.jsx("input",{ref:L,value:h,onChange:j=>v(j.target.value),onBlur:W,onKeyDown:j=>{j.key==="Enter"&&W(),j.key==="Escape"&&p(!1)},style:{width:"100%",background:"var(--bg-primary)",border:"1px solid var(--accent-blue)",color:"var(--text-bright)",borderRadius:"3px",padding:"1px 4px",fontSize:"14px",outline:"none"}}):r.jsx("div",{onDoubleClick:R,style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:g?"Double-click to rename":e.name,children:e.name}),r.jsxs("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:[e.terminalIds.length," terminal",e.terminalIds.length!==1?"s":""," · ",cn(Math.floor(e.createdAt/1e3))]})]}),g?r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:U,style:{flexShrink:0},title:"Close tab",children:"×"}):r.jsxs("div",{style:{display:"flex",gap:"4px",flexShrink:0},children:[r.jsx("button",{className:"pane-btn",onClick:D,title:"Reopen tab",style:{fontSize:"11px",padding:"2px 6px"},children:"↻"}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:H,title:"Delete tab",children:"×"})]})]}),g&&C&&l.length>0&&r.jsx("div",{style:{paddingLeft:"28px",backgroundColor:"rgba(0, 0, 0, 0.2)"},children:l.map(j=>r.jsxs("div",{style:{padding:"4px 8px",fontSize:"11px",color:"var(--text-secondary)",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center"},title:`Connected: ${j.connected}`,children:[r.jsx("span",{style:{fontFamily:"monospace"},children:j.id}),r.jsx("span",{style:{marginLeft:"8px",color:j.connected?"var(--accent-green)":"var(--accent-red)"},children:j.connected?"●":"○"}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:S=>{S.stopPropagation(),window.confirm(`Close terminal "${j.id}"?`)&&f(j.id)},style:{marginLeft:"auto",flexShrink:0},title:"Close terminal",children:"×"})]},j.id))})]})}function xo({sessionId:n,active:e,createdAt:t}){const o=A(d=>d.addTerminal),a=A(d=>d.killServerSession),c=()=>{o("horizontal",n)},i=d=>{d.stopPropagation(),window.confirm(`Delete orphaned session "${n}"? This will kill the tmux session.`)&&a(n)};return r.jsxs("div",{onClick:c,style:{padding:"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid var(--border)",transition:"background-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.backgroundColor="rgba(122, 162, 247, 0.05)"},onMouseLeave:d=>{d.currentTarget.style.backgroundColor="transparent"},children:[r.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:e?"var(--accent-green)":"var(--text-secondary)",flexShrink:0}}),r.jsxs("div",{style:{flex:1,minWidth:0},children:[r.jsx("div",{style:{color:"var(--text-bright)",fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n}),r.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"11px",marginTop:"2px"},children:cn(t)})]}),r.jsx("button",{className:"pane-btn pane-btn--danger",onClick:i,style:{flexShrink:0},title:"Delete session",children:"×"})]})}function go(){const n=A(l=>l.sidebarOpen),e=A(l=>l.toggleSidebar),t=A(l=>l.fetchSessions),o=A(l=>n?l.serverSessions:[]),a=A(l=>n?l.tabs:[]),c=A(l=>l.terminalIds.length),i=new Set(a.flatMap(l=>l.terminalIds)),d=o.filter(l=>!i.has(l.sessionId));return s.useEffect(()=>{if(!n)return;t();let l=setInterval(t,5e3);const f=()=>{document.hidden?l&&(clearInterval(l),l=null):(t(),l||(l=setInterval(t,5e3)))};return document.addEventListener("visibilitychange",f),()=>{l&&clearInterval(l),document.removeEventListener("visibilitychange",f)}},[n,t]),s.useEffect(()=>{if(!n)return;const l=setTimeout(t,800);return()=>clearTimeout(l)},[c,n,t]),r.jsxs("div",{className:"session-sidebar",style:{width:n?280:0,height:"100%",backgroundColor:"var(--bg-secondary)",borderLeft:n?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,overflow:"hidden",transition:"width 0.2s ease"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[r.jsx("span",{style:{color:"var(--accent-blue)",fontSize:"14px",fontWeight:"bold"},children:"Tabs & Terminals"}),r.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:"16px",padding:"0 4px",lineHeight:1},title:"Close sidebar",children:"×"})]}),r.jsxs("div",{style:{flex:1,overflowY:"auto"},children:[r.jsxs("div",{children:[r.jsx("div",{style:{padding:"8px 12px",color:"var(--accent-blue)",fontSize:"12px",fontWeight:"bold",backgroundColor:"rgba(122, 162, 247, 0.05)",borderBottom:"1px solid var(--border)"},children:"Tabs"}),a.length===0?r.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"14px",textAlign:"center",padding:"12px"},children:"No tabs"}):a.map(l=>r.jsx(bo,{tabId:l.id},l.id))]}),d.length>0&&r.jsxs("div",{style:{marginTop:"16px"},children:[r.jsx("div",{style:{padding:"8px 12px",color:"var(--accent-yellow)",fontSize:"12px",fontWeight:"bold",backgroundColor:"rgba(224, 175, 104, 0.05)",borderBottom:"1px solid var(--border)"},children:"ORPHANED SESSIONS"}),d.map(l=>r.jsx(xo,{sessionId:l.sessionId,active:l.active,createdAt:l.createdAt},l.sessionId))]})]})]})}const pn=gt.memo(()=>{const n=A(R=>R.tabs),e=A(R=>R.activeTabId),t=A(R=>R.addTab),o=A(R=>R.switchTab),a=A(R=>R.closeTab),c=A(R=>R.renameTab),[i,d]=s.useState(null),[l,f]=s.useState(""),m=s.useRef(null),p=n.filter(R=>R.status==="open");s.useEffect(()=>{i&&m.current&&(m.current.focus(),m.current.select())},[i]);const h=R=>{d(R.id),f(R.name)},v=()=>{i&&l.trim()&&c(i,l.trim()),d(null),f("")},C=()=>{d(null),f("")},$=R=>{R.key==="Enter"?v():R.key==="Escape"&&C()},L=R=>{i||o(R)},T=(R,W)=>{R.stopPropagation(),a(W)},g=(R,W)=>{R.button===1&&(R.preventDefault(),a(W))},z=p.length>1;return r.jsxs("div",{className:"tab-bar",children:[p.map(R=>{const W=R.id===e,D=i===R.id,U=R.terminalIds.length;return r.jsx("div",{className:`tab-item ${W?"tab-item--active":""}`,onClick:()=>L(R.id),onDoubleClick:()=>h(R),onMouseDown:H=>g(H,R.id),children:D?r.jsx("input",{ref:m,type:"text",value:l,onChange:H=>f(H.target.value),onBlur:v,onKeyDown:$,className:"tab-item__rename-input"}):r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"tab-item__name",children:[R.name," ",U>0&&`(${U})`]}),z&&r.jsx("button",{className:"tab-item__close",onClick:H=>T(H,R.id),title:"Close tab","aria-label":"Close tab",children:"×"})]})},R.id)}),r.jsx("button",{className:"tab-bar-add",onClick:()=>t(),title:"New tab","aria-label":"Add new tab",children:"+"})]})});pn.displayName="TabBar";function yo(){return localStorage.getItem("ai-cli-online-token")}function vo(){const n=A(m=>m.token),e=A(m=>m.setToken),t=A(m=>m.tabs),o=A(m=>m.addTab),a=A(m=>m.toggleSidebar),c=A(m=>m.fontSize),i=A(m=>m.setFontSize),d=A(m=>m.tabsLoading),l=A(m=>m.theme),f=A(m=>m.toggleTheme);return s.useEffect(()=>{const m=yo();m&&!n&&e(m)},[]),s.useEffect(()=>{n&&!d&&t.filter(m=>m.status==="open").length===0&&o("Default")},[n,d]),n?r.jsxs("div",{style:{height:"100vh",display:"flex",flexDirection:"column",backgroundColor:"var(--bg-primary)"},children:[r.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 16px",backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border)",flexShrink:0},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[r.jsx("span",{style:{fontSize:"15px",fontWeight:"bold",color:"var(--accent-blue)",letterSpacing:"0.5px"},children:"AI-Cli Online"}),r.jsxs("span",{style:{fontSize:"11px",color:"var(--text-secondary)",fontWeight:400},children:["v","2.9.4"]})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"1px 4px",borderRadius:"6px",backgroundColor:"rgba(0,0,0,0.2)"},children:[r.jsx("button",{className:"header-btn",onClick:()=>i(c-1),disabled:c<=10,title:"Decrease font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A−"}),r.jsx("span",{style:{fontSize:"11px",color:"var(--text-primary)",minWidth:"20px",textAlign:"center"},children:c}),r.jsx("button",{className:"header-btn",onClick:()=>i(c+1),disabled:c>=24,title:"Increase font size",style:{fontSize:"11px",padding:"1px 5px",minWidth:0},children:"A+"})]}),r.jsx(So,{}),r.jsx("button",{className:"header-btn",onClick:f,title:`Switch to ${l==="dark"?"light":"dark"} mode`,"aria-label":"Toggle theme",children:l==="dark"?"☀":"🌙"}),r.jsx("button",{className:"header-btn",onClick:a,title:"Toggle Tabs & Terminals Sidebar","aria-label":"Toggle sidebar",children:"☰"}),r.jsx("button",{className:"header-btn header-btn--muted",onClick:()=>{window.confirm("Logout will close all terminals. Continue?")&&e(null)},children:"Logout"})]})]}),r.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[r.jsx("main",{style:{flex:1,overflow:"hidden"},children:r.jsx(po,{})}),r.jsx(go,{})]}),r.jsx(pn,{})]}):r.jsx(fr,{})}const wo=[1,2,3,4];function So(){const n=A(o=>o.latency);if(n===null)return r.jsx("span",{style:{fontSize:"10px",color:"var(--scrollbar-thumb-hover)"},title:"Measuring latency...",children:"--ms"});let e,t;return n<50?(e="var(--accent-green)",t=4):n<150?(e="var(--accent-yellow)",t=3):n<300?(e="var(--accent-orange)",t=2):(e="var(--accent-red)",t=1),r.jsxs("span",{style:{display:"inline-flex",alignItems:"end",gap:"1.5px",padding:"2px 8px",borderRadius:"10px",backgroundColor:"rgba(0,0,0,0.2)"},title:`Latency: ${n}ms`,children:[wo.map(o=>r.jsx("span",{style:{display:"inline-block",width:"2.5px",height:`${3+o*2}px`,backgroundColor:o<=t?e:"var(--border)",borderRadius:"1px",transition:"background-color 0.3s ease"}},o)),r.jsxs("span",{style:{fontSize:"10px",color:e,marginLeft:"4px",fontWeight:500},children:[n,"ms"]})]})}mt.createRoot(document.getElementById("root")).render(r.jsx(gt.StrictMode,{children:r.jsx(un,{children:r.jsx(vo,{})})}));
|
package/web/dist/index.html
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<!-- LXGW WenKai Mono (中文等宽字体, CDN unicode-range 按需加载) -->
|
|
11
11
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lxgw-wenkai-webfont@1.7.0/lxgwwenkaimono-regular.css" />
|
|
12
12
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lxgw-wenkai-webfont@1.7.0/lxgwwenkaimono-bold.css" />
|
|
13
|
-
<script type="module" crossorigin src="/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/assets/index-BHcKdCrR.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">
|