@umage.ai/redline-agent 0.2.0 → 0.2.2
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/README.md +3 -1
- package/dist/index.cjs +3 -3
- package/dist/panel.js +19 -6
- package/dist/terminal.js +18 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,8 @@ it (prebuilt on Windows and macOS, compiled on Linux; without build tools: `npm
|
|
|
29
29
|
| **The agent toolbar** | **← Agent**, the state ("Claude Code · Working…"), a tab per session (named by its notes), **Apply N notes**, **>_** the CLI window, **⚙** settings |
|
|
30
30
|
| **Questions in a card** | Permission prompts with their diff, Claude Code's stepped questions, trust dialogs: every option, and a field for your own answer. ACP agents send theirs as data |
|
|
31
31
|
| **Several CLIs** | Every installed one is offered; ⚙ or holding **Apply** switches; model and effort per CLI (only values the CLI offers reach it) |
|
|
32
|
+
| **All your notes** | **Apply** hands over the open notes on every page, so you can pin across the app and apply them in one go; ⚙ › Notes narrows it to this page |
|
|
33
|
+
| **Send after a save** | A toast after each note: **This note** or **All N** to the agent, gone in a few seconds; ⚙ › Notes turns it off |
|
|
32
34
|
| **Fresh sessions** | A new session per prompt with only its notes, several at once; or one shared session that keeps its context |
|
|
33
35
|
| **Worktrees** | ⚙ **Each new session in its own git worktree**: its own branch, `redline/<name>`; when it ends, keep, merge (clean only) or discard it |
|
|
34
36
|
| **Attachments** | A 📎 count on each tab: per prompt, the files it changed (with the diff), images, files and links it pointed at |
|
|
@@ -61,7 +63,7 @@ redline({
|
|
|
61
63
|
Or hand it over yourself, typed: `import { agent } from '@umage.ai/redline-agent'; redline({ agent: agent({ command: 'codex' }) })`.
|
|
62
64
|
Every option and its default: [docs/OPTIONS.md](https://github.com/umage-ai/redline/blob/main/docs/OPTIONS.md#agent-umageairedline-agent-d53).
|
|
63
65
|
|
|
64
|
-
Prompts fill in `{page}`, `{url}
|
|
66
|
+
Prompts fill in `{page}`, `{url}`, `{ids}` (the open notes no running session has: on every page, or this page only per ⚙ › Notes) and `{pages}` (where they are); a prompt with `{ids}`
|
|
65
67
|
shows their count and tags those notes in the notes panel (sent, being worked on, waiting for you, done).
|
|
66
68
|
`instructions` (text, or `{ file }` read at every start) reach Claude Code as `--append-system-prompt-file`, any other CLI
|
|
67
69
|
ahead of its first prompt.
|
package/dist/index.cjs
CHANGED
|
@@ -5155,7 +5155,7 @@ var import_node_fs = require("node:fs");
|
|
|
5155
5155
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
5156
5156
|
function git(cwd, args, timeout = 3e4) {
|
|
5157
5157
|
return new Promise((resolve, reject) => {
|
|
5158
|
-
(0, import_node_child_process.execFile)("git", args, { cwd, timeout, windowsHide: true, maxBuffer: 16 * 1024 * 1024, env: { ...process.env, GIT_TERMINAL_PROMPT: "0", LC_ALL: "C" } }, (err, stdout, stderr) => {
|
|
5158
|
+
(0, import_node_child_process.execFile)("git", args, { cwd, timeout, windowsHide: true, maxBuffer: 16 * 1024 * 1024, env: { ...process.env, GIT_TERMINAL_PROMPT: "0", GIT_OPTIONAL_LOCKS: "0", LC_ALL: "C" } }, (err, stdout, stderr) => {
|
|
5159
5159
|
if (err) reject(Object.assign(new Error(String(stderr || err.message).trim().split("\n").pop() || "git failed"), { code: err.code }));
|
|
5160
5160
|
else resolve(String(stdout));
|
|
5161
5161
|
});
|
|
@@ -5379,7 +5379,7 @@ async function snapshot(cwd) {
|
|
|
5379
5379
|
try {
|
|
5380
5380
|
await import_node_fs2.promises.copyFile(index, tmp).catch(() => {
|
|
5381
5381
|
});
|
|
5382
|
-
const env = { ...process.env, GIT_INDEX_FILE: tmp, GIT_TERMINAL_PROMPT: "0", LC_ALL: "C" };
|
|
5382
|
+
const env = { ...process.env, GIT_INDEX_FILE: tmp, GIT_TERMINAL_PROMPT: "0", GIT_OPTIONAL_LOCKS: "0", LC_ALL: "C" };
|
|
5383
5383
|
const run = (args) => new Promise((resolve, reject) => (0, import_node_child_process2.execFile)("git", args, { cwd, env, windowsHide: true, maxBuffer: 16 * 1024 * 1024, timeout: 6e4 }, (e, out, err) => e ? reject(new Error(String(err || e.message))) : resolve(String(out))));
|
|
5384
5384
|
await run(["add", "-A", "--", ":/"]);
|
|
5385
5385
|
return (await run(["write-tree"])).trim() || null;
|
|
@@ -7781,7 +7781,7 @@ function createBridge(setup) {
|
|
|
7781
7781
|
var HERE2 = typeof __dirname === "string" ? __dirname : import_node_path7.default.dirname((0, import_node_url2.fileURLToPath)(void 0));
|
|
7782
7782
|
var DIST = import_node_path7.default.basename(HERE2) === "dist" ? HERE2 : import_node_path7.default.join(HERE2, "../dist");
|
|
7783
7783
|
var DEFAULT_COMMANDS = [
|
|
7784
|
-
{ label: "Apply notes", title: "Ask the agent to apply the open notes
|
|
7784
|
+
{ label: "Apply notes", title: "Ask the agent to apply the open notes", prompt: "Apply the open Redline notes {ids} on {pages}, following the redline skill. Mark each one done when it is applied." }
|
|
7785
7785
|
];
|
|
7786
7786
|
var MCP_TOKEN = (0, import_node_crypto3.randomBytes)(24).toString("base64url");
|
|
7787
7787
|
var terminalPage = (base) => `<!doctype html><html><head><meta charset="utf-8"><title>Agent</title>
|
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; }
|
|
@@ -112,6 +112,19 @@ var yt="/__redline";async function $t(s){let i=await ze(s),r=async(n,m={})=>{let
|
|
|
112
112
|
.ag-radio input { accent-color: var(--ink); margin: 0; flex: none; }
|
|
113
113
|
.ag-radio span { min-width: 0; }
|
|
114
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)); }
|
|
115
128
|
.ag-field { display: grid; gap: 0; }
|
|
116
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; }
|
|
117
130
|
.ag-field select:disabled { opacity: .6; }
|
|
@@ -173,8 +186,8 @@ var yt="/__redline";async function $t(s){let i=await ze(s),r=async(n,m={})=>{let
|
|
|
173
186
|
.bar button.ag-icon { padding: 6px; }
|
|
174
187
|
.ag-row .ag-row-main { grid-template-columns: 8px auto auto 1fr; padding: 10px 4px 10px 8px; }
|
|
175
188
|
.ag-radio { padding: 9px 10px; }
|
|
176
|
-
}`,
|
|
177
|
-
`)},
|
|
178
|
-
`]:[],...p.map(Jt)]))),o.question&&f.append(t("div",{class:"ag-q"},o.question));let c=t("div",{class:"ag-opts"});o.options.forEach((p,u)=>{let d=t("span",{class:"n",attrs:{"aria-hidden":"true"}},String(p.n??u+1));if(p.input){let v=t("input",{placeholder:p.label.replace(/\.$/,"")+"\u2026",disabled:ne,data:{k:`opt:${u}`},attrs:{"aria-label":p.label.replace(/\.$/,"")}}),g=()=>{let x=v.value.trim();x&&(v.blur(),et(u,x))};v.addEventListener("keydown",x=>{x.key==="Enter"&&(x.preventDefault(),g())}),v.addEventListener("focus",()=>{ke=!0}),v.addEventListener("blur",()=>{ke=!1}),c.append(t("div",{class:"ag-input"},d,v,t("button",{onclick:g,disabled:ne},"Send")));return}c.append(t("button",{class:"ag-opt"+(p.selected?" sel":""),disabled:ne,onclick:()=>{et(u)},title:p.selected?"Selected in the CLI":"",data:{k:`opt:${u}`}},d,t("span",{},p.label),p.description?t("span",{class:"d"},p.description):null))}),f.append(c,t("div",{class:"ag-foot"},t("span",{},o.hint??""),t("button",{title:"Esc in the CLI",onclick:()=>re(nn)},"Cancel"),t("button",{title:`Show ${P(a)}'s CLI window`,onclick:()=>Q?.show()},"Open CLI window"))),e.append(O(),f)}function ct(e,a,o){let l=t("div",{class:"ag-list ag-menu",attrs:{role:"menu","aria-label":e}},t("h4",{attrs:{"aria-hidden":"true"}},e)),f=a.some(u=>u.checked!==void 0),c=a.find(u=>u.checked)?.k??a[0]?.k,p=a.map(u=>t("button",{class:"ag-mi",title:u.title??"",data:{k:u.k},tabIndex:u.k===c?0:-1,attrs:{role:f?"menuitemradio":"menuitem","aria-checked":f?String(!!u.checked):void 0,"aria-disabled":u.disabled?"true":void 0},onclick:()=>{u.disabled||u.act()}},t("b",{},u.text),u.sub?t("span",{},u.sub):null));return mn(l,p),l.append(...p),o&&l.append(t("div",{class:"ag-hint"},o)),l}function Ft(){return ct("Run the next prompt with",b().map(e=>({k:`cli:${e.id}`,text:e.name,sub:e.name!==e.command?e.command:void 0,checked:e.id===y,title:`Run ${e.name} (${e.command}) for the next prompt${X()?"":", in place of the shared session"}`,act:()=>{gt(e.id),k=null,I="primary",s.toast(`Next prompt: ${e.name}`),R()}})),"Model and effort: \u2699")}function Ut(){return ct("Prompts",r.commands.slice(1).map((e,a)=>{let o=Fe(e)?be().length:-1;return{k:`cmd:${a}`,text:e.label,sub:o>=0?`${o} note${o===1?"":"s"}`:void 0,disabled:o===0,title:e.title??e.prompt,act:()=>{k=null,I="more-cmds",C?.render(),Ze(e)}}}),`with ${F()}${X()?", in a new session":""}`)}let gt=e=>{y=e,je(e)},Le=null;function pt(){let e=W(),a=r.defaults??{},o=Be(e,T),l=t("div",{class:"ag-set",attrs:{role:"dialog","aria-label":"Agent settings"}},t("h4",{attrs:{"aria-hidden":"true"}},"Agent settings")),f=(d,v,g,x,$)=>{let S=t("fieldset",{},t("legend",{},d));for(let M of g){let A=t("input",{type:"radio",name:v,value:M.value,checked:M.value===x,data:{k:M.k}});A.addEventListener("change",()=>{A.checked&&$(M.value)}),S.append(t("label",{class:"ag-radio"},A,t("span",{},M.label),M.sub?t("small",{},M.sub):null))}return S},c=(d,v,g,x,$,S)=>{let M=`ag-${v}`,A=t("select",{id:M,data:{k:v}},t("option",{value:""},`Default${$?` (${$})`:""}`),...g.map(N=>t("option",{value:N.value,selected:N.value===x},N.name??N.value)));return A.addEventListener("change",()=>S(A.value)),t("div",{class:"ag-field"},t("label",{class:"ag-lbl",htmlFor:M},d),A)},p=(d,v)=>{if(!e)return;let g={...T[e.id],[d]:v||void 0};g.model||delete g.model,g.effort||delete g.effort,T={...T,[e.id]:g},!g.model&&!g.effort&&delete T[e.id],De(T),ce()};w()&&l.append(f("Agent","ag-set-cli",b().map(d=>({value:d.id,label:d.name,sub:d.name!==d.command?d.command:void 0,k:`set-cli:${d.id}`})),y,d=>{gt(d),ce(),R()})),e?.pending?l.append(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 ${e.name} for its models\u2026`)))):e?.models?.length&&l.append(c("Model","set-model",e.models,o.model,a.model,d=>p("model",d))),e?.efforts?.length&&l.append(c("Effort","set-effort",e.efforts,o.effort,a.effort,d=>p("effort",d))),e&&!e.pending&&!e.models?.length&&!e.efforts?.length&&l.append(t("div",{class:"ag-note"},`${e.name} offers no model or effort choice here: it uses its own config.`)),l.append(f("Sessions","ag-set-mode",[{value:"fresh",label:"New session per prompt",sub:`up to ${n.max} at once`,k:"set-mode:fresh"},{value:"shared",label:"Keep one session going",sub:"keeps its context",k:"set-mode:shared"}],n.mode,d=>{K("/mode",{mode:d}).then(v=>{n={...n,...v},R()}).catch(H)}));let u=n.worktrees;if(u){let d=!u.git,v=t("input",{type:"checkbox",checked:u.on,disabled:d,data:{k:"set-wt"},attrs:{"aria-describedby":"ag-wt-help"}});v.addEventListener("change",()=>{K("/worktrees",{on:v.checked}).then(x=>{n={...n,...x},ce(),R()}).catch(x=>{v.checked=!v.checked,H(x)})});let g=d?`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.${n.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.`;l.append(t("fieldset",{},t("legend",{},"Worktrees"),t("label",{class:"ag-radio"+(d?" off":"")},v,t("span",{},"Each new session in its own git worktree")),t("div",{class:"ag-help",id:"ag-wt-help"},g)))}return l.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 and sessions",onclick:Kt},"Reset to project defaults"))),l.addEventListener("keydown",d=>{d.key==="Escape"&&/^(INPUT|SELECT)$/.test(d.target.tagName)&&(d.preventDefault(),ae())}),Le=l,l}function ce(){if(!Le?.isConnected){C?.render();return}let e=ie()?.activeElement?.closest("[data-k]")?.dataset.k,a=Le,o=pt();a.replaceWith(o),e&&o.querySelector(`[data-k="${CSS.escape(e)}"]`)?.focus(),C?.render()}async function Kt(){T={},De(null),y=se(b(),null,r.cli),je(null);let e=r.defaults?.sessions??"fresh";if(n.mode!==e)try{n={...n,...await K("/mode",{mode:e})}}catch(o){H(o)}let a=!!r.defaults?.worktrees;if(n.worktrees?.git&&n.worktrees.on!==a)try{n={...n,...await K("/worktrees",{on:a})}}catch(o){H(o)}I="set-reset",s.toast("Agent settings: back to the project's defaults"),R()}let Te=new Map,ge=new Set,Me=!1,Ie=new Map,ut=(e,a)=>`${oe}/file?id=${encodeURIComponent(e)}&path=${encodeURIComponent(a)}&token=${encodeURIComponent(i.info.token)}`;function _t(e){let a=`${e.rounds??0}:${e.attachments??0}`,o=Te.get(e.id);return o?.key===a?o.rounds:(Te.set(e.id,{key:a,rounds:o?.rounds??null}),fetch(`${oe}/attachments?id=${encodeURIComponent(e.id)}&token=${encodeURIComponent(i.info.token)}`).then(l=>l.ok?l.json():null).then(l=>{l&&(Te.set(e.id,{key:a,rounds:l.rounds}),k==="files"&&(Me&&(Me=!1,I="files-first"),C?.render()))}).catch(()=>{}),o?.rounds??null)}function qt(e,a){let o=ie();if(!o)return;let l=t("div",{class:"zoom",tabIndex:-1,attrs:{role:"dialog","aria-label":"Image, Esc to close"}},t("img",{src:e,alt:""})),f=()=>{l.remove(),a.focus()};l.addEventListener("click",f),l.addEventListener("keydown",c=>{c.key==="Escape"&&(c.preventDefault(),c.stopPropagation(),f())}),o.append(l),l.focus()}function Gt(){let e=L(),a=t("div",{class:"ag-list ag-files",attrs:{role:"dialog","aria-label":`Attachments of ${U(e)}`}},t("h4",{},`${e.label}${e.title?` \xB7 ${e.title}`:""} \xB7 attachments`)),o=e.id?_t(e):[];if(!o)return Me=!0,a.append(t("div",{class:"ag-hint",data:{k:"files-first"},tabIndex:-1},"Loading\u2026")),a;o.some(c=>c.items.length)||a.append(t("div",{class:"ag-hint"},"Nothing yet: files it changes, images and links it points at show here, per prompt."));let l=!0,f=c=>l?(l=!1,"files-first"):c;for(let c of o){if(!c.items.length)continue;let p=pn(c.items),u=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(p.images.length&&u.append(t("div",{class:"ag-thumbs"},...p.images.map(g=>{let x=ut(e.id,g.path),$=t("button",{class:"ag-thumb",title:`${g.title?g.title+" \xB7 ":""}${g.path} (click to zoom)`,data:{k:f(`img:${g.id}`)},attrs:{"aria-label":`Zoom ${g.title??g.path}`}},t("img",{src:x,alt:g.title??g.path??"",loading:"lazy"}));return $.onclick=()=>qt(x,$),$}))),p.changed.length){let g=p.changed.reduce(($,S)=>$+(S.added??0),0),x=p.changed.reduce(($,S)=>$+(S.removed??0),0);u.append(t("div",{class:"ag-sub"},`Changed ${p.changed.length} file${p.changed.length===1?"":"s"}`,t("span",{class:"ag-num"},t("i",{class:"add"},`+${g}`)," ",t("i",{class:"del"},`\u2212${x}`))));for(let $ of p.changed){let S=`${e.id}:${c.n}:${$.path}`,M=ge.has(S),A=t("button",{class:"ag-frow",data:{k:f(`chg:${$.id}`)},attrs:{"aria-expanded":String(M)},title:M?"Hide the diff":"Show the diff",onclick:()=>{ge.has(S)?ge.delete(S):(ge.add(S),Ie.has(S)||fetch(`${oe}/diff?id=${encodeURIComponent(e.id)}&round=${c.n}&path=${encodeURIComponent($.path)}&token=${encodeURIComponent(i.info.token)}`).then(N=>N.ok?N.text():"(no diff)").then(N=>{Ie.set(S,N),C?.render()}).catch(()=>{})),I=`chg:${$.id}`,C?.render()}},t("span",{class:"ag-st",attrs:{"aria-label":{A:"added",D:"deleted",M:"modified"}[$.status??"M"]??"changed"}},$.status??"M"),t("span",{class:"ag-path"},$.path??""),t("span",{class:"ag-num"},t("i",{class:"add"},`+${$.added??0}`)," ",t("i",{class:"del"},`\u2212${$.removed??0}`)));if(u.append(A),M){let N=Ie.get(S);u.append(N===void 0?t("div",{class:"ag-hint"},"Loading the diff\u2026"):t("pre",{class:"ag-ctx ag-diff"},...N.split(`
|
|
179
|
-
`).filter(
|
|
180
|
-
`]:[],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};
|