aicodeman 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +2 -1
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.js +27 -0
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config/dependency-registry.d.ts +42 -0
  6. package/dist/config/dependency-registry.d.ts.map +1 -0
  7. package/dist/config/dependency-registry.js +104 -0
  8. package/dist/config/dependency-registry.js.map +1 -0
  9. package/dist/config/workflow-config.d.ts +24 -0
  10. package/dist/config/workflow-config.d.ts.map +1 -0
  11. package/dist/config/workflow-config.js +24 -0
  12. package/dist/config/workflow-config.js.map +1 -0
  13. package/dist/hooks-config.d.ts +17 -0
  14. package/dist/hooks-config.d.ts.map +1 -1
  15. package/dist/hooks-config.js +39 -0
  16. package/dist/hooks-config.js.map +1 -1
  17. package/dist/subagent-watcher.d.ts +34 -0
  18. package/dist/subagent-watcher.d.ts.map +1 -1
  19. package/dist/subagent-watcher.js +147 -4
  20. package/dist/subagent-watcher.js.map +1 -1
  21. package/dist/types/index.d.ts +1 -0
  22. package/dist/types/index.d.ts.map +1 -1
  23. package/dist/types/index.js +1 -0
  24. package/dist/types/index.js.map +1 -1
  25. package/dist/types/workflow-run.d.ts +130 -0
  26. package/dist/types/workflow-run.d.ts.map +1 -0
  27. package/dist/types/workflow-run.js +20 -0
  28. package/dist/types/workflow-run.js.map +1 -0
  29. package/dist/utils/dependency-checker.d.ts +42 -0
  30. package/dist/utils/dependency-checker.d.ts.map +1 -0
  31. package/dist/utils/dependency-checker.js +167 -0
  32. package/dist/utils/dependency-checker.js.map +1 -0
  33. package/dist/utils/dependency-report.d.ts +26 -0
  34. package/dist/utils/dependency-report.d.ts.map +1 -0
  35. package/dist/utils/dependency-report.js +68 -0
  36. package/dist/utils/dependency-report.js.map +1 -0
  37. package/dist/web/middleware/auth.d.ts +4 -8
  38. package/dist/web/middleware/auth.d.ts.map +1 -1
  39. package/dist/web/middleware/auth.js +14 -22
  40. package/dist/web/middleware/auth.js.map +1 -1
  41. package/dist/web/public/api-client.c9b1cddc.js.gz +0 -0
  42. package/dist/web/public/app.eaa14cdd.js +37 -0
  43. package/dist/web/public/app.eaa14cdd.js.br +0 -0
  44. package/dist/web/public/app.eaa14cdd.js.gz +0 -0
  45. package/dist/web/public/{constants.00fa5405.js → constants.1c779517.js} +20 -0
  46. package/dist/web/public/constants.1c779517.js.br +0 -0
  47. package/dist/web/public/constants.1c779517.js.gz +0 -0
  48. package/dist/web/public/image-input.0ea86695.js.gz +0 -0
  49. package/dist/web/public/index.html +48 -10
  50. package/dist/web/public/index.html.br +0 -0
  51. package/dist/web/public/index.html.gz +0 -0
  52. package/dist/web/public/input-cjk.b8686b5e.js.gz +0 -0
  53. package/dist/web/public/keyboard-accessory.bc753cc7.js.gz +0 -0
  54. package/dist/web/public/{mobile-handlers.763a7439.js → mobile-handlers.db3dc3c8.js} +3 -0
  55. package/dist/web/public/mobile-handlers.db3dc3c8.js.br +0 -0
  56. package/dist/web/public/mobile-handlers.db3dc3c8.js.gz +0 -0
  57. package/dist/web/public/mobile.06b38d3a.css.gz +0 -0
  58. package/dist/web/public/notification-manager.9c984ac2.js.gz +0 -0
  59. package/dist/web/public/orchestrator-panel.js.gz +0 -0
  60. package/dist/web/public/{panels-ui.2f467969.js → panels-ui.f3f08e26.js} +48 -48
  61. package/dist/web/public/panels-ui.f3f08e26.js.br +0 -0
  62. package/dist/web/public/panels-ui.f3f08e26.js.gz +0 -0
  63. package/dist/web/public/ralph-panel.6de2d0f8.js.gz +0 -0
  64. package/dist/web/public/ralph-wizard.13a1831e.js.gz +0 -0
  65. package/dist/web/public/respawn-ui.2d249da9.js.gz +0 -0
  66. package/dist/web/public/sanitize-html.bc7078d6.js +1 -0
  67. package/dist/web/public/sanitize-html.bc7078d6.js.br +0 -0
  68. package/dist/web/public/sanitize-html.bc7078d6.js.gz +0 -0
  69. package/dist/web/public/session-ui.1463b824.js.gz +0 -0
  70. package/dist/web/public/settings-ui.601c30c1.js +55 -0
  71. package/dist/web/public/settings-ui.601c30c1.js.br +0 -0
  72. package/dist/web/public/settings-ui.601c30c1.js.gz +0 -0
  73. package/dist/web/public/styles.7e612fc4.css +1 -0
  74. package/dist/web/public/styles.7e612fc4.css.br +0 -0
  75. package/dist/web/public/styles.7e612fc4.css.gz +0 -0
  76. package/dist/web/public/subagent-windows.a366a4ad.js.gz +0 -0
  77. package/dist/web/public/sw.js.gz +0 -0
  78. package/dist/web/public/terminal-ui.a7e046da.js +3 -0
  79. package/dist/web/public/terminal-ui.a7e046da.js.br +0 -0
  80. package/dist/web/public/terminal-ui.a7e046da.js.gz +0 -0
  81. package/dist/web/public/ultracode-panel.js +304 -0
  82. package/dist/web/public/ultracode-panel.js.br +0 -0
  83. package/dist/web/public/ultracode-panel.js.gz +0 -0
  84. package/dist/web/public/upload.html.gz +0 -0
  85. package/dist/web/public/vendor/dompurify.min.js +3 -0
  86. package/dist/web/public/vendor/dompurify.min.js.br +0 -0
  87. package/dist/web/public/vendor/dompurify.min.js.gz +0 -0
  88. package/dist/web/public/vendor/marked.min.js.gz +0 -0
  89. package/dist/web/public/vendor/xterm-addon-fit.min.js.gz +0 -0
  90. package/dist/web/public/vendor/xterm-addon-serialize.min.js.gz +0 -0
  91. package/dist/web/public/vendor/xterm-addon-unicode11.min.js.gz +0 -0
  92. package/dist/web/public/vendor/xterm-addon-webgl.min.js.gz +0 -0
  93. package/dist/web/public/vendor/xterm-zerolag-input.137ad9f0.js.gz +0 -0
  94. package/dist/web/public/vendor/xterm.css.gz +0 -0
  95. package/dist/web/public/vendor/xterm.min.js.gz +0 -0
  96. package/dist/web/public/voice-input.085e9e73.js.gz +0 -0
  97. package/dist/web/routes/file-routes.d.ts.map +1 -1
  98. package/dist/web/routes/file-routes.js +80 -24
  99. package/dist/web/routes/file-routes.js.map +1 -1
  100. package/dist/web/routes/session-routes.d.ts.map +1 -1
  101. package/dist/web/routes/session-routes.js +13 -1
  102. package/dist/web/routes/session-routes.js.map +1 -1
  103. package/dist/web/routes/system-routes.d.ts.map +1 -1
  104. package/dist/web/routes/system-routes.js +21 -0
  105. package/dist/web/routes/system-routes.js.map +1 -1
  106. package/dist/web/schemas.d.ts +1 -0
  107. package/dist/web/schemas.d.ts.map +1 -1
  108. package/dist/web/schemas.js +2 -0
  109. package/dist/web/schemas.js.map +1 -1
  110. package/dist/web/server.d.ts +12 -0
  111. package/dist/web/server.d.ts.map +1 -1
  112. package/dist/web/server.js +56 -1
  113. package/dist/web/server.js.map +1 -1
  114. package/dist/web/sse-events.d.ts +10 -0
  115. package/dist/web/sse-events.d.ts.map +1 -1
  116. package/dist/web/sse-events.js +12 -0
  117. package/dist/web/sse-events.js.map +1 -1
  118. package/dist/workflow-run-watcher.d.ts +76 -0
  119. package/dist/workflow-run-watcher.d.ts.map +1 -0
  120. package/dist/workflow-run-watcher.js +327 -0
  121. package/dist/workflow-run-watcher.js.map +1 -0
  122. package/package.json +1 -1
  123. package/dist/web/public/app.9daf49ad.js +0 -37
  124. package/dist/web/public/app.9daf49ad.js.br +0 -0
  125. package/dist/web/public/app.9daf49ad.js.gz +0 -0
  126. package/dist/web/public/constants.00fa5405.js.br +0 -0
  127. package/dist/web/public/constants.00fa5405.js.gz +0 -0
  128. package/dist/web/public/mobile-handlers.763a7439.js.br +0 -0
  129. package/dist/web/public/mobile-handlers.763a7439.js.gz +0 -0
  130. package/dist/web/public/panels-ui.2f467969.js.br +0 -0
  131. package/dist/web/public/panels-ui.2f467969.js.gz +0 -0
  132. package/dist/web/public/settings-ui.44b99ce0.js +0 -55
  133. package/dist/web/public/settings-ui.44b99ce0.js.br +0 -0
  134. package/dist/web/public/settings-ui.44b99ce0.js.gz +0 -0
  135. package/dist/web/public/styles.c13845d5.css +0 -1
  136. package/dist/web/public/styles.c13845d5.css.br +0 -0
  137. package/dist/web/public/styles.c13845d5.css.gz +0 -0
  138. package/dist/web/public/terminal-ui.5bf97f7e.js +0 -3
  139. package/dist/web/public/terminal-ui.5bf97f7e.js.br +0 -0
  140. package/dist/web/public/terminal-ui.5bf97f7e.js.gz +0 -0
@@ -1,3 +0,0 @@
1
- "use strict";(function(e){const i=/^\x1b\[[\?>=]?[\d;]*[cnR]$/,s=/^\x1b\][\d;]*[^\x07\x1b]*(?:\x07|\x1b\\)$/;function l(m){return i.test(m)||s.test(m)}function r(m){return l(m)}const o={og:{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"},"daylight-green":{background:"#161b23",foreground:"#dfe6ef",cursor:"#2fd3aa",cursorAccent:"#161b23",selection:"rgba(47,211,170,0.22)",black:"#161b23",red:"#ff8585",green:"#34d8a0",yellow:"#f0c25a",blue:"#5cc6e8",magenta:"#c79af2",cyan:"#2bcbbb",white:"#dfe6ef",brightBlack:"#5b6675",brightRed:"#ffa0a0",brightGreen:"#5fe6b8",brightYellow:"#ffd884",brightBlue:"#82d4ee",brightMagenta:"#d6b3f7",brightCyan:"#5ee0d4",brightWhite:"#f3f6fa"},"daylight-blue":{background:"#161b23",foreground:"#dfe6ef",cursor:"#38b6f0",cursorAccent:"#161b23",selection:"rgba(56,182,240,0.22)",black:"#161b23",red:"#ff8585",green:"#34d8a0",yellow:"#f0c25a",blue:"#5cc6e8",magenta:"#c79af2",cyan:"#2bcbbb",white:"#dfe6ef",brightBlack:"#5b6675",brightRed:"#ffa0a0",brightGreen:"#5fe6b8",brightYellow:"#ffd884",brightBlue:"#82d4ee",brightMagenta:"#d6b3f7",brightCyan:"#5ee0d4",brightWhite:"#f3f6fa"}};function u(){const m=typeof document<"u"&&document.documentElement.dataset.skin||"daylight-blue";return o[m]||o["daylight-blue"]}e.CodemanTerminalInput={isTerminalQueryResponse:l,shouldSuppressTerminalQueryResponse:r,USER_SCROLL_STICKY_SUPPRESS_MS:1500},e.CODEMAN_XTERM_THEMES=o,e.codemanCurrentXtermTheme=u})(window),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:{...window.codemanCurrentXtermTheme()},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),this._xtermSnapshots=new Map,typeof SerializeAddon<"u")try{this._serializeAddon=new SerializeAddon.SerializeAddon,this.terminal.loadAddon(this._serializeAddon)}catch{this._serializeAddon=null}if(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 c=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._localEchoOverlay?.suppressBufferDetection(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),c&&(this._pendingInput+=c,a()),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"})})},c?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 c=!1,f=0;t.addEventListener("compositionstart",()=>{c=!0}),t.addEventListener("compositionend",()=>{c=!1}),t.addEventListener("keydown",d=>{!d.isComposing&&d.keyCode!==229&&(f=Date.now())}),t.addEventListener("input",d=>{if(c||d.isComposing||d.inputType!=="insertText"||!d.data||Date.now()-f<50)return;const h=d.data,_=this._localEchoOverlay?.pendingText||"";Promise.resolve().then(()=>{if(this._lastTerminalData?.data===h&&performance.now()-this._lastTerminalData.time<100){t.value="";return}const y=this._localEchoOverlay?.pendingText||"";if(this._localEchoEnabled&&y.length>_.length&&y.endsWith(h)){t.value="";return}const b=t.value;!b||b.trim()===""&&h!==" "||(this.terminal._core.coreService.triggerDataEvent(h,!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:c}=JSON.parse(t);return Date.now()-c>WEBGL_FALLBACK.STICKY_EXPIRY_MS?(localStorage.removeItem("codeman-webgl-disabled"),!1):!0}catch{return!1}})(),r=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"),!r)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),MobileDetection.isTouchDevice()&&(this.terminal.onCursorMove(()=>this._syncMobileHelperTextareaToCursor()),this.terminal.onRender(()=>this._syncMobileHelperTextareaToCursor())),this._cjkInput=null,typeof CjkInput<"u"&&(this._cjkInput=CjkInput.init({send:t=>{this._handleCjkInput(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 c=Math.round(t.deltaY/25)||(t.deltaY>0?1:-1);this._noteTerminalUserScroll(c),this.terminal.scrollLines(c)},{passive:!1});{const t=()=>this.terminal._core?._renderService?.dimensions?.css?.cell?.height||13;let c=0,f=0,d=0,h=null,_=!1;const y=g=>{const E=d?(g-d)/16.67:1;if(d=g,!_&&Math.abs(f)>.3){const T=Math.round(f/t());T!==0&&this.terminal.scrollLines(T),f*=.92,h=requestAnimationFrame(y)}else _?h=requestAnimationFrame(y):(h=null,f=0)};let b=0,S=!1;s.addEventListener("touchstart",g=>{g.touches.length===1&&(c=g.touches[0].clientY,f=0,b=0,_=!0,S=!1,d=0,h&&(cancelAnimationFrame(h),h=null))},{passive:!0}),s.addEventListener("touchmove",g=>{if(g.touches.length===1&&_){g.preventDefault(),S=!0;const E=g.touches[0].clientY,T=c-E;b+=T,f=T*1.2,c=E;const I=t(),v=Math.trunc(b/I);v!==0&&(this._noteTerminalUserScroll(v),this.terminal.scrollLines(v),b-=v*I)}},{passive:!1}),s.addEventListener("touchend",()=>{if(_=!1,!h&&Math.abs(f)>.3&&(h=requestAnimationFrame(y)),!S&&this.terminal){const g=document.getElementById("cjkInput");g?.classList.contains("cjk-input-visible")?g.focus():(this._syncMobileHelperTextareaToCursor(),this.terminal.focus())}},{passive:!0}),s.addEventListener("touchcancel",()=>{_=!1,f=0,b=0},{passive:!0})}this.showWelcome(),this.initImageInput(),this._chunkedWriteGen=0,this._bufferLoadSeq=0,this._bufferLoadOwner=null,this._lastUserScrollUpAt=null,this._resizeTimeout=null,this._lastResizeDims=null;const u=40,m=10,p=()=>{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 c=this.fitAddon.proposeDimensions(),f=c?Math.max(c.cols,u):u,d=c?Math.max(c.rows,m):m;if(!this._lastResizeDims||f!==this._lastResizeDims.cols||d!==this._lastResizeDims.rows){const h=this.activeSessionId?this.sessions.get(this.activeSessionId):null;h&&h.mode!=="shell"&&this.terminal&&this.isTerminalAtBottom()&&this.terminal.write("\x1B[3J\x1B[H\x1B[2J"),this._lastResizeDims={cols:f,rows:d};const _=typeof MobileDetection<"u"&&MobileDetection.getDeviceType?MobileDetection.getDeviceType():"desktop";let y=!1;if(this._wsReady&&this._wsSessionId===this.activeSessionId)try{this._ws.send(JSON.stringify({t:"z",c:f,r:d,v:_})),y=!0}catch{}y||fetch(`/api/sessions/${this.activeSessionId}/resize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cols:f,rows:d,viewportType:_})}).catch(()=>{})}}this.updateConnectionLines(),this._localEchoOverlay?.hasPending&&this._localEchoOverlay.rerender()},300)};window.addEventListener("resize",p),this.terminalResizeObserver&&this.terminalResizeObserver.disconnect(),this.terminalResizeObserver=new ResizeObserver(p),this.terminalResizeObserver.observe(s),this._pendingInput="",this._inputFlushTimeout=null,this._lastKeystrokeTime=0;const a=()=>{if(this._inputFlushTimeout=null,this._pendingInput&&this.activeSessionId){const t=this._pendingInput,c=this.activeSessionId;this._pendingInput="",this._sendInputAsync(c,t)}};this.terminal.onData(t=>{if(!(window.cjkActive||document.activeElement?.id==="cjkInput")&&this.activeSessionId){if(window.CodemanTerminalInput?.shouldSuppressTerminalQueryResponse(t))return;if(this._lastTerminalData={data:t,time:performance.now()},this._localEchoEnabled){if(t==="\x7F"){if(this._localEchoOverlay?.removeChar()==="flushed"){const{count:d,text:h}=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,h))),this._pendingInput+=t,a()}return}if(/^[\r\n]+$/.test(t)){const f=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),f&&(this._pendingInput+=f,a()),setTimeout(()=>{this._pendingInput+="\r",a()},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,a();return}if(this._restoringFlushedState){this._pendingInput+=t,a();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 h="";try{const y=this._localEchoOverlay?.findPrompt?.();if(y){const b=this.terminal.buffer.active,S=b.getLine(b.viewportY+y.row);S&&(h=S.translateToString(!0).slice(y.col+2).trimEnd())}}catch{}this._tabCompletionBaseText=h,a(),this._tabCompletionSessionId=this.activeSessionId,this._tabCompletionRetries=0,this._tabCompletionFallback&&clearTimeout(this._tabCompletionFallback);const _=this;this._tabCompletionFallback=setTimeout(()=>{if(_._tabCompletionFallback=null,!_._tabCompletionSessionId||_._tabCompletionSessionId!==_.activeSessionId)return;const y=_._localEchoOverlay;!y||y.pendingText||_.terminal.write("",()=>{if(!_._tabCompletionSessionId)return;y.resetBufferDetection();const b=y.detectBufferText();b&&b!==_._tabCompletionBaseText&&(_._tabCompletionSessionId=null,_._tabCompletionRetries=0,_._tabCompletionBaseText=null,y.rerender())})},300);return}const f=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._localEchoOverlay?.suppressBufferDetection(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),f&&(this._pendingInput+=f),this._pendingInput+=t,this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null),a();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),a();return}const c=performance.now();c-this._lastKeystrokeTime>50?(this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null),this._lastKeystrokeTime=c,a()):(this._lastKeystrokeTime=c,this._inputFlushTimeout||(this._inputFlushTimeout=setTimeout(a,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 r=e.terminal.buffer.active.getLine(s-1);if(!r){n(void 0);return}const o=r.translateToString(!0);if(!o||!o.includes("/")){n(void 0);return}const u=[],m=/https?:\/\/[^\s"'<>|;&)\]\x00-\x1f]+/g,p=(h,_)=>{const y=h.replace(/[.,;:!?)]+$/,""),b=o.indexOf(y,_);b!==-1&&(u.some(S=>S.range.start.x===b+1)||u.push({text:y,range:{start:{x:b+1,y:s},end:{x:b+y.length+1,y:s}},decorations:{pointerCursor:!0,underline:!0},activate(S,g){window.open(g,"_blank","noopener,noreferrer")}}))},a=/\b(tail|cat|head|less|grep|watch|vim|nano)\s+(?:[^\s\/]+\s+){0,4}(\/[^\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,c=/Bash\([^)]*?(\/(?:home|tmp|var|etc|opt)[^\s"'<>|;&\)\n\x00-\x1f]+)/g,f=(h,_)=>{const y=o.indexOf(h,_);y!==-1&&(u.some(b=>b.range.start.x===y+1)||u.push({text:h,range:{start:{x:y+1,y:s},end:{x:y+h.length+1,y:s}},decorations:{pointerCursor:!0,underline:!0},activate(b,S){e.openLogViewerWindow(S,e.activeSessionId)}}))};let d;for(m.lastIndex=0;(d=m.exec(o))!==null;)p(d[0],d.index);for(a.lastIndex=0;(d=a.exec(o))!==null;)f(d[2],d.index);for(t.lastIndex=0;(d=t.exec(o))!==null;)f(d[1],d.index);for(c.lastIndex=0;(d=c.exec(o))!==null;)f(d[1],d.index);u.length>0&&console.debug("[LinkProvider] Found links:",u.map(h=>h.text)),n(u.length>0?u: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()).data?.sessions||[];if(s.length===0)return[];const n=new Map;for(const r of s){const o=r.projectKey||r.workingDir;n.has(o)||n.set(o,[]),n.get(o).push(r)}const l=[];for(const[,r]of n)l.push(...r.slice(0,3));return l.sort((r,o)=>new Date(o.lastModified)-new Date(r.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`,r=new Date(e.lastModified),o=r.toLocaleDateString("en",{month:"short",day:"numeric"})+" "+r.toLocaleTimeString("en",{hour:"2-digit",minute:"2-digit",hour12:!1}),u=this._shortenHomePath(e.workingDir),m=this._resolveCaseLabel(e.workingDir,i),p=document.createElement("div");p.className="history-item",p.title=e.workingDir;const a=document.createElement("div");a.className="history-item-main",a.addEventListener("click",()=>this.resumeHistorySession(e.sessionId,e.workingDir));const t=document.createElement("div");t.className="history-item-text";const c=document.createElement("span");c.className="history-item-title",c.textContent=e.firstPrompt||u;const f=document.createElement("span");f.className="history-item-subtitle",m.startsWith("#")&&f.classList.add("is-case"),f.textContent=m,t.append(c,f);const d=document.createElement("span");d.className="history-item-meta",d.textContent=o;const h=document.createElement("button");h.className="history-item-expand",h.type="button",h.setAttribute("aria-label","Show details"),h.setAttribute("aria-expanded","false"),h.textContent="\u22EF",a.append(t,d,h);const _=document.createElement("div");_.className="history-item-detail",_.hidden=!0;const y=document.createElement("div");y.className="history-detail-row";const b=document.createElement("span");b.className="history-detail-label",b.textContent="Prompt";const S=document.createElement("span");S.className="history-detail-value history-detail-prompt",S.textContent=e.firstPrompt||"(no prompt captured)",y.append(b,S);const g=document.createElement("div");g.className="history-detail-row";const E=document.createElement("span");E.className="history-detail-label",E.textContent="Path";const T=document.createElement("span");T.className="history-detail-value history-detail-path",T.textContent=u,g.append(E,T);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)}`,_.append(y,g,I),n&&e.projectKey){const v=document.createElement("div");v.className="history-detail-row history-detail-actions";const w=document.createElement("button");w.type="button",w.className="history-view-all-btn",w.textContent="View all in this folder",w.addEventListener("click",x=>{x.stopPropagation(),this.openFolderHistoryModal(e.projectKey,e.workingDir,i)}),v.appendChild(w),_.appendChild(v)}return h.addEventListener("click",v=>{v.stopPropagation();const w=p.classList.toggle("expanded");_.hidden=!w,h.setAttribute("aria-expanded",w?"true":"false")}),p.append(a,_),p},_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():null).then(o=>o?.data||[]).catch(()=>[]),[n,l]=await Promise.all([this._fetchHistorySessions(30),s]);if(n.length===0){e.style.display="none";return}i.replaceChildren();const r=this._HISTORY_INITIAL_COUNT;for(let o=0;o<Math.min(r,n.length);o++)i.appendChild(this._buildHistoryItem(n[o],l));if(n.length>r){const o=document.createElement("button");o.className="history-show-more",o.textContent=`Show ${n.length-r} more`,o.addEventListener("click",()=>{for(let u=r;u<n.length;u++)i.insertBefore(this._buildHistoryItem(n[u],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 r=document.createElement("div");r.className="modal-content modal-lg";const o=document.createElement("div");o.className="modal-header";const u=document.createElement("h3");u.textContent="Folder History";const m=document.createElement("div");m.className="folder-history-subtitle",m.textContent=this._shortenHomePath(i);const p=document.createElement("button");p.className="modal-close",p.setAttribute("aria-label","Close"),p.innerHTML="&times;",p.addEventListener("click",()=>this._closeFolderHistoryModal()),o.append(u,p);const a=document.createElement("div");a.className="modal-body";const t=document.createElement("div");t.className="folder-history-list",t.setAttribute("data-loading","true"),t.textContent="Loading...",a.append(m,t),r.append(o,a),n.append(l,r),document.body.appendChild(n),this._folderHistoryState={projectKey:e,workingDir:i,cases:s||[],offset:0,total:null,list:t},this._folderHistoryEscHandler=c=>{c.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,r=e.offset,o=n.querySelector(".folder-history-more");o&&o.remove(),r===0&&(n.replaceChildren(),n.removeAttribute("data-loading"));try{const u=`/api/history/sessions?projectKey=${encodeURIComponent(i)}&offset=${r}&limit=${l}`,p=await(await fetch(u)).json(),a=p.data?.sessions||[];if(e.total=typeof p.data?.total=="number"?p.data.total:a.length+r,r===0&&a.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 a)n.appendChild(this._buildHistoryItem(t,s,{showViewAll:!1}));if(e.offset=r+a.length,e.offset<e.total){const t=e.total-e.offset,c=document.createElement("button");c.className="history-show-more folder-history-more",c.textContent=`Show ${Math.min(l,t)} more (${t} remaining)`,c.addEventListener("click",()=>this._loadFolderHistoryPage()),n.appendChild(c)}}catch(u){console.error("[loadFolderHistoryPage]",u);const m=document.createElement("div");m.className="folder-history-empty",m.textContent="Failed to load folder history.",n.appendChild(m)}},_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[,f]of this.sessions){const d=f.name&&f.name.match(/^w(\d+)-/);if(d){const h=parseInt(d[1]);h>=n&&(n=h+1)}}const l=`w${n}-${s}`,o=(this.cases||[]).find(f=>f.path===i)?.name||i.split("/").pop()||"",u=this.loadAppSettingsFromStorage(),m=this.buildEnvOverrides(this.getCaseSettings(o),u),p=this.getEffortSetting(u),t=await(await fetch("/api/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workingDir:i,name:l,resumeSessionId:e,...Object.keys(m).length>0?{envOverrides:m}:{},...p?{effort:p}:{}})})).json();if(!t.success)throw new Error(t.error);const c=t.data.session.id;await fetch(`/api/sessions/${c}/interactive`,{method:"POST"}),this.terminal.writeln(`\x1B[90m Session ${l} ready\x1B[0m`),await this.selectSession(c),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},_noteTerminalUserScroll(e){e<0?this._lastUserScrollUpAt=performance.now():this.isTerminalAtBottom()&&(this._lastUserScrollUpAt=null)},_hasRecentUserScrollUp(){return typeof this._lastUserScrollUpAt!="number"?!1:performance.now()-this._lastUserScrollUpAt<window.CodemanTerminalInput.USER_SCROLL_STICKY_SUPPRESS_MS},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 r=l.buffer.active,o=r.cursorY,u=r.getLine(r.viewportY+o);if(!u)return null;const p=u.translateToString(!0).indexOf("\u2503");return p>=0?{row:o,col:p}:null}catch{return null}}}):i.mode==="shell"?(this._localEchoOverlay.clear(),this._localEchoEnabled=!1):this._localEchoOverlay.setPrompt({type:"custom",offset:0,find:l=>{try{const r=l.buffer.active;for(let o=l.rows-1;o>=0;o--){const u=r.getLine(r.viewportY+o);if(!u)continue;const p=u.translateToString(!0).lastIndexOf("\u276F");if(p>=0)return{row:o,col:p+2}}return{row:Math.max(0,Math.min(l.rows-1,r.cursorY)),col:Math.max(0,Math.min(l.cols-1,r.cursorX))}}catch{return null}}}))},_handleCjkInput(e){if(!this.activeSessionId)return;const i=this.activeSessionId,s=this.sessions.get(i);if(!!!(this._localEchoEnabled&&this._localEchoOverlay&&s?.mode!=="shell")){this._sendInputAsync(i,e);return}if(e==="\x7F"){if(this._localEchoOverlay.removeChar()==="flushed"){const{count:r,text:o}=this._localEchoOverlay.getFlushed();this._flushedOffsets?.has(i)&&(r===0?(this._flushedOffsets.delete(i),this._flushedTexts?.delete(i)):(this._flushedOffsets.set(i,r),this._flushedTexts?.set(i,o))),this._sendInputAsync(i,e)}return}if(/[\r\n]+$/.test(e)){const l=e.replace(/[\r\n]+$/g,"");l&&this._localEchoOverlay.appendText(l);const r=this._localEchoOverlay.pendingText||"";this._localEchoOverlay.clear(),this._localEchoOverlay.suppressBufferDetection(),this._flushedOffsets?.delete(i),this._flushedTexts?.delete(i),r&&this._sendInputAsync(i,r),setTimeout(()=>this._sendInputAsync(i,"\r"),r?80:0);return}if(e.length>1&&e.charCodeAt(0)===27){this._sendInputAsync(i,e);return}if(e.length===1&&e.charCodeAt(0)<32){const l=this._localEchoOverlay.pendingText||"";this._localEchoOverlay.clear(),this._localEchoOverlay.suppressBufferDetection(),this._flushedOffsets?.delete(i),this._flushedTexts?.delete(i),l&&this._sendInputAsync(i,l),this._sendInputAsync(i,e);return}this._localEchoOverlay.appendText(e)},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 l=(this.activeSessionId&&this.sessions?this.sessions.get(this.activeSessionId):null)?.mode==="codex"?32768:65536;let r=!1;const o=this._hasRecentUserScrollUp()&&this.terminal.buffer?.active?this.terminal.buffer.active.viewportY:null;s<=l?this.terminal.write(i):(this.terminal.write(i.slice(0,l)),this.pendingWrites.push(i.slice(l)),r=!0,this.writeFrameScheduled||(this.writeFrameScheduled=!0,this._safeYield(()=>{this.flushPendingWrites(),this.writeFrameScheduled=!1}))),o!==null&&this.terminal.buffer?.active?.viewportY!==o&&typeof this.terminal.scrollToLine=="function"&&this.terminal.scrollToLine(o);const u=r?l:s,m=performance.now()-e;if((m>100||r)&&console.warn(`[CRASH-DIAG] flushPendingWrites: ${m.toFixed(0)}ms, ${(u/1024).toFixed(0)}KB written${r?", rest deferred":""} (total ${(s/1024).toFixed(0)}KB)`),this._wasAtBottomBeforeWrite&&!this._hasRecentUserScrollUp()&&this.terminal.scrollToBottom(),this._localEchoOverlay?.hasPending&&this._localEchoOverlay.rerender(),this._tabCompletionSessionId&&this._tabCompletionSessionId===this.activeSessionId&&this._localEchoOverlay&&!this._localEchoOverlay.pendingText){const p=this._localEchoOverlay,a=this;this.terminal.write("",()=>{if(!a._tabCompletionSessionId)return;p.resetBufferDetection();const t=p.detectBufferText();t?t===a._tabCompletionBaseText?(p.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),p.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}},scrollToLastNonEmptyLine(){if(!this.terminal?.buffer?.active){this.terminal?.scrollToBottom?.();return}const e=this.terminal.buffer.active,i=e.baseY+e.length;let s=-1;for(let n=i-1;n>=0;n--)if(e.getLine(n)?.translateToString(!0).trim()){s=n;break}if(s>=0&&typeof this.terminal.scrollToLine=="function"){let n=Math.max(0,s-this.terminal.rows+2);const l=Math.max(0,s);for(;n<l&&!e.getLine(n)?.translateToString(!0).trim();)n++;this.terminal.scrollToLine(n)}else this.terminal.scrollToBottom()},chunkedTerminalWrite(e,i=TERMINAL_CHUNK_SIZE,s){const n=++this._chunkedWriteGen,l=this._beginBufferLoad(s);return new Promise(r=>{if(!e||e.length===0){this._finishBufferLoad(l),r();return}const o=e.replace(DEC_SYNC_STRIP_RE,""),u=()=>{this._chunkedWriteGen===n&&this._finishBufferLoad(l),r()};if(o.length<=i){this.terminal.write(o,u);return}let m=0;const p=performance.now();let a=0;const t=()=>{if(this._chunkedWriteGen!==n){r();return}if(m>=o.length){const h=performance.now()-p;console.log(`[CRASH-DIAG] chunkedTerminalWrite complete: ${o.length} bytes in ${a} chunks, ${h.toFixed(0)}ms total`),this._safeYield(u);return}const c=performance.now(),f=o.slice(m,m+i);this.terminal.write(f);const d=performance.now()-c;a++,d>50&&console.warn(`[CRASH-DIAG] chunk #${a} write took ${d.toFixed(0)}ms (${f.length} bytes at offset ${m})`),m+=i,this._safeYield(t)};this._safeYield(t)})},_beginBufferLoad(e){this._bufferLoadSeq===void 0&&(this._bufferLoadSeq=0);const i=e===void 0?`buffer-${++this._bufferLoadSeq}`:e;return this._bufferLoadOwner=i,this._isLoadingBuffer=!0,this._loadBufferQueue=[],i},_finishBufferLoad(e){return e!==void 0&&this._bufferLoadOwner!==e?!1:(this._isLoadingBuffer=!1,this._loadBufferQueue=null,this._bufferLoadOwner=null,!0)},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")}},_syncMobileHelperTextareaToCursor(){if(!(!MobileDetection.isTouchDevice()||!this.terminal?.element))try{const e=this.terminal.element,i=this.terminal.element.querySelector(".xterm-cursor"),s=this.terminal.element.querySelector(".xterm-screen");if(!(e instanceof HTMLElement)||!(i instanceof HTMLElement)||!(s instanceof HTMLElement))return;const n=i.getBoundingClientRect(),l=s.getBoundingClientRect();if(!n.width&&!n.height)return;const r=Math.max(0,Math.round(n.left-l.left)),o=Math.max(0,Math.round(n.top-l.top));e.style.setProperty("--xterm-helper-left",`${r}px`),e.style.setProperty("--xterm-helper-top",`${o}px`)}catch{}},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,i={}){this.fitAddon&&this.fitAddon.fit();const s=this.getTerminalDimensions();if(!s)return!1;const n=this._lastResizeDims,l=!n||n.cols!==s.cols||n.rows!==s.rows;this._lastResizeDims={cols:s.cols,rows:s.rows};const r=typeof MobileDetection<"u"&&MobileDetection.getDeviceType?MobileDetection.getDeviceType():window.innerWidth<430?"mobile":window.innerWidth<768?"tablet":"desktop";if(!i.forceHttp&&this._wsReady&&this._wsSessionId===e)try{return this._ws.send(JSON.stringify({t:"z",c:s.cols,r:s.rows,v:r})),l}catch{}return await fetch(`/api/sessions/${e}/resize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...s,viewportType:r})}),l},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)},applyTerminalSkin(e){const i={...window.CODEMAN_XTERM_THEMES[e]||window.CODEMAN_XTERM_THEMES["daylight-blue"]};if(this.terminal){this.terminal.options.theme=i;try{this.terminal.refresh(0,this.terminal.rows-1)}catch{}}if(this.teammateTerminals){for(const[,s]of this.teammateTerminals)if(s&&s.terminal){s.terminal.options.theme={...i};try{s.terminal.refresh(0,s.terminal.rows-1)}catch{}}}}});