tmux-weblink 3.1.1 → 3.2.1

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.
@@ -1,123 +1,127 @@
1
- var As=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function en(t){return t.replace(/\x1b\[\?1049[hl]/g,"")}function Ge(t){return t.replace(As,"")}var St;function zs(){return St||(document.querySelector("link[data-tmux-web-xterm-css]")?St=Promise.resolve():(St=new Promise(t=>{let e=document.createElement("link");e.rel="stylesheet",e.href="/assets/xterm.css",e.setAttribute("data-tmux-web-xterm-css",""),e.addEventListener("load",()=>t(),{once:!0}),e.addEventListener("error",()=>t(),{once:!0}),document.head.appendChild(e)}),St))}var Ms=class us{terminal;fitAddon;container;webglActive=!1;repaintTimer=0;webglAddon=null;constructor(e,n,i){this.container=e,this.terminal=n,this.fitAddon=i,this.terminal.loadAddon(this.fitAddon),this.terminal.open(e),this.enableWebglRenderer(),document.addEventListener("visibilitychange",()=>{document.hidden||this.refreshPaintedRows()})}enableWebglRenderer(){if(Rs()==="webgl"){try{if(!document.createElement("canvas").getContext("webgl2",{failIfMajorPerformanceCaveat:!0}))return}catch{return}import("./addon-webgl-B45EJ6AW.js").then(({WebglAddon:e})=>{let n=new e;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(e,n,i){let[{Terminal:s},{FitAddon:l}]=await Promise.all([import("./xterm-BXEES47M.js"),import("./addon-fit-D5N335P2.js"),zs()]),a="'JetBrains Mono', 'SF Mono', 'Menlo', monospace",r=new s({fontSize:Bs(14,a),fontFamily:a,cursorBlink:!0,cursorStyle:"bar",scrollback:n,convertEol:!1,smoothScrollDuration:120,theme:i});return new us(e,r,new l)}get cols(){return this.terminal.cols}get rows(){return this.terminal.rows}write(e){return new Promise(n=>this.terminal.write(e,n))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom()}scrollToLine(e,n=!1){this.terminal.scrollToLine(Math.max(0,e),n),this.scheduleRepaintCheck()}scrollLines(e){this.terminal.scrollLines(e),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 e=this.terminal.element?.querySelector(".xterm-screen")?.getBoundingClientRect().height??0,n=this.terminal.rows;return e>0&&n>0?e/n:16}fit(){let e=Ps(this.container);if(e.width<=0||e.height<=0)return!1;let n=this.terminal.cols,i=this.terminal.rows,s=this.paintedCellWidth();s<=0&&(this.fitAddon.fit(),s=this.paintedCellWidth());let l=this.fitAddon.proposeDimensions?.();if(!l)return this.fitAddon.fit(),!0;let a=this.overlayScrollbarWidth(),r=a>0?a+2:0,o=s>0?Math.max(10,Math.min(l.cols,Math.floor((e.width-r)/s))):l.cols,c=l.rows;return(o!==this.terminal.cols||c!==this.terminal.rows)&&this.terminal.resize(o,c),this.webglActive&&(n!==this.terminal.cols||i!==this.terminal.rows)&&this.refreshPaintedRows(),!0}paintedCellWidth(){let e=this.terminal.element?.querySelector(".xterm-screen")?.getBoundingClientRect().width??0,n=this.terminal.cols;return e>0&&n>0?e/n:0}overlayScrollbarWidth(){let e=this.terminal.element?.querySelector(".vertical.scrollbar");if(!e)return 0;let n=e.getBoundingClientRect();return!(n.width>0)||!(n.height>0)?0:Math.round(n.width)}focus(){this.terminal.focus()}pasteText(e){this.terminal.paste(e)}input(e){this.terminal.input(e,!1)}onData(e){this.terminal.onData(e),this.terminal.onBinary(e)}onResize(e){this.terminal.onResize(e)}onScroll(e){this.terminal.onScroll(e)}attachCustomKeyEventHandler(e){this.terminal.attachCustomKeyEventHandler(e)}isFocused(){let e=document.activeElement;return e?e===this.container||e===this.terminal.textarea||this.container.contains(e)||!!e.closest?.(".xterm"):!1}getScreenText(){return this.getRowsText(0,this.terminal.rows-1)}getRowsText(e,n){let i=this.terminal.buffer.active,[s,l]=e<=n?[e,n]:[n,e],a=i.viewportY,r=[];for(let o=s;o<=l;o++){let c=i.getLine(a+o);r.push(c?c.translateToString(!0):"")}return r.join(`
2
- `)}selectRows(e,n){let i=this.terminal.buffer.active,[s,l]=e<=n?[e,n]:[n,e];this.terminal.selectLines(i.viewportY+s,i.viewportY+l)}selectCells(e,n,i,s){let l=this.terminal.buffer.active,a=Math.min(n,s),r=Math.max(n,s);if(a===r){let o=Math.min(e,i),c=Math.max(e,i);this.terminal.select(o,l.viewportY+a,c-o+1)}else this.terminal.selectLines(l.viewportY+a,l.viewportY+r)}getCellsText(e,n,i,s){let l=this.terminal.buffer.active,a=Math.min(n,s),r=Math.max(n,s),o=n<s?e:n>s?i:Math.min(e,i),c=n<s?i:n>s?e:Math.max(e,i),d=l.viewportY,m=[];for(let p=a;p<=r;p++){let h=l.getLine(d+p);if(!h){m.push("");continue}let f=p===a?o:0,b=p===r?c:this.terminal.cols-1,w="";for(let y=f;y<=b;y++){let C=h.getCell(y);C&&(w+=C.getChars())}m.push(w.replace(/\s+$/,""))}return m.join(`
3
- `)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function Bs(t,e){try{let n=document.createElement("canvas").getContext("2d");if(!n)return t;let i=100;n.font=`${i}px ${e}`;let s=n.measureText("M").width/i;if(!Number.isFinite(s)||s<=0)return t;let l=window.devicePixelRatio||1,a=t,r=Number.POSITIVE_INFINITY;for(let o=4;o<=40;o++){let c=o/(s*l);if(c<t-1.5||c>t+1.5)continue;let d=Math.abs(c-t);d<r&&(r=d,a=c)}return Math.round(a*100)/100}catch{return t}}function Rs(){try{let t=new URLSearchParams(window.location.search).get("renderer");return t==="dom"||t==="webgl"?t:null}catch{return null}}function Ps(t){let e=t.getBoundingClientRect(),n=window.visualViewport;return n?{width:Math.min(e.width,n.width),height:Math.max(0,Math.min(e.height,n.height-Math.max(0,e.top)))}:e}function Ds(t,e,n){return t.innerHTML="",t.classList.add("terminal-pending"),(async()=>{let i=await Ms.create(t,n.scrollback,n.theme),s,l=0,a,r=null,o=0,c=0,d=.2,m=10,p=.95,h=.04,f=null,b=null;function w(u){f||(f=document.createElement("div"),f.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(";"),t.appendChild(f)),f.textContent=u?"\u2191 \u4E0A\u7FFB\u4E00\u9875 (PgUp)":"\u2193 \u4E0B\u7FFB\u4E00\u9875 (PgDn)",f.style.top=u?"10%":"auto",f.style.bottom=u?"auto":"10%",f.style.opacity="1",b&&clearTimeout(b),b=setTimeout(()=>{f&&(f.style.opacity="0")},900)}function y(){b&&clearTimeout(b),f&&(f.style.opacity="0")}function C(){o&&(cancelAnimationFrame(o),o=0),c=0}function M(u){if(C(),Math.abs(u)<d)return;c=Math.max(-m,Math.min(m,u));let v=()=>{if(B){o=0;return}let S=i.cellHeight(),R=S>0?Math.round(c*16/S):c>0?1:-1;R===0&&(R=c>0?1:-1);let O=i.viewportY()-R,he=i.baseY(),Ee=Math.max(0,Math.min(O,he));if(i.scrollToLine(Ee,!0),c*=p,Ee!==O){o=0;return}if(Math.abs(c)<h){o=0;return}o=requestAnimationFrame(v)};o=requestAnimationFrame(v)}let T=0,I="connecting",$=0,z=!1,x=[],F="",B=!1,Z=1e3,A=location.protocol==="https:"?"wss:":"ws:",Se=n.wsBase||"/ws",W=A+"//"+location.host+Se+"/"+encodeURIComponent(e),L=(Se.replace(/^\/ws/,"")||"")+"/api/session/"+encodeURIComponent(e)+"/upload",U=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function ve(){return x.join("")+F}async function q(u,v=0){let S=u?i.viewportY():0,R=Ge(ve());if(i.reset(),!R){u||i.scrollToBottom();return}await i.write(R),u?i.scrollToLine(v+S):i.scrollToBottom()}function Y(u){s?.readyState===WebSocket.OPEN&&s.send(JSON.stringify(u))}function $e(u){let v;try{v=JSON.parse(u)}catch{I==="live"&&(F+=u,i.write(Ge(u)));return}if(v.type==="auth.required"){let S=localStorage.getItem("tmux-web-token");S?Y({type:"auth.token",token:S}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(v.type==="attach_failed"&&typeof v.message=="string"){Ne=!0,I="dead",i.reset(),i.write(`\r
4
- \x1B[31m`+Ge(v.message)+`\x1B[0m\r
5
- `).then(()=>{kt();try{s?.close()}catch{}});return}if(v.type==="auth.ok"){v.token&&localStorage.setItem("tmux-web-token",v.token),Z=1e3,Ie(),Y({type:"resize",cols:i.cols,rows:i.rows}),ne();return}if(v.type==="auth.failed"){if(v.permanentLock||v.retryAfterMs&&v.retryAfterMs>6e4){localStorage.removeItem("tmux-web-token"),location.href="/login?error="+encodeURIComponent(v.message);return}return}if(v.type==="snapshot"&&typeof v.data=="string"){let S=en(Ge(v.data));x=[S],F="",$=typeof v.lines=="number"?v.lines:n.terminal.initialLines,I="live",i.reset(),Ie(),Y({type:"resize",cols:i.cols,rows:i.rows}),i.write(S).then(()=>i.scrollToBottom());return}if(v.type==="window_changed"&&typeof v.activeIndex=="number"){let S=new URL(location.href);S.searchParams.get("window")!==String(v.activeIndex)&&(S.searchParams.set("window",String(v.activeIndex)),history.replaceState(history.state,"",S)),window.dispatchEvent(new CustomEvent("tmux:windows",{detail:v.windows}));return}if(v.type==="history"&&typeof v.data=="string"){v.lines>0&&v.data?(x.unshift(en(v.data)),$+=v.lines,q(!0,v.lines).finally(()=>{z=!1})):z=!1;return}if(v.type==="data"&&typeof v.data=="string"){let S=en(Ge(v.data));if(I==="connecting"){I="live",F=S,i.write(S);return}I==="live"&&(F+=S,i.write(S))}}let Ne=!1;function Nn(){if(Ne)return;let u=W,v=localStorage.getItem("tmux-web-token");v&&(u+=(u.includes("?")?"&":"?")+"token="+encodeURIComponent(v)),u+=(u.includes("?")?"&":"?")+"cols="+i.cols+"&rows="+i.rows,s=new WebSocket(u),s.onopen=()=>{I="connecting",$=0,z=!1,x=[],F="",i.reset(),Z=1e3},s.onmessage=S=>{typeof S.data=="string"&&$e(S.data)},s.onclose=()=>{B||(I="connecting",!Ne&&setTimeout(()=>{Z=Math.min(Z*2,1e4),!B&&!Ne&&Nn()},Z))},s.onerror=()=>s?.close()}function Oe(u){Y({type:"input",data:u})}function Ie(){return i.fit()}function kt(){t.classList.remove("terminal-pending")}function ne(){l&&cancelAnimationFrame(l),a&&clearTimeout(a),Ie(),l=requestAnimationFrame(()=>{l=0,Ie()&&kt()}),a=setTimeout(()=>{Ie()&&kt()},120)}function hs(){ne(),setTimeout(ne,50),setTimeout(ne,150),setTimeout(ne,300)}function On(u){return typeof u=="string"&&u.startsWith("image/")}function qn(u){return u?.files?.length?u.files[0]??null:null}function ms(u){if(!u?.items)return null;for(let v=0;v<u.items.length;v++){let S=u.items[v];if(S?.kind==="file"&&On(S.type))return S.getAsFile()}return null}async function fs(u){let v=new FormData,S=u instanceof File&&u.name?u.name:"upload";v.append("file",u,S);let R=localStorage.getItem("tmux-web-token"),O={};R&&(O.Authorization="Bearer "+R);let he=await fetch(L,{method:"POST",body:v,headers:O});if(!he.ok){let Yn="upload failed";try{let Xn=await he.json();Xn.error&&(Yn=Xn.error)}catch{}throw new Error(Yn)}let Ee=await he.json();if(!Ee.path)throw new Error("no path in response");return Ee.path}async function Kt(u){try{let v=await fs(u);Oe(v)}catch{}}i.onData(u=>Oe(u)),i.onResize(({cols:u,rows:v})=>Y({type:"resize",cols:u,rows:v})),i.onScroll(()=>{I!=="live"||z||!i.isNearScrollbackTop()||(z=!0,Y({type:"load_history",before:$}))});let Ze=!1,Ye=!1,X=null,Q=null,Xe=document.createElement("div");Xe.className="terminal-copy-banner",Xe.innerHTML='<strong>Copy mode</strong><span class="hint">drag to copy \xB7 Esc exits</span>',Xe.hidden=!0,t.appendChild(Xe);let be=document.createElement("div");be.className="terminal-copy-banner terminal-copy-toast",be.textContent="Copied",be.hidden=!0,t.appendChild(be);function jn(u,v){let S=t.querySelector(".xterm-screen, canvas"),R=(S&&S.getBoundingClientRect().width>0?S:t).getBoundingClientRect(),O=R.height>0&&i.rows>0?R.height/i.rows:18,he=R.width>0&&i.cols>0?R.width/i.cols:9;return{row:Math.max(0,Math.min(i.rows-1,Math.floor((v-R.top)/O))),col:Math.max(0,Math.min(i.cols-1,Math.floor((u-R.left)/he)))}}async function wt(u){if(!u)return;try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(u);return}}catch{}let v=document.createElement("textarea");v.value=u,v.style.position="fixed",v.style.opacity="0",v.style.pointerEvents="none",document.body.appendChild(v),v.focus(),v.select();try{document.execCommand("copy")}catch{}v.remove()}let Ke;function yt(){be.hidden=!1,Ke&&clearTimeout(Ke),Ke=setTimeout(()=>{be.hidden=!0},1e3)}function qe(u){Ze=u,Xe.hidden=!u,t.classList.toggle("terminal-copy-mode-active",u),u&&i.focus()}function Vn(){qe(!Ze)}function gs(u){B||u.button!==0||Ye||(Ze||u.shiftKey)&&(u.preventDefault(),u.stopPropagation(),Ye=!0,X=jn(u.clientX,u.clientY),Q=X,i.selectCells(X.col,X.row,Q.col,Q.row),document.addEventListener("mousemove",Qt,!0),document.addEventListener("mouseup",Gt,!0))}function Qt(u){B||!Ye||!X||(u.preventDefault(),u.stopPropagation(),Q=jn(u.clientX,u.clientY),i.selectCells(X.col,X.row,Q.col,Q.row))}function Gt(u){if(B||!Ye||!X||!Q)return;u.preventDefault(),u.stopPropagation(),document.removeEventListener("mousemove",Qt,!0),document.removeEventListener("mouseup",Gt,!0),Ye=!1;let v=i.getCellsText(X.col,X.row,Q.col,Q.row);X=null,Q=null,i.clearSelection(),qe(!1),v&&(be.textContent="\u5DF2\u590D\u5236",wt(v).then(yt)),i.focus()}t.addEventListener("mousedown",gs,!0),document.addEventListener("keydown",vs,!0);function vs(u){if(!(B||!i.isFocused()||u.defaultPrevented||u.isComposing)){if(Ze){if(u.key==="Escape"){u.preventDefault(),u.stopPropagation(),X=null,Q=null,i.clearSelection(),qe(!1);return}if(u.key==="Enter"||(u.ctrlKey||u.metaKey)&&u.code==="KeyC"){u.preventDefault(),u.stopPropagation(),wt(i.getScreenText()).then(yt),qe(!1);return}}if(u.altKey&&u.code==="KeyC"&&!u.ctrlKey&&!u.metaKey){if(u.preventDefault(),u.stopPropagation(),X&&Q){let v=i.getCellsText(X.col,X.row,Q.col,Q.row);X=null,Q=null,i.clearSelection(),qe(!1),v&&(be.textContent="Copied",wt(v).then(yt))}else{let v=i.getSelection();v?(i.clearSelection(),be.textContent="Copied",wt(v).then(yt)):Vn()}return}if((u.ctrlKey||u.metaKey)&&u.code==="KeyV"){u.preventDefault(),u.stopPropagation(),(async()=>{try{if(navigator.clipboard?.read){let v=await navigator.clipboard.read();for(let S of v)for(let R of S.types)if(On(R)){let O=await S.getType(R);await Kt(O);return}}}catch{}try{let v=await navigator.clipboard?.readText();v&&i.pasteText(Wn(v))}catch{}})();return}}}let xt=0;function Wn(u){return u.split(`\r
1
+ var Xs=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function fn(e){return e.replace(/\x1b\[\?1049[hl]/g,"")}function rt(e){return e.replace(Xs,"")}var Tt;function Ks(){return Tt||(document.querySelector("link[data-tmux-web-xterm-css]")?Tt=Promise.resolve():(Tt=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)}),Tt))}var Qs=class zs{terminal;fitAddon;container;webglActive=!1;repaintTimer=0;webglAddon=null;constructor(t,n,i){this.container=t,this.terminal=n,this.fitAddon=i,this.terminal.loadAddon(this.fitAddon),this.terminal.open(t),this.enableWebglRenderer(),document.addEventListener("visibilitychange",()=>{document.hidden||this.refreshPaintedRows()})}enableWebglRenderer(){if(ea()==="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,i){let[{Terminal:s},{FitAddon:a}]=await Promise.all([import("./xterm-BXEES47M.js"),import("./addon-fit-D5N335P2.js"),Ks()]),l="'JetBrains Mono', 'SF Mono', 'Menlo', monospace",r=new s({fontSize:Gs(14,l),fontFamily:l,cursorBlink:!0,cursorStyle:"bar",scrollback:n,convertEol:!1,smoothScrollDuration:120,theme:i});return new zs(t,r,new a)}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=ta(this.container);if(t.width<=0||t.height<=0)return!1;let n=this.terminal.cols,i=this.terminal.rows,s=this.paintedCellWidth();s<=0&&(this.fitAddon.fit(),s=this.paintedCellWidth());let a=this.fitAddon.proposeDimensions?.();if(!a)return this.fitAddon.fit(),!0;let l=this.overlayScrollbarWidth(),r=l>0?l+2:0,o=s>0?Math.max(10,Math.min(a.cols,Math.floor((t.width-r)/s))):a.cols,c=a.rows;return(o!==this.terminal.cols||c!==this.terminal.rows)&&this.terminal.resize(o,c),this.webglActive&&(n!==this.terminal.cols||i!==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 i=this.terminal.buffer.active,[s,a]=t<=n?[t,n]:[n,t],l=i.viewportY,r=[];for(let o=s;o<=a;o++){let c=i.getLine(l+o);r.push(c?c.translateToString(!0):"")}return r.join(`
2
+ `)}selectRows(t,n){let i=this.terminal.buffer.active,[s,a]=t<=n?[t,n]:[n,t];this.terminal.selectLines(i.viewportY+s,i.viewportY+a)}selectCells(t,n,i,s){let a=this.terminal.buffer.active,l=Math.min(n,s),r=Math.max(n,s);if(l===r){let o=Math.min(t,i),c=Math.max(t,i);this.terminal.select(o,a.viewportY+l,c-o+1)}else this.terminal.selectLines(a.viewportY+l,a.viewportY+r)}getCellsText(t,n,i,s){let a=this.terminal.buffer.active,l=Math.min(n,s),r=Math.max(n,s),o=n<s?t:n>s?i:Math.min(t,i),c=n<s?i:n>s?t:Math.max(t,i),d=a.viewportY,v=[];for(let h=l;h<=r;h++){let p=a.getLine(d+h);if(!p){v.push("");continue}let f=h===l?o:0,m=h===r?c:this.terminal.cols-1,k="";for(let w=f;w<=m;w++){let L=p.getCell(w);L&&(k+=L.getChars())}v.push(k.replace(/\s+$/,""))}return v.join(`
3
+ `)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function Gs(e,t){try{let n=document.createElement("canvas").getContext("2d");if(!n)return e;let i=100;n.font=`${i}px ${t}`;let s=n.measureText("M").width/i;if(!Number.isFinite(s)||s<=0)return e;let a=window.devicePixelRatio||1,l=e,r=Number.POSITIVE_INFINITY;for(let o=4;o<=40;o++){let c=o/(s*a);if(c<e-1.5||c>e+1.5)continue;let d=Math.abs(c-e);d<r&&(r=d,l=c)}return Math.round(l*100)/100}catch{return e}}function ea(){try{let e=new URLSearchParams(window.location.search).get("renderer");return e==="dom"||e==="webgl"?e:null}catch{return null}}function ta(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 na(e,t,n){return e.innerHTML="",e.classList.add("terminal-pending"),(async()=>{let i=await Qs.create(e,n.scrollback,n.theme),s,a=0,l,r=null,o=0,c=0,d=.2,v=10,h=.95,p=.04,f=null,m=null;function k(u){f||(f=document.createElement("div"),f.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(f)),f.textContent=u?"\u2191 \u4E0A\u7FFB\u4E00\u9875 (PgUp)":"\u2193 \u4E0B\u7FFB\u4E00\u9875 (PgDn)",f.style.top=u?"10%":"auto",f.style.bottom=u?"auto":"10%",f.style.opacity="1",m&&clearTimeout(m),m=setTimeout(()=>{f&&(f.style.opacity="0")},900)}function w(){m&&clearTimeout(m),f&&(f.style.opacity="0")}function L(){o&&(cancelAnimationFrame(o),o=0),c=0}function M(u){if(L(),Math.abs(u)<d)return;c=Math.max(-v,Math.min(v,u));let b=()=>{if(z){o=0;return}let S=i.cellHeight(),P=S>0?Math.round(c*16/S):c>0?1:-1;P===0&&(P=c>0?1:-1);let W=i.viewportY()-P,ke=i.baseY(),Re=Math.max(0,Math.min(W,ke));if(i.scrollToLine(Re,!0),c*=h,Re!==W){o=0;return}if(Math.abs(c)<p){o=0;return}o=requestAnimationFrame(b)};o=requestAnimationFrame(b)}let $=0,T="connecting",I=0,B=!1,x=[],A="",z=!1,se=1e3,D=location.protocol==="https:"?"wss:":"ws:",Ee=n.wsBase||"/ws",K=D+"//"+location.host+Ee+"/"+encodeURIComponent(t),X=(Ee.replace(/^\/ws/,"")||"")+"/api/session/"+encodeURIComponent(t)+"/upload",Be=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function ae(){return x.join("")+A}async function q(u,b=0){let S=u?i.viewportY():0,P=rt(ae());if(i.reset(),!P){u||i.scrollToBottom();return}await i.write(P),u?i.scrollToLine(b+S):i.scrollToBottom()}function j(u){s?.readyState===WebSocket.OPEN&&s.send(JSON.stringify(u))}function ve(u){let b;try{b=JSON.parse(u)}catch{T==="live"&&(A+=u,i.write(rt(u)));return}if(b.type==="auth.required"){let S=localStorage.getItem("tmux-web-token");S?j({type:"auth.token",token:S}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(b.type==="attach_failed"&&typeof b.message=="string"){le=!0,T="dead",i.reset(),i.write(`\r
4
+ \x1B[31m`+rt(b.message)+`\x1B[0m\r
5
+ `).then(()=>{oe();try{s?.close()}catch{}});return}if(b.type==="auth.ok"){b.token&&localStorage.setItem("tmux-web-token",b.token),se=1e3,Z(),j({type:"resize",cols:i.cols,rows:i.rows}),J();return}if(b.type==="auth.failed"){if(b.permanentLock||b.retryAfterMs&&b.retryAfterMs>6e4){localStorage.removeItem("tmux-web-token"),location.href="/login?error="+encodeURIComponent(b.message);return}return}if(b.type==="snapshot"&&typeof b.data=="string"){let S=fn(rt(b.data));x=[S],A="",I=typeof b.lines=="number"?b.lines:n.terminal.initialLines,T="live",i.reset(),Z(),j({type:"resize",cols:i.cols,rows:i.rows}),i.write(S).then(()=>i.scrollToBottom());return}if(b.type==="window_changed"&&typeof b.activeIndex=="number"){let S=new URL(location.href);S.searchParams.get("window")!==String(b.activeIndex)&&(S.searchParams.set("window",String(b.activeIndex)),history.replaceState(history.state,"",S)),window.dispatchEvent(new CustomEvent("tmux:windows",{detail:b.windows}));return}if(b.type==="history"&&typeof b.data=="string"){b.lines>0&&b.data?(x.unshift(fn(b.data)),I+=b.lines,q(!0,b.lines).finally(()=>{B=!1})):B=!1;return}if(b.type==="data"&&typeof b.data=="string"){let S=fn(rt(b.data));if(T==="connecting"){T="live",A=S,i.write(S);return}T==="live"&&(A+=S,i.write(S))}}let le=!1;function E(){if(le)return;let u=K,b=localStorage.getItem("tmux-web-token");b&&(u+=(u.includes("?")?"&":"?")+"token="+encodeURIComponent(b)),u+=(u.includes("?")?"&":"?")+"cols="+i.cols+"&rows="+i.rows,s=new WebSocket(u),s.onopen=()=>{T="connecting",I=0,B=!1,x=[],A="",i.reset(),se=1e3},s.onmessage=S=>{typeof S.data=="string"&&ve(S.data)},s.onclose=()=>{z||(T="connecting",!le&&setTimeout(()=>{se=Math.min(se*2,1e4),!z&&!le&&E()},se))},s.onerror=()=>s?.close()}function R(u){j({type:"input",data:u})}function Z(){return i.fit()}function oe(){e.classList.remove("terminal-pending")}function J(){a&&cancelAnimationFrame(a),l&&clearTimeout(l),Z(),a=requestAnimationFrame(()=>{a=0,Z()&&oe()}),l=setTimeout(()=>{Z()&&oe()},120)}function Bs(){J(),setTimeout(J,50),setTimeout(J,150),setTimeout(J,300)}function ei(u){return typeof u=="string"&&u.startsWith("image/")}function ti(u){return u?.files?.length?u.files[0]??null:null}function Rs(u){if(!u?.items)return null;for(let b=0;b<u.items.length;b++){let S=u.items[b];if(S?.kind==="file"&&ei(S.type))return S.getAsFile()}return null}async function Ps(u){let b=new FormData,S=u instanceof File&&u.name?u.name:"upload";b.append("file",u,S);let P=localStorage.getItem("tmux-web-token"),W={};P&&(W.Authorization="Bearer "+P);let ke=await fetch(X,{method:"POST",body:b,headers:W});if(!ke.ok){let oi="upload failed";try{let ci=await ke.json();ci.error&&(oi=ci.error)}catch{}throw new Error(oi)}let Re=await ke.json();if(!Re.path)throw new Error("no path in response");return Re.path}async function pn(u){try{let b=await Ps(u);R(b)}catch{}}i.onData(u=>R(u)),i.onResize(({cols:u,rows:b})=>j({type:"resize",cols:u,rows:b})),i.onScroll(()=>{T!=="live"||B||!i.isNearScrollbackTop()||(B=!0,j({type:"load_history",before:I}))});let nt=!1,it=!1,Q=null,ee=null,st=document.createElement("div");st.className="terminal-copy-banner",st.innerHTML='<strong>Copy mode</strong><span class="hint">drag to copy \xB7 Esc exits</span>',st.hidden=!0,e.appendChild(st);let Se=document.createElement("div");Se.className="terminal-copy-banner terminal-copy-toast",Se.textContent="Copied",Se.hidden=!0,e.appendChild(Se);function ni(u,b){let S=e.querySelector(".xterm-screen, canvas"),P=(S&&S.getBoundingClientRect().width>0?S:e).getBoundingClientRect(),W=P.height>0&&i.rows>0?P.height/i.rows:18,ke=P.width>0&&i.cols>0?P.width/i.cols:9;return{row:Math.max(0,Math.min(i.rows-1,Math.floor((b-P.top)/W))),col:Math.max(0,Math.min(i.cols-1,Math.floor((u-P.left)/ke)))}}async function Lt(u){if(!u)return;try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(u);return}}catch{}let b=document.createElement("textarea");b.value=u,b.style.position="fixed",b.style.opacity="0",b.style.pointerEvents="none",document.body.appendChild(b),b.focus(),b.select();try{document.execCommand("copy")}catch{}b.remove()}let at;function $t(){Se.hidden=!1,at&&clearTimeout(at),at=setTimeout(()=>{Se.hidden=!0},1e3)}function Ye(u){nt=u,st.hidden=!u,e.classList.toggle("terminal-copy-mode-active",u),u&&i.focus()}function ii(){Ye(!nt)}function Ds(u){z||u.button!==0||it||(nt||u.shiftKey)&&(u.preventDefault(),u.stopPropagation(),it=!0,Q=ni(u.clientX,u.clientY),ee=Q,i.selectCells(Q.col,Q.row,ee.col,ee.row),document.addEventListener("mousemove",un,!0),document.addEventListener("mouseup",hn,!0))}function un(u){z||!it||!Q||(u.preventDefault(),u.stopPropagation(),ee=ni(u.clientX,u.clientY),i.selectCells(Q.col,Q.row,ee.col,ee.row))}function hn(u){if(z||!it||!Q||!ee)return;u.preventDefault(),u.stopPropagation(),document.removeEventListener("mousemove",un,!0),document.removeEventListener("mouseup",hn,!0),it=!1;let b=i.getCellsText(Q.col,Q.row,ee.col,ee.row);Q=null,ee=null,i.clearSelection(),Ye(!1),b&&(Se.textContent="\u5DF2\u590D\u5236",Lt(b).then($t)),i.focus()}e.addEventListener("mousedown",Ds,!0),document.addEventListener("keydown",Hs,!0);function Hs(u){if(!(z||!i.isFocused()||u.defaultPrevented||u.isComposing)){if(nt){if(u.key==="Escape"){u.preventDefault(),u.stopPropagation(),Q=null,ee=null,i.clearSelection(),Ye(!1);return}if(u.key==="Enter"||(u.ctrlKey||u.metaKey)&&u.code==="KeyC"){u.preventDefault(),u.stopPropagation(),Lt(i.getScreenText()).then($t),Ye(!1);return}}if(u.altKey&&u.code==="KeyC"&&!u.ctrlKey&&!u.metaKey){if(u.preventDefault(),u.stopPropagation(),Q&&ee){let b=i.getCellsText(Q.col,Q.row,ee.col,ee.row);Q=null,ee=null,i.clearSelection(),Ye(!1),b&&(Se.textContent="Copied",Lt(b).then($t))}else{let b=i.getSelection();b?(i.clearSelection(),Se.textContent="Copied",Lt(b).then($t)):ii()}return}if((u.ctrlKey||u.metaKey)&&u.code==="KeyV"){u.preventDefault(),u.stopPropagation(),(async()=>{try{if(navigator.clipboard?.read){let b=await navigator.clipboard.read();for(let S of b)for(let P of S.types)if(ei(P)){let W=await S.getType(P);await pn(W);return}}}catch{}try{let b=await navigator.clipboard?.readText();b&&i.pasteText(si(b))}catch{}})();return}}}let It=0;function si(u){return u.split(`\r
6
6
  `).join(`
7
7
  `).split(`
8
- `).join("\r")}async function bs(u){let v=ms(u.clipboardData);if(v){u.preventDefault(),u.stopPropagation();let O=Date.now();if(O-xt<50)return;xt=O,await Kt(v);return}let S=u.clipboardData?.getData("text/plain");if(!S)return;u.preventDefault(),u.stopPropagation();let R=Date.now();R-xt<50||(xt=R,i.pasteText(Wn(S)))}let Qe=0;function ks(u){u.preventDefault(),Qe++,qn(u.dataTransfer)&&t.classList.add("terminal-drag-over")}function ws(u){u.preventDefault(),u.dataTransfer&&(u.dataTransfer.dropEffect="copy")}function ys(u){u.preventDefault(),Qe--,Qe<=0&&(Qe=0,t.classList.remove("terminal-drag-over"))}async function xs(u){u.preventDefault(),Qe=0,t.classList.remove("terminal-drag-over");let v=qn(u.dataTransfer);v&&await Kt(v)}function Un(u){!U||u.key!=="Escape"||Ze||u.defaultPrevented||u.repeat||u.metaKey||u.ctrlKey||u.altKey||i.isFocused()&&(u.preventDefault(),u.stopPropagation(),Oe("\x1B"))}t.addEventListener("paste",bs),t.addEventListener("dragenter",ks),t.addEventListener("dragover",ws),t.addEventListener("dragleave",ys),t.addEventListener("drop",xs),document.addEventListener("keydown",Un,!0);function Ss(u){if(u.touches.length!==1){r=null;return}let v=u.touches[0];if(!v)return;C();let S=t.getBoundingClientRect(),R=v.clientX-S.left<S.width*.4?"tui":"history",O=v.clientY-S.top<S.height*.5;r={startX:v.clientX,startY:v.clientY,lastX:v.clientX,lastY:v.clientY,lastT:performance.now(),velocity:0,scrolling:!1,zone:R,tuiUp:O,sent:!1},u.stopPropagation()}function Es(u){if(!r||u.touches.length!==1)return;let v=u.touches[0];if(!v)return;let S=v.clientY-r.startY,R=v.clientX-r.startX;if(!r.scrolling){if(Math.abs(S)<8||Math.abs(S)<Math.abs(R))return;r.scrolling=!0,T=Date.now()+500}u.preventDefault(),u.stopPropagation();let O=performance.now(),he=v.clientY-r.lastY;if(r.zone==="tui"){r.sent||(r.sent=!0,Oe(r.tuiUp?"\x1B[5~":"\x1B[6~"),w(r.tuiUp)),r.lastX=v.clientX,r.lastY=v.clientY,r.lastT=O;return}let Ee=O-r.lastT;Ee>0&&(r.velocity=he/Ee),$s(-he),r.lastX=v.clientX,r.lastY=v.clientY,r.lastT=O}function Cs(u){if(!r)return;let v=r.scrolling,S=r.zone,R=r.tuiUp,O=r.velocity;if(r=null,u.stopPropagation(),S==="tui"){v||(Oe(R?"\x1B[5~":"\x1B[6~"),w(R),T=Date.now()+500,u.preventDefault());return}if(!v){i.focus();return}T=Date.now()+500,u.preventDefault(),O&&M(O)}function Ls(u){r=null,C(),u.stopPropagation()}function Ts(u){u.pointerType==="touch"&&Date.now()<T&&(u.preventDefault(),u.stopPropagation())}function $s(u){let v=i.cellHeight(),S=v>0?Math.round(u/v):u>0?1:-1;S===0&&(S=u>0?1:-1),i.scrollLines(S)}t.addEventListener("touchstart",Ss,{passive:!0,capture:!0}),t.addEventListener("touchmove",Es,{passive:!1,capture:!0}),t.addEventListener("touchend",Cs,{passive:!1,capture:!0}),t.addEventListener("touchcancel",Ls,{passive:!0,capture:!0}),t.addEventListener("pointerup",Ts,!0);function Jn(){ne()}window.addEventListener("resize",Jn),window.visualViewport?.addEventListener("resize",ne),window.visualViewport?.addEventListener("scroll",ne);let Zn=new ResizeObserver(()=>ne());Zn.observe(t),document.fonts?.ready.then(()=>{ne(),setTimeout(ne,50),setTimeout(ne,200)}),t.addEventListener("focusin",hs,!0);async function Is(){if(document.fonts?.ready)try{await Promise.race([document.fonts.ready,new Promise(u=>setTimeout(u,1e3))])}catch{}}return requestAnimationFrame(()=>{Ie()&&kt(),(async()=>(await Is(),Ie()&&Y({type:"resize",cols:i.cols,rows:i.rows}),Nn(),ne()))()}),{destroy(){if(B=!0,C(),qe(!1),Ke&&clearTimeout(Ke),document.removeEventListener("mousemove",Qt,!0),document.removeEventListener("mouseup",Gt,!0),s){try{s.close(1e3,"session switch")}catch{}s=void 0}t.innerHTML="",t.classList.remove("terminal-pending"),window.removeEventListener("resize",Jn),Zn.disconnect(),document.removeEventListener("keydown",Un,!0)},focus(){i.focus()},sendInput(u){Oe(u)},toggleCopyMode(){Vn()}}})()}var Kn={menu:"M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z",close:"M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7a1 1 0 1 0-1.41 1.41L10.59 12l-4.89 4.89a1 1 0 1 0 1.41 1.41L12 13.41l4.89 4.89a1 1 0 1 0 1.41-1.41L13.41 12l4.89-4.89a1 1 0 0 0 0-1.4z",search:"M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z",refresh:"M17.65 6.35A7.96 7.96 0 0 0 12 4a8 8 0 1 0 8 8h-2a6 6 0 1 1-6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM5.92 19H5v-.92l9.06-9.06.92.92L5.92 19zm13.66-12.83a1 1 0 0 0 0-1.41l-1.34-1.34a1 1 0 0 0-1.41 0l-1.05 1.05 2.75 2.75 1.05-1.05z",delete:"M15 4V3H9v1H4v2h1.5l.81 13.05A2 2 0 0 0 8.3 21h7.4a2 2 0 0 0 1.99-1.95L18.5 6H20V4h-5zm-5.5 2h5l-.75 12h-3.5L9.5 6z",check:"M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",sessions:"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z",notes:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",schedule:"M19 4h-1V2h-2v2H8V2H6v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 16H5V10h14v10zM9 14H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-8 4H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z",agents:"M12 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm0 8a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm-7 13v-2a5 5 0 0 1 5-5h4a5 5 0 0 1 5 5v2h2v-2a7 7 0 0 0-7-7H10a7 7 0 0 0-7 7v2h2z",history:"M13 3a9 9 0 0 0-9 9H1l4 4 4-4H6a7 7 0 1 1 7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.96 8.96 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.25 2.55.75-1.23-3.5-2.08V8H12z","quick-commands":"M13 3 4 14h7l-1 7 9-11h-7l1-7z",windows:"M4 6h16v2H4V6zm0 5h10v2H4v-2zm0 5h16v2H4v-2z",terminal:"M4 17.6 6.4 20l8-8-8-8L4 6.4 11.6 12 4 17.6zM20 18h-8v2h8v-2z",microphone:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z",keyboard:"M20 5H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-9 3h2v2h-2V8zm0 3h2v2h-2v-2zM8 8h2v2H8V8zm0 3h2v2H8v-2zm-1 2H5v-2h2v2zm0-3H5V8h2v2zm9 7H8v-2h8v2zm0-4h-2v-2h2v2zm0-3h-2V8h2v2zm3 3h-2v-2h2v2zm0-3h-2V8h2v2z",bot:"M11 2h2v3h2a3 3 0 0 1 3 3v1h1a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-1v1a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3v-1H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2h1V8a3 3 0 0 1 3-3h2V2zm-2 6v1h6V8H9zm-2 5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm10 0a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z",layers:"M12 2 2 7l10 5 10-5-10-5zm0 7.5L4.5 5.8 12 2l7.5 3.8L12 9.5zM2 12l10 5 10-5-1.9-.95L12 14.9l-8.1-3.85L2 12zm0 4.5 10 5 10-5-1.9-.95L12 19.4l-8.1-3.85-1.9.95z",inbox:"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zm0 16H5v-3h3.6a3.5 3.5 0 0 0 6.8 0H19v3zm0-5h-4.7a3.5 3.5 0 0 1-6.6 0H5V5h14v9z","chevron-down":"M7.4 8.6 12 13.2l4.6-4.6L18 10l-6 6-6-6 1.4-1.4z",settings:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6a3.6 3.6 0 1 1 0-7.2 3.6 3.6 0 0 1 0 7.2z",pin:"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4z","pin-outline":"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4zm-4.8 7.2V11l2-2V4h1.6v5l2 2v5.2H11.2z",folder:"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",file:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",worktree:"M6 3a3 3 0 0 0-1 5.83v6.34a3 3 0 1 0 2 0V8.83A3 3 0 0 0 6 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm0 12a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM18 3a3 3 0 0 0-1 5.83V9a4 4 0 0 1-4 4h-2a3 3 0 1 0 0 2h2a6 6 0 0 0 6-6v-.17A3 3 0 0 0 18 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM9 13a1 1 0 1 1 0 2 1 1 0 0 1 0-2z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",export:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",chevronRight:"M9.29 6.71a1 1 0 0 0 0 1.41L13.17 12l-3.88 3.88a1 1 0 1 0 1.41 1.41l4.59-4.59a1 1 0 0 0 0-1.41L10.7 6.7a1 1 0 0 0-1.41.01z",lightning:"M11 21h-1l1-7H7.5c-.58 0-.57-.32-.38-.66.19-.33.51-.89.73-1.27L13 3h1l-1 7h3.5c.49 0 .56.33.47.51l-.07.15c-.22.46-.58 1.18-.78 1.58L11 21z","git-branch":"M13.5 7a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zm0 10a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zM11 9.5v5.1a4.03 4.03 0 0 0-3-.1V9.4a4.03 4.03 0 0 0 3 .1z",external:"M14 3h7v7h-2V6l-9.29 9.29-1.41-1.41L17.59 4.5H14V3zm4 16H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7h-2v7z",play:"M8 5v14l11-7L8 5z",stop:"M6 6h12v12H6V6z",warning:"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z",info:"M11 7h2v2h-2V7zm0 4h2v6h-2v-6zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z",shield:"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25z","shield-up":"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25zM13 8.6v4.6h2l-3 3.6-3-3.6h2V8.6h2z","shield-alert":"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25zM11 7.5h2v5h-2v-5zm0 6.5h2v2h-2v-2z",spinner:"M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46A7.93 7.93 0 0 0 20 12c0-4.42-3.58-8-8-8z",dots:"M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"};function Hs(t){return Kn[t]??Kn.menu}function ae(t,e=""){return`<svg viewBox="0 0 24 24" fill="currentColor"${e?" "+e:""}><path d="${Hs(t)}"/></svg>`}function tn(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Ae=tn();function Qn(t){Ae=t}var ze={exec:()=>null};function Me(t){let e=[];return n=>{let i=Math.max(0,Math.min(3,n-1)),s=e[i];return s||(s=t(i),e[i]=s),s}}function E(t,e=""){let n=typeof t=="string"?t:t.source,i={replace:(s,l)=>{let a=typeof l=="string"?l:l.source;return a=a.replace(_.caret,"$1"),n=n.replace(s,a),i},getRegex:()=>new RegExp(n,e)};return i}var Gn=((t="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+t)}catch{return!1}})(),ei="^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)",_={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,listInterruptsParagraph:/^ {0,3}(?:[*+-]|0{0,8}1[.)])[ \t]+[^ \t\n]/,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^( {1,3})(?:`{3}|~{3})/,beginningSpace:/^[ \t]{1,3}/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,multipleSpaceTabGlobal:/[ \t\r\n]+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,textIndentedContinuation:/^(?:\n(?: {4}| {0,3}\t)[ \t]*[^ \t\n][^\n]*)+/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+)[ \t]*)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,blockquoteMarkerWhitespace:/^( {0,3}>)(\t[ \t]*)/gm,blockquoteFenceOpen:/^ {0,3}(`{3,}(?=[^`]*$)|~{3,})/,blockquoteFenceClose:/^ {0,3}(`{3,}|~{3,})[ \t]*$/,blockquoteListItemStart:/^ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|$)/,nestedBlockMarker:/^ {0,3}(?:(?:[*+-]|\d{1,9}[.)])(?: |$)|> ?)/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\][ \t]+\S/,listReplaceTask:/^\[[ xX]\][ \t]+/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableHeader:new RegExp(ei+"(?:\\n|$)"),tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/,numericCharacterReferenceOrAmpersand:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:Me(t=>new RegExp(`^ {0,${t}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:Me(t=>new RegExp(`^ {0,${t}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:Me(t=>new RegExp(`^ {0,${t}}(?:\`{3,}(?=[^\`\\n]*(?:\\n|$))|~~~)`)),headingBeginRegex:Me(t=>new RegExp(`^ {0,${t}}#{1,6}(?:\\s|$)`)),pedanticHeadingBeginRegex:Me(t=>new RegExp(`^ {0,${t}}#`)),htmlBeginRegex:Me(t=>new RegExp(`^ {0,${t}}(?:</?(?:${sn})(?:[ \\t]+|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,"i")),blockquoteBeginRegex:Me(t=>new RegExp(`^ {0,${t}}>`)),nestedContainerMarkers:/^(?: {0,3}(?:(?:[*+-]|\d{1,9}[.)])[ \t]+|>[ \t]?))+/},_s=/^(?:[ \t]*(?:\n|$))+/,Fs=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ns=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}(?:(?=`)\1`*|(?=~)\1~*)[ \t]*(?=\n|$)|$)/,et=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Os=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,nn=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,sn="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",tt=E(" {0,3}(?:</?(?:tag)(?:[ \\t]+|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",sn).getRegex(),ti=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?![ \t]*\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/,ni=E(ti).replace(/bull/g,nn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}(?=[^`\n]*(?:\n|$))|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/\|table/g,"").replace(/html/g,tt).getRegex(),qs=E(ti).replace(/bull/g,nn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}(?=[^`\n]*(?:\n|$))|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).replace(/html/g,tt).getRegex(),an=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,js=/^[^\n]+/,ln=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/,Vs=E(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<(?:\\.|[^\n<>\\])*>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ln).replace("title",/(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\\n]|\n(?!\n))*'|\((?:\\[\s\S]|[^()\\])*\))/).getRegex(),Ws=E(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,nn).getRegex(),rn=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Us=E("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?:[ \\t]+|\\n|/?>|$)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!(?:script|pre|style|textarea)(?![a-z0-9-]))([a-z][a-z0-9-]*)(?:attribute)*?[ \\t]*/?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",rn).replace("tag",sn).replace("attribute",/[ \t]+[a-zA-Z:_][\w.:-]*(?:[ \t]*=[ \t]*"[^"\n]*"|[ \t]*=[ \t]*'[^'\n]*'|[ \t]*=[ \t]*[^\s"'=<>`]+)?/).getRegex(),ii=t=>E(an).replace("hr",et).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",t).replace("html",tt).getRegex(),Js=ii(_.listInterruptsParagraph),Zs=ii(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),si=/ {0,3}> ?(?:(?!blank)(paragraph)|[^\n]*)(?:\n|$)/,Ys=E(/^(first)(?:next)*/).replace("first",E(si).replace("blank",/[ \t]*(?:\n|$)| {4}/).getRegex()).replace("next",E(si).replace("blank",/[ \t]*(?:\n|$)/).getRegex()).replace(/paragraph/g,Zs).getRegex(),on={blockquote:Ys,code:Fs,def:Vs,fences:Ns,heading:Os,hr:et,html:Us,lheading:ni,list:Ws,newline:_s,paragraph:Js,table:ze,text:js},Xs=E(ei+"(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",et).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|0{0,8}1[.)])[ \\t]").replace("html",tt).getRegex(),Ks={...on,lheading:qs,table:Xs,paragraph:E(an).replace("hr",et).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",_.tableHeader).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",_.listInterruptsParagraph).replace("html",tt).getRegex()},Qs={...on,html:E(`^ *(?:comment(?: *\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1>(?: *\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?>(?: *\\n{2,}|\\s*$))`).replace("comment",rn).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:ze,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:E(an).replace("hr",et).replace("heading",` *#{1,6} *[^
9
- ]`).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").replace("lheading",ni).getRegex()},Gs=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,ea=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ai=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,ta=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,me=/[\p{P}\p{S}]/u,je=/[\s\p{P}\p{S}]/u,nt=/[^\s\p{P}\p{S}]/u,na=E(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,je).getRegex(),ia=/[\p{Pi}\p{Ps}"']/u,li=/(?!~)[\p{P}\p{S}]/u,sa=/(?!~)[\s\p{P}\p{S}]/u,aa=/(?:[^\s\p{P}\p{S}]|~)/u,la=E(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Gn?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),ri=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,ra=E(ri,"u").replace(/punct/g,me).getRegex(),oa=E(ri,"u").replace(/punct/g,li).getRegex(),ca=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,da=E(ca,"u").replace(/openQuote/g,ia).replace(/punct/g,me).getRegex(),oi="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",pa=E(oi,"gu").replace(/notPunctSpace/g,nt).replace(/punctSpace/g,je).replace(/punct/g,me).getRegex(),ua=E(oi,"gu").replace(/notPunctSpace/g,aa).replace(/punctSpace/g,sa).replace(/punct/g,li).getRegex(),ha="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",ma=E(ha,"gu").replace(/notPunctSpace/g,nt).replace(/punctSpace/g,je).replace(/punct/g,me).getRegex(),fa=E("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,nt).replace(/punctSpace/g,je).replace(/punct/g,me).getRegex(),ga="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",va=E(ga,"gu").replace(/notPunctSpace/g,nt).replace(/punctSpace/g,je).replace(/punct/g,me).getRegex(),ba=E(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,me).getRegex(),ka="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",wa=E(ka,"gu").replace(/notPunctSpace/g,nt).replace(/punctSpace/g,je).replace(/punct/g,me).getRegex(),ya=E(/\\(punct)/,"gu").replace(/punct/g,me).getRegex(),xa=E(/(`+)(?:[^`]|[^`][\s\S]*?[^`])\1(?!`)|`+|\\(punct)/,"gu").replace(/punct/g,me).getRegex(),Sa=E(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Ea=E(rn).replace("(?:-->|$)","-->").getRegex(),Ca=E("^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Ea).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),ci=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,Et=E(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace("brackets",ci).getRegex(),Ct=/\\[^ \t\n\x00-\x1f]|\\(?=[ \t\n])|[^ \t\n\x00-\x1f\\()]/,La=E(/\((?:char)*\)/).replace("char",Ct).getRegex(),Ta=E(/\((?:char|p1)*\)/).replace("char",Ct).replace("p1",La).getRegex(),$a=E(/\((?:char|p2)*\)/).replace("char",Ct).replace("p2",Ta).getRegex(),Ia=E(/(?!<)(?:char|p3)+/).replace("char",Ct).replace("p3",$a).getRegex(),Aa=E(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace("label",Et).replace("href",E(/<(?:\\.|[^\n<>\\])*>|bareHref|(?=\))/).replace("bareHref",Ia).getRegex()).replace("title",/"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|\((?:\\[\s\S]|[^)\\])*\)/).getRegex(),za=E(/^!?\[(label)\]\[(ref)\]/).replace("label",Et).replace("ref",ln).getRegex(),Ma=E(/^!?\[(ref)\](?:\[\])?/).replace("ref",ln).getRegex(),di=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,Ba=E(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace("brackets",ci).getRegex(),Ra=E("reflink|nolink(?!\\()","g").replace("reflink",E(/^!?\[(label)\]\[(ref)\]/).replace("label",Ba).replace("ref",di).getRegex()).replace("nolink",E(/^!?\[(ref)\](?:\[\])?/).replace("ref",di).getRegex()).getRegex(),pi=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,Pa=/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/,Da=E(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,Pa).getRegex(),cn={_backpedal:ze,anyPunctuation:ya,anyPunctuationOutsideCode:xa,autolink:Sa,blockSkip:la,br:ai,code:ea,del:ze,delLDelim:ze,delRDelim:ze,emStrongLDelim:ra,emStrongRDelimAst:pa,emStrongRDelimUnd:fa,escape:Gs,link:Aa,nolink:Ma,punctuation:na,reflink:za,reflinkSearch:Ra,tag:Ca,text:ta,url:ze},Ha={...cn,emStrongLDelim:da,emStrongRDelimAst:ma,emStrongRDelimUnd:va,link:E(/^!?\[(label)\]\((.*?)\)/).replace("label",Et).getRegex(),reflink:E(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Et).getRegex()},dn={...cn,emStrongRDelimAst:ua,emStrongLDelim:oa,delLDelim:ba,delRDelim:wa,url:E(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("emailProtocol",Da).replace("protocol",pi).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:E(/^(?:[A-Za-z0-9.+-]+(?=@)|[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|wwwStart|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace("protocol",pi).replace(/emailProtocol/g,/(?:mailto|xmpp):/).replace("wwwStart",Gn?"(?<![^\\s*_~(])www\\.":"www\\.").getRegex()},_a={...dn,br:E(ai).replace("{2,}","*").getRegex(),text:E(dn.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Lt={normal:on,gfm:Ks,pedantic:Qs},it={normal:cn,gfm:dn,breaks:_a,pedantic:Ha},Fa={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ui=t=>Fa[t];function G(t,e){if(e){if(_.escapeTest.test(t))return t.replace(_.escapeReplace,ui)}else if(_.escapeTestNoEncode.test(t))return t.replace(_.escapeReplaceNoEncode,ui);return t}function Na(t){return _.numericCharacterReference.test(t)?t.replace(_.numericCharacterReferenceOrAmpersand,(e,n,i)=>{if(n===void 0&&i===void 0)return"&amp;";let s=n===void 0?Number.parseInt(i,16):Number.parseInt(n,10);return s===0||s>1114111||s>=55296&&s<=57343?"\uFFFD":s===38?"&amp;":String.fromCodePoint(s)}):t}function hi(t){try{t=encodeURI(t).replace(_.percentDecode,"%")}catch{return null}return t}function pn(t,e){let n=t.replace(_.findPipe,(l,a,r)=>{let o=!1,c=a;for(;--c>=0&&r[c]==="\\";)o=!o;return o?"|":" |"}),i=n.split(_.splitPipe),s=0;if(i[0].trim()||i.shift(),i.length>0&&!i.at(-1)?.trim()&&i.pop(),e)if(i.length>e)i.splice(e);else for(;i.length<e;)i.push("");for(;s<i.length;s++)i[s]=i[s].trim().replace(_.slashPipe,"|");return i}function ke(t,e,n){let i=t.length;if(i===0)return"";let s=0;for(;s<i;){let l=t.charAt(i-s-1);if(l===e&&!n)s++;else if(l!==e&&n)s++;else break}return t.slice(0,i-s)}function mi(t){let e=t.split(`
10
- `),n=e.length-1;for(;n>=0&&_.blankLine.test(e[n]);)n--;return e.length-n<=2?t:e.slice(0,n+1).join(`
11
- `)}function Tt(t,e=!1){let n=e?_.multipleSpaceGlobal:_.multipleSpaceTabGlobal;return t.trim().replace(n," ").toLowerCase().toUpperCase().toLowerCase()}function fi(t,e){if(t.indexOf(e[0])===-1&&t.indexOf(e[1])===-1)return-1;let n=0;for(let i=0;i<t.length;i++)if(t[i]==="\\")i++;else if(t[i]===e[0])n++;else if(t[i]===e[1]&&(n--,n<0))return i;return n>0?-2:-1}var Ve=new WeakMap;function un(t){let e={"*":-1,_:-1},n=-1,i=t.length;for(let s=0;s<i;s++){let l=t[s];if(l!=="*"&&l!=="_"&&l!=="~")continue;let a=s===0?`
12
- `:t[s-1],r=s+1;for(;r<i&&t[r]===l;)r++;a!==" "&&a!==" "&&a!==`
13
- `&&a!=="\r"&&a!=="\f"&&(l==="~"?n=s:e[l]=s),s=r-1}return{maskedSrc:t,lastPossibleEmStrongCloserIndex:e,lastPossibleDelCloserIndex:n}}function Oa(t,e){let n=un(e),i=Ve.get(t);i?i.push(n):Ve.set(t,[n])}function qa(t){let e=Ve.get(t);e&&(e.pop(),e.length===0&&Ve.delete(t))}function gi(t,e,n){let i=Ve.get(t)?.at(-1);return i&&i.maskedSrc===e?i.lastPossibleEmStrongCloserIndex[n]:un(e).lastPossibleEmStrongCloserIndex[n]}function vi(t,e){let n=Ve.get(t)?.at(-1);return n&&n.maskedSrc===e?n.lastPossibleDelCloserIndex:un(e).lastPossibleDelCloserIndex}function st(t,e=0){let n=e,i="";for(let s of t)if(s===" "){let l=4-n%4;i+=" ".repeat(l),n+=l}else i+=s,n++;return i}function ja(t){let e,n=!1;return t.map(i=>{if(n)return i;let{depth:s,expanded:l,keptIndent:a,content:r}=Va(i,e?.depth??1/0);if(e?.depth!==s&&(e=void 0),e){let c=_.blockquoteFenceClose.exec(r)?.[1];return!c||c[0]!==e.marker[0]||c.length<e.marker.length?a:(e=void 0,l)}if(n=_.blockquoteListItemStart.test(r),n)return i;let o=_.blockquoteFenceOpen.exec(r)?.[1];return o&&(e={marker:o,depth:s}),l}).join(`
14
- `)}function Va(t,e){let n=0,i=0,s=0,l=0,a="";for(;s<e;){let d=n,m=i;for(;t[d]===" "||t[d]===" ";)m+=bi(t[d],m),d++;if(t[d]!==">"||m-l>3)break;a+=" ".repeat(m-i)+">",s++,n=d+1,i=m+1,l=t[n]===" "||t[n]===" "?i+1:i}if(s===0)return{depth:s,expanded:t,keptIndent:t,content:t};let r="",o="";for(;(t[n]===" "||t[n]===" ")&&i<l+4;){let d=bi(t[n],i);r+=" ".repeat(d),o+=i<l&&d>1?" ".repeat(d):t[n],i+=d,n++}let c=t.slice(n);return{depth:s,expanded:a+r+c,keptIndent:a+o+c,content:" ".repeat(Math.max(0,i-l))+c}}function bi(t,e){return t===" "?4-e%4:1}function Wa(t,e){let n="";for(let i=0;i<t.length;i++){if(t[i]==="`"){let s=e.inline.code.exec(t.slice(i));if(s){n+=s[0],i+=s[0].length-1;continue}}if(t[i]==="\\"&&(t[i+1]==="["||t[i+1]==="]")){n+=t[i+1],i++;continue}n+=t[i]}return n}function ki(t,e,n,i,s){let l=e.href,a=e.title||null,r=Wa(t[1],s),o=t[0].charAt(0)==="!",c=i.state.inLink,d=i.state.linkEmitted,m=i.state.inRawBlock;i.state.inLink=!0,i.state.linkEmitted=!1;let p=i.inlineTokens(r),h=i.state.linkEmitted;if(i.state.linkEmitted=d,i.state.inLink=c,!o){if(h){i.state.inRawBlock=m;return}i.state.linkEmitted=!0}return{type:o?"image":"link",raw:n,href:l,title:a,text:r,tokens:p}}function Ua(t,e,n,i){let s=t.match(n.other.indentCodeCompensation);if(s===null)return e;let l=s[1].length;return e.split(`
15
- `).map(a=>{let r=a.match(n.other.beginningSpace);if(r===null)return a;let[o]=r,c=o.indexOf(" ");if(c!==-1&&c<l){if(i)return" ".repeat(4-l)+a.slice(c+1);if(t[l]==="~")return a}return a.slice(Math.min(o.length,l))}).join(`
16
- `)}function wi(t,e,n,i){if(!e.includes("<"))return!1;for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="`"){let r=i.inline.code.exec(e.slice(s));if(r){s+=r[0].length-1;continue}}if(e[s]!=="<")continue;let l=t.slice(n+s),a=i.inline.tag.exec(l)||i.inline.autolink.exec(l);if(a){if(a[0].length>e.length-s)return!0;s+=a[0].length-1}}return!1}var Be=class{options;rules;lexer;constructor(t){this.options=t||Ae}space(t){let e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){let e=this.rules.block.code.exec(t);if(e){let n=this.options.pedantic?e[0]:mi(e[0]),i=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:i}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],i=Ua(n,e[3]||"",this.rules,this.lexer.state.top&&!this.lexer.state.inBlockquote);e[3]!==void 0&&(i===""||i.endsWith(`
8
+ `).join("\r")}async function _s(u){let b=Rs(u.clipboardData);if(b){u.preventDefault(),u.stopPropagation();let W=Date.now();if(W-It<50)return;It=W,await pn(b);return}let S=u.clipboardData?.getData("text/plain");if(!S)return;u.preventDefault(),u.stopPropagation();let P=Date.now();P-It<50||(It=P,i.pasteText(si(S)))}let lt=0;function Fs(u){u.preventDefault(),lt++,ti(u.dataTransfer)&&e.classList.add("terminal-drag-over")}function Ns(u){u.preventDefault(),u.dataTransfer&&(u.dataTransfer.dropEffect="copy")}function js(u){u.preventDefault(),lt--,lt<=0&&(lt=0,e.classList.remove("terminal-drag-over"))}async function qs(u){u.preventDefault(),lt=0,e.classList.remove("terminal-drag-over");let b=ti(u.dataTransfer);b&&await pn(b)}function ai(u){!Be||u.key!=="Escape"||nt||u.defaultPrevented||u.repeat||u.metaKey||u.ctrlKey||u.altKey||i.isFocused()&&(u.preventDefault(),u.stopPropagation(),R("\x1B"))}e.addEventListener("paste",_s),e.addEventListener("dragenter",Fs),e.addEventListener("dragover",Ns),e.addEventListener("dragleave",js),e.addEventListener("drop",qs),document.addEventListener("keydown",ai,!0);function Os(u){if(u.touches.length!==1){r=null;return}let b=u.touches[0];if(!b)return;L();let S=e.getBoundingClientRect(),P=b.clientX-S.left<S.width*.4?"tui":"history",W=b.clientY-S.top<S.height*.5;r={startX:b.clientX,startY:b.clientY,lastX:b.clientX,lastY:b.clientY,lastT:performance.now(),velocity:0,scrolling:!1,zone:P,tuiUp:W,sent:!1},u.stopPropagation()}function Vs(u){if(!r||u.touches.length!==1)return;let b=u.touches[0];if(!b)return;let S=b.clientY-r.startY,P=b.clientX-r.startX;if(!r.scrolling){if(Math.abs(S)<8||Math.abs(S)<Math.abs(P))return;r.scrolling=!0,$=Date.now()+500}u.preventDefault(),u.stopPropagation();let W=performance.now(),ke=b.clientY-r.lastY;if(r.zone==="tui"){r.sent||(r.sent=!0,R(r.tuiUp?"\x1B[5~":"\x1B[6~"),k(r.tuiUp)),r.lastX=b.clientX,r.lastY=b.clientY,r.lastT=W;return}let Re=W-r.lastT;Re>0&&(r.velocity=ke/Re),Js(-ke),r.lastX=b.clientX,r.lastY=b.clientY,r.lastT=W}function Ws(u){if(!r)return;let b=r.scrolling,S=r.zone,P=r.tuiUp,W=r.velocity;if(r=null,u.stopPropagation(),S==="tui"){b||(R(P?"\x1B[5~":"\x1B[6~"),k(P),$=Date.now()+500,u.preventDefault());return}if(!b){i.focus();return}$=Date.now()+500,u.preventDefault(),W&&M(W)}function Us(u){r=null,L(),u.stopPropagation()}function Zs(u){u.pointerType==="touch"&&Date.now()<$&&(u.preventDefault(),u.stopPropagation())}function Js(u){let b=i.cellHeight(),S=b>0?Math.round(u/b):u>0?1:-1;S===0&&(S=u>0?1:-1),i.scrollLines(S)}e.addEventListener("touchstart",Os,{passive:!0,capture:!0}),e.addEventListener("touchmove",Vs,{passive:!1,capture:!0}),e.addEventListener("touchend",Ws,{passive:!1,capture:!0}),e.addEventListener("touchcancel",Us,{passive:!0,capture:!0}),e.addEventListener("pointerup",Zs,!0);function li(){J()}window.addEventListener("resize",li),window.visualViewport?.addEventListener("resize",J),window.visualViewport?.addEventListener("scroll",J);let ri=new ResizeObserver(()=>J());ri.observe(e),document.fonts?.ready.then(()=>{J(),setTimeout(J,50),setTimeout(J,200)}),e.addEventListener("focusin",Bs,!0);async function Ys(){if(document.fonts?.ready)try{await Promise.race([document.fonts.ready,new Promise(u=>setTimeout(u,1e3))])}catch{}}return requestAnimationFrame(()=>{Z()&&oe(),(async()=>(await Ys(),Z()&&j({type:"resize",cols:i.cols,rows:i.rows}),E(),J()))()}),{destroy(){if(z=!0,L(),Ye(!1),at&&clearTimeout(at),document.removeEventListener("mousemove",un,!0),document.removeEventListener("mouseup",hn,!0),s){try{s.close(1e3,"session switch")}catch{}s=void 0}e.innerHTML="",e.classList.remove("terminal-pending"),window.removeEventListener("resize",li),ri.disconnect(),document.removeEventListener("keydown",ai,!0)},focus(){i.focus()},sendInput(u){R(u)},toggleCopyMode(){ii()}}})()}var di={menu:"M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z",close:"M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7a1 1 0 1 0-1.41 1.41L10.59 12l-4.89 4.89a1 1 0 1 0 1.41 1.41L12 13.41l4.89 4.89a1 1 0 1 0 1.41-1.41L13.41 12l4.89-4.89a1 1 0 0 0 0-1.4z",search:"M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z",refresh:"M17.65 6.35A7.96 7.96 0 0 0 12 4a8 8 0 1 0 8 8h-2a6 6 0 1 1-6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM5.92 19H5v-.92l9.06-9.06.92.92L5.92 19zm13.66-12.83a1 1 0 0 0 0-1.41l-1.34-1.34a1 1 0 0 0-1.41 0l-1.05 1.05 2.75 2.75 1.05-1.05z",delete:"M15 4V3H9v1H4v2h1.5l.81 13.05A2 2 0 0 0 8.3 21h7.4a2 2 0 0 0 1.99-1.95L18.5 6H20V4h-5zm-5.5 2h5l-.75 12h-3.5L9.5 6z",check:"M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",sessions:"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z",notes:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",schedule:"M19 4h-1V2h-2v2H8V2H6v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 16H5V10h14v10zM9 14H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-8 4H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z",agents:"M12 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm0 8a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm-7 13v-2a5 5 0 0 1 5-5h4a5 5 0 0 1 5 5v2h2v-2a7 7 0 0 0-7-7H10a7 7 0 0 0-7 7v2h2z",history:"M13 3a9 9 0 0 0-9 9H1l4 4 4-4H6a7 7 0 1 1 7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.96 8.96 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.25 2.55.75-1.23-3.5-2.08V8H12z","quick-commands":"M13 3 4 14h7l-1 7 9-11h-7l1-7z",windows:"M4 6h16v2H4V6zm0 5h10v2H4v-2zm0 5h16v2H4v-2z",terminal:"M4 17.6 6.4 20l8-8-8-8L4 6.4 11.6 12 4 17.6zM20 18h-8v2h8v-2z",microphone:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z",keyboard:"M20 5H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-9 3h2v2h-2V8zm0 3h2v2h-2v-2zM8 8h2v2H8V8zm0 3h2v2H8v-2zm-1 2H5v-2h2v2zm0-3H5V8h2v2zm9 7H8v-2h8v2zm0-4h-2v-2h2v2zm0-3h-2V8h2v2zm3 3h-2v-2h2v2zm0-3h-2V8h2v2z",bot:"M11 2h2v3h2a3 3 0 0 1 3 3v1h1a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-1v1a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3v-1H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2h1V8a3 3 0 0 1 3-3h2V2zm-2 6v1h6V8H9zm-2 5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm10 0a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z",layers:"M12 2 2 7l10 5 10-5-10-5zm0 7.5L4.5 5.8 12 2l7.5 3.8L12 9.5zM2 12l10 5 10-5-1.9-.95L12 14.9l-8.1-3.85L2 12zm0 4.5 10 5 10-5-1.9-.95L12 19.4l-8.1-3.85-1.9.95z",inbox:"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zm0 16H5v-3h3.6a3.5 3.5 0 0 0 6.8 0H19v3zm0-5h-4.7a3.5 3.5 0 0 1-6.6 0H5V5h14v9z","chevron-down":"M7.4 8.6 12 13.2l4.6-4.6L18 10l-6 6-6-6 1.4-1.4z",settings:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6a3.6 3.6 0 1 1 0-7.2 3.6 3.6 0 0 1 0 7.2z",pin:"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4z","pin-outline":"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4zm-4.8 7.2V11l2-2V4h1.6v5l2 2v5.2H11.2z",folder:"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",file:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",worktree:"M6 3a3 3 0 0 0-1 5.83v6.34a3 3 0 1 0 2 0V8.83A3 3 0 0 0 6 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm0 12a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM18 3a3 3 0 0 0-1 5.83V9a4 4 0 0 1-4 4h-2a3 3 0 1 0 0 2h2a6 6 0 0 0 6-6v-.17A3 3 0 0 0 18 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM9 13a1 1 0 1 1 0 2 1 1 0 0 1 0-2z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",export:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",chevronRight:"M9.29 6.71a1 1 0 0 0 0 1.41L13.17 12l-3.88 3.88a1 1 0 1 0 1.41 1.41l4.59-4.59a1 1 0 0 0 0-1.41L10.7 6.7a1 1 0 0 0-1.41.01z",lightning:"M11 21h-1l1-7H7.5c-.58 0-.57-.32-.38-.66.19-.33.51-.89.73-1.27L13 3h1l-1 7h3.5c.49 0 .56.33.47.51l-.07.15c-.22.46-.58 1.18-.78 1.58L11 21z","git-branch":"M13.5 7a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zm0 10a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zM11 9.5v5.1a4.03 4.03 0 0 0-3-.1V9.4a4.03 4.03 0 0 0 3 .1z",external:"M14 3h7v7h-2V6l-9.29 9.29-1.41-1.41L17.59 4.5H14V3zm4 16H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7h-2v7z",play:"M8 5v14l11-7L8 5z",stop:"M6 6h12v12H6V6z",warning:"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z",attach:"M16.5 6v11.5c0 2.5-2 4.5-4.5 4.5s-4.5-2-4.5-4.5V5c0-1.4 1.1-2.5 2.5-2.5S12.5 3.6 12.5 5v10.5c0 .6-.4 1-1 1s-1-.4-1-1V6H9v9.5c0 1.4 1.1 2.5 2.5 2.5s2.5-1.1 2.5-2.5V5C14 2.8 12.2 1 10 1S6 2.8 6 5v12.5c0 3.6 2.9 6.5 6.5 6.5s6.5-2.9 6.5-6.5V6h-2.5z",info:"M11 7h2v2h-2V7zm0 4h2v6h-2v-6zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z",shield:"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25z","shield-up":"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25zM13 8.6v4.6h2l-3 3.6-3-3.6h2V8.6h2z","shield-alert":"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25zM11 7.5h2v5h-2v-5zm0 6.5h2v2h-2v-2z",spinner:"M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46A7.93 7.93 0 0 0 20 12c0-4.42-3.58-8-8-8z",dots:"M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"};function ia(e){return di[e]??di.menu}function re(e,t=""){return`<svg viewBox="0 0 24 24" fill="currentColor"${t?" "+t:""}><path d="${ia(e)}"/></svg>`}function mn(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var _e=mn();function pi(e){_e=e}var Fe={exec:()=>null};function Ne(e){let t=[];return n=>{let i=Math.max(0,Math.min(3,n-1)),s=t[i];return s||(s=e(i),t[i]=s),s}}function C(e,t=""){let n=typeof e=="string"?e:e.source,i={replace:(s,a)=>{let l=typeof a=="string"?a:a.source;return l=l.replace(N.caret,"$1"),n=n.replace(s,l),i},getRegex:()=>new RegExp(n,t)};return i}var ui=((e="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+e)}catch{return!1}})(),hi="^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)",N={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,listInterruptsParagraph:/^ {0,3}(?:[*+-]|0{0,8}1[.)])[ \t]+[^ \t\n]/,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^( {1,3})(?:`{3}|~{3})/,beginningSpace:/^[ \t]{1,3}/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,multipleSpaceTabGlobal:/[ \t\r\n]+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,textIndentedContinuation:/^(?:\n(?: {4}| {0,3}\t)[ \t]*[^ \t\n][^\n]*)+/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+)[ \t]*)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,blockquoteMarkerWhitespace:/^( {0,3}>)(\t[ \t]*)/gm,blockquoteFenceOpen:/^ {0,3}(`{3,}(?=[^`]*$)|~{3,})/,blockquoteFenceClose:/^ {0,3}(`{3,}|~{3,})[ \t]*$/,blockquoteListItemStart:/^ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|$)/,nestedBlockMarker:/^ {0,3}(?:(?:[*+-]|\d{1,9}[.)])(?: |$)|> ?)/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\][ \t]+\S/,listReplaceTask:/^\[[ xX]\][ \t]+/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableHeader:new RegExp(hi+"(?:\\n|$)"),tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/,numericCharacterReferenceOrAmpersand:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:Ne(e=>new RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:Ne(e=>new RegExp(`^ {0,${e}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:Ne(e=>new RegExp(`^ {0,${e}}(?:\`{3,}(?=[^\`\\n]*(?:\\n|$))|~~~)`)),headingBeginRegex:Ne(e=>new RegExp(`^ {0,${e}}#{1,6}(?:\\s|$)`)),pedanticHeadingBeginRegex:Ne(e=>new RegExp(`^ {0,${e}}#`)),htmlBeginRegex:Ne(e=>new RegExp(`^ {0,${e}}(?:</?(?:${bn})(?:[ \\t]+|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,"i")),blockquoteBeginRegex:Ne(e=>new RegExp(`^ {0,${e}}>`)),nestedContainerMarkers:/^(?: {0,3}(?:(?:[*+-]|\d{1,9}[.)])[ \t]+|>[ \t]?))+/},sa=/^(?:[ \t]*(?:\n|$))+/,aa=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,la=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}(?:(?=`)\1`*|(?=~)\1~*)[ \t]*(?=\n|$)|$)/,ot=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,ra=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,gn=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,bn="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",ct=C(" {0,3}(?:</?(?:tag)(?:[ \\t]+|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",bn).getRegex(),fi=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?![ \t]*\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/,mi=C(fi).replace(/bull/g,gn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}(?=[^`\n]*(?:\n|$))|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/\|table/g,"").replace(/html/g,ct).getRegex(),oa=C(fi).replace(/bull/g,gn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}(?=[^`\n]*(?:\n|$))|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).replace(/html/g,ct).getRegex(),vn=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,ca=/^[^\n]+/,kn=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/,da=C(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<(?:\\.|[^\n<>\\])*>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",kn).replace("title",/(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\\n]|\n(?!\n))*'|\((?:\\[\s\S]|[^()\\])*\))/).getRegex(),pa=C(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,gn).getRegex(),wn=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,ua=C("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?:[ \\t]+|\\n|/?>|$)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!(?:script|pre|style|textarea)(?![a-z0-9-]))([a-z][a-z0-9-]*)(?:attribute)*?[ \\t]*/?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",wn).replace("tag",bn).replace("attribute",/[ \t]+[a-zA-Z:_][\w.:-]*(?:[ \t]*=[ \t]*"[^"\n]*"|[ \t]*=[ \t]*'[^'\n]*'|[ \t]*=[ \t]*[^\s"'=<>`]+)?/).getRegex(),gi=e=>C(vn).replace("hr",ot).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",e).replace("html",ct).getRegex(),ha=gi(N.listInterruptsParagraph),fa=gi(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),bi=/ {0,3}> ?(?:(?!blank)(paragraph)|[^\n]*)(?:\n|$)/,ma=C(/^(first)(?:next)*/).replace("first",C(bi).replace("blank",/[ \t]*(?:\n|$)| {4}/).getRegex()).replace("next",C(bi).replace("blank",/[ \t]*(?:\n|$)/).getRegex()).replace(/paragraph/g,fa).getRegex(),yn={blockquote:ma,code:aa,def:da,fences:la,heading:ra,hr:ot,html:ua,lheading:mi,list:pa,newline:sa,paragraph:ha,table:Fe,text:ca},ga=C(hi+"(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",ot).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|0{0,8}1[.)])[ \\t]").replace("html",ct).getRegex(),ba={...yn,lheading:oa,table:ga,paragraph:C(vn).replace("hr",ot).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",N.tableHeader).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",N.listInterruptsParagraph).replace("html",ct).getRegex()},va={...yn,html:C(`^ *(?:comment(?: *\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1>(?: *\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?>(?: *\\n{2,}|\\s*$))`).replace("comment",wn).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Fe,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:C(vn).replace("hr",ot).replace("heading",` *#{1,6} *[^
9
+ ]`).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").replace("lheading",mi).getRegex()},ka=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,wa=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,vi=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,ya=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,we=/[\p{P}\p{S}]/u,Xe=/[\s\p{P}\p{S}]/u,dt=/[^\s\p{P}\p{S}]/u,xa=C(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Xe).getRegex(),Ea=/[\p{Pi}\p{Ps}"']/u,ki=/(?!~)[\p{P}\p{S}]/u,Sa=/(?!~)[\s\p{P}\p{S}]/u,Ca=/(?:[^\s\p{P}\p{S}]|~)/u,La=C(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",ui?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),wi=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,$a=C(wi,"u").replace(/punct/g,we).getRegex(),Ia=C(wi,"u").replace(/punct/g,ki).getRegex(),Ta=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,Aa=C(Ta,"u").replace(/openQuote/g,Ea).replace(/punct/g,we).getRegex(),yi="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Ma=C(yi,"gu").replace(/notPunctSpace/g,dt).replace(/punctSpace/g,Xe).replace(/punct/g,we).getRegex(),za=C(yi,"gu").replace(/notPunctSpace/g,Ca).replace(/punctSpace/g,Sa).replace(/punct/g,ki).getRegex(),Ba="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",Ra=C(Ba,"gu").replace(/notPunctSpace/g,dt).replace(/punctSpace/g,Xe).replace(/punct/g,we).getRegex(),Pa=C("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,dt).replace(/punctSpace/g,Xe).replace(/punct/g,we).getRegex(),Da="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",Ha=C(Da,"gu").replace(/notPunctSpace/g,dt).replace(/punctSpace/g,Xe).replace(/punct/g,we).getRegex(),_a=C(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,we).getRegex(),Fa="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Na=C(Fa,"gu").replace(/notPunctSpace/g,dt).replace(/punctSpace/g,Xe).replace(/punct/g,we).getRegex(),ja=C(/\\(punct)/,"gu").replace(/punct/g,we).getRegex(),qa=C(/(`+)(?:[^`]|[^`][\s\S]*?[^`])\1(?!`)|`+|\\(punct)/,"gu").replace(/punct/g,we).getRegex(),Oa=C(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Va=C(wn).replace("(?:-->|$)","-->").getRegex(),Wa=C("^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Va).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),xi=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,At=C(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace("brackets",xi).getRegex(),Mt=/\\[^ \t\n\x00-\x1f]|\\(?=[ \t\n])|[^ \t\n\x00-\x1f\\()]/,Ua=C(/\((?:char)*\)/).replace("char",Mt).getRegex(),Za=C(/\((?:char|p1)*\)/).replace("char",Mt).replace("p1",Ua).getRegex(),Ja=C(/\((?:char|p2)*\)/).replace("char",Mt).replace("p2",Za).getRegex(),Ya=C(/(?!<)(?:char|p3)+/).replace("char",Mt).replace("p3",Ja).getRegex(),Xa=C(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace("label",At).replace("href",C(/<(?:\\.|[^\n<>\\])*>|bareHref|(?=\))/).replace("bareHref",Ya).getRegex()).replace("title",/"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|\((?:\\[\s\S]|[^)\\])*\)/).getRegex(),Ka=C(/^!?\[(label)\]\[(ref)\]/).replace("label",At).replace("ref",kn).getRegex(),Qa=C(/^!?\[(ref)\](?:\[\])?/).replace("ref",kn).getRegex(),Ei=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,Ga=C(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace("brackets",xi).getRegex(),el=C("reflink|nolink(?!\\()","g").replace("reflink",C(/^!?\[(label)\]\[(ref)\]/).replace("label",Ga).replace("ref",Ei).getRegex()).replace("nolink",C(/^!?\[(ref)\](?:\[\])?/).replace("ref",Ei).getRegex()).getRegex(),Si=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,tl=/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/,nl=C(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,tl).getRegex(),xn={_backpedal:Fe,anyPunctuation:ja,anyPunctuationOutsideCode:qa,autolink:Oa,blockSkip:La,br:vi,code:wa,del:Fe,delLDelim:Fe,delRDelim:Fe,emStrongLDelim:$a,emStrongRDelimAst:Ma,emStrongRDelimUnd:Pa,escape:ka,link:Xa,nolink:Qa,punctuation:xa,reflink:Ka,reflinkSearch:el,tag:Wa,text:ya,url:Fe},il={...xn,emStrongLDelim:Aa,emStrongRDelimAst:Ra,emStrongRDelimUnd:Ha,link:C(/^!?\[(label)\]\((.*?)\)/).replace("label",At).getRegex(),reflink:C(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",At).getRegex()},En={...xn,emStrongRDelimAst:za,emStrongLDelim:Ia,delLDelim:_a,delRDelim:Na,url:C(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("emailProtocol",nl).replace("protocol",Si).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:C(/^(?:[A-Za-z0-9.+-]+(?=@)|[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|wwwStart|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace("protocol",Si).replace(/emailProtocol/g,/(?:mailto|xmpp):/).replace("wwwStart",ui?"(?<![^\\s*_~(])www\\.":"www\\.").getRegex()},sl={...En,br:C(vi).replace("{2,}","*").getRegex(),text:C(En.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},zt={normal:yn,gfm:ba,pedantic:va},pt={normal:xn,gfm:En,breaks:sl,pedantic:il},al={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Ci=e=>al[e];function te(e,t){if(t){if(N.escapeTest.test(e))return e.replace(N.escapeReplace,Ci)}else if(N.escapeTestNoEncode.test(e))return e.replace(N.escapeReplaceNoEncode,Ci);return e}function ll(e){return N.numericCharacterReference.test(e)?e.replace(N.numericCharacterReferenceOrAmpersand,(t,n,i)=>{if(n===void 0&&i===void 0)return"&amp;";let s=n===void 0?Number.parseInt(i,16):Number.parseInt(n,10);return s===0||s>1114111||s>=55296&&s<=57343?"\uFFFD":s===38?"&amp;":String.fromCodePoint(s)}):e}function Li(e){try{e=encodeURI(e).replace(N.percentDecode,"%")}catch{return null}return e}function Sn(e,t){let n=e.replace(N.findPipe,(a,l,r)=>{let o=!1,c=l;for(;--c>=0&&r[c]==="\\";)o=!o;return o?"|":" |"}),i=n.split(N.splitPipe),s=0;if(i[0].trim()||i.shift(),i.length>0&&!i.at(-1)?.trim()&&i.pop(),t)if(i.length>t)i.splice(t);else for(;i.length<t;)i.push("");for(;s<i.length;s++)i[s]=i[s].trim().replace(N.slashPipe,"|");return i}function Ce(e,t,n){let i=e.length;if(i===0)return"";let s=0;for(;s<i;){let a=e.charAt(i-s-1);if(a===t&&!n)s++;else if(a!==t&&n)s++;else break}return e.slice(0,i-s)}function $i(e){let t=e.split(`
10
+ `),n=t.length-1;for(;n>=0&&N.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
11
+ `)}function Bt(e,t=!1){let n=t?N.multipleSpaceGlobal:N.multipleSpaceTabGlobal;return e.trim().replace(n," ").toLowerCase().toUpperCase().toLowerCase()}function Ii(e,t){if(e.indexOf(t[0])===-1&&e.indexOf(t[1])===-1)return-1;let n=0;for(let i=0;i<e.length;i++)if(e[i]==="\\")i++;else if(e[i]===t[0])n++;else if(e[i]===t[1]&&(n--,n<0))return i;return n>0?-2:-1}var Ke=new WeakMap;function Cn(e){let t={"*":-1,_:-1},n=-1,i=e.length;for(let s=0;s<i;s++){let a=e[s];if(a!=="*"&&a!=="_"&&a!=="~")continue;let l=s===0?`
12
+ `:e[s-1],r=s+1;for(;r<i&&e[r]===a;)r++;l!==" "&&l!==" "&&l!==`
13
+ `&&l!=="\r"&&l!=="\f"&&(a==="~"?n=s:t[a]=s),s=r-1}return{maskedSrc:e,lastPossibleEmStrongCloserIndex:t,lastPossibleDelCloserIndex:n}}function rl(e,t){let n=Cn(t),i=Ke.get(e);i?i.push(n):Ke.set(e,[n])}function ol(e){let t=Ke.get(e);t&&(t.pop(),t.length===0&&Ke.delete(e))}function Ti(e,t,n){let i=Ke.get(e)?.at(-1);return i&&i.maskedSrc===t?i.lastPossibleEmStrongCloserIndex[n]:Cn(t).lastPossibleEmStrongCloserIndex[n]}function Ai(e,t){let n=Ke.get(e)?.at(-1);return n&&n.maskedSrc===t?n.lastPossibleDelCloserIndex:Cn(t).lastPossibleDelCloserIndex}function ut(e,t=0){let n=t,i="";for(let s of e)if(s===" "){let a=4-n%4;i+=" ".repeat(a),n+=a}else i+=s,n++;return i}function cl(e){let t,n=!1;return e.map(i=>{if(n)return i;let{depth:s,expanded:a,keptIndent:l,content:r}=dl(i,t?.depth??1/0);if(t?.depth!==s&&(t=void 0),t){let c=N.blockquoteFenceClose.exec(r)?.[1];return!c||c[0]!==t.marker[0]||c.length<t.marker.length?l:(t=void 0,a)}if(n=N.blockquoteListItemStart.test(r),n)return i;let o=N.blockquoteFenceOpen.exec(r)?.[1];return o&&(t={marker:o,depth:s}),a}).join(`
14
+ `)}function dl(e,t){let n=0,i=0,s=0,a=0,l="";for(;s<t;){let d=n,v=i;for(;e[d]===" "||e[d]===" ";)v+=Mi(e[d],v),d++;if(e[d]!==">"||v-a>3)break;l+=" ".repeat(v-i)+">",s++,n=d+1,i=v+1,a=e[n]===" "||e[n]===" "?i+1:i}if(s===0)return{depth:s,expanded:e,keptIndent:e,content:e};let r="",o="";for(;(e[n]===" "||e[n]===" ")&&i<a+4;){let d=Mi(e[n],i);r+=" ".repeat(d),o+=i<a&&d>1?" ".repeat(d):e[n],i+=d,n++}let c=e.slice(n);return{depth:s,expanded:l+r+c,keptIndent:l+o+c,content:" ".repeat(Math.max(0,i-a))+c}}function Mi(e,t){return e===" "?4-t%4:1}function pl(e,t){let n="";for(let i=0;i<e.length;i++){if(e[i]==="`"){let s=t.inline.code.exec(e.slice(i));if(s){n+=s[0],i+=s[0].length-1;continue}}if(e[i]==="\\"&&(e[i+1]==="["||e[i+1]==="]")){n+=e[i+1],i++;continue}n+=e[i]}return n}function zi(e,t,n,i,s){let a=t.href,l=t.title||null,r=pl(e[1],s),o=e[0].charAt(0)==="!",c=i.state.inLink,d=i.state.linkEmitted,v=i.state.inRawBlock;i.state.inLink=!0,i.state.linkEmitted=!1;let h=i.inlineTokens(r),p=i.state.linkEmitted;if(i.state.linkEmitted=d,i.state.inLink=c,!o){if(p){i.state.inRawBlock=v;return}i.state.linkEmitted=!0}return{type:o?"image":"link",raw:n,href:a,title:l,text:r,tokens:h}}function ul(e,t,n,i){let s=e.match(n.other.indentCodeCompensation);if(s===null)return t;let a=s[1].length;return t.split(`
15
+ `).map(l=>{let r=l.match(n.other.beginningSpace);if(r===null)return l;let[o]=r,c=o.indexOf(" ");if(c!==-1&&c<a){if(i)return" ".repeat(4-a)+l.slice(c+1);if(e[a]==="~")return l}return l.slice(Math.min(o.length,a))}).join(`
16
+ `)}function Bi(e,t,n,i){if(!t.includes("<"))return!1;for(let s=0;s<t.length;s++){if(t[s]==="\\"){s++;continue}if(t[s]==="`"){let r=i.inline.code.exec(t.slice(s));if(r){s+=r[0].length-1;continue}}if(t[s]!=="<")continue;let a=e.slice(n+s),l=i.inline.tag.exec(a)||i.inline.autolink.exec(a);if(l){if(l[0].length>t.length-s)return!0;s+=l[0].length-1}}return!1}var je=class{options;rules;lexer;constructor(e){this.options=e||_e}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let n=this.options.pedantic?t[0]:$i(t[0]),i=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:i}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],i=ul(n,t[3]||"",this.rules,this.lexer.state.top&&!this.lexer.state.inBlockquote);t[3]!==void 0&&(i===""||i.endsWith(`
17
17
  `))&&(i+=`
18
- `);let s=e[2];if(s){let l=0,a=s.length;for(;l<a&&(s[l]===" "||s[l]===" ");)l++;for(;a>l&&(s[a-1]===" "||s[a-1]===" ");)a--;s=s.slice(l,a).replace(this.rules.inline.anyPunctuation,"$1")}return{type:"code",raw:n,lang:s,text:i}}}heading(t){let e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(this.rules.other.endingHash.test(n)){let i=ke(n,"#");(this.options.pedantic||!i||this.rules.other.endingSpaceTabChar.test(i))&&(n=i.trim())}return{type:"heading",raw:ke(e[0],`
19
- `),depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){let e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:ke(e[0],`
20
- `)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=ke(e[0],`
18
+ `);let s=t[2];if(s){let a=0,l=s.length;for(;a<l&&(s[a]===" "||s[a]===" ");)a++;for(;l>a&&(s[l-1]===" "||s[l-1]===" ");)l--;s=s.slice(a,l).replace(this.rules.inline.anyPunctuation,"$1")}return{type:"code",raw:n,lang:s,text:i}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(this.rules.other.endingHash.test(n)){let i=Ce(n,"#");(this.options.pedantic||!i||this.rules.other.endingSpaceTabChar.test(i))&&(n=i.trim())}return{type:"heading",raw:Ce(t[0],`
19
+ `),depth:t[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:Ce(t[0],`
20
+ `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=Ce(t[0],`
21
21
  `).split(`
22
- `),i="",s="",l=[];for(;n.length>0;){let a=!1,r=[],o;for(o=0;o<n.length;o++)if(this.rules.other.blockquoteStart.test(n[o]))r.push(n[o]),a=!0;else if(!a)r.push(n[o]);else break;n=n.slice(o);let c=r.join(`
23
- `),d=(this.lexer.state.top&&!this.lexer.state.inBlockquote&&c.includes(" ")?ja(r):c).replace(this.rules.other.blockquoteMarkerWhitespace,(b,w,y)=>y.startsWith(" ")?w+" "+y.slice(1):w+st(y,w.length)).replace(this.rules.other.blockquoteSetextReplace,`
22
+ `),i="",s="",a=[];for(;n.length>0;){let l=!1,r=[],o;for(o=0;o<n.length;o++)if(this.rules.other.blockquoteStart.test(n[o]))r.push(n[o]),l=!0;else if(!l)r.push(n[o]);else break;n=n.slice(o);let c=r.join(`
23
+ `),d=(this.lexer.state.top&&!this.lexer.state.inBlockquote&&c.includes(" ")?cl(r):c).replace(this.rules.other.blockquoteMarkerWhitespace,(m,k,w)=>w.startsWith(" ")?k+" "+w.slice(1):k+ut(w,k.length)).replace(this.rules.other.blockquoteSetextReplace,`
24
24
  $1`).replace(this.rules.other.blockquoteSetextReplace2,"");i=i?`${i}
25
25
  ${c}`:c,s=s?`${s}
26
- ${d}`:d;let m=this.lexer.state.top,p=this.lexer.state.inBlockquote,h=this.lexer.state.lastToken;if(this.lexer.state.top=!0,this.lexer.state.inBlockquote=!0,this.lexer.blockTokens(d,l,!0),this.lexer.state.top=m,this.lexer.state.inBlockquote=p,n.length===0)break;let f=l.at(-1);if(f?.type==="code"||f?.type==="heading"||f?.type==="hr"||f?.type==="html"||f?.type==="table")break;if(f?.type==="blockquote"){let b=f,w=n.join(`
27
- `),y=b.raw+`
28
- `+w.replace(this.rules.other.blockquoteSetextReplace2,"");this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=l.at(-2);let C=this.blockquote(y);this.lexer.state.inBlockquote=p,this.lexer.state.lastToken=h,l[l.length-1]=C;let M=y.substring(C.raw.length).replace(/^\n/,""),T=M?M.split(`
29
- `).length:0,I=T?n.slice(0,-T):n;if(I.length>0&&(i=`${i}
30
- ${I.join(`
31
- `)}`),s=s.substring(0,s.length-b.text.length)+C.text,n=n.slice(I.length),n.length>0&&this.rules.other.blockquoteStart.test(n[0]))continue;break}else if(f?.type==="list"){let b=f,w=b.raw+`
26
+ ${d}`:d;let v=this.lexer.state.top,h=this.lexer.state.inBlockquote,p=this.lexer.state.lastToken;if(this.lexer.state.top=!0,this.lexer.state.inBlockquote=!0,this.lexer.blockTokens(d,a,!0),this.lexer.state.top=v,this.lexer.state.inBlockquote=h,n.length===0)break;let f=a.at(-1);if(f?.type==="code"||f?.type==="heading"||f?.type==="hr"||f?.type==="html"||f?.type==="table")break;if(f?.type==="blockquote"){let m=f,k=n.join(`
27
+ `),w=m.raw+`
28
+ `+k.replace(this.rules.other.blockquoteSetextReplace2,"");this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=a.at(-2);let L=this.blockquote(w);this.lexer.state.inBlockquote=h,this.lexer.state.lastToken=p,a[a.length-1]=L;let M=w.substring(L.raw.length).replace(/^\n/,""),$=M?M.split(`
29
+ `).length:0,T=$?n.slice(0,-$):n;if(T.length>0&&(i=`${i}
30
+ ${T.join(`
31
+ `)}`),s=s.substring(0,s.length-m.text.length)+L.text,n=n.slice(T.length),n.length>0&&this.rules.other.blockquoteStart.test(n[0]))continue;break}else if(f?.type==="list"){let m=f,k=m.raw+`
32
32
  `+n.join(`
33
- `);this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=l.at(-2);let y=this.list(w);this.lexer.state.top=m,this.lexer.state.inBlockquote=p,this.lexer.state.lastToken=h,l[l.length-1]=y;let C=y.raw.length>b.raw.length?w.slice(b.raw.length+1,y.raw.length).split(`
34
- `).length:0;if(C>0){let M=n.slice(0,C).join(`
33
+ `);this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=a.at(-2);let w=this.list(k);this.lexer.state.top=v,this.lexer.state.inBlockquote=h,this.lexer.state.lastToken=p,a[a.length-1]=w;let L=w.raw.length>m.raw.length?k.slice(m.raw.length+1,w.raw.length).split(`
34
+ `).length:0;if(L>0){let M=n.slice(0,L).join(`
35
35
  `);i=`${i}
36
36
  ${M}`,s=`${s}
37
- ${M}`}if(n=n.slice(C),n.length>0&&!this.rules.other.blockquoteStart.test(n[0]))break;continue}}return{type:"blockquote",raw:i,tokens:l,text:s}}}list(t){let e=this.rules.block.list.exec(t);if(e){if(!this.options.pedantic&&this.lexer.state.lastToken?.type==="text"&&!this.rules.other.listInterruptsParagraph.test(t))return;let n=t,i=()=>n.length-t.length,s=e[1].trim(),l=s.length>1,a={type:"list",raw:"",ordered:l,start:l?+s.slice(0,-1):"",loose:!1,items:[]};s=l?`\\d{1,9}\\${s.slice(-1)}`:`\\${s}`,this.options.pedantic&&(s=l?s:"[*+-]");let r=this.rules.other.listItemRegex(s),o=!1;for(;t;){let p=!1,h="";if(!(e=r.exec(t))||this.rules.block.hr.test(t))break;let f=i();t=t.substring(e[0].length);let b=e[2].split(`
38
- `,1)[0],w=e[1].length,y=this.options.pedantic?st(b,w):b.replace(this.rules.other.leadingSpaceTab,$=>st($,w)),C=t.split(`
39
- `,1)[0],M=!y.trim(),T=0;if(this.options.pedantic?(T=2,h=y.trimStart()):M?T=w+1:(T=y.search(this.rules.other.nonSpaceChar),T=T>4?1:T,h=y.slice(T),y=h,T+=w),M&&this.rules.other.blankLine.test(C)&&(t=t.substring(C.length+1),p=!0),!p){let $=this.rules.other.nextBulletRegex(T),z=this.rules.other.hrRegex(T),x=this.rules.other.fencesBeginRegex(T),F=this.options.pedantic?this.rules.other.pedanticHeadingBeginRegex(T):this.rules.other.headingBeginRegex(T),B=this.rules.other.htmlBeginRegex(T),Z=this.rules.other.blockquoteBeginRegex(T),A=!1;for(;t;){let Se=t.split(`
40
- `,1)[0],W;if(C=Se,this.options.pedantic?(C=C.replace(this.rules.other.listReplaceNesting," "),W=C):W=C.replace(this.rules.other.leadingSpaceTab,L=>st(L)),x.test(C)||F.test(C)||B.test(C)||Z.test(C)||$.test(C)||z.test(C))break;if(W.search(this.rules.other.nonSpaceChar)>=T||!C.trim())h+=`
41
- `+W.slice(T),A=!1;else{if(M)break;let L=y;if(!this.options.pedantic&&!h.includes(`
42
- `)&&!y.includes(" ")){let q;for(;!z.test(L)&&(q=this.rules.other.nestedBlockMarker.exec(L));)L=L.slice(q[0].length);if(!L.trim())break}if(L.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||x.test(L)||F.test(L)||B.test(L)||z.test(L))break;if(!this.options.pedantic&&!A){let q=y.replace(this.rules.other.nestedContainerMarkers,"");if(this.rules.block.fences.test(q)||this.rules.block.heading.test(q)||this.rules.block.hr.test(q))break}let U=!this.options.pedantic&&/^ {0,3}(?:=+|-+) *$/.test(C)&&this.rules.block.lheading.test(`${y}
43
- ${C}`)?` ${W.replace(/^ {0,3}/,"")}`:C,ve=!this.options.pedantic&&!A&&W.startsWith(" ")?this.rules.block.list.exec(y):null;if(ve?.[2]){let q=ve[1].length,Y=ve[2].replace(this.rules.other.leadingSpaceTab,Ne=>st(Ne,q)),$e=Y.search(this.rules.other.nonSpaceChar);$e>0&&$e<=4&&!this.rules.other.nestedBlockMarker.test(Y.slice($e))&&W.search(this.rules.other.nonSpaceChar)>=q+$e&&this.rules.other.listInterruptsParagraph.test(W.slice(q+$e))&&(U=` ${W}`)}h+=`
44
- `+U,A=!0}M=!C.trim(),t=t.substring(Se.length+1),y=W.slice(T)}}let I=n.slice(f,i());a.loose||(o?a.loose=!0:this.rules.other.doubleBlankLine.test(I)&&(o=!0)),a.items.push({type:"list_item",raw:I,task:!!this.options.gfm&&this.rules.other.listIsTask.test(h),loose:!1,text:h,tokens:[]})}let c=a.items.at(-1);if(c)c.raw=c.raw.trimEnd(),c.text=c.text.trimEnd();else return;a.raw=n.slice(0,i()).trimEnd();let d=[],m=this.lexer.state.top;for(let p of a.items)if(this.lexer.state.top=!1,d.push(this.lexer.inlineQueue.length),p.tokens=this.lexer.blockTokens(p.text,[]),!a.loose){let h=p.tokens.filter(b=>b.type==="space"),f=h.length>0&&h.some(b=>this.rules.other.anyLine.test(b.raw));a.loose=f}this.lexer.state.top=m;for(let p=0;p<a.items.length;p++){let h=a.items[p],f=h.tokens[0];if(h.task&&(f?.type==="text"||f?.type==="paragraph")){h.text=h.text.replace(this.rules.other.listReplaceTask,""),f.raw=f.raw.replace(this.rules.other.listReplaceTask,""),f.text=f.text.replace(this.rules.other.listReplaceTask,"");let b=this.lexer.inlineQueue;for(let y=d[p];y<b.length;y++)if(b[y].tokens===f.tokens){b[y].src=b[y].src.replace(this.rules.other.listReplaceTask,"");break}let w=this.rules.other.listTaskCheckbox.exec(h.raw);if(w){let y={type:"checkbox",raw:w[0]+" ",checked:w[0]!=="[ ]"};h.checked=y.checked,a.loose?h.tokens[0]&&["paragraph","text"].includes(h.tokens[0].type)&&"tokens"in h.tokens[0]&&h.tokens[0].tokens?(h.tokens[0].raw=y.raw+h.tokens[0].raw,h.tokens[0].text=y.raw+h.tokens[0].text,h.tokens[0].tokens.unshift(y)):h.tokens.unshift({type:"paragraph",raw:y.raw,text:y.raw,tokens:[y]}):h.tokens.unshift(y)}}else h.task&&(h.task=!1)}if(a.loose)for(let p of a.items){p.loose=!0;for(let h of p.tokens)h.type==="text"&&(h.type="paragraph")}return a}}html(t){let e=this.rules.block.html.exec(t);if(e){if(this.lexer.state.lastToken?.type==="paragraph"&&!this.rules.other.htmlBeginRegex(4).test(t))return;let n=mi(e[0]);return{type:"html",block:!0,raw:n,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:n}}}def(t){let e=this.rules.block.def.exec(t);if(e){if(!this.rules.other.startAngleBracket.test(e[2])&&fi(e[2],"()")!==-1)return;let n=Tt(e[1],this.options.pedantic),i=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:n,raw:ke(e[0],`
45
- `),href:i,title:s}}}table(t){let e,n;if(this.options.gfm&&!this.options.pedantic){let a=this.rules.other.tableHeader.exec(t);if(!a||!this.rules.other.tableDelimiter.test(a[2])||(e=pn(a[1]),n=a[2].replace(this.rules.other.tableAlignChars,"").split("|"),e.length!==n.length))return}let i=this.rules.block.table.exec(t);if(!i||!this.rules.other.tableDelimiter.test(i[2]))return;e??=pn(i[1]),n??=i[2].replace(this.rules.other.tableAlignChars,"").split("|");let s=i[3]?.trim()?i[3].replace(this.rules.other.tableRowBlankLine,"").split(`
46
- `):[],l={type:"table",raw:ke(i[0],`
47
- `),header:[],align:[],rows:[]};if(e.length===n.length){for(let a of n)this.rules.other.tableAlignRight.test(a)?l.align.push("right"):this.rules.other.tableAlignCenter.test(a)?l.align.push("center"):this.rules.other.tableAlignLeft.test(a)?l.align.push("left"):l.align.push(null);for(let a=0;a<e.length;a++)l.header.push({text:e[a],tokens:this.lexer.inline(e[a]),header:!0,align:l.align[a]});for(let a of s)l.rows.push(pn(a,l.header.length).map((r,o)=>({text:r,tokens:this.lexer.inline(r),header:!1,align:l.align[o]})));return l}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e){let n=e[1].trim();return{type:"heading",raw:ke(e[0],`
48
- `),depth:e[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(t){let e=this.rules.block.paragraph.exec(t);if(e){let n=e[1].charAt(e[1].length-1)===`
49
- `?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){let e=this.rules.block.text.exec(t);if(e){let n=e[0],i=e[0],s=this.rules.other.textIndentedContinuation.exec(t.slice(n.length));return s&&(n+=s[0],i+=s[0].replace(this.rules.other.codeRemoveIndent,"")),{type:"text",raw:n,text:i,tokens:this.lexer.inline(i)}}}escape(t){if(t.charCodeAt(0)!==92)return;let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){if(t.charCodeAt(0)!==60)return;let e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){if(this.lexer.state.linkParenPossible===!1)return;let e=t.charCodeAt(0);if(e!==91&&e!==33)return;let n=this.rules.inline.link.exec(t);if(n){let i=n[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&wi(t,n[1],i,this.rules))return;let s=n[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(s)){if(!this.rules.other.endAngleBracket.test(s))return;let o=ke(s.slice(0,-1),"\\");if((s.length-o.length)%2===0)return}else{let o=fi(n[2],"()");if(o===-2)return;if(o>-1){let c=(n[0].indexOf("!")===0?5:4)+n[1].length+o;n[2]=n[2].substring(0,o),n[0]=n[0].substring(0,c).trim(),n[3]=""}}let l=ke(n[0].slice(0,-1),"\\");if((n[0].length-l.length)%2===0)return;let a=n[2],r="";if(this.options.pedantic){let o=this.rules.other.pedanticHrefTitle.exec(a);o&&(a=o[1],r=o[3])}else r=n[3]?n[3].slice(1,-1):"";return this.options.pedantic&&(a=a.trim()),this.rules.other.startAngleBracket.test(a)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(s)?a=a.slice(1):a=a.slice(1,-1)),ki(n,{href:a&&a.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},n[0],this.lexer,this.rules)}}reflink(t,e){let n=t.charCodeAt(0);if(n!==91&&n!==33)return;let i;if((i=this.rules.inline.reflink.exec(t))||(i=this.rules.inline.nolink.exec(t))){let s=i[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&wi(t,i[1],s,this.rules))return;let l=e[Tt(i[2]||i[1],this.options.pedantic)];if(!l){let a=i[0].charAt(0);return{type:"text",raw:a,text:a}}return ki(i,l,i[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let i=this.rules.inline.emStrongLDelim.exec(t);if(!i||!i[1]&&!i[2]&&!i[3]&&!i[4])return;let s=i[0][0],l=n===s,a=e.length-t.length,r=a;for(;!this.options.pedantic&&r>0&&e[r-1]===s;)r--;let o=[...e.slice(Math.max(0,r-2),r)].at(-1)??"",c=o==="*"||o==="_"||!!this.rules.inline.punctuation.exec(o);r<a&&(n=o);let d=r<a?c:n==="*"||n==="_"||!!this.rules.inline.punctuation.exec(n);if(i[4]&&n.match(this.rules.other.unicodeAlphaNumeric))return;let m=i[1]||i[3]||"";if(!m||!n||d){let p=[...i[0]].length-1,h,f,b=p,w=0,y=a-r+p,C=!this.options.pedantic&&!!o.trim()&&(!!m||s==="*"&&!c);if(s!=="*"&&s!=="_")return;let M=s==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd,T=gi(this,e,s),I=e.length-t.length+p;if(T<I)return;e=e.slice(-1*t.length+p);let $=T-I;for(M.lastIndex=0;(i=M.exec(e))!==null&&!(i.index>$);){if(h=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!h)continue;f=[...h].length;let z=f>b-p;if(i[3]||i[4]){b+=f;continue}else if((i[5]||i[6]||C&&z)&&y%3&&!((y+f)%3)){if(l&&(i[5]||i[6]))break;w+=f;continue}if(b-=f,b>0)continue;f=Math.min(f,f+b+w);let x=[...i[0]][0].length,F=t.slice(0,p+i.index+x+f);if(Math.min(p,f)%2){let Z=F.slice(1,-1);return{type:"em",raw:F,text:Z,tokens:this.lexer.inlineTokens(Z)}}let B=F.slice(2,-2);return{type:"strong",raw:F,text:B,tokens:this.lexer.inlineTokens(B)}}}}codespan(t){if(t.charCodeAt(0)!==96)return;let e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," "),i=this.rules.other.nonSpaceChar.test(n),s=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return i&&s&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){let e=t.charCodeAt(0);if(e!==32&&e!==92&&e!==10)return;let n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t,e,n=""){if(t.charCodeAt(0)!==126)return;let i=this.rules.inline.delLDelim.exec(t);if(i&&(!i[1]||!n||this.rules.inline.punctuation.exec(n))){let s=[...i[0]].length-1,l,a,r=s,o=this.rules.inline.delRDelim,c=vi(this,e),d=e.length-t.length+s;if(c<d)return;e=e.slice(-1*t.length+s);let m=c-d;for(o.lastIndex=0;(i=o.exec(e))!==null&&!(i.index>m);){if(l=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!l||(a=[...l].length,a!==s))continue;if(i[3]||i[4]){r+=a;continue}if(r-=a,r>0)continue;a=Math.min(a,a+r);let p=[...i[0]][0].length,h=t.slice(0,s+i.index+p+a),f=h.slice(s,-s);return{type:"del",raw:h,text:f,tokens:this.lexer.inlineTokens(f)}}}}autolink(t){if(t.charCodeAt(0)!==60)return;let e=this.rules.inline.autolink.exec(t);if(e){let n,i;return e[2]==="@"?(n=e[1],i="mailto:"+n):(n=e[1],i=n),{type:"link",raw:e[0],text:n,href:i,autolink:!0,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,i;if(e[2]==="@")n=e[0],i="mailto:"+n;else{let s;do s=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(s!==e[0]);n=e[0],e[1]==="www."?i="http://"+e[0]:i=e[0]}return{type:"link",raw:e[0],text:n,href:i,autolink:!0,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(t){let e=this.rules.inline.text.exec(t);if(e){let n=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:n?e[0]:Na(e[0]),escaped:n}}}},le=class _n{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Ae,this.options.tokenizer=this.options.tokenizer||new Be,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,linkEmitted:!1,linkParenPossible:!0,top:!0,inBlockquote:!1};let n={other:_,block:Lt.normal,inline:it.normal};this.options.pedantic?(n.block=Lt.pedantic,n.inline=it.pedantic):this.options.gfm&&(n.block=Lt.gfm,this.options.breaks?n.inline=it.breaks:n.inline=it.gfm),this.tokenizer.rules=n}static get rules(){return{block:Lt,inline:it}}static lex(e,n){return new _n(n).lex(e)}static lexInline(e,n){let i=new _n(n);return e.includes("\r")&&(e=e.replace(_.carriageReturn,`
50
- `)),i.inlineTokens(e)}lex(e){e=e.replace(_.carriageReturn,`
51
- `),this.blockTokens(e,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let i=this.inlineQueue[n];this.state.inRawBlock=!1,this.inlineTokens(i.src,i.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,n=[],i=!1){this.tokenizer.lexer=this;let s=this.state.lastToken;this.options.pedantic&&(e=e.replace(_.tabCharGlobal," ").replace(_.spaceLine,""));let l=1/0,a,r=this.options.gfm&&!this.options.pedantic&&this.tokenizer.paragraph===Be.prototype.paragraph;for(;e;){if(e.length<l)l=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}this.state.lastToken=n.at(-1);let o;if(this.options.extensions?.block?.some(d=>(o=d.call({lexer:this},e,n))?(e=e.substring(o.raw.length),n.push(o),!0):!1))continue;if(o=this.tokenizer.space(e)){e=e.substring(o.raw.length);let d=n.at(-1);o.raw.length===1&&d!==void 0?d.raw+=`
52
- `:n.push(o);continue}if(o=this.tokenizer.code(e)){e=e.substring(o.raw.length);let d=n.at(-1);d?.type==="paragraph"||d?.type==="text"?(d.raw+=(d.raw.endsWith(`
37
+ ${M}`}if(n=n.slice(L),n.length>0&&!this.rules.other.blockquoteStart.test(n[0]))break;continue}}return{type:"blockquote",raw:i,tokens:a,text:s}}}list(e){let t=this.rules.block.list.exec(e);if(t){if(!this.options.pedantic&&this.lexer.state.lastToken?.type==="text"&&!this.rules.other.listInterruptsParagraph.test(e))return;let n=e,i=()=>n.length-e.length,s=t[1].trim(),a=s.length>1,l={type:"list",raw:"",ordered:a,start:a?+s.slice(0,-1):"",loose:!1,items:[]};s=a?`\\d{1,9}\\${s.slice(-1)}`:`\\${s}`,this.options.pedantic&&(s=a?s:"[*+-]");let r=this.rules.other.listItemRegex(s),o=!1;for(;e;){let h=!1,p="";if(!(t=r.exec(e))||this.rules.block.hr.test(e))break;let f=i();e=e.substring(t[0].length);let m=t[2].split(`
38
+ `,1)[0],k=t[1].length,w=this.options.pedantic?ut(m,k):m.replace(this.rules.other.leadingSpaceTab,I=>ut(I,k)),L=e.split(`
39
+ `,1)[0],M=!w.trim(),$=0;if(this.options.pedantic?($=2,p=w.trimStart()):M?$=k+1:($=w.search(this.rules.other.nonSpaceChar),$=$>4?1:$,p=w.slice($),w=p,$+=k),M&&this.rules.other.blankLine.test(L)&&(e=e.substring(L.length+1),h=!0),!h){let I=this.rules.other.nextBulletRegex($),B=this.rules.other.hrRegex($),x=this.rules.other.fencesBeginRegex($),A=this.options.pedantic?this.rules.other.pedanticHeadingBeginRegex($):this.rules.other.headingBeginRegex($),z=this.rules.other.htmlBeginRegex($),se=this.rules.other.blockquoteBeginRegex($),D=!1;for(;e;){let Ee=e.split(`
40
+ `,1)[0],K;if(L=Ee,this.options.pedantic?(L=L.replace(this.rules.other.listReplaceNesting," "),K=L):K=L.replace(this.rules.other.leadingSpaceTab,X=>ut(X)),x.test(L)||A.test(L)||z.test(L)||se.test(L)||I.test(L)||B.test(L))break;if(K.search(this.rules.other.nonSpaceChar)>=$||!L.trim())p+=`
41
+ `+K.slice($),D=!1;else{if(M)break;let X=w;if(!this.options.pedantic&&!p.includes(`
42
+ `)&&!w.includes(" ")){let q;for(;!B.test(X)&&(q=this.rules.other.nestedBlockMarker.exec(X));)X=X.slice(q[0].length);if(!X.trim())break}if(X.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||x.test(X)||A.test(X)||z.test(X)||B.test(X))break;if(!this.options.pedantic&&!D){let q=w.replace(this.rules.other.nestedContainerMarkers,"");if(this.rules.block.fences.test(q)||this.rules.block.heading.test(q)||this.rules.block.hr.test(q))break}let Be=!this.options.pedantic&&/^ {0,3}(?:=+|-+) *$/.test(L)&&this.rules.block.lheading.test(`${w}
43
+ ${L}`)?` ${K.replace(/^ {0,3}/,"")}`:L,ae=!this.options.pedantic&&!D&&K.startsWith(" ")?this.rules.block.list.exec(w):null;if(ae?.[2]){let q=ae[1].length,j=ae[2].replace(this.rules.other.leadingSpaceTab,le=>ut(le,q)),ve=j.search(this.rules.other.nonSpaceChar);ve>0&&ve<=4&&!this.rules.other.nestedBlockMarker.test(j.slice(ve))&&K.search(this.rules.other.nonSpaceChar)>=q+ve&&this.rules.other.listInterruptsParagraph.test(K.slice(q+ve))&&(Be=` ${K}`)}p+=`
44
+ `+Be,D=!0}M=!L.trim(),e=e.substring(Ee.length+1),w=K.slice($)}}let T=n.slice(f,i());l.loose||(o?l.loose=!0:this.rules.other.doubleBlankLine.test(T)&&(o=!0)),l.items.push({type:"list_item",raw:T,task:!!this.options.gfm&&this.rules.other.listIsTask.test(p),loose:!1,text:p,tokens:[]})}let c=l.items.at(-1);if(c)c.raw=c.raw.trimEnd(),c.text=c.text.trimEnd();else return;l.raw=n.slice(0,i()).trimEnd();let d=[],v=this.lexer.state.top;for(let h of l.items)if(this.lexer.state.top=!1,d.push(this.lexer.inlineQueue.length),h.tokens=this.lexer.blockTokens(h.text,[]),!l.loose){let p=h.tokens.filter(m=>m.type==="space"),f=p.length>0&&p.some(m=>this.rules.other.anyLine.test(m.raw));l.loose=f}this.lexer.state.top=v;for(let h=0;h<l.items.length;h++){let p=l.items[h],f=p.tokens[0];if(p.task&&(f?.type==="text"||f?.type==="paragraph")){p.text=p.text.replace(this.rules.other.listReplaceTask,""),f.raw=f.raw.replace(this.rules.other.listReplaceTask,""),f.text=f.text.replace(this.rules.other.listReplaceTask,"");let m=this.lexer.inlineQueue;for(let w=d[h];w<m.length;w++)if(m[w].tokens===f.tokens){m[w].src=m[w].src.replace(this.rules.other.listReplaceTask,"");break}let k=this.rules.other.listTaskCheckbox.exec(p.raw);if(k){let w={type:"checkbox",raw:k[0]+" ",checked:k[0]!=="[ ]"};p.checked=w.checked,l.loose?p.tokens[0]&&["paragraph","text"].includes(p.tokens[0].type)&&"tokens"in p.tokens[0]&&p.tokens[0].tokens?(p.tokens[0].raw=w.raw+p.tokens[0].raw,p.tokens[0].text=w.raw+p.tokens[0].text,p.tokens[0].tokens.unshift(w)):p.tokens.unshift({type:"paragraph",raw:w.raw,text:w.raw,tokens:[w]}):p.tokens.unshift(w)}}else p.task&&(p.task=!1)}if(l.loose)for(let h of l.items){h.loose=!0;for(let p of h.tokens)p.type==="text"&&(p.type="paragraph")}return l}}html(e){let t=this.rules.block.html.exec(e);if(t){if(this.lexer.state.lastToken?.type==="paragraph"&&!this.rules.other.htmlBeginRegex(4).test(e))return;let n=$i(t[0]);return{type:"html",block:!0,raw:n,pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:n}}}def(e){let t=this.rules.block.def.exec(e);if(t){if(!this.rules.other.startAngleBracket.test(t[2])&&Ii(t[2],"()")!==-1)return;let n=Bt(t[1],this.options.pedantic),i=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:Ce(t[0],`
45
+ `),href:i,title:s}}}table(e){let t,n;if(this.options.gfm&&!this.options.pedantic){let l=this.rules.other.tableHeader.exec(e);if(!l||!this.rules.other.tableDelimiter.test(l[2])||(t=Sn(l[1]),n=l[2].replace(this.rules.other.tableAlignChars,"").split("|"),t.length!==n.length))return}let i=this.rules.block.table.exec(e);if(!i||!this.rules.other.tableDelimiter.test(i[2]))return;t??=Sn(i[1]),n??=i[2].replace(this.rules.other.tableAlignChars,"").split("|");let s=i[3]?.trim()?i[3].replace(this.rules.other.tableRowBlankLine,"").split(`
46
+ `):[],a={type:"table",raw:Ce(i[0],`
47
+ `),header:[],align:[],rows:[]};if(t.length===n.length){for(let l of n)this.rules.other.tableAlignRight.test(l)?a.align.push("right"):this.rules.other.tableAlignCenter.test(l)?a.align.push("center"):this.rules.other.tableAlignLeft.test(l)?a.align.push("left"):a.align.push(null);for(let l=0;l<t.length;l++)a.header.push({text:t[l],tokens:this.lexer.inline(t[l]),header:!0,align:a.align[l]});for(let l of s)a.rows.push(Sn(l,a.header.length).map((r,o)=>({text:r,tokens:this.lexer.inline(r),header:!1,align:a.align[o]})));return a}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let n=t[1].trim();return{type:"heading",raw:Ce(t[0],`
48
+ `),depth:t[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let n=t[1].charAt(t[1].length-1)===`
49
+ `?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(e){let t=this.rules.block.text.exec(e);if(t){let n=t[0],i=t[0],s=this.rules.other.textIndentedContinuation.exec(e.slice(n.length));return s&&(n+=s[0],i+=s[0].replace(this.rules.other.codeRemoveIndent,"")),{type:"text",raw:n,text:i,tokens:this.lexer.inline(i)}}}escape(e){if(e.charCodeAt(0)!==92)return;let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){if(e.charCodeAt(0)!==60)return;let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){if(this.lexer.state.linkParenPossible===!1)return;let t=e.charCodeAt(0);if(t!==91&&t!==33)return;let n=this.rules.inline.link.exec(e);if(n){let i=n[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&Bi(e,n[1],i,this.rules))return;let s=n[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(s)){if(!this.rules.other.endAngleBracket.test(s))return;let o=Ce(s.slice(0,-1),"\\");if((s.length-o.length)%2===0)return}else{let o=Ii(n[2],"()");if(o===-2)return;if(o>-1){let c=(n[0].indexOf("!")===0?5:4)+n[1].length+o;n[2]=n[2].substring(0,o),n[0]=n[0].substring(0,c).trim(),n[3]=""}}let a=Ce(n[0].slice(0,-1),"\\");if((n[0].length-a.length)%2===0)return;let l=n[2],r="";if(this.options.pedantic){let o=this.rules.other.pedanticHrefTitle.exec(l);o&&(l=o[1],r=o[3])}else r=n[3]?n[3].slice(1,-1):"";return this.options.pedantic&&(l=l.trim()),this.rules.other.startAngleBracket.test(l)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(s)?l=l.slice(1):l=l.slice(1,-1)),zi(n,{href:l&&l.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},n[0],this.lexer,this.rules)}}reflink(e,t){let n=e.charCodeAt(0);if(n!==91&&n!==33)return;let i;if((i=this.rules.inline.reflink.exec(e))||(i=this.rules.inline.nolink.exec(e))){let s=i[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&Bi(e,i[1],s,this.rules))return;let a=t[Bt(i[2]||i[1],this.options.pedantic)];if(!a){let l=i[0].charAt(0);return{type:"text",raw:l,text:l}}return zi(i,a,i[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let i=this.rules.inline.emStrongLDelim.exec(e);if(!i||!i[1]&&!i[2]&&!i[3]&&!i[4])return;let s=i[0][0],a=n===s,l=t.length-e.length,r=l;for(;!this.options.pedantic&&r>0&&t[r-1]===s;)r--;let o=[...t.slice(Math.max(0,r-2),r)].at(-1)??"",c=o==="*"||o==="_"||!!this.rules.inline.punctuation.exec(o);r<l&&(n=o);let d=r<l?c:n==="*"||n==="_"||!!this.rules.inline.punctuation.exec(n);if(i[4]&&n.match(this.rules.other.unicodeAlphaNumeric))return;let v=i[1]||i[3]||"";if(!v||!n||d){let h=[...i[0]].length-1,p,f,m=h,k=0,w=l-r+h,L=!this.options.pedantic&&!!o.trim()&&(!!v||s==="*"&&!c);if(s!=="*"&&s!=="_")return;let M=s==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd,$=Ti(this,t,s),T=t.length-e.length+h;if($<T)return;t=t.slice(-1*e.length+h);let I=$-T;for(M.lastIndex=0;(i=M.exec(t))!==null&&!(i.index>I);){if(p=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!p)continue;f=[...p].length;let B=f>m-h;if(i[3]||i[4]){m+=f;continue}else if((i[5]||i[6]||L&&B)&&w%3&&!((w+f)%3)){if(a&&(i[5]||i[6]))break;k+=f;continue}if(m-=f,m>0)continue;f=Math.min(f,f+m+k);let x=[...i[0]][0].length,A=e.slice(0,h+i.index+x+f);if(Math.min(h,f)%2){let se=A.slice(1,-1);return{type:"em",raw:A,text:se,tokens:this.lexer.inlineTokens(se)}}let z=A.slice(2,-2);return{type:"strong",raw:A,text:z,tokens:this.lexer.inlineTokens(z)}}}}codespan(e){if(e.charCodeAt(0)!==96)return;let t=this.rules.inline.code.exec(e);if(t){let n=t[2].replace(this.rules.other.newLineCharGlobal," "),i=this.rules.other.nonSpaceChar.test(n),s=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return i&&s&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:t[0],text:n}}}br(e){let t=e.charCodeAt(0);if(t!==32&&t!==92&&t!==10)return;let n=this.rules.inline.br.exec(e);if(n)return{type:"br",raw:n[0]}}del(e,t,n=""){if(e.charCodeAt(0)!==126)return;let i=this.rules.inline.delLDelim.exec(e);if(i&&(!i[1]||!n||this.rules.inline.punctuation.exec(n))){let s=[...i[0]].length-1,a,l,r=s,o=this.rules.inline.delRDelim,c=Ai(this,t),d=t.length-e.length+s;if(c<d)return;t=t.slice(-1*e.length+s);let v=c-d;for(o.lastIndex=0;(i=o.exec(t))!==null&&!(i.index>v);){if(a=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!a||(l=[...a].length,l!==s))continue;if(i[3]||i[4]){r+=l;continue}if(r-=l,r>0)continue;l=Math.min(l,l+r);let h=[...i[0]][0].length,p=e.slice(0,s+i.index+h+l),f=p.slice(s,-s);return{type:"del",raw:p,text:f,tokens:this.lexer.inlineTokens(f)}}}}autolink(e){if(e.charCodeAt(0)!==60)return;let t=this.rules.inline.autolink.exec(e);if(t){let n,i;return t[2]==="@"?(n=t[1],i="mailto:"+n):(n=t[1],i=n),{type:"link",raw:t[0],text:n,href:i,autolink:!0,tokens:[{type:"text",raw:n,text:n}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let n,i;if(t[2]==="@")n=t[0],i="mailto:"+n;else{let s;do s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(s!==t[0]);n=t[0],t[1]==="www."?i="http://"+t[0]:i=t[0]}return{type:"link",raw:t[0],text:n,href:i,autolink:!0,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let n=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:n?t[0]:ll(t[0]),escaped:n}}}},pe=class Qn{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||_e,this.options.tokenizer=this.options.tokenizer||new je,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,linkEmitted:!1,linkParenPossible:!0,top:!0,inBlockquote:!1};let n={other:N,block:zt.normal,inline:pt.normal};this.options.pedantic?(n.block=zt.pedantic,n.inline=pt.pedantic):this.options.gfm&&(n.block=zt.gfm,this.options.breaks?n.inline=pt.breaks:n.inline=pt.gfm),this.tokenizer.rules=n}static get rules(){return{block:zt,inline:pt}}static lex(t,n){return new Qn(n).lex(t)}static lexInline(t,n){let i=new Qn(n);return t.includes("\r")&&(t=t.replace(N.carriageReturn,`
50
+ `)),i.inlineTokens(t)}lex(t){t=t.replace(N.carriageReturn,`
51
+ `),this.blockTokens(t,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let i=this.inlineQueue[n];this.state.inRawBlock=!1,this.inlineTokens(i.src,i.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(t,n=[],i=!1){this.tokenizer.lexer=this;let s=this.state.lastToken;this.options.pedantic&&(t=t.replace(N.tabCharGlobal," ").replace(N.spaceLine,""));let a=1/0,l,r=this.options.gfm&&!this.options.pedantic&&this.tokenizer.paragraph===je.prototype.paragraph;for(;t;){if(t.length<a)a=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}this.state.lastToken=n.at(-1);let o;if(this.options.extensions?.block?.some(d=>(o=d.call({lexer:this},t,n))?(t=t.substring(o.raw.length),n.push(o),!0):!1))continue;if(o=this.tokenizer.space(t)){t=t.substring(o.raw.length);let d=n.at(-1);o.raw.length===1&&d!==void 0?d.raw+=`
52
+ `:n.push(o);continue}if(o=this.tokenizer.code(t)){t=t.substring(o.raw.length);let d=n.at(-1);d?.type==="paragraph"||d?.type==="text"?(d.raw+=(d.raw.endsWith(`
53
53
  `)?"":`
54
54
  `)+o.raw,d.text+=`
55
- `+o.text,this.inlineQueue.at(-1).src=d.text):n.push(o);continue}if(o=this.tokenizer.fences(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.heading(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.hr(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.blockquote(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.list(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.html(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.def(e)){e=e.substring(o.raw.length);let d=n.at(-1);d?.type==="paragraph"||d?.type==="text"?(d.raw+=(d.raw.endsWith(`
55
+ `+o.text,this.inlineQueue.at(-1).src=d.text):n.push(o);continue}if(o=this.tokenizer.fences(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.heading(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.hr(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.blockquote(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.list(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.html(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.def(t)){t=t.substring(o.raw.length);let d=n.at(-1);d?.type==="paragraph"||d?.type==="text"?(d.raw+=(d.raw.endsWith(`
56
56
  `)?"":`
57
57
  `)+o.raw,d.text+=`
58
- `+o.raw,this.inlineQueue.at(-1).src=d.text):(this.tokens.links[o.tag]||(this.tokens.links[o.tag]={href:o.href,title:o.title}),n.push(o));continue}if(o=this.tokenizer.table(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.lheading(e)){e=e.substring(o.raw.length),n.push(o);continue}let c=e;if(this.options.extensions?.startBlock){let d=1/0,m=e.slice(1),p;this.options.extensions.startBlock.forEach(h=>{p=h.call({lexer:this},m),typeof p=="number"&&p>=0&&(d=Math.min(d,p))}),d<1/0&&d>=0&&(c=e.substring(0,d+1))}if(this.state.top&&(o=this.tokenizer.paragraph(c))){let d=n.at(-1);(i||d===a&&r)&&d?.type==="paragraph"?(d.raw+=(d.raw.endsWith(`
58
+ `+o.raw,this.inlineQueue.at(-1).src=d.text):(this.tokens.links[o.tag]||(this.tokens.links[o.tag]={href:o.href,title:o.title}),n.push(o));continue}if(o=this.tokenizer.table(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.lheading(t)){t=t.substring(o.raw.length),n.push(o);continue}let c=t;if(this.options.extensions?.startBlock){let d=1/0,v=t.slice(1),h;this.options.extensions.startBlock.forEach(p=>{h=p.call({lexer:this},v),typeof h=="number"&&h>=0&&(d=Math.min(d,h))}),d<1/0&&d>=0&&(c=t.substring(0,d+1))}if(this.state.top&&(o=this.tokenizer.paragraph(c))){let d=n.at(-1);(i||d===l&&r)&&d?.type==="paragraph"?(d.raw+=(d.raw.endsWith(`
59
59
  `)?"":`
60
60
  `)+o.raw,d.text+=`
61
- `+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text,a=d):(n.push(o),a=o),i=c.length!==e.length,e=e.substring(o.raw.length);continue}if(o=this.tokenizer.text(e)){e=e.substring(o.raw.length);let d=n.at(-1);d?.type==="text"?(d.raw+=(d.raw.endsWith(`
61
+ `+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text,l=d):(n.push(o),l=o),i=c.length!==t.length,t=t.substring(o.raw.length);continue}if(o=this.tokenizer.text(t)){t=t.substring(o.raw.length);let d=n.at(-1);d?.type==="text"?(d.raw+=(d.raw.endsWith(`
62
62
  `)?"":`
63
63
  `)+o.raw,d.text+=`
64
- `+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text):n.push(o);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,this.state.lastToken=s,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}linkInText(e){if(!e.includes("["))return!1;let n=this.tokenizer.rules.inline.link;for(let i of e.matchAll(this.tokenizer.rules.inline.blockSkip))if(n.test(i[0])&&e.charAt(i.index-1)!=="!")return!0;for(let i of e.matchAll(this.tokenizer.rules.inline.reflinkSearch)){let s=i[0],l=s.lastIndexOf("[");if(!(s.charAt(0)==="!"||!Object.hasOwn(this.tokens.links,Tt(s.slice(l+1,-1),this.options.pedantic)))&&!(l>1&&this.linkInText(s.slice(1,l-1))))return!0}return!1}inlineTokens(e,n=[]){this.tokenizer.lexer=this;let i=this.state.linkParenPossible;this.state.linkParenPossible=e.includes(")");try{return this.#t(e,n)}finally{this.state.linkParenPossible=i}}#t(e,n){let i=e.includes("*")||e.includes("_")||e.includes("~"),s=i||this.options.hooks?.emStrongMask||this.tokenizer.emStrong!==Be.prototype.emStrong||this.tokenizer.del!==Be.prototype.del?this.#i(e):e;if(!i)return this.#e(e,s,n);Oa(this.tokenizer,s);try{return this.#e(e,s,n)}finally{qa(this.tokenizer)}}#e(e,n,i){let s=!1,l="",a=1/0;for(;e;){if(e.length<a)a=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}s||(l=""),s=!1;let r;if(this.options.extensions?.inline?.some(d=>(r=d.call({lexer:this},e,i))?(e=e.substring(r.raw.length),i.push(r),!0):!1))continue;if(r=this.tokenizer.escape(e)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.tag(e)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.link(e)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);let d=i.at(-1);r.type==="text"&&d?.type==="text"?(d.raw+=r.raw,d.text+=r.text):i.push(r);continue}let o=e[0];if(o==="*"||o==="_"){let d=n.length-e.length;if(gi(this.tokenizer,n,o)<=d){let m=1;for(;m<e.length&&e.charCodeAt(m)===o.charCodeAt(0);)m++;let p=e.substring(0,m),h=i.at(-1);h?.type==="text"&&!h.escaped?(h.raw+=p,h.text+=p):i.push({type:"text",raw:p,text:p,escaped:!1}),e=e.substring(m),l=o,s=!0;continue}}else if(o==="~"){let d=n.length-e.length;if(vi(this.tokenizer,n)<=d){let m=1;for(;m<e.length&&e.charCodeAt(m)===126;)m++;let p=e.substring(0,m),h=i.at(-1);h?.type==="text"&&!h.escaped?(h.raw+=p,h.text+=p):i.push({type:"text",raw:p,text:p,escaped:!1}),e=e.substring(m),l=o,s=!0;continue}}if(r=this.tokenizer.emStrong(e,n,l)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.codespan(e)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.br(e)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.del(e,n,l)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.autolink(e)){e=e.substring(r.raw.length),i.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),i.push(r);continue}let c=e;if(this.options.extensions?.startInline){let d=1/0,m=e.slice(1),p;this.options.extensions.startInline.forEach(h=>{p=h.call({lexer:this},m),typeof p=="number"&&p>=0&&(d=Math.min(d,p))}),d<1/0&&d>=0&&(c=e.substring(0,d+1))}if(r=this.tokenizer.inlineText(c)){e=e.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(l=r.raw.slice(-1)),s=!0;let d=i.at(-1);d?.type==="text"?(d.raw+=r.raw,d.text+=r.text):i.push(r);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return i}#n(e){let{blockSkip:n,tag:i,autolink:s}=this.tokenizer.rules.inline,l="",a=0,r;for(n.lastIndex=0;r=n.exec(e);){let o=r.index+(r[2]?r[2].length:0),c=r.index+r[0].length;if(e.charAt(o)==="<"){let d=e.slice(o),m=i.exec(d)||s.exec(d);if(!m){n.lastIndex=o+1;continue}c=o+m[0].length,n.lastIndex=c}l+=e.slice(a,o)+"["+"a".repeat(c-o-2)+"]",a=c}return l+e.slice(a)}#i(e){let n=e;if(this.tokens.links&&e.includes("[")){let i=this.tokenizer.rules.inline.reflinkSearch,s=l=>{let a=l.lastIndexOf("[");if(!Object.hasOwn(this.tokens.links,Tt(l.slice(a+1,-1),this.options.pedantic)))return l;if(a>1&&l.charAt(0)!=="!"){let r=l.slice(1,a-1);if(this.linkInText(r))return"["+r.replace(i,s)+"]["+"a".repeat(l.length-a-2)+"]"}return"["+"a".repeat(l.length-2)+"]"};n=n.replace(i,s)}return n=n.replace(this.tokenizer.rules.inline.anyPunctuationOutsideCode,(i,s,l)=>l?"+".repeat(i.length):s?s+i.slice(s.length,-s.length).replace(/`/g,"+")+s:i),n=this.#n(n),n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n,n}infiniteLoopError(e){let n="Infinite loop on byte: "+e;if(this.options.silent)console.error(n);else throw new Error(n)}};function hn(t,e=!1){let n;for(let i=0;i<t.length;i++){let s=t[i],l=s;if(s.type==="codespan"||s.type==="escape"||e&&s.type==="text"){let a=G(s.text,!0);a!==s.text&&(l={...s,text:a})}else if(s.type==="link"&&s.autolink){let a=G(s.text,!0),r=s.tokens,o=r&&(r.length===1&&r[0].type==="text"&&r[0].text===s.text?a!==s.text?[{...r[0],text:a}]:r:hn(r,!0));(a!==s.text||o!==r)&&(l=o!==r?{...s,text:a,tokens:o}:{...s,text:a})}else if("tokens"in s&&s.tokens){let a=hn(s.tokens,e);a!==s.tokens&&(l={...s,tokens:a})}l!==s?(n||(n=t.slice(0,i)),n.push(l)):n&&n.push(s)}return n||t}var $t=class{options;parser;constructor(t){this.options=t||Ae}space(t){return""}code({text:t,lang:e,escaped:n}){let i=(e||"").trim().match(_.notSpaceStart)?.[0],s=t?t.replace(_.endingNewline,"")+`
65
- `:"";return i?'<pre><code class="language-'+G(i)+'">'+(n?s:G(s,!0))+`</code></pre>
66
- `:"<pre><code>"+(n?s:G(s,!0))+`</code></pre>
67
- `}blockquote({tokens:t}){return`<blockquote>
68
- ${this.parser.parse(t)}</blockquote>
69
- `}html({text:t}){return t}def(t){return""}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
70
- `}hr(t){return`<hr>
71
- `}list(t){let e=t.ordered,n=t.start,i="";for(let a=0;a<t.items.length;a++){let r=t.items[a];i+=this.listitem(r)}let s=e?"ol":"ul",l=e&&n!==1?' start="'+n+'"':"";return"<"+s+l+`>
64
+ `+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text):n.push(o);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return this.state.top=!0,this.state.lastToken=s,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}linkInText(t){if(!t.includes("["))return!1;let n=this.tokenizer.rules.inline.link;for(let i of t.matchAll(this.tokenizer.rules.inline.blockSkip))if(n.test(i[0])&&t.charAt(i.index-1)!=="!")return!0;for(let i of t.matchAll(this.tokenizer.rules.inline.reflinkSearch)){let s=i[0],a=s.lastIndexOf("[");if(!(s.charAt(0)==="!"||!Object.hasOwn(this.tokens.links,Bt(s.slice(a+1,-1),this.options.pedantic)))&&!(a>1&&this.linkInText(s.slice(1,a-1))))return!0}return!1}inlineTokens(t,n=[]){this.tokenizer.lexer=this;let i=this.state.linkParenPossible;this.state.linkParenPossible=t.includes(")");try{return this.#t(t,n)}finally{this.state.linkParenPossible=i}}#t(t,n){let i=t.includes("*")||t.includes("_")||t.includes("~"),s=i||this.options.hooks?.emStrongMask||this.tokenizer.emStrong!==je.prototype.emStrong||this.tokenizer.del!==je.prototype.del?this.#i(t):t;if(!i)return this.#e(t,s,n);rl(this.tokenizer,s);try{return this.#e(t,s,n)}finally{ol(this.tokenizer)}}#e(t,n,i){let s=!1,a="",l=1/0;for(;t;){if(t.length<l)l=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}s||(a=""),s=!1;let r;if(this.options.extensions?.inline?.some(d=>(r=d.call({lexer:this},t,i))?(t=t.substring(r.raw.length),i.push(r),!0):!1))continue;if(r=this.tokenizer.escape(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.tag(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.link(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(r.raw.length);let d=i.at(-1);r.type==="text"&&d?.type==="text"?(d.raw+=r.raw,d.text+=r.text):i.push(r);continue}let o=t[0];if(o==="*"||o==="_"){let d=n.length-t.length;if(Ti(this.tokenizer,n,o)<=d){let v=1;for(;v<t.length&&t.charCodeAt(v)===o.charCodeAt(0);)v++;let h=t.substring(0,v),p=i.at(-1);p?.type==="text"&&!p.escaped?(p.raw+=h,p.text+=h):i.push({type:"text",raw:h,text:h,escaped:!1}),t=t.substring(v),a=o,s=!0;continue}}else if(o==="~"){let d=n.length-t.length;if(Ai(this.tokenizer,n)<=d){let v=1;for(;v<t.length&&t.charCodeAt(v)===126;)v++;let h=t.substring(0,v),p=i.at(-1);p?.type==="text"&&!p.escaped?(p.raw+=h,p.text+=h):i.push({type:"text",raw:h,text:h,escaped:!1}),t=t.substring(v),a=o,s=!0;continue}}if(r=this.tokenizer.emStrong(t,n,a)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.codespan(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.br(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.del(t,n,a)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.autolink(t)){t=t.substring(r.raw.length),i.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t))){t=t.substring(r.raw.length),i.push(r);continue}let c=t;if(this.options.extensions?.startInline){let d=1/0,v=t.slice(1),h;this.options.extensions.startInline.forEach(p=>{h=p.call({lexer:this},v),typeof h=="number"&&h>=0&&(d=Math.min(d,h))}),d<1/0&&d>=0&&(c=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(c)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(a=r.raw.slice(-1)),s=!0;let d=i.at(-1);d?.type==="text"?(d.raw+=r.raw,d.text+=r.text):i.push(r);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return i}#n(t){let{blockSkip:n,tag:i,autolink:s}=this.tokenizer.rules.inline,a="",l=0,r;for(n.lastIndex=0;r=n.exec(t);){let o=r.index+(r[2]?r[2].length:0),c=r.index+r[0].length;if(t.charAt(o)==="<"){let d=t.slice(o),v=i.exec(d)||s.exec(d);if(!v){n.lastIndex=o+1;continue}c=o+v[0].length,n.lastIndex=c}a+=t.slice(l,o)+"["+"a".repeat(c-o-2)+"]",l=c}return a+t.slice(l)}#i(t){let n=t;if(this.tokens.links&&t.includes("[")){let i=this.tokenizer.rules.inline.reflinkSearch,s=a=>{let l=a.lastIndexOf("[");if(!Object.hasOwn(this.tokens.links,Bt(a.slice(l+1,-1),this.options.pedantic)))return a;if(l>1&&a.charAt(0)!=="!"){let r=a.slice(1,l-1);if(this.linkInText(r))return"["+r.replace(i,s)+"]["+"a".repeat(a.length-l-2)+"]"}return"["+"a".repeat(a.length-2)+"]"};n=n.replace(i,s)}return n=n.replace(this.tokenizer.rules.inline.anyPunctuationOutsideCode,(i,s,a)=>a?"+".repeat(i.length):s?s+i.slice(s.length,-s.length).replace(/`/g,"+")+s:i),n=this.#n(n),n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n,n}infiniteLoopError(t){let n="Infinite loop on byte: "+t;if(this.options.silent)console.error(n);else throw new Error(n)}};function Ln(e,t=!1){let n;for(let i=0;i<e.length;i++){let s=e[i],a=s;if(s.type==="codespan"||s.type==="escape"||t&&s.type==="text"){let l=te(s.text,!0);l!==s.text&&(a={...s,text:l})}else if(s.type==="link"&&s.autolink){let l=te(s.text,!0),r=s.tokens,o=r&&(r.length===1&&r[0].type==="text"&&r[0].text===s.text?l!==s.text?[{...r[0],text:l}]:r:Ln(r,!0));(l!==s.text||o!==r)&&(a=o!==r?{...s,text:l,tokens:o}:{...s,text:l})}else if("tokens"in s&&s.tokens){let l=Ln(s.tokens,t);l!==s.tokens&&(a={...s,tokens:l})}a!==s?(n||(n=e.slice(0,i)),n.push(a)):n&&n.push(s)}return n||e}var Rt=class{options;parser;constructor(e){this.options=e||_e}space(e){return""}code({text:e,lang:t,escaped:n}){let i=(t||"").trim().match(N.notSpaceStart)?.[0],s=e?e.replace(N.endingNewline,"")+`
65
+ `:"";return i?'<pre><code class="language-'+te(i)+'">'+(n?s:te(s,!0))+`</code></pre>
66
+ `:"<pre><code>"+(n?s:te(s,!0))+`</code></pre>
67
+ `}blockquote({tokens:e}){return`<blockquote>
68
+ ${this.parser.parse(e)}</blockquote>
69
+ `}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
70
+ `}hr(e){return`<hr>
71
+ `}list(e){let t=e.ordered,n=e.start,i="";for(let l=0;l<e.items.length;l++){let r=e.items[l];i+=this.listitem(r)}let s=t?"ol":"ul",a=t&&n!==1?' start="'+n+'"':"";return"<"+s+a+`>
72
72
  `+i+"</"+s+`>
73
- `}listitem(t){return`<li>${this.parser.parse(t.tokens)}</li>
74
- `}checkbox({checked:t}){return"<input "+(t?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:t}){return`<p>${this.parser.parseInline(t)}</p>
75
- `}table(t){let e="",n="";for(let s=0;s<t.header.length;s++)n+=this.tablecell(t.header[s]);e+=this.tablerow({text:n});let i="";for(let s=0;s<t.rows.length;s++){let l=t.rows[s];n="";for(let a=0;a<l.length;a++)n+=this.tablecell(l[a]);i+=this.tablerow({text:n})}return i&&(i=`<tbody>${i}</tbody>`),`<table>
73
+ `}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
74
+ `}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
75
+ `}table(e){let t="",n="";for(let s=0;s<e.header.length;s++)n+=this.tablecell(e.header[s]);t+=this.tablerow({text:n});let i="";for(let s=0;s<e.rows.length;s++){let a=e.rows[s];n="";for(let l=0;l<a.length;l++)n+=this.tablecell(a[l]);i+=this.tablerow({text:n})}return i&&(i=`<tbody>${i}</tbody>`),`<table>
76
76
  <thead>
77
- `+e+`</thead>
77
+ `+t+`</thead>
78
78
  `+i+`</table>
79
- `}tablerow({text:t}){return`<tr>
80
- ${t}</tr>
81
- `}tablecell(t){let e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
82
- `}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${G(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,text:n,tokens:i,autolink:s}){let l=s?G(n,!0):this.parser.parseInline(i),a=hi(t);if(a===null)return l;t=G(a,s);let r='<a href="'+t+'"';return e&&(r+=' title="'+G(e)+'"'),r+=">"+l+"</a>",r}image({href:t,title:e,text:n,tokens:i}){i&&(n=this.parser.parseInline(hn(i),this.parser.textRenderer));let s=hi(t);if(s===null)return G(n);t=s;let l=`<img src="${G(t)}" alt="${G(n)}"`;return e&&(l+=` title="${G(e)}"`),l+=">",l}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:G(t.text)}},mn=class{parser;strong({text:t,tokens:e}){return e?this.parser.parseInline(e,this):t}em({text:t,tokens:e}){return e?this.parser.parseInline(e,this):t}codespan({text:t}){return t}del({text:t,tokens:e}){return e?this.parser.parseInline(e,this):t}html({text:t}){return t}text({text:t}){return t}link({text:t,tokens:e}){return e?this.parser.parseInline(e,this):t}image({text:t,tokens:e}){return e?this.parser.parseInline(e,this):t}br(){return`
83
- `}checkbox({raw:t}){return t}},re=class Fn{options;renderer;textRenderer;constructor(e){this.options=e||Ae,this.options.renderer=this.options.renderer||new $t,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new mn,this.textRenderer.parser=this}static parse(e,n){return new Fn(n).parse(e)}static parseInline(e,n){return new Fn(n).parseInline(e)}parse(e){this.renderer.parser=this;let n="";for(let i=0;i<e.length;i++){let s=e[i],l=this.options.extensions?.renderers;if(l&&Object.hasOwn(l,s.type)&&l[s.type]){let r=s,o=l[r.type].call({parser:this},r);if(o!==!1||!["space","hr","heading","code","table","blockquote","list","checkbox","html","def","paragraph","text"].includes(r.type)){n+=o===!1?"":o??"";continue}}let a=s;switch(a.type){case"space":{n+=this.renderer.space(a);break}case"hr":{n+=this.renderer.hr(a);break}case"heading":{n+=this.renderer.heading(a);break}case"code":{n+=this.renderer.code(a);break}case"table":{n+=this.renderer.table(a);break}case"blockquote":{n+=this.renderer.blockquote(a);break}case"list":{n+=this.renderer.list(a);break}case"checkbox":{n+=this.renderer.checkbox(a);break}case"html":{n+=this.renderer.html(a);break}case"def":{n+=this.renderer.def(a);break}case"paragraph":{n+=this.renderer.paragraph(a);break}case"text":{n+=this.renderer.text(a);break}default:{let r='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(r),"";throw new Error(r)}}}return n}parseInline(e,n=this.renderer){this.renderer.parser=this;let i="";for(let s=0;s<e.length;s++){let l=e[s],a=this.options.extensions?.renderers;if(a&&Object.hasOwn(a,l.type)&&a[l.type]){let o=a[l.type].call({parser:this},l);if(o!==!1||!["escape","html","link","image","checkbox","strong","em","codespan","br","del","text"].includes(l.type)){i+=o===!1?"":o??"";continue}}let r=l;switch(r.type){case"escape":{i+=n.text(r);break}case"html":{i+=n.html(r);break}case"link":{i+=n.link(r);break}case"image":{i+=n.image(r);break}case"checkbox":{i+=n.checkbox(r);break}case"strong":{i+=n.strong(r);break}case"em":{i+=n.em(r);break}case"codespan":{i+=n.codespan(r);break}case"br":{i+=n.br(r);break}case"del":{i+=n.del(r);break}case"text":{i+=n.text(r);break}default:{let o='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return i}},at=class{options;block;constructor(t){this.options=t||Ae}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(t=this.block){return t?le.lex:le.lexInline}provideParser(t=this.block){return t?re.parse:re.parseInline}};function Ce(t,e){if(Array.isArray(e))for(let n=0;n<e.length;n++)t.push(e[n]);else t.push(e)}var Ja=class{defaults=tn();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=re;Renderer=$t;TextRenderer=mn;Lexer=le;Tokenizer=Be;Hooks=at;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let i of t)switch(Ce(n,e.call(this,i)),i.type){case"table":{let s=i;for(let l of s.header)Ce(n,this.walkTokens(l.tokens,e));for(let l of s.rows)for(let a of l)Ce(n,this.walkTokens(a.tokens,e));break}case"list":{let s=i;Ce(n,this.walkTokens(s.items,e));break}default:{let s=i;this.defaults.extensions?.childTokens?.[s.type]?this.defaults.extensions.childTokens[s.type].forEach(l=>{if(s[l]){let a=s[l].flat(1/0);Ce(n,this.walkTokens(a,e))}}):s.tokens&&Ce(n,this.walkTokens(s.tokens,e))}}return n}use(...t){let e=this.defaults.extensions||{renderers:Object.create(null),childTokens:Object.create(null)};return t.forEach(n=>{let i={...n};if(i.async=this.defaults.async||i.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s&&s.renderer){let l=s.renderer,a=e.renderers[s.name];a?e.renderers[s.name]=function(...r){let o=l.apply(this,r);return o===!1&&(o=a.apply(this,r)),o}:e.renderers[s.name]=l}if("tokenizer"in s&&s.tokenizer){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let l=e[s.level];l?l.unshift(s.tokenizer):e[s.level]=[s.tokenizer],s.start&&(s.level==="block"?e.startBlock?e.startBlock.push(s.start):e.startBlock=[s.start]:s.level==="inline"&&(e.startInline?e.startInline.push(s.start):e.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(e.childTokens[s.name]=s.childTokens)}),i.extensions=e),n.renderer){let s=this.defaults.renderer||new $t(this.defaults);for(let l in n.renderer){if(!(l in s))throw new Error(`renderer '${l}' does not exist`);if(["options","parser"].includes(l))continue;let a=l,r=n.renderer[a];if(r===void 0)continue;let o=s[a];s[a]=(...c)=>{let d=r.apply(s,c);return d===!1&&(d=o.apply(s,c)),d===!1?"":d??""}}i.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new Be(this.defaults);for(let l in n.tokenizer){if(!(l in s))throw new Error(`tokenizer '${l}' does not exist`);if(["options","rules","lexer"].includes(l))continue;let a=l,r=n.tokenizer[a];if(r===void 0)continue;let o=s[a];s[a]=(...c)=>{let d=r.apply(s,c);return d===!1&&(d=o.apply(s,c)),d}}i.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new at;for(let l in n.hooks){if(!(l in s))throw new Error(`hook '${l}' does not exist`);if(["options","block"].includes(l))continue;let a=l,r=n.hooks[a];if(r===void 0)continue;let o=s[a];at.passThroughHooks.has(l)?s[a]=c=>{if(s.options.async&&at.passThroughHooksRespectAsync.has(l))return(async()=>{let m=await r.call(s,c);return o.call(s,m)})();let d=r.call(s,c);return o.call(s,d)}:s[a]=(...c)=>{if(s.options.async)return(async()=>{let m=await r.apply(s,c);return m===!1&&(m=await o.apply(s,c)),m})();let d=r.apply(s,c);return d===!1&&(d=o.apply(s,c)),d}}i.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,l=n.walkTokens;i.walkTokens=function(a){let r=[];return Ce(r,l.call(this,a)),s&&Ce(r,s.call(this,a)),r}}this.defaults={...this.defaults,...i}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return le.lex(t,e??this.defaults)}parser(t,e){return re.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let i={...n},s={...this.defaults,...i},l=this.onError(!!s.silent,!!s.async);if(this.defaults.async===!0&&i.async===!1)return l(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return l(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=t),s.async)return(async()=>{let a=s.hooks?await s.hooks.preprocess(e):e,r=await(s.hooks?await s.hooks.provideLexer(t):t?le.lex:le.lexInline)(a,s),o=s.hooks?await s.hooks.processAllTokens(r):r;s.walkTokens&&await Promise.all(this.walkTokens(o,s.walkTokens));let c=await(s.hooks?await s.hooks.provideParser(t):t?re.parse:re.parseInline)(o,s);return s.hooks?await s.hooks.postprocess(c):c})().catch(l);try{s.hooks&&(e=s.hooks.preprocess(e));let a=(s.hooks?s.hooks.provideLexer(t):t?le.lex:le.lexInline)(e,s);s.hooks&&(a=s.hooks.processAllTokens(a)),s.walkTokens&&this.walkTokens(a,s.walkTokens);let r=(s.hooks?s.hooks.provideParser(t):t?re.parse:re.parseInline)(a,s);return s.hooks&&(r=s.hooks.postprocess(r)),r}catch(a){return l(a)}}}onError(t,e){return n=>{let i=n instanceof Error?n:new Error(String(n));if(i.message+=`
84
- Please report this to https://github.com/markedjs/marked.`,t){let s="<p>An error occurred:</p><pre>"+G(i.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(i);throw i}}},Re=new Ja;function P(t,e){return Re.parse(t,e)}function Za(t,e){return Re.parseInline(t,e)}P.options=P.setOptions=function(t){return Re.setOptions(t),P.defaults=Re.defaults,Qn(P.defaults),P},P.getDefaults=tn,P.defaults=Ae;function Ya(...t){return Re.use(...t),P.defaults=Re.defaults,Qn(P.defaults),P}P.use=Ya,P.walkTokens=function(t,e){return Re.walkTokens(t,e)},P.parseInline=Za,P.Parser=re,P.parser=re.parse,P.Renderer=$t,P.TextRenderer=mn,P.Lexer=le,P.lexer=le.lex,P.Tokenizer=Be,P.Hooks=at,P.parse=P;var Ql=P.options,Gl=P.setOptions,er=P.walkTokens,tr=P.parseInline,nr=re.parse,ir=le.lex,Xa=new Set(["http:","https:","mailto:"]);function yi(t){let e=(t??"").trim();if(!e||e.startsWith("//"))return null;if(!/^[a-z][a-z0-9+.-]*:/i.test(e))return e;try{return Xa.has(new URL(e).protocol)?e:null}catch{return null}}var xi=t=>/^[a-z][a-z0-9+.-]*:/i.test(t)&&!t.startsWith("mailto:"),Si=4e5,Ka=200;function Qa(t){let e=new Map,n=0;function i(m,p){let h=m.length+Ka;if(!(h>Si/4)){e.set(m,{fragment:p,chars:h}),n+=h;for(let f of e.keys()){if(n<=Si)break;let b=e.get(f);b&&(e.delete(f),n-=b.chars)}}}function s(m,p){p.split(`
85
- `).forEach((h,f)=>{f>0&&m.appendChild(t.createElement("br")),h&&m.appendChild(t.createTextNode(h))})}function l(m,p){switch(p.type){case"text":{if(p.tokens?.length){for(let h of p.tokens)l(m,h);return}s(m,p.text??p.raw??"");return}case"escape":m.appendChild(t.createTextNode(p.text??""));return;case"strong":case"em":case"del":{let h=t.createElement(p.type==="strong"?"strong":p.type==="em"?"em":"del");for(let f of p.tokens??[])l(h,f);m.appendChild(h);return}case"codespan":{let h=t.createElement("code");h.textContent=p.text??"",m.appendChild(h);return}case"br":m.appendChild(t.createElement("br"));return;case"link":{let h=p.tokens??[],f=yi(p.href);if(!f){for(let w of h)l(m,w);return}let b=t.createElement("a");b.href=f,b.rel="noreferrer noopener",p.title&&(b.title=p.title),xi(f)&&(b.target="_blank");for(let w of h)l(b,w);m.appendChild(b);return}case"image":{let h=yi(p.href),f=p.text?.trim()||p.href||"image";if(!h){m.appendChild(t.createTextNode(f));return}let b=t.createElement("a");b.href=h,b.textContent=f,b.rel="noreferrer noopener",xi(h)&&(b.target="_blank"),m.appendChild(b);return}case"html":m.appendChild(t.createTextNode(p.raw??p.text??""));return;default:if(p.tokens?.length){for(let h of p.tokens)l(m,h);return}s(m,p.text??p.raw??"")}}function a(m){let p=t.createElement("div");p.className="bv-code";let h=t.createElement("div");h.className="bv-code-head";let f=(m.lang??"").trim().split(/\s+/)[0]??"",b=t.createElement("span");b.className="bv-code-lang",b.textContent=f||"text";let w=t.createElement("button");w.type="button",w.className="bv-code-copy",w.textContent="Copy";let y=m.text??"";w.addEventListener("click",()=>{let T=navigator.clipboard?.writeText(y);T&&T.then(()=>{w.textContent="Copied",window.setTimeout(()=>{w.textContent="Copy"},1200)},()=>{})}),h.append(b,w);let C=t.createElement("pre"),M=t.createElement("code");return f&&(M.className=`language-${f}`),M.textContent=y,C.appendChild(M),p.append(h,C),p}function r(m,p){let h=t.createElement("div");h.className="bv-table";let f=t.createElement("table"),b=t.createElement("thead"),w=t.createElement("tr"),y=p.align??[],C=(T,I,$)=>{let z=t.createElement(T);y[$]&&(z.style.textAlign=y[$]);for(let x of I.tokens??[])l(z,x);return z};(p.header??[]).forEach((T,I)=>w.appendChild(C("th",T,I))),b.appendChild(w);let M=t.createElement("tbody");for(let T of p.rows??[]){let I=t.createElement("tr");T.forEach(($,z)=>I.appendChild(C("td",$,z))),M.appendChild(I)}f.append(b,M),h.appendChild(f),m.appendChild(h)}function o(m,p){let h=t.createElement("li");if(p.task){let f=t.createElement("input");f.type="checkbox",f.disabled=!0,f.checked=p.checked===!0,h.appendChild(f)}for(let f of p.tokens??[])if(f.type==="text")l(h,f);else if(f.type==="paragraph")for(let b of f.tokens??[])l(h,b);else c(h,f);m.appendChild(h)}function c(m,p){switch(p.type){case"space":return;case"heading":{let h=Math.min(Math.max(p.depth??1,1),6),f=t.createElement(`h${h}`);for(let b of p.tokens??[])l(f,b);m.appendChild(f);return}case"paragraph":{let h=t.createElement("p");for(let f of p.tokens??[])l(h,f);m.appendChild(h);return}case"text":l(m,p);return;case"code":m.appendChild(a(p));return;case"blockquote":{let h=t.createElement("blockquote");for(let f of p.tokens??[])c(h,f);m.appendChild(h);return}case"list":{let h=p.items??p.tokens??[];if(p.ordered){let f=t.createElement("ol");typeof p.start=="number"&&p.start!==1&&(f.start=p.start);for(let b of h)o(f,b);m.appendChild(f)}else{let f=t.createElement("ul");for(let b of h)o(f,b);m.appendChild(f)}return}case"table":r(m,p);return;case"hr":m.appendChild(t.createElement("hr"));return;case"html":case"escape":m.appendChild(t.createTextNode(p.raw??p.text??""));return;default:if(p.tokens?.length){for(let h of p.tokens)c(m,h);return}p.text&&m.appendChild(t.createTextNode(p.text))}}function d(m){let p=t.createDocumentFragment();try{let h=P.lexer(m);for(let f of h)c(p,f)}catch{p.replaceChildren(t.createTextNode(m))}return p}return m=>{let p=e.get(m);if(p)return e.delete(m),e.set(m,p),p.fragment.cloneNode(!0);let h=d(m);return i(m,h),h.cloneNode(!0)}}var fn=Qa(document),k={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1},Le=[],fe=!0,Ga=!1,Ei=0;function gn(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function j(t,e){let n=await fetch(t,{...e,headers:{"content-type":"application/json",Authorization:`Bearer ${gn()}`,...e?.headers||{}}}),i=await n.text(),s=i?JSON.parse(i):null;if(!n.ok)throw new Error(s&&s.error||`HTTP ${n.status}`);return s}function g(t,e,n){let i=document.createElement(t);return e&&(i.className=e),n!==void 0&&(i.textContent=n),i}function Ci(t){return t==="running"?"var(--panel-success)":t==="waiting_approval"||t==="waiting_input"?"#e0a23c":t==="failed"?"var(--panel-danger, #e5534b)":t==="completed"?"var(--panel-accent)":"var(--panel-muted)"}function Te(){vn||(vn=requestAnimationFrame(()=>{vn=0,el()}))}var vn=0,It="";function el(){let t=document.getElementById("bots-view");if(!t)return;let e=window.visualViewport,n=window.matchMedia("(max-width: 640px)").matches,i=!document.querySelector(".sidebar")?.classList.contains("collapsed");if(k.activeId&&e&&n&&!i){let s=document.querySelector(".fixed-header"),l=s?Math.round(s.getBoundingClientRect().height):0,a=Math.round(e.offsetTop)+l,r=Math.round(e.offsetLeft),o=Math.round(e.width),c=Math.max(120,Math.round(e.height)-l),d=`fixed|${a}|${r}|${o}|${c}`;if(d===It)return;It=d,t.style.position="fixed",t.style.top=`${a}px`,t.style.left=`${r}px`,t.style.width=`${o}px`,t.style.height=`${c}px`,t.style.right="auto",t.style.bottom="auto"}else{if(It==="")return;It="",t.style.position="",t.style.top="",t.style.left="",t.style.width="",t.style.height="",t.style.right="",t.style.bottom=""}}window.visualViewport?.addEventListener("resize",Te),window.visualViewport?.addEventListener("scroll",Te),window.addEventListener("resize",Te),document.addEventListener("click",Te);var Li=document.querySelector(".sidebar");Li&&new MutationObserver(Te).observe(Li,{attributes:!0,attributeFilter:["class"]}),window.__syncBotsViewport=Te;function At(){let t=k.approvals.length,e=document.getElementById("bots-inbox-badge");e&&(e.style.display=t?"inline-block":"none",e.textContent=String(t));let n=document.getElementById("bv-inbox-count");n&&(n.textContent=t?`(${t})`:""),window.__botsSnapshot=k.bots,window.__refreshSidebar?.()}function tl(){let t=document.getElementById("set-bot-templates"),e=document.getElementById("set-bot-new"),n=document.getElementById("set-bot-inbox"),i=()=>{document.getElementById("settings-popover")?.classList.remove("open"),document.getElementById("settings-backdrop")?.classList.remove("open")};t?.addEventListener("click",()=>{i(),lt()}),e?.addEventListener("click",()=>{i(),fl()}),n?.addEventListener("click",()=>{i(),Tn()})}function nl(){let t=g("div","bots-view");t.id="bots-view",t.hidden=!0;let e=g("div","bots-view-head"),n=g("div","bv-title"),i=g("span","bots-dot");i.id="bv-dot";let s=g("span","bv-title-text");s.id="bv-title";let l=g("span","bv-status");l.id="bv-status",n.append(i,s,l);let a=g("div","bv-actions"),r=g("div","bv-mode"),o=g("button","bv-mode-btn");o.id="bv-mode-btn",o.type="button",o.setAttribute("aria-haspopup","menu"),o.setAttribute("aria-expanded","false"),Bi(o,"supervised");let c=g("div","bv-menu bv-mode-menu");c.id="bv-mode-menu",c.setAttribute("role","menu"),c.hidden=!0;for(let[L,U,ve]of[["supervised","\u9ED8\u8BA4","\u53EA\u8BFB\u5DE5\u5177\uFF08read/grep/find/ls\uFF09\u76F4\u63A5\u653E\u884C\uFF1Bbash\u3001edit\u3001write\u3001\u6269\u5C55/MCP \u5DE5\u5177\u4F1A\u95EE\u4F60"],["parent-supervised","\u76D1\u7BA1","\u5176\u4F59\u5DE5\u5177\u4EA4\u7ED9\u4E0A\u7EA7 bot \u51B3\u5B9A\uFF08\u5E26\u7406\u7531\uFF09\uFF1B\u4F60\u4ECD\u7136\u80FD\u770B\u5230\u5E76\u56DE\u7B54\uFF0C\u5148\u7B54\u5148\u5F97\uFF1B\u6CA1\u6709\u4E0A\u7EA7\u65F6\u56DE\u843D\u5230\u9ED8\u8BA4"],["full-access","\u5168\u653E\u884C","\u6240\u6709\u5DE5\u5177\u76F4\u63A5\u6267\u884C\uFF0C\u4E0D\u518D\u8BE2\u95EE\u3002\u6CE8\u610F\u8FD9\u4E0D\u662F\u6C99\u7BB1"]]){let q=g("button","bv-menu-item");q.dataset.mode=L,q.setAttribute("role","menuitemradio"),q.innerHTML=`<span class="bv-menu-icon">${ae(Mi[L],'width="15" height="15"')}</span><span class="bv-menu-text"><b>${U}</b><span>${ve}</span></span><span class="bv-menu-check">${ae("check",'width="13" height="13"')}</span>`,q.onclick=()=>{d(!1),sl(L)},c.appendChild(q)}let d=L=>{L&&I(!1),c.hidden=!L,o.setAttribute("aria-expanded",L?"true":"false")};o.onclick=L=>{L.stopPropagation(),d(c.hidden)},r.append(o);let m=g("button","btn bv-inbox");m.id="bv-inbox",m.title="Requests waiting for you";let p=g("span",void 0,"Needs you"),h=g("span","bv-inbox-count");h.id="bv-inbox-count",m.append(p,h),m.onclick=()=>void Tn();let f=g("button","bv-icon-btn");f.id="bv-more-btn",f.type="button",f.title="More actions",f.setAttribute("aria-label","More actions"),f.setAttribute("aria-haspopup","menu"),f.setAttribute("aria-expanded","false"),f.innerHTML=ae("dots",'width="16" height="16"');let b=g("div","bv-menu");b.id="bv-more-menu",b.setAttribute("role","menu"),b.hidden=!0;let w=(L,U,ve,q)=>{let Y=g("button",`bv-menu-item${L?` ${L}`:""}`);return Y.type="button",Y.setAttribute("role","menuitem"),Y.innerHTML=`<span class="bv-menu-icon">${ae(U,'width="15" height="15"')}</span><span class="bv-menu-text"><b>${ve}</b></span>`,Y.onclick=()=>{I(!1),q()},Y},y=w("","check","Allow all",()=>{if(!k.activeId)return;let L=k.approvals.filter(U=>U.botId===k.activeId);Promise.all(L.map(U=>j(`/api/bots/${U.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:U.id,allow:!0})}))).finally(()=>void oe(!0))});y.id="bv-allow-all",y.title="Approve every pending request for this bot";let C=w("","refresh","Resume bot",()=>Ii(L=>j(`/api/bots/${L}/resume`,{method:"POST"}).then(()=>oe(!0)))),M=w("","stop","Stop run",()=>Ii(L=>j(`/api/bots/${L}/stop`,{method:"POST"}).then(()=>oe(!0)))),T=w("danger","delete","Delete bot",()=>{k.activeId&&confirm("Delete this bot and its session?")&&j(`/api/bots/${k.activeId}`,{method:"DELETE"}).then(()=>{kn(),oe(!0)})});b.append(y,C,M,g("div","bv-menu-sep"),T);let I=L=>{L&&d(!1),b.hidden=!L,f.setAttribute("aria-expanded",L?"true":"false")};f.onclick=L=>{L.stopPropagation(),I(b.hidden)},document.addEventListener("click",L=>{let U=L.target;U&&(!r.contains(U)&&!c.contains(U)&&d(!1),!f.contains(U)&&!b.contains(U)&&I(!1))}),a.append(r,m,f),e.append(n,a);let $=g("div","bots-messages");$.id="bots-messages";let z=g("button","bv-jump");z.type="button",z.id="bv-jump",z.innerHTML=`${ae("chevron-down",'width="14" height="14"')}<span>Latest</span>`,z.title="Jump to the latest message",z.hidden=!0,z.onclick=()=>{fe=!0,$.scrollTop=$.scrollHeight,z.hidden=!0};let x=()=>{fe=$.scrollHeight-$.scrollTop-$.clientHeight<48,z.hidden=fe};$.addEventListener("scroll",x,{passive:!0}),$.addEventListener("touchmove",()=>{fe=!1,z.hidden=$.scrollHeight-$.clientHeight<1},{passive:!0}),$.addEventListener("wheel",()=>{fe=!1},{passive:!0});let F=g("div","bots-composer-wrap"),B=g("div","bv-composer-error");B.id="bv-composer-error",B.hidden=!0;let Z=g("div","bots-composer"),A=g("textarea");A.id="bots-input",A.rows=1,A.placeholder="Message the bot\u2026",A.spellcheck=!1;let Se=window.matchMedia("(pointer: coarse)").matches;Se||(A.enterKeyHint="send"),A.onkeydown=L=>{L.key!=="Enter"||L.shiftKey||L.isComposing||Se||L.keyCode===229||(L.preventDefault(),$i())},A.oninput=()=>bn(null);let W=g("button","btn primary");W.id="bv-send",W.title="Send",W.setAttribute("aria-label","Send"),W.innerHTML='<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>',W.onclick=()=>void $i(),Z.append(A,W),Z.addEventListener("click",L=>{L.target?.closest("button")||document.activeElement!==A&&A.focus()}),F.append(B,Z),t.append(e,$,z,F,c,b),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||hl()}function bn(t){let e=document.getElementById("bv-composer-error");e&&(e.textContent=t??"",e.hidden=!t)}function Ti(t){let e=document.getElementById("bv-send");e&&(e.disabled=t,e.setAttribute("aria-busy",t?"true":"false"),e.title=t?"Sending\u2026":"Send")}async function $i(){let t=document.getElementById("bots-input");if(!t||!k.activeId||Ga||!t.value.trim())return;let e=k.activeId,n=t.value;bn(null),Ti(!0);try{await j(`/api/bots/${e}/input`,{method:"POST",body:JSON.stringify({text:n})}),t.value===n&&(t.value=""),fe=!0}catch(i){bn(i instanceof Error?i.message:String(i))}finally{Ti(!1)}}function Ii(t){k.activeId&&t(k.activeId).catch(e=>Pe({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)}))}function kn(){k.activeId=null,Le=[],fe=!0,Te();let t=document.getElementById("bots-view");t&&(t.hidden=!0);try{k.ws?.close()}catch{}k.ws=null,At();let e=document.getElementById("terminal-container"),n=document.getElementById("main-placeholder"),i=!!document.querySelector(".session-item.active:not(.bot-item)");e&&i?(e.style.display="",n&&(n.style.display="none")):n&&(n.style.display="")}async function Ai(t){k.activeId=t,Le=[],fe=!0;let e=document.getElementById("bv-jump");e&&(e.hidden=!0),window.__collapseSidebar?.(),Te(),k.items.set(t,[]);let n=document.getElementById("bots-view");n&&(n.hidden=!1);let i=document.getElementById("main-placeholder");i&&(i.style.display="none");let s=document.getElementById("terminal-container");s&&(s.style.display="none");let l=document.getElementById("file-editor");l&&(l.style.display="none"),At(),En();try{k.ws?.close()}catch{}let a=location.protocol==="https:"?"wss:":"ws:",r=new WebSocket(`${a}//${location.host}/ws/bots/${encodeURIComponent(t)}?token=${encodeURIComponent(gn())}`);k.ws=r,r.onmessage=o=>{try{Ri(JSON.parse(String(o.data)))}catch{}},r.onclose=()=>{k.activeId===t&&setTimeout(()=>{k.activeId===t&&oe(!0)},1500)},await oe(!0)}function wn(){return k.bots.find(t=>t.id===k.activeId)||null}function yn(){let t=wn();if(!t)return;let e=document.getElementById("bv-title"),n=document.getElementById("bv-status"),i=document.getElementById("bv-dot");e&&(e.textContent=t.title),n&&(n.textContent=il[t.status]??t.status.replace(/_/g," "),n.dataset.status=t.status,n.style.color=Ci(t.status),n.title=`${t.status.replace(/_/g," ")} \xB7 ${t.templateId} \xB7 ${t.projectPath}`);let s=document.getElementById("bv-mode-btn");s&&Bi(s,t.runtimeMode||"supervised");for(let r of document.querySelectorAll("#bv-mode-menu button")){let o=r.dataset.mode===t.runtimeMode;r.classList.toggle("active",o),r.setAttribute("aria-checked",o?"true":"false")}let l=document.getElementById("bv-allow-all"),a=k.approvals.filter(r=>r.botId===t.id).length;if(l){l.hidden=a===0;let r=l.querySelector(".bv-menu-text b");r&&(r.textContent=`Allow all (${a})`)}i&&(i.style.background=Ci(t.status))}var il={queued:"queued",starting:"starting",running:"running",waiting_input:"waiting",waiting_approval:"approval",completed:"done",failed:"failed",cancelled:"stopped",stale:"stale"},zi={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"},Mi={supervised:"shield","parent-supervised":"shield-up","full-access":"shield-alert"};function Bi(t,e){let n=Mi[e]??"shield";t.dataset.mode=e,t.innerHTML=ae(n,'width="15" height="15"');let i=`\u5BA1\u6279\u6A21\u5F0F\uFF1A${zi[e]??e}`;t.title=`${i}\uFF08\u70B9\u5F00\u53EF\u5207\u6362\uFF09`,t.setAttribute("aria-label",i)}async function sl(t){if(k.activeId)try{await j(`/api/bots/${k.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:t})});let e=wn();e&&(e.runtimeMode=t),yn(),Pe({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${zi[t]||t}`})}catch(e){Pe({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)})}}function Pe(t,e=k.activeId){if(!e)return;let n=k.items.get(e)||[];n.push(t),k.items.set(e,n),e===k.activeId&&De()}function De(){if(k.renderQueued)return;k.renderQueued=!0;let t=Math.max(0,60-(performance.now()-Ei));window.setTimeout(()=>{k.renderQueued=!1,Ei=performance.now(),En()},t)}function xn(t){switch(t.kind){case"assistant":return{text:t.text,thinking:t.thinking};case"tool":return{phase:t.phase,output:t.output,error:t.isError,durationMs:t.durationMs};case"approval":return{decided:t.decided,approvalState:t.approval.state};default:return{}}}function al(t,e){return t.text!==e.text||t.thinking!==e.thinking||t.phase!==e.phase||t.output!==e.output||t.error!==e.error||t.durationMs!==e.durationMs||t.decided!==e.decided||t.approvalState!==e.approvalState}function Sn(t){if(t.kind==="user"){let e=g("div","bv-msg bv-user");return e.appendChild(fn(t.text)),e}if(t.kind==="assistant"){let e=g("div","bv-msg bv-assistant");if(t.thinking){let i=g("details","bv-thinking");i.appendChild(g("summary",void 0,"thinking")),i.appendChild(g("div",void 0,t.thinking)),e.appendChild(i)}let n=g("div","bv-text");return n.appendChild(fn(t.text)),e.appendChild(n),e}return t.kind==="tool"?rl(t):t.kind==="approval"?ol(t):g("div",`bv-notice bv-notice-${t.level}`,t.text)}function ll(t,e){let n=t.querySelector("details.bv-thinking");if(e.thinking)if(n){let s=n.querySelector("div");s&&s.textContent!==e.thinking&&(s.textContent=e.thinking)}else{let s=g("details","bv-thinking");s.appendChild(g("summary",void 0,"thinking")),s.appendChild(g("div",void 0,e.thinking)),t.prepend(s)}else n&&n.remove();let i=t.querySelector(".bv-text");i&&i.replaceChildren(fn(e.text))}function En(){let t=document.getElementById("bots-messages");if(!t||!k.activeId||document.getElementById("bots-view")?.hidden)return;let e=k.items.get(k.activeId)||[],n=fe;if(e.length<Le.length||e.some((i,s)=>Le[s]?.item!==i))t.textContent="",Le=e.map(i=>{let s=Sn(i);return t.appendChild(s),{item:i,snapshot:xn(i),node:s}});else{for(let i=Le.length;i<e.length;i++){let s=e[i],l=Sn(s);t.appendChild(l),Le.push({item:s,snapshot:xn(s),node:l})}for(let i=0;i<e.length;i++){let s=e[i],l=Le[i],a=xn(s);if(al(l.snapshot,a)){if(s.kind==="assistant")ll(l.node,s);else{let r=Sn(s);l.node.replaceWith(r),l.node=r}l.snapshot=a}}}n&&(t.scrollTop=t.scrollHeight)}function rl(t){let e=g("details","bv-tool");e.open=t.phase!=="end"||!!t.isError;let n=g("summary"),i=g("span","bv-tool-name",t.name);if(n.appendChild(i),t.phase!=="end"&&n.appendChild(g("span","bv-tool-phase",t.phase)),t.isError&&n.appendChild(g("span","bv-tool-error","error")),typeof t.durationMs=="number"&&n.appendChild(g("span","bv-tool-meta",`${Math.round(t.durationMs)}ms`)),e.appendChild(n),t.args!==void 0){let s=g("pre","bv-pre");s.textContent=typeof t.args=="string"?t.args:JSON.stringify(t.args,null,2),e.appendChild(s)}if(t.output){let s=g("pre","bv-pre bv-output");s.textContent=t.output,e.appendChild(s)}return e}function ol(t){let e=g("div","bv-approval"),n=t.approval;if(e.appendChild(g("div","bv-approval-tag","Needs approval")),e.appendChild(g("div","bv-approval-title",n.title)),n.message){let p=g("pre","bv-pre bv-approval-detail");p.textContent=n.message,e.appendChild(p)}if(t.decided)return e.appendChild(g("div","bv-approval-decided",t.decided==="allowed"?"Allowed":"Denied")),e;let i=g("input","bv-reason");i.placeholder="reason (optional)",i.setAttribute("aria-label","Reason (optional)");let s=g("div","bv-approval-actions"),l=g("button","btn primary","Allow once"),a=/^Allow (.+?)\?$/.exec(n.title)?.[1],r=n.method==="confirm"?a&&a.length<=24?`Always allow ${a}`:"Always allow this tool":"Allow for this session",o=g("button","btn",r);o.hidden=n.method!=="confirm";let c=g("button","btn danger","Deny"),d=[l,o,c],m=async(p,h,f)=>{let b=f.textContent??"";for(let w of d)w.disabled=!0;f.textContent=p?"Allowing\u2026":"Denying\u2026";try{await j(`/api/bots/${n.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:n.id,allow:p,always:h,reason:i.value||void 0})}),t.decided=p?"allowed":"denied",De(),oe(!0)}catch(w){for(let y of d)y.disabled=!1;f.textContent=b,Pe({kind:"notice",level:"error",text:w instanceof Error?w.message:String(w)})}};return l.onclick=()=>void m(!0,!1,l),o.onclick=()=>void m(!0,!0,o),c.onclick=()=>void m(!1,!1,c),s.append(i,l,o,c),e.appendChild(s),e}function Ri(t){let e=String(t.type||""),n=k.activeId;if(!n)return;let i=k.items.get(n)||[];if(e==="snapshot")k.items.set(n,[]);else if(e==="user")fe=!0,Pe({kind:"user",text:String(t.text||"")});else if(e==="status"){let s=wn();s&&(s.status=String(t.status||s.status)),yn(),pl()}else if(e==="message"){let s=t.message;if(!s||String(s.role||"")!=="assistant")return;let l=cl(s),a=dl(s),r=i[i.length-1];r&&r.kind==="assistant"?(r.text=l||r.text,r.thinking=a||r.thinking):i.push({kind:"assistant",text:l,thinking:a}),k.items.set(n,i),De()}else if(e==="delta"){let s=String(t.kind||""),l=String(t.delta||""),a=i[i.length-1];(!a||a.kind!=="assistant")&&(i.push({kind:"assistant",text:"",thinking:""}),a=i[i.length-1]),a.kind==="assistant"&&(s==="text"?a.text+=l:s==="thinking"&&(a.thinking+=l)),k.items.set(n,i),De()}else if(e==="tool"){let s=String(t.callId||""),l=i.find(r=>r.kind==="tool"&&r.callId===s),a=String(t.phase||"start");l?(l.phase=a,a==="update"&&t.output&&(l.output=String(t.output)),a==="end"&&(t.output&&(l.output=String(t.output)),l.isError=t.isError===!0,typeof t.durationMs=="number"&&(l.durationMs=t.durationMs))):i.push({kind:"tool",callId:s,name:String(t.name||"tool"),args:t.args,output:t.output?String(t.output):void 0,isError:t.isError===!0,durationMs:typeof t.durationMs=="number"?t.durationMs:void 0,phase:a}),k.items.set(n,i),De()}else if(e==="approval"){let s=t.approval;if(!s)return;let l=i;for(let a=l.length-1;a>=0;a--){let r=l[a];if(r.kind==="approval"&&r.approval.id===s.id){r.approval=s,s.state!=="pending"&&(r.decided=s.state==="allowed"?"allowed":"denied"),k.items.set(n,l),De();return}}l.push({kind:"approval",approval:s}),k.items.set(n,l),De()}else e==="notice"&&Pe({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function cl(t){let e=t.content;return Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&n.type==="text"?String(n.text||""):"").join(""):String(t.text||"")}function dl(t){let e=t.content;return Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&n.type==="thinking"?String(n.thinking||""):"").join(""):""}async function oe(t=!1){try{let[e,n]=await Promise.all([j("/api/bots"),j("/api/bots/approvals")]);if(k.bots=e,k.approvals=n,At(),yn(),t&&k.activeId){let i=await j(`/api/bots/${k.activeId}/events?limit=300`);ul(i)}}catch{}}async function pl(){try{k.bots=await j("/api/bots"),At()}catch{}}function ul(t){if(k.activeId){k.items.set(k.activeId,[]);for(let e of t)Ri(e);En()}}function hl(){let t=g("div","bots-modal");t.id="bots-modal",t.hidden=!0;let e=g("div","bots-modal-card"),n=g("div","bots-modal-head"),i=g("span");i.id="bots-modal-title";let s=g("button","btn");s.innerHTML=ae("close",'width="14" height="14"'),s.title="Close",s.onclick=()=>zt(),n.append(i,s);let l=g("div","bots-modal-body");l.id="bots-modal-body",e.append(n,l),t.appendChild(e),t.onclick=a=>{a.target===t&&zt()},document.body.appendChild(t)}function Cn(t){let e=document.getElementById("bots-modal"),n=document.getElementById("bots-modal-title"),i=document.getElementById("bots-modal-body");if(!e||!i)throw new Error("modal missing");return n&&(n.textContent=t),i.textContent="",e.hidden=!1,i}function zt(){let t=document.getElementById("bots-modal");t&&(t.hidden=!0)}async function ml(){return k.catalog||(k.catalog=await j("/api/bots/catalog")),k.catalog}async function Pi(){return k.templates=await j("/api/bots/templates"),k.templates}async function lt(){let t=Cn("Bot templates"),[e,n]=await Promise.all([ml(),Pi()]),i=g("div","bv-template-list");for(let o of n){let c=g("div","bv-template-row");c.appendChild(g("span","bv-template-name",o.manifest.name)),c.appendChild(g("span","bv-template-desc",o.manifest.description||""));let d=g("button","btn","Edit");d.onclick=()=>Di(t,e,o);let m=g("button","btn","Copy");m.title="Duplicate this template",m.onclick=()=>{let f=JSON.parse(JSON.stringify(o.manifest));f.name=`${o.manifest.name} copy`,j("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:f})}).then(()=>lt()).catch(b=>alert(b instanceof Error?b.message:String(b)))};let p=g("button","btn danger","Delete");p.onclick=()=>{confirm(`Delete template ${o.manifest.name}?`)&&j(`/api/bots/templates/${o.id}`,{method:"DELETE"}).then(()=>lt())};let h=g("span","bv-template-actions");h.append(d,m,p),c.appendChild(h),i.appendChild(c)}n.length===0&&i.appendChild(g("div","bots-empty","No templates yet")),t.appendChild(i);let s=g("div","bv-template-actions"),l=g("button","btn primary","New template");l.onclick=()=>Di(t,e,null);let a=g("button","btn","Export");a.title="Download templates + library as JSON",a.onclick=()=>{(async()=>{try{let o=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${gn()}`}});if(!o.ok)throw new Error(`HTTP ${o.status}`);let c=await o.blob(),d=document.createElement("a");d.href=URL.createObjectURL(c),d.download=`tmux-weblink-bots-${new Date().toISOString().slice(0,10)}.json`,d.click(),setTimeout(()=>URL.revokeObjectURL(d.href),2e3)}catch(o){alert(o instanceof Error?o.message:String(o))}})()};let r=g("button","btn","Import");r.title="Restore templates from a JSON bundle",r.onclick=()=>{let o=document.createElement("input");o.type="file",o.accept="application/json,.json",o.onchange=()=>{let c=o.files?.[0];c&&(async()=>{try{let d=JSON.parse(await c.text()),m=await j("/api/bots/import",{method:"POST",body:JSON.stringify(d)});alert(`Imported ${m.templates} templates, ${m.files} library files (${m.skipped} kept)`),await lt()}catch(d){alert(d instanceof Error?d.message:String(d))}})()},o.click()},s.append(l,a,r),t.appendChild(s)}function Ln(t,e,n){let i=g("div","bv-field");i.appendChild(g("label","bv-label",t));let s=g("div","bv-check-grid"),l=[];for(let a of e){let r=g("label","bv-check"),o=document.createElement("input");o.type="checkbox",o.checked=n.includes(a.id),r.append(o,g("span",void 0,a.label)),a.hint&&(r.title=a.hint),s.appendChild(r),l.push({id:a.id,input:o})}return i.appendChild(s),{element:i,get:()=>l.filter(a=>a.input.checked).map(a=>a.id)}}function Di(t,e,n){t.textContent="";let i=n?JSON.parse(JSON.stringify(n.manifest)):{name:"new-bot",description:""},s=g("input","bv-input");s.value=i.name,s.placeholder="Template name";let l=g("input","bv-input");l.value=i.description||"",l.placeholder="One line description";let a=g("textarea","bv-textarea");a.rows=6,a.value=i.system||"",a.placeholder="System prompt for this bot (written to SYSTEM.md)";let r=Ln("Skills",e.skills.map(x=>({id:x.id,label:x.name,hint:x.description})),i.skills||[]),o=Ln("Extensions (Pi builtins + library)",e.extensions.map(x=>({id:x.id,label:`${x.name}${x.kind==="builtin"?" (builtin)":""}`,hint:x.description})),(i.extensions||[]).map(x=>x.replace(/^.*\//,"").replace(/\.(js|ts)$/,""))),c=Ln("Prompt templates",e.prompts.map(x=>({id:x.id,label:x.name})),i.prompts||[]),d=g("select","bv-input");d.appendChild(new Option("none",""));for(let x of e.mcp)d.appendChild(new Option(x.name,x.id));i.mcp&&(d.value=e.mcp.find(x=>JSON.stringify(x.servers)===JSON.stringify(i.mcp?.mcpServers))?.id||"");let m=g("div","bv-field");m.appendChild(g("label","bv-label","Tools (allow list; deny always blocks)"));let p=g("div","bv-check-grid"),h=[];for(let x of e.tools){let F=g("label","bv-check"),B=document.createElement("input");B.type="checkbox",B.checked=(i.tools?.allow||[]).includes(x.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(x.name),F.append(B,g("span",void 0,x.name)),p.appendChild(F),h.push({name:x.name,input:B})}m.appendChild(p);let f=g("input","bv-input");f.value=(i.tools?.deny||[]).join(", "),f.placeholder="Always deny (comma separated), e.g. bash, write";let b=g("textarea","bv-textarea");b.rows=2,b.value=(i.packages||[]).join(`
86
- `),b.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";let w=g("select","bv-input");w.appendChild(new Option("default (Pi settings)",""));for(let x of e.models)w.appendChild(new Option(`${x.provider}/${x.model}`,`${x.provider}
87
- ${x.model}`));i.model?.provider&&i.model?.id&&(w.value=`${i.model.provider}
88
- ${i.model.id}`);let y=g("select","bv-input");for(let x of["","off","minimal","low","medium","high","xhigh","max"])y.appendChild(new Option(x||"default",x));i.model?.thinking&&(y.value=i.model.thinking);let C=g("select","bv-input");for(let x of["supervised","auto-accept-edits","full-access"])C.appendChild(new Option(x,x));C.value=i.permissions?.runtimeMode||"supervised";let M=g("select","bv-input");M.appendChild(new Option("ignore project .pi (recommended)","ignore")),M.appendChild(new Option("inherit project .pi (needs trust)","inherit")),M.value=i.projectResources||"ignore";let T=g("label","bv-check"),I=document.createElement("input");I.type="checkbox",I.checked=!!i.orchestrator,T.append(I,g("span",void 0,"Super bot: gets orchestration tools (create/stop/status child bots)"));let $=(x,F)=>{let B=g("div","bv-field");return B.appendChild(g("label","bv-label",x)),B.appendChild(F),B};t.append($("Name",s),$("Description",l),$("System prompt",a),r.element,o.element,c.element,$("MCP preset",d),m,$("Always deny tools",f),$("Packages",b),$("Model",w),$("Thinking level",y),$("Approval mode",C),$("Project resources",M),T);let z=g("button","btn primary",n?"Save template":"Create template");z.onclick=async()=>{let[x,F]=w.value.split(`
89
- `),B=e.mcp.find(A=>A.id===d.value),Z={name:s.value.trim()||"bot",description:l.value.trim()||void 0,system:a.value.trim()||void 0,skills:r.get(),extensions:o.get().map(A=>(A.startsWith("builtin:"),A)),prompts:c.get(),packages:b.value.split(`
90
- `).map(A=>A.trim()).filter(Boolean),mcp:B?{mcpServers:B.servers}:void 0,tools:{allow:h.filter(A=>A.input.checked).map(A=>A.name),deny:f.value.split(",").map(A=>A.trim()).filter(Boolean)},model:x?{provider:x,id:F,thinking:y.value||void 0}:void 0,permissions:{runtimeMode:C.value},projectResources:M.value==="inherit"?"inherit":"ignore",orchestrator:I.checked||void 0};try{await j("/api/bots/templates",{method:"POST",body:JSON.stringify({id:n?.id,manifest:Z})}),zt(),await lt()}catch(A){alert(A instanceof Error?A.message:String(A))}},t.appendChild(z)}async function fl(){return Hi("")}async function Hi(t){let e=Cn("New bot"),n=await Pi();if(n.length===0){e.appendChild(g("div","bots-empty","No templates yet \u2014 create one with \u201CNew template\u201D."));return}let i=g("select","bv-input");for(let c of n)i.appendChild(new Option(c.manifest.name,c.id));let s=g("input","bv-input");s.placeholder="Title (defaults to template name)";let l=g("input","bv-input");l.placeholder="/path/to/project";let a=t||k.bots[0]?.projectPath||"";l.value=a;let r=g("select","bv-input");r.appendChild(new Option("shared \u2014 run in the project folder","shared")),r.appendChild(new Option("worktree \u2014 isolated git worktree","worktree")),e.append(Mt("Template",i),Mt("Title",s),Mt("Project path",l),Mt("Workspace",r));let o=g("button","btn primary","Create bot");o.onclick=async()=>{try{let c=await j("/api/bots",{method:"POST",body:JSON.stringify({templateId:i.value,title:s.value.trim()||void 0,projectPath:l.value.trim()||void 0,isolation:r.value})});zt(),await oe(!0),await Ai(c.id)}catch(c){alert(c instanceof Error?c.message:String(c))}},e.appendChild(o)}function Mt(t,e){let n=g("div","bv-field");return n.appendChild(g("label","bv-label",t)),n.appendChild(e),n}async function Tn(){let t=Cn("Needs you");if(k.approvals=await j("/api/bots/approvals"),k.approvals.length===0){t.appendChild(g("div","bots-empty","Nothing waiting."));return}for(let e of k.approvals){let n=g("div","bv-approval");if(n.appendChild(g("div","bv-approval-tag",e.botTitle)),n.appendChild(g("div","bv-approval-title",e.title)),e.message){let c=g("pre","bv-pre bv-approval-detail");c.textContent=e.message,n.appendChild(c)}let i=g("input","bv-reason");i.placeholder="reason (optional)",i.setAttribute("aria-label","Reason (optional)");let s=g("div","bv-approval-actions"),l=g("button","btn primary","Allow once"),a=g("button","btn danger","Deny"),r=[l,a],o=async(c,d)=>{let m=d.textContent??"";for(let p of r)p.disabled=!0;d.textContent=c?"Allowing\u2026":"Denying\u2026";try{await j(`/api/bots/${e.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:e.id,allow:c,reason:i.value||void 0})}),await oe(!0),await Tn()}catch(p){for(let h of r)h.disabled=!1;d.textContent=m,Pe({kind:"notice",level:"error",text:p instanceof Error?p.message:String(p)})}};l.onclick=()=>void o(!0,l),a.onclick=()=>void o(!1,a),s.append(i,l,a),n.appendChild(s),t.appendChild(n)}}function gl(){window.__botsInited||(window.__botsInited=!0,nl(),tl(),window.__openBot=Ai,document.addEventListener("click",t=>{let e=t.target;e&&(e.closest(".session-item.bot-item")||e.closest(".session-item")&&k.activeId&&setTimeout(()=>kn(),0))},!0),document.addEventListener("click",t=>{let e=t.target;!e||!k.activeId||(e.closest("#mode-files")||e.closest(".file-tree-item")||e.closest(".file-roots-list li"))&&kn()}),oe(!0),k.pollTimer=window.setInterval(()=>{document.hidden||oe()},6e3),window.addEventListener("beforeunload",()=>window.clearInterval(k.pollTimer)))}var rt=window.__TMUX_WEB_SHELL__,N=null,V=null,ot=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null,ee=ot;window.__tmuxWebScopeAgent=ot;var $n="sessions",we="",Bt="",Rt="",_i="";function K(t){return ee?"/a/"+encodeURIComponent(ee)+t:t}var D=document.getElementById("sidebar-content"),He=document.getElementById("main-placeholder"),ie=document.getElementById("terminal-container"),ct=document.getElementById("file-editor"),vl=document.getElementById("fe-path"),ce=document.getElementById("fe-status"),dt=document.getElementById("fe-content"),_e=document.getElementById("fe-save"),bl=document.getElementById("fe-delete"),kl=document.getElementById("fe-back"),Fi=document.getElementById("fe-new-name"),wl=document.getElementById("fe-new-btn"),In=document.getElementById("settings-backdrop"),Ni=document.getElementById("settings-popover"),Oi=document.querySelector(".sidebar"),qi="tmux-web-force-narrow";function Pt(){try{return localStorage.getItem(qi)==="1"}catch{return!1}}function ji(){document.documentElement.classList.toggle("force-narrow",Pt()),Pt()&&Vi()&&pt()}function Vi(){return Pt()?!0:window.matchMedia("(max-width: 640px)").matches}function pt(){Vi()&&Oi.classList.add("collapsed")}function Wi(){Oi.classList.remove("collapsed")}window.__collapseSidebar=pt,document.getElementById("mode-sessions").addEventListener("click",()=>{Wi(),Ui("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{Wi(),Ui("files")});function Ui(t){$n=t,document.querySelectorAll(".mode-btn").forEach(n=>n.classList.remove("active"));let e=document.getElementById(t==="sessions"?"mode-sessions":"mode-files");e&&e.classList.add("active"),t==="sessions"?(An="",ye()):Pl()}var An="";async function ye(){if($n!=="sessions")return;try{let e=await(await fetch("/api/sidebar/sessions")).json(),n=(window.__botsSnapshot||[]).map(s=>[s.id,s.title,s.status,s.projectPath]),i=JSON.stringify({recent:e.recent,agents:e.agents,tombstones:e.tombstones,bots:n});if(i===An)return;An=i,Ll(e)}catch{D.innerHTML+='<div class="file-tree-empty">Failed to load sessions</div>'}let t=document.getElementById("ns-btn");t&&t.addEventListener("click",()=>{let e=window.__openNewSessionModal;typeof e=="function"?e():document.getElementById("new-session-modal")?.classList.add("open")}),Hn()}var Ji="tmux-web-sidebar-group-collapsed";function Zi(){try{return new Set(JSON.parse(localStorage.getItem(Ji)||"[]"))}catch{return new Set}}function yl(t){try{localStorage.setItem(Ji,JSON.stringify([...t]))}catch{}}function xl(t,e,n){if(!t)return"\u2026";let i=n&&(t===n||t.startsWith(n+"/"))?"~"+t.slice(n.length):t,s=i.split("/").filter(Boolean);if(s.length===0)return t;for(let l=1;l<=s.length;l++){let a=s.slice(-l).join("/");if(!e.some(r=>!r||r===t?!1:(n&&(r===n||r.startsWith(n+"/"))?"~"+r.slice(n.length):r).split("/").filter(Boolean).slice(-l).join("/")===a))return a}return i}function Sl(t){let e=document.createElement("div");e.className="session-item bot-item",e.setAttribute("data-bot-id",t.id),e.title=`Bot \xB7 ${t.projectPath}`;let n=t.status==="running"?"var(--panel-success)":t.status==="waiting_approval"||t.status==="waiting_input"?"#e0a23c":t.status==="failed"?"var(--panel-danger, #e5534b)":"var(--panel-muted)";return e.innerHTML=`${ae("bot",'class="bot-icon"')}<span>${H(t.title)}</span><span class="bot-status-dot" style="background:${n}"></span>`,e.addEventListener("click",i=>{i.stopPropagation(),window.__openBot?.(t.id)}),e}function Yi(t,e,n,i=!0){let s=new Map;for(let c of t){let d=c.path||"";s.has(d)||s.set(d,[]),s.get(d).push(c)}let l=n?[]:window.__botsSnapshot||[],a=new Map;for(let c of l)s.has(c.projectPath)||s.set(c.projectPath,[]),a.has(c.projectPath)||a.set(c.projectPath,[]),a.get(c.projectPath).push(c);let r=[...s.keys()],o=Zi();for(let[c,d]of s){let m=xl(c,r,e),p=o.has(c),h=document.createElement("div");if(h.className="session-group-header"+(p?" collapsed":""),h.title=c||"No working directory",h.innerHTML=`<span class="sg-folder">&#128193;</span><span class="sg-label">${H(m)}</span>`,!n&&c){let b=document.createElement("button");b.className="sg-add-bot",b.innerHTML=ae("add",'width="12" height="12"'),b.title=`New bot in ${c}`,b.addEventListener("click",w=>{w.stopPropagation(),Mn(c)}),h.appendChild(b)}h.addEventListener("click",()=>{let b=Zi(),w=h.nextElementSibling;b.has(c)?(b.delete(c),h.classList.remove("collapsed"),w?.classList.remove("collapsed")):(b.add(c),h.classList.add("collapsed"),w?.classList.add("collapsed")),yl(b)});let f=document.createElement("div");f.className="session-group-body"+(p?" collapsed":"");for(let b of d)f.appendChild(n?El(b,n,i):Cl(b));for(let b of a.get(c)||[])f.appendChild(Sl(b));D.appendChild(h),D.appendChild(f)}}function El(t,e,n){let i=document.createElement("div");i.className="session-item"+(t.name===V&&ee===e?" active":"")+(n?"":" session-offline"),i.setAttribute("data-session",t.name),i.setAttribute("data-agent",e),i.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${t.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>
91
- <span>${H(t.name)}</span>${n?"":'<span class="meta">offline</span>'}
92
- <button class="session-edit-btn" data-session="${H(t.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&&i.addEventListener("click",l=>{l.target.closest(".session-edit-btn")||ut(t.name,e)});let s=i.querySelector(".session-edit-btn");return s&&s.addEventListener("click",l=>{l.stopPropagation(),Wt(t.name,s,{agentId:e})}),i}function Cl(t){let e=document.createElement("div");e.className="session-item"+(t.name===V&&!ee?" active":""),e.setAttribute("data-session",t.name),e.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${t.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>
93
- <span>${H(t.name)}</span>
94
- <button class="session-edit-btn" data-session="${H(t.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>
95
- `,e.addEventListener("click",i=>{i.target.closest(".session-edit-btn")||ut(t.name)});let n=e.querySelector(".session-edit-btn");return n&&n.addEventListener("click",i=>{i.stopPropagation(),Wt(t.name,n)}),e}function Ll(t){D.innerHTML='<button class="new-session-sidebar-btn" id="ns-btn">+ New Session</button>';let e=t.recent||[],n=document.createElement("div");n.className="sidebar-section-label"+(ot?" clickable":""),n.textContent=ot?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",ot&&(n.title="Back to hub",n.addEventListener("click",()=>{window.location.href="/"})),D.appendChild(n),Yi(e,t.home);let i=t.agents||[];for(let l of i){if(!l.sessions||l.sessions.length===0)continue;let a=l.agentId===ee,r=document.createElement("div");r.className="sidebar-section-label machine-label"+(l.online?"":" agent-offline-label")+(!a&&l.online?" clickable":""),r.textContent=l.agentName+(l.online?"":" (offline)"),!a&&l.online&&(r.title="\u6253\u5F00 "+l.agentName,r.addEventListener("click",()=>{window.location.href="/a/"+encodeURIComponent(l.agentId)+"/"})),D.appendChild(r),Yi(l.sessions,t.home,l.agentId,l.online)}let s=t.tombstones||[];if(s.length>0){let l=document.createElement("div");l.className="sidebar-section-label tombstone-label",l.textContent="\u5931\u6548\u4F1A\u8BDD",D.appendChild(l);for(let a of s){let r=document.createElement("div");r.className="session-item session-tombstone",r.setAttribute("data-session",a.name),a.agentId&&r.setAttribute("data-agent",a.agentId);let o=a.agentId?a.agentOnline?" (agent)":" (agent \u79BB\u7EBF)":"";r.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"></svg>
96
- <span>${H(a.name)}</span><span class="meta">\u5931\u6548${o}</span>
97
- <button class="session-edit-btn" data-session="${H(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>`,r.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",r.addEventListener("click",()=>{Wt(a.name,r,{tombstone:!0,agentId:a.agentId})});let c=r.querySelector(".session-edit-btn");c&&c.addEventListener("click",d=>{d.stopPropagation(),Wt(a.name,c,{tombstone:!0,agentId:a.agentId})}),D.appendChild(r)}}}function H(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}async function ut(t,e){if(V===t&&N&&ee===(e||null))return;ct.style.display="none",He.style.display="none",ie.style.display="",ie.classList.add("terminal-pending"),pt(),N&&(jt(),N.destroy(),N=null),V=t,ee=e||null,window.__tmuxWebScopeAgent=ee,window.__tmuxWebCurrentSession=V,Kl(t,e);let n=Dn(t,e);ds.set(n,Date.now()+Yl);let i=Je.get(n);if(i&&i.state==="working"){i.state="idle",i.doneUntil=void 0,i.unread=!1;let s=D.querySelector(e?'.session-item[data-agent="'+CSS.escape(e)+'"][data-session="'+CSS.escape(t)+'"]':'.session-item[data-session="'+CSS.escape(t)+'"]:not([data-agent])');s&&Xt(s,n,i)}for(let s of D.querySelectorAll(".session-item"))s.classList.toggle("active",s.getAttribute("data-session")===t&&(s.getAttribute("data-agent")||null)===ee);try{N=await Ds(ie,t,{terminal:rt.terminal,scrollback:rt.scrollback,theme:rt.theme,wsBase:ee?"/ws/a/"+encodeURIComponent(ee):rt.wsBase||"/ws"}),as()}catch(s){console.error("[shell] terminal init failed:",s);let l=s&&typeof s=="object"&&"message"in s?s.message:String(s);ie.textContent="Failed to open terminal for "+t+": "+l,ie.classList.remove("terminal-pending")}}var Dt=[],J=null,Xi=!1;function Tl(t){if(!J||!J.files.length)return null;let e=J.repoRoot;if(!e||!t.startsWith(e))return null;let n=t.slice(e.length+1);for(let i of J.files)if(i.path===n)return i.status;return null}async function $l(t){Xi=!0;try{let e=await fetch(K("/api/git/status?path="+encodeURIComponent(t)));e.ok?J=await e.json():J=null}catch{J=null}finally{Xi=!1}}function Il(){if(!J||!J.branch)return"";let{branch:t,linesAdded:e,linesRemoved:n}=J,i=`<div class="sidebar-git"><div class="git-branch-badge">
79
+ `}tablerow({text:e}){return`<tr>
80
+ ${e}</tr>
81
+ `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
82
+ `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${te(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,text:n,tokens:i,autolink:s}){let a=s?te(n,!0):this.parser.parseInline(i),l=Li(e);if(l===null)return a;e=te(l,s);let r='<a href="'+e+'"';return t&&(r+=' title="'+te(t)+'"'),r+=">"+a+"</a>",r}image({href:e,title:t,text:n,tokens:i}){i&&(n=this.parser.parseInline(Ln(i),this.parser.textRenderer));let s=Li(e);if(s===null)return te(n);e=s;let a=`<img src="${te(e)}" alt="${te(n)}"`;return t&&(a+=` title="${te(t)}"`),a+=">",a}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:te(e.text)}},$n=class{parser;strong({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}em({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}codespan({text:e}){return e}del({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}html({text:e}){return e}text({text:e}){return e}link({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}image({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}br(){return`
83
+ `}checkbox({raw:e}){return e}},ue=class Gn{options;renderer;textRenderer;constructor(t){this.options=t||_e,this.options.renderer=this.options.renderer||new Rt,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new $n,this.textRenderer.parser=this}static parse(t,n){return new Gn(n).parse(t)}static parseInline(t,n){return new Gn(n).parseInline(t)}parse(t){this.renderer.parser=this;let n="";for(let i=0;i<t.length;i++){let s=t[i],a=this.options.extensions?.renderers;if(a&&Object.hasOwn(a,s.type)&&a[s.type]){let r=s,o=a[r.type].call({parser:this},r);if(o!==!1||!["space","hr","heading","code","table","blockquote","list","checkbox","html","def","paragraph","text"].includes(r.type)){n+=o===!1?"":o??"";continue}}let l=s;switch(l.type){case"space":{n+=this.renderer.space(l);break}case"hr":{n+=this.renderer.hr(l);break}case"heading":{n+=this.renderer.heading(l);break}case"code":{n+=this.renderer.code(l);break}case"table":{n+=this.renderer.table(l);break}case"blockquote":{n+=this.renderer.blockquote(l);break}case"list":{n+=this.renderer.list(l);break}case"checkbox":{n+=this.renderer.checkbox(l);break}case"html":{n+=this.renderer.html(l);break}case"def":{n+=this.renderer.def(l);break}case"paragraph":{n+=this.renderer.paragraph(l);break}case"text":{n+=this.renderer.text(l);break}default:{let r='Token with "'+l.type+'" type was not found.';if(this.options.silent)return console.error(r),"";throw new Error(r)}}}return n}parseInline(t,n=this.renderer){this.renderer.parser=this;let i="";for(let s=0;s<t.length;s++){let a=t[s],l=this.options.extensions?.renderers;if(l&&Object.hasOwn(l,a.type)&&l[a.type]){let o=l[a.type].call({parser:this},a);if(o!==!1||!["escape","html","link","image","checkbox","strong","em","codespan","br","del","text"].includes(a.type)){i+=o===!1?"":o??"";continue}}let r=a;switch(r.type){case"escape":{i+=n.text(r);break}case"html":{i+=n.html(r);break}case"link":{i+=n.link(r);break}case"image":{i+=n.image(r);break}case"checkbox":{i+=n.checkbox(r);break}case"strong":{i+=n.strong(r);break}case"em":{i+=n.em(r);break}case"codespan":{i+=n.codespan(r);break}case"br":{i+=n.br(r);break}case"del":{i+=n.del(r);break}case"text":{i+=n.text(r);break}default:{let o='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return i}},ht=class{options;block;constructor(e){this.options=e||_e}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?pe.lex:pe.lexInline}provideParser(e=this.block){return e?ue.parse:ue.parseInline}};function Pe(e,t){if(Array.isArray(t))for(let n=0;n<t.length;n++)e.push(t[n]);else e.push(t)}var hl=class{defaults=mn();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=ue;Renderer=Rt;TextRenderer=$n;Lexer=pe;Tokenizer=je;Hooks=ht;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let i of e)switch(Pe(n,t.call(this,i)),i.type){case"table":{let s=i;for(let a of s.header)Pe(n,this.walkTokens(a.tokens,t));for(let a of s.rows)for(let l of a)Pe(n,this.walkTokens(l.tokens,t));break}case"list":{let s=i;Pe(n,this.walkTokens(s.items,t));break}default:{let s=i;this.defaults.extensions?.childTokens?.[s.type]?this.defaults.extensions.childTokens[s.type].forEach(a=>{if(s[a]){let l=s[a].flat(1/0);Pe(n,this.walkTokens(l,t))}}):s.tokens&&Pe(n,this.walkTokens(s.tokens,t))}}return n}use(...e){let t=this.defaults.extensions||{renderers:Object.create(null),childTokens:Object.create(null)};return e.forEach(n=>{let i={...n};if(i.async=this.defaults.async||i.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s&&s.renderer){let a=s.renderer,l=t.renderers[s.name];l?t.renderers[s.name]=function(...r){let o=a.apply(this,r);return o===!1&&(o=l.apply(this,r)),o}:t.renderers[s.name]=a}if("tokenizer"in s&&s.tokenizer){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let a=t[s.level];a?a.unshift(s.tokenizer):t[s.level]=[s.tokenizer],s.start&&(s.level==="block"?t.startBlock?t.startBlock.push(s.start):t.startBlock=[s.start]:s.level==="inline"&&(t.startInline?t.startInline.push(s.start):t.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(t.childTokens[s.name]=s.childTokens)}),i.extensions=t),n.renderer){let s=this.defaults.renderer||new Rt(this.defaults);for(let a in n.renderer){if(!(a in s))throw new Error(`renderer '${a}' does not exist`);if(["options","parser"].includes(a))continue;let l=a,r=n.renderer[l];if(r===void 0)continue;let o=s[l];s[l]=(...c)=>{let d=r.apply(s,c);return d===!1&&(d=o.apply(s,c)),d===!1?"":d??""}}i.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new je(this.defaults);for(let a in n.tokenizer){if(!(a in s))throw new Error(`tokenizer '${a}' does not exist`);if(["options","rules","lexer"].includes(a))continue;let l=a,r=n.tokenizer[l];if(r===void 0)continue;let o=s[l];s[l]=(...c)=>{let d=r.apply(s,c);return d===!1&&(d=o.apply(s,c)),d}}i.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new ht;for(let a in n.hooks){if(!(a in s))throw new Error(`hook '${a}' does not exist`);if(["options","block"].includes(a))continue;let l=a,r=n.hooks[l];if(r===void 0)continue;let o=s[l];ht.passThroughHooks.has(a)?s[l]=c=>{if(s.options.async&&ht.passThroughHooksRespectAsync.has(a))return(async()=>{let v=await r.call(s,c);return o.call(s,v)})();let d=r.call(s,c);return o.call(s,d)}:s[l]=(...c)=>{if(s.options.async)return(async()=>{let v=await r.apply(s,c);return v===!1&&(v=await o.apply(s,c)),v})();let d=r.apply(s,c);return d===!1&&(d=o.apply(s,c)),d}}i.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,a=n.walkTokens;i.walkTokens=function(l){let r=[];return Pe(r,a.call(this,l)),s&&Pe(r,s.call(this,l)),r}}this.defaults={...this.defaults,...i}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return pe.lex(e,t??this.defaults)}parser(e,t){return ue.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let i={...n},s={...this.defaults,...i},a=this.onError(!!s.silent,!!s.async);if(this.defaults.async===!0&&i.async===!1)return a(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||t===null)return a(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return a(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=e),s.async)return(async()=>{let l=s.hooks?await s.hooks.preprocess(t):t,r=await(s.hooks?await s.hooks.provideLexer(e):e?pe.lex:pe.lexInline)(l,s),o=s.hooks?await s.hooks.processAllTokens(r):r;s.walkTokens&&await Promise.all(this.walkTokens(o,s.walkTokens));let c=await(s.hooks?await s.hooks.provideParser(e):e?ue.parse:ue.parseInline)(o,s);return s.hooks?await s.hooks.postprocess(c):c})().catch(a);try{s.hooks&&(t=s.hooks.preprocess(t));let l=(s.hooks?s.hooks.provideLexer(e):e?pe.lex:pe.lexInline)(t,s);s.hooks&&(l=s.hooks.processAllTokens(l)),s.walkTokens&&this.walkTokens(l,s.walkTokens);let r=(s.hooks?s.hooks.provideParser(e):e?ue.parse:ue.parseInline)(l,s);return s.hooks&&(r=s.hooks.postprocess(r)),r}catch(l){return a(l)}}}onError(e,t){return n=>{let i=n instanceof Error?n:new Error(String(n));if(i.message+=`
84
+ Please report this to https://github.com/markedjs/marked.`,e){let s="<p>An error occurred:</p><pre>"+te(i.message+"",!0)+"</pre>";return t?Promise.resolve(s):s}if(t)return Promise.reject(i);throw i}}},qe=new hl;function H(e,t){return qe.parse(e,t)}function fl(e,t){return qe.parseInline(e,t)}H.options=H.setOptions=function(e){return qe.setOptions(e),H.defaults=qe.defaults,pi(H.defaults),H},H.getDefaults=mn,H.defaults=_e;function ml(...e){return qe.use(...e),H.defaults=qe.defaults,pi(H.defaults),H}H.use=ml,H.walkTokens=function(e,t){return qe.walkTokens(e,t)},H.parseInline=fl,H.Parser=ue,H.parser=ue.parse,H.Renderer=Rt,H.TextRenderer=$n,H.Lexer=pe,H.lexer=pe.lex,H.Tokenizer=je,H.Hooks=ht,H.parse=H;var Rr=H.options,Pr=H.setOptions,Dr=H.walkTokens,Hr=H.parseInline,_r=ue.parse,Fr=pe.lex,gl=["const","let","var","function","return","if","else","for","while","do","switch","case","default","break","continue","class","extends","implements","interface","type","enum","import","export","from","as","async","await","try","catch","finally","throw","new","this","super","typeof","instanceof","in","of","void","null","undefined","true","false","public","private","protected","readonly","static","yield","delete","declare","namespace","satisfies","infer","keyof","is"],bl=["def","class","return","if","elif","else","for","while","try","except","finally","with","as","import","from","pass","raise","lambda","yield","assert","del","global","nonlocal","and","or","not","in","is","None","True","False","async","await","match","case"],vl=["if","then","else","elif","fi","for","while","do","done","case","esac","function","return","export","local","set","unset","source","echo","cd","exit","in"],kl={js:"js",jsx:"js",ts:"js",tsx:"js",javascript:"js",typescript:"js",node:"js",mjs:"js",cjs:"js",py:"py",python:"py",sh:"sh",bash:"sh",shell:"sh",zsh:"sh",console:"sh",json:"json",jsonc:"json",css:"css",scss:"css",diff:"diff",patch:"diff"},wl={js:gl,py:bl,sh:vl,json:[],css:[],diff:[],plain:[]},yl={js:[{cls:"com",source:"\\/\\/[^\\n]*|\\/\\*[\\s\\S]*?\\*\\/"},{cls:"str",source:"\"(?:\\\\.|[^\"\\\\])*\"|'(?:\\\\.|[^'\\\\])*'|`(?:\\\\.|[^`\\\\])*`"},{cls:"num",source:"\\b\\d[\\d_]*(?:\\.\\d+)?\\b"},{cls:"word",source:"\\b[A-Za-z_$][\\w$]*\\b"}],py:[{cls:"com",source:"#[^\\n]*"},{cls:"str",source:`"""[\\s\\S]*?"""|'''[\\s\\S]*?'''|"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'`},{cls:"num",source:"\\b\\d[\\d_]*(?:\\.\\d+)?\\b"},{cls:"word",source:"\\b[A-Za-z_][\\w]*\\b"}],sh:[{cls:"com",source:"#[^\\n]*"},{cls:"str",source:`"(?:\\\\.|[^"\\\\])*"|'[^']*'`},{cls:"num",source:"\\b\\d+\\b"},{cls:"word",source:"\\b[A-Za-z_][\\w-]*\\b"}],json:[{cls:"str",source:'"(?:\\\\.|[^"\\\\])*"'},{cls:"num",source:"-?\\b\\d+(?:\\.\\d+)?\\b"},{cls:"word",source:"\\b(?:true|false|null)\\b"}],css:[{cls:"com",source:"\\/\\*[\\s\\S]*?\\*\\/"},{cls:"str",source:`"(?:\\\\.|[^"\\\\])*"|'[^']*'`},{cls:"num",source:"#[0-9a-fA-F]{3,8}\\b|-?\\b\\d+(?:\\.\\d+)?(?:px|em|rem|%|vh|vw|s|ms)?\\b"},{cls:"word",source:"[.#][\\w-]+|@[\\w-]+|\\b[a-z-]+(?=\\s*:)"}],diff:[],plain:[]};function xl(e,t,n){let i=kl[n.trim().toLowerCase()]??"plain",s=e.createDocumentFragment();if(i==="diff")return El(e,s,t),s;let a=yl[i];if(a.length===0)return s.appendChild(e.createTextNode(t)),s;let l=new Set(wl[i]),r=a.map((d,v)=>`g${v}`).join(""),o=new RegExp(a.map((d,v)=>`(?<g${v}>${d.source})`).join("|"),"g"),c=0;for(let d of t.matchAll(o)){let v=d.index??0;v>c&&s.appendChild(e.createTextNode(t.slice(c,v))),c=v+d[0].length;let h=d.groups??{},p=a.findIndex((L,M)=>h[`g${M}`]!==void 0),f=d[0];if(p<0){s.appendChild(e.createTextNode(f));continue}let m=a[p].cls,k=m==="word"?l.has(f)?"tok-kw":null:`tok-${m}`;if(i==="json"&&m==="str"&&t.slice(c).trimStart().startsWith(":")&&(k="tok-key"),k===null){s.appendChild(e.createTextNode(f));continue}let w=e.createElement("span");w.className=k,w.textContent=f,s.appendChild(w)}return c<t.length&&s.appendChild(e.createTextNode(t.slice(c))),s}function El(e,t,n){let i=n.split(`
85
+ `);i.forEach((s,a)=>{let l=s.startsWith("+")?"tok-add":s.startsWith("-")?"tok-del":s.startsWith("@@")?"tok-meta":null;if(l){let r=e.createElement("span");r.className=l,r.textContent=s,t.appendChild(r)}else t.appendChild(e.createTextNode(s));a<i.length-1&&t.appendChild(e.createTextNode(`
86
+ `))})}var Sl=new Set(["http:","https:","mailto:"]);function Ri(e){let t=(e??"").trim();if(!t||t.startsWith("//"))return null;if(!/^[a-z][a-z0-9+.-]*:/i.test(t))return t;try{return Sl.has(new URL(t).protocol)?t:null}catch{return null}}var Pi=e=>/^[a-z][a-z0-9+.-]*:/i.test(e)&&!e.startsWith("mailto:"),Di=4e5,Cl=200,Ll=900;function $l(e){if(e.length<Ll||/^ {0,3}(?:<|:::|\$\$|\\\[|\[\^)/m.test(e)||/^[ \t]*\[[^\]]+\]:/m.test(e))return null;let t=e.split(`
87
+ `),n=[],i=[],s=null,a=()=>{let l=i.join(`
88
+ `);l.trim()&&n.push(l),i=[]};for(let l=0;l<t.length;l++){let r=t[l],o=/^ {0,3}(`{3,}|~{3,})/.exec(r);if(s){i.push(r),o&&r.trimStart().startsWith(s)&&(s=null);continue}if(o){s=o[1],i.push(r);continue}if(i.push(r),r.trim()!=="")continue;let c=l+1;for(;c<t.length&&t[c].trim()==="";)c++;if(c>=t.length)break;let d=t[c];if(/^[ \t]/.test(d)||/^(?:[-*+](?:[ \t]|$)|\d{1,9}[.)](?:[ \t]|$)|>|\||:::|```|~~~)/.test(d))continue;let v=[...i].reverse().find(p=>p.trim()!=="")??"";if(/^[ \t]*(?:\||>)/.test(v))continue;let h=v.trim();/^[-*+]$/.test(h)||/^\d{1,9}[.)]$/.test(h)||a()}return a(),n.length>1?n:null}function Il(e){let t=new Map,n=0;function i(h,p){let f=h.length+Cl;if(!(f>Di/4)){t.set(h,{fragment:p,chars:f}),n+=f;for(let m of t.keys()){if(n<=Di)break;let k=t.get(m);k&&(t.delete(m),n-=k.chars)}}}function s(h,p){p.split(`
89
+ `).forEach((f,m)=>{m>0&&h.appendChild(e.createElement("br")),f&&h.appendChild(e.createTextNode(f))})}function a(h,p){switch(p.type){case"text":{if(p.tokens?.length){for(let f of p.tokens)a(h,f);return}s(h,p.text??p.raw??"");return}case"escape":h.appendChild(e.createTextNode(p.text??""));return;case"strong":case"em":case"del":{let f=e.createElement(p.type==="strong"?"strong":p.type==="em"?"em":"del");for(let m of p.tokens??[])a(f,m);h.appendChild(f);return}case"codespan":{let f=e.createElement("code");f.textContent=p.text??"",h.appendChild(f);return}case"br":h.appendChild(e.createElement("br"));return;case"link":{let f=p.tokens??[],m=Ri(p.href);if(!m){for(let w of f)a(h,w);return}let k=e.createElement("a");k.href=m,k.rel="noreferrer noopener",p.title&&(k.title=p.title),Pi(m)&&(k.target="_blank");for(let w of f)a(k,w);h.appendChild(k);return}case"image":{let f=Ri(p.href),m=p.text?.trim()||p.href||"image";if(!f){h.appendChild(e.createTextNode(m));return}let k=e.createElement("a");k.href=f,k.textContent=m,k.rel="noreferrer noopener",Pi(f)&&(k.target="_blank"),h.appendChild(k);return}case"html":h.appendChild(e.createTextNode(p.raw??p.text??""));return;default:if(p.tokens?.length){for(let f of p.tokens)a(h,f);return}s(h,p.text??p.raw??"")}}function l(h){let p=e.createElement("div");p.className="bv-code";let f=e.createElement("div");f.className="bv-code-head";let m=(h.lang??"").trim().split(/\s+/)[0]??"",k=e.createElement("span");k.className="bv-code-lang",k.textContent=m||"text";let w=e.createElement("button");w.type="button",w.className="bv-code-copy",w.textContent="Copy";let L=h.text??"";w.addEventListener("click",()=>{let T=navigator.clipboard?.writeText(L);T&&T.then(()=>{w.textContent="Copied",window.setTimeout(()=>{w.textContent="Copy"},1200)},()=>{})}),f.append(k,w);let M=e.createElement("pre"),$=e.createElement("code");return m&&($.className=`language-${m}`),$.appendChild(xl(e,L,m)),M.appendChild($),p.append(f,M),p}function r(h,p){let f=e.createElement("div");f.className="bv-table";let m=e.createElement("table"),k=e.createElement("thead"),w=e.createElement("tr"),L=p.align??[],M=(T,I,B)=>{let x=e.createElement(T);L[B]&&(x.style.textAlign=L[B]);for(let A of I.tokens??[])a(x,A);return x};(p.header??[]).forEach((T,I)=>w.appendChild(M("th",T,I))),k.appendChild(w);let $=e.createElement("tbody");for(let T of p.rows??[]){let I=e.createElement("tr");T.forEach((B,x)=>I.appendChild(M("td",B,x))),$.appendChild(I)}m.append(k,$),f.appendChild(m),h.appendChild(f)}function o(h,p){let f=e.createElement("li");if(p.task){let m=e.createElement("input");m.type="checkbox",m.disabled=!0,m.checked=p.checked===!0,f.appendChild(m)}for(let m of p.tokens??[])if(m.type==="text")a(f,m);else if(m.type==="paragraph")for(let k of m.tokens??[])a(f,k);else c(f,m);h.appendChild(f)}function c(h,p){switch(p.type){case"space":return;case"heading":{let f=Math.min(Math.max(p.depth??1,1),6),m=e.createElement(`h${f}`);for(let k of p.tokens??[])a(m,k);h.appendChild(m);return}case"paragraph":{let f=e.createElement("p");for(let m of p.tokens??[])a(f,m);h.appendChild(f);return}case"text":a(h,p);return;case"code":h.appendChild(l(p));return;case"blockquote":{let f=e.createElement("blockquote");for(let m of p.tokens??[])c(f,m);h.appendChild(f);return}case"list":{let f=p.items??p.tokens??[];if(p.ordered){let m=e.createElement("ol");typeof p.start=="number"&&p.start!==1&&(m.start=p.start);for(let k of f)o(m,k);h.appendChild(m)}else{let m=e.createElement("ul");for(let k of f)o(m,k);h.appendChild(m)}return}case"table":r(h,p);return;case"hr":h.appendChild(e.createElement("hr"));return;case"html":case"escape":h.appendChild(e.createTextNode(p.raw??p.text??""));return;default:if(p.tokens?.length){for(let f of p.tokens)c(h,f);return}p.text&&h.appendChild(e.createTextNode(p.text))}}function d(h){let p=e.createDocumentFragment();try{let f=H.lexer(h);for(let m of f)c(p,m)}catch{p.replaceChildren(e.createTextNode(h))}return p}function v(h){let p=t.get(h);if(p)return t.delete(h),t.set(h,p),p.fragment.cloneNode(!0);let f=d(h);return i(h,f),f.cloneNode(!0)}return h=>{let p=t.get(h);if(p)return t.delete(h),t.set(h,p),p.fragment.cloneNode(!0);let f=$l(h);if(f){let k=e.createDocumentFragment();for(let w of f)k.appendChild(v(w));return k}let m=d(h);return i(h,m),m.cloneNode(!0)}}var In=Il(document),y={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,queues:new Map,ws:null,pollTimer:0,renderQueued:!1},Le=[],ye=!0,Hi=200,_i=Hi,Tl=!1,Fi=0;function Tn(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function O(e,t){let n=await fetch(e,{...t,headers:{"content-type":"application/json",Authorization:`Bearer ${Tn()}`,...t?.headers||{}}}),i=await n.text(),s=i?JSON.parse(i):null;if(!n.ok)throw new Error(s&&s.error||`HTTP ${n.status}`);return s}function g(e,t,n){let i=document.createElement(e);return t&&(i.className=t),n!==void 0&&(i.textContent=n),i}function Ni(e){return e==="running"?"var(--panel-success)":e==="waiting_approval"||e==="waiting_input"?"#e0a23c":e==="failed"?"var(--panel-danger, #e5534b)":e==="completed"?"var(--panel-accent)":"var(--panel-muted)"}function De(){An||(An=requestAnimationFrame(()=>{An=0,Al()}))}var An=0,Pt="";function Al(){let e=document.getElementById("bots-view");if(!e)return;let t=window.visualViewport,n=window.matchMedia("(max-width: 640px)").matches,i=document.querySelector(".sidebar")?.classList.contains("open")===!0;if(y.activeId&&t&&n&&!i){let s=document.querySelector(".fixed-header"),a=s?Math.round(s.getBoundingClientRect().height):0,l=Math.round(t.offsetTop)+a,r=Math.round(t.offsetLeft),o=Math.round(t.width),c=Math.max(120,Math.round(t.height)-a),d=`fixed|${l}|${r}|${o}|${c}`;if(d===Pt)return;Pt=d,e.style.position="fixed",e.style.top=`${l}px`,e.style.left=`${r}px`,e.style.width=`${o}px`,e.style.height=`${c}px`,e.style.right="auto",e.style.bottom="auto"}else{if(Pt==="")return;Pt="",e.style.position="",e.style.top="",e.style.left="",e.style.width="",e.style.height="",e.style.right="",e.style.bottom=""}}window.visualViewport?.addEventListener("resize",De),window.visualViewport?.addEventListener("scroll",De),window.addEventListener("resize",De),document.addEventListener("click",De);var ji=document.querySelector(".sidebar");ji&&new MutationObserver(De).observe(ji,{attributes:!0,attributeFilter:["class"]}),window.__syncBotsViewport=De;function Dt(){let e=y.approvals.length,t=document.getElementById("bots-inbox-badge");t&&(t.style.display=e?"inline-block":"none",t.textContent=String(e));let n=document.getElementById("bv-inbox-count");n&&(n.textContent=e?`(${e})`:""),window.__botsSnapshot=y.bots,window.__refreshSidebar?.()}function Ml(){let e=document.getElementById("set-bot-templates"),t=document.getElementById("set-bot-new"),n=document.getElementById("set-bot-inbox"),i=()=>{document.getElementById("settings-popover")?.classList.remove("open"),document.getElementById("settings-backdrop")?.classList.remove("open")};e?.addEventListener("click",()=>{i(),ft()}),t?.addEventListener("click",()=>{i(),Jl()}),n?.addEventListener("click",()=>{i(),Nn()})}function zl(){let e=g("div","bots-view");e.id="bots-view",e.hidden=!0;let t=g("div","bots-view-head"),n=g("div","bv-title"),i=g("span","bots-dot");i.id="bv-dot";let s=g("span","bv-title-text");s.id="bv-title";let a=g("span","bv-status");a.id="bv-status",n.append(i,s,a);let l=g("div","bv-actions"),r=g("div","bv-mode"),o=g("button","bv-mode-btn");o.id="bv-mode-btn",o.type="button",o.setAttribute("aria-haspopup","menu"),o.setAttribute("aria-expanded","false"),Qi(o,"supervised");let c=g("div","bv-menu bv-mode-menu");c.id="bv-mode-menu",c.setAttribute("role","menu"),c.hidden=!0;for(let[E,R,Z]of[["supervised","\u9ED8\u8BA4","\u53EA\u8BFB\u5DE5\u5177\uFF08read/grep/find/ls\uFF09\u76F4\u63A5\u653E\u884C\uFF1Bbash\u3001edit\u3001write\u3001\u6269\u5C55/MCP \u5DE5\u5177\u4F1A\u95EE\u4F60"],["parent-supervised","\u76D1\u7BA1","\u5176\u4F59\u5DE5\u5177\u4EA4\u7ED9\u4E0A\u7EA7 bot \u51B3\u5B9A\uFF08\u5E26\u7406\u7531\uFF09\uFF1B\u4F60\u4ECD\u7136\u80FD\u770B\u5230\u5E76\u56DE\u7B54\uFF0C\u5148\u7B54\u5148\u5F97\uFF1B\u6CA1\u6709\u4E0A\u7EA7\u65F6\u56DE\u843D\u5230\u9ED8\u8BA4"],["full-access","\u5168\u653E\u884C","\u6240\u6709\u5DE5\u5177\u76F4\u63A5\u6267\u884C\uFF0C\u4E0D\u518D\u8BE2\u95EE\u3002\u6CE8\u610F\u8FD9\u4E0D\u662F\u6C99\u7BB1"]]){let oe=g("button","bv-menu-item");oe.dataset.mode=E,oe.setAttribute("role","menuitemradio"),oe.innerHTML=`<span class="bv-menu-icon">${re(Ki[E],'width="15" height="15"')}</span><span class="bv-menu-text"><b>${R}</b><span>${Z}</span></span><span class="bv-menu-check">${re("check",'width="13" height="13"')}</span>`,oe.onclick=()=>{d(!1),Dl(E)},c.appendChild(oe)}let d=E=>{E&&T(!1),c.hidden=!E,o.setAttribute("aria-expanded",E?"true":"false")};o.onclick=E=>{E.stopPropagation(),d(c.hidden)},r.append(o);let v=g("button","btn bv-inbox");v.id="bv-inbox",v.title="Requests waiting for you";let h=g("span",void 0,"Needs you"),p=g("span","bv-inbox-count");p.id="bv-inbox-count",v.append(h,p),v.onclick=()=>void Nn();let f=g("button","bv-icon-btn");f.id="bv-more-btn",f.type="button",f.title="More actions",f.setAttribute("aria-label","More actions"),f.setAttribute("aria-haspopup","menu"),f.setAttribute("aria-expanded","false"),f.innerHTML=re("dots",'width="16" height="16"');let m=g("div","bv-menu");m.id="bv-more-menu",m.setAttribute("role","menu"),m.hidden=!0;let k=(E,R,Z,oe)=>{let J=g("button",`bv-menu-item${E?` ${E}`:""}`);return J.type="button",J.setAttribute("role","menuitem"),J.innerHTML=`<span class="bv-menu-icon">${re(R,'width="15" height="15"')}</span><span class="bv-menu-text"><b>${Z}</b></span>`,J.onclick=()=>{T(!1),oe()},J},w=k("","check","Allow all",()=>{if(!y.activeId)return;let E=y.approvals.filter(R=>R.botId===y.activeId);Promise.all(E.map(R=>O(`/api/bots/${R.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:R.id,allow:!0})}))).finally(()=>void he(!0))});w.id="bv-allow-all",w.title="Approve every pending request for this bot";let L=k("","refresh","Resume bot",()=>Ji(E=>O(`/api/bots/${E}/resume`,{method:"POST"}).then(()=>he(!0)))),M=k("","stop","Stop run",()=>Ji(E=>O(`/api/bots/${E}/stop`,{method:"POST"}).then(()=>he(!0)))),$=k("danger","delete","Delete bot",()=>{y.activeId&&confirm("Delete this bot and its session?")&&O(`/api/bots/${y.activeId}`,{method:"DELETE"}).then(()=>{Rn(),he(!0)})});m.append(w,L,M,g("div","bv-menu-sep"),$);let T=E=>{E&&d(!1),m.hidden=!E,f.setAttribute("aria-expanded",E?"true":"false")};f.onclick=E=>{E.stopPropagation(),T(m.hidden)},document.addEventListener("click",E=>{let R=E.target;R&&(!r.contains(R)&&!c.contains(R)&&d(!1),!f.contains(R)&&!m.contains(R)&&T(!1))}),l.append(r,v,f),t.append(n,l);let I=g("div","bots-messages");I.id="bots-messages";let B=g("button","bv-jump");B.type="button",B.id="bv-jump",B.innerHTML=`${re("chevron-down",'width="14" height="14"')}<span>Latest</span>`,B.title="Jump to the latest message",B.hidden=!0,B.onclick=()=>{ye=!0,I.scrollTop=I.scrollHeight,B.hidden=!0};let x=()=>{ye=I.scrollHeight-I.scrollTop-I.clientHeight<48,B.hidden=ye};I.addEventListener("scroll",x,{passive:!0}),I.addEventListener("touchmove",()=>{ye=!1,B.hidden=I.scrollHeight-I.clientHeight<1},{passive:!0}),I.addEventListener("wheel",()=>{ye=!1},{passive:!0});let A=g("div","bots-composer-wrap"),z=g("div","bv-queue");z.id="bv-queue",z.hidden=!0;let se=g("span","bv-queue-text"),D=g("button","bv-queue-clear","Clear");D.type="button",D.title="Drop the queued messages",D.onclick=()=>{y.activeId&&O(`/api/bots/${y.activeId}/queue/clear`,{method:"POST"}).then(()=>zn(),E=>$e(E instanceof Error?E.message:String(E)))},z.append(se,D);let Ee=g("div","bv-attach-strip");Ee.id="bv-attach-strip",Ee.hidden=!0;let K=g("div","bv-composer-error");K.id="bv-composer-error",K.hidden=!0;let X=g("div","bv-suggest");X.id="bv-suggest",X.hidden=!0;let Be=g("div","bots-composer"),ae=g("button","bv-attach-btn");ae.type="button",ae.id="bv-attach",ae.title="Attach an image",ae.setAttribute("aria-label","Attach an image"),ae.innerHTML=re("attach",'width="18" height="18"');let q=g("input");q.type="file",q.accept="image/*",q.multiple=!0,q.hidden=!0,ae.onclick=()=>q.click(),q.onchange=()=>{for(let E of Array.from(q.files??[]))Mn(E);q.value=""};let j=g("textarea");j.id="bots-input",j.rows=1,j.placeholder="Message the bot\u2026",j.spellcheck=!1;let ve=window.matchMedia("(pointer: coarse)").matches;ve||(j.enterKeyHint="send"),j.onkeydown=E=>{Rl(E)||E.key!=="Enter"||E.shiftKey||E.isComposing||ve||E.keyCode===229||(E.preventDefault(),Zi())},j.oninput=()=>{$e(null),Ht(j),Wi()},j.onclick=()=>Wi(),j.addEventListener("paste",E=>{let R=Array.from(E.clipboardData?.files??[]).filter(Z=>Z.type.startsWith("image/"));if(R.length!==0){E.preventDefault();for(let Z of R)Mn(Z)}});let le=g("button","btn primary");le.id="bv-send",le.title="Send",le.setAttribute("aria-label","Send"),le.innerHTML='<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>',le.onclick=()=>void Zi(),Be.append(ae,j,le),Be.addEventListener("click",E=>{let R=E.target;R?.closest("button")&&He(),!R?.closest("button")&&document.activeElement!==j&&j.focus()}),A.addEventListener("dragover",E=>{E.dataTransfer&&(E.preventDefault(),A.classList.add("drop-target"))}),A.addEventListener("dragleave",()=>A.classList.remove("drop-target")),A.addEventListener("drop",E=>{E.preventDefault(),A.classList.remove("drop-target");let R=Array.from(E.dataTransfer?.files??[]).filter(Z=>Z.type.startsWith("image/"));for(let Z of R)Mn(Z)}),A.append(z,Ee,X,K,q,Be),e.append(t,I,B,A,c,m),document.querySelector(".main-area")?.appendChild(e),document.getElementById("bots-modal")||Ul()}function $e(e){let t=document.getElementById("bv-composer-error");t&&(t.textContent=e??"",t.hidden=!e)}function qi(e){let t=document.getElementById("bv-send");t&&(t.disabled=e,t.setAttribute("aria-busy",e?"true":"false"),t.title=e?"Sending\u2026":"Send")}var Ie=[],Oi=4,Bl=4*1024*1024;function Ht(e){e.style.height="auto";let t=window.matchMedia("(max-width: 640px)").matches?132:160;e.style.height=`${Math.min(t,e.scrollHeight)}px`}function _t(){let e=document.getElementById("bv-attach-strip");e&&(e.textContent="",e.hidden=Ie.length===0,Ie.forEach((t,n)=>{let i=g("span","bv-attach-chip"),s=g("img");s.src=t.preview,s.alt=t.name;let a=g("button","bv-attach-remove","\xD7");a.type="button",a.title=`Remove ${t.name}`,a.setAttribute("aria-label",`Remove ${t.name}`),a.onclick=()=>{Ie.splice(n,1),_t()},i.append(s,a),e.appendChild(i)}))}async function Mn(e){if(!e.type.startsWith("image/")){$e("Only image attachments are supported.");return}if(Ie.length>=Oi){$e(`At most ${Oi} images per message.`);return}if(e.size>Bl){$e("Images must be smaller than 4 MB.");return}let t=await new Promise((i,s)=>{let a=new FileReader;a.onload=()=>i(String(a.result??"")),a.onerror=()=>s(new Error("could not read the image")),a.readAsDataURL(e)}),n=t.indexOf(",");Ie.push({data:t.slice(n+1),mimeType:e.type,name:e.name||"image",preview:t}),$e(null),_t()}function zn(){let e=document.getElementById("bv-queue");if(!e)return;let t=y.activeId?y.queues.get(y.activeId):void 0,n=t?.steering.length??0,i=t?.followUp.length??0;if(n+i===0){e.hidden=!0;return}let s=[];n&&s.push(`${n} steering`),i&&s.push(`${i} follow-up`),e.hidden=!1;let a=e.querySelector(".bv-queue-text");a&&(a.textContent=`Queued \xB7 ${s.join(" \xB7 ")}`)}var Te=[],Qe=0,Ft=null;function He(){let e=document.getElementById("bv-suggest");e&&(e.hidden=!0),Te=[],Ft=null}function Bn(){let e=document.getElementById("bv-suggest");if(e){if(e.textContent="",Te.length===0){e.hidden=!0;return}e.hidden=!1,Te.forEach((t,n)=>{let i=g("button",`bv-suggest-item${n===Qe?" active":""}`);i.type="button",i.innerHTML=`<span class="bv-suggest-kind">${t.kind==="file"?"@":"/"}</span><span class="bv-suggest-label">${Vi(t.label)}</span><span class="bv-suggest-detail">${Vi(t.detail)}</span>`,i.onmousedown=s=>s.preventDefault(),i.onclick=()=>Ui(n),e.appendChild(i)})}}function Vi(e){return e.replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t])}async function Wi(){let e=document.getElementById("bots-input");if(!e)return;let t=e.selectionStart??e.value.length,n=e.value.slice(0,t),i=/(^|\s)([/@])([^\s]*)$/.exec(n);if(!i){He();return}let s=i[2],a=i[3];if(Ft={start:t-a.length-1,end:t},s==="/"){let d=y.catalog,v=(d?.prompts??[]).map(p=>({kind:"prompt",label:`/${p.name}`,detail:"prompt template",value:`/${p.name} `})),h=(d?.skills??[]).map(p=>({kind:"skill",label:`/skill:${p.name}`,detail:p.description||"skill",value:`/skill:${p.name} `}));Te=[...v,...h].filter(p=>p.label.toLowerCase().includes(a.toLowerCase())||p.detail.toLowerCase().includes(a.toLowerCase())).slice(0,8),Qe=0,Bn();return}let l=Nt();if(!l){He();return}let r=a.lastIndexOf("/"),o=r>=0?`${l.projectPath}/${a.slice(0,r)}`:l.projectPath,c=r>=0?a.slice(r+1):a;try{Te=((await O(`/api/fs/list?path=${encodeURIComponent(o)}`)).entries??[]).filter(d=>d.name.toLowerCase().startsWith(c.toLowerCase())).slice(0,8).map(d=>{let v=r>=0?a.slice(0,r+1):"";return{kind:"file",label:`@${v}${d.name}${d.type==="dir"?"/":""}`,detail:d.type==="dir"?"directory":"file",value:`@${v}${d.name}${d.type==="dir"?"/":" "}`}}),Qe=0,Bn()}catch{He()}}function Ui(e){let t=document.getElementById("bots-input"),n=Te[e];if(!t||!n||!Ft)return;let{start:i,end:s}=Ft;t.value=`${t.value.slice(0,i)}${n.value}${t.value.slice(s)}`;let a=i+n.value.length;He(),t.focus(),t.setSelectionRange(a,a),Ht(t)}function Rl(e){let t=document.getElementById("bv-suggest");if(!t||t.hidden||Te.length===0)return!1;if(e.key==="ArrowDown"||e.key==="ArrowUp"){e.preventDefault();let n=e.key==="ArrowDown"?1:-1;return Qe=(Qe+n+Te.length)%Te.length,Bn(),!0}return e.key==="Enter"||e.key==="Tab"?(e.preventDefault(),Ui(Qe),!0):e.key==="Escape"?(e.preventDefault(),He(),!0):!1}async function Zi(){let e=document.getElementById("bots-input");if(!e||!y.activeId||Tl||!e.value.trim()&&Ie.length===0)return;let t=y.activeId,n=e.value.trim()?e.value:"See the attached image",i=Ie.map(({data:s,mimeType:a})=>({data:s,mimeType:a}));$e(null),qi(!0);try{await O(`/api/bots/${t}/input`,{method:"POST",body:JSON.stringify({text:n,images:i.length?i:void 0})}),e.value===n&&(e.value="",Ht(e)),He(),Ie.length=0,_t(),ye=!0}catch(s){$e(s instanceof Error?s.message:String(s))}finally{qi(!1)}}function Ji(e){y.activeId&&e(y.activeId).catch(t=>Oe({kind:"notice",level:"error",text:t instanceof Error?t.message:String(t)}))}function Rn(){y.activeId=null,Le=[],ye=!0,De();let e=document.getElementById("bots-view");e&&(e.hidden=!0);try{y.ws?.close()}catch{}y.ws=null,Dt();let t=document.getElementById("terminal-container"),n=document.getElementById("main-placeholder"),i=!!document.querySelector(".session-item.active:not(.bot-item)");t&&i?(t.style.display="",n&&(n.style.display="none")):n&&(n.style.display="")}async function Yi(e){y.activeId=e,Le=[],ye=!0,Ie.length=0,_t(),zn(),He();let t=document.getElementById("bots-input");t&&(t.value="",Ht(t)),$e(null);let n=document.getElementById("bv-jump");n&&(n.hidden=!0),window.__collapseSidebar?.(),De(),y.items.set(e,[]);let i=document.getElementById("bots-view");i&&(i.hidden=!1);let s=document.getElementById("main-placeholder");s&&(s.style.display="none");let a=document.getElementById("terminal-container");a&&(a.style.display="none");let l=document.getElementById("file-editor");l&&(l.style.display="none"),Dt(),jt();try{y.ws?.close()}catch{}let r=location.protocol==="https:"?"wss:":"ws:",o=new WebSocket(`${r}//${location.host}/ws/bots/${encodeURIComponent(e)}?token=${encodeURIComponent(Tn())}`);y.ws=o,o.onmessage=c=>{try{Gi(JSON.parse(String(c.data)))}catch{}},o.onclose=()=>{y.activeId===e&&setTimeout(()=>{y.activeId===e&&he(!0)},1500)},await he(!0)}function Nt(){return y.bots.find(e=>e.id===y.activeId)||null}function Pn(){let e=Nt();if(!e)return;let t=document.getElementById("bv-title"),n=document.getElementById("bv-status"),i=document.getElementById("bv-dot");t&&(t.textContent=e.title),n&&(n.textContent=Pl[e.status]??e.status.replace(/_/g," "),n.dataset.status=e.status,n.style.color=Ni(e.status),n.title=`${e.status.replace(/_/g," ")} \xB7 ${e.templateId} \xB7 ${e.projectPath}`);let s=document.getElementById("bv-mode-btn");s&&Qi(s,e.runtimeMode||"supervised");for(let r of document.querySelectorAll("#bv-mode-menu button")){let o=r.dataset.mode===e.runtimeMode;r.classList.toggle("active",o),r.setAttribute("aria-checked",o?"true":"false")}let a=document.getElementById("bv-allow-all"),l=y.approvals.filter(r=>r.botId===e.id).length;if(a){a.hidden=l===0;let r=a.querySelector(".bv-menu-text b");r&&(r.textContent=`Allow all (${l})`)}i&&(i.style.background=Ni(e.status))}var Pl={queued:"queued",starting:"starting",running:"running",waiting_input:"waiting",waiting_approval:"approval",completed:"done",failed:"failed",cancelled:"stopped",stale:"stale"},Xi={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"},Ki={supervised:"shield","parent-supervised":"shield-up","full-access":"shield-alert"};function Qi(e,t){let n=Ki[t]??"shield";e.dataset.mode=t,e.innerHTML=re(n,'width="15" height="15"');let i=`\u5BA1\u6279\u6A21\u5F0F\uFF1A${Xi[t]??t}`;e.title=`${i}\uFF08\u70B9\u5F00\u53EF\u5207\u6362\uFF09`,e.setAttribute("aria-label",i)}async function Dl(e){if(y.activeId)try{await O(`/api/bots/${y.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:e})});let t=Nt();t&&(t.runtimeMode=e),Pn(),Oe({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${Xi[e]||e}`})}catch(t){Oe({kind:"notice",level:"error",text:t instanceof Error?t.message:String(t)})}}function Oe(e,t=y.activeId){if(!t)return;let n=y.items.get(t)||[];n.push(e),y.items.set(t,n),t===y.activeId&&Ve()}function Ve(){if(y.renderQueued)return;y.renderQueued=!0;let e=Math.max(0,60-(performance.now()-Fi));window.setTimeout(()=>{y.renderQueued=!1,Fi=performance.now(),jt()},e)}function Dn(e){switch(e.kind){case"assistant":return{text:e.text,thinking:e.thinking};case"tool":return{phase:e.phase,output:e.output,error:e.isError,durationMs:e.durationMs};case"approval":return{decided:e.decided,approvalState:e.approval.state};default:return{}}}function Hl(e,t){return e.text!==t.text||e.thinking!==t.thinking||e.phase!==t.phase||e.output!==t.output||e.error!==t.error||e.durationMs!==t.durationMs||e.decided!==t.decided||e.approvalState!==t.approvalState}function Hn(e){if(e.kind==="user"){let t=g("div","bv-msg bv-user");return t.appendChild(In(e.text)),t}if(e.kind==="assistant"){let t=g("div","bv-msg bv-assistant");if(e.thinking){let i=g("details","bv-thinking");i.appendChild(g("summary",void 0,"thinking")),i.appendChild(g("div",void 0,e.thinking)),t.appendChild(i)}let n=g("div","bv-text");return n.appendChild(In(e.text)),t.appendChild(n),t}return e.kind==="tool"?Nl(e):e.kind==="approval"?jl(e):g("div",`bv-notice bv-notice-${e.level}`,e.text)}function _l(e,t){let n=e.querySelector("details.bv-thinking");if(t.thinking)if(n){let s=n.querySelector("div");s&&s.textContent!==t.thinking&&(s.textContent=t.thinking)}else{let s=g("details","bv-thinking");s.appendChild(g("summary",void 0,"thinking")),s.appendChild(g("div",void 0,t.thinking)),e.prepend(s)}else n&&n.remove();let i=e.querySelector(".bv-text");i&&i.replaceChildren(In(t.text))}function jt(){let e=document.getElementById("bots-messages");if(!e||!y.activeId||document.getElementById("bots-view")?.hidden)return;let t=y.items.get(y.activeId)||[],n=Math.max(0,t.length-_i),i=n?t.slice(n):t,s=ye;if(i.length<Le.length||i.some((a,l)=>Le[l]?.item!==a))e.textContent="",Le=i.map(a=>{let l=Hn(a);return e.appendChild(l),{item:a,snapshot:Dn(a),node:l}});else{for(let a=Le.length;a<i.length;a++){let l=i[a],r=Hn(l);e.appendChild(r),Le.push({item:l,snapshot:Dn(l),node:r})}for(let a=0;a<i.length;a++){let l=i[a],r=Le[a],o=Dn(l);if(Hl(r.snapshot,o)){if(l.kind==="assistant")_l(r.node,l);else{let c=Hn(l);r.node.replaceWith(c),r.node=c}r.snapshot=o}}}Fl(e,n),s&&(e.scrollTop=e.scrollHeight)}function Fl(e,t){let n=e.querySelector(":scope > .bv-earlier");if(t===0){n?.remove();return}let i=`Show earlier messages (${t})`;if(n){n.textContent!==i&&(n.textContent=i);return}let s=g("button","bv-earlier",i);s.type="button",s.onclick=()=>{let a=e.scrollHeight,l=e.scrollTop;_i+=Hi,Le=[],jt(),e.scrollTop=l+(e.scrollHeight-a)},e.prepend(s)}function Nl(e){let t=g("details","bv-tool");t.open=e.phase!=="end"||!!e.isError;let n=g("summary"),i=g("span","bv-tool-name",e.name);if(n.appendChild(i),e.phase!=="end"&&n.appendChild(g("span","bv-tool-phase",e.phase)),e.isError&&n.appendChild(g("span","bv-tool-error","error")),typeof e.durationMs=="number"&&n.appendChild(g("span","bv-tool-meta",`${Math.round(e.durationMs)}ms`)),t.appendChild(n),e.args!==void 0){let s=g("pre","bv-pre");s.textContent=typeof e.args=="string"?e.args:JSON.stringify(e.args,null,2),t.appendChild(s)}if(e.output){let s=g("pre","bv-pre bv-output");s.textContent=e.output,t.appendChild(s)}return t}function jl(e){let t=g("div","bv-approval"),n=e.approval;if(t.appendChild(g("div","bv-approval-tag","Needs approval")),t.appendChild(g("div","bv-approval-title",n.title)),n.message){let h=g("pre","bv-pre bv-approval-detail");h.textContent=n.message,t.appendChild(h)}if(e.decided)return t.appendChild(g("div","bv-approval-decided",e.decided==="allowed"?"Allowed":"Denied")),t;let i=g("input","bv-reason");i.placeholder="reason (optional)",i.setAttribute("aria-label","Reason (optional)");let s=g("div","bv-approval-actions"),a=g("button","btn primary","Allow once"),l=/^Allow (.+?)\?$/.exec(n.title)?.[1],r=n.method==="confirm"?l&&l.length<=24?`Always allow ${l}`:"Always allow this tool":"Allow for this session",o=g("button","btn",r);o.hidden=n.method!=="confirm";let c=g("button","btn danger","Deny"),d=[a,o,c],v=async(h,p,f)=>{let m=f.textContent??"";for(let k of d)k.disabled=!0;f.textContent=h?"Allowing\u2026":"Denying\u2026";try{await O(`/api/bots/${n.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:n.id,allow:h,always:p,reason:i.value||void 0})}),e.decided=h?"allowed":"denied",Ve(),he(!0)}catch(k){for(let w of d)w.disabled=!1;f.textContent=m,Oe({kind:"notice",level:"error",text:k instanceof Error?k.message:String(k)})}};return a.onclick=()=>void v(!0,!1,a),o.onclick=()=>void v(!0,!0,o),c.onclick=()=>void v(!1,!1,c),s.append(i,a,o,c),t.appendChild(s),t}function Gi(e){let t=String(e.type||""),n=y.activeId;if(!n)return;let i=y.items.get(n)||[];if(t==="snapshot")y.items.set(n,[]);else if(t==="queue")y.queues.set(n,{steering:Array.isArray(e.steering)?e.steering:[],followUp:Array.isArray(e.followUp)?e.followUp:[]}),zn();else if(t==="user")ye=!0,Oe({kind:"user",text:String(e.text||"")});else if(t==="status"){let s=Nt();s&&(s.status=String(e.status||s.status)),Pn(),Vl()}else if(t==="message"){let s=e.message;if(!s||String(s.role||"")!=="assistant")return;let a=ql(s),l=Ol(s),r=i[i.length-1];r&&r.kind==="assistant"?(r.text=a||r.text,r.thinking=l||r.thinking):i.push({kind:"assistant",text:a,thinking:l}),y.items.set(n,i),Ve()}else if(t==="delta"){let s=String(e.kind||""),a=String(e.delta||""),l=i[i.length-1];(!l||l.kind!=="assistant")&&(i.push({kind:"assistant",text:"",thinking:""}),l=i[i.length-1]),l.kind==="assistant"&&(s==="text"?l.text+=a:s==="thinking"&&(l.thinking+=a)),y.items.set(n,i),Ve()}else if(t==="tool"){let s=String(e.callId||""),a=i.find(r=>r.kind==="tool"&&r.callId===s),l=String(e.phase||"start");a?(a.phase=l,l==="update"&&e.output&&(a.output=String(e.output)),l==="end"&&(e.output&&(a.output=String(e.output)),a.isError=e.isError===!0,typeof e.durationMs=="number"&&(a.durationMs=e.durationMs))):i.push({kind:"tool",callId:s,name:String(e.name||"tool"),args:e.args,output:e.output?String(e.output):void 0,isError:e.isError===!0,durationMs:typeof e.durationMs=="number"?e.durationMs:void 0,phase:l}),y.items.set(n,i),Ve()}else if(t==="approval"){let s=e.approval;if(!s)return;let a=i;for(let l=a.length-1;l>=0;l--){let r=a[l];if(r.kind==="approval"&&r.approval.id===s.id){r.approval=s,s.state!=="pending"&&(r.decided=s.state==="allowed"?"allowed":"denied"),y.items.set(n,a),Ve();return}}a.push({kind:"approval",approval:s}),y.items.set(n,a),Ve()}else t==="notice"&&Oe({kind:"notice",level:String(e.level||"info"),text:String(e.text||"")})}function ql(e){let t=e.content;return Array.isArray(t)?t.map(n=>n&&typeof n=="object"&&n.type==="text"?String(n.text||""):"").join(""):String(e.text||"")}function Ol(e){let t=e.content;return Array.isArray(t)?t.map(n=>n&&typeof n=="object"&&n.type==="thinking"?String(n.thinking||""):"").join(""):""}async function he(e=!1){try{let[t,n]=await Promise.all([O("/api/bots"),O("/api/bots/approvals")]);if(y.bots=t,y.approvals=n,Dt(),Pn(),e&&y.activeId){let i=await O(`/api/bots/${y.activeId}/events?limit=300`);Wl(i)}}catch{}}async function Vl(){try{y.bots=await O("/api/bots"),Dt()}catch{}}function Wl(e){if(y.activeId){y.items.set(y.activeId,[]);for(let t of e)Gi(t);jt()}}function Ul(){let e=g("div","bots-modal");e.id="bots-modal",e.hidden=!0;let t=g("div","bots-modal-card"),n=g("div","bots-modal-head"),i=g("span");i.id="bots-modal-title";let s=g("button","btn");s.innerHTML=re("close",'width="14" height="14"'),s.title="Close",s.onclick=()=>qt(),n.append(i,s);let a=g("div","bots-modal-body");a.id="bots-modal-body",t.append(n,a),e.appendChild(t),e.onclick=l=>{l.target===e&&qt()},document.body.appendChild(e)}function _n(e){let t=document.getElementById("bots-modal"),n=document.getElementById("bots-modal-title"),i=document.getElementById("bots-modal-body");if(!t||!i)throw new Error("modal missing");return n&&(n.textContent=e),i.textContent="",t.hidden=!1,i}function qt(){let e=document.getElementById("bots-modal");e&&(e.hidden=!0)}async function Zl(){return y.catalog||(y.catalog=await O("/api/bots/catalog")),y.catalog}async function es(){return y.templates=await O("/api/bots/templates"),y.templates}async function ft(){let e=_n("Bot templates"),[t,n]=await Promise.all([Zl(),es()]),i=g("div","bv-template-list");for(let o of n){let c=g("div","bv-template-row");c.appendChild(g("span","bv-template-name",o.manifest.name)),c.appendChild(g("span","bv-template-desc",o.manifest.description||""));let d=g("button","btn","Edit");d.onclick=()=>ts(e,t,o);let v=g("button","btn","Copy");v.title="Duplicate this template",v.onclick=()=>{let f=JSON.parse(JSON.stringify(o.manifest));f.name=`${o.manifest.name} copy`,O("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:f})}).then(()=>ft()).catch(m=>alert(m instanceof Error?m.message:String(m)))};let h=g("button","btn danger","Delete");h.onclick=()=>{confirm(`Delete template ${o.manifest.name}?`)&&O(`/api/bots/templates/${o.id}`,{method:"DELETE"}).then(()=>ft())};let p=g("span","bv-template-actions");p.append(d,v,h),c.appendChild(p),i.appendChild(c)}n.length===0&&i.appendChild(g("div","bots-empty","No templates yet")),e.appendChild(i);let s=g("div","bv-template-actions"),a=g("button","btn primary","New template");a.onclick=()=>ts(e,t,null);let l=g("button","btn","Export");l.title="Download templates + library as JSON",l.onclick=()=>{(async()=>{try{let o=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${Tn()}`}});if(!o.ok)throw new Error(`HTTP ${o.status}`);let c=await o.blob(),d=document.createElement("a");d.href=URL.createObjectURL(c),d.download=`tmux-weblink-bots-${new Date().toISOString().slice(0,10)}.json`,d.click(),setTimeout(()=>URL.revokeObjectURL(d.href),2e3)}catch(o){alert(o instanceof Error?o.message:String(o))}})()};let r=g("button","btn","Import");r.title="Restore templates from a JSON bundle",r.onclick=()=>{let o=document.createElement("input");o.type="file",o.accept="application/json,.json",o.onchange=()=>{let c=o.files?.[0];c&&(async()=>{try{let d=JSON.parse(await c.text()),v=await O("/api/bots/import",{method:"POST",body:JSON.stringify(d)});alert(`Imported ${v.templates} templates, ${v.files} library files (${v.skipped} kept)`),await ft()}catch(d){alert(d instanceof Error?d.message:String(d))}})()},o.click()},s.append(a,l,r),e.appendChild(s)}function Fn(e,t,n){let i=g("div","bv-field");i.appendChild(g("label","bv-label",e));let s=g("div","bv-check-grid"),a=[];for(let l of t){let r=g("label","bv-check"),o=document.createElement("input");o.type="checkbox",o.checked=n.includes(l.id),r.append(o,g("span",void 0,l.label)),l.hint&&(r.title=l.hint),s.appendChild(r),a.push({id:l.id,input:o})}return i.appendChild(s),{element:i,get:()=>a.filter(l=>l.input.checked).map(l=>l.id)}}function ts(e,t,n){e.textContent="";let i=n?JSON.parse(JSON.stringify(n.manifest)):{name:"new-bot",description:""},s=g("input","bv-input");s.value=i.name,s.placeholder="Template name";let a=g("input","bv-input");a.value=i.description||"",a.placeholder="One line description";let l=g("textarea","bv-textarea");l.rows=6,l.value=i.system||"",l.placeholder="System prompt for this bot (written to SYSTEM.md)";let r=Fn("Skills",t.skills.map(x=>({id:x.id,label:x.name,hint:x.description})),i.skills||[]),o=Fn("Extensions (Pi builtins + library)",t.extensions.map(x=>({id:x.id,label:`${x.name}${x.kind==="builtin"?" (builtin)":""}`,hint:x.description})),(i.extensions||[]).map(x=>x.replace(/^.*\//,"").replace(/\.(js|ts)$/,""))),c=Fn("Prompt templates",t.prompts.map(x=>({id:x.id,label:x.name})),i.prompts||[]),d=g("select","bv-input");d.appendChild(new Option("none",""));for(let x of t.mcp)d.appendChild(new Option(x.name,x.id));i.mcp&&(d.value=t.mcp.find(x=>JSON.stringify(x.servers)===JSON.stringify(i.mcp?.mcpServers))?.id||"");let v=g("div","bv-field");v.appendChild(g("label","bv-label","Tools (allow list; deny always blocks)"));let h=g("div","bv-check-grid"),p=[];for(let x of t.tools){let A=g("label","bv-check"),z=document.createElement("input");z.type="checkbox",z.checked=(i.tools?.allow||[]).includes(x.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(x.name),A.append(z,g("span",void 0,x.name)),h.appendChild(A),p.push({name:x.name,input:z})}v.appendChild(h);let f=g("input","bv-input");f.value=(i.tools?.deny||[]).join(", "),f.placeholder="Always deny (comma separated), e.g. bash, write";let m=g("textarea","bv-textarea");m.rows=2,m.value=(i.packages||[]).join(`
90
+ `),m.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";let k=g("select","bv-input");k.appendChild(new Option("default (Pi settings)",""));for(let x of t.models)k.appendChild(new Option(`${x.provider}/${x.model}`,`${x.provider}
91
+ ${x.model}`));i.model?.provider&&i.model?.id&&(k.value=`${i.model.provider}
92
+ ${i.model.id}`);let w=g("select","bv-input");for(let x of["","off","minimal","low","medium","high","xhigh","max"])w.appendChild(new Option(x||"default",x));i.model?.thinking&&(w.value=i.model.thinking);let L=g("select","bv-input");for(let x of["supervised","auto-accept-edits","full-access"])L.appendChild(new Option(x,x));L.value=i.permissions?.runtimeMode||"supervised";let M=g("select","bv-input");M.appendChild(new Option("ignore project .pi (recommended)","ignore")),M.appendChild(new Option("inherit project .pi (needs trust)","inherit")),M.value=i.projectResources||"ignore";let $=g("label","bv-check"),T=document.createElement("input");T.type="checkbox",T.checked=!!i.orchestrator,$.append(T,g("span",void 0,"Super bot: gets orchestration tools (create/stop/status child bots)"));let I=(x,A)=>{let z=g("div","bv-field");return z.appendChild(g("label","bv-label",x)),z.appendChild(A),z};e.append(I("Name",s),I("Description",a),I("System prompt",l),r.element,o.element,c.element,I("MCP preset",d),v,I("Always deny tools",f),I("Packages",m),I("Model",k),I("Thinking level",w),I("Approval mode",L),I("Project resources",M),$);let B=g("button","btn primary",n?"Save template":"Create template");B.onclick=async()=>{let[x,A]=k.value.split(`
93
+ `),z=t.mcp.find(D=>D.id===d.value),se={name:s.value.trim()||"bot",description:a.value.trim()||void 0,system:l.value.trim()||void 0,skills:r.get(),extensions:o.get().map(D=>(D.startsWith("builtin:"),D)),prompts:c.get(),packages:m.value.split(`
94
+ `).map(D=>D.trim()).filter(Boolean),mcp:z?{mcpServers:z.servers}:void 0,tools:{allow:p.filter(D=>D.input.checked).map(D=>D.name),deny:f.value.split(",").map(D=>D.trim()).filter(Boolean)},model:x?{provider:x,id:A,thinking:w.value||void 0}:void 0,permissions:{runtimeMode:L.value},projectResources:M.value==="inherit"?"inherit":"ignore",orchestrator:T.checked||void 0};try{await O("/api/bots/templates",{method:"POST",body:JSON.stringify({id:n?.id,manifest:se})}),qt(),await ft()}catch(D){alert(D instanceof Error?D.message:String(D))}},e.appendChild(B)}async function Jl(){return ns("")}async function ns(e){let t=_n("New bot"),n=await es();if(n.length===0){t.appendChild(g("div","bots-empty","No templates yet \u2014 create one with \u201CNew template\u201D."));return}let i=g("select","bv-input");for(let c of n)i.appendChild(new Option(c.manifest.name,c.id));let s=g("input","bv-input");s.placeholder="Title (defaults to template name)";let a=g("input","bv-input");a.placeholder="/path/to/project";let l=e||y.bots[0]?.projectPath||"";a.value=l;let r=g("select","bv-input");r.appendChild(new Option("shared \u2014 run in the project folder","shared")),r.appendChild(new Option("worktree \u2014 isolated git worktree","worktree")),t.append(Ot("Template",i),Ot("Title",s),Ot("Project path",a),Ot("Workspace",r));let o=g("button","btn primary","Create bot");o.onclick=async()=>{try{let c=await O("/api/bots",{method:"POST",body:JSON.stringify({templateId:i.value,title:s.value.trim()||void 0,projectPath:a.value.trim()||void 0,isolation:r.value})});qt(),await he(!0),await Yi(c.id)}catch(c){alert(c instanceof Error?c.message:String(c))}},t.appendChild(o)}function Ot(e,t){let n=g("div","bv-field");return n.appendChild(g("label","bv-label",e)),n.appendChild(t),n}async function Nn(){let e=_n("Needs you");if(y.approvals=await O("/api/bots/approvals"),y.approvals.length===0){e.appendChild(g("div","bots-empty","Nothing waiting."));return}for(let t of y.approvals){let n=g("div","bv-approval");if(n.appendChild(g("div","bv-approval-tag",t.botTitle)),n.appendChild(g("div","bv-approval-title",t.title)),t.message){let c=g("pre","bv-pre bv-approval-detail");c.textContent=t.message,n.appendChild(c)}let i=g("input","bv-reason");i.placeholder="reason (optional)",i.setAttribute("aria-label","Reason (optional)");let s=g("div","bv-approval-actions"),a=g("button","btn primary","Allow once"),l=g("button","btn danger","Deny"),r=[a,l],o=async(c,d)=>{let v=d.textContent??"";for(let h of r)h.disabled=!0;d.textContent=c?"Allowing\u2026":"Denying\u2026";try{await O(`/api/bots/${t.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:t.id,allow:c,reason:i.value||void 0})}),await he(!0),await Nn()}catch(h){for(let p of r)p.disabled=!1;d.textContent=v,Oe({kind:"notice",level:"error",text:h instanceof Error?h.message:String(h)})}};a.onclick=()=>void o(!0,a),l.onclick=()=>void o(!1,l),s.append(i,a,l),n.appendChild(s),e.appendChild(n)}}function Yl(){window.__botsInited||(window.__botsInited=!0,zl(),Ml(),window.__openBot=Yi,document.addEventListener("click",e=>{let t=e.target;t&&(t.closest(".session-item.bot-item")||t.closest(".session-item")&&y.activeId&&setTimeout(()=>Rn(),0))},!0),document.addEventListener("click",e=>{let t=e.target;!t||!y.activeId||(t.closest("#mode-files")||t.closest(".file-tree-item")||t.closest(".file-roots-list li"))&&Rn()}),he(!0),y.pollTimer=window.setInterval(()=>{document.hidden||he()},6e3),window.addEventListener("beforeunload",()=>window.clearInterval(y.pollTimer)))}var Vt=null;function is(e){return e.replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t])}function Wt(){Vt?.dispose(),Vt=null}function Xl(e){let t=Vt?.anchor===e.anchor;Wt(),!t&&Kl(e)}function Kl(e){let{anchor:t,items:n}=e,i=document.createElement("div");i.className="bv-menu overlay-menu",i.setAttribute("role","menu"),e.label&&i.setAttribute("aria-label",e.label);let s=[];for(let o of n){let c=document.createElement("button");c.type="button",c.className=`bv-menu-item${o.danger?" danger":""}`,c.setAttribute("role","menuitem"),c.disabled=o.disabled===!0,c.innerHTML=`<span class="bv-menu-icon">${re(o.icon,'width="15" height="15"')}</span><span class="bv-menu-text"><b>${is(o.label)}</b>${o.detail?`<span>${is(o.detail)}</span>`:""}</span>`,c.addEventListener("click",()=>{c.disabled||(Wt(),o.onSelect?.())}),i.appendChild(c),c.disabled||s.push(c)}let a=window.matchMedia("(max-width: 640px)").matches;if(document.body.appendChild(i),!a){i.classList.add("anchored");let o=t.getBoundingClientRect(),c=i.offsetWidth||260,d=i.offsetHeight||0,v=Math.min(Math.max(8,o.left),window.innerWidth-c-8),h=window.innerHeight-o.bottom>d+24?o.bottom+6:Math.max(8,o.top-d-6);i.style.left=`${Math.round(v)}px`,i.style.top=`${Math.round(h)}px`}t.setAttribute("aria-expanded","true"),s[0]?.focus();let l=o=>{if(o.key==="Escape"){o.stopPropagation(),Wt(),t.focus();return}if(o.key!=="ArrowDown"&&o.key!=="ArrowUp")return;o.preventDefault();let c=s.indexOf(document.activeElement),d=o.key==="ArrowDown"?1:-1;s[(c+d+s.length)%s.length]?.focus()},r=o=>{let c=o.target;c&&(i.contains(c)||t.contains(c))||Wt()};document.addEventListener("keydown",l,!0),document.addEventListener("pointerdown",r,!0),Vt={anchor:t,dispose:()=>{document.removeEventListener("keydown",l,!0),document.removeEventListener("pointerdown",r,!0),i.remove(),t.setAttribute("aria-expanded","false")}}}var mt=window.__TMUX_WEB_SHELL__,V=null,U=null,gt=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null,ne=gt;window.__tmuxWebScopeAgent=gt;var jn="sessions",Ae="",Ut="",Zt="",ss="";function G(e){return ne?"/a/"+encodeURIComponent(ne)+e:e}var _=document.getElementById("sidebar-content"),We=document.getElementById("main-placeholder"),ce=document.getElementById("terminal-container"),bt=document.getElementById("file-editor"),Ql=document.getElementById("fe-path"),fe=document.getElementById("fe-status"),vt=document.getElementById("fe-content"),Ue=document.getElementById("fe-save"),Gl=document.getElementById("fe-delete"),er=document.getElementById("fe-back"),as=document.getElementById("fe-new-name"),tr=document.getElementById("fe-new-btn"),qn=document.getElementById("settings-backdrop"),ls=document.getElementById("settings-popover"),rs=document.querySelector(".sidebar"),os="tmux-web-force-narrow";function Jt(){try{return localStorage.getItem(os)==="1"}catch{return!1}}function cs(){document.documentElement.classList.toggle("force-narrow",Jt()),Jt()&&On()&&Ze()}function On(){return Jt()?!0:window.matchMedia("(max-width: 640px)").matches}function ds(e){rs.classList.toggle("open",e),document.getElementById("sidebar-backdrop")?.classList.toggle("open",e)}function Ze(){On()&&ds(!1)}function ps(){ds(!0)}document.getElementById("sidebar-backdrop")?.addEventListener("click",()=>Ze()),window.addEventListener("keydown",e=>{e.key==="Escape"&&On()&&rs.classList.contains("open")&&(e.stopPropagation(),Ze())}),window.__collapseSidebar=Ze,document.getElementById("mode-sessions").addEventListener("click",()=>{ps(),us("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{ps(),us("files")});function us(e){jn=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"?(Vn="",Me()):br()}var Vn="";async function Me(){if(jn!=="sessions")return;try{let t=await(await fetch("/api/sidebar/sessions")).json(),n=(window.__botsSnapshot||[]).map(s=>[s.id,s.title,s.status,s.projectPath]),i=JSON.stringify({recent:t.recent,agents:t.agents,tombstones:t.tombstones,bots:n});if(i===Vn)return;Vn=i,or(t)}catch{_.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")}),Kn()}var hs="tmux-web-sidebar-group-collapsed";function fs(){try{return new Set(JSON.parse(localStorage.getItem(hs)||"[]"))}catch{return new Set}}function nr(e){try{localStorage.setItem(hs,JSON.stringify([...e]))}catch{}}function ir(e,t,n){if(!e)return"\u2026";let i=n&&(e===n||e.startsWith(n+"/"))?"~"+e.slice(n.length):e,s=i.split("/").filter(Boolean);if(s.length===0)return e;for(let a=1;a<=s.length;a++){let l=s.slice(-a).join("/");if(!t.some(r=>!r||r===e?!1:(n&&(r===n||r.startsWith(n+"/"))?"~"+r.slice(n.length):r).split("/").filter(Boolean).slice(-a).join("/")===l))return l}return i}var sr={running:"var(--panel-success)",waiting_approval:"#e0a23c",waiting_input:"#e0a23c",queued:"var(--panel-accent)",starting:"var(--panel-accent)",failed:"var(--panel-danger, #e5534b)"};function ar(e){let t=document.createElement("div");return t.className="session-item bot-item",t.setAttribute("data-bot-id",e.id),t.dataset.status=e.status,t.title=`Bot \xB7 ${e.status.replace(/_/g," ")} \xB7 ${e.projectPath}`,t.style.setProperty("--bot-status",sr[e.status]??"var(--panel-muted)"),t.innerHTML=`${re("bot",'class="bot-icon"')}<span>${F(e.title)}</span>`,t.addEventListener("click",n=>{n.stopPropagation(),window.__openBot?.(e.id)}),t}function ms(e,t,n,i=!0){let s=new Map;for(let c of e){let d=c.path||"";s.has(d)||s.set(d,[]),s.get(d).push(c)}let a=n?[]:window.__botsSnapshot||[],l=new Map;for(let c of a)s.has(c.projectPath)||s.set(c.projectPath,[]),l.has(c.projectPath)||l.set(c.projectPath,[]),l.get(c.projectPath).push(c);let r=[...s.keys()],o=fs();for(let[c,d]of s){let v=ir(c,r,t),h=o.has(c),p=document.createElement("div");if(p.className="session-group-header"+(h?" collapsed":""),p.title=c||"No working directory",p.innerHTML=`<span class="sg-folder">&#128193;</span><span class="sg-label">${F(v)}</span>`,c){let m=document.createElement("button");m.className="sg-add-btn",m.innerHTML=re("add",'width="14" height="14"');let k=t&&c.startsWith(t)?`~${c.slice(t.length)}`:c;m.title=`New session or bot in ${k}`,m.setAttribute("aria-label",`New session or bot in ${k}`),m.setAttribute("aria-haspopup","menu"),m.setAttribute("aria-expanded","false"),m.addEventListener("click",w=>{w.stopPropagation(),Xl({anchor:m,label:`Add to ${k}`,items:[{icon:"terminal",label:"New tmux session",detail:`in ${k}`,onSelect:()=>window.__openNewSessionModal?.(c)},{icon:"agents",label:"New bot",detail:n?"only for folders on this host":`in ${k}`,disabled:!!n,onSelect:()=>void Un(c)}]})}),p.appendChild(m)}p.addEventListener("click",()=>{let m=fs(),k=p.nextElementSibling;m.has(c)?(m.delete(c),p.classList.remove("collapsed"),k?.classList.remove("collapsed")):(m.add(c),p.classList.add("collapsed"),k?.classList.add("collapsed")),nr(m)});let f=document.createElement("div");f.className="session-group-body"+(h?" collapsed":"");for(let m of d)f.appendChild(n?lr(m,n,i):rr(m));for(let m of l.get(c)||[])f.appendChild(ar(m));_.appendChild(p),_.appendChild(f)}}function lr(e,t,n){let i=document.createElement("div");i.className="session-item"+(e.name===U&&ne===t?" active":"")+(n?"":" session-offline"),i.setAttribute("data-session",e.name),i.setAttribute("data-agent",t),i.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>
95
+ <span>${F(e.name)}</span>${n?"":'<span class="meta">offline</span>'}
96
+ <button class="session-edit-btn" data-session="${F(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&&i.addEventListener("click",a=>{a.target.closest(".session-edit-btn")||kt(e.name,t)});let s=i.querySelector(".session-edit-btn");return s&&s.addEventListener("click",a=>{a.stopPropagation(),an(e.name,s,{agentId:t})}),i}function rr(e){let t=document.createElement("div");t.className="session-item"+(e.name===U&&!ne?" 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>
97
+ <span>${F(e.name)}</span>
98
+ <button class="session-edit-btn" data-session="${F(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>
99
+ `,t.addEventListener("click",i=>{i.target.closest(".session-edit-btn")||kt(e.name)});let n=t.querySelector(".session-edit-btn");return n&&n.addEventListener("click",i=>{i.stopPropagation(),an(e.name,n)}),t}function or(e){_.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"+(gt?" clickable":""),n.textContent=gt?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",gt&&(n.title="Back to hub",n.addEventListener("click",()=>{window.location.href="/"})),_.appendChild(n),ms(t,e.home);let i=e.agents||[];for(let a of i){if(!a.sessions||a.sessions.length===0)continue;let l=a.agentId===ne,r=document.createElement("div");r.className="sidebar-section-label machine-label"+(a.online?"":" agent-offline-label")+(!l&&a.online?" clickable":""),r.textContent=a.agentName+(a.online?"":" (offline)"),!l&&a.online&&(r.title="\u6253\u5F00 "+a.agentName,r.addEventListener("click",()=>{window.location.href="/a/"+encodeURIComponent(a.agentId)+"/"})),_.appendChild(r),ms(a.sessions,e.home,a.agentId,a.online)}let s=e.tombstones||[];if(s.length>0){let a=document.createElement("div");a.className="sidebar-section-label tombstone-label",a.textContent="\u5931\u6548\u4F1A\u8BDD",_.appendChild(a);for(let l of s){let r=document.createElement("div");r.className="session-item session-tombstone",r.setAttribute("data-session",l.name),l.agentId&&r.setAttribute("data-agent",l.agentId);let o=l.agentId?l.agentOnline?" (agent)":" (agent \u79BB\u7EBF)":"";r.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"></svg>
100
+ <span>${F(l.name)}</span><span class="meta">\u5931\u6548${o}</span>
101
+ <button class="session-edit-btn" data-session="${F(l.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>`,r.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",r.addEventListener("click",()=>{an(l.name,r,{tombstone:!0,agentId:l.agentId})});let c=r.querySelector(".session-edit-btn");c&&c.addEventListener("click",d=>{d.stopPropagation(),an(l.name,c,{tombstone:!0,agentId:l.agentId})}),_.appendChild(r)}}}function F(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}async function kt(e,t){if(U===e&&V&&ne===(t||null))return;bt.style.display="none",We.style.display="none",ce.style.display="",ce.classList.add("terminal-pending"),Ze(),V&&(nn(),V.destroy(),V=null),U=e,ne=t||null,window.__tmuxWebScopeAgent=ne,window.__tmuxWebCurrentSession=U,Br(e,t);let n=Xn(e,t);As.set(n,Date.now()+Mr);let i=tt.get(n);if(i&&i.state==="working"){i.state="idle",i.doneUntil=void 0,i.unread=!1;let s=_.querySelector(t?'.session-item[data-agent="'+CSS.escape(t)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])');s&&dn(s,n,i)}for(let s of _.querySelectorAll(".session-item"))s.classList.toggle("active",s.getAttribute("data-session")===e&&(s.getAttribute("data-agent")||null)===ne);try{V=await na(ce,e,{terminal:mt.terminal,scrollback:mt.scrollback,theme:mt.theme,wsBase:ne?"/ws/a/"+encodeURIComponent(ne):mt.wsBase||"/ws"}),Cs()}catch(s){console.error("[shell] terminal init failed:",s);let a=s&&typeof s=="object"&&"message"in s?s.message:String(s);ce.textContent="Failed to open terminal for "+e+": "+a,ce.classList.remove("terminal-pending")}}var Yt=[],Y=null,gs=!1;function cr(e){if(!Y||!Y.files.length)return null;let t=Y.repoRoot;if(!t||!e.startsWith(t))return null;let n=e.slice(t.length+1);for(let i of Y.files)if(i.path===n)return i.status;return null}async function dr(e){gs=!0;try{let t=await fetch(G("/api/git/status?path="+encodeURIComponent(e)));t.ok?Y=await t.json():Y=null}catch{Y=null}finally{gs=!1}}function pr(){if(!Y||!Y.branch)return"";let{branch:e,linesAdded:t,linesRemoved:n}=Y,i=`<div class="sidebar-git"><div class="git-branch-badge">
98
102
  <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>
99
- ${H(t)}</div>`;return(e>0||n>0)&&(i+=`<div class="git-diff-stats">+<span class="add">${e}</span> <span class="del">-${n}</span></div>`),i+"</div>"}D.addEventListener("click",t=>{t.target.closest(".sidebar-git")&&We&&J&&(t.stopPropagation(),ts())});var ht=document.getElementById("header-git"),Ki=document.getElementById("git-diff-view"),Qi=document.getElementById("gd-path"),Ht=document.getElementById("gd-status"),_t=document.getElementById("gd-content"),Al=document.getElementById("gd-back"),We=null;function mt(t){if(!t||!t.branch){ht.style.display="none",We=null;return}We=t.repoRoot;let{branch:e,linesAdded:n,linesRemoved:i}=t,s=`<span class="branch">${H(e)}</span>`;(n>0||i>0)&&(s+=`<span class="sep">\xB7</span>+<span class="diff-add">${n}</span> <span class="diff-del">-${i}</span>`),ht.innerHTML=s,ht.style.display="block"}ht.addEventListener("click",t=>{We&&J&&(t.stopPropagation(),ts())});var te=document.getElementById("git-popover"),Ft=document.getElementById("git-popover-backdrop");function zn(){let t=ht.getBoundingClientRect();te.style.top=t.bottom+4+"px",te.style.left=Math.max(8,Math.min(t.left,window.innerWidth-400))+"px"}function Gi(){let t=We,e=document.getElementById("git-popover-browse");e&&e.addEventListener("click",()=>{if(Ot(),t){$n="files",document.querySelectorAll(".mode-btn").forEach(i=>i.classList.remove("active"));let n=document.getElementById("mode-files");n&&n.classList.add("active"),xe(t)}})}var es="";function ts(){if(!J)return;let t=J.files||[];if(!t.length)te.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
100
- <div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>`;else{let e=`<div class="git-popover-header">${t.length} file${t.length>1?"s":""} changed</div>`;for(let n=0;n<t.length;n++){let i=t[n],s=i.additions||0,l=i.deletions||0,a="";switch(i.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}e+=`<div class="git-popover-item" data-idx="${n}">
101
- ${a}<span class="file-path">${H(i.path)}</span>
103
+ ${F(e)}</div>`;return(t>0||n>0)&&(i+=`<div class="git-diff-stats">+<span class="add">${t}</span> <span class="del">-${n}</span></div>`),i+"</div>"}_.addEventListener("click",e=>{e.target.closest(".sidebar-git")&&Ge&&Y&&(e.stopPropagation(),ys())});var wt=document.getElementById("header-git"),bs=document.getElementById("git-diff-view"),vs=document.getElementById("gd-path"),Xt=document.getElementById("gd-status"),Kt=document.getElementById("gd-content"),ur=document.getElementById("gd-back"),Ge=null;function yt(e){if(!e||!e.branch){wt.style.display="none",Ge=null;return}Ge=e.repoRoot;let{branch:t,linesAdded:n,linesRemoved:i}=e,s=`<span class="branch">${F(t)}</span>`;(n>0||i>0)&&(s+=`<span class="sep">\xB7</span>+<span class="diff-add">${n}</span> <span class="diff-del">-${i}</span>`),wt.innerHTML=s,wt.style.display="block"}wt.addEventListener("click",e=>{Ge&&Y&&(e.stopPropagation(),ys())});var ie=document.getElementById("git-popover"),Qt=document.getElementById("git-popover-backdrop");function Wn(){let e=wt.getBoundingClientRect();ie.style.top=e.bottom+4+"px",ie.style.left=Math.max(8,Math.min(e.left,window.innerWidth-400))+"px"}function ks(){let e=Ge,t=document.getElementById("git-popover-browse");t&&t.addEventListener("click",()=>{if(en(),e){jn="files",document.querySelectorAll(".mode-btn").forEach(i=>i.classList.remove("active"));let n=document.getElementById("mode-files");n&&n.classList.add("active"),ze(e)}})}var ws="";function ys(){if(!Y)return;let e=Y.files||[];if(!e.length)ie.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
104
+ <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 i=e[n],s=i.additions||0,a=i.deletions||0,l="";switch(i.status){case"M":l='<span class="git-file-status M">M</span>';break;case"A":l='<span class="git-file-status A">A</span>';break;case"D":l='<span class="git-file-status D">D</span>';break;case"?":l='<span class="git-file-status ?">?</span>';break;case"R":l='<span class="git-file-status R">R</span>';break}t+=`<div class="git-popover-item" data-idx="${n}">
105
+ ${l}<span class="file-path">${F(i.path)}</span>
102
106
  <span class="file-add">${s>0?"+"+s:""}</span>
103
- <span class="file-del">${l>0?"-"+l:""}</span>
104
- </div>`}e+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',es=e,te.innerHTML=e,te.querySelectorAll(".git-popover-item").forEach(n=>{let i=parseInt(n.dataset.idx||"0",10),s=t[i];!s||s.status==="D"||(n.classList.add("clickable"),n.style.cursor="pointer",n.addEventListener("click",()=>is(s.path)))})}zn(),te.classList.add("open"),Ft.classList.add("open"),Gi()}function zl(){return window.innerWidth>=1024}function ns(t,e){let n=(t+(e&&t?`
105
- `:"")+e).split(`
106
- `),i="",s=0,l=0;for(let a of n){let r=a;if(r.startsWith("@@")){let o=r.match(/@@\s+-(\d+)[^+]*\+(\d+)/);o&&(s=parseInt(o[1],10)-1,l=parseInt(o[2],10)-1),i+=`<div class="diff-line hunk"><span class="ln-body">${H(r)}</span></div>`;continue}if(r.startsWith("diff --git")||r.startsWith("index ")||r.startsWith("--- ")||r.startsWith("+++ ")||r.startsWith("new file")||r.startsWith("deleted file")){r.startsWith("diff --git")&&(i+=`<div class="diff-line header"><span class="ln-body">${H(r)}</span></div>`);continue}if(r.startsWith("+"))l++,i+=`<div class="diff-line add"><span class="ln-no">${l}</span><span class="ln-body">${H(r)}</span></div>`;else if(r.startsWith("-"))s++,i+=`<div class="diff-line del"><span class="ln-no">${s}</span><span class="ln-body">${H(r)}</span></div>`;else if(r.startsWith("\\"))i+=`<div class="diff-line"><span class="ln-body">${H(r)}</span></div>`;else{if(!r&&!s&&!l)continue;s++,l++,i+=`<div class="diff-line"><span class="ln-no">${s}</span><span class="ln-no" style="margin-right:12px">${l}</span><span class="ln-body">${H(r)}</span></div>`}}return{html:i,lineCount:n.length}}var Nt=null;async function is(t){let e=We;if(e)if(Ot(),zl()){ie.style.display="none",N&&(jt(),N.destroy(),N=null,Nt=V,V=null),mt(null),ct.style.display="none",He.style.display="none",Ki.style.display="flex",Qi.textContent=t,Ht.textContent="Loading\u2026",_t.innerHTML="";try{let n=await fetch(K("/api/git/diff?path="+encodeURIComponent(e)+"&file="+encodeURIComponent(t)));if(!n.ok)throw new Error(await n.text());let i=await n.json();Bl(t,i.diff,i.stagedDiff)}catch(n){let i=n instanceof Error?n.message:String(n);Ht.textContent="Error",_t.innerHTML=`<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">Error: ${H(i)}</div>`}}else{te.innerHTML=`<div class="git-diff-view"><div class="diff-header">
107
+ <span class="file-del">${a>0?"-"+a:""}</span>
108
+ </div>`}t+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',ws=t,ie.innerHTML=t,ie.querySelectorAll(".git-popover-item").forEach(n=>{let i=parseInt(n.dataset.idx||"0",10),s=e[i];!s||s.status==="D"||(n.classList.add("clickable"),n.style.cursor="pointer",n.addEventListener("click",()=>Es(s.path)))})}Wn(),ie.classList.add("open"),Qt.classList.add("open"),ks()}function hr(){return window.innerWidth>=1024}function xs(e,t){let n=(e+(t&&e?`
109
+ `:"")+t).split(`
110
+ `),i="",s=0,a=0;for(let l of n){let r=l;if(r.startsWith("@@")){let o=r.match(/@@\s+-(\d+)[^+]*\+(\d+)/);o&&(s=parseInt(o[1],10)-1,a=parseInt(o[2],10)-1),i+=`<div class="diff-line hunk"><span class="ln-body">${F(r)}</span></div>`;continue}if(r.startsWith("diff --git")||r.startsWith("index ")||r.startsWith("--- ")||r.startsWith("+++ ")||r.startsWith("new file")||r.startsWith("deleted file")){r.startsWith("diff --git")&&(i+=`<div class="diff-line header"><span class="ln-body">${F(r)}</span></div>`);continue}if(r.startsWith("+"))a++,i+=`<div class="diff-line add"><span class="ln-no">${a}</span><span class="ln-body">${F(r)}</span></div>`;else if(r.startsWith("-"))s++,i+=`<div class="diff-line del"><span class="ln-no">${s}</span><span class="ln-body">${F(r)}</span></div>`;else if(r.startsWith("\\"))i+=`<div class="diff-line"><span class="ln-body">${F(r)}</span></div>`;else{if(!r&&!s&&!a)continue;s++,a++,i+=`<div class="diff-line"><span class="ln-no">${s}</span><span class="ln-no" style="margin-right:12px">${a}</span><span class="ln-body">${F(r)}</span></div>`}}return{html:i,lineCount:n.length}}var Gt=null;async function Es(e){let t=Ge;if(t)if(en(),hr()){ce.style.display="none",V&&(nn(),V.destroy(),V=null,Gt=U,U=null),yt(null),bt.style.display="none",We.style.display="none",bs.style.display="flex",vs.textContent=e,Xt.textContent="Loading\u2026",Kt.innerHTML="";try{let n=await fetch(G("/api/git/diff?path="+encodeURIComponent(t)+"&file="+encodeURIComponent(e)));if(!n.ok)throw new Error(await n.text());let i=await n.json();mr(e,i.diff,i.stagedDiff)}catch(n){let i=n instanceof Error?n.message:String(n);Xt.textContent="Error",Kt.innerHTML=`<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">Error: ${F(i)}</div>`}}else{ie.innerHTML=`<div class="git-diff-view"><div class="diff-header">
107
111
  <button class="diff-back">\u2190 Back</button>
108
- <span class="diff-filename">${H(t)}</span>
112
+ <span class="diff-filename">${F(e)}</span>
109
113
  <span class="diff-loading">Loading\u2026</span>
110
- </div></div>`,zn(),te.classList.add("open"),Ft.classList.add("open");try{let n=await fetch(K("/api/git/diff?path="+encodeURIComponent(e)+"&file="+encodeURIComponent(t)));if(!n.ok)throw new Error(await n.text());let i=await n.json();Ml(t,i.diff,i.stagedDiff)}catch(n){let i=n instanceof Error?n.message:String(n);te.innerHTML=`<div class="git-diff-view"><div class="diff-header">
114
+ </div></div>`,Wn(),ie.classList.add("open"),Qt.classList.add("open");try{let n=await fetch(G("/api/git/diff?path="+encodeURIComponent(t)+"&file="+encodeURIComponent(e)));if(!n.ok)throw new Error(await n.text());let i=await n.json();fr(e,i.diff,i.stagedDiff)}catch(n){let i=n instanceof Error?n.message:String(n);ie.innerHTML=`<div class="git-diff-view"><div class="diff-header">
111
115
  <button class="diff-back">\u2190 Back</button>
112
- <span class="diff-filename">${H(t)}</span>
113
- </div><div class="diff-empty">Error loading diff: ${H(i)}</div></div>`}}}function Ml(t,e,n){if(!e&&!n){te.innerHTML=`<div class="git-diff-view"><div class="diff-header">
116
+ <span class="diff-filename">${F(e)}</span>
117
+ </div><div class="diff-empty">Error loading diff: ${F(i)}</div></div>`}}}function fr(e,t,n){if(!t&&!n){ie.innerHTML=`<div class="git-diff-view"><div class="diff-header">
114
118
  <button class="diff-back">\u2190 Back</button>
115
- <span class="diff-filename">${H(t)}</span>
116
- </div><div class="diff-empty">No diff content available</div></div>`;return}let{html:i,lineCount:s}=ns(e,n);te.innerHTML=`<div class="git-diff-view"><div class="diff-header">
119
+ <span class="diff-filename">${F(e)}</span>
120
+ </div><div class="diff-empty">No diff content available</div></div>`;return}let{html:i,lineCount:s}=xs(t,n);ie.innerHTML=`<div class="git-diff-view"><div class="diff-header">
117
121
  <button class="diff-back">\u2190 Back</button>
118
- <span class="diff-filename">${H(t)}</span>
122
+ <span class="diff-filename">${F(e)}</span>
119
123
  <span class="diff-filesize">${s} lines</span>
120
- </div><div class="diff-content">${i}</div></div>`,te.querySelector(".diff-back")?.addEventListener("click",()=>{te.innerHTML=es,zn(),J&&te.querySelectorAll(".git-popover-item").forEach(l=>{let a=parseInt(l.dataset.idx||"0",10),r=J.files[a];!r||r.status==="D"||(l.style.cursor="pointer",l.addEventListener("click",()=>is(r.path)))}),Gi()})}function Bl(t,e,n){if(!e&&!n){Ht.textContent="No diff",_t.innerHTML='<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">No diff content available</div>';return}let{html:i,lineCount:s}=ns(e,n);Qi.textContent=t,Ht.textContent=s+" lines",_t.innerHTML=i}function Rl(){Ki.style.display="none",Nt?(ie.style.display="",ie.classList.add("terminal-pending"),ut(Nt),Nt=null):V?(ie.style.display="",ie.classList.add("terminal-pending"),as()):He.style.display="flex"}Al.addEventListener("click",Rl);function Ot(){te.classList.remove("open"),Ft.classList.remove("open")}Ft.addEventListener("click",Ot),document.addEventListener("keydown",t=>{t.key==="Escape"&&(Ot(),Yt())});async function ss(t){try{let e=await(await fetch("/api/fs/session-path?session="+encodeURIComponent(t))).json();if(e.path){let n=await fetch("/api/git/status?path="+encodeURIComponent(e.path));if(n.ok){let i=await n.json();J=i,mt(i);return}}}catch{}J=null,mt(null)}var qt=null;function as(){jt(),V&&(ss(V),qt=setInterval(()=>{V&&ss(V)},3e4))}function jt(){qt&&(clearInterval(qt),qt=null)}async function Mn(t){let e=t;if(e.startsWith("~"))try{let n=await(await fetch(K("/api/fs/list?path="+encodeURIComponent(e)))).json();typeof n.path=="string"&&n.path&&(e=n.path)}catch{}e=e.replace(/\/+$/,"")||"/",Hi(e)}function ls(t,e){let n=document.createElement("button");n.className="file-tree-bot-btn",n.innerHTML=ae("add",'width="12" height="12"'),n.title=`Create bot in ${e}`,n.setAttribute("aria-label",`Create bot in ${e}`),n.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),Mn(e)}),t.appendChild(n)}function Pl(){if(Dt=rt.fsRoots||[],Dt.length===0){if(V){Dl(V);return}xe("");return}D.innerHTML="";for(let t of Dt){let e=document.createElement("div");e.className="file-tree-item",e.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${H(t)}`,e.addEventListener("click",()=>xe(t)),ls(e,t),D.appendChild(e)}}async function Dl(t){D.innerHTML='<div class="file-tree-empty">Loading...</div>';try{let e=await(await fetch(K("/api/fs/session-path?session="+encodeURIComponent(t)))).json();e.path?xe(e.path):D.innerHTML='<div class="file-tree-info">Could not determine session directory.</div>'}catch{D.innerHTML='<div class="file-tree-error">Failed to get session directory</div>'}}async function xe(t){we=t,D.innerHTML='<div class="file-tree-empty">Loading...</div>';let e=$l(t);try{let n=await(await fetch(K("/api/fs/list?path="+encodeURIComponent(t)))).json(),i=typeof n.path=="string"&&n.path?n.path:t;if(i&&(we=i),await e,D.innerHTML="",i){let a=document.createElement("div");a.className="file-tree-item file-tree-create-bot",a.innerHTML=`<span class="file-tree-bot-plus">${ae("add",'width="11" height="11"')}</span> Create bot in this folder`,a.title=`Create bot in ${i}`,a.addEventListener("click",()=>void Mn(i)),D.appendChild(a)}mt(J),D.innerHTML+=Il();let s=Hl(i||t);if(s&&!Dt.some(a=>i===a)){let a=document.createElement("div");a.className="file-tree-item",a.innerHTML="..",a.addEventListener("click",()=>xe(s)),D.appendChild(a)}if(n.dirs)for(let a of n.dirs){let r=a.split("/").pop()||a.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(r)}`,o.addEventListener("click",()=>xe(a)),ls(o,a),D.appendChild(o)}else D.innerHTML="";let l=n.files||[];for(let a of l){let r=a.split("/").pop()||a.split("\\").pop(),o=Tl(a),c="",d="";if(o)switch(o){case"M":c="git-mod",d='<span class="git-file-status M">M</span>';break;case"A":c="git-add",d='<span class="git-file-status A">A</span>';break;case"D":c="git-del",d='<span class="git-file-status D">D</span>';break;case"?":c="git-untracked",d='<span class="git-file-status ?">?</span>';break;case"R":c="git-mod",d='<span class="git-file-status R">R</span>';break}let m=document.createElement("div");m.className="file-tree-item file"+(c?" "+c:""),m.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${d}${H(r)}`,m.addEventListener("click",()=>_l(a)),D.appendChild(m)}}catch{D.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function Hl(t){let e=t.lastIndexOf("/");return e<=0?null:t.substring(0,e)}async function _l(t){Bt=t,ie.style.display="none",N&&(jt(),N.destroy(),N=null,V=null),mt(null),pt(),He.style.display="none",ct.style.display="flex",vl.textContent=t,ce.textContent="Loading...",_e.style.display="none";try{let e=await fetch(K("/api/file?path="+encodeURIComponent(t)));if(!e.ok){let i=await e.json();ce.textContent=i.error||"Failed to load",dt.value="";return}let n=await e.json();dt.value=n.content,Rt=n.content,_i=n.content,ce.textContent=n.size+" bytes",_e.style.display=""}catch{ce.textContent="Failed to load",dt.value=""}}dt.addEventListener("input",()=>{Rt=dt.value}),_e.addEventListener("click",async()=>{_e.textContent="Saving...",_e.disabled=!0;try{let t=await fetch(K("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Bt,content:Rt})});if(!t.ok){let e=await t.json();ce.textContent=e.error||"Save failed";return}_i=Rt,ce.textContent="Saved"}catch{ce.textContent="Save failed"}finally{_e.disabled=!1,_e.textContent="Save"}}),bl.addEventListener("click",async()=>{if(confirm("Delete "+Bt+"?"))try{let t=await fetch(K("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Bt})});if(!t.ok){let e=await t.json();ce.textContent=e.error||"Delete failed";return}ct.style.display="none",He.style.display="flex",we&&xe(we)}catch{ce.textContent="Delete failed"}}),kl.addEventListener("click",()=>{ct.style.display="none",He.style.display="flex",we&&xe(we)}),wl.addEventListener("click",async()=>{let t=Fi.value.trim();if(!t)return;let e=we+"/"+t;try{let n=await fetch(K("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})});if(!n.ok){let i=await n.json();ce.textContent=i.error||"Create failed";return}Fi.value="",we&&xe(we)}catch{ce.textContent="Create failed"}});var Vt=document.getElementById("force-narrow-toggle");Vt&&(Vt.checked=Pt(),Vt.addEventListener("change",()=>{try{localStorage.setItem(qi,Vt.checked?"1":"0")}catch{}ji(),ye()})),ji(),document.getElementById("mode-settings").addEventListener("click",()=>{let t=Ni.classList.toggle("open");In.classList.toggle("open",t)}),In.addEventListener("click",()=>{Ni.classList.remove("open"),In.classList.remove("open")});var se="",de=!1,pe,ft=document.createElement("div");ft.className="session-popover-backdrop",document.body.appendChild(ft);var ue=document.createElement("div");ue.id="session-popover",ue.className="session-popover",ue.style.display="none",ue.innerHTML=`<div class="sp-field">
124
+ </div><div class="diff-content">${i}</div></div>`,ie.querySelector(".diff-back")?.addEventListener("click",()=>{ie.innerHTML=ws,Wn(),Y&&ie.querySelectorAll(".git-popover-item").forEach(a=>{let l=parseInt(a.dataset.idx||"0",10),r=Y.files[l];!r||r.status==="D"||(a.style.cursor="pointer",a.addEventListener("click",()=>Es(r.path)))}),ks()})}function mr(e,t,n){if(!t&&!n){Xt.textContent="No diff",Kt.innerHTML='<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">No diff content available</div>';return}let{html:i,lineCount:s}=xs(t,n);vs.textContent=e,Xt.textContent=s+" lines",Kt.innerHTML=i}function gr(){bs.style.display="none",Gt?(ce.style.display="",ce.classList.add("terminal-pending"),kt(Gt),Gt=null):U?(ce.style.display="",ce.classList.add("terminal-pending"),Cs()):We.style.display="flex"}ur.addEventListener("click",gr);function en(){ie.classList.remove("open"),Qt.classList.remove("open")}Qt.addEventListener("click",en),document.addEventListener("keydown",e=>{e.key==="Escape"&&(en(),cn())});async function Ss(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 i=await n.json();Y=i,yt(i);return}}}catch{}Y=null,yt(null)}var tn=null;function Cs(){nn(),U&&(Ss(U),tn=setInterval(()=>{U&&Ss(U)},3e4))}function nn(){tn&&(clearInterval(tn),tn=null)}async function Un(e){let t=e;if(t.startsWith("~"))try{let n=await(await fetch(G("/api/fs/list?path="+encodeURIComponent(t)))).json();typeof n.path=="string"&&n.path&&(t=n.path)}catch{}t=t.replace(/\/+$/,"")||"/",ns(t)}function Ls(e,t){let n=document.createElement("button");n.className="file-tree-bot-btn",n.innerHTML=re("add",'width="12" height="12"'),n.title=`Create bot in ${t}`,n.setAttribute("aria-label",`Create bot in ${t}`),n.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),Un(t)}),e.appendChild(n)}function br(){if(Yt=mt.fsRoots||[],Yt.length===0){if(U){vr(U);return}ze("");return}_.innerHTML="";for(let e of Yt){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> ${F(e)}`,t.addEventListener("click",()=>ze(e)),Ls(t,e),_.appendChild(t)}}async function vr(e){_.innerHTML='<div class="file-tree-empty">Loading...</div>';try{let t=await(await fetch(G("/api/fs/session-path?session="+encodeURIComponent(e)))).json();t.path?ze(t.path):_.innerHTML='<div class="file-tree-info">Could not determine session directory.</div>'}catch{_.innerHTML='<div class="file-tree-error">Failed to get session directory</div>'}}async function ze(e){Ae=e,_.innerHTML='<div class="file-tree-empty">Loading...</div>';let t=dr(e);try{let n=await(await fetch(G("/api/fs/list?path="+encodeURIComponent(e)))).json(),i=typeof n.path=="string"&&n.path?n.path:e;if(i&&(Ae=i),await t,_.innerHTML="",i){let l=document.createElement("div");l.className="file-tree-item file-tree-create-bot",l.innerHTML=`<span class="file-tree-bot-plus">${re("add",'width="11" height="11"')}</span> Create bot in this folder`,l.title=`Create bot in ${i}`,l.addEventListener("click",()=>void Un(i)),_.appendChild(l)}yt(Y),_.innerHTML+=pr();let s=kr(i||e);if(s&&!Yt.some(l=>i===l)){let l=document.createElement("div");l.className="file-tree-item",l.innerHTML="..",l.addEventListener("click",()=>ze(s)),_.appendChild(l)}if(n.dirs)for(let l of n.dirs){let r=l.split("/").pop()||l.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> ${F(r)}`,o.addEventListener("click",()=>ze(l)),Ls(o,l),_.appendChild(o)}else _.innerHTML="";let a=n.files||[];for(let l of a){let r=l.split("/").pop()||l.split("\\").pop(),o=cr(l),c="",d="";if(o)switch(o){case"M":c="git-mod",d='<span class="git-file-status M">M</span>';break;case"A":c="git-add",d='<span class="git-file-status A">A</span>';break;case"D":c="git-del",d='<span class="git-file-status D">D</span>';break;case"?":c="git-untracked",d='<span class="git-file-status ?">?</span>';break;case"R":c="git-mod",d='<span class="git-file-status R">R</span>';break}let v=document.createElement("div");v.className="file-tree-item file"+(c?" "+c:""),v.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${d}${F(r)}`,v.addEventListener("click",()=>wr(l)),_.appendChild(v)}}catch{_.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function kr(e){let t=e.lastIndexOf("/");return t<=0?null:e.substring(0,t)}async function wr(e){Ut=e,ce.style.display="none",V&&(nn(),V.destroy(),V=null,U=null),yt(null),Ze(),We.style.display="none",bt.style.display="flex",Ql.textContent=e,fe.textContent="Loading...",Ue.style.display="none";try{let t=await fetch(G("/api/file?path="+encodeURIComponent(e)));if(!t.ok){let i=await t.json();fe.textContent=i.error||"Failed to load",vt.value="";return}let n=await t.json();vt.value=n.content,Zt=n.content,ss=n.content,fe.textContent=n.size+" bytes",Ue.style.display=""}catch{fe.textContent="Failed to load",vt.value=""}}vt.addEventListener("input",()=>{Zt=vt.value}),Ue.addEventListener("click",async()=>{Ue.textContent="Saving...",Ue.disabled=!0;try{let e=await fetch(G("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Ut,content:Zt})});if(!e.ok){let t=await e.json();fe.textContent=t.error||"Save failed";return}ss=Zt,fe.textContent="Saved"}catch{fe.textContent="Save failed"}finally{Ue.disabled=!1,Ue.textContent="Save"}}),Gl.addEventListener("click",async()=>{if(confirm("Delete "+Ut+"?"))try{let e=await fetch(G("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Ut})});if(!e.ok){let t=await e.json();fe.textContent=t.error||"Delete failed";return}bt.style.display="none",We.style.display="flex",Ae&&ze(Ae)}catch{fe.textContent="Delete failed"}}),er.addEventListener("click",()=>{bt.style.display="none",We.style.display="flex",Ae&&ze(Ae)}),tr.addEventListener("click",async()=>{let e=as.value.trim();if(!e)return;let t=Ae+"/"+e;try{let n=await fetch(G("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!n.ok){let i=await n.json();fe.textContent=i.error||"Create failed";return}as.value="",Ae&&ze(Ae)}catch{fe.textContent="Create failed"}});var sn=document.getElementById("force-narrow-toggle");sn&&(sn.checked=Jt(),sn.addEventListener("change",()=>{try{localStorage.setItem(os,sn.checked?"1":"0")}catch{}cs(),Me()})),cs(),document.getElementById("mode-settings").addEventListener("click",()=>{let e=ls.classList.toggle("open");qn.classList.toggle("open",e)}),qn.addEventListener("click",()=>{ls.classList.remove("open"),qn.classList.remove("open")});var de="",me=!1,ge,xt=document.createElement("div");xt.className="session-popover-backdrop",document.body.appendChild(xt);var be=document.createElement("div");be.id="session-popover",be.className="session-popover",be.style.display="none",be.innerHTML=`<div class="sp-field">
121
125
  <label>Rename session</label>
122
126
  <input type="text" id="sp-name" />
123
127
  </div>
@@ -127,5 +131,5 @@ ${i.model.id}`);let y=g("select","bv-input");for(let x of["","off","minimal","lo
127
131
  <button class="btn danger sp-delete" id="sp-delete">Delete</button>
128
132
  </div>
129
133
  <hr class="sp-divider" id="sp-divider" />
130
- <button class="btn primary" id="sp-rebuild" style="display:none">\u91CD\u5EFA\u540C\u540D\u540C\u8DEF\u5F84 session</button>`,document.body.appendChild(ue);function Fl(t){let e=t.getBoundingClientRect(),n=window.innerHeight,i=ue.offsetHeight||240,s=e.bottom+4;s+i>n-8&&(s=Math.max(8,e.top-i-4)),ue.style.top=s+"px",ue.style.left=Math.max(8,Math.min(e.left,window.innerWidth-240))+"px"}function Wt(t,e,n){se=t,de=!!n?.tombstone,pe=n?.agentId;let i=document.getElementById("sp-name");i.value=t;let s=ue.querySelector(".sp-field label");s.textContent=de?"\u91CD\u547D\u540D (\u4EC5\u8BB0\u5F55\uFF0C\u4E0D\u91CD\u5EFA)":"Rename session";let l=document.getElementById("sp-rebuild");l.style.display=de?"":"none";let a=document.getElementById("sp-delete");a.textContent=de?"\u5220\u9664\u8BB0\u5F55":"Delete",a.title=de?"\u5220\u9664\u5931\u6548\u8BB0\u5F55\uFF08\u5893\u7891\u6D88\u5931\uFF09":"Delete session";let r=document.getElementById("sp-divider");r&&(r.style.display=de?"":"none");let o=document.getElementById("sp-save");o.textContent=de?"\u91CD\u547D\u540D":"Save",ft.classList.add("open"),ue.style.display="block",Fl(e),setTimeout(()=>i.focus(),50)}function Fe(){ft.classList.remove("open"),ue.style.display="none"}ft.addEventListener("click",Fe),document.getElementById("sp-save").addEventListener("click",async()=>{let t=document.getElementById("sp-name").value.trim();if(!t||t===se){Fe();return}try{let e=de?{oldName:se,newName:t,agentId:pe}:{oldName:se,newName:t,...pe?{agentId:pe}:{}};if(!(await fetch(K(de?"/api/sessions/rename-tombstone":"/api/sessions/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok)return;Fe(),ye(),!de&&V===se&&(pe??null)===ee&&ut(t,pe)}catch{}}),document.getElementById("sp-rebuild").addEventListener("click",async()=>{if(confirm('\u91CD\u5EFA\u4F1A\u8BDD "'+se+'" (\u540C\u540D\u540C\u8DEF\u5F84\uFF0C\u5185\u5BB9\u4E3A\u7A7A)\uFF1F'))try{let t=await fetch(K("/api/sessions/rebuild"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:se,agentId:pe})});if(!t.ok){let e=await t.json();alert(e.error||"\u91CD\u5EFA\u5931\u8D25");return}Fe(),ye()}catch{}}),document.getElementById("sp-delete").addEventListener("click",async()=>{if(de){if(!confirm('\u5220\u9664\u5931\u6548\u8BB0\u5F55 "'+se+'"\uFF1F'))return;try{if(!(await fetch(K("/api/sessions/dismiss"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:se,agentId:pe})})).ok)return;Fe(),ye()}catch{}return}if(confirm('Delete session "'+se+'"?'))try{if(!(await fetch(K("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:se,...pe?{agentId:pe}:{}})})).ok)return;Fe(),V===se&&(pe??null)===ee&&(N&&(N.destroy(),N=null),V=null,ie.style.display="none",He.style.display="flex"),ye()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",Fe);var rs={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"},Ut=document.getElementById("mobile-keys"),Nl=new Set(["up","down","left","right","tab","s-tab","space"]),Ol=400,ql=80,gt=0,Jt=0,Zt=!1;function jl(){gt&&(clearTimeout(gt),gt=0),Jt&&(clearInterval(Jt),Jt=0)}Ut.addEventListener("mousedown",t=>{t.target.closest("button[data-key]")&&t.preventDefault()}),Ut.addEventListener("pointerdown",t=>{let e=t.target.closest("button[data-key]");if(!e)return;let n=e.dataset.key;Nl.has(n)&&(Zt=!1,gt=setTimeout(()=>{gt=0,Zt=!0,Jt=setInterval(()=>{let i=rs[n];i&&N&&N.sendInput(i)},ql)},Ol))});for(let t of["pointerup","pointercancel","pointerleave"])Ut.addEventListener(t,jl);Ut.addEventListener("click",t=>{let e=t.target.closest("button[data-key]");if(!e||!N)return;if(Zt){Zt=!1;return}let n=rs[e.dataset.key];n&&(N.sendInput(n),N.focus())});var ge=document.getElementById("mk-input"),os=document.getElementById("mk-send");function cs(){if(!ge||!N)return;let t=ge.value;t&&(N.sendInput(t+"\r"),ge.value="",ge.rows=1,N.focus())}if(ge&&(ge.addEventListener("input",()=>{ge.rows=1;let t=ge.value.split(`
131
- `).length;ge.rows=Math.min(t,4)}),ge.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),cs())})),os&&os.addEventListener("click",cs),window.visualViewport){let t=document.querySelector(".app-layout"),e=()=>{t&&(t.style.height=window.visualViewport.height+"px"),window.scrollTo(0,0),document.documentElement.scrollTop=0,document.body.scrollTop=0};window.visualViewport.addEventListener("resize",e),window.addEventListener("orientationchange",()=>setTimeout(e,100)),document.addEventListener("touchstart",()=>{(window.scrollY>0||document.documentElement.scrollTop>0)&&window.scrollTo(0,0)},{passive:!0})}var Bn=document.getElementById("process-panel"),vt=document.getElementById("proc-list"),Vl=document.getElementById("proc-close"),Rn=document.getElementById("proc-backdrop"),Wl=document.getElementById("header-ram");function Ul(){vt.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(K("/api/system/processes")).then(t=>t.json()).then(t=>{if(!Array.isArray(t)||!t.length){vt.innerHTML='<div class="proc-empty">No processes</div>';return}let e="";for(let n of t){let i=n.rss,s=i<1048576?(i/1024).toFixed(0)+"K":(i/1048576).toFixed(1)+"M";e+='<div class="proc-row" data-pid="'+n.pid+'"><span class="proc-mem">'+n.mem+'%</span><span class="proc-rss">'+s+'</span><span class="proc-cmd" title="'+H(n.command)+'">'+H(n.command)+'</span><button class="proc-kill" title="Kill PID '+n.pid+'">&times;</button></div>'}vt.innerHTML=e;for(let n of vt.querySelectorAll(".proc-row")){let i=n.querySelector(".proc-kill");i&&i.addEventListener("click",s=>{let l=s.target.closest(".proc-row");!l||!confirm("Kill PID "+l.dataset.pid+"?")||fetch(K("/api/system/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:parseInt(l.dataset.pid,10)})}).then(a=>a.json()).then(a=>{a.ok?l.style.opacity="0.3":alert("Failed: "+(a.error||"unknown"))}).catch(()=>alert("Network error"))})}}).catch(()=>{vt.innerHTML='<div class="proc-empty">Failed to load</div>'})}function Jl(){Bn.classList.add("open"),Rn.classList.add("open"),Ul()}function Yt(){Bn.classList.remove("open"),Rn.classList.remove("open")}Wl.addEventListener("click",t=>{t.stopPropagation(),Bn.classList.contains("open")?Yt():Jl()}),Vl.addEventListener("click",Yt),Rn.addEventListener("click",Yt);var Zl=2e3,bt=null,Pn=null,Ue=new Map,Je=new Map,Yl=5e3,ds=new Map;function Dn(t,e){return(e?"a:"+e+":":"l:")+t}function Xl(t,e,n){let i=Dn(t,e);if(n==="working"){let c=ds.get(i);if(c&&Date.now()<c)return}let s=Je.get(i),l=t===V&&(e??null)===ee,a=n==="idle"&&s?.state==="working";Je.set(i,{session:t,agentId:e,state:n,doneUntil:a?Date.now()+Zl:void 0,unread:a?!l:!1});let r=e?'.session-item[data-agent="'+CSS.escape(e)+'"][data-session="'+CSS.escape(t)+'"]':'.session-item[data-session="'+CSS.escape(t)+'"]:not([data-agent])',o=D.querySelector(r);o&&Xt(o,i,Je.get(i))}function Xt(t,e,n){let i=Ue.get(e);i&&(clearTimeout(i),Ue.delete(e)),t.classList.remove("working","just-done");let s=n.session===V&&(n.agentId??null)===ee;n.state==="working"?t.classList.add("working"):s&&n.doneUntil&&Date.now()<n.doneUntil?(t.classList.add("just-done"),Ue.set(e,setTimeout(()=>{t.classList.remove("just-done"),Ue.delete(e)},Math.max(0,n.doneUntil-Date.now())))):!s&&n.unread&&t.classList.add("just-done")}function Hn(){for(let[t,e]of Je){let n=e.agentId?'.session-item[data-agent="'+CSS.escape(e.agentId)+'"][data-session="'+CSS.escape(e.session)+'"]':'.session-item[data-session="'+CSS.escape(e.session)+'"]:not([data-agent])',i=D.querySelector(n);i&&Xt(i,t,e)}}function Kl(t,e){let n=Dn(t,e),i=Je.get(n);if(!i)return;let s=Ue.get(n);s&&(clearTimeout(s),Ue.delete(n)),i.doneUntil=void 0,i.unread=!1;let l=e?'.session-item[data-agent="'+CSS.escape(e)+'"][data-session="'+CSS.escape(t)+'"]':'.session-item[data-session="'+CSS.escape(t)+'"]:not([data-agent])',a=D.querySelector(l);a&&Xt(a,n,i)}function ps(){if(bt||Pn)return;let t=localStorage.getItem("tmux-web-token"),e=(location.protocol==="https:"?"wss:":"ws:")+"//"+location.host+"/ws/activity";t&&(e+="?token="+encodeURIComponent(t));try{let n=new WebSocket(e);bt=n,n.onmessage=i=>{try{let s=JSON.parse(String(i.data));s&&s.type==="session.activity"&&typeof s.session=="string"&&Xl(s.session,s.agentId||void 0,s.state==="working"?"working":"idle")}catch{}},n.onclose=()=>{bt===n&&(bt=null,Pn=setTimeout(()=>{Pn=null,ps()},5e3))},n.onerror=()=>{try{n.close()}catch{}}}catch{bt=null}}window.__openSession=ut,window.__refreshSidebar=ye,ye(),pt(),Hn(),ps(),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Hn()}),setInterval(()=>{document.visibilityState==="visible"&&ye()},1e4),gl();
134
+ <button class="btn primary" id="sp-rebuild" style="display:none">\u91CD\u5EFA\u540C\u540D\u540C\u8DEF\u5F84 session</button>`,document.body.appendChild(be);function yr(e){let t=e.getBoundingClientRect(),n=window.innerHeight,i=be.offsetHeight||240,s=t.bottom+4;s+i>n-8&&(s=Math.max(8,t.top-i-4)),be.style.top=s+"px",be.style.left=Math.max(8,Math.min(t.left,window.innerWidth-240))+"px"}function an(e,t,n){de=e,me=!!n?.tombstone,ge=n?.agentId;let i=document.getElementById("sp-name");i.value=e;let s=be.querySelector(".sp-field label");s.textContent=me?"\u91CD\u547D\u540D (\u4EC5\u8BB0\u5F55\uFF0C\u4E0D\u91CD\u5EFA)":"Rename session";let a=document.getElementById("sp-rebuild");a.style.display=me?"":"none";let l=document.getElementById("sp-delete");l.textContent=me?"\u5220\u9664\u8BB0\u5F55":"Delete",l.title=me?"\u5220\u9664\u5931\u6548\u8BB0\u5F55\uFF08\u5893\u7891\u6D88\u5931\uFF09":"Delete session";let r=document.getElementById("sp-divider");r&&(r.style.display=me?"":"none");let o=document.getElementById("sp-save");o.textContent=me?"\u91CD\u547D\u540D":"Save",xt.classList.add("open"),be.style.display="block",yr(t),setTimeout(()=>i.focus(),50)}function Je(){xt.classList.remove("open"),be.style.display="none"}xt.addEventListener("click",Je),document.getElementById("sp-save").addEventListener("click",async()=>{let e=document.getElementById("sp-name").value.trim();if(!e||e===de){Je();return}try{let t=me?{oldName:de,newName:e,agentId:ge}:{oldName:de,newName:e,...ge?{agentId:ge}:{}};if(!(await fetch(G(me?"/api/sessions/rename-tombstone":"/api/sessions/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok)return;Je(),Me(),!me&&U===de&&(ge??null)===ne&&kt(e,ge)}catch{}}),document.getElementById("sp-rebuild").addEventListener("click",async()=>{if(confirm('\u91CD\u5EFA\u4F1A\u8BDD "'+de+'" (\u540C\u540D\u540C\u8DEF\u5F84\uFF0C\u5185\u5BB9\u4E3A\u7A7A)\uFF1F'))try{let e=await fetch(G("/api/sessions/rebuild"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:de,agentId:ge})});if(!e.ok){let t=await e.json();alert(t.error||"\u91CD\u5EFA\u5931\u8D25");return}Je(),Me()}catch{}}),document.getElementById("sp-delete").addEventListener("click",async()=>{if(me){if(!confirm('\u5220\u9664\u5931\u6548\u8BB0\u5F55 "'+de+'"\uFF1F'))return;try{if(!(await fetch(G("/api/sessions/dismiss"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:de,agentId:ge})})).ok)return;Je(),Me()}catch{}return}if(confirm('Delete session "'+de+'"?'))try{if(!(await fetch(G("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:de,...ge?{agentId:ge}:{}})})).ok)return;Je(),U===de&&(ge??null)===ne&&(V&&(V.destroy(),V=null),U=null,ce.style.display="none",We.style.display="flex"),Me()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",Je);var $s={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"},ln=document.getElementById("mobile-keys"),xr=new Set(["up","down","left","right","tab","s-tab","space"]),Er=400,Sr=80,Et=0,rn=0,on=!1;function Cr(){Et&&(clearTimeout(Et),Et=0),rn&&(clearInterval(rn),rn=0)}ln.addEventListener("mousedown",e=>{e.target.closest("button[data-key]")&&e.preventDefault()}),ln.addEventListener("pointerdown",e=>{let t=e.target.closest("button[data-key]");if(!t)return;let n=t.dataset.key;xr.has(n)&&(on=!1,Et=setTimeout(()=>{Et=0,on=!0,rn=setInterval(()=>{let i=$s[n];i&&V&&V.sendInput(i)},Sr)},Er))});for(let e of["pointerup","pointercancel","pointerleave"])ln.addEventListener(e,Cr);ln.addEventListener("click",e=>{let t=e.target.closest("button[data-key]");if(!t||!V)return;if(on){on=!1;return}let n=$s[t.dataset.key];n&&(V.sendInput(n),V.focus())});var xe=document.getElementById("mk-input"),Is=document.getElementById("mk-send");function Ts(){if(!xe||!V)return;let e=xe.value;e&&(V.sendInput(e+"\r"),xe.value="",xe.rows=1,V.focus())}if(xe&&(xe.addEventListener("input",()=>{xe.rows=1;let e=xe.value.split(`
135
+ `).length;xe.rows=Math.min(e,4)}),xe.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Ts())})),Is&&Is.addEventListener("click",Ts),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 Zn=document.getElementById("process-panel"),St=document.getElementById("proc-list"),Lr=document.getElementById("proc-close"),Jn=document.getElementById("proc-backdrop"),$r=document.getElementById("header-ram");function Ir(){St.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(G("/api/system/processes")).then(e=>e.json()).then(e=>{if(!Array.isArray(e)||!e.length){St.innerHTML='<div class="proc-empty">No processes</div>';return}let t="";for(let n of e){let i=n.rss,s=i<1048576?(i/1024).toFixed(0)+"K":(i/1048576).toFixed(1)+"M";t+='<div class="proc-row" data-pid="'+n.pid+'"><span class="proc-mem">'+n.mem+'%</span><span class="proc-rss">'+s+'</span><span class="proc-cmd" title="'+F(n.command)+'">'+F(n.command)+'</span><button class="proc-kill" title="Kill PID '+n.pid+'">&times;</button></div>'}St.innerHTML=t;for(let n of St.querySelectorAll(".proc-row")){let i=n.querySelector(".proc-kill");i&&i.addEventListener("click",s=>{let a=s.target.closest(".proc-row");!a||!confirm("Kill PID "+a.dataset.pid+"?")||fetch(G("/api/system/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:parseInt(a.dataset.pid,10)})}).then(l=>l.json()).then(l=>{l.ok?a.style.opacity="0.3":alert("Failed: "+(l.error||"unknown"))}).catch(()=>alert("Network error"))})}}).catch(()=>{St.innerHTML='<div class="proc-empty">Failed to load</div>'})}function Tr(){Zn.classList.add("open"),Jn.classList.add("open"),Ir()}function cn(){Zn.classList.remove("open"),Jn.classList.remove("open")}$r.addEventListener("click",e=>{e.stopPropagation(),Zn.classList.contains("open")?cn():Tr()}),Lr.addEventListener("click",cn),Jn.addEventListener("click",cn);var Ar=2e3,Ct=null,Yn=null,et=new Map,tt=new Map,Mr=5e3,As=new Map;function Xn(e,t){return(t?"a:"+t+":":"l:")+e}function zr(e,t,n){let i=Xn(e,t);if(n==="working"){let c=As.get(i);if(c&&Date.now()<c)return}let s=tt.get(i),a=e===U&&(t??null)===ne,l=n==="idle"&&s?.state==="working";tt.set(i,{session:e,agentId:t,state:n,doneUntil:l?Date.now()+Ar:void 0,unread:l?!a:!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])',o=_.querySelector(r);o&&dn(o,i,tt.get(i))}function dn(e,t,n){let i=et.get(t);i&&(clearTimeout(i),et.delete(t)),e.classList.remove("working","just-done");let s=n.session===U&&(n.agentId??null)===ne;n.state==="working"?e.classList.add("working"):s&&n.doneUntil&&Date.now()<n.doneUntil?(e.classList.add("just-done"),et.set(t,setTimeout(()=>{e.classList.remove("just-done"),et.delete(t)},Math.max(0,n.doneUntil-Date.now())))):!s&&n.unread&&e.classList.add("just-done")}function Kn(){for(let[e,t]of tt){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])',i=_.querySelector(n);i&&dn(i,e,t)}}function Br(e,t){let n=Xn(e,t),i=tt.get(n);if(!i)return;let s=et.get(n);s&&(clearTimeout(s),et.delete(n)),i.doneUntil=void 0,i.unread=!1;let a=t?'.session-item[data-agent="'+CSS.escape(t)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])',l=_.querySelector(a);l&&dn(l,n,i)}function Ms(){if(Ct||Yn)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);Ct=n,n.onmessage=i=>{try{let s=JSON.parse(String(i.data));s&&s.type==="session.activity"&&typeof s.session=="string"&&zr(s.session,s.agentId||void 0,s.state==="working"?"working":"idle")}catch{}},n.onclose=()=>{Ct===n&&(Ct=null,Yn=setTimeout(()=>{Yn=null,Ms()},5e3))},n.onerror=()=>{try{n.close()}catch{}}}catch{Ct=null}}window.__openSession=kt,window.__refreshSidebar=Me,Me(),Ze(),Kn(),Ms(),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Kn()}),setInterval(()=>{document.visibilityState==="visible"&&Me()},1e4),Yl();