aicodeman 0.8.0 → 0.8.1

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.
Files changed (76) hide show
  1. package/dist/mux-interface.d.ts +6 -2
  2. package/dist/mux-interface.d.ts.map +1 -1
  3. package/dist/session-cli-builder.d.ts +16 -2
  4. package/dist/session-cli-builder.d.ts.map +1 -1
  5. package/dist/session-cli-builder.js +21 -1
  6. package/dist/session-cli-builder.js.map +1 -1
  7. package/dist/session.d.ts +6 -1
  8. package/dist/session.d.ts.map +1 -1
  9. package/dist/session.js +23 -6
  10. package/dist/session.js.map +1 -1
  11. package/dist/tmux-manager.d.ts.map +1 -1
  12. package/dist/tmux-manager.js +35 -5
  13. package/dist/tmux-manager.js.map +1 -1
  14. package/dist/types/session.d.ts +12 -0
  15. package/dist/types/session.d.ts.map +1 -1
  16. package/dist/types/session.js +10 -1
  17. package/dist/types/session.js.map +1 -1
  18. package/dist/web/public/api-client.3adebdc2.js.gz +0 -0
  19. package/dist/web/public/app.d044eb65.js.gz +0 -0
  20. package/dist/web/public/constants.cb6426c4.js.gz +0 -0
  21. package/dist/web/public/image-input.7cade6a8.js.gz +0 -0
  22. package/dist/web/public/index.html +5 -4
  23. package/dist/web/public/index.html.br +0 -0
  24. package/dist/web/public/index.html.gz +0 -0
  25. package/dist/web/public/input-cjk.88082175.js.gz +0 -0
  26. package/dist/web/public/keyboard-accessory.cdfd8c04.js.gz +0 -0
  27. package/dist/web/public/mobile-handlers.1e2a8ef8.js.gz +0 -0
  28. package/dist/web/public/mobile.26dc30d6.css.gz +0 -0
  29. package/dist/web/public/notification-manager.9c984ac2.js.gz +0 -0
  30. package/dist/web/public/orchestrator-panel.js.gz +0 -0
  31. package/dist/web/public/panels-ui.cf998835.js.gz +0 -0
  32. package/dist/web/public/ralph-panel.61076370.js.gz +0 -0
  33. package/dist/web/public/{ralph-wizard.6b0f0be7.js → ralph-wizard.52d533d2.js} +4 -4
  34. package/dist/web/public/ralph-wizard.52d533d2.js.br +0 -0
  35. package/dist/web/public/{ralph-wizard.6b0f0be7.js.gz → ralph-wizard.52d533d2.js.gz} +0 -0
  36. package/dist/web/public/respawn-ui.5377f958.js.gz +0 -0
  37. package/dist/web/public/session-ui.3e0cf024.js +36 -0
  38. package/dist/web/public/session-ui.3e0cf024.js.br +0 -0
  39. package/dist/web/public/session-ui.3e0cf024.js.gz +0 -0
  40. package/dist/web/public/settings-ui.25a18120.js.gz +0 -0
  41. package/dist/web/public/styles.42be1d59.css.gz +0 -0
  42. package/dist/web/public/subagent-windows.a366a4ad.js.gz +0 -0
  43. package/dist/web/public/sw.js.gz +0 -0
  44. package/dist/web/public/terminal-ui.37caa926.js +3 -0
  45. package/dist/web/public/terminal-ui.37caa926.js.br +0 -0
  46. package/dist/web/public/terminal-ui.37caa926.js.gz +0 -0
  47. package/dist/web/public/upload.html.gz +0 -0
  48. package/dist/web/public/vendor/marked.min.js.gz +0 -0
  49. package/dist/web/public/vendor/xterm-addon-fit.min.js.gz +0 -0
  50. package/dist/web/public/vendor/xterm-addon-unicode11.min.js.gz +0 -0
  51. package/dist/web/public/vendor/xterm-addon-webgl.min.js.gz +0 -0
  52. package/dist/web/public/vendor/xterm-zerolag-input.137ad9f0.js.gz +0 -0
  53. package/dist/web/public/vendor/xterm.css.gz +0 -0
  54. package/dist/web/public/vendor/xterm.min.js.gz +0 -0
  55. package/dist/web/public/voice-input.085e9e73.js.gz +0 -0
  56. package/dist/web/routes/ralph-routes.d.ts.map +1 -1
  57. package/dist/web/routes/ralph-routes.js +2 -1
  58. package/dist/web/routes/ralph-routes.js.map +1 -1
  59. package/dist/web/routes/session-routes.d.ts.map +1 -1
  60. package/dist/web/routes/session-routes.js +3 -1
  61. package/dist/web/routes/session-routes.js.map +1 -1
  62. package/dist/web/schemas.d.ts +24 -0
  63. package/dist/web/schemas.d.ts.map +1 -1
  64. package/dist/web/schemas.js +13 -0
  65. package/dist/web/schemas.js.map +1 -1
  66. package/dist/web/server.d.ts.map +1 -1
  67. package/dist/web/server.js +3 -0
  68. package/dist/web/server.js.map +1 -1
  69. package/package.json +1 -1
  70. package/dist/web/public/ralph-wizard.6b0f0be7.js.br +0 -0
  71. package/dist/web/public/session-ui.f1555cd1.js +0 -36
  72. package/dist/web/public/session-ui.f1555cd1.js.br +0 -0
  73. package/dist/web/public/session-ui.f1555cd1.js.gz +0 -0
  74. package/dist/web/public/terminal-ui.7616b9fd.js +0 -3
  75. package/dist/web/public/terminal-ui.7616b9fd.js.br +0 -0
  76. package/dist/web/public/terminal-ui.7616b9fd.js.gz +0 -0
@@ -1,3 +0,0 @@
1
- "use strict";Object.assign(CodemanApp.prototype,{initTerminal(){const e=parseInt(localStorage.getItem("codeman-scrollback")),i=Number.isFinite(e)&&e>0?Math.max(e,DEFAULT_SCROLLBACK):DEFAULT_SCROLLBACK;if(this.terminal=new Terminal({theme:{background:"#0d0d0d",foreground:"#e0e0e0",cursor:"#e0e0e0",cursorAccent:"#0d0d0d",selection:"rgba(255, 255, 255, 0.3)",black:"#0d0d0d",red:"#ff6b6b",green:"#51cf66",yellow:"#ffd43b",blue:"#339af0",magenta:"#cc5de8",cyan:"#22b8cf",white:"#e0e0e0",brightBlack:"#495057",brightRed:"#ff8787",brightGreen:"#69db7c",brightYellow:"#ffe066",brightBlue:"#5c7cfa",brightMagenta:"#da77f2",brightCyan:"#66d9e8",brightWhite:"#ffffff"},fontFamily:'"Fira Code", "Cascadia Code", "JetBrains Mono", "SF Mono", Monaco, monospace',fontSize:MobileDetection.getDeviceType()==="mobile"?10:14,lineHeight:1.2,cursorBlink:!1,cursorStyle:"block",scrollback:i,allowTransparency:!0,allowProposedApi:!0}),this.fitAddon=new FitAddon.FitAddon,this.terminal.loadAddon(this.fitAddon),typeof Unicode11Addon<"u")try{const t=new Unicode11Addon.Unicode11Addon;this.terminal.loadAddon(t),this.terminal.unicode.activeVersion="11"}catch{}const s=document.getElementById("terminalContainer");this.terminal.open(s),this.terminal.attachCustomKeyEventHandler(t=>{if(t.isComposing||t.keyCode===229||t.altKey&&t.key>="0"&&t.key<="9")return!1;if((t.ctrlKey||t.metaKey)&&t.key==="v"&&t.type==="keydown")return this.activeSessionId&&this._handleImagePaste&&this._handleImagePaste(),!1;if(t.key==="Enter"&&(t.shiftKey||t.ctrlKey)&&t.type==="keydown"){if(this.activeSessionId)if(this._localEchoEnabled){const r=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._localEchoOverlay?.suppressBufferDetection(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),r&&(this._pendingInput+=r,p()),setTimeout(()=>{fetch(`/api/sessions/${this.activeSessionId}/send-key`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:t.ctrlKey?"C-Enter":"S-Enter"})})},r?80:0)}else fetch(`/api/sessions/${this.activeSessionId}/send-key`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:t.ctrlKey?"C-Enter":"S-Enter"})});return!1}return!0});{const t=s.querySelector(".xterm-helper-textarea");if(t&&MobileDetection.isTouchDevice()){let r=!1,u=0;t.addEventListener("compositionstart",()=>{r=!0}),t.addEventListener("compositionend",()=>{r=!1}),t.addEventListener("keydown",d=>{!d.isComposing&&d.keyCode!==229&&(u=Date.now())}),t.addEventListener("input",d=>{if(r||d.isComposing||d.inputType!=="insertText"||!d.data||Date.now()-u<50)return;const m=d.data;Promise.resolve().then(()=>{const y=t.value;!y||y.trim()===""&&m!==" "||(this.terminal._core.coreService.triggerDataEvent(m,!0),t.value="")})})}}this._webglAddon=null;const n=new URLSearchParams(location.search);if(n.get("webgl")==="force")try{localStorage.removeItem("codeman-webgl-disabled")}catch{}const l=(()=>{try{const t=localStorage.getItem("codeman-webgl-disabled");if(!t)return!1;const{at:r}=JSON.parse(t);return Date.now()-r>WEBGL_FALLBACK.STICKY_EXPIRY_MS?(localStorage.removeItem("codeman-webgl-disabled"),!1):!0}catch{return!1}})(),c=MobileDetection.getDeviceType()!=="desktop"||n.has("nowebgl")||l;if(l&&console.log("[CRASH-DIAG] WebGL sticky-disabled from prior stalls \u2014 DOM renderer in use. Re-enable: ?webgl=force"),!c)if(typeof WebglAddon<"u")this._initWebGL();else{const t=document.createElement("script");t.src="vendor/xterm-addon-webgl.min.js",t.onload=()=>this._initWebGL(),t.onerror=()=>console.warn("[CRASH-DIAG] Failed to load WebGL addon \u2014 using canvas renderer"),document.head.appendChild(t)}this._localEchoOverlay=new LocalEchoOverlay(this.terminal),this._cjkInput=null,typeof CjkInput<"u"&&(this._cjkInput=CjkInput.init({send:t=>{this.activeSessionId&&this._sendInputAsync(this.activeSessionId,t)}})),MobileDetection.getDeviceType()==="mobile"&&document.body.classList.contains("safari-browser")?requestAnimationFrame(()=>{this.fitAddon.fit(),requestAnimationFrame(()=>this.fitAddon.fit())}):this.fitAddon.fit(),this.registerFilePathLinkProvider(),s.addEventListener("wheel",t=>{t.preventDefault();const r=Math.round(t.deltaY/25)||(t.deltaY>0?1:-1);this.terminal.scrollLines(r)},{passive:!1});{const t=()=>this.terminal._core?._renderService?.dimensions?.css?.cell?.height||13;let r=0,u=0,d=0,m=null,y=!1;const _=v=>{const E=d?(v-d)/16.67:1;if(d=v,!y&&Math.abs(u)>.3){const S=Math.round(u/t());S!==0&&this.terminal.scrollLines(S),u*=.92,m=requestAnimationFrame(_)}else y?m=requestAnimationFrame(_):(m=null,u=0)};let g=0,b=!1;s.addEventListener("touchstart",v=>{v.touches.length===1&&(r=v.touches[0].clientY,u=0,g=0,y=!0,b=!1,d=0,m&&(cancelAnimationFrame(m),m=null))},{passive:!0}),s.addEventListener("touchmove",v=>{if(v.touches.length===1&&y){b=!0;const E=v.touches[0].clientY,S=r-E;g+=S,u=S*1.2,r=E;const I=t(),w=Math.trunc(g/I);w!==0&&(this.terminal.scrollLines(w),g-=w*I)}},{passive:!0}),s.addEventListener("touchend",()=>{y=!1,!m&&Math.abs(u)>.3&&(m=requestAnimationFrame(_)),!b&&this.terminal&&this.terminal.focus()},{passive:!0}),s.addEventListener("touchcancel",()=>{y=!1,u=0,g=0},{passive:!0})}this.showWelcome(),this.initImageInput(),this._chunkedWriteGen=0,this._resizeTimeout=null,this._lastResizeDims=null;const h=40,a=10,f=()=>{this._resizeTimeout&&clearTimeout(this._resizeTimeout),this._resizeTimeout=setTimeout(()=>{this._resizeTimeout=null,this.fitAddon&&this.fitAddon.fit(),this.flickerFilterBuffer&&(this.flickerFilterTimeout&&(clearTimeout(this.flickerFilterTimeout),this.flickerFilterTimeout=null),this.flushFlickerBuffer());const t=typeof KeyboardHandler<"u"&&KeyboardHandler.keyboardVisible;if(this.activeSessionId&&!t){const r=this.fitAddon.proposeDimensions(),u=r?Math.max(r.cols,h):h,d=r?Math.max(r.rows,a):a;if(!this._lastResizeDims||u!==this._lastResizeDims.cols||d!==this._lastResizeDims.rows){const m=this.activeSessionId?this.sessions.get(this.activeSessionId):null;m&&m.mode!=="shell"&&this.terminal&&this.isTerminalAtBottom()&&this.terminal.write("\x1B[3J\x1B[H\x1B[2J"),this._lastResizeDims={cols:u,rows:d},fetch(`/api/sessions/${this.activeSessionId}/resize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cols:u,rows:d})}).catch(()=>{})}}this.updateConnectionLines(),this._localEchoOverlay?.hasPending&&this._localEchoOverlay.rerender()},300)};window.addEventListener("resize",f),this.terminalResizeObserver&&this.terminalResizeObserver.disconnect(),this.terminalResizeObserver=new ResizeObserver(f),this.terminalResizeObserver.observe(s),this._pendingInput="",this._inputFlushTimeout=null,this._lastKeystrokeTime=0;const p=()=>{if(this._inputFlushTimeout=null,this._pendingInput&&this.activeSessionId){const t=this._pendingInput,r=this.activeSessionId;this._pendingInput="",this._sendInputAsync(r,t)}};this.terminal.onData(t=>{if(!(window.cjkActive||document.activeElement?.id==="cjkInput")&&this.activeSessionId){if(/^\x1b\[[\?>=]?[\d;]*[cnR]$/.test(t))return;if(this._localEchoEnabled){if(t==="\x7F"){if(this._localEchoOverlay?.removeChar()==="flushed"){const{count:d,text:m}=this._localEchoOverlay.getFlushed();this._flushedOffsets?.has(this.activeSessionId)&&(d===0?(this._flushedOffsets.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId)):(this._flushedOffsets.set(this.activeSessionId,d),this._flushedTexts?.set(this.activeSessionId,m))),this._pendingInput+=t,p()}return}if(/^[\r\n]+$/.test(t)){const u=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._localEchoOverlay?.suppressBufferDetection(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null),u&&(this._pendingInput+=u,p()),setTimeout(()=>{this._pendingInput+="\r",p()},80);return}if(t.length>1&&t.charCodeAt(0)>=32){this._localEchoOverlay?.appendText(t);return}if(t.charCodeAt(0)<32){if(t.length>1&&t.charCodeAt(0)===27){this._pendingInput+=t,p();return}if(this._restoringFlushedState){this._pendingInput+=t,p();return}if(t===" "){const d=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),d&&(this._pendingInput+=d),this._pendingInput+=t,this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null);let m="";try{const _=this._localEchoOverlay?.findPrompt?.();if(_){const g=this.terminal.buffer.active,b=g.getLine(g.viewportY+_.row);b&&(m=b.translateToString(!0).slice(_.col+2).trimEnd())}}catch{}this._tabCompletionBaseText=m,p(),this._tabCompletionSessionId=this.activeSessionId,this._tabCompletionRetries=0,this._tabCompletionFallback&&clearTimeout(this._tabCompletionFallback);const y=this;this._tabCompletionFallback=setTimeout(()=>{if(y._tabCompletionFallback=null,!y._tabCompletionSessionId||y._tabCompletionSessionId!==y.activeSessionId)return;const _=y._localEchoOverlay;!_||_.pendingText||y.terminal.write("",()=>{if(!y._tabCompletionSessionId)return;_.resetBufferDetection();const g=_.detectBufferText();g&&g!==y._tabCompletionBaseText&&(y._tabCompletionSessionId=null,y._tabCompletionRetries=0,y._tabCompletionBaseText=null,_.rerender())})},300);return}const u=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._localEchoOverlay?.suppressBufferDetection(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),u&&(this._pendingInput+=u),this._pendingInput+=t,this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null),p();return}if(t.length===1&&t.charCodeAt(0)>=32){this._localEchoOverlay?.addChar(t);return}}if(this._pendingInput+=t,t.charCodeAt(0)<32||t.length>1){this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null),p();return}const r=performance.now();r-this._lastKeystrokeTime>50?(this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null),this._lastKeystrokeTime=r,p()):(this._lastKeystrokeTime=r,this._inputFlushTimeout||(this._inputFlushTimeout=setTimeout(p,0)))}})},registerFilePathLinkProvider(){const e=this;let i=-1;this.terminal.registerLinkProvider({provideLinks(s,n){s!==i&&(i=s,console.debug("[LinkProvider] Checking line:",s));const c=e.terminal.buffer.active.getLine(s-1);if(!c){n(void 0);return}const o=c.translateToString(!0);if(!o||!o.includes("/")){n(void 0);return}const h=[],a=/https?:\/\/[^\s"'<>|;&)\]\x00-\x1f]+/g,f=(m,y)=>{const _=m.replace(/[.,;:!?)]+$/,""),g=o.indexOf(_,y);g!==-1&&(h.some(b=>b.range.start.x===g+1)||h.push({text:_,range:{start:{x:g+1,y:s},end:{x:g+_.length+1,y:s}},decorations:{pointerCursor:!0,underline:!0},activate(b,v){window.open(v,"_blank","noopener,noreferrer")}}))},p=/(tail|cat|head|less|grep|watch|vim|nano)\s+(?:[^\s\/]*\s+)*(\/[^\s"'<>|;&\n\x00-\x1f]+)/g,t=/(\/(?:home|tmp|var|etc|opt)[^\s"'<>|;&\n\x00-\x1f]*\.(?:log|txt|json|md|yaml|yml|csv|xml|sh|py|ts|js))\b/g,r=/Bash\([^)]*?(\/(?:home|tmp|var|etc|opt)[^\s"'<>|;&\)\n\x00-\x1f]+)/g,u=(m,y)=>{const _=o.indexOf(m,y);_!==-1&&(h.some(g=>g.range.start.x===_+1)||h.push({text:m,range:{start:{x:_+1,y:s},end:{x:_+m.length+1,y:s}},decorations:{pointerCursor:!0,underline:!0},activate(g,b){e.openLogViewerWindow(b,e.activeSessionId)}}))};let d;for(a.lastIndex=0;(d=a.exec(o))!==null;)f(d[0],d.index);for(p.lastIndex=0;(d=p.exec(o))!==null;)u(d[2],d.index);for(t.lastIndex=0;(d=t.exec(o))!==null;)u(d[1],d.index);for(r.lastIndex=0;(d=r.exec(o))!==null;)u(d[1],d.index);h.length>0&&console.debug("[LinkProvider] Found links:",h.map(m=>m.text)),n(h.length>0?h:void 0)}}),console.log("[LinkProvider] File path link provider registered")},showWelcome(){const e=document.getElementById("welcomeOverlay");e&&(e.classList.add("visible"),this.loadTunnelStatus(),this.loadHistorySessions())},hideWelcome(){const e=document.getElementById("welcomeOverlay");e&&e.classList.remove("visible");const i=document.getElementById("welcomeQr");i&&(clearTimeout(this._welcomeQrShrinkTimer),i.classList.remove("expanded"))},async _fetchHistorySessions(){const s=(await(await fetch("/api/history/sessions")).json()).sessions||[];if(s.length===0)return[];const n=new Map;for(const c of s){const o=c.projectKey||c.workingDir;n.has(o)||n.set(o,[]),n.get(o).push(c)}const l=[];for(const[,c]of n)l.push(...c.slice(0,3));return l.sort((c,o)=>new Date(o.lastModified)-new Date(c.lastModified)),l},_resolveCaseLabel(e,i){if(!e)return"";let s=null;for(const n of i||[])if(!(!n||!n.path)){if(e===n.path)return`#${n.name}`;if(e.startsWith(n.path+"/")){const l=n.path.length;(!s||l>s.len)&&(s={name:n.name,suffix:e.slice(l),len:l})}}return s?`#${s.name}${s.suffix}`:e.split("/").pop()||e},_shortenHomePath(e){return(e||"").replace(/^\/home\/[^/]+\//,"~/").replace(/^\/Users\/[^/]+\//,"~/")},_buildHistoryItem(e,i,s){const n=s?.showViewAll!==!1,l=e.sizeBytes<1024?`${e.sizeBytes}B`:e.sizeBytes<1048576?`${(e.sizeBytes/1024).toFixed(0)}K`:`${(e.sizeBytes/1048576).toFixed(1)}M`,c=new Date(e.lastModified),o=c.toLocaleDateString("en",{month:"short",day:"numeric"})+" "+c.toLocaleTimeString("en",{hour:"2-digit",minute:"2-digit",hour12:!1}),h=this._shortenHomePath(e.workingDir),a=this._resolveCaseLabel(e.workingDir,i),f=document.createElement("div");f.className="history-item",f.title=e.workingDir;const p=document.createElement("div");p.className="history-item-main",p.addEventListener("click",()=>this.resumeHistorySession(e.sessionId,e.workingDir));const t=document.createElement("div");t.className="history-item-text";const r=document.createElement("span");r.className="history-item-title",r.textContent=e.firstPrompt||h;const u=document.createElement("span");u.className="history-item-subtitle",a.startsWith("#")&&u.classList.add("is-case"),u.textContent=a,t.append(r,u);const d=document.createElement("span");d.className="history-item-meta",d.textContent=o;const m=document.createElement("button");m.className="history-item-expand",m.type="button",m.setAttribute("aria-label","Show details"),m.setAttribute("aria-expanded","false"),m.textContent="\u22EF",p.append(t,d,m);const y=document.createElement("div");y.className="history-item-detail",y.hidden=!0;const _=document.createElement("div");_.className="history-detail-row";const g=document.createElement("span");g.className="history-detail-label",g.textContent="Prompt";const b=document.createElement("span");b.className="history-detail-value history-detail-prompt",b.textContent=e.firstPrompt||"(no prompt captured)",_.append(g,b);const v=document.createElement("div");v.className="history-detail-row";const E=document.createElement("span");E.className="history-detail-label",E.textContent="Path";const S=document.createElement("span");S.className="history-detail-value history-detail-path",S.textContent=h,v.append(E,S);const I=document.createElement("div");if(I.className="history-detail-row history-detail-meta",I.textContent=`${o} \xB7 ${l} \xB7 ${e.sessionId.slice(0,8)}`,y.append(_,v,I),n&&e.projectKey){const w=document.createElement("div");w.className="history-detail-row history-detail-actions";const T=document.createElement("button");T.type="button",T.className="history-view-all-btn",T.textContent="View all in this folder",T.addEventListener("click",x=>{x.stopPropagation(),this.openFolderHistoryModal(e.projectKey,e.workingDir,i)}),w.appendChild(T),y.appendChild(w)}return m.addEventListener("click",w=>{w.stopPropagation();const T=f.classList.toggle("expanded");y.hidden=!T,m.setAttribute("aria-expanded",T?"true":"false")}),f.append(p,y),f},_HISTORY_INITIAL_COUNT:4,async loadHistorySessions(){const e=document.getElementById("historySessions"),i=document.getElementById("historyList");if(!(!e||!i))try{const s=Array.isArray(this.cases)&&this.cases.length>0?Promise.resolve(this.cases):fetch("/api/cases").then(o=>o.ok?o.json():[]).catch(()=>[]),[n,l]=await Promise.all([this._fetchHistorySessions(30),s]);if(n.length===0){e.style.display="none";return}i.replaceChildren();const c=this._HISTORY_INITIAL_COUNT;for(let o=0;o<Math.min(c,n.length);o++)i.appendChild(this._buildHistoryItem(n[o],l));if(n.length>c){const o=document.createElement("button");o.className="history-show-more",o.textContent=`Show ${n.length-c} more`,o.addEventListener("click",()=>{for(let h=c;h<n.length;h++)i.insertBefore(this._buildHistoryItem(n[h],l),o);o.remove()}),i.appendChild(o)}e.style.display=""}catch(s){console.error("[loadHistorySessions]",s),e.style.display="none"}},_FOLDER_HISTORY_PAGE_SIZE:20,openFolderHistoryModal(e,i,s){this._closeFolderHistoryModal();const n=document.createElement("div");n.className="modal active folder-history-modal",n.id="folderHistoryModal";const l=document.createElement("div");l.className="modal-backdrop",l.addEventListener("click",()=>this._closeFolderHistoryModal());const c=document.createElement("div");c.className="modal-content modal-lg";const o=document.createElement("div");o.className="modal-header";const h=document.createElement("h3");h.textContent="Folder History";const a=document.createElement("div");a.className="folder-history-subtitle",a.textContent=this._shortenHomePath(i);const f=document.createElement("button");f.className="modal-close",f.setAttribute("aria-label","Close"),f.innerHTML="&times;",f.addEventListener("click",()=>this._closeFolderHistoryModal()),o.append(h,f);const p=document.createElement("div");p.className="modal-body";const t=document.createElement("div");t.className="folder-history-list",t.setAttribute("data-loading","true"),t.textContent="Loading...",p.append(a,t),c.append(o,p),n.append(l,c),document.body.appendChild(n),this._folderHistoryState={projectKey:e,workingDir:i,cases:s||[],offset:0,total:null,list:t},this._folderHistoryEscHandler=r=>{r.key==="Escape"&&this._closeFolderHistoryModal()},document.addEventListener("keydown",this._folderHistoryEscHandler),this._loadFolderHistoryPage()},async _loadFolderHistoryPage(){const e=this._folderHistoryState;if(!e)return;const{projectKey:i,cases:s,list:n}=e,l=this._FOLDER_HISTORY_PAGE_SIZE,c=e.offset,o=n.querySelector(".folder-history-more");o&&o.remove(),c===0&&(n.replaceChildren(),n.removeAttribute("data-loading"));try{const h=`/api/history/sessions?projectKey=${encodeURIComponent(i)}&offset=${c}&limit=${l}`,f=await(await fetch(h)).json(),p=f.sessions||[];if(e.total=typeof f.total=="number"?f.total:p.length+c,c===0&&p.length===0){const t=document.createElement("div");t.className="folder-history-empty",t.textContent="No conversations found in this folder.",n.appendChild(t);return}for(const t of p)n.appendChild(this._buildHistoryItem(t,s,{showViewAll:!1}));if(e.offset=c+p.length,e.offset<e.total){const t=e.total-e.offset,r=document.createElement("button");r.className="history-show-more folder-history-more",r.textContent=`Show ${Math.min(l,t)} more (${t} remaining)`,r.addEventListener("click",()=>this._loadFolderHistoryPage()),n.appendChild(r)}}catch(h){console.error("[loadFolderHistoryPage]",h);const a=document.createElement("div");a.className="folder-history-empty",a.textContent="Failed to load folder history.",n.appendChild(a)}},_closeFolderHistoryModal(){const e=document.getElementById("folderHistoryModal");e&&e.remove(),this._folderHistoryEscHandler&&(document.removeEventListener("keydown",this._folderHistoryEscHandler),this._folderHistoryEscHandler=null),this._folderHistoryState=null},async resumeHistorySession(e,i){document.getElementById("runModeMenu")?.classList.remove("active"),this._closeFolderHistoryModal();try{this.terminal.clear(),this.terminal.writeln(`\x1B[1;32m Resuming conversation ${e.slice(0,8)}...\x1B[0m`);const s=i.split("/").pop()||"session";let n=1;for(const[,t]of this.sessions){const r=t.name&&t.name.match(/^w(\d+)-/);if(r){const u=parseInt(r[1]);u>=n&&(n=u+1)}}const l=`w${n}-${s}`,o=(this.cases||[]).find(t=>t.path===i)?.name||i.split("/").pop()||"",h=this.buildEnvOverrides(this.getCaseSettings(o),this.loadAppSettingsFromStorage()),f=await(await fetch("/api/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workingDir:i,name:l,resumeSessionId:e,...Object.keys(h).length>0?{envOverrides:h}:{}})})).json();if(!f.success)throw new Error(f.error);const p=f.session.id;await fetch(`/api/sessions/${p}/interactive`,{method:"POST"}),this.terminal.writeln(`\x1B[90m Session ${l} ready\x1B[0m`),await this.selectSession(p),this.terminal.focus()}catch(s){this.terminal.writeln(`\x1B[1;31m Error: ${s.message}\x1B[0m`)}},isTerminalAtBottom(){if(!this.terminal)return!0;const e=this.terminal.buffer.active;return e.viewportY>=e.baseY-2},batchTerminalWrite(e){if(this._isLoadingBuffer){this._loadBufferQueue&&this._loadBufferQueue.push(e);return}if(this.writeFrameScheduled||(this._wasAtBottomBeforeWrite=this.isTerminalAtBottom()),(this.activeSessionId?this.sessions.get(this.activeSessionId):null)?.flickerFilterEnabled??!1){if(e.includes("\x1B[2J")||e.includes("\x1B[H\x1B[J")||e.includes("\x1B[H")&&e.includes("\x1B[?25l")){this.flickerFilterActive=!0,this.flickerFilterBuffer+=e,this.flickerFilterTimeout&&clearTimeout(this.flickerFilterTimeout),this.flickerFilterTimeout=setTimeout(()=>{this.flickerFilterTimeout=null,this.flushFlickerBuffer()},SYNC_WAIT_TIMEOUT_MS);return}if(this.flickerFilterActive){this.flickerFilterBuffer+=e;return}}this.pendingWrites.push(e),this.writeFrameScheduled||(this.writeFrameScheduled=!0,this._safeYield(()=>{this.flushPendingWrites(),this.writeFrameScheduled=!1}))},flushFlickerBuffer(){this.flickerFilterBuffer&&(this.pendingWrites.push(this.flickerFilterBuffer),this.flickerFilterBuffer="",this.flickerFilterActive=!1,this.writeFrameScheduled||(this.writeFrameScheduled=!0,this._safeYield(()=>{this.flushPendingWrites(),this.writeFrameScheduled=!1})))},_updateLocalEchoState(){const e=this.loadAppSettingsFromStorage(),i=this.activeSessionId?this.sessions.get(this.activeSessionId):null,n=!!((e.localEchoEnabled??MobileDetection.isTouchDevice())&&i);this._localEchoEnabled&&!n&&this._localEchoOverlay?.clear(),this._localEchoEnabled=n,this._localEchoOverlay&&i&&(i.mode==="opencode"?this._localEchoOverlay.setPrompt({type:"custom",offset:3,find:l=>{try{const c=l.buffer.active,o=c.cursorY,h=c.getLine(c.viewportY+o);if(!h)return null;const f=h.translateToString(!0).indexOf("\u2503");return f>=0?{row:o,col:f}:null}catch{return null}}}):i.mode==="shell"?(this._localEchoOverlay.clear(),this._localEchoEnabled=!1):this._localEchoOverlay.setPrompt({type:"character",char:"\u276F",offset:2}))},flushPendingWrites(){if(this.pendingWrites.length===0||!this.terminal)return;const e=performance.now(),i=this.pendingWrites.join("");this.pendingWrites=[];const s=i.length;s>16384&&_crashDiag.log(`FLUSH: ${(s/1024).toFixed(0)}KB`);const n=65536;let l=!1;s<=n?this.terminal.write(i):(this.terminal.write(i.slice(0,n)),this.pendingWrites.push(i.slice(n)),l=!0,this.writeFrameScheduled||(this.writeFrameScheduled=!0,this._safeYield(()=>{this.flushPendingWrites(),this.writeFrameScheduled=!1})));const c=l?n:s,o=performance.now()-e;if((o>100||l)&&console.warn(`[CRASH-DIAG] flushPendingWrites: ${o.toFixed(0)}ms, ${(c/1024).toFixed(0)}KB written${l?", rest deferred":""} (total ${(s/1024).toFixed(0)}KB)`),this._wasAtBottomBeforeWrite&&this.terminal.scrollToBottom(),this._localEchoOverlay?.hasPending&&this._localEchoOverlay.rerender(),this._tabCompletionSessionId&&this._tabCompletionSessionId===this.activeSessionId&&this._localEchoOverlay&&!this._localEchoOverlay.pendingText){const h=this._localEchoOverlay,a=this;this.terminal.write("",()=>{if(!a._tabCompletionSessionId)return;h.resetBufferDetection();const f=h.detectBufferText();f?f===a._tabCompletionBaseText?(h.undoDetection(),a._tabCompletionRetries=(a._tabCompletionRetries||0)+1,a._tabCompletionRetries>60&&(a._tabCompletionSessionId=null,a._tabCompletionRetries=0)):(a._tabCompletionSessionId=null,a._tabCompletionRetries=0,a._tabCompletionBaseText=null,a._tabCompletionFallback&&(clearTimeout(a._tabCompletionFallback),a._tabCompletionFallback=null),h.rerender()):(a._tabCompletionRetries=(a._tabCompletionRetries||0)+1,a._tabCompletionRetries>60&&(a._tabCompletionSessionId=null,a._tabCompletionRetries=0))})}},_safeYield(e){let i=!1;const s=()=>{i||(i=!0,e())};requestAnimationFrame(s),setTimeout(s,50),this._workerYield(s)},_workerYield(e){try{if(this._yieldWorker===void 0){const i="onmessage=()=>setTimeout(()=>postMessage(0),0);",s=new Blob([i],{type:"application/javascript"}),n=URL.createObjectURL(s);this._yieldWorker=new Worker(n),URL.revokeObjectURL(n),this._yieldQueue=[],this._yieldWorker.onmessage=()=>{const l=this._yieldQueue.shift();l&&l()}}if(!this._yieldWorker)return;this._yieldQueue.push(e),this._yieldWorker.postMessage(0)}catch{this._yieldWorker=null}},chunkedTerminalWrite(e,i=TERMINAL_CHUNK_SIZE){const s=++this._chunkedWriteGen;return new Promise(n=>{if(!e||e.length===0){this._finishBufferLoad(),n();return}this._isLoadingBuffer=!0,this._loadBufferQueue=[];const l=e.replace(DEC_SYNC_STRIP_RE,""),c=()=>{this._chunkedWriteGen===s&&this._finishBufferLoad(),n()};if(l.length<=i){this.terminal.write(l),c();return}let o=0;const h=performance.now();let a=0;const f=()=>{if(this._chunkedWriteGen!==s){n();return}if(o>=l.length){const u=performance.now()-h;console.log(`[CRASH-DIAG] chunkedTerminalWrite complete: ${l.length} bytes in ${a} chunks, ${u.toFixed(0)}ms total`),this._safeYield(c);return}const p=performance.now(),t=l.slice(o,o+i);this.terminal.write(t);const r=performance.now()-p;a++,r>50&&console.warn(`[CRASH-DIAG] chunk #${a} write took ${r.toFixed(0)}ms (${t.length} bytes at offset ${o})`),o+=i,this._safeYield(f)};this._safeYield(f)})},_finishBufferLoad(){this._isLoadingBuffer=!1,this._loadBufferQueue=null},clearTerminal(){this.terminal.clear()},async restoreTerminalSize(){if(!this.activeSessionId){this.showToast("No active session","warning");return}const e=this.getTerminalDimensions();if(!e){this.showToast("Could not determine terminal size","error");return}try{await this.sendResize(this.activeSessionId),this.showToast(`Terminal restored to ${e.cols}x${e.rows}`,"success")}catch(i){console.error("Failed to restore terminal size:",i),this.showToast("Failed to restore terminal size","error")}},sendPendingCtrlL(e){},async copyTerminal(){try{const e=this.terminal.buffer.active;let i="";for(let s=0;s<e.length;s++){const n=e.getLine(s);n&&(i+=n.translateToString(!0)+`
2
- `)}await navigator.clipboard.writeText(i.replace(/\n+$/,`
3
- `)),this.showToast("Copied to clipboard","success")}catch{this.showToast("Failed to copy","error")}},increaseFontSize(){const e=this.terminal.options.fontSize||14;this.setFontSize(Math.min(e+2,24))},decreaseFontSize(){const e=this.terminal.options.fontSize||14;this.setFontSize(Math.max(e-2,10))},setFontSize(e){this.terminal.options.fontSize=e,document.getElementById("fontSizeDisplay").textContent=e,this.fitAddon.fit(),localStorage.setItem("codeman-font-size",e),this._localEchoOverlay?.refreshFont()},loadFontSize(){const e=localStorage.getItem("codeman-font-size");if(e){const i=parseInt(e,10);i>=10&&i<=24&&(this.terminal.options.fontSize=i,document.getElementById("fontSizeDisplay").textContent=i)}},getTerminalDimensions(){const s=this.fitAddon?.proposeDimensions();return s?{cols:Math.max(s.cols,40),rows:Math.max(s.rows,10)}:null},async sendResize(e){this.fitAddon&&this.fitAddon.fit();const i=this.getTerminalDimensions();if(i){if(this._lastResizeDims={cols:i.cols,rows:i.rows},this._wsReady&&this._wsSessionId===e)try{this._ws.send(JSON.stringify({t:"z",c:i.cols,r:i.rows}));return}catch{}await fetch(`/api/sessions/${e}/resize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})}},async sendInput(e){this.activeSessionId&&await fetch(`/api/sessions/${this.activeSessionId}/input`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:e,useMux:!0})})},toggleDirInput(){const e=document.querySelector("#dirDisplay").parentElement,i=document.getElementById("dirInput");i.classList.contains("hidden")&&(i.classList.remove("hidden"),e.style.display="none",i.focus())},hideDirInput(){const e=document.querySelector("#dirDisplay").parentElement,i=document.getElementById("dirInput");setTimeout(()=>{i.classList.add("hidden"),e.style.display="";const s=i.value.trim();document.getElementById("dirDisplay").textContent=s||"No directory"},100)}});