@umage.ai/redline-agent 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/panel.js +6 -6
- package/dist/terminal.js +18 -18
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5924,6 +5924,7 @@ function unnumbered(L, hintAt) {
|
|
|
5924
5924
|
while (a > 0 && isRow(a - 1)) a--;
|
|
5925
5925
|
while (b + 1 < hintAt && isRow(b + 1)) b++;
|
|
5926
5926
|
if (b === a) return null;
|
|
5927
|
+
for (let i = b + 1; i < hintAt; i++) if (L[i].text.trim()) return null;
|
|
5927
5928
|
return L.slice(a, b + 1).map((l, k) => ({ i: a + k, label: (k + a === c ? l.text.slice(col) : l.text).trim(), selected: k + a === c, desc: [] }));
|
|
5928
5929
|
}
|
|
5929
5930
|
function parseSteps(line) {
|
package/dist/panel.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var zt="/__redline";async function Ht(o){let l=await qe(o),s=async(a,f={})=>{let w=await fetch(`${o}${a}`,{method:"POST",headers:{"content-type":"application/json","x-agent-token":l.token},body:JSON.stringify(f)});if(!w.ok)throw new Error((await w.json().catch(()=>null))?.error??`HTTP ${w.status}`);return w.json()};return{get info(){return l},async refresh(){return l=await qe(o),l},post:s,watch(a,f,w,x){let $=null,k=!1,N=()=>{if($?.close(),!k){$=new EventSource(`${o}/stream?status=1&token=${encodeURIComponent(l.token)}`);for(let A of["hello","status"])$.addEventListener(A,ne=>a(JSON.parse(ne.data)));$.onopen=()=>x?.(!0),$.addEventListener("clis",A=>{l.clis=JSON.parse(A.data),f?.(l.clis)}),$.onerror=async()=>{if(x?.(!1),!($?.readyState!==EventSource.CLOSED||k))try{l=await qe(o),w?.(l),setTimeout(N,1e3)}catch{}}}};return N(),()=>{k=!0,$?.close()}},stream(a){return new EventSource(`${o}/stream?id=${encodeURIComponent(a)}&token=${encodeURIComponent(l.token)}`)},send:(a,f={})=>s("/send",{text:a,...f}),start:(a={})=>s("/start",a),choose:(a,f,w)=>s("/choose",{id:a,index:f,...w===void 0?{}:{text:w}}),answer:(a,f)=>s("/answer",{id:a,choice:f}),input:(a,f)=>s("/input",{id:a,data:f}),resize:(a,f,w)=>s("/resize",{id:a,cols:f,rows:w}),ack:a=>s("/ack",{id:a}),mode:a=>s("/mode",{mode:a}),worktrees:a=>s("/worktrees",{on:a}),worktree:(a,f,w=!1)=>s("/worktree",{branch:a,action:f,confirm:w}),end:a=>s("/end",a?{id:a}:{})}}async function qe(o){let l=await fetch(`${o}/info`);if(!l.ok)throw new Error(`agent bridge: HTTP ${l.status}`);return l.json()}var Dt=()=>typeof document>"u"||document.visibilityState!=="hidden";function jt(o){let l=o.graceMs??15e3,s=o.stall?.ms??5e3,a=null,f,w,x=!1,$=!1,k=0,N=!1,A=0,ne=()=>{clearTimeout(f),f=void 0,clearTimeout(w),w=void 0,A++;let P=a;a=null;try{P?.()}catch{}},le=P=>{let z=o.stall;if(!z||P!==A)return;let Y=!1;Promise.resolve().then(z.probe).then(()=>{Y=!0},()=>{Y=!0}),w=setTimeout(()=>{if(!(Y||P!==A||$)&&(k=Date.now()+6e4,ne(),!N)){N=!0;try{z.stalled()}catch{}}},s)},ae=()=>{let P=++A,z=!1;if(a=o.open(Y=>{P===A&&(Y&&!z&&(z=!0,clearTimeout(w),le(P)),Y||(z=!1))}),x)try{o.resumed?.()}catch{}x=!0,o.stall&&(w=setTimeout(()=>{z||le(P)},s))},oe=()=>{if($)return;Dt()&&(o.want?.()??!0)&&Date.now()>=k?(clearTimeout(f),f=void 0,a||ae()):a&&!f&&(f=setTimeout(ne,l))},ue=()=>{Dt()&&(k=0),oe()};return typeof document<"u"&&document.addEventListener("visibilitychange",ue),oe(),{update:oe,stop(){$=!0,typeof document<"u"&&document.removeEventListener("visibilitychange",ue),ne()},get opened(){return!!a}}}var Ve="redline.agent.cli",Ye="redline.agent.scope",Je="redline.agent.settings",Xe="redline.agent.offer",Ft=()=>{try{return localStorage.getItem(Ve)}catch{return null}},Ze=o=>{try{o?localStorage.setItem(Ve,o):localStorage.removeItem(Ve)}catch{}},Bt=()=>{try{let o=localStorage.getItem(Ye);return o==="app"||o==="page"?o:null}catch{return null}},Qe=o=>{try{o?localStorage.setItem(Ye,o):localStorage.removeItem(Ye)}catch{}},Wt=()=>{try{return localStorage.getItem(Xe)!=="0"}catch{return!0}},et=o=>{try{o===!1?localStorage.setItem(Xe,"0"):localStorage.removeItem(Xe)}catch{}};function Ut(){try{let o=JSON.parse(localStorage.getItem(Je)??"{}");return o&&typeof o=="object"&&!Array.isArray(o)?o:{}}catch{return{}}}var tt=o=>{try{o&&Object.keys(o).length?localStorage.setItem(Je,JSON.stringify(o)):localStorage.removeItem(Je)}catch{}};function be(o,l,s){return o.find(a=>a.id===l)?.id??o.find(a=>a.id===s)?.id??o[0]?.id??""}function Le(o,l){let s=o?l[o.id]:void 0;if(!o||!s)return{};let a=s.model&&o.models?.some(w=>w.value===s.model)?s.model:void 0,f=s.effort&&o.efforts?.some(w=>w.value===s.effort)?s.effort:void 0;return{...a?{model:a}:{},...f?{effort:f}:{}}}var we=`${zt}/agent`,mn={blocked:4,working:3,error:2,done:1,idle:0};function nt(o){let l,s=-1;for(let a of o){if(!a.running&&a.status.state!=="done"&&a.status.state!=="error")continue;let f=mn[a.status.state]??0;f>=s&&(l=a,s=f)}return l}var qt="#a3a3ad",bn="#5c5c66",wn="\x1B",Kt="\x1B[D",_t="\x1B[C",at="Apply notes",vn=500;function Vt(o){let l=o.status;if(!o.running&&l.state!=="done"&&l.state!=="error")return null;let s=f=>`${o.command}: ${f}${l.progress!==void 0&&l.state==="working"?` ${l.progress}%`:""}${l.msg?` \xB7 ${l.msg}`:""}`,a={toolbar:"outline",launcher:"ring"};switch(l.state){case"working":return{...a,color:"#4f8cff",spin:!0,title:s(l.source==="activity"?"busy":"working")};case"blocked":return l.kind==="permission"?{...a,color:"#ff9f0a",pulse:!0,title:s("waiting for your approval")}:{...a,color:"#ffd60a",pulse:!0,title:s("waiting for your answer")};case"done":return{...a,color:"#3ecf8e",title:s("done")};case"error":return{...a,color:"#ff453a",title:s("failed")};default:return{color:qt,toolbar:!1,launcher:!1,title:s("ready")}}}function se(o){let l=o.status,s=l.msg||void 0;if(!o.running&&l.state!=="done"&&l.state!=="error")return{label:o.exitCode===void 0?"Not started":`Stopped${o.exitCode?` (exit ${o.exitCode})`:""}`,color:bn};let a=Vt(o)?.color??qt;switch(l.state){case"working":return{label:l.progress!==void 0?`Working ${l.progress}%`:"Working\u2026",msg:s,color:a};case"blocked":return{label:l.kind==="permission"?"Needs your approval":"Needs your answer",msg:s,color:a};case"done":return{label:"Done",msg:s,color:a};case"error":return{label:"Failed",msg:s,color:a};default:return{label:"Ready",msg:s,color:a}}}function kn(o,l,s=it(l)){let a=s.join(", "),f=l.notes("all"),w=[...new Set(s.map($=>f.find(k=>k.id===$)?.page).filter($=>!!$))],x=w.length>1?`pages ${w.join(", ")}`:`page ${w[0]??l.page()}`;return o.replace(/\{(page|pages|url|ids)\}/g,($,k)=>k==="page"?l.page():k==="pages"?x:k==="url"?location.href:a||"none")}var it=(o,l="page")=>o.notes(l).filter(s=>!s.done).map(s=>s.id);function xn(o,l,s="page"){let a=new Set(l.filter(f=>f.running).flatMap(f=>f.sent??[]));return it(o,s).filter(f=>!a.has(f))}var re=o=>o.prompt.includes("{ids}"),st=o=>((o.body??"").trim()||(o.type==="text"?o.to??"":"")||o.type).replace(/\s+/g," ").trim(),rt=(o,l=18)=>{let s=o.replace(/\s+/g," ").trim();return s.length>l?s.slice(0,l-1).trimEnd()+"\u2026":s};function yn(o,l=""){return o.length?rt(st(o[0]))+(o.length>1?` +${o.length-1}`:""):l}function $n(o){let l=o.match(/\p{Lu}/gu)??[];return l.length?l.slice(0,2).join(""):o.split(/[\s._-]+/).filter(Boolean).slice(0,2).map(s=>s[0].toUpperCase()).join("")}function ot(o){return o.running?o.status.state==="idle"?1:0:2}function Sn(o,l,s=3){let a=new Set(o.filter(x=>x.id===l||x.running&&x.status.state==="blocked").map(x=>x.id)),f=[...o].reverse();for(let x of[0,1,2])for(let $ of f)a.size<s&&ot($)===x&&a.add($.id);let w=x=>x.map(($,k)=>({s:$,i:k})).sort(($,k)=>ot($.s)-ot(k.s)||$.i-k.i).map($=>$.s.id);return{shown:w(o.filter(x=>a.has(x.id))),hidden:w(o.filter(x=>!a.has(x.id)))}}var Cn=/\.(png|jpe?g|gif|webp|avif|svg)$/i;function En(o){try{let{hostname:l,protocol:s}=new URL(o);return/^https?:$/.test(s)&&/^(localhost|127(\.\d+){3}|\[::1\]|[^.]+\.localhost)$/i.test(l)}catch{return!1}}function Tn(o){let l=o.filter(a=>a.source==="mentioned"),s=o.filter(a=>a.source!=="mentioned");return{images:s.filter(a=>a.kind==="image"||a.kind==="diff"&&a.status!=="D"&&Cn.test(a.path??"")),changed:s.filter(a=>a.kind==="diff"),files:s.filter(a=>a.kind==="file"),links:s.filter(a=>a.kind==="url"),mentioned:l}}function Gt(o){let l=[o.ahead?`${o.ahead} commit${o.ahead===1?"":"s"}`:"",o.dirty?"uncommitted changes":""].filter(Boolean);return l.length?l.join(" \xB7 "):o.dirty===void 0?"checking\u2026":"no changes"}function Bn(o,l){return l.has(o.id)?o.done?"done":"sent":null}function Ln(o,l,s){let a=[...l].reverse().find(w=>w.sent?.includes(o.id));if(!a)return null;if(o.done)return{cls:"done",text:`\u2713 done by ${s(a)}`};let f=a.running?a.status.state:"stopped";return f==="working"?a.focus&&a.focus!==o.id?{cls:"sent",text:`\u2933 sent to ${s(a)}, next`}:{cls:"sent working",text:`${s(a)} is working on it`}:f==="blocked"?{cls:"sent asking",text:`${s(a)} needs your answer`}:{cls:"sent",text:`\u2933 sent to ${s(a)}`}}var ie=o=>`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${o}</svg>`,In={term:ie('<rect x="3" y="4.5" width="18" height="15" rx="2.5"/><path d="M7.5 9.5l3 2.5-3 2.5"/><path d="M12.5 15h4"/>'),gear:ie('<path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/>'),more:ie('<circle cx="5" cy="12" r="1.4" fill="currentColor" stroke="none"/><circle cx="12" cy="12" r="1.4" fill="currentColor" stroke="none"/><circle cx="19" cy="12" r="1.4" fill="currentColor" stroke="none"/>'),x:ie('<path d="M7 7l10 10M17 7L7 17"/>'),down:ie('<path d="M7 10l5 5 5-5"/>'),clip:ie('<path d="M20.5 11.5l-8.2 8.2a5 5 0 0 1-7.1-7.1l8.6-8.6a3.4 3.4 0 0 1 4.8 4.8l-8.6 8.6a1.7 1.7 0 0 1-2.4-2.4l7.9-7.9"/>'),branch:ie('<circle cx="6" cy="5.5" r="2.2"/><circle cx="6" cy="18.5" r="2.2"/><circle cx="18" cy="8" r="2.2"/><path d="M6 7.7v8.6"/><path d="M18 10.2c0 4-4.5 3.8-10.4 7"/>')},V=o=>{let l=document.createElement("span");return l.className="ag-ic",l.innerHTML=In[o],l},Mn=`
|
|
2
2
|
.ag-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
3
3
|
.xbar[data-toolbar="agent"] button:focus-visible, .attach[data-toolbar="agent"] :is(button, input, select, label):focus-visible, .win-controls .ag-wend:focus-visible { outline: 2px solid var(--ink-2); outline-offset: 1px; }
|
|
4
4
|
.ag-ic { display: grid; place-items: center; width: 16px; height: 16px; flex: none; }
|
|
@@ -186,8 +186,8 @@ var Nt="/__redline";async function Rt(o){let l=await Ue(o),s=async(a,m={})=>{let
|
|
|
186
186
|
.bar button.ag-icon { padding: 6px; }
|
|
187
187
|
.ag-row .ag-row-main { grid-template-columns: 8px auto auto 1fr; padding: 10px 4px 10px 8px; }
|
|
188
188
|
.ag-radio { padding: 9px 10px; }
|
|
189
|
-
}`,
|
|
190
|
-
`)},
|
|
191
|
-
`]:[],...g.map(dn)]))),r.question&&p.append(t("div",{class:"ag-q"},r.question));let c=t("div",{class:"ag-opts"});r.options.forEach((g,f)=>{let h=t("span",{class:"n",attrs:{"aria-hidden":"true"}},String(g.n??f+1));if(g.input){let C=t("input",{placeholder:g.label.replace(/\.$/,"")+"\u2026",disabled:ce,data:{k:`opt:${f}`},attrs:{"aria-label":g.label.replace(/\.$/,"")}}),u=()=>{let T=C.value.trim();T&&(C.blur(),gt(f,T))};C.addEventListener("keydown",T=>{T.key==="Enter"&&(T.preventDefault(),u())}),C.addEventListener("focus",()=>{Le=!0}),C.addEventListener("blur",()=>{Le=!1}),c.append(t("div",{class:"ag-input"},h,C,t("button",{onclick:u,disabled:ce},"Send")));return}c.append(t("button",{class:"ag-opt"+(g.selected?" sel":""),disabled:ce,onclick:()=>{gt(f)},title:g.selected?"Selected in the CLI":"",data:{k:`opt:${f}`}},h,t("span",{},g.label),g.description?t("span",{class:"d"},g.description):null))}),p.append(c,t("div",{class:"ag-foot"},t("span",{},r.hint??""),t("button",{title:"Esc in the CLI",onclick:()=>fe(fn)},"Cancel"),t("button",{title:`Show ${H(n)}'s CLI window`,onclick:()=>se?.show()},"Open CLI window"))),e.append(W(),p)}function xt(e,n,r){let i=t("div",{class:"ag-list ag-menu",attrs:{role:"menu","aria-label":e}},t("h4",{attrs:{"aria-hidden":"true"}},e)),p=n.some(f=>f.checked!==void 0),c=n.find(f=>f.checked)?.k??n[0]?.k,g=n.map(f=>t("button",{class:"ag-mi",title:f.title??"",data:{k:f.k},tabIndex:f.k===c?0:-1,attrs:{role:p?"menuitemradio":"menuitem","aria-checked":p?String(!!f.checked):void 0,"aria-disabled":f.disabled?"true":void 0},onclick:()=>{f.disabled||f.act()}},t("b",{},f.text),f.sub?t("span",{},f.sub):null));return Ln(i,g),i.append(...g),r&&i.append(t("div",{class:"ag-hint"},r)),i}function en(){return xt("Run the next prompt with",v().map(e=>({k:`cli:${e.id}`,text:e.name,sub:e.name!==e.command?e.command:void 0,checked:e.id===x,title:`Run ${e.name} (${e.command}) for the next prompt${U()?"":", in place of the shared session"}`,act:()=>{yt(e.id),y=null,R="primary",o.toast(`Next prompt: ${e.name}`),P()}})),"Model and effort: \u2699")}function tn(){let e=s.commands[0],n=O==="app"?"page":"app",r=e&&ne(e)?(()=>{let i=X(n).length;return{k:"cmd:scope",text:`${e.label===Qe?`Apply ${i} note${i===1?"":"s"}`:e.label} ${n==="app"?"on every page":"on this page only"}`,sub:"this time",disabled:i===0,title:`${e.title??e.prompt} \xB7 the open notes ${$e(n)}, this time only (\u2699 \u203A Notes sets it for good)`,act:()=>{y=null,R="more-cmds",M?.render(),de(e,n)}}})():null;return xt("Prompts",[...r?[r]:[],...s.commands.slice(1).map((i,p)=>{let c=ne(i)?X().length:-1;return{k:`cmd:${p}`,text:i.label,sub:c>=0?`${c} note${c===1?"":"s"}`:void 0,disabled:c===0,title:i.title??i.prompt,act:()=>{y=null,R="more-cmds",M?.render(),de(i)}}})],`with ${D()}${U()?", in a new session":""}`)}let yt=e=>{x=e,Ve(e)},Oe=null,ze=null;function $t(){let e=s.defaults??{},n=t("div",{class:"ag-set",attrs:{role:"dialog","aria-label":"Agent settings"}},t("h4",{attrs:{"aria-hidden":"true"}},"Agent settings")),r=(d,w,$,S,E)=>{let z=t("fieldset",{},t("legend",{},d));for(let A of $){let j=t("input",{type:"radio",name:w,value:A.value,checked:A.value===S,data:{k:A.k}});j.addEventListener("change",()=>{j.checked&&E(A.value)}),z.append(t("label",{class:"ag-radio"},j,t("span",{},A.label),A.sub?t("small",{},A.sub):null))}return z},i=(d,w,$,S,E,z)=>{let A=`ag-${w}`,j=t("select",{id:A,data:{k:w}},t("option",{value:""},`Default${E?` (${E})`:""}`),...$.map(G=>t("option",{value:G.value,selected:G.value===S},G.name??G.value)));return j.addEventListener("change",()=>z(j.value)),t("div",{class:"ag-field"},t("label",{class:"ag-lbl",htmlFor:A},d),j)},p=(d,w,$,S,E,z)=>{let A=ze===d,j=`ag-sb-${w.replace(/[^\w-]/g,"_")}`,G=t("button",{class:"ag-srow",data:{k:w},attrs:{"aria-expanded":String(A),"aria-controls":A?j:void 0},title:A?`Close the options of ${$}`:`${$}: ${E}. Open its options`,onclick:()=>{ze=A?null:d,R=w,Q()}},t("span",{class:"ag-sname"},$),S?t("span",{class:"ag-sbadge"},S):null,t("small",{},E),V("down"));return t("div",{class:"ag-sgroup"+(A?" open":"")},G,A?t("div",{class:"ag-sbody",id:j},...z()):null)},c=(d,w)=>{let $=d?.find(S=>S.value===w);return $?$.name??$.value:void 0},g=d=>e,f=d=>{if(d.pending)return"Asking for its models\u2026";if(!d.models?.length&&!d.efforts?.length)return"Its own config";let w=ye(d,N),$=g(d);return[d.models?.length?c(d.models,w.model)??($.model?`Default (${$.model})`:"Default model"):null,d.efforts?.length?c(d.efforts,w.effort)??($.effort?`default (${$.effort})`:"default effort"):null].filter(Boolean).join(" \xB7 ")},h=(d,w,$)=>{let S={...N[d.id],[w]:$||void 0};S.model||delete S.model,S.effort||delete S.effort,N={...N,[d.id]:S},!S.model&&!S.effort&&delete N[d.id],Xe(N),Q()},C=d=>{let w=ye(d,N),$=g(d),S=[];return k()&&S.push(d.id===x?t("div",{class:"ag-note"},`${d.name} runs the next prompt.`):t("button",{class:"ag-use",data:{k:`use-cli:${d.id}`},title:`Run ${d.name} for the next prompt`,onclick:()=>{yt(d.id),R=`set-cli:${d.id}`,Q(),P()}},`Use ${d.name} for the next prompt`)),d.pending?S.push(t("div",{class:"ag-field"},t("label",{class:"ag-lbl",htmlFor:"ag-set-model"},"Model"),t("select",{id:"ag-set-model",disabled:!0,data:{k:"set-model"}},t("option",{},`Asking ${d.name} for its models\u2026`)))):d.models?.length&&S.push(i("Model","set-model",d.models,w.model,$.model,E=>h(d,"model",E))),d.efforts?.length&&S.push(i("Effort","set-effort",d.efforts,w.effort,$.effort,E=>h(d,"effort",E))),!d.pending&&!d.models?.length&&!d.efforts?.length&&S.push(t("div",{class:"ag-note"},`${d.name} offers no model or effort choice here: it uses its own config.`)),S};n.append(t("div",{class:"ag-lbl"},k()?"Agents":"Agent"));for(let d of v())n.append(p(`cli:${d.id}`,`set-cli:${d.id}`,d.name,k()&&d.id===x?"In use":null,f(d),()=>C(d)));n.append(p("notes","set-notes","Notes",null,O==="app"?"Every page":"This page only",()=>[r("Apply hands over","ag-set-scope",[{value:"app",label:"Open notes on every page",sub:`${X("app").length} now`,k:"set-scope:app"},{value:"page",label:"Open notes on this page",sub:`${X("page").length} now`,k:"set-scope:page"}],O,d=>{Ut(d),Q(),P()}),(()=>{let d=t("input",{type:"checkbox",checked:le,data:{k:"set-offer"}});return d.addEventListener("change",()=>{le=d.checked,Je(le),Q()}),t("fieldset",{},t("legend",{},"After a save"),t("label",{class:"ag-radio"},d,t("span",{},"Offer to send the new note to the agent")))})()]));let u=a.worktrees,T=(U()?`New per prompt, up to ${a.max}`:"One kept going")+(u?.on&&U()?" \xB7 worktrees":"");return n.append(p("sessions","set-sessions","Sessions",null,T,()=>{let d=[r("Sessions","ag-set-mode",[{value:"fresh",label:"New session per prompt",sub:`up to ${a.max} at once`,k:"set-mode:fresh"},{value:"shared",label:"Keep one session going",sub:"keeps its context",k:"set-mode:shared"}],a.mode,w=>{J("/mode",{mode:w}).then($=>{a={...a,...$},Q(),P()}).catch(F)})];if(u){let w=!u.git,$=t("input",{type:"checkbox",checked:u.on,disabled:w,data:{k:"set-wt"},attrs:{"aria-describedby":"ag-wt-help"}});$.addEventListener("change",()=>{J("/worktrees",{on:$.checked}).then(E=>{a={...a,...E},Q(),P()}).catch(E=>{$.checked=!$.checked,F(E)})});let S=w?`Needs a git repository (${u.why??"checking\u2026"}).`:`Its own branch (redline/\u2026) and folder in .redline/worktrees, so sessions never edit the same files; when it ends: keep, merge or discard the branch.${a.mode==="shared"?" Only with a new session per prompt.":""} No node_modules there: the agent can edit and use git; running the app or tests in it needs an install.`;d.push(t("fieldset",{},t("legend",{},"Worktrees"),t("label",{class:"ag-radio"+(w?" off":"")},$,t("span",{},"Each new session in its own git worktree")),t("div",{class:"ag-help",id:"ag-wt-help"},S)))}return d})),n.append(t("footer",{},t("span",{},"Applies to new sessions."),t("button",{data:{k:"set-reset"},title:"Forget this browser's choices: the project's CLI, model, effort, notes and sessions",onclick:nn},"Reset to project defaults"))),n.addEventListener("keydown",d=>{d.key==="Escape"&&/^(INPUT|SELECT)$/.test(d.target.tagName)&&(d.preventDefault(),ge())}),Oe=n,n}function Q(){if(!Oe?.isConnected){M?.render();return}let e=he()?.activeElement?.closest("[data-k]")?.dataset.k,n=Oe,r=$t();n.replaceWith(r),e&&r.querySelector(`[data-k="${CSS.escape(e)}"]`)?.focus(),M?.render()}async function nn(){N={},Xe(null),O="app",Ye(null),le=!0,Je(null),x=pe(v(),null,s.cli),Ve(null);let e=s.defaults?.sessions??"fresh";if(a.mode!==e)try{a={...a,...await J("/mode",{mode:e})}}catch(r){F(r)}let n=!!s.defaults?.worktrees;if(a.worktrees?.git&&a.worktrees.on!==n)try{a={...a,...await J("/worktrees",{on:n})}}catch(r){F(r)}R="set-reset",o.toast("Agent settings: back to the project's defaults"),P()}let He=new Map,we=new Set,je=!1,De=new Map,St=(e,n)=>`${ue}/file?id=${encodeURIComponent(e)}&path=${encodeURIComponent(n)}&token=${encodeURIComponent(l.info.token)}`;function an(e){let n=`${e.rounds??0}:${e.attachments??0}`,r=He.get(e.id);return r?.key===n?r.rounds:(He.set(e.id,{key:n,rounds:r?.rounds??null}),fetch(`${ue}/attachments?id=${encodeURIComponent(e.id)}&token=${encodeURIComponent(l.info.token)}`).then(i=>i.ok?i.json():null).then(i=>{i&&(He.set(e.id,{key:n,rounds:i.rounds}),y==="files"&&(je&&(je=!1,R="files-first"),M?.render()))}).catch(()=>{}),r?.rounds??null)}function on(e,n){let r=he();if(!r)return;let i=t("div",{class:"zoom",tabIndex:-1,attrs:{role:"dialog","aria-label":"Image, Esc to close"}},t("img",{src:e,alt:""})),p=()=>{i.remove(),n.focus()};i.addEventListener("click",p),i.addEventListener("keydown",c=>{c.key==="Escape"&&(c.preventDefault(),c.stopPropagation(),p())}),r.append(i),i.focus()}function sn(){let e=I(),n=t("div",{class:"ag-list ag-files",attrs:{role:"dialog","aria-label":`Attachments of ${Y(e)}`}},t("h4",{},`${e.label}${e.title?` \xB7 ${e.title}`:""} \xB7 attachments`)),r=e.id?an(e):[];if(!r)return je=!0,n.append(t("div",{class:"ag-hint",data:{k:"files-first"},tabIndex:-1},"Loading\u2026")),n;r.some(c=>c.items.length)||n.append(t("div",{class:"ag-hint"},"Nothing yet: files it changes, images and links it points at show here, per prompt."));let i=!0,p=c=>i?(i=!1,"files-first"):c;for(let c of r){if(!c.items.length)continue;let g=$n(c.items),f=t("section",{class:"ag-round",attrs:{"aria-label":`Prompt ${c.n}`}},t("div",{class:"ag-round-h"},t("b",{},`Prompt ${c.n}`),c.task?t("span",{},c.task):null,c.done?null:t("span",{class:"ag-live"},"working\u2026")));if(g.images.length&&f.append(t("div",{class:"ag-thumbs"},...g.images.map(u=>{let T=St(e.id,u.path),d=t("button",{class:"ag-thumb",title:`${u.title?u.title+" \xB7 ":""}${u.path} (click to zoom)`,data:{k:p(`img:${u.id}`)},attrs:{"aria-label":`Zoom ${u.title??u.path}`}},t("img",{src:T,alt:u.title??u.path??"",loading:"lazy"}));return d.onclick=()=>on(T,d),d}))),g.changed.length){let u=g.changed.reduce((d,w)=>d+(w.added??0),0),T=g.changed.reduce((d,w)=>d+(w.removed??0),0);f.append(t("div",{class:"ag-sub"},`Changed ${g.changed.length} file${g.changed.length===1?"":"s"}`,t("span",{class:"ag-num"},t("i",{class:"add"},`+${u}`)," ",t("i",{class:"del"},`\u2212${T}`))));for(let d of g.changed){let w=`${e.id}:${c.n}:${d.path}`,$=we.has(w),S=t("button",{class:"ag-frow",data:{k:p(`chg:${d.id}`)},attrs:{"aria-expanded":String($)},title:$?"Hide the diff":"Show the diff",onclick:()=>{we.has(w)?we.delete(w):(we.add(w),De.has(w)||fetch(`${ue}/diff?id=${encodeURIComponent(e.id)}&round=${c.n}&path=${encodeURIComponent(d.path)}&token=${encodeURIComponent(l.info.token)}`).then(E=>E.ok?E.text():"(no diff)").then(E=>{De.set(w,E),M?.render()}).catch(()=>{})),R=`chg:${d.id}`,M?.render()}},t("span",{class:"ag-st",attrs:{"aria-label":{A:"added",D:"deleted",M:"modified"}[d.status??"M"]??"changed"}},d.status??"M"),t("span",{class:"ag-path"},d.path??""),t("span",{class:"ag-num"},t("i",{class:"add"},`+${d.added??0}`)," ",t("i",{class:"del"},`\u2212${d.removed??0}`)));if(f.append(S),$){let E=De.get(w);f.append(E===void 0?t("div",{class:"ag-hint"},"Loading the diff\u2026"):t("pre",{class:"ag-ctx ag-diff"},...E.split(`
|
|
192
|
-
`).filter(
|
|
193
|
-
`]:[],t("span",{class:
|
|
189
|
+
}`,U=()=>Object.assign(document.createElement("style"),{textContent:Mn});function t(o,l={},...s){let{class:a,data:f,attrs:w,...x}=l,$=Object.assign(document.createElement(o),x);a&&($.className=a);for(let[k,N]of Object.entries(f??{}))$.dataset[k]=N;for(let[k,N]of Object.entries(w??{}))N!==!1&&N!==void 0&&$.setAttribute(k,N);return $.append(...s.filter(k=>!!k)),$}function An(o,l){o.addEventListener("keydown",s=>{let a=l.indexOf(s.target);if(a<0)return;let f=s.key==="ArrowDown"?a+1:s.key==="ArrowUp"?a-1:s.key==="Home"?0:s.key==="End"?l.length-1:null;f!==null&&(s.preventDefault(),l[(f+l.length)%l.length].focus())})}async function Rn(o){if(!(o.version>=5)||typeof o.addToolbar!="function")return;let l,s;try{l=await Ht(we),s=l.info}catch{return}let a=s,f=()=>s.command,w=()=>s.clis??[],x=()=>w().length>1,$=e=>w().find(n=>n.id===e),k=be(w(),Ft(),s.cli),N=Ut(),A=Bt()??"app",ne=e=>{A=e,Qe(e)},le=(e=A)=>e==="app"?"on every page":"on this page",ae=Wt(),oe=null,ue=()=>$(k),P=()=>ue()?.name??f(),z=e=>$(e.cli)?.name??w()[0]?.name??f(),Y=()=>({id:"",label:"",running:!1,command:f(),cli:k,status:{state:"idle",source:"none"},sent:[]}),B=null,I=()=>a.sessions.find(e=>e.id===B)??a.sessions[a.sessions.length-1]??Y(),Yt=()=>a.sessions.length>1,K=()=>a.mode==="fresh",j=e=>Yt()&&e.label?`${z(e)} ${e.label}`:z(e),J=e=>e.title||e.label,lt=new Set,dt=e=>`${e.id}:${e.status.msg??""}`,ct=e=>e.running&&e.status.state==="done"&<.has(dt(e)),gt=e=>e.running?ct(e)?"seen":e.status.state:"stopped",Jt=()=>new Set(a.sessions.flatMap(e=>e.sent??[])),pt=()=>s.hotkey?s.hotkey.split("+").map(e=>e.length===1?e.toUpperCase():e[0].toUpperCase()+e.slice(1)).join("+"):"",Ie=e=>{let n=o.notes("all");return e.map(r=>n.find(i=>i.id===r)).filter(r=>!!r)},X=(e,n={})=>l.post(e,n),de=(e,n={})=>X(e,{...n,...I().id?{id:I().id}:{}}),W=e=>o.toast(`Agent: ${e.message}`,!0),Z=(e=A)=>xn(o,a.sessions,e),fe=async(e,n=A,r)=>{let i=re(e)?r??Z(n):[];K()?o.toast(`Starting a new ${P()} session\u2026`):(!I().running||x()&&I().cli!==k)&&o.toast(`Starting ${P()}\u2026`);try{let p=await X("/send",{text:kn(e.prompt,o,i),notes:i,title:yn(Ie(i),e.label),task:e.label,...!K()&&I().id?{id:I().id}:{},...x()?{cli:k}:{},...Le(ue(),N)});p?.id&&(B=p.id,H())}catch(p){W(p)}},ut=e=>{de("/answer",{choice:e}).catch(W)},he=!1,ft=async(e,n)=>{he=!0,M?.render();try{await de("/choose",n===void 0?{index:e}:{index:e,text:n})}catch(r){W(r)}finally{setTimeout(()=>{he=!1,M?.render()},400)}},ve=e=>{de("/input",{data:e}).catch(W)},ht=new Set,Me={id:"",asking:!1},Ae=!1,y=null,O=null,Re=null,mt=null,ke=()=>Re?.getRootNode(),Xt=()=>{let e=ke()?.activeElement;O||!e||!(Re?.contains(e)||mt?.contains(e))||(O=e.closest("[data-k]")?.dataset.k??null)},Zt=()=>{let e=O,n=ke();if(O=null,!e||!n||!("querySelector"in n))return;let r=n.querySelector(`[data-k="${CSS.escape(e)}"]`);r&&n.activeElement!==r&&r.focus()},Q=(e,n=null)=>{y=y===e?null:e,O=y?n:O,M?.render()},Qt={list:"more",switch:"primary",cmds:"more-cmds",settings:"gear",branches:"branches",files:"att"},me=()=>{if(!y)return!1;let e=y==="list"&&matchMedia("(max-width: 560px)").matches?"sw":Qt[y];return y=null,O=e,M?.render(),!0},G=null,Ne=0,Pe=e=>e.running&&(e.status.state==="working"||e.status.state==="blocked"),bt=()=>{M?.render(),Ke()},wt=e=>{if(Pe(e)&&G!==e.id){G=e.id,clearTimeout(Ne),Ne=window.setTimeout(()=>{G=null,bt()},2500),bt();return}G=null,clearTimeout(Ne),X("/end",{id:e.id}).then(()=>{e.worktree&&(y="branches",O=`wt-keep:${e.worktree.branch}`,M?.render())}).catch(W)},vt=e=>G===e.id?`Press again to end ${j(e)}`:e.running?`End ${j(e)}: stop the CLI and close the session${Pe(e)?" (asks first)":""}`:`Close ${j(e)} (ended)`,kt=(e,n)=>t("button",{class:"ag-x"+(G===e.id?" armed":""),title:vt(e),data:{end:e.id,k:n},attrs:{"aria-label":G===e.id?`Press again to end ${J(e)}`:`End ${J(e)}`},onclick:r=>{r.stopPropagation(),wt(e)}},G===e.id?"End?":V("x")),_=null,xt=e=>_?.contentWindow?.postMessage(e,location.origin),Oe=()=>`${we}/terminal${I().id?`?id=${encodeURIComponent(I().id)}`:""}`,ce=null,xe=null,M=null,ze=null,He=new Map,De=t("span",{class:"ag-sr",attrs:{role:"status"}}),yt=e=>o.addButton({id:"agent",label:"Agent",key:s.key===!1?void 0:s.key||"a",title:e??`${P()}: agent toolbar${s.hotkey?` \xB7 ${pt()} from anywhere`:""}`,onClick:()=>M?.show(),active:()=>!!M?.isOpen()});yt();let $t=e=>{let n=se(e),r=Ie(e.sent??[]);return[`${e.label} \xB7 ${z(e)} \xB7 ${n.label}`,e.task&&`Prompt: ${e.task}`,r.length?`Notes: ${r.slice(0,3).map(i=>rt(st(i),40)).join("; ")}${r.length>3?` (+${r.length-3})`:""}`:e.sent?.length?`Notes: ${e.sent.length}`:"",[e.model&&`Model: ${e.model}`,e.effort&&`Effort: ${e.effort}`].filter(Boolean).join(" \xB7 "),e.focus&&e.running&&`On: ${(i=>i?rt(st(i),50):e.focus)(Ie([e.focus])[0])}`,e.worktree&&`Branch: ${e.worktree.branch} (${e.worktree.path})`,n.msg&&`Last: ${n.msg}`,e.status.state==="blocked"&&e.running?"Click to answer":""].filter(Boolean).join(`
|
|
190
|
+
`)},ye=0,ge=!1,en=e=>{if(!x()||e.button!==0)return;ge=!1,clearTimeout(ye);let n=e.clientX,r=e.clientY,i=c=>{Math.hypot(c.clientX-n,c.clientY-r)>10&&clearTimeout(ye)},p=()=>{clearTimeout(ye);for(let c of["pointerup","pointercancel"])window.removeEventListener(c,p,!0);window.removeEventListener("pointermove",i,!0),ge&&setTimeout(()=>{ge=!1},50)};ye=window.setTimeout(()=>{ge=!0,y=null,Q("switch",`cli:${k}`)},vn);for(let c of["pointerup","pointercancel"])window.addEventListener(c,p,!0);window.addEventListener("pointermove",i,!0)};function tn(e,n){let r=re(e)?Z().length:-1,i=r>=0?it(o,A).length-r:0,p=r===0&&A==="page"?Z("app").length:0,c=e.label===at&&r>=0?t("span",{},r?`Apply ${r}`:"Apply",t("span",{class:"ag-wide"},r===1?" note":" notes")):e.label,g=r===0||n&&!K(),h="Hold, right-click or Alt+\u2193 to switch the agent",m=t("button",{class:"ag-primary",data:{k:"primary",cmd:e.label,...r>=0?{count:String(r)}:{}},title:[e.title??e.prompt,r>=0&&`the open notes ${le()}`,`with ${P()}`,K()&&"in a new session",i&&`${i} note${i===1?" is":"s are"} already with a session`,r===0&&(A==="app"?"no open notes":"no open notes on this page"),p&&`${p} on other pages: \u22EF or \u2699 \u203A Notes`,x()&&h].filter(Boolean).join(" \xB7 "),attrs:{"aria-disabled":g?"true":void 0,"aria-keyshortcuts":x()?"Alt+ArrowDown Shift+F10":void 0,"aria-description":x()?`Runs ${P()}. ${h}.`:void 0},onclick:()=>{if(ge){ge=!1;return}g||fe(e)}},c,r>=0&&e.label!==at?t("span",{class:"count"},String(r)):null);return m.addEventListener("pointerdown",en),m.addEventListener("contextmenu",E=>{x()&&(E.preventDefault(),y!=="switch"&&Q("switch",`cli:${k}`))}),m.addEventListener("keydown",E=>{!x()||!(E.altKey&&E.key==="ArrowDown"||E.shiftKey&&E.key==="F10"||E.key==="ContextMenu")||(E.preventDefault(),y!=="switch"&&Q("switch",`cli:${k}`))}),m}function nn(e){Xt(),Re=e;let n=I(),r=se(n),i=n.status,p=n.running&&i.state==="blocked",c=p&&(!!n.prompt?.options.length||i.kind==="permission"&&s.approve),g=(b,pe,_e,Ge="",Ee="",Te={})=>t("button",{class:Ge,title:pe,onclick:_e,data:Ee?{k:Ee}:{},attrs:Te},b),h=(b="")=>t("div",{class:`sep ${b}`});n.running&&i.state==="done"&<.add(dt(n));let m=`${z(n)} \xB7 ${r.label}`;De.textContent!==m&&(De.textContent=m);let E=t("div",{class:"ag-chip ag-desk",title:`${j(n)}: ${r.label}${r.msg?` \xB7 ${r.msg}`:""}`,data:{state:n.running?i.state:"stopped"}},t("span",{class:"ag-dot"}),t("span",{class:"ag-who"},z(n)),t("span",{class:"ag-mid",attrs:{"aria-hidden":"true"}}," \xB7 "),t("b",{},r.label),r.msg&&!c?t("span",{class:"ag-msg"},r.msg):null);E.style.setProperty("--c",r.color);let u=Sn(a.sessions.map(b=>ct(b)?{...b,status:{...b.status,state:"idle"}}:b),n.id),L=a.sessions.filter(b=>u.hidden.includes(b.id)),d=null;if(L.length){let b=nt(L.filter(Pe));d=g(`+${L.length}`,`${L.length} more session${L.length===1?"":"s"}: show all`,()=>Q("list",`row:${L[0].id}`),"ag-more"+(b?" lit":""),"more",{"aria-haspopup":"dialog","aria-expanded":String(y==="list"),"aria-label":`${L.length} more sessions`}),b&&d.style.setProperty("--c",se(b).color)}let v=new Set(a.sessions.map(b=>b.cli)).size>1,S=a.sessions.length?t("div",{class:"ag-tabs ag-desk",attrs:{role:"group","aria-label":"Sessions"}},...u.shown.map(b=>a.sessions.find(pe=>pe.id===b)).map(b=>{let pe=se(b),_e=gt(b),Ge=t("button",{class:"ag-tab-main",title:$t(b),data:{k:`tab:${b.id}`},attrs:{"aria-current":b.id===n.id?"true":void 0,"aria-label":`${J(b)}, ${z(b)}, ${pe.label}`},onclick:()=>{B=b.id,y=null,H()}},t("span",{class:"ag-dot"}),v?t("span",{class:"ag-ini",attrs:{"aria-hidden":"true"}},$n(z(b))):null,t("span",{class:"ag-name"},J(b))),Ee=b.attachments?t("button",{class:"ag-att",title:`${b.attachments} attachment${b.attachments===1?"":"s"}: files changed, images, links`,data:{k:`att:${b.id}`},attrs:{"aria-label":`${b.attachments} attachment${b.attachments===1?"":"s"} of ${J(b)}`,"aria-haspopup":"dialog","aria-expanded":String(y==="files"&&b.id===n.id)},onclick:hn=>{hn.stopPropagation();let Ot=y==="files"&&B===b.id;B=b.id,y=Ot?null:"files",O=Ot?`att:${b.id}`:"files-first",H()}},V("clip"),t("span",{},String(b.attachments))):null,Te=t("div",{class:"ag-tab"+(b.id===n.id?" cur":""),data:{id:b.id,state:_e}},Ge,Ee,kt(b,`x:${b.id}`));return Te.style.setProperty("--c",pe.color),Te}),d,h()):null,C=g(t("span",{class:"ag-name"},n.id?J(n):"Sessions"),"All sessions",()=>Q("list",n.id?`row:${n.id}`:"list-done"),"ag-switch ag-phone","sw",{"aria-haspopup":"dialog","aria-expanded":String(y==="list"),"aria-label":`Sessions: ${n.id?`${J(n)}, ${r.label}`:"none"}`});C.prepend(t("span",{class:"ag-dot"})),C.append(V("down")),C.style.setProperty("--c",r.color),C.dataset.state=n.running?i.state:"stopped";let[T,...D]=s.commands,R=T?[tn(T,p)]:[];(D.length||T&&re(T))&&R.push(g(V("more"),"More prompts",()=>Q("cmds",T&&re(T)?"cmd:scope":"cmd:0"),"ag-icon ag-cmds","more-cmds",{"aria-label":"More prompts","aria-haspopup":"menu","aria-expanded":String(y==="cmds")}));let F=!!ce?.isOpen(),q=p&&!c,Nt=g(V("term"),F?"Hide the CLI window (the session keeps running)":q?`${j(n)} is asking: answer in the CLI window`:`Show ${j(n)}'s CLI window`,()=>ce?.toggle(),"ag-icon ag-term"+(q&&!F?" ask":""),"term",{"aria-label":"CLI window","aria-pressed":String(F)});Nt.dataset.cli="";let fn=g(V("gear"),"Agent settings: CLI, model, effort, sessions",()=>{Fe=null,Q("settings",`set-cli:${k}`)},"ag-icon ag-gear","gear",{"aria-label":"Agent settings","aria-haspopup":"dialog","aria-expanded":String(y==="settings")}),te=a.worktrees?.left??[],Pt=te.length?g(t("span",{class:"ag-bc"},V("branch"),t("span",{class:"count"},String(te.length))),`${te.length} ended session${te.length===1?"":"s"}' branch${te.length===1?"":"es"}: keep, merge or discard`,()=>Q("branches",`wt-keep:${te[0].branch}`),"ag-icon ag-branches","branches",{"aria-label":`${te.length} branch${te.length===1?"":"es"} to keep, merge or discard`,"aria-haspopup":"dialog","aria-expanded":String(y==="branches")}):null;e.replaceChildren(U(),De,E,h("ag-desk"),...S?[S]:[],C,...R,h("ag-desk"),...Pt?[Pt]:[],Nt,fn),queueMicrotask(Zt)}function an(e){if(mt=e,y==="settings")return void e.append(U(),Et());if(y==="switch"&&x())return void e.append(U(),on());if(y==="cmds")return void e.append(U(),sn());if(y==="list")return pn(e);if(y==="branches")return void e.append(U(),gn());if(y==="files")return void e.append(U(),cn());let n=I(),r=n.running?n.prompt:void 0,i=se(n),p=t("div",{class:"ag-card",data:{kind:n.status.kind??"",session:n.id},attrs:{role:"group","aria-label":`${j(n)} asks`}});if(p.style.setProperty("--c",i.color),p.append(t("div",{class:"ag-who"},t("span",{class:"ag-dot"}),`${j(n)}${n.title?` \xB7 ${n.title}`:""} \xB7 ${i.label}`)),!r?.options.length){if(!(n.running&&n.status.state==="blocked"&&n.status.kind==="permission"&&s.approve))return;i.msg&&p.append(t("div",{class:"ag-q"},i.msg)),p.append(t("div",{class:"ag-ask"},t("button",{class:"ag-allow",title:`Approve (${j(n)}'s prompt)`,data:{k:"allow"},onclick:()=>ut("allow")},"Allow"),t("button",{class:"ag-deny",title:"Decline",data:{k:"deny"},onclick:()=>ut("deny")},"Deny")),t("div",{class:"ag-foot"},t("span",{},"Its own prompt is in the CLI window"),t("button",{title:`Show ${j(n)}'s CLI window`,onclick:()=>ce?.show()},"Open CLI window"))),e.append(U(),p);return}if(r.steps?.length){let g=r.steps.findIndex(m=>m.current),h=m=>{g>=0&&m!==g&&ve((m>g?_t:Kt).repeat(Math.abs(m-g)))};p.append(t("div",{class:"ag-steps"},t("button",{class:"nav",title:"Previous question",attrs:{"aria-label":"Previous question"},onclick:()=>ve(Kt)},"\u2190"),...r.steps.map((m,E)=>t("button",{class:(m.current?"cur ":"")+m.state,title:m.label,attrs:{"aria-current":m.current?"step":void 0},onclick:()=>h(E)},(m.state==="done"?"\u2612 ":m.state==="submit"?"\u2714 ":"\u2610 ")+m.label)),t("button",{class:"nav",title:"Next question",attrs:{"aria-label":"Next question"},onclick:()=>ve(_t)},"\u2192")))}r.lines.length&&p.append(t("pre",{class:"ag-ctx"},...r.lines.flatMap((g,h)=>[...h?[`
|
|
191
|
+
`]:[],...g.map(un)]))),r.question&&p.append(t("div",{class:"ag-q"},r.question));let c=t("div",{class:"ag-opts"});r.options.forEach((g,h)=>{let m=t("span",{class:"n",attrs:{"aria-hidden":"true"}},String(g.n??h+1));if(g.input){let E=t("input",{placeholder:g.label.replace(/\.$/,"")+"\u2026",disabled:he,data:{k:`opt:${h}`},attrs:{"aria-label":g.label.replace(/\.$/,"")}}),u=()=>{let L=E.value.trim();L&&(E.blur(),ft(h,L))};E.addEventListener("keydown",L=>{L.key==="Enter"&&(L.preventDefault(),u())}),E.addEventListener("focus",()=>{Ae=!0}),E.addEventListener("blur",()=>{Ae=!1}),c.append(t("div",{class:"ag-input"},m,E,t("button",{onclick:u,disabled:he},"Send")));return}c.append(t("button",{class:"ag-opt"+(g.selected?" sel":""),disabled:he,onclick:()=>{ft(h)},title:g.selected?"Selected in the CLI":"",data:{k:`opt:${h}`}},m,t("span",{},g.label),g.description?t("span",{class:"d"},g.description):null))}),p.append(c,t("div",{class:"ag-foot"},t("span",{},r.hint??""),t("button",{title:"Esc in the CLI",onclick:()=>ve(wn)},"Cancel"),t("button",{title:`Show ${j(n)}'s CLI window`,onclick:()=>ce?.show()},"Open CLI window"))),e.append(U(),p)}function St(e,n,r){let i=t("div",{class:"ag-list ag-menu",attrs:{role:"menu","aria-label":e}},t("h4",{attrs:{"aria-hidden":"true"}},e)),p=n.some(h=>h.checked!==void 0),c=n.find(h=>h.checked)?.k??n[0]?.k,g=n.map(h=>t("button",{class:"ag-mi",title:h.title??"",data:{k:h.k},tabIndex:h.k===c?0:-1,attrs:{role:p?"menuitemradio":"menuitem","aria-checked":p?String(!!h.checked):void 0,"aria-disabled":h.disabled?"true":void 0},onclick:()=>{h.disabled||h.act()}},t("b",{},h.text),h.sub?t("span",{},h.sub):null));return An(i,g),i.append(...g),r&&i.append(t("div",{class:"ag-hint"},r)),i}function on(){return St("Run the next prompt with",w().map(e=>({k:`cli:${e.id}`,text:e.name,sub:e.name!==e.command?e.command:void 0,checked:e.id===k,title:`Run ${e.name} (${e.command}) for the next prompt${K()?"":", in place of the shared session"}`,act:()=>{Ct(e.id),y=null,O="primary",o.toast(`Next prompt: ${e.name}`),H()}})),"Model and effort: \u2699")}function sn(){let e=s.commands[0],n=A==="app"?"page":"app",r=e&&re(e)?(()=>{let i=Z(n).length;return{k:"cmd:scope",text:`${e.label===at?`Apply ${i} note${i===1?"":"s"}`:e.label} ${n==="app"?"on every page":"on this page only"}`,sub:"this time",disabled:i===0,title:`${e.title??e.prompt} \xB7 the open notes ${le(n)}, this time only (\u2699 \u203A Notes sets it for good)`,act:()=>{y=null,O="more-cmds",M?.render(),fe(e,n)}}})():null;return St("Prompts",[...r?[r]:[],...s.commands.slice(1).map((i,p)=>{let c=re(i)?Z().length:-1;return{k:`cmd:${p}`,text:i.label,sub:c>=0?`${c} note${c===1?"":"s"}`:void 0,disabled:c===0,title:i.title??i.prompt,act:()=>{y=null,O="more-cmds",M?.render(),fe(i)}}})],`with ${P()}${K()?", in a new session":""}`)}let Ct=e=>{k=e,Ze(e)},je=null,Fe=null;function Et(){let e=s.defaults??{},n=t("div",{class:"ag-set",attrs:{role:"dialog","aria-label":"Agent settings"}},t("h4",{attrs:{"aria-hidden":"true"}},"Agent settings")),r=(d,v,S,C,T)=>{let D=t("fieldset",{},t("legend",{},d));for(let R of S){let F=t("input",{type:"radio",name:v,value:R.value,checked:R.value===C,data:{k:R.k}});F.addEventListener("change",()=>{F.checked&&T(R.value)}),D.append(t("label",{class:"ag-radio"},F,t("span",{},R.label),R.sub?t("small",{},R.sub):null))}return D},i=(d,v,S,C,T,D)=>{let R=`ag-${v}`,F=t("select",{id:R,data:{k:v}},t("option",{value:""},`Default${T?` (${T})`:""}`),...S.map(q=>t("option",{value:q.value,selected:q.value===C},q.name??q.value)));return F.addEventListener("change",()=>D(F.value)),t("div",{class:"ag-field"},t("label",{class:"ag-lbl",htmlFor:R},d),F)},p=(d,v,S,C,T,D)=>{let R=Fe===d,F=`ag-sb-${v.replace(/[^\w-]/g,"_")}`,q=t("button",{class:"ag-srow",data:{k:v},attrs:{"aria-expanded":String(R),"aria-controls":R?F:void 0},title:R?`Close the options of ${S}`:`${S}: ${T}. Open its options`,onclick:()=>{Fe=R?null:d,O=v,ee()}},t("span",{class:"ag-sname"},S),C?t("span",{class:"ag-sbadge"},C):null,t("small",{},T),V("down"));return t("div",{class:"ag-sgroup"+(R?" open":"")},q,R?t("div",{class:"ag-sbody",id:F},...D()):null)},c=(d,v)=>{let S=d?.find(C=>C.value===v);return S?S.name??S.value:void 0},g=d=>e,h=d=>{if(d.pending)return"Asking for its models\u2026";if(!d.models?.length&&!d.efforts?.length)return"Its own config";let v=Le(d,N),S=g(d);return[d.models?.length?c(d.models,v.model)??(S.model?`Default (${S.model})`:"Default model"):null,d.efforts?.length?c(d.efforts,v.effort)??(S.effort?`default (${S.effort})`:"default effort"):null].filter(Boolean).join(" \xB7 ")},m=(d,v,S)=>{let C={...N[d.id],[v]:S||void 0};C.model||delete C.model,C.effort||delete C.effort,N={...N,[d.id]:C},!C.model&&!C.effort&&delete N[d.id],tt(N),ee()},E=d=>{let v=Le(d,N),S=g(d),C=[];return x()&&C.push(d.id===k?t("div",{class:"ag-note"},`${d.name} runs the next prompt.`):t("button",{class:"ag-use",data:{k:`use-cli:${d.id}`},title:`Run ${d.name} for the next prompt`,onclick:()=>{Ct(d.id),O=`set-cli:${d.id}`,ee(),H()}},`Use ${d.name} for the next prompt`)),d.pending?C.push(t("div",{class:"ag-field"},t("label",{class:"ag-lbl",htmlFor:"ag-set-model"},"Model"),t("select",{id:"ag-set-model",disabled:!0,data:{k:"set-model"}},t("option",{},`Asking ${d.name} for its models\u2026`)))):d.models?.length&&C.push(i("Model","set-model",d.models,v.model,S.model,T=>m(d,"model",T))),d.efforts?.length&&C.push(i("Effort","set-effort",d.efforts,v.effort,S.effort,T=>m(d,"effort",T))),!d.pending&&!d.models?.length&&!d.efforts?.length&&C.push(t("div",{class:"ag-note"},`${d.name} offers no model or effort choice here: it uses its own config.`)),C};n.append(t("div",{class:"ag-lbl"},x()?"Agents":"Agent"));for(let d of w())n.append(p(`cli:${d.id}`,`set-cli:${d.id}`,d.name,x()&&d.id===k?"In use":null,h(d),()=>E(d)));n.append(p("notes","set-notes","Notes",null,A==="app"?"Every page":"This page only",()=>[r("Apply hands over","ag-set-scope",[{value:"app",label:"Open notes on every page",sub:`${Z("app").length} now`,k:"set-scope:app"},{value:"page",label:"Open notes on this page",sub:`${Z("page").length} now`,k:"set-scope:page"}],A,d=>{ne(d),ee(),H()}),(()=>{let d=t("input",{type:"checkbox",checked:ae,data:{k:"set-offer"}});return d.addEventListener("change",()=>{ae=d.checked,et(ae),ee()}),t("fieldset",{},t("legend",{},"After a save"),t("label",{class:"ag-radio"},d,t("span",{},"Offer to send the new note to the agent")))})()]));let u=a.worktrees,L=(K()?`New per prompt, up to ${a.max}`:"One kept going")+(u?.on&&K()?" \xB7 worktrees":"");return n.append(p("sessions","set-sessions","Sessions",null,L,()=>{let d=[r("Sessions","ag-set-mode",[{value:"fresh",label:"New session per prompt",sub:`up to ${a.max} at once`,k:"set-mode:fresh"},{value:"shared",label:"Keep one session going",sub:"keeps its context",k:"set-mode:shared"}],a.mode,v=>{X("/mode",{mode:v}).then(S=>{a={...a,...S},ee(),H()}).catch(W)})];if(u){let v=!u.git,S=t("input",{type:"checkbox",checked:u.on,disabled:v,data:{k:"set-wt"},attrs:{"aria-describedby":"ag-wt-help"}});S.addEventListener("change",()=>{X("/worktrees",{on:S.checked}).then(T=>{a={...a,...T},ee(),H()}).catch(T=>{S.checked=!S.checked,W(T)})});let C=v?`Needs a git repository (${u.why??"checking\u2026"}).`:`Its own branch (redline/\u2026) and folder in .redline/worktrees, so sessions never edit the same files; when it ends: keep, merge or discard the branch.${a.mode==="shared"?" Only with a new session per prompt.":""} No node_modules there: the agent can edit and use git; running the app or tests in it needs an install.`;d.push(t("fieldset",{},t("legend",{},"Worktrees"),t("label",{class:"ag-radio"+(v?" off":"")},S,t("span",{},"Each new session in its own git worktree")),t("div",{class:"ag-help",id:"ag-wt-help"},C)))}return d})),n.append(t("footer",{},t("span",{},"Applies to new sessions."),t("button",{data:{k:"set-reset"},title:"Forget this browser's choices: the project's CLI, model, effort, notes and sessions",onclick:rn},"Reset to project defaults"))),n.addEventListener("keydown",d=>{d.key==="Escape"&&/^(INPUT|SELECT)$/.test(d.target.tagName)&&(d.preventDefault(),me())}),je=n,n}function ee(){if(!je?.isConnected){M?.render();return}let e=ke()?.activeElement?.closest("[data-k]")?.dataset.k,n=je,r=Et();n.replaceWith(r),e&&r.querySelector(`[data-k="${CSS.escape(e)}"]`)?.focus(),M?.render()}async function rn(){N={},tt(null),A="app",Qe(null),ae=!0,et(null),k=be(w(),null,s.cli),Ze(null);let e=s.defaults?.sessions??"fresh";if(a.mode!==e)try{a={...a,...await X("/mode",{mode:e})}}catch(r){W(r)}let n=!!s.defaults?.worktrees;if(a.worktrees?.git&&a.worktrees.on!==n)try{a={...a,...await X("/worktrees",{on:n})}}catch(r){W(r)}O="set-reset",o.toast("Agent settings: back to the project's defaults"),H()}let Be=new Map,$e=new Set,We=!1,Ue=new Map,Tt=(e,n)=>`${we}/file?id=${encodeURIComponent(e)}&path=${encodeURIComponent(n)}&token=${encodeURIComponent(l.info.token)}`;function ln(e){let n=`${e.rounds??0}:${e.attachments??0}`,r=Be.get(e.id);return r?.key===n?r.rounds:(Be.set(e.id,{key:n,rounds:r?.rounds??null}),fetch(`${we}/attachments?id=${encodeURIComponent(e.id)}&token=${encodeURIComponent(l.info.token)}`).then(i=>i.ok?i.json():null).then(i=>{i&&(Be.set(e.id,{key:n,rounds:i.rounds}),y==="files"&&(We&&(We=!1,O="files-first"),M?.render()))}).catch(()=>{}),r?.rounds??null)}function dn(e,n){let r=ke();if(!r)return;let i=t("div",{class:"zoom",tabIndex:-1,attrs:{role:"dialog","aria-label":"Image, Esc to close"}},t("img",{src:e,alt:""})),p=()=>{i.remove(),n.focus()};i.addEventListener("click",p),i.addEventListener("keydown",c=>{c.key==="Escape"&&(c.preventDefault(),c.stopPropagation(),p())}),r.append(i),i.focus()}function cn(){let e=I(),n=t("div",{class:"ag-list ag-files",attrs:{role:"dialog","aria-label":`Attachments of ${J(e)}`}},t("h4",{},`${e.label}${e.title?` \xB7 ${e.title}`:""} \xB7 attachments`)),r=e.id?ln(e):[];if(!r)return We=!0,n.append(t("div",{class:"ag-hint",data:{k:"files-first"},tabIndex:-1},"Loading\u2026")),n;r.some(c=>c.items.length)||n.append(t("div",{class:"ag-hint"},"Nothing yet: files it changes, images and links it points at show here, per prompt."));let i=!0,p=c=>i?(i=!1,"files-first"):c;for(let c of r){if(!c.items.length)continue;let g=Tn(c.items),h=t("section",{class:"ag-round",attrs:{"aria-label":`Prompt ${c.n}`}},t("div",{class:"ag-round-h"},t("b",{},`Prompt ${c.n}`),c.task?t("span",{},c.task):null,c.done?null:t("span",{class:"ag-live"},"working\u2026")));if(g.images.length&&h.append(t("div",{class:"ag-thumbs"},...g.images.map(u=>{let L=Tt(e.id,u.path),d=t("button",{class:"ag-thumb",title:`${u.title?u.title+" \xB7 ":""}${u.path} (click to zoom)`,data:{k:p(`img:${u.id}`)},attrs:{"aria-label":`Zoom ${u.title??u.path}`}},t("img",{src:L,alt:u.title??u.path??"",loading:"lazy"}));return d.onclick=()=>dn(L,d),d}))),g.changed.length){let u=g.changed.reduce((d,v)=>d+(v.added??0),0),L=g.changed.reduce((d,v)=>d+(v.removed??0),0);h.append(t("div",{class:"ag-sub"},`Changed ${g.changed.length} file${g.changed.length===1?"":"s"}`,t("span",{class:"ag-num"},t("i",{class:"add"},`+${u}`)," ",t("i",{class:"del"},`\u2212${L}`))));for(let d of g.changed){let v=`${e.id}:${c.n}:${d.path}`,S=$e.has(v),C=t("button",{class:"ag-frow",data:{k:p(`chg:${d.id}`)},attrs:{"aria-expanded":String(S)},title:S?"Hide the diff":"Show the diff",onclick:()=>{$e.has(v)?$e.delete(v):($e.add(v),Ue.has(v)||fetch(`${we}/diff?id=${encodeURIComponent(e.id)}&round=${c.n}&path=${encodeURIComponent(d.path)}&token=${encodeURIComponent(l.info.token)}`).then(T=>T.ok?T.text():"(no diff)").then(T=>{Ue.set(v,T),M?.render()}).catch(()=>{})),O=`chg:${d.id}`,M?.render()}},t("span",{class:"ag-st",attrs:{"aria-label":{A:"added",D:"deleted",M:"modified"}[d.status??"M"]??"changed"}},d.status??"M"),t("span",{class:"ag-path"},d.path??""),t("span",{class:"ag-num"},t("i",{class:"add"},`+${d.added??0}`)," ",t("i",{class:"del"},`\u2212${d.removed??0}`)));if(h.append(C),S){let T=Ue.get(v);h.append(T===void 0?t("div",{class:"ag-hint"},"Loading the diff\u2026"):t("pre",{class:"ag-ctx ag-diff"},...T.split(`
|
|
192
|
+
`).filter(D=>!/^(diff --git|index |--- |\+\+\+ )/.test(D)).flatMap((D,R)=>[...R?[`
|
|
193
|
+
`]:[],t("span",{class:D.startsWith("+")?"add":D.startsWith("-")?"del":D.startsWith("@@")?"hunk":""},D)])))}}}let m=(u,L="")=>{let d=/\.(png|jpe?g|gif|webp|avif|svg|txt|md|json|csv|log|ya?ml|html?|css|[cm]?[jt]sx?|vue|svelte|astro|py|cs|razor|cshtml)$/i.test(u.path??""),v=[t("span",{class:"ag-path"},u.path??""),u.title?t("span",{class:"ag-t"},u.title):null];return d?t("a",{class:"ag-frow "+L,href:Tt(e.id,u.path),target:"_blank",rel:"noopener noreferrer",title:`Open ${u.path} in a new tab`,data:{k:p(`file:${u.id}`)}},...v):t("div",{class:"ag-frow "+L,title:u.path??""},...v)},E=(u,L="")=>{let d=En(u.url??""),v=[t("span",{class:"ag-path"},u.title??u.url??""),u.title?t("span",{class:"ag-t"},u.url??""):null];return d?t("a",{class:"ag-frow "+L,href:u.url,target:"_blank",rel:"noopener noreferrer",title:`Open ${u.url} in a new tab`,data:{k:p(`url:${u.id}`)}},...v):t("div",{class:"ag-frow ag-ext "+L,title:`${u.url} (not on this machine: copy it to open)`},...v)};g.files.length&&h.append(t("div",{class:"ag-sub"},"Files"),...g.files.map(u=>m(u))),g.links.length&&h.append(t("div",{class:"ag-sub"},"Links"),...g.links.map(u=>E(u))),g.mentioned.length&&h.append(t("details",{class:"ag-ment"},t("summary",{},`Mentioned (${g.mentioned.length})`),...g.mentioned.map(u=>u.kind==="url"?E(u,"dim"):m(u,"dim")))),n.append(h)}return n.append(t("div",{class:"ag-foot"},t("span",{},"Kept while the session runs"),t("button",{data:{k:"files-done"},onclick:()=>me()},"Done"))),n}let Se=null,Lt=0;function gn(){let e=a.worktrees?.left??[],n=t("div",{class:"ag-list ag-wts",attrs:{role:"dialog","aria-label":"Branches of ended sessions"}},t("h4",{},e.length?"Ended sessions: their branches":"No branches left to decide on")),r=(i,p,c=!1)=>{l.worktree(i.branch,p,c).then(g=>o.toast(g.message,!g.ok)).catch(W)};for(let i of e){let p=!!(i.dirty||i.ahead),c=Se===i.branch,g=t("button",{class:"ag-wt-discard"+(c?" armed":""),data:{k:`wt-discard:${i.branch}`},title:p?`Delete the worktree and the branch, with its ${Gt(i)}`:"Delete the worktree and the branch",onclick:()=>{if(p&&!c){Se=i.branch,clearTimeout(Lt),Lt=window.setTimeout(()=>{Se=null,M?.render()},4e3),O=`wt-discard:${i.branch}`,M?.render();return}Se=null,r(i,"discard",p)}},c?"Discard? Work is lost":"Discard");n.append(t("div",{class:"ag-wt",data:{branch:i.branch}},t("div",{class:"ag-wt-head"},V("branch"),t("b",{},i.branch),t("span",{},[i.session,i.title].filter(Boolean).join(" \xB7 "))),t("div",{class:"ag-wt-sub"},`${Gt(i)} \xB7 from ${i.base} \xB7 ${i.path}`),t("div",{class:"ag-wt-acts"},t("button",{data:{k:`wt-keep:${i.branch}`},title:"Keep the branch (the folder too while it has uncommitted changes)",onclick:()=>r(i,"keep")},"Keep branch"),t("button",{data:{k:`wt-merge:${i.branch}`},disabled:!!i.dirty,title:i.dirty?"Commit its changes first (or ask the agent to)":`Merge into ${i.base}: only a fast-forward or a clean merge`,onclick:()=>r(i,"merge")},`Merge into ${i.base}`),g)))}return n.append(t("div",{class:"ag-foot"},t("span",{},""),t("button",{data:{k:"wt-done"},onclick:()=>me()},"Done"))),n}function pn(e){let n=a.sessions.filter(c=>!c.running),r=[...a.sessions].reverse().map(c=>{let g=se(c),h=c.sent?.length??0,m=t("button",{class:"ag-row-main",title:$t(c),data:{k:`row:${c.id}`},attrs:{"aria-current":c.id===I().id?"true":void 0},onclick:()=>{B=c.id,y=null,O=matchMedia("(max-width: 560px)").matches?"sw":`tab:${c.id}`,H()}},t("span",{class:"ag-dot"}),t("span",{class:"l"},c.label),t("b",{},g.label),t("span",{class:"m"},[c.title,x()?z(c):"",c.worktree?.branch??"",h?`${h} note${h===1?"":"s"}`:"",c.attachments?`${c.attachments} attached`:"",g.msg??""].filter(Boolean).join(" \xB7 "))),E=t("div",{class:"ag-row"+(c.id===I().id?" cur":""),data:{id:c.id,state:gt(c)}},m,kt(c,`rowx:${c.id}`));return E.style.setProperty("--c",g.color),E}),i=async()=>{for(let c of n)await X("/end",{id:c.id}).catch(W)},p=a.sessions.filter(c=>c.running).length;e.append(U(),t("div",{class:"ag-list",attrs:{role:"dialog","aria-label":"Sessions"}},t("h4",{},a.sessions.length?`Sessions \xB7 ${p} running`:"No sessions yet"),...r,t("div",{class:"ag-foot"},t("span",{},""),n.length?t("button",{data:{k:"close-ended"},onclick:()=>{i()}},`Close ended (${n.length})`):null,t("button",{data:{k:"list-done"},onclick:()=>me()},"Done"))))}let un=e=>{let n=t("span",{},e.t);return e.fg&&(n.style.color=e.fg),e.bg&&(n.style.background=e.bg),e.b&&(n.style.fontWeight="700"),e.dim&&(n.style.opacity=".6"),n};M=o.addToolbar({id:"agent",title:"Agent",backTitle:"Back to the Redline toolbar (Esc)",hotkey:s.hotkey||void 0,render:nn,attached:an,onEscape:me,onShow(){oe?.(),I().id&&de("/ack").catch(()=>{}),H()},onHide(){y=null,H()}});let It=()=>{let e=I();return e.id?[e.label,z(e),e.title,e.worktree?.branch].filter(Boolean).join(" \xB7 "):`${P()} \xB7 no session yet`};function Ke(){if(!xe)return;let e=I();if(!e.id){xe.replaceChildren();return}let n=G===e.id;xe.replaceChildren(U(),t("button",{class:"ag-wend"+(n?" armed":""),title:vt(e),data:{k:"wend"},onclick:()=>wt(e)},n?"End? Press again":e.running?"End session":"Close session"))}ce=o.addWindow({id:"agent",title:It(),width:680,height:440,hideAs:"minimize",render(e,n){xe=n,Ke(),_=document.createElement("iframe"),_.src=Oe(),_.title=`${f()} terminal`,_.setAttribute("style","position:absolute;inset:0;width:100%;height:100%;border:0;background:#131316"),e.append(_)},onShow(){I().id&&de("/ack").catch(()=>{}),xt({type:"focus"}),M?.render()},onHide(){M?.render()},onResize(){xt({type:"fit"})}});function Mt(){if(!ze)return;let e=nt(a.sessions)??I(),n=se(e),r=o.notes("all"),i=Jt(),p=r.filter(u=>i.has(u.id)&&!u.done).length,c=r.filter(u=>i.has(u.id)&&u.done).length,g=a.sessions.filter(u=>u.running).length,h=[g>1&&`${g} sessions`,p&&`${p} sent note${p===1?"":"s"} open`,c&&`${c} done`].filter(Boolean).join(" \xB7 "),m=e.running||e.status.state==="done"||e.status.state==="error"?`${j(e)}: ${n.label}${h?` \xB7 ${h}`:n.msg?` \xB7 ${n.msg}`:""}`:`Hand these notes to ${P()}`,E=t("button",{class:"ag-line",title:"Open the agent toolbar",onclick:()=>M?.show(),data:{state:e.running?e.status.state:"stopped"}},t("span",{class:"ag-dot"}),t("span",{},m),s.hotkey?t("kbd",{},pt()):s.key!==!1?t("kbd",{},(s.key||"a").toUpperCase()):null);E.style.setProperty("--c",n.color),ze.replaceChildren(U(),E)}function At(e){let n=Ln(e.note,a.sessions,j),r=!!n&&/working|asking/.test(n.cls);e.el.replaceChildren(...n?[t("span",{class:`ag-tag ${n.cls}`,...r?{title:"Open the agent toolbar",onclick:()=>M?.show()}:{}},n.text)]:[])}o.addPanelSection({id:"agent",render(e){ze=e,Mt()}}),o.on("noteCreated",e=>{let n=s.commands[0];if(!ae||!(o.version>=7)||!n||!re(n)||e.done||!K()&&I().running&&I().status.state==="blocked")return;let r=()=>[...new Set([e.id,...Z()])],i=r().length;oe?.();let p=e.file;oe=o.toast(`${p?`Saved \u2192 ${p}`:"Saved"} \xB7 Send to ${P()}?`,{actions:[{label:"This note",primary:!0,title:`Apply this note with ${P()}${K()?" in a new session":""}`,onClick:()=>{fe(n,A,[e.id])}},...i>1?[{label:`All ${i}`,title:`Apply the ${i} open notes ${le()} with ${P()}`,onClick:()=>{fe(n,A,r())}}]:[]]})}),o.addCardDecorator({id:"agent",render(e,n){let r={el:n,note:e};He.set(e.id,r),At(r)}});function H(){B&&!a.sessions.some(m=>m.id===B)&&(B=null);let e=m=>m.running&&m.status.state==="blocked",n=a.sessions.filter(e).map(m=>m.id),r=n.find(m=>!ht.has(m));ht=new Set(n);let i=I(),p=Me.id===i.id&&Me.asking&&!e(i),c=r??(p?n[0]:void 0);c&&!Ae&&!e(i)&&(B=c,y==="list"&&(y=null)),Me={id:I().id,asking:e(I())},y==="files"&&e(I())&&(y=null),k=be(w(),k,s.cli);let g=nt(a.sessions),h=g?Vt({...g,command:j(g)}):null;o.setStatus("agent",h?{...h,onClick:()=>M?.show()}:null),yt(h?.title),_&&!_.src.endsWith(Oe())&&(_.src=Oe()),ce?.setTitle(It()),Ke(),M?.render(),Mt();for(let m of He.values())m.el.isConnected?At(m):He.delete(m.note.id)}let Rt=e=>{s=e,a=s,k=be(w(),k,s.cli),H()},Ce=jt({open:e=>l.watch(n=>{a=n,H()},n=>{s.clis=n,y==="settings"&&ee(),H()},Rt,e),want:()=>o.isOpen()});o.on("open",()=>Ce.update()),o.on("close",()=>Ce.update()),setInterval(()=>{Ce.update(),!Ce.opened&&document.visibilityState!=="hidden"&&l.refresh().then(Rt,()=>{})},5e3),window.addEventListener("message",e=>{e.origin!==location.origin||e.source!==_?.contentWindow||(e.data?.type==="ack"&&de("/ack").catch(()=>{}),e.data?.type==="session"&&typeof e.data.id=="string"&&(B=e.data.id,H()))}),H()}export{Rn as default,kn as fill,xn as freeIds,Tn as groupAttachments,Vt as indicatorFor,$n as initials,En as isLocalUrl,Bn as noteTag,st as noteText,nt as overall,be as pickCli,rt as shorten,se as stateLabel,ot as tabRank,yn as tabTitle,Ln as tagFor,Sn as visibleTabs,Gt as worktreeState};
|