tmux-weblink 3.2.2 → 3.2.3

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,69 +1,69 @@
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
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 ot(e){return e.replace(Xs,"")}var Mt;function Ks(){return Mt||(document.querySelector("link[data-tmux-web-xterm-css]")?Mt=Promise.resolve():(Mt=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)}),Mt))}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 u=l;u<=r;u++){let p=a.getLine(d+u);if(!p){v.push("");continue}let m=u===l?o:0,f=u===r?c:this.terminal.cols-1,k="";for(let w=m;w<=f;w++){let E=p.getCell(w);E&&(k+=E.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,u=.95,p=.04,m=null,f=null;function k(h){m||(m=document.createElement("div"),m.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(m)),m.textContent=h?"\u2191 \u4E0A\u7FFB\u4E00\u9875 (PgUp)":"\u2193 \u4E0B\u7FFB\u4E00\u9875 (PgDn)",m.style.top=h?"10%":"auto",m.style.bottom=h?"auto":"10%",m.style.opacity="1",f&&clearTimeout(f),f=setTimeout(()=>{m&&(m.style.opacity="0")},900)}function w(){f&&clearTimeout(f),m&&(m.style.opacity="0")}function E(){o&&(cancelAnimationFrame(o),o=0),c=0}function B(h){if(E(),Math.abs(h)<d)return;c=Math.max(-v,Math.min(v,h));let b=()=>{if(I){o=0;return}let C=i.cellHeight(),R=C>0?Math.round(c*16/C):c>0?1:-1;R===0&&(R=c>0?1:-1);let W=i.viewportY()-R,be=i.baseY(),Re=Math.max(0,Math.min(W,be));if(i.scrollToLine(Re,!0),c*=u,Re!==W){o=0;return}if(Math.abs(c)<p){o=0;return}o=requestAnimationFrame(b)};o=requestAnimationFrame(b)}let $=0,T="connecting",A=0,M=!1,x=[],F="",I=!1,K=1e3,N=location.protocol==="https:"?"wss:":"ws:",ge=n.wsBase||"/ws",Q=N+"//"+location.host+ge+"/"+encodeURIComponent(t),X=(ge.replace(/^\/ws/,"")||"")+"/api/session/"+encodeURIComponent(t)+"/upload",ze=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function ye(){return x.join("")+F}async function U(h,b=0){let C=h?i.viewportY():0,R=ot(ye());if(i.reset(),!R){h||i.scrollToBottom();return}await i.write(R),h?i.scrollToLine(b+C):i.scrollToBottom()}function J(h){s?.readyState===WebSocket.OPEN&&s.send(JSON.stringify(h))}function O(h){let b;try{b=JSON.parse(h)}catch{T==="live"&&(F+=h,i.write(ot(h)));return}if(b.type==="auth.required"){let C=localStorage.getItem("tmux-web-token");C?J({type:"auth.token",token:C}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(b.type==="attach_failed"&&typeof b.message=="string"){xe=!0,T="dead",i.reset(),i.write(`\r
4
+ \x1B[31m`+ot(b.message)+`\x1B[0m\r
5
+ `).then(()=>{G();try{s?.close()}catch{}});return}if(b.type==="auth.ok"){b.token&&localStorage.setItem("tmux-web-token",b.token),K=1e3,z(),J({type:"resize",cols:i.cols,rows:i.rows}),V();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 C=fn(ot(b.data));x=[C],F="",A=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(C).then(()=>i.scrollToBottom());return}if(b.type==="window_changed"&&typeof b.activeIndex=="number"){let C=new URL(location.href);C.searchParams.get("window")!==String(b.activeIndex)&&(C.searchParams.set("window",String(b.activeIndex)),history.replaceState(history.state,"",C)),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)),A+=b.lines,U(!0,b.lines).finally(()=>{M=!1})):M=!1;return}if(b.type==="data"&&typeof b.data=="string"){let C=fn(ot(b.data));if(T==="connecting"){T="live",F=C,i.write(C);return}T==="live"&&(F+=C,i.write(C))}}let xe=!1;function Se(){if(xe)return;let h=Q,b=localStorage.getItem("tmux-web-token");b&&(h+=(h.includes("?")?"&":"?")+"token="+encodeURIComponent(b)),h+=(h.includes("?")?"&":"?")+"cols="+i.cols+"&rows="+i.rows,s=new WebSocket(h),s.onopen=()=>{T="connecting",A=0,M=!1,x=[],F="",i.reset(),K=1e3},s.onmessage=C=>{typeof C.data=="string"&&O(C.data)},s.onclose=()=>{I||(T="connecting",!xe&&setTimeout(()=>{K=Math.min(K*2,1e4),!I&&!xe&&Se()},K))},s.onerror=()=>s?.close()}function S(h){J({type:"input",data:h})}function z(){return i.fit()}function G(){e.classList.remove("terminal-pending")}function V(){a&&cancelAnimationFrame(a),l&&clearTimeout(l),z(),a=requestAnimationFrame(()=>{a=0,z()&&G()}),l=setTimeout(()=>{z()&&G()},120)}function _e(){V(),setTimeout(V,50),setTimeout(V,150),setTimeout(V,300)}function ti(h){return typeof h=="string"&&h.startsWith("image/")}function ni(h){return h?.files?.length?h.files[0]??null:null}function Rs(h){if(!h?.items)return null;for(let b=0;b<h.items.length;b++){let C=h.items[b];if(C?.kind==="file"&&ti(C.type))return C.getAsFile()}return null}async function Ps(h){let b=new FormData,C=h instanceof File&&h.name?h.name:"upload";b.append("file",h,C);let R=localStorage.getItem("tmux-web-token"),W={};R&&(W.Authorization="Bearer "+R);let be=await fetch(X,{method:"POST",body:b,headers:W});if(!be.ok){let ci="upload failed";try{let di=await be.json();di.error&&(ci=di.error)}catch{}throw new Error(ci)}let Re=await be.json();if(!Re.path)throw new Error("no path in response");return Re.path}async function un(h){try{let b=await Ps(h);S(b)}catch{}}i.onData(h=>S(h)),i.onResize(({cols:h,rows:b})=>J({type:"resize",cols:h,rows:b})),i.onScroll(()=>{T!=="live"||M||!i.isNearScrollbackTop()||(M=!0,J({type:"load_history",before:A}))});let it=!1,st=!1,ee=null,ne=null,at=document.createElement("div");at.className="terminal-copy-banner",at.innerHTML='<strong>Copy mode</strong><span class="hint">drag to copy \xB7 Esc exits</span>',at.hidden=!0,e.appendChild(at);let Ee=document.createElement("div");Ee.className="terminal-copy-banner terminal-copy-toast",Ee.textContent="Copied",Ee.hidden=!0,e.appendChild(Ee);function ii(h,b){let C=e.querySelector(".xterm-screen, canvas"),R=(C&&C.getBoundingClientRect().width>0?C:e).getBoundingClientRect(),W=R.height>0&&i.rows>0?R.height/i.rows:18,be=R.width>0&&i.cols>0?R.width/i.cols:9;return{row:Math.max(0,Math.min(i.rows-1,Math.floor((b-R.top)/W))),col:Math.max(0,Math.min(i.cols-1,Math.floor((h-R.left)/be)))}}async function Tt(h){if(!h)return;try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(h);return}}catch{}let b=document.createElement("textarea");b.value=h,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 lt;function It(){Ee.hidden=!1,lt&&clearTimeout(lt),lt=setTimeout(()=>{Ee.hidden=!0},1e3)}function Xe(h){it=h,at.hidden=!h,e.classList.toggle("terminal-copy-mode-active",h),h&&i.focus()}function si(){Xe(!it)}function Ds(h){I||h.button!==0||st||(it||h.shiftKey)&&(h.preventDefault(),h.stopPropagation(),st=!0,ee=ii(h.clientX,h.clientY),ne=ee,i.selectCells(ee.col,ee.row,ne.col,ne.row),document.addEventListener("mousemove",hn,!0),document.addEventListener("mouseup",mn,!0))}function hn(h){I||!st||!ee||(h.preventDefault(),h.stopPropagation(),ne=ii(h.clientX,h.clientY),i.selectCells(ee.col,ee.row,ne.col,ne.row))}function mn(h){if(I||!st||!ee||!ne)return;h.preventDefault(),h.stopPropagation(),document.removeEventListener("mousemove",hn,!0),document.removeEventListener("mouseup",mn,!0),st=!1;let b=i.getCellsText(ee.col,ee.row,ne.col,ne.row);ee=null,ne=null,i.clearSelection(),Xe(!1),b&&(Ee.textContent="\u5DF2\u590D\u5236",Tt(b).then(It)),i.focus()}e.addEventListener("mousedown",Ds,!0),document.addEventListener("keydown",Hs,!0);function Hs(h){if(!(I||!i.isFocused()||h.defaultPrevented||h.isComposing)){if(it){if(h.key==="Escape"){h.preventDefault(),h.stopPropagation(),ee=null,ne=null,i.clearSelection(),Xe(!1);return}if(h.key==="Enter"||(h.ctrlKey||h.metaKey)&&h.code==="KeyC"){h.preventDefault(),h.stopPropagation(),Tt(i.getScreenText()).then(It),Xe(!1);return}}if(h.altKey&&h.code==="KeyC"&&!h.ctrlKey&&!h.metaKey){if(h.preventDefault(),h.stopPropagation(),ee&&ne){let b=i.getCellsText(ee.col,ee.row,ne.col,ne.row);ee=null,ne=null,i.clearSelection(),Xe(!1),b&&(Ee.textContent="Copied",Tt(b).then(It))}else{let b=i.getSelection();b?(i.clearSelection(),Ee.textContent="Copied",Tt(b).then(It)):si()}return}if((h.ctrlKey||h.metaKey)&&h.code==="KeyV"){h.preventDefault(),h.stopPropagation(),(async()=>{try{if(navigator.clipboard?.read){let b=await navigator.clipboard.read();for(let C of b)for(let R of C.types)if(ti(R)){let W=await C.getType(R);await un(W);return}}}catch{}try{let b=await navigator.clipboard?.readText();b&&i.pasteText(ai(b))}catch{}})();return}}}let At=0;function ai(h){return h.split(`\r
6
6
  `).join(`
7
7
  `).split(`
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?`
8
+ `).join("\r")}async function _s(h){let b=Rs(h.clipboardData);if(b){h.preventDefault(),h.stopPropagation();let W=Date.now();if(W-At<50)return;At=W,await un(b);return}let C=h.clipboardData?.getData("text/plain");if(!C)return;h.preventDefault(),h.stopPropagation();let R=Date.now();R-At<50||(At=R,i.pasteText(ai(C)))}let rt=0;function Fs(h){h.preventDefault(),rt++,ni(h.dataTransfer)&&e.classList.add("terminal-drag-over")}function Ns(h){h.preventDefault(),h.dataTransfer&&(h.dataTransfer.dropEffect="copy")}function js(h){h.preventDefault(),rt--,rt<=0&&(rt=0,e.classList.remove("terminal-drag-over"))}async function qs(h){h.preventDefault(),rt=0,e.classList.remove("terminal-drag-over");let b=ni(h.dataTransfer);b&&await un(b)}function li(h){!ze||h.key!=="Escape"||it||h.defaultPrevented||h.repeat||h.metaKey||h.ctrlKey||h.altKey||i.isFocused()&&(h.preventDefault(),h.stopPropagation(),S("\x1B"))}e.addEventListener("paste",_s),e.addEventListener("dragenter",Fs),e.addEventListener("dragover",Ns),e.addEventListener("dragleave",js),e.addEventListener("drop",qs),document.addEventListener("keydown",li,!0);function Os(h){if(h.touches.length!==1){r=null;return}let b=h.touches[0];if(!b)return;E();let C=e.getBoundingClientRect(),R=b.clientX-C.left<C.width*.4?"tui":"history",W=b.clientY-C.top<C.height*.5;r={startX:b.clientX,startY:b.clientY,lastX:b.clientX,lastY:b.clientY,lastT:performance.now(),velocity:0,scrolling:!1,zone:R,tuiUp:W,sent:!1},h.stopPropagation()}function Vs(h){if(!r||h.touches.length!==1)return;let b=h.touches[0];if(!b)return;let C=b.clientY-r.startY,R=b.clientX-r.startX;if(!r.scrolling){if(Math.abs(C)<8||Math.abs(C)<Math.abs(R))return;r.scrolling=!0,$=Date.now()+500}h.preventDefault(),h.stopPropagation();let W=performance.now(),be=b.clientY-r.lastY;if(r.zone==="tui"){r.sent||(r.sent=!0,S(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=be/Re),Zs(-be),r.lastX=b.clientX,r.lastY=b.clientY,r.lastT=W}function Ws(h){if(!r)return;let b=r.scrolling,C=r.zone,R=r.tuiUp,W=r.velocity;if(r=null,h.stopPropagation(),C==="tui"){b||(S(R?"\x1B[5~":"\x1B[6~"),k(R),$=Date.now()+500,h.preventDefault());return}if(!b){i.focus();return}$=Date.now()+500,h.preventDefault(),W&&B(W)}function Us(h){r=null,E(),h.stopPropagation()}function Js(h){h.pointerType==="touch"&&Date.now()<$&&(h.preventDefault(),h.stopPropagation())}function Zs(h){let b=i.cellHeight(),C=b>0?Math.round(h/b):h>0?1:-1;C===0&&(C=h>0?1:-1),i.scrollLines(C)}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",Js,!0);function ri(){V()}window.addEventListener("resize",ri),window.visualViewport?.addEventListener("resize",V),window.visualViewport?.addEventListener("scroll",V);let oi=new ResizeObserver(()=>V());oi.observe(e),document.fonts?.ready.then(()=>{V(),setTimeout(V,50),setTimeout(V,200)}),e.addEventListener("focusin",_e,!0);async function Ys(){if(document.fonts?.ready)try{await Promise.race([document.fonts.ready,new Promise(h=>setTimeout(h,1e3))])}catch{}}return requestAnimationFrame(()=>{z()&&G(),(async()=>(await Ys(),z()&&J({type:"resize",cols:i.cols,rows:i.rows}),Se(),V()))()}),{destroy(){if(I=!0,E(),Xe(!1),lt&&clearTimeout(lt),document.removeEventListener("mousemove",hn,!0),document.removeEventListener("mouseup",mn,!0),s){try{s.close(1e3,"session switch")}catch{}s=void 0}e.innerHTML="",e.classList.remove("terminal-pending"),window.removeEventListener("resize",ri),oi.disconnect(),document.removeEventListener("keydown",li,!0)},focus(){i.focus()},sendInput(h){S(h)},toggleCopyMode(){si()}}})()}var pi={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 pi[e]??pi.menu}function le(e,t=""){return`<svg viewBox="0 0 24 24" fill="currentColor"${t?" "+t:""}><path d="${ia(e)}"/></svg>`}function gn(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Fe=gn();function ui(e){Fe=e}var Ne={exec:()=>null};function je(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 L(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(_.caret,"$1"),n=n.replace(s,l),i},getRegex:()=>new RegExp(n,t)};return i}var hi=((e="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+e)}catch{return!1}})(),mi="^ *([^\\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(mi+"(?:\\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:je(e=>new RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:je(e=>new RegExp(`^ {0,${e}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:je(e=>new RegExp(`^ {0,${e}}(?:\`{3,}(?=[^\`\\n]*(?:\\n|$))|~~~)`)),headingBeginRegex:je(e=>new RegExp(`^ {0,${e}}#{1,6}(?:\\s|$)`)),pedanticHeadingBeginRegex:je(e=>new RegExp(`^ {0,${e}}#`)),htmlBeginRegex:je(e=>new RegExp(`^ {0,${e}}(?:</?(?:${vn})(?:[ \\t]+|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,"i")),blockquoteBeginRegex:je(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|$)|$)/,ct=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,ra=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,bn=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,vn="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",dt=L(" {0,3}(?:</?(?:tag)(?:[ \\t]+|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",vn).getRegex(),fi=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?![ \t]*\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/,gi=L(fi).replace(/bull/g,bn).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,dt).getRegex(),oa=L(fi).replace(/bull/g,bn).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,dt).getRegex(),kn=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,ca=/^[^\n]+/,wn=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/,da=L(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<(?:\\.|[^\n<>\\])*>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",wn).replace("title",/(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\\n]|\n(?!\n))*'|\((?:\\[\s\S]|[^()\\])*\))/).getRegex(),pa=L(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,bn).getRegex(),yn=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,ua=L("^ {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",yn).replace("tag",vn).replace("attribute",/[ \t]+[a-zA-Z:_][\w.:-]*(?:[ \t]*=[ \t]*"[^"\n]*"|[ \t]*=[ \t]*'[^'\n]*'|[ \t]*=[ \t]*[^\s"'=<>`]+)?/).getRegex(),bi=e=>L(kn).replace("hr",ct).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",dt).getRegex(),ha=bi(_.listInterruptsParagraph),ma=bi(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),vi=/ {0,3}> ?(?:(?!blank)(paragraph)|[^\n]*)(?:\n|$)/,fa=L(/^(first)(?:next)*/).replace("first",L(vi).replace("blank",/[ \t]*(?:\n|$)| {4}/).getRegex()).replace("next",L(vi).replace("blank",/[ \t]*(?:\n|$)/).getRegex()).replace(/paragraph/g,ma).getRegex(),xn={blockquote:fa,code:aa,def:da,fences:la,heading:ra,hr:ct,html:ua,lheading:gi,list:pa,newline:sa,paragraph:ha,table:Ne,text:ca},ga=L(mi+"(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",ct).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",dt).getRegex(),ba={...xn,lheading:oa,table:ga,paragraph:L(kn).replace("hr",ct).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",dt).getRegex()},va={...xn,html:L(`^ *(?:comment(?: *\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1>(?: *\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?>(?: *\\n{2,}|\\s*$))`).replace("comment",yn).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:Ne,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:L(kn).replace("hr",ct).replace("heading",` *#{1,6} *[^
9
+ ]`).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").replace("lheading",gi).getRegex()},ka=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,wa=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ki=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,ya=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,ve=/[\p{P}\p{S}]/u,Ke=/[\s\p{P}\p{S}]/u,pt=/[^\s\p{P}\p{S}]/u,xa=L(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Ke).getRegex(),Sa=/[\p{Pi}\p{Ps}"']/u,wi=/(?!~)[\p{P}\p{S}]/u,Ea=/(?!~)[\s\p{P}\p{S}]/u,Ca=/(?:[^\s\p{P}\p{S}]|~)/u,La=L(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",hi?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),yi=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,$a=L(yi,"u").replace(/punct/g,ve).getRegex(),Ta=L(yi,"u").replace(/punct/g,wi).getRegex(),Ia=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,Aa=L(Ia,"u").replace(/openQuote/g,Sa).replace(/punct/g,ve).getRegex(),xi="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Ma=L(xi,"gu").replace(/notPunctSpace/g,pt).replace(/punctSpace/g,Ke).replace(/punct/g,ve).getRegex(),Ba=L(xi,"gu").replace(/notPunctSpace/g,Ca).replace(/punctSpace/g,Ea).replace(/punct/g,wi).getRegex(),za="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",Ra=L(za,"gu").replace(/notPunctSpace/g,pt).replace(/punctSpace/g,Ke).replace(/punct/g,ve).getRegex(),Pa=L("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,pt).replace(/punctSpace/g,Ke).replace(/punct/g,ve).getRegex(),Da="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",Ha=L(Da,"gu").replace(/notPunctSpace/g,pt).replace(/punctSpace/g,Ke).replace(/punct/g,ve).getRegex(),_a=L(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,ve).getRegex(),Fa="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Na=L(Fa,"gu").replace(/notPunctSpace/g,pt).replace(/punctSpace/g,Ke).replace(/punct/g,ve).getRegex(),ja=L(/\\(punct)/,"gu").replace(/punct/g,ve).getRegex(),qa=L(/(`+)(?:[^`]|[^`][\s\S]*?[^`])\1(?!`)|`+|\\(punct)/,"gu").replace(/punct/g,ve).getRegex(),Oa=L(/^<(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=L(yn).replace("(?:-->|$)","-->").getRegex(),Wa=L("^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(),Si=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,Bt=L(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace("brackets",Si).getRegex(),zt=/\\[^ \t\n\x00-\x1f]|\\(?=[ \t\n])|[^ \t\n\x00-\x1f\\()]/,Ua=L(/\((?:char)*\)/).replace("char",zt).getRegex(),Ja=L(/\((?:char|p1)*\)/).replace("char",zt).replace("p1",Ua).getRegex(),Za=L(/\((?:char|p2)*\)/).replace("char",zt).replace("p2",Ja).getRegex(),Ya=L(/(?!<)(?:char|p3)+/).replace("char",zt).replace("p3",Za).getRegex(),Xa=L(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace("label",Bt).replace("href",L(/<(?:\\.|[^\n<>\\])*>|bareHref|(?=\))/).replace("bareHref",Ya).getRegex()).replace("title",/"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|\((?:\\[\s\S]|[^)\\])*\)/).getRegex(),Ka=L(/^!?\[(label)\]\[(ref)\]/).replace("label",Bt).replace("ref",wn).getRegex(),Qa=L(/^!?\[(ref)\](?:\[\])?/).replace("ref",wn).getRegex(),Ei=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,Ga=L(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace("brackets",Si).getRegex(),el=L("reflink|nolink(?!\\()","g").replace("reflink",L(/^!?\[(label)\]\[(ref)\]/).replace("label",Ga).replace("ref",Ei).getRegex()).replace("nolink",L(/^!?\[(ref)\](?:\[\])?/).replace("ref",Ei).getRegex()).getRegex(),Ci=/[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=L(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,tl).getRegex(),Sn={_backpedal:Ne,anyPunctuation:ja,anyPunctuationOutsideCode:qa,autolink:Oa,blockSkip:La,br:ki,code:wa,del:Ne,delLDelim:Ne,delRDelim:Ne,emStrongLDelim:$a,emStrongRDelimAst:Ma,emStrongRDelimUnd:Pa,escape:ka,link:Xa,nolink:Qa,punctuation:xa,reflink:Ka,reflinkSearch:el,tag:Wa,text:ya,url:Ne},il={...Sn,emStrongLDelim:Aa,emStrongRDelimAst:Ra,emStrongRDelimUnd:Ha,link:L(/^!?\[(label)\]\((.*?)\)/).replace("label",Bt).getRegex(),reflink:L(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Bt).getRegex()},En={...Sn,emStrongRDelimAst:Ba,emStrongLDelim:Ta,delLDelim:_a,delRDelim:Na,url:L(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("emailProtocol",nl).replace("protocol",Ci).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:L(/^(?:[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",Ci).replace(/emailProtocol/g,/(?:mailto|xmpp):/).replace("wwwStart",hi?"(?<![^\\s*_~(])www\\.":"www\\.").getRegex()},sl={...En,br:L(ki).replace("{2,}","*").getRegex(),text:L(En.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Rt={normal:xn,gfm:ba,pedantic:va},ut={normal:Sn,gfm:En,breaks:sl,pedantic:il},al={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Li=e=>al[e];function ie(e,t){if(t){if(_.escapeTest.test(e))return e.replace(_.escapeReplace,Li)}else if(_.escapeTestNoEncode.test(e))return e.replace(_.escapeReplaceNoEncode,Li);return e}function ll(e){return _.numericCharacterReference.test(e)?e.replace(_.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 $i(e){try{e=encodeURI(e).replace(_.percentDecode,"%")}catch{return null}return e}function Cn(e,t){let n=e.replace(_.findPipe,(a,l,r)=>{let o=!1,c=l;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(),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(_.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 Ti(e){let t=e.split(`
10
+ `),n=t.length-1;for(;n>=0&&_.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
11
+ `)}function Pt(e,t=!1){let n=t?_.multipleSpaceGlobal:_.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 Qe=new WeakMap;function Ln(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
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(`
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=Ln(t),i=Qe.get(e);i?i.push(n):Qe.set(e,[n])}function ol(e){let t=Qe.get(e);t&&(t.pop(),t.length===0&&Qe.delete(e))}function Ai(e,t,n){let i=Qe.get(e)?.at(-1);return i&&i.maskedSrc===t?i.lastPossibleEmStrongCloserIndex[n]:Ln(t).lastPossibleEmStrongCloserIndex[n]}function Mi(e,t){let n=Qe.get(e)?.at(-1);return n&&n.maskedSrc===t?n.lastPossibleDelCloserIndex:Ln(t).lastPossibleDelCloserIndex}function ht(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=_.blockquoteFenceClose.exec(r)?.[1];return!c||c[0]!==t.marker[0]||c.length<t.marker.length?l:(t=void 0,a)}if(n=_.blockquoteListItemStart.test(r),n)return i;let o=_.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+=Bi(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=Bi(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 Bi(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 u=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:u}}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
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(`
16
+ `)}function Ri(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 qe=class{options;rules;lexer;constructor(e){this.options=e||Fe}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]:Ti(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
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
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
20
  `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=Ce(t[0],`
21
21
  `).split(`
22
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,`
23
+ `),d=(this.lexer.state.top&&!this.lexer.state.inBlockquote&&c.includes(" ")?cl(r):c).replace(this.rules.other.blockquoteMarkerWhitespace,(f,k,w)=>w.startsWith(" ")?k+" "+w.slice(1):k+ht(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 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(`
26
+ ${d}`:d;let v=this.lexer.state.top,u=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=u,n.length===0)break;let m=a.at(-1);if(m?.type==="code"||m?.type==="heading"||m?.type==="hr"||m?.type==="html"||m?.type==="table")break;if(m?.type==="blockquote"){let f=m,k=n.join(`
27
+ `),w=f.raw+`
28
+ `+k.replace(this.rules.other.blockquoteSetextReplace2,"");this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=a.at(-2);let E=this.blockquote(w);this.lexer.state.inBlockquote=u,this.lexer.state.lastToken=p,a[a.length-1]=E;let B=w.substring(E.raw.length).replace(/^\n/,""),$=B?B.split(`
29
29
  `).length:0,T=$?n.slice(0,-$):n;if(T.length>0&&(i=`${i}
30
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+`
31
+ `)}`),s=s.substring(0,s.length-f.text.length)+E.text,n=n.slice(T.length),n.length>0&&this.rules.other.blockquoteStart.test(n[0]))continue;break}else if(m?.type==="list"){let f=m,k=f.raw+`
32
32
  `+n.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(`
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=u,this.lexer.state.lastToken=p,a[a.length-1]=w;let E=w.raw.length>f.raw.length?k.slice(f.raw.length+1,w.raw.length).split(`
34
+ `).length:0;if(E>0){let B=n.slice(0,E).join(`
35
35
  `);i=`${i}
36
- ${M}`,s=`${s}
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(`
36
+ ${B}`,s=`${s}
37
+ ${B}`}if(n=n.slice(E),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 u=!1,p="";if(!(t=r.exec(e))||this.rules.block.hr.test(e))break;let m=i();e=e.substring(t[0].length);let f=t[2].split(`
38
+ `,1)[0],k=t[1].length,w=this.options.pedantic?ht(f,k):f.replace(this.rules.other.leadingSpaceTab,A=>ht(A,k)),E=e.split(`
39
+ `,1)[0],B=!w.trim(),$=0;if(this.options.pedantic?($=2,p=w.trimStart()):B?$=k+1:($=w.search(this.rules.other.nonSpaceChar),$=$>4?1:$,p=w.slice($),w=p,$+=k),B&&this.rules.other.blankLine.test(E)&&(e=e.substring(E.length+1),u=!0),!u){let A=this.rules.other.nextBulletRegex($),M=this.rules.other.hrRegex($),x=this.rules.other.fencesBeginRegex($),F=this.options.pedantic?this.rules.other.pedanticHeadingBeginRegex($):this.rules.other.headingBeginRegex($),I=this.rules.other.htmlBeginRegex($),K=this.rules.other.blockquoteBeginRegex($),N=!1;for(;e;){let ge=e.split(`
40
+ `,1)[0],Q;if(E=ge,this.options.pedantic?(E=E.replace(this.rules.other.listReplaceNesting," "),Q=E):Q=E.replace(this.rules.other.leadingSpaceTab,X=>ht(X)),x.test(E)||F.test(E)||I.test(E)||K.test(E)||A.test(E)||M.test(E))break;if(Q.search(this.rules.other.nonSpaceChar)>=$||!E.trim())p+=`
41
+ `+Q.slice($),N=!1;else{if(B)break;let X=w;if(!this.options.pedantic&&!p.includes(`
42
+ `)&&!w.includes(" ")){let U;for(;!M.test(X)&&(U=this.rules.other.nestedBlockMarker.exec(X));)X=X.slice(U[0].length);if(!X.trim())break}if(X.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||x.test(X)||F.test(X)||I.test(X)||M.test(X))break;if(!this.options.pedantic&&!N){let U=w.replace(this.rules.other.nestedContainerMarkers,"");if(this.rules.block.fences.test(U)||this.rules.block.heading.test(U)||this.rules.block.hr.test(U))break}let ze=!this.options.pedantic&&/^ {0,3}(?:=+|-+) *$/.test(E)&&this.rules.block.lheading.test(`${w}
43
+ ${E}`)?` ${Q.replace(/^ {0,3}/,"")}`:E,ye=!this.options.pedantic&&!N&&Q.startsWith(" ")?this.rules.block.list.exec(w):null;if(ye?.[2]){let U=ye[1].length,J=ye[2].replace(this.rules.other.leadingSpaceTab,xe=>ht(xe,U)),O=J.search(this.rules.other.nonSpaceChar);O>0&&O<=4&&!this.rules.other.nestedBlockMarker.test(J.slice(O))&&Q.search(this.rules.other.nonSpaceChar)>=U+O&&this.rules.other.listInterruptsParagraph.test(Q.slice(U+O))&&(ze=` ${Q}`)}p+=`
44
+ `+ze,N=!0}B=!E.trim(),e=e.substring(ge.length+1),w=Q.slice($)}}let T=n.slice(m,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 u of l.items)if(this.lexer.state.top=!1,d.push(this.lexer.inlineQueue.length),u.tokens=this.lexer.blockTokens(u.text,[]),!l.loose){let p=u.tokens.filter(f=>f.type==="space"),m=p.length>0&&p.some(f=>this.rules.other.anyLine.test(f.raw));l.loose=m}this.lexer.state.top=v;for(let u=0;u<l.items.length;u++){let p=l.items[u],m=p.tokens[0];if(p.task&&(m?.type==="text"||m?.type==="paragraph")){p.text=p.text.replace(this.rules.other.listReplaceTask,""),m.raw=m.raw.replace(this.rules.other.listReplaceTask,""),m.text=m.text.replace(this.rules.other.listReplaceTask,"");let f=this.lexer.inlineQueue;for(let w=d[u];w<f.length;w++)if(f[w].tokens===m.tokens){f[w].src=f[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 u of l.items){u.loose=!0;for(let p of u.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=Ti(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=Pt(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=Cn(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??=Cn(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
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],`
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(Cn(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
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+=`
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&&Ri(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&&Ri(e,i[1],s,this.rules))return;let a=t[Pt(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 u=[...i[0]].length-1,p,m,f=u,k=0,w=l-r+u,E=!this.options.pedantic&&!!o.trim()&&(!!v||s==="*"&&!c);if(s!=="*"&&s!=="_")return;let B=s==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd,$=Ai(this,t,s),T=t.length-e.length+u;if($<T)return;t=t.slice(-1*e.length+u);let A=$-T;for(B.lastIndex=0;(i=B.exec(t))!==null&&!(i.index>A);){if(p=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!p)continue;m=[...p].length;let M=m>f-u;if(i[3]||i[4]){f+=m;continue}else if((i[5]||i[6]||E&&M)&&w%3&&!((w+m)%3)){if(a&&(i[5]||i[6]))break;k+=m;continue}if(f-=m,f>0)continue;m=Math.min(m,m+f+k);let x=[...i[0]][0].length,F=e.slice(0,u+i.index+x+m);if(Math.min(u,m)%2){let K=F.slice(1,-1);return{type:"em",raw:F,text:K,tokens:this.lexer.inlineTokens(K)}}let I=F.slice(2,-2);return{type:"strong",raw:F,text:I,tokens:this.lexer.inlineTokens(I)}}}}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=Mi(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 u=[...i[0]][0].length,p=e.slice(0,s+i.index+u+l),m=p.slice(s,-s);return{type:"del",raw:p,text:m,tokens:this.lexer.inlineTokens(m)}}}}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}}}},de=class Gn{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Fe,this.options.tokenizer=this.options.tokenizer||new qe,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:Rt.normal,inline:ut.normal};this.options.pedantic?(n.block=Rt.pedantic,n.inline=ut.pedantic):this.options.gfm&&(n.block=Rt.gfm,this.options.breaks?n.inline=ut.breaks:n.inline=ut.gfm),this.tokenizer.rules=n}static get rules(){return{block:Rt,inline:ut}}static lex(t,n){return new Gn(n).lex(t)}static lexInline(t,n){let i=new Gn(n);return t.includes("\r")&&(t=t.replace(_.carriageReturn,`
50
+ `)),i.inlineTokens(t)}lex(t){t=t.replace(_.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(_.tabCharGlobal," ").replace(_.spaceLine,""));let a=1/0,l,r=this.options.gfm&&!this.options.pedantic&&this.tokenizer.paragraph===qe.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
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
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(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(`
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),u;this.options.extensions.startBlock.forEach(p=>{u=p.call({lexer:this},v),typeof u=="number"&&u>=0&&(d=Math.min(d,u))}),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
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(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>
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,Pt(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!==qe.prototype.emStrong||this.tokenizer.del!==qe.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(Ai(this.tokenizer,n,o)<=d){let v=1;for(;v<t.length&&t.charCodeAt(v)===o.charCodeAt(0);)v++;let u=t.substring(0,v),p=i.at(-1);p?.type==="text"&&!p.escaped?(p.raw+=u,p.text+=u):i.push({type:"text",raw:u,text:u,escaped:!1}),t=t.substring(v),a=o,s=!0;continue}}else if(o==="~"){let d=n.length-t.length;if(Mi(this.tokenizer,n)<=d){let v=1;for(;v<t.length&&t.charCodeAt(v)===126;)v++;let u=t.substring(0,v),p=i.at(-1);p?.type==="text"&&!p.escaped?(p.raw+=u,p.text+=u):i.push({type:"text",raw:u,text:u,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),u;this.options.extensions.startInline.forEach(p=>{u=p.call({lexer:this},v),typeof u=="number"&&u>=0&&(d=Math.min(d,u))}),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,Pt(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 $n(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=ie(s.text,!0);l!==s.text&&(a={...s,text:l})}else if(s.type==="link"&&s.autolink){let l=ie(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:$n(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=$n(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 Dt=class{options;parser;constructor(e){this.options=e||Fe}space(e){return""}code({text:e,lang:t,escaped:n}){let i=(t||"").trim().match(_.notSpaceStart)?.[0],s=e?e.replace(_.endingNewline,"")+`
65
+ `:"";return i?'<pre><code class="language-'+ie(i)+'">'+(n?s:ie(s,!0))+`</code></pre>
66
+ `:"<pre><code>"+(n?s:ie(s,!0))+`</code></pre>
67
67
  `}blockquote({tokens:e}){return`<blockquote>
68
68
  ${this.parser.parse(e)}</blockquote>
69
69
  `}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
@@ -79,49 +79,49 @@ ${this.parser.parse(e)}</blockquote>
79
79
  `}tablerow({text:e}){return`<tr>
80
80
  ${e}</tr>
81
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(`
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>${ie(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?ie(n,!0):this.parser.parseInline(i),l=$i(e);if(l===null)return a;e=ie(l,s);let r='<a href="'+e+'"';return t&&(r+=' title="'+ie(t)+'"'),r+=">"+a+"</a>",r}image({href:e,title:t,text:n,tokens:i}){i&&(n=this.parser.parseInline($n(i),this.parser.textRenderer));let s=$i(e);if(s===null)return ie(n);e=s;let a=`<img src="${ie(e)}" alt="${ie(n)}"`;return t&&(a+=` title="${ie(t)}"`),a+=">",a}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:ie(e.text)}},Tn=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}},pe=class ei{options;renderer;textRenderer;constructor(t){this.options=t||Fe,this.options.renderer=this.options.renderer||new Dt,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Tn,this.textRenderer.parser=this}static parse(t,n){return new ei(n).parse(t)}static parseInline(t,n){return new ei(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}},mt=class{options;block;constructor(e){this.options=e||Fe}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?de.lex:de.lexInline}provideParser(e=this.block){return e?pe.parse:pe.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=gn();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=pe;Renderer=Dt;TextRenderer=Tn;Lexer=de;Tokenizer=qe;Hooks=mt;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 Dt(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 qe(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 mt;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];mt.passThroughHooks.has(a)?s[l]=c=>{if(s.options.async&&mt.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 de.lex(e,t??this.defaults)}parser(e,t){return pe.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?de.lex:de.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?pe.parse:pe.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?de.lex:de.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?pe.parse:pe.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>"+ie(i.message+"",!0)+"</pre>";return t?Promise.resolve(s):s}if(t)return Promise.reject(i);throw i}}},Oe=new hl;function P(e,t){return Oe.parse(e,t)}function ml(e,t){return Oe.parseInline(e,t)}P.options=P.setOptions=function(e){return Oe.setOptions(e),P.defaults=Oe.defaults,ui(P.defaults),P},P.getDefaults=gn,P.defaults=Fe;function fl(...e){return Oe.use(...e),P.defaults=Oe.defaults,ui(P.defaults),P}P.use=fl,P.walkTokens=function(e,t){return Oe.walkTokens(e,t)},P.parseInline=ml,P.Parser=pe,P.parser=pe.parse,P.Renderer=Dt,P.TextRenderer=Tn,P.Lexer=de,P.lexer=de.lex,P.Tokenizer=qe,P.Hooks=mt,P.parse=P;var Rr=P.options,Pr=P.setOptions,Dr=P.walkTokens,Hr=P.parseInline,_r=pe.parse,Fr=de.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 Sl(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 u=d.groups??{},p=a.findIndex((E,B)=>u[`g${B}`]!==void 0),m=d[0];if(p<0){s.appendChild(e.createTextNode(m));continue}let f=a[p].cls,k=f==="word"?l.has(m)?"tok-kw":null:`tok-${f}`;if(i==="json"&&f==="str"&&t.slice(c).trimStart().startsWith(":")&&(k="tok-key"),k===null){s.appendChild(e.createTextNode(m));continue}let w=e.createElement("span");w.className=k,w.textContent=m,s.appendChild(w)}return c<t.length&&s.appendChild(e.createTextNode(t.slice(c))),s}function Sl(e,t,n){let i=n.split(`
85
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(`
86
+ `))})}var El=new Set(["http:","https:","mailto:"]);function Pi(e){let t=(e??"").trim();if(!t||t.startsWith("//"))return null;if(!/^[a-z][a-z0-9+.-]*:/i.test(t))return t;try{return El.has(new URL(t).protocol)?t:null}catch{return null}}var Di=e=>/^[a-z][a-z0-9+.-]*:/i.test(e)&&!e.startsWith("mailto:"),Hi=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
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}
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 u=v.trim();/^[-*+]$/.test(u)||/^\d{1,9}[.)]$/.test(u)||a()}return a(),n.length>1?n:null}function Tl(e){let t=new Map,n=0;function i(u,p){let m=u.length+Cl;if(!(m>Hi/4)){t.set(u,{fragment:p,chars:m}),n+=m;for(let f of t.keys()){if(n<=Hi)break;let k=t.get(f);k&&(t.delete(f),n-=k.chars)}}}function s(u,p){p.split(`
89
+ `).forEach((m,f)=>{f>0&&u.appendChild(e.createElement("br")),m&&u.appendChild(e.createTextNode(m))})}function a(u,p){switch(p.type){case"text":{if(p.tokens?.length){for(let m of p.tokens)a(u,m);return}s(u,p.text??p.raw??"");return}case"escape":u.appendChild(e.createTextNode(p.text??""));return;case"strong":case"em":case"del":{let m=e.createElement(p.type==="strong"?"strong":p.type==="em"?"em":"del");for(let f of p.tokens??[])a(m,f);u.appendChild(m);return}case"codespan":{let m=e.createElement("code");m.textContent=p.text??"",u.appendChild(m);return}case"br":u.appendChild(e.createElement("br"));return;case"link":{let m=p.tokens??[],f=Pi(p.href);if(!f){for(let w of m)a(u,w);return}let k=e.createElement("a");k.href=f,k.rel="noreferrer noopener",p.title&&(k.title=p.title),Di(f)&&(k.target="_blank");for(let w of m)a(k,w);u.appendChild(k);return}case"image":{let m=Pi(p.href),f=p.text?.trim()||p.href||"image";if(!m){u.appendChild(e.createTextNode(f));return}let k=e.createElement("a");k.href=m,k.textContent=f,k.rel="noreferrer noopener",Di(m)&&(k.target="_blank"),u.appendChild(k);return}case"html":u.appendChild(e.createTextNode(p.raw??p.text??""));return;default:if(p.tokens?.length){for(let m of p.tokens)a(u,m);return}s(u,p.text??p.raw??"")}}function l(u){let p=e.createElement("div");p.className="bv-code";let m=e.createElement("div");m.className="bv-code-head";let f=(u.lang??"").trim().split(/\s+/)[0]??"",k=e.createElement("span");k.className="bv-code-lang",k.textContent=f||"text";let w=e.createElement("button");w.type="button",w.className="bv-code-copy",w.textContent="Copy";let E=u.text??"";w.addEventListener("click",()=>{let T=navigator.clipboard?.writeText(E);T&&T.then(()=>{w.textContent="Copied",window.setTimeout(()=>{w.textContent="Copy"},1200)},()=>{})}),m.append(k,w);let B=e.createElement("pre"),$=e.createElement("code");return f&&($.className=`language-${f}`),$.appendChild(xl(e,E,f)),B.appendChild($),p.append(m,B),p}function r(u,p){let m=e.createElement("div");m.className="bv-table";let f=e.createElement("table"),k=e.createElement("thead"),w=e.createElement("tr"),E=p.align??[],B=(T,A,M)=>{let x=e.createElement(T);E[M]&&(x.style.textAlign=E[M]);for(let F of A.tokens??[])a(x,F);return x};(p.header??[]).forEach((T,A)=>w.appendChild(B("th",T,A))),k.appendChild(w);let $=e.createElement("tbody");for(let T of p.rows??[]){let A=e.createElement("tr");T.forEach((M,x)=>A.appendChild(B("td",M,x))),$.appendChild(A)}f.append(k,$),m.appendChild(f),u.appendChild(m)}function o(u,p){let m=e.createElement("li");if(p.task){let f=e.createElement("input");f.type="checkbox",f.disabled=!0,f.checked=p.checked===!0,m.appendChild(f)}for(let f of p.tokens??[])if(f.type==="text")a(m,f);else if(f.type==="paragraph")for(let k of f.tokens??[])a(m,k);else c(m,f);u.appendChild(m)}function c(u,p){switch(p.type){case"space":return;case"heading":{let m=Math.min(Math.max(p.depth??1,1),6),f=e.createElement(`h${m}`);for(let k of p.tokens??[])a(f,k);u.appendChild(f);return}case"paragraph":{let m=e.createElement("p");for(let f of p.tokens??[])a(m,f);u.appendChild(m);return}case"text":a(u,p);return;case"code":u.appendChild(l(p));return;case"blockquote":{let m=e.createElement("blockquote");for(let f of p.tokens??[])c(m,f);u.appendChild(m);return}case"list":{let m=p.items??p.tokens??[];if(p.ordered){let f=e.createElement("ol");typeof p.start=="number"&&p.start!==1&&(f.start=p.start);for(let k of m)o(f,k);u.appendChild(f)}else{let f=e.createElement("ul");for(let k of m)o(f,k);u.appendChild(f)}return}case"table":r(u,p);return;case"hr":u.appendChild(e.createElement("hr"));return;case"html":case"escape":u.appendChild(e.createTextNode(p.raw??p.text??""));return;default:if(p.tokens?.length){for(let m of p.tokens)c(u,m);return}p.text&&u.appendChild(e.createTextNode(p.text))}}function d(u){let p=e.createDocumentFragment();try{let m=P.lexer(u);for(let f of m)c(p,f)}catch{p.replaceChildren(e.createTextNode(u))}return p}function v(u){let p=t.get(u);if(p)return t.delete(u),t.set(u,p),p.fragment.cloneNode(!0);let m=d(u);return i(u,m),m.cloneNode(!0)}return u=>{let p=t.get(u);if(p)return t.delete(u),t.set(u,p),p.fragment.cloneNode(!0);let m=$l(u);if(m){let k=e.createDocumentFragment();for(let w of m)k.appendChild(v(w));return k}let f=d(u);return i(u,f),f.cloneNode(!0)}}var In=Tl(document),y={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,queues:new Map,ws:null,pollTimer:0,renderQueued:!1},Le=[],ke=!0,_i=200,Fi=_i,Il=!1,Ni=0;function An(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function j(e,t){let n=await fetch(e,{...t,headers:{"content-type":"application/json",Authorization:`Bearer ${An()}`,...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 ji(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(){Mn||(Mn=requestAnimationFrame(()=>{Mn=0,Al()}))}var Mn=0,Ht="";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===Ht)return;Ht=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(Ht==="")return;Ht="",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 qi=document.querySelector(".sidebar");qi&&new MutationObserver(De).observe(qi,{attributes:!0,attributeFilter:["class"]}),window.__syncBotsViewport=De;function _t(){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(),gt()}),t?.addEventListener("click",()=>{i(),Zl()}),n?.addEventListener("click",()=>{i(),jn()})}function Bl(){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"),Gi(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[S,z,G]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 V=g("button","bv-menu-item");V.dataset.mode=S,V.setAttribute("role","menuitemradio"),V.innerHTML=`<span class="bv-menu-icon">${le(Qi[S],'width="15" height="15"')}</span><span class="bv-menu-text"><b>${z}</b><span>${G}</span></span><span class="bv-menu-check">${le("check",'width="13" height="13"')}</span>`,V.onclick=()=>{d(!1),Dl(S)},c.appendChild(V)}let d=S=>{S&&A(!1),c.hidden=!S,o.setAttribute("aria-expanded",S?"true":"false")};o.onclick=S=>{S.stopPropagation(),d(c.hidden)},r.append(o);let v=g("button","btn bv-resume","Resume");v.id="bv-resume",v.type="button",v.title="Continue this bot from its session",v.onclick=()=>{y.activeId&&(v.disabled=!0,j(`/api/bots/${y.activeId}/resume`,{method:"POST"}).then(()=>re(!0)).finally(()=>{v.disabled=!1}))},v.hidden=!0;let u=g("button","btn bv-inbox");u.id="bv-inbox",u.title="Requests waiting for you";let p=g("span",void 0,"Needs you"),m=g("span","bv-inbox-count");m.id="bv-inbox-count",u.append(p,m),u.onclick=()=>void jn();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=le("dots",'width="16" height="16"');let k=g("div","bv-menu");k.id="bv-more-menu",k.setAttribute("role","menu"),k.hidden=!0;let w=(S,z,G,V)=>{let _e=g("button",`bv-menu-item${S?` ${S}`:""}`);return _e.type="button",_e.setAttribute("role","menuitem"),_e.innerHTML=`<span class="bv-menu-icon">${le(z,'width="15" height="15"')}</span><span class="bv-menu-text"><b>${G}</b></span>`,_e.onclick=()=>{A(!1),V()},_e},E=w("","check","Allow all",()=>{if(!y.activeId)return;let S=y.approvals.filter(z=>z.botId===y.activeId);Promise.all(S.map(z=>j(`/api/bots/${z.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:z.id,allow:!0})}))).finally(()=>void re(!0))});E.id="bv-allow-all",E.title="Approve every pending request for this bot";let B=w("","refresh","Resume bot",()=>Yi(S=>j(`/api/bots/${S}/resume`,{method:"POST"}).then(()=>re(!0)))),$=w("","stop","Stop run",()=>Yi(S=>j(`/api/bots/${S}/stop`,{method:"POST"}).then(()=>re(!0)))),T=w("danger","delete","Delete bot",()=>{y.activeId&&confirm("Delete this bot and its session?")&&j(`/api/bots/${y.activeId}`,{method:"DELETE"}).then(()=>{Pn(),re(!0)})});k.append(E,B,$,g("div","bv-menu-sep"),T);let A=S=>{S&&d(!1),k.hidden=!S,f.setAttribute("aria-expanded",S?"true":"false")};f.onclick=S=>{S.stopPropagation(),A(k.hidden)},document.addEventListener("click",S=>{let z=S.target;z&&(!r.contains(z)&&!c.contains(z)&&d(!1),!f.contains(z)&&!k.contains(z)&&A(!1))}),l.append(r,v,u,f),t.append(n,l);let M=g("div","bots-messages");M.id="bots-messages";let x=g("button","bv-jump");x.type="button",x.id="bv-jump",x.innerHTML=`${le("chevron-down",'width="14" height="14"')}<span>Latest</span>`,x.title="Jump to the latest message",x.hidden=!0,x.onclick=()=>{ke=!0,M.scrollTop=M.scrollHeight,x.hidden=!0};let F=()=>{ke=M.scrollHeight-M.scrollTop-M.clientHeight<48,x.hidden=ke};M.addEventListener("scroll",F,{passive:!0}),M.addEventListener("touchmove",()=>{ke=!1,x.hidden=M.scrollHeight-M.clientHeight<1},{passive:!0}),M.addEventListener("wheel",()=>{ke=!1},{passive:!0});let I=g("div","bots-composer-wrap"),K=g("div","bv-queue");K.id="bv-queue",K.hidden=!0;let N=g("span","bv-queue-text"),ge=g("button","bv-queue-clear","Clear");ge.type="button",ge.title="Drop the queued messages",ge.onclick=()=>{y.activeId&&j(`/api/bots/${y.activeId}/queue/clear`,{method:"POST"}).then(()=>zn(),S=>$e(S instanceof Error?S.message:String(S)))},K.append(N,ge);let Q=g("div","bv-attach-strip");Q.id="bv-attach-strip",Q.hidden=!0;let X=g("div","bv-composer-error");X.id="bv-composer-error",X.hidden=!0;let ze=g("div","bv-suggest");ze.id="bv-suggest",ze.hidden=!0;let ye=g("div","bots-composer"),U=g("button","bv-attach-btn");U.type="button",U.id="bv-attach",U.title="Attach an image",U.setAttribute("aria-label","Attach an image"),U.innerHTML=le("attach",'width="18" height="18"');let J=g("input");J.type="file",J.accept="image/*",J.multiple=!0,J.hidden=!0,U.onclick=()=>J.click(),J.onchange=()=>{for(let S of Array.from(J.files??[]))Bn(S);J.value=""};let O=g("textarea");O.id="bots-input",O.rows=1,O.placeholder="Message the bot\u2026",O.spellcheck=!1;let xe=window.matchMedia("(pointer: coarse)").matches;xe||(O.enterKeyHint="send"),O.onkeydown=S=>{Rl(S)||S.key!=="Enter"||S.shiftKey||S.isComposing||xe||S.keyCode===229||(S.preventDefault(),Zi())},O.oninput=()=>{$e(null),Ft(O),Ui()},O.onclick=()=>Ui(),O.addEventListener("paste",S=>{let z=Array.from(S.clipboardData?.files??[]).filter(G=>G.type.startsWith("image/"));if(z.length!==0){S.preventDefault();for(let G of z)Bn(G)}});let Se=g("button","btn primary");Se.id="bv-send",Se.title="Send",Se.setAttribute("aria-label","Send"),Se.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>',Se.onclick=()=>void Zi(),ye.append(U,O,Se),ye.addEventListener("click",S=>{let z=S.target;z?.closest("button")&&He(),!z?.closest("button")&&document.activeElement!==O&&O.focus()}),I.addEventListener("dragover",S=>{S.dataTransfer&&(S.preventDefault(),I.classList.add("drop-target"))}),I.addEventListener("dragleave",()=>I.classList.remove("drop-target")),I.addEventListener("drop",S=>{S.preventDefault(),I.classList.remove("drop-target");let z=Array.from(S.dataTransfer?.files??[]).filter(G=>G.type.startsWith("image/"));for(let G of z)Bn(G)}),I.append(K,Q,ze,X,J,ye),e.append(t,M,x,I,c,k),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 Oi(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 Te=[],Vi=4,zl=4*1024*1024;function Ft(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 Nt(){let e=document.getElementById("bv-attach-strip");e&&(e.textContent="",e.hidden=Te.length===0,Te.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=()=>{Te.splice(n,1),Nt()},i.append(s,a),e.appendChild(i)}))}async function Bn(e){if(!e.type.startsWith("image/")){$e("Only image attachments are supported.");return}if(Te.length>=Vi){$e(`At most ${Vi} images per message.`);return}if(e.size>zl){$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(",");Te.push({data:t.slice(n+1),mimeType:e.type,name:e.name||"image",preview:t}),$e(null),Nt()}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 Ie=[],Ge=0,jt=null;function He(){let e=document.getElementById("bv-suggest");e&&(e.hidden=!0),Ie=[],jt=null}function Rn(){let e=document.getElementById("bv-suggest");if(e){if(e.textContent="",Ie.length===0){e.hidden=!0;return}e.hidden=!1,Ie.forEach((t,n)=>{let i=g("button",`bv-suggest-item${n===Ge?" active":""}`);i.type="button",i.innerHTML=`<span class="bv-suggest-kind">${t.kind==="file"?"@":"/"}</span><span class="bv-suggest-label">${Wi(t.label)}</span><span class="bv-suggest-detail">${Wi(t.detail)}</span>`,i.onmousedown=s=>s.preventDefault(),i.onclick=()=>Ji(n),e.appendChild(i)})}}function Wi(e){return e.replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t])}async function Ui(){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(jt={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} `})),u=(d?.skills??[]).map(p=>({kind:"skill",label:`/skill:${p.name}`,detail:p.description||"skill",value:`/skill:${p.name} `}));Ie=[...v,...u].filter(p=>p.label.toLowerCase().includes(a.toLowerCase())||p.detail.toLowerCase().includes(a.toLowerCase())).slice(0,8),Ge=0,Rn();return}let l=ft();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{Ie=((await j(`/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"?"/":" "}`}}),Ge=0,Rn()}catch{He()}}function Ji(e){let t=document.getElementById("bots-input"),n=Ie[e];if(!t||!n||!jt)return;let{start:i,end:s}=jt;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),Ft(t)}function Rl(e){let t=document.getElementById("bv-suggest");if(!t||t.hidden||Ie.length===0)return!1;if(e.key==="ArrowDown"||e.key==="ArrowUp"){e.preventDefault();let n=e.key==="ArrowDown"?1:-1;return Ge=(Ge+n+Ie.length)%Ie.length,Rn(),!0}return e.key==="Enter"||e.key==="Tab"?(e.preventDefault(),Ji(Ge),!0):e.key==="Escape"?(e.preventDefault(),He(),!0):!1}async function Zi(){let e=document.getElementById("bots-input");if(!e||!y.activeId||Il||!e.value.trim()&&Te.length===0)return;let t=y.activeId,n=e.value.trim()?e.value:"See the attached image",i=Te.map(({data:s,mimeType:a})=>({data:s,mimeType:a}));$e(null),Oi(!0);try{await j(`/api/bots/${t}/input`,{method:"POST",body:JSON.stringify({text:n,images:i.length?i:void 0})}),e.value===n&&(e.value="",Ft(e)),He(),Te.length=0,Nt(),ke=!0}catch(s){$e(s instanceof Error?s.message:String(s))}finally{Oi(!1)}}function Yi(e){y.activeId&&e(y.activeId).catch(t=>Ve({kind:"notice",level:"error",text:t instanceof Error?t.message:String(t)}))}function Pn(){y.activeId=null,Le=[],ke=!0,De();let e=document.getElementById("bots-view");e&&(e.hidden=!0);try{y.ws?.close()}catch{}y.ws=null,_t();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 Xi(e){y.activeId=e,Le=[],ke=!0,Te.length=0,Nt(),zn(),He();let t=document.getElementById("bots-input");t&&(t.value="",Ft(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"),_t(),qt();let r=ft();r&&r.status==="stale"&&j(`/api/bots/${e}/resume`,{method:"POST"}).then(()=>re(!0)).catch(()=>{});try{y.ws?.close()}catch{}let o=location.protocol==="https:"?"wss:":"ws:",c=new WebSocket(`${o}//${location.host}/ws/bots/${encodeURIComponent(e)}?token=${encodeURIComponent(An())}`);y.ws=c,c.onmessage=d=>{try{es(JSON.parse(String(d.data)))}catch{}},c.onclose=()=>{y.activeId===e&&setTimeout(()=>{y.activeId===e&&re(!0)},1500)},await re(!0)}function ft(){return y.bots.find(e=>e.id===y.activeId)||null}function Dn(){let e=ft();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=ji(e.status),n.title=`${e.status.replace(/_/g," ")} \xB7 ${e.templateId} \xB7 ${e.projectPath}`);let s=document.getElementById("bv-mode-btn");s&&Gi(s,e.runtimeMode||"supervised");for(let o of document.querySelectorAll("#bv-mode-menu button")){let c=o.dataset.mode===e.runtimeMode;o.classList.toggle("active",c),o.setAttribute("aria-checked",c?"true":"false")}let a=document.getElementById("bv-resume");a&&(a.hidden=!["stale","completed","failed","cancelled"].includes(e.status));let l=document.getElementById("bv-allow-all"),r=y.approvals.filter(o=>o.botId===e.id).length;if(l){l.hidden=r===0;let o=l.querySelector(".bv-menu-text b");o&&(o.textContent=`Allow all (${r})`)}i&&(i.style.background=ji(e.status))}var Pl={queued:"queued",starting:"starting",running:"running",waiting_input:"waiting",waiting_approval:"approval",completed:"done",failed:"failed",cancelled:"stopped",stale:"stale"},Ki={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"},Qi={supervised:"shield","parent-supervised":"shield-up","full-access":"shield-alert"};function Gi(e,t){let n=Qi[t]??"shield";e.dataset.mode=t,e.innerHTML=le(n,'width="15" height="15"');let i=`\u5BA1\u6279\u6A21\u5F0F\uFF1A${Ki[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 j(`/api/bots/${y.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:e})});let t=ft();t&&(t.runtimeMode=e),Dn(),Ve({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${Ki[e]||e}`})}catch(t){Ve({kind:"notice",level:"error",text:t instanceof Error?t.message:String(t)})}}function Ve(e,t=y.activeId){if(!t)return;let n=y.items.get(t)||[];n.push(e),y.items.set(t,n),t===y.activeId&&We()}function We(){if(y.renderQueued)return;y.renderQueued=!0;let e=Math.max(0,60-(performance.now()-Ni));window.setTimeout(()=>{y.renderQueued=!1,Ni=performance.now(),qt()},e)}function Hn(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 _n(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 qt(){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-Fi),i=n?t.slice(n):t,s=ke;if(i.length<Le.length||i.some((a,l)=>Le[l]?.item!==a))e.textContent="",Le=i.map(a=>{let l=_n(a);return e.appendChild(l),{item:a,snapshot:Hn(a),node:l}});else{for(let a=Le.length;a<i.length;a++){let l=i[a],r=_n(l);e.appendChild(r),Le.push({item:l,snapshot:Hn(l),node:r})}for(let a=0;a<i.length;a++){let l=i[a],r=Le[a],o=Hn(l);if(Hl(r.snapshot,o)){if(l.kind==="assistant")_l(r.node,l);else{let c=_n(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;Fi+=_i,Le=[],qt(),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 u=g("pre","bv-pre bv-approval-detail");u.textContent=n.message,t.appendChild(u)}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(u,p,m)=>{let f=m.textContent??"";for(let k of d)k.disabled=!0;m.textContent=u?"Allowing\u2026":"Denying\u2026";try{await j(`/api/bots/${n.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:n.id,allow:u,always:p,reason:i.value||void 0})}),e.decided=u?"allowed":"denied",We(),re(!0)}catch(k){for(let w of d)w.disabled=!1;m.textContent=f,Ve({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 es(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")ke=!0,Ve({kind:"user",text:String(e.text||"")});else if(t==="status"){let s=ft();s&&(s.status=String(e.status||s.status)),Dn(),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),We()}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),We()}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),We()}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),We();return}}a.push({kind:"approval",approval:s}),y.items.set(n,a),We()}else t==="notice"&&Ve({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 re(e=!1){try{let[t,n]=await Promise.all([j("/api/bots"),j("/api/bots/approvals")]);if(y.bots=t,y.approvals=n,_t(),Dn(),e&&y.activeId){let i=await j(`/api/bots/${y.activeId}/events?limit=300`);Wl(i)}}catch{}}async function Vl(){try{y.bots=await j("/api/bots"),_t()}catch{}}function Wl(e){if(y.activeId){y.items.set(y.activeId,[]);for(let t of e)es(t);qt()}}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=le("close",'width="14" height="14"'),s.title="Close",s.onclick=()=>Ot(),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&&Ot()},document.body.appendChild(e)}function Fn(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 Ot(){let e=document.getElementById("bots-modal");e&&(e.hidden=!0)}async function Jl(){return y.catalog||(y.catalog=await j("/api/bots/catalog")),y.catalog}async function ts(){return y.templates=await j("/api/bots/templates"),y.templates}async function gt(){let e=Fn("Bot templates"),[t,n]=await Promise.all([Jl(),ts()]),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=()=>ns(e,t,o);let v=g("button","btn","Copy");v.title="Duplicate this template",v.onclick=()=>{let m=JSON.parse(JSON.stringify(o.manifest));m.name=`${o.manifest.name} copy`,j("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:m})}).then(()=>gt()).catch(f=>alert(f instanceof Error?f.message:String(f)))};let u=g("button","btn danger","Delete");u.onclick=()=>{confirm(`Delete template ${o.manifest.name}?`)&&j(`/api/bots/templates/${o.id}`,{method:"DELETE"}).then(()=>gt())};let p=g("span","bv-template-actions");p.append(d,v,u),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=()=>ns(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 ${An()}`}});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 j("/api/bots/import",{method:"POST",body:JSON.stringify(d)});alert(`Imported ${v.templates} templates, ${v.files} library files (${v.skipped} kept)`),await gt()}catch(d){alert(d instanceof Error?d.message:String(d))}})()},o.click()},s.append(a,l,r),e.appendChild(s)}function Nn(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 ns(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=Nn("Skills",t.skills.map(x=>({id:x.id,label:x.name,hint:x.description})),i.skills||[]),o=Nn("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=Nn("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 u=g("div","bv-check-grid"),p=[];for(let x of t.tools){let F=g("label","bv-check"),I=document.createElement("input");I.type="checkbox",I.checked=(i.tools?.allow||[]).includes(x.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(x.name),F.append(I,g("span",void 0,x.name)),u.appendChild(F),p.push({name:x.name,input:I})}v.appendChild(u);let m=g("input","bv-input");m.value=(i.tools?.deny||[]).join(", "),m.placeholder="Always deny (comma separated), e.g. bash, write";let f=g("textarea","bv-textarea");f.rows=2,f.value=(i.packages||[]).join(`
90
+ `),f.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
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">
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 E=g("select","bv-input");for(let x of["supervised","auto-accept-edits","full-access"])E.appendChild(new Option(x,x));E.value=i.permissions?.runtimeMode||"supervised";let B=g("select","bv-input");B.appendChild(new Option("ignore project .pi (recommended)","ignore")),B.appendChild(new Option("inherit project .pi (needs trust)","inherit")),B.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 A=(x,F)=>{let I=g("div","bv-field");return I.appendChild(g("label","bv-label",x)),I.appendChild(F),I};e.append(A("Name",s),A("Description",a),A("System prompt",l),r.element,o.element,c.element,A("MCP preset",d),v,A("Always deny tools",m),A("Packages",f),A("Model",k),A("Thinking level",w),A("Approval mode",E),A("Project resources",B),$);let M=g("button","btn primary",n?"Save template":"Create template");M.onclick=async()=>{let[x,F]=k.value.split(`
93
+ `),I=t.mcp.find(N=>N.id===d.value),K={name:s.value.trim()||"bot",description:a.value.trim()||void 0,system:l.value.trim()||void 0,skills:r.get(),extensions:o.get().map(N=>(N.startsWith("builtin:"),N)),prompts:c.get(),packages:f.value.split(`
94
+ `).map(N=>N.trim()).filter(Boolean),mcp:I?{mcpServers:I.servers}:void 0,tools:{allow:p.filter(N=>N.input.checked).map(N=>N.name),deny:m.value.split(",").map(N=>N.trim()).filter(Boolean)},model:x?{provider:x,id:F,thinking:w.value||void 0}:void 0,permissions:{runtimeMode:E.value},projectResources:B.value==="inherit"?"inherit":"ignore",orchestrator:T.checked||void 0};try{await j("/api/bots/templates",{method:"POST",body:JSON.stringify({id:n?.id,manifest:K})}),Ot(),await gt()}catch(N){alert(N instanceof Error?N.message:String(N))}},e.appendChild(M)}async function Zl(){return is("")}async function is(e){let t=Fn("New bot"),n=await ts();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(Vt("Template",i),Vt("Title",s),Vt("Project path",a),Vt("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:a.value.trim()||void 0,isolation:r.value})});Ot(),await re(!0),await Xi(c.id)}catch(c){alert(c instanceof Error?c.message:String(c))}},t.appendChild(o)}function Vt(e,t){let n=g("div","bv-field");return n.appendChild(g("label","bv-label",e)),n.appendChild(t),n}async function jn(){let e=Fn("Needs you");if(y.approvals=await j("/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 u of r)u.disabled=!0;d.textContent=c?"Allowing\u2026":"Denying\u2026";try{await j(`/api/bots/${t.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:t.id,allow:c,reason:i.value||void 0})}),await re(!0),await jn()}catch(u){for(let p of r)p.disabled=!1;d.textContent=v,Ve({kind:"notice",level:"error",text:u instanceof Error?u.message:String(u)})}};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,Bl(),Ml(),window.__openBot=Xi,document.addEventListener("click",e=>{let t=e.target;t&&(t.closest(".session-item.bot-item")||t.closest(".session-item")&&y.activeId&&setTimeout(()=>Pn(),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"))&&Pn()}),re(!0),y.pollTimer=window.setInterval(()=>{document.hidden||re()},6e3),window.addEventListener("beforeunload",()=>window.clearInterval(y.pollTimer)))}var Wt=null;function ss(e){return e.replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t])}function Ut(){Wt?.dispose(),Wt=null}function Xl(e){let t=Wt?.anchor===e.anchor;Ut(),!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">${le(o.icon,'width="15" height="15"')}</span><span class="bv-menu-text"><b>${ss(o.label)}</b>${o.detail?`<span>${ss(o.detail)}</span>`:""}</span>`,c.addEventListener("click",()=>{c.disabled||(Ut(),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),u=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(u)}px`}t.setAttribute("aria-expanded","true"),s[0]?.focus();let l=o=>{if(o.key==="Escape"){o.stopPropagation(),Ut(),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))||Ut()};document.addEventListener("keydown",l,!0),document.addEventListener("pointerdown",r,!0),Wt={anchor:t,dispose:()=>{document.removeEventListener("keydown",l,!0),document.removeEventListener("pointerdown",r,!0),i.remove(),t.setAttribute("aria-expanded","false")}}}var bt=window.__TMUX_WEB_SHELL__,q=null,Z=null,vt=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null,se=vt;window.__tmuxWebScopeAgent=vt;var qn="sessions",Ae="",Jt="",Zt="",as="";function te(e){return se?"/a/"+encodeURIComponent(se)+e:e}var D=document.getElementById("sidebar-content"),Ue=document.getElementById("main-placeholder"),oe=document.getElementById("terminal-container"),kt=document.getElementById("file-editor"),Ql=document.getElementById("fe-path"),ue=document.getElementById("fe-status"),wt=document.getElementById("fe-content"),Je=document.getElementById("fe-save"),Gl=document.getElementById("fe-delete"),er=document.getElementById("fe-back"),ls=document.getElementById("fe-new-name"),tr=document.getElementById("fe-new-btn"),On=document.getElementById("settings-backdrop"),rs=document.getElementById("settings-popover"),os=document.querySelector(".sidebar"),cs="tmux-web-force-narrow";function Yt(){try{return localStorage.getItem(cs)==="1"}catch{return!1}}function ds(){document.documentElement.classList.toggle("force-narrow",Yt()),Yt()&&Vn()&&Ze()}function Vn(){return Yt()?!0:window.matchMedia("(max-width: 640px)").matches}function ps(e){os.classList.toggle("open",e),document.getElementById("sidebar-backdrop")?.classList.toggle("open",e)}function Ze(){Vn()&&ps(!1)}function us(){ps(!0)}document.getElementById("sidebar-backdrop")?.addEventListener("click",()=>Ze()),window.addEventListener("keydown",e=>{e.key==="Escape"&&Vn()&&os.classList.contains("open")&&(e.stopPropagation(),Ze())}),window.__collapseSidebar=Ze,document.getElementById("mode-sessions").addEventListener("click",()=>{us(),hs("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{us(),hs("files")});function hs(e){qn=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"?(Wn="",Me()):br()}var Wn="";async function Me(){if(qn!=="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===Wn)return;Wn=i,or(t)}catch{D.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")}),Qn()}var ms="tmux-web-sidebar-group-collapsed";function fs(){try{return new Set(JSON.parse(localStorage.getItem(ms)||"[]"))}catch{return new Set}}function nr(e){try{localStorage.setItem(ms,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=`${le("bot",'class="bot-icon"')}<span>${H(e.title)}</span>`,t.addEventListener("click",n=>{n.stopPropagation(),window.__openBot?.(e.id)}),t}function gs(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),u=o.has(c),p=document.createElement("div");if(p.className="session-group-header"+(u?" collapsed":""),p.title=c||"No working directory",p.innerHTML=`<span class="sg-folder">&#128193;</span><span class="sg-label">${H(v)}</span>`,c){let f=document.createElement("button");f.className="sg-add-btn",f.innerHTML=le("add",'width="14" height="14"');let k=t&&c.startsWith(t)?`~${c.slice(t.length)}`:c;f.title=`New session or bot in ${k}`,f.setAttribute("aria-label",`New session or bot in ${k}`),f.setAttribute("aria-haspopup","menu"),f.setAttribute("aria-expanded","false"),f.addEventListener("click",w=>{w.stopPropagation(),Xl({anchor:f,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 Jn(c)}]})}),p.appendChild(f)}p.addEventListener("click",()=>{let f=fs(),k=p.nextElementSibling;f.has(c)?(f.delete(c),p.classList.remove("collapsed"),k?.classList.remove("collapsed")):(f.add(c),p.classList.add("collapsed"),k?.classList.add("collapsed")),nr(f)});let m=document.createElement("div");m.className="session-group-body"+(u?" collapsed":"");for(let f of d)m.appendChild(n?lr(f,n,i):rr(f));for(let f of l.get(c)||[])m.appendChild(ar(f));D.appendChild(p),D.appendChild(m)}}function lr(e,t,n){let i=document.createElement("div");i.className="session-item"+(e.name===Z&&se===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>${H(e.name)}</span>${n?"":'<span class="meta">offline</span>'}
96
+ <button class="session-edit-btn" data-session="${H(e.name)}" title="Edit session"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>`,n&&i.addEventListener("click",a=>{a.target.closest(".session-edit-btn")||yt(e.name,t)});let s=i.querySelector(".session-edit-btn");return s&&s.addEventListener("click",a=>{a.stopPropagation(),ln(e.name,s,{agentId:t})}),i}function rr(e){let t=document.createElement("div");t.className="session-item"+(e.name===Z&&!se?" 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>${H(e.name)}</span>
98
+ <button class="session-edit-btn" data-session="${H(e.name)}" title="Edit session"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>
99
+ `,t.addEventListener("click",i=>{i.target.closest(".session-edit-btn")||yt(e.name)});let n=t.querySelector(".session-edit-btn");return n&&n.addEventListener("click",i=>{i.stopPropagation(),ln(e.name,n)}),t}function or(e){D.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"+(vt?" clickable":""),n.textContent=vt?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",vt&&(n.title="Back to hub",n.addEventListener("click",()=>{window.location.href="/"})),D.appendChild(n),gs(t,e.home);let i=e.agents||[];for(let a of i){if(!a.sessions||a.sessions.length===0)continue;let l=a.agentId===se,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)+"/"})),D.appendChild(r),gs(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",D.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>${H(l.name)}</span><span class="meta">\u5931\u6548${o}</span>
101
+ <button class="session-edit-btn" data-session="${H(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",()=>{ln(l.name,r,{tombstone:!0,agentId:l.agentId})});let c=r.querySelector(".session-edit-btn");c&&c.addEventListener("click",d=>{d.stopPropagation(),ln(l.name,c,{tombstone:!0,agentId:l.agentId})}),D.appendChild(r)}}}function H(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}async function yt(e,t){if(Z===e&&q&&se===(t||null))return;kt.style.display="none",Ue.style.display="none",oe.style.display="",oe.classList.add("terminal-pending"),Ze(),q&&(sn(),q.destroy(),q=null),Z=e,se=t||null,window.__tmuxWebScopeAgent=se,window.__tmuxWebCurrentSession=Z,zr(e,t);let n=Kn(e,t);Ms.set(n,Date.now()+Mr);let i=nt.get(n);if(i&&i.state==="working"){i.state="idle",i.doneUntil=void 0,i.unread=!1;let s=D.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&&pn(s,n,i)}for(let s of D.querySelectorAll(".session-item"))s.classList.toggle("active",s.getAttribute("data-session")===e&&(s.getAttribute("data-agent")||null)===se);try{q=await na(oe,e,{terminal:bt.terminal,scrollback:bt.scrollback,theme:bt.theme,wsBase:se?"/ws/a/"+encodeURIComponent(se):bt.wsBase||"/ws"}),Ls()}catch(s){console.error("[shell] terminal init failed:",s);let a=s&&typeof s=="object"&&"message"in s?s.message:String(s);oe.textContent="Failed to open terminal for "+e+": "+a,oe.classList.remove("terminal-pending")}}var Xt=[],Y=null,bs=!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){bs=!0;try{let t=await fetch(te("/api/git/status?path="+encodeURIComponent(e)));t.ok?Y=await t.json():Y=null}catch{Y=null}finally{bs=!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">
102
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>
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>
103
+ ${H(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>"}D.addEventListener("click",e=>{e.target.closest(".sidebar-git")&&et&&Y&&(e.stopPropagation(),xs())});var xt=document.getElementById("header-git"),vs=document.getElementById("git-diff-view"),ks=document.getElementById("gd-path"),Kt=document.getElementById("gd-status"),Qt=document.getElementById("gd-content"),ur=document.getElementById("gd-back"),et=null;function St(e){if(!e||!e.branch){xt.style.display="none",et=null;return}et=e.repoRoot;let{branch:t,linesAdded:n,linesRemoved:i}=e,s=`<span class="branch">${H(t)}</span>`;(n>0||i>0)&&(s+=`<span class="sep">\xB7</span>+<span class="diff-add">${n}</span> <span class="diff-del">-${i}</span>`),xt.innerHTML=s,xt.style.display="block"}xt.addEventListener("click",e=>{et&&Y&&(e.stopPropagation(),xs())});var ae=document.getElementById("git-popover"),Gt=document.getElementById("git-popover-backdrop");function Un(){let e=xt.getBoundingClientRect();ae.style.top=e.bottom+4+"px",ae.style.left=Math.max(8,Math.min(e.left,window.innerWidth-400))+"px"}function ws(){let e=et,t=document.getElementById("git-popover-browse");t&&t.addEventListener("click",()=>{if(tn(),e){qn="files",document.querySelectorAll(".mode-btn").forEach(i=>i.classList.remove("active"));let n=document.getElementById("mode-files");n&&n.classList.add("active"),Be(e)}})}var ys="";function xs(){if(!Y)return;let e=Y.files||[];if(!e.length)ae.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
104
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>
105
+ ${l}<span class="file-path">${H(i.path)}</span>
106
106
  <span class="file-add">${s>0?"+"+s:""}</span>
107
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?`
108
+ </div>`}t+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',ys=t,ae.innerHTML=t,ae.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)))})}Un(),ae.classList.add("open"),Gt.classList.add("open"),ws()}function hr(){return window.innerWidth>=1024}function Ss(e,t){let n=(e+(t&&e?`
109
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">
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">${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("+"))a++,i+=`<div class="diff-line add"><span class="ln-no">${a}</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&&!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">${H(r)}</span></div>`}}return{html:i,lineCount:n.length}}var en=null;async function Es(e){let t=et;if(t)if(tn(),hr()){oe.style.display="none",q&&(sn(),q.destroy(),q=null,en=Z,Z=null),St(null),kt.style.display="none",Ue.style.display="none",vs.style.display="flex",ks.textContent=e,Kt.textContent="Loading\u2026",Qt.innerHTML="";try{let n=await fetch(te("/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);Kt.textContent="Error",Qt.innerHTML=`<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">Error: ${H(i)}</div>`}}else{ae.innerHTML=`<div class="git-diff-view"><div class="diff-header">
111
111
  <button class="diff-back">\u2190 Back</button>
112
- <span class="diff-filename">${F(e)}</span>
112
+ <span class="diff-filename">${H(e)}</span>
113
113
  <span class="diff-loading">Loading\u2026</span>
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">
114
+ </div></div>`,Un(),ae.classList.add("open"),Gt.classList.add("open");try{let n=await fetch(te("/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);ae.innerHTML=`<div class="git-diff-view"><div class="diff-header">
115
115
  <button class="diff-back">\u2190 Back</button>
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">
116
+ <span class="diff-filename">${H(e)}</span>
117
+ </div><div class="diff-empty">Error loading diff: ${H(i)}</div></div>`}}}function mr(e,t,n){if(!t&&!n){ae.innerHTML=`<div class="git-diff-view"><div class="diff-header">
118
118
  <button class="diff-back">\u2190 Back</button>
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">
119
+ <span class="diff-filename">${H(e)}</span>
120
+ </div><div class="diff-empty">No diff content available</div></div>`;return}let{html:i,lineCount:s}=Ss(t,n);ae.innerHTML=`<div class="git-diff-view"><div class="diff-header">
121
121
  <button class="diff-back">\u2190 Back</button>
122
- <span class="diff-filename">${F(e)}</span>
122
+ <span class="diff-filename">${H(e)}</span>
123
123
  <span class="diff-filesize">${s} lines</span>
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">
124
+ </div><div class="diff-content">${i}</div></div>`,ae.querySelector(".diff-back")?.addEventListener("click",()=>{ae.innerHTML=ys,Un(),Y&&ae.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)))}),ws()})}function fr(e,t,n){if(!t&&!n){Kt.textContent="No diff",Qt.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}=Ss(t,n);ks.textContent=e,Kt.textContent=s+" lines",Qt.innerHTML=i}function gr(){vs.style.display="none",en?(oe.style.display="",oe.classList.add("terminal-pending"),yt(en),en=null):Z?(oe.style.display="",oe.classList.add("terminal-pending"),Ls()):Ue.style.display="flex"}ur.addEventListener("click",gr);function tn(){ae.classList.remove("open"),Gt.classList.remove("open")}Gt.addEventListener("click",tn),document.addEventListener("keydown",e=>{e.key==="Escape"&&(tn(),dn())});async function Cs(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,St(i);return}}}catch{}Y=null,St(null)}var nn=null;function Ls(){sn(),Z&&(Cs(Z),nn=setInterval(()=>{Z&&Cs(Z)},3e4))}function sn(){nn&&(clearInterval(nn),nn=null)}async function Jn(e){let t=e;if(t.startsWith("~"))try{let n=await(await fetch(te("/api/fs/list?path="+encodeURIComponent(t)))).json();typeof n.path=="string"&&n.path&&(t=n.path)}catch{}t=t.replace(/\/+$/,"")||"/",is(t)}function $s(e,t){let n=document.createElement("button");n.className="file-tree-bot-btn",n.innerHTML=le("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(),Jn(t)}),e.appendChild(n)}function br(){if(Xt=bt.fsRoots||[],Xt.length===0){if(Z){vr(Z);return}Be("");return}D.innerHTML="";for(let e of Xt){let t=document.createElement("div");t.className="file-tree-item",t.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${H(e)}`,t.addEventListener("click",()=>Be(e)),$s(t,e),D.appendChild(t)}}async function vr(e){D.innerHTML='<div class="file-tree-empty">Loading...</div>';try{let t=await(await fetch(te("/api/fs/session-path?session="+encodeURIComponent(e)))).json();t.path?Be(t.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 Be(e){Ae=e,D.innerHTML='<div class="file-tree-empty">Loading...</div>';let t=dr(e);try{let n=await(await fetch(te("/api/fs/list?path="+encodeURIComponent(e)))).json(),i=typeof n.path=="string"&&n.path?n.path:e;if(i&&(Ae=i),await t,D.innerHTML="",i){let l=document.createElement("div");l.className="file-tree-item file-tree-create-bot",l.innerHTML=`<span class="file-tree-bot-plus">${le("add",'width="11" height="11"')}</span> Create bot in this folder`,l.title=`Create bot in ${i}`,l.addEventListener("click",()=>void Jn(i)),D.appendChild(l)}St(Y),D.innerHTML+=pr();let s=kr(i||e);if(s&&!Xt.some(l=>i===l)){let l=document.createElement("div");l.className="file-tree-item",l.innerHTML="..",l.addEventListener("click",()=>Be(s)),D.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> ${H(r)}`,o.addEventListener("click",()=>Be(l)),$s(o,l),D.appendChild(o)}else D.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}${H(r)}`,v.addEventListener("click",()=>wr(l)),D.appendChild(v)}}catch{D.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){Jt=e,oe.style.display="none",q&&(sn(),q.destroy(),q=null,Z=null),St(null),Ze(),Ue.style.display="none",kt.style.display="flex",Ql.textContent=e,ue.textContent="Loading...",Je.style.display="none";try{let t=await fetch(te("/api/file?path="+encodeURIComponent(e)));if(!t.ok){let i=await t.json();ue.textContent=i.error||"Failed to load",wt.value="";return}let n=await t.json();wt.value=n.content,Zt=n.content,as=n.content,ue.textContent=n.size+" bytes",Je.style.display=""}catch{ue.textContent="Failed to load",wt.value=""}}wt.addEventListener("input",()=>{Zt=wt.value}),Je.addEventListener("click",async()=>{Je.textContent="Saving...",Je.disabled=!0;try{let e=await fetch(te("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Jt,content:Zt})});if(!e.ok){let t=await e.json();ue.textContent=t.error||"Save failed";return}as=Zt,ue.textContent="Saved"}catch{ue.textContent="Save failed"}finally{Je.disabled=!1,Je.textContent="Save"}}),Gl.addEventListener("click",async()=>{if(confirm("Delete "+Jt+"?"))try{let e=await fetch(te("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Jt})});if(!e.ok){let t=await e.json();ue.textContent=t.error||"Delete failed";return}kt.style.display="none",Ue.style.display="flex",Ae&&Be(Ae)}catch{ue.textContent="Delete failed"}}),er.addEventListener("click",()=>{kt.style.display="none",Ue.style.display="flex",Ae&&Be(Ae)}),tr.addEventListener("click",async()=>{let e=ls.value.trim();if(!e)return;let t=Ae+"/"+e;try{let n=await fetch(te("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!n.ok){let i=await n.json();ue.textContent=i.error||"Create failed";return}ls.value="",Ae&&Be(Ae)}catch{ue.textContent="Create failed"}});var an=document.getElementById("force-narrow-toggle");an&&(an.checked=Yt(),an.addEventListener("change",()=>{try{localStorage.setItem(cs,an.checked?"1":"0")}catch{}ds(),Me()})),ds(),document.getElementById("mode-settings").addEventListener("click",()=>{let e=rs.classList.toggle("open");On.classList.toggle("open",e)}),On.addEventListener("click",()=>{rs.classList.remove("open"),On.classList.remove("open")});var ce="",he=!1,me,Et=document.createElement("div");Et.className="session-popover-backdrop",document.body.appendChild(Et);var fe=document.createElement("div");fe.id="session-popover",fe.className="session-popover",fe.style.display="none",fe.innerHTML=`<div class="sp-field">
125
125
  <label>Rename session</label>
126
126
  <input type="text" id="sp-name" />
127
127
  </div>
@@ -131,5 +131,5 @@ ${i.model.id}`);let w=g("select","bv-input");for(let x of["","off","minimal","lo
131
131
  <button class="btn danger sp-delete" id="sp-delete">Delete</button>
132
132
  </div>
133
133
  <hr class="sp-divider" id="sp-divider" />
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();
134
+ <button class="btn primary" id="sp-rebuild" style="display:none">\u91CD\u5EFA\u540C\u540D\u540C\u8DEF\u5F84 session</button>`,document.body.appendChild(fe);function yr(e){let t=e.getBoundingClientRect(),n=window.innerHeight,i=fe.offsetHeight||240,s=t.bottom+4;s+i>n-8&&(s=Math.max(8,t.top-i-4)),fe.style.top=s+"px",fe.style.left=Math.max(8,Math.min(t.left,window.innerWidth-240))+"px"}function ln(e,t,n){ce=e,he=!!n?.tombstone,me=n?.agentId;let i=document.getElementById("sp-name");i.value=e;let s=fe.querySelector(".sp-field label");s.textContent=he?"\u91CD\u547D\u540D (\u4EC5\u8BB0\u5F55\uFF0C\u4E0D\u91CD\u5EFA)":"Rename session";let a=document.getElementById("sp-rebuild");a.style.display=he?"":"none";let l=document.getElementById("sp-delete");l.textContent=he?"\u5220\u9664\u8BB0\u5F55":"Delete",l.title=he?"\u5220\u9664\u5931\u6548\u8BB0\u5F55\uFF08\u5893\u7891\u6D88\u5931\uFF09":"Delete session";let r=document.getElementById("sp-divider");r&&(r.style.display=he?"":"none");let o=document.getElementById("sp-save");o.textContent=he?"\u91CD\u547D\u540D":"Save",Et.classList.add("open"),fe.style.display="block",yr(t),setTimeout(()=>i.focus(),50)}function Ye(){Et.classList.remove("open"),fe.style.display="none"}Et.addEventListener("click",Ye),document.getElementById("sp-save").addEventListener("click",async()=>{let e=document.getElementById("sp-name").value.trim();if(!e||e===ce){Ye();return}try{let t=he?{oldName:ce,newName:e,agentId:me}:{oldName:ce,newName:e,...me?{agentId:me}:{}};if(!(await fetch(te(he?"/api/sessions/rename-tombstone":"/api/sessions/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok)return;Ye(),Me(),!he&&Z===ce&&(me??null)===se&&yt(e,me)}catch{}}),document.getElementById("sp-rebuild").addEventListener("click",async()=>{if(confirm('\u91CD\u5EFA\u4F1A\u8BDD "'+ce+'" (\u540C\u540D\u540C\u8DEF\u5F84\uFF0C\u5185\u5BB9\u4E3A\u7A7A)\uFF1F'))try{let e=await fetch(te("/api/sessions/rebuild"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ce,agentId:me})});if(!e.ok){let t=await e.json();alert(t.error||"\u91CD\u5EFA\u5931\u8D25");return}Ye(),Me()}catch{}}),document.getElementById("sp-delete").addEventListener("click",async()=>{if(he){if(!confirm('\u5220\u9664\u5931\u6548\u8BB0\u5F55 "'+ce+'"\uFF1F'))return;try{if(!(await fetch(te("/api/sessions/dismiss"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ce,agentId:me})})).ok)return;Ye(),Me()}catch{}return}if(confirm('Delete session "'+ce+'"?'))try{if(!(await fetch(te("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ce,...me?{agentId:me}:{}})})).ok)return;Ye(),Z===ce&&(me??null)===se&&(q&&(q.destroy(),q=null),Z=null,oe.style.display="none",Ue.style.display="flex"),Me()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",Ye);var Ts={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"},rn=document.getElementById("mobile-keys"),xr=new Set(["up","down","left","right","tab","s-tab","space"]),Sr=400,Er=80,Ct=0,on=0,cn=!1;function Cr(){Ct&&(clearTimeout(Ct),Ct=0),on&&(clearInterval(on),on=0)}rn.addEventListener("mousedown",e=>{e.target.closest("button[data-key]")&&e.preventDefault()}),rn.addEventListener("pointerdown",e=>{let t=e.target.closest("button[data-key]");if(!t)return;let n=t.dataset.key;xr.has(n)&&(cn=!1,Ct=setTimeout(()=>{Ct=0,cn=!0,on=setInterval(()=>{let i=Ts[n];i&&q&&q.sendInput(i)},Er)},Sr))});for(let e of["pointerup","pointercancel","pointerleave"])rn.addEventListener(e,Cr);rn.addEventListener("click",e=>{let t=e.target.closest("button[data-key]");if(!t||!q)return;if(cn){cn=!1;return}let n=Ts[t.dataset.key];n&&(q.sendInput(n),q.focus())});var we=document.getElementById("mk-input"),Is=document.getElementById("mk-send");function As(){if(!we||!q)return;let e=we.value;e&&(q.sendInput(e+"\r"),we.value="",we.rows=1,q.focus())}if(we&&(we.addEventListener("input",()=>{we.rows=1;let e=we.value.split(`
135
+ `).length;we.rows=Math.min(e,4)}),we.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),As())})),Is&&Is.addEventListener("click",As),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"),Lt=document.getElementById("proc-list"),Lr=document.getElementById("proc-close"),Yn=document.getElementById("proc-backdrop"),$r=document.getElementById("header-ram");function Tr(){Lt.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(te("/api/system/processes")).then(e=>e.json()).then(e=>{if(!Array.isArray(e)||!e.length){Lt.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="'+H(n.command)+'">'+H(n.command)+'</span><button class="proc-kill" title="Kill PID '+n.pid+'">&times;</button></div>'}Lt.innerHTML=t;for(let n of Lt.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(te("/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(()=>{Lt.innerHTML='<div class="proc-empty">Failed to load</div>'})}function Ir(){Zn.classList.add("open"),Yn.classList.add("open"),Tr()}function dn(){Zn.classList.remove("open"),Yn.classList.remove("open")}$r.addEventListener("click",e=>{e.stopPropagation(),Zn.classList.contains("open")?dn():Ir()}),Lr.addEventListener("click",dn),Yn.addEventListener("click",dn);var Ar=2e3,$t=null,Xn=null,tt=new Map,nt=new Map,Mr=5e3,Ms=new Map;function Kn(e,t){return(t?"a:"+t+":":"l:")+e}function Br(e,t,n){let i=Kn(e,t);if(n==="working"){let c=Ms.get(i);if(c&&Date.now()<c)return}let s=nt.get(i),a=e===Z&&(t??null)===se,l=n==="idle"&&s?.state==="working";nt.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=D.querySelector(r);o&&pn(o,i,nt.get(i))}function pn(e,t,n){let i=tt.get(t);i&&(clearTimeout(i),tt.delete(t)),e.classList.remove("working","just-done");let s=n.session===Z&&(n.agentId??null)===se;n.state==="working"?e.classList.add("working"):s&&n.doneUntil&&Date.now()<n.doneUntil?(e.classList.add("just-done"),tt.set(t,setTimeout(()=>{e.classList.remove("just-done"),tt.delete(t)},Math.max(0,n.doneUntil-Date.now())))):!s&&n.unread&&e.classList.add("just-done")}function Qn(){for(let[e,t]of nt){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=D.querySelector(n);i&&pn(i,e,t)}}function zr(e,t){let n=Kn(e,t),i=nt.get(n);if(!i)return;let s=tt.get(n);s&&(clearTimeout(s),tt.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=D.querySelector(a);l&&pn(l,n,i)}function Bs(){if($t||Xn)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);$t=n,n.onmessage=i=>{try{let s=JSON.parse(String(i.data));s&&s.type==="session.activity"&&typeof s.session=="string"&&Br(s.session,s.agentId||void 0,s.state==="working"?"working":"idle")}catch{}},n.onclose=()=>{$t===n&&($t=null,Xn=setTimeout(()=>{Xn=null,Bs()},5e3))},n.onerror=()=>{try{n.close()}catch{}}}catch{$t=null}}window.__openSession=yt,window.__refreshSidebar=Me,Me(),Ze(),Qn(),Bs(),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Qn()}),setInterval(()=>{document.visibilityState==="visible"&&Me()},1e4),Yl();