aicodeman 0.6.3 → 0.6.5

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 (40) hide show
  1. package/dist/web/public/api-client.3adebdc2.js.gz +0 -0
  2. package/dist/web/public/app.6f362fec.js.gz +0 -0
  3. package/dist/web/public/constants.193cefd7.js.gz +0 -0
  4. package/dist/web/public/index.html +2 -2
  5. package/dist/web/public/index.html.br +0 -0
  6. package/dist/web/public/index.html.gz +0 -0
  7. package/dist/web/public/input-cjk.88082175.js.gz +0 -0
  8. package/dist/web/public/keyboard-accessory.29aebd9c.js.gz +0 -0
  9. package/dist/web/public/mobile-handlers.1e2a8ef8.js.gz +0 -0
  10. package/dist/web/public/mobile.37d62c06.css.gz +0 -0
  11. package/dist/web/public/notification-manager.2d5ea8ec.js.gz +0 -0
  12. package/dist/web/public/orchestrator-panel.js.gz +0 -0
  13. package/dist/web/public/panels-ui.07e4dee7.js.gz +0 -0
  14. package/dist/web/public/ralph-panel.61076370.js.gz +0 -0
  15. package/dist/web/public/ralph-wizard.6b0f0be7.js.gz +0 -0
  16. package/dist/web/public/{respawn-ui.60be6ef5.js → respawn-ui.5377f958.js} +4 -4
  17. package/dist/web/public/respawn-ui.5377f958.js.br +0 -0
  18. package/dist/web/public/{respawn-ui.60be6ef5.js.gz → respawn-ui.5377f958.js.gz} +0 -0
  19. package/dist/web/public/session-ui.536c2703.js.gz +0 -0
  20. package/dist/web/public/settings-ui.25a18120.js.gz +0 -0
  21. package/dist/web/public/styles.24bfe89a.css.gz +0 -0
  22. package/dist/web/public/subagent-windows.a366a4ad.js.gz +0 -0
  23. package/dist/web/public/sw.js.gz +0 -0
  24. package/dist/web/public/terminal-ui.9ec9bdd7.js +3 -0
  25. package/dist/web/public/terminal-ui.9ec9bdd7.js.br +0 -0
  26. package/dist/web/public/terminal-ui.9ec9bdd7.js.gz +0 -0
  27. package/dist/web/public/upload.html.gz +0 -0
  28. package/dist/web/public/vendor/marked.min.js.gz +0 -0
  29. package/dist/web/public/vendor/xterm-addon-fit.min.js.gz +0 -0
  30. package/dist/web/public/vendor/xterm-addon-unicode11.min.js.gz +0 -0
  31. package/dist/web/public/vendor/xterm-addon-webgl.min.js.gz +0 -0
  32. package/dist/web/public/vendor/xterm-zerolag-input.137ad9f0.js.gz +0 -0
  33. package/dist/web/public/vendor/xterm.css.gz +0 -0
  34. package/dist/web/public/vendor/xterm.min.js.gz +0 -0
  35. package/dist/web/public/voice-input.085e9e73.js.gz +0 -0
  36. package/package.json +1 -1
  37. package/dist/web/public/respawn-ui.60be6ef5.js.br +0 -0
  38. package/dist/web/public/terminal-ui.f8f6f753.js +0 -3
  39. package/dist/web/public/terminal-ui.f8f6f753.js.br +0 -0
  40. package/dist/web/public/terminal-ui.f8f6f753.js.gz +0 -0
Binary file
@@ -1794,8 +1794,8 @@
1794
1794
  <script defer src="keyboard-accessory.29aebd9c.js"></script>
1795
1795
  <script defer src="input-cjk.88082175.js"></script>
1796
1796
  <script defer src="app.6f362fec.js"></script>
1797
- <script defer src="terminal-ui.f8f6f753.js"></script>
1798
- <script defer src="respawn-ui.60be6ef5.js"></script>
1797
+ <script defer src="terminal-ui.9ec9bdd7.js"></script>
1798
+ <script defer src="respawn-ui.5377f958.js"></script>
1799
1799
  <script defer src="ralph-panel.61076370.js"></script>
1800
1800
  <script defer src="orchestrator-panel.js"></script>
1801
1801
  <script defer src="settings-ui.25a18120.js"></script>
Binary file
Binary file
@@ -1,5 +1,5 @@
1
- "use strict";Object.assign(CodemanApp.prototype,{_onRespawnStarted(e){this.respawnStatus[e.sessionId]=e.status,e.sessionId===this.activeSessionId&&this.showRespawnBanner()},_onRespawnStopped(e){delete this.respawnStatus[e.sessionId],e.sessionId===this.activeSessionId&&this.hideRespawnBanner()},_onRespawnStateChanged(e){this.respawnStatus[e.sessionId]&&(this.respawnStatus[e.sessionId].state=e.state),e.sessionId===this.activeSessionId&&this.updateRespawnBanner(e.state)},_onRespawnCycleStarted(e){this.respawnStatus[e.sessionId]&&(this.respawnStatus[e.sessionId].cycleCount=e.cycleNumber),e.sessionId===this.activeSessionId&&(document.getElementById("respawnCycleCount").textContent=e.cycleNumber)},_onRespawnBlocked(e){const s={circuit_breaker_open:"Circuit Breaker Open",exit_signal:"Exit Signal Detected",status_blocked:"Claude Reported BLOCKED"}[e.reason]||"Respawn Blocked";if(this._notifySession(e.sessionId,"critical","respawn-blocked",s,e.details),e.sessionId===this.activeSessionId){const n=document.getElementById("respawnStateLabel");n&&(n.textContent=s,n.classList.add("respawn-blocked"))}},_onRespawnAutoAcceptSent(e){const t=this.sessions.get(e.sessionId);this._notifySession(e.sessionId,"info","auto-accept","Plan Accepted",`Accepted plan mode for ${t?.name||"session"}`)},_onRespawnDetectionUpdate(e){this.respawnStatus[e.sessionId]&&(this.respawnStatus[e.sessionId].detection=e.detection),e.sessionId===this.activeSessionId&&this.updateDetectionDisplay(e.detection)},_onRespawnTimerStarted(e){if(e.endAt&&(this.respawnTimers[e.sessionId]={endAt:e.endAt,startedAt:e.startedAt,durationMinutes:e.durationMinutes},e.sessionId===this.activeSessionId&&this.showRespawnTimer()),e.timer){const{sessionId:t,timer:s}=e;this.respawnCountdownTimers[t]||(this.respawnCountdownTimers[t]={}),this.respawnCountdownTimers[t][s.name]={endsAt:s.endsAt,totalMs:s.durationMs,reason:s.reason},t===this.activeSessionId&&(this.updateCountdownTimerDisplay(),this.startCountdownInterval())}},_onRespawnTimerCancelled(e){const{sessionId:t,timerName:s}=e;this.respawnCountdownTimers[t]&&delete this.respawnCountdownTimers[t][s],t===this.activeSessionId&&this.updateCountdownTimerDisplay()},_onRespawnTimerCompleted(e){const{sessionId:t,timerName:s}=e;this.respawnCountdownTimers[t]&&delete this.respawnCountdownTimers[t][s],t===this.activeSessionId&&this.updateCountdownTimerDisplay()},_onRespawnError(e){this._notifySession(e.sessionId,"critical","session-error","Respawn Error",e.error||e.message||"Respawn encountered an error")},_onRespawnActionLog(e){const{sessionId:t,action:s}=e;this.addActionLogEntry(t,s),t===this.activeSessionId&&(this.updateCountdownTimerDisplay(),this.updateActionLogDisplay())},showRespawnBanner(){this.$("respawnBanner").style.display="flex",this.activeSessionId&&this.respawnTimers[this.activeSessionId]&&this.showRespawnTimer();const e=this.sessions.get(this.activeSessionId);e&&e.tokens&&this.updateRespawnTokens(e.tokens)},hideRespawnBanner(){this.$("respawnBanner").style.display="none",this.hideRespawnTimer()},getStateLabel(e){return{stopped:"Stopped",watching:"Watching",confirming_idle:"Confirming idle",ai_checking:"AI checking",sending_update:"Sending prompt",waiting_update:"Running prompt",sending_clear:"Clearing context",waiting_clear:"Clearing...",sending_init:"Initializing",waiting_init:"Initializing...",monitoring_init:"Waiting for work",sending_kickstart:"Kickstarting",waiting_kickstart:"Kickstarting..."}[e]||e.replace(/_/g," ")},updateRespawnBanner(e){const t=this.$("respawnState");t.textContent=this.getStateLabel(e),t.classList.remove("respawn-blocked")},updateDetectionDisplay(e){if(!e)return;const t=this.$("detectionStatus"),s=this.$("detectionWaiting"),n=this.$("detectionConfidence"),i=document.getElementById("detectionAiCheck"),a=document.getElementById("detectionHook");if(a)if(e.stopHookReceived||e.idlePromptReceived){const r=e.idlePromptReceived?"idle":"stop";a.textContent=`\u{1F3AF} ${r} hook`,a.className="detection-hook hook-active",a.style.display=""}else a.style.display="none";e.statusText&&e.statusText!=="Watching..."?(t.textContent=e.statusText,t.style.display=""):t.style.display="none",s.style.display="none";const c=e.confidenceLevel||0;if(c>0?(n.textContent=`${c}%`,n.style.display="",n.className="detection-confidence",e.stopHookReceived||e.idlePromptReceived?n.classList.add("hook-confirmed"):c>=60?n.classList.add("high"):c>=30&&n.classList.add("medium")):n.style.display="none",i&&e.aiCheck){const r=e.aiCheck;let o="",d="detection-ai-check";if(r.status==="checking")o="\u{1F50D} AI checking...",d+=" ai-checking";else if(r.status==="cooldown"&&r.cooldownEndsAt){const m=Math.ceil((r.cooldownEndsAt-Date.now())/1e3);m>0&&(r.lastVerdict==="WORKING"?(o=`\u23F3 Working, retry ${m}s`,d+=" ai-working"):(o=`\u2713 Idle, wait ${m}s`,d+=" ai-idle"))}else if(r.status==="disabled")o="\u26A0 AI disabled",d+=" ai-disabled";else if(r.lastVerdict&&r.lastCheckTime){const m=Math.round((Date.now()-r.lastCheckTime)/1e3);m<120&&(o=r.lastVerdict==="IDLE"?`\u2713 Idle (${m}s)`:`\u23F3 Working (${m}s)`,d+=r.lastVerdict==="IDLE"?" ai-idle":" ai-working")}i.textContent=o,i.className=d,i.style.display=o?"":"none"}else i&&(i.style.display="none");const l=this.$("respawnStatusRow2");if(l){const r=a&&a.style.display!=="none"||i&&i.style.display!=="none"||t&&t.style.display!=="none"||this.respawnCountdownTimers[this.activeSessionId]&&Object.keys(this.respawnCountdownTimers[this.activeSessionId]).length>0;l.style.display=r?"":"none"}},showRespawnTimer(){const e=this.$("respawnTimer");e.style.display="",this.updateRespawnTimer(),this.respawnTimerInterval&&clearInterval(this.respawnTimerInterval),this.respawnTimerInterval=setInterval(()=>this.updateRespawnTimer(),1e3)},hideRespawnTimer(){this.$("respawnTimer").style.display="none",this.respawnTimerInterval&&(clearInterval(this.respawnTimerInterval),this.respawnTimerInterval=null)},updateRespawnTimer(){if(!this.activeSessionId||!this.respawnTimers[this.activeSessionId]){this.hideRespawnTimer();return}const e=this.respawnTimers[this.activeSessionId];if(!e.endAt||isNaN(e.endAt)){this.hideRespawnTimer();return}const t=Date.now(),s=Math.max(0,e.endAt-t);if(s<=0){this.$("respawnTimer").textContent="Time up",delete this.respawnTimers[this.activeSessionId],this.hideRespawnTimer();return}this.$("respawnTimer").textContent=this.formatTime(s)},updateRespawnTokens(e){const t=e&&typeof e=="object",s=t?e.total:e;if(s===this._lastRespawnTokenTotal)return;this._lastRespawnTokenTotal=s;const n=this.$("respawnTokens"),i=t?e.input||0:Math.round(s*.6),a=t?e.output||0:Math.round(s*.4);if(s>0){n.style.display="";const c=this.formatTokens(s);if(this.loadAppSettingsFromStorage().showCost??!1){const o=this.estimateCost(i,a);n.textContent=`${c} tokens \xB7 $${o.toFixed(2)}`}else n.textContent=`${c} tokens`}else n.style.display="none";this.updateCliInfoDisplay()},updateCliInfoDisplay(){const e=this.$("cliInfoBar");if(!e)return;const t=this.sessions.get(this.activeSessionId);if(!t){e.style.display="none";return}let s=[];if(t.tokens){const n=typeof t.tokens=="object"?t.tokens.total:t.tokens;n>0&&s.push(`${this.formatTokens(n)} tokens`)}if(t.cliModel){let n=t.cliModel;n.includes("opus")?n="Opus":n.includes("sonnet")?n="Sonnet":n.includes("haiku")&&(n="Haiku"),s.push(n)}if(t.cliVersion){let n=`v${t.cliVersion}`;t.cliLatestVersion&&t.cliLatestVersion!==t.cliVersion&&(n+=" \u2191"),s.push(n)}s.length>0?(e.textContent=s.join(" \xB7 "),e.style.display=""):e.style.display="none"},addActionLogEntry(e,t){if(!["command","hook"].includes(t.type)){if(t.type==="ai-check"){if(t.detail.includes("Spawning"))return}else if(t.type==="plan-check"){if(t.detail.includes("Spawning"))return}else if(t.type!=="transcript")return}this.respawnActionLogs[e]||(this.respawnActionLogs[e]=[]),this.respawnActionLogs[e].unshift(t),this.respawnActionLogs[e].length>30&&this.respawnActionLogs[e].pop()},startCountdownInterval(){this.timerCountdownInterval||(this.timerCountdownInterval=setInterval(()=>{this.activeSessionId&&this.respawnCountdownTimers[this.activeSessionId]&&this.updateCountdownTimerDisplay()},100))},stopCountdownInterval(){this.timerCountdownInterval&&(clearInterval(this.timerCountdownInterval),this.timerCountdownInterval=null)},updateCountdownTimerDisplay(){const e=this.$("respawnCountdownTimers"),t=this.$("respawnStatusRow2");if(!e)return;const s=this.respawnCountdownTimers[this.activeSessionId];if(!(s&&Object.keys(s).length>0)){if(e.innerHTML="",t){const c=document.getElementById("detectionHook"),l=document.getElementById("detectionAiCheck"),r=this.$("detectionStatus"),o=c&&c.style.display!=="none"||l&&l.style.display!=="none"||r&&r.style.display!=="none";t.style.display=o?"":"none"}return}t&&(t.style.display="");const i=Date.now();let a="";for(const[c,l]of Object.entries(s)){const r=Math.max(0,l.endsAt-i),o=(r/1e3).toFixed(1),d=Math.max(0,Math.min(100,r/l.totalMs*100)),m=c.replace(/-/g," ").replace(/^\w/,u=>u.toUpperCase());a+=`<div class="respawn-countdown-timer" title="${escapeHtml(l.reason||"")}">
2
- <span class="timer-name">${escapeHtml(m)}</span>
1
+ "use strict";Object.assign(CodemanApp.prototype,{_onRespawnStarted(e){this.respawnStatus[e.sessionId]=e.status,e.sessionId===this.activeSessionId&&this.showRespawnBanner()},_onRespawnStopped(e){delete this.respawnStatus[e.sessionId],e.sessionId===this.activeSessionId&&this.hideRespawnBanner()},_onRespawnStateChanged(e){this.respawnStatus[e.sessionId]&&(this.respawnStatus[e.sessionId].state=e.state),e.sessionId===this.activeSessionId&&this.updateRespawnBanner(e.state)},_onRespawnCycleStarted(e){this.respawnStatus[e.sessionId]&&(this.respawnStatus[e.sessionId].cycleCount=e.cycleNumber),e.sessionId===this.activeSessionId&&(document.getElementById("respawnCycleCount").textContent=e.cycleNumber)},_onRespawnBlocked(e){const s={circuit_breaker_open:"Circuit Breaker Open",exit_signal:"Exit Signal Detected",status_blocked:"Claude Reported BLOCKED"}[e.reason]||"Respawn Blocked";if(this._notifySession(e.sessionId,"critical","respawn-blocked",s,e.details),e.sessionId===this.activeSessionId){const n=document.getElementById("respawnStateLabel");n&&(n.textContent=s,n.classList.add("respawn-blocked"))}},_onRespawnAutoAcceptSent(e){const t=this.sessions.get(e.sessionId);this._notifySession(e.sessionId,"info","auto-accept","Plan Accepted",`Accepted plan mode for ${t?.name||"session"}`)},_onRespawnDetectionUpdate(e){this.respawnStatus[e.sessionId]&&(this.respawnStatus[e.sessionId].detection=e.detection),e.sessionId===this.activeSessionId&&this.updateDetectionDisplay(e.detection)},_onRespawnTimerStarted(e){if(e.endAt&&(this.respawnTimers[e.sessionId]={endAt:e.endAt,startedAt:e.startedAt,durationMinutes:e.durationMinutes},e.sessionId===this.activeSessionId&&this.showRespawnTimer()),e.timer){const{sessionId:t,timer:s}=e;this.respawnCountdownTimers[t]||(this.respawnCountdownTimers[t]={}),this.respawnCountdownTimers[t][s.name]={endsAt:s.endsAt,totalMs:s.durationMs,reason:s.reason},t===this.activeSessionId&&(this.updateCountdownTimerDisplay(),this.startCountdownInterval())}},_onRespawnTimerCancelled(e){const{sessionId:t,timerName:s}=e;this.respawnCountdownTimers[t]&&delete this.respawnCountdownTimers[t][s],t===this.activeSessionId&&this.updateCountdownTimerDisplay()},_onRespawnTimerCompleted(e){const{sessionId:t,timerName:s}=e;this.respawnCountdownTimers[t]&&delete this.respawnCountdownTimers[t][s],t===this.activeSessionId&&this.updateCountdownTimerDisplay()},_onRespawnError(e){this._notifySession(e.sessionId,"critical","session-error","Respawn Error",e.error||e.message||"Respawn encountered an error")},_onRespawnActionLog(e){const{sessionId:t,action:s}=e;this.addActionLogEntry(t,s),t===this.activeSessionId&&(this.updateCountdownTimerDisplay(),this.updateActionLogDisplay())},showRespawnBanner(){this.$("respawnBanner").style.display="flex",this.activeSessionId&&this.respawnTimers[this.activeSessionId]&&this.showRespawnTimer();const e=this.sessions.get(this.activeSessionId);e&&e.tokens&&this.updateRespawnTokens(e.tokens)},hideRespawnBanner(){this.$("respawnBanner").style.display="none",this.hideRespawnTimer()},getStateLabel(e){return{stopped:"Stopped",watching:"Watching",confirming_idle:"Confirming idle",ai_checking:"AI checking",sending_update:"Sending prompt",waiting_update:"Running prompt",sending_clear:"Clearing context",waiting_clear:"Clearing...",sending_init:"Initializing",waiting_init:"Initializing...",monitoring_init:"Waiting for work",sending_kickstart:"Kickstarting",waiting_kickstart:"Kickstarting..."}[e]||e.replace(/_/g," ")},updateRespawnBanner(e){const t=this.$("respawnState");t.textContent=this.getStateLabel(e),t.classList.remove("respawn-blocked")},updateDetectionDisplay(e){if(!e)return;const t=this.$("detectionStatus"),s=this.$("detectionWaiting"),n=this.$("detectionConfidence"),i=document.getElementById("detectionAiCheck"),a=document.getElementById("detectionHook");if(a)if(e.stopHookReceived||e.idlePromptReceived){const r=e.idlePromptReceived?"idle":"stop";a.textContent=`\u{1F3AF} ${r} hook`,a.className="detection-hook hook-active",a.style.display=""}else a.style.display="none";e.statusText&&e.statusText!=="Watching..."?(t.textContent=e.statusText,t.style.display=""):t.style.display="none",s.style.display="none";const c=e.confidenceLevel||0;if(c>0?(n.textContent=`${c}%`,n.style.display="",n.className="detection-confidence",e.stopHookReceived||e.idlePromptReceived?n.classList.add("hook-confirmed"):c>=60?n.classList.add("high"):c>=30&&n.classList.add("medium")):n.style.display="none",i&&e.aiCheck){const r=e.aiCheck;let o="",d="detection-ai-check";if(r.status==="checking")o="\u{1F50D} AI checking...",d+=" ai-checking";else if(r.status==="cooldown"&&r.cooldownEndsAt){const u=Math.ceil((r.cooldownEndsAt-Date.now())/1e3);u>0&&(r.lastVerdict==="WORKING"?(o=`\u23F3 Working, retry ${u}s`,d+=" ai-working"):(o=`\u2713 Idle, wait ${u}s`,d+=" ai-idle"))}else if(r.status==="disabled")o="\u26A0 AI disabled",d+=" ai-disabled";else if(r.lastVerdict&&r.lastCheckTime){const u=Math.round((Date.now()-r.lastCheckTime)/1e3);u<120&&(o=r.lastVerdict==="IDLE"?`\u2713 Idle (${u}s)`:`\u23F3 Working (${u}s)`,d+=r.lastVerdict==="IDLE"?" ai-idle":" ai-working")}i.textContent=o,i.className=d,i.style.display=o?"":"none"}else i&&(i.style.display="none");const l=this.$("respawnStatusRow2");if(l){const r=a&&a.style.display!=="none"||i&&i.style.display!=="none"||t&&t.style.display!=="none"||this.respawnCountdownTimers[this.activeSessionId]&&Object.keys(this.respawnCountdownTimers[this.activeSessionId]).length>0;l.style.display=r?"":"none"}},showRespawnTimer(){const e=this.$("respawnTimer");e.style.display="",this.updateRespawnTimer(),this.respawnTimerInterval&&clearInterval(this.respawnTimerInterval),this.respawnTimerInterval=setInterval(()=>this.updateRespawnTimer(),1e3)},hideRespawnTimer(){this.$("respawnTimer").style.display="none",this.respawnTimerInterval&&(clearInterval(this.respawnTimerInterval),this.respawnTimerInterval=null)},updateRespawnTimer(){if(!this.activeSessionId||!this.respawnTimers[this.activeSessionId]){this.hideRespawnTimer();return}const e=this.respawnTimers[this.activeSessionId];if(!e.endAt||isNaN(e.endAt)){this.hideRespawnTimer();return}const t=Date.now(),s=Math.max(0,e.endAt-t);if(s<=0){this.$("respawnTimer").textContent="Time up",delete this.respawnTimers[this.activeSessionId],this.hideRespawnTimer();return}this.$("respawnTimer").textContent=this.formatTime(s)},updateRespawnTokens(e){const t=e&&typeof e=="object",s=t?e.total:e;if(s===this._lastRespawnTokenTotal)return;this._lastRespawnTokenTotal=s;const n=this.$("respawnTokens"),i=t?e.input||0:Math.round(s*.6),a=t?e.output||0:Math.round(s*.4);if(s>0){n.style.display="";const c=this.formatTokens(s);if(this.loadAppSettingsFromStorage().showCost??!1){const o=this.estimateCost(i,a);n.textContent=`${c} tokens \xB7 $${o.toFixed(2)}`}else n.textContent=`${c} tokens`}else n.style.display="none";this.updateCliInfoDisplay()},updateCliInfoDisplay(){const e=this.$("cliInfoBar");if(!e)return;const t=this.sessions.get(this.activeSessionId);if(!t){e.style.display="none";return}let s=[];if(t.tokens){const n=typeof t.tokens=="object"?t.tokens.total:t.tokens;n>0&&s.push(`${this.formatTokens(n)} tokens`)}if(t.cliModel){let n=t.cliModel;n.includes("opus")?n="Opus":n.includes("sonnet")?n="Sonnet":n.includes("haiku")&&(n="Haiku"),s.push(n)}if(t.cliVersion){let n=`v${t.cliVersion}`;t.cliLatestVersion&&t.cliLatestVersion!==t.cliVersion&&(n+=" \u2191"),s.push(n)}s.length>0?(e.textContent=s.join(" \xB7 "),e.style.display=""):e.style.display="none"},addActionLogEntry(e,t){if(!["command","hook"].includes(t.type)){if(t.type==="ai-check"){if(t.detail.includes("Spawning"))return}else if(t.type==="plan-check"){if(t.detail.includes("Spawning"))return}else if(t.type!=="transcript")return}this.respawnActionLogs[e]||(this.respawnActionLogs[e]=[]),this.respawnActionLogs[e].unshift(t),this.respawnActionLogs[e].length>30&&this.respawnActionLogs[e].pop()},startCountdownInterval(){this.timerCountdownInterval||(this.timerCountdownInterval=setInterval(()=>{this.activeSessionId&&this.respawnCountdownTimers[this.activeSessionId]&&this.updateCountdownTimerDisplay()},100))},stopCountdownInterval(){this.timerCountdownInterval&&(clearInterval(this.timerCountdownInterval),this.timerCountdownInterval=null)},updateCountdownTimerDisplay(){const e=this.$("respawnCountdownTimers"),t=this.$("respawnStatusRow2");if(!e)return;const s=this.respawnCountdownTimers[this.activeSessionId];if(!(s&&Object.keys(s).length>0)){if(e.innerHTML="",t){const c=document.getElementById("detectionHook"),l=document.getElementById("detectionAiCheck"),r=this.$("detectionStatus"),o=c&&c.style.display!=="none"||l&&l.style.display!=="none"||r&&r.style.display!=="none";t.style.display=o?"":"none"}return}t&&(t.style.display="");const i=Date.now();let a="";for(const[c,l]of Object.entries(s)){const r=Math.max(0,l.endsAt-i),o=(r/1e3).toFixed(1),d=Math.max(0,Math.min(100,r/l.totalMs*100)),u=c.replace(/-/g," ").replace(/^\w/,m=>m.toUpperCase());a+=`<div class="respawn-countdown-timer" title="${escapeHtml(l.reason||"")}">
2
+ <span class="timer-name">${escapeHtml(u)}</span>
3
3
  <span class="timer-value">${o}s</span>
4
4
  <div class="respawn-timer-bar">
5
5
  <div class="respawn-timer-progress" style="width: ${d}%"></div>
@@ -8,7 +8,7 @@
8
8
  <span class="action-time">${i}</span>
9
9
  <span class="action-type">[${n.type}]</span>
10
10
  <span class="action-detail">${escapeHtml(n.detail)}</span>
11
- </div>`}e.innerHTML=s},clearCountdownTimers(e){delete this.respawnCountdownTimers[e],delete this.respawnActionLogs[e],e===this.activeSessionId&&(this.updateCountdownTimerDisplay(),this.updateActionLogDisplay())},async stopRespawn(){if(this.activeSessionId)try{await this._apiPost(`/api/sessions/${this.activeSessionId}/respawn/stop`,{}),delete this.respawnTimers[this.activeSessionId],this.clearCountdownTimers(this.activeSessionId)}catch{this.showToast("Failed to stop respawn","error")}},loadRespawnPresets(){const e=this._serverRespawnPresets;if(e)return[...BUILTIN_RESPAWN_PRESETS,...e];const t=localStorage.getItem("codeman-respawn-presets"),s=t?JSON.parse(t):[];return[...BUILTIN_RESPAWN_PRESETS,...s]},saveRespawnPresets(e){const t=e.filter(s=>!s.builtIn);this._serverRespawnPresets=t,localStorage.setItem("codeman-respawn-presets",JSON.stringify(t)),this._apiPut("/api/settings",{respawnPresets:t}).catch(()=>{})},renderPresetDropdown(){const e=this.loadRespawnPresets(),t=document.getElementById("builtinPresetsGroup"),s=document.getElementById("customPresetsGroup");!t||!s||(t.innerHTML="",s.innerHTML="",e.forEach(n=>{const i=document.createElement("option");i.value=n.id,i.textContent=n.name,n.builtIn?t.appendChild(i):s.appendChild(i)}))},updatePresetDescription(){const e=document.getElementById("respawnPresetSelect"),t=document.getElementById("presetDescriptionHint");if(!e||!t)return;const s=e.value;if(!s){t.textContent="";return}const i=this.loadRespawnPresets().find(a=>a.id===s);t.textContent=i?.description||""},loadRespawnPreset(){const e=document.getElementById("respawnPresetSelect"),t=e?.value;if(!t){this.showToast("Please select a preset first","warning");return}const n=this.loadRespawnPresets().find(i=>i.id===t);n&&(document.getElementById("modalRespawnPrompt").value=n.config.updatePrompt||"",document.getElementById("modalRespawnSendClear").checked=n.config.sendClear??!1,document.getElementById("modalRespawnSendInit").checked=n.config.sendInit??!1,document.getElementById("modalRespawnKickstart").value=n.config.kickstartPrompt||"",document.getElementById("modalRespawnAutoAccept").checked=n.config.autoAcceptPrompts??!0,n.durationMinutes&&this.selectDurationPreset(String(n.durationMinutes)),e.value="",document.getElementById("presetDescriptionHint").textContent="",this.showToast(`Loaded preset: ${n.name}`,"info"))},saveCurrentAsPreset(){document.getElementById("savePresetModal").classList.add("active"),document.getElementById("presetNameInput").value="",document.getElementById("presetDescriptionInput").value="",document.getElementById("presetNameInput").focus()},closeSavePresetModal(){document.getElementById("savePresetModal").classList.remove("active")},confirmSavePreset(){const e=document.getElementById("presetNameInput").value.trim();if(!e){this.showToast("Please enter a preset name","error");return}const t=document.getElementById("modalRespawnPrompt").value,s=document.getElementById("modalRespawnSendClear").checked,n=document.getElementById("modalRespawnSendInit").checked,i=document.getElementById("modalRespawnKickstart").value.trim()||void 0,a=this.getSelectedDuration(),c={id:"custom-"+Date.now(),name:e,description:document.getElementById("presetDescriptionInput").value.trim()||void 0,config:{idleTimeoutMs:5e3,updatePrompt:t,interStepDelayMs:3e3,sendClear:s,sendInit:n,kickstartPrompt:i},durationMinutes:a||void 0,builtIn:!1,createdAt:Date.now()},l=this.loadRespawnPresets();l.push(c),this.saveRespawnPresets(l),this.renderPresetDropdown(),this.closeSavePresetModal(),this.showToast(`Saved preset: ${e}`,"success")},deletePreset(e){const t=this.loadRespawnPresets(),s=t.find(i=>i.id===e);if(!s||s.builtIn){this.showToast("Cannot delete built-in presets","warning");return}const n=t.filter(i=>i.id!==e);this.saveRespawnPresets(n),this.renderPresetDropdown(),this.showToast(`Deleted preset: ${s.name}`,"success")},getModalRespawnConfig(){const e=document.getElementById("modalRespawnPrompt").value,t=document.getElementById("modalRespawnSendClear").checked,s=document.getElementById("modalRespawnSendInit").checked,n=document.getElementById("modalRespawnKickstart").value.trim()||void 0,i=document.getElementById("modalRespawnAutoAccept").checked,a=this.getSelectedDuration(),c=document.getElementById("modalAutoCompactEnabled").checked,l=parseInt(document.getElementById("modalAutoCompactThreshold").value)||11e4,r=document.getElementById("modalAutoCompactPrompt").value.trim()||void 0,o=document.getElementById("modalAutoClearEnabled").checked,d=parseInt(document.getElementById("modalAutoClearThreshold").value)||14e4;return{respawnConfig:{enabled:!0,updatePrompt:e,sendClear:t,sendInit:s,kickstartPrompt:n,autoAcceptPrompts:i},durationMinutes:a,autoCompactEnabled:c,autoCompactThreshold:l,autoCompactPrompt:r,autoClearEnabled:o,autoClearThreshold:d}},async enableRespawnFromModal(){if(!this.editingSessionId){this.showToast("No session selected","warning");return}const{respawnConfig:e,durationMinutes:t,autoCompactEnabled:s,autoCompactThreshold:n,autoCompactPrompt:i,autoClearEnabled:a,autoClearThreshold:c}=this.getModalRespawnConfig();try{const r=await(await fetch(`/api/sessions/${this.editingSessionId}/respawn/enable`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({config:e,durationMinutes:t})})).json();if(r.error)throw new Error(r.error);s&&await fetch(`/api/sessions/${this.editingSessionId}/auto-compact`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!0,threshold:n,prompt:i})}),a&&await fetch(`/api/sessions/${this.editingSessionId}/auto-clear`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!0,threshold:c})});const o=document.getElementById("sessionRespawnStatus");o.classList.add("active"),o.querySelector(".respawn-status-text").textContent="WATCHING",document.getElementById("modalEnableRespawnBtn").style.display="none",document.getElementById("modalStopRespawnBtn").style.display="",this.showToast("Respawn enabled","success")}catch(l){this.showToast("Failed to enable respawn: "+l.message,"error")}},async stopRespawnFromModal(){if(this.editingSessionId)try{await fetch(`/api/sessions/${this.editingSessionId}/respawn/stop`,{method:"POST"}),delete this.respawnTimers[this.editingSessionId];const e=document.getElementById("sessionRespawnStatus");e.classList.remove("active"),e.querySelector(".respawn-status-text").textContent="Not active",document.getElementById("modalEnableRespawnBtn").style.display="",document.getElementById("modalStopRespawnBtn").style.display="none",this.showToast("Respawn stopped","success")}catch{this.showToast("Failed to stop respawn","error")}},closeSessionOptions(){this.editingSessionId=null,this.stopRunSummaryAutoRefresh(),document.getElementById("sessionOptionsModal").classList.remove("active"),this.activeFocusTrap&&(this.activeFocusTrap.deactivate(),this.activeFocusTrap=null)},setupColorPicker(){const e=document.getElementById("sessionColorPicker");e&&e.addEventListener("click",t=>{const s=t.target.closest(".color-swatch");if(!s||!this.editingSessionId)return;const n=s.dataset.color;this.setSessionColor(this.editingSessionId,n)})},async setSessionColor(e,t){try{if((await fetch(`/api/sessions/${e}/color`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({color:t})})).ok){const n=this.sessions.get(e);n&&(n.color=t,this.renderSessionTabs());const i=document.getElementById("sessionColorPicker");i&&i.querySelectorAll(".color-swatch").forEach(a=>{a.classList.toggle("selected",a.dataset.color===t)})}else this.showToast("Failed to set session color","error")}catch{this.showToast("Failed to set session color","error")}},async openRunSummary(e){this.openSessionOptions(e),this.switchOptionsTab("summary"),this.runSummarySessionId=e,this.runSummaryFilter="all",document.querySelectorAll(".run-summary-filters .filter-btn").forEach(t=>{t.classList.toggle("active",t.dataset.filter==="all")}),await this.loadRunSummary(e)},closeRunSummary(){this.runSummarySessionId=null,this.stopRunSummaryAutoRefresh(),this.closeSessionOptions()},async refreshRunSummary(){const e=this.runSummarySessionId||this.editingSessionId;e&&await this.loadRunSummary(e)},toggleRunSummaryAutoRefresh(){document.getElementById("runSummaryAutoRefresh").checked?this.startRunSummaryAutoRefresh():this.stopRunSummaryAutoRefresh()},startRunSummaryAutoRefresh(){this.runSummaryAutoRefreshTimer||(this.runSummaryAutoRefreshTimer=setInterval(()=>{this.runSummarySessionId&&this.loadRunSummary(this.runSummarySessionId)},5e3))},stopRunSummaryAutoRefresh(){this.runSummaryAutoRefreshTimer&&(clearInterval(this.runSummaryAutoRefreshTimer),this.runSummaryAutoRefreshTimer=null);const e=document.getElementById("runSummaryAutoRefresh");e&&(e.checked=!1)},exportRunSummary(e){if(!this.runSummaryData){this.showToast("No summary data to export","error");return}const{stats:t,events:s,sessionName:n,startedAt:i,lastUpdatedAt:a}=this.runSummaryData,c=new Date().toISOString().slice(0,19).replace(/:/g,"-"),l=`run-summary-${n||"session"}-${c}`;if(e==="json"){const r=JSON.stringify(this.runSummaryData,null,2);this.downloadFile(`${l}.json`,r,"application/json")}else if(e==="md"){const r=a-i;let o=`# Run Summary: ${n||"Session"}
11
+ </div>`}e.innerHTML=s},clearCountdownTimers(e){delete this.respawnCountdownTimers[e],delete this.respawnActionLogs[e],e===this.activeSessionId&&(this.updateCountdownTimerDisplay(),this.updateActionLogDisplay())},async stopRespawn(){if(this.activeSessionId)try{await this._apiPost(`/api/sessions/${this.activeSessionId}/respawn/stop`,{}),delete this.respawnTimers[this.activeSessionId],this.clearCountdownTimers(this.activeSessionId)}catch{this.showToast("Failed to stop respawn","error")}},loadRespawnPresets(){const e=this._serverRespawnPresets;if(e)return[...BUILTIN_RESPAWN_PRESETS,...e];const t=localStorage.getItem("codeman-respawn-presets"),s=t?JSON.parse(t):[];return[...BUILTIN_RESPAWN_PRESETS,...s]},saveRespawnPresets(e){const t=e.filter(s=>!s.builtIn);this._serverRespawnPresets=t,localStorage.setItem("codeman-respawn-presets",JSON.stringify(t)),this._apiPut("/api/settings",{respawnPresets:t}).catch(()=>{})},renderPresetDropdown(){const e=this.loadRespawnPresets(),t=document.getElementById("builtinPresetsGroup"),s=document.getElementById("customPresetsGroup");!t||!s||(t.innerHTML="",s.innerHTML="",e.forEach(n=>{const i=document.createElement("option");i.value=n.id,i.textContent=n.name,n.builtIn?t.appendChild(i):s.appendChild(i)}))},updatePresetDescription(){const e=document.getElementById("respawnPresetSelect"),t=document.getElementById("presetDescriptionHint");if(!e||!t)return;const s=e.value;if(!s){t.textContent="";return}const i=this.loadRespawnPresets().find(a=>a.id===s);t.textContent=i?.description||""},loadRespawnPreset(){const e=document.getElementById("respawnPresetSelect"),t=e?.value;if(!t){this.showToast("Please select a preset first","warning");return}const n=this.loadRespawnPresets().find(i=>i.id===t);n&&(document.getElementById("modalRespawnPrompt").value=n.config.updatePrompt||"",document.getElementById("modalRespawnSendClear").checked=n.config.sendClear??!1,document.getElementById("modalRespawnSendInit").checked=n.config.sendInit??!1,document.getElementById("modalRespawnKickstart").value=n.config.kickstartPrompt||"",document.getElementById("modalRespawnAutoAccept").checked=n.config.autoAcceptPrompts??!0,n.durationMinutes&&this.selectDurationPreset(String(n.durationMinutes)),e.value="",document.getElementById("presetDescriptionHint").textContent="",this.showToast(`Loaded preset: ${n.name}`,"info"))},saveCurrentAsPreset(){document.getElementById("savePresetModal").classList.add("active"),document.getElementById("presetNameInput").value="",document.getElementById("presetDescriptionInput").value="",document.getElementById("presetNameInput").focus()},closeSavePresetModal(){document.getElementById("savePresetModal").classList.remove("active")},confirmSavePreset(){const e=document.getElementById("presetNameInput").value.trim();if(!e){this.showToast("Please enter a preset name","error");return}const t=document.getElementById("modalRespawnPrompt").value,s=document.getElementById("modalRespawnSendClear").checked,n=document.getElementById("modalRespawnSendInit").checked,i=document.getElementById("modalRespawnKickstart").value.trim()||void 0,a=this.getSelectedDuration(),c={id:"custom-"+Date.now(),name:e,description:document.getElementById("presetDescriptionInput").value.trim()||void 0,config:{idleTimeoutMs:5e3,updatePrompt:t,interStepDelayMs:3e3,sendClear:s,sendInit:n,kickstartPrompt:i},durationMinutes:a||void 0,builtIn:!1,createdAt:Date.now()},l=this.loadRespawnPresets();l.push(c),this.saveRespawnPresets(l),this.renderPresetDropdown(),this.closeSavePresetModal(),this.showToast(`Saved preset: ${e}`,"success")},deletePreset(e){const t=this.loadRespawnPresets(),s=t.find(i=>i.id===e);if(!s||s.builtIn){this.showToast("Cannot delete built-in presets","warning");return}const n=t.filter(i=>i.id!==e);this.saveRespawnPresets(n),this.renderPresetDropdown(),this.showToast(`Deleted preset: ${s.name}`,"success")},getModalRespawnConfig(){const e=document.getElementById("modalRespawnPrompt").value,t=document.getElementById("modalRespawnSendClear").checked,s=document.getElementById("modalRespawnSendInit").checked,n=document.getElementById("modalRespawnKickstart").value.trim()||void 0,i=document.getElementById("modalRespawnAutoAccept").checked,a=this.getSelectedDuration(),c=document.getElementById("modalAutoCompactEnabled").checked,l=parseInt(document.getElementById("modalAutoCompactThreshold").value)||11e4,r=document.getElementById("modalAutoCompactPrompt").value.trim()||void 0,o=document.getElementById("modalAutoClearEnabled").checked,d=parseInt(document.getElementById("modalAutoClearThreshold").value)||14e4;return{respawnConfig:{enabled:!0,updatePrompt:e,sendClear:t,sendInit:s,kickstartPrompt:n,autoAcceptPrompts:i},durationMinutes:a,autoCompactEnabled:c,autoCompactThreshold:l,autoCompactPrompt:r,autoClearEnabled:o,autoClearThreshold:d}},async enableRespawnFromModal(){if(!this.editingSessionId){this.showToast("No session selected","warning");return}const{respawnConfig:e,durationMinutes:t,autoCompactEnabled:s,autoCompactThreshold:n,autoCompactPrompt:i,autoClearEnabled:a,autoClearThreshold:c}=this.getModalRespawnConfig();try{const r=await(await fetch(`/api/sessions/${this.editingSessionId}/respawn/enable`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({config:e,durationMinutes:t??void 0})})).json();if(r.error)throw new Error(r.error);s&&await fetch(`/api/sessions/${this.editingSessionId}/auto-compact`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!0,threshold:n,prompt:i})}),a&&await fetch(`/api/sessions/${this.editingSessionId}/auto-clear`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!0,threshold:c})});const o=document.getElementById("sessionRespawnStatus");o.classList.add("active"),o.querySelector(".respawn-status-text").textContent="WATCHING",document.getElementById("modalEnableRespawnBtn").style.display="none",document.getElementById("modalStopRespawnBtn").style.display="",this.showToast("Respawn enabled","success")}catch(l){this.showToast("Failed to enable respawn: "+l.message,"error")}},async stopRespawnFromModal(){if(this.editingSessionId)try{await fetch(`/api/sessions/${this.editingSessionId}/respawn/stop`,{method:"POST"}),delete this.respawnTimers[this.editingSessionId];const e=document.getElementById("sessionRespawnStatus");e.classList.remove("active"),e.querySelector(".respawn-status-text").textContent="Not active",document.getElementById("modalEnableRespawnBtn").style.display="",document.getElementById("modalStopRespawnBtn").style.display="none",this.showToast("Respawn stopped","success")}catch{this.showToast("Failed to stop respawn","error")}},closeSessionOptions(){this.editingSessionId=null,this.stopRunSummaryAutoRefresh(),document.getElementById("sessionOptionsModal").classList.remove("active"),this.activeFocusTrap&&(this.activeFocusTrap.deactivate(),this.activeFocusTrap=null)},setupColorPicker(){const e=document.getElementById("sessionColorPicker");e&&e.addEventListener("click",t=>{const s=t.target.closest(".color-swatch");if(!s||!this.editingSessionId)return;const n=s.dataset.color;this.setSessionColor(this.editingSessionId,n)})},async setSessionColor(e,t){try{if((await fetch(`/api/sessions/${e}/color`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({color:t})})).ok){const n=this.sessions.get(e);n&&(n.color=t,this.renderSessionTabs());const i=document.getElementById("sessionColorPicker");i&&i.querySelectorAll(".color-swatch").forEach(a=>{a.classList.toggle("selected",a.dataset.color===t)})}else this.showToast("Failed to set session color","error")}catch{this.showToast("Failed to set session color","error")}},async openRunSummary(e){this.openSessionOptions(e),this.switchOptionsTab("summary"),this.runSummarySessionId=e,this.runSummaryFilter="all",document.querySelectorAll(".run-summary-filters .filter-btn").forEach(t=>{t.classList.toggle("active",t.dataset.filter==="all")}),await this.loadRunSummary(e)},closeRunSummary(){this.runSummarySessionId=null,this.stopRunSummaryAutoRefresh(),this.closeSessionOptions()},async refreshRunSummary(){const e=this.runSummarySessionId||this.editingSessionId;e&&await this.loadRunSummary(e)},toggleRunSummaryAutoRefresh(){document.getElementById("runSummaryAutoRefresh").checked?this.startRunSummaryAutoRefresh():this.stopRunSummaryAutoRefresh()},startRunSummaryAutoRefresh(){this.runSummaryAutoRefreshTimer||(this.runSummaryAutoRefreshTimer=setInterval(()=>{this.runSummarySessionId&&this.loadRunSummary(this.runSummarySessionId)},5e3))},stopRunSummaryAutoRefresh(){this.runSummaryAutoRefreshTimer&&(clearInterval(this.runSummaryAutoRefreshTimer),this.runSummaryAutoRefreshTimer=null);const e=document.getElementById("runSummaryAutoRefresh");e&&(e.checked=!1)},exportRunSummary(e){if(!this.runSummaryData){this.showToast("No summary data to export","error");return}const{stats:t,events:s,sessionName:n,startedAt:i,lastUpdatedAt:a}=this.runSummaryData,c=new Date().toISOString().slice(0,19).replace(/:/g,"-"),l=`run-summary-${n||"session"}-${c}`;if(e==="json"){const r=JSON.stringify(this.runSummaryData,null,2);this.downloadFile(`${l}.json`,r,"application/json")}else if(e==="md"){const r=a-i;let o=`# Run Summary: ${n||"Session"}
12
12
 
13
13
  `;if(o+=`**Duration**: ${this.formatDuration(r)}
14
14
  `,o+=`**Started**: ${new Date(i).toLocaleString()}
@@ -32,7 +32,7 @@
32
32
  `,s.length===0)o+=`No events recorded.
33
33
  `;else{o+=`| Time | Type | Severity | Title | Details |
34
34
  `,o+=`|------|------|----------|-------|----------|
35
- `;for(const d of s){const m=new Date(d.timestamp).toLocaleTimeString("en-US",{hour12:!1}),u=d.details?d.details.replace(/\|/g,"\\|"):"-";o+=`| ${m} | ${d.type} | ${d.severity} | ${d.title} | ${u} |
35
+ `;for(const d of s){const u=new Date(d.timestamp).toLocaleTimeString("en-US",{hour12:!1}),m=d.details?d.details.replace(/\|/g,"\\|"):"-";o+=`| ${u} | ${d.type} | ${d.severity} | ${d.title} | ${m} |
36
36
  `}}this.downloadFile(`${l}.md`,o,"text/markdown")}this.showToast(`Exported as ${e.toUpperCase()}`,"success")},downloadFile(e,t,s){const n=new Blob([t],{type:s}),i=URL.createObjectURL(n),a=document.createElement("a");a.href=i,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)},async loadRunSummary(e){const t=document.getElementById("runSummaryTimeline");t.innerHTML='<p class="empty-message">Loading summary...</p>';try{const n=await(await fetch(`/api/sessions/${e}/run-summary`)).json();if(!n.success){t.innerHTML=`<p class="empty-message">Failed to load summary: ${escapeHtml(n.error)}</p>`;return}this.runSummaryData=n.summary,this.renderRunSummary()}catch(s){console.error("Failed to load run summary:",s),t.innerHTML='<p class="empty-message">Failed to load summary</p>'}},renderRunSummary(){if(!this.runSummaryData)return;const{stats:e,events:t,sessionName:s,startedAt:n,lastUpdatedAt:i}=this.runSummaryData,a=i-n;document.getElementById("runSummarySessionInfo").textContent=`${s||"Session"} - ${this.formatDuration(a)} total`;const c=this.filterRunSummaryEvents(t);this.renderRunSummaryTimeline(c)},filterRunSummaryEvents(e){return this.runSummaryFilter==="all"?e:e.filter(t=>{switch(this.runSummaryFilter){case"errors":return t.severity==="error";case"warnings":return t.severity==="warning"||t.severity==="error";case"respawn":return t.type.startsWith("respawn_")||t.type==="state_stuck";case"idle":return t.type==="idle_detected"||t.type==="working_detected";default:return!0}})},filterRunSummary(e){this.runSummaryFilter=e,document.querySelectorAll(".run-summary-filters .filter-btn").forEach(t=>{t.classList.toggle("active",t.dataset.filter===e)}),this.renderRunSummary()},renderRunSummaryTimeline(e){const t=document.getElementById("runSummaryTimeline");if(!e||e.length===0){t.innerHTML='<p class="empty-message">No events recorded yet</p>';return}const n=[...e].reverse().map(i=>{const a=new Date(i.timestamp).toLocaleTimeString("en-US",{hour12:!1}),c=`event-${i.severity}`,l=this.getEventIcon(i.type,i.severity);return`
37
37
  <div class="timeline-event ${c}">
38
38
  <div class="event-icon">${l}</div>
Binary file
@@ -0,0 +1,3 @@
1
+ "use strict";Object.assign(CodemanApp.prototype,{initTerminal(){const e=parseInt(localStorage.getItem("codeman-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:e,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 i=document.getElementById("terminalContainer");this.terminal.open(i),this.terminal.attachCustomKeyEventHandler(t=>{if(t.isComposing||t.keyCode===229||t.altKey&&t.key>="0"&&t.key<="9")return!1;if(t.key==="Enter"&&(t.shiftKey||t.ctrlKey)&&t.type==="keydown"){if(this.activeSessionId)if(this._localEchoEnabled){const l=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._localEchoOverlay?.suppressBufferDetection(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),l&&(this._pendingInput+=l,r()),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"})})},l?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=i.querySelector(".xterm-helper-textarea");if(t&&MobileDetection.isTouchDevice()){let l=!1,h=0;t.addEventListener("compositionstart",()=>{l=!0}),t.addEventListener("compositionend",()=>{l=!1}),t.addEventListener("keydown",c=>{!c.isComposing&&c.keyCode!==229&&(h=Date.now())}),t.addEventListener("input",c=>{if(l||c.isComposing||c.inputType!=="insertText"||!c.data||Date.now()-h<50)return;const u=c.data;Promise.resolve().then(()=>{const a=t.value;!a||a.trim()===""&&u!==" "||(this.terminal._core.coreService.triggerDataEvent(u,!0),t.value="")})})}}if(this._webglAddon=null,!(MobileDetection.getDeviceType()!=="desktop")&&!new URLSearchParams(location.search).has("nowebgl"))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(),i.addEventListener("wheel",t=>{t.preventDefault();const l=Math.round(t.deltaY/25)||(t.deltaY>0?1:-1);this.terminal.scrollLines(l)},{passive:!1});{const t=()=>this.terminal._core?._renderService?.dimensions?.css?.cell?.height||13;let l=0,h=0,c=0,u=null,a=!1;const m=y=>{const _=c?(y-c)/16.67:1;if(c=y,!a&&Math.abs(h)>.3){const v=Math.round(h/t());v!==0&&this.terminal.scrollLines(v),h*=.92,u=requestAnimationFrame(m)}else a?u=requestAnimationFrame(m):(u=null,h=0)};let p=0,g=!1;i.addEventListener("touchstart",y=>{y.touches.length===1&&(l=y.touches[0].clientY,h=0,p=0,a=!0,g=!1,c=0,u&&(cancelAnimationFrame(u),u=null))},{passive:!0}),i.addEventListener("touchmove",y=>{if(y.touches.length===1&&a){g=!0;const _=y.touches[0].clientY,v=l-_;p+=v,h=v*1.2,l=_;const b=t(),S=Math.trunc(p/b);S!==0&&(this.terminal.scrollLines(S),p-=S*b)}},{passive:!0}),i.addEventListener("touchend",()=>{a=!1,!u&&Math.abs(h)>.3&&(u=requestAnimationFrame(m)),!g&&this.terminal&&this.terminal.focus()},{passive:!0}),i.addEventListener("touchcancel",()=>{a=!1,h=0,p=0},{passive:!0})}this.showWelcome(),this._chunkedWriteGen=0,this._resizeTimeout=null,this._lastResizeDims=null;const d=40,f=10,o=()=>{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 l=this.fitAddon.proposeDimensions(),h=l?Math.max(l.cols,d):d,c=l?Math.max(l.rows,f):f;if(!this._lastResizeDims||h!==this._lastResizeDims.cols||c!==this._lastResizeDims.rows){const u=this.activeSessionId?this.sessions.get(this.activeSessionId):null;u&&u.mode!=="shell"&&!u._ended&&this.terminal&&this.isTerminalAtBottom()&&this.terminal.write("\x1B[3J\x1B[H\x1B[2J"),this._lastResizeDims={cols:h,rows:c},fetch(`/api/sessions/${this.activeSessionId}/resize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cols:h,rows:c})}).catch(()=>{})}}this.updateConnectionLines(),this._localEchoOverlay?.hasPending&&this._localEchoOverlay.rerender()},300)};window.addEventListener("resize",o),this.terminalResizeObserver&&this.terminalResizeObserver.disconnect(),this.terminalResizeObserver=new ResizeObserver(o),this.terminalResizeObserver.observe(i),this._pendingInput="",this._inputFlushTimeout=null,this._lastKeystrokeTime=0;const r=()=>{if(this._inputFlushTimeout=null,this._pendingInput&&this.activeSessionId){const t=this._pendingInput,l=this.activeSessionId;this._pendingInput="",this._sendInputAsync(l,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:c,text:u}=this._localEchoOverlay.getFlushed();this._flushedOffsets?.has(this.activeSessionId)&&(c===0?(this._flushedOffsets.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId)):(this._flushedOffsets.set(this.activeSessionId,c),this._flushedTexts?.set(this.activeSessionId,u))),this._pendingInput+=t,r()}return}if(/^[\r\n]+$/.test(t)){const h=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),h&&(this._pendingInput+=h,r()),setTimeout(()=>{this._pendingInput+="\r",r()},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,r();return}if(this._restoringFlushedState){this._pendingInput+=t,r();return}if(t===" "){const c=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),c&&(this._pendingInput+=c),this._pendingInput+=t,this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null);let u="";try{const m=this._localEchoOverlay?.findPrompt?.();if(m){const p=this.terminal.buffer.active,g=p.getLine(p.viewportY+m.row);g&&(u=g.translateToString(!0).slice(m.col+2).trimEnd())}}catch{}this._tabCompletionBaseText=u,r(),this._tabCompletionSessionId=this.activeSessionId,this._tabCompletionRetries=0,this._tabCompletionFallback&&clearTimeout(this._tabCompletionFallback);const a=this;this._tabCompletionFallback=setTimeout(()=>{if(a._tabCompletionFallback=null,!a._tabCompletionSessionId||a._tabCompletionSessionId!==a.activeSessionId)return;const m=a._localEchoOverlay;!m||m.pendingText||a.terminal.write("",()=>{if(!a._tabCompletionSessionId)return;m.resetBufferDetection();const p=m.detectBufferText();p&&p!==a._tabCompletionBaseText&&(a._tabCompletionSessionId=null,a._tabCompletionRetries=0,a._tabCompletionBaseText=null,m.rerender())})},300);return}const h=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._localEchoOverlay?.suppressBufferDetection(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),h&&(this._pendingInput+=h),this._pendingInput+=t,this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null),r();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),r();return}const l=performance.now();l-this._lastKeystrokeTime>50?(this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null),this._lastKeystrokeTime=l,r()):(this._lastKeystrokeTime=l,this._inputFlushTimeout||(this._inputFlushTimeout=setTimeout(r,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 f=e.terminal.buffer.active.getLine(s-1);if(!f){n(void 0);return}const o=f.translateToString(!0);if(!o||!o.includes("/")){n(void 0);return}const r=[],t=/https?:\/\/[^\s"'<>|;&)\]\x00-\x1f]+/g,l=(p,g)=>{const y=p.replace(/[.,;:!?)]+$/,""),_=o.indexOf(y,g);_!==-1&&(r.some(v=>v.range.start.x===_+1)||r.push({text:y,range:{start:{x:_+1,y:s},end:{x:_+y.length+1,y:s}},decorations:{pointerCursor:!0,underline:!0},activate(v,b){window.open(b,"_blank","noopener,noreferrer")}}))},h=/(tail|cat|head|less|grep|watch|vim|nano)\s+(?:[^\s\/]*\s+)*(\/[^\s"'<>|;&\n\x00-\x1f]+)/g,c=/(\/(?:home|tmp|var|etc|opt)[^\s"'<>|;&\n\x00-\x1f]*\.(?:log|txt|json|md|yaml|yml|csv|xml|sh|py|ts|js))\b/g,u=/Bash\([^)]*?(\/(?:home|tmp|var|etc|opt)[^\s"'<>|;&\)\n\x00-\x1f]+)/g,a=(p,g)=>{const y=o.indexOf(p,g);y!==-1&&(r.some(_=>_.range.start.x===y+1)||r.push({text:p,range:{start:{x:y+1,y:s},end:{x:y+p.length+1,y:s}},decorations:{pointerCursor:!0,underline:!0},activate(_,v){e.openLogViewerWindow(v,e.activeSessionId)}}))};let m;for(t.lastIndex=0;(m=t.exec(o))!==null;)l(m[0],m.index);for(h.lastIndex=0;(m=h.exec(o))!==null;)a(m[2],m.index);for(c.lastIndex=0;(m=c.exec(o))!==null;)a(m[1],m.index);for(u.lastIndex=0;(m=u.exec(o))!==null;)a(m[1],m.index);r.length>0&&console.debug("[LinkProvider] Found links:",r.map(p=>p.text)),n(r.length>0?r: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 f of s){const o=f.projectKey||f.workingDir;n.has(o)||n.set(o,[]),n.get(o).push(f)}const d=[];for(const[,f]of n)d.push(...f.slice(0,3));return d.sort((f,o)=>new Date(o.lastModified)-new Date(f.lastModified)),d},_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 d=n.path.length;(!s||d>s.len)&&(s={name:n.name,suffix:e.slice(d),len:d})}}return s?`#${s.name}${s.suffix}`:e.split("/").pop()||e},_shortenHomePath(e){return(e||"").replace(/^\/home\/[^/]+\//,"~/").replace(/^\/Users\/[^/]+\//,"~/")},_buildHistoryItem(e,i){const s=e.sizeBytes<1024?`${e.sizeBytes}B`:e.sizeBytes<1048576?`${(e.sizeBytes/1024).toFixed(0)}K`:`${(e.sizeBytes/1048576).toFixed(1)}M`,n=new Date(e.lastModified),d=n.toLocaleDateString("en",{month:"short",day:"numeric"})+" "+n.toLocaleTimeString("en",{hour:"2-digit",minute:"2-digit",hour12:!1}),f=this._shortenHomePath(e.workingDir),o=this._resolveCaseLabel(e.workingDir,i),r=document.createElement("div");r.className="history-item",r.title=e.workingDir;const t=document.createElement("div");t.className="history-item-main",t.addEventListener("click",()=>this.resumeHistorySession(e.sessionId,e.workingDir));const l=document.createElement("div");l.className="history-item-text";const h=document.createElement("span");h.className="history-item-title",h.textContent=e.firstPrompt||f;const c=document.createElement("span");c.className="history-item-subtitle",o.startsWith("#")&&c.classList.add("is-case"),c.textContent=o,l.append(h,c);const u=document.createElement("span");u.className="history-item-meta",u.textContent=d;const a=document.createElement("button");a.className="history-item-expand",a.type="button",a.setAttribute("aria-label","Show details"),a.setAttribute("aria-expanded","false"),a.textContent="\u22EF",t.append(l,u,a);const m=document.createElement("div");m.className="history-item-detail",m.hidden=!0;const p=document.createElement("div");p.className="history-detail-row";const g=document.createElement("span");g.className="history-detail-label",g.textContent="Prompt";const y=document.createElement("span");y.className="history-detail-value history-detail-prompt",y.textContent=e.firstPrompt||"(no prompt captured)",p.append(g,y);const _=document.createElement("div");_.className="history-detail-row";const v=document.createElement("span");v.className="history-detail-label",v.textContent="Path";const b=document.createElement("span");b.className="history-detail-value history-detail-path",b.textContent=f,_.append(v,b);const S=document.createElement("div");return S.className="history-detail-row history-detail-meta",S.textContent=`${d} \xB7 ${s} \xB7 ${e.sessionId.slice(0,8)}`,m.append(p,_,S),a.addEventListener("click",x=>{x.stopPropagation();const T=r.classList.toggle("expanded");m.hidden=!T,a.setAttribute("aria-expanded",T?"true":"false")}),r.append(t,m),r},_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,d]=await Promise.all([this._fetchHistorySessions(30),s]);if(n.length===0){e.style.display="none";return}i.replaceChildren();const f=this._HISTORY_INITIAL_COUNT;for(let o=0;o<Math.min(f,n.length);o++)i.appendChild(this._buildHistoryItem(n[o],d));if(n.length>f){const o=document.createElement("button");o.className="history-show-more",o.textContent=`Show ${n.length-f} more`,o.addEventListener("click",()=>{for(let r=f;r<n.length;r++)i.insertBefore(this._buildHistoryItem(n[r],d),o);o.remove()}),i.appendChild(o)}e.style.display=""}catch(s){console.error("[loadHistorySessions]",s),e.style.display="none"}},async resumeHistorySession(e,i){document.getElementById("runModeMenu")?.classList.remove("active");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[,c]of this.sessions){const u=c.name&&c.name.match(/^w(\d+)-/);if(u){const a=parseInt(u[1]);a>=n&&(n=a+1)}}const d=`w${n}-${s}`,o=(this.cases||[]).find(c=>c.path===i)?.name||i.split("/").pop()||"",r=this.buildEnvOverrides(this.getCaseSettings(o),this.loadAppSettingsFromStorage()),l=await(await fetch("/api/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workingDir:i,name:d,resumeSessionId:e,...Object.keys(r).length>0?{envOverrides:r}:{}})})).json();if(!l.success)throw new Error(l.error);const h=l.session.id;await fetch(`/api/sessions/${h}/interactive`,{method:"POST"}),this.terminal.writeln(`\x1B[90m Session ${d} ready\x1B[0m`),await this.selectSession(h),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,requestAnimationFrame(()=>{this.flushPendingWrites(),this.writeFrameScheduled=!1}))},flushFlickerBuffer(){this.flickerFilterBuffer&&(this.pendingWrites.push(this.flickerFilterBuffer),this.flickerFilterBuffer="",this.flickerFilterActive=!1,this.writeFrameScheduled||(this.writeFrameScheduled=!0,requestAnimationFrame(()=>{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:d=>{try{const f=d.buffer.active,o=f.cursorY,r=f.getLine(f.viewportY+o);if(!r)return null;const l=r.translateToString(!0).indexOf("\u2503");return l>=0?{row:o,col:l}: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 d=!1;s<=n?this.terminal.write(i):(this.terminal.write(i.slice(0,n)),this.pendingWrites.push(i.slice(n)),d=!0,this.writeFrameScheduled||(this.writeFrameScheduled=!0,requestAnimationFrame(()=>{this.flushPendingWrites(),this.writeFrameScheduled=!1})));const f=d?n:s,o=performance.now()-e;if((o>100||d)&&console.warn(`[CRASH-DIAG] flushPendingWrites: ${o.toFixed(0)}ms, ${(f/1024).toFixed(0)}KB written${d?", 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 r=this._localEchoOverlay,t=this;this.terminal.write("",()=>{if(!t._tabCompletionSessionId)return;r.resetBufferDetection();const l=r.detectBufferText();l?l===t._tabCompletionBaseText?(r.undoDetection(),t._tabCompletionRetries=(t._tabCompletionRetries||0)+1,t._tabCompletionRetries>60&&(t._tabCompletionSessionId=null,t._tabCompletionRetries=0)):(t._tabCompletionSessionId=null,t._tabCompletionRetries=0,t._tabCompletionBaseText=null,t._tabCompletionFallback&&(clearTimeout(t._tabCompletionFallback),t._tabCompletionFallback=null),r.rerender()):(t._tabCompletionRetries=(t._tabCompletionRetries||0)+1,t._tabCompletionRetries>60&&(t._tabCompletionSessionId=null,t._tabCompletionRetries=0))})}},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 d=e.replace(DEC_SYNC_STRIP_RE,""),f=()=>{this._chunkedWriteGen===s&&this._finishBufferLoad(),n()};if(d.length<=i){this.terminal.write(d),f();return}let o=0;const r=performance.now();let t=0;const l=()=>{if(this._chunkedWriteGen!==s){n();return}if(o>=d.length){const a=performance.now()-r;console.log(`[CRASH-DIAG] chunkedTerminalWrite complete: ${d.length} bytes in ${t} chunks, ${a.toFixed(0)}ms total`),requestAnimationFrame(f);return}const h=performance.now(),c=d.slice(o,o+i);this.terminal.write(c);const u=performance.now()-h;t++,u>50&&console.warn(`[CRASH-DIAG] chunk #${t} write took ${u.toFixed(0)}ms (${c.length} bytes at offset ${o})`),o+=i,requestAnimationFrame(l)};requestAnimationFrame(l)})},_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),await fetch(`/api/sessions/${this.activeSessionId}/input`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:"\f"})}),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){!this.pendingCtrlL||!this.pendingCtrlL.has(e)||(this.pendingCtrlL.delete(e),e===this.activeSessionId&&this.sendResize(e).then(()=>{fetch(`/api/sessions/${e}/input`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:"\f"})})}))},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)}});
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicodeman",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "The missing control plane for AI coding agents - run 20 autonomous agents with real-time monitoring and session persistence",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,3 +0,0 @@
1
- "use strict";Object.assign(CodemanApp.prototype,{initTerminal(){const e=parseInt(localStorage.getItem("codeman-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:e,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 i=document.getElementById("terminalContainer");this.terminal.open(i),this.terminal.attachCustomKeyEventHandler(t=>{if(t.isComposing||t.keyCode===229||t.altKey&&t.key>="0"&&t.key<="9")return!1;if(t.key==="Enter"&&(t.shiftKey||t.ctrlKey)&&t.type==="keydown"){if(this.activeSessionId)if(this._localEchoEnabled){const l=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._localEchoOverlay?.suppressBufferDetection(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),l&&(this._pendingInput+=l,r()),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"})})},l?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=i.querySelector(".xterm-helper-textarea");if(t&&MobileDetection.isTouchDevice()){let l=!1,h=0;t.addEventListener("compositionstart",()=>{l=!0}),t.addEventListener("compositionend",()=>{l=!1}),t.addEventListener("keydown",c=>{!c.isComposing&&c.keyCode!==229&&(h=Date.now())}),t.addEventListener("input",c=>{if(l||c.isComposing||c.inputType!=="insertText"||!c.data||Date.now()-h<50)return;const u=c.data;Promise.resolve().then(()=>{const a=t.value;!a||a.trim()===""||(this.terminal._core.coreService.triggerDataEvent(u,!0),t.value="")})})}}if(this._webglAddon=null,!(MobileDetection.getDeviceType()!=="desktop")&&!new URLSearchParams(location.search).has("nowebgl"))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(),i.addEventListener("wheel",t=>{t.preventDefault();const l=Math.round(t.deltaY/25)||(t.deltaY>0?1:-1);this.terminal.scrollLines(l)},{passive:!1});{const t=()=>this.terminal._core?._renderService?.dimensions?.css?.cell?.height||13;let l=0,h=0,c=0,u=null,a=!1;const m=y=>{const _=c?(y-c)/16.67:1;if(c=y,!a&&Math.abs(h)>.3){const v=Math.round(h/t());v!==0&&this.terminal.scrollLines(v),h*=.92,u=requestAnimationFrame(m)}else a?u=requestAnimationFrame(m):(u=null,h=0)};let p=0,g=!1;i.addEventListener("touchstart",y=>{y.touches.length===1&&(l=y.touches[0].clientY,h=0,p=0,a=!0,g=!1,c=0,u&&(cancelAnimationFrame(u),u=null))},{passive:!0}),i.addEventListener("touchmove",y=>{if(y.touches.length===1&&a){g=!0;const _=y.touches[0].clientY,v=l-_;p+=v,h=v*1.2,l=_;const b=t(),S=Math.trunc(p/b);S!==0&&(this.terminal.scrollLines(S),p-=S*b)}},{passive:!0}),i.addEventListener("touchend",()=>{a=!1,!u&&Math.abs(h)>.3&&(u=requestAnimationFrame(m)),!g&&this.terminal&&this.terminal.focus()},{passive:!0}),i.addEventListener("touchcancel",()=>{a=!1,h=0,p=0},{passive:!0})}this.showWelcome(),this._chunkedWriteGen=0,this._resizeTimeout=null,this._lastResizeDims=null;const d=40,f=10,o=()=>{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 l=this.fitAddon.proposeDimensions(),h=l?Math.max(l.cols,d):d,c=l?Math.max(l.rows,f):f;if(!this._lastResizeDims||h!==this._lastResizeDims.cols||c!==this._lastResizeDims.rows){const u=this.activeSessionId?this.sessions.get(this.activeSessionId):null;u&&u.mode!=="shell"&&!u._ended&&this.terminal&&this.isTerminalAtBottom()&&this.terminal.write("\x1B[3J\x1B[H\x1B[2J"),this._lastResizeDims={cols:h,rows:c},fetch(`/api/sessions/${this.activeSessionId}/resize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cols:h,rows:c})}).catch(()=>{})}}this.updateConnectionLines(),this._localEchoOverlay?.hasPending&&this._localEchoOverlay.rerender()},300)};window.addEventListener("resize",o),this.terminalResizeObserver&&this.terminalResizeObserver.disconnect(),this.terminalResizeObserver=new ResizeObserver(o),this.terminalResizeObserver.observe(i),this._pendingInput="",this._inputFlushTimeout=null,this._lastKeystrokeTime=0;const r=()=>{if(this._inputFlushTimeout=null,this._pendingInput&&this.activeSessionId){const t=this._pendingInput,l=this.activeSessionId;this._pendingInput="",this._sendInputAsync(l,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:c,text:u}=this._localEchoOverlay.getFlushed();this._flushedOffsets?.has(this.activeSessionId)&&(c===0?(this._flushedOffsets.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId)):(this._flushedOffsets.set(this.activeSessionId,c),this._flushedTexts?.set(this.activeSessionId,u))),this._pendingInput+=t,r()}return}if(/^[\r\n]+$/.test(t)){const h=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),h&&(this._pendingInput+=h,r()),setTimeout(()=>{this._pendingInput+="\r",r()},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,r();return}if(this._restoringFlushedState){this._pendingInput+=t,r();return}if(t===" "){const c=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),c&&(this._pendingInput+=c),this._pendingInput+=t,this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null);let u="";try{const m=this._localEchoOverlay?.findPrompt?.();if(m){const p=this.terminal.buffer.active,g=p.getLine(p.viewportY+m.row);g&&(u=g.translateToString(!0).slice(m.col+2).trimEnd())}}catch{}this._tabCompletionBaseText=u,r(),this._tabCompletionSessionId=this.activeSessionId,this._tabCompletionRetries=0,this._tabCompletionFallback&&clearTimeout(this._tabCompletionFallback);const a=this;this._tabCompletionFallback=setTimeout(()=>{if(a._tabCompletionFallback=null,!a._tabCompletionSessionId||a._tabCompletionSessionId!==a.activeSessionId)return;const m=a._localEchoOverlay;!m||m.pendingText||a.terminal.write("",()=>{if(!a._tabCompletionSessionId)return;m.resetBufferDetection();const p=m.detectBufferText();p&&p!==a._tabCompletionBaseText&&(a._tabCompletionSessionId=null,a._tabCompletionRetries=0,a._tabCompletionBaseText=null,m.rerender())})},300);return}const h=this._localEchoOverlay?.pendingText||"";this._localEchoOverlay?.clear(),this._localEchoOverlay?.suppressBufferDetection(),this._flushedOffsets?.delete(this.activeSessionId),this._flushedTexts?.delete(this.activeSessionId),h&&(this._pendingInput+=h),this._pendingInput+=t,this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null),r();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),r();return}const l=performance.now();l-this._lastKeystrokeTime>50?(this._inputFlushTimeout&&(clearTimeout(this._inputFlushTimeout),this._inputFlushTimeout=null),this._lastKeystrokeTime=l,r()):(this._lastKeystrokeTime=l,this._inputFlushTimeout||(this._inputFlushTimeout=setTimeout(r,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 f=e.terminal.buffer.active.getLine(s-1);if(!f){n(void 0);return}const o=f.translateToString(!0);if(!o||!o.includes("/")){n(void 0);return}const r=[],t=/https?:\/\/[^\s"'<>|;&)\]\x00-\x1f]+/g,l=(p,g)=>{const y=p.replace(/[.,;:!?)]+$/,""),_=o.indexOf(y,g);_!==-1&&(r.some(v=>v.range.start.x===_+1)||r.push({text:y,range:{start:{x:_+1,y:s},end:{x:_+y.length+1,y:s}},decorations:{pointerCursor:!0,underline:!0},activate(v,b){window.open(b,"_blank","noopener,noreferrer")}}))},h=/(tail|cat|head|less|grep|watch|vim|nano)\s+(?:[^\s\/]*\s+)*(\/[^\s"'<>|;&\n\x00-\x1f]+)/g,c=/(\/(?:home|tmp|var|etc|opt)[^\s"'<>|;&\n\x00-\x1f]*\.(?:log|txt|json|md|yaml|yml|csv|xml|sh|py|ts|js))\b/g,u=/Bash\([^)]*?(\/(?:home|tmp|var|etc|opt)[^\s"'<>|;&\)\n\x00-\x1f]+)/g,a=(p,g)=>{const y=o.indexOf(p,g);y!==-1&&(r.some(_=>_.range.start.x===y+1)||r.push({text:p,range:{start:{x:y+1,y:s},end:{x:y+p.length+1,y:s}},decorations:{pointerCursor:!0,underline:!0},activate(_,v){e.openLogViewerWindow(v,e.activeSessionId)}}))};let m;for(t.lastIndex=0;(m=t.exec(o))!==null;)l(m[0],m.index);for(h.lastIndex=0;(m=h.exec(o))!==null;)a(m[2],m.index);for(c.lastIndex=0;(m=c.exec(o))!==null;)a(m[1],m.index);for(u.lastIndex=0;(m=u.exec(o))!==null;)a(m[1],m.index);r.length>0&&console.debug("[LinkProvider] Found links:",r.map(p=>p.text)),n(r.length>0?r: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 f of s){const o=f.projectKey||f.workingDir;n.has(o)||n.set(o,[]),n.get(o).push(f)}const d=[];for(const[,f]of n)d.push(...f.slice(0,3));return d.sort((f,o)=>new Date(o.lastModified)-new Date(f.lastModified)),d},_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 d=n.path.length;(!s||d>s.len)&&(s={name:n.name,suffix:e.slice(d),len:d})}}return s?`#${s.name}${s.suffix}`:e.split("/").pop()||e},_shortenHomePath(e){return(e||"").replace(/^\/home\/[^/]+\//,"~/").replace(/^\/Users\/[^/]+\//,"~/")},_buildHistoryItem(e,i){const s=e.sizeBytes<1024?`${e.sizeBytes}B`:e.sizeBytes<1048576?`${(e.sizeBytes/1024).toFixed(0)}K`:`${(e.sizeBytes/1048576).toFixed(1)}M`,n=new Date(e.lastModified),d=n.toLocaleDateString("en",{month:"short",day:"numeric"})+" "+n.toLocaleTimeString("en",{hour:"2-digit",minute:"2-digit",hour12:!1}),f=this._shortenHomePath(e.workingDir),o=this._resolveCaseLabel(e.workingDir,i),r=document.createElement("div");r.className="history-item",r.title=e.workingDir;const t=document.createElement("div");t.className="history-item-main",t.addEventListener("click",()=>this.resumeHistorySession(e.sessionId,e.workingDir));const l=document.createElement("div");l.className="history-item-text";const h=document.createElement("span");h.className="history-item-title",h.textContent=e.firstPrompt||f;const c=document.createElement("span");c.className="history-item-subtitle",o.startsWith("#")&&c.classList.add("is-case"),c.textContent=o,l.append(h,c);const u=document.createElement("span");u.className="history-item-meta",u.textContent=d;const a=document.createElement("button");a.className="history-item-expand",a.type="button",a.setAttribute("aria-label","Show details"),a.setAttribute("aria-expanded","false"),a.textContent="\u22EF",t.append(l,u,a);const m=document.createElement("div");m.className="history-item-detail",m.hidden=!0;const p=document.createElement("div");p.className="history-detail-row";const g=document.createElement("span");g.className="history-detail-label",g.textContent="Prompt";const y=document.createElement("span");y.className="history-detail-value history-detail-prompt",y.textContent=e.firstPrompt||"(no prompt captured)",p.append(g,y);const _=document.createElement("div");_.className="history-detail-row";const v=document.createElement("span");v.className="history-detail-label",v.textContent="Path";const b=document.createElement("span");b.className="history-detail-value history-detail-path",b.textContent=f,_.append(v,b);const S=document.createElement("div");return S.className="history-detail-row history-detail-meta",S.textContent=`${d} \xB7 ${s} \xB7 ${e.sessionId.slice(0,8)}`,m.append(p,_,S),a.addEventListener("click",x=>{x.stopPropagation();const T=r.classList.toggle("expanded");m.hidden=!T,a.setAttribute("aria-expanded",T?"true":"false")}),r.append(t,m),r},_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,d]=await Promise.all([this._fetchHistorySessions(30),s]);if(n.length===0){e.style.display="none";return}i.replaceChildren();const f=this._HISTORY_INITIAL_COUNT;for(let o=0;o<Math.min(f,n.length);o++)i.appendChild(this._buildHistoryItem(n[o],d));if(n.length>f){const o=document.createElement("button");o.className="history-show-more",o.textContent=`Show ${n.length-f} more`,o.addEventListener("click",()=>{for(let r=f;r<n.length;r++)i.insertBefore(this._buildHistoryItem(n[r],d),o);o.remove()}),i.appendChild(o)}e.style.display=""}catch(s){console.error("[loadHistorySessions]",s),e.style.display="none"}},async resumeHistorySession(e,i){document.getElementById("runModeMenu")?.classList.remove("active");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[,c]of this.sessions){const u=c.name&&c.name.match(/^w(\d+)-/);if(u){const a=parseInt(u[1]);a>=n&&(n=a+1)}}const d=`w${n}-${s}`,o=(this.cases||[]).find(c=>c.path===i)?.name||i.split("/").pop()||"",r=this.buildEnvOverrides(this.getCaseSettings(o),this.loadAppSettingsFromStorage()),l=await(await fetch("/api/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workingDir:i,name:d,resumeSessionId:e,...Object.keys(r).length>0?{envOverrides:r}:{}})})).json();if(!l.success)throw new Error(l.error);const h=l.session.id;await fetch(`/api/sessions/${h}/interactive`,{method:"POST"}),this.terminal.writeln(`\x1B[90m Session ${d} ready\x1B[0m`),await this.selectSession(h),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,requestAnimationFrame(()=>{this.flushPendingWrites(),this.writeFrameScheduled=!1}))},flushFlickerBuffer(){this.flickerFilterBuffer&&(this.pendingWrites.push(this.flickerFilterBuffer),this.flickerFilterBuffer="",this.flickerFilterActive=!1,this.writeFrameScheduled||(this.writeFrameScheduled=!0,requestAnimationFrame(()=>{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:d=>{try{const f=d.buffer.active,o=f.cursorY,r=f.getLine(f.viewportY+o);if(!r)return null;const l=r.translateToString(!0).indexOf("\u2503");return l>=0?{row:o,col:l}: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 d=!1;s<=n?this.terminal.write(i):(this.terminal.write(i.slice(0,n)),this.pendingWrites.push(i.slice(n)),d=!0,this.writeFrameScheduled||(this.writeFrameScheduled=!0,requestAnimationFrame(()=>{this.flushPendingWrites(),this.writeFrameScheduled=!1})));const f=d?n:s,o=performance.now()-e;if((o>100||d)&&console.warn(`[CRASH-DIAG] flushPendingWrites: ${o.toFixed(0)}ms, ${(f/1024).toFixed(0)}KB written${d?", 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 r=this._localEchoOverlay,t=this;this.terminal.write("",()=>{if(!t._tabCompletionSessionId)return;r.resetBufferDetection();const l=r.detectBufferText();l?l===t._tabCompletionBaseText?(r.undoDetection(),t._tabCompletionRetries=(t._tabCompletionRetries||0)+1,t._tabCompletionRetries>60&&(t._tabCompletionSessionId=null,t._tabCompletionRetries=0)):(t._tabCompletionSessionId=null,t._tabCompletionRetries=0,t._tabCompletionBaseText=null,t._tabCompletionFallback&&(clearTimeout(t._tabCompletionFallback),t._tabCompletionFallback=null),r.rerender()):(t._tabCompletionRetries=(t._tabCompletionRetries||0)+1,t._tabCompletionRetries>60&&(t._tabCompletionSessionId=null,t._tabCompletionRetries=0))})}},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 d=e.replace(DEC_SYNC_STRIP_RE,""),f=()=>{this._chunkedWriteGen===s&&this._finishBufferLoad(),n()};if(d.length<=i){this.terminal.write(d),f();return}let o=0;const r=performance.now();let t=0;const l=()=>{if(this._chunkedWriteGen!==s){n();return}if(o>=d.length){const a=performance.now()-r;console.log(`[CRASH-DIAG] chunkedTerminalWrite complete: ${d.length} bytes in ${t} chunks, ${a.toFixed(0)}ms total`),requestAnimationFrame(f);return}const h=performance.now(),c=d.slice(o,o+i);this.terminal.write(c);const u=performance.now()-h;t++,u>50&&console.warn(`[CRASH-DIAG] chunk #${t} write took ${u.toFixed(0)}ms (${c.length} bytes at offset ${o})`),o+=i,requestAnimationFrame(l)};requestAnimationFrame(l)})},_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),await fetch(`/api/sessions/${this.activeSessionId}/input`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:"\f"})}),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){!this.pendingCtrlL||!this.pendingCtrlL.has(e)||(this.pendingCtrlL.delete(e),e===this.activeSessionId&&this.sendResize(e).then(()=>{fetch(`/api/sessions/${e}/input`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:"\f"})})}))},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)}});