tmux-weblink 2.2.36 → 2.2.37
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 +17 -17
- package/dist/browser/shell-client.js +13 -13
- package/dist/lib/pages/shell.js +54 -24
- package/package.json +1 -1
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)}selectRows(t,n){let s=this.terminal.buffer.active,[a,r]=t<=n?[t,n]:[n,t];this.terminal.selectLines(s.viewportY+a,s.viewportY+r)}selectCells(t,n,s,a){let r=this.terminal.buffer.active,c=Math.min(n,a),o=Math.max(n,a);if(c===o){let u=Math.min(t,s),p=Math.max(t,s);this.terminal.select(u,r.viewportY+c,p-u+1)}else this.terminal.selectLines(r.viewportY+c,r.viewportY+o)}getCellsText(t,n,s,a){let r=this.terminal.buffer.active,c=Math.min(n,a),o=Math.max(n,a),u=n<a?t:n>a?s:Math.min(t,s),p=n<a?s:n>a?t:Math.max(t,s),E=r.viewportY,x=[];for(let A=c;A<=o;A++){let
|
|
3
|
-
`)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function
|
|
1
|
+
var kn=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function st(e){return e.replace(/\x1b\[\?1049[hl]/g,"")}function me(e){return e.replace(kn,"")}var He;function Sn(){return He||(document.querySelector("link[data-tmux-web-xterm-css]")?He=Promise.resolve():(He=new Promise(e=>{let t=document.createElement("link");t.rel="stylesheet",t.href="/assets/xterm.css",t.setAttribute("data-tmux-web-xterm-css",""),t.addEventListener("load",()=>e(),{once:!0}),t.addEventListener("error",()=>e(),{once:!0}),document.head.appendChild(t)}),He))}var Tn=class Gt{terminal;fitAddon;container;webglActive=!1;repaintTimer=0;webglAddon=null;constructor(t,n,s){this.container=t,this.terminal=n,this.fitAddon=s,this.terminal.loadAddon(this.fitAddon),this.terminal.open(t),this.enableWebglRenderer(),document.addEventListener("visibilitychange",()=>{document.hidden||this.refreshPaintedRows()})}enableWebglRenderer(){if(Bn()==="webgl"){try{if(!document.createElement("canvas").getContext("webgl2",{failIfMajorPerformanceCaveat:!0}))return}catch{return}import("./addon-webgl-B45EJ6AW.js").then(({WebglAddon:t})=>{let n=new t;n.onContextLoss(()=>{this.webglActive=!1,this.webglAddon=null;try{n.dispose()}catch{}this.fit()});try{this.terminal.loadAddon(n)}catch{return}this.webglAddon=n,this.webglActive=!0,this.fit()}).catch(()=>{})}}refreshPaintedRows(){if(this.webglActive){try{this.webglAddon?.clearTextureAtlas?.()}catch{}try{this.terminal.refresh(0,Math.max(0,this.terminal.rows-1))}catch{}}}static async create(t,n,s){let[{Terminal:a},{FitAddon:r}]=await Promise.all([import("./xterm-BXEES47M.js"),import("./addon-fit-D5N335P2.js"),Sn()]),c="'JetBrains Mono', 'SF Mono', 'Menlo', monospace",o=new a({fontSize:In(14,c),fontFamily:c,cursorBlink:!0,cursorStyle:"bar",scrollback:n,convertEol:!1,smoothScrollDuration:120,theme:s});return new Gt(t,o,new r)}get cols(){return this.terminal.cols}get rows(){return this.terminal.rows}write(t){return new Promise(n=>this.terminal.write(t,n))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom()}scrollToLine(t,n=!1){this.terminal.scrollToLine(Math.max(0,t),n),this.scheduleRepaintCheck()}scrollLines(t){this.terminal.scrollLines(t),this.scheduleRepaintCheck()}scheduleRepaintCheck(){this.webglActive&&(this.repaintTimer&&clearTimeout(this.repaintTimer),this.repaintTimer=setTimeout(()=>{this.repaintTimer=0,this.refreshPaintedRows()},150))}isNearScrollbackTop(){return this.terminal.buffer.active.viewportY<=1}viewportY(){return this.terminal.buffer.active.viewportY}baseY(){return this.terminal.buffer.active.baseY}cellHeight(){let t=this.terminal.element?.querySelector(".xterm-screen")?.getBoundingClientRect().height??0,n=this.terminal.rows;return t>0&&n>0?t/n:16}fit(){let t=Mn(this.container);if(t.width<=0||t.height<=0)return!1;let n=this.terminal.cols,s=this.terminal.rows,a=this.paintedCellWidth();a<=0&&(this.fitAddon.fit(),a=this.paintedCellWidth());let r=this.fitAddon.proposeDimensions?.();if(!r)return this.fitAddon.fit(),!0;let c=this.overlayScrollbarWidth(),o=c>0?c+2:0,u=a>0?Math.max(10,Math.min(r.cols,Math.floor((t.width-o)/a))):r.cols,p=r.rows;return(u!==this.terminal.cols||p!==this.terminal.rows)&&this.terminal.resize(u,p),this.webglActive&&(n!==this.terminal.cols||s!==this.terminal.rows)&&this.refreshPaintedRows(),!0}paintedCellWidth(){let t=this.terminal.element?.querySelector(".xterm-screen")?.getBoundingClientRect().width??0,n=this.terminal.cols;return t>0&&n>0?t/n:0}overlayScrollbarWidth(){let t=this.terminal.element?.querySelector(".vertical.scrollbar");if(!t)return 0;let n=t.getBoundingClientRect();return!(n.width>0)||!(n.height>0)?0:Math.round(n.width)}focus(){this.terminal.focus()}pasteText(t){this.terminal.paste(t)}input(t){this.terminal.input(t,!1)}onData(t){this.terminal.onData(t),this.terminal.onBinary(t)}onResize(t){this.terminal.onResize(t)}onScroll(t){this.terminal.onScroll(t)}attachCustomKeyEventHandler(t){this.terminal.attachCustomKeyEventHandler(t)}isFocused(){let t=document.activeElement;return t?t===this.container||t===this.terminal.textarea||this.container.contains(t)||!!t.closest?.(".xterm"):!1}getScreenText(){return this.getRowsText(0,this.terminal.rows-1)}getRowsText(t,n){let s=this.terminal.buffer.active,[a,r]=t<=n?[t,n]:[n,t],c=s.viewportY,o=[];for(let u=a;u<=r;u++){let p=s.getLine(c+u);o.push(p?p.translateToString(!0):"")}return o.join(`
|
|
2
|
+
`)}selectRows(t,n){let s=this.terminal.buffer.active,[a,r]=t<=n?[t,n]:[n,t];this.terminal.selectLines(s.viewportY+a,s.viewportY+r)}selectCells(t,n,s,a){let r=this.terminal.buffer.active,c=Math.min(n,a),o=Math.max(n,a);if(c===o){let u=Math.min(t,s),p=Math.max(t,s);this.terminal.select(u,r.viewportY+c,p-u+1)}else this.terminal.selectLines(r.viewportY+c,r.viewportY+o)}getCellsText(t,n,s,a){let r=this.terminal.buffer.active,c=Math.min(n,a),o=Math.max(n,a),u=n<a?t:n>a?s:Math.min(t,s),p=n<a?s:n>a?t:Math.max(t,s),E=r.viewportY,x=[];for(let A=c;A<=o;A++){let B=r.getLine(E+A);if(!B){x.push("");continue}let b=A===c?u:0,O=A===o?p:this.terminal.cols-1,ae="";for(let ke=b;ke<=O;ke++){let K=B.getCell(ke);K&&(ae+=K.getChars())}x.push(ae.replace(/\s+$/,""))}return x.join(`
|
|
3
|
+
`)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function In(e,t){try{let n=document.createElement("canvas").getContext("2d");if(!n)return e;let s=100;n.font=`${s}px ${t}`;let a=n.measureText("M").width/s;if(!Number.isFinite(a)||a<=0)return e;let r=window.devicePixelRatio||1,c=e,o=Number.POSITIVE_INFINITY;for(let u=4;u<=40;u++){let p=u/(a*r);if(p<e-1.5||p>e+1.5)continue;let E=Math.abs(p-e);E<o&&(o=E,c=p)}return Math.round(c*100)/100}catch{return e}}function Bn(){try{let e=new URLSearchParams(window.location.search).get("renderer");return e==="dom"||e==="webgl"?e:null}catch{return null}}function Mn(e){let t=e.getBoundingClientRect(),n=window.visualViewport;return n?{width:Math.min(t.width,n.width),height:Math.max(0,Math.min(t.height,n.height-Math.max(0,t.top)))}:t}function Dn(e,t,n){return e.innerHTML="",e.classList.add("terminal-pending"),(async()=>{let s=await Tn.create(e,n.scrollback,n.theme),a,r=0,c,o=null,u=0,p=0,E=.2,x=10,A=.95,B=.04,b=null,O=null;function ae(i){b||(b=document.createElement("div"),b.style.cssText=["position:absolute","left:0","width:40%","padding:10px 0","text-align:center","font:600 14px/1.4 system-ui, -apple-system, sans-serif","color:rgba(255,255,255,0.95)","background:rgba(20,30,50,0.55)","border:1px solid rgba(255,255,255,0.25)","border-radius:10px","pointer-events:none","opacity:0","transition:opacity 0.15s ease","z-index:6"].join(";"),e.appendChild(b)),b.textContent=i?"\u2191 \u4E0A\u7FFB\u4E00\u9875 (PgUp)":"\u2193 \u4E0B\u7FFB\u4E00\u9875 (PgDn)",b.style.top=i?"10%":"auto",b.style.bottom=i?"auto":"10%",b.style.opacity="1",O&&clearTimeout(O),O=setTimeout(()=>{b&&(b.style.opacity="0")},900)}function ke(){O&&clearTimeout(O),b&&(b.style.opacity="0")}function K(){u&&(cancelAnimationFrame(u),u=0),p=0}function Qt(i){if(K(),Math.abs(i)<E)return;p=Math.max(-x,Math.min(x,i));let l=()=>{if(W){u=0;return}let d=s.cellHeight(),m=d>0?Math.round(p*16/d):p>0?1:-1;m===0&&(m=p>0?1:-1);let v=s.viewportY()-m,P=s.baseY(),_=Math.max(0,Math.min(v,P));if(s.scrollToLine(_,!0),p*=A,_!==v){u=0;return}if(Math.abs(p)<B){u=0;return}u=requestAnimationFrame(l)};u=requestAnimationFrame(l)}let Se=0,$="connecting",Te=0,oe=!1,Ie=[],Q="",W=!1,le=1e3,en=location.protocol==="https:"?"wss:":"ws:",mt=n.wsBase||"/ws",tn=en+"//"+location.host+mt+"/"+encodeURIComponent(t),nn=(mt.replace(/^\/ws/,"")||"")+"/api/session/"+encodeURIComponent(t)+"/upload",sn=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function an(){return Ie.join("")+Q}async function on(i,l=0){let d=i?s.viewportY():0,m=me(an());if(s.reset(),!m){i||s.scrollToBottom();return}await s.write(m),i?s.scrollToLine(l+d):s.scrollToBottom()}function V(i){a?.readyState===WebSocket.OPEN&&a.send(JSON.stringify(i))}function ln(i){let l;try{l=JSON.parse(i)}catch{$==="live"&&(Q+=i,s.write(me(i)));return}if(l.type==="auth.required"){let d=localStorage.getItem("tmux-web-token");d?V({type:"auth.token",token:d}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(l.type==="attach_failed"&&typeof l.message=="string"){Be=!0,$="dead",s.reset(),s.write(`\r
|
|
4
4
|
\x1B[31m`+me(l.message)+`\x1B[0m\r
|
|
5
|
-
`).then(()=>{
|
|
5
|
+
`).then(()=>{Me();try{a?.close()}catch{}});return}if(l.type==="auth.ok"){l.token&&localStorage.setItem("tmux-web-token",l.token),le=1e3,X(),V({type:"resize",cols:s.cols,rows:s.rows}),I();return}if(l.type==="auth.failed"){if(l.permanentLock||l.retryAfterMs&&l.retryAfterMs>6e4){localStorage.removeItem("tmux-web-token"),location.href="/login?error="+encodeURIComponent(l.message);return}return}if(l.type==="snapshot"&&typeof l.data=="string"){let d=st(me(l.data));Ie=[d],Q="",Te=typeof l.lines=="number"?l.lines:n.terminal.initialLines,$="live",s.reset(),X(),V({type:"resize",cols:s.cols,rows:s.rows}),s.write(d).then(()=>s.scrollToBottom());return}if(l.type==="window_changed"&&typeof l.activeIndex=="number"){let d=new URL(location.href);d.searchParams.get("window")!==String(l.activeIndex)&&(d.searchParams.set("window",String(l.activeIndex)),history.replaceState(history.state,"",d)),window.dispatchEvent(new CustomEvent("tmux:windows",{detail:l.windows}));return}if(l.type==="history"&&typeof l.data=="string"){l.lines>0&&l.data?(Ie.unshift(st(l.data)),Te+=l.lines,on(!0,l.lines).finally(()=>{oe=!1})):oe=!1;return}if(l.type==="data"&&typeof l.data=="string"){let d=st(me(l.data));if($==="connecting"){$="live",Q=d,s.write(d);return}$==="live"&&(Q+=d,s.write(d))}}let Be=!1;function ft(){if(Be)return;let i=tn,l=localStorage.getItem("tmux-web-token");l&&(i+=(i.includes("?")?"&":"?")+"token="+encodeURIComponent(l)),i+=(i.includes("?")?"&":"?")+"cols="+s.cols+"&rows="+s.rows,a=new WebSocket(i),a.onopen=()=>{$="connecting",Te=0,oe=!1,Ie=[],Q="",s.reset(),le=1e3},a.onmessage=d=>{typeof d.data=="string"&&ln(d.data)},a.onclose=()=>{W||($="connecting",!Be&&setTimeout(()=>{le=Math.min(le*2,1e4),!W&&!Be&&ft()},le))},a.onerror=()=>a?.close()}function ee(i){V({type:"input",data:i})}function X(){return s.fit()}function Me(){e.classList.remove("terminal-pending")}function I(){r&&cancelAnimationFrame(r),c&&clearTimeout(c),X(),r=requestAnimationFrame(()=>{r=0,X()&&Me()}),c=setTimeout(()=>{X()&&Me()},120)}function rn(){I(),setTimeout(I,50),setTimeout(I,150),setTimeout(I,300)}function ht(i){return typeof i=="string"&&i.startsWith("image/")}function gt(i){return i?.files?.length?i.files[0]??null:null}function cn(i){if(!i?.items)return null;for(let l=0;l<i.items.length;l++){let d=i.items[l];if(d?.kind==="file"&&ht(d.type))return d.getAsFile()}return null}async function dn(i){let l=new FormData,d=i instanceof File&&i.name?i.name:"upload";l.append("file",i,d);let m=localStorage.getItem("tmux-web-token"),v={};m&&(v.Authorization="Bearer "+m);let P=await fetch(nn,{method:"POST",body:l,headers:v});if(!P.ok){let xt="upload failed";try{let Ct=await P.json();Ct.error&&(xt=Ct.error)}catch{}throw new Error(xt)}let _=await P.json();if(!_.path)throw new Error("no path in response");return _.path}async function et(i){try{let l=await dn(i);ee(l)}catch{}}s.onData(i=>ee(i)),s.onResize(({cols:i,rows:l})=>V({type:"resize",cols:i,rows:l})),s.onScroll(()=>{$!=="live"||oe||!s.isNearScrollbackTop()||(oe=!0,V({type:"load_history",before:Te}))});let re=!1,ce=!1,L=null,C=null,de=document.createElement("div");de.className="terminal-copy-banner",de.innerHTML='<strong>Copy mode</strong><span class="hint">drag to copy \xB7 Esc exits</span>',de.hidden=!0,e.appendChild(de);let z=document.createElement("div");z.className="terminal-copy-banner terminal-copy-toast",z.textContent="Copied",z.hidden=!0,e.appendChild(z);function vt(i,l){let d=e.querySelector(".xterm-screen, canvas"),m=(d&&d.getBoundingClientRect().width>0?d:e).getBoundingClientRect(),v=m.height>0&&s.rows>0?m.height/s.rows:18,P=m.width>0&&s.cols>0?m.width/s.cols:9;return{row:Math.max(0,Math.min(s.rows-1,Math.floor((l-m.top)/v))),col:Math.max(0,Math.min(s.cols-1,Math.floor((i-m.left)/P)))}}async function De(i){if(!i)return;try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(i);return}}catch{}let l=document.createElement("textarea");l.value=i,l.style.position="fixed",l.style.opacity="0",l.style.pointerEvents="none",document.body.appendChild(l),l.focus(),l.select();try{document.execCommand("copy")}catch{}l.remove()}let ue;function Ae(){z.hidden=!1,ue&&clearTimeout(ue),ue=setTimeout(()=>{z.hidden=!0},1e3)}function te(i){re=i,de.hidden=!i,e.classList.toggle("terminal-copy-mode-active",i),i&&s.focus()}function yt(){te(!re)}function un(i){W||i.button!==0||ce||(re||i.shiftKey)&&(i.preventDefault(),i.stopPropagation(),ce=!0,L=vt(i.clientX,i.clientY),C=L,s.selectCells(L.col,L.row,C.col,C.row),document.addEventListener("mousemove",tt,!0),document.addEventListener("mouseup",nt,!0))}function tt(i){W||!ce||!L||(i.preventDefault(),i.stopPropagation(),C=vt(i.clientX,i.clientY),s.selectCells(L.col,L.row,C.col,C.row))}function nt(i){if(W||!ce||!L||!C)return;i.preventDefault(),i.stopPropagation(),document.removeEventListener("mousemove",tt,!0),document.removeEventListener("mouseup",nt,!0),ce=!1;let l=s.getCellsText(L.col,L.row,C.col,C.row);L=null,C=null,s.clearSelection(),te(!1),l&&(z.textContent="\u5DF2\u590D\u5236",De(l).then(Ae)),s.focus()}e.addEventListener("mousedown",un,!0),document.addEventListener("keydown",pn,!0);function pn(i){if(!(W||!s.isFocused()||i.defaultPrevented||i.isComposing)){if(re){if(i.key==="Escape"){i.preventDefault(),i.stopPropagation(),L=null,C=null,s.clearSelection(),te(!1);return}if(i.key==="Enter"||(i.ctrlKey||i.metaKey)&&i.code==="KeyC"){i.preventDefault(),i.stopPropagation(),De(s.getScreenText()).then(Ae),te(!1);return}}if(i.altKey&&i.code==="KeyC"&&!i.ctrlKey&&!i.metaKey){if(i.preventDefault(),i.stopPropagation(),L&&C){let l=s.getCellsText(L.col,L.row,C.col,C.row);L=null,C=null,s.clearSelection(),te(!1),l&&(z.textContent="Copied",De(l).then(Ae))}else{let l=s.getSelection();l?(s.clearSelection(),z.textContent="Copied",De(l).then(Ae)):yt()}return}if((i.ctrlKey||i.metaKey)&&i.code==="KeyV"){i.preventDefault(),i.stopPropagation(),(async()=>{try{if(navigator.clipboard?.read){let l=await navigator.clipboard.read();for(let d of l)for(let m of d.types)if(ht(m)){let v=await d.getType(m);await et(v);return}}}catch{}try{let l=await navigator.clipboard?.readText();l&&s.pasteText(wt(l))}catch{}})();return}}}let Fe=0;function wt(i){return i.split(`\r
|
|
6
6
|
`).join(`
|
|
7
7
|
`).split(`
|
|
8
|
-
`).join("\r")}async function
|
|
8
|
+
`).join("\r")}async function mn(i){let l=cn(i.clipboardData);if(l){i.preventDefault(),i.stopPropagation();let v=Date.now();if(v-Fe<50)return;Fe=v,await et(l);return}let d=i.clipboardData?.getData("text/plain");if(!d)return;i.preventDefault(),i.stopPropagation();let m=Date.now();m-Fe<50||(Fe=m,s.pasteText(wt(d)))}let pe=0;function fn(i){i.preventDefault(),pe++,gt(i.dataTransfer)&&e.classList.add("terminal-drag-over")}function hn(i){i.preventDefault(),i.dataTransfer&&(i.dataTransfer.dropEffect="copy")}function gn(i){i.preventDefault(),pe--,pe<=0&&(pe=0,e.classList.remove("terminal-drag-over"))}async function vn(i){i.preventDefault(),pe=0,e.classList.remove("terminal-drag-over");let l=gt(i.dataTransfer);l&&await et(l)}function bt(i){!sn||i.key!=="Escape"||re||i.defaultPrevented||i.repeat||i.metaKey||i.ctrlKey||i.altKey||s.isFocused()&&(i.preventDefault(),i.stopPropagation(),ee("\x1B"))}e.addEventListener("paste",mn),e.addEventListener("dragenter",fn),e.addEventListener("dragover",hn),e.addEventListener("dragleave",gn),e.addEventListener("drop",vn),document.addEventListener("keydown",bt,!0);function yn(i){if(i.touches.length!==1){o=null;return}let l=i.touches[0];if(!l)return;K();let d=e.getBoundingClientRect(),m=l.clientX-d.left<d.width*.4?"tui":"history",v=l.clientY-d.top<d.height*.5;o={startX:l.clientX,startY:l.clientY,lastX:l.clientX,lastY:l.clientY,lastT:performance.now(),velocity:0,scrolling:!1,zone:m,tuiUp:v,sent:!1},i.stopPropagation()}function wn(i){if(!o||i.touches.length!==1)return;let l=i.touches[0];if(!l)return;let d=l.clientY-o.startY,m=l.clientX-o.startX;if(!o.scrolling){if(Math.abs(d)<8||Math.abs(d)<Math.abs(m))return;o.scrolling=!0,Se=Date.now()+500}i.preventDefault(),i.stopPropagation();let v=performance.now(),P=l.clientY-o.lastY;if(o.zone==="tui"){o.sent||(o.sent=!0,ee(o.tuiUp?"\x1B[5~":"\x1B[6~"),ae(o.tuiUp)),o.lastX=l.clientX,o.lastY=l.clientY,o.lastT=v;return}let _=v-o.lastT;_>0&&(o.velocity=P/_),xn(-P),o.lastX=l.clientX,o.lastY=l.clientY,o.lastT=v}function bn(i){if(!o)return;let l=o.scrolling,d=o.zone,m=o.tuiUp,v=o.velocity;if(o=null,i.stopPropagation(),d==="tui"){l||(ee(m?"\x1B[5~":"\x1B[6~"),ae(m),Se=Date.now()+500,i.preventDefault());return}if(!l){s.focus();return}Se=Date.now()+500,i.preventDefault(),v&&Qt(v)}function En(i){o=null,K(),i.stopPropagation()}function Ln(i){i.pointerType==="touch"&&Date.now()<Se&&(i.preventDefault(),i.stopPropagation())}function xn(i){let l=s.cellHeight(),d=l>0?Math.round(i/l):i>0?1:-1;d===0&&(d=i>0?1:-1),s.scrollLines(d)}e.addEventListener("touchstart",yn,{passive:!0,capture:!0}),e.addEventListener("touchmove",wn,{passive:!1,capture:!0}),e.addEventListener("touchend",bn,{passive:!1,capture:!0}),e.addEventListener("touchcancel",En,{passive:!0,capture:!0}),e.addEventListener("pointerup",Ln,!0);function Et(){I()}window.addEventListener("resize",Et),window.visualViewport?.addEventListener("resize",I),window.visualViewport?.addEventListener("scroll",I);let Lt=new ResizeObserver(()=>I());Lt.observe(e),document.fonts?.ready.then(()=>{I(),setTimeout(I,50),setTimeout(I,200)}),e.addEventListener("focusin",rn,!0);async function Cn(){if(document.fonts?.ready)try{await Promise.race([document.fonts.ready,new Promise(i=>setTimeout(i,1e3))])}catch{}}return requestAnimationFrame(()=>{X()&&Me(),(async()=>(await Cn(),X()&&V({type:"resize",cols:s.cols,rows:s.rows}),ft(),I()))()}),{destroy(){if(W=!0,K(),te(!1),ue&&clearTimeout(ue),document.removeEventListener("mousemove",tt,!0),document.removeEventListener("mouseup",nt,!0),a){try{a.close(1e3,"session switch")}catch{}a=void 0}e.innerHTML="",e.classList.remove("terminal-pending"),window.removeEventListener("resize",Et),Lt.disconnect(),document.removeEventListener("keydown",bt,!0)},focus(){s.focus()},sendInput(i){ee(i)},toggleCopyMode(){yt()}}})()}var fe=window.__TMUX_WEB_SHELL__,g=null,y=null,he=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null,k=he;window.__tmuxWebScopeAgent=he;var it="sessions",Y="",Re="",Pe="",kt="";function S(e){return k?"/a/"+encodeURIComponent(k)+e:e}var f=document.getElementById("sidebar-content"),J=document.getElementById("main-placeholder"),M=document.getElementById("terminal-container"),ge=document.getElementById("file-editor"),An=document.getElementById("fe-path"),F=document.getElementById("fe-status"),ve=document.getElementById("fe-content"),Z=document.getElementById("fe-save"),Fn=document.getElementById("fe-delete"),Hn=document.getElementById("fe-back"),St=document.getElementById("fe-new-name"),Rn=document.getElementById("fe-new-btn"),at=document.getElementById("settings-backdrop"),Tt=document.getElementById("settings-popover"),It=document.querySelector(".sidebar"),Bt="tmux-web-force-narrow";function Ne(){try{return localStorage.getItem(Bt)==="1"}catch{return!1}}function Mt(){document.documentElement.classList.toggle("force-narrow",Ne()),Ne()&&Dt()&&$e()}function Dt(){return Ne()?!0:window.matchMedia("(max-width: 640px)").matches}function $e(){Dt()&&It.classList.add("collapsed")}function At(){It.classList.remove("collapsed")}document.getElementById("mode-sessions").addEventListener("click",()=>{At(),Ft("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{At(),Ft("files")});function Ft(e){it=e,document.querySelectorAll(".mode-btn").forEach(n=>n.classList.remove("active"));let t=document.getElementById(e==="sessions"?"mode-sessions":"mode-files");t&&t.classList.add("active"),e==="sessions"?(ot="",j()):Xn()}var ot="";async function j(){if(it!=="sessions")return;try{let t=await(await fetch("/api/sidebar/sessions")).json(),n=JSON.stringify({recent:t.recent,agents:t.agents,tombstones:t.tombstones});if(n===ot)return;ot=n,jn(t)}catch{f.innerHTML+='<div class="file-tree-empty">Failed to load sessions</div>'}let e=document.getElementById("ns-btn");e&&e.addEventListener("click",()=>{let t=window.__openNewSessionModal;typeof t=="function"?t():document.getElementById("new-session-modal")?.classList.add("open")}),pt()}var Ht="tmux-web-sidebar-group-collapsed";function Rt(){try{return new Set(JSON.parse(localStorage.getItem(Ht)||"[]"))}catch{return new Set}}function Pn(e){try{localStorage.setItem(Ht,JSON.stringify([...e]))}catch{}}function Nn(e,t,n){if(!e)return"\u2026";let s=n&&(e===n||e.startsWith(n+"/"))?"~"+e.slice(n.length):e,a=s.split("/").filter(Boolean);if(a.length===0)return e;for(let r=1;r<=a.length;r++){let c=a.slice(-r).join("/");if(!t.some(o=>!o||o===e?!1:(n&&(o===n||o.startsWith(n+"/"))?"~"+o.slice(n.length):o).split("/").filter(Boolean).slice(-r).join("/")===c))return c}return s}function Pt(e,t,n,s=!0){let a=new Map;for(let o of e){let u=o.path||"";a.has(u)||a.set(u,[]),a.get(u).push(o)}let r=[...a.keys()],c=Rt();for(let[o,u]of a){let p=Nn(o,r,t),E=c.has(o),x=document.createElement("div");x.className="session-group-header"+(E?" collapsed":""),x.title=o||"No working directory",x.innerHTML=`<span class="sg-folder">📁</span><span class="sg-label">${h(p)}</span>`,x.addEventListener("click",()=>{let B=Rt(),b=x.nextElementSibling;B.has(o)?(B.delete(o),x.classList.remove("collapsed"),b?.classList.remove("collapsed")):(B.add(o),x.classList.add("collapsed"),b?.classList.add("collapsed")),Pn(B)});let A=document.createElement("div");A.className="session-group-body"+(E?" collapsed":"");for(let B of u)A.appendChild(n?$n(B,n,s):zn(B));f.appendChild(x),f.appendChild(A)}}function $n(e,t,n){let s=document.createElement("div");s.className="session-item"+(e.name===y&&k===t?" active":"")+(n?"":" session-offline"),s.setAttribute("data-session",e.name),s.setAttribute("data-agent",t),s.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${e.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>
|
|
9
9
|
<span>${h(e.name)}</span>${n?"":'<span class="meta">offline</span>'}
|
|
10
|
-
<button class="session-edit-btn" data-session="${h(e.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>`,n&&s.addEventListener("click",r=>{r.target.closest(".session-edit-btn")||ye(e.name,t)});let a=s.querySelector(".session-edit-btn");return a&&a.addEventListener("click",r=>{r.stopPropagation(),
|
|
10
|
+
<button class="session-edit-btn" data-session="${h(e.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>`,n&&s.addEventListener("click",r=>{r.target.closest(".session-edit-btn")||ye(e.name,t)});let a=s.querySelector(".session-edit-btn");return a&&a.addEventListener("click",r=>{r.stopPropagation(),Ve(e.name,a,{agentId:t})}),s}function zn(e){let t=document.createElement("div");t.className="session-item"+(e.name===y&&!k?" active":""),t.setAttribute("data-session",e.name),t.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${e.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>
|
|
11
11
|
<span>${h(e.name)}</span>
|
|
12
12
|
<button class="session-edit-btn" data-session="${h(e.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>
|
|
13
|
-
`,t.addEventListener("click",s=>{s.target.closest(".session-edit-btn")||ye(e.name)});let n=t.querySelector(".session-edit-btn");return n&&n.addEventListener("click",s=>{s.stopPropagation(),
|
|
13
|
+
`,t.addEventListener("click",s=>{s.target.closest(".session-edit-btn")||ye(e.name)});let n=t.querySelector(".session-edit-btn");return n&&n.addEventListener("click",s=>{s.stopPropagation(),Ve(e.name,n)}),t}function jn(e){f.innerHTML='<button class="new-session-sidebar-btn" id="ns-btn">+ New Session</button>';let t=e.recent||[],n=document.createElement("div");n.className="sidebar-section-label"+(he?" clickable":""),n.textContent=he?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",he&&(n.title="Back to hub",n.addEventListener("click",()=>{window.location.href="/"})),f.appendChild(n),Pt(t,e.home);let s=e.agents||[];for(let r of s){if(!r.sessions||r.sessions.length===0)continue;let c=r.agentId===k,o=document.createElement("div");o.className="sidebar-section-label machine-label"+(r.online?"":" agent-offline-label")+(!c&&r.online?" clickable":""),o.textContent=r.agentName+(r.online?"":" (offline)"),!c&&r.online&&(o.title="\u6253\u5F00 "+r.agentName,o.addEventListener("click",()=>{window.location.href="/a/"+encodeURIComponent(r.agentId)+"/"})),f.appendChild(o),Pt(r.sessions,e.home,r.agentId,r.online)}let a=e.tombstones||[];if(a.length>0){let r=document.createElement("div");r.className="sidebar-section-label tombstone-label",r.textContent="\u5931\u6548\u4F1A\u8BDD",f.appendChild(r);for(let c of a){let o=document.createElement("div");o.className="session-item session-tombstone",o.setAttribute("data-session",c.name),c.agentId&&o.setAttribute("data-agent",c.agentId);let u=c.agentId?c.agentOnline?" (agent)":" (agent \u79BB\u7EBF)":"";o.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"></svg>
|
|
14
14
|
<span>${h(c.name)}</span><span class="meta">\u5931\u6548${u}</span>
|
|
15
|
-
<button class="session-edit-btn" data-session="${h(c.name)}" title="\u6062\u590D\u4F1A\u8BDD"><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>`,o.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",o.addEventListener("click",()=>{
|
|
15
|
+
<button class="session-edit-btn" data-session="${h(c.name)}" title="\u6062\u590D\u4F1A\u8BDD"><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>`,o.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",o.addEventListener("click",()=>{Ve(c.name,o,{tombstone:!0,agentId:c.agentId})});let p=o.querySelector(".session-edit-btn");p&&p.addEventListener("click",E=>{E.stopPropagation(),Ve(c.name,p,{tombstone:!0,agentId:c.agentId})}),f.appendChild(o)}}}function h(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function ye(e,t){if(y===e&&g&&k===(t||null))return;ge.style.display="none",J.style.display="none",M.style.display="",M.classList.add("terminal-pending"),$e(),g&&(Oe(),g.destroy(),g=null),y=e,k=t||null,window.__tmuxWebScopeAgent=k,window.__tmuxWebCurrentSession=y,us(e,t);let n=ut(e,t);Jt.set(n,Date.now()+cs);let s=ie.get(n);if(s&&s.state==="working"){s.state="idle",s.doneUntil=void 0,s.unread=!1;let a=f.querySelector(t?'.session-item[data-agent="'+CSS.escape(t)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])');a&&Qe(a,n,s)}for(let a of f.querySelectorAll(".session-item"))a.classList.toggle("active",a.getAttribute("data-session")===e&&(a.getAttribute("data-agent")||null)===k);try{g=await Dn(M,e,{terminal:fe.terminal,scrollback:fe.scrollback,theme:fe.theme,wsBase:k?"/ws/a/"+encodeURIComponent(k):fe.wsBase||"/ws"}),Ot()}catch(a){console.error("[shell] terminal init failed:",a);let r=a&&typeof a=="object"&&"message"in a?a.message:String(a);M.textContent="Failed to open terminal for "+e+": "+r,M.classList.remove("terminal-pending")}}var ze=[],w=null,Nt=!1;function Un(e){if(!w||!w.files.length)return null;let t=w.repoRoot;if(!t||!e.startsWith(t))return null;let n=e.slice(t.length+1);for(let s of w.files)if(s.path===n)return s.status;return null}async function Wn(e){Nt=!0;try{let t=await fetch(S("/api/git/status?path="+encodeURIComponent(e)));t.ok?w=await t.json():w=null}catch{w=null}finally{Nt=!1}}function _n(){if(!w||!w.branch)return"";let{branch:e,linesAdded:t,linesRemoved:n}=w,s=`<div class="sidebar-git"><div class="git-branch-badge">
|
|
16
16
|
<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>
|
|
17
|
-
${h(e)}</div>`;return(t>0||n>0)&&(s+=`<div class="git-diff-stats">+<span class="add">${t}</span> <span class="del">-${n}</span></div>`),s+"</div>"}f.addEventListener("click",e=>{e.target.closest(".sidebar-git")&&ne&&w&&(e.stopPropagation()
|
|
17
|
+
${h(e)}</div>`;return(t>0||n>0)&&(s+=`<div class="git-diff-stats">+<span class="add">${t}</span> <span class="del">-${n}</span></div>`),s+"</div>"}f.addEventListener("click",e=>{e.target.closest(".sidebar-git")&&ne&&w&&(e.stopPropagation(),Wt())});var we=document.getElementById("header-git"),$t=document.getElementById("git-diff-view"),zt=document.getElementById("gd-path"),je=document.getElementById("gd-status"),Ue=document.getElementById("gd-content"),Yn=document.getElementById("gd-back"),ne=null;function be(e){if(!e||!e.branch){we.style.display="none",ne=null;return}ne=e.repoRoot;let{branch:t,linesAdded:n,linesRemoved:s}=e,a=`<span class="branch">${h(t)}</span>`;(n>0||s>0)&&(a+=`<span class="sep">\xB7</span>+<span class="diff-add">${n}</span> <span class="diff-del">-${s}</span>`),we.innerHTML=a,we.style.display="block"}we.addEventListener("click",e=>{ne&&w&&(e.stopPropagation(),Wt())});var T=document.getElementById("git-popover"),We=document.getElementById("git-popover-backdrop");function lt(){let e=we.getBoundingClientRect();T.style.top=e.bottom+4+"px",T.style.left=Math.max(8,Math.min(e.left,window.innerWidth-400))+"px"}function jt(){let e=ne,t=document.getElementById("git-popover-browse");t&&t.addEventListener("click",()=>{if(Ye(),e){it="files",document.querySelectorAll(".mode-btn").forEach(s=>s.classList.remove("active"));let n=document.getElementById("mode-files");n&&n.classList.add("active"),q(e)}})}var Ut="";function Wt(){if(!w)return;let e=w.files||[];if(!e.length)T.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
|
|
18
18
|
<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>`;else{let t=`<div class="git-popover-header">${e.length} file${e.length>1?"s":""} changed</div>`;for(let n=0;n<e.length;n++){let s=e[n],a=s.additions||0,r=s.deletions||0,c="";switch(s.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}t+=`<div class="git-popover-item" data-idx="${n}">
|
|
19
19
|
${c}<span class="file-path">${h(s.path)}</span>
|
|
20
20
|
<span class="file-add">${a>0?"+"+a:""}</span>
|
|
21
21
|
<span class="file-del">${r>0?"-"+r:""}</span>
|
|
22
|
-
</div>`}t+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',
|
|
22
|
+
</div>`}t+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',Ut=t,T.innerHTML=t,T.querySelectorAll(".git-popover-item").forEach(n=>{let s=parseInt(n.dataset.idx||"0",10),a=e[s];!a||a.status==="D"||(n.classList.add("clickable"),n.style.cursor="pointer",n.addEventListener("click",()=>Yt(a.path)))})}lt(),T.classList.add("open"),We.classList.add("open"),jt()}function qn(){return window.innerWidth>=1024}function _t(e,t){let n=(e+(t&&e?`
|
|
23
23
|
`:"")+t).split(`
|
|
24
|
-
`),s="",a=0,r=0;for(let c of n){let o=c;if(o.startsWith("@@")){let u=o.match(/@@\s+-(\d+)[^+]*\+(\d+)/);u&&(a=parseInt(u[1],10)-1,r=parseInt(u[2],10)-1),s+=`<div class="diff-line hunk"><span class="ln-body">${h(o)}</span></div>`;continue}if(o.startsWith("diff --git")||o.startsWith("index ")||o.startsWith("--- ")||o.startsWith("+++ ")||o.startsWith("new file")||o.startsWith("deleted file")){o.startsWith("diff --git")&&(s+=`<div class="diff-line header"><span class="ln-body">${h(o)}</span></div>`);continue}if(o.startsWith("+"))r++,s+=`<div class="diff-line add"><span class="ln-no">${r}</span><span class="ln-body">${h(o)}</span></div>`;else if(o.startsWith("-"))a++,s+=`<div class="diff-line del"><span class="ln-no">${a}</span><span class="ln-body">${h(o)}</span></div>`;else if(o.startsWith("\\"))s+=`<div class="diff-line"><span class="ln-body">${h(o)}</span></div>`;else{if(!o&&!a&&!r)continue;a++,r++,s+=`<div class="diff-line"><span class="ln-no">${a}</span><span class="ln-no" style="margin-right:12px">${r}</span><span class="ln-body">${h(o)}</span></div>`}}return{html:s,lineCount:n.length}}var
|
|
24
|
+
`),s="",a=0,r=0;for(let c of n){let o=c;if(o.startsWith("@@")){let u=o.match(/@@\s+-(\d+)[^+]*\+(\d+)/);u&&(a=parseInt(u[1],10)-1,r=parseInt(u[2],10)-1),s+=`<div class="diff-line hunk"><span class="ln-body">${h(o)}</span></div>`;continue}if(o.startsWith("diff --git")||o.startsWith("index ")||o.startsWith("--- ")||o.startsWith("+++ ")||o.startsWith("new file")||o.startsWith("deleted file")){o.startsWith("diff --git")&&(s+=`<div class="diff-line header"><span class="ln-body">${h(o)}</span></div>`);continue}if(o.startsWith("+"))r++,s+=`<div class="diff-line add"><span class="ln-no">${r}</span><span class="ln-body">${h(o)}</span></div>`;else if(o.startsWith("-"))a++,s+=`<div class="diff-line del"><span class="ln-no">${a}</span><span class="ln-body">${h(o)}</span></div>`;else if(o.startsWith("\\"))s+=`<div class="diff-line"><span class="ln-body">${h(o)}</span></div>`;else{if(!o&&!a&&!r)continue;a++,r++,s+=`<div class="diff-line"><span class="ln-no">${a}</span><span class="ln-no" style="margin-right:12px">${r}</span><span class="ln-body">${h(o)}</span></div>`}}return{html:s,lineCount:n.length}}var _e=null;async function Yt(e){let t=ne;if(t)if(Ye(),qn()){M.style.display="none",g&&(Oe(),g.destroy(),g=null,_e=y,y=null),be(null),ge.style.display="none",J.style.display="none",$t.style.display="flex",zt.textContent=e,je.textContent="Loading\u2026",Ue.innerHTML="";try{let n=await fetch(S("/api/git/diff?path="+encodeURIComponent(t)+"&file="+encodeURIComponent(e)));if(!n.ok)throw new Error(await n.text());let s=await n.json();Kn(e,s.diff,s.stagedDiff)}catch(n){let s=n instanceof Error?n.message:String(n);je.textContent="Error",Ue.innerHTML=`<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">Error: ${h(s)}</div>`}}else{T.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">${h(e)}</span>
|
|
27
27
|
<span class="diff-loading">Loading\u2026</span>
|
|
28
|
-
</div></div>`,
|
|
28
|
+
</div></div>`,lt(),T.classList.add("open"),We.classList.add("open");try{let n=await fetch(S("/api/git/diff?path="+encodeURIComponent(t)+"&file="+encodeURIComponent(e)));if(!n.ok)throw new Error(await n.text());let s=await n.json();On(e,s.diff,s.stagedDiff)}catch(n){let s=n instanceof Error?n.message:String(n);T.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
29
29
|
<button class="diff-back">\u2190 Back</button>
|
|
30
30
|
<span class="diff-filename">${h(e)}</span>
|
|
31
|
-
</div><div class="diff-empty">Error loading diff: ${h(s)}</div></div>`}}}function
|
|
31
|
+
</div><div class="diff-empty">Error loading diff: ${h(s)}</div></div>`}}}function On(e,t,n){if(!t&&!n){T.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
32
32
|
<button class="diff-back">\u2190 Back</button>
|
|
33
33
|
<span class="diff-filename">${h(e)}</span>
|
|
34
|
-
</div><div class="diff-empty">No diff content available</div></div>`;return}let{html:s,lineCount:a}=
|
|
34
|
+
</div><div class="diff-empty">No diff content available</div></div>`;return}let{html:s,lineCount:a}=_t(t,n);T.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
35
35
|
<button class="diff-back">\u2190 Back</button>
|
|
36
36
|
<span class="diff-filename">${h(e)}</span>
|
|
37
37
|
<span class="diff-filesize">${a} lines</span>
|
|
38
|
-
</div><div class="diff-content">${s}</div></div>`,T.querySelector(".diff-back")?.addEventListener("click",()=>{T.innerHTML=
|
|
38
|
+
</div><div class="diff-content">${s}</div></div>`,T.querySelector(".diff-back")?.addEventListener("click",()=>{T.innerHTML=Ut,lt(),w&&T.querySelectorAll(".git-popover-item").forEach(r=>{let c=parseInt(r.dataset.idx||"0",10),o=w.files[c];!o||o.status==="D"||(r.style.cursor="pointer",r.addEventListener("click",()=>Yt(o.path)))}),jt()})}function Kn(e,t,n){if(!t&&!n){je.textContent="No diff",Ue.innerHTML='<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">No diff content available</div>';return}let{html:s,lineCount:a}=_t(t,n);zt.textContent=e,je.textContent=a+" lines",Ue.innerHTML=s}function Vn(){$t.style.display="none",_e?(M.style.display="",M.classList.add("terminal-pending"),ye(_e),_e=null):y?(M.style.display="",M.classList.add("terminal-pending"),Ot()):J.style.display="flex"}Yn.addEventListener("click",Vn);function Ye(){T.classList.remove("open"),We.classList.remove("open")}We.addEventListener("click",Ye),document.addEventListener("keydown",e=>{e.key==="Escape"&&(Ye(),Ge())});async function qt(e){try{let t=await(await fetch("/api/fs/session-path?session="+encodeURIComponent(e))).json();if(t.path){let n=await fetch("/api/git/status?path="+encodeURIComponent(t.path));if(n.ok){let s=await n.json();w=s,be(s);return}}}catch{}w=null,be(null)}var qe=null;function Ot(){Oe(),y&&(qt(y),qe=setInterval(()=>{y&&qt(y)},3e4))}function Oe(){qe&&(clearInterval(qe),qe=null)}function Xn(){if(ze=fe.fsRoots||[],ze.length===0){if(y){Jn(y);return}f.innerHTML='<div class="file-tree-info">Open a session first, then switch to Files to browse its directory.</div>';return}f.innerHTML="";for(let e of ze){let t=document.createElement("div");t.className="file-tree-item",t.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> ${h(e)}`,t.addEventListener("click",()=>q(e)),f.appendChild(t)}}async function Jn(e){f.innerHTML='<div class="file-tree-empty">Loading...</div>';try{let t=await(await fetch(S("/api/fs/session-path?session="+encodeURIComponent(e)))).json();t.path?q(t.path):f.innerHTML='<div class="file-tree-info">Could not determine session directory.</div>'}catch{f.innerHTML='<div class="file-tree-error">Failed to get session directory</div>'}}async function q(e){Y=e,f.innerHTML='<div class="file-tree-empty">Loading...</div>';let t=Wn(e);try{let n=await(await fetch(S("/api/fs/list?path="+encodeURIComponent(e)))).json();await t,f.innerHTML="",be(w),f.innerHTML+=_n();let s=Zn(e);if(s&&!ze.some(r=>e===r)){let r=document.createElement("div");r.className="file-tree-item",r.innerHTML="..",r.addEventListener("click",()=>q(s)),f.appendChild(r)}if(n.dirs)for(let r of n.dirs){let c=r.split("/").pop()||r.split("\\").pop(),o=document.createElement("div");o.className="file-tree-item",o.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> ${h(c)}`,o.addEventListener("click",()=>q(r)),f.appendChild(o)}else f.innerHTML="";let a=n.files||[];for(let r of a){let c=r.split("/").pop()||r.split("\\").pop(),o=Un(r),u="",p="";if(o)switch(o){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 E=document.createElement("div");E.className="file-tree-item file"+(u?" "+u:""),E.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${p}${h(c)}`,E.addEventListener("click",()=>Gn(r)),f.appendChild(E)}}catch{f.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function Zn(e){let t=e.lastIndexOf("/");return t<=0?null:e.substring(0,t)}async function Gn(e){Re=e,M.style.display="none",g&&(Oe(),g.destroy(),g=null,y=null),be(null),$e(),J.style.display="none",ge.style.display="flex",An.textContent=e,F.textContent="Loading...",Z.style.display="none";try{let t=await fetch(S("/api/file?path="+encodeURIComponent(e)));if(!t.ok){let s=await t.json();F.textContent=s.error||"Failed to load",ve.value="";return}let n=await t.json();ve.value=n.content,Pe=n.content,kt=n.content,F.textContent=n.size+" bytes",Z.style.display=""}catch{F.textContent="Failed to load",ve.value=""}}ve.addEventListener("input",()=>{Pe=ve.value}),Z.addEventListener("click",async()=>{Z.textContent="Saving...",Z.disabled=!0;try{let e=await fetch(S("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Re,content:Pe})});if(!e.ok){let t=await e.json();F.textContent=t.error||"Save failed";return}kt=Pe,F.textContent="Saved"}catch{F.textContent="Save failed"}finally{Z.disabled=!1,Z.textContent="Save"}}),Fn.addEventListener("click",async()=>{if(confirm("Delete "+Re+"?"))try{let e=await fetch(S("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Re})});if(!e.ok){let t=await e.json();F.textContent=t.error||"Delete failed";return}ge.style.display="none",J.style.display="flex",Y&&q(Y)}catch{F.textContent="Delete failed"}}),Hn.addEventListener("click",()=>{ge.style.display="none",J.style.display="flex",Y&&q(Y)}),Rn.addEventListener("click",async()=>{let e=St.value.trim();if(!e)return;let t=Y+"/"+e;try{let n=await fetch(S("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!n.ok){let s=await n.json();F.textContent=s.error||"Create failed";return}St.value="",Y&&q(Y)}catch{F.textContent="Create failed"}});var Ke=document.getElementById("force-narrow-toggle");Ke&&(Ke.checked=Ne(),Ke.addEventListener("change",()=>{try{localStorage.setItem(Bt,Ke.checked?"1":"0")}catch{}Mt(),j()})),Mt(),document.getElementById("mode-settings").addEventListener("click",()=>{let e=Tt.classList.toggle("open");at.classList.toggle("open",e)}),at.addEventListener("click",()=>{Tt.classList.remove("open"),at.classList.remove("open")});var D="",U=!1,H,Ee=document.createElement("div");Ee.className="session-popover-backdrop",document.body.appendChild(Ee);var R=document.createElement("div");R.id="session-popover",R.className="session-popover",R.style.display="none",R.innerHTML=`<div class="sp-field">
|
|
39
39
|
<label>Rename session</label>
|
|
40
40
|
<input type="text" id="sp-name" />
|
|
41
41
|
</div>
|
|
@@ -45,5 +45,5 @@ var bn=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function
|
|
|
45
45
|
</div>
|
|
46
46
|
<hr class="sp-divider" />
|
|
47
47
|
<button class="btn primary" id="sp-rebuild" style="display:none">\u91CD\u5EFA\u540C\u540D\u540C\u8DEF\u5F84 session</button>
|
|
48
|
-
<button class="btn danger" id="sp-delete">Delete session</button>`,document.body.appendChild(R);function
|
|
49
|
-
`).length;N.rows=Math.min(e,4)}),N.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),
|
|
48
|
+
<button class="btn danger" id="sp-delete">Delete session</button>`,document.body.appendChild(R);function Qn(e){let t=e.getBoundingClientRect(),n=window.innerHeight,s=R.offsetHeight||240,a=t.bottom+4;a+s>n-8&&(a=Math.max(8,t.top-s-4)),R.style.top=a+"px",R.style.left=Math.max(8,Math.min(t.left,window.innerWidth-240))+"px"}function Ve(e,t,n){D=e,U=!!n?.tombstone,H=n?.agentId;let s=document.getElementById("sp-name");s.value=e;let a=R.querySelector(".sp-field label");a.textContent=U?"\u91CD\u547D\u540D (\u4EC5\u8BB0\u5F55\uFF0C\u4E0D\u91CD\u5EFA)":"Rename session";let r=document.getElementById("sp-rebuild");r.style.display=U?"":"none";let c=document.getElementById("sp-delete");c.textContent=U?"\u5220\u9664\u5931\u6548\u8BB0\u5F55 (\u5893\u7891\u6D88\u5931)":"Delete session";let o=document.getElementById("sp-save");o.textContent=U?"\u91CD\u547D\u540D":"Save",Ee.classList.add("open"),R.style.display="block",Qn(t),setTimeout(()=>s.focus(),50)}function G(){Ee.classList.remove("open"),R.style.display="none"}Ee.addEventListener("click",G),document.getElementById("sp-save").addEventListener("click",async()=>{let e=document.getElementById("sp-name").value.trim();if(!e||e===D){G();return}try{let t=U?{oldName:D,newName:e,agentId:H}:{oldName:D,newName:e,...H?{agentId:H}:{}};if(!(await fetch(S(U?"/api/sessions/rename-tombstone":"/api/sessions/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok)return;G(),j(),!U&&y===D&&(H??null)===k&&ye(e,H)}catch{}}),document.getElementById("sp-rebuild").addEventListener("click",async()=>{if(confirm('\u91CD\u5EFA\u4F1A\u8BDD "'+D+'" (\u540C\u540D\u540C\u8DEF\u5F84\uFF0C\u5185\u5BB9\u4E3A\u7A7A)\uFF1F'))try{let e=await fetch(S("/api/sessions/rebuild"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:D,agentId:H})});if(!e.ok){let t=await e.json();alert(t.error||"\u91CD\u5EFA\u5931\u8D25");return}G(),j()}catch{}}),document.getElementById("sp-delete").addEventListener("click",async()=>{if(U){if(!confirm('\u5220\u9664\u5931\u6548\u8BB0\u5F55 "'+D+'"\uFF1F'))return;try{if(!(await fetch(S("/api/sessions/dismiss"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:D,agentId:H})})).ok)return;G(),j()}catch{}return}if(confirm('Delete session "'+D+'"?'))try{if(!(await fetch(S("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:D,...H?{agentId:H}:{}})})).ok)return;G(),y===D&&(H??null)===k&&(g&&(g.destroy(),g=null),y=null,M.style.display="none",J.style.display="flex"),j()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",G);var Kt={esc:"\x1B",tab:" ","s-tab":"\x1B[Z",up:"\x1B[A",down:"\x1B[B",left:"\x1B[D",right:"\x1B[C",space:" ",enter:"\r","ctrl-r":"","ctrl-c":"",btw:"/btw ",yes:"yes\r"},Xe=document.getElementById("mobile-keys"),es=new Set(["up","down","left","right","tab","s-tab","space"]),ts=400,ns=80,Le=0,Je=0,Ze=!1;function ss(){Le&&(clearTimeout(Le),Le=0),Je&&(clearInterval(Je),Je=0)}Xe.addEventListener("mousedown",e=>{e.target.closest("button[data-key]")&&e.preventDefault()}),Xe.addEventListener("pointerdown",e=>{let t=e.target.closest("button[data-key]");if(!t)return;let n=t.dataset.key;es.has(n)&&(Ze=!1,Le=setTimeout(()=>{Le=0,Ze=!0,Je=setInterval(()=>{let s=Kt[n];s&&g&&g.sendInput(s)},ns)},ts))});for(let e of["pointerup","pointercancel","pointerleave"])Xe.addEventListener(e,ss);Xe.addEventListener("click",e=>{let t=e.target.closest("button[data-key]");if(!t||!g)return;if(Ze){Ze=!1;return}let n=Kt[t.dataset.key];n&&(g.sendInput(n),g.focus())});var N=document.getElementById("mk-input"),Vt=document.getElementById("mk-send");function Xt(){if(!N||!g)return;let e=N.value;e&&(g.sendInput(e+"\r"),N.value="",N.rows=1,g.focus())}if(N&&(N.addEventListener("input",()=>{N.rows=1;let e=N.value.split(`
|
|
49
|
+
`).length;N.rows=Math.min(e,4)}),N.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Xt())})),Vt&&Vt.addEventListener("click",Xt),window.visualViewport){let e=document.querySelector(".app-layout"),t=()=>{e&&(e.style.height=window.visualViewport.height+"px"),window.scrollTo(0,0),document.documentElement.scrollTop=0,document.body.scrollTop=0};window.visualViewport.addEventListener("resize",t),window.addEventListener("orientationchange",()=>setTimeout(t,100)),document.addEventListener("touchstart",()=>{(window.scrollY>0||document.documentElement.scrollTop>0)&&window.scrollTo(0,0)},{passive:!0})}var rt=document.getElementById("process-panel"),xe=document.getElementById("proc-list"),is=document.getElementById("proc-close"),ct=document.getElementById("proc-backdrop"),as=document.getElementById("header-ram");function os(){xe.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(S("/api/system/processes")).then(e=>e.json()).then(e=>{if(!Array.isArray(e)||!e.length){xe.innerHTML='<div class="proc-empty">No processes</div>';return}let t="";for(let n of e){let s=n.rss,a=s<1048576?(s/1024).toFixed(0)+"K":(s/1048576).toFixed(1)+"M";t+='<div class="proc-row" data-pid="'+n.pid+'"><span class="proc-mem">'+n.mem+'%</span><span class="proc-rss">'+a+'</span><span class="proc-cmd" title="'+h(n.command)+'">'+h(n.command)+'</span><button class="proc-kill" title="Kill PID '+n.pid+'">×</button></div>'}xe.innerHTML=t;for(let n of xe.querySelectorAll(".proc-row")){let s=n.querySelector(".proc-kill");s&&s.addEventListener("click",a=>{let r=a.target.closest(".proc-row");!r||!confirm("Kill PID "+r.dataset.pid+"?")||fetch(S("/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(()=>{xe.innerHTML='<div class="proc-empty">Failed to load</div>'})}function ls(){rt.classList.add("open"),ct.classList.add("open"),os()}function Ge(){rt.classList.remove("open"),ct.classList.remove("open")}as.addEventListener("click",e=>{e.stopPropagation(),rt.classList.contains("open")?Ge():ls()}),is.addEventListener("click",Ge),ct.addEventListener("click",Ge);var rs=2e3,Ce=null,dt=null,se=new Map,ie=new Map,cs=5e3,Jt=new Map;function ut(e,t){return(t?"a:"+t+":":"l:")+e}function ds(e,t,n){let s=ut(e,t);if(n==="working"){let p=Jt.get(s);if(p&&Date.now()<p)return}let a=ie.get(s),r=e===y&&(t??null)===k,c=n==="idle"&&a?.state==="working";ie.set(s,{session:e,agentId:t,state:n,doneUntil:c?Date.now()+rs:void 0,unread:c?!r:!1});let o=t?'.session-item[data-agent="'+CSS.escape(t)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])',u=f.querySelector(o);u&&Qe(u,s,ie.get(s))}function Qe(e,t,n){let s=se.get(t);s&&(clearTimeout(s),se.delete(t)),e.classList.remove("working","just-done");let a=n.session===y&&(n.agentId??null)===k;n.state==="working"?e.classList.add("working"):a&&n.doneUntil&&Date.now()<n.doneUntil?(e.classList.add("just-done"),se.set(t,setTimeout(()=>{e.classList.remove("just-done"),se.delete(t)},Math.max(0,n.doneUntil-Date.now())))):!a&&n.unread&&e.classList.add("just-done")}function pt(){for(let[e,t]of ie){let n=t.agentId?'.session-item[data-agent="'+CSS.escape(t.agentId)+'"][data-session="'+CSS.escape(t.session)+'"]':'.session-item[data-session="'+CSS.escape(t.session)+'"]:not([data-agent])',s=f.querySelector(n);s&&Qe(s,e,t)}}function us(e,t){let n=ut(e,t),s=ie.get(n);if(!s)return;let a=se.get(n);a&&(clearTimeout(a),se.delete(n)),s.doneUntil=void 0,s.unread=!1;let r=t?'.session-item[data-agent="'+CSS.escape(t)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])',c=f.querySelector(r);c&&Qe(c,n,s)}function Zt(){if(Ce||dt)return;let e=localStorage.getItem("tmux-web-token"),t=(location.protocol==="https:"?"wss:":"ws:")+"//"+location.host+"/ws/activity";e&&(t+="?token="+encodeURIComponent(e));try{let n=new WebSocket(t);Ce=n,n.onmessage=s=>{try{let a=JSON.parse(String(s.data));a&&a.type==="session.activity"&&typeof a.session=="string"&&ds(a.session,a.agentId||void 0,a.state==="working"?"working":"idle")}catch{}},n.onclose=()=>{Ce===n&&(Ce=null,dt=setTimeout(()=>{dt=null,Zt()},5e3))},n.onerror=()=>{try{n.close()}catch{}}}catch{Ce=null}}window.__openSession=ye,window.__refreshSidebar=j,j(),$e(),pt(),Zt(),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&pt()}),setInterval(()=>{document.visibilityState==="visible"&&j()},1e4);
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import{initTerminal as
|
|
1
|
+
import{initTerminal as Xe}from"./terminal-core.js";const D=window.__TMUX_WEB_SHELL__;let p=null,u=null;const P=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null;let g=P;window.__tmuxWebScopeAgent=P;let me="sessions",x="",J="",K="",Se="";function v(e){return g?"/a/"+encodeURIComponent(g)+e:e}const r=document.getElementById("sidebar-content"),H=document.getElementById("main-placeholder"),b=document.getElementById("terminal-container"),j=document.getElementById("file-editor"),Ze=document.getElementById("fe-path"),E=document.getElementById("fe-status"),O=document.getElementById("fe-content"),R=document.getElementById("fe-save"),Qe=document.getElementById("fe-delete"),et=document.getElementById("fe-back"),Ce=document.getElementById("fe-new-name"),tt=document.getElementById("fe-new-btn"),ge=document.getElementById("settings-backdrop"),Ie=document.getElementById("settings-popover"),Be=document.querySelector(".sidebar"),xe="tmux-web-force-narrow";function Y(){try{return localStorage.getItem(xe)==="1"}catch{return!1}}function Te(){document.documentElement.classList.toggle("force-narrow",Y()),Y()&&Me()&&X()}function Me(){return Y()?!0:window.matchMedia("(max-width: 640px)").matches}function X(){Me()&&Be.classList.add("collapsed")}function He(){Be.classList.remove("collapsed")}document.getElementById("mode-sessions").addEventListener("click",()=>{He(),Re("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{He(),Re("files")});function Re(e){me=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"?(ve="",I()):gt()}let ve="";async function I(){if(me!=="sessions")return;try{const t=await(await fetch("/api/sidebar/sessions")).json(),s=JSON.stringify({recent:t.recent,agents:t.agents,tombstones:t.tombstones});if(s===ve)return;ve=s,at(t)}catch{r.innerHTML+='<div class="file-tree-empty">Failed to load sessions</div>'}const e=document.getElementById("ns-btn");e&&e.addEventListener("click",()=>{const n=window.__openNewSessionModal;typeof n=="function"?n():document.getElementById("new-session-modal")?.classList.add("open")}),Ee()}const Ne="tmux-web-sidebar-group-collapsed";function Ae(){try{return new Set(JSON.parse(localStorage.getItem(Ne)||"[]"))}catch{return new Set}}function nt(e){try{localStorage.setItem(Ne,JSON.stringify([...e]))}catch{}}function st(e,n,t){if(!e)return"\u2026";const s=t&&(e===t||e.startsWith(t+"/"))?"~"+e.slice(t.length):e,i=s.split("/").filter(Boolean);if(i.length===0)return e;for(let o=1;o<=i.length;o++){const a=i.slice(-o).join("/");if(!n.some(c=>!c||c===e?!1:(t&&(c===t||c.startsWith(t+"/"))?"~"+c.slice(t.length):c).split("/").filter(Boolean).slice(-o).join("/")===a))return a}return s}function _e(e,n,t,s=!0){const i=new Map;for(const l of e){const c=l.path||"";i.has(c)||i.set(c,[]),i.get(c).push(l)}const o=[...i.keys()],a=Ae();for(const[l,c]of i){const f=st(l,o,n),L=a.has(l),h=document.createElement("div");h.className="session-group-header"+(L?" collapsed":""),h.title=l||"No working directory",h.innerHTML=`<span class="sg-folder">📁</span><span class="sg-label">${d(f)}</span>`,h.addEventListener("click",()=>{const M=Ae(),ke=h.nextElementSibling;M.has(l)?(M.delete(l),h.classList.remove("collapsed"),ke?.classList.remove("collapsed")):(M.add(l),h.classList.add("collapsed"),ke?.classList.add("collapsed")),nt(M)});const ue=document.createElement("div");ue.className="session-group-body"+(L?" collapsed":"");for(const M of c)ue.appendChild(t?it(M,t,s):ot(M));r.appendChild(h),r.appendChild(ue)}}function it(e,n,t){const s=document.createElement("div");s.className="session-item"+(e.name===u&&g===n?" active":"")+(t?"":" session-offline"),s.setAttribute("data-session",e.name),s.setAttribute("data-agent",n),s.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${e.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(e.name)}</span>${t?"":'<span class="meta">offline</span>'}
|
|
3
|
-
<button class="session-edit-btn" data-session="${d(e.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>`,t&&s.addEventListener("click",o=>{o.target.closest(".session-edit-btn")||U(e.name,n)});const i=s.querySelector(".session-edit-btn");return i&&i.addEventListener("click",o=>{o.stopPropagation(),
|
|
3
|
+
<button class="session-edit-btn" data-session="${d(e.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>`,t&&s.addEventListener("click",o=>{o.target.closest(".session-edit-btn")||U(e.name,n)});const i=s.querySelector(".session-edit-btn");return i&&i.addEventListener("click",o=>{o.stopPropagation(),le(e.name,i,{agentId:n})}),s}function ot(e){const n=document.createElement("div");n.className="session-item"+(e.name===u&&!g?" active":""),n.setAttribute("data-session",e.name),n.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${e.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>
|
|
4
4
|
<span>${d(e.name)}</span>
|
|
5
5
|
<button class="session-edit-btn" data-session="${d(e.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>
|
|
6
|
-
`,n.addEventListener("click",s=>{s.target.closest(".session-edit-btn")||U(e.name)});const t=n.querySelector(".session-edit-btn");return t&&t.addEventListener("click",s=>{s.stopPropagation(),
|
|
6
|
+
`,n.addEventListener("click",s=>{s.target.closest(".session-edit-btn")||U(e.name)});const t=n.querySelector(".session-edit-btn");return t&&t.addEventListener("click",s=>{s.stopPropagation(),le(e.name,t)}),n}function at(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"+(P?" clickable":""),t.textContent=P?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",P&&(t.title="Back to hub",t.addEventListener("click",()=>{window.location.href="/"})),r.appendChild(t),_e(n,e.home);const s=e.agents||[];for(const o of s){if(!o.sessions||o.sessions.length===0)continue;const a=o.agentId===g,l=document.createElement("div");l.className="sidebar-section-label machine-label"+(o.online?"":" agent-offline-label")+(!a&&o.online?" clickable":""),l.textContent=o.agentName+(o.online?"":" (offline)"),!a&&o.online&&(l.title="\u6253\u5F00 "+o.agentName,l.addEventListener("click",()=>{window.location.href="/a/"+encodeURIComponent(o.agentId)+"/"})),r.appendChild(l),_e(o.sessions,e.home,o.agentId,o.online)}const i=e.tombstones||[];if(i.length>0){const o=document.createElement("div");o.className="sidebar-section-label tombstone-label",o.textContent="\u5931\u6548\u4F1A\u8BDD",r.appendChild(o);for(const a of i){const l=document.createElement("div");l.className="session-item session-tombstone",l.setAttribute("data-session",a.name),a.agentId&&l.setAttribute("data-agent",a.agentId);const c=a.agentId?a.agentOnline?" (agent)":" (agent \u79BB\u7EBF)":"";l.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"></svg>
|
|
7
7
|
<span>${d(a.name)}</span><span class="meta">\u5931\u6548${c}</span>
|
|
8
|
-
<button class="session-edit-btn" data-session="${d(a.name)}" title="\u6062\u590D\u4F1A\u8BDD"><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>`,l.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",l.addEventListener("click",()=>{
|
|
8
|
+
<button class="session-edit-btn" data-session="${d(a.name)}" title="\u6062\u590D\u4F1A\u8BDD"><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>`,l.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",l.addEventListener("click",()=>{le(a.name,l,{tombstone:!0,agentId:a.agentId})});const f=l.querySelector(".session-edit-btn");f&&f.addEventListener("click",L=>{L.stopPropagation(),le(a.name,f,{tombstone:!0,agentId:a.agentId})}),r.appendChild(l)}}}function d(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function U(e,n){if(u===e&&p&&g===(n||null))return;j.style.display="none",H.style.display="none",b.style.display="",b.classList.add("terminal-pending"),X(),p&&(oe(),p.destroy(),p=null),u=e,g=n||null,window.__tmuxWebScopeAgent=g,window.__tmuxWebCurrentSession=u,Ht(e,n);const t=Le(e,n);Ke.set(t,Date.now()+Tt);const s=$.get(t);if(s&&s.state==="working"){s.state="idle",s.doneUntil=void 0,s.unread=!1;const i=r.querySelector(n?'.session-item[data-agent="'+CSS.escape(n)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])');i&&fe(i,t,s)}for(const i of r.querySelectorAll(".session-item"))i.classList.toggle("active",i.getAttribute("data-session")===e&&(i.getAttribute("data-agent")||null)===g);try{p=await Xe(b,e,{terminal:D.terminal,scrollback:D.scrollback,theme:D.theme,wsBase:g?"/ws/a/"+encodeURIComponent(g):D.wsBase||"/ws"}),Ge()}catch(i){console.error("[shell] terminal init failed:",i);const o=i&&typeof i=="object"&&"message"in i?i.message:String(i);b.textContent="Failed to open terminal for "+e+": "+o,b.classList.remove("terminal-pending")}}let Z=[],m=null,$e=!1;function lt(e){if(!m||!m.files.length)return null;const n=m.repoRoot;if(!n||!e.startsWith(n))return null;const t=e.slice(n.length+1);for(const s of m.files)if(s.path===t)return s.status;return null}async function ct(e){$e=!0;try{const n=await fetch(v("/api/git/status?path="+encodeURIComponent(e)));n.ok?m=await n.json():m=null}catch{m=null}finally{$e=!1}}function rt(){if(!m||!m.branch)return"";const{branch:e,linesAdded:n,linesRemoved:t}=m;let s=`<div class="sidebar-git"><div class="git-branch-badge">
|
|
9
9
|
<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>
|
|
10
|
-
${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")
|
|
10
|
+
${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")&&A&&m&&(e.stopPropagation(),Ue())});const W=document.getElementById("header-git"),De=document.getElementById("git-diff-view"),Pe=document.getElementById("gd-path"),Q=document.getElementById("gd-status"),ee=document.getElementById("gd-content"),dt=document.getElementById("gd-back");let A=null;function z(e){if(!e||!e.branch){W.style.display="none",A=null;return}A=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>`),W.innerHTML=i,W.style.display="block"}W.addEventListener("click",e=>{A&&m&&(e.stopPropagation(),Ue())});const y=document.getElementById("git-popover"),te=document.getElementById("git-popover-backdrop");function ye(){const e=W.getBoundingClientRect();y.style.top=e.bottom+4+"px",y.style.left=Math.max(8,Math.min(e.left,window.innerWidth-400))+"px"}function je(){const e=A,n=document.getElementById("git-popover-browse");n&&n.addEventListener("click",()=>{if(se(),e){me="files",document.querySelectorAll(".mode-btn").forEach(s=>s.classList.remove("active"));const t=document.getElementById("mode-files");t&&t.classList.add("active"),T(e)}})}let Oe="";function Ue(){if(!m)return;const e=m.files||[];if(!e.length)y.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
|
|
11
11
|
<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,o=s.deletions||0;let a="";switch(s.status){case"M":a='<span class="git-file-status M">M</span>';break;case"A":a='<span class="git-file-status A">A</span>';break;case"D":a='<span class="git-file-status D">D</span>';break;case"?":a='<span class="git-file-status ?">?</span>';break;case"R":a='<span class="git-file-status R">R</span>';break}n+=`<div class="git-popover-item" data-idx="${t}">
|
|
12
12
|
${a}<span class="file-path">${d(s.path)}</span>
|
|
13
13
|
<span class="file-add">${i>0?"+"+i:""}</span>
|
|
14
14
|
<span class="file-del">${o>0?"-"+o:""}</span>
|
|
15
|
-
</div>`}n+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',
|
|
15
|
+
</div>`}n+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',Oe=n,y.innerHTML=n,y.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",()=>ze(i.path)))})}ye(),y.classList.add("open"),te.classList.add("open"),je()}function pt(){return window.innerWidth>=1024}function We(e,n){const s=(e+(n&&e?`
|
|
16
16
|
`:"")+n).split(`
|
|
17
|
-
`);let i="",o=0,a=0;for(const l of s){const c=l;if(c.startsWith("@@")){const
|
|
17
|
+
`);let i="",o=0,a=0;for(const l of s){const c=l;if(c.startsWith("@@")){const f=c.match(/@@\s+-(\d+)[^+]*\+(\d+)/);f&&(o=parseInt(f[1],10)-1,a=parseInt(f[2],10)-1),i+=`<div class="diff-line hunk"><span class="ln-body">${d(c)}</span></div>`;continue}if(c.startsWith("diff --git")||c.startsWith("index ")||c.startsWith("--- ")||c.startsWith("+++ ")||c.startsWith("new file")||c.startsWith("deleted file")){c.startsWith("diff --git")&&(i+=`<div class="diff-line header"><span class="ln-body">${d(c)}</span></div>`);continue}if(c.startsWith("+"))a++,i+=`<div class="diff-line add"><span class="ln-no">${a}</span><span class="ln-body">${d(c)}</span></div>`;else if(c.startsWith("-"))o++,i+=`<div class="diff-line del"><span class="ln-no">${o}</span><span class="ln-body">${d(c)}</span></div>`;else if(c.startsWith("\\"))i+=`<div class="diff-line"><span class="ln-body">${d(c)}</span></div>`;else{if(!c&&!o&&!a)continue;o++,a++,i+=`<div class="diff-line"><span class="ln-no">${o}</span><span class="ln-no" style="margin-right:12px">${a}</span><span class="ln-body">${d(c)}</span></div>`}}return{html:i,lineCount:s.length}}let ne=null;async function ze(e){const n=A;if(n)if(se(),pt()){b.style.display="none",p&&(oe(),p.destroy(),p=null,ne=u,u=null),z(null),j.style.display="none",H.style.display="none",De.style.display="flex",Pe.textContent=e,Q.textContent="Loading\u2026",ee.innerHTML="";try{const t=await fetch(v("/api/git/diff?path="+encodeURIComponent(n)+"&file="+encodeURIComponent(e)));if(!t.ok)throw new Error(await t.text());const s=await t.json();ut(e,s.diff,s.stagedDiff)}catch(t){const s=t instanceof Error?t.message:String(t);Q.textContent="Error",ee.innerHTML=`<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">Error: ${d(s)}</div>`}}else{y.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
18
18
|
<button class="diff-back">\u2190 Back</button>
|
|
19
19
|
<span class="diff-filename">${d(e)}</span>
|
|
20
20
|
<span class="diff-loading">Loading\u2026</span>
|
|
21
|
-
</div></div>`,
|
|
21
|
+
</div></div>`,ye(),y.classList.add("open"),te.classList.add("open");try{const t=await fetch(v("/api/git/diff?path="+encodeURIComponent(n)+"&file="+encodeURIComponent(e)));if(!t.ok)throw new Error(await t.text());const s=await t.json();ft(e,s.diff,s.stagedDiff)}catch(t){const s=t instanceof Error?t.message:String(t);y.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">Error loading diff: ${d(s)}</div></div>`}}}function
|
|
24
|
+
</div><div class="diff-empty">Error loading diff: ${d(s)}</div></div>`}}}function ft(e,n,t){if(!n&&!t){y.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
|
-
</div><div class="diff-empty">No diff content available</div></div>`;return}const{html:s,lineCount:i}=
|
|
27
|
+
</div><div class="diff-empty">No diff content available</div></div>`;return}const{html:s,lineCount:i}=We(n,t);y.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
28
28
|
<button class="diff-back">\u2190 Back</button>
|
|
29
29
|
<span class="diff-filename">${d(e)}</span>
|
|
30
30
|
<span class="diff-filesize">${i} lines</span>
|
|
31
|
-
</div><div class="diff-content">${s}</div></div>`,y.querySelector(".diff-back")?.addEventListener("click",()=>{y.innerHTML=
|
|
31
|
+
</div><div class="diff-content">${s}</div></div>`,y.querySelector(".diff-back")?.addEventListener("click",()=>{y.innerHTML=Oe,ye(),m&&y.querySelectorAll(".git-popover-item").forEach(o=>{const a=parseInt(o.dataset.idx||"0",10),l=m.files[a];!l||l.status==="D"||(o.style.cursor="pointer",o.addEventListener("click",()=>ze(l.path)))}),je()})}function ut(e,n,t){if(!n&&!t){Q.textContent="No diff",ee.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}=We(n,t);Pe.textContent=e,Q.textContent=i+" lines",ee.innerHTML=s}function mt(){De.style.display="none",ne?(b.style.display="",b.classList.add("terminal-pending"),U(ne),ne=null):u?(b.style.display="",b.classList.add("terminal-pending"),Ge()):H.style.display="flex"}dt.addEventListener("click",mt);function se(){y.classList.remove("open"),te.classList.remove("open")}te.addEventListener("click",se),document.addEventListener("keydown",e=>{e.key==="Escape"&&(se(),pe())});async function Fe(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();m=i,z(i);return}}}catch{}m=null,z(null)}let ie=null;function Ge(){oe(),u&&(Fe(u),ie=setInterval(()=>{u&&Fe(u)},3e4))}function oe(){ie&&(clearInterval(ie),ie=null)}function gt(){if(Z=D.fsRoots||[],Z.length===0){if(u){vt(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",()=>T(e)),r.appendChild(n)}}async function vt(e){r.innerHTML='<div class="file-tree-empty">Loading...</div>';try{const t=await(await fetch(v("/api/fs/session-path?session="+encodeURIComponent(e)))).json();t.path?T(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 T(e){x=e,r.innerHTML='<div class="file-tree-empty">Loading...</div>';const n=ct(e);try{const s=await(await fetch(v("/api/fs/list?path="+encodeURIComponent(e)))).json();await n,r.innerHTML="",z(m),r.innerHTML+=rt();const i=yt(e);if(i&&!Z.some(l=>e===l)){const l=document.createElement("div");l.className="file-tree-item",l.innerHTML="..",l.addEventListener("click",()=>T(i)),r.appendChild(l)}if(s.dirs)for(const a of s.dirs){const l=a.split("/").pop()||a.split("\\").pop(),c=document.createElement("div");c.className="file-tree-item",c.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(l)}`,c.addEventListener("click",()=>T(a)),r.appendChild(c)}else r.innerHTML="";const o=s.files||[];for(const a of o){const l=a.split("/").pop()||a.split("\\").pop(),c=lt(a);let f="",L="";if(c)switch(c){case"M":f="git-mod",L='<span class="git-file-status M">M</span>';break;case"A":f="git-add",L='<span class="git-file-status A">A</span>';break;case"D":f="git-del",L='<span class="git-file-status D">D</span>';break;case"?":f="git-untracked",L='<span class="git-file-status ?">?</span>';break;case"R":f="git-mod",L='<span class="git-file-status R">R</span>';break}const h=document.createElement("div");h.className="file-tree-item file"+(f?" "+f:""),h.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${L}${d(l)}`,h.addEventListener("click",()=>ht(a)),r.appendChild(h)}}catch{r.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function yt(e){const n=e.lastIndexOf("/");return n<=0?null:e.substring(0,n)}async function ht(e){J=e,b.style.display="none",p&&(oe(),p.destroy(),p=null,u=null),z(null),X(),H.style.display="none",j.style.display="flex",Ze.textContent=e,E.textContent="Loading...",R.style.display="none";try{const n=await fetch(v("/api/file?path="+encodeURIComponent(e)));if(!n.ok){const s=await n.json();E.textContent=s.error||"Failed to load",O.value="";return}const t=await n.json();O.value=t.content,K=t.content,Se=t.content,E.textContent=t.size+" bytes",R.style.display=""}catch{E.textContent="Failed to load",O.value=""}}O.addEventListener("input",()=>{K=O.value}),R.addEventListener("click",async()=>{R.textContent="Saving...",R.disabled=!0;try{const e=await fetch(v("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:J,content:K})});if(!e.ok){const n=await e.json();E.textContent=n.error||"Save failed";return}Se=K,E.textContent="Saved"}catch{E.textContent="Save failed"}finally{R.disabled=!1,R.textContent="Save"}}),Qe.addEventListener("click",async()=>{if(confirm("Delete "+J+"?"))try{const e=await fetch(v("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:J})});if(!e.ok){const n=await e.json();E.textContent=n.error||"Delete failed";return}j.style.display="none",H.style.display="flex",x&&T(x)}catch{E.textContent="Delete failed"}}),et.addEventListener("click",()=>{j.style.display="none",H.style.display="flex",x&&T(x)}),tt.addEventListener("click",async()=>{const e=Ce.value.trim();if(!e)return;const n=x+"/"+e;try{const t=await fetch(v("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(!t.ok){const s=await t.json();E.textContent=s.error||"Create failed";return}Ce.value="",x&&T(x)}catch{E.textContent="Create failed"}});const ae=document.getElementById("force-narrow-toggle");ae&&(ae.checked=Y(),ae.addEventListener("change",()=>{try{localStorage.setItem(xe,ae.checked?"1":"0")}catch{}Te(),I()})),Te(),document.getElementById("mode-settings").addEventListener("click",()=>{const e=Ie.classList.toggle("open");ge.classList.toggle("open",e)}),ge.addEventListener("click",()=>{Ie.classList.remove("open"),ge.classList.remove("open")});let w="",B=!1,k;const F=document.createElement("div");F.className="session-popover-backdrop",document.body.appendChild(F);const S=document.createElement("div");S.id="session-popover",S.className="session-popover",S.style.display="none",S.innerHTML=`<div class="sp-field">
|
|
32
32
|
<label>Rename session</label>
|
|
33
33
|
<input type="text" id="sp-name" />
|
|
34
34
|
</div>
|
|
@@ -38,5 +38,5 @@ import{initTerminal as qe}from"./terminal-core.js";const D=window.__TMUX_WEB_SHE
|
|
|
38
38
|
</div>
|
|
39
39
|
<hr class="sp-divider" />
|
|
40
40
|
<button class="btn primary" id="sp-rebuild" style="display:none">\u91CD\u5EFA\u540C\u540D\u540C\u8DEF\u5F84 session</button>
|
|
41
|
-
<button class="btn danger" id="sp-delete">Delete session</button>`,document.body.appendChild(S);function
|
|
42
|
-
`).length;C.rows=Math.min(e,4)}),C.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),
|
|
41
|
+
<button class="btn danger" id="sp-delete">Delete session</button>`,document.body.appendChild(S);function bt(e){const n=e.getBoundingClientRect(),t=window.innerHeight,s=S.offsetHeight||240;let i=n.bottom+4;i+s>t-8&&(i=Math.max(8,n.top-s-4)),S.style.top=i+"px",S.style.left=Math.max(8,Math.min(n.left,window.innerWidth-240))+"px"}function le(e,n,t){w=e,B=!!t?.tombstone,k=t?.agentId;const s=document.getElementById("sp-name");s.value=e;const i=S.querySelector(".sp-field label");i.textContent=B?"\u91CD\u547D\u540D (\u4EC5\u8BB0\u5F55\uFF0C\u4E0D\u91CD\u5EFA)":"Rename session";const o=document.getElementById("sp-rebuild");o.style.display=B?"":"none";const a=document.getElementById("sp-delete");a.textContent=B?"\u5220\u9664\u5931\u6548\u8BB0\u5F55 (\u5893\u7891\u6D88\u5931)":"Delete session";const l=document.getElementById("sp-save");l.textContent=B?"\u91CD\u547D\u540D":"Save",F.classList.add("open"),S.style.display="block",bt(n),setTimeout(()=>s.focus(),50)}function N(){F.classList.remove("open"),S.style.display="none"}F.addEventListener("click",N),document.getElementById("sp-save").addEventListener("click",async()=>{const e=document.getElementById("sp-name").value.trim();if(!e||e===w){N();return}try{const n=B?{oldName:w,newName:e,agentId:k}:{oldName:w,newName:e,...k?{agentId:k}:{}};if(!(await fetch(v(B?"/api/sessions/rename-tombstone":"/api/sessions/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})).ok)return;N(),I(),!B&&u===w&&(k??null)===g&&U(e,k)}catch{}}),document.getElementById("sp-rebuild").addEventListener("click",async()=>{if(confirm('\u91CD\u5EFA\u4F1A\u8BDD "'+w+'" (\u540C\u540D\u540C\u8DEF\u5F84\uFF0C\u5185\u5BB9\u4E3A\u7A7A)\uFF1F'))try{const e=await fetch(v("/api/sessions/rebuild"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:w,agentId:k})});if(!e.ok){const n=await e.json();alert(n.error||"\u91CD\u5EFA\u5931\u8D25");return}N(),I()}catch{}}),document.getElementById("sp-delete").addEventListener("click",async()=>{if(B){if(!confirm('\u5220\u9664\u5931\u6548\u8BB0\u5F55 "'+w+'"\uFF1F'))return;try{if(!(await fetch(v("/api/sessions/dismiss"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:w,agentId:k})})).ok)return;N(),I()}catch{}return}if(confirm('Delete session "'+w+'"?'))try{if(!(await fetch(v("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:w,...k?{agentId:k}:{}})})).ok)return;N(),u===w&&(k??null)===g&&(p&&(p.destroy(),p=null),u=null,b.style.display="none",H.style.display="flex"),I()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",N);const qe={esc:"\x1B",tab:" ","s-tab":"\x1B[Z",up:"\x1B[A",down:"\x1B[B",left:"\x1B[D",right:"\x1B[C",space:" ",enter:"\r","ctrl-r":"","ctrl-c":"",btw:"/btw ",yes:"yes\r"},ce=document.getElementById("mobile-keys"),wt=new Set(["up","down","left","right","tab","s-tab","space"]),Lt=400,Et=80;let G=0,re=0,de=!1;function kt(){G&&(clearTimeout(G),G=0),re&&(clearInterval(re),re=0)}ce.addEventListener("mousedown",e=>{e.target.closest("button[data-key]")&&e.preventDefault()}),ce.addEventListener("pointerdown",e=>{const n=e.target.closest("button[data-key]");if(!n)return;const t=n.dataset.key;wt.has(t)&&(de=!1,G=setTimeout(()=>{G=0,de=!0,re=setInterval(()=>{const s=qe[t];s&&p&&p.sendInput(s)},Et)},Lt))});for(const e of["pointerup","pointercancel","pointerleave"])ce.addEventListener(e,kt);ce.addEventListener("click",e=>{const n=e.target.closest("button[data-key]");if(!n||!p)return;if(de){de=!1;return}const t=qe[n.dataset.key];t&&(p.sendInput(t),p.focus())});const C=document.getElementById("mk-input"),Ve=document.getElementById("mk-send");function Je(){if(!C||!p)return;const e=C.value;e&&(p.sendInput(e+"\r"),C.value="",C.rows=1,p.focus())}if(C&&(C.addEventListener("input",()=>{C.rows=1;const e=C.value.split(`
|
|
42
|
+
`).length;C.rows=Math.min(e,4)}),C.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Je())})),Ve&&Ve.addEventListener("click",Je),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 he=document.getElementById("process-panel"),q=document.getElementById("proc-list"),St=document.getElementById("proc-close"),be=document.getElementById("proc-backdrop"),Ct=document.getElementById("header-ram");function It(){q.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(v("/api/system/processes")).then(e=>e.json()).then(e=>{if(!Array.isArray(e)||!e.length){q.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>'}q.innerHTML=n;for(const t of q.querySelectorAll(".proc-row")){const s=t.querySelector(".proc-kill");s&&s.addEventListener("click",i=>{const o=i.target.closest(".proc-row");!o||!confirm("Kill PID "+o.dataset.pid+"?")||fetch(v("/api/system/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:parseInt(o.dataset.pid,10)})}).then(a=>a.json()).then(a=>{a.ok?o.style.opacity="0.3":alert("Failed: "+(a.error||"unknown"))}).catch(()=>alert("Network error"))})}}).catch(()=>{q.innerHTML='<div class="proc-empty">Failed to load</div>'})}function Bt(){he.classList.add("open"),be.classList.add("open"),It()}function pe(){he.classList.remove("open"),be.classList.remove("open")}Ct.addEventListener("click",e=>{e.stopPropagation(),he.classList.contains("open")?pe():Bt()}),St.addEventListener("click",pe),be.addEventListener("click",pe);const xt=2e3;let V=null,we=null;const _=new Map,$=new Map,Tt=5e3,Ke=new Map;function Le(e,n){return(n?"a:"+n+":":"l:")+e}function Mt(e,n,t){const s=Le(e,n);if(t==="working"){const f=Ke.get(s);if(f&&Date.now()<f)return}const i=$.get(s),o=e===u&&(n??null)===g,a=t==="idle"&&i?.state==="working";$.set(s,{session:e,agentId:n,state:t,doneUntil:a?Date.now()+xt:void 0,unread:a?!o:!1});const l=n?'.session-item[data-agent="'+CSS.escape(n)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])',c=r.querySelector(l);c&&fe(c,s,$.get(s))}function fe(e,n,t){const s=_.get(n);s&&(clearTimeout(s),_.delete(n)),e.classList.remove("working","just-done");const i=t.session===u&&(t.agentId??null)===g;t.state==="working"?e.classList.add("working"):i&&t.doneUntil&&Date.now()<t.doneUntil?(e.classList.add("just-done"),_.set(n,setTimeout(()=>{e.classList.remove("just-done"),_.delete(n)},Math.max(0,t.doneUntil-Date.now())))):!i&&t.unread&&e.classList.add("just-done")}function Ee(){for(const[e,n]of $){const t=n.agentId?'.session-item[data-agent="'+CSS.escape(n.agentId)+'"][data-session="'+CSS.escape(n.session)+'"]':'.session-item[data-session="'+CSS.escape(n.session)+'"]:not([data-agent])',s=r.querySelector(t);s&&fe(s,e,n)}}function Ht(e,n){const t=Le(e,n),s=$.get(t);if(!s)return;const i=_.get(t);i&&(clearTimeout(i),_.delete(t)),s.doneUntil=void 0,s.unread=!1;const o=n?'.session-item[data-agent="'+CSS.escape(n)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])',a=r.querySelector(o);a&&fe(a,t,s)}function Ye(){if(V||we)return;const e=localStorage.getItem("tmux-web-token");let t=(location.protocol==="https:"?"wss:":"ws:")+"//"+location.host+"/ws/activity";e&&(t+="?token="+encodeURIComponent(e));try{const s=new WebSocket(t);V=s,s.onmessage=i=>{try{const o=JSON.parse(String(i.data));o&&o.type==="session.activity"&&typeof o.session=="string"&&Mt(o.session,o.agentId||void 0,o.state==="working"?"working":"idle")}catch{}},s.onclose=()=>{V===s&&(V=null,we=setTimeout(()=>{we=null,Ye()},5e3))},s.onerror=()=>{try{s.close()}catch{}}}catch{V=null}}window.__openSession=U,window.__refreshSidebar=I,I(),X(),Ee(),Ye(),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Ee()}),setInterval(()=>{document.visibilityState==="visible"&&I()},1e4);
|
package/dist/lib/pages/shell.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{cssVarsStyle as d}from"../theme.js";import{newSessionModalCSS as c,newSessionModalHTML as f,newSessionModalScript as g,reducedMotion as b}from"../shared-layout.js";import{icon as
|
|
1
|
+
import{cssVarsStyle as d}from"../theme.js";import{newSessionModalCSS as c,newSessionModalHTML as f,newSessionModalScript as g,reducedMotion as b}from"../shared-layout.js";import{icon as n}from"../icons.js";function v(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function o(t="var(--panel-accent)"){return`box-shadow: 0 0 0 2px ${t}; outline: none;`}function y(t){const{theme:e,fsRoots:i,terminalCfg:r,scrollback:a,wsBase:s}=t,l=`
|
|
2
2
|
*, *::before, *::after { box-sizing: border-box; }
|
|
3
3
|
html, body {
|
|
4
4
|
background: var(--page-bg); color: var(--page-fg);
|
|
@@ -575,6 +575,16 @@ import{cssVarsStyle as d}from"../theme.js";import{newSessionModalCSS as c,newSes
|
|
|
575
575
|
touch-action: manipulation; user-select: none;
|
|
576
576
|
}
|
|
577
577
|
.mobile-keys button:active { opacity: 0.55; }
|
|
578
|
+
/* Slim tappable strip under the input: the "empty space" that expands the keys. */
|
|
579
|
+
.mobile-keys .mk-handle {
|
|
580
|
+
display: flex; align-items: center; justify-content: center;
|
|
581
|
+
height: 16px; margin-top: 2px; border-radius: 6px;
|
|
582
|
+
color: var(--panel-muted); opacity: 0.65;
|
|
583
|
+
cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
|
|
584
|
+
}
|
|
585
|
+
.mobile-keys .mk-handle:active { opacity: 1; }
|
|
586
|
+
.mobile-keys .mk-handle svg { transition: transform 0.15s; }
|
|
587
|
+
.mobile-keys.mk-open .mk-handle svg { transform: rotate(180deg); }
|
|
578
588
|
.mobile-keys .mk-input {
|
|
579
589
|
display: flex; gap: 4px; flex: 1 1 100%;
|
|
580
590
|
}
|
|
@@ -630,7 +640,14 @@ import{cssVarsStyle as d}from"../theme.js";import{newSessionModalCSS as c,newSes
|
|
|
630
640
|
.sidebar.collapsed { max-height: 48px; overflow: hidden; }
|
|
631
641
|
.mobile-keys { display: flex; }
|
|
632
642
|
.mobile-keys .mk-buttons { display: none; }
|
|
633
|
-
|
|
643
|
+
/* Expanded state is explicit (remembered per browser) rather than tied to
|
|
644
|
+
input focus: tapping a key moves focus, which used to collapse the strip
|
|
645
|
+
after every press. */
|
|
646
|
+
.mobile-keys.mk-open .mk-buttons {
|
|
647
|
+
display: flex; flex-wrap: nowrap; gap: 4px;
|
|
648
|
+
overflow-x: auto; overscroll-behavior-x: contain;
|
|
649
|
+
-webkit-overflow-scrolling: touch;
|
|
650
|
+
}
|
|
634
651
|
}
|
|
635
652
|
|
|
636
653
|
/* Forced narrow layout (settings toggle): same rules as the 640px
|
|
@@ -642,8 +659,11 @@ import{cssVarsStyle as d}from"../theme.js";import{newSessionModalCSS as c,newSes
|
|
|
642
659
|
html.force-narrow .sidebar.collapsed { max-height: 48px; overflow: hidden; }
|
|
643
660
|
html.force-narrow .mobile-keys { display: flex; }
|
|
644
661
|
html.force-narrow .mobile-keys .mk-buttons { display: none; }
|
|
645
|
-
html.force-narrow .mobile-keys.mk-
|
|
646
|
-
|
|
662
|
+
html.force-narrow .mobile-keys.mk-open .mk-buttons {
|
|
663
|
+
display: flex; flex-wrap: nowrap; gap: 4px;
|
|
664
|
+
overflow-x: auto; overscroll-behavior-x: contain;
|
|
665
|
+
}
|
|
666
|
+
`,x=JSON.stringify(e.terminal).replace(/</g,"\\u003c"),p=JSON.stringify({terminal:r,scrollback:a,theme:e.terminal,fsRoots:i,wsBase:s||""}).replace(/</g,"\\u003c");return`<!DOCTYPE html>
|
|
647
667
|
<html lang="en">
|
|
648
668
|
<head>
|
|
649
669
|
<meta charset="UTF-8" />
|
|
@@ -691,9 +711,9 @@ import{cssVarsStyle as d}from"../theme.js";import{newSessionModalCSS as c,newSes
|
|
|
691
711
|
<aside class="sidebar">
|
|
692
712
|
<div class="sidebar-content" id="sidebar-content"></div>
|
|
693
713
|
<div class="sidebar-footer">
|
|
694
|
-
<button class="mode-btn active" id="mode-sessions" title="Sessions">${
|
|
695
|
-
<button class="mode-btn" id="mode-files" title="Files">${
|
|
696
|
-
<button class="mode-btn" id="mode-settings" title="Settings">${
|
|
714
|
+
<button class="mode-btn active" id="mode-sessions" title="Sessions">${n("sessions",'width="20" height="20"')}</button>
|
|
715
|
+
<button class="mode-btn" id="mode-files" title="Files">${n("folder",'width="20" height="20"')}</button>
|
|
716
|
+
<button class="mode-btn" id="mode-settings" title="Settings">${n("settings",'width="20" height="20"')}</button>
|
|
697
717
|
</div>
|
|
698
718
|
</aside>
|
|
699
719
|
|
|
@@ -731,6 +751,7 @@ import{cssVarsStyle as d}from"../theme.js";import{newSessionModalCSS as c,newSes
|
|
|
731
751
|
<textarea id="mk-input" placeholder="Type or voice input\u2026" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" rows="1"></textarea>
|
|
732
752
|
<button id="mk-send" type="button" title="Send (Enter)"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg></button>
|
|
733
753
|
</div>
|
|
754
|
+
<div class="mk-handle" id="mk-handle" role="button" tabindex="0" aria-pressed="false" title="Show/hide extra keys" aria-label="Show or hide extra keys"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 15l6-6 6 6"/></svg></div>
|
|
734
755
|
<div class="mk-buttons" id="mk-buttons">
|
|
735
756
|
<button data-key="esc">ESC</button>
|
|
736
757
|
<button data-key="tab">Tab</button>
|
|
@@ -855,24 +876,33 @@ ${g("__onSessionCreated")}
|
|
|
855
876
|
});
|
|
856
877
|
}
|
|
857
878
|
|
|
858
|
-
/* Mobile keys:
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
879
|
+
/* Mobile keys: collapsible strip, expanded by tapping the space under the
|
|
880
|
+
input. The expanded state is remembered per browser and does not depend on
|
|
881
|
+
input focus, so keys stay pressable without re-activating the text field. */
|
|
882
|
+
(function() {
|
|
883
|
+
var mobileKeys = document.getElementById('mobile-keys');
|
|
884
|
+
var mkHandle = document.getElementById('mk-handle');
|
|
885
|
+
if (!mobileKeys || !mkHandle) return;
|
|
886
|
+
var MK_OPEN_KEY = 'tmux-web-mk-open';
|
|
887
|
+
function stored() {
|
|
888
|
+
try { return localStorage.getItem(MK_OPEN_KEY) === '1'; } catch (e) { return false; }
|
|
889
|
+
}
|
|
890
|
+
function apply(open) {
|
|
891
|
+
mobileKeys.classList.toggle('mk-open', open);
|
|
892
|
+
mkHandle.setAttribute('aria-pressed', open ? 'true' : 'false');
|
|
893
|
+
}
|
|
894
|
+
apply(stored());
|
|
895
|
+
function toggle(e) {
|
|
896
|
+
if (e) { e.preventDefault(); e.stopPropagation(); }
|
|
897
|
+
var open = !mobileKeys.classList.contains('mk-open');
|
|
898
|
+
apply(open);
|
|
899
|
+
try { localStorage.setItem(MK_OPEN_KEY, open ? '1' : '0'); } catch (err) {}
|
|
900
|
+
}
|
|
901
|
+
mkHandle.addEventListener('click', toggle);
|
|
902
|
+
mkHandle.addEventListener('keydown', function(e) {
|
|
903
|
+
if (e.key === 'Enter' || e.key === ' ') toggle(e);
|
|
874
904
|
});
|
|
875
|
-
}
|
|
905
|
+
})();
|
|
876
906
|
})();
|
|
877
907
|
</script>
|
|
878
908
|
<script>
|