@umage.ai/redline-agent 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/panel.js CHANGED
@@ -1,17 +1,51 @@
1
- var ce="/__redline";var z=`${ce}/agent`,Ce={blocked:4,working:3,error:2,done:1,idle:0};function V(r){let n,s=-1;for(let a of r){if(!a.running&&a.status.state!=="done"&&a.status.state!=="error")continue;let w=Ce[a.status.state]??0;w>=s&&(n=a,s=w)}return n}var fe="#a3a3ad",Ee="#5c5c66",Te="\x1B",ge="\x1B[D",pe="\x1B[C";function be(r){let n=r.status;if(!r.running&&n.state!=="done"&&n.state!=="error")return null;let s=w=>`${r.command}: ${w}${n.progress!==void 0&&n.state==="working"?` ${n.progress}%`:""}${n.msg?` \xB7 ${n.msg}`:""}`,a={toolbar:"outline",launcher:"ring"};switch(n.state){case"working":return{...a,color:"#4f8cff",spin:!0,title:s(n.source==="activity"?"busy":"working")};case"blocked":return n.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:fe,toolbar:!1,launcher:!1,title:s("ready")}}}function I(r){let n=r.status,s=n.msg||void 0;if(!r.running&&n.state!=="done"&&n.state!=="error")return{label:r.exitCode===void 0?"Not started":`Stopped${r.exitCode?` (exit ${r.exitCode})`:""}`,color:Ee};let a=be(r)?.color??fe;switch(n.state){case"working":return{label:`Working${n.progress!==void 0?` ${n.progress}%`:""}`,msg:s,color:a};case"blocked":return{label:n.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 Ne(r,n,s=Y(n)){let a=s.join(", ");return r.replace(/\{(page|url|ids)\}/g,(w,c)=>c==="page"?n.page():c==="url"?location.href:a||"none")}var Y=r=>r.notes("page").filter(n=>!n.done).map(n=>n.id);function Le(r,n){let s=new Set(n.filter(a=>a.running).flatMap(a=>a.sent??[]));return Y(r).filter(a=>!s.has(a))}var ue=r=>r.prompt.includes("{ids}");function Re(r,n,s=3){let a=new Set(r.filter(c=>c.id===n||c.running&&c.status.state==="blocked").map(c=>c.id)),w=[...r].reverse();for(let c of[...w.filter(u=>u.running),...w.filter(u=>!u.running)])a.size<s&&a.add(c.id);return{shown:r.filter(c=>a.has(c.id)).map(c=>c.id),hidden:r.filter(c=>!a.has(c.id)).map(c=>c.id)}}function He(r,n){return n.has(r.id)?r.done?"done":"sent":null}function Pe(r,n,s){let a=[...n].reverse().find(c=>c.sent?.includes(r.id));if(!a)return null;if(r.done)return{cls:"done",text:`\u2713 done by ${s(a)}`};let w=a.running?a.status.state:"stopped";return w==="working"?{cls:"sent working",text:`${s(a)} is working on it`}:w==="blocked"?{cls:"sent asking",text:`${s(a)} needs your answer`}:{cls:"sent",text:`\u2933 sent to ${s(a)}`}}var Ae=`
2
- /* A fixed width, so the toolbar doesn't change size with every message (the full text is the hover). */
3
- .ag-chip { display: flex; align-items: center; gap: 7px; padding: 0 8px; flex: none; width: 290px; box-sizing: border-box; color: var(--fg); white-space: nowrap; overflow: hidden; }
4
- .ag-chip b { flex: none; }
5
- .ag-chip .ag-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent); }
6
- .ag-chip b { font-weight: 650; }
1
+ var Nt="/__redline";async function Rt(o){let l=await Ue(o),s=async(a,m={})=>{let v=await fetch(`${o}${a}`,{method:"POST",headers:{"content-type":"application/json","x-agent-token":l.token},body:JSON.stringify(m)});if(!v.ok)throw new Error((await v.json().catch(()=>null))?.error??`HTTP ${v.status}`);return v.json()};return{get info(){return l},async refresh(){return l=await Ue(o),l},post:s,watch(a,m,v){let k=null,L=!1,x=()=>{if(k?.close(),!L){k=new EventSource(`${o}/stream?status=1&token=${encodeURIComponent(l.token)}`);for(let N of["hello","status"])k.addEventListener(N,O=>a(JSON.parse(O.data)));k.addEventListener("clis",N=>{l.clis=JSON.parse(N.data),m?.(l.clis)}),k.onerror=async()=>{if(!(k?.readyState!==EventSource.CLOSED||L))try{l=await Ue(o),v?.(l),setTimeout(x,1e3)}catch{}}}};return x(),()=>{L=!0,k?.close()}},stream(a){return new EventSource(`${o}/stream?id=${encodeURIComponent(a)}&token=${encodeURIComponent(l.token)}`)},send:(a,m={})=>s("/send",{text:a,...m}),start:(a={})=>s("/start",a),choose:(a,m,v)=>s("/choose",{id:a,index:m,...v===void 0?{}:{text:v}}),answer:(a,m)=>s("/answer",{id:a,choice:m}),input:(a,m)=>s("/input",{id:a,data:m}),resize:(a,m,v)=>s("/resize",{id:a,cols:m,rows:v}),ack:a=>s("/ack",{id:a}),mode:a=>s("/mode",{mode:a}),worktrees:a=>s("/worktrees",{on:a}),worktree:(a,m,v=!1)=>s("/worktree",{branch:a,action:m,confirm:v}),end:a=>s("/end",a?{id:a}:{})}}async function Ue(o){let l=await fetch(`${o}/info`);if(!l.ok)throw new Error(`agent bridge: HTTP ${l.status}`);return l.json()}var Ke="redline.agent.cli",_e="redline.agent.scope",qe="redline.agent.settings",Ge="redline.agent.offer",Pt=()=>{try{return localStorage.getItem(Ke)}catch{return null}},Ve=o=>{try{o?localStorage.setItem(Ke,o):localStorage.removeItem(Ke)}catch{}},Ot=()=>{try{let o=localStorage.getItem(_e);return o==="app"||o==="page"?o:null}catch{return null}},Ye=o=>{try{o?localStorage.setItem(_e,o):localStorage.removeItem(_e)}catch{}},zt=()=>{try{return localStorage.getItem(Ge)!=="0"}catch{return!0}},Je=o=>{try{o===!1?localStorage.setItem(Ge,"0"):localStorage.removeItem(Ge)}catch{}};function Ht(){try{let o=JSON.parse(localStorage.getItem(qe)??"{}");return o&&typeof o=="object"&&!Array.isArray(o)?o:{}}catch{return{}}}var Xe=o=>{try{o&&Object.keys(o).length?localStorage.setItem(qe,JSON.stringify(o)):localStorage.removeItem(qe)}catch{}};function pe(o,l,s){return o.find(a=>a.id===l)?.id??o.find(a=>a.id===s)?.id??o[0]?.id??""}function ye(o,l){let s=o?l[o.id]:void 0;if(!o||!s)return{};let a=s.model&&o.models?.some(v=>v.value===s.model)?s.model:void 0,m=s.effort&&o.efforts?.some(v=>v.value===s.effort)?s.effort:void 0;return{...a?{model:a}:{},...m?{effort:m}:{}}}var ue=`${Nt}/agent`,pn={blocked:4,working:3,error:2,done:1,idle:0};function Ze(o){let l,s=-1;for(let a of o){if(!a.running&&a.status.state!=="done"&&a.status.state!=="error")continue;let m=pn[a.status.state]??0;m>=s&&(l=a,s=m)}return l}var Ft="#a3a3ad",un="#5c5c66",fn="\x1B",jt="\x1B[D",Dt="\x1B[C",Qe="Apply notes",hn=500;function Wt(o){let l=o.status;if(!o.running&&l.state!=="done"&&l.state!=="error")return null;let s=m=>`${o.command}: ${m}${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:Ft,toolbar:!1,launcher:!1,title:s("ready")}}}function te(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:un};let a=Wt(o)?.color??Ft;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 mn(o,l,s=at(l)){let a=s.join(", "),m=l.notes("all"),v=[...new Set(s.map(L=>m.find(x=>x.id===L)?.page).filter(L=>!!L))],k=v.length>1?`pages ${v.join(", ")}`:`page ${v[0]??l.page()}`;return o.replace(/\{(page|pages|url|ids)\}/g,(L,x)=>x==="page"?l.page():x==="pages"?k:x==="url"?location.href:a||"none")}var at=(o,l="page")=>o.notes(l).filter(s=>!s.done).map(s=>s.id);function bn(o,l,s="page"){let a=new Set(l.filter(m=>m.running).flatMap(m=>m.sent??[]));return at(o,s).filter(m=>!a.has(m))}var ne=o=>o.prompt.includes("{ids}"),tt=o=>((o.body??"").trim()||(o.type==="text"?o.to??"":"")||o.type).replace(/\s+/g," ").trim(),nt=(o,l=18)=>{let s=o.replace(/\s+/g," ").trim();return s.length>l?s.slice(0,l-1).trimEnd()+"\u2026":s};function wn(o,l=""){return o.length?nt(tt(o[0]))+(o.length>1?` +${o.length-1}`:""):l}function kn(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 et(o){return o.running?o.status.state==="idle"?1:0:2}function vn(o,l,s=3){let a=new Set(o.filter(k=>k.id===l||k.running&&k.status.state==="blocked").map(k=>k.id)),m=[...o].reverse();for(let k of[0,1,2])for(let L of m)a.size<s&&et(L)===k&&a.add(L.id);let v=k=>k.map((L,x)=>({s:L,i:x})).sort((L,x)=>et(L.s)-et(x.s)||L.i-x.i).map(L=>L.s.id);return{shown:v(o.filter(k=>a.has(k.id))),hidden:v(o.filter(k=>!a.has(k.id)))}}var xn=/\.(png|jpe?g|gif|webp|avif|svg)$/i;function yn(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 $n(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"&&xn.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 Bt(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 On(o,l){return l.has(o.id)?o.done?"done":"sent":null}function Sn(o,l,s){let a=[...l].reverse().find(v=>v.sent?.includes(o.id));if(!a)return null;if(o.done)return{cls:"done",text:`\u2713 done by ${s(a)}`};let m=a.running?a.status.state:"stopped";return m==="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`}:m==="blocked"?{cls:"sent asking",text:`${s(a)} needs your answer`}:{cls:"sent",text:`\u2933 sent to ${s(a)}`}}var ae=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>`,Cn={term:ae('<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:ae('<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:ae('<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:ae('<path d="M7 7l10 10M17 7L7 17"/>'),down:ae('<path d="M7 10l5 5 5-5"/>'),clip:ae('<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:ae('<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=Cn[o],l},En=`
2
+ .ag-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
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
+ .ag-ic { display: grid; place-items: center; width: 16px; height: 16px; flex: none; }
5
+ .ag-ic svg { width: 16px; height: 16px; display: block; }
6
+ .ag-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
7
+ /* the state: a fixed width, so the toolbar doesn't change size with every message (the full text is the hover) */
8
+ .ag-chip { display: flex; align-items: center; gap: 6px; padding: 0 8px; flex: none; width: 270px; box-sizing: border-box; color: var(--fg); white-space: nowrap; overflow: hidden; }
9
+ .ag-chip .ag-dot { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent); }
10
+ .ag-chip .ag-who { flex: none; max-width: 120px; overflow: hidden; text-overflow: ellipsis; color: var(--fg-2); }
11
+ .ag-chip .ag-mid { flex: none; color: var(--fg-3); }
12
+ .ag-chip b { flex: none; font-weight: 650; }
7
13
  .ag-chip .ag-msg { color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; min-width: 0; }
8
- .bar button.ag-allow { background: #3ecf8e; color: #08130d; font-weight: 650; }
9
- .bar button.ag-allow:hover { background: #5fdca3; color: #08130d; }
10
- .bar button.ag-deny:hover { background: color-mix(in srgb, #ff453a 25%, var(--bg-3)); }
14
+ /* the primary action, filled; long-press (or right-click, Alt+\u2193) switches the agent */
15
+ .bar button.ag-primary { background: var(--ink); color: #fff; font-weight: 650; padding: 6px 12px; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
16
+ .bar button.ag-primary:hover { background: var(--ink-2); color: #fff; }
17
+ .bar button.ag-primary[aria-disabled="true"] { cursor: default; background: var(--bg-3); color: var(--fg-3); }
18
+ .bar button.ag-primary .count { background: rgba(255,255,255,.25); color: #fff; }
19
+ .bar button.ag-icon { padding: 6px 7px; }
20
+ .bar button.ag-icon[aria-pressed="true"], .bar button.ag-icon[aria-expanded="true"] { background: var(--bg-3); color: var(--fg); }
21
+ .bar button.ag-term.ask { color: var(--fg); box-shadow: inset 0 0 0 1px #ff9f0a; }
22
+ /* session tabs: named by their notes; the dot is the state; seen and ended ones fade */
23
+ .ag-tabs { display: flex; align-items: center; gap: 2px; }
24
+ .ag-tab { display: flex; align-items: center; border-radius: 8px; transition: opacity .15s; }
25
+ .ag-tab:hover { background: var(--bg-2); }
26
+ .ag-tab.cur { background: var(--bg-3); }
27
+ .bar .ag-tab button { padding: 5px 2px 5px 8px; gap: 6px; background: none; }
28
+ .bar .ag-tab button:hover { background: none; color: var(--fg); }
29
+ .bar .ag-tab.cur button { color: var(--fg); }
30
+ .ag-tab .ag-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
31
+ .ag-tab[data-state="done"] .ag-name { font-weight: 700; color: var(--fg); }
32
+ .ag-tab:is([data-state="idle"], [data-state="seen"], [data-state="stopped"]):not(.cur):not(:hover):not(:focus-within) { opacity: .55; }
33
+ .ag-ini { flex: none; font-size: 10px; font-weight: 700; line-height: 1; padding: 2px 4px; border-radius: 4px; background: var(--bg-2); color: var(--fg-2); }
34
+ .bar .ag-tab button.ag-x { padding: 5px 7px 5px 4px; color: var(--fg-2); }
35
+ .ag-x .ag-ic, .ag-x .ag-ic svg { width: 12px; height: 12px; }
36
+ .bar .ag-tab button.ag-x:hover, .ag-row .ag-x:hover { color: var(--fg); }
37
+ .ag-x.armed, .bar .ag-tab button.ag-x.armed { color: #fff; background: #ff2d55; border-radius: 6px; padding: 3px 7px; margin-right: 2px; font-size: 12px; font-weight: 650; }
38
+ .bar button.ag-more { padding: 0 8px; height: 28px; font-variant-numeric: tabular-nums; }
39
+ .bar button.ag-more.lit { color: var(--fg); box-shadow: inset 0 0 0 1px var(--c); }
40
+ .bar .ag-phone { display: none; }
41
+ .bar button.ag-switch { gap: 6px; max-width: 150px; }
42
+ .ag-switch .ag-name { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
43
+ @keyframes ag-beat { 50% { opacity: .45; transform: scale(.75); } }
44
+ :is(.ag-chip, .ag-tab, .ag-switch, .ag-row, .ag-line)[data-state="working"] .ag-dot { animation: ag-beat 1.2s ease-in-out infinite; }
45
+ /* the notes panel: a status line and tags */
11
46
  .ag-line { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border-radius: 8px; background: var(--bg-2); color: var(--fg); text-align: left; cursor: pointer; }
12
47
  .ag-line:hover { background: var(--bg-3); }
13
- .ag-line .ag-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
14
- .ag-line span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
48
+ .ag-line span:not(.ag-dot) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
15
49
  .ag-line kbd { flex: none; }
16
50
  .ag-tag { display: inline-block; margin-top: 6px; padding: 1px 7px; border-radius: 9px; font-size: 11px; font-weight: 600; }
17
51
  .ag-tag.sent { color: #8fb4ff; background: color-mix(in srgb, #4f8cff 18%, transparent); }
@@ -19,12 +53,10 @@ var ce="/__redline";var z=`${ce}/agent`,Ce={blocked:4,working:3,error:2,done:1,i
19
53
  .ag-tag.working, .ag-tag.asking { cursor: pointer; }
20
54
  .ag-tag.asking { color: #ffb340; background: color-mix(in srgb, #ff9f0a 18%, transparent); }
21
55
  .ag-tag.working::before, .ag-tag.asking::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: currentColor; vertical-align: 1px; animation: ag-beat 1.2s ease-in-out infinite; }
22
- @keyframes ag-beat { 50% { opacity: .45; transform: scale(.75); } }
23
- .ag-chip[data-state="working"] .ag-dot, .ag-tab[data-state="working"] .ag-dot, .ag-switch[data-state="working"] .ag-dot, .ag-line[data-state="working"] .ag-dot { animation: ag-beat 1.2s ease-in-out infinite; }
24
- @media (prefers-reduced-motion: reduce) { .ag-tag::before, .ag-dot { animation: none !important; } }
56
+ @media (prefers-reduced-motion: reduce) { .ag-tag::before, .ag-dot { animation: none !important; } .ag-tab { transition: none; } }
57
+ /* the card: what the CLI asks */
25
58
  .ag-card { display: grid; gap: 10px; font-size: 13px; }
26
59
  .ag-card .ag-who { display: flex; align-items: center; gap: 7px; color: var(--fg-2); font-size: 12px; }
27
- .ag-card .ag-who .ag-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
28
60
  .ag-steps { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
29
61
  .ag-steps button { padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); color: var(--fg-2); font-size: 12px; }
30
62
  .ag-steps button.cur { color: var(--fg); border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, transparent); }
@@ -41,43 +73,121 @@ var ce="/__redline";var z=`${ce}/agent`,Ce={blocked:4,working:3,error:2,done:1,i
41
73
  .ag-opt .d { grid-column: 2; color: var(--fg-2); font-size: 12px; line-height: 1.35; }
42
74
  .ag-input { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; padding: 5px 6px 5px 10px; border-radius: 8px; border: 1px dashed var(--line); }
43
75
  .ag-input input { min-width: 0; background: transparent; border: 0; outline: 0; color: var(--fg); font: inherit; padding: 4px 0; }
44
- .ag-input button, .ag-foot button { padding: 4px 10px; border-radius: 7px; background: var(--bg-3); color: var(--fg); }
76
+ .ag-input button, .ag-foot button, .ag-set footer button { padding: 5px 10px; border-radius: 7px; background: var(--bg-3); color: var(--fg); }
77
+ .ag-input button:hover, .ag-foot button:hover, .ag-set footer button:hover { background: color-mix(in srgb, var(--fg) 12%, var(--bg-3)); }
78
+ .ag-ask { display: flex; gap: 8px; }
79
+ .ag-ask button { padding: 7px 14px; border-radius: 8px; background: var(--bg-3); color: var(--fg); font-weight: 600; }
80
+ .ag-ask button.ag-allow { background: #3ecf8e; color: #08130d; }
81
+ .ag-ask button.ag-allow:hover { background: #5fdca3; }
82
+ .ag-ask button.ag-deny:hover { background: color-mix(in srgb, #ff453a 25%, var(--bg-3)); }
45
83
  .ag-foot { display: flex; align-items: center; gap: 8px; color: var(--fg-2); font-size: 11.5px; }
46
84
  .ag-foot span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
47
- .ag-tabs { display: flex; align-items: center; gap: 2px; }
48
- .bar button.ag-tab { gap: 5px; padding: 0 7px; font-variant-numeric: tabular-nums; }
49
- .ag-tab .ag-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
50
- .ag-tab .ag-x { opacity: .55; padding-left: 2px; }
51
- .ag-tab .ag-x:hover { opacity: 1; }
52
- .bar button.ag-tab.cur { background: var(--bg-3); color: var(--fg); }
53
- .bar button.ag-mode.on { background: color-mix(in srgb, #4f8cff 28%, var(--bg-3)); color: var(--fg); }
54
- .bar button.ag-more { padding: 0 7px; font-variant-numeric: tabular-nums; }
55
- .bar button.ag-more.lit { color: var(--fg); box-shadow: inset 0 0 0 1px var(--c); }
56
- .ag-list { display: grid; gap: 4px; font-size: 13px; min-width: min(420px, calc(100vw - 48px)); }
57
- .ag-list h4 { margin: 0 0 4px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-2); }
58
- .ag-row { display: grid; grid-template-columns: 8px 28px auto 1fr auto; gap: 8px; align-items: center; padding: 7px 10px; border-radius: 8px; background: var(--bg-2); color: var(--fg); text-align: left; cursor: pointer; border: 1px solid transparent; }
85
+ /* menus and the session list */
86
+ .ag-list { display: grid; gap: 4px; font-size: 13px; min-width: min(360px, calc(100vw - 48px)); }
87
+ .ag-list h4, .ag-set h4 { margin: 0 0 4px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-2); }
88
+ .ag-mi { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--bg-2); color: var(--fg); text-align: left; cursor: pointer; border: 1px solid transparent; }
89
+ .ag-mi:hover, .ag-mi:focus-visible { background: var(--bg-3); }
90
+ .ag-mi b { font-weight: 650; }
91
+ .ag-mi span { margin-left: auto; color: var(--fg-2); font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
92
+ .ag-mi[aria-checked]::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--fg-2); }
93
+ .ag-mi[aria-checked="true"] { border-color: color-mix(in srgb, var(--ink) 55%, var(--line)); }
94
+ .ag-mi[aria-checked="true"]::before { background: var(--ink); box-shadow: none; }
95
+ .ag-mi[aria-disabled="true"] { opacity: .5; cursor: default; }
96
+ .ag-hint { color: var(--fg-3); font-size: 11.5px; padding: 2px 2px 0; }
97
+ .ag-row { display: flex; align-items: center; border-radius: 8px; background: var(--bg-2); border: 1px solid transparent; }
59
98
  .ag-row:hover { background: var(--bg-3); }
60
99
  .ag-row.cur { border-color: color-mix(in srgb, var(--c) 60%, var(--line)); }
61
- .ag-row .ag-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
100
+ .ag-row .ag-row-main { flex: 1; min-width: 0; display: grid; grid-template-columns: 8px auto auto 1fr; gap: 8px; align-items: center; padding: 8px 4px 8px 10px; color: var(--fg); text-align: left; cursor: pointer; }
62
101
  .ag-row .l { font-variant-numeric: tabular-nums; color: var(--fg-2); }
63
102
  .ag-row .m { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-2); }
64
- .ag-row .ag-x { padding: 0 4px; color: var(--fg-2); }
65
- .ag-row .ag-x:hover { color: var(--fg); }
66
- .ag-row[data-state="working"] .ag-dot { animation: ag-beat 1.2s ease-in-out infinite; }
67
- .ag-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
68
- .ag-head h4 { margin: 0; }
69
- .ag-head .ag-mode { padding: 4px 10px; border-radius: 7px; background: var(--bg-3); color: var(--fg-2); }
70
- .ag-head .ag-mode.on { background: color-mix(in srgb, #4f8cff 28%, var(--bg-3)); color: var(--fg); }
71
- .bar .ag-phone { display: none; }
72
- .bar button.ag-switch { gap: 5px; font-variant-numeric: tabular-nums; }
73
- .ag-switch .ag-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
74
- /* Phones: what fits one row. The outline says the state, the list has the words: the
75
- session button (its dot the state) in place of the chip and tabs, Fresh and stop in its list, then the prompts and CLI. */
103
+ .ag-row .ag-x { flex: none; display: flex; align-items: center; padding: 8px 10px; color: var(--fg-2); }
104
+ .ag-row:is([data-state="idle"], [data-state="seen"], [data-state="stopped"]) .ag-row-main { opacity: .7; }
105
+ /* settings (\u2699) */
106
+ .ag-set { display: grid; gap: 14px; font-size: 13px; min-width: min(360px, calc(100vw - 48px)); }
107
+ .ag-set fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 4px; min-width: 0; }
108
+ .ag-set legend, .ag-set .ag-lbl { padding: 0; margin: 0 0 6px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-2); }
109
+ .ag-radio { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; background: var(--bg-2); color: var(--fg); cursor: pointer; border: 1px solid transparent; }
110
+ .ag-radio:hover { background: var(--bg-3); }
111
+ .ag-radio:has(input:checked) { border-color: color-mix(in srgb, var(--ink) 55%, var(--line)); }
112
+ .ag-radio input { accent-color: var(--ink); margin: 0; flex: none; }
113
+ .ag-radio span { min-width: 0; }
114
+ .ag-radio small { margin-left: auto; color: var(--fg-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
115
+ .ag-sgroup { display: grid; border-radius: 9px; background: var(--bg-2); border: 1px solid transparent; }
116
+ .ag-sgroup.open { border-color: var(--line); }
117
+ .ag-srow { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 0; border-radius: 9px; background: transparent; color: var(--fg); font: inherit; text-align: left; cursor: pointer; min-width: 0; }
118
+ .ag-srow:hover { background: var(--bg-3); }
119
+ .ag-srow .ag-sname { font-weight: 600; white-space: nowrap; }
120
+ .ag-srow .ag-sbadge { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: color-mix(in srgb, var(--ink) 22%, var(--bg-3)); color: var(--fg); white-space: nowrap; }
121
+ .ag-srow small { margin-left: auto; color: var(--fg-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
122
+ .ag-srow .ag-ic { flex: none; color: var(--fg-2); transform: rotate(-90deg); transition: transform .15s; }
123
+ .ag-sgroup.open .ag-srow .ag-ic { transform: none; }
124
+ .ag-sbody { display: grid; gap: 12px; padding: 4px 10px 12px; }
125
+ .ag-sbody .ag-radio { background: var(--bg-3); }
126
+ .ag-use { justify-self: start; padding: 6px 12px; border-radius: 7px; border: 0; background: var(--bg-3); color: var(--fg); font: inherit; cursor: pointer; }
127
+ .ag-use:hover { background: color-mix(in srgb, var(--fg) 12%, var(--bg-3)); }
128
+ .ag-field { display: grid; gap: 0; }
129
+ .ag-field select { width: 100%; font: inherit; color: var(--fg); background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; }
130
+ .ag-field select:disabled { opacity: .6; }
131
+ .ag-set :is(.ag-note, .ag-help) { color: var(--fg-2); font-size: 12px; line-height: 1.4; }
132
+ .ag-set footer { display: flex; align-items: center; gap: 8px; color: var(--fg-2); font-size: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
133
+ .ag-set footer span { flex: 1; }
134
+ /* attachments (D56): the \u{1F4CE} on a tab, and the card's list */
135
+ .bar .ag-tab button.ag-att { padding: 5px 2px 5px 4px; gap: 2px; color: var(--fg-2); font-size: 11px; font-variant-numeric: tabular-nums; }
136
+ .ag-att .ag-ic, .ag-att .ag-ic svg { width: 13px; height: 13px; }
137
+ .bar .ag-tab button.ag-att:hover, .bar .ag-tab button.ag-att[aria-expanded="true"] { color: var(--fg); }
138
+ .ag-files { max-height: min(60vh, 560px); overflow: auto; }
139
+ .ag-round { display: grid; gap: 4px; padding: 6px 0 8px; border-top: 1px solid var(--line); }
140
+ .ag-round:first-of-type { border-top: 0; padding-top: 0; }
141
+ .ag-round-h { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
142
+ .ag-round-h span { color: var(--fg-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
143
+ .ag-round-h .ag-live { color: #8fb4ff; }
144
+ .ag-sub { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-2); }
145
+ .ag-num { font: 600 11.5px ui-monospace, Consolas, monospace; text-transform: none; letter-spacing: 0; }
146
+ .ag-num i { font-style: normal; } .ag-num .add, .ag-diff .add { color: #3ecf8e; } .ag-num .del, .ag-diff .del { color: #ff6b6b; } .ag-diff .hunk { color: #8fb4ff; }
147
+ .ag-frow { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; background: var(--bg-2); color: var(--fg); text-align: left; text-decoration: none; min-width: 0; cursor: pointer; border: 0; font: inherit; font-size: 12.5px; }
148
+ .ag-frow:hover { background: var(--bg-3); }
149
+ .ag-frow.ag-ext, div.ag-frow { cursor: text; user-select: text; }
150
+ .ag-frow.dim { opacity: .75; }
151
+ .ag-frow .ag-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
152
+ .ag-frow .ag-t { color: var(--fg-2); font-size: 12px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
153
+ .ag-st { flex: none; width: 16px; text-align: center; font: 700 11px ui-monospace, Consolas, monospace; color: var(--fg-2); }
154
+ .ag-thumbs { display: flex; flex-wrap: wrap; gap: 6px; }
155
+ .ag-thumb { padding: 0; border-radius: 7px; border: 1px solid var(--line); background: var(--bg-2); cursor: zoom-in; overflow: hidden; }
156
+ .ag-thumb img { display: block; width: 96px; height: 64px; object-fit: cover; }
157
+ .ag-diff { max-height: 220px; }
158
+ .ag-ment summary { cursor: pointer; color: var(--fg-2); font-size: 12px; padding: 4px 2px; }
159
+ .ag-ment { display: grid; gap: 4px; }
160
+ /* ended sessions' branches (D64) */
161
+ .ag-bc { display: flex; align-items: center; gap: 4px; }
162
+ .bar button.ag-branches .count { background: var(--bg-3); color: var(--fg); }
163
+ .ag-wt { display: grid; gap: 6px; padding: 8px 10px; border-radius: 8px; background: var(--bg-2); }
164
+ .ag-wt-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
165
+ .ag-wt-head b { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
166
+ .ag-wt-head span:last-child { margin-left: auto; color: var(--fg-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
167
+ .ag-wt-sub { color: var(--fg-2); font-size: 12px; overflow-wrap: anywhere; }
168
+ .ag-wt-acts { display: flex; gap: 6px; flex-wrap: wrap; }
169
+ .ag-wt-acts button { padding: 5px 10px; border-radius: 7px; background: var(--bg-3); color: var(--fg); }
170
+ .ag-wt-acts button:hover:not(:disabled) { background: color-mix(in srgb, var(--fg) 12%, var(--bg-3)); }
171
+ .ag-wt-acts button:disabled { opacity: .5; cursor: default; }
172
+ .ag-wt-acts button.ag-wt-discard:hover, .ag-wt-acts button.ag-wt-discard.armed { background: #ff2d55; color: #fff; }
173
+ .ag-radio.off { opacity: .6; cursor: default; }
174
+ /* the CLI window's header */
175
+ .win-controls button.ag-wend { color: #ff6b85; }
176
+ .win-controls button.ag-wend:hover { background: color-mix(in srgb, #ff2d55 20%, var(--bg-3)); color: #fff; }
177
+ .win-controls button.ag-wend.armed { background: #ff2d55; color: #fff; }
178
+ /* phones: what fits one row. The outline says the state; the session button (its dot the state) opens
179
+ the list with every session and End; the prompts, >_ and \u2699 stay. */
76
180
  @media (max-width: 560px) {
77
- .ag-chip, .ag-chip + .sep { display: none; }
78
181
  .bar .ag-desk { display: none; }
79
182
  .bar .ag-phone { display: flex; }
80
- .bar button.ag-switch { padding: 6px 8px; }
81
- .ag-row { grid-template-columns: 8px 24px auto 1fr auto; padding: 9px 8px; }
82
- }`,q=()=>Object.assign(document.createElement("style"),{textContent:Ae});function o(r,n={},...s){let{class:a,data:w,...c}=n,u=Object.assign(document.createElement(r),c);a&&(u.className=a);for(let[M,S]of Object.entries(w??{}))u.dataset[M]=S;return u.append(...s.filter(M=>!!M)),u}async function Me(r){if(!(r.version>=5)||typeof r.addToolbar!="function")return;let n;try{let e=await fetch(`${z}/info`);if(!e.ok)return;n=await e.json()}catch{return}let s=n,a=()=>n.command,w=()=>({id:"",label:"",running:!1,command:a(),status:{state:"idle",source:"none"},sent:[]}),c=null,u=()=>s.sessions.find(e=>e.id===c)??s.sessions[s.sessions.length-1]??w(),M=()=>s.sessions.length>1,S=()=>s.mode==="fresh",v=e=>M()&&e.label?`${a()} ${e.label}`:a(),me=()=>new Set(s.sessions.flatMap(e=>e.sent??[])),Q=()=>n.hotkey?n.hotkey.split("+").map(e=>e.length===1?e.toUpperCase():e[0].toUpperCase()+e.slice(1)).join("+"):"",R=async(e,t={})=>{let i=await fetch(`${z}${e}`,{method:"POST",headers:{"content-type":"application/json","x-redline":"1","x-redline-agent":n.token},body:JSON.stringify(t)});if(!i.ok)throw new Error((await i.json().catch(()=>null))?.error??`HTTP ${i.status}`);return i.json()},P=(e,t={})=>R(e,{...t,...u().id?{id:u().id}:{}}),C=e=>r.toast(`Agent: ${e.message}`,!0),X=()=>Le(r,s.sessions),he=async e=>{let t=ue(e)?X():[];S()?r.toast(`Starting a new ${a()} session\u2026`):u().running||r.toast(`Starting ${a()}\u2026`);try{let i=await R("/send",{text:Ne(e.prompt,r,t),notes:t,...!S()&&u().id?{id:u().id}:{}});i?.id&&(c=i.id,T())}catch(i){C(i)}},Z=e=>{P("/answer",{choice:e}).catch(C)},H=!1,ee=async(e,t)=>{H=!0,k?.render();try{await P("/choose",t===void 0?{index:e}:{index:e,text:t})}catch(i){C(i)}finally{setTimeout(()=>{H=!1,k?.render()},400)}},F=e=>{P("/input",{data:e}).catch(C)},te=new Set,_={id:"",asking:!1},G=!1,N=!1,E=null,ne=e=>E?.contentWindow?.postMessage(e,location.origin),K=()=>`${z}/terminal${u().id?`?id=${encodeURIComponent(u().id)}`:""}`,O=null,k=null,U=null,J=new Map,se=e=>r.addButton({id:"agent",label:"Agent",key:n.key===!1?void 0:n.key||"a",title:e??`${a()}: agent toolbar${n.hotkey?` \xB7 ${Q()} from anywhere`:""}`,onClick:()=>k?.show(),active:()=>!!k?.isOpen()});se();function xe(e){let t=u(),i=I(t),h=t.status,m=t.running&&h.state==="blocked",d=m&&!!t.prompt?.options.length,g=m&&!d&&h.kind==="permission"&&n.approve,f=(p,x,L,A="",...Se)=>o("button",{class:A,title:x,onclick:L},p,...Se),l=o("div",{class:"ag-chip",title:`${v(t)}: ${i.label}${i.msg?` \xB7 ${i.msg}`:""}`,data:{state:t.running?h.state:"stopped"}},o("span",{class:"ag-dot"}),o("b",{},i.label),i.msg&&!d?o("span",{class:"ag-msg"},i.msg):null);l.style.setProperty("--c",i.color);let b=()=>o("div",{class:"sep"}),y=Re(s.sessions,t.id),$=s.sessions.filter(p=>y.hidden.includes(p.id)),D=null;if($.length){let p=V($.filter(x=>x.running&&(x.status.state==="working"||x.status.state==="blocked")));D=f(`+${$.length}`,`${$.length} more session${$.length===1?"":"s"}: show all`,()=>{N=!N,k?.render()},"ag-more"+(p?" lit":"")+(N?" on":"")),p&&D.style.setProperty("--c",I(p).color)}let W=M()||S()&&s.sessions.length?o("div",{class:"ag-tabs"},...s.sessions.filter(p=>y.shown.includes(p.id)).map(p=>{let x=I(p),L=o("button",{class:"ag-tab"+(p.id===t.id?" cur":""),title:`${v(p)}: ${x.label}${x.msg?` \xB7 ${x.msg}`:""}`,data:{id:p.id,state:p.running?p.status.state:"stopped"},onclick:()=>{c=p.id,T()}},o("span",{class:"ag-dot"}),p.label);return L.style.setProperty("--c",x.color),p.running||L.append(o("span",{class:"ag-x",title:"Close this session",onclick:A=>{A.stopPropagation(),R("/dismiss",{id:p.id}).catch(C)}},"\xD7")),L}),...D?[D]:[],b()):null,ye=g?[f("Allow",`Approve (${v(t)}'s prompt)`,()=>Z("allow"),"ag-allow"),f("Deny","Decline",()=>Z("deny"),"ag-deny")]:n.commands.map(p=>{let x=ue(p)?X().length:-1,L=x>=0?Y(r).length-x:0,A=f(p.label,(p.title??p.prompt)+(S()?" (in a new session)":"")+(L?` \xB7 ${L} note${L===1?" is":"s are"} already with a session`:""),()=>{he(p)},"",...x>=0?[o("span",{class:"count"},String(x))]:[]);return A.disabled=x===0||m&&!S(),A.dataset.cmd=p.label,A}),$e=oe("ag-desk"),le=f(m&&!g&&!d?"Answer in CLI":"CLI",O?.isOpen()?"Hide the terminal":`Show ${v(t)}'s terminal`,()=>O?.toggle(),O?.isOpen()?"on":"");le.dataset.cli="";let de=t.running?f("\u25A0",`Stop ${v(t)}`,()=>{P("/stop").catch(C)},"ag-stop ag-desk"):null,B=f(`${t.label||"Sessions"} \u25BE`,"All sessions, Fresh, stop",()=>{N=!N,k?.render()},"ag-switch ag-phone"+(N?" on":""));B.prepend(o("span",{class:"ag-dot"})),B.style.setProperty("--c",i.color),B.dataset.state=t.running?h.state:"stopped",W&&W.classList.add("ag-desk"),e.replaceChildren(q(),l,b(),...W?[W]:[],B,...ye,$e,b(),le,...de?[de]:[])}function oe(e=""){return o("button",{class:`ag-mode ${e}`+(S()?" on":""),title:S()?`On: every prompt starts a new session with just its notes (up to ${s.max} at once). Click for one shared session`:"Off: prompts go to one session that keeps its context. Click to start a new session for every prompt",onclick:()=>{R("/mode",{mode:S()?"shared":"fresh"}).then(i=>{s={...s,...i},T()}).catch(C)}},"Fresh")}function we(e){let t=u(),i=t.running?t.prompt:void 0;if(!i?.options.length){N&&ke(e);return}let h=I(t),m=o("div",{class:"ag-card",data:{kind:t.status.kind??"",session:t.id}});if(m.style.setProperty("--c",h.color),m.append(o("div",{class:"ag-who"},o("span",{class:"ag-dot"}),v(t)+" \xB7 "+h.label)),i.steps?.length){let g=i.steps.findIndex(l=>l.current),f=l=>{g>=0&&l!==g&&F((l>g?pe:ge).repeat(Math.abs(l-g)))};m.append(o("div",{class:"ag-steps"},o("button",{class:"nav",title:"Previous question",onclick:()=>F(ge)},"\u2190"),...i.steps.map((l,b)=>o("button",{class:(l.current?"cur ":"")+l.state,title:l.label,onclick:()=>f(b)},(l.state==="done"?"\u2612 ":l.state==="submit"?"\u2714 ":"\u2610 ")+l.label)),o("button",{class:"nav",title:"Next question",onclick:()=>F(pe)},"\u2192")))}i.lines.length&&m.append(o("pre",{class:"ag-ctx"},...i.lines.flatMap((g,f)=>[...f?[`
83
- `]:[],...g.map(ve)]))),i.question&&m.append(o("div",{class:"ag-q"},i.question));let d=o("div",{class:"ag-opts"});i.options.forEach((g,f)=>{let l=o("span",{class:"n"},String(g.n??f+1));if(g.input){let b=document.createElement("input");b.placeholder=g.label.replace(/\.$/,"")+"\u2026",b.disabled=H;let y=()=>{let $=b.value.trim();$&&(b.blur(),ee(f,$))};b.addEventListener("keydown",$=>{$.key==="Enter"&&($.preventDefault(),y())}),b.addEventListener("focus",()=>{G=!0}),b.addEventListener("blur",()=>{G=!1}),d.append(o("div",{class:"ag-input"},l,b,o("button",{onclick:y,disabled:H},"Send")));return}d.append(o("button",{class:"ag-opt"+(g.selected?" sel":""),disabled:H,onclick:()=>{ee(f)},title:g.selected?"Selected in the CLI":""},l,o("span",{},g.label),g.description?o("span",{class:"d"},g.description):null))}),m.append(d,o("div",{class:"ag-foot"},o("span",{},i.hint??""),o("button",{title:"Esc in the CLI",onclick:()=>F(Te)},"Cancel"),o("button",{title:"Show "+v(t)+"'s terminal",onclick:()=>O?.show()},"CLI"))),e.append(q(),m)}function ke(e){let t=s.sessions.filter(d=>!d.running),i=[...s.sessions].reverse().map(d=>{let g=I(d),f=d.sent?.length??0,l=o("button",{class:"ag-row"+(d.id===u().id?" cur":""),title:`${v(d)}: ${g.label}${g.msg?` \xB7 ${g.msg}`:""}`,data:{id:d.id,state:d.running?d.status.state:"stopped"},onclick:()=>{c=d.id,N=!1,T()}},o("span",{class:"ag-dot"}),o("span",{class:"l"},d.label),o("b",{},g.label),o("span",{class:"m"},[f?`${f} note${f===1?"":"s"}`:"",g.msg??""].filter(Boolean).join(" \xB7 ")),d.running?o("span",{class:"ag-x",title:`Stop ${v(d)}`,onclick:b=>{b.stopPropagation(),R("/stop",{id:d.id}).catch(C)}},"\u25A0"):o("span",{class:"ag-x",title:"Close this session",onclick:b=>{b.stopPropagation(),R("/dismiss",{id:d.id}).catch(C)}},"\xD7"));return l.style.setProperty("--c",g.color),l}),h=async()=>{for(let d of t)await R("/dismiss",{id:d.id}).catch(C)},m=s.sessions.filter(d=>d.running).length;e.append(q(),o("div",{class:"ag-list"},o("div",{class:"ag-head"},o("h4",{},s.sessions.length?`Sessions \xB7 ${m} running`:"No sessions yet"),oe()),...i,o("div",{class:"ag-foot"},o("span",{},""),t.length?o("button",{onclick:()=>{h()}},`Close ended (${t.length})`):null,o("button",{onclick:()=>{N=!1,k?.render()}},"Done"))))}let ve=e=>{let t=o("span",{},e.t);return e.fg&&(t.style.color=e.fg),e.bg&&(t.style.background=e.bg),e.b&&(t.style.fontWeight="700"),e.dim&&(t.style.opacity=".6"),t};k=r.addToolbar({id:"agent",hotkey:n.hotkey||void 0,render:xe,attached:we,onShow(){u().id&&P("/ack").catch(()=>{}),T()},onHide(){T()}}),O=r.addWindow({id:"agent",title:a(),width:680,height:440,render(e){E=document.createElement("iframe"),E.src=K(),E.title=`${a()} terminal`,E.setAttribute("style","position:absolute;inset:0;width:100%;height:100%;border:0;background:#131316"),e.append(E)},onShow(){u().id&&P("/ack").catch(()=>{}),ne({type:"focus"}),k?.render()},onHide(){k?.render()},onResize(){ne({type:"fit"})}});function ae(){if(!U)return;let e=V(s.sessions)??u(),t=I(e),i=r.notes("all"),h=me(),m=i.filter(y=>h.has(y.id)&&!y.done).length,d=i.filter(y=>h.has(y.id)&&y.done).length,g=s.sessions.filter(y=>y.running).length,f=[g>1&&`${g} sessions`,m&&`${m} sent note${m===1?"":"s"} open`,d&&`${d} done`].filter(Boolean).join(" \xB7 "),l=e.running||e.status.state==="done"||e.status.state==="error"?`${v(e)}: ${t.label}${f?` \xB7 ${f}`:t.msg?` \xB7 ${t.msg}`:""}`:`Hand these notes to ${a()}`,b=o("button",{class:"ag-line",title:"Open the agent toolbar",onclick:()=>k?.show(),data:{state:e.running?e.status.state:"stopped"}},o("span",{class:"ag-dot"}),o("span",{},l),n.hotkey?o("kbd",{},Q()):n.key!==!1?o("kbd",{},(n.key||"a").toUpperCase()):null);b.style.setProperty("--c",t.color),U.replaceChildren(q(),b)}function re(e){let t=Pe(e.note,s.sessions,v),i=!!t&&/working|asking/.test(t.cls);e.el.replaceChildren(...t?[o("span",{class:`ag-tag ${t.cls}`,...i?{title:"Open the agent toolbar",onclick:()=>k?.show()}:{}},t.text)]:[])}r.addPanelSection({id:"agent",render(e){U=e,ae()}}),r.addCardDecorator({id:"agent",render(e,t){let i={el:t,note:e};J.set(e.id,i),re(i)}});function T(){c&&!s.sessions.some(l=>l.id===c)&&(c=null);let e=l=>l.running&&l.status.state==="blocked",t=s.sessions.filter(e).map(l=>l.id),i=t.find(l=>!te.has(l));te=new Set(t);let h=u(),m=_.id===h.id&&_.asking&&!e(h),d=i??(m?t[0]:void 0);d&&!G&&!e(h)&&(c=d),_={id:u().id,asking:e(u())};let g=V(s.sessions),f=g?be({...g,command:v(g)}):null;r.setStatus("agent",f?{...f,onClick:()=>k?.show()}:null),se(f?.title),E&&!E.src.endsWith(K())&&(E.src=K()),O?.setTitle(v(u())),k?.render(),ae();for(let l of J.values())l.el.isConnected?re(l):J.delete(l.note.id)}let j=null,ie=()=>{j?.close(),j=new EventSource(`${z}/stream?status=1&token=${encodeURIComponent(n.token)}`);for(let e of["hello","status"])j.addEventListener(e,t=>{s=JSON.parse(t.data),T()});j.onerror=async()=>{if(j?.readyState===EventSource.CLOSED)try{let e=await fetch(`${z}/info`);e.ok&&(n=await e.json(),s=n,T(),setTimeout(ie,1e3))}catch{}}};ie(),window.addEventListener("message",e=>{e.origin!==location.origin||e.source!==E?.contentWindow||(e.data?.type==="ack"&&P("/ack").catch(()=>{}),e.data?.type==="session"&&typeof e.data.id=="string"&&(c=e.data.id,T()))}),T()}export{Me as default,Ne as fill,Le as freeIds,be as indicatorFor,He as noteTag,V as overall,I as stateLabel,Pe as tagFor,Re as visibleTabs};
183
+ .bar button.ag-switch { padding: 6px 7px; max-width: 92px; }
184
+ .bar button.ag-primary { padding: 6px 10px; }
185
+ .bar button.ag-primary .ag-wide { display: none; }
186
+ .bar button.ag-icon { padding: 6px; }
187
+ .ag-row .ag-row-main { grid-template-columns: 8px auto auto 1fr; padding: 10px 4px 10px 8px; }
188
+ .ag-radio { padding: 9px 10px; }
189
+ }`,W=()=>Object.assign(document.createElement("style"),{textContent:En});function t(o,l={},...s){let{class:a,data:m,attrs:v,...k}=l,L=Object.assign(document.createElement(o),k);a&&(L.className=a);for(let[x,N]of Object.entries(m??{}))L.dataset[x]=N;for(let[x,N]of Object.entries(v??{}))N!==!1&&N!==void 0&&L.setAttribute(x,N);return L.append(...s.filter(x=>!!x)),L}function Ln(o,l){o.addEventListener("keydown",s=>{let a=l.indexOf(s.target);if(a<0)return;let m=s.key==="ArrowDown"?a+1:s.key==="ArrowUp"?a-1:s.key==="Home"?0:s.key==="End"?l.length-1:null;m!==null&&(s.preventDefault(),l[(m+l.length)%l.length].focus())})}async function Tn(o){if(!(o.version>=5)||typeof o.addToolbar!="function")return;let l,s;try{l=await Rt(ue),s=l.info}catch{return}let a=s,m=()=>s.command,v=()=>s.clis??[],k=()=>v().length>1,L=e=>v().find(n=>n.id===e),x=pe(v(),Pt(),s.cli),N=Ht(),O=Ot()??"app",Ut=e=>{O=e,Ye(e)},$e=(e=O)=>e==="app"?"on every page":"on this page",le=zt(),Se=null,ot=()=>L(x),D=()=>ot()?.name??m(),_=e=>L(e.cli)?.name??v()[0]?.name??m(),Kt=()=>({id:"",label:"",running:!1,command:m(),cli:x,status:{state:"idle",source:"none"},sent:[]}),B=null,I=()=>a.sessions.find(e=>e.id===B)??a.sessions[a.sessions.length-1]??Kt(),_t=()=>a.sessions.length>1,U=()=>a.mode==="fresh",H=e=>_t()&&e.label?`${_(e)} ${e.label}`:_(e),Y=e=>e.title||e.label,st=new Set,rt=e=>`${e.id}:${e.status.msg??""}`,it=e=>e.running&&e.status.state==="done"&&st.has(rt(e)),lt=e=>e.running?it(e)?"seen":e.status.state:"stopped",qt=()=>new Set(a.sessions.flatMap(e=>e.sent??[])),dt=()=>s.hotkey?s.hotkey.split("+").map(e=>e.length===1?e.toUpperCase():e[0].toUpperCase()+e.slice(1)).join("+"):"",Ce=e=>{let n=o.notes("all");return e.map(r=>n.find(i=>i.id===r)).filter(r=>!!r)},J=(e,n={})=>l.post(e,n),oe=(e,n={})=>J(e,{...n,...I().id?{id:I().id}:{}}),F=e=>o.toast(`Agent: ${e.message}`,!0),X=(e=O)=>bn(o,a.sessions,e),de=async(e,n=O,r)=>{let i=ne(e)?r??X(n):[];U()?o.toast(`Starting a new ${D()} session\u2026`):(!I().running||k()&&I().cli!==x)&&o.toast(`Starting ${D()}\u2026`);try{let p=await J("/send",{text:mn(e.prompt,o,i),notes:i,title:wn(Ce(i),e.label),task:e.label,...!U()&&I().id?{id:I().id}:{},...k()?{cli:x}:{},...ye(ot(),N)});p?.id&&(B=p.id,P())}catch(p){F(p)}},ct=e=>{oe("/answer",{choice:e}).catch(F)},ce=!1,gt=async(e,n)=>{ce=!0,M?.render();try{await oe("/choose",n===void 0?{index:e}:{index:e,text:n})}catch(r){F(r)}finally{setTimeout(()=>{ce=!1,M?.render()},400)}},fe=e=>{oe("/input",{data:e}).catch(F)},pt=new Set,Ee={id:"",asking:!1},Le=!1,y=null,R=null,Te=null,ut=null,he=()=>Te?.getRootNode(),Gt=()=>{let e=he()?.activeElement;R||!e||!(Te?.contains(e)||ut?.contains(e))||(R=e.closest("[data-k]")?.dataset.k??null)},Vt=()=>{let e=R,n=he();if(R=null,!e||!n||!("querySelector"in n))return;let r=n.querySelector(`[data-k="${CSS.escape(e)}"]`);r&&n.activeElement!==r&&r.focus()},Z=(e,n=null)=>{y=y===e?null:e,R=y?n:R,M?.render()},Yt={list:"more",switch:"primary",cmds:"more-cmds",settings:"gear",branches:"branches",files:"att"},ge=()=>{if(!y)return!1;let e=y==="list"&&matchMedia("(max-width: 560px)").matches?"sw":Yt[y];return y=null,R=e,M?.render(),!0},q=null,Ie=0,Me=e=>e.running&&(e.status.state==="working"||e.status.state==="blocked"),ft=()=>{M?.render(),Be()},ht=e=>{if(Me(e)&&q!==e.id){q=e.id,clearTimeout(Ie),Ie=window.setTimeout(()=>{q=null,ft()},2500),ft();return}q=null,clearTimeout(Ie),J("/end",{id:e.id}).then(()=>{e.worktree&&(y="branches",R=`wt-keep:${e.worktree.branch}`,M?.render())}).catch(F)},mt=e=>q===e.id?`Press again to end ${H(e)}`:e.running?`End ${H(e)}: stop the CLI and close the session${Me(e)?" (asks first)":""}`:`Close ${H(e)} (ended)`,bt=(e,n)=>t("button",{class:"ag-x"+(q===e.id?" armed":""),title:mt(e),data:{end:e.id,k:n},attrs:{"aria-label":q===e.id?`Press again to end ${Y(e)}`:`End ${Y(e)}`},onclick:r=>{r.stopPropagation(),ht(e)}},q===e.id?"End?":V("x")),K=null,wt=e=>K?.contentWindow?.postMessage(e,location.origin),Ae=()=>`${ue}/terminal${I().id?`?id=${encodeURIComponent(I().id)}`:""}`,se=null,me=null,M=null,Ne=null,Re=new Map,Pe=t("span",{class:"ag-sr",attrs:{role:"status"}}),kt=e=>o.addButton({id:"agent",label:"Agent",key:s.key===!1?void 0:s.key||"a",title:e??`${D()}: agent toolbar${s.hotkey?` \xB7 ${dt()} from anywhere`:""}`,onClick:()=>M?.show(),active:()=>!!M?.isOpen()});kt();let vt=e=>{let n=te(e),r=Ce(e.sent??[]);return[`${e.label} \xB7 ${_(e)} \xB7 ${n.label}`,e.task&&`Prompt: ${e.task}`,r.length?`Notes: ${r.slice(0,3).map(i=>nt(tt(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?nt(tt(i),50):e.focus)(Ce([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
+ `)},be=0,re=!1,Jt=e=>{if(!k()||e.button!==0)return;re=!1,clearTimeout(be);let n=e.clientX,r=e.clientY,i=c=>{Math.hypot(c.clientX-n,c.clientY-r)>10&&clearTimeout(be)},p=()=>{clearTimeout(be);for(let c of["pointerup","pointercancel"])window.removeEventListener(c,p,!0);window.removeEventListener("pointermove",i,!0),re&&setTimeout(()=>{re=!1},50)};be=window.setTimeout(()=>{re=!0,y=null,Z("switch",`cli:${x}`)},hn);for(let c of["pointerup","pointercancel"])window.addEventListener(c,p,!0);window.addEventListener("pointermove",i,!0)};function Xt(e,n){let r=ne(e)?X().length:-1,i=r>=0?at(o,O).length-r:0,p=r===0&&O==="page"?X("app").length:0,c=e.label===Qe&&r>=0?t("span",{},r?`Apply ${r}`:"Apply",t("span",{class:"ag-wide"},r===1?" note":" notes")):e.label,g=r===0||n&&!U(),f="Hold, right-click or Alt+\u2193 to switch the agent",h=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 ${$e()}`,`with ${D()}`,U()&&"in a new session",i&&`${i} note${i===1?" is":"s are"} already with a session`,r===0&&(O==="app"?"no open notes":"no open notes on this page"),p&&`${p} on other pages: \u22EF or \u2699 \u203A Notes`,k()&&f].filter(Boolean).join(" \xB7 "),attrs:{"aria-disabled":g?"true":void 0,"aria-keyshortcuts":k()?"Alt+ArrowDown Shift+F10":void 0,"aria-description":k()?`Runs ${D()}. ${f}.`:void 0},onclick:()=>{if(re){re=!1;return}g||de(e)}},c,r>=0&&e.label!==Qe?t("span",{class:"count"},String(r)):null);return h.addEventListener("pointerdown",Jt),h.addEventListener("contextmenu",C=>{k()&&(C.preventDefault(),y!=="switch"&&Z("switch",`cli:${x}`))}),h.addEventListener("keydown",C=>{!k()||!(C.altKey&&C.key==="ArrowDown"||C.shiftKey&&C.key==="F10"||C.key==="ContextMenu")||(C.preventDefault(),y!=="switch"&&Z("switch",`cli:${x}`))}),h}function Zt(e){Gt(),Te=e;let n=I(),r=te(n),i=n.status,p=n.running&&i.state==="blocked",c=p&&(!!n.prompt?.options.length||i.kind==="permission"&&s.approve),g=(b,ie,Fe,We="",ve="",xe={})=>t("button",{class:We,title:ie,onclick:Fe,data:ve?{k:ve}:{},attrs:xe},b),f=(b="")=>t("div",{class:`sep ${b}`});n.running&&i.state==="done"&&st.add(rt(n));let h=`${_(n)} \xB7 ${r.label}`;Pe.textContent!==h&&(Pe.textContent=h);let C=t("div",{class:"ag-chip ag-desk",title:`${H(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"},_(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);C.style.setProperty("--c",r.color);let u=vn(a.sessions.map(b=>it(b)?{...b,status:{...b.status,state:"idle"}}:b),n.id),T=a.sessions.filter(b=>u.hidden.includes(b.id)),d=null;if(T.length){let b=Ze(T.filter(Me));d=g(`+${T.length}`,`${T.length} more session${T.length===1?"":"s"}: show all`,()=>Z("list",`row:${T[0].id}`),"ag-more"+(b?" lit":""),"more",{"aria-haspopup":"dialog","aria-expanded":String(y==="list"),"aria-label":`${T.length} more sessions`}),b&&d.style.setProperty("--c",te(b).color)}let w=new Set(a.sessions.map(b=>b.cli)).size>1,$=a.sessions.length?t("div",{class:"ag-tabs ag-desk",attrs:{role:"group","aria-label":"Sessions"}},...u.shown.map(b=>a.sessions.find(ie=>ie.id===b)).map(b=>{let ie=te(b),Fe=lt(b),We=t("button",{class:"ag-tab-main",title:vt(b),data:{k:`tab:${b.id}`},attrs:{"aria-current":b.id===n.id?"true":void 0,"aria-label":`${Y(b)}, ${_(b)}, ${ie.label}`},onclick:()=>{B=b.id,y=null,P()}},t("span",{class:"ag-dot"}),w?t("span",{class:"ag-ini",attrs:{"aria-hidden":"true"}},kn(_(b))):null,t("span",{class:"ag-name"},Y(b))),ve=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 ${Y(b)}`,"aria-haspopup":"dialog","aria-expanded":String(y==="files"&&b.id===n.id)},onclick:gn=>{gn.stopPropagation();let At=y==="files"&&B===b.id;B=b.id,y=At?null:"files",R=At?`att:${b.id}`:"files-first",P()}},V("clip"),t("span",{},String(b.attachments))):null,xe=t("div",{class:"ag-tab"+(b.id===n.id?" cur":""),data:{id:b.id,state:Fe}},We,ve,bt(b,`x:${b.id}`));return xe.style.setProperty("--c",ie.color),xe}),d,f()):null,S=g(t("span",{class:"ag-name"},n.id?Y(n):"Sessions"),"All sessions",()=>Z("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?`${Y(n)}, ${r.label}`:"none"}`});S.prepend(t("span",{class:"ag-dot"})),S.append(V("down")),S.style.setProperty("--c",r.color),S.dataset.state=n.running?i.state:"stopped";let[E,...z]=s.commands,A=E?[Xt(E,p)]:[];(z.length||E&&ne(E))&&A.push(g(V("more"),"More prompts",()=>Z("cmds",E&&ne(E)?"cmd:scope":"cmd:0"),"ag-icon ag-cmds","more-cmds",{"aria-label":"More prompts","aria-haspopup":"menu","aria-expanded":String(y==="cmds")}));let j=!!se?.isOpen(),G=p&&!c,It=g(V("term"),j?"Hide the CLI window (the session keeps running)":G?`${H(n)} is asking: answer in the CLI window`:`Show ${H(n)}'s CLI window`,()=>se?.toggle(),"ag-icon ag-term"+(G&&!j?" ask":""),"term",{"aria-label":"CLI window","aria-pressed":String(j)});It.dataset.cli="";let cn=g(V("gear"),"Agent settings: CLI, model, effort, sessions",()=>{ze=null,Z("settings",`set-cli:${x}`)},"ag-icon ag-gear","gear",{"aria-label":"Agent settings","aria-haspopup":"dialog","aria-expanded":String(y==="settings")}),ee=a.worktrees?.left??[],Mt=ee.length?g(t("span",{class:"ag-bc"},V("branch"),t("span",{class:"count"},String(ee.length))),`${ee.length} ended session${ee.length===1?"":"s"}' branch${ee.length===1?"":"es"}: keep, merge or discard`,()=>Z("branches",`wt-keep:${ee[0].branch}`),"ag-icon ag-branches","branches",{"aria-label":`${ee.length} branch${ee.length===1?"":"es"} to keep, merge or discard`,"aria-haspopup":"dialog","aria-expanded":String(y==="branches")}):null;e.replaceChildren(W(),Pe,C,f("ag-desk"),...$?[$]:[],S,...A,f("ag-desk"),...Mt?[Mt]:[],It,cn),queueMicrotask(Vt)}function Qt(e){if(ut=e,y==="settings")return void e.append(W(),$t());if(y==="switch"&&k())return void e.append(W(),en());if(y==="cmds")return void e.append(W(),tn());if(y==="list")return ln(e);if(y==="branches")return void e.append(W(),rn());if(y==="files")return void e.append(W(),sn());let n=I(),r=n.running?n.prompt:void 0,i=te(n),p=t("div",{class:"ag-card",data:{kind:n.status.kind??"",session:n.id},attrs:{role:"group","aria-label":`${H(n)} asks`}});if(p.style.setProperty("--c",i.color),p.append(t("div",{class:"ag-who"},t("span",{class:"ag-dot"}),`${H(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 (${H(n)}'s prompt)`,data:{k:"allow"},onclick:()=>ct("allow")},"Allow"),t("button",{class:"ag-deny",title:"Decline",data:{k:"deny"},onclick:()=>ct("deny")},"Deny")),t("div",{class:"ag-foot"},t("span",{},"Its own prompt is in the CLI window"),t("button",{title:`Show ${H(n)}'s CLI window`,onclick:()=>se?.show()},"Open CLI window"))),e.append(W(),p);return}if(r.steps?.length){let g=r.steps.findIndex(h=>h.current),f=h=>{g>=0&&h!==g&&fe((h>g?Dt:jt).repeat(Math.abs(h-g)))};p.append(t("div",{class:"ag-steps"},t("button",{class:"nav",title:"Previous question",attrs:{"aria-label":"Previous question"},onclick:()=>fe(jt)},"\u2190"),...r.steps.map((h,C)=>t("button",{class:(h.current?"cur ":"")+h.state,title:h.label,attrs:{"aria-current":h.current?"step":void 0},onclick:()=>f(C)},(h.state==="done"?"\u2612 ":h.state==="submit"?"\u2714 ":"\u2610 ")+h.label)),t("button",{class:"nav",title:"Next question",attrs:{"aria-label":"Next question"},onclick:()=>fe(Dt)},"\u2192")))}r.lines.length&&p.append(t("pre",{class:"ag-ctx"},...r.lines.flatMap((g,f)=>[...f?[`
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(z=>!/^(diff --git|index |--- |\+\+\+ )/.test(z)).flatMap((z,A)=>[...A?[`
193
+ `]:[],t("span",{class:z.startsWith("+")?"add":z.startsWith("-")?"del":z.startsWith("@@")?"hunk":""},z)])))}}}let h=(u,T="")=>{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??""),w=[t("span",{class:"ag-path"},u.path??""),u.title?t("span",{class:"ag-t"},u.title):null];return d?t("a",{class:"ag-frow "+T,href:St(e.id,u.path),target:"_blank",rel:"noopener noreferrer",title:`Open ${u.path} in a new tab`,data:{k:p(`file:${u.id}`)}},...w):t("div",{class:"ag-frow "+T,title:u.path??""},...w)},C=(u,T="")=>{let d=yn(u.url??""),w=[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 "+T,href:u.url,target:"_blank",rel:"noopener noreferrer",title:`Open ${u.url} in a new tab`,data:{k:p(`url:${u.id}`)}},...w):t("div",{class:"ag-frow ag-ext "+T,title:`${u.url} (not on this machine: copy it to open)`},...w)};g.files.length&&f.append(t("div",{class:"ag-sub"},"Files"),...g.files.map(u=>h(u))),g.links.length&&f.append(t("div",{class:"ag-sub"},"Links"),...g.links.map(u=>C(u))),g.mentioned.length&&f.append(t("details",{class:"ag-ment"},t("summary",{},`Mentioned (${g.mentioned.length})`),...g.mentioned.map(u=>u.kind==="url"?C(u,"dim"):h(u,"dim")))),n.append(f)}return n.append(t("div",{class:"ag-foot"},t("span",{},"Kept while the session runs"),t("button",{data:{k:"files-done"},onclick:()=>ge()},"Done"))),n}let ke=null,Ct=0;function rn(){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(F)};for(let i of e){let p=!!(i.dirty||i.ahead),c=ke===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 ${Bt(i)}`:"Delete the worktree and the branch",onclick:()=>{if(p&&!c){ke=i.branch,clearTimeout(Ct),Ct=window.setTimeout(()=>{ke=null,M?.render()},4e3),R=`wt-discard:${i.branch}`,M?.render();return}ke=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"},`${Bt(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:()=>ge()},"Done"))),n}function ln(e){let n=a.sessions.filter(c=>!c.running),r=[...a.sessions].reverse().map(c=>{let g=te(c),f=c.sent?.length??0,h=t("button",{class:"ag-row-main",title:vt(c),data:{k:`row:${c.id}`},attrs:{"aria-current":c.id===I().id?"true":void 0},onclick:()=>{B=c.id,y=null,R=matchMedia("(max-width: 560px)").matches?"sw":`tab:${c.id}`,P()}},t("span",{class:"ag-dot"}),t("span",{class:"l"},c.label),t("b",{},g.label),t("span",{class:"m"},[c.title,k()?_(c):"",c.worktree?.branch??"",f?`${f} note${f===1?"":"s"}`:"",c.attachments?`${c.attachments} attached`:"",g.msg??""].filter(Boolean).join(" \xB7 "))),C=t("div",{class:"ag-row"+(c.id===I().id?" cur":""),data:{id:c.id,state:lt(c)}},h,bt(c,`rowx:${c.id}`));return C.style.setProperty("--c",g.color),C}),i=async()=>{for(let c of n)await J("/end",{id:c.id}).catch(F)},p=a.sessions.filter(c=>c.running).length;e.append(W(),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:()=>ge()},"Done"))))}let dn=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:Zt,attached:Qt,onEscape:ge,onShow(){Se?.(),I().id&&oe("/ack").catch(()=>{}),P()},onHide(){y=null,P()}});let Et=()=>{let e=I();return e.id?[e.label,_(e),e.title,e.worktree?.branch].filter(Boolean).join(" \xB7 "):`${D()} \xB7 no session yet`};function Be(){if(!me)return;let e=I();if(!e.id){me.replaceChildren();return}let n=q===e.id;me.replaceChildren(W(),t("button",{class:"ag-wend"+(n?" armed":""),title:mt(e),data:{k:"wend"},onclick:()=>ht(e)},n?"End? Press again":e.running?"End session":"Close session"))}se=o.addWindow({id:"agent",title:Et(),width:680,height:440,hideAs:"minimize",render(e,n){me=n,Be(),K=document.createElement("iframe"),K.src=Ae(),K.title=`${m()} terminal`,K.setAttribute("style","position:absolute;inset:0;width:100%;height:100%;border:0;background:#131316"),e.append(K)},onShow(){I().id&&oe("/ack").catch(()=>{}),wt({type:"focus"}),M?.render()},onHide(){M?.render()},onResize(){wt({type:"fit"})}});function Lt(){if(!Ne)return;let e=Ze(a.sessions)??I(),n=te(e),r=o.notes("all"),i=qt(),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,f=[g>1&&`${g} sessions`,p&&`${p} sent note${p===1?"":"s"} open`,c&&`${c} done`].filter(Boolean).join(" \xB7 "),h=e.running||e.status.state==="done"||e.status.state==="error"?`${H(e)}: ${n.label}${f?` \xB7 ${f}`:n.msg?` \xB7 ${n.msg}`:""}`:`Hand these notes to ${D()}`,C=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",{},h),s.hotkey?t("kbd",{},dt()):s.key!==!1?t("kbd",{},(s.key||"a").toUpperCase()):null);C.style.setProperty("--c",n.color),Ne.replaceChildren(W(),C)}function Tt(e){let n=Sn(e.note,a.sessions,H),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){Ne=e,Lt()}}),o.on("noteCreated",e=>{let n=s.commands[0];if(!le||!(o.version>=7)||!n||!ne(n)||e.done||!U()&&I().running&&I().status.state==="blocked")return;let r=()=>[...new Set([e.id,...X()])],i=r().length;Se?.();let p=e.file;Se=o.toast(`${p?`Saved \u2192 ${p}`:"Saved"} \xB7 Send to ${D()}?`,{actions:[{label:"This note",primary:!0,title:`Apply this note with ${D()}${U()?" in a new session":""}`,onClick:()=>{de(n,O,[e.id])}},...i>1?[{label:`All ${i}`,title:`Apply the ${i} open notes ${$e()} with ${D()}`,onClick:()=>{de(n,O,r())}}]:[]]})}),o.addCardDecorator({id:"agent",render(e,n){let r={el:n,note:e};Re.set(e.id,r),Tt(r)}});function P(){B&&!a.sessions.some(h=>h.id===B)&&(B=null);let e=h=>h.running&&h.status.state==="blocked",n=a.sessions.filter(e).map(h=>h.id),r=n.find(h=>!pt.has(h));pt=new Set(n);let i=I(),p=Ee.id===i.id&&Ee.asking&&!e(i),c=r??(p?n[0]:void 0);c&&!Le&&!e(i)&&(B=c,y==="list"&&(y=null)),Ee={id:I().id,asking:e(I())},y==="files"&&e(I())&&(y=null),x=pe(v(),x,s.cli);let g=Ze(a.sessions),f=g?Wt({...g,command:H(g)}):null;o.setStatus("agent",f?{...f,onClick:()=>M?.show()}:null),kt(f?.title),K&&!K.src.endsWith(Ae())&&(K.src=Ae()),se?.setTitle(Et()),Be(),M?.render(),Lt();for(let h of Re.values())h.el.isConnected?Tt(h):Re.delete(h.note.id)}l.watch(e=>{a=e,P()},e=>{s.clis=e,y==="settings"&&Q(),P()},e=>{s=e,a=s,x=pe(v(),x,s.cli),P()}),window.addEventListener("message",e=>{e.origin!==location.origin||e.source!==K?.contentWindow||(e.data?.type==="ack"&&oe("/ack").catch(()=>{}),e.data?.type==="session"&&typeof e.data.id=="string"&&(B=e.data.id,P()))}),P()}export{Tn as default,mn as fill,bn as freeIds,$n as groupAttachments,Wt as indicatorFor,kn as initials,yn as isLocalUrl,On as noteTag,tt as noteText,Ze as overall,pe as pickCli,nt as shorten,te as stateLabel,et as tabRank,wn as tabTitle,Sn as tagFor,vn as visibleTabs,Bt as worktreeState};