tmux-weblink 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/shell-client.js +22 -22
- package/dist/browser/shell-client.js +16 -16
- package/dist/lib/agent-client.js +1 -1
- package/dist/lib/pages/shell.js +8 -41
- package/dist/lib/scope-script.js +2 -33
- package/package.json +1 -1
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)}selectRows(e,n){let a=this.terminal.buffer.active,[o,r]=e<=n?[e,n]:[n,e];this.terminal.selectLines(a.viewportY+o,a.viewportY+r)}hasSelectionSupport(){return!0}},
|
|
3
|
-
`)}catch{return""}}selectRows(e,n){try{if(typeof this.terminal?.selectLines!="function")return;let a=this.terminal.buffer?.active,o=typeof a?.viewportY=="number"?a.viewportY:0,[r,c]=e<=n?[e,n]:[n,e];this.terminal.selectLines(o+r,o+c)}catch{}}hasSelectionSupport(){return typeof this.terminal?.selectLines=="function"}updateCellMetrics(e=!1){let n=this.container.querySelector("canvas");if(n instanceof HTMLElement&&n.offsetWidth>0&&n.offsetHeight>0&&this.colsValue>0&&this.rowsValue>0){let a=n.offsetWidth/this.colsValue,o=n.offsetHeight/this.rowsValue;(e||!this.charW||!this.charH)&&(this.charW=a,this.charH=o)}(!this.charW||!this.charH)&&(this.charW=9,this.charH=18)}};function Oe(t){let e=t.getBoundingClientRect(),n=window.visualViewport;return n?{width:Math.min(e.width,n.width),height:Math.max(0,Math.min(e.height,n.height-Math.max(0,e.top)))}:e}function
|
|
1
|
+
var jt="https://esm.sh/ghostty-web@0.4.0",Vt=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function ce(t){return t.replace(Vt,"")}var de;function Ft(){return de||(document.querySelector("link[data-tmux-web-xterm-css]")?de=Promise.resolve():(de=new Promise(t=>{let e=document.createElement("link");e.rel="stylesheet",e.href="/assets/xterm.css",e.setAttribute("data-tmux-web-xterm-css",""),e.addEventListener("load",()=>t(),{once:!0}),e.addEventListener("error",()=>t(),{once:!0}),document.head.appendChild(e)}),de))}var Ue=class ht{terminal;fitAddon;container;constructor(e,n,a){this.container=e,this.terminal=n,this.fitAddon=a,this.terminal.loadAddon(this.fitAddon),this.terminal.open(e)}static async create(e,n,a){let[{Terminal:o},{FitAddon:r}]=await Promise.all([import("./xterm-BXEES47M.js"),import("./addon-fit-D5N335P2.js"),Ft()]),c=new o({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:n,convertEol:!1,theme:a});return new ht(e,c,new r)}get cols(){return this.terminal.cols}get rows(){return this.terminal.rows}write(e){return new Promise(n=>this.terminal.write(e,n))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom()}scrollToLine(e){this.terminal.scrollToLine(Math.max(0,e))}isNearScrollbackTop(){return this.terminal.buffer.active.viewportY<=1}viewportY(){return this.terminal.buffer.active.viewportY}baseY(){return this.terminal.buffer.active.baseY}fit(){let e=Oe(this.container);return e.width<=0||e.height<=0?!1:(this.fitAddon.fit(),!0)}focus(){this.terminal.focus()}pasteText(e){this.terminal.paste(e)}input(e){this.terminal.input(e,!1)}onData(e){this.terminal.onData(e),this.terminal.onBinary(e)}onResize(e){this.terminal.onResize(e)}onScroll(e){this.terminal.onScroll(e)}attachCustomKeyEventHandler(e){this.terminal.attachCustomKeyEventHandler(e)}isFocused(){let e=document.activeElement;return!!e&&(e===this.container||this.container.contains(e))}getScreenText(){return this.getRowsText(0,this.terminal.rows-1)}getRowsText(e,n){let a=this.terminal.buffer.active,[o,r]=e<=n?[e,n]:[n,e],c=a.viewportY,l=[];for(let u=o;u<=r;u++){let p=a.getLine(c+u);l.push(p?p.translateToString(!0):"")}return l.join(`
|
|
2
|
+
`)}selectRows(e,n){let a=this.terminal.buffer.active,[o,r]=e<=n?[e,n]:[n,e];this.terminal.selectLines(a.viewportY+o,a.viewportY+r)}hasSelectionSupport(){return!0}},_t=class vt{terminal;container;colsValue=80;rowsValue=24;charW=0;charH=0;resizeCallbacks=[];constructor(e,n){this.container=e,this.terminal=n,this.terminal.open(e)}static async create(e,n,a){let o=await import(jt);await o.init();let r=new o.Terminal({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:n,convertEol:!1,theme:a});return new vt(e,r)}get cols(){return this.colsValue}get rows(){return this.rowsValue}write(e){return new Promise(n=>this.terminal.write(e,n))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom?.()}scrollToLine(e){this.terminal.scrollToLine?.(Math.max(0,e))}isNearScrollbackTop(){let e=this.terminal.buffer?.active;return e?e.viewportY>=e.baseY:!1}viewportY(){return this.terminal.buffer?.active?.viewportY??0}baseY(){return this.terminal.buffer?.active?.baseY??0}fit(){let e=Oe(this.container);if(e.width<=0||e.height<=0)return!1;this.updateCellMetrics(!this.charW||!this.charH);let n=Math.floor(e.width/this.charW),a=Math.floor(e.height/this.charH);if(n<10||a<5)return!1;if(n!==this.colsValue||a!==this.rowsValue){this.colsValue=n,this.rowsValue=a,this.terminal.resize(n,a);for(let o of this.resizeCallbacks)o({cols:n,rows:a})}return!0}focus(){(this.terminal.textarea||this.container.querySelector("textarea")||this.container)?.focus?.()}pasteText(e){let n=this.terminal.getMode?.(2004)??!1;this.input(n?"\x1B[200~"+e+"\x1B[201~":e)}input(e){this.terminal.input?.(e,!1)}onData(e){this.terminal.onData(n=>e(n))}onResize(e){this.resizeCallbacks.push(e)}onScroll(e){this.terminal.onScroll(e)}attachCustomKeyEventHandler(e){this.terminal.attachCustomKeyEventHandler(e)}isFocused(){let e=document.activeElement;return!!e&&(e===this.container||e===this.terminal.textarea||this.container.contains(e))}getScreenText(){return this.getRowsText(0,this.rowsValue-1)}getRowsText(e,n){try{let a=this.terminal.buffer?.active;if(!a||typeof a.getLine!="function")return"";let[o,r]=e<=n?[e,n]:[n,e],c=typeof a.viewportY=="number"?a.viewportY:0,l=[];for(let u=o;u<=r;u++){let p=a.getLine(c+u);l.push(typeof p?.translateToString=="function"?p.translateToString(!0):"")}return l.join(`
|
|
3
|
+
`)}catch{return""}}selectRows(e,n){try{if(typeof this.terminal?.selectLines!="function")return;let a=this.terminal.buffer?.active,o=typeof a?.viewportY=="number"?a.viewportY:0,[r,c]=e<=n?[e,n]:[n,e];this.terminal.selectLines(o+r,o+c)}catch{}}hasSelectionSupport(){return typeof this.terminal?.selectLines=="function"}updateCellMetrics(e=!1){let n=this.container.querySelector("canvas");if(n instanceof HTMLElement&&n.offsetWidth>0&&n.offsetHeight>0&&this.colsValue>0&&this.rowsValue>0){let a=n.offsetWidth/this.colsValue,o=n.offsetHeight/this.rowsValue;(e||!this.charW||!this.charH)&&(this.charW=a,this.charH=o)}(!this.charW||!this.charH)&&(this.charW=9,this.charH=18)}};function Oe(t){let e=t.getBoundingClientRect(),n=window.visualViewport;return n?{width:Math.min(e.width,n.width),height:Math.max(0,Math.min(e.height,n.height-Math.max(0,e.top)))}:e}function Kt(t,e,n){return t.innerHTML="",t.classList.add("terminal-pending"),(async()=>{let a;if(n.renderer==="ghostty")try{a=await _t.create(t,n.scrollback,n.theme)}catch{console.error("[tmux-web] ghostty-web failed; falling back to xterm.js"),a=await Ue.create(t,n.scrollback,n.theme)}else a=await Ue.create(t,n.scrollback,n.theme);let o,r=0,c,l=null,u=0,p="connecting",I=0,se=!1,oe=[],z="",N=!1,V=1e3,yt=location.protocol==="https:"?"wss:":"ws:",gt=n.wsBase||"/ws",wt=yt+"//"+location.host+gt+"/"+encodeURIComponent(e),bt="/api/session/"+encodeURIComponent(e)+"/upload",Et=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function Lt(){return oe.join("")+z}async function kt(i,s=0){let d=i?a.viewportY():0,L=i?a.baseY():0,C=ce(Lt());if(a.reset(),!C){i||a.scrollToBottom();return}await a.write(C),i?a.scrollToLine(L+d+s):a.scrollToBottom()}function F(i){o?.readyState===WebSocket.OPEN&&o.send(JSON.stringify(i))}function xt(i){let s;try{s=JSON.parse(i)}catch{p==="live"&&(z+=i,a.write(ce(i)));return}if(s.type==="auth.required"){let d=localStorage.getItem("tmux-web-token");d?F({type:"auth.token",token:d}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(s.type==="auth.ok"){s.token&&localStorage.setItem("tmux-web-token",s.token),V=1e3,_(),F({type:"resize",cols:a.cols,rows:a.rows}),b();return}if(s.type==="auth.failed"){if(s.permanentLock||s.retryAfterMs&&s.retryAfterMs>6e4){localStorage.removeItem("tmux-web-token"),location.href="/login?error="+encodeURIComponent(s.message);return}return}if(s.type==="snapshot"&&typeof s.data=="string"){let d=ce(s.data);oe=[d],z="",I=typeof s.lines=="number"?s.lines:n.terminal.initialLines,p="live",a.reset(),a.write(d).then(()=>a.scrollToBottom());return}if(s.type==="window_changed"&&typeof s.activeIndex=="number"){let d=new URL(location.href);d.searchParams.get("window")!==String(s.activeIndex)&&(d.searchParams.set("window",String(s.activeIndex)),history.replaceState(history.state,"",d)),window.dispatchEvent(new CustomEvent("tmux:windows",{detail:s.windows}));return}if(s.type==="history"&&typeof s.data=="string"){se=!1,s.lines>0&&s.data&&(oe.unshift(s.data),I+=s.lines,kt(!0,s.lines));return}if(s.type==="data"&&typeof s.data=="string"){let d=ce(s.data);if(p==="connecting"){p="live",z=d,a.write(d);return}p==="live"&&(z+=d,a.write(d))}}function De(){let i=wt,s=localStorage.getItem("tmux-web-token");s&&(i+=(i.includes("?")?"&":"?")+"token="+encodeURIComponent(s)),o=new WebSocket(i),o.onopen=()=>{p="connecting",I=0,se=!1,oe=[],z="",a.reset(),V=1e3},o.onmessage=d=>{typeof d.data=="string"&&xt(d.data)},o.onclose=()=>{N||(p="connecting",setTimeout(()=>{V=Math.min(V*2,1e4),N||De()},V))},o.onerror=()=>o?.close()}function le(i){F({type:"input",data:i})}function _(){return a.fit()}function Le(){t.classList.remove("terminal-pending")}function b(){r&&cancelAnimationFrame(r),c&&clearTimeout(c),_(),r=requestAnimationFrame(()=>{r=0,_()&&Le()}),c=setTimeout(()=>{_()&&Le()},120)}function Tt(){b(),setTimeout(b,50),setTimeout(b,150),setTimeout(b,300)}function Re(i){return typeof i=="string"&&i.startsWith("image/")}function Ae(i){return i?.files?.length?i.files[0]??null:null}function Ct(i){if(!i?.items)return null;for(let s=0;s<i.items.length;s++){let d=i.items[s];if(d?.kind==="file"&&Re(d.type))return d.getAsFile()}return null}async function Mt(i){let s=new FormData,d=i instanceof File&&i.name?i.name:"upload";s.append("file",i,d);let L=localStorage.getItem("tmux-web-token"),C={};L&&(C.Authorization="Bearer "+L);let Ce=await fetch(bt,{method:"POST",body:s,headers:C});if(!Ce.ok){let _e="upload failed";try{let Ke=await Ce.json();Ke.error&&(_e=Ke.error)}catch{}throw new Error(_e)}let Fe=await Ce.json();if(!Fe.path)throw new Error("no path in response");return Fe.path}async function ke(i){try{let s=await Mt(i);le(s)}catch{}}a.onData(i=>le(i)),a.onResize(({cols:i,rows:s})=>F({type:"resize",cols:i,rows:s})),a.onScroll(()=>{p!=="live"||se||!a.isNearScrollbackTop()||(se=!0,F({type:"load_history",before:I}))});let K=!1,U=!1,x=null,D=null,O=document.createElement("div");O.className="terminal-copy-banner",O.innerHTML='<strong>Copy mode</strong><span class="hint">drag to select \xB7 Esc exits</span>',O.hidden=!0,t.appendChild(O);let P=document.createElement("div");P.className="terminal-copy-banner terminal-copy-toast",P.textContent="Copied",P.hidden=!0,t.appendChild(P);function $e(i){let s=t.getBoundingClientRect(),d=s.height>0&&a.rows>0?s.height/a.rows:18;return Math.max(0,Math.min(a.rows-1,Math.floor((i-s.top)/d)))}async function ze(i){if(!i)return;try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(i);return}}catch{}let s=document.createElement("textarea");s.value=i,s.style.position="fixed",s.style.opacity="0",s.style.pointerEvents="none",document.body.appendChild(s),s.focus(),s.select();try{document.execCommand("copy")}catch{}s.remove()}let q;function Ne(){P.hidden=!1,q&&clearTimeout(q),q=setTimeout(()=>{P.hidden=!0},1e3)}function X(i){K=i,O.hidden=!i,t.classList.toggle("terminal-copy-mode-active",i),i&&a.focus()}function Pe(){X(!K)}function It(){return x===null||D===null?null:x<=D?[x,D]:[D,x]}function Bt(i){N||i.button!==0||U||(K||i.shiftKey)&&(i.preventDefault(),i.stopPropagation(),U=!0,x=$e(i.clientY),D=x,a.selectRows(x,x),document.addEventListener("mousemove",xe,!0),document.addEventListener("mouseup",Te,!0))}function xe(i){N||!U||x===null||(i.preventDefault(),i.stopPropagation(),D=$e(i.clientY),a.selectRows(x,D))}function Te(i){if(N||!U||x===null)return;i.preventDefault(),i.stopPropagation();let s=It();document.removeEventListener("mousemove",xe,!0),document.removeEventListener("mouseup",Te,!0),U=!1,X(!1),s&&(ze(a.getRowsText(s[0],s[1])).then(Ne),a.focus())}t.addEventListener("mousedown",Bt,!0),a.attachCustomKeyEventHandler(i=>{if(i.type!=="keydown")return!0;if(K){if(i.key==="Escape")return i.preventDefault(),X(!1),!1;if(i.key==="Enter"||(i.ctrlKey||i.metaKey)&&i.code==="KeyC")return i.preventDefault(),ze(a.getScreenText()).then(Ne),X(!1),!1}return i.altKey&&i.code==="KeyC"&&!i.ctrlKey&&!i.metaKey?(i.preventDefault(),Pe(),!1):(i.ctrlKey||i.metaKey)&&i.code==="KeyV"?(i.preventDefault(),(async()=>{try{if(navigator.clipboard?.read){let s=await navigator.clipboard.read();for(let d of s)for(let L of d.types)if(Re(L)){let C=await d.getType(L);await ke(C);return}}}catch{}try{let s=await navigator.clipboard?.readText();s&&a.pasteText(Ye(s))}catch{}})(),!1):!0});let re=0;function Ye(i){return i.split(`\r
|
|
4
4
|
`).join(`
|
|
5
5
|
`).split(`
|
|
6
|
-
`).join("\r")}async function
|
|
7
|
-
<span>${
|
|
8
|
-
<button class="session-edit-btn" data-session="${
|
|
9
|
-
`,r.addEventListener("click",l=>{l.target.closest(".session-edit-btn")||Q(o.name)}),m.appendChild(r);let c=r.querySelector(".session-edit-btn");c&&c.addEventListener("click",l=>{l.stopPropagation(),
|
|
10
|
-
<span>${
|
|
6
|
+
`).join("\r")}async function St(i){let s=Ct(i.clipboardData);if(s){i.preventDefault(),i.stopPropagation();let C=Date.now();if(C-re<50)return;re=C,await ke(s);return}let d=i.clipboardData?.getData("text/plain");if(!d)return;i.preventDefault(),i.stopPropagation();let L=Date.now();L-re<50||(re=L,a.pasteText(Ye(d)))}let J=0;function Ht(i){i.preventDefault(),J++,Ae(i.dataTransfer)&&t.classList.add("terminal-drag-over")}function Dt(i){i.preventDefault(),i.dataTransfer&&(i.dataTransfer.dropEffect="copy")}function Rt(i){i.preventDefault(),J--,J<=0&&(J=0,t.classList.remove("terminal-drag-over"))}async function At(i){i.preventDefault(),J=0,t.classList.remove("terminal-drag-over");let s=Ae(i.dataTransfer);s&&await ke(s)}function We(i){!Et||i.key!=="Escape"||K||i.defaultPrevented||i.repeat||i.metaKey||i.ctrlKey||i.altKey||a.isFocused()&&(i.preventDefault(),i.stopPropagation(),le("\x1B"))}t.addEventListener("paste",St),t.addEventListener("dragenter",Ht),t.addEventListener("dragover",Dt),t.addEventListener("dragleave",Rt),t.addEventListener("drop",At),document.addEventListener("keydown",We,!0);function $t(i){if(i.touches.length!==1){l=null;return}let s=i.touches[0];s&&(l={startX:s.clientX,startY:s.clientY,lastX:s.clientX,lastY:s.clientY,scrolling:!1},i.stopPropagation())}function zt(i){if(!l||i.touches.length!==1)return;let s=i.touches[0];if(!s)return;let d=s.clientY-l.startY,L=s.clientX-l.startX;if(!l.scrolling){if(Math.abs(d)<8||Math.abs(d)<Math.abs(L))return;l.scrolling=!0,u=Date.now()+500}i.preventDefault(),i.stopPropagation(),Wt(-(s.clientY-l.lastY),s.clientX,s.clientY),l.lastX=s.clientX,l.lastY=s.clientY}function Nt(i){if(!l)return;let s=l.scrolling;l=null,i.stopPropagation(),s?(u=Date.now()+500,i.preventDefault()):a.focus()}function Pt(i){l=null,i.stopPropagation()}function Yt(i){i.pointerType==="touch"&&Date.now()<u&&(i.preventDefault(),i.stopPropagation())}function Wt(i,s,d){(t.querySelector(".xterm-screen")??t).dispatchEvent(new WheelEvent("wheel",{deltaY:i,deltaMode:WheelEvent.DOM_DELTA_PIXEL,clientX:s,clientY:d,bubbles:!0,cancelable:!0}))}t.addEventListener("touchstart",$t,{passive:!0,capture:!0}),t.addEventListener("touchmove",zt,{passive:!1,capture:!0}),t.addEventListener("touchend",Nt,{passive:!1,capture:!0}),t.addEventListener("touchcancel",Pt,{passive:!0,capture:!0}),t.addEventListener("pointerup",Yt,!0);function je(){b()}window.addEventListener("resize",je),window.visualViewport?.addEventListener("resize",b),window.visualViewport?.addEventListener("scroll",b);let Ve=new ResizeObserver(()=>b());return Ve.observe(t),document.fonts?.ready.then(()=>{b(),setTimeout(b,50),setTimeout(b,200)}),t.addEventListener("focusin",Tt,!0),requestAnimationFrame(()=>{_()&&Le(),De(),b()}),{destroy(){if(N=!0,X(!1),q&&clearTimeout(q),document.removeEventListener("mousemove",xe,!0),document.removeEventListener("mouseup",Te,!0),o){try{o.close(1e3,"session switch")}catch{}o=void 0}t.innerHTML="",t.classList.remove("terminal-pending"),window.removeEventListener("resize",je),Ve.disconnect(),document.removeEventListener("keydown",We,!0)},focus(){a.focus()},sendInput(i){le(i)},toggleCopyMode(){Pe()}}})()}var Y=window.__TMUX_WEB_SHELL__,h=null,y=null,qe=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null,w=qe;window.__tmuxWebScopeAgent=qe;var Xe="sessions",S="",ue="",pe="",Je="";function E(t){return w?"/a/"+encodeURIComponent(w)+t:t}var m=document.getElementById("sidebar-content"),R=document.getElementById("main-placeholder"),k=document.getElementById("terminal-container"),Z=document.getElementById("file-editor"),Ut=document.getElementById("fe-path"),T=document.getElementById("fe-status"),G=document.getElementById("fe-content"),A=document.getElementById("fe-save"),Ot=document.getElementById("fe-delete"),qt=document.getElementById("fe-back"),Ze=document.getElementById("fe-new-name"),Xt=document.getElementById("fe-new-btn"),Me=document.getElementById("settings-backdrop"),Ge=document.getElementById("settings-popover"),Qe=document.querySelector(".sidebar");function Jt(){return window.matchMedia("(max-width: 640px)").matches}function Ie(){Jt()&&Qe.classList.add("collapsed")}function et(){Qe.classList.remove("collapsed")}document.getElementById("mode-sessions").addEventListener("click",()=>{et(),tt("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{et(),tt("files")});function tt(t){Xe=t,document.querySelectorAll(".mode-btn").forEach(n=>n.classList.remove("active"));let e=document.getElementById(t==="sessions"?"mode-sessions":"mode-files");e&&e.classList.add("active"),t==="sessions"?W():ln()}var nt="";async function W(){try{let e=await(await fetch("/api/sidebar/sessions")).json(),n=JSON.stringify({recent:e.recent,agents:e.agents});if(n===nt)return;nt=n,Zt(e)}catch{m.innerHTML+='<div class="file-tree-empty">Failed to load sessions</div>'}let t=document.getElementById("ns-btn");t&&t.addEventListener("click",()=>document.getElementById("new-session-modal")?.classList.add("open"))}function Zt(t){m.innerHTML='<button class="new-session-sidebar-btn" id="ns-btn">+ New Session</button>';let e=t.recent||[],n=document.createElement("div");n.className="sidebar-section-label"+(w?" clickable":""),n.textContent=w?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",w&&(n.title="Back to hub",n.addEventListener("click",()=>{window.location.href="/"})),m.appendChild(n);for(let o of e){let r=document.createElement("div");r.className="session-item"+(o.name===y&&!w?" active":""),r.setAttribute("data-session",o.name),r.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${o.attached?"M19 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 14H5V6h14v12z":"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"}"></svg>
|
|
7
|
+
<span>${f(o.name)}</span>
|
|
8
|
+
<button class="session-edit-btn" data-session="${f(o.name)}" title="Edit session"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>
|
|
9
|
+
`,r.addEventListener("click",l=>{l.target.closest(".session-edit-btn")||Q(o.name)}),m.appendChild(r);let c=r.querySelector(".session-edit-btn");c&&c.addEventListener("click",l=>{l.stopPropagation(),pn(o.name,c)})}let a=t.agents||[];for(let o of a){if(!o.sessions||o.sessions.length===0)continue;let r=o.agentId===w,c=document.createElement("div");c.className="sidebar-section-label machine-label"+(o.online?"":" agent-offline-label")+(!r&&o.online?" clickable":""),c.textContent=o.agentName+(o.online?"":" (offline)"),!r&&o.online&&(c.title="\u6253\u5F00 "+o.agentName,c.addEventListener("click",()=>{window.location.href="/a/"+encodeURIComponent(o.agentId)+"/"})),m.appendChild(c);for(let l of o.sessions){let u=document.createElement("div");u.className="session-item"+(l.name===y&&w===o.agentId?" active":"")+(o.online?"":" session-offline"),u.setAttribute("data-session",l.name),u.setAttribute("data-agent",o.agentId),u.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${l.attached?"M19 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 14H5V6h14v12z":"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"}"></svg>
|
|
10
|
+
<span>${f(l.name)}</span><span class="meta">${o.online?"":"offline"}</span>`,o.online&&u.addEventListener("click",p=>{p.target.closest(".session-edit-btn")||Q(l.name,o.agentId)}),m.appendChild(u)}}}function f(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function Q(t,e){if(!(y===t&&h&&w===(e||null))){Z.style.display="none",R.style.display="none",k.style.display="",k.classList.add("terminal-pending"),Ie(),h&&(be(),h.destroy(),h=null),y=t,w=e||null,window.__tmuxWebScopeAgent=w;for(let n of m.querySelectorAll(".session-item"))n.classList.toggle("active",n.getAttribute("data-session")===t&&(n.getAttribute("data-agent")||null)===w);try{h=await Kt(k,t,{terminal:Y.terminal,scrollback:Y.scrollback,theme:Y.theme,renderer:Y.renderer,wsBase:w?"/ws/a/"+encodeURIComponent(w):Y.wsBase||"/ws"}),pt()}catch(n){console.error("[shell] terminal init failed:",n);let a=n&&typeof n=="object"&&"message"in n?n.message:String(n);k.textContent="Failed to open terminal for "+t+": "+a,k.classList.remove("terminal-pending")}}}var fe=[],v=null,it=!1;function Gt(t){if(!v||!v.files.length)return null;let e=v.repoRoot;if(!e||!t.startsWith(e))return null;let n=t.slice(e.length+1);for(let a of v.files)if(a.path===n)return a.status;return null}async function Qt(t){it=!0;try{let e=await fetch(E("/api/git/status?path="+encodeURIComponent(t)));e.ok?v=await e.json():v=null}catch{v=null}finally{it=!1}}function en(){if(!v||!v.branch)return"";let{branch:t,linesAdded:e,linesRemoved:n}=v,a=`<div class="sidebar-git"><div class="git-branch-badge">
|
|
11
11
|
<svg viewBox="0 0 16 16" fill="currentColor"><path d="M11.63 1.22a.75.75 0 00-1.06 0L5.99 5.8 4.12 3.93a.75.75 0 10-1.06 1.06L4.93 6.87A3.5 3.5 0 003 10.09v3.16a.75.75 0 001 0v-3.16a2.5 2.5 0 012.5-2.5h.27l-1.06 1.06a.75.75 0 001.06 1.06l2.37-2.38a.75.75 0 000-1.06L7.59 5.27l4.04-4.05a.75.75 0 000-1.06L11.63 1.22zM3.25 13.94a.75.75 0 01-.75-.75v-.69a.75.75 0 011.5 0v.69c0 .414-.336.75-.75.75z"/></svg>
|
|
12
|
-
${
|
|
12
|
+
${f(t)}</div>`;return(e>0||n>0)&&(a+=`<div class="git-diff-stats">+<span class="add">${e}</span> <span class="del">-${n}</span></div>`),a+"</div>"}m.addEventListener("click",t=>{t.target.closest(".sidebar-git")&&j&&v&&(t.stopPropagation(),rt())});var ee=document.getElementById("header-git"),at=document.getElementById("git-diff-view"),st=document.getElementById("gd-path"),me=document.getElementById("gd-status"),he=document.getElementById("gd-content"),tn=document.getElementById("gd-back"),j=null;function te(t){if(!t||!t.branch){ee.style.display="none",j=null;return}j=t.repoRoot;let{branch:e,linesAdded:n,linesRemoved:a}=t,o=`<span class="branch">${f(e)}</span>`;(n>0||a>0)&&(o+=`<span class="sep">\xB7</span>+<span class="diff-add">${n}</span> <span class="diff-del">-${a}</span>`),ee.innerHTML=o,ee.style.display="block"}ee.addEventListener("click",t=>{j&&v&&(t.stopPropagation(),rt())});var g=document.getElementById("git-popover"),ve=document.getElementById("git-popover-backdrop");function Be(){let t=ee.getBoundingClientRect();g.style.top=t.bottom+4+"px",g.style.left=Math.max(8,Math.min(t.left,window.innerWidth-400))+"px"}function ot(){let t=j,e=document.getElementById("git-popover-browse");e&&e.addEventListener("click",()=>{if(ge(),t){Xe="files",document.querySelectorAll(".mode-btn").forEach(a=>a.classList.remove("active"));let n=document.getElementById("mode-files");n&&n.classList.add("active"),H(t)}})}var lt="";function rt(){if(!v)return;let t=v.files||[];if(!t.length)g.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
|
|
13
13
|
<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>`;else{let e=`<div class="git-popover-header">${t.length} file${t.length>1?"s":""} changed</div>`;for(let n=0;n<t.length;n++){let a=t[n],o=a.additions||0,r=a.deletions||0,c="";switch(a.status){case"M":c='<span class="git-file-status M">M</span>';break;case"A":c='<span class="git-file-status A">A</span>';break;case"D":c='<span class="git-file-status D">D</span>';break;case"?":c='<span class="git-file-status ?">?</span>';break;case"R":c='<span class="git-file-status R">R</span>';break}e+=`<div class="git-popover-item" data-idx="${n}">
|
|
14
|
-
${c}<span class="file-path">${
|
|
14
|
+
${c}<span class="file-path">${f(a.path)}</span>
|
|
15
15
|
<span class="file-add">${o>0?"+"+o:""}</span>
|
|
16
16
|
<span class="file-del">${r>0?"-"+r:""}</span>
|
|
17
|
-
</div>`}e+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',
|
|
17
|
+
</div>`}e+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',lt=e,g.innerHTML=e,g.querySelectorAll(".git-popover-item").forEach(n=>{let a=parseInt(n.dataset.idx||"0",10),o=t[a];!o||o.status==="D"||(n.classList.add("clickable"),n.style.cursor="pointer",n.addEventListener("click",()=>dt(o.path)))})}Be(),g.classList.add("open"),ve.classList.add("open"),ot()}function nn(){return window.innerWidth>=1024}function ct(t,e){let n=(t+(e&&t?`
|
|
18
18
|
`:"")+e).split(`
|
|
19
|
-
`),a="",o=0,r=0;for(let c of n){let l=c;if(l.startsWith("@@")){let u=l.match(/@@\s+-(\d+)[^+]*\+(\d+)/);u&&(o=parseInt(u[1],10)-1,r=parseInt(u[2],10)-1),a+=`<div class="diff-line hunk"><span class="ln-body">${
|
|
19
|
+
`),a="",o=0,r=0;for(let c of n){let l=c;if(l.startsWith("@@")){let u=l.match(/@@\s+-(\d+)[^+]*\+(\d+)/);u&&(o=parseInt(u[1],10)-1,r=parseInt(u[2],10)-1),a+=`<div class="diff-line hunk"><span class="ln-body">${f(l)}</span></div>`;continue}if(l.startsWith("diff --git")||l.startsWith("index ")||l.startsWith("--- ")||l.startsWith("+++ ")||l.startsWith("new file")||l.startsWith("deleted file")){l.startsWith("diff --git")&&(a+=`<div class="diff-line header"><span class="ln-body">${f(l)}</span></div>`);continue}if(l.startsWith("+"))r++,a+=`<div class="diff-line add"><span class="ln-no">${r}</span><span class="ln-body">${f(l)}</span></div>`;else if(l.startsWith("-"))o++,a+=`<div class="diff-line del"><span class="ln-no">${o}</span><span class="ln-body">${f(l)}</span></div>`;else if(l.startsWith("\\"))a+=`<div class="diff-line"><span class="ln-body">${f(l)}</span></div>`;else{if(!l&&!o&&!r)continue;o++,r++,a+=`<div class="diff-line"><span class="ln-no">${o}</span><span class="ln-no" style="margin-right:12px">${r}</span><span class="ln-body">${f(l)}</span></div>`}}return{html:a,lineCount:n.length}}var ye=null;async function dt(t){let e=j;if(e)if(ge(),nn()){k.style.display="none",h&&(be(),h.destroy(),h=null,ye=y,y=null),te(null),Z.style.display="none",R.style.display="none",at.style.display="flex",st.textContent=t,me.textContent="Loading\u2026",he.innerHTML="";try{let n=await fetch(E("/api/git/diff?path="+encodeURIComponent(e)+"&file="+encodeURIComponent(t)));if(!n.ok)throw new Error(await n.text());let a=await n.json();sn(t,a.diff,a.stagedDiff)}catch(n){let a=n instanceof Error?n.message:String(n);me.textContent="Error",he.innerHTML=`<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">Error: ${f(a)}</div>`}}else{g.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
20
20
|
<button class="diff-back">\u2190 Back</button>
|
|
21
|
-
<span class="diff-filename">${
|
|
21
|
+
<span class="diff-filename">${f(t)}</span>
|
|
22
22
|
<span class="diff-loading">Loading\u2026</span>
|
|
23
|
-
</div></div>`,
|
|
23
|
+
</div></div>`,Be(),g.classList.add("open"),ve.classList.add("open");try{let n=await fetch(E("/api/git/diff?path="+encodeURIComponent(e)+"&file="+encodeURIComponent(t)));if(!n.ok)throw new Error(await n.text());let a=await n.json();an(t,a.diff,a.stagedDiff)}catch(n){let a=n instanceof Error?n.message:String(n);g.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
24
24
|
<button class="diff-back">\u2190 Back</button>
|
|
25
|
-
<span class="diff-filename">${
|
|
26
|
-
</div><div class="diff-empty">Error loading diff: ${
|
|
25
|
+
<span class="diff-filename">${f(t)}</span>
|
|
26
|
+
</div><div class="diff-empty">Error loading diff: ${f(a)}</div></div>`}}}function an(t,e,n){if(!e&&!n){g.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
27
27
|
<button class="diff-back">\u2190 Back</button>
|
|
28
|
-
<span class="diff-filename">${
|
|
29
|
-
</div><div class="diff-empty">No diff content available</div></div>`;return}let{html:a,lineCount:o}=
|
|
28
|
+
<span class="diff-filename">${f(t)}</span>
|
|
29
|
+
</div><div class="diff-empty">No diff content available</div></div>`;return}let{html:a,lineCount:o}=ct(e,n);g.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
30
30
|
<button class="diff-back">\u2190 Back</button>
|
|
31
|
-
<span class="diff-filename">${
|
|
31
|
+
<span class="diff-filename">${f(t)}</span>
|
|
32
32
|
<span class="diff-filesize">${o} lines</span>
|
|
33
|
-
</div><div class="diff-content">${a}</div></div>`,g.querySelector(".diff-back")?.addEventListener("click",()=>{g.innerHTML=
|
|
33
|
+
</div><div class="diff-content">${a}</div></div>`,g.querySelector(".diff-back")?.addEventListener("click",()=>{g.innerHTML=lt,Be(),v&&g.querySelectorAll(".git-popover-item").forEach(r=>{let c=parseInt(r.dataset.idx||"0",10),l=v.files[c];!l||l.status==="D"||(r.style.cursor="pointer",r.addEventListener("click",()=>dt(l.path)))}),ot()})}function sn(t,e,n){if(!e&&!n){me.textContent="No diff",he.innerHTML='<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">No diff content available</div>';return}let{html:a,lineCount:o}=ct(e,n);st.textContent=t,me.textContent=o+" lines",he.innerHTML=a}function on(){at.style.display="none",ye?(k.style.display="",k.classList.add("terminal-pending"),Q(ye),ye=null):y?(k.style.display="",k.classList.add("terminal-pending"),pt()):R.style.display="flex"}tn.addEventListener("click",on);function ge(){g.classList.remove("open"),ve.classList.remove("open")}ve.addEventListener("click",ge),document.addEventListener("keydown",t=>{t.key==="Escape"&&(ge(),Ee())});async function ut(t){try{let e=await(await fetch("/api/fs/session-path?session="+encodeURIComponent(t))).json();if(e.path){let n=await fetch("/api/git/status?path="+encodeURIComponent(e.path));if(n.ok){let a=await n.json();v=a,te(a);return}}}catch{}v=null,te(null)}var we=null;function pt(){be(),y&&(ut(y),we=setInterval(()=>{y&&ut(y)},3e4))}function be(){we&&(clearInterval(we),we=null)}function ln(){if(fe=Y.fsRoots||[],fe.length===0){if(y){rn(y);return}m.innerHTML='<div class="file-tree-info">Open a session first, then switch to Files to browse its directory.</div>';return}m.innerHTML="";for(let t of fe){let e=document.createElement("div");e.className="file-tree-item",e.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${f(t)}`,e.addEventListener("click",()=>H(t)),m.appendChild(e)}}async function rn(t){m.innerHTML='<div class="file-tree-empty">Loading...</div>';try{let e=await(await fetch(E("/api/fs/session-path?session="+encodeURIComponent(t)))).json();e.path?H(e.path):m.innerHTML='<div class="file-tree-info">Could not determine session directory.</div>'}catch{m.innerHTML='<div class="file-tree-error">Failed to get session directory</div>'}}async function H(t){S=t,m.innerHTML='<div class="file-tree-empty">Loading...</div>';let e=Qt(t);try{let n=await(await fetch(E("/api/fs/list?path="+encodeURIComponent(t)))).json();await e,m.innerHTML="",te(v),m.innerHTML+=en();let a=cn(t);if(a&&!fe.some(r=>t===r)){let r=document.createElement("div");r.className="file-tree-item",r.innerHTML="..",r.addEventListener("click",()=>H(a)),m.appendChild(r)}if(n.dirs)for(let r of n.dirs){let c=r.split("/").pop()||r.split("\\").pop(),l=document.createElement("div");l.className="file-tree-item",l.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${f(c)}`,l.addEventListener("click",()=>H(r)),m.appendChild(l)}else m.innerHTML="";let o=n.files||[];for(let r of o){let c=r.split("/").pop()||r.split("\\").pop(),l=Gt(r),u="",p="";if(l)switch(l){case"M":u="git-mod",p='<span class="git-file-status M">M</span>';break;case"A":u="git-add",p='<span class="git-file-status A">A</span>';break;case"D":u="git-del",p='<span class="git-file-status D">D</span>';break;case"?":u="git-untracked",p='<span class="git-file-status ?">?</span>';break;case"R":u="git-mod",p='<span class="git-file-status R">R</span>';break}let I=document.createElement("div");I.className="file-tree-item file"+(u?" "+u:""),I.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${p}${f(c)}`,I.addEventListener("click",()=>dn(r)),m.appendChild(I)}}catch{m.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function cn(t){let e=t.lastIndexOf("/");return e<=0?null:t.substring(0,e)}async function dn(t){ue=t,k.style.display="none",h&&(be(),h.destroy(),h=null,y=null),te(null),Ie(),R.style.display="none",Z.style.display="flex",Ut.textContent=t,T.textContent="Loading...",A.style.display="none";try{let e=await fetch(E("/api/file?path="+encodeURIComponent(t)));if(!e.ok){let a=await e.json();T.textContent=a.error||"Failed to load",G.value="";return}let n=await e.json();G.value=n.content,pe=n.content,Je=n.content,T.textContent=n.size+" bytes",A.style.display=""}catch{T.textContent="Failed to load",G.value=""}}G.addEventListener("input",()=>{pe=G.value}),A.addEventListener("click",async()=>{A.textContent="Saving...",A.disabled=!0;try{let t=await fetch(E("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:ue,content:pe})});if(!t.ok){let e=await t.json();T.textContent=e.error||"Save failed";return}Je=pe,T.textContent="Saved"}catch{T.textContent="Save failed"}finally{A.disabled=!1,A.textContent="Save"}}),Ot.addEventListener("click",async()=>{if(confirm("Delete "+ue+"?"))try{let t=await fetch(E("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:ue})});if(!t.ok){let e=await t.json();T.textContent=e.error||"Delete failed";return}Z.style.display="none",R.style.display="flex",S&&H(S)}catch{T.textContent="Delete failed"}}),qt.addEventListener("click",()=>{Z.style.display="none",R.style.display="flex",S&&H(S)}),Xt.addEventListener("click",async()=>{let t=Ze.value.trim();if(!t)return;let e=S+"/"+t;try{let n=await fetch(E("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})});if(!n.ok){let a=await n.json();T.textContent=a.error||"Create failed";return}Ze.value="",S&&H(S)}catch{T.textContent="Create failed"}}),document.getElementById("mode-settings").addEventListener("click",()=>{let t=Ge.classList.toggle("open");Me.classList.toggle("open",t)}),Me.addEventListener("click",()=>{Ge.classList.remove("open"),Me.classList.remove("open")});var $="",ne=document.createElement("div");ne.className="session-popover-backdrop",document.body.appendChild(ne);var B=document.createElement("div");B.id="session-popover",B.className="session-popover",B.style.display="none",B.innerHTML=`<div class="sp-field">
|
|
34
34
|
<label>Rename session</label>
|
|
35
35
|
<input type="text" id="sp-name" />
|
|
36
36
|
</div>
|
|
@@ -39,5 +39,5 @@ var Nt="https://esm.sh/ghostty-web@0.4.0",Wt=/\x1b\](?:10|11|110|111|104)(?:;[^\
|
|
|
39
39
|
<button class="btn" id="sp-cancel">Cancel</button>
|
|
40
40
|
</div>
|
|
41
41
|
<hr class="sp-divider" />
|
|
42
|
-
<button class="btn danger" id="sp-delete">Delete session</button>`,document.body.appendChild(
|
|
43
|
-
`).length;M.rows=Math.min(t,4)}),M.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),
|
|
42
|
+
<button class="btn danger" id="sp-delete">Delete session</button>`,document.body.appendChild(B);function un(t){let e=t.getBoundingClientRect();B.style.top=e.bottom+4+"px",B.style.left=Math.max(8,Math.min(e.left,window.innerWidth-240))+"px"}function pn(t,e){$=t;let n=document.getElementById("sp-name");n.value=t,ne.classList.add("open"),B.style.display="block",un(e),setTimeout(()=>n.focus(),50)}function ie(){ne.classList.remove("open"),B.style.display="none"}ne.addEventListener("click",ie),document.getElementById("sp-save").addEventListener("click",async()=>{let t=document.getElementById("sp-name").value.trim();if(!t||t===$){ie();return}try{if(!(await fetch(E("/api/sessions/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldName:$,newName:t})})).ok)return;ie(),W(),y===$&&Q(t)}catch{}}),document.getElementById("sp-delete").addEventListener("click",async()=>{if(confirm('Delete session "'+$+'"?'))try{if(!(await fetch(E("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:$})})).ok)return;ie(),y===$&&(h&&(h.destroy(),h=null),y=null,k.style.display="none",R.style.display="flex"),W()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",ie);var fn={esc:"\x1B",tab:" ","s-tab":"\x1B[Z",up:"\x1B[A",down:"\x1B[B",left:"\x1B[D",right:"\x1B[C",space:" ",enter:"\r",exit:"exit\r",yes:"yes\r"};document.getElementById("mobile-keys").addEventListener("click",t=>{let e=t.target.closest("button[data-key]");if(!e||!h)return;let n=fn[e.dataset.key];n&&(h.sendInput(n),h.focus())});var M=document.getElementById("mk-input"),ft=document.getElementById("mk-send");function mt(){if(!M||!h)return;let t=M.value;t&&(h.sendInput(t+"\r"),M.value="",M.rows=1,h.focus())}if(M&&(M.addEventListener("input",()=>{M.rows=1;let t=M.value.split(`
|
|
43
|
+
`).length;M.rows=Math.min(t,4)}),M.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),mt())})),ft&&ft.addEventListener("click",mt),window.visualViewport){let t=document.querySelector(".app-layout"),e=()=>{t&&(t.style.height=window.visualViewport.height+"px"),window.scrollTo(0,0),document.documentElement.scrollTop=0,document.body.scrollTop=0};window.visualViewport.addEventListener("resize",e),window.addEventListener("orientationchange",()=>setTimeout(e,100)),document.addEventListener("touchstart",()=>{(window.scrollY>0||document.documentElement.scrollTop>0)&&window.scrollTo(0,0)},{passive:!0})}var Se=document.getElementById("process-panel"),ae=document.getElementById("proc-list"),mn=document.getElementById("proc-close"),He=document.getElementById("proc-backdrop"),hn=document.getElementById("header-ram");function vn(){ae.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(E("/api/system/processes")).then(t=>t.json()).then(t=>{if(!Array.isArray(t)||!t.length){ae.innerHTML='<div class="proc-empty">No processes</div>';return}let e="";for(let n of t){let a=n.rss,o=a<1048576?(a/1024).toFixed(0)+"K":(a/1048576).toFixed(1)+"M";e+='<div class="proc-row" data-pid="'+n.pid+'"><span class="proc-mem">'+n.mem+'%</span><span class="proc-rss">'+o+'</span><span class="proc-cmd" title="'+f(n.command)+'">'+f(n.command)+'</span><button class="proc-kill" title="Kill PID '+n.pid+'">×</button></div>'}ae.innerHTML=e;for(let n of ae.querySelectorAll(".proc-row")){let a=n.querySelector(".proc-kill");a&&a.addEventListener("click",o=>{let r=o.target.closest(".proc-row");!r||!confirm("Kill PID "+r.dataset.pid+"?")||fetch(E("/api/system/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:parseInt(r.dataset.pid,10)})}).then(c=>c.json()).then(c=>{c.ok?r.style.opacity="0.3":alert("Failed: "+(c.error||"unknown"))}).catch(()=>alert("Network error"))})}}).catch(()=>{ae.innerHTML='<div class="proc-empty">Failed to load</div>'})}function yn(){Se.classList.add("open"),He.classList.add("open"),vn()}function Ee(){Se.classList.remove("open"),He.classList.remove("open")}hn.addEventListener("click",t=>{t.stopPropagation(),Se.classList.contains("open")?Ee():yn()}),mn.addEventListener("click",Ee),He.addEventListener("click",Ee),window.__openSession=Q,window.__refreshSidebar=W,W(),Ie(),setInterval(()=>{document.visibilityState==="visible"&&W()},1e4);
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import{initTerminal as
|
|
1
|
+
import{initTerminal as ke}from"./terminal-core.js";const M=window.__TMUX_WEB_SHELL__;let p=null,u=null;const ne=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null;let v=ne;window.__tmuxWebScopeAgent=ne;let se="sessions",E="",j="",W="",ie="";function y(e){return v?"/a/"+encodeURIComponent(v)+e:e}const r=document.getElementById("sidebar-content"),C=document.getElementById("main-placeholder"),h=document.getElementById("terminal-container"),H=document.getElementById("file-editor"),Ce=document.getElementById("fe-path"),b=document.getElementById("fe-status"),$=document.getElementById("fe-content"),I=document.getElementById("fe-save"),Ie=document.getElementById("fe-delete"),Be=document.getElementById("fe-back"),oe=document.getElementById("fe-new-name"),xe=document.getElementById("fe-new-btn"),Y=document.getElementById("settings-backdrop"),ae=document.getElementById("settings-popover"),le=document.querySelector(".sidebar");function Me(){return window.matchMedia("(max-width: 640px)").matches}function Z(){Me()&&le.classList.add("collapsed")}function ce(){le.classList.remove("collapsed")}document.getElementById("mode-sessions").addEventListener("click",()=>{ce(),de("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{ce(),de("files")});function de(e){se=e,document.querySelectorAll(".mode-btn").forEach(t=>t.classList.remove("active"));const n=document.getElementById(e==="sessions"?"mode-sessions":"mode-files");n&&n.classList.add("active"),e==="sessions"?S():_e()}let re="";async function S(){try{const t=await(await fetch("/api/sidebar/sessions")).json(),s=JSON.stringify({recent:t.recent,agents:t.agents});if(s===re)return;re=s,Se(t)}catch{r.innerHTML+='<div class="file-tree-empty">Failed to load sessions</div>'}const e=document.getElementById("ns-btn");e&&e.addEventListener("click",()=>document.getElementById("new-session-modal")?.classList.add("open"))}function Se(e){r.innerHTML='<button class="new-session-sidebar-btn" id="ns-btn">+ New Session</button>';const n=e.recent||[],t=document.createElement("div");t.className="sidebar-section-label"+(v?" clickable":""),t.textContent=v?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",v&&(t.title="Back to hub",t.addEventListener("click",()=>{window.location.href="/"})),r.appendChild(t);for(const i of n){const l=document.createElement("div");l.className="session-item"+(i.name===u&&!v?" active":""),l.setAttribute("data-session",i.name),l.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${i.attached?"M19 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 14H5V6h14v12z":"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"}"></svg>
|
|
2
2
|
<span>${d(i.name)}</span>
|
|
3
3
|
<button class="session-edit-btn" data-session="${d(i.name)}" title="Edit session"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>
|
|
4
|
-
`,
|
|
5
|
-
<span>${d(c.name)}</span><span class="meta">${i.online?"":"offline"}</span>`,i.online&&a.addEventListener("click",
|
|
4
|
+
`,l.addEventListener("click",c=>{c.target.closest(".session-edit-btn")||R(i.name)}),r.appendChild(l);const o=l.querySelector(".session-edit-btn");o&&o.addEventListener("click",c=>{c.stopPropagation(),Oe(i.name,o)})}const s=e.agents||[];for(const i of s){if(!i.sessions||i.sessions.length===0)continue;const l=i.agentId===v,o=document.createElement("div");o.className="sidebar-section-label machine-label"+(i.online?"":" agent-offline-label")+(!l&&i.online?" clickable":""),o.textContent=i.agentName+(i.online?"":" (offline)"),!l&&i.online&&(o.title="\u6253\u5F00 "+i.agentName,o.addEventListener("click",()=>{window.location.href="/a/"+encodeURIComponent(i.agentId)+"/"})),r.appendChild(o);for(const c of i.sessions){const a=document.createElement("div");a.className="session-item"+(c.name===u&&v===i.agentId?" active":"")+(i.online?"":" session-offline"),a.setAttribute("data-session",c.name),a.setAttribute("data-agent",i.agentId),a.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${c.attached?"M19 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 14H5V6h14v12z":"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"}"></svg>
|
|
5
|
+
<span>${d(c.name)}</span><span class="meta">${i.online?"":"offline"}</span>`,i.online&&a.addEventListener("click",g=>{g.target.closest(".session-edit-btn")||R(c.name,i.agentId)}),r.appendChild(a)}}}function d(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function R(e,n){if(!(u===e&&p&&v===(n||null))){H.style.display="none",C.style.display="none",h.style.display="",h.classList.add("terminal-pending"),Z(),p&&(K(),p.destroy(),p=null),u=e,v=n||null,window.__tmuxWebScopeAgent=v;for(const t of r.querySelectorAll(".session-item"))t.classList.toggle("active",t.getAttribute("data-session")===e&&(t.getAttribute("data-agent")||null)===v);try{p=await ke(h,e,{terminal:M.terminal,scrollback:M.scrollback,theme:M.theme,renderer:M.renderer,wsBase:v?"/ws/a/"+encodeURIComponent(v):M.wsBase||"/ws"}),we()}catch(t){console.error("[shell] terminal init failed:",t);const s=t&&typeof t=="object"&&"message"in t?t.message:String(t);h.textContent="Failed to open terminal for "+e+": "+s,h.classList.remove("terminal-pending")}}}let z=[],f=null,pe=!1;function Te(e){if(!f||!f.files.length)return null;const n=f.repoRoot;if(!n||!e.startsWith(n))return null;const t=e.slice(n.length+1);for(const s of f.files)if(s.path===t)return s.status;return null}async function He(e){pe=!0;try{const n=await fetch(y("/api/git/status?path="+encodeURIComponent(e)));n.ok?f=await n.json():f=null}catch{f=null}finally{pe=!1}}function $e(){if(!f||!f.branch)return"";const{branch:e,linesAdded:n,linesRemoved:t}=f;let s=`<div class="sidebar-git"><div class="git-branch-badge">
|
|
6
6
|
<svg viewBox="0 0 16 16" fill="currentColor"><path d="M11.63 1.22a.75.75 0 00-1.06 0L5.99 5.8 4.12 3.93a.75.75 0 10-1.06 1.06L4.93 6.87A3.5 3.5 0 003 10.09v3.16a.75.75 0 001 0v-3.16a2.5 2.5 0 012.5-2.5h.27l-1.06 1.06a.75.75 0 001.06 1.06l2.37-2.38a.75.75 0 000-1.06L7.59 5.27l4.04-4.05a.75.75 0 000-1.06L11.63 1.22zM3.25 13.94a.75.75 0 01-.75-.75v-.69a.75.75 0 011.5 0v.69c0 .414-.336.75-.75.75z"/></svg>
|
|
7
|
-
${d(e)}</div>`;return(n>0||t>0)&&(s+=`<div class="git-diff-stats">+<span class="add">${n}</span> <span class="del">-${t}</span></div>`),s+"</div>"}r.addEventListener("click",e=>{e.target.closest(".sidebar-git")&&T&&f&&(e.stopPropagation(),
|
|
8
|
-
<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>`;else{let n=`<div class="git-popover-header">${e.length} file${e.length>1?"s":""} changed</div>`;for(let t=0;t<e.length;t++){const s=e[t],
|
|
7
|
+
${d(e)}</div>`;return(n>0||t>0)&&(s+=`<div class="git-diff-stats">+<span class="add">${n}</span> <span class="del">-${t}</span></div>`),s+"</div>"}r.addEventListener("click",e=>{e.target.closest(".sidebar-git")&&T&&f&&(e.stopPropagation(),ge())});const N=document.getElementById("header-git"),fe=document.getElementById("git-diff-view"),ue=document.getElementById("gd-path"),O=document.getElementById("gd-status"),U=document.getElementById("gd-content"),Re=document.getElementById("gd-back");let T=null;function D(e){if(!e||!e.branch){N.style.display="none",T=null;return}T=e.repoRoot;const{branch:n,linesAdded:t,linesRemoved:s}=e;let i=`<span class="branch">${d(n)}</span>`;(t>0||s>0)&&(i+=`<span class="sep">\xB7</span>+<span class="diff-add">${t}</span> <span class="diff-del">-${s}</span>`),N.innerHTML=i,N.style.display="block"}N.addEventListener("click",e=>{T&&f&&(e.stopPropagation(),ge())});const m=document.getElementById("git-popover"),G=document.getElementById("git-popover-backdrop");function Q(){const e=N.getBoundingClientRect();m.style.top=e.bottom+4+"px",m.style.left=Math.max(8,Math.min(e.left,window.innerWidth-400))+"px"}function me(){const e=T,n=document.getElementById("git-popover-browse");n&&n.addEventListener("click",()=>{if(q(),e){se="files",document.querySelectorAll(".mode-btn").forEach(s=>s.classList.remove("active"));const t=document.getElementById("mode-files");t&&t.classList.add("active"),k(e)}})}let ve="";function ge(){if(!f)return;const e=f.files||[];if(!e.length)m.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
|
|
8
|
+
<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>`;else{let n=`<div class="git-popover-header">${e.length} file${e.length>1?"s":""} changed</div>`;for(let t=0;t<e.length;t++){const s=e[t],i=s.additions||0,l=s.deletions||0;let o="";switch(s.status){case"M":o='<span class="git-file-status M">M</span>';break;case"A":o='<span class="git-file-status A">A</span>';break;case"D":o='<span class="git-file-status D">D</span>';break;case"?":o='<span class="git-file-status ?">?</span>';break;case"R":o='<span class="git-file-status R">R</span>';break}n+=`<div class="git-popover-item" data-idx="${t}">
|
|
9
9
|
${o}<span class="file-path">${d(s.path)}</span>
|
|
10
|
-
<span class="file-add">${
|
|
11
|
-
<span class="file-del">${
|
|
12
|
-
</div>`}n+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',
|
|
10
|
+
<span class="file-add">${i>0?"+"+i:""}</span>
|
|
11
|
+
<span class="file-del">${l>0?"-"+l:""}</span>
|
|
12
|
+
</div>`}n+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',ve=n,m.innerHTML=n,m.querySelectorAll(".git-popover-item").forEach(t=>{const s=parseInt(t.dataset.idx||"0",10),i=e[s];!i||i.status==="D"||(t.classList.add("clickable"),t.style.cursor="pointer",t.addEventListener("click",()=>he(i.path)))})}Q(),m.classList.add("open"),G.classList.add("open"),me()}function Ne(){return window.innerWidth>=1024}function ye(e,n){const s=(e+(n&&e?`
|
|
13
13
|
`:"")+n).split(`
|
|
14
|
-
`);let
|
|
14
|
+
`);let i="",l=0,o=0;for(const c of s){const a=c;if(a.startsWith("@@")){const g=a.match(/@@\s+-(\d+)[^+]*\+(\d+)/);g&&(l=parseInt(g[1],10)-1,o=parseInt(g[2],10)-1),i+=`<div class="diff-line hunk"><span class="ln-body">${d(a)}</span></div>`;continue}if(a.startsWith("diff --git")||a.startsWith("index ")||a.startsWith("--- ")||a.startsWith("+++ ")||a.startsWith("new file")||a.startsWith("deleted file")){a.startsWith("diff --git")&&(i+=`<div class="diff-line header"><span class="ln-body">${d(a)}</span></div>`);continue}if(a.startsWith("+"))o++,i+=`<div class="diff-line add"><span class="ln-no">${o}</span><span class="ln-body">${d(a)}</span></div>`;else if(a.startsWith("-"))l++,i+=`<div class="diff-line del"><span class="ln-no">${l}</span><span class="ln-body">${d(a)}</span></div>`;else if(a.startsWith("\\"))i+=`<div class="diff-line"><span class="ln-body">${d(a)}</span></div>`;else{if(!a&&!l&&!o)continue;l++,o++,i+=`<div class="diff-line"><span class="ln-no">${l}</span><span class="ln-no" style="margin-right:12px">${o}</span><span class="ln-body">${d(a)}</span></div>`}}return{html:i,lineCount:s.length}}let V=null;async function he(e){const n=T;if(n)if(q(),Ne()){h.style.display="none",p&&(K(),p.destroy(),p=null,V=u,u=null),D(null),H.style.display="none",C.style.display="none",fe.style.display="flex",ue.textContent=e,O.textContent="Loading\u2026",U.innerHTML="";try{const t=await fetch(y("/api/git/diff?path="+encodeURIComponent(n)+"&file="+encodeURIComponent(e)));if(!t.ok)throw new Error(await t.text());const s=await t.json();Pe(e,s.diff,s.stagedDiff)}catch(t){const s=t instanceof Error?t.message:String(t);O.textContent="Error",U.innerHTML=`<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">Error: ${d(s)}</div>`}}else{m.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
15
15
|
<button class="diff-back">\u2190 Back</button>
|
|
16
16
|
<span class="diff-filename">${d(e)}</span>
|
|
17
17
|
<span class="diff-loading">Loading\u2026</span>
|
|
18
|
-
</div></div>`,Q(),m.classList.add("open"),
|
|
18
|
+
</div></div>`,Q(),m.classList.add("open"),G.classList.add("open");try{const t=await fetch(y("/api/git/diff?path="+encodeURIComponent(n)+"&file="+encodeURIComponent(e)));if(!t.ok)throw new Error(await t.text());const s=await t.json();De(e,s.diff,s.stagedDiff)}catch(t){const s=t instanceof Error?t.message:String(t);m.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
19
19
|
<button class="diff-back">\u2190 Back</button>
|
|
20
20
|
<span class="diff-filename">${d(e)}</span>
|
|
21
|
-
</div><div class="diff-empty">Error loading diff: ${d(s)}</div></div>`}}}function
|
|
21
|
+
</div><div class="diff-empty">Error loading diff: ${d(s)}</div></div>`}}}function De(e,n,t){if(!n&&!t){m.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
22
22
|
<button class="diff-back">\u2190 Back</button>
|
|
23
23
|
<span class="diff-filename">${d(e)}</span>
|
|
24
|
-
</div><div class="diff-empty">No diff content available</div></div>`;return}const{html:s,lineCount:
|
|
24
|
+
</div><div class="diff-empty">No diff content available</div></div>`;return}const{html:s,lineCount:i}=ye(n,t);m.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
25
25
|
<button class="diff-back">\u2190 Back</button>
|
|
26
26
|
<span class="diff-filename">${d(e)}</span>
|
|
27
|
-
<span class="diff-filesize">${
|
|
28
|
-
</div><div class="diff-content">${s}</div></div>`,m.querySelector(".diff-back")?.addEventListener("click",()=>{m.innerHTML=
|
|
27
|
+
<span class="diff-filesize">${i} lines</span>
|
|
28
|
+
</div><div class="diff-content">${s}</div></div>`,m.querySelector(".diff-back")?.addEventListener("click",()=>{m.innerHTML=ve,Q(),f&&m.querySelectorAll(".git-popover-item").forEach(l=>{const o=parseInt(l.dataset.idx||"0",10),c=f.files[o];!c||c.status==="D"||(l.style.cursor="pointer",l.addEventListener("click",()=>he(c.path)))}),me()})}function Pe(e,n,t){if(!n&&!t){O.textContent="No diff",U.innerHTML='<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">No diff content available</div>';return}const{html:s,lineCount:i}=ye(n,t);ue.textContent=e,O.textContent=i+" lines",U.innerHTML=s}function Ae(){fe.style.display="none",V?(h.style.display="",h.classList.add("terminal-pending"),R(V),V=null):u?(h.style.display="",h.classList.add("terminal-pending"),we()):C.style.display="flex"}Re.addEventListener("click",Ae);function q(){m.classList.remove("open"),G.classList.remove("open")}G.addEventListener("click",q),document.addEventListener("keydown",e=>{e.key==="Escape"&&(q(),X())});async function be(e){try{const t=await(await fetch("/api/fs/session-path?session="+encodeURIComponent(e))).json();if(t.path){const s=await fetch("/api/git/status?path="+encodeURIComponent(t.path));if(s.ok){const i=await s.json();f=i,D(i);return}}}catch{}f=null,D(null)}let J=null;function we(){K(),u&&(be(u),J=setInterval(()=>{u&&be(u)},3e4))}function K(){J&&(clearInterval(J),J=null)}function _e(){if(z=M.fsRoots||[],z.length===0){if(u){Fe(u);return}r.innerHTML='<div class="file-tree-info">Open a session first, then switch to Files to browse its directory.</div>';return}r.innerHTML="";for(const e of z){const n=document.createElement("div");n.className="file-tree-item",n.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${d(e)}`,n.addEventListener("click",()=>k(e)),r.appendChild(n)}}async function Fe(e){r.innerHTML='<div class="file-tree-empty">Loading...</div>';try{const t=await(await fetch(y("/api/fs/session-path?session="+encodeURIComponent(e)))).json();t.path?k(t.path):r.innerHTML='<div class="file-tree-info">Could not determine session directory.</div>'}catch{r.innerHTML='<div class="file-tree-error">Failed to get session directory</div>'}}async function k(e){E=e,r.innerHTML='<div class="file-tree-empty">Loading...</div>';const n=He(e);try{const s=await(await fetch(y("/api/fs/list?path="+encodeURIComponent(e)))).json();await n,r.innerHTML="",D(f),r.innerHTML+=$e();const i=je(e);if(i&&!z.some(c=>e===c)){const c=document.createElement("div");c.className="file-tree-item",c.innerHTML="..",c.addEventListener("click",()=>k(i)),r.appendChild(c)}if(s.dirs)for(const o of s.dirs){const c=o.split("/").pop()||o.split("\\").pop(),a=document.createElement("div");a.className="file-tree-item",a.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${d(c)}`,a.addEventListener("click",()=>k(o)),r.appendChild(a)}else r.innerHTML="";const l=s.files||[];for(const o of l){const c=o.split("/").pop()||o.split("\\").pop(),a=Te(o);let g="",x="";if(a)switch(a){case"M":g="git-mod",x='<span class="git-file-status M">M</span>';break;case"A":g="git-add",x='<span class="git-file-status A">A</span>';break;case"D":g="git-del",x='<span class="git-file-status D">D</span>';break;case"?":g="git-untracked",x='<span class="git-file-status ?">?</span>';break;case"R":g="git-mod",x='<span class="git-file-status R">R</span>';break}const F=document.createElement("div");F.className="file-tree-item file"+(g?" "+g:""),F.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${x}${d(c)}`,F.addEventListener("click",()=>We(o)),r.appendChild(F)}}catch{r.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function je(e){const n=e.lastIndexOf("/");return n<=0?null:e.substring(0,n)}async function We(e){j=e,h.style.display="none",p&&(K(),p.destroy(),p=null,u=null),D(null),Z(),C.style.display="none",H.style.display="flex",Ce.textContent=e,b.textContent="Loading...",I.style.display="none";try{const n=await fetch(y("/api/file?path="+encodeURIComponent(e)));if(!n.ok){const s=await n.json();b.textContent=s.error||"Failed to load",$.value="";return}const t=await n.json();$.value=t.content,W=t.content,ie=t.content,b.textContent=t.size+" bytes",I.style.display=""}catch{b.textContent="Failed to load",$.value=""}}$.addEventListener("input",()=>{W=$.value}),I.addEventListener("click",async()=>{I.textContent="Saving...",I.disabled=!0;try{const e=await fetch(y("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:j,content:W})});if(!e.ok){const n=await e.json();b.textContent=n.error||"Save failed";return}ie=W,b.textContent="Saved"}catch{b.textContent="Save failed"}finally{I.disabled=!1,I.textContent="Save"}}),Ie.addEventListener("click",async()=>{if(confirm("Delete "+j+"?"))try{const e=await fetch(y("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:j})});if(!e.ok){const n=await e.json();b.textContent=n.error||"Delete failed";return}H.style.display="none",C.style.display="flex",E&&k(E)}catch{b.textContent="Delete failed"}}),Be.addEventListener("click",()=>{H.style.display="none",C.style.display="flex",E&&k(E)}),xe.addEventListener("click",async()=>{const e=oe.value.trim();if(!e)return;const n=E+"/"+e;try{const t=await fetch(y("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(!t.ok){const s=await t.json();b.textContent=s.error||"Create failed";return}oe.value="",E&&k(E)}catch{b.textContent="Create failed"}}),document.getElementById("mode-settings").addEventListener("click",()=>{const e=ae.classList.toggle("open");Y.classList.toggle("open",e)}),Y.addEventListener("click",()=>{ae.classList.remove("open"),Y.classList.remove("open")});let B="";const P=document.createElement("div");P.className="session-popover-backdrop",document.body.appendChild(P);const L=document.createElement("div");L.id="session-popover",L.className="session-popover",L.style.display="none",L.innerHTML=`<div class="sp-field">
|
|
29
29
|
<label>Rename session</label>
|
|
30
30
|
<input type="text" id="sp-name" />
|
|
31
31
|
</div>
|
|
@@ -34,5 +34,5 @@ import{initTerminal as we}from"./terminal-core.js";const M=window.__TMUX_WEB_SHE
|
|
|
34
34
|
<button class="btn" id="sp-cancel">Cancel</button>
|
|
35
35
|
</div>
|
|
36
36
|
<hr class="sp-divider" />
|
|
37
|
-
<button class="btn danger" id="sp-delete">Delete session</button>`,document.body.appendChild(
|
|
38
|
-
`).length;
|
|
37
|
+
<button class="btn danger" id="sp-delete">Delete session</button>`,document.body.appendChild(L);function ze(e){const n=e.getBoundingClientRect();L.style.top=n.bottom+4+"px",L.style.left=Math.max(8,Math.min(n.left,window.innerWidth-240))+"px"}function Oe(e,n){B=e;const t=document.getElementById("sp-name");t.value=e,P.classList.add("open"),L.style.display="block",ze(n),setTimeout(()=>t.focus(),50)}function A(){P.classList.remove("open"),L.style.display="none"}P.addEventListener("click",A),document.getElementById("sp-save").addEventListener("click",async()=>{const e=document.getElementById("sp-name").value.trim();if(!e||e===B){A();return}try{if(!(await fetch(y("/api/sessions/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldName:B,newName:e})})).ok)return;A(),S(),u===B&&R(e)}catch{}}),document.getElementById("sp-delete").addEventListener("click",async()=>{if(confirm('Delete session "'+B+'"?'))try{if(!(await fetch(y("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:B})})).ok)return;A(),u===B&&(p&&(p.destroy(),p=null),u=null,h.style.display="none",C.style.display="flex"),S()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",A);const Ue={esc:"\x1B",tab:" ","s-tab":"\x1B[Z",up:"\x1B[A",down:"\x1B[B",left:"\x1B[D",right:"\x1B[C",space:" ",enter:"\r",exit:"exit\r",yes:"yes\r"};document.getElementById("mobile-keys").addEventListener("click",e=>{const n=e.target.closest("button[data-key]");if(!n||!p)return;const t=Ue[n.dataset.key];t&&(p.sendInput(t),p.focus())});const w=document.getElementById("mk-input"),Le=document.getElementById("mk-send");function Ee(){if(!w||!p)return;const e=w.value;e&&(p.sendInput(e+"\r"),w.value="",w.rows=1,p.focus())}if(w&&(w.addEventListener("input",()=>{w.rows=1;const e=w.value.split(`
|
|
38
|
+
`).length;w.rows=Math.min(e,4)}),w.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Ee())})),Le&&Le.addEventListener("click",Ee),window.visualViewport){const e=document.querySelector(".app-layout"),n=()=>{e&&(e.style.height=window.visualViewport.height+"px"),window.scrollTo(0,0),document.documentElement.scrollTop=0,document.body.scrollTop=0};window.visualViewport.addEventListener("resize",n),window.addEventListener("orientationchange",()=>setTimeout(n,100)),document.addEventListener("touchstart",()=>{(window.scrollY>0||document.documentElement.scrollTop>0)&&window.scrollTo(0,0)},{passive:!0})}const ee=document.getElementById("process-panel"),_=document.getElementById("proc-list"),Ge=document.getElementById("proc-close"),te=document.getElementById("proc-backdrop"),Ve=document.getElementById("header-ram");function qe(){_.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(y("/api/system/processes")).then(e=>e.json()).then(e=>{if(!Array.isArray(e)||!e.length){_.innerHTML='<div class="proc-empty">No processes</div>';return}let n="";for(const t of e){const s=t.rss,i=s<1048576?(s/1024).toFixed(0)+"K":(s/1048576).toFixed(1)+"M";n+='<div class="proc-row" data-pid="'+t.pid+'"><span class="proc-mem">'+t.mem+'%</span><span class="proc-rss">'+i+'</span><span class="proc-cmd" title="'+d(t.command)+'">'+d(t.command)+'</span><button class="proc-kill" title="Kill PID '+t.pid+'">×</button></div>'}_.innerHTML=n;for(const t of _.querySelectorAll(".proc-row")){const s=t.querySelector(".proc-kill");s&&s.addEventListener("click",i=>{const l=i.target.closest(".proc-row");!l||!confirm("Kill PID "+l.dataset.pid+"?")||fetch(y("/api/system/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:parseInt(l.dataset.pid,10)})}).then(o=>o.json()).then(o=>{o.ok?l.style.opacity="0.3":alert("Failed: "+(o.error||"unknown"))}).catch(()=>alert("Network error"))})}}).catch(()=>{_.innerHTML='<div class="proc-empty">Failed to load</div>'})}function Je(){ee.classList.add("open"),te.classList.add("open"),qe()}function X(){ee.classList.remove("open"),te.classList.remove("open")}Ve.addEventListener("click",e=>{e.stopPropagation(),ee.classList.contains("open")?X():Je()}),Ge.addEventListener("click",X),te.addEventListener("click",X),window.__openSession=R,window.__refreshSidebar=S,S(),Z(),setInterval(()=>{document.visibilityState==="visible"&&S()},1e4);
|
package/dist/lib/agent-client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WebSocket as E}from"ws";import{attachTerminal as
|
|
1
|
+
import{WebSocket as E}from"ws";import{attachTerminal as q}from"./attach-terminal.js";import{encodeBinaryFrame as U,decodeBinaryFrame as D,BIN_KIND_HTTP_BODY as N}from"./agent-channel.js";const J=parseInt(process.env.TMUX_WEB_AGENT_HEARTBEAT_MS||"15000",10),j=parseInt(process.env.TMUX_WEB_AGENT_SESSIONS_POLL_MS||"10000",10),x=new Set(["content-type","content-disposition","location","cache-control","etag"]);function X(o){const I=o.log??(e=>console.log(`[agent] ${e}`)),_=e=>console.error(`[agent] ${e}`);let s=null,g=1e3,T=null,S=!1;const u=new Map,f=new Map;let h=null,p=null,w="",m=null;const y={state:"idle",agentId:null,hub:o.hub,name:o.name};function d(e,t){t!==void 0&&(y.lastError=t),y.state=e,y.agentId=m,o.onStatus?.({...y})}function c(e){s&&s.readyState===E.OPEN&&s.send(JSON.stringify(e))}function B(){let e;try{e=o.listSessions()}catch{return}const t=JSON.stringify(e);t!==w&&(w=t,c({type:"sessions",sessions:e}))}function P(){h||(h=setInterval(B,j)),p||(p=setInterval(()=>c({type:"ping",ts:Date.now()}),J))}function A(){h&&(clearInterval(h),h=null),p&&(clearInterval(p),p=null)}async function $(e){let t;if(e.hasBody){const a=f.get(e.id);f.delete(e.id),t=a&&a.length?Buffer.concat(a):Buffer.alloc(0)}const n=new URL(e.path,"http://agent.invalid");let i;try{const a={method:e.method,headers:e.headers};t&&t.length&&(a.body=t),i=await Promise.race([o.app.request(new Request(n,a)),new Promise((K,R)=>setTimeout(()=>R(new Error("app.request timed out")),3e4))])}catch(a){_(`tunnel request failed: ${e.method} ${e.path} ${a.message}`),c({type:"http_resp",id:e.id,status:500,headers:{"content-type":"application/json"},hasBody:!1});return}const b={};i.headers.forEach((a,l)=>{x.has(l.toLowerCase())&&(b[l]=a)});const r=Buffer.from(await i.arrayBuffer());if(c({type:"http_resp",id:e.id,status:i.status,headers:b,hasBody:r.length>0}),r.length>0){for(let l=0;l<r.length;l+=65536){if(!s||s.readyState!==E.OPEN)return;s.send(U(N,e.id,r.subarray(l,l+65536)))}c({type:"http_body_end",id:e.id})}}function v(e){const t=e.session;let n=!1;try{n=o.listSessions().some(r=>r.name===t)}catch{n=!1}if(!n){c({type:"attach_err",connId:e.connId,session:t,message:"no such session"});return}let i=null;const b=q(t,{send:r=>c({type:"ws_to_hub",connId:e.connId,msg:r}),onMessage:r=>{i=r},onClose:()=>{}},{terminalBufferConfig:o.terminalBufferConfig,getSessionPaneTarget:o.getSessionPaneTarget,capturePaneTail:o.capturePaneTail,capturePaneHistoryChunk:o.capturePaneHistoryChunk,toCrlf:o.toCrlf,handleClientMessage:o.handleClientMessage,acquireControlClient:o.acquireControlClient,onPtyExit:(r,a)=>{c({type:"ws_close",connId:e.connId,code:1e3,reason:`tmux exited (${a})`})},onSpawnError:(r,a)=>{c({type:"attach_err",connId:e.connId,session:t,message:a})},onAttached:r=>{c({type:"attach_ok",connId:e.connId,session:t})}});u.set(e.connId,{onMessage:r=>i?.(r),dispose:()=>{u.delete(e.connId),b.dispose()}})}function H(e){let t;try{t=JSON.parse(e)}catch{return}switch(t.type){case"hello_ok":m=t.agentId,g=1e3,I(`connected to hub as "${m}"`),d("connected"),B(),P();break;case"hello_err":if(_(`hub rejected us: ${t.reason}`),d("error",t.reason),s)try{s.close(4003,"hello rejected")}catch{}break;case"sessions_req":B();break;case"http_req":$(t);break;case"http_body_end":break;case"attach":v(t);break;case"ws_to_agent":{const n=u.get(t.connId);if(n)try{n.onMessage(JSON.stringify(t.msg))}catch{}break}case"detach":{const n=u.get(t.connId);n&&n.dispose();break}case"pong":break;default:break}}function O(e){const t=D(e);if(t&&t.kind===N){const n=f.get(t.id)??[];n.push(t.payload),f.set(t.id,n)}}function C(){A();for(const e of u.values())try{e.dispose()}catch{}u.clear(),f.clear(),w=""}function k(){if(s){try{s.removeAllListeners()}catch{}s=null}if(C(),S)return;d("connecting");const e=g+Math.random()*500;I(`reconnecting in ${Math.round(e)}ms\u2026`),T=setTimeout(M,e),g=Math.min(g*2,6e4)}function M(){if(S||s)return;const e=o.hub.replace(/\/+$/,"").replace(/^http:/,"ws:").replace(/^https:/,"wss:")+"/agent/ws";let t;try{t=new E(e)}catch(n){_(`bad hub URL: ${n.message} (${e})`),d("error",`bad hub URL: ${n.message}`);return}s=t,d("connecting"),t.on("open",()=>{I(`connecting to ${e}\u2026`),c({type:"hello",token:o.token,name:o.name,version:o.version})}),t.on("message",(n,i)=>{i?O(Array.isArray(n)?Buffer.concat(n):Buffer.isBuffer(n)?n:Buffer.from(n)):H(typeof n=="string"?n:Buffer.from(n).toString("utf-8"))}),t.on("close",()=>{s===t&&k()}),t.on("error",n=>{_(`connection error: ${n.message}`),s===t&&k()})}function L(){if(!S){if(S=!0,T&&clearTimeout(T),C(),s){try{s.removeAllListeners(),s.close(1e3,"shutdown")}catch{}s=null}m=null,d("idle")}}return M(),{stop:L,status:()=>({...y})}}export{X as startAgentClient};
|
package/dist/lib/pages/shell.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{cssVarsStyle as g}from"../theme.js";import{commandbarCSS as b,commandbarHTML as x,commandbarScript as m}from"../commandbar.js";import{newSessionModalCSS as v,newSessionModalHTML as u,newSessionModalScript as h,reducedMotion as y}from"../shared-layout.js";import{icon as i}from"../icons.js";function $(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function n(o="var(--panel-accent)"){return`box-shadow: 0 0 0 2px ${o}; outline: none;`}function
|
|
1
|
+
import{cssVarsStyle as g}from"../theme.js";import{commandbarCSS as b,commandbarHTML as x,commandbarScript as m}from"../commandbar.js";import{newSessionModalCSS as v,newSessionModalHTML as u,newSessionModalScript as h,reducedMotion as y}from"../shared-layout.js";import{icon as i}from"../icons.js";function $(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function n(o="var(--panel-accent)"){return`box-shadow: 0 0 0 2px ${o}; outline: none;`}function T(o){const{theme:e,commandbarEnabled:t,commandbarSessions:a,fsRoots:s,terminalCfg:p,renderer:r,scrollback:l,wsBase:d}=o,c=`
|
|
2
2
|
*, *::before, *::after { box-sizing: border-box; }
|
|
3
3
|
html, body {
|
|
4
4
|
background: var(--page-bg); color: var(--page-fg);
|
|
@@ -116,23 +116,14 @@ import{cssVarsStyle as g}from"../theme.js";import{commandbarCSS as b,commandbarH
|
|
|
116
116
|
color: var(--panel-muted); padding: 8px 12px 4px; font-weight: 500;
|
|
117
117
|
}
|
|
118
118
|
.sidebar-section-label.agent-offline-label { color: color-mix(in srgb, var(--panel-muted) 60%, transparent); }
|
|
119
|
-
.
|
|
120
|
-
.session-item .meta { margin-left: auto; }
|
|
121
|
-
#tw-scope-native {
|
|
122
|
-
flex-shrink: 0;
|
|
123
|
-
max-width: 160px;
|
|
124
|
-
background: color-mix(in srgb, var(--panel-bg) 80%, transparent);
|
|
125
|
-
color: var(--page-fg);
|
|
126
|
-
border: 1px solid var(--panel-border);
|
|
127
|
-
border-radius: 8px;
|
|
128
|
-
padding: 4px 8px;
|
|
129
|
-
font-size: 12px;
|
|
130
|
-
font-family: var(--font-sans);
|
|
131
|
-
outline: none;
|
|
119
|
+
.sidebar-section-label.clickable {
|
|
132
120
|
cursor: pointer;
|
|
121
|
+
user-select: none;
|
|
122
|
+
transition: color 0.15s;
|
|
133
123
|
}
|
|
134
|
-
|
|
135
|
-
|
|
124
|
+
.sidebar-section-label.clickable:hover { color: var(--panel-accent); }
|
|
125
|
+
.session-item.session-offline { opacity: 0.5; cursor: default; }
|
|
126
|
+
.session-item .meta { margin-left: auto; }
|
|
136
127
|
.new-session-sidebar-btn {
|
|
137
128
|
display: flex; align-items: center; gap: 8px;
|
|
138
129
|
width: 100%; padding: 10px 12px; border-radius: 10px; margin-bottom: 6px;
|
|
@@ -644,7 +635,6 @@ import{cssVarsStyle as g}from"../theme.js";import{commandbarCSS as b,commandbarH
|
|
|
644
635
|
<div class="header-actions">
|
|
645
636
|
${t?`<button class="header-btn" id="cmdbar-btn" title="Search" aria-label="Search">${i("search")}</button>`:""}
|
|
646
637
|
</div>
|
|
647
|
-
<select id="tw-scope-native" title="Switch machine"><option value="">\u672C\u673A</option></select>
|
|
648
638
|
<div id="header-git" title="Click to browse repository"></div>
|
|
649
639
|
<span id="header-ram"></span>
|
|
650
640
|
</header>
|
|
@@ -815,29 +805,6 @@ ${h("__onSessionCreated")}
|
|
|
815
805
|
})();
|
|
816
806
|
</script>
|
|
817
807
|
<script>
|
|
818
|
-
(function(){
|
|
819
|
-
var sel = document.getElementById('tw-scope-native');
|
|
820
|
-
if (!sel) return;
|
|
821
|
-
function refresh(){
|
|
822
|
-
fetch('/api/agents').then(function(r){ return r.json(); }).then(function(agents){
|
|
823
|
-
var cur = window.__tmuxWebScopeAgent || null;
|
|
824
|
-
var opts = '<option value="/">\u672C\u673A</option>';
|
|
825
|
-
(agents || []).forEach(function(a){
|
|
826
|
-
if (!a.online) return;
|
|
827
|
-
var selAttr = a.agentId === cur ? ' selected' : '';
|
|
828
|
-
opts += '<option value="/a/' + encodeURIComponent(a.agentId) + '/"' + selAttr + '>' + a.name + '</option>';
|
|
829
|
-
});
|
|
830
|
-
sel.innerHTML = opts;
|
|
831
|
-
}).catch(function(){});
|
|
832
|
-
}
|
|
833
|
-
refresh();
|
|
834
|
-
setInterval(refresh, 15000);
|
|
835
|
-
sel.addEventListener('change', function(){
|
|
836
|
-
if (sel.value) window.location.href = sel.value;
|
|
837
|
-
});
|
|
838
|
-
})();
|
|
839
|
-
</script>
|
|
840
|
-
<script>
|
|
841
808
|
(function(){
|
|
842
809
|
/* Logo toggle sidebar */
|
|
843
810
|
var brand = document.getElementById('brand-toggle');
|
|
@@ -874,4 +841,4 @@ if ('serviceWorker' in navigator) {
|
|
|
874
841
|
}
|
|
875
842
|
</script>
|
|
876
843
|
</body>
|
|
877
|
-
</html>`}export{
|
|
844
|
+
</html>`}export{T as renderShell};
|
package/dist/lib/scope-script.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function n(e){const i=e.prefix,t=e.agentId??"";return`<script>
|
|
2
2
|
window.__TMUX_WEB_SCOPE__ = { prefix: ${JSON.stringify(i)}, agentId: ${JSON.stringify(t)} };
|
|
3
3
|
(function(){
|
|
4
4
|
var prefix = window.__TMUX_WEB_SCOPE__.prefix || '';
|
|
@@ -37,35 +37,4 @@ window.__TMUX_WEB_SCOPE__ = { prefix: ${JSON.stringify(i)}, agentId: ${JSON.stri
|
|
|
37
37
|
if (action && isRel(action) && action.indexOf(prefix) !== 0) f.setAttribute('action', pref(action));
|
|
38
38
|
}, true);
|
|
39
39
|
})();
|
|
40
|
-
</script>
|
|
41
|
-
<script>
|
|
42
|
-
(function(){
|
|
43
|
-
if (document.getElementById('tw-scope-native')) return; // shell has a native switcher
|
|
44
|
-
if (document.getElementById('tw-scope-chip')) return;
|
|
45
|
-
var prefix = window.__TMUX_WEB_SCOPE__ ? window.__TMUX_WEB_SCOPE__.prefix : '';
|
|
46
|
-
var agentId = window.__TMUX_WEB_SCOPE__ ? window.__TMUX_WEB_SCOPE__.agentId : null;
|
|
47
|
-
var style = 'position:fixed;bottom:12px;right:12px;z-index:9990;display:flex;align-items:center;gap:6px;';
|
|
48
|
-
style += 'background:rgba(20,20,24,0.92);color:#e6e6e6;border:1px solid rgba(255,255,255,0.12);border-radius:20px;';
|
|
49
|
-
style += 'padding:6px 12px;font-size:12px;font-family:system-ui,sans-serif;box-shadow:0 4px 16px rgba(0,0,0,0.3);';
|
|
50
|
-
var chip = document.createElement('div');
|
|
51
|
-
chip.id = 'tw-scope-chip';
|
|
52
|
-
chip.style.cssText = style;
|
|
53
|
-
chip.innerHTML = '<span>Machine</span><select id="tw-scope-select" style="background:#2a2a31;color:#e6e6e6;border:1px solid rgba(255,255,255,0.15);border-radius:8px;padding:3px 8px;font-size:12px;max-width:180px"></select>';
|
|
54
|
-
document.body.appendChild(chip);
|
|
55
|
-
var sel = document.getElementById('tw-scope-select');
|
|
56
|
-
sel.innerHTML = '<option value="">Loading\u2026</option>';
|
|
57
|
-
var origFetch = window.fetch;
|
|
58
|
-
origFetch(location.origin + '/api/agents').then(function(r){ return r.json(); }).then(function(agents){
|
|
59
|
-
var opts = '<option value="/" ' + (agentId ? '' : 'selected') + '>\u672C\u673A</option>';
|
|
60
|
-
(agents || []).forEach(function(a){
|
|
61
|
-
if (!a.online) return;
|
|
62
|
-
var isCur = a.agentId === agentId;
|
|
63
|
-
opts += '<option value="/a/' + encodeURIComponent(a.agentId) + '/" ' + (isCur ? 'selected' : '') + '>' + (isCur ? '\u2022 ' : '') + a.name + '</option>';
|
|
64
|
-
});
|
|
65
|
-
sel.innerHTML = opts;
|
|
66
|
-
}).catch(function(){ sel.innerHTML = '<option value="">offline</option>'; });
|
|
67
|
-
sel.addEventListener('change', function(){
|
|
68
|
-
if (sel.value) window.location.href = sel.value;
|
|
69
|
-
});
|
|
70
|
-
})();
|
|
71
|
-
</script>`}function o(e,i){if(e.includes("window.__TMUX_WEB_SCOPE__"))return e;const t=r(i),n=e.indexOf("</head>");return n===-1?e+t:e.slice(0,n)+t+e.slice(n)}export{o as injectScopeScript,r as scopeScriptHtml};
|
|
40
|
+
</script>`}function f(e,i){if(e.includes("window.__TMUX_WEB_SCOPE__"))return e;const t=n(i),r=e.indexOf("</head>");return r===-1?e+t:e.slice(0,r)+t+e.slice(r)}export{f as injectScopeScript,n as scopeScriptHtml};
|