tmux-weblink 2.2.27 → 2.2.28
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 +21 -21
- package/dist/browser/shell-client.js +13 -13
- package/dist/lib/pages/shell.js +22 -1
- package/package.json +1 -1
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)}selectRows(t,s){let n=this.terminal.buffer.active,[
|
|
3
|
-
`)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function
|
|
4
|
-
\x1B[31m`+
|
|
5
|
-
`).then(()=>{
|
|
1
|
+
var bn=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function et(e){return e.replace(/\x1b\[\?1049[hl]/g,"")}function fe(e){return e.replace(bn,"")}var He;function En(){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 Ln=class Kt{terminal;fitAddon;container;constructor(t,s,n){this.container=t,this.terminal=s,this.fitAddon=n,this.terminal.loadAddon(this.fitAddon),this.terminal.open(t)}static async create(t,s,n){let[{Terminal:i},{FitAddon:r}]=await Promise.all([import("./xterm-BXEES47M.js"),import("./addon-fit-D5N335P2.js"),En()]),c=new i({fontSize:14,fontFamily:"'JetBrains Mono', 'SF Mono', 'Menlo', monospace",cursorBlink:!0,cursorStyle:"bar",scrollback:s,convertEol:!1,smoothScrollDuration:120,theme:n});return new Kt(t,c,new r)}get cols(){return this.terminal.cols}get rows(){return this.terminal.rows}write(t){return new Promise(s=>this.terminal.write(t,s))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom()}scrollToLine(t,s=!1){this.terminal.scrollToLine(Math.max(0,t),s)}scrollLines(t){let s=this.terminal.buffer?.active;this.terminal.scrollLines(t)}isNearScrollbackTop(){return this.terminal.buffer.active.viewportY<=1}viewportY(){return this.terminal.buffer.active.viewportY}baseY(){return this.terminal.buffer.active.baseY}fit(){let t=xn(this.container);if(t.width<=0||t.height<=0)return!1;let s=this.terminal._core?._renderService?.dimensions?.css?.cell;if(!s?.width||!s?.height)return this.fitAddon.fit(),!0;let n=s.width,i=s.height,r=this.terminal.element?.querySelector(".xterm-viewport"),c=r?Math.max(0,r.offsetWidth-r.clientWidth):0,o=Math.max(2,Math.floor((t.width-c-n/2)/n)),u=Math.max(2,Math.floor(t.height/i));return(o!==this.terminal.cols||u!==this.terminal.rows)&&this.terminal.resize(o,u),!0}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,s){let n=this.terminal.buffer.active,[i,r]=t<=s?[t,s]:[s,t],c=n.viewportY,o=[];for(let u=i;u<=r;u++){let m=n.getLine(c+u);o.push(m?m.translateToString(!0):"")}return o.join(`
|
|
2
|
+
`)}selectRows(t,s){let n=this.terminal.buffer.active,[i,r]=t<=s?[t,s]:[s,t];this.terminal.selectLines(n.viewportY+i,n.viewportY+r)}selectCells(t,s,n,i){let r=this.terminal.buffer.active,c=Math.min(s,i),o=Math.max(s,i);if(c===o){let u=Math.min(t,n),m=Math.max(t,n);this.terminal.select(u,r.viewportY+c,m-u+1)}else this.terminal.selectLines(r.viewportY+c,r.viewportY+o)}getCellsText(t,s,n,i){let r=this.terminal.buffer.active,c=Math.min(s,i),o=Math.max(s,i),u=s<i?t:s>i?n:Math.min(t,n),m=s<i?n:s>i?t:Math.max(t,n),B=r.viewportY,L=[];for(let F=c;F<=o;F++){let I=r.getLine(B+F);if(!I){L.push("");continue}let b=F===c?u:0,O=F===o?m:this.terminal.cols-1,ie="";for(let ke=b;ke<=O;ke++){let W=I.getCell(ke);W&&(ie+=W.getChars())}L.push(ie.replace(/\s+$/,""))}return L.join(`
|
|
3
|
+
`)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function xn(e){let t=e.getBoundingClientRect(),s=window.visualViewport;return s?{width:Math.min(t.width,s.width),height:Math.max(0,Math.min(t.height,s.height-Math.max(0,t.top)))}:t}function Cn(e,t,s){return e.innerHTML="",e.classList.add("terminal-pending"),(async()=>{let n=await Ln.create(e,s.scrollback,s.theme),i,r=0,c,o=null,u=0,m=0,B=.2,L=10,F=.95,I=.04,b=null,O=null;function ie(a){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=a?"\u2191 \u4E0A\u7FFB\u4E00\u9875 (PgUp)":"\u2193 \u4E0B\u7FFB\u4E00\u9875 (PgDn)",b.style.top=a?"10%":"auto",b.style.bottom=a?"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 W(){u&&(cancelAnimationFrame(u),u=0),m=0}function Vt(a){if(W(),Math.abs(a)<B)return;m=Math.max(-L,Math.min(L,a));let l=()=>{if(_){u=0;return}let d=e.querySelector(".xterm-rows > div"),p=d?d.getBoundingClientRect().height:16,v=p>0?Math.round(m*16/p):m>0?1:-1;v===0&&(v=m>0?1:-1);let A=n.viewportY()-v,X=n.baseY(),me=Math.max(0,Math.min(A,X));if(n.scrollToLine(me,!0),m*=F,me!==A){u=0;return}if(Math.abs(m)<I){u=0;return}u=requestAnimationFrame(l)};u=requestAnimationFrame(l)}let Se=0,$="connecting",Be=0,oe=!1,Te=[],Q="",_=!1,le=1e3,Xt=location.protocol==="https:"?"wss:":"ws:",dt=s.wsBase||"/ws",Jt=Xt+"//"+location.host+dt+"/"+encodeURIComponent(t),Zt=(dt.replace(/^\/ws/,"")||"")+"/api/session/"+encodeURIComponent(t)+"/upload",Gt=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function Qt(){return Te.join("")+Q}async function en(a,l=0){let d=a?n.viewportY():0,p=fe(Qt());if(n.reset(),!p){a||n.scrollToBottom();return}await n.write(p),a?n.scrollToLine(l+d):n.scrollToBottom()}function K(a){i?.readyState===WebSocket.OPEN&&i.send(JSON.stringify(a))}function tn(a){let l;try{l=JSON.parse(a)}catch{$==="live"&&(Q+=a,n.write(fe(a)));return}if(l.type==="auth.required"){let d=localStorage.getItem("tmux-web-token");d?K({type:"auth.token",token:d}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(l.type==="attach_failed"&&typeof l.message=="string"){Ie=!0,$="dead",n.reset(),n.write(`\r
|
|
4
|
+
\x1B[31m`+fe(l.message)+`\x1B[0m\r
|
|
5
|
+
`).then(()=>{Me();try{i?.close()}catch{}});return}if(l.type==="auth.ok"){l.token&&localStorage.setItem("tmux-web-token",l.token),le=1e3,V(),K({type:"resize",cols:n.cols,rows:n.rows}),T();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=et(fe(l.data));Te=[d],Q="",Be=typeof l.lines=="number"?l.lines:s.terminal.initialLines,$="live",n.reset(),V(),K({type:"resize",cols:n.cols,rows:n.rows}),n.write(d).then(()=>n.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?(Te.unshift(et(l.data)),Be+=l.lines,en(!0,l.lines).finally(()=>{oe=!1})):oe=!1;return}if(l.type==="data"&&typeof l.data=="string"){let d=et(fe(l.data));if($==="connecting"){$="live",Q=d,n.write(d);return}$==="live"&&(Q+=d,n.write(d))}}let Ie=!1;function ut(){if(Ie)return;let a=Jt,l=localStorage.getItem("tmux-web-token");l&&(a+=(a.includes("?")?"&":"?")+"token="+encodeURIComponent(l)),a+=(a.includes("?")?"&":"?")+"cols="+n.cols+"&rows="+n.rows,i=new WebSocket(a),i.onopen=()=>{$="connecting",Be=0,oe=!1,Te=[],Q="",n.reset(),le=1e3},i.onmessage=d=>{typeof d.data=="string"&&tn(d.data)},i.onclose=()=>{_||($="connecting",!Ie&&setTimeout(()=>{le=Math.min(le*2,1e4),!_&&!Ie&&ut()},le))},i.onerror=()=>i?.close()}function ee(a){K({type:"input",data:a})}function V(){return n.fit()}function Me(){e.classList.remove("terminal-pending")}function T(){r&&cancelAnimationFrame(r),c&&clearTimeout(c),V(),r=requestAnimationFrame(()=>{r=0,V()&&Me()}),c=setTimeout(()=>{V()&&Me()},120)}function nn(){T(),setTimeout(T,50),setTimeout(T,150),setTimeout(T,300)}function pt(a){return typeof a=="string"&&a.startsWith("image/")}function mt(a){return a?.files?.length?a.files[0]??null:null}function sn(a){if(!a?.items)return null;for(let l=0;l<a.items.length;l++){let d=a.items[l];if(d?.kind==="file"&&pt(d.type))return d.getAsFile()}return null}async function an(a){let l=new FormData,d=a instanceof File&&a.name?a.name:"upload";l.append("file",a,d);let p=localStorage.getItem("tmux-web-token"),v={};p&&(v.Authorization="Bearer "+p);let A=await fetch(Zt,{method:"POST",body:l,headers:v});if(!A.ok){let me="upload failed";try{let bt=await A.json();bt.error&&(me=bt.error)}catch{}throw new Error(me)}let X=await A.json();if(!X.path)throw new Error("no path in response");return X.path}async function Ze(a){try{let l=await an(a);ee(l)}catch{}}n.onData(a=>ee(a)),n.onResize(({cols:a,rows:l})=>K({type:"resize",cols:a,rows:l})),n.onScroll(()=>{$!=="live"||oe||!n.isNearScrollbackTop()||(oe=!0,K({type:"load_history",before:Be}))});let re=!1,ce=!1,E=null,x=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 ft(a,l){let d=e.querySelector(".xterm-screen, canvas"),p=(d&&d.getBoundingClientRect().width>0?d:e).getBoundingClientRect(),v=p.height>0&&n.rows>0?p.height/n.rows:18,A=p.width>0&&n.cols>0?p.width/n.cols:9;return{row:Math.max(0,Math.min(n.rows-1,Math.floor((l-p.top)/v))),col:Math.max(0,Math.min(n.cols-1,Math.floor((a-p.left)/A)))}}async function De(a){if(!a)return;try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(a);return}}catch{}let l=document.createElement("textarea");l.value=a,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 Fe(){z.hidden=!1,ue&&clearTimeout(ue),ue=setTimeout(()=>{z.hidden=!0},1e3)}function te(a){re=a,de.hidden=!a,e.classList.toggle("terminal-copy-mode-active",a),a&&n.focus()}function ht(){te(!re)}function on(a){_||a.button!==0||ce||(re||a.shiftKey)&&(a.preventDefault(),a.stopPropagation(),ce=!0,E=ft(a.clientX,a.clientY),x=E,n.selectCells(E.col,E.row,x.col,x.row),document.addEventListener("mousemove",Ge,!0),document.addEventListener("mouseup",Qe,!0))}function Ge(a){_||!ce||!E||(a.preventDefault(),a.stopPropagation(),x=ft(a.clientX,a.clientY),n.selectCells(E.col,E.row,x.col,x.row))}function Qe(a){if(_||!ce||!E||!x)return;a.preventDefault(),a.stopPropagation(),document.removeEventListener("mousemove",Ge,!0),document.removeEventListener("mouseup",Qe,!0),ce=!1;let l=n.getCellsText(E.col,E.row,x.col,x.row);E=null,x=null,n.clearSelection(),te(!1),l&&(z.textContent="\u5DF2\u590D\u5236",De(l).then(Fe)),n.focus()}e.addEventListener("mousedown",on,!0),document.addEventListener("keydown",ln,!0);function ln(a){if(!(_||!n.isFocused()||a.defaultPrevented||a.isComposing)){if(re){if(a.key==="Escape"){a.preventDefault(),a.stopPropagation(),E=null,x=null,n.clearSelection(),te(!1);return}if(a.key==="Enter"||(a.ctrlKey||a.metaKey)&&a.code==="KeyC"){a.preventDefault(),a.stopPropagation(),De(n.getScreenText()).then(Fe),te(!1);return}}if(a.altKey&&a.code==="KeyC"&&!a.ctrlKey&&!a.metaKey){if(a.preventDefault(),a.stopPropagation(),E&&x){let l=n.getCellsText(E.col,E.row,x.col,x.row);E=null,x=null,n.clearSelection(),te(!1),l&&(z.textContent="Copied",De(l).then(Fe))}else{let l=n.getSelection();l?(n.clearSelection(),z.textContent="Copied",De(l).then(Fe)):ht()}return}if((a.ctrlKey||a.metaKey)&&a.code==="KeyV"){a.preventDefault(),a.stopPropagation(),(async()=>{try{if(navigator.clipboard?.read){let l=await navigator.clipboard.read();for(let d of l)for(let p of d.types)if(pt(p)){let v=await d.getType(p);await Ze(v);return}}}catch{}try{let l=await navigator.clipboard?.readText();l&&n.pasteText(vt(l))}catch{}})();return}}}let Ae=0;function vt(a){return a.split(`\r
|
|
6
6
|
`).join(`
|
|
7
7
|
`).split(`
|
|
8
|
-
`).join("\r")}async function
|
|
8
|
+
`).join("\r")}async function rn(a){let l=sn(a.clipboardData);if(l){a.preventDefault(),a.stopPropagation();let v=Date.now();if(v-Ae<50)return;Ae=v,await Ze(l);return}let d=a.clipboardData?.getData("text/plain");if(!d)return;a.preventDefault(),a.stopPropagation();let p=Date.now();p-Ae<50||(Ae=p,n.pasteText(vt(d)))}let pe=0;function cn(a){a.preventDefault(),pe++,mt(a.dataTransfer)&&e.classList.add("terminal-drag-over")}function dn(a){a.preventDefault(),a.dataTransfer&&(a.dataTransfer.dropEffect="copy")}function un(a){a.preventDefault(),pe--,pe<=0&&(pe=0,e.classList.remove("terminal-drag-over"))}async function pn(a){a.preventDefault(),pe=0,e.classList.remove("terminal-drag-over");let l=mt(a.dataTransfer);l&&await Ze(l)}function gt(a){!Gt||a.key!=="Escape"||re||a.defaultPrevented||a.repeat||a.metaKey||a.ctrlKey||a.altKey||n.isFocused()&&(a.preventDefault(),a.stopPropagation(),ee("\x1B"))}e.addEventListener("paste",rn),e.addEventListener("dragenter",cn),e.addEventListener("dragover",dn),e.addEventListener("dragleave",un),e.addEventListener("drop",pn),document.addEventListener("keydown",gt,!0);function mn(a){if(a.touches.length!==1){o=null;return}let l=a.touches[0];if(!l)return;W();let d=e.getBoundingClientRect(),p=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:p,tuiUp:v,sent:!1},a.stopPropagation()}function fn(a){if(!o||a.touches.length!==1)return;let l=a.touches[0];if(!l)return;let d=l.clientY-o.startY,p=l.clientX-o.startX;if(!o.scrolling){if(Math.abs(d)<8||Math.abs(d)<Math.abs(p))return;o.scrolling=!0,Se=Date.now()+500}a.preventDefault(),a.stopPropagation();let v=performance.now(),A=l.clientY-o.lastY;if(o.zone==="tui"){o.sent||(o.sent=!0,ee(o.tuiUp?"\x1B[5~":"\x1B[6~"),ie(o.tuiUp)),o.lastX=l.clientX,o.lastY=l.clientY,o.lastT=v;return}let X=v-o.lastT;X>0&&(o.velocity=A/X),yn(-A),o.lastX=l.clientX,o.lastY=l.clientY,o.lastT=v}function hn(a){if(!o)return;let l=o.scrolling,d=o.zone,p=o.tuiUp,v=o.velocity;if(o=null,a.stopPropagation(),d==="tui"){l||(ee(p?"\x1B[5~":"\x1B[6~"),ie(p),Se=Date.now()+500,a.preventDefault());return}if(!l){n.focus();return}Se=Date.now()+500,a.preventDefault(),v&&Vt(v)}function vn(a){o=null,W(),a.stopPropagation()}function gn(a){a.pointerType==="touch"&&Date.now()<Se&&(a.preventDefault(),a.stopPropagation())}function yn(a){let l=e.querySelector(".xterm-rows > div"),d=l?l.getBoundingClientRect().height:16,p=d>0?Math.round(a/d):a>0?1:-1;p===0&&(p=a>0?1:-1),n.scrollLines(p)}e.addEventListener("touchstart",mn,{passive:!0,capture:!0}),e.addEventListener("touchmove",fn,{passive:!1,capture:!0}),e.addEventListener("touchend",hn,{passive:!1,capture:!0}),e.addEventListener("touchcancel",vn,{passive:!0,capture:!0}),e.addEventListener("pointerup",gn,!0);function yt(){T()}window.addEventListener("resize",yt),window.visualViewport?.addEventListener("resize",T),window.visualViewport?.addEventListener("scroll",T);let wt=new ResizeObserver(()=>T());wt.observe(e),document.fonts?.ready.then(()=>{T(),setTimeout(T,50),setTimeout(T,200)}),e.addEventListener("focusin",nn,!0);async function wn(){if(document.fonts?.ready)try{await Promise.race([document.fonts.ready,new Promise(a=>setTimeout(a,1e3))])}catch{}}return requestAnimationFrame(()=>{V()&&Me(),(async()=>(await wn(),V()&&K({type:"resize",cols:n.cols,rows:n.rows}),ut(),T()))()}),{destroy(){if(_=!0,W(),te(!1),ue&&clearTimeout(ue),document.removeEventListener("mousemove",Ge,!0),document.removeEventListener("mouseup",Qe,!0),i){try{i.close(1e3,"session switch")}catch{}i=void 0}e.innerHTML="",e.classList.remove("terminal-pending"),window.removeEventListener("resize",yt),wt.disconnect(),document.removeEventListener("keydown",gt,!0)},focus(){n.focus()},sendInput(a){ee(a)},toggleCopyMode(){ht()}}})()}var he=window.__TMUX_WEB_SHELL__,g=null,y=null,ve=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null,C=ve;window.__tmuxWebScopeAgent=ve;var tt="sessions",Y="",Ne="",Re="",Et="";function k(e){return C?"/a/"+encodeURIComponent(C)+e:e}var f=document.getElementById("sidebar-content"),J=document.getElementById("main-placeholder"),M=document.getElementById("terminal-container"),ge=document.getElementById("file-editor"),kn=document.getElementById("fe-path"),H=document.getElementById("fe-status"),ye=document.getElementById("fe-content"),Z=document.getElementById("fe-save"),Sn=document.getElementById("fe-delete"),Bn=document.getElementById("fe-back"),Lt=document.getElementById("fe-new-name"),Tn=document.getElementById("fe-new-btn"),nt=document.getElementById("settings-backdrop"),xt=document.getElementById("settings-popover"),Ct=document.querySelector(".sidebar"),kt="tmux-web-force-narrow";function Pe(){try{return localStorage.getItem(kt)==="1"}catch{return!1}}function St(){document.documentElement.classList.toggle("force-narrow",Pe()),Pe()&&Bt()&&$e()}function Bt(){return Pe()?!0:window.matchMedia("(max-width: 640px)").matches}function $e(){Bt()&&Ct.classList.add("collapsed")}function Tt(){Ct.classList.remove("collapsed")}document.getElementById("mode-sessions").addEventListener("click",()=>{Tt(),It("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{Tt(),It("files")});function It(e){tt=e,document.querySelectorAll(".mode-btn").forEach(s=>s.classList.remove("active"));let t=document.getElementById(e==="sessions"?"mode-sessions":"mode-files");t&&t.classList.add("active"),e==="sessions"?(st="",j()):_n()}var st="";async function j(){if(tt!=="sessions")return;try{let t=await(await fetch("/api/sidebar/sessions")).json(),s=JSON.stringify({recent:t.recent,agents:t.agents,tombstones:t.tombstones});if(s===st)return;st=s,An(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")}),ct()}var Mt="tmux-web-sidebar-group-collapsed";function Dt(){try{return new Set(JSON.parse(localStorage.getItem(Mt)||"[]"))}catch{return new Set}}function In(e){try{localStorage.setItem(Mt,JSON.stringify([...e]))}catch{}}function Mn(e,t,s){if(!e)return"\u2026";let n=s&&(e===s||e.startsWith(s+"/"))?"~"+e.slice(s.length):e,i=n.split("/").filter(Boolean);if(i.length===0)return e;for(let r=1;r<=i.length;r++){let c=i.slice(-r).join("/");if(!t.some(o=>!o||o===e?!1:(s&&(o===s||o.startsWith(s+"/"))?"~"+o.slice(s.length):o).split("/").filter(Boolean).slice(-r).join("/")===c))return c}return n}function Ft(e,t,s,n=!0){let i=new Map;for(let o of e){let u=o.path||"";i.has(u)||i.set(u,[]),i.get(u).push(o)}let r=[...i.keys()],c=Dt();for(let[o,u]of i){let m=Mn(o,r,t),B=c.has(o),L=document.createElement("div");L.className="session-group-header"+(B?" collapsed":""),L.title=o||"No working directory",L.innerHTML=`<span class="sg-folder">📁</span><span class="sg-label">${h(m)}</span>`,L.addEventListener("click",()=>{let I=Dt(),b=L.nextElementSibling;I.has(o)?(I.delete(o),L.classList.remove("collapsed"),b?.classList.remove("collapsed")):(I.add(o),L.classList.add("collapsed"),b?.classList.add("collapsed")),In(I)});let F=document.createElement("div");F.className="session-group-body"+(B?" collapsed":"");for(let I of u)F.appendChild(s?Dn(I,s,n):Fn(I));f.appendChild(L),f.appendChild(F)}}function Dn(e,t,s){let n=document.createElement("div");n.className="session-item"+(e.name===y&&C===t?" active":"")+(s?"":" session-offline"),n.setAttribute("data-session",e.name),n.setAttribute("data-agent",t),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>
|
|
9
9
|
<span>${h(e.name)}</span>${s?"":'<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>`,s&&n.addEventListener("click",r=>{r.target.closest(".session-edit-btn")||we(e.name,t)});let
|
|
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>`,s&&n.addEventListener("click",r=>{r.target.closest(".session-edit-btn")||we(e.name,t)});let i=n.querySelector(".session-edit-btn");return i&&i.addEventListener("click",r=>{r.stopPropagation(),Ve(e.name,i,{agentId:t})}),n}function Fn(e){let t=document.createElement("div");t.className="session-item"+(e.name===y&&!C?" 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",n=>{n.target.closest(".session-edit-btn")||we(e.name)});let s=t.querySelector(".session-edit-btn");return s&&s.addEventListener("click",n=>{n.stopPropagation(),
|
|
13
|
+
`,t.addEventListener("click",n=>{n.target.closest(".session-edit-btn")||we(e.name)});let s=t.querySelector(".session-edit-btn");return s&&s.addEventListener("click",n=>{n.stopPropagation(),Ve(e.name,s)}),t}function An(e){f.innerHTML='<button class="new-session-sidebar-btn" id="ns-btn">+ New Session</button>';let t=e.recent||[],s=document.createElement("div");s.className="sidebar-section-label"+(ve?" clickable":""),s.textContent=ve?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",ve&&(s.title="Back to hub",s.addEventListener("click",()=>{window.location.href="/"})),f.appendChild(s),Ft(t,e.home);let n=e.agents||[];for(let r of n){if(!r.sessions||r.sessions.length===0)continue;let c=r.agentId===C,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),Ft(r.sessions,e.home,r.agentId,r.online)}let i=e.tombstones||[];if(i.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 i){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 m=o.querySelector(".session-edit-btn");m&&m.addEventListener("click",B=>{B.stopPropagation(),Ve(c.name,m,{tombstone:!0,agentId:c.agentId})}),f.appendChild(o)}}}function h(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function we(e,t){if(y===e&&g&&C===(t||null))return;ge.style.display="none",J.style.display="none",M.style.display="",M.classList.add("terminal-pending"),$e(),g&&(We(),g.destroy(),g=null),y=e,C=t||null,window.__tmuxWebScopeAgent=C,window.__tmuxWebCurrentSession=y,ts(e,t);let s=rt(e,t);Ot.set(s,Date.now()+Qn);let n=ae.get(s);if(n&&n.state==="working"){n.state="idle",n.doneUntil=void 0,n.unread=!1;let i=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])');i&&Je(i,s,n)}for(let i of f.querySelectorAll(".session-item"))i.classList.toggle("active",i.getAttribute("data-session")===e&&(i.getAttribute("data-agent")||null)===C);try{g=await Cn(M,e,{terminal:he.terminal,scrollback:he.scrollback,theme:he.theme,wsBase:C?"/ws/a/"+encodeURIComponent(C):he.wsBase||"/ws"}),_t()}catch(i){console.error("[shell] terminal init failed:",i);let r=i&&typeof i=="object"&&"message"in i?i.message:String(i);M.textContent="Failed to open terminal for "+e+": "+r,M.classList.remove("terminal-pending")}}var ze=[],w=null,At=!1;function Hn(e){if(!w||!w.files.length)return null;let t=w.repoRoot;if(!t||!e.startsWith(t))return null;let s=e.slice(t.length+1);for(let n of w.files)if(n.path===s)return n.status;return null}async function Nn(e){At=!0;try{let t=await fetch(k("/api/git/status?path="+encodeURIComponent(e)));t.ok?w=await t.json():w=null}catch{w=null}finally{At=!1}}function Rn(){if(!w||!w.branch)return"";let{branch:e,linesAdded:t,linesRemoved:s}=w,n=`<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||s>0)&&(n+=`<div class="git-diff-stats">+<span class="add">${t}</span> <span class="del">-${s}</span></div>`),n+"</div>"}
|
|
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 s=0;s<e.length;s++){let n=e[s],
|
|
17
|
+
${h(e)}</div>`;return(t>0||s>0)&&(n+=`<div class="git-diff-stats">+<span class="add">${t}</span> <span class="del">-${s}</span></div>`),n+"</div>"}f.addEventListener("click",e=>{e.target.closest(".sidebar-git")&&ne&&w&&(e.stopPropagation(),$t())});var be=document.getElementById("header-git"),Ht=document.getElementById("git-diff-view"),Nt=document.getElementById("gd-path"),je=document.getElementById("gd-status"),Ue=document.getElementById("gd-content"),Pn=document.getElementById("gd-back"),ne=null;function Ee(e){if(!e||!e.branch){be.style.display="none",ne=null;return}ne=e.repoRoot;let{branch:t,linesAdded:s,linesRemoved:n}=e,i=`<span class="branch">${h(t)}</span>`;(s>0||n>0)&&(i+=`<span class="sep">\xB7</span>+<span class="diff-add">${s}</span> <span class="diff-del">-${n}</span>`),be.innerHTML=i,be.style.display="block"}be.addEventListener("click",e=>{ne&&w&&(e.stopPropagation(),$t())});var S=document.getElementById("git-popover"),_e=document.getElementById("git-popover-backdrop");function at(){let e=be.getBoundingClientRect();S.style.top=e.bottom+4+"px",S.style.left=Math.max(8,Math.min(e.left,window.innerWidth-400))+"px"}function Rt(){let e=ne,t=document.getElementById("git-popover-browse");t&&t.addEventListener("click",()=>{if(qe(),e){tt="files",document.querySelectorAll(".mode-btn").forEach(n=>n.classList.remove("active"));let s=document.getElementById("mode-files");s&&s.classList.add("active"),q(e)}})}var Pt="";function $t(){if(!w)return;let e=w.files||[];if(!e.length)S.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
|
|
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 s=0;s<e.length;s++){let n=e[s],i=n.additions||0,r=n.deletions||0,c="";switch(n.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="${s}">
|
|
19
19
|
${c}<span class="file-path">${h(n.path)}</span>
|
|
20
|
-
<span class="file-add">${
|
|
20
|
+
<span class="file-add">${i>0?"+"+i:""}</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>',Pt=t,S.innerHTML=t,S.querySelectorAll(".git-popover-item").forEach(s=>{let n=parseInt(s.dataset.idx||"0",10),i=e[n];!i||i.status==="D"||(s.classList.add("clickable"),s.style.cursor="pointer",s.addEventListener("click",()=>jt(i.path)))})}at(),S.classList.add("open"),_e.classList.add("open"),Rt()}function $n(){return window.innerWidth>=1024}function zt(e,t){let s=(e+(t&&e?`
|
|
23
23
|
`:"")+t).split(`
|
|
24
|
-
`),n="",
|
|
24
|
+
`),n="",i=0,r=0;for(let c of s){let o=c;if(o.startsWith("@@")){let u=o.match(/@@\s+-(\d+)[^+]*\+(\d+)/);u&&(i=parseInt(u[1],10)-1,r=parseInt(u[2],10)-1),n+=`<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")&&(n+=`<div class="diff-line header"><span class="ln-body">${h(o)}</span></div>`);continue}if(o.startsWith("+"))r++,n+=`<div class="diff-line add"><span class="ln-no">${r}</span><span class="ln-body">${h(o)}</span></div>`;else if(o.startsWith("-"))i++,n+=`<div class="diff-line del"><span class="ln-no">${i}</span><span class="ln-body">${h(o)}</span></div>`;else if(o.startsWith("\\"))n+=`<div class="diff-line"><span class="ln-body">${h(o)}</span></div>`;else{if(!o&&!i&&!r)continue;i++,r++,n+=`<div class="diff-line"><span class="ln-no">${i}</span><span class="ln-no" style="margin-right:12px">${r}</span><span class="ln-body">${h(o)}</span></div>`}}return{html:n,lineCount:s.length}}var Ye=null;async function jt(e){let t=ne;if(t)if(qe(),$n()){M.style.display="none",g&&(We(),g.destroy(),g=null,Ye=y,y=null),Ee(null),ge.style.display="none",J.style.display="none",Ht.style.display="flex",Nt.textContent=e,je.textContent="Loading\u2026",Ue.innerHTML="";try{let s=await fetch(k("/api/git/diff?path="+encodeURIComponent(t)+"&file="+encodeURIComponent(e)));if(!s.ok)throw new Error(await s.text());let n=await s.json();jn(e,n.diff,n.stagedDiff)}catch(s){let n=s instanceof Error?s.message:String(s);je.textContent="Error",Ue.innerHTML=`<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">Error: ${h(n)}</div>`}}else{S.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>`,at(),S.classList.add("open"),_e.classList.add("open");try{let s=await fetch(k("/api/git/diff?path="+encodeURIComponent(t)+"&file="+encodeURIComponent(e)));if(!s.ok)throw new Error(await s.text());let n=await s.json();zn(e,n.diff,n.stagedDiff)}catch(s){let n=s instanceof Error?s.message:String(s);S.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(n)}</div></div>`}}}function
|
|
31
|
+
</div><div class="diff-empty">Error loading diff: ${h(n)}</div></div>`}}}function zn(e,t,s){if(!t&&!s){S.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:n,lineCount:
|
|
34
|
+
</div><div class="diff-empty">No diff content available</div></div>`;return}let{html:n,lineCount:i}=zt(t,s);S.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
|
-
<span class="diff-filesize">${
|
|
38
|
-
</div><div class="diff-content">${n}</div></div>`,S.querySelector(".diff-back")?.addEventListener("click",()=>{S.innerHTML=
|
|
37
|
+
<span class="diff-filesize">${i} lines</span>
|
|
38
|
+
</div><div class="diff-content">${n}</div></div>`,S.querySelector(".diff-back")?.addEventListener("click",()=>{S.innerHTML=Pt,at(),w&&S.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",()=>jt(o.path)))}),Rt()})}function jn(e,t,s){if(!t&&!s){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:n,lineCount:i}=zt(t,s);Nt.textContent=e,je.textContent=i+" lines",Ue.innerHTML=n}function Un(){Ht.style.display="none",Ye?(M.style.display="",M.classList.add("terminal-pending"),we(Ye),Ye=null):y?(M.style.display="",M.classList.add("terminal-pending"),_t()):J.style.display="flex"}Pn.addEventListener("click",Un);function qe(){S.classList.remove("open"),_e.classList.remove("open")}_e.addEventListener("click",qe),document.addEventListener("keydown",e=>{e.key==="Escape"&&(qe(),Xe())});async function Ut(e){try{let t=await(await fetch("/api/fs/session-path?session="+encodeURIComponent(e))).json();if(t.path){let s=await fetch("/api/git/status?path="+encodeURIComponent(t.path));if(s.ok){let n=await s.json();w=n,Ee(n);return}}}catch{}w=null,Ee(null)}var Oe=null;function _t(){We(),y&&(Ut(y),Oe=setInterval(()=>{y&&Ut(y)},3e4))}function We(){Oe&&(clearInterval(Oe),Oe=null)}function _n(){if(ze=he.fsRoots||[],ze.length===0){if(y){Yn(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 Yn(e){f.innerHTML='<div class="file-tree-empty">Loading...</div>';try{let t=await(await fetch(k("/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=Nn(e);try{let s=await(await fetch(k("/api/fs/list?path="+encodeURIComponent(e)))).json();await t,f.innerHTML="",Ee(w),f.innerHTML+=Rn();let n=qn(e);if(n&&!ze.some(r=>e===r)){let r=document.createElement("div");r.className="file-tree-item",r.innerHTML="..",r.addEventListener("click",()=>q(n)),f.appendChild(r)}if(s.dirs)for(let r of s.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 i=s.files||[];for(let r of i){let c=r.split("/").pop()||r.split("\\").pop(),o=Hn(r),u="",m="";if(o)switch(o){case"M":u="git-mod",m='<span class="git-file-status M">M</span>';break;case"A":u="git-add",m='<span class="git-file-status A">A</span>';break;case"D":u="git-del",m='<span class="git-file-status D">D</span>';break;case"?":u="git-untracked",m='<span class="git-file-status ?">?</span>';break;case"R":u="git-mod",m='<span class="git-file-status R">R</span>';break}let B=document.createElement("div");B.className="file-tree-item file"+(u?" "+u:""),B.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${m}${h(c)}`,B.addEventListener("click",()=>On(r)),f.appendChild(B)}}catch{f.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function qn(e){let t=e.lastIndexOf("/");return t<=0?null:e.substring(0,t)}async function On(e){Ne=e,M.style.display="none",g&&(We(),g.destroy(),g=null,y=null),Ee(null),$e(),J.style.display="none",ge.style.display="flex",kn.textContent=e,H.textContent="Loading...",Z.style.display="none";try{let t=await fetch(k("/api/file?path="+encodeURIComponent(e)));if(!t.ok){let n=await t.json();H.textContent=n.error||"Failed to load",ye.value="";return}let s=await t.json();ye.value=s.content,Re=s.content,Et=s.content,H.textContent=s.size+" bytes",Z.style.display=""}catch{H.textContent="Failed to load",ye.value=""}}ye.addEventListener("input",()=>{Re=ye.value}),Z.addEventListener("click",async()=>{Z.textContent="Saving...",Z.disabled=!0;try{let e=await fetch(k("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Ne,content:Re})});if(!e.ok){let t=await e.json();H.textContent=t.error||"Save failed";return}Et=Re,H.textContent="Saved"}catch{H.textContent="Save failed"}finally{Z.disabled=!1,Z.textContent="Save"}}),Sn.addEventListener("click",async()=>{if(confirm("Delete "+Ne+"?"))try{let e=await fetch(k("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Ne})});if(!e.ok){let t=await e.json();H.textContent=t.error||"Delete failed";return}ge.style.display="none",J.style.display="flex",Y&&q(Y)}catch{H.textContent="Delete failed"}}),Bn.addEventListener("click",()=>{ge.style.display="none",J.style.display="flex",Y&&q(Y)}),Tn.addEventListener("click",async()=>{let e=Lt.value.trim();if(!e)return;let t=Y+"/"+e;try{let s=await fetch(k("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!s.ok){let n=await s.json();H.textContent=n.error||"Create failed";return}Lt.value="",Y&&q(Y)}catch{H.textContent="Create failed"}});var Ke=document.getElementById("force-narrow-toggle");Ke&&(Ke.checked=Pe(),Ke.addEventListener("change",()=>{try{localStorage.setItem(kt,Ke.checked?"1":"0")}catch{}St(),j()})),St(),document.getElementById("mode-settings").addEventListener("click",()=>{let e=xt.classList.toggle("open");nt.classList.toggle("open",e)}),nt.addEventListener("click",()=>{xt.classList.remove("open"),nt.classList.remove("open")});var D="",U=!1,N,Le=document.createElement("div");Le.className="session-popover-backdrop",document.body.appendChild(Le);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 hn=/\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;P.rows=Math.min(e,4)}),P.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 Wn(e){let t=e.getBoundingClientRect(),s=window.innerHeight,n=R.offsetHeight||240,i=t.bottom+4;i+n>s-8&&(i=Math.max(8,t.top-n-4)),R.style.top=i+"px",R.style.left=Math.max(8,Math.min(t.left,window.innerWidth-240))+"px"}function Ve(e,t,s){D=e,U=!!s?.tombstone,N=s?.agentId;let n=document.getElementById("sp-name");n.value=e;let i=R.querySelector(".sp-field label");i.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",Le.classList.add("open"),R.style.display="block",Wn(t),setTimeout(()=>n.focus(),50)}function G(){Le.classList.remove("open"),R.style.display="none"}Le.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:N}:{oldName:D,newName:e,...N?{agentId:N}:{}};if(!(await fetch(k(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&&(N??null)===C&&we(e,N)}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(k("/api/sessions/rebuild"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:D,agentId:N})});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(k("/api/sessions/dismiss"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:D,agentId:N})})).ok)return;G(),j()}catch{}return}if(confirm('Delete session "'+D+'"?'))try{if(!(await fetch(k("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:D,...N?{agentId:N}:{}})})).ok)return;G(),y===D&&(N??null)===C&&(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 Kn={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"};document.getElementById("mobile-keys").addEventListener("click",e=>{let t=e.target.closest("button[data-key]");if(!t||!g)return;let s=Kn[t.dataset.key];s&&(g.sendInput(s),g.focus())});var P=document.getElementById("mk-input"),Yt=document.getElementById("mk-send");function qt(){if(!P||!g)return;let e=P.value;e&&(g.sendInput(e+"\r"),P.value="",P.rows=1,g.focus())}if(P&&(P.addEventListener("input",()=>{P.rows=1;let e=P.value.split(`
|
|
49
|
+
`).length;P.rows=Math.min(e,4)}),P.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),qt())})),Yt&&Yt.addEventListener("click",qt),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 it=document.getElementById("process-panel"),xe=document.getElementById("proc-list"),Vn=document.getElementById("proc-close"),ot=document.getElementById("proc-backdrop"),Xn=document.getElementById("header-ram");function Jn(){xe.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(k("/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 s of e){let n=s.rss,i=n<1048576?(n/1024).toFixed(0)+"K":(n/1048576).toFixed(1)+"M";t+='<div class="proc-row" data-pid="'+s.pid+'"><span class="proc-mem">'+s.mem+'%</span><span class="proc-rss">'+i+'</span><span class="proc-cmd" title="'+h(s.command)+'">'+h(s.command)+'</span><button class="proc-kill" title="Kill PID '+s.pid+'">×</button></div>'}xe.innerHTML=t;for(let s of xe.querySelectorAll(".proc-row")){let n=s.querySelector(".proc-kill");n&&n.addEventListener("click",i=>{let r=i.target.closest(".proc-row");!r||!confirm("Kill PID "+r.dataset.pid+"?")||fetch(k("/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 Zn(){it.classList.add("open"),ot.classList.add("open"),Jn()}function Xe(){it.classList.remove("open"),ot.classList.remove("open")}Xn.addEventListener("click",e=>{e.stopPropagation(),it.classList.contains("open")?Xe():Zn()}),Vn.addEventListener("click",Xe),ot.addEventListener("click",Xe);var Gn=2e3,Ce=null,lt=null,se=new Map,ae=new Map,Qn=5e3,Ot=new Map;function rt(e,t){return(t?"a:"+t+":":"l:")+e}function es(e,t,s){let n=rt(e,t);if(s==="working"){let m=Ot.get(n);if(m&&Date.now()<m)return}let i=ae.get(n),r=e===y&&(t??null)===C,c=s==="idle"&&i?.state==="working";ae.set(n,{session:e,agentId:t,state:s,doneUntil:c?Date.now()+Gn: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&&Je(u,n,ae.get(n))}function Je(e,t,s){let n=se.get(t);n&&(clearTimeout(n),se.delete(t)),e.classList.remove("working","just-done");let i=s.session===y&&(s.agentId??null)===C;s.state==="working"?e.classList.add("working"):i&&s.doneUntil&&Date.now()<s.doneUntil?(e.classList.add("just-done"),se.set(t,setTimeout(()=>{e.classList.remove("just-done"),se.delete(t)},Math.max(0,s.doneUntil-Date.now())))):!i&&s.unread&&e.classList.add("just-done")}function ct(){for(let[e,t]of ae){let s=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])',n=f.querySelector(s);n&&Je(n,e,t)}}function ts(e,t){let s=rt(e,t),n=ae.get(s);if(!n)return;let i=se.get(s);i&&(clearTimeout(i),se.delete(s)),n.doneUntil=void 0,n.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&&Je(c,s,n)}function Wt(){if(Ce||lt)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 s=new WebSocket(t);Ce=s,s.onmessage=n=>{try{let i=JSON.parse(String(n.data));i&&i.type==="session.activity"&&typeof i.session=="string"&&es(i.session,i.agentId||void 0,i.state==="working"?"working":"idle")}catch{}},s.onclose=()=>{Ce===s&&(Ce=null,lt=setTimeout(()=>{lt=null,Wt()},5e3))},s.onerror=()=>{try{s.close()}catch{}}}catch{Ce=null}}window.__openSession=we,window.__refreshSidebar=j,j(),$e(),ct(),Wt(),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&ct()}),setInterval(()=>{document.visibilityState==="visible"&&j()},1e4);
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import{initTerminal as
|
|
1
|
+
import{initTerminal as qe}from"./terminal-core.js";const D=window.__TMUX_WEB_SHELL__;let f=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 de="sessions",x="",V="",J="",we="";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"),Ve=document.getElementById("fe-path"),E=document.getElementById("fe-status"),O=document.getElementById("fe-content"),N=document.getElementById("fe-save"),Je=document.getElementById("fe-delete"),Ke=document.getElementById("fe-back"),Le=document.getElementById("fe-new-name"),Ye=document.getElementById("fe-new-btn"),pe=document.getElementById("settings-backdrop"),Ee=document.getElementById("settings-popover"),ke=document.querySelector(".sidebar"),Se="tmux-web-force-narrow";function K(){try{return localStorage.getItem(Se)==="1"}catch{return!1}}function Ce(){document.documentElement.classList.toggle("force-narrow",K()),K()&&Ie()&&Y()}function Ie(){return K()?!0:window.matchMedia("(max-width: 640px)").matches}function Y(){Ie()&&ke.classList.add("collapsed")}function Be(){ke.classList.remove("collapsed")}document.getElementById("mode-sessions").addEventListener("click",()=>{Be(),xe("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{Be(),xe("files")});function xe(e){de=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"?(fe="",I()):dt()}let fe="";async function I(){if(de!=="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===fe)return;fe=s,tt(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")}),he()}const Me="tmux-web-sidebar-group-collapsed";function Te(){try{return new Set(JSON.parse(localStorage.getItem(Me)||"[]"))}catch{return new Set}}function Xe(e){try{localStorage.setItem(Me,JSON.stringify([...e]))}catch{}}function Ze(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 He(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=Te();for(const[l,c]of i){const p=Ze(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(p)}</span>`,h.addEventListener("click",()=>{const T=Te(),be=h.nextElementSibling;T.has(l)?(T.delete(l),h.classList.remove("collapsed"),be?.classList.remove("collapsed")):(T.add(l),h.classList.add("collapsed"),be?.classList.add("collapsed")),Xe(T)});const re=document.createElement("div");re.className="session-group-body"+(L?" collapsed":"");for(const T of c)re.appendChild(t?Qe(T,t,s):et(T));r.appendChild(h),r.appendChild(re)}}function Qe(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(),ae(e.name,i,{agentId:n})}),s}function et(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(),ae(e.name,t)}),n}function tt(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),He(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),He(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",()=>{ae(a.name,l,{tombstone:!0,agentId:a.agentId})});const p=l.querySelector(".session-edit-btn");p&&p.addEventListener("click",L=>{L.stopPropagation(),ae(a.name,p,{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&&f&&g===(n||null))return;j.style.display="none",H.style.display="none",b.style.display="",b.classList.add("terminal-pending"),Y(),f&&(ie(),f.destroy(),f=null),u=e,g=n||null,window.__tmuxWebScopeAgent=g,window.__tmuxWebCurrentSession=u,kt(e,n);const t=ye(e,n);Fe.set(t,Date.now()+Lt);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&&ce(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{f=await qe(b,e,{terminal:D.terminal,scrollback:D.scrollback,theme:D.theme,wsBase:g?"/ws/a/"+encodeURIComponent(g):D.wsBase||"/ws"}),Ue()}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 X=[],m=null,Ne=!1;function nt(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 st(e){Ne=!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{Ne=!1}}function it(){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")&&$&&m&&(e.stopPropagation(),
|
|
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")&&$&&m&&(e.stopPropagation(),De())});const W=document.getElementById("header-git"),Re=document.getElementById("git-diff-view"),$e=document.getElementById("gd-path"),Z=document.getElementById("gd-status"),Q=document.getElementById("gd-content"),ot=document.getElementById("gd-back");let $=null;function z(e){if(!e||!e.branch){W.style.display="none",$=null;return}$=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=>{$&&m&&(e.stopPropagation(),De())});const y=document.getElementById("git-popover"),ee=document.getElementById("git-popover-backdrop");function ue(){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 Ae(){const e=$,n=document.getElementById("git-popover-browse");n&&n.addEventListener("click",()=>{if(ne(),e){de="files",document.querySelectorAll(".mode-btn").forEach(s=>s.classList.remove("active"));const t=document.getElementById("mode-files");t&&t.classList.add("active"),M(e)}})}let _e="";function De(){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>',_e=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",()=>je(i.path)))})}ue(),y.classList.add("open"),ee.classList.add("open"),Ae()}function at(){return window.innerWidth>=1024}function Pe(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 p=c.match(/@@\s+-(\d+)[^+]*\+(\d+)/);p&&(o=parseInt(p[1],10)-1,a=parseInt(p[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
|
|
17
|
+
`);let i="",o=0,a=0;for(const l of s){const c=l;if(c.startsWith("@@")){const p=c.match(/@@\s+-(\d+)[^+]*\+(\d+)/);p&&(o=parseInt(p[1],10)-1,a=parseInt(p[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 te=null;async function je(e){const n=$;if(n)if(ne(),at()){b.style.display="none",f&&(ie(),f.destroy(),f=null,te=u,u=null),z(null),j.style.display="none",H.style.display="none",Re.style.display="flex",$e.textContent=e,Z.textContent="Loading\u2026",Q.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();ct(e,s.diff,s.stagedDiff)}catch(t){const s=t instanceof Error?t.message:String(t);Z.textContent="Error",Q.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>`,ue(),y.classList.add("open"),ee.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();lt(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 lt(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}=Pe(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=_e,ue(),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",()=>je(l.path)))}),Ae()})}function ct(e,n,t){if(!n&&!t){Z.textContent="No diff",Q.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}=Pe(n,t);$e.textContent=e,Z.textContent=i+" lines",Q.innerHTML=s}function rt(){Re.style.display="none",te?(b.style.display="",b.classList.add("terminal-pending"),U(te),te=null):u?(b.style.display="",b.classList.add("terminal-pending"),Ue()):H.style.display="flex"}ot.addEventListener("click",rt);function ne(){y.classList.remove("open"),ee.classList.remove("open")}ee.addEventListener("click",ne),document.addEventListener("keydown",e=>{e.key==="Escape"&&(ne(),le())});async function Oe(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 se=null;function Ue(){ie(),u&&(Oe(u),se=setInterval(()=>{u&&Oe(u)},3e4))}function ie(){se&&(clearInterval(se),se=null)}function dt(){if(X=D.fsRoots||[],X.length===0){if(u){pt(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 X){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",()=>M(e)),r.appendChild(n)}}async function pt(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?M(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 M(e){x=e,r.innerHTML='<div class="file-tree-empty">Loading...</div>';const n=st(e);try{const s=await(await fetch(v("/api/fs/list?path="+encodeURIComponent(e)))).json();await n,r.innerHTML="",z(m),r.innerHTML+=it();const i=ft(e);if(i&&!X.some(l=>e===l)){const l=document.createElement("div");l.className="file-tree-item",l.innerHTML="..",l.addEventListener("click",()=>M(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",()=>M(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=nt(a);let p="",L="";if(c)switch(c){case"M":p="git-mod",L='<span class="git-file-status M">M</span>';break;case"A":p="git-add",L='<span class="git-file-status A">A</span>';break;case"D":p="git-del",L='<span class="git-file-status D">D</span>';break;case"?":p="git-untracked",L='<span class="git-file-status ?">?</span>';break;case"R":p="git-mod",L='<span class="git-file-status R">R</span>';break}const h=document.createElement("div");h.className="file-tree-item file"+(p?" "+p:""),h.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${L}${d(l)}`,h.addEventListener("click",()=>ut(a)),r.appendChild(h)}}catch{r.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function ft(e){const n=e.lastIndexOf("/");return n<=0?null:e.substring(0,n)}async function ut(e){V=e,b.style.display="none",f&&(ie(),f.destroy(),f=null,u=null),z(null),Y(),H.style.display="none",j.style.display="flex",Ve.textContent=e,E.textContent="Loading...",N.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,J=t.content,we=t.content,E.textContent=t.size+" bytes",N.style.display=""}catch{E.textContent="Failed to load",O.value=""}}O.addEventListener("input",()=>{J=O.value}),N.addEventListener("click",async()=>{N.textContent="Saving...",N.disabled=!0;try{const e=await fetch(v("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:V,content:J})});if(!e.ok){const n=await e.json();E.textContent=n.error||"Save failed";return}we=J,E.textContent="Saved"}catch{E.textContent="Save failed"}finally{N.disabled=!1,N.textContent="Save"}}),Je.addEventListener("click",async()=>{if(confirm("Delete "+V+"?"))try{const e=await fetch(v("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:V})});if(!e.ok){const n=await e.json();E.textContent=n.error||"Delete failed";return}j.style.display="none",H.style.display="flex",x&&M(x)}catch{E.textContent="Delete failed"}}),Ke.addEventListener("click",()=>{j.style.display="none",H.style.display="flex",x&&M(x)}),Ye.addEventListener("click",async()=>{const e=Le.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}Le.value="",x&&M(x)}catch{E.textContent="Create failed"}});const oe=document.getElementById("force-narrow-toggle");oe&&(oe.checked=K(),oe.addEventListener("change",()=>{try{localStorage.setItem(Se,oe.checked?"1":"0")}catch{}Ce(),I()})),Ce(),document.getElementById("mode-settings").addEventListener("click",()=>{const e=Ee.classList.toggle("open");pe.classList.toggle("open",e)}),pe.addEventListener("click",()=>{Ee.classList.remove("open"),pe.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 Ue}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 mt(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 ae(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",mt(n),setTimeout(()=>s.focus(),50)}function R(){F.classList.remove("open"),S.style.display="none"}F.addEventListener("click",R),document.getElementById("sp-save").addEventListener("click",async()=>{const e=document.getElementById("sp-name").value.trim();if(!e||e===w){R();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;R(),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}R(),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;R(),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;R(),u===w&&(k??null)===g&&(f&&(f.destroy(),f=null),u=null,b.style.display="none",H.style.display="flex"),I()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",R);const gt={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"};document.getElementById("mobile-keys").addEventListener("click",e=>{const n=e.target.closest("button[data-key]");if(!n||!f)return;const t=gt[n.dataset.key];t&&(f.sendInput(t),f.focus())});const C=document.getElementById("mk-input"),We=document.getElementById("mk-send");function ze(){if(!C||!f)return;const e=C.value;e&&(f.sendInput(e+"\r"),C.value="",C.rows=1,f.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(),ze())})),We&&We.addEventListener("click",ze),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 me=document.getElementById("process-panel"),G=document.getElementById("proc-list"),vt=document.getElementById("proc-close"),ge=document.getElementById("proc-backdrop"),yt=document.getElementById("header-ram");function ht(){G.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){G.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>'}G.innerHTML=n;for(const t of G.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(()=>{G.innerHTML='<div class="proc-empty">Failed to load</div>'})}function bt(){me.classList.add("open"),ge.classList.add("open"),ht()}function le(){me.classList.remove("open"),ge.classList.remove("open")}yt.addEventListener("click",e=>{e.stopPropagation(),me.classList.contains("open")?le():bt()}),vt.addEventListener("click",le),ge.addEventListener("click",le);const wt=2e3;let q=null,ve=null;const A=new Map,_=new Map,Lt=5e3,Fe=new Map;function ye(e,n){return(n?"a:"+n+":":"l:")+e}function Et(e,n,t){const s=ye(e,n);if(t==="working"){const p=Fe.get(s);if(p&&Date.now()<p)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()+wt: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&&ce(c,s,_.get(s))}function ce(e,n,t){const s=A.get(n);s&&(clearTimeout(s),A.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"),A.set(n,setTimeout(()=>{e.classList.remove("just-done"),A.delete(n)},Math.max(0,t.doneUntil-Date.now())))):!i&&t.unread&&e.classList.add("just-done")}function he(){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&&ce(s,e,n)}}function kt(e,n){const t=ye(e,n),s=_.get(t);if(!s)return;const i=A.get(t);i&&(clearTimeout(i),A.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&&ce(a,t,s)}function Ge(){if(q||ve)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);q=s,s.onmessage=i=>{try{const o=JSON.parse(String(i.data));o&&o.type==="session.activity"&&typeof o.session=="string"&&Et(o.session,o.agentId||void 0,o.state==="working"?"working":"idle")}catch{}},s.onclose=()=>{q===s&&(q=null,ve=setTimeout(()=>{ve=null,Ge()},5e3))},s.onerror=()=>{try{s.close()}catch{}}}catch{q=null}}window.__openSession=U,window.__refreshSidebar=I,I(),Y(),he(),Ge(),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&he()}),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 i}from"../icons.js";function
|
|
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 i}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:n,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);
|
|
@@ -449,6 +449,12 @@ import{cssVarsStyle as d}from"../theme.js";import{newSessionModalCSS as c,newSes
|
|
|
449
449
|
padding: 8px;
|
|
450
450
|
}
|
|
451
451
|
.settings-popover.open { display: block; }
|
|
452
|
+
.force-narrow-row {
|
|
453
|
+
display: flex; align-items: center; justify-content: space-between; gap: 12px;
|
|
454
|
+
padding: 10px 12px; cursor: pointer; font-size: var(--text-sm); color: var(--page-fg);
|
|
455
|
+
}
|
|
456
|
+
.force-narrow-row:hover { background: color-mix(in srgb, var(--panel-accent) 8%, transparent); }
|
|
457
|
+
.force-narrow-row input { width: 16px; height: 16px; accent-color: var(--panel-accent); cursor: pointer; }
|
|
452
458
|
.settings-item {
|
|
453
459
|
display: flex; align-items: center; justify-content: space-between;
|
|
454
460
|
padding: 10px 12px; border-radius: 8px;
|
|
@@ -626,6 +632,17 @@ import{cssVarsStyle as d}from"../theme.js";import{newSessionModalCSS as c,newSes
|
|
|
626
632
|
.mobile-keys .mk-buttons { display: none; }
|
|
627
633
|
.mobile-keys.mk-focused .mk-buttons { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
628
634
|
}
|
|
635
|
+
|
|
636
|
+
/* Forced narrow layout (settings toggle): same rules as the 640px
|
|
637
|
+
breakpoint, applied unconditionally when the html has .force-narrow. */
|
|
638
|
+
html.force-narrow .app-layout { flex-direction: column; }
|
|
639
|
+
html.force-narrow .sidebar { flex: 0 0 auto; border-right: none; border-bottom: 1px solid var(--panel-border); transition: max-height 0.2s; }
|
|
640
|
+
html.force-narrow .sidebar.collapsed .sidebar-content { display: none; }
|
|
641
|
+
html.force-narrow .sidebar.collapsed .sidebar-footer { display: none; }
|
|
642
|
+
html.force-narrow .sidebar.collapsed { max-height: 48px; overflow: hidden; }
|
|
643
|
+
html.force-narrow .mobile-keys { display: flex; }
|
|
644
|
+
html.force-narrow .mobile-keys .mk-buttons { display: none; }
|
|
645
|
+
html.force-narrow .mobile-keys.mk-focused .mk-buttons { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
629
646
|
`,x=JSON.stringify(e.terminal).replace(/</g,"\\u003c"),p=JSON.stringify({terminal:r,scrollback:a,theme:e.terminal,fsRoots:n,wsBase:s||""}).replace(/</g,"\\u003c");return`<!DOCTYPE html>
|
|
630
647
|
<html lang="en">
|
|
631
648
|
<head>
|
|
@@ -742,6 +759,10 @@ import{cssVarsStyle as d}from"../theme.js";import{newSessionModalCSS as c,newSes
|
|
|
742
759
|
<button class="theme-option" data-theme="warm-clay" title="Warm Clay"><span class="theme-dot" style="background:#b86b52"></span>Warm Clay${e.template==="warm-clay"?'<span class="theme-check">\u2713</span>':""}</button>
|
|
743
760
|
<button class="theme-option" data-theme="dark-cove" title="Dark Cove"><span class="theme-dot" style="background:#7aa2f7"></span>Dark Cove${e.template==="dark-cove"?'<span class="theme-check">\u2713</span>':""}</button>
|
|
744
761
|
</div>
|
|
762
|
+
<label class="force-narrow-row" title="\u7A84\u5C4F\u65F6\u4FA7\u8FB9\u680F\u6298\u53E0\u4E3A\u9876\u680F\u3001\u7EC8\u7AEF\u5360\u6EE1\u3001\u5E95\u90E8\u663E\u793A\u865A\u62DF\u952E\u76D8\u5DE5\u5177\u680F\uFF08\u4EC5\u5F71\u54CD\u672C\u6D4F\u89C8\u5668\uFF09">
|
|
763
|
+
<span>\u5F3A\u5236\u7A84\u5C4F\uFF08\u79FB\u52A8\u5E03\u5C40\uFF09</span>
|
|
764
|
+
<input type="checkbox" id="force-narrow-toggle" />
|
|
765
|
+
</label>
|
|
745
766
|
<hr class="settings-divider" />
|
|
746
767
|
<a href="/settings" class="settings-item" id="set-settings-link" style="cursor:pointer;color:inherit;text-decoration:none">
|
|
747
768
|
<span>Settings</span>
|