tmux-weblink 2.2.50 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import{icon as D}from"../lib/icons.js";const a={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1};function R(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function f(t,e){const n=await fetch(t,{...e,headers:{"content-type":"application/json",Authorization:`Bearer ${R()}`,...e?.headers||{}}}),i=await n.text(),s=i?JSON.parse(i):null;if(!n.ok)throw new Error(s&&s.error||`HTTP ${n.status}`);return s}function o(t,e,n){const i=document.createElement(t);return e&&(i.className=e),n!==void 0&&(i.textContent=n),i}function nt(t){return t==="running"?"var(--panel-success)":t==="waiting_approval"||t==="waiting_input"?"#e0a23c":t==="failed"?"var(--panel-danger, #e5534b)":t==="completed"?"var(--panel-accent)":"var(--panel-muted)"}function P(){const t=document.getElementById("bots-view");if(!t)return;const e=window.visualViewport,n=window.matchMedia("(max-width: 640px)").matches,i=!document.querySelector(".sidebar")?.classList.contains("collapsed");if(a.activeId&&e&&n&&!i){const s=document.querySelector(".fixed-header"),l=s?Math.round(s.getBoundingClientRect().height):0;t.style.position="fixed",t.style.top=`${Math.round(e.offsetTop)+l}px`,t.style.left=`${Math.round(e.offsetLeft)}px`,t.style.width=`${Math.round(e.width)}px`,t.style.height=`${Math.max(120,Math.round(e.height)-l)}px`,t.style.right="auto",t.style.bottom="auto"}else t.style.position="",t.style.top="",t.style.left="",t.style.width="",t.style.height="",t.style.right="",t.style.bottom=""}window.visualViewport?.addEventListener("resize",P),window.visualViewport?.addEventListener("scroll",P),window.addEventListener("resize",P),document.addEventListener("click",()=>setTimeout(P,0));function j(){const t=a.approvals.length,e=document.getElementById("bots-inbox-badge");e&&(e.style.display=t?"inline-block":"none",e.textContent=String(t));const n=document.getElementById("bv-inbox-count");n&&(n.textContent=t?`(${t})`:""),window.__botsSnapshot=a.bots,window.__refreshSidebar?.()}function ot(){const t=document.getElementById("set-bot-templates"),e=document.getElementById("set-bot-new"),n=document.getElementById("set-bot-inbox"),i=()=>{document.getElementById("settings-popover")?.classList.remove("open"),document.getElementById("settings-backdrop")?.classList.remove("open")};t?.addEventListener("click",()=>{i(),A()}),e?.addEventListener("click",()=>{i(),bt()}),n?.addEventListener("click",()=>{i(),Q()})}function it(){const t=o("div","bots-view");t.id="bots-view",t.hidden=!0;const e=o("div","bots-view-head"),n=o("div","bv-title"),i=o("span","bots-dot");i.id="bv-dot";const s=o("span","bv-title-text");s.id="bv-title";const l=o("span","bv-status");l.id="bv-status",n.append(i,s,l);const d=o("div","bv-actions"),p=o("div","bv-mode"),r=o("button","bv-mode-btn");r.id="bv-mode-btn",r.type="button",r.title="\u5BA1\u6279\u6A21\u5F0F\uFF08\u70B9\u5F00\u770B\u8BF4\u660E\uFF09",r.innerHTML=`<span id="bv-mode-label"></span>${D("chevron-down",'width="12" height="12"')}`;const u=o("div","bv-mode-menu");u.id="bv-mode-menu",u.hidden=!0;for(const[b,v,L]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"]]){const c=o("button");c.dataset.mode=b,c.innerHTML=`<b>${v}</b><span>${L}</span>`,c.onclick=()=>{u.hidden=!0,st(b)},u.appendChild(c)}r.onclick=b=>{b.stopPropagation(),u.hidden=!u.hidden},p.append(r,u),document.addEventListener("click",b=>{p.contains(b.target)||(u.hidden=!0)});const m=o("button","btn","Allow all");m.id="bv-allow-all",m.title="Approve every pending request for this bot",m.onclick=()=>{if(!a.activeId)return;const b=a.approvals.filter(v=>v.botId===a.activeId);Promise.all(b.map(v=>f(`/api/bots/${v.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:v.id,allow:!0})}))).finally(()=>void S(!0))};const h=o("button","btn","Needs you "),I=o("span");I.id="bv-inbox-count",h.appendChild(I),h.onclick=()=>void Q();const E=o("button","btn","Resume");E.onclick=()=>void G(b=>f(`/api/bots/${b}/resume`,{method:"POST"}).then(()=>S(!0)));const C=o("button","btn danger","Stop");C.onclick=()=>void G(b=>f(`/api/bots/${b}/stop`,{method:"POST"}).then(()=>S(!0)));const y=o("button","btn","Delete");y.onclick=()=>{a.activeId&&confirm("Delete this bot and its session?")&&f(`/api/bots/${a.activeId}`,{method:"DELETE"}).then(()=>{H(),S(!0)})};const x=o("button","btn");x.innerHTML=D("close",'width="14" height="14"'),x.title="Close bot view",x.onclick=()=>H(),d.append(p,m,h,E,C,y,x),e.append(n,d);const O=o("div","bots-messages");O.id="bots-messages";const B=o("div","bots-composer"),w=o("textarea");w.id="bots-input",w.rows=1,w.placeholder="Message the bot\u2026 (Enter to send, Shift+Enter for newline)",w.onkeydown=b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),F())};const $=o("button","btn primary");$.title="Send",$.setAttribute("aria-label","Send"),$.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>',$.onclick=()=>void F(),B.append(w,$),t.append(e,O,B),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||ut()}async function F(){const t=document.getElementById("bots-input");if(!t||!a.activeId||!t.value.trim())return;const e=t.value;t.value="";try{await f(`/api/bots/${a.activeId}/input`,{method:"POST",body:JSON.stringify({text:e})})}catch(n){T({kind:"notice",level:"error",text:n instanceof Error?n.message:String(n)})}}function G(t){a.activeId&&t(a.activeId).catch(e=>T({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)}))}function H(){a.activeId=null,P();const t=document.getElementById("bots-view");t&&(t.hidden=!0);try{a.ws?.close()}catch{}a.ws=null,j();const e=document.getElementById("terminal-container"),n=document.getElementById("main-placeholder"),i=!!document.querySelector(".session-item.active:not(.bot-item)");e&&i?(e.style.display="",n&&(n.style.display="none")):n&&(n.style.display="")}async function K(t){a.activeId=t,window.__collapseSidebar?.(),P(),a.items.set(t,[]);const e=document.getElementById("bots-view");e&&(e.hidden=!1);const n=document.getElementById("main-placeholder");n&&(n.style.display="none");const i=document.getElementById("terminal-container");i&&(i.style.display="none");const s=document.getElementById("file-editor");s&&(s.style.display="none"),j(),U();try{a.ws?.close()}catch{}const l=location.protocol==="https:"?"wss:":"ws:",d=new WebSocket(`${l}//${location.host}/ws/bots/${encodeURIComponent(t)}?token=${encodeURIComponent(R())}`);a.ws=d,d.onmessage=p=>{try{X(JSON.parse(String(p.data)))}catch{}},d.onclose=()=>{a.activeId===t&&setTimeout(()=>{a.activeId===t&&S(!0)},1500)},await S(!0)}function q(){return a.bots.find(t=>t.id===a.activeId)||null}function W(){const t=q();if(!t)return;const e=document.getElementById("bv-title"),n=document.getElementById("bv-status"),i=document.getElementById("bv-dot");e&&(e.textContent=t.title),n&&(n.textContent=`${t.status.replace(/_/g," ")} \xB7 ${t.templateId} \xB7 ${t.projectPath}`);const s=document.getElementById("bv-mode-label");s&&t.runtimeMode&&(s.textContent=Y[t.runtimeMode]||t.runtimeMode);for(const p of document.querySelectorAll("#bv-mode-menu button"))p.classList.toggle("active",p.dataset.mode===t.runtimeMode);const l=document.getElementById("bv-allow-all"),d=a.approvals.filter(p=>p.botId===t.id).length;l&&(l.hidden=d===0,l.textContent=`Allow all (${d})`),i&&(i.style.background=nt(t.status))}const Y={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"};async function st(t){if(a.activeId)try{await f(`/api/bots/${a.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:t})});const e=q();e&&(e.runtimeMode=t),W(),T({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${Y[t]||t}`})}catch(e){T({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)})}}function T(t,e=a.activeId){if(!e)return;const n=a.items.get(e)||[];n.push(t),a.items.set(e,n),e===a.activeId&&M()}function M(){a.renderQueued||(a.renderQueued=!0,requestAnimationFrame(()=>{a.renderQueued=!1,U()}))}function U(){const t=document.getElementById("bots-messages");if(!t||!a.activeId)return;const e=a.items.get(a.activeId)||[];t.textContent="";let n=null;for(const i of e)if(i.kind==="user"){const s=o("div","bv-msg bv-user");s.textContent=i.text,t.appendChild(s),n=null}else if(i.kind==="assistant"){const s=o("div","bv-msg bv-assistant");if(i.thinking){const d=o("details","bv-thinking");d.appendChild(o("summary",void 0,"thinking")),d.appendChild(o("div",void 0,i.thinking)),s.appendChild(d)}const l=o("div","bv-text");l.textContent=i.text,s.appendChild(l),t.appendChild(s),n=l}else if(i.kind==="tool")t.appendChild(at(i)),n=null;else if(i.kind==="approval")t.appendChild(dt(i)),n=null;else if(i.kind==="notice"){const s=o("div",`bv-notice bv-notice-${i.level}`,i.text);t.appendChild(s)}n&&(n.scrollTop=n.scrollHeight),t.scrollTop=t.scrollHeight}function at(t){const e=o("details","bv-tool");e.open=t.phase!=="end"||!!t.isError;const n=o("summary"),i=o("span","bv-tool-name",t.name);if(n.appendChild(i),t.phase!=="end"&&n.appendChild(o("span","bv-tool-phase",t.phase)),t.isError&&n.appendChild(o("span","bv-tool-error","error")),typeof t.durationMs=="number"&&n.appendChild(o("span","bv-tool-meta",`${Math.round(t.durationMs)}ms`)),e.appendChild(n),t.args!==void 0){const s=o("pre","bv-pre");s.textContent=typeof t.args=="string"?t.args:JSON.stringify(t.args,null,2),e.appendChild(s)}if(t.output){const s=o("pre","bv-pre bv-output");s.textContent=t.output,e.appendChild(s)}return e}function dt(t){const e=o("div","bv-approval"),n=t.approval;if(e.appendChild(o("div","bv-approval-title",n.title)),n.message&&e.appendChild(o("pre","bv-pre",n.message)),t.decided)return e.appendChild(o("div","bv-approval-decided",t.decided==="allowed"?"Allowed":"Denied")),e;const i=o("input","bv-reason");i.placeholder="reason (optional)";const s=o("div","bv-approval-actions"),l=o("button","btn primary","Allow"),d=o("button","btn",n.method==="confirm"&&/^Allow (.+?)\?$/.test(n.title)?`Always allow ${/^Allow (.+?)\?$/.exec(n.title)?.[1]}`:"Always allow");d.hidden=n.method!=="confirm";const p=o("button","btn danger","Deny"),r=async(u,m=!1)=>{try{await f(`/api/bots/${n.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:n.id,allow:u,always:m,reason:i.value||void 0})}),t.decided=u?"allowed":"denied",M(),S(!0)}catch(h){T({kind:"notice",level:"error",text:h instanceof Error?h.message:String(h)})}};return l.onclick=()=>void r(!0),d.onclick=()=>void r(!0,!0),p.onclick=()=>void r(!1),s.append(i,l,d,p),e.appendChild(s),e}function X(t){const e=String(t.type||""),n=a.activeId;if(!n)return;const i=a.items.get(n)||[];if(e==="snapshot")a.items.set(n,[]);else if(e==="user")T({kind:"user",text:String(t.text||"")});else if(e==="status"){const s=q();s&&(s.status=String(t.status||s.status)),W(),ct()}else if(e==="message"){const s=t.message;if(!s||String(s.role||"")!=="assistant")return;const d=lt(s),p=rt(s),r=i[i.length-1];r&&r.kind==="assistant"?(r.text=d||r.text,r.thinking=p||r.thinking):i.push({kind:"assistant",text:d,thinking:p}),a.items.set(n,i),M()}else if(e==="delta"){const s=String(t.kind||""),l=String(t.delta||"");let d=i[i.length-1];(!d||d.kind!=="assistant")&&(i.push({kind:"assistant",text:"",thinking:""}),d=i[i.length-1]),d.kind==="assistant"&&(s==="text"?d.text+=l:s==="thinking"&&(d.thinking+=l)),a.items.set(n,i),M()}else if(e==="tool"){const s=String(t.callId||""),l=i.find(p=>p.kind==="tool"&&p.callId===s),d=String(t.phase||"start");l?(l.phase=d,d==="update"&&t.output&&(l.output=String(t.output)),d==="end"&&(t.output&&(l.output=String(t.output)),l.isError=t.isError===!0,typeof t.durationMs=="number"&&(l.durationMs=t.durationMs))):i.push({kind:"tool",callId:s,name:String(t.name||"tool"),args:t.args,output:t.output?String(t.output):void 0,isError:t.isError===!0,durationMs:typeof t.durationMs=="number"?t.durationMs:void 0,phase:d}),a.items.set(n,i),M()}else if(e==="approval"){const s=t.approval;if(!s)return;const l=i;for(let d=l.length-1;d>=0;d--){const p=l[d];if(p.kind==="approval"&&p.approval.id===s.id){p.approval=s,s.state!=="pending"&&(p.decided=s.state==="allowed"?"allowed":"denied"),a.items.set(n,l),M();return}}l.push({kind:"approval",approval:s}),a.items.set(n,l),M()}else e==="notice"&&T({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function lt(t){const e=t.content;return Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&n.type==="text"?String(n.text||""):"").join(""):String(t.text||"")}function rt(t){const e=t.content;return Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&n.type==="thinking"?String(n.thinking||""):"").join(""):""}async function S(t=!1){try{const[e,n]=await Promise.all([f("/api/bots"),f("/api/bots/approvals")]);if(a.bots=e,a.approvals=n,j(),W(),t&&a.activeId){const i=await f(`/api/bots/${a.activeId}/events?limit=300`);pt(i)}}catch{}}async function ct(){try{a.bots=await f("/api/bots"),j()}catch{}}function pt(t){if(a.activeId){a.items.set(a.activeId,[]);for(const e of t)X(e);U()}}function ut(){const t=o("div","bots-modal");t.id="bots-modal",t.hidden=!0;const e=o("div","bots-modal-card"),n=o("div","bots-modal-head"),i=o("span");i.id="bots-modal-title";const s=o("button","btn");s.innerHTML=D("close",'width="14" height="14"'),s.title="Close",s.onclick=()=>J(),n.append(i,s);const l=o("div","bots-modal-body");l.id="bots-modal-body",e.append(n,l),t.appendChild(e),t.onclick=d=>{d.target===t&&J()},document.body.appendChild(t)}function V(t){const e=document.getElementById("bots-modal"),n=document.getElementById("bots-modal-title"),i=document.getElementById("bots-modal-body");if(!e||!i)throw new Error("modal missing");return n&&(n.textContent=t),i.textContent="",e.hidden=!1,i}function J(){const t=document.getElementById("bots-modal");t&&(t.hidden=!0)}async function mt(){return a.catalog||(a.catalog=await f("/api/bots/catalog")),a.catalog}async function Z(){return a.templates=await f("/api/bots/templates"),a.templates}async function A(){const t=V("Bot templates"),[e,n]=await Promise.all([mt(),Z()]),i=o("div","bv-template-list");for(const r of n){const u=o("div","bv-template-row");u.appendChild(o("span","bv-template-name",r.manifest.name)),u.appendChild(o("span","bv-template-desc",r.manifest.description||""));const m=o("button","btn","Edit");m.onclick=()=>tt(t,e,r);const h=o("button","btn","Copy");h.title="Duplicate this template",h.onclick=()=>{const C=JSON.parse(JSON.stringify(r.manifest));C.name=`${r.manifest.name} copy`,f("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:C})}).then(()=>A()).catch(y=>alert(y instanceof Error?y.message:String(y)))};const I=o("button","btn danger","Delete");I.onclick=()=>{confirm(`Delete template ${r.manifest.name}?`)&&f(`/api/bots/templates/${r.id}`,{method:"DELETE"}).then(()=>A())};const E=o("span","bv-template-actions");E.append(m,h,I),u.appendChild(E),i.appendChild(u)}n.length===0&&i.appendChild(o("div","bots-empty","No templates yet")),t.appendChild(i);const s=o("div","bv-template-actions"),l=o("button","btn primary","New template");l.onclick=()=>tt(t,e,null);const d=o("button","btn","Export");d.title="Download templates + library as JSON",d.onclick=()=>{(async()=>{try{const r=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${R()}`}});if(!r.ok)throw new Error(`HTTP ${r.status}`);const u=await r.blob(),m=document.createElement("a");m.href=URL.createObjectURL(u),m.download=`tmux-weblink-bots-${new Date().toISOString().slice(0,10)}.json`,m.click(),setTimeout(()=>URL.revokeObjectURL(m.href),2e3)}catch(r){alert(r instanceof Error?r.message:String(r))}})()};const p=o("button","btn","Import");p.title="Restore templates from a JSON bundle",p.onclick=()=>{const r=document.createElement("input");r.type="file",r.accept="application/json,.json",r.onchange=()=>{const u=r.files?.[0];u&&(async()=>{try{const m=JSON.parse(await u.text()),h=await f("/api/bots/import",{method:"POST",body:JSON.stringify(m)});alert(`Imported ${h.templates} templates, ${h.files} library files (${h.skipped} kept)`),await A()}catch(m){alert(m instanceof Error?m.message:String(m))}})()},r.click()},s.append(l,d,p),t.appendChild(s)}function z(t,e,n){const i=o("div","bv-field");i.appendChild(o("label","bv-label",t));const s=o("div","bv-check-grid"),l=[];for(const d of e){const p=o("label","bv-check"),r=document.createElement("input");r.type="checkbox",r.checked=n.includes(d.id),p.append(r,o("span",void 0,d.label)),d.hint&&(p.title=d.hint),s.appendChild(p),l.push({id:d.id,input:r})}return i.appendChild(s),{element:i,get:()=>l.filter(d=>d.input.checked).map(d=>d.id)}}function tt(t,e,n){t.textContent="";const i=n?JSON.parse(JSON.stringify(n.manifest)):{name:"new-bot",description:""},s=o("input","bv-input");s.value=i.name,s.placeholder="Template name";const l=o("input","bv-input");l.value=i.description||"",l.placeholder="One line description";const d=o("textarea","bv-textarea");d.rows=6,d.value=i.system||"",d.placeholder="System prompt for this bot (written to SYSTEM.md)";const p=z("Skills",e.skills.map(c=>({id:c.id,label:c.name,hint:c.description})),i.skills||[]),r=z("Extensions (Pi builtins + library)",e.extensions.map(c=>({id:c.id,label:`${c.name}${c.kind==="builtin"?" (builtin)":""}`,hint:c.description})),(i.extensions||[]).map(c=>c.replace(/^.*\//,"").replace(/\.(js|ts)$/,""))),u=z("Prompt templates",e.prompts.map(c=>({id:c.id,label:c.name})),i.prompts||[]),m=o("select","bv-input");m.appendChild(new Option("none",""));for(const c of e.mcp)m.appendChild(new Option(c.name,c.id));i.mcp&&(m.value=e.mcp.find(c=>JSON.stringify(c.servers)===JSON.stringify(i.mcp?.mcpServers))?.id||"");const h=o("div","bv-field");h.appendChild(o("label","bv-label","Tools (allow list; deny always blocks)"));const I=o("div","bv-check-grid"),E=[];for(const c of e.tools){const N=o("label","bv-check"),k=document.createElement("input");k.type="checkbox",k.checked=(i.tools?.allow||[]).includes(c.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(c.name),N.append(k,o("span",void 0,c.name)),I.appendChild(N),E.push({name:c.name,input:k})}h.appendChild(I);const C=o("input","bv-input");C.value=(i.tools?.deny||[]).join(", "),C.placeholder="Always deny (comma separated), e.g. bash, write";const y=o("textarea","bv-textarea");y.rows=2,y.value=(i.packages||[]).join(`
2
- `),y.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";const x=o("select","bv-input");x.appendChild(new Option("default (Pi settings)",""));for(const c of e.models)x.appendChild(new Option(`${c.provider}/${c.model}`,`${c.provider}
3
- ${c.model}`));i.model?.provider&&i.model?.id&&(x.value=`${i.model.provider}
4
- ${i.model.id}`);const O=o("select","bv-input");for(const c of["","off","minimal","low","medium","high","xhigh","max"])O.appendChild(new Option(c||"default",c));i.model?.thinking&&(O.value=i.model.thinking);const B=o("select","bv-input");for(const c of["supervised","auto-accept-edits","full-access"])B.appendChild(new Option(c,c));B.value=i.permissions?.runtimeMode||"supervised";const w=o("select","bv-input");w.appendChild(new Option("ignore project .pi (recommended)","ignore")),w.appendChild(new Option("inherit project .pi (needs trust)","inherit")),w.value=i.projectResources||"ignore";const $=o("label","bv-check"),b=document.createElement("input");b.type="checkbox",b.checked=!!i.orchestrator,$.append(b,o("span",void 0,"Super bot: gets orchestration tools (create/stop/status child bots)"));const v=(c,N)=>{const k=o("div","bv-field");return k.appendChild(o("label","bv-label",c)),k.appendChild(N),k};t.append(v("Name",s),v("Description",l),v("System prompt",d),p.element,r.element,u.element,v("MCP preset",m),h,v("Always deny tools",C),v("Packages",y),v("Model",x),v("Thinking level",O),v("Approval mode",B),v("Project resources",w),$);const L=o("button","btn primary",n?"Save template":"Create template");L.onclick=async()=>{const[c,N]=x.value.split(`
5
- `),k=e.mcp.find(g=>g.id===m.value),et={name:s.value.trim()||"bot",description:l.value.trim()||void 0,system:d.value.trim()||void 0,skills:p.get(),extensions:r.get().map(g=>(g.startsWith("builtin:"),g)),prompts:u.get(),packages:y.value.split(`
6
- `).map(g=>g.trim()).filter(Boolean),mcp:k?{mcpServers:k.servers}:void 0,tools:{allow:E.filter(g=>g.input.checked).map(g=>g.name),deny:C.value.split(",").map(g=>g.trim()).filter(Boolean)},model:c?{provider:c,id:N,thinking:O.value||void 0}:void 0,permissions:{runtimeMode:B.value},projectResources:w.value==="inherit"?"inherit":"ignore",orchestrator:b.checked||void 0};try{await f("/api/bots/templates",{method:"POST",body:JSON.stringify({id:n?.id,manifest:et})}),J(),await A()}catch(g){alert(g instanceof Error?g.message:String(g))}},t.appendChild(L)}async function bt(){return ft("")}async function ft(t){const e=V("New bot"),n=await Z();if(n.length===0){e.appendChild(o("div","bots-empty","No templates yet \u2014 create one with \u201CNew template\u201D."));return}const i=o("select","bv-input");for(const u of n)i.appendChild(new Option(u.manifest.name,u.id));const s=o("input","bv-input");s.placeholder="Title (defaults to template name)";const l=o("input","bv-input");l.placeholder="/path/to/project";const d=t||a.bots[0]?.projectPath||"";l.value=d;const p=o("select","bv-input");p.appendChild(new Option("shared \u2014 run in the project folder","shared")),p.appendChild(new Option("worktree \u2014 isolated git worktree","worktree")),e.append(_("Template",i),_("Title",s),_("Project path",l),_("Workspace",p));const r=o("button","btn primary","Create bot");r.onclick=async()=>{try{const u=await f("/api/bots",{method:"POST",body:JSON.stringify({templateId:i.value,title:s.value.trim()||void 0,projectPath:l.value.trim()||void 0,isolation:p.value})});J(),await S(!0),await K(u.id)}catch(u){alert(u instanceof Error?u.message:String(u))}},e.appendChild(r)}function _(t,e){const n=o("div","bv-field");return n.appendChild(o("label","bv-label",t)),n.appendChild(e),n}async function Q(){const t=V("Needs you");if(a.approvals=await f("/api/bots/approvals"),a.approvals.length===0){t.appendChild(o("div","bots-empty","Nothing waiting."));return}for(const e of a.approvals){const n=o("div","bv-approval");n.appendChild(o("div","bv-approval-title",`${e.botTitle}: ${e.title}`)),e.message&&n.appendChild(o("pre","bv-pre",e.message));const i=o("input","bv-reason");i.placeholder="reason (optional)";const s=o("div","bv-approval-actions"),l=o("button","btn primary","Allow"),d=o("button","btn danger","Deny"),p=async r=>{await f(`/api/bots/${e.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:e.id,allow:r,reason:i.value||void 0})}),await S(!0),await Q()};l.onclick=()=>void p(!0),d.onclick=()=>void p(!1),s.append(i,l,d),n.appendChild(s),t.appendChild(n)}}function vt(){window.__botsInited||(window.__botsInited=!0,it(),ot(),window.__openBot=K,document.addEventListener("click",t=>{const e=t.target;e&&(e.closest(".session-item.bot-item")||e.closest(".session-item")&&a.activeId&&setTimeout(()=>H(),0))},!0),S(!0),a.pollTimer=window.setInterval(()=>{document.hidden||S()},6e3),window.addEventListener("beforeunload",()=>window.clearInterval(a.pollTimer)))}export{vt as initBots,ft as openNewBotForPath};
1
+ import{icon as H}from"../lib/icons.js";import{createMarkdownRenderer as bt}from"./markdown.js";const F=bt(document),l={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1};let A=[],E=!0,vt=!1,it=0;function U(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function b(t,e){const o=await fetch(t,{...e,headers:{"content-type":"application/json",Authorization:`Bearer ${U()}`,...e?.headers||{}}}),i=await o.text(),s=i?JSON.parse(i):null;if(!o.ok)throw new Error(s&&s.error||`HTTP ${o.status}`);return s}function n(t,e,o){const i=document.createElement(t);return e&&(i.className=e),o!==void 0&&(i.textContent=o),i}function gt(t){return t==="running"?"var(--panel-success)":t==="waiting_approval"||t==="waiting_input"?"#e0a23c":t==="failed"?"var(--panel-danger, #e5534b)":t==="completed"?"var(--panel-accent)":"var(--panel-muted)"}function N(){z||(z=requestAnimationFrame(()=>{z=0,yt()}))}let z=0,R="";function yt(){const t=document.getElementById("bots-view");if(!t)return;const e=window.visualViewport,o=window.matchMedia("(max-width: 640px)").matches,i=!document.querySelector(".sidebar")?.classList.contains("collapsed");if(l.activeId&&e&&o&&!i){const s=document.querySelector(".fixed-header"),r=s?Math.round(s.getBoundingClientRect().height):0,a=Math.round(e.offsetTop)+r,c=Math.round(e.offsetLeft),d=Math.round(e.width),m=Math.max(120,Math.round(e.height)-r),h=`fixed|${a}|${c}|${d}|${m}`;if(h===R)return;R=h,t.style.position="fixed",t.style.top=`${a}px`,t.style.left=`${c}px`,t.style.width=`${d}px`,t.style.height=`${m}px`,t.style.right="auto",t.style.bottom="auto"}else{if(R==="")return;R="",t.style.position="",t.style.top="",t.style.left="",t.style.width="",t.style.height="",t.style.right="",t.style.bottom=""}}window.visualViewport?.addEventListener("resize",N),window.visualViewport?.addEventListener("scroll",N),window.addEventListener("resize",N),document.addEventListener("click",N);const st=document.querySelector(".sidebar");st&&new MutationObserver(N).observe(st,{attributes:!0,attributeFilter:["class"]}),window.__syncBotsViewport=N;function q(){const t=l.approvals.length,e=document.getElementById("bots-inbox-badge");e&&(e.style.display=t?"inline-block":"none",e.textContent=String(t));const o=document.getElementById("bv-inbox-count");o&&(o.textContent=t?`(${t})`:""),window.__botsSnapshot=l.bots,window.__refreshSidebar?.()}function wt(){const t=document.getElementById("set-bot-templates"),e=document.getElementById("set-bot-new"),o=document.getElementById("set-bot-inbox"),i=()=>{document.getElementById("settings-popover")?.classList.remove("open"),document.getElementById("settings-backdrop")?.classList.remove("open")};t?.addEventListener("click",()=>{i(),D()}),e?.addEventListener("click",()=>{i(),Nt()}),o?.addEventListener("click",()=>{i(),ot()})}function kt(){const t=n("div","bots-view");t.id="bots-view",t.hidden=!0;const e=n("div","bots-view-head"),o=n("div","bv-title"),i=n("span","bots-dot");i.id="bv-dot";const s=n("span","bv-title-text");s.id="bv-title";const r=n("span","bv-status");r.id="bv-status",o.append(i,s,r);const a=n("div","bv-actions"),c=n("div","bv-mode"),d=n("button","bv-mode-btn");d.id="bv-mode-btn",d.type="button",d.setAttribute("aria-haspopup","menu"),d.setAttribute("aria-expanded","false"),ut(d,"supervised");const m=n("div","bv-mode-menu");m.id="bv-mode-menu",m.setAttribute("role","menu"),m.hidden=!0;for(const[u,B,v]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"]]){const _=n("button");_.dataset.mode=u,_.setAttribute("role","menuitemradio"),_.innerHTML=`<span class="bv-mode-row-icon">${H(pt[u],'width="14" height="14"')}</span><span class="bv-mode-row-text"><b>${B}</b><span>${v}</span></span><span class="bv-mode-row-check">${H("check",'width="13" height="13"')}</span>`,_.onclick=()=>{h(!1),St(u)},m.appendChild(_)}const h=u=>{m.hidden=!u,d.setAttribute("aria-expanded",u?"true":"false")};d.onclick=u=>{u.stopPropagation(),h(m.hidden)},c.append(d,m),document.addEventListener("click",u=>{c.contains(u.target)||h(!1)});const f=n("button","btn","Allow all");f.id="bv-allow-all",f.title="Approve every pending request for this bot",f.onclick=()=>{if(!l.activeId)return;const u=l.approvals.filter(B=>B.botId===l.activeId);Promise.all(u.map(B=>b(`/api/bots/${B.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:B.id,allow:!0})}))).finally(()=>void C(!0))};const $=n("button","btn","Needs you "),O=n("span");O.id="bv-inbox-count",$.appendChild(O),$.onclick=()=>void ot();const I=n("button","btn","Resume");I.onclick=()=>void dt(u=>b(`/api/bots/${u}/resume`,{method:"POST"}).then(()=>C(!0)));const x=n("button","btn danger","Stop");x.onclick=()=>void dt(u=>b(`/api/bots/${u}/stop`,{method:"POST"}).then(()=>C(!0)));const M=n("button","btn","Delete");M.onclick=()=>{l.activeId&&confirm("Delete this bot and its session?")&&b(`/api/bots/${l.activeId}`,{method:"DELETE"}).then(()=>{K(),C(!0)})},a.append(c,f,$,I,x,M),e.append(o,a);const g=n("div","bots-messages");g.id="bots-messages";const y=n("button","bv-jump");y.type="button",y.id="bv-jump",y.innerHTML=`${H("chevron-down",'width="14" height="14"')}<span>Latest</span>`,y.title="Jump to the latest message",y.hidden=!0,y.onclick=()=>{E=!0,g.scrollTop=g.scrollHeight,y.hidden=!0};const L=()=>{E=g.scrollHeight-g.scrollTop-g.clientHeight<48,y.hidden=E};g.addEventListener("scroll",L,{passive:!0}),g.addEventListener("touchmove",()=>{E=!1,y.hidden=g.scrollHeight-g.clientHeight<1},{passive:!0}),g.addEventListener("wheel",()=>{E=!1},{passive:!0});const J=n("div","bots-composer-wrap"),T=n("div","bv-composer-error");T.id="bv-composer-error",T.hidden=!0;const w=n("div","bots-composer"),k=n("textarea");k.id="bots-input",k.rows=1,k.placeholder="Message the bot\u2026",k.spellcheck=!1;const p=window.matchMedia("(pointer: coarse)").matches;p||(k.enterKeyHint="send"),k.onkeydown=u=>{u.key!=="Enter"||u.shiftKey||u.isComposing||p||u.keyCode===229||(u.preventDefault(),rt())},k.oninput=()=>Q(null);const S=n("button","btn primary");S.id="bv-send",S.title="Send",S.setAttribute("aria-label","Send"),S.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>',S.onclick=()=>void rt(),w.append(k,S),w.addEventListener("click",u=>{u.target?.closest("button")||document.activeElement!==k&&k.focus()}),J.append(T,w),t.append(e,g,y,J),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||Tt()}function Q(t){const e=document.getElementById("bv-composer-error");e&&(e.textContent=t??"",e.hidden=!t)}function at(t){const e=document.getElementById("bv-send");e&&(e.disabled=t,e.setAttribute("aria-busy",t?"true":"false"),e.title=t?"Sending\u2026":"Send")}async function rt(){const t=document.getElementById("bots-input");if(!t||!l.activeId||vt||!t.value.trim())return;const e=l.activeId,o=t.value;Q(null),at(!0);try{await b(`/api/bots/${e}/input`,{method:"POST",body:JSON.stringify({text:o})}),t.value===o&&(t.value=""),E=!0}catch(i){Q(i instanceof Error?i.message:String(i))}finally{at(!1)}}function dt(t){l.activeId&&t(l.activeId).catch(e=>P({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)}))}function K(){l.activeId=null,A=[],E=!0,N();const t=document.getElementById("bots-view");t&&(t.hidden=!0);try{l.ws?.close()}catch{}l.ws=null,q();const e=document.getElementById("terminal-container"),o=document.getElementById("main-placeholder"),i=!!document.querySelector(".session-item.active:not(.bot-item)");e&&i?(e.style.display="",o&&(o.style.display="none")):o&&(o.style.display="")}async function lt(t){l.activeId=t,A=[],E=!0;const e=document.getElementById("bv-jump");e&&(e.hidden=!0),window.__collapseSidebar?.(),N(),l.items.set(t,[]);const o=document.getElementById("bots-view");o&&(o.hidden=!1);const i=document.getElementById("main-placeholder");i&&(i.style.display="none");const s=document.getElementById("terminal-container");s&&(s.style.display="none");const r=document.getElementById("file-editor");r&&(r.style.display="none"),q(),tt();try{l.ws?.close()}catch{}const a=location.protocol==="https:"?"wss:":"ws:",c=new WebSocket(`${a}//${location.host}/ws/bots/${encodeURIComponent(t)}?token=${encodeURIComponent(U())}`);l.ws=c,c.onmessage=d=>{try{mt(JSON.parse(String(d.data)))}catch{}},c.onclose=()=>{l.activeId===t&&setTimeout(()=>{l.activeId===t&&C(!0)},1500)},await C(!0)}function G(){return l.bots.find(t=>t.id===l.activeId)||null}function Y(){const t=G();if(!t)return;const e=document.getElementById("bv-title"),o=document.getElementById("bv-status"),i=document.getElementById("bv-dot");e&&(e.textContent=t.title),o&&(o.textContent=`${t.status.replace(/_/g," ")} \xB7 ${t.templateId} \xB7 ${t.projectPath}`);const s=document.getElementById("bv-mode-btn");s&&ut(s,t.runtimeMode||"supervised");for(const c of document.querySelectorAll("#bv-mode-menu button")){const d=c.dataset.mode===t.runtimeMode;c.classList.toggle("active",d),c.setAttribute("aria-checked",d?"true":"false")}const r=document.getElementById("bv-allow-all"),a=l.approvals.filter(c=>c.botId===t.id).length;r&&(r.hidden=a===0,r.textContent=`Allow all (${a})`),i&&(i.style.background=gt(t.status))}const ct={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"},pt={supervised:"shield","parent-supervised":"shield-up","full-access":"shield-alert"};function ut(t,e){const o=pt[e]??"shield";t.dataset.mode=e,t.innerHTML=H(o,'width="15" height="15"');const i=`\u5BA1\u6279\u6A21\u5F0F\uFF1A${ct[e]??e}`;t.title=`${i}\uFF08\u70B9\u5F00\u53EF\u5207\u6362\uFF09`,t.setAttribute("aria-label",i)}async function St(t){if(l.activeId)try{await b(`/api/bots/${l.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:t})});const e=G();e&&(e.runtimeMode=t),Y(),P({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${ct[t]||t}`})}catch(e){P({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)})}}function P(t,e=l.activeId){if(!e)return;const o=l.items.get(e)||[];o.push(t),l.items.set(e,o),e===l.activeId&&j()}function j(){if(l.renderQueued)return;l.renderQueued=!0;const t=Math.max(0,60-(performance.now()-it));window.setTimeout(()=>{l.renderQueued=!1,it=performance.now(),tt()},t)}function X(t){switch(t.kind){case"assistant":return{text:t.text,thinking:t.thinking};case"tool":return{phase:t.phase,output:t.output,error:t.isError,durationMs:t.durationMs};case"approval":return{decided:t.decided,approvalState:t.approval.state};default:return{}}}function xt(t,e){return t.text!==e.text||t.thinking!==e.thinking||t.phase!==e.phase||t.output!==e.output||t.error!==e.error||t.durationMs!==e.durationMs||t.decided!==e.decided||t.approvalState!==e.approvalState}function Z(t){if(t.kind==="user"){const e=n("div","bv-msg bv-user");return e.appendChild(F(t.text)),e}if(t.kind==="assistant"){const e=n("div","bv-msg bv-assistant");if(t.thinking){const i=n("details","bv-thinking");i.appendChild(n("summary",void 0,"thinking")),i.appendChild(n("div",void 0,t.thinking)),e.appendChild(i)}const o=n("div","bv-text");return o.appendChild(F(t.text)),e.appendChild(o),e}return t.kind==="tool"?It(t):t.kind==="approval"?Et(t):n("div",`bv-notice bv-notice-${t.level}`,t.text)}function Ct(t,e){const o=t.querySelector("details.bv-thinking");if(e.thinking)if(o){const s=o.querySelector("div");s&&s.textContent!==e.thinking&&(s.textContent=e.thinking)}else{const s=n("details","bv-thinking");s.appendChild(n("summary",void 0,"thinking")),s.appendChild(n("div",void 0,e.thinking)),t.prepend(s)}else o&&o.remove();const i=t.querySelector(".bv-text");i&&i.replaceChildren(F(e.text))}function tt(){const t=document.getElementById("bots-messages");if(!t||!l.activeId||document.getElementById("bots-view")?.hidden)return;const e=l.items.get(l.activeId)||[],o=E;if(e.length<A.length||e.some((s,r)=>A[r]?.item!==s))t.textContent="",A=e.map(s=>{const r=Z(s);return t.appendChild(r),{item:s,snapshot:X(s),node:r}});else{for(let s=A.length;s<e.length;s++){const r=e[s],a=Z(r);t.appendChild(a),A.push({item:r,snapshot:X(r),node:a})}for(let s=0;s<e.length;s++){const r=e[s],a=A[s],c=X(r);if(xt(a.snapshot,c)){if(r.kind==="assistant")Ct(a.node,r);else{const d=Z(r);a.node.replaceWith(d),a.node=d}a.snapshot=c}}}o&&(t.scrollTop=t.scrollHeight)}function It(t){const e=n("details","bv-tool");e.open=t.phase!=="end"||!!t.isError;const o=n("summary"),i=n("span","bv-tool-name",t.name);if(o.appendChild(i),t.phase!=="end"&&o.appendChild(n("span","bv-tool-phase",t.phase)),t.isError&&o.appendChild(n("span","bv-tool-error","error")),typeof t.durationMs=="number"&&o.appendChild(n("span","bv-tool-meta",`${Math.round(t.durationMs)}ms`)),e.appendChild(o),t.args!==void 0){const s=n("pre","bv-pre");s.textContent=typeof t.args=="string"?t.args:JSON.stringify(t.args,null,2),e.appendChild(s)}if(t.output){const s=n("pre","bv-pre bv-output");s.textContent=t.output,e.appendChild(s)}return e}function Et(t){const e=n("div","bv-approval"),o=t.approval;if(e.appendChild(n("div","bv-approval-title",o.title)),o.message&&e.appendChild(n("pre","bv-pre",o.message)),t.decided)return e.appendChild(n("div","bv-approval-decided",t.decided==="allowed"?"Allowed":"Denied")),e;const i=n("input","bv-reason");i.placeholder="reason (optional)";const s=n("div","bv-approval-actions"),r=n("button","btn primary","Allow"),a=n("button","btn",o.method==="confirm"&&/^Allow (.+?)\?$/.test(o.title)?`Always allow ${/^Allow (.+?)\?$/.exec(o.title)?.[1]}`:"Always allow");a.hidden=o.method!=="confirm";const c=n("button","btn danger","Deny"),d=async(m,h=!1)=>{try{await b(`/api/bots/${o.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:o.id,allow:m,always:h,reason:i.value||void 0})}),t.decided=m?"allowed":"denied",j(),C(!0)}catch(f){P({kind:"notice",level:"error",text:f instanceof Error?f.message:String(f)})}};return r.onclick=()=>void d(!0),a.onclick=()=>void d(!0,!0),c.onclick=()=>void d(!1),s.append(i,r,a,c),e.appendChild(s),e}function mt(t){const e=String(t.type||""),o=l.activeId;if(!o)return;const i=l.items.get(o)||[];if(e==="snapshot")l.items.set(o,[]);else if(e==="user")E=!0,P({kind:"user",text:String(t.text||"")});else if(e==="status"){const s=G();s&&(s.status=String(t.status||s.status)),Y(),Ot()}else if(e==="message"){const s=t.message;if(!s||String(s.role||"")!=="assistant")return;const a=$t(s),c=Bt(s),d=i[i.length-1];d&&d.kind==="assistant"?(d.text=a||d.text,d.thinking=c||d.thinking):i.push({kind:"assistant",text:a,thinking:c}),l.items.set(o,i),j()}else if(e==="delta"){const s=String(t.kind||""),r=String(t.delta||"");let a=i[i.length-1];(!a||a.kind!=="assistant")&&(i.push({kind:"assistant",text:"",thinking:""}),a=i[i.length-1]),a.kind==="assistant"&&(s==="text"?a.text+=r:s==="thinking"&&(a.thinking+=r)),l.items.set(o,i),j()}else if(e==="tool"){const s=String(t.callId||""),r=i.find(c=>c.kind==="tool"&&c.callId===s),a=String(t.phase||"start");r?(r.phase=a,a==="update"&&t.output&&(r.output=String(t.output)),a==="end"&&(t.output&&(r.output=String(t.output)),r.isError=t.isError===!0,typeof t.durationMs=="number"&&(r.durationMs=t.durationMs))):i.push({kind:"tool",callId:s,name:String(t.name||"tool"),args:t.args,output:t.output?String(t.output):void 0,isError:t.isError===!0,durationMs:typeof t.durationMs=="number"?t.durationMs:void 0,phase:a}),l.items.set(o,i),j()}else if(e==="approval"){const s=t.approval;if(!s)return;const r=i;for(let a=r.length-1;a>=0;a--){const c=r[a];if(c.kind==="approval"&&c.approval.id===s.id){c.approval=s,s.state!=="pending"&&(c.decided=s.state==="allowed"?"allowed":"denied"),l.items.set(o,r),j();return}}r.push({kind:"approval",approval:s}),l.items.set(o,r),j()}else e==="notice"&&P({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function $t(t){const e=t.content;return Array.isArray(e)?e.map(o=>o&&typeof o=="object"&&o.type==="text"?String(o.text||""):"").join(""):String(t.text||"")}function Bt(t){const e=t.content;return Array.isArray(e)?e.map(o=>o&&typeof o=="object"&&o.type==="thinking"?String(o.thinking||""):"").join(""):""}async function C(t=!1){try{const[e,o]=await Promise.all([b("/api/bots"),b("/api/bots/approvals")]);if(l.bots=e,l.approvals=o,q(),Y(),t&&l.activeId){const i=await b(`/api/bots/${l.activeId}/events?limit=300`);Mt(i)}}catch{}}async function Ot(){try{l.bots=await b("/api/bots"),q()}catch{}}function Mt(t){if(l.activeId){l.items.set(l.activeId,[]);for(const e of t)mt(e);tt()}}function Tt(){const t=n("div","bots-modal");t.id="bots-modal",t.hidden=!0;const e=n("div","bots-modal-card"),o=n("div","bots-modal-head"),i=n("span");i.id="bots-modal-title";const s=n("button","btn");s.innerHTML=H("close",'width="14" height="14"'),s.title="Close",s.onclick=()=>V(),o.append(i,s);const r=n("div","bots-modal-body");r.id="bots-modal-body",e.append(o,r),t.appendChild(e),t.onclick=a=>{a.target===t&&V()},document.body.appendChild(t)}function et(t){const e=document.getElementById("bots-modal"),o=document.getElementById("bots-modal-title"),i=document.getElementById("bots-modal-body");if(!e||!i)throw new Error("modal missing");return o&&(o.textContent=t),i.textContent="",e.hidden=!1,i}function V(){const t=document.getElementById("bots-modal");t&&(t.hidden=!0)}async function At(){return l.catalog||(l.catalog=await b("/api/bots/catalog")),l.catalog}async function ht(){return l.templates=await b("/api/bots/templates"),l.templates}async function D(){const t=et("Bot templates"),[e,o]=await Promise.all([At(),ht()]),i=n("div","bv-template-list");for(const d of o){const m=n("div","bv-template-row");m.appendChild(n("span","bv-template-name",d.manifest.name)),m.appendChild(n("span","bv-template-desc",d.manifest.description||""));const h=n("button","btn","Edit");h.onclick=()=>ft(t,e,d);const f=n("button","btn","Copy");f.title="Duplicate this template",f.onclick=()=>{const I=JSON.parse(JSON.stringify(d.manifest));I.name=`${d.manifest.name} copy`,b("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:I})}).then(()=>D()).catch(x=>alert(x instanceof Error?x.message:String(x)))};const $=n("button","btn danger","Delete");$.onclick=()=>{confirm(`Delete template ${d.manifest.name}?`)&&b(`/api/bots/templates/${d.id}`,{method:"DELETE"}).then(()=>D())};const O=n("span","bv-template-actions");O.append(h,f,$),m.appendChild(O),i.appendChild(m)}o.length===0&&i.appendChild(n("div","bots-empty","No templates yet")),t.appendChild(i);const s=n("div","bv-template-actions"),r=n("button","btn primary","New template");r.onclick=()=>ft(t,e,null);const a=n("button","btn","Export");a.title="Download templates + library as JSON",a.onclick=()=>{(async()=>{try{const d=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${U()}`}});if(!d.ok)throw new Error(`HTTP ${d.status}`);const m=await d.blob(),h=document.createElement("a");h.href=URL.createObjectURL(m),h.download=`tmux-weblink-bots-${new Date().toISOString().slice(0,10)}.json`,h.click(),setTimeout(()=>URL.revokeObjectURL(h.href),2e3)}catch(d){alert(d instanceof Error?d.message:String(d))}})()};const c=n("button","btn","Import");c.title="Restore templates from a JSON bundle",c.onclick=()=>{const d=document.createElement("input");d.type="file",d.accept="application/json,.json",d.onchange=()=>{const m=d.files?.[0];m&&(async()=>{try{const h=JSON.parse(await m.text()),f=await b("/api/bots/import",{method:"POST",body:JSON.stringify(h)});alert(`Imported ${f.templates} templates, ${f.files} library files (${f.skipped} kept)`),await D()}catch(h){alert(h instanceof Error?h.message:String(h))}})()},d.click()},s.append(r,a,c),t.appendChild(s)}function nt(t,e,o){const i=n("div","bv-field");i.appendChild(n("label","bv-label",t));const s=n("div","bv-check-grid"),r=[];for(const a of e){const c=n("label","bv-check"),d=document.createElement("input");d.type="checkbox",d.checked=o.includes(a.id),c.append(d,n("span",void 0,a.label)),a.hint&&(c.title=a.hint),s.appendChild(c),r.push({id:a.id,input:d})}return i.appendChild(s),{element:i,get:()=>r.filter(a=>a.input.checked).map(a=>a.id)}}function ft(t,e,o){t.textContent="";const i=o?JSON.parse(JSON.stringify(o.manifest)):{name:"new-bot",description:""},s=n("input","bv-input");s.value=i.name,s.placeholder="Template name";const r=n("input","bv-input");r.value=i.description||"",r.placeholder="One line description";const a=n("textarea","bv-textarea");a.rows=6,a.value=i.system||"",a.placeholder="System prompt for this bot (written to SYSTEM.md)";const c=nt("Skills",e.skills.map(p=>({id:p.id,label:p.name,hint:p.description})),i.skills||[]),d=nt("Extensions (Pi builtins + library)",e.extensions.map(p=>({id:p.id,label:`${p.name}${p.kind==="builtin"?" (builtin)":""}`,hint:p.description})),(i.extensions||[]).map(p=>p.replace(/^.*\//,"").replace(/\.(js|ts)$/,""))),m=nt("Prompt templates",e.prompts.map(p=>({id:p.id,label:p.name})),i.prompts||[]),h=n("select","bv-input");h.appendChild(new Option("none",""));for(const p of e.mcp)h.appendChild(new Option(p.name,p.id));i.mcp&&(h.value=e.mcp.find(p=>JSON.stringify(p.servers)===JSON.stringify(i.mcp?.mcpServers))?.id||"");const f=n("div","bv-field");f.appendChild(n("label","bv-label","Tools (allow list; deny always blocks)"));const $=n("div","bv-check-grid"),O=[];for(const p of e.tools){const S=n("label","bv-check"),u=document.createElement("input");u.type="checkbox",u.checked=(i.tools?.allow||[]).includes(p.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(p.name),S.append(u,n("span",void 0,p.name)),$.appendChild(S),O.push({name:p.name,input:u})}f.appendChild($);const I=n("input","bv-input");I.value=(i.tools?.deny||[]).join(", "),I.placeholder="Always deny (comma separated), e.g. bash, write";const x=n("textarea","bv-textarea");x.rows=2,x.value=(i.packages||[]).join(`
2
+ `),x.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";const M=n("select","bv-input");M.appendChild(new Option("default (Pi settings)",""));for(const p of e.models)M.appendChild(new Option(`${p.provider}/${p.model}`,`${p.provider}
3
+ ${p.model}`));i.model?.provider&&i.model?.id&&(M.value=`${i.model.provider}
4
+ ${i.model.id}`);const g=n("select","bv-input");for(const p of["","off","minimal","low","medium","high","xhigh","max"])g.appendChild(new Option(p||"default",p));i.model?.thinking&&(g.value=i.model.thinking);const y=n("select","bv-input");for(const p of["supervised","auto-accept-edits","full-access"])y.appendChild(new Option(p,p));y.value=i.permissions?.runtimeMode||"supervised";const L=n("select","bv-input");L.appendChild(new Option("ignore project .pi (recommended)","ignore")),L.appendChild(new Option("inherit project .pi (needs trust)","inherit")),L.value=i.projectResources||"ignore";const J=n("label","bv-check"),T=document.createElement("input");T.type="checkbox",T.checked=!!i.orchestrator,J.append(T,n("span",void 0,"Super bot: gets orchestration tools (create/stop/status child bots)"));const w=(p,S)=>{const u=n("div","bv-field");return u.appendChild(n("label","bv-label",p)),u.appendChild(S),u};t.append(w("Name",s),w("Description",r),w("System prompt",a),c.element,d.element,m.element,w("MCP preset",h),f,w("Always deny tools",I),w("Packages",x),w("Model",M),w("Thinking level",g),w("Approval mode",y),w("Project resources",L),J);const k=n("button","btn primary",o?"Save template":"Create template");k.onclick=async()=>{const[p,S]=M.value.split(`
5
+ `),u=e.mcp.find(v=>v.id===h.value),B={name:s.value.trim()||"bot",description:r.value.trim()||void 0,system:a.value.trim()||void 0,skills:c.get(),extensions:d.get().map(v=>(v.startsWith("builtin:"),v)),prompts:m.get(),packages:x.value.split(`
6
+ `).map(v=>v.trim()).filter(Boolean),mcp:u?{mcpServers:u.servers}:void 0,tools:{allow:O.filter(v=>v.input.checked).map(v=>v.name),deny:I.value.split(",").map(v=>v.trim()).filter(Boolean)},model:p?{provider:p,id:S,thinking:g.value||void 0}:void 0,permissions:{runtimeMode:y.value},projectResources:L.value==="inherit"?"inherit":"ignore",orchestrator:T.checked||void 0};try{await b("/api/bots/templates",{method:"POST",body:JSON.stringify({id:o?.id,manifest:B})}),V(),await D()}catch(v){alert(v instanceof Error?v.message:String(v))}},t.appendChild(k)}async function Nt(){return Lt("")}async function Lt(t){const e=et("New bot"),o=await ht();if(o.length===0){e.appendChild(n("div","bots-empty","No templates yet \u2014 create one with \u201CNew template\u201D."));return}const i=n("select","bv-input");for(const m of o)i.appendChild(new Option(m.manifest.name,m.id));const s=n("input","bv-input");s.placeholder="Title (defaults to template name)";const r=n("input","bv-input");r.placeholder="/path/to/project";const a=t||l.bots[0]?.projectPath||"";r.value=a;const c=n("select","bv-input");c.appendChild(new Option("shared \u2014 run in the project folder","shared")),c.appendChild(new Option("worktree \u2014 isolated git worktree","worktree")),e.append(W("Template",i),W("Title",s),W("Project path",r),W("Workspace",c));const d=n("button","btn primary","Create bot");d.onclick=async()=>{try{const m=await b("/api/bots",{method:"POST",body:JSON.stringify({templateId:i.value,title:s.value.trim()||void 0,projectPath:r.value.trim()||void 0,isolation:c.value})});V(),await C(!0),await lt(m.id)}catch(m){alert(m instanceof Error?m.message:String(m))}},e.appendChild(d)}function W(t,e){const o=n("div","bv-field");return o.appendChild(n("label","bv-label",t)),o.appendChild(e),o}async function ot(){const t=et("Needs you");if(l.approvals=await b("/api/bots/approvals"),l.approvals.length===0){t.appendChild(n("div","bots-empty","Nothing waiting."));return}for(const e of l.approvals){const o=n("div","bv-approval");o.appendChild(n("div","bv-approval-title",`${e.botTitle}: ${e.title}`)),e.message&&o.appendChild(n("pre","bv-pre",e.message));const i=n("input","bv-reason");i.placeholder="reason (optional)";const s=n("div","bv-approval-actions"),r=n("button","btn primary","Allow"),a=n("button","btn danger","Deny"),c=async d=>{await b(`/api/bots/${e.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:e.id,allow:d,reason:i.value||void 0})}),await C(!0),await ot()};r.onclick=()=>void c(!0),a.onclick=()=>void c(!1),s.append(i,r,a),o.appendChild(s),t.appendChild(o)}}function Jt(){window.__botsInited||(window.__botsInited=!0,kt(),wt(),window.__openBot=lt,document.addEventListener("click",t=>{const e=t.target;e&&(e.closest(".session-item.bot-item")||e.closest(".session-item")&&l.activeId&&setTimeout(()=>K(),0))},!0),document.addEventListener("click",t=>{const e=t.target;!e||!l.activeId||(e.closest("#mode-files")||e.closest(".file-tree-item")||e.closest(".file-roots-list li"))&&K()}),C(!0),l.pollTimer=window.setInterval(()=>{document.hidden||C()},6e3),window.addEventListener("beforeunload",()=>window.clearInterval(l.pollTimer)))}export{Jt as initBots,Lt as openNewBotForPath};
@@ -0,0 +1,2 @@
1
+ import{marked as R}from"marked";const H=new Set(["http:","https:","mailto:"]);function x(a){const s=(a??"").trim();if(!s||s.startsWith("//"))return null;if(!/^[a-z][a-z0-9+.-]*:/i.test(s))return s;try{return H.has(new URL(s).protocol)?s:null}catch{return null}}const y=a=>/^[a-z][a-z0-9+.-]*:/i.test(a)&&!a.startsWith("mailto:"),w=4e5,M=200;function z(a){const s=new Map;let E=0;function N(n,e){const t=n.length+M;if(!(t>w/4)){s.set(n,{fragment:e,chars:t}),E+=t;for(const r of s.keys()){if(E<=w)break;const c=s.get(r);c&&(s.delete(r),E-=c.chars)}}}function g(n,e){e.split(`
2
+ `).forEach((r,c)=>{c>0&&n.appendChild(a.createElement("br")),r&&n.appendChild(a.createTextNode(r))})}function o(n,e){switch(e.type){case"text":{if(e.tokens?.length){for(const t of e.tokens)o(n,t);return}g(n,e.text??e.raw??"");return}case"escape":n.appendChild(a.createTextNode(e.text??""));return;case"strong":case"em":case"del":{const t=a.createElement(e.type==="strong"?"strong":e.type==="em"?"em":"del");for(const r of e.tokens??[])o(t,r);n.appendChild(t);return}case"codespan":{const t=a.createElement("code");t.textContent=e.text??"",n.appendChild(t);return}case"br":n.appendChild(a.createElement("br"));return;case"link":{const t=e.tokens??[],r=x(e.href);if(!r){for(const l of t)o(n,l);return}const c=a.createElement("a");c.href=r,c.rel="noreferrer noopener",e.title&&(c.title=e.title),y(r)&&(c.target="_blank");for(const l of t)o(c,l);n.appendChild(c);return}case"image":{const t=x(e.href),r=e.text?.trim()||e.href||"image";if(!t){n.appendChild(a.createTextNode(r));return}const c=a.createElement("a");c.href=t,c.textContent=r,c.rel="noreferrer noopener",y(t)&&(c.target="_blank"),n.appendChild(c);return}case"html":n.appendChild(a.createTextNode(e.raw??e.text??""));return;default:if(e.tokens?.length){for(const t of e.tokens)o(n,t);return}g(n,e.text??e.raw??"")}}function v(n){const e=a.createElement("div");e.className="bv-code";const t=a.createElement("div");t.className="bv-code-head";const r=(n.lang??"").trim().split(/\s+/)[0]??"",c=a.createElement("span");c.className="bv-code-lang",c.textContent=r||"text";const l=a.createElement("button");l.type="button",l.className="bv-code-copy",l.textContent="Copy";const f=n.text??"";l.addEventListener("click",()=>{const i=navigator.clipboard?.writeText(f);i&&i.then(()=>{l.textContent="Copied",window.setTimeout(()=>{l.textContent="Copy"},1200)},()=>{})}),t.append(c,l);const p=a.createElement("pre"),d=a.createElement("code");return r&&(d.className=`language-${r}`),d.textContent=f,p.appendChild(d),e.append(t,p),e}function T(n,e){const t=a.createElement("div");t.className="bv-table";const r=a.createElement("table"),c=a.createElement("thead"),l=a.createElement("tr"),f=e.align??[],p=(i,h,C)=>{const u=a.createElement(i);f[C]&&(u.style.textAlign=f[C]);for(const A of h.tokens??[])o(u,A);return u};(e.header??[]).forEach((i,h)=>l.appendChild(p("th",i,h))),c.appendChild(l);const d=a.createElement("tbody");for(const i of e.rows??[]){const h=a.createElement("tr");i.forEach((C,u)=>h.appendChild(p("td",C,u))),d.appendChild(h)}r.append(c,d),t.appendChild(r),n.appendChild(t)}function b(n,e){const t=a.createElement("li");if(e.task){const r=a.createElement("input");r.type="checkbox",r.disabled=!0,r.checked=e.checked===!0,t.appendChild(r)}for(const r of e.tokens??[])if(r.type==="text")o(t,r);else if(r.type==="paragraph")for(const c of r.tokens??[])o(t,c);else m(t,r);n.appendChild(t)}function m(n,e){switch(e.type){case"space":return;case"heading":{const t=Math.min(Math.max(e.depth??1,1),6),r=a.createElement(`h${t}`);for(const c of e.tokens??[])o(r,c);n.appendChild(r);return}case"paragraph":{const t=a.createElement("p");for(const r of e.tokens??[])o(t,r);n.appendChild(t);return}case"text":o(n,e);return;case"code":n.appendChild(v(e));return;case"blockquote":{const t=a.createElement("blockquote");for(const r of e.tokens??[])m(t,r);n.appendChild(t);return}case"list":{const t=e.items??e.tokens??[];if(e.ordered){const r=a.createElement("ol");typeof e.start=="number"&&e.start!==1&&(r.start=e.start);for(const c of t)b(r,c);n.appendChild(r)}else{const r=a.createElement("ul");for(const c of t)b(r,c);n.appendChild(r)}return}case"table":T(n,e);return;case"hr":n.appendChild(a.createElement("hr"));return;case"html":case"escape":n.appendChild(a.createTextNode(e.raw??e.text??""));return;default:if(e.tokens?.length){for(const t of e.tokens)m(n,t);return}e.text&&n.appendChild(a.createTextNode(e.text))}}function _(n){const e=a.createDocumentFragment();try{const t=R.lexer(n);for(const r of t)m(e,r)}catch{e.replaceChildren(a.createTextNode(n))}return e}return n=>{const e=s.get(n);if(e)return s.delete(n),s.set(n,e),e.fragment.cloneNode(!0);const t=_(n);return N(n,t),t.cloneNode(!0)}}export{z as createMarkdownRenderer,x as safeHref};
@@ -1,4 +1,4 @@
1
- import{execFileSync as v}from"node:child_process";import{mkdirSync as m,readFileSync as w,rmSync as x,writeFileSync as I}from"node:fs";import p from"node:path";import k from"node:os";import{getBotStore as A}from"./store.js";import{materialize as B}from"./materialize.js";import{PiRpc as M}from"./rpc.js";import{buildCatalog as O,ORCHESTRATION_TOOLS as j,READONLY_TOOLS as D}from"./catalog.js";import{TERMINAL_STATUSES as d}from"./types.js";const f=4,E=8;class P{store=A();token;apiBase;runtimes=new Map;sockets=new Map;listeners=new Set;approvals=new Map;recent=new Map;constructor(t){this.token=this.store.token,this.apiBase=`http://127.0.0.1:${t}/api/bots`;for(const e of this.store.listInstances()){let s=!1;!d.includes(e.status)&&e.status!=="queued"&&(e.status="stale",s=!0);const n=g(e.runtimeMode);n!==e.runtimeMode&&(e.runtimeMode=n,s=!0),s&&this.store.saveInstance(e)}}listTemplates(){return this.store.listTemplates()}getTemplate(t){return this.store.getTemplate(t)}saveTemplate(t){return this.store.saveTemplate(t)}deleteTemplate(t){return this.store.deleteTemplate(t)}catalog(){return O()}listBots(t={}){return this.store.listInstances().filter(s=>!(t.project&&s.projectPath!==t.project||t.parentBotId&&s.parentBotId!==t.parentBotId||t.status&&s.status!==t.status))}getBot(t){return this.store.getInstance(t)}children(t){return this.store.listInstances().filter(e=>e.parentBotId===t)}createInstance(t){const e=this.getTemplate(t.templateId);if(!e)throw new Error(`unknown template: ${t.templateId}`);let s=null;if(t.parentBotId){if(s=this.getBot(t.parentBotId),!s)throw new Error("parent bot not found");if(s.depth+1>f)throw new Error(`nesting depth limit is ${f}`)}let n=t.projectPath||s?.projectPath||process.env.HOME||"/";n==="~"?n=k.homedir():n.startsWith("~/")&&(n=p.join(k.homedir(),n.slice(2)));const r=p.resolve(n),o=this.store.newId(),i=t.isolation||"shared";let a=r;if(i==="worktree"){const h=p.join(this.store.root,"worktrees",o);try{m(p.dirname(h),{recursive:!0,mode:448}),v("git",["-C",r,"worktree","add","-b",`tw-bot/${o.slice(0,8)}`,h],{timeout:2e4,stdio:"ignore"}),a=h}catch{a=r}}const c=new Date().toISOString(),u={id:o,templateId:e.id,title:t.title||e.manifest.name,projectPath:r,workspacePath:a,isolation:i,parentBotId:s?.id,depth:s?s.depth+1:0,runtimeMode:g(t.runtimeMode||e.manifest.permissions?.runtimeMode),projectResources:e.manifest.projectResources||"ignore",status:"queued",sessionFile:p.join(this.store.sessionsDir(o),`${o}.jsonl`),createdAt:c,updatedAt:c,model:e.manifest.model};return m(this.store.sessionsDir(o),{recursive:!0,mode:448}),this.store.saveInstance(u),this.emit(u.id,{type:"status",status:"queued",at:c}),this.pump(),u}activeInProject(t){return this.store.listInstances().filter(e=>e.projectPath===t&&!d.includes(e.status)&&e.status!=="queued").length}pump(){for(const t of this.store.listInstances())t.status==="queued"&&(this.activeInProject(t.projectPath)>=E||this.start(t))}start(t){const e=this.getTemplate(t.templateId);if(!e){this.setStatus(t.id,"failed","template disappeared");return}const s=B(e,t,{apiBase:this.apiBase,token:this.token}),n=e.manifest.binaryPath||"pi",r=new M({command:n,args:s.args,cwd:t.workspacePath,env:s.env,onEvent:o=>this.handleEvent(t.id,o),onStderr:o=>{/error|failed/i.test(o)&&this.emit(t.id,{type:"notice",level:"warn",text:o.slice(0,500),at:new Date().toISOString()})},onExit:()=>{this.runtimes.delete(t.id);const o=this.store.getInstance(t.id);o&&!d.includes(o.status)&&this.setStatus(t.id,"failed","pi exited unexpectedly"),this.pump()}});this.runtimes.set(t.id,r),t.status="starting",t.pid=void 0,this.store.saveInstance(t),this.emit(t.id,{type:"status",status:"starting",at:new Date().toISOString()}),r.start()}handleEvent(t,e){const s=String(e.type||""),n=new Date().toISOString();switch(s){case"agent_start":this.setStatus(t,"running");break;case"agent_end":break;case"agent_settled":this.setStatus(t,e.aborted===!0?"cancelled":"completed");break;case"message_start":case"message_end":{const r=e.message;if(r){if(s==="message_end"&&r.role==="assistant"){const o=this.store.getInstance(t),i=b(r);o&&i&&(o.lastText=i,this.store.saveInstance(o))}this.emit(t,{type:"message",message:r,at:n})}break}case"message_update":{const r=e.assistantMessageEvent;if(!r)break;const o=r.type==="text_delta"?"text":r.type==="thinking_delta"?"thinking":r.type==="toolcall_delta"?"tool-args":null;if(!o)break;const i=e.message;this.emit(t,{type:"delta",kind:o,delta:String(r.delta||""),contentIndex:typeof r.contentIndex=="number"?r.contentIndex:void 0,messageId:typeof i?.id=="string"?i.id:void 0,at:n});break}case"tool_execution_start":this.emit(t,{type:"tool",phase:"start",callId:String(e.toolCallId||""),name:String(e.toolName||"tool"),args:e.args,at:n});break;case"tool_execution_update":this.emit(t,{type:"tool",phase:"update",callId:String(e.toolCallId||""),name:String(e.toolName||"tool"),output:_(e.partialResult),at:n});break;case"tool_execution_end":this.emit(t,{type:"tool",phase:"end",callId:String(e.toolCallId||""),name:String(e.toolName||"tool"),output:_(e.result),isError:e.isError===!0,durationMs:typeof e.durationMs=="number"?e.durationMs:void 0,at:n});break;case"extension_ui_request":this.handleUiRequest(t,e);break;default:break}}handleUiRequest(t,e){const s=String(e.method||""),n=new Date().toISOString(),r=this.store.getInstance(t);if(s==="notify"){this.emit(t,{type:"notice",level:e.notifyType==="error"?"error":e.notifyType==="warning"?"warn":"info",text:String(e.message||""),at:n});return}if(!["confirm","select","input","editor"].includes(s))return;const o=String(e.id||""),i=o?this.approvals.get(t)?.get(o):void 0;if(i&&i.state==="pending")return;const a=String(e.title||"Approval required"),c=/^Allow (.+?)\?$/.exec(a),u={id:String(e.id||""),botId:t,botTitle:r?.title||t,kind:s==="confirm"?"tool":"question",method:s,title:a,toolName:c?c[1]:void 0,message:typeof e.message=="string"?e.message:void 0,options:Array.isArray(e.options)?e.options.map(String):void 0,state:"pending",createdAt:n};if(this.approvals.has(t)||this.approvals.set(t,new Map),this.approvals.get(t).set(u.id,u),r&&r.runtimeMode==="parent-supervised"&&r.parentBotId){const h=this.store.getInstance(r.parentBotId);if(h){u.escalatedTo=h.id;const S=u.message?u.message.slice(0,500):"",T=[`Child bot "${r.title}" (${r.id}) needs approval: ${u.title}`,S?`Arguments: ${S}`:"",`Decide with bot_approve({ botId: "${r.id}", requestId: "${u.id}", allow: true|false, reason: "..." }).`,"If you do nothing the user will answer it."].filter(Boolean).join(`
2
- `);this.input(h.id,T,"steer").catch(()=>{this.emit(t,{type:"notice",level:"warn",text:"Could not reach the supervising bot; waiting for the user.",at:n})})}}this.setStatus(t,"waiting_approval"),this.emit(t,{type:"approval",approval:u,at:n})}allowTool(t,e){if(!this.store.getInstance(t))throw new Error("bot not found");const n=p.join(this.store.agentDir(t),".allowed-tools");let r=[];try{r=JSON.parse(w(n,"utf8")),Array.isArray(r)||(r=[])}catch{r=[]}return r.includes(e)||r.push(e),m(p.dirname(n),{recursive:!0,mode:448}),I(n,`${JSON.stringify(r)}
1
+ import{execFileSync as v}from"node:child_process";import{mkdirSync as m,readFileSync as w,rmSync as x,writeFileSync as I}from"node:fs";import p from"node:path";import k from"node:os";import{getBotStore as A}from"./store.js";import{materialize as B}from"./materialize.js";import{PiRpc as M}from"./rpc.js";import{buildCatalog as O,ORCHESTRATION_TOOLS as j,READONLY_TOOLS as D}from"./catalog.js";import{TERMINAL_STATUSES as d}from"./types.js";const f=4,_=8,P=["starting","running","waiting_input","waiting_approval"];class b{store=A();token;apiBase;runtimes=new Map;sockets=new Map;listeners=new Set;approvals=new Map;recent=new Map;streaming=new Set;constructor(t){this.token=this.store.token,this.apiBase=`http://127.0.0.1:${t}/api/bots`;for(const e of this.store.listInstances()){let s=!1;!d.includes(e.status)&&e.status!=="queued"&&(e.status="stale",s=!0);const n=g(e.runtimeMode);n!==e.runtimeMode&&(e.runtimeMode=n,s=!0),s&&this.store.saveInstance(e)}}listTemplates(){return this.store.listTemplates()}getTemplate(t){return this.store.getTemplate(t)}saveTemplate(t){return this.store.saveTemplate(t)}deleteTemplate(t){return this.store.deleteTemplate(t)}catalog(){return O()}listBots(t={}){return this.store.listInstances().filter(s=>!(t.project&&s.projectPath!==t.project||t.parentBotId&&s.parentBotId!==t.parentBotId||t.status&&s.status!==t.status))}getBot(t){return this.store.getInstance(t)}children(t){return this.store.listInstances().filter(e=>e.parentBotId===t)}createInstance(t){const e=this.getTemplate(t.templateId);if(!e)throw new Error(`unknown template: ${t.templateId}`);let s=null;if(t.parentBotId){if(s=this.getBot(t.parentBotId),!s)throw new Error("parent bot not found");if(s.depth+1>f)throw new Error(`nesting depth limit is ${f}`)}let n=t.projectPath||s?.projectPath||process.env.HOME||"/";n==="~"?n=k.homedir():n.startsWith("~/")&&(n=p.join(k.homedir(),n.slice(2)));const r=p.resolve(n),o=this.store.newId(),i=t.isolation||"shared";let u=r;if(i==="worktree"){const h=p.join(this.store.root,"worktrees",o);try{m(p.dirname(h),{recursive:!0,mode:448}),v("git",["-C",r,"worktree","add","-b",`tw-bot/${o.slice(0,8)}`,h],{timeout:2e4,stdio:"ignore"}),u=h}catch{u=r}}const a=new Date().toISOString(),c={id:o,templateId:e.id,title:t.title||e.manifest.name,projectPath:r,workspacePath:u,isolation:i,parentBotId:s?.id,depth:s?s.depth+1:0,runtimeMode:g(t.runtimeMode||e.manifest.permissions?.runtimeMode),projectResources:e.manifest.projectResources||"ignore",status:"queued",sessionFile:p.join(this.store.sessionsDir(o),`${o}.jsonl`),createdAt:a,updatedAt:a,model:e.manifest.model};return m(this.store.sessionsDir(o),{recursive:!0,mode:448}),this.store.saveInstance(c),this.emit(c.id,{type:"status",status:"queued",at:a}),this.pump(),c}activeInProject(t){return this.store.listInstances().filter(e=>e.projectPath===t&&!d.includes(e.status)&&e.status!=="queued").length}pump(){for(const t of this.store.listInstances())t.status==="queued"&&(this.activeInProject(t.projectPath)>=_||this.start(t))}start(t){const e=this.getTemplate(t.templateId);if(!e){this.setStatus(t.id,"failed","template disappeared");return}const s=B(e,t,{apiBase:this.apiBase,token:this.token}),n=e.manifest.binaryPath||"pi",r=new M({command:n,args:s.args,cwd:t.workspacePath,env:s.env,onEvent:o=>this.handleEvent(t.id,o),onStderr:o=>{/error|failed/i.test(o)&&this.emit(t.id,{type:"notice",level:"warn",text:o.slice(0,500),at:new Date().toISOString()})},onExit:()=>{this.runtimes.delete(t.id),this.streaming.delete(t.id);const o=this.store.getInstance(t.id);o&&!d.includes(o.status)&&this.setStatus(t.id,"failed","pi exited unexpectedly"),this.pump()}});this.runtimes.set(t.id,r),t.status="starting",t.pid=void 0,this.store.saveInstance(t),this.emit(t.id,{type:"status",status:"starting",at:new Date().toISOString()}),r.start()}handleEvent(t,e){const s=String(e.type||""),n=new Date().toISOString();switch(s){case"agent_start":this.streaming.add(t),this.setStatus(t,"running");break;case"agent_end":break;case"agent_settled":this.streaming.delete(t),this.setStatus(t,e.aborted===!0?"cancelled":"completed");break;case"message_start":case"message_end":{const r=e.message;if(r){if(s==="message_end"&&r.role==="assistant"){const o=this.store.getInstance(t),i=N(r);o&&i&&(o.lastText=i,this.store.saveInstance(o))}this.emit(t,{type:"message",message:r,at:n})}break}case"message_update":{const r=e.assistantMessageEvent;if(!r)break;const o=r.type==="text_delta"?"text":r.type==="thinking_delta"?"thinking":r.type==="toolcall_delta"?"tool-args":null;if(!o)break;const i=e.message;this.emit(t,{type:"delta",kind:o,delta:String(r.delta||""),contentIndex:typeof r.contentIndex=="number"?r.contentIndex:void 0,messageId:typeof i?.id=="string"?i.id:void 0,at:n});break}case"tool_execution_start":this.emit(t,{type:"tool",phase:"start",callId:String(e.toolCallId||""),name:String(e.toolName||"tool"),args:e.args,at:n});break;case"tool_execution_update":this.emit(t,{type:"tool",phase:"update",callId:String(e.toolCallId||""),name:String(e.toolName||"tool"),output:E(e.partialResult),at:n});break;case"tool_execution_end":this.emit(t,{type:"tool",phase:"end",callId:String(e.toolCallId||""),name:String(e.toolName||"tool"),output:E(e.result),isError:e.isError===!0,durationMs:typeof e.durationMs=="number"?e.durationMs:void 0,at:n});break;case"extension_ui_request":this.handleUiRequest(t,e);break;default:break}}handleUiRequest(t,e){const s=String(e.method||""),n=new Date().toISOString(),r=this.store.getInstance(t);if(s==="notify"){this.emit(t,{type:"notice",level:e.notifyType==="error"?"error":e.notifyType==="warning"?"warn":"info",text:String(e.message||""),at:n});return}if(!["confirm","select","input","editor"].includes(s))return;const o=String(e.id||""),i=o?this.approvals.get(t)?.get(o):void 0;if(i&&i.state==="pending")return;const u=String(e.title||"Approval required"),a=/^Allow (.+?)\?$/.exec(u),c={id:String(e.id||""),botId:t,botTitle:r?.title||t,kind:s==="confirm"?"tool":"question",method:s,title:u,toolName:a?a[1]:void 0,message:typeof e.message=="string"?e.message:void 0,options:Array.isArray(e.options)?e.options.map(String):void 0,state:"pending",createdAt:n};if(this.approvals.has(t)||this.approvals.set(t,new Map),this.approvals.get(t).set(c.id,c),r&&r.runtimeMode==="parent-supervised"&&r.parentBotId){const h=this.store.getInstance(r.parentBotId);if(h){c.escalatedTo=h.id;const S=c.message?c.message.slice(0,500):"",T=[`Child bot "${r.title}" (${r.id}) needs approval: ${c.title}`,S?`Arguments: ${S}`:"",`Decide with bot_approve({ botId: "${r.id}", requestId: "${c.id}", allow: true|false, reason: "..." }).`,"If you do nothing the user will answer it."].filter(Boolean).join(`
2
+ `);this.input(h.id,T,"steer").catch(()=>{this.emit(t,{type:"notice",level:"warn",text:"Could not reach the supervising bot; waiting for the user.",at:n})})}}this.setStatus(t,"waiting_approval"),this.emit(t,{type:"approval",approval:c,at:n})}allowTool(t,e){if(!this.store.getInstance(t))throw new Error("bot not found");const n=p.join(this.store.agentDir(t),".allowed-tools");let r=[];try{r=JSON.parse(w(n,"utf8")),Array.isArray(r)||(r=[])}catch{r=[]}return r.includes(e)||r.push(e),m(p.dirname(n),{recursive:!0,mode:448}),I(n,`${JSON.stringify(r)}
3
3
  `,{mode:384}),r}allowedTools(t){try{const e=JSON.parse(w(p.join(this.store.agentDir(t),".allowed-tools"),"utf8"));return Array.isArray(e)?e.map(String):[]}catch{return[]}}setRuntimeMode(t,e){const s=this.store.getInstance(t);if(!s)throw new Error("bot not found");s.runtimeMode=g(e),this.store.saveInstance(s);const n=p.join(this.store.agentDir(t),".runtime-mode");m(p.dirname(n),{recursive:!0,mode:448}),I(n,`${s.runtimeMode}
4
- `,{mode:384}),this.emit(t,{type:"notice",level:"info",text:`Approval mode: ${e}`,at:new Date().toISOString()})}respondApproval(t,e,s,n,r="human",o=!1){const i=this.approvals.get(t)?.get(e);if(!i)throw new Error("approval not found");const a=this.runtimes.get(t);if(!a)throw new Error("bot is not running");const c={type:"extension_ui_response",id:e};i.method==="confirm"?c.confirmed=s:i.method==="select"?c.value=s?i.options?.[0]:i.options?.[1]||i.options?.[0]:s?c.value=n||"":c.cancelled=!0,a.send(c),s&&o&&i.toolName&&this.allowTool(t,i.toolName),i.state=s?"allowed":"denied",i.decidedBy=r,i.reason=n,i.decidedAt=new Date().toISOString();try{this.store.appendEvent(t,{type:"approval",approval:i,at:i.decidedAt})}catch{}return this.broadcast(t,{type:"approval",approval:i,at:i.decidedAt}),this.setStatus(t,"running"),i}listApprovals(){const t=[];for(const[,e]of this.approvals)for(const s of e.values())s.state==="pending"&&t.push(s);return t.sort((e,s)=>e.createdAt.localeCompare(s.createdAt))}async input(t,e,s){const n=this.store.getInstance(t);if(!n)throw new Error("bot not found");if(!this.runtimes.has(t)){this.resume(t);const a=Date.now()+2e4;for(;!this.runtimes.has(t)&&Date.now()<a;)await new Promise(c=>setTimeout(c,150))}const r=this.runtimes.get(t);if(!r)throw new Error("bot is not running");const o=new Date().toISOString();this.emit(t,{type:"user",text:e,at:o});const i={type:"prompt",message:e};s==="steer"&&(i.streamingBehavior="steer"),s==="follow_up"&&(i.streamingBehavior="followUp"),!i.streamingBehavior&&(n.status==="running"||n.status==="waiting_approval")&&(i.streamingBehavior="steer");try{await r.request(i,2e4)}catch(a){const c=a instanceof Error?a.message:String(a);if(!i.streamingBehavior&&/streaming/i.test(c)){await r.request({...i,streamingBehavior:"steer"},2e4);return}throw a}}stop(t,e=!0){const s=this.store.getInstance(t);if(!s)throw new Error("bot not found");if(e)for(const n of this.children(t))this.stop(n.id,!0);try{this.runtimes.get(t)?.kill()}catch{}this.runtimes.delete(t),d.includes(s.status)||this.setStatus(t,"cancelled"),this.pump()}resume(t){const e=this.store.getInstance(t);if(!e)throw new Error("bot not found");this.runtimes.has(t)||(e.status="queued",this.store.saveInstance(e),this.emit(t,{type:"status",status:"queued",at:new Date().toISOString()}),this.pump())}deleteBot(t,e=!0){const s=this.store.getInstance(t);if(!s)throw new Error("bot not found");if(e)for(const n of this.children(t))this.deleteBot(n.id,!0);try{this.runtimes.get(t)?.kill()}catch{}if(this.runtimes.delete(t),this.store.deleteInstance(t),this.approvals.delete(t),this.recent.delete(t),s.isolation==="worktree"){try{v("git",["-C",s.projectPath,"worktree","remove","--force",s.workspacePath],{timeout:2e4,stdio:"ignore"})}catch{}x(s.workspacePath,{recursive:!0,force:!0})}this.pump()}status(t){const e=this.store.getInstance(t);if(!e)throw new Error("bot not found");const s=[...this.approvals.get(t)?.values()||[]].filter(n=>n.state==="pending");return{...e,pendingApprovals:s.length,lastText:e.lastText?.slice(0,4e3)}}result(t){const e=this.store.getInstance(t);if(!e)throw new Error("bot not found");return{botId:t,status:e.status,text:e.lastText||"",title:e.title}}async waitFor(t,e=45e3){const s=Date.now()+Math.min(e,45e3),n=new Set(t);for(;Date.now()<s;){const r=[...n].filter(o=>{const i=this.store.getInstance(o);return!i||d.includes(i.status)});if(r.length)return{bots:r.map(o=>this.result(o))};await new Promise(o=>setTimeout(o,250))}return{timeout:!0,bots:t.map(r=>{const o=this.store.getInstance(r);return{botId:r,status:o?.status||"missing",title:o?.title}})}}attachSocket(t,e){this.sockets.has(t)||this.sockets.set(t,new Set),this.sockets.get(t).add(e);const s=this.store.getInstance(t);e.send(JSON.stringify({type:"snapshot",bot:s,approvals:this.listApprovals().filter(n=>n.botId===t)}));for(const n of this.store.readEvents(t,400))e.send(JSON.stringify(n));e.on("close",()=>this.sockets.get(t)?.delete(e))}broadcast(t,e){const s=JSON.stringify(e);for(const n of this.sockets.get(t)||[])if(n.readyState===1)try{n.send(s)}catch{}}emit(t,e){this.store.appendEvent(t,e);const s=this.recent.get(t)||[];s.push(e),s.length>800&&s.splice(0,s.length-800),this.recent.set(t,s),this.broadcast(t,e);for(const n of this.listeners)try{n(e)}catch{}}onEvent(t){return this.listeners.add(t),()=>this.listeners.delete(t)}setStatus(t,e,s){const n=this.store.getInstance(t);n&&(n.status=e,s&&(n.lastError=s),this.store.saveInstance(n),this.emit(t,{type:"status",status:e,at:new Date().toISOString(),error:s}),d.includes(e)&&this.pump())}}function g(l){return l==="full-access"?"full-access":l==="parent-supervised"?"parent-supervised":"supervised"}function b(l){const t=l.content;return Array.isArray(t)?t.map(e=>e&&typeof e=="object"&&e.type==="text"?String(e.text||""):"").join("").trim():""}function _(l){if(l==null)return"";if(typeof l=="string")return l;try{return JSON.stringify(l).slice(0,4e3)}catch{return String(l)}}let y=null;function H(){if(!y){const l=Number(process.env.PORT)||21e3;y=new P(l)}return y}export{P as BotManager,E as MAX_CONCURRENT_PER_PROJECT,f as MAX_DEPTH,j as ORCHESTRATION_TOOLS,D as READONLY_TOOLS,H as getBotManager};
4
+ `,{mode:384}),this.emit(t,{type:"notice",level:"info",text:`Approval mode: ${e}`,at:new Date().toISOString()})}respondApproval(t,e,s,n,r="human",o=!1){const i=this.approvals.get(t)?.get(e);if(!i)throw new Error("approval not found");const u=this.runtimes.get(t);if(!u)throw new Error("bot is not running");const a={type:"extension_ui_response",id:e};i.method==="confirm"?a.confirmed=s:i.method==="select"?a.value=s?i.options?.[0]:i.options?.[1]||i.options?.[0]:s?a.value=n||"":a.cancelled=!0,u.send(a),s&&o&&i.toolName&&this.allowTool(t,i.toolName),i.state=s?"allowed":"denied",i.decidedBy=r,i.reason=n,i.decidedAt=new Date().toISOString();try{this.store.appendEvent(t,{type:"approval",approval:i,at:i.decidedAt})}catch{}return this.broadcast(t,{type:"approval",approval:i,at:i.decidedAt}),this.setStatus(t,"running"),i}listApprovals(){const t=[];for(const[,e]of this.approvals)for(const s of e.values())s.state==="pending"&&t.push(s);return t.sort((e,s)=>e.createdAt.localeCompare(s.createdAt))}async input(t,e,s){const n=this.store.getInstance(t);if(!n)throw new Error("bot not found");if(!this.runtimes.has(t)){this.resume(t);const a=Date.now()+1e4;for(;!this.runtimes.has(t)&&Date.now()<a;)await new Promise(c=>setTimeout(c,150))}const r=this.runtimes.get(t);if(!r){const a=this.store.getInstance(t)?.status;throw new Error(a==="queued"?"bot is queued behind other bots in this project; send again once it starts":"bot is still starting; send again in a moment")}const o=new Date().toISOString();this.emit(t,{type:"user",text:e,at:o});const i={type:"prompt",message:e},u=this.streaming.has(t)||P.includes(n.status);s==="follow_up"?i.streamingBehavior="followUp":(s==="steer"||u)&&(i.streamingBehavior="steer");try{await r.request(i,3e4)}catch(a){const c=a instanceof Error?a.message:String(a);if(!i.streamingBehavior&&/stream/i.test(c)){await r.request({...i,streamingBehavior:"steer"},3e4);return}throw a}}stop(t,e=!0){const s=this.store.getInstance(t);if(!s)throw new Error("bot not found");if(e)for(const n of this.children(t))this.stop(n.id,!0);try{this.runtimes.get(t)?.kill()}catch{}this.runtimes.delete(t),this.streaming.delete(t),d.includes(s.status)||this.setStatus(t,"cancelled"),this.pump()}resume(t){const e=this.store.getInstance(t);if(!e)throw new Error("bot not found");this.runtimes.has(t)||(e.status="queued",this.store.saveInstance(e),this.emit(t,{type:"status",status:"queued",at:new Date().toISOString()}),this.pump())}deleteBot(t,e=!0){const s=this.store.getInstance(t);if(!s)throw new Error("bot not found");if(e)for(const n of this.children(t))this.deleteBot(n.id,!0);try{this.runtimes.get(t)?.kill()}catch{}if(this.runtimes.delete(t),this.streaming.delete(t),this.store.deleteInstance(t),this.approvals.delete(t),this.recent.delete(t),s.isolation==="worktree"){try{v("git",["-C",s.projectPath,"worktree","remove","--force",s.workspacePath],{timeout:2e4,stdio:"ignore"})}catch{}x(s.workspacePath,{recursive:!0,force:!0})}this.pump()}status(t){const e=this.store.getInstance(t);if(!e)throw new Error("bot not found");const s=[...this.approvals.get(t)?.values()||[]].filter(n=>n.state==="pending");return{...e,pendingApprovals:s.length,lastText:e.lastText?.slice(0,4e3)}}result(t){const e=this.store.getInstance(t);if(!e)throw new Error("bot not found");return{botId:t,status:e.status,text:e.lastText||"",title:e.title}}async waitFor(t,e=45e3){const s=Date.now()+Math.min(e,45e3),n=new Set(t);for(;Date.now()<s;){const r=[...n].filter(o=>{const i=this.store.getInstance(o);return!i||d.includes(i.status)});if(r.length)return{bots:r.map(o=>this.result(o))};await new Promise(o=>setTimeout(o,250))}return{timeout:!0,bots:t.map(r=>{const o=this.store.getInstance(r);return{botId:r,status:o?.status||"missing",title:o?.title}})}}attachSocket(t,e){this.sockets.has(t)||this.sockets.set(t,new Set),this.sockets.get(t).add(e);const s=this.store.getInstance(t);e.send(JSON.stringify({type:"snapshot",bot:s,approvals:this.listApprovals().filter(n=>n.botId===t)}));for(const n of this.store.readEvents(t,400))e.send(JSON.stringify(n));e.on("close",()=>this.sockets.get(t)?.delete(e))}broadcast(t,e){const s=JSON.stringify(e);for(const n of this.sockets.get(t)||[])if(n.readyState===1)try{n.send(s)}catch{}}emit(t,e){this.store.appendEvent(t,e);const s=this.recent.get(t)||[];s.push(e),s.length>800&&s.splice(0,s.length-800),this.recent.set(t,s),this.broadcast(t,e);for(const n of this.listeners)try{n(e)}catch{}}onEvent(t){return this.listeners.add(t),()=>this.listeners.delete(t)}setStatus(t,e,s){const n=this.store.getInstance(t);n&&(n.status=e,s&&(n.lastError=s),this.store.saveInstance(n),this.emit(t,{type:"status",status:e,at:new Date().toISOString(),error:s}),d.includes(e)&&this.pump())}}function g(l){return l==="full-access"?"full-access":l==="parent-supervised"?"parent-supervised":"supervised"}function N(l){const t=l.content;return Array.isArray(t)?t.map(e=>e&&typeof e=="object"&&e.type==="text"?String(e.text||""):"").join("").trim():""}function E(l){if(l==null)return"";if(typeof l=="string")return l;try{return JSON.stringify(l).slice(0,4e3)}catch{return String(l)}}let y=null;function z(){if(!y){const l=Number(process.env.PORT)||21e3;y=new b(l)}return y}export{b as BotManager,_ as MAX_CONCURRENT_PER_PROJECT,f as MAX_DEPTH,j as ORCHESTRATION_TOOLS,D as READONLY_TOOLS,z as getBotManager};
package/dist/lib/icons.js CHANGED
@@ -1 +1 @@
1
- const a={menu:"M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z",close:"M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7a1 1 0 1 0-1.41 1.41L10.59 12l-4.89 4.89a1 1 0 1 0 1.41 1.41L12 13.41l4.89 4.89a1 1 0 1 0 1.41-1.41L13.41 12l4.89-4.89a1 1 0 0 0 0-1.4z",search:"M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z",refresh:"M17.65 6.35A7.96 7.96 0 0 0 12 4a8 8 0 1 0 8 8h-2a6 6 0 1 1-6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM5.92 19H5v-.92l9.06-9.06.92.92L5.92 19zm13.66-12.83a1 1 0 0 0 0-1.41l-1.34-1.34a1 1 0 0 0-1.41 0l-1.05 1.05 2.75 2.75 1.05-1.05z",delete:"M15 4V3H9v1H4v2h1.5l.81 13.05A2 2 0 0 0 8.3 21h7.4a2 2 0 0 0 1.99-1.95L18.5 6H20V4h-5zm-5.5 2h5l-.75 12h-3.5L9.5 6z",check:"M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",sessions:"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z",notes:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",schedule:"M19 4h-1V2h-2v2H8V2H6v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 16H5V10h14v10zM9 14H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-8 4H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z",agents:"M12 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm0 8a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm-7 13v-2a5 5 0 0 1 5-5h4a5 5 0 0 1 5 5v2h2v-2a7 7 0 0 0-7-7H10a7 7 0 0 0-7 7v2h2z",history:"M13 3a9 9 0 0 0-9 9H1l4 4 4-4H6a7 7 0 1 1 7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.96 8.96 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.25 2.55.75-1.23-3.5-2.08V8H12z","quick-commands":"M13 3 4 14h7l-1 7 9-11h-7l1-7z",windows:"M4 6h16v2H4V6zm0 5h10v2H4v-2zm0 5h16v2H4v-2z",terminal:"M4 17.6 6.4 20l8-8-8-8L4 6.4 11.6 12 4 17.6zM20 18h-8v2h8v-2z",microphone:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z",keyboard:"M20 5H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-9 3h2v2h-2V8zm0 3h2v2h-2v-2zM8 8h2v2H8V8zm0 3h2v2H8v-2zm-1 2H5v-2h2v2zm0-3H5V8h2v2zm9 7H8v-2h8v2zm0-4h-2v-2h2v2zm0-3h-2V8h2v2zm3 3h-2v-2h2v2zm0-3h-2V8h2v2z",bot:"M11 2h2v3h2a3 3 0 0 1 3 3v1h1a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-1v1a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3v-1H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2h1V8a3 3 0 0 1 3-3h2V2zm-2 6v1h6V8H9zm-2 5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm10 0a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z",layers:"M12 2 2 7l10 5 10-5-10-5zm0 7.5L4.5 5.8 12 2l7.5 3.8L12 9.5zM2 12l10 5 10-5-1.9-.95L12 14.9l-8.1-3.85L2 12zm0 4.5 10 5 10-5-1.9-.95L12 19.4l-8.1-3.85-1.9.95z",inbox:"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zm0 16H5v-3h3.6a3.5 3.5 0 0 0 6.8 0H19v3zm0-5h-4.7a3.5 3.5 0 0 1-6.6 0H5V5h14v9z","chevron-down":"M7.4 8.6 12 13.2l4.6-4.6L18 10l-6 6-6-6 1.4-1.4z",settings:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6a3.6 3.6 0 1 1 0-7.2 3.6 3.6 0 0 1 0 7.2z",pin:"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4z","pin-outline":"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4zm-4.8 7.2V11l2-2V4h1.6v5l2 2v5.2H11.2z",folder:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z",file:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",worktree:"M6 3a3 3 0 0 0-1 5.83v6.34a3 3 0 1 0 2 0V8.83A3 3 0 0 0 6 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm0 12a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM18 3a3 3 0 0 0-1 5.83V9a4 4 0 0 1-4 4h-2a3 3 0 1 0 0 2h2a6 6 0 0 0 6-6v-.17A3 3 0 0 0 18 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM9 13a1 1 0 1 1 0 2 1 1 0 0 1 0-2z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",export:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",chevronRight:"M9.29 6.71a1 1 0 0 0 0 1.41L13.17 12l-3.88 3.88a1 1 0 1 0 1.41 1.41l4.59-4.59a1 1 0 0 0 0-1.41L10.7 6.7a1 1 0 0 0-1.41.01z",lightning:"M11 21h-1l1-7H7.5c-.58 0-.57-.32-.38-.66.19-.33.51-.89.73-1.27L13 3h1l-1 7h3.5c.49 0 .56.33.47.51l-.07.15c-.22.46-.58 1.18-.78 1.58L11 21z","git-branch":"M13.5 7a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zm0 10a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zM11 9.5v5.1a4.03 4.03 0 0 0-3-.1V9.4a4.03 4.03 0 0 0 3 .1z",external:"M14 3h7v7h-2V6l-9.29 9.29-1.41-1.41L17.59 4.5H14V3zm4 16H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7h-2v7z",play:"M8 5v14l11-7L8 5z",stop:"M6 6h12v12H6V6z",warning:"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z",info:"M11 7h2v2h-2V7zm0 4h2v6h-2v-6zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z",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 l(h){return a[h]??a.menu}function c(h,v=""){return`<svg viewBox="0 0 24 24" fill="currentColor"${v?" "+v:""}><path d="${l(h)}"/></svg>`}function H(h){return`<path d="${l(h)}"/>`}const m={};function V(h,v){const z=m[h];return z?c(z):v?.trim().startsWith("<svg")?v:`<span style="font-size:18px;line-height:1">${v??""}</span>`}export{V as extIcon,c as icon,l as iconPath,H as iconPathString};
1
+ const a={menu:"M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z",close:"M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7a1 1 0 1 0-1.41 1.41L10.59 12l-4.89 4.89a1 1 0 1 0 1.41 1.41L12 13.41l4.89 4.89a1 1 0 1 0 1.41-1.41L13.41 12l4.89-4.89a1 1 0 0 0 0-1.4z",search:"M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z",refresh:"M17.65 6.35A7.96 7.96 0 0 0 12 4a8 8 0 1 0 8 8h-2a6 6 0 1 1-6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM5.92 19H5v-.92l9.06-9.06.92.92L5.92 19zm13.66-12.83a1 1 0 0 0 0-1.41l-1.34-1.34a1 1 0 0 0-1.41 0l-1.05 1.05 2.75 2.75 1.05-1.05z",delete:"M15 4V3H9v1H4v2h1.5l.81 13.05A2 2 0 0 0 8.3 21h7.4a2 2 0 0 0 1.99-1.95L18.5 6H20V4h-5zm-5.5 2h5l-.75 12h-3.5L9.5 6z",check:"M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",sessions:"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z",notes:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",schedule:"M19 4h-1V2h-2v2H8V2H6v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 16H5V10h14v10zM9 14H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-8 4H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z",agents:"M12 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm0 8a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm-7 13v-2a5 5 0 0 1 5-5h4a5 5 0 0 1 5 5v2h2v-2a7 7 0 0 0-7-7H10a7 7 0 0 0-7 7v2h2z",history:"M13 3a9 9 0 0 0-9 9H1l4 4 4-4H6a7 7 0 1 1 7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.96 8.96 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.25 2.55.75-1.23-3.5-2.08V8H12z","quick-commands":"M13 3 4 14h7l-1 7 9-11h-7l1-7z",windows:"M4 6h16v2H4V6zm0 5h10v2H4v-2zm0 5h16v2H4v-2z",terminal:"M4 17.6 6.4 20l8-8-8-8L4 6.4 11.6 12 4 17.6zM20 18h-8v2h8v-2z",microphone:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z",keyboard:"M20 5H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-9 3h2v2h-2V8zm0 3h2v2h-2v-2zM8 8h2v2H8V8zm0 3h2v2H8v-2zm-1 2H5v-2h2v2zm0-3H5V8h2v2zm9 7H8v-2h8v2zm0-4h-2v-2h2v2zm0-3h-2V8h2v2zm3 3h-2v-2h2v2zm0-3h-2V8h2v2z",bot:"M11 2h2v3h2a3 3 0 0 1 3 3v1h1a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-1v1a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3v-1H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2h1V8a3 3 0 0 1 3-3h2V2zm-2 6v1h6V8H9zm-2 5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm10 0a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z",layers:"M12 2 2 7l10 5 10-5-10-5zm0 7.5L4.5 5.8 12 2l7.5 3.8L12 9.5zM2 12l10 5 10-5-1.9-.95L12 14.9l-8.1-3.85L2 12zm0 4.5 10 5 10-5-1.9-.95L12 19.4l-8.1-3.85-1.9.95z",inbox:"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zm0 16H5v-3h3.6a3.5 3.5 0 0 0 6.8 0H19v3zm0-5h-4.7a3.5 3.5 0 0 1-6.6 0H5V5h14v9z","chevron-down":"M7.4 8.6 12 13.2l4.6-4.6L18 10l-6 6-6-6 1.4-1.4z",settings:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6a3.6 3.6 0 1 1 0-7.2 3.6 3.6 0 0 1 0 7.2z",pin:"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4z","pin-outline":"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4zm-4.8 7.2V11l2-2V4h1.6v5l2 2v5.2H11.2z",folder:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z",file:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",worktree:"M6 3a3 3 0 0 0-1 5.83v6.34a3 3 0 1 0 2 0V8.83A3 3 0 0 0 6 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm0 12a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM18 3a3 3 0 0 0-1 5.83V9a4 4 0 0 1-4 4h-2a3 3 0 1 0 0 2h2a6 6 0 0 0 6-6v-.17A3 3 0 0 0 18 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM9 13a1 1 0 1 1 0 2 1 1 0 0 1 0-2z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",export:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",chevronRight:"M9.29 6.71a1 1 0 0 0 0 1.41L13.17 12l-3.88 3.88a1 1 0 1 0 1.41 1.41l4.59-4.59a1 1 0 0 0 0-1.41L10.7 6.7a1 1 0 0 0-1.41.01z",lightning:"M11 21h-1l1-7H7.5c-.58 0-.57-.32-.38-.66.19-.33.51-.89.73-1.27L13 3h1l-1 7h3.5c.49 0 .56.33.47.51l-.07.15c-.22.46-.58 1.18-.78 1.58L11 21z","git-branch":"M13.5 7a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zm0 10a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zM11 9.5v5.1a4.03 4.03 0 0 0-3-.1V9.4a4.03 4.03 0 0 0 3 .1z",external:"M14 3h7v7h-2V6l-9.29 9.29-1.41-1.41L17.59 4.5H14V3zm4 16H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7h-2v7z",play:"M8 5v14l11-7L8 5z",stop:"M6 6h12v12H6V6z",warning:"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z",info:"M11 7h2v2h-2V7zm0 4h2v6h-2v-6zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z",shield:"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25z","shield-up":"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25zM13 8.6v4.6h2l-3 3.6-3-3.6h2V8.6h2z","shield-alert":"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25zM11 7.5h2v5h-2v-5zm0 6.5h2v2h-2v-2z",spinner:"M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46A7.93 7.93 0 0 0 20 12c0-4.42-3.58-8-8-8z",dots:"M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"};function l(h){return a[h]??a.menu}function c(h,v=""){return`<svg viewBox="0 0 24 24" fill="currentColor"${v?" "+v:""}><path d="${l(h)}"/></svg>`}function m(h){return`<path d="${l(h)}"/>`}const V={};function H(h,v){const z=V[h];return z?c(z):v?.trim().startsWith("<svg")?v:`<span style="font-size:18px;line-height:1">${v??""}</span>`}export{H as extIcon,c as icon,l as iconPath,m as iconPathString};
@@ -21,7 +21,16 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
21
21
  .fixed-header .brand {
22
22
  font-size: var(--text-base); font-weight: 600; color: var(--page-fg);
23
23
  flex-shrink: 0;
24
+ /* The logo is the session-list toggle on a phone, so it needs a real touch
25
+ target (44px) rather than the height of the text itself. */
26
+ display: inline-flex; align-items: center;
27
+ min-height: 44px; padding: 0 6px; margin-left: -6px;
28
+ border-radius: 8px; cursor: pointer;
29
+ touch-action: manipulation; -webkit-tap-highlight-color: transparent;
30
+ user-select: none;
24
31
  }
32
+ .fixed-header .brand:active { background: color-mix(in srgb, var(--panel-accent) 10%, transparent); }
33
+ .fixed-header .brand:focus-visible { ${a()} }
25
34
  .fixed-header .brand span { color: var(--panel-accent); font-weight: 500; }
26
35
  .fixed-header .brand a { color: inherit; text-decoration: none; }
27
36
  #header-git {
@@ -96,6 +105,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
96
105
  display: flex; align-items: center; gap: 8px;
97
106
  padding: 10px 12px; border-radius: 10px;
98
107
  cursor: pointer; font-size: var(--text-sm); color: var(--page-fg);
108
+ touch-action: manipulation;
99
109
  text-decoration: none; margin-bottom: 2px;
100
110
  transition: background 0.1s;
101
111
  }
@@ -215,34 +225,48 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
215
225
  }
216
226
  .session-group-header:hover .sg-add-bot { opacity: 1; color: var(--panel-accent); border-color: var(--panel-accent); }
217
227
  @media (hover: none) { .session-group-header .sg-add-bot { opacity: 0.85; } }
218
- .bv-mode { position: relative; }
228
+ .bv-mode { position: relative; display: inline-flex; }
219
229
  .bv-mode-btn {
220
- display: inline-flex; align-items: center; gap: 4px;
221
- background: var(--page-bg); color: var(--page-fg);
222
- border: 1px solid var(--panel-border); border-radius: 7px;
223
- font-size: 11px; padding: 4px 8px; cursor: pointer; white-space: nowrap;
230
+ display: inline-flex; align-items: center; justify-content: center;
231
+ width: 28px; height: 28px; padding: 0; flex: 0 0 auto;
232
+ background: var(--page-bg); color: var(--panel-muted);
233
+ border: 1px solid var(--panel-border); border-radius: 8px;
234
+ cursor: pointer; touch-action: manipulation;
235
+ transition: color 0.15s, border-color 0.15s, background 0.15s;
224
236
  }
225
237
  .bv-mode-btn:hover { border-color: var(--panel-accent); color: var(--panel-accent); }
238
+ .bv-mode-btn[aria-expanded="true"] { border-color: var(--panel-accent); color: var(--panel-accent); background: color-mix(in srgb, var(--panel-accent) 10%, transparent); }
239
+ /* The shield glyph carries the mode: plain = supervised, arrow = delegated,
240
+ exclamation = everyone runs unattended. */
241
+ .bv-mode-btn[data-mode="parent-supervised"] { color: var(--panel-accent); }
242
+ .bv-mode-btn[data-mode="full-access"] { color: #e0a23c; border-color: color-mix(in srgb, #e0a23c 45%, var(--panel-border)); }
226
243
  .bv-mode-menu {
227
- position: absolute; right: 0; top: calc(100% + 4px); z-index: 20;
228
- width: 300px; background: var(--panel-bg); border: 1px solid var(--panel-border);
229
- border-radius: 9px; padding: 4px; display: flex; flex-direction: column; gap: 2px;
244
+ position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
245
+ width: 320px; background: var(--panel-bg); border: 1px solid var(--panel-border);
246
+ border-radius: 10px; padding: 4px; display: flex; flex-direction: column; gap: 2px;
230
247
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
231
248
  }
232
249
  .bv-mode-menu[hidden] { display: none; }
233
250
  .bv-mode-menu button {
234
- display: flex; flex-direction: column; gap: 2px; text-align: left;
235
- background: none; border: none; border-radius: 7px; padding: 7px 9px;
236
- color: var(--page-fg); cursor: pointer; font: inherit;
237
- }
238
- .bv-mode-menu button:hover { background: color-mix(in srgb, var(--panel-accent) 10%, transparent); }
239
- .bv-mode-menu button.active { background: color-mix(in srgb, var(--panel-accent) 14%, transparent); }
251
+ display: grid; grid-template-columns: 18px minmax(0, 1fr) 14px;
252
+ align-items: start; gap: 8px;
253
+ text-align: left; background: none; border: none; border-radius: 8px; padding: 8px 9px;
254
+ color: var(--page-fg); cursor: pointer; font: inherit; touch-action: manipulation;
255
+ }
256
+ .bv-mode-menu button:hover { background: color-mix(in srgb, var(--panel-accent) 8%, transparent); }
257
+ .bv-mode-menu button.active { background: color-mix(in srgb, var(--panel-accent) 12%, transparent); }
258
+ .bv-mode-row-icon { color: var(--panel-muted); padding-top: 1px; }
259
+ .bv-mode-row-icon svg { display: block; }
260
+ .bv-mode-menu button.active .bv-mode-row-icon { color: var(--panel-accent); }
261
+ .bv-mode-menu button[data-mode="full-access"] .bv-mode-row-icon { color: #e0a23c; }
262
+ .bv-mode-row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
240
263
  .bv-mode-menu b { font-size: 12px; font-weight: 600; }
241
- .bv-mode-menu span { font-size: 11px; color: var(--panel-muted); line-height: 1.4; }
242
- .bv-actions .bv-mode-select {
243
- background: var(--page-bg); color: var(--page-fg);
244
- border: 1px solid var(--panel-border); border-radius: 7px;
245
- font-size: 11px; padding: 4px 6px; max-width: 160px;
264
+ .bv-mode-menu .bv-mode-row-text span { font-size: 11px; color: var(--panel-muted); line-height: 1.45; }
265
+ .bv-mode-row-check { color: var(--panel-accent); visibility: hidden; padding-top: 2px; }
266
+ .bv-mode-menu button.active .bv-mode-row-check { visibility: visible; }
267
+ .bv-actions .btn {
268
+ height: 28px; min-height: 28px; padding: 0 10px;
269
+ font-size: 11.5px; border-radius: 8px;
246
270
  }
247
271
  .bv-actions .btn[hidden] { display: none; }
248
272
 
@@ -497,6 +521,9 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
497
521
  display: inline-flex; align-items: center; justify-content: center;
498
522
  min-height: 36px; padding: 6px 14px; border-radius: 8px;
499
523
  font-size: var(--text-sm); font-family: inherit; cursor: pointer;
524
+ /* No double-tap zoom on iOS: a second tap should press the button again,
525
+ not zoom the page. */
526
+ touch-action: manipulation;
500
527
  border: 1px solid var(--panel-border); background: var(--panel-bg);
501
528
  color: var(--page-fg); transition: opacity 0.15s; text-decoration: none;
502
529
  }
@@ -741,18 +768,87 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
741
768
  .bv-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
742
769
  .bv-title-text { font-family: var(--font-mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
743
770
  .bv-status { font-size: 11px; color: var(--panel-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
744
- .bv-actions { display: flex; gap: 6px; flex-shrink: 0; }
745
- .bv-actions .btn { padding: 4px 10px; font-size: 11px; }
771
+ .bv-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }
746
772
 
747
- .bots-messages { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
773
+ .bots-messages {
774
+ flex: 1; overflow-y: auto; padding: 14px 16px;
775
+ display: flex; flex-direction: column; gap: 10px;
776
+ /* The transcript is its own scroll surface: momentum scrolling, and the
777
+ gesture never chains to the page (which would move the pinned view). */
778
+ -webkit-overflow-scrolling: touch;
779
+ overscroll-behavior: contain;
780
+ }
781
+ /* Shown only while the reader is away from the tail during streaming. */
782
+ .bv-jump {
783
+ position: absolute; right: 14px; bottom: calc(70px + env(safe-area-inset-bottom, 0px));
784
+ z-index: 7; min-width: 44px; height: 44px; padding: 0 12px;
785
+ border-radius: 22px; border: 1px solid var(--panel-border);
786
+ background: color-mix(in srgb, var(--panel-bg) 92%, transparent);
787
+ color: var(--page-fg); font-size: 12px; font-family: var(--font-mono);
788
+ display: inline-flex; align-items: center; justify-content: center; gap: 4px;
789
+ cursor: pointer; touch-action: manipulation;
790
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
791
+ }
792
+ .bv-jump[hidden] { display: none; }
793
+ .bv-jump:hover { border-color: var(--panel-accent); color: var(--panel-accent); }
748
794
  .bv-msg { max-width: min(860px, 100%); font-size: 13px; line-height: 1.55; }
749
- .bv-user { align-self: flex-end; background: color-mix(in srgb, var(--panel-accent) 16%, transparent); border: 1px solid color-mix(in srgb, var(--panel-accent) 30%, transparent); padding: 8px 12px; border-radius: 10px; white-space: pre-wrap; }
795
+ .bv-user { align-self: flex-end; background: color-mix(in srgb, var(--panel-accent) 16%, transparent); border: 1px solid color-mix(in srgb, var(--panel-accent) 30%, transparent); padding: 8px 12px; border-radius: 10px; }
750
796
  .bv-assistant { align-self: flex-start; }
751
- .bv-text { white-space: pre-wrap; word-break: break-word; }
797
+ .bv-text { word-break: break-word; overflow-wrap: anywhere; }
752
798
  .bv-thinking { margin-bottom: 6px; color: var(--panel-muted); font-size: 12px; }
753
799
  .bv-thinking summary { cursor: pointer; opacity: 0.8; }
754
800
  .bv-thinking div { white-space: pre-wrap; border-left: 2px solid var(--panel-border); padding-left: 8px; margin-top: 4px; }
755
801
 
802
+ /* \u2500\u2500 Rendered markdown in a message \u2500\u2500 */
803
+ .bv-text > :first-child, .bv-user > :first-child { margin-top: 0; }
804
+ .bv-text > :last-child, .bv-user > :last-child { margin-bottom: 0; }
805
+ .bv-text p, .bv-user p { margin: 0 0 8px; }
806
+ .bv-text h1, .bv-text h2, .bv-text h3, .bv-text h4, .bv-text h5, .bv-text h6 {
807
+ margin: 14px 0 6px; line-height: 1.3; font-weight: 600;
808
+ }
809
+ .bv-text h1 { font-size: 17px; }
810
+ .bv-text h2 { font-size: 15.5px; }
811
+ .bv-text h3 { font-size: 14px; }
812
+ .bv-text h4, .bv-text h5, .bv-text h6 { font-size: 13px; color: var(--panel-muted); }
813
+ .bv-text ul, .bv-text ol { margin: 0 0 8px; padding-left: 20px; }
814
+ .bv-text li { margin: 2px 0; }
815
+ .bv-text li > ul, .bv-text li > ol { margin: 2px 0; }
816
+ .bv-text li > input[type="checkbox"] { margin: 0 5px 0 -16px; vertical-align: middle; }
817
+ .bv-text a, .bv-user a { color: var(--panel-accent); text-decoration: underline; text-underline-offset: 2px; }
818
+ .bv-text code, .bv-user code {
819
+ font-family: var(--font-mono); font-size: 11.5px;
820
+ background: color-mix(in srgb, var(--page-bg), var(--panel-bg) 55%);
821
+ border: 1px solid var(--panel-border); border-radius: 4px; padding: 0 4px;
822
+ }
823
+ .bv-text blockquote {
824
+ margin: 0 0 8px; padding: 1px 10px;
825
+ border-left: 2px solid var(--panel-border); color: var(--panel-muted);
826
+ }
827
+ .bv-text hr { border: none; border-top: 1px solid var(--panel-border); margin: 12px 0; }
828
+ .bv-table { max-width: 100%; overflow-x: auto; margin: 0 0 8px; }
829
+ .bv-text table { border-collapse: collapse; font-size: 12px; }
830
+ .bv-text th, .bv-text td { border: 1px solid var(--panel-border); padding: 4px 8px; vertical-align: top; }
831
+ .bv-text th { background: color-mix(in srgb, var(--page-bg), var(--panel-bg) 55%); font-weight: 600; }
832
+ .bv-code {
833
+ margin: 0 0 8px; border: 1px solid var(--panel-border); border-radius: 8px;
834
+ background: color-mix(in srgb, var(--page-bg), var(--panel-bg) 45%); overflow: hidden;
835
+ }
836
+ .bv-code-head {
837
+ display: flex; align-items: center; justify-content: space-between; gap: 8px;
838
+ padding: 3px 8px; border-bottom: 1px solid var(--panel-border);
839
+ font-family: var(--font-mono); font-size: 10px; color: var(--panel-muted);
840
+ }
841
+ .bv-code-copy {
842
+ background: none; border: none; color: var(--panel-muted); cursor: pointer;
843
+ font-family: inherit; font-size: 10px; padding: 2px 4px; border-radius: 4px;
844
+ }
845
+ .bv-code-copy:hover { color: var(--panel-accent); background: color-mix(in srgb, var(--panel-accent) 10%, transparent); }
846
+ .bv-code pre { margin: 0; padding: 8px 10px; overflow-x: auto; }
847
+ .bv-code code {
848
+ font-family: var(--font-mono); font-size: 11.5px; line-height: 1.5;
849
+ background: none; border: none; padding: 0; white-space: pre;
850
+ }
851
+
756
852
  .bv-tool { border: 1px solid var(--panel-border); border-radius: 8px; background: color-mix(in srgb, var(--page-bg), var(--panel-bg) 45%); font-family: var(--font-mono); font-size: 11.5px; }
757
853
  .bv-tool > summary { padding: 6px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
758
854
  .bv-tool-name { color: var(--panel-accent); }
@@ -773,16 +869,28 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
773
869
  .bv-notice-error { color: var(--panel-danger, #e5534b); }
774
870
 
775
871
  /* Same look and metrics as the terminal's mobile input row (.mk-input). */
776
- .bots-composer { display: flex; gap: 4px; padding: 6px 8px; border-top: 1px solid var(--panel-border); background: var(--panel-bg); flex-shrink: 0; align-items: stretch; }
872
+ .bots-composer-wrap { flex-shrink: 0; border-top: 1px solid var(--panel-border); background: var(--panel-bg); }
873
+ .bv-composer-error {
874
+ padding: 6px 10px; font-size: 11.5px; line-height: 1.45; word-break: break-word;
875
+ color: var(--panel-danger, #e5534b);
876
+ }
877
+ .bv-composer-error[hidden] { display: none; }
878
+ .bots-composer { display: flex; gap: 4px; padding: 6px 8px; align-items: stretch; }
879
+ .bots-composer .btn.primary[aria-busy="true"] { opacity: 0.55; cursor: default; }
880
+ .bots-composer .btn.primary:disabled { filter: none; }
777
881
  .bots-composer textarea {
778
882
  flex: 1; resize: none; box-sizing: border-box;
779
883
  min-height: 38px; max-height: 80px;
884
+ /* Focus on the first tap: no double-tap zoom and no 300ms click delay. */
885
+ touch-action: manipulation;
780
886
  background: color-mix(in srgb, var(--page-bg), var(--panel-bg) 50%);
781
887
  color: var(--page-fg); border: 1px solid var(--panel-border);
782
888
  border-radius: 8px; padding: 6px 10px;
783
889
  font-family: var(--font-mono); font-size: var(--text-base); line-height: 1.4; outline: none;
784
890
  }
785
891
  .bots-composer textarea:focus { border-color: var(--panel-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--panel-accent) 15%, transparent); }
892
+ /* Same muted placeholder as the terminal's mobile input row. */
893
+ .bots-composer textarea::placeholder { color: var(--panel-muted); opacity: 0.6; }
786
894
  .bots-composer .btn.primary {
787
895
  min-width: 44px; padding: 0 12px; border: none; color: white;
788
896
  background: var(--panel-success); border-radius: 8px; cursor: pointer;
@@ -829,15 +937,24 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
829
937
  .bots-view-head { flex-wrap: wrap; row-gap: 6px; padding: 6px 10px; }
830
938
  .bv-title { flex: 1 1 100%; }
831
939
  .bv-status { display: none; }
832
- .bv-actions { flex: 1 1 100%; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
833
- .bv-actions .btn, .bv-actions .bv-mode-btn { flex: 0 0 auto; padding: 5px 9px; font-size: 11px; }
940
+ .bv-actions { flex: 1 1 100%; display: flex; gap: 6px; align-items: center; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
941
+ /* Same height for every control in the row; the mode chip is an icon, so it
942
+ is a square, not a shorter box next to the text buttons. */
943
+ .bv-actions .btn, .bv-actions .bv-mode-btn { flex: 0 0 auto; height: 32px; min-height: 32px; }
944
+ .bv-actions .btn { padding: 0 11px; font-size: 11.5px; }
945
+ .bv-actions .bv-mode-btn { width: 32px; padding: 0; }
946
+ .bv-actions .bv-mode-btn svg { width: 16px; height: 16px; }
834
947
  .bv-mode-menu { position: fixed; left: 10px; right: 10px; top: auto; bottom: 10px; width: auto; max-height: 60vh; overflow-y: auto; }
835
948
  .bots-messages { padding: 10px; }
836
949
  .bv-msg { max-width: 100%; }
837
- .bots-composer { padding: 8px 10px; gap: 6px; }
950
+ /* Keep the field clear of the home-indicator gesture bar. */
951
+ .bots-composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) 10px; gap: 6px; }
838
952
  .bv-approval-actions { flex-wrap: wrap; }
839
953
  .bv-reason { flex: 1 1 100%; }
840
954
  .sidebar { flex: 0 0 auto; border-right: none; border-bottom: 1px solid var(--panel-border); transition: max-height 0.2s; }
955
+ /* An expanded list must leave room for the terminal/chat below it; without a
956
+ cap a long session list pushed the main area off-screen. */
957
+ .sidebar:not(.collapsed) { max-height: 62dvh; }
841
958
  .sidebar.collapsed .sidebar-content { display: none; }
842
959
  .sidebar.collapsed .sidebar-footer { display: none; }
843
960
  .sidebar.collapsed { max-height: 48px; overflow: hidden; }
@@ -857,6 +974,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
857
974
  breakpoint, applied unconditionally when the html has .force-narrow. */
858
975
  html.force-narrow .app-layout { flex-direction: column; }
859
976
  html.force-narrow .sidebar { flex: 0 0 auto; border-right: none; border-bottom: 1px solid var(--panel-border); transition: max-height 0.2s; }
977
+ html.force-narrow .sidebar:not(.collapsed) { max-height: 62dvh; }
860
978
  html.force-narrow .sidebar.collapsed .sidebar-content { display: none; }
861
979
  html.force-narrow .sidebar.collapsed .sidebar-footer { display: none; }
862
980
  html.force-narrow .sidebar.collapsed { max-height: 48px; overflow: hidden; }
@@ -904,7 +1022,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
904
1022
  </script>
905
1023
 
906
1024
  <header class="fixed-header">
907
- <div class="brand" id="brand-toggle">tmux<span>-weblink</span></div>
1025
+ <div class="brand" id="brand-toggle" role="button" tabindex="0" aria-label="Toggle session list" aria-expanded="true" title="Toggle session list">tmux<span>-weblink</span></div>
908
1026
  <div class="header-actions">
909
1027
  </div>
910
1028
  <div id="header-git" title="Click to browse repository"></div>
@@ -1086,13 +1204,32 @@ ${g("__onSessionCreated")}
1086
1204
  </script>
1087
1205
  <script>
1088
1206
  (function(){
1089
- /* Logo toggle sidebar */
1207
+ /* Logo toggles the session list. It is the main way out of the bot chat on a
1208
+ phone, so it acts on pointerdown (a tap during heavy streaming output still
1209
+ lands) and a double tap in quick succession cannot undo itself. */
1090
1210
  var brand = document.getElementById('brand-toggle');
1091
1211
  var sbar = document.querySelector('.sidebar');
1092
1212
  if (brand && sbar) {
1093
- brand.addEventListener('click', function(e) {
1094
- sbar.classList.toggle('collapsed');
1213
+ var setExpanded = function(expanded) {
1214
+ sbar.classList.toggle('collapsed', !expanded);
1215
+ brand.setAttribute('aria-expanded', expanded ? 'true' : 'false');
1216
+ /* Unpin/repin the bot chat before the next paint, so the list is never
1217
+ drawn underneath the pinned chat view. */
1218
+ if (window.__syncBotsViewport) window.__syncBotsViewport();
1219
+ };
1220
+ var lastToggle = 0;
1221
+ var toggle = function(e) {
1222
+ if (e) e.preventDefault();
1223
+ var now = Date.now();
1224
+ if (now - lastToggle < 350) return;
1225
+ lastToggle = now;
1226
+ setExpanded(sbar.classList.contains('collapsed'));
1227
+ };
1228
+ brand.addEventListener('pointerdown', toggle);
1229
+ brand.addEventListener('keydown', function(e) {
1230
+ if (e.key === 'Enter' || e.key === ' ') toggle(e);
1095
1231
  });
1232
+ brand.setAttribute('aria-expanded', sbar.classList.contains('collapsed') ? 'false' : 'true');
1096
1233
  }
1097
1234
 
1098
1235
  /* Mobile keys: collapsible strip, expanded by tapping the space under the