<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf" content="{{CSRF}}">
<link rel="icon" href="/favicon.ico" sizes="any">
<title>eclipse</title>
<style>
{{PALETTE}}
* { box-sizing: border-box; }
body { margin:0; height:100vh; display:flex; background:var(--bg); color:var(--fg); font:15px/1.5 system-ui, sans-serif; }
aside { width:260px; background:var(--panel); border-right:1px solid var(--line); display:flex; flex-direction:column; }
aside h1 { font-size:16px; margin:0; padding:14px 16px; border-bottom:1px solid var(--line); }
aside small { display:block; color:var(--dim); font-weight:normal; margin-top:2px; }
#model { background:transparent; border:0; padding:0; font:inherit; color:var(--dim); cursor:pointer; text-align:left; max-width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
aside h1 { display:flex; align-items:center; gap:8px; font-size:17px; letter-spacing:.02em;
color:var(--accent); }
aside h1 #mark { display:block; width:22px; height:22px; flex:none; }
aside h1 .version { color:var(--faint); font:11px ui-monospace, monospace; letter-spacing:0; }
#statsrow { position:relative; display:flex; align-items:baseline; gap:10px; padding:6px 20px 0; }
#statsrow #stats { flex:1; padding:0; }
#statsrow #yolo { font:600 11px/1.4 ui-monospace, monospace; letter-spacing:.08em;
text-transform:uppercase; color:var(--bad); border:1px solid var(--bad);
border-radius:3px; padding:0 5px; }
#statsrow #yolo[hidden] { display:none; }
#statsrow #judge { font:600 11px/1.4 ui-monospace, monospace; letter-spacing:.08em;
text-transform:uppercase; color:var(--bad); border:1px dashed var(--bad);
border-radius:3px; padding:0 5px; }
#statsrow #judge[hidden] { display:none; }
#jump { position:absolute; right:20px; bottom:calc(100% + 8px); z-index:19;
background:var(--panel); color:var(--accent); border:1px solid var(--line); border-radius:999px;
padding:5px 12px; font:600 12px/1.3 ui-monospace, monospace; cursor:pointer;
box-shadow:0 6px 18px rgba(0,0,0,.45); }
#jump:hover { color:var(--fg); border-color:var(--accent); }
#jump.card { color:var(--bad); border-color:var(--bad); }
#jump[hidden] { display:none; }
#model { flex:none; background:transparent; color:var(--dim); border:1px solid var(--line);
border-radius:999px; padding:1px 10px; font:11px/1.5 ui-monospace, monospace; cursor:pointer;
max-width:40ch; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
#model:hover, #model[aria-expanded="true"] { color:var(--fg); border-color:var(--accent); }
#effort { flex:none; font:11px/1.5 ui-monospace, monospace; color:var(--faint);
white-space:nowrap; }
#effort.session { color:var(--accent); }
#models { position:absolute; right:20px; bottom:calc(100% + 6px); z-index:20; min-width:280px;
max-width:min(420px, 90vw); max-height:45vh; overflow-y:auto; background:var(--panel);
border:1px solid var(--line); border-radius:8px; box-shadow:0 8px 24px rgb(0 0 0 / .45); }
#models button { display:block; width:100%; text-align:left; background:transparent; color:var(--fg);
border:0; border-radius:0; padding:6px 12px; font:12px/1.5 ui-monospace, monospace; cursor:pointer; }
#models button:hover, #models button:focus-visible { background:var(--hover); outline:none; }
#models button.current { color:var(--accent); }
#models button.dim { color:var(--dim); }
#models button:disabled { color:var(--faint); cursor:default; }
#models button.head { color:var(--dim); font-size:10px; letter-spacing:.1em; text-transform:uppercase; }
#modelnote { color:var(--dim); font-size:11px; padding:8px 12px; border-top:1px solid var(--line); }
#modelnote:empty { display:none; }
#models[hidden] { display:none; }
#cmdmenu { position:absolute; left:0; bottom:calc(100% + 6px); z-index:21; min-width:340px;
max-width:min(560px, 100%); max-height:280px; overflow-y:auto; background:var(--bg);
border:1px solid var(--line); border-radius:10px; padding:5px; box-shadow:0 10px 28px rgba(0,0,0,.45); }
#cmdmenu button { display:flex; gap:10px; align-items:baseline; width:100%; text-align:left;
background:transparent; color:var(--fg); border:0; border-radius:6px; padding:5px 8px; cursor:pointer;
font:12px/1.4 ui-monospace, monospace; }
#cmdmenu button .label { color:var(--accent); white-space:nowrap; }
#cmdmenu button .why { color:var(--dim); font-family:inherit; overflow:hidden;
text-overflow:ellipsis; white-space:nowrap; }
#cmdmenu button[aria-selected="true"] { background:var(--hover); }
#cmdmenu .empty { color:var(--dim); font:12px/1.5 ui-monospace, monospace; padding:5px 8px; }
#cmdmenu[hidden] { display:none; }
#modellist button { display:block; width:100%; text-align:left; background:transparent; border:0; border-left:3px solid transparent; color:var(--fg); font:12px/1.5 ui-monospace, monospace; padding:5px 13px; cursor:pointer; overflow-wrap:anywhere; }
#modellist button:hover:not(:disabled) { background:var(--hover); }
#modellist button.current { border-left-color:var(--accent); color:var(--accent); }
#modellist button.dim { color:var(--dim); }
#settings { display:block; width:100%; margin:8px 0; background:transparent; color:var(--dim);
border:1px solid var(--line); border-radius:6px; padding:5px 8px; cursor:pointer; }
#settings:hover, #settings[aria-expanded="true"] { color:var(--fg); border-color:var(--accent); }
#settingswindow { width:min(1040px, 94vw); height:min(760px, 84vh); padding:0; background:var(--bg);
color:var(--fg); border:1px solid var(--line); border-radius:12px; box-shadow:0 24px 60px rgba(0,0,0,.55); }
#settingswindow[open] { display:flex; flex-direction:column; }
#settingswindow::backdrop { background:rgba(0,0,0,.55); }
#settingswindow header { display:flex; gap:10px; align-items:center; padding:14px 18px;
border-bottom:1px solid var(--line); flex:0 0 auto; }
#settingswindow h2 { margin:0; font-size:13px; font-weight:600; letter-spacing:.06em;
text-transform:uppercase; color:var(--dim); }
#settingswindow header .grow { flex:1; }
#setfind { width:240px; background:var(--panel); color:var(--fg); border:1px solid var(--line);
border-radius:6px; padding:6px 9px; font:inherit; font-size:13px; }
#setclose { background:transparent; border:1px solid var(--line); color:var(--dim); border-radius:6px;
width:28px; height:28px; cursor:pointer; font-size:14px; line-height:1; }
#setbody { display:flex; gap:0; flex:1; min-height:0; }
#setsections { width:200px; flex:0 0 auto; border-right:1px solid var(--line); overflow-y:auto;
padding:12px 8px; }
#setsections button { display:flex; justify-content:space-between; gap:8px; width:100%;
background:transparent; border:0; color:var(--dim); border-radius:6px; padding:7px 10px; cursor:pointer;
font:inherit; font-size:13px; text-align:left; min-height:32px; align-items:center; }
#setsections button:hover { background:var(--hover); color:var(--fg); }
#setsections button[aria-current="true"] { background:var(--hover); color:var(--fg); }
#setsections .count { color:var(--faint); font-size:12px; }
#setrows { flex:1; min-width:0; overflow-y:auto; scrollbar-gutter:stable; padding:18px 24px 28px; }
#setrows h3 { margin:24px 0 2px; font:11px/1.4 ui-monospace, monospace; color:var(--dim);
letter-spacing:.08em; text-transform:uppercase; }
#setrows h3:first-child { margin-top:0; }
#setrows .sectionabout { color:var(--dim); font-size:13px; line-height:1.5; margin:0 0 12px;
max-width:66ch; }
.srow { padding:15px 0 17px; border-bottom:1px solid var(--line); }
.srow:last-child { border-bottom:0; }
.srow .what { display:flex; gap:8px; align-items:baseline; flex-wrap:wrap; }
.srow code { font:13px/1.4 ui-monospace, monospace; color:var(--fg); }
.srow .about { color:var(--dim); font-size:13px; line-height:1.5; margin:5px 0 10px;
max-width:66ch; }
.srow .ctl { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.srow .ctl .where { margin-left:auto; text-align:right; }
.srow input[type=text], .srow input[type=password], .srow input[type=number], .srow select,
.srow textarea { background:var(--panel); color:var(--fg); border:1px solid var(--line);
border-radius:6px; padding:5px 8px; font:13px/1.4 ui-monospace, monospace; min-width:170px; }
.srow textarea { min-width:300px; resize:vertical; }
.srow input:focus, .srow select:focus, .srow textarea:focus { outline:1px solid var(--accent); }
.srow button { background:transparent; color:var(--dim); border:1px solid var(--line);
border-radius:6px; padding:5px 10px; cursor:pointer; font:inherit; font-size:13px; }
.srow button:hover:not(:disabled) { color:var(--fg); border-color:var(--accent); }
.srow button:disabled { color:var(--faint); cursor:default; }
.srow .switch { display:inline-flex; align-items:center; gap:9px; background:transparent; border:0;
padding:0; cursor:pointer; color:var(--dim); font:inherit; font-size:13px; }
.srow .switch .track { position:relative; width:34px; height:18px; border-radius:9px;
background:var(--panel); border:1px solid var(--line); transition:background .12s, border-color .12s; }
.srow .switch .track::after { content:''; position:absolute; top:2px; left:2px; width:12px;
height:12px; border-radius:50%; background:var(--dim); transition:transform .12s, background .12s; }
.srow .switch[aria-checked="true"] { color:var(--fg); }
.srow .switch[aria-checked="true"] .track { background:var(--accent); border-color:var(--accent); }
.srow .switch[aria-checked="true"] .track::after { transform:translateX(16px); background:var(--bg); }
.srow .where { color:var(--faint); font-size:11px; }
.srow .where .restart { color:var(--warn); border:1px solid currentColor; border-radius:999px;
padding:1px 7px; font-size:10.5px; letter-spacing:.02em; white-space:nowrap; }
.srow .err { color:var(--bad); font-size:12px; margin-top:8px; }
.srow .err:empty { display:none; }
#setsections h4 { margin:14px 0 4px; padding:0 10px; font:10px/1.4 ui-monospace, monospace;
color:var(--faint); letter-spacing:.1em; text-transform:uppercase; }
#setsections h4:first-child { margin-top:2px; }
#setrows .meter { display:flex; flex-direction:column; gap:5px; color:var(--dim); font-size:12px;
margin:6px 0 12px; }
#setrows .meter .bar { height:4px; background:var(--panel); border-radius:2px; overflow:hidden; }
#setrows .meter .bar i { display:block; height:4px; background:var(--accent); }
#setrows .meter .bar.over i { background:var(--bad); }
#setrows .about.warn { color:var(--warn); }
#filetext { width:100%; box-sizing:border-box; background:var(--panel); color:var(--fg);
border:1px solid var(--line); border-radius:8px; padding:10px 12px; resize:vertical;
min-height:320px; font:12.5px/1.5 ui-monospace, monospace; }
#filetext:focus { outline:1px solid var(--accent); }
.filebar { margin-top:8px; }
.filebar .where { margin-left:auto; }
.srow button.primary, .filebar button.primary { color:var(--accent); border-color:var(--accent); }
.srow button.primary:disabled, .filebar button.primary:disabled { color:var(--faint);
border-color:var(--line); }
#setnote { color:var(--dim); font-size:11px; padding:8px 14px; border-top:1px solid var(--line); }
#modelnote { color:var(--dim); font-size:11px; line-height:1.4; padding:4px 13px 8px; }
#new { margin:10px; padding:8px; background:transparent; color:var(--accent); border:1px solid var(--line); border-radius:6px; cursor:pointer; }
#logout { margin:10px; }
#logout button { width:100%; padding:6px; background:transparent; color:var(--dim); border:1px solid var(--line); border-radius:6px; cursor:pointer; }
#sessions { list-style:none; margin:0; padding:0; overflow-y:auto; flex:1; }
#sessions li { padding:8px 16px; cursor:pointer; border-bottom:1px solid var(--line); font-size:13px; }
#sessions li.group, #sessions li.session { border-bottom:0; }
#sessions li:hover, #sessions li.active { background:var(--hover); }
#sessions .meta { color:var(--dim); font-size:11px; }
#sessions .name { overflow-wrap:anywhere; }
#sessions li.session { display:flex; align-items:flex-start; gap:6px; position:relative; }
#sessions li.session .name { flex:1; min-width:0; }
#sessions .dots { flex:none; background:transparent; border:0; color:var(--dim);
font:14px/1 inherit; padding:0 2px; cursor:pointer; opacity:.35; }
#sessions li.session:hover .dots, #sessions li.session:focus-within .dots,
#sessions li.session.active .dots, #sessions .dots[aria-expanded="true"] { opacity:1; }
#sessions .dots:hover { color:var(--fg); }
#sessions .menu { position:absolute; right:8px; top:4px; z-index:6; min-width:150px;
background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:4px;
box-shadow:0 10px 30px rgba(0,0,0,.45); }
#sessions .menu[hidden] { display:none; }
#sessions .menu button { display:block; width:100%; text-align:left; background:transparent;
border:0; border-radius:5px; color:var(--fg); font:12px/1.5 inherit; padding:5px 9px;
cursor:pointer; }
#sessions .menu button:hover, #sessions .menu button:focus-visible { background:var(--hover); }
#sessions .menu button.danger { color:var(--bad); }
#sessions li.group { display:flex; align-items:center; padding:0; border:0; }
#sessions li.group > button { display:flex; align-items:center; gap:8px; flex:1; width:100%;
padding:10px 16px 4px; border:0; background:transparent; cursor:pointer;
font:10px/1.4 ui-monospace, monospace; letter-spacing:.12em; text-transform:uppercase;
color:var(--dim); text-align:left; }
#sessions li.group > button::after { content:''; flex:1; height:1px; background:var(--line); }
#sessions li.group > button:hover { color:var(--fg); }
#sessions li.group > button:focus-visible { outline:2px solid var(--accent); outline-offset:-3px;
border-radius:6px; }
#sessions li.group .chev { width:9px; flex:0 0 9px; }
#sessions li.group .gcount { color:var(--dim); opacity:.7; letter-spacing:.06em; }
#sessions li.group > button.here .chev { color:var(--accent); }
#sessions li.group > button.here .gname { color:var(--accent); }
#sessions li.session[data-archived="1"] .name { color:var(--dim); }
#archtoggle { display:flex; align-items:center; gap:6px; margin:0 10px 6px; color:var(--dim);
font:11px/1.4 ui-monospace, monospace; cursor:pointer; }
#archtoggle input { margin:0; accent-color:var(--accent); }
#plus { flex:0 0 auto; width:30px; height:30px; border-radius:50%; background:transparent;
border:1px solid var(--line); color:var(--dim); font:16px/1 inherit; cursor:pointer;
align-self:flex-end; margin-bottom:5px; }
#plus:hover, #plus[aria-expanded="true"] { color:var(--fg); border-color:var(--accent); }
.switchrow { display:flex; align-items:center; justify-content:space-between; gap:12px; width:100%; }
.switchrow .track { position:relative; flex:0 0 auto; width:30px; height:16px; border-radius:999px;
background:var(--line); transition:background .12s ease; }
.switchrow .track .knob { position:absolute; top:2px; left:2px; width:12px; height:12px;
border-radius:50%; background:var(--dim); transition:left .12s ease, background .12s ease; }
.switchrow[aria-checked="true"] .track { background:var(--accent); }
.switchrow[aria-checked="true"] .track .knob { left:16px; background:var(--bg); }
.switchrow .switchlabel { color:var(--fg); }
.switchrow.dim .switchlabel { color:var(--dim); }
.switchrow:disabled { cursor:default; }
.switchrow:disabled .track { opacity:.45; }
#attachmenu { position:absolute; bottom:calc(100% + 8px); left:0; z-index:20; min-width:300px;
background:var(--bg); border:1px solid var(--line); border-radius:10px; padding:6px;
box-shadow:0 16px 40px rgba(0,0,0,.5); display:flex; flex-direction:column; gap:2px; }
#attachmenu[hidden] { display:none; }
#attachmenu button { display:flex; flex-direction:column; gap:1px; align-items:flex-start;
background:transparent; border:0; border-radius:6px; padding:7px 10px; cursor:pointer;
color:var(--fg); font:inherit; font-size:13px; text-align:left; }
#attachmenu button span { color:var(--dim); font-size:11.5px; }
#attachmenu button:hover:not(:disabled), #attachmenu button:focus-visible { background:var(--hover); }
#attachmenu button:disabled { color:var(--faint); cursor:default; }
#attachmenu button:disabled b { color:var(--faint); }
#attached { display:flex; gap:8px; flex-wrap:wrap; padding:6px 20px 0; }
#attached[hidden] { display:none; }
#attached .chip { display:inline-flex; align-items:center; gap:8px; background:var(--panel);
border:1px solid var(--line); border-radius:999px; padding:3px 4px 3px 10px;
font:11.5px/1.4 ui-monospace, monospace; color:var(--fg); }
#attached .chip .x { width:18px; height:18px; border-radius:50%; border:0; background:transparent;
color:var(--dim); cursor:pointer; font:12px/1 inherit; }
#attached .chip .x:hover { color:var(--bad); }
#composer { position:relative; }
#find { margin:0 10px 6px; padding:6px 8px; background:var(--bg); color:var(--fg); border:1px solid var(--line); border-radius:6px; font:12px/1.4 inherit; }
#findinfo { color:var(--dim); font-size:11px; padding:0 10px 6px; min-height:14px; }
main { flex:1; display:flex; flex-direction:column; min-width:0; }
#notice { position:relative; display:flex; justify-content:flex-end; padding:8px 20px 0; }
#notice[hidden] { display:none; }
#updatebadge { background:transparent; border:1px solid var(--line); border-radius:999px;
color:var(--warn); font:12px/1.4 ui-monospace, monospace; padding:2px 10px; cursor:pointer; }
#updatebadge:hover, #updatebadge[aria-expanded="true"] { border-color:var(--warn); }
#updatepop { position:absolute; right:20px; top:32px; z-index:5; width:min(340px, 86vw);
background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:12px 14px;
box-shadow:0 10px 30px rgba(0,0,0,.45); }
#updatepop[hidden] { display:none; }
#updatepop p { margin:0 0 8px; }
#updatepop code { display:block; font:12px/1.5 ui-monospace, monospace; background:var(--bg);
border:1px solid var(--line); border-radius:4px; padding:5px 8px; margin-bottom:6px; }
#updatepop .why { color:var(--dim); font-size:12px; margin:8px 0 0; }
#log { flex:1; overflow-y:auto; padding:20px; }
.msg { margin:0 0 14px; white-space:pre-wrap; overflow-wrap:anywhere; }
.msg img.sent { display:block; margin-top:8px; max-width:100%; max-height:340px;
border:1px solid var(--line); border-radius:8px; }
.msg.user { background:var(--panel); border-left:3px solid var(--user); border-radius:0 8px 8px 0; padding:10px 14px; }
.msg.command { font:12px/1.5 ui-monospace, monospace; color:var(--dim); padding:2px 0; }
.msg.assistant { padding:2px 0; }
.msg.tool { font:12px/1.4 ui-monospace, monospace; color:var(--dim); border-left:3px solid var(--line); border-radius:0; padding:4px 10px; }
.msg.approval { border:1px solid var(--accent); background:var(--panel); border-radius:8px; padding:10px 14px; }
.msg.approval .meta { color:var(--dim); font-size:12px; margin-top:4px; }
.msg.approval .actions { margin-top:8px; display:flex; gap:8px; }
.msg.approval button { border:1px solid var(--line); border-radius:6px; padding:4px 14px; cursor:pointer; color:var(--fg); background:transparent; }
.msg.approval button.yes { background:var(--accent); color:var(--ink); border:0; font-weight:600; }
.msg.error { color:var(--bad); border:1px solid var(--bad); border-radius:8px; padding:10px 14px; }
.msg.notice { font:12px/1.55 ui-monospace, monospace; color:var(--fg); background:transparent;
border-left:3px solid var(--accent); border-radius:0; padding:6px 10px; white-space:pre-wrap;
overflow-wrap:anywhere; }
.msg.notice.refusal { color:var(--bad); border-left-color:var(--bad); }
details.msg { padding:0; }
details.msg.user.big { background:var(--panel); border-left:3px solid var(--user); border-radius:0 8px 8px 0; }
details.msg.user.big > summary { color:var(--dim); font:12px/1.5 ui-monospace, monospace; padding:8px 14px; }
details.msg.user.big > summary:hover { color:var(--fg); }
details.msg.user.big .pasted { padding:0 14px 10px; white-space:pre-wrap; overflow-wrap:anywhere;
max-height:60vh; overflow-y:auto; }
details.msg > summary { cursor:pointer; padding:6px 12px; list-style:none; }
details.msg > summary::-webkit-details-marker { display:none; }
details.msg > summary::marker { content:''; }
details.msg > summary:hover { color:var(--fg); }
details.reasoning { font-size:13px; font-style:italic; color:var(--dim); border-left:3px solid var(--rule); border-radius:0; }
details.reasoning > summary { font-style:normal; }
details.reasoning .think { padding:0 12px 8px; white-space:pre-wrap; overflow-wrap:anywhere; }
details.tool { font:12px/1.4 ui-monospace, monospace; color:var(--dim); border-left:3px solid var(--rule); border-radius:0; }
details.tool > summary { overflow-wrap:anywhere; }
details.tool .mark { margin-right:6px; }
details.tool.running .mark, details.tool.refused .mark { color:var(--warn); }
details.tool.ok .mark { color:var(--ok); }
details.tool.failed .mark { color:var(--bad); }
details.tool.failed > summary { color:var(--bad); }
details.tool .cap { color:var(--dim); font-size:10px; letter-spacing:.1em; text-transform:uppercase; padding:0 12px 2px; }
details.tool .args, details.tool .out { margin:0; padding:0 12px 8px; color:var(--fg); font-size:11px; white-space:pre-wrap; overflow-wrap:anywhere; }
details.tool .out { color:var(--dim); }
#thinkbar { padding:8px 20px 0; }
#thinkbar[hidden] { display:none; }
#thinkall { background:transparent; border:1px solid var(--line); border-radius:999px;
color:var(--dim); font:11px/1.4 ui-monospace, monospace; padding:1px 9px; cursor:pointer; }
#thinkall:hover { color:var(--fg); border-color:var(--dim); }
.msg.composing { opacity:.7; }
#form { display:flex; flex-direction:column; gap:8px; padding:14px 20px; border-top:1px solid var(--line); width:100%; }
#composer { display:flex; gap:8px; align-items:flex-start; }
#pastes { display:flex; flex-wrap:wrap; gap:6px; }
#pastes[hidden] { display:none; }
.paste { display:inline-flex; align-items:center; gap:6px; background:var(--panel); color:var(--dim);
border:1px solid var(--line); border-radius:999px; padding:2px 10px;
font:11px/1.6 ui-monospace, monospace; cursor:pointer; }
.paste:hover { color:var(--fg); border-color:var(--bad); }
.paste .x { color:var(--faint); }
textarea { flex:1; resize:none; background:var(--panel); color:var(--fg); border:1px solid var(--line); border-radius:8px; padding:10px; font:inherit; }
button.go { align-self:center; height:34px; min-width:74px; padding:0 16px; border-radius:8px;
background:var(--accent); color:var(--ink); border:0; font-weight:600; cursor:pointer; }
button.go.stop { background:transparent; color:var(--dim); border:1px solid var(--line); }
button.go.stop:hover { color:var(--fg); border-color:var(--bad); }
button.go[data-state="starting"] { color:var(--dim); }
button:disabled { opacity:.5; cursor:default; }
#status { color:var(--dim); font-size:12px; text-align:center; padding-bottom:8px; }
#open { display:flex; gap:10px; align-items:baseline; padding:2px 20px 8px; font-size:13px; color:var(--fg); }
#open[hidden] { display:none; }
#openname { font-weight:600; overflow-wrap:anywhere; }
#openid { color:var(--faint); font:11px/1.4 ui-monospace, monospace; }
#stats { font:12px/1.4 ui-monospace, monospace; color:var(--dim); padding:6px 20px 0; text-align:center; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
#stats.last { opacity:.72; }
#cron, #bots { display:block; width:100%; margin:0 0 8px; background:transparent; color:var(--dim);
border:1px solid var(--line); border-radius:8px; padding:5px 0; cursor:pointer; }
#cron:hover, #cron.on, #bots:hover, #bots.on { color:var(--fg); border-color:var(--accent); }
main.cron #log, main.cron #stats, main.cron #status, main.cron #form,
main.cron #thinkbar, main.cron #notice, main.cron #open { display:none; }
#cronpane { display:none; flex:1; overflow-y:auto; padding:16px 20px; }
main.cron #cronpane { display:block; }
#cronpane h2 { font-size:15px; margin:0 0 2px; font-weight:600; }
#cronpane header { display:flex; align-items:baseline; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
#cronpane header small { color:var(--dim); font:11px ui-monospace, monospace; overflow-wrap:anywhere; }
#cronpane header .grow { flex:1; }
#cronpane button { background:transparent; color:var(--dim); border:1px solid var(--line);
border-radius:6px; padding:3px 9px; cursor:pointer; font:12px/1.4 inherit; }
#cronpane button:hover:not(:disabled) { color:var(--fg); border-color:var(--accent); }
#cronpane button:disabled { opacity:.45; cursor:default; }
#cronpane button.go { color:var(--accent); }
#cronpane button.bad:hover { color:var(--bad); border-color:var(--bad); }
#crontable { width:100%; border-collapse:collapse; font-size:13px; }
#crontable th { text-align:left; color:var(--dim); font-weight:normal; font-size:11px;
text-transform:uppercase; letter-spacing:.06em; border-bottom:1px solid var(--rule); padding:4px 8px 4px 0; }
#crontable td { border-bottom:1px solid var(--line); padding:6px 8px 6px 0; vertical-align:top; }
#crontable td.name { font-family:ui-monospace, monospace; color:var(--accent); overflow-wrap:anywhere; }
#crontable td.when { color:var(--dim); white-space:nowrap; }
#crontable td.acts { text-align:right; white-space:nowrap; }
#crontable td.acts button { margin-left:4px; padding:2px 7px; }
#crontable tr.off td.name, #crontable tr.off td.when { color:var(--dim); text-decoration:line-through; }
#crontable td.last.ok { color:var(--ok); }
#crontable td.last.failed { color:var(--bad); }
#cronmsg { font-size:12px; min-height:1.2em; margin:0 0 10px; color:var(--dim); }
#cronmsg.bad { color:var(--bad); }
#cronform { border:1px solid var(--line); border-radius:8px; padding:12px; margin:14px 0; }
#cronform label { display:block; color:var(--dim); font-size:12px; margin-bottom:8px; }
#cronform input, #cronform textarea { display:block; width:100%; margin-top:3px; background:var(--bg);
color:var(--fg); border:1px solid var(--line); border-radius:6px; padding:5px 8px;
font:13px/1.5 ui-monospace, monospace; }
#cronform input:focus, #cronform textarea:focus { outline:1px solid var(--accent); }
#cronform .row { display:flex; gap:8px; margin-top:8px; }
#cronlogs { margin-top:16px; }
#cronlogs h3 { font-size:13px; margin:0 0 6px; }
#cronlogs article { border-left:2px solid var(--line); padding:2px 0 2px 10px; margin-bottom:10px; }
#cronlogs .at { color:var(--dim); font:11px ui-monospace, monospace; }
#cronlogs pre { margin:4px 0 0; white-space:pre-wrap; overflow-wrap:anywhere;
font:12px/1.5 ui-monospace, monospace; color:var(--fg); }
#cronlogs .more { color:var(--warn); font-size:11px; }
#mcp { display:block; width:100%; margin:0 0 8px; background:transparent; color:var(--dim);
border:1px solid var(--line); border-radius:8px; padding:5px 0; cursor:pointer; }
#mcp:hover, #mcp.on { color:var(--fg); border-color:var(--accent); }
main.mcp #log, main.mcp #stats, main.mcp #status, main.mcp #form,
main.mcp #thinkbar, main.mcp #notice, main.mcp #open { display:none; }
#mcppane { display:none; flex:1; overflow-y:auto; padding:16px 20px; }
main.mcp #mcppane { display:block; }
#mcppane h2 { font-size:15px; margin:0 0 2px; font-weight:600; }
#mcppane header { display:flex; align-items:baseline; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
#mcppane header small { color:var(--dim); font:11px ui-monospace, monospace; overflow-wrap:anywhere; }
#mcppane header .grow { flex:1; }
#mcppane button { background:transparent; color:var(--dim); border:1px solid var(--line);
border-radius:6px; padding:3px 9px; cursor:pointer; font:12px/1.4 inherit; }
#mcppane button:hover:not(:disabled) { color:var(--fg); border-color:var(--accent); }
#mcppane button:disabled { opacity:.45; cursor:default; }
#mcppane button.go { color:var(--accent); }
#mcppane button.bad:hover { color:var(--bad); border-color:var(--bad); }
#mcptable { width:100%; border-collapse:collapse; font-size:13px; }
#mcptable th { text-align:left; color:var(--dim); font-weight:normal; font-size:11px;
text-transform:uppercase; letter-spacing:.06em; border-bottom:1px solid var(--rule); padding:4px 8px 4px 0; }
#mcptable td { border-bottom:1px solid var(--line); padding:6px 8px 6px 0; vertical-align:top; }
#mcptable td.name { font-family:ui-monospace, monospace; color:var(--accent); overflow-wrap:anywhere; }
#mcptable td.when { color:var(--dim); white-space:nowrap; }
#mcptable td.cmd { font-family:ui-monospace, monospace; overflow-wrap:anywhere; color:var(--dim); }
#mcptable td.acts { text-align:right; white-space:nowrap; }
#mcptable td.acts button { margin-left:4px; padding:2px 7px; }
#mcptable tr.off td.name, #mcptable tr.off td.when { color:var(--dim); text-decoration:line-through; }
#mcptable td.state.ok { color:var(--ok); }
#mcptable td.state.failed { color:var(--bad); }
#mcptable td.token { color:var(--dim); font-family:ui-monospace, monospace; }
#mcptable td.token.unset { color:var(--bad); }
#mcpform .editing { color:var(--accent); font-size:12px; margin:0 0 8px; }
#mcpform .editing:empty { display:none; }
#mcpmsg { font-size:12px; min-height:1.2em; margin:0 0 10px; color:var(--dim); }
#mcpmsg.bad { color:var(--bad); }
#mcpform { border:1px solid var(--line); border-radius:8px; padding:12px; margin:14px 0; }
#mcpform label { display:block; color:var(--dim); font-size:12px; margin-bottom:8px; }
#mcpform input, #mcpform select { display:block; width:100%; margin-top:3px; background:var(--bg);
color:var(--fg); border:1px solid var(--line); border-radius:6px; padding:5px 8px;
font:13px/1.5 ui-monospace, monospace; }
#mcpform input:focus, #mcpform select:focus { outline:1px solid var(--accent); }
#mcpform .row { display:flex; gap:8px; margin-top:8px; }
#problems { display:block; width:100%; margin:0 0 8px; background:transparent; color:var(--dim);
border:1px solid var(--line); border-radius:8px; padding:5px 0; cursor:pointer; }
#problems:hover, #problems.on { color:var(--fg); border-color:var(--accent); }
#problems.has { color:var(--warn); border-color:var(--warn); }
main.problems #log, main.problems #stats, main.problems #status, main.problems #form,
main.problems #thinkbar, main.problems #notice, main.problems #open { display:none; }
#problemspane { display:none; flex:1; overflow-y:auto; padding:16px 20px; }
main.problems #problemspane { display:block; }
#problemspane h2 { font-size:15px; margin:0 0 2px; font-weight:600; }
#problemspane header { display:flex; align-items:baseline; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
#problemspane header small { color:var(--dim); font:11px ui-monospace, monospace; overflow-wrap:anywhere; }
#problemspane header .grow { flex:1; }
#problemspane button { background:transparent; color:var(--dim); border:1px solid var(--line);
border-radius:6px; padding:3px 9px; cursor:pointer; font:12px/1.4 inherit; }
#problemspane button:hover { color:var(--fg); border-color:var(--accent); }
#problemsmsg { font-size:12px; min-height:1.2em; margin:0 0 10px; color:var(--dim); }
#problemsmsg.bad { color:var(--bad); }
#problemstable { width:100%; border-collapse:collapse; font-size:13px; }
#problemstable th { text-align:left; color:var(--dim); font-weight:normal; font-size:11px;
text-transform:uppercase; letter-spacing:.06em; border-bottom:1px solid var(--rule); padding:4px 8px 4px 0; }
#problemstable td { border-bottom:1px solid var(--line); padding:6px 8px 6px 0; vertical-align:top; }
#problemstable td.kind { color:var(--warn); white-space:nowrap; font-family:ui-monospace, monospace; }
#problemstable td.what { overflow-wrap:anywhere; }
#problemstable td.path { color:var(--dim); font:11px ui-monospace, monospace; overflow-wrap:anywhere; }
#problemstable td.none { color:var(--ok); }
#problemschecked { color:var(--dim); font:11px ui-monospace, monospace; white-space:pre-wrap;
margin-top:14px; overflow-wrap:anywhere; }
main.bots #log, main.bots #stats, main.bots #status, main.bots #form,
main.bots #thinkbar, main.bots #notice, main.bots #open { display:none; }
#botspane { display:none; flex:1; overflow-y:auto; padding:16px 20px; }
main.bots #botspane { display:block; }
#botspane h2 { font-size:15px; margin:0 0 2px; font-weight:600; }
#botspane header { display:flex; align-items:baseline; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
#botspane header small { color:var(--dim); font:11px ui-monospace, monospace; overflow-wrap:anywhere; }
#botspane header .grow { flex:1; }
#botspane button { background:transparent; color:var(--dim); border:1px solid var(--line);
border-radius:4px; padding:3px 9px; cursor:pointer; font-size:11px; font-family:inherit; }
#botspane button:hover:not(:disabled) { color:var(--fg); border-color:var(--accent); }
#botspane button.go { color:var(--accent); }
#botspane button.bad:hover { color:var(--bad); border-color:var(--bad); }
#botstable { width:100%; border-collapse:collapse; font-size:12px; }
#botstable th { text-align:left; color:var(--dim); font-weight:600; font-size:10px;
text-transform:uppercase; letter-spacing:.06em; border-bottom:1px solid var(--rule); padding:4px 8px 4px 0; }
#botstable td { border-bottom:1px solid var(--line); padding:6px 8px 6px 0; vertical-align:top; }
#botstable td.name { color:var(--fg); font-weight:600; white-space:nowrap; }
#botstable td.acts { white-space:nowrap; text-align:right; }
#botstable td.acts button { margin-left:4px; }
#botsmsg { color:var(--dim); font-size:12px; min-height:16px; margin-bottom:8px; }
#botsmsg.bad { color:var(--bad); }
#botsprompt { margin-top:16px; border-top:1px solid var(--rule); padding-top:12px; }
#botsprompt h3 { font-size:12px; margin:0 0 6px; color:var(--dim); font-weight:600; }
#botsprompt pre { white-space:pre-wrap; overflow-wrap:anywhere; font:11px/1.5 ui-monospace, monospace;
color:var(--fg); background:var(--panel); border:1px solid var(--line); border-radius:4px; padding:10px; }
main.flares #log, main.flares #stats, main.flares #status, main.flares #form,
main.flares #thinkbar, main.flares #notice, main.flares #open { display:none; }
#flarespane { display:none; flex:1; overflow-y:auto; padding:16px 20px; }
main.flares #flarespane { display:block; }
#flarespane h2 { font-size:15px; margin:0 0 2px; font-weight:600; }
#flarespane header { display:flex; align-items:baseline; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
#flarespane header small { color:var(--dim); font:11px ui-monospace, monospace; }
#flarespane header .grow { flex:1; }
#flarespane button { background:transparent; color:var(--dim); border:1px solid var(--line);
border-radius:4px; padding:3px 9px; cursor:pointer; font-size:11px; font-family:inherit; }
#flarespane button:hover:not(:disabled) { color:var(--fg); border-color:var(--accent); }
#flarespane button:disabled { opacity:.5; cursor:default; }
#flarespane button.go { color:var(--accent); }
#flarespane button.bad:hover { color:var(--bad); border-color:var(--bad); }
#flaresmsg { color:var(--dim); font-size:12px; min-height:16px; margin-bottom:8px; }
#flaresmsg.bad { color:var(--bad); }
#flaretable { width:100%; border-collapse:collapse; font-size:12px; }
#flaretable th { text-align:left; color:var(--dim); font-weight:600; font-size:10px;
text-transform:uppercase; letter-spacing:.06em; border-bottom:1px solid var(--rule); padding:4px 8px 4px 0; }
#flaretable td { border-bottom:1px solid var(--line); padding:6px 8px 6px 0; vertical-align:top; }
#flaretable td.run { color:var(--fg); font-family:ui-monospace, monospace; white-space:nowrap; }
#flaretable td.run .task { display:block; color:var(--dim); font-family:inherit; font-weight:normal;
font-size:11px; max-width:46ch; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
#flaretable td.state { white-space:nowrap; font-family:ui-monospace, monospace; }
#flaretable td.state.done { color:var(--ok); }
#flaretable td.state.running { color:var(--accent); }
#flaretable td.state.failed, #flaretable td.state.cancelled { color:var(--warn); }
#flaretable td.age, #flaretable td.jobs { white-space:nowrap; color:var(--dim); }
#flaretable td.routes { color:var(--dim); font-family:ui-monospace, monospace; font-size:11px;
overflow-wrap:anywhere; }
#flaretable td.cost { color:var(--dim); font-family:ui-monospace, monospace; font-size:11px;
white-space:nowrap; }
#flaretable td.acts { text-align:right; white-space:nowrap; }
#flaretable td.acts button { margin-left:4px; }
#flaretable tr.jobs td { background:var(--panel); padding:8px 8px 10px 18px; }
#flaretable tr.jobs .job { display:flex; align-items:baseline; gap:8px; flex-wrap:wrap; padding:3px 0; }
#flaretable tr.jobs .job .n { width:2.5ch; color:var(--faint); font-family:ui-monospace, monospace; }
#flaretable tr.jobs .job .state { font-family:ui-monospace, monospace; }
#flaretable tr.jobs .job .state.done { color:var(--ok); }
#flaretable tr.jobs .job .state.running { color:var(--accent); }
#flaretable tr.jobs .job .state.failed { color:var(--bad); }
#flaretable tr.jobs .job .state.dropped { color:var(--warn); }
#flaretable tr.jobs .job .route { color:var(--dim); font-family:ui-monospace, monospace; font-size:11px; }
#flaretable tr.jobs .job small { color:var(--dim); font:11px ui-monospace, monospace; }
#flaretable tr.jobs .job small.why { color:var(--warn); overflow-wrap:anywhere; }
#flaretable tr.jobs .empty { color:var(--dim); font-size:12px; }
</style>
</head>
<body>
<aside>
<h1><img id="mark" src="/logo.svg" alt="" aria-hidden="true" width="22" height="22">eclipse
<small class="version">v{{VERSION}}</small></h1>
<button id="new">+ New session</button>
<input id="find" type="search" placeholder="find in transcripts…" autocomplete="off"
aria-label="search the transcripts">
<div id="findinfo"></div>
<label id="archtoggle" title="sessions filed away: out of the list, still in the find box">
<input id="showarchived" type="checkbox"> show archived
</label>
<ul id="sessions">{{SESSIONS}}</ul>
{{BOTS_BUTTON}}
{{FLARES_BUTTON}}
<button id="settings" type="button" aria-expanded="false"
title="every key this build reads, as the file says it">settings</button>
<dialog id="settingswindow" aria-label="settings">
<header>
<h2>settings</h2>
<small id="setpath"></small>
<span class="grow"></span>
<input id="setfind" type="search" placeholder="filter keys and their descriptions…"
autocomplete="off" aria-label="filter the settings">
<button type="button" id="setclose" aria-label="close settings">×</button>
</header>
<div id="setbody">
<nav id="setsections" aria-label="sections"></nav>
<div id="setrows"></div>
</div>
<div id="setnote"></div>
</dialog>
<button id="cron" type="button" aria-expanded="false"
title="the jobs the timer runs — the same ones `eclipse cron` shows">scheduled jobs</button>
<button id="mcp" type="button" aria-expanded="false"
title="the MCP servers — the same ones `eclipse mcp list` shows">mcp servers</button>
<button id="problems" type="button" aria-expanded="false"
title="what the loaders complained about — the same warnings the CLI prints">problems</button>
<form id="logout"><button type="submit">Sign out</button></form>
</aside>
<main>
<div id="thinkbar" hidden>
<button id="thinkall" type="button" title="every reasoning block in this transcript">expand all thinking</button>
</div>
<div id="notice" hidden>
<button id="updatebadge" type="button" aria-expanded="false" aria-controls="updatepop"
title="this install is behind the newest release — click for the two commands">
<span id="updatetext"></span>
</button>
<div id="updatepop" hidden role="dialog" aria-label="how to update">
<p><strong>Update available.</strong></p>
<code>eclipse upgrade</code>
<code>eclipse gateway restart</code>
<p class="why">In that order: the upgrade installs the new build, and the restart is what
makes this dashboard run it. A restart alone upgrades nothing; an upgrade alone leaves the
process you are reading this in on the old binary.</p>
</div>
</div>
<div id="open" hidden><span id="openname"></span><small id="openid"></small></div>
{{BOTS_PANE}}
{{FLARES_PANE}}
<section id="cronpane" hidden aria-label="scheduled jobs">
<header>
<h2>scheduled jobs</h2>
<small id="cronfile"></small>
<span class="grow"></span>
<button id="cronnew" type="button">+ new job</button>
<button id="cronrefresh" type="button">refresh</button>
</header>
<div id="cronmsg"></div>
<table id="crontable">
<thead><tr><th>job</th><th>schedule</th><th>next</th><th>last</th><th></th></tr></thead>
<tbody id="cronrows"></tbody>
</table>
<form id="cronform" hidden>
<label>name
<input id="cr-name" autocomplete="off" spellcheck="false" placeholder="brief">
</label>
<label>schedule
<input id="cr-schedule" autocomplete="off" spellcheck="false"
placeholder="every 30m · hourly · daily 07:30 · weekly mon 09:00">
</label>
<label>prompt
<textarea id="cr-prompt" rows="3" placeholder="what to ask when it fires"></textarea>
</label>
<label>workdir (optional)
<input id="cr-workdir" autocomplete="off" spellcheck="false" placeholder="~/notes">
</label>
<div class="row">
<button type="submit" class="go" id="cronsave">save</button>
<button type="button" id="croncancel">cancel</button>
<span id="cronediting"></span>
</div>
</form>
<div id="cronlogs" hidden></div>
</section>
<section id="problemspane" hidden aria-label="problems">
<header>
<h2>problems</h2>
<small id="problemssummary"></small>
<span class="grow"></span>
<button id="problemsrefresh" type="button">refresh</button>
</header>
<div id="problemsmsg"></div>
<table id="problemstable">
<thead><tr><th>from</th><th>what</th><th>where</th></tr></thead>
<tbody id="problemsrows"></tbody>
</table>
<div id="problemschecked"></div>
</section>
<section id="mcppane" hidden aria-label="mcp servers">
<header>
<h2>mcp servers</h2>
<small id="mcpfile"></small>
<span class="grow"></span>
<button id="mcpnew" type="button">+ add server</button>
<button id="mcprefresh" type="button">refresh</button>
</header>
<div id="mcpmsg"></div>
<table id="mcptable">
<thead><tr><th>name</th><th>source</th><th>tools</th><th>command</th><th>token</th><th>state</th><th></th></tr></thead>
<tbody id="mcprows"></tbody>
</table>
<form id="mcpform" hidden>
<div class="editing" id="mpediting"></div>
<label>name
<input id="mp-name" autocomplete="off" spellcheck="false" placeholder="fs">
</label>
<label>transport
<select id="mp-transport">
<option value="">auto — a url means http, a command means stdio</option>
<option value="stdio">stdio — a process this build starts</option>
<option value="http">http — an endpoint this build posts to</option>
</select>
</label>
<label>url (http)
<input id="mp-url" autocomplete="off" spellcheck="false"
placeholder="http://127.0.0.1:18811/api/mcp">
</label>
<label>command (stdio)
<input id="mp-command" autocomplete="off" spellcheck="false" placeholder="npx">
</label>
<label>args (stdio, space-separated)
<input id="mp-args" autocomplete="off" spellcheck="false"
placeholder="-y @modelcontextprotocol/server-filesystem /srv/data">
</label>
<label>token_env (http — the <em>name</em> of a variable holding the token, never the token)
<input id="mp-token" autocomplete="off" spellcheck="false" placeholder="HA_TOKEN">
</label>
<label>prefix (optional)
<input id="mp-prefix" autocomplete="off" spellcheck="false" placeholder="fs_">
</label>
<label>policy
<select id="mp-policy">
<option value="">ask — approve every call (the default)</option>
<option value="allow">allow — run without asking</option>
<option value="deny">deny — never run</option>
</select>
</label>
<div class="row">
<button type="submit" class="go" id="mcpsave">save</button>
<button type="button" id="mcpcancel">cancel</button>
</div>
</form>
</section>
<div id="log"></div>
<div id="statsrow">
<div id="stats" title="the same numbers the CLI prints above its prompt">ctx -- · first -- · wall -- · ↑-- t/s · ⚡--</div>
<span id="yolo" {{YOLO_ATTR}} title="{{YOLO_DETAIL}}">yolo</span>
<span id="judge" {{JUDGE_ATTR}} title="`[cli] approval = "smart"`: a cheap model rules allow, deny or escalate on each call that would have been a card, and only escalate asks you">judged</span>
<button id="jump" type="button" hidden title="the newest line — this pane stops following when you scroll up"></button>
<span id="effort" class="{{EFFORT_CLASS}}" data-label="{{EFFORT}}" title="{{EFFORT_DETAIL}}">effort {{EFFORT}}</span>
<button id="model" type="button" aria-expanded="false" aria-haspopup="menu" aria-controls="models"
title="the model the next turn uses — click to switch">{{MODEL}}</button>
<div id="models" hidden role="menu" aria-label="model">
<div id="modellist"></div>
<div id="modelsub" hidden></div>
<div id="modelnote"></div>
</div>
</div>
<div id="status">{{STATUS}}</div>
<form id="form" data-paste-limit="{{PASTE_LIMIT}}">
<div id="pastes" hidden></div>
<div id="attached" hidden></div>
<div id="composer">
<div id="cmdmenu" role="listbox" aria-label="Commands" hidden></div>
<button id="plus" type="button" aria-haspopup="menu" aria-expanded="false"
aria-label="Attach a file, a path or a link" title="attach: file, path or link">+</button>
<div id="attachmenu" role="menu" aria-label="Attach" hidden>
<button type="button" role="menuitem" data-attach="file"><b>file…</b><span>read here, sent with the turn</span></button>
<button type="button" role="menuitem" data-attach="path"><b>path…</b><span>a file on this machine: the agent reads it</span></button>
<button type="button" role="menuitem" data-attach="url"><b>link…</b><span>a page: the agent fetches it</span></button>
<button type="button" role="menuitem" data-attach="image"
title="a picture, read here and sent with the turn"><b>image…</b><span>a picture: read here, sent with the turn</span></button>
<button type="button" role="menuitem" data-attach="audio" disabled
title="there is no transcription endpoint yet"><b>audio</b><span>needs a transcription endpoint</span></button>
</div>
<input id="attachfile" type="file" hidden>
<input id="attachpicture" type="file" accept="image/png,image/jpeg,image/webp,image/gif" hidden>
<textarea id="input" rows="2" placeholder="Message (Enter to send, Shift+Enter for newline)" autofocus></textarea>
<button class="go" id="go" type="button" data-state="idle" aria-label="Send">Send</button>
</div>
</form>
</main>
<script>
(() => {
const CSRF = (document.querySelector('meta[name=csrf]') || {}).content || '';
const post = (url, body) => fetch(url, {
method: 'POST',
headers: body === undefined
? { 'X-Eclipse-CSRF': CSRF }
: { 'X-Eclipse-CSRF': CSRF, 'content-type': 'application/json' },
body: body === undefined ? undefined : JSON.stringify(body),
});
const log = document.getElementById('log');
const input = document.getElementById('input');
const cmdmenu = document.getElementById('cmdmenu');
const go = document.getElementById('go');
const status = document.getElementById('status');
const list = document.getElementById('sessions');
const showarchived = document.getElementById('showarchived');
const openbar = document.getElementById('open');
const openname = document.getElementById('openname');
const openid = document.getElementById('openid');
const stats = document.getElementById('stats');
const yoloChip = document.getElementById('yolo');
function paintYolo(on) { yoloChip.hidden = !on; }
const effortEl = document.getElementById('effort');
const EFFORT0 = effortEl.dataset.label;
const EFFORT_DETAIL0 = effortEl.title;
let effortLabel = EFFORT0;
let sessionId = null;
let runId = null; let master = [];
function setGo(state) {
go.dataset.state = state;
go.classList.toggle('stop', state === 'stop');
go.textContent = state === 'idle' ? 'Send' : state === 'starting' ? 'Starting…' : 'Stop';
go.setAttribute('aria-label',
state === 'idle' ? 'Send'
: state === 'starting' ? 'Starting — nothing to stop yet'
: 'Stop the run in flight');
go.disabled = state === 'starting';
}
let busy = false;
let live = null; let deferredLine = null; let thinking = null; let composing = null;
function endBlocks() {
thinking = null;
composing = null;
live = null;
}
const JUMP_SLACK = 24; const jump = document.getElementById('jump');
const pendingApprovals = new Map();
const outcomes = { approved: 'Approved', denied: 'Denied', timeout: 'No answer: declined', cancelled: 'Cancelled' };
let pinned = true; let unseen = 0;
function atBottom() {
return log.scrollHeight - log.scrollTop - log.clientHeight <= JUMP_SLACK;
}
function pin() {
log.scrollTop = log.scrollHeight;
unseen = 0;
}
function paintJump() {
const away = !atBottom();
jump.hidden = !away;
if (!away) return;
const cards = pendingApprovals.size;
jump.classList.toggle('card', cards > 0);
jump.textContent = cards > 0
? '↓ ' + cards + (cards === 1 ? ' approval' : ' approvals')
: unseen > 0 ? '↓ ' + unseen + ' newer' : '↓ bottom';
}
function follow() {
if (pinned) pin();
else unseen += 1;
paintJump();
}
log.addEventListener('scroll', () => {
pinned = atBottom();
if (pinned) unseen = 0;
paintJump();
}, { passive: true });
jump.addEventListener('click', () => {
pinned = true;
pin();
paintJump();
input.focus();
});
function add(kind, text) {
const el = document.createElement('div');
el.className = 'msg ' + kind;
el.textContent = text;
log.appendChild(el);
follow();
return el;
}
const PASTE_FOLD_LINES = 6;
function userMessage(text) {
const lines = text.replace(/\n+$/, '').split('\n').length;
const chars = Array.from(text).length;
if (lines <= PASTE_FOLD_LINES && chars <= PASTE_LIMIT) return add('user', text);
const d = document.createElement('details');
d.className = 'msg user big';
const sum = document.createElement('summary');
sum.textContent = lines + ' lines · ' + chars + ' chars — click to read';
const body = document.createElement('div');
body.className = 'pasted';
body.textContent = text;
d.appendChild(sum);
d.appendChild(body);
log.appendChild(d);
follow();
return d;
}
const thinkBar = document.getElementById('thinkbar');
const thinkAll = document.getElementById('thinkall');
function thinkingBlocks() {
return Array.from(log.querySelectorAll('details.reasoning'));
}
function noteThinking() {
thinkBar.hidden = thinkingBlocks().length === 0;
}
function clearLog() {
log.textContent = '';
noteThinking();
pinned = true;
pin();
paintJump();
}
function thinkingHeader(body) {
const text = body.textContent;
const n = text ? text.split('\n').length : 0;
body.parentElement.querySelector('summary').textContent =
'💭 Thinking · ' + n + (n === 1 ? ' line' : ' lines');
}
function addThinking(text) {
const el = document.createElement('details');
el.className = 'msg reasoning';
const summary = document.createElement('summary');
const body = document.createElement('div');
body.className = 'think';
body.textContent = text || '';
el.append(summary, body);
log.appendChild(el);
thinkingHeader(body);
noteThinking();
follow();
return body;
}
const GLYPH = { running: '⏺', ok: '✓', refused: '⊘', failed: '✗' };
function addCall(name, args, summary, state, callId) {
const el = document.createElement('details');
el.className = 'msg tool call';
el.dataset.name = name;
if (callId) el.dataset.call = callId;
const line = document.createElement('summary');
const mark = document.createElement('span');
mark.className = 'mark';
line.append(mark, document.createTextNode('→ ' + (summary || (name + '(' + args + ')'))));
const body = document.createElement('pre');
body.className = 'args';
body.textContent = args;
el.append(line, body);
callState(el, state || 'running');
log.appendChild(el);
follow();
return el;
}
function callState(el, state) {
for (const known of Object.keys(GLYPH)) el.classList.remove(known);
el.classList.add(GLYPH[state] ? state : 'ok');
const mark = el.querySelector('summary .mark');
if (mark) mark.textContent = GLYPH[state] || GLYPH.ok;
}
function attachOutput(el, text) {
if (!el || text == null) return;
let out = el.querySelector('.out');
if (!out) {
const cap = document.createElement('div');
cap.className = 'cap';
cap.textContent = 'output';
out = document.createElement('pre');
out.className = 'out';
el.append(cap, out);
}
out.textContent = text;
}
function callRow(id, name) {
if (id) {
const exact = Array.from(log.querySelectorAll('details.tool')).find(el => el.dataset.call === id);
if (exact) return exact;
}
const rows = Array.from(log.querySelectorAll('details.tool'));
return rows.find(el => el.dataset.name === name && !el.querySelector('.out')) || null;
}
thinkAll.addEventListener('click', () => {
const blocks = thinkingBlocks();
const opening = blocks.some(d => !d.open);
for (const d of blocks) d.open = opening;
thinkAll.textContent = opening ? 'collapse all thinking' : 'expand all thinking';
});
const UNKNOWN = '--';
function tokens(n) {
if (typeof n !== 'number' || !isFinite(n) || n < 0) return UNKNOWN;
if (n < 1e3) return String(Math.round(n));
if (n < 1e6) { const v = n / 1e3; return (v < 100 ? v.toFixed(1) : v.toFixed(0)) + 'K'; }
const v = n / 1e6;
return (v < 100 ? v.toFixed(1) : v.toFixed(0)) + 'M';
}
function duration(ms) {
if (typeof ms !== 'number' || !isFinite(ms) || ms <= 0) return UNKNOWN;
if (ms < 1e4) return (ms / 1e3).toFixed(1) + 's';
if (ms < 6e4) return (ms / 1e3).toFixed(0) + 's';
if (ms < 3.6e6) {
const s = Math.floor(ms / 1e3);
return Math.floor(s / 60) + 'm' + String(s % 60).padStart(2, '0') + 's';
}
const m = Math.floor(ms / 6e4);
return Math.floor(m / 60) + 'h' + String(m % 60).padStart(2, '0') + 'm';
}
function statsLine(d) {
const ctx = d.ctx || 'ctx --';
const cache = (typeof d.cached_tokens !== 'number')
? '⚡' + UNKNOWN
: '⚡' + tokens(d.cached_tokens) +
(d.prompt_tokens > 0
? ' (' + Math.round(d.cached_tokens / d.prompt_tokens * 100) + '%)' : '');
const speed = (typeof d.tokens_per_sec === 'number' && isFinite(d.tokens_per_sec))
? d.tokens_per_sec.toFixed(0) : UNKNOWN;
return [
ctx,
'first ' + duration(d.ttft_ms),
'wall ' + duration(d.latency_ms),
'↑' + speed + ' t/s',
cache,
].join(' · ');
}
function setEffort(label, detail, session) {
effortLabel = label || EFFORT0;
effortEl.textContent = 'effort ' + effortLabel;
effortEl.title = detail || EFFORT_DETAIL0;
effortEl.classList.toggle('session', !!session);
}
const LIVE_TITLE = 'the same numbers the CLI prints above its prompt';
function ago(at) {
if (!at) return '';
const s = Math.max(0, Math.round((Date.now() - at) / 1000));
if (s < 45) return 'just now';
if (s < 5400) return Math.round(s / 60) + 'm ago';
if (s < 172800) return Math.round(s / 3600) + 'h ago';
return Math.round(s / 86400) + 'd ago';
}
function paintCost(cost) {
stats.classList.toggle('last', !!cost);
stats.title = cost
? 'the last turn in this session, ' + ago(cost.at_ms) + ' — send a message for the current one'
: LIVE_TITLE;
stats.textContent = cost
? statsLine(cost) + ' · ' + ago(cost.at_ms)
: statsLine({});
}
function paintLive(d) {
stats.classList.remove('last');
stats.title = LIVE_TITLE;
stats.textContent = statsLine(d);
}
function costOf(id) {
if (!id) return null;
for (const li of master) {
if (li.dataset.id !== id) continue;
try { return li.dataset.cost ? JSON.parse(li.dataset.cost) : null; }
catch (e) { return null; }
}
return null;
}
function clearStats() {
paintCost(costOf(sessionId));
}
function markActive() {
let parked = null;
for (const li of master) {
const mine = li.dataset.id === sessionId;
li.classList.toggle('active', mine);
if (mine && !li.isConnected) parked = li;
}
const here = parked ? sectionOf(parked) : null;
for (const btn of list.querySelectorAll('.grouptoggle')) {
btn.classList.toggle('here', here !== null && btn.dataset.section === here);
}
showOpen(parked);
}
const MARKS = /^\u2605 /;
function showOpen(parked) {
const row = parked || master.find(li => li.dataset.id === sessionId);
const name = row && row.querySelector('.name');
openbar.hidden = !sessionId;
openname.textContent = name ? name.textContent.replace(MARKS, '') : '';
openid.textContent = sessionId || '';
}
function labelOf(s) {
const child = s.subagent ? '[subagent · ' + s.subagent.route + '] ' : '';
return child + (s.title || s.preview || s.id);
}
function sessionRow(s) {
const li = document.createElement('li');
li.className = 'session';
li.dataset.id = s.id;
li.dataset.updated = String(s.updated_ms || Date.now());
li.dataset.pinned = s.pinned ? '1' : '0';
li.dataset.archived = s.archived ? '1' : '0';
li.dataset.cost = s.cost ? JSON.stringify(s.cost) : '';
const name = document.createElement('div');
name.className = 'name';
name.textContent = (s.pinned ? '★ ' : '') + labelOf(s);
const dots = document.createElement('button');
dots.type = 'button';
dots.className = 'dots';
dots.textContent = '⋮';
dots.title = 'pin, archive, rename, copy or delete this session';
dots.setAttribute('aria-haspopup', 'menu');
dots.setAttribute('aria-expanded', 'false');
const menu = document.createElement('div');
menu.className = 'menu';
menu.hidden = true;
menu.setAttribute('role', 'menu');
const item = (act, text, title, cls) => {
const b = document.createElement('button');
b.type = 'button';
b.dataset.act = act;
b.setAttribute('role', 'menuitem');
b.textContent = text;
b.title = title;
if (cls) b.className = cls;
menu.appendChild(b);
};
item(s.pinned ? 'unpin' : 'pin', s.pinned ? 'unpin' : 'pin',
s.pinned ? 'let a prune take this session again'
: 'keep this session first, and out of reach of every prune');
item(s.archived ? 'unarchive' : 'archive', s.archived ? 'unarchive' : 'archive',
s.archived ? 'put this session back in the list'
: 'file this session away — out of the list, still in the find box');
item('rename', 'rename', 'give this session a title');
item('copy', 'copy id', 'copy the id to the clipboard');
item('delete', 'delete', 'delete the transcript, its title and its memory', 'danger');
li.append(name, dots, menu);
return li;
}
function closeMenus(except) {
for (const menu of list.querySelectorAll('.menu')) {
if (menu === except) continue;
menu.hidden = true;
const dots = menu.parentElement.querySelector('.dots');
if (dots) dots.setAttribute('aria-expanded', 'false');
}
}
function toggleMenu(menu, dots, force) {
const open = force === undefined ? menu.hidden : force;
closeMenus(open ? menu : null);
menu.hidden = !open;
dots.setAttribute('aria-expanded', String(open));
if (open) {
const first = menu.querySelector('button');
if (first) first.focus();
} else {
dots.focus();
}
}
const DAY = 86400000;
const SECTIONS = ['Today', 'Yesterday', 'Last week', 'Last month', 'Older'];
function section(updated, now) {
if (!updated) return 'Older';
const then = new Date(updated); then.setHours(0, 0, 0, 0);
const today = new Date(now); today.setHours(0, 0, 0, 0);
const days = Math.round((today - then) / DAY);
if (days <= 0) return 'Today';
if (days === 1) return 'Yesterday';
if (days <= 7) return 'Last week';
if (days <= 31) return 'Last month';
return 'Older';
}
function sectionOf(li, now) {
if (li.dataset.archived === '1') return 'Archived';
if (li.dataset.pinned === '1') return 'Pinned';
return section(Number(li.dataset.updated) || 0, now || Date.now());
}
const COLLAPSED_KEY = 'sessions.collapsed';
function loadCollapsed() {
try {
const saved = JSON.parse(localStorage.getItem(COLLAPSED_KEY) || '[]');
return new Set(Array.isArray(saved) ? saved.filter(n => typeof n === 'string') : []);
} catch (e) { return new Set(); }
}
const collapsed = loadCollapsed();
function saveCollapsed() {
try { localStorage.setItem(COLLAPSED_KEY, JSON.stringify([...collapsed])); } catch (e) {}
}
function header(label, count) {
const li = document.createElement('li');
li.className = 'group';
const btn = document.createElement('button');
btn.type = 'button';
btn.className = 'grouptoggle';
btn.dataset.section = label;
const shut = collapsed.has(label);
btn.setAttribute('aria-expanded', String(!shut));
btn.title = (shut ? 'open ' : 'close ') + label.toLowerCase();
const chev = document.createElement('span');
chev.className = 'chev';
chev.textContent = shut ? '\u25b8' : '\u25be';
const name = document.createElement('span');
name.className = 'gname';
name.textContent = label;
const num = document.createElement('span');
num.className = 'gcount';
num.textContent = '\u00b7 ' + count;
btn.append(chev, name, num);
li.append(btn);
return li;
}
function groupList() {
if (!master.length) return;
const now = Date.now();
const pinned = [];
const archived = [];
const buckets = new Map();
for (const li of master) {
const name = sectionOf(li, now);
if (name === 'Archived') { archived.push(li); continue; }
if (name === 'Pinned') { pinned.push(li); continue; }
if (!buckets.has(name)) buckets.set(name, []);
buckets.get(name).push(li);
}
const out = [];
const add = (label, rows) => {
if (!rows.length) return;
out.push(header(label, rows.length));
if (!collapsed.has(label)) out.push(...rows);
};
add('Pinned', pinned);
for (const name of SECTIONS) add(name, buckets.get(name) || []);
add('Archived', archived);
list.replaceChildren(...out);
}
list.addEventListener('click', ev => {
const btn = ev.target.closest('.grouptoggle');
if (!btn) return;
const label = btn.dataset.section;
if (collapsed.has(label)) collapsed.delete(label); else collapsed.add(label);
saveCollapsed();
groupList();
markActive();
});
async function refreshSessions() {
const url = '/api/sessions' + (showarchived.checked ? '?archived=1' : '');
let r;
try { r = await fetch(url); }
catch (e) { return; }
if (r.status === 401) return location.reload();
if (!r.ok) return;
master = (await r.json()).map(sessionRow);
groupList();
markActive();
}
showarchived.addEventListener('change', () => { dropFind({ rebuild: false }); refreshSessions(); });
async function sessionWrite(id, act, body) {
const url = '/api/sessions/' + encodeURIComponent(id) + '/' + act;
let r;
try { r = await post(url, body); }
catch (e) { status.textContent = String(e); return null; }
if (r.status === 401) { location.reload(); return null; }
const data = await r.json().catch(() => ({}));
if (!r.ok) { status.textContent = data.error || ('HTTP ' + r.status); return null; }
return data;
}
async function afterWrite() {
if (find.value) dropFind({ rebuild: false });
await refreshSessions();
}
async function loadSession(id) {
if (busy) return;
let r;
try { r = await fetch('/api/sessions/' + encodeURIComponent(id)); }
catch (e) { return add('error', String(e)); }
if (r.status === 401) return location.reload();
if (!r.ok) return add('error', 'Could not load session');
setView('session');
sessionId = id;
clearLog();
clearStats();
const byCall = new Map();
for (const m of await r.json()) {
if (m.reasoning_content) addThinking(m.reasoning_content);
const calls = m.calls || [];
(m.tool_calls || []).forEach((c, i) => {
const info = calls[i] || {};
byCall.set(c.id, addCall(c.function.name, c.function.arguments, info.summary, info.state));
});
if (m.role === 'tool') {
attachOutput(byCall.get(m.tool_call_id), m.content);
continue;
}
const pictures = m.images || [];
if (pictures.length) {
const box = m.role === 'user' ? userMessage(m.content || '') : add(m.role, m.content || '');
for (const picture of pictures) {
const img = document.createElement('img');
img.className = 'sent';
img.src = picture.url;
img.alt = picture.name || 'attached picture';
img.title = (picture.name || 'picture') + ' (' + picture.mime + ')' +
(picture.seen ? ' — described: ' + picture.seen : '');
box.appendChild(img);
}
} else if (m.content) {
if (m.role === 'user') userMessage(m.content);
else add(m.role, m.content);
}
}
pinned = true;
pin();
paintJump();
markActive();
}
list.addEventListener('click', async e => {
const li = e.target.closest('li[data-id]');
if (!li) return;
const id = li.dataset.id;
const dots = e.target.closest('.dots');
if (dots) {
const menu = li.querySelector('.menu');
if (menu) toggleMenu(menu, dots);
return;
}
const btn = e.target.closest('button[data-act]');
if (!btn) return loadSession(id);
closeMenus();
const act = btn.dataset.act;
if (act === 'copy') {
try { await navigator.clipboard.writeText(id); status.textContent = 'copied ' + id; }
catch (err) { status.textContent = 'could not copy: ' + err; }
return;
}
if (act === 'rename') {
const shown = (li.querySelector('.name') || {}).textContent || '';
const title = window.prompt('Title for this session', shown.replace(MARKS, ''));
if (title === null) return;
if (await sessionWrite(id, 'rename', { title })) {
status.textContent = 'renamed ' + id;
await afterWrite();
}
return;
}
if (act === 'pin' || act === 'unpin') {
if (await sessionWrite(id, 'pin', { pinned: act === 'pin' })) {
status.textContent = (act === 'pin' ? 'pinned ' : 'unpinned ') + id;
await afterWrite();
}
return;
}
if (act === 'archive' || act === 'unarchive') {
if (await sessionWrite(id, 'archive', { archived: act === 'archive' })) {
status.textContent = (act === 'archive'
? 'archived ' + id + ' — still in the find box'
: 'unarchived ' + id + ' — back in the list');
await afterWrite();
}
return;
}
if (act === 'delete') {
if (!window.confirm('Delete this session? Its transcript, title and memory go with it.')) return;
if (await sessionWrite(id, 'delete')) {
if (sessionId === id) { sessionId = null; clearLog(); clearStats(); }
status.textContent = 'deleted ' + id;
await afterWrite();
}
}
});
document.getElementById('new').addEventListener('click', () => {
if (busy) return;
setView('session');
sessionId = null; clearLog(); markActive(); clearStats(); input.focus();
});
const find = document.getElementById('find');
const findinfo = document.getElementById('findinfo');
let findTimer = null;
let findSeq = 0;
function dropFind(opts) {
find.value = '';
clearTimeout(findTimer);
findinfo.textContent = '';
if (!opts || opts.rebuild !== false) refreshSessions();
}
async function runFind() {
const q = find.value.trim();
if (!q) return dropFind();
const mine = ++findSeq;
let r;
try { r = await fetch('/api/search?q=' + encodeURIComponent(q)); }
catch (e) { findinfo.textContent = String(e); return; }
if (r.status === 401) return location.reload();
if (!r.ok) { findinfo.textContent = 'search failed'; return; }
const hits = await r.json();
if (mine !== findSeq) return;
list.textContent = '';
const sessions = new Set();
for (const h of hits) {
sessions.add(h.session_id);
const li = document.createElement('li');
li.dataset.id = h.session_id;
const name = document.createElement('div');
name.textContent = h.title || h.session_id;
const snip = document.createElement('div');
snip.className = 'meta';
snip.textContent = '#' + h.seq + ' ' + h.role + ' · ' + h.snippet;
li.append(name, snip);
list.appendChild(li);
}
findinfo.textContent = hits.length === 0
? 'no match'
: hits.length + (hits.length === 1 ? ' hit' : ' hits') + ' in ' +
sessions.size + (sessions.size === 1 ? ' session' : ' sessions');
markActive();
}
find.addEventListener('input', () => { clearTimeout(findTimer); findTimer = setTimeout(runFind, 180); });
find.addEventListener('keydown', e => {
if (e.key === 'Escape') { e.preventDefault(); dropFind(); }
if (e.key === 'Enter') { e.preventDefault(); clearTimeout(findTimer); runFind(); }
});
const modelLabel = document.getElementById('model');
const models = document.getElementById('models');
const modelList = document.getElementById('modellist');
const modelSub = document.getElementById('modelsub');
const modelNote = document.getElementById('modelnote');
let modelSeq = 0; let reasoningSeq = 0;
function closeModels() {
modelSeq++;
reasoningSeq++;
models.hidden = true;
modelList.hidden = false;
modelSub.hidden = true;
modelLabel.setAttribute('aria-expanded', 'false');
modelList.textContent = '';
modelSub.textContent = '';
modelNote.textContent = '';
}
function modelRow(text, cls, onClick, into) {
const b = document.createElement('button');
b.type = 'button';
b.textContent = text;
b.setAttribute('role', 'menuitem');
if (cls) b.className = cls;
if (onClick) b.addEventListener('click', onClick); else b.disabled = true;
(into || modelList).appendChild(b);
return b;
}
function switchRow(label, on, opts, into) {
const b = document.createElement('button');
b.type = 'button';
b.className = 'switchrow' + (opts.dim ? ' dim' : '');
b.setAttribute('role', 'switch');
b.setAttribute('aria-checked', on ? 'true' : 'false');
const name = document.createElement('span');
name.className = 'switchlabel';
name.textContent = label;
const track = document.createElement('span');
track.className = 'track';
track.setAttribute('aria-hidden', 'true');
const knob = document.createElement('span');
knob.className = 'knob';
track.appendChild(knob);
b.append(name, track);
if (opts.title) b.title = opts.title;
if (opts.onClick) b.addEventListener('click', opts.onClick); else b.disabled = true;
(into || modelList).appendChild(b);
return b;
}
function modelRows() {
return Array.from(models.querySelectorAll('button:not(:disabled)'));
}
function focusRow(delta) {
const rows = modelRows();
if (!rows.length) return;
const at = rows.indexOf(document.activeElement);
rows[(at + delta + rows.length) % rows.length].focus();
}
async function pickModel(name) {
try {
const r = await post('/api/model', { model: name });
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) { modelNote.textContent = data.error || ('HTTP ' + r.status); return; }
modelLabel.textContent = data.model || '(not configured)';
closeModels();
modelLabel.focus();
status.textContent = 'the next turn uses ' + (data.model || 'the configured model');
} catch (e) { modelNote.textContent = String(e); }
}
function setThinking(open) {
for (const d of thinkingBlocks()) d.open = open;
thinkAll.textContent = open ? 'collapse all thinking' : 'expand all thinking';
}
function showModelList() {
modelSub.hidden = true;
modelList.hidden = false;
modelNote.textContent = '';
const first = modelRows()[0];
if (first) first.focus();
}
function applyReasoning(data) {
setEffort(data.effort, data.effort_detail, data.effort_session);
}
let lastPicked = null;
async function pickEffort(level) {
try {
const r = await post('/api/reasoning', { level });
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) { modelNote.textContent = data.error || ('HTTP ' + r.status); return; }
if (level && level !== (data.off_word || 'none')) lastPicked = level;
applyReasoning(data);
renderReasoning(data);
} catch (e) { modelNote.textContent = String(e); }
}
function renderReasoning(data) {
modelSub.textContent = '';
const offWord = data.off_word || null;
const isOff = offWord !== null && data.effort === offWord;
const levels = data.levels || [];
const said = data.described || {};
const restore = (lastPicked && levels.includes(lastPicked) ? lastPicked : null)
|| (data.configured && levels.includes(data.configured) ? data.configured : null)
|| levels.find(w => w !== offWord) || null;
switchRow('Reasoning', !isOff, {
title: offWord
? (isOff ? 'thinking is off for this session: press to ask for ' + (restore || 'the default') + ' again'
: 'thinking is on for this session: press to turn it off')
: data.off_why,
onClick: offWord ? () => pickEffort(isOff ? restore : offWord) : null,
}, modelSub);
modelRow('effort · ' + effortLabel, 'head', null, modelSub);
for (const word of levels) {
if (word === offWord) continue;
const on = !isOff && word === data.effort;
const row = modelRow(on ? word + ' ✓' : word, on ? 'current' : (isOff ? 'dim' : ''),
on ? null : () => pickEffort(word), modelSub);
if (said[word]) row.title = said[word];
}
const from = data.configured ? ' (' + data.configured + ')' : '';
if (data.effort_session) {
modelRow('default · back to the file' + from, '', () => pickEffort(null), modelSub);
} else {
modelRow('default · the file is in charge' + from, 'dim', null, modelSub);
}
modelRow('‹ model list', 'dim', showModelList, modelSub);
if (levels.length === 0) {
modelNote.textContent = data.note || 'this route takes no reasoning level';
} else {
modelNote.textContent = (isOff
? 'off for this session — the next turn carries this route\'s off. ' : '') +
'this dashboard only: the next turn uses it, a reload keeps it, and it is gone when ' +
'eclipse-web restarts. config.toml is not touched — the settings page writes the file.';
}
const first = modelRows()[0];
if (first) first.focus();
}
async function showReasoning() {
modelList.hidden = true;
modelSub.hidden = false;
modelSub.textContent = '';
modelNote.textContent = '';
modelRow('reading the route…', 'dim', null, modelSub);
const mine = ++reasoningSeq;
let r;
try { r = await fetch('/api/reasoning'); }
catch (e) {
if (mine === reasoningSeq) { modelSub.textContent = ''; modelNote.textContent = String(e); }
return;
}
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (mine !== reasoningSeq) return;
modelSub.textContent = '';
if (!r.ok) { modelNote.textContent = data.error || ('HTTP ' + r.status); return; }
applyReasoning(data);
renderReasoning(data);
}
async function openModels() {
const mine = ++modelSeq;
models.hidden = false;
modelList.hidden = false;
modelSub.hidden = true;
modelLabel.setAttribute('aria-expanded', 'true');
modelList.textContent = '';
modelSub.textContent = '';
modelNote.textContent = '';
modelRow('listing models…', 'dim');
let r;
try { r = await fetch('/api/models'); }
catch (e) { if (mine === modelSeq) { modelList.textContent = ''; modelNote.textContent = String(e); } return; }
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (mine !== modelSeq) return;
modelList.textContent = '';
if (!r.ok) { modelNote.textContent = data.error || ('HTTP ' + r.status); return; }
const current = data.model || null;
const configured = data.configured || null;
const listed = data.models || [];
for (const name of listed) {
modelRow(name === current ? name + ' · current' : name,
name === current ? 'current' : '', () => pickModel(name));
}
if (configured && configured !== current) {
modelRow('back to ' + configured + ' (what the config names)', 'dim', () => pickModel(null));
}
modelRow('Reasoning ›', '', showReasoning);
if (listed.length === 0) {
modelNote.textContent = 'the endpoint listed no models';
} else {
modelNote.textContent = listed.length + (listed.length === 1 ? ' model' : ' models') +
' · the next turn uses the choice; it lasts until eclipse-web stops and the config is not changed';
}
const first = modelRows()[0];
if (first) first.focus();
}
modelLabel.addEventListener('click', () => {
if (!models.hidden) return closeModels();
openModels();
});
modelLabel.addEventListener('keydown', e => {
if (e.key === 'ArrowDown' && models.hidden) { e.preventDefault(); openModels(); }
});
models.addEventListener('keydown', e => {
if (e.key === 'ArrowDown') { e.preventDefault(); focusRow(1); }
else if (e.key === 'ArrowUp') { e.preventDefault(); focusRow(-1); }
else if (e.key === 'Home') { e.preventDefault(); const r = modelRows()[0]; if (r) r.focus(); }
else if (e.key === 'End') { e.preventDefault(); const r = modelRows(); const last = r[r.length - 1]; if (last) last.focus(); }
else if (e.key === 'Escape') {
e.preventDefault();
if (!modelSub.hidden) showModelList();
else { closeModels(); modelLabel.focus(); }
} else if (e.key === 'Tab') { closeModels(); }
});
document.addEventListener('click', e => {
if (models.hidden) return;
if (models.contains(e.target) || modelLabel.contains(e.target)) return;
closeModels();
});
const setLabel = document.getElementById('settings');
const setWin = document.getElementById('settingswindow');
const setRowsBox = document.getElementById('setrows');
const setSections = document.getElementById('setsections');
const setFind = document.getElementById('setfind');
const setNote = document.getElementById('setnote');
const setPath = document.getElementById('setpath');
const setClose = document.getElementById('setclose');
let setRows = []; let setSection = ''; let setSeq = 0;
const SET_KIND_LABEL = { bool: 'true or false', integer: 'a whole number', float: 'a number',
list: 'a list', datetime: 'a date' };
const SET_SECTION_ABOUT = {
agent: 'the run itself: how many requests it may make, what it may do without asking, and what it is allowed to be',
provider: 'the model: where it is reached, which one, and how much reasoning it is asked for',
context: 'what goes into the prompt before your message does — the files, the budget, compaction',
sessions: 'the store: retention, pruning, and where the transcripts live',
tools: 'what the agent may use, and which calls need a person to say yes',
web: 'the dashboard: where it listens, who may sign in, and what the page can do',
cli: 'the terminal: the prompt, its colours, and what it remembers between lines',
user: 'who is running this: the names and files the agent reads about its operator',
update: 'how this build learns about a newer one, and the daily check it makes',
plugins: 'what is loaded beyond the build\'s own code',
gateway: 'the long-lived process the messaging platforms talk to',
skills: 'where skills are read from',
hooks: 'shell commands run around a turn'
};
function closeSettings() {
setSeq++;
if (setWin.open) setWin.close();
setLabel.setAttribute('aria-expanded', 'false');
}
function setShown(row) {
if (row.secret) return row.set ? '(set — the value is not shown)' : '(not set)';
return row.value === null || row.value === undefined ? '(not set)' : row.value;
}
function setErr(row) {
const box = document.createElement('div');
box.className = 'err';
return box;
}
function setRow(row) {
const wrap = document.createElement('div');
wrap.className = 'srow';
wrap.id = 'set-' + row.key;
const what = document.createElement('div');
what.className = 'what';
const name = document.createElement('code');
name.textContent = row.key;
what.appendChild(name);
wrap.appendChild(what);
const about = document.createElement('p');
about.className = 'about';
about.textContent = row.about || SET_KIND_LABEL[row.kind] || '';
wrap.appendChild(about);
const ctl = document.createElement('div');
ctl.className = 'ctl';
const err = setErr(row);
const send = async value => {
err.textContent = '';
try {
const r = await post('/api/settings', { key: row.key, value });
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) { err.textContent = data.error || ('HTTP ' + r.status); return; }
const i = setRows.findIndex(x => x.key === data.key);
if (i >= 0) setRows[i] = data;
redrawSetting(data.key);
setNote.textContent = data.key + ' = ' + setShown(data) + ' · written; ' + data.applies;
} catch (e) { err.textContent = String(e); }
};
if (row.kind === 'bool') {
const on = row.value === 'true';
const b = document.createElement('button');
b.type = 'button';
b.className = 'switch';
b.setAttribute('role', 'switch');
b.setAttribute('aria-checked', String(on));
b.title = on ? 'click to turn off' : 'click to turn on';
const track = document.createElement('span');
track.className = 'track';
const state = document.createElement('span');
state.className = 'state';
state.textContent = on ? 'on' : 'off';
b.appendChild(track);
b.appendChild(state);
b.addEventListener('click', () => send(on ? 'false' : 'true'));
ctl.appendChild(b);
} else if (row.choices && row.choices.length > 0) {
const sel = document.createElement('select');
const current = (row.value || '').replace(/^"|"$/g, '');
for (const choice of row.choices) {
const o = document.createElement('option');
o.value = choice;
o.textContent = choice;
if (choice === current) o.selected = true;
sel.appendChild(o);
}
const b = document.createElement('button');
b.type = 'button';
b.textContent = 'set';
b.addEventListener('click', () => send(sel.value));
ctl.appendChild(sel);
ctl.appendChild(b);
} else if (row.kind === 'list') {
const ta = document.createElement('textarea');
ta.rows = 2;
const items = (() => {
try { const v = JSON.parse(row.value || '[]'); return Array.isArray(v) ? v : []; }
catch (e) { return []; }
})();
ta.value = items.join('\n');
ta.placeholder = 'one item per line';
const b = document.createElement('button');
b.type = 'button';
b.textContent = 'set';
b.addEventListener('click', () => {
const lines = ta.value.split('\n').map(x => x.trim()).filter(x => x.length > 0);
send(JSON.stringify(lines));
});
ctl.appendChild(ta);
ctl.appendChild(b);
} else {
const input = document.createElement('input');
input.type = row.kind === 'integer' || row.kind === 'float' ? 'number' : 'text';
if (row.kind === 'float') input.step = 'any';
if (row.secret) {
input.type = 'password';
input.placeholder = row.set ? 'leave alone to keep the one set' : 'no value set';
input.autocomplete = 'new-password';
} else if (row.value !== null && row.value !== undefined) {
input.value = row.kind === 'str' ? String(row.value).replace(/^"(.*)"$/s, '$1') : row.value;
}
const b = document.createElement('button');
b.type = 'button';
b.textContent = 'set';
const commit = () => {
const typed = input.value;
if (row.secret && typed.length === 0) { err.textContent = 'type a value to replace it, or use reset'; return; }
send(typed);
};
b.addEventListener('click', commit);
input.addEventListener('keydown', e => {
if (e.key === 'Enter') { e.preventDefault(); commit(); }
});
ctl.appendChild(input);
ctl.appendChild(b);
}
const reset = document.createElement('button');
reset.type = 'button';
reset.textContent = 'reset';
reset.title = 'comment the line out, so the key falls back to what this build defaults to';
reset.disabled = row.is_default === true;
reset.addEventListener('click', () => send(null));
ctl.appendChild(reset);
const where = document.createElement('div');
where.className = 'where';
where.textContent = 'now: ' + setShown(row) +
(row.default === null || row.default === undefined ? '' : ' · default: ' + row.default) +
(row.is_default ? ' · at the default' : '');
const when = document.createElement('span');
when.className = row.applies === 'restart the dashboard' ? 'restart' : '';
when.textContent = ' · ' + (row.applies === 'restart the dashboard'
? 'needs a dashboard restart, not the next message'
: 'the next run uses it');
where.appendChild(when);
ctl.appendChild(where);
wrap.appendChild(ctl);
wrap.appendChild(err);
return wrap;
}
function redrawSetting(key) {
const row = setRows.find(r => r.key === key);
const old = document.getElementById('set-' + key);
if (!row || !old || !old.parentNode) return;
old.parentNode.replaceChild(setRow(row), old);
}
function paintSettings() {
if (ctxSel) return paintFile();
const q = setFind.value.trim().toLowerCase();
const shown = setRows.filter(r =>
(setSection === '' || r.section === setSection) &&
(q === '' || r.key.toLowerCase().includes(q) || String(r.about || '').toLowerCase().includes(q)));
setRowsBox.textContent = '';
let lastSection = null;
for (const row of shown) {
if (row.section !== lastSection) {
lastSection = row.section;
const h = document.createElement('h3');
h.textContent = row.section;
setRowsBox.appendChild(h);
const what = SET_SECTION_ABOUT[row.section];
if (what) {
const p = document.createElement('p');
p.className = 'sectionabout';
p.textContent = what;
setRowsBox.appendChild(p);
}
}
setRowsBox.appendChild(setRow(row));
}
if (shown.length === 0) {
const p = document.createElement('p');
p.className = 'about';
p.textContent = setRows.length === 0 ? 'the config could not be read' : 'no key matches that';
setRowsBox.appendChild(p);
}
setNote.textContent = shown.length + ' of ' + setRows.length + ' key(s)' +
(setSection ? ' in [' + setSection + ']' : '') +
' · a write is read back from the file before it answers';
}
function paintSections() {
const counts = new Map();
for (const r of setRows) counts.set(r.section, (counts.get(r.section) || 0) + 1);
setSections.textContent = '';
const group = label => {
const h = document.createElement('h4');
h.textContent = label;
setSections.appendChild(h);
};
const add = (label, value, count, isFile) => {
const b = document.createElement('button');
b.type = 'button';
const current = isFile ? ctxSel === value : ctxSel === '' && setSection === value;
b.setAttribute('aria-current', String(current));
const name = document.createElement('span');
name.textContent = label;
const n = document.createElement('span');
n.className = 'count';
n.textContent = String(count);
b.appendChild(name);
b.appendChild(n);
b.addEventListener('click', () => {
if (isFile) { ctxSel = value; } else { ctxSel = ''; setSection = value; }
paintSections();
paintSettings();
});
setSections.appendChild(b);
};
group('settings');
add('all', '', setRows.length, false);
for (const [section, count] of [...counts.entries()].sort()) add(section, section, count, false);
if (ctxFiles.length > 0) {
group('context files');
for (const f of ctxFiles) {
const id = String(f.chars) + (f.truncated ? ' clipped' : '');
add(f.file, f.name, id, true);
}
}
}
let ctxFiles = []; let ctxSel = ''; let ctxBaseline = '';
async function loadContext() {
try {
const r = await fetch('/api/context');
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) { setNote.textContent = data.error || ('HTTP ' + r.status); return; }
ctxFiles = data.files || [];
paintSections();
if (ctxSel) paintFile();
} catch (e) { setNote.textContent = String(e); }
}
function paintFile() {
const row = ctxFiles.find(f => f.name === ctxSel);
setRowsBox.textContent = '';
if (!row) {
const p = document.createElement('p');
p.className = 'about';
p.textContent = 'that file is not in the list this config resolves';
setRowsBox.appendChild(p);
return;
}
const head = document.createElement('h3');
head.textContent = row.file + (row.exists ? '' : ' (does not exist yet — saving creates it)');
setRowsBox.appendChild(head);
const where = document.createElement('p');
where.className = 'about';
where.textContent = row.path;
setRowsBox.appendChild(where);
const budget = row.own_budget === null || row.own_budget === undefined ? row.max_chars : row.own_budget;
const meter = document.createElement('div');
meter.className = 'meter';
const bar = document.createElement('div');
bar.className = 'bar';
const fill = document.createElement('i');
fill.style.width = budget > 0 ? Math.min(100, Math.round(100 * row.chars / budget)) + '%' : '0%';
bar.appendChild(fill);
if (row.chars > budget) bar.classList.add('over');
meter.appendChild(document.createTextNode(row.chars + ' chars of ' + (budget > 0 ? budget : 'no cap')));
meter.appendChild(bar);
setRowsBox.appendChild(meter);
const said = [];
if (row.truncated) {
said.push('the prompt is already clipping this file: it keeps ' + row.kept + ' of ' + row.chars + ' chars');
}
if (row.others > 0) {
said.push(row.others + ' more ' + row.file + ' layer(s) are injected above this one — the nearest file wins the last word');
}
if (row.kind === 'memory') {
said.push('entries are separated by a line holding §; the memory tool owns this file, its budget is a refusal rather than a clip, and the same lock and rename apply to a save from here');
}
said.push('total across the files: ' + row.total + ' of ' + row.total_budget + ' chars');
for (const line of said) {
const p = document.createElement('p');
p.className = row.truncated && line.startsWith('the prompt is already') ? 'about warn' : 'about';
p.textContent = line;
setRowsBox.appendChild(p);
}
const area = document.createElement('textarea');
area.id = 'filetext';
area.spellcheck = false;
area.value = row.text;
area.rows = 18;
ctxBaseline = row.text;
setRowsBox.appendChild(area);
const ctl = document.createElement('div');
ctl.className = 'ctl filebar';
const counter = document.createElement('span');
counter.className = 'where';
const count = () => {
const now = [...area.value].length;
counter.textContent = now + ' chars' + (now === row.chars ? '' : ' (' + (now - row.chars > 0 ? '+' : '') + (now - row.chars) + ')');
};
count();
area.addEventListener('input', () => {
count();
save.disabled = area.value === ctxBaseline;
});
const save = document.createElement('button');
save.type = 'button';
save.textContent = 'save';
save.className = 'primary';
save.disabled = true;
const revert = document.createElement('button');
revert.type = 'button';
revert.textContent = 'revert';
revert.addEventListener('click', () => {
area.value = ctxBaseline;
count();
save.disabled = true;
err.textContent = '';
});
const err = document.createElement('div');
err.className = 'err';
save.addEventListener('click', async () => {
err.textContent = '';
save.disabled = true;
try {
const r = await post('/api/context', { name: row.name, text: area.value });
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) { err.textContent = data.error || ('HTTP ' + r.status); save.disabled = false; return; }
const i = ctxFiles.findIndex(f => f.name === row.name);
if (i >= 0) ctxFiles[i] = data.file;
paintSections();
paintFile();
setNote.textContent = 'saved ' + data.file.file + ' · ' + data.applies +
(data.file.truncated ? ' · and the prompt will clip it: it keeps ' + data.file.kept + ' of ' + data.file.chars + ' chars' : '');
} catch (e) { err.textContent = String(e); save.disabled = false; }
});
ctl.appendChild(save);
ctl.appendChild(revert);
ctl.appendChild(counter);
setRowsBox.appendChild(ctl);
setRowsBox.appendChild(err);
setNote.textContent = 'a save applies to the next run; a turn already in flight keeps the prompt it was built with';
}
async function loadSettings() {
const mine = ++setSeq;
setRowsBox.textContent = '';
setSections.textContent = '';
setNote.textContent = 'reading the config…';
let r;
try { r = await fetch('/api/settings'); }
catch (e) { if (mine === setSeq) setNote.textContent = String(e); return; }
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (mine !== setSeq) return;
if (!r.ok) { setNote.textContent = data.error || ('HTTP ' + r.status); return; }
setRows = data.settings || [];
setSection = '';
setPath.textContent = (data.profile || 'default') + (data.path ? ' · ' + data.path : '');
paintSections();
paintSettings();
}
setLabel.addEventListener('click', () => {
if (setWin.open) return closeSettings();
setLabel.setAttribute('aria-expanded', 'true');
setFind.value = '';
ctxSel = '';
if (!setWin.open) setWin.showModal();
loadSettings();
loadContext();
});
setClose.addEventListener('click', closeSettings);
setWin.addEventListener('close', () => {
setSeq++;
setLabel.setAttribute('aria-expanded', 'false');
});
setFind.addEventListener('input', paintSettings);
function showApproval(d) {
const el = document.createElement('div');
el.className = 'msg approval';
const text = document.createElement('div');
text.textContent = 'Allow ' + d.tool + '? ' + d.summary;
const note = document.createElement('div');
note.className = 'meta';
note.textContent = 'Declined automatically after ' + d.timeout_secs + 's without an answer.';
const actions = document.createElement('div');
actions.className = 'actions';
const decide = async approved => {
for (const b of actions.children) b.disabled = true;
try {
const r = await post('/api/approvals/' + encodeURIComponent(d.id), { approved });
if (r.status === 401) location.reload();
else if (!r.ok) note.textContent = 'The decision could not be delivered (already answered or expired).';
} catch (e) { note.textContent = String(e); }
};
for (const [label, approved, cls] of [['Approve', true, 'yes'], ['Deny', false, 'no']]) {
const b = document.createElement('button');
b.type = 'button'; b.className = cls; b.textContent = label;
b.addEventListener('click', () => decide(approved));
actions.appendChild(b);
}
el.append(text, note, actions);
pendingApprovals.set(d.id, { note, actions });
log.appendChild(el);
status.textContent = 'waiting for your approval…';
follow();
}
function resolveApproval(d) {
const p = pendingApprovals.get(d.id);
if (!p) return;
pendingApprovals.delete(d.id);
p.actions.remove();
p.note.textContent = outcomes[d.outcome] || d.outcome;
status.textContent = 'thinking…';
}
function handle(event, data) {
switch (event) {
case 'session':
setView('session');
if (deferredLine) { userMessage(deferredLine); deferredLine = null; }
sessionId = data.session_id;
runId = data.run_id || null;
if (runId && busy) setGo('stop');
if (find.value) dropFind({ rebuild: false });
if (!master.some(li => li.dataset.id === sessionId)) {
master.unshift(sessionRow({ id: sessionId, preview: input.dataset.last || '' }));
}
groupList();
markActive();
break;
case 'reasoning':
if (thinking) {
thinking.textContent += data.text;
thinkingHeader(thinking);
} else {
thinking = addThinking(data.text);
}
follow();
break;
case 'delta':
thinking = null; composing = null;
if (!live) live = add('assistant', '');
live.textContent += data.text;
follow();
break;
case 'tool_call_delta':
thinking = null; live = null;
if (!composing) {
composing = add('tool', '→ working out a tool call…');
composing.classList.add('composing');
}
follow();
break;
case 'tool_call': {
const row = addCall(data.name, data.arguments, data.summary, 'running', data.call_id);
if (composing) { composing.replaceWith(row); composing = null; }
endBlocks();
break;
}
case 'context_trimmed': {
let note = '[context: ' + data.turns + ' older turn(s) not sent to fit the context budget';
if (data.memory === 'reused') note += '; reused from this session\'s stored memory';
if (data.memory === 'saved') note += '; saved to this session\'s memory';
if (data.memory === 'save_failed') note += '; could not save session memory';
if (data.memory_error) note += '; memory error: ' + data.memory_error;
if (data.judgement === 'used') {
note += '; ' + data.judgement_bullets + ' handoff bullet(s) written by the model';
} else if (data.judgement === 'rejected') {
note += '; handoff notes rejected: ' + data.judgement_error;
} else if (data.judgement === 'failed') {
note += '; handoff notes failed: ' + data.judgement_error;
}
add('tool', note + ']');
break;
}
case 'tool_result': {
const row = callRow(data.call_id, data.name);
if (!row) { add(data.is_error ? 'error' : 'tool', data.output); break; }
callState(row, data.state);
attachOutput(row, data.output);
follow();
break;
}
case 'message':
thinking = null; composing = null;
if (live) { live.textContent = data.text; live = null; } else add('assistant', data.text);
break;
case 'notice':
endBlocks();
if (deferredLine) { add('command', deferredLine); deferredLine = null; }
{
const row = add('notice', data.text);
if (data.kind === 'refusal') row.classList.add('refusal');
}
if (data.clear_session) { sessionId = null; runId = null; markActive(); }
if (data.yolo !== null && data.yolo !== undefined) paintYolo(data.yolo);
break;
case 'approval_request': showApproval(data); break;
case 'approval_resolved': resolveApproval(data); break;
case 'stats':
paintLive(data);
if (data.effort) setEffort(data.effort, data.effort_detail, data.effort_session);
break;
case 'cancelled': endBlocks(); add('tool', '[cancelled]'); break;
case 'error': endBlocks(); add('error', data.message); break;
}
}
const PASTE_LIMIT = Number(document.getElementById('form').dataset.pasteLimit || 160);
const pastes = []; const pasteBar = document.getElementById('pastes');
function pasteLines(text) {
const trimmed = text.replace(/\n+$/, '');
return Math.max(1, trimmed.split('\n').length);
}
function fitsInline(text) {
return pasteLines(text) === 1 && Array.from(text).length <= PASTE_LIMIT;
}
function chipFor(text) {
return '[Pasted #' + (pastes.length + 1) + ': ' + pasteLines(text) + ' line(s), ' +
Array.from(text).length + ' chars]';
}
function renderPastes() {
pasteBar.textContent = '';
pasteBar.hidden = pastes.length === 0;
pastes.forEach((paste, i) => {
const b = document.createElement('button');
b.type = 'button';
b.className = 'paste';
b.title = 'remove this paste — the text is dropped, nothing else changes';
b.textContent = paste.chip + ' ';
const x = document.createElement('span');
x.className = 'x';
x.textContent = '×';
b.appendChild(x);
b.addEventListener('click', () => {
const at = input.value.indexOf(paste.chip);
if (at >= 0) input.value = input.value.slice(0, at) + input.value.slice(at + paste.chip.length);
pastes.splice(i, 1);
renderPastes();
input.focus();
});
pasteBar.appendChild(b);
});
}
function expandPastes(line) {
let out = line;
for (const paste of pastes) out = out.replace(paste.chip, () => paste.text);
return out;
}
input.addEventListener('paste', e => {
const text = (e.clipboardData || window.clipboardData).getData('text');
if (!text || fitsInline(text)) return; e.preventDefault();
const chip = chipFor(text);
pastes.push({ chip, text });
const at = input.selectionStart;
input.value = input.value.slice(0, at) + chip + input.value.slice(input.selectionEnd);
input.selectionStart = input.selectionEnd = at + chip.length;
renderPastes();
});
const ATTACH_MAX_CHARS = 65536;
const PICTURE_MAX_BYTES = 2 * 1024 * 1024;
const PICTURE_TYPES = ['image/png', 'image/jpeg', 'image/webp', 'image/gif'];
const attached = [];
const attachFile = document.getElementById('attachfile');
const pictureInput = document.getElementById('attachpicture');
const attachMenu = document.getElementById('attachmenu');
const plus = document.getElementById('plus');
function renderAttached() {
const box = document.getElementById('attached');
box.textContent = '';
box.hidden = attached.length === 0;
attached.forEach((a, i) => {
const chip = document.createElement('span');
chip.className = 'chip';
const label = document.createElement('span');
label.textContent = a.kind === 'text'
? a.name + ' · ' + a.value.length + ' chars'
: a.kind === 'image' ? 'picture: ' + a.name
: a.kind === 'path' ? 'path: ' + a.value : 'link: ' + a.value;
const x = document.createElement('button');
x.type = 'button';
x.className = 'x';
x.textContent = '×';
x.title = 'remove this attachment';
x.addEventListener('click', () => { attached.splice(i, 1); renderAttached(); plus.focus(); });
chip.append(label, x);
box.appendChild(chip);
});
}
function closeAttach() {
attachMenu.hidden = true;
plus.setAttribute('aria-expanded', 'false');
}
function attachRow(kind) {
if (kind === 'file') {
closeAttach();
attachFile.click();
return;
}
if (kind === 'path') {
closeAttach();
const typed = window.prompt('Path to a file on this machine (the agent reads it with read_file)', '');
if (typed === null) return;
const value = typed.trim();
if (!value) return;
if (value.length > 512 || /[\u0000-\u001f]/.test(value)) {
status.textContent = 'a path is one line, at most 512 characters';
return;
}
attached.push({ kind: 'path', name: '', value });
renderAttached();
status.textContent = 'attached path: ' + value;
return;
}
if (kind === 'image') {
closeAttach();
pictureInput.click();
return;
}
if (kind === 'url') {
closeAttach();
const typed = window.prompt('Link (the agent fetches it)', 'https://');
if (typed === null) return;
const value = typed.trim();
if (!value) return;
if (!/^https?:\/\/\S+$/.test(value) || value.length > 2048) {
status.textContent = 'a link starts with http:// or https:// and holds no spaces';
return;
}
attached.push({ kind: 'url', name: '', value });
renderAttached();
status.textContent = 'attached link: ' + value;
}
}
attachFile.addEventListener('change', async e => {
const f = e.target.files && e.target.files[0];
e.target.value = '';
if (!f) return;
if (f.size > ATTACH_MAX_CHARS) {
status.textContent = f.name + ' is ' + f.size + ' bytes and the limit is ' + ATTACH_MAX_CHARS +
' — attach it as a path instead and the agent reads the part it needs';
return;
}
let text;
try { text = await f.text(); } catch (err) {
status.textContent = f.name + ' could not be read as text: ' + err;
return;
}
if (text.length > ATTACH_MAX_CHARS) {
status.textContent = f.name + ' is ' + text.length + ' characters and the limit is ' + ATTACH_MAX_CHARS +
' — attach it as a path instead';
return;
}
attached.push({ kind: 'text', name: f.name, value: text });
renderAttached();
status.textContent = 'attached ' + f.name + ' · ' + text.length + ' chars';
input.focus();
});
pictureInput.addEventListener('change', async e => {
const f = e.target.files && e.target.files[0];
e.target.value = '';
if (!f) return;
if (f.size > PICTURE_MAX_BYTES) {
status.textContent = f.name + ' is ' + Math.round(f.size / 1024) + ' KB and a picture may be ' +
Math.round(PICTURE_MAX_BYTES / 1024) + ' KB';
return;
}
let url;
try {
url = await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(String(reader.result));
reader.onerror = () => reject(reader.error || 'could not read it');
reader.readAsDataURL(f);
});
} catch (err) {
status.textContent = f.name + ' could not be read: ' + err;
return;
}
const mime = (url.match(/^data:([^;,]+)/) || [])[1] || f.type || '';
if (!PICTURE_TYPES.includes(mime)) {
status.textContent = f.name + ' is ' + (mime || 'an unknown type') +
'; this build carries ' + PICTURE_TYPES.join(', ');
return;
}
attached.push({ kind: 'image', name: f.name, value: url });
renderAttached();
status.textContent = 'attached picture: ' + f.name + ' · ' + Math.round(f.size / 1024) + ' KB';
input.focus();
});
plus.addEventListener('click', () => {
if (!attachMenu.hidden) { closeAttach(); return; }
attachMenu.hidden = false;
plus.setAttribute('aria-expanded', 'true');
const first = attachMenu.querySelector('button:not(:disabled)');
if (first) first.focus();
});
attachMenu.addEventListener('click', e => {
const row = e.target.closest('button[data-attach]');
if (row && !row.disabled) attachRow(row.dataset.attach);
});
attachMenu.addEventListener('keydown', e => {
const rows = [...attachMenu.querySelectorAll('button:not(:disabled)')];
const at = rows.indexOf(document.activeElement);
if (e.key === 'Escape') { e.preventDefault(); closeAttach(); plus.focus(); }
else if (e.key === 'ArrowDown') { e.preventDefault(); (rows[(at + 1) % rows.length] || plus).focus(); }
else if (e.key === 'ArrowUp') { e.preventDefault(); (rows[(at - 1 + rows.length) % rows.length] || plus).focus(); }
});
document.addEventListener('mousedown', e => {
if (!attachMenu.hidden && !attachMenu.contains(e.target) && e.target !== plus) closeAttach();
});
async function submit() {
const text = expandPastes(input.value).trim();
if ((!text && attached.length === 0) || busy) return;
const carrying = attached.map(a => ({ kind: a.kind, name: a.name || '', value: a.value }));
const typed = input.value;
const pastesBefore = pastes.slice();
const attachedBefore = attached.slice();
const restoreComposer = () => {
input.value = typed;
pastes.length = 0;
pastes.push(...pastesBefore);
renderPastes();
attached.length = 0;
attached.push(...attachedBefore);
renderAttached();
};
busy = true;
endBlocks();
clearStats();
closeCmdMenu();
input.value = '';
pastes.length = 0;
renderPastes();
attached.length = 0;
renderAttached();
input.dataset.last = text.slice(0, 50);
const said = text || (carrying.length ? '(' + carrying.length + ' attached)' : '');
let echo = null;
if (text.startsWith('/')) deferredLine = said; else echo = userMessage(said);
setGo('starting'); status.textContent = 'thinking…';
let reader = null;
try {
const resp = await post('/api/chat',
carrying.length ? { message: text, session_id: sessionId, attachments: carrying }
: { message: text, session_id: sessionId });
if (resp.status === 401) { location.reload(); return; }
if (!resp.ok) {
const err = await resp.json().catch(() => ({}));
add('error', err.error || ('HTTP ' + resp.status));
if (echo) echo.remove();
restoreComposer();
return;
}
let finished = false;
reader = resp.body.getReader();
const dec = new TextDecoder();
let buf = '';
for (;;) {
const { done, value } = await reader.read();
if (done) break;
buf += dec.decode(value, { stream: true });
let idx;
while ((idx = buf.indexOf('\n\n')) >= 0) {
const block = buf.slice(0, idx); buf = buf.slice(idx + 2);
let event = 'message', data = '';
for (const line of block.split('\n')) {
if (line.startsWith('event:')) event = line.slice(6).trim();
else if (line.startsWith('data:')) data += line.slice(5).trim();
}
if (event === 'done') finished = true;
if (data) {
try { handle(event, JSON.parse(data)); }
catch (e) { add('error', 'a malformed event: ' + e); }
}
}
}
if (!finished) add('error', 'Connection closed before the reply finished');
} catch (e) {
add('error', String(e));
} finally {
if (reader) { try { await reader.cancel(); } catch (e) { } }
deferredLine = null;
busy = false; setGo('idle'); runId = null;
status.textContent = ''; input.focus();
if (!find.value) {
refreshSessions();
setTimeout(() => { if (!find.value && !busy) refreshSessions(); }, 5000);
}
}
}
async function cancelRun() {
if (!runId) return;
status.textContent = 'cancelling…';
try {
await post('/api/runs/' + encodeURIComponent(runId) + '/cancel');
} catch (e) {
add('error', String(e));
}
}
go.addEventListener('click', () => {
switch (go.dataset.state) {
case 'stop': cancelRun(); break;
case 'starting': status.textContent = 'starting — nothing to cancel yet'; break;
default: document.getElementById('form').requestSubmit();
}
});
document.getElementById('logout').addEventListener('submit', async e => {
e.preventDefault();
try { await post('/logout'); } finally { location.href = '/login'; }
});
document.getElementById('form').addEventListener('submit', e => { e.preventDefault(); submit(); });
let commands = null;
let cmdRows = []; let cmdActive = -1;
const commandWord = () => {
const line = input.value;
if (!line.startsWith('/') || /\s/.test(line)) return null;
return line;
};
function closeCmdMenu() {
cmdmenu.hidden = true;
cmdmenu.textContent = '';
input.removeAttribute('aria-activedescendant');
input.setAttribute('aria-expanded', 'false');
cmdRows = [];
cmdActive = -1;
}
function markCmdRow() {
for (let i = 0; i < cmdRows.length; i++) {
const on = i === cmdActive;
cmdRows[i].el.setAttribute('aria-selected', String(on));
if (on) {
input.setAttribute('aria-activedescendant', cmdRows[i].el.id);
const top = cmdRows[i].el.offsetTop, bottom = top + cmdRows[i].el.offsetHeight;
if (top < cmdmenu.scrollTop) cmdmenu.scrollTop = top;
else if (bottom > cmdmenu.scrollTop + cmdmenu.clientHeight) {
cmdmenu.scrollTop = bottom - cmdmenu.clientHeight;
}
}
}
if (cmdActive < 0) input.removeAttribute('aria-activedescendant');
}
function paintCmdMenu(word) {
cmdmenu.textContent = '';
cmdRows = [];
cmdActive = -1;
if (commands === null) { cmdmenu.hidden = true; return; }
const shown = commands.filter(c => c.name.startsWith(word) ||
(c.aliases || []).some(a => a.startsWith(word)));
if (shown.length === 0) {
const empty = document.createElement('div');
empty.className = 'empty';
empty.textContent = 'no command starts with ' + word + ' — Enter sends it as a line';
cmdmenu.appendChild(empty);
cmdmenu.hidden = false;
input.setAttribute('aria-expanded', 'true');
return;
}
for (const c of shown) {
const el = document.createElement('button');
el.type = 'button';
el.id = 'cmd-' + c.name.replace(/^\//, '');
el.setAttribute('role', 'option');
el.setAttribute('aria-selected', 'false');
const label = document.createElement('span');
label.className = 'label';
label.textContent = c.label || c.name;
const why = document.createElement('span');
why.className = 'why';
why.textContent = c.help || '';
el.appendChild(label);
el.appendChild(why);
el.addEventListener('mousedown', e => { e.preventDefault(); acceptCmd(c); });
cmdmenu.appendChild(el);
cmdRows.push({ el, command: c });
}
cmdmenu.hidden = false;
input.setAttribute('aria-expanded', 'true');
if (cmdRows.length === 1) { cmdActive = 0; markCmdRow(); }
}
function acceptCmd(c) {
const word = commandWord();
if (word === null) return closeCmdMenu();
input.value = c.name + (c.takes_arg ? ' ' : '');
input.selectionStart = input.selectionEnd = input.value.length;
closeCmdMenu();
input.focus();
}
async function loadCommands() {
if (commands !== null) return;
try {
const r = await fetch('/api/commands');
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
commands = r.ok && Array.isArray(data.commands) ? data.commands : [];
} catch (e) {
commands = []; }
const word = commandWord();
if (word !== null) paintCmdMenu(word);
}
loadCommands();
input.addEventListener('input', () => {
const word = commandWord();
if (word === null) return closeCmdMenu();
if (commands === null) { loadCommands(); return; }
paintCmdMenu(word);
});
input.addEventListener('keydown', e => {
const open = !cmdmenu.hidden;
if (open) {
if (e.key === 'ArrowDown') { e.preventDefault(); cmdActive = cmdActive < 0 ? 0 : (cmdActive + 1) % Math.max(cmdRows.length, 1); markCmdRow(); return; }
if (e.key === 'ArrowUp') { e.preventDefault(); cmdActive = cmdActive < 0 ? cmdRows.length - 1 : (cmdActive - 1 + cmdRows.length) % Math.max(cmdRows.length, 1); markCmdRow(); return; }
if (e.key === 'Tab' || (e.key === 'Enter' && cmdRows.length > 0 && cmdActive >= 0)) {
if (cmdActive >= 0) { e.preventDefault(); acceptCmd(cmdRows[cmdActive].command); return; }
}
if (e.key === 'Escape') {
e.preventDefault(); e.stopPropagation(); closeCmdMenu(); return;
}
}
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); submit(); }
});
document.addEventListener('mousedown', e => {
if (cmdmenu.hidden) return;
if (cmdmenu.contains(e.target) || e.target === input) return;
closeCmdMenu();
});
const notice = document.getElementById('notice');
const updateBadge = document.getElementById('updatebadge');
const updateText = document.getElementById('updatetext');
const updatePop = document.getElementById('updatepop');
const closeUpdate = () => {
updatePop.hidden = true;
updateBadge.setAttribute('aria-expanded', 'false');
};
async function refreshUpdate() {
let r;
try { r = await fetch('/api/update'); } catch (e) { return; }
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok || !data.behind) { notice.hidden = true; closeUpdate(); return; }
updateText.textContent = '↑ ' + String(data.latest || '').replace(/^v/, '') + ' available';
notice.hidden = false;
}
updateBadge.addEventListener('click', e => {
e.stopPropagation();
const opening = updatePop.hidden;
updatePop.hidden = !opening;
updateBadge.setAttribute('aria-expanded', String(opening));
});
document.addEventListener('click', e => {
if (updatePop.hidden) return;
if (updatePop.contains(e.target) || updateBadge.contains(e.target)) return;
closeUpdate();
});
document.addEventListener('keydown', e => {
if (e.key !== 'Escape') return;
if (!updatePop.hidden) { e.preventDefault(); closeUpdate(); return; }
const open = list.querySelector('.menu:not([hidden])');
if (open) {
e.preventDefault();
toggleMenu(open, open.parentElement.querySelector('.dots'), false);
}
});
document.addEventListener('click', e => {
if (!e.target.closest('#sessions .dots') && !e.target.closest('#sessions .menu')) closeMenus();
});
refreshUpdate();
setInterval(refreshUpdate, 30 * 60 * 1000);
const cronBtn = document.getElementById('cron');
const cronPane = document.getElementById('cronpane');
const cronRows = document.getElementById('cronrows');
const cronMsg = document.getElementById('cronmsg');
const cronFile = document.getElementById('cronfile');
const cronForm = document.getElementById('cronform');
const crName = document.getElementById('cr-name');
const crSchedule = document.getElementById('cr-schedule');
const crPrompt = document.getElementById('cr-prompt');
const crWorkdir = document.getElementById('cr-workdir');
const crEditing = document.getElementById('cronediting');
const cronLogsBox = document.getElementById('cronlogs');
let cronOpen = false;
let cronJobs = [];
let cronNow = 0;
let cronBusy = new Set(); let cronEditingName = null;
const write = (method, url, body) => fetch(url, {
method,
headers: body === undefined
? { 'X-Eclipse-CSRF': CSRF }
: { 'X-Eclipse-CSRF': CSRF, 'content-type': 'application/json' },
body: body === undefined ? undefined : JSON.stringify(body),
});
function cronSay(text, bad) {
cronMsg.textContent = text || '';
cronMsg.className = bad ? 'bad' : '';
}
function inWords(ms) {
const delta = ms - cronNow;
if (delta < 0) return 'due';
const mins = Math.round(delta / 60000);
if (mins < 60) return 'in ' + mins + 'm';
const hours = Math.floor(mins / 60);
if (hours < 24) return 'in ' + hours + 'h ' + (mins % 60) + 'm';
return 'in ' + Math.floor(hours / 24) + 'd ' + (hours % 24) + 'h';
}
function agoWords(ms) {
const delta = cronNow - ms;
if (delta < 60000) return 'just now';
const mins = Math.floor(delta / 60000);
if (mins < 60) return mins + 'm ago';
const hours = Math.floor(mins / 60);
if (hours < 24) return hours + 'h ago';
return Math.floor(hours / 24) + 'd ago';
}
function cronCell(td, text, cls) {
td.textContent = text;
if (cls) td.className = cls;
return td;
}
function rowButton(label, title, handler, cls) {
const b = document.createElement('button');
b.type = 'button';
b.textContent = label;
b.title = title;
if (cls) b.className = cls;
b.addEventListener('click', handler);
return b;
}
function renderCron() {
cronRows.textContent = '';
if (!cronJobs.length) {
const tr = document.createElement('tr');
const td = document.createElement('td');
td.colSpan = 5;
td.className = 'when';
td.textContent = 'no jobs are scheduled — “+ new job” writes the first one';
tr.appendChild(td);
cronRows.appendChild(tr);
return;
}
for (const job of cronJobs) {
const tr = document.createElement('tr');
if (!job.enabled) tr.className = 'off';
tr.appendChild(cronCell(document.createElement('td'), job.name, 'name'));
tr.appendChild(cronCell(document.createElement('td'), job.schedule));
tr.appendChild(cronCell(document.createElement('td'),
job.enabled ? (job.next_ms ? inWords(job.next_ms) : '—') : 'off', 'when'));
const last = job.last_outcome
? job.last_outcome + (job.last_started_ms ? ' · ' + agoWords(job.last_started_ms) : '')
: 'never';
tr.appendChild(cronCell(document.createElement('td'), last,
'last ' + (job.last_outcome === 'failed' ? 'failed' : job.last_outcome ? 'ok' : '')));
const acts = document.createElement('td');
acts.className = 'acts';
const running = cronBusy.has(job.name) ||
(job.last_started_ms && job.last_finished_ms && job.last_started_ms > job.last_finished_ms);
const run = rowButton(running ? 'running…' : 'run', 'run it now, whether or not it is due',
() => runNow(job.name), 'go');
run.disabled = Boolean(running);
acts.appendChild(run);
acts.appendChild(rowButton(job.enabled ? 'off' : 'on',
job.enabled ? 'stop it firing, keeping the job' : 'let it fire again',
() => toggleJob(job.name, !job.enabled)));
acts.appendChild(rowButton('logs', 'the last runs and what they answered',
() => showLogs(job.name)));
acts.appendChild(rowButton('edit', 'change the schedule or the prompt', () => editJob(job)));
acts.appendChild(rowButton('remove', 'delete the job; its run logs stay on disk',
() => removeJob(job.name), 'bad'));
tr.appendChild(acts);
cronRows.appendChild(tr);
}
}
async function loadCron(quiet) {
let r;
try { r = await fetch('/api/cron'); } catch (e) { cronSay('the dashboard is not answering', true); return; }
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) { cronSay(data.error || ('could not read the jobs (' + r.status + ')'), true); return; }
cronJobs = data.jobs || [];
cronNow = data.now_ms || Date.now();
cronFile.textContent = data.jobs_file || '';
if (cronBusy.size) {
for (const job of cronJobs) {
if (cronBusy.has(job.name) && job.last_started_ms && job.last_started_ms > job.last_finished_ms) {
cronBusy.delete(job.name);
}
}
}
renderCron();
if (!quiet) cronSay('');
}
async function runNow(name) {
cronBusy.add(name);
renderCron();
let r;
try { r = await write('POST', '/api/cron/' + encodeURIComponent(name) + '/run'); }
catch (e) { cronBusy.delete(name); renderCron(); return cronSay('the dashboard is not answering', true); }
const data = await r.json().catch(() => ({}));
if (!r.ok) { cronBusy.delete(name); renderCron(); return cronSay(data.error || 'could not start it', true); }
cronSay('started ' + name + ' — the answer lands in its run log');
setTimeout(() => loadCron(true), 2500);
setTimeout(() => loadCron(true), 8000);
}
async function toggleJob(name, enabled) {
const r = await write('POST', '/api/cron/' + encodeURIComponent(name) + '/enabled', { enabled });
const data = await r.json().catch(() => ({}));
if (!r.ok) return cronSay(data.error || 'could not change it', true);
cronSay((enabled ? 'enabled ' : 'disabled ') + name);
loadCron(true);
}
async function removeJob(name) {
if (!confirm('remove the job “' + name + '”? its run logs stay on disk.')) return;
const r = await write('DELETE', '/api/cron/' + encodeURIComponent(name));
const data = await r.json().catch(() => ({}));
if (!r.ok) return cronSay(data.error || 'could not remove it', true);
if (cronEditingName === name) cancelForm();
if (!cronLogsBox.hidden && cronLogsBox.dataset.job === name) cronLogsBox.hidden = true;
cronSay('removed ' + name);
loadCron(true);
}
async function showLogs(name) {
const r = await fetch('/api/cron/' + encodeURIComponent(name) + '/logs?limit=3');
const data = await r.json().catch(() => ({}));
if (!r.ok) return cronSay(data.error || 'could not read its logs', true);
cronLogsBox.textContent = '';
cronLogsBox.dataset.job = name;
const h = document.createElement('h3');
h.textContent = 'last runs · ' + name;
cronLogsBox.appendChild(h);
const runs = data.runs || [];
if (!runs.length) {
const p = document.createElement('div');
p.className = 'when';
p.textContent = 'no runs yet — “run” starts one now';
cronLogsBox.appendChild(p);
}
for (const run of runs) {
const art = document.createElement('article');
const body = run.text.indexOf('---\n') >= 0 ? run.text.slice(run.text.indexOf('---\n') + 4) : run.text;
const at = document.createElement('div');
at.className = 'at';
at.textContent = run.at;
art.appendChild(at);
const pre = document.createElement('pre');
pre.textContent = body.trim() || run.answer || '(no output)';
art.appendChild(pre);
if (run.truncated) {
const more = document.createElement('div');
more.className = 'more';
more.textContent = 'showing the first ' + body.trim().length + ' of ' + run.chars +
' characters — the rest is in ' + run.path;
art.appendChild(more);
}
cronLogsBox.appendChild(art);
}
const where = document.createElement('div');
where.className = 'at';
where.textContent = data.runs_dir;
cronLogsBox.appendChild(where);
cronLogsBox.hidden = false;
}
function editJob(job) {
cronEditingName = job.name;
crName.value = job.name;
crName.disabled = true; crSchedule.value = job.schedule;
crPrompt.value = job.prompt;
crWorkdir.value = job.workdir || '';
crEditing.textContent = 'editing “' + job.name + '”';
cronForm.hidden = false;
cronPane.scrollTop = 0;
crSchedule.focus();
}
function cancelForm() {
cronEditingName = null;
cronForm.hidden = true;
crName.disabled = false;
cronForm.reset();
crEditing.textContent = '';
}
cronForm.addEventListener('submit', async e => {
e.preventDefault();
const body = {
name: crName.value.trim(),
schedule: crSchedule.value.trim(),
prompt: crPrompt.value,
workdir: crWorkdir.value.trim() || null,
};
const r = cronEditingName
? await write('PUT', '/api/cron/' + encodeURIComponent(cronEditingName), body)
: await write('POST', '/api/cron', body);
const data = await r.json().catch(() => ({}));
if (!r.ok) return cronSay(data.error || 'could not save it', true);
cronSay((cronEditingName ? 'saved ' : 'added ') + data.name + ' (' + data.schedule + ')');
cancelForm();
loadCron(true);
});
document.getElementById('croncancel').addEventListener('click', cancelForm);
document.getElementById('cronrefresh').addEventListener('click', () => loadCron());
document.getElementById('cronnew').addEventListener('click', () => {
cancelForm();
cronForm.hidden = false;
crEditing.textContent = '';
crName.focus();
});
function setView(view) {
const cron = view === 'cron';
const mcp = view === 'mcp';
const problems = view === 'problems';
const bots = view === 'bots' && Boolean(botsBtn);
const flares = view === 'flares' && Boolean(flaresBtn);
cronOpen = cron;
mcpOpen = mcp;
problemsOpen = problems;
botsOpen = bots;
flaresOpen = flares;
cronPane.hidden = !cron;
mcpPane.hidden = !mcp;
problemsPane.hidden = !problems;
if (botsPane) botsPane.hidden = !bots;
if (flaresPane) flaresPane.hidden = !flares;
document.querySelector('main').classList.toggle('cron', cron);
document.querySelector('main').classList.toggle('mcp', mcp);
document.querySelector('main').classList.toggle('problems', problems);
document.querySelector('main').classList.toggle('bots', bots);
document.querySelector('main').classList.toggle('flares', flares);
cronBtn.classList.toggle('on', cron);
mcpBtn.classList.toggle('on', mcp);
problemsBtn.classList.toggle('on', problems);
if (botsBtn) botsBtn.classList.toggle('on', bots);
if (flaresBtn) flaresBtn.classList.toggle('on', flares);
cronBtn.setAttribute('aria-expanded', String(cron));
mcpBtn.setAttribute('aria-expanded', String(mcp));
problemsBtn.setAttribute('aria-expanded', String(problems));
if (botsBtn) botsBtn.setAttribute('aria-expanded', String(bots));
if (flaresBtn) flaresBtn.setAttribute('aria-expanded', String(flares));
if (cron) loadCron(); else cancelForm();
if (mcp) loadMcp(); else cancelMcpForm();
if (problems) loadProblems();
if (bots) loadBots();
if (flares) loadFlares();
}
const problemsBtn = document.getElementById('problems');
const problemsPane = document.getElementById('problemspane');
const problemsRows = document.getElementById('problemsrows');
const problemsMsg = document.getElementById('problemsmsg');
const problemsSummary = document.getElementById('problemssummary');
const problemsChecked = document.getElementById('problemschecked');
let problemsOpen = false;
let problemsCount = 0;
function problemsSay(text, bad) {
problemsMsg.textContent = text || '';
problemsMsg.className = bad ? 'bad' : '';
}
function problemsBadge(count) {
problemsCount = count;
problemsBtn.textContent = count ? 'problems (' + count + ')' : 'problems';
problemsBtn.classList.toggle('has', count > 0);
}
function renderProblems(data) {
problemsRows.textContent = '';
const problems = data.problems || [];
const configError = data.config_error;
problemsSummary.textContent = data.summary || '';
problemsBadge(problems.length + (configError ? 1 : 0));
if (configError) {
const tr = document.createElement('tr');
const kind = document.createElement('td');
kind.className = 'kind';
kind.textContent = 'config';
const what = document.createElement('td');
what.className = 'what';
what.textContent = configError;
const where = document.createElement('td');
where.className = 'path';
tr.appendChild(kind); tr.appendChild(what); tr.appendChild(where);
problemsRows.appendChild(tr);
}
if (!problems.length && !configError) {
const tr = document.createElement('tr');
const td = document.createElement('td');
td.colSpan = 3;
td.className = 'none';
td.textContent = data.summary || 'nothing to fix';
tr.appendChild(td);
problemsRows.appendChild(tr);
}
for (const p of problems) {
const tr = document.createElement('tr');
const kind = document.createElement('td');
kind.className = 'kind';
kind.textContent = p.kind || '';
const what = document.createElement('td');
what.className = 'what';
what.textContent = p.text || '';
const where = document.createElement('td');
where.className = 'path';
where.textContent = p.path || '';
tr.appendChild(kind); tr.appendChild(what); tr.appendChild(where);
problemsRows.appendChild(tr);
}
const checked = data.checked || [];
problemsChecked.textContent = checked.length
? 'checked:\n ' + checked.join('\n ')
: 'nothing to check — no plugin directory and no skills root was found';
}
async function loadProblems(quiet) {
let r;
try { r = await fetch('/api/problems'); } catch (e) {
if (!quiet) problemsSay('the dashboard is not answering', true);
return;
}
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) {
problemsSay(data.error || ('could not read the loaders\' report (' + r.status + ')'), true);
return;
}
if (!quiet) problemsSay('');
renderProblems(data);
}
function showProblems(open) { setView(open ? 'problems' : 'session'); }
problemsBtn.addEventListener('click', () => showProblems(!problemsOpen));
document.getElementById('problemsrefresh').addEventListener('click', () => loadProblems());
var botsBtn = document.getElementById('bots');
var botsPane = document.getElementById('botspane');
var botsRows = document.getElementById('botsrows');
var botsMsg = document.getElementById('botsmsg');
var botsFile = document.getElementById('botsfile');
var botsPrompt = document.getElementById('botsprompt');
var botsOpen = false;
function botsSay(text, bad) {
if (!botsMsg) return;
botsMsg.textContent = text || '';
botsMsg.className = bad ? 'bad' : '';
}
async function botWrite(name, act, body) {
const url = '/api/bots/' + encodeURIComponent(name) + '/' + act;
let r;
try { r = await post(url, body); }
catch (e) { botsSay(String(e), true); return null; }
if (r.status === 401) { location.reload(); return null; }
const data = await r.json().catch(() => ({}));
if (!r.ok) { botsSay(data.error || ('HTTP ' + r.status), true); return null; }
return data;
}
function renderBots(bots) {
if (!botsRows) return;
botsRows.textContent = '';
if (botsPrompt) { botsPrompt.hidden = true; botsPrompt.textContent = ''; }
if (!bots.length) {
const tr = document.createElement('tr');
const td = document.createElement('td');
td.colSpan = 5;
td.className = 'when';
td.textContent = 'no bots are declared — add a [bots.<name>] section to the config file';
tr.appendChild(td);
botsRows.appendChild(tr);
return;
}
if (botsFile) botsFile.textContent = bots.length + ' declared';
for (const bot of bots) {
const tr = document.createElement('tr');
tr.dataset.name = bot.name;
const name = document.createElement('td');
name.className = 'name';
name.textContent = bot.name;
const lane = document.createElement('td');
lane.textContent = bot.lane;
const last = document.createElement('td');
last.textContent = bot.last_activity_ms ? agoWords(bot.last_activity_ms) : 'never';
const said = document.createElement('td');
if (bot.problem) {
said.textContent = bot.problem;
said.className = 'bad';
} else {
said.textContent = bot.messages + ' msg' + (bot.messages === 1 ? '' : 's') +
(bot.sessions > 1 ? ' · ' + bot.sessions + ' conversations' : '') +
(bot.archived ? ' · cleared' : '');
}
const acts = document.createElement('td');
acts.className = 'acts';
if (!bot.problem) {
acts.appendChild(rowButton('open', 'open this bot\'s conversation',
() => openBot(bot.name), 'go'));
acts.appendChild(rowButton('rename', 'name this bot\'s conversation',
() => renameBot(bot.name)));
acts.appendChild(rowButton('clear', 'file this conversation away and start a fresh one',
() => clearBot(bot.name), 'bad'));
}
acts.appendChild(rowButton('prompt', 'the instructions this bot runs with',
() => showBotPrompt(bot.name)));
tr.appendChild(name); tr.appendChild(lane); tr.appendChild(last);
tr.appendChild(said); tr.appendChild(acts);
botsRows.appendChild(tr);
}
}
async function loadBots(quiet) {
if (!botsRows) return;
let r;
try { r = await fetch('/api/bots'); } catch (e) {
if (!quiet) botsSay('the dashboard is not answering', true);
return;
}
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ([]));
if (!r.ok) {
botsSay(data.error || ('could not read the bots (' + r.status + ')'), true);
return;
}
if (!quiet) botsSay('');
renderBots(data);
}
async function openBot(name) {
botsSay('opening ' + name + '…');
const data = await botWrite(name, 'open');
if (!data) return;
botsSay('');
await loadSession(data.session_id);
await refreshSessions();
}
async function renameBot(name) {
const typed = window.prompt('Title for this bot\'s conversation', name);
if (typed === null) return;
const title = typed.trim();
if (!title) return;
const data = await botWrite(name, 'rename', { title });
if (!data) return;
botsSay('renamed the ' + name + ' conversation to “' + title + '”');
await loadBots(true);
await refreshSessions();
}
async function clearBot(name) {
if (!window.confirm('File the ' + name + ' conversation away and start a fresh one? The ' +
'transcript stays in the archive; the bot keeps its identity.')) return;
const data = await botWrite(name, 'clear');
if (!data) return;
botsSay('cleared ' + name + ' · ' + data.archived + ' conversation(s) archived');
await loadBots(true);
await refreshSessions();
}
async function showBotPrompt(name) {
let r;
try { r = await fetch('/api/bots/' + encodeURIComponent(name) + '/prompt'); }
catch (e) { return botsSay(String(e), true); }
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) return botsSay(data.error || ('could not read the prompt (' + r.status + ')'), true);
if (!botsPrompt) return;
botsPrompt.textContent = '';
const h = document.createElement('h3');
h.textContent = 'prompt · ' + data.name +
(data.instructions && data.instructions.path ? ' · ' + data.instructions.path : '');
botsPrompt.appendChild(h);
const pre = document.createElement('pre');
if (data.instructions && data.instructions.body) {
pre.textContent = data.instructions.body;
} else if (data.why) {
pre.textContent = data.why;
} else {
pre.textContent = 'this bot declares no instructions — it runs on the agent\'s own prompt, ' +
'with its own memory and the skills it named';
}
botsPrompt.appendChild(pre);
const facts = document.createElement('h3');
facts.textContent = 'declaration';
botsPrompt.appendChild(facts);
const decl = document.createElement('pre');
const skills = data.skills ? (data.skills.join(', ') || '(none)') : '(every root)';
decl.textContent = 'lane: ' + (data.adapter || 'web') +
'\nmemory: ' + (data.memory || '(none)') +
'\nskills: ' + skills +
(data.problem ? '\nproblem: ' + data.problem : '');
botsPrompt.appendChild(decl);
botsPrompt.hidden = false;
}
if (botsBtn) {
botsBtn.addEventListener('click', () => setView(botsOpen ? 'session' : 'bots'));
const botsRefresh = document.getElementById('botsrefresh');
if (botsRefresh) botsRefresh.addEventListener('click', () => loadBots());
}
var flaresBtn = document.getElementById('flares');
var flaresPane = document.getElementById('flarespane');
var flaresRows = document.getElementById('flarerows');
var flaresMsg = document.getElementById('flaresmsg');
var flaresFile = document.getElementById('flaresfile');
var flaresOpen = false;
function flaresSay(text, bad) {
if (!flaresMsg) return;
flaresMsg.textContent = text || '';
flaresMsg.className = bad ? 'bad' : '';
}
function flareTokens(n) {
return (typeof n === 'number' && isFinite(n) && n >= 0) ? tokens(n) : '?';
}
function flareCost(iters, prompt, completion) {
return iters + (iters === 1 ? ' iteration' : ' iterations') +
' · ' + flareTokens(prompt) + ' prompt / ' + flareTokens(completion) + ' completion';
}
function flareSpan(text, cls) {
const s = document.createElement('span');
s.className = cls;
s.textContent = text;
return s;
}
function renderFlares(runs) {
if (!flaresRows) return;
flaresRows.textContent = '';
if (flaresFile) {
flaresFile.textContent = runs.length + (runs.length === 1 ? ' run' : ' runs') +
(runs.length === 50 ? ' · the newest 50' : '');
}
if (!runs.length) {
const tr = document.createElement('tr');
const td = cronCell(document.createElement('td'),
'no flare runs on the ledger — `eclipse flares run "…"` starts one', 'when');
td.colSpan = 7;
tr.appendChild(td);
flaresRows.appendChild(tr);
return;
}
for (const run of runs) {
const tr = document.createElement('tr');
tr.dataset.run = run.id;
const id = flareCell(run.id, 'run');
if (run.task) {
const task = flareSpan(run.task, 'task');
task.title = run.task;
id.appendChild(task);
}
const age = flareCell(ago(run.started_ms), 'age');
age.title = run.finished_ms
? 'started ' + ago(run.started_ms) + ', finished ' + ago(run.finished_ms)
: 'started ' + ago(run.started_ms) + ', still going';
const routes = flareCell(run.routes.join(', ') || '?', 'routes');
if (run.parent) routes.title = 'led from session ' + run.parent;
const cost = flareCell(
flareCost(run.iterations, run.prompt_tokens, run.completion_tokens), 'cost');
if (run.running) {
cost.title = 'a run still going has counted only the children that finished';
}
const acts = document.createElement('td');
acts.className = 'acts';
const children = rowButton('children',
'the flares this run started — each one opens its own transcript',
() => toggleFlare(run, tr, children), 'go');
children.setAttribute('aria-expanded', 'false');
acts.appendChild(children);
if (run.running) {
acts.appendChild(rowButton('cancel',
'drop the queued flares and stop the running ones at their next boundary',
() => cancelFlare(run), 'bad'));
}
tr.appendChild(id);
tr.appendChild(flareCell(run.state, 'state ' + run.state));
tr.appendChild(age);
tr.appendChild(routes);
tr.appendChild(flareCell(String(run.jobs), 'jobs'));
tr.appendChild(cost);
tr.appendChild(acts);
flaresRows.appendChild(tr);
}
}
function flareCell(text, cls) {
return cronCell(document.createElement('td'), text, cls);
}
async function toggleFlare(run, tr, btn) {
const shown = tr.nextElementSibling;
if (shown && shown.classList.contains('jobs')) {
shown.hidden = !shown.hidden;
btn.textContent = shown.hidden ? 'children' : 'hide';
btn.setAttribute('aria-expanded', String(!shown.hidden));
return;
}
btn.disabled = true;
let r;
try { r = await fetch('/api/flares/' + encodeURIComponent(run.id)); }
catch (e) { btn.disabled = false; return flaresSay(String(e), true); }
btn.disabled = false;
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) {
flaresSay(data.error || ('could not read the run (' + r.status + ')'), true);
return;
}
const row = document.createElement('tr');
row.className = 'jobs';
const cell = document.createElement('td');
cell.colSpan = 7;
cell.appendChild(flareJobsList(data.jobs || []));
row.appendChild(cell);
tr.insertAdjacentElement('afterend', row);
btn.textContent = 'hide';
btn.setAttribute('aria-expanded', 'true');
}
function flareJobsList(jobs) {
const box = document.createElement('div');
if (!jobs.length) {
const empty = flareSpan('this run has no children on the ledger yet — a cancelled run ' +
'stops before its queue empties', 'empty');
box.appendChild(empty);
return box;
}
for (const job of jobs) {
const line = document.createElement('div');
line.className = 'job';
line.appendChild(flareSpan(job.n + '.', 'n'));
line.appendChild(flareSpan(job.state, 'state ' + job.state));
line.appendChild(flareSpan(job.route, 'route'));
if (job.session_id) {
line.appendChild(rowButton('open session',
'open this flare\'s transcript — the same view every session opens in',
() => loadSession(job.session_id), 'go'));
const cost = document.createElement('small');
cost.textContent = flareCost(job.iterations, job.prompt_tokens, job.completion_tokens);
line.appendChild(cost);
} else {
const why = document.createElement('small');
why.className = 'why';
why.textContent = job.why || 'never ran — no session, no cost';
line.appendChild(why);
}
if (job.session_id && job.why) {
const why = document.createElement('small');
why.className = 'why';
why.textContent = job.why;
line.appendChild(why);
}
box.appendChild(line);
}
return box;
}
async function loadFlares(quiet) {
if (!flaresRows) return;
let r;
try { r = await fetch('/api/flares'); } catch (e) {
if (!quiet) flaresSay('the dashboard is not answering', true);
return;
}
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ([]));
if (!r.ok) {
flaresSay(data.error || ('could not read the flare runs (' + r.status + ')'), true);
return;
}
if (!quiet) flaresSay('');
renderFlares(data);
}
async function cancelFlare(run) {
if (!window.confirm('Ask run ' + run.id + ' to stop? Queued flares are dropped before they ' +
'start; a running one ends at its next boundary.')) return;
flaresSay('asking ' + run.id + ' to stop…');
let r;
try { r = await post('/api/flares/' + encodeURIComponent(run.id) + '/cancel'); }
catch (e) { return flaresSay(String(e), true); }
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) return flaresSay(data.error || ('HTTP ' + r.status), true);
flaresSay(data.note || 'cancel requested');
await loadFlares(true);
}
if (flaresBtn) {
flaresBtn.addEventListener('click', () => setView(flaresOpen ? 'session' : 'flares'));
const flaresRefresh = document.getElementById('flaresrefresh');
if (flaresRefresh) flaresRefresh.addEventListener('click', () => loadFlares());
}
function showCron(open) { setView(open ? 'cron' : 'session'); }
cronBtn.addEventListener('click', () => showCron(!cronOpen));
setInterval(() => { if (cronOpen) loadCron(true); }, 10000);
const mcpBtn = document.getElementById('mcp');
const mcpPane = document.getElementById('mcppane');
const mcpRows = document.getElementById('mcprows');
const mcpMsg = document.getElementById('mcpmsg');
const mcpFile = document.getElementById('mcpfile');
const mcpForm = document.getElementById('mcpform');
const mpName = document.getElementById('mp-name');
const mpTransport = document.getElementById('mp-transport');
const mpUrl = document.getElementById('mp-url');
const mpCommand = document.getElementById('mp-command');
const mpArgs = document.getElementById('mp-args');
const mpPrefix = document.getElementById('mp-prefix');
const mpPolicy = document.getElementById('mp-policy');
const mpToken = document.getElementById('mp-token');
const mpEditing = document.getElementById('mpediting');
const mcpSave = document.getElementById('mcpsave');
let mcpOpen = false;
let mcpServers = [];
let mcpBusy = new Set(); let mcpEditingName = null;
function mcpSay(text, bad) {
mcpMsg.textContent = text || '';
mcpMsg.className = bad ? 'bad' : '';
}
function mcpCell(td, text, cls) {
td.textContent = text;
if (cls) td.className = cls;
return td;
}
function replaceServer(row) {
const i = mcpServers.findIndex(s => s.name === row.name);
if (i >= 0) mcpServers[i] = row;
else mcpServers.push(row);
renderMcp();
}
function renderMcp() {
mcpRows.textContent = '';
if (!mcpServers.length) {
const tr = document.createElement('tr');
const td = document.createElement('td');
td.colSpan = 6;
td.className = 'when';
td.textContent = 'no MCP server is configured — “+ add server” writes the first entry';
tr.appendChild(td);
mcpRows.appendChild(tr);
return;
}
for (const s of mcpServers) {
const tr = document.createElement('tr');
if (s.disabled) tr.className = 'off';
tr.appendChild(mcpCell(document.createElement('td'), s.name, 'name'));
tr.appendChild(mcpCell(document.createElement('td'), s.source, 'when'));
tr.appendChild(mcpCell(document.createElement('td'),
s.disabled ? 'off' : (s.error ? 'failed' : String(s.tools)), 'when'));
tr.appendChild(mcpCell(document.createElement('td'), s.command, 'cmd'));
const tokenTd = document.createElement('td');
tokenTd.className = 'token' + (s.token === 'unset' ? ' unset' : '');
if (s.token_env) {
tokenTd.textContent = s.token_env + ': ' + s.token;
tokenTd.title = s.token === 'unset'
? s.token_env + ' is set neither in the environment nor in .env, so this server cannot authenticate'
: 'the token is read from ' + (s.token === '.env' ? 'the .env file' : 'the environment');
} else {
tokenTd.textContent = '—';
tokenTd.title = 'the entry asks for no token';
}
tr.appendChild(tokenTd);
let state = s.disabled ? 'off' : (s.error ? 'failed' : 'ok');
if (s.tested && !s.disabled && !s.error) {
state = 'protocol ' + (s.protocol || '(not reported)') + ' · ' + s.tools + ' tool(s)';
}
const stateTd = mcpCell(document.createElement('td'), state,
'state ' + (s.error ? 'failed' : s.disabled ? '' : 'ok'));
if (s.error) stateTd.title = s.error;
tr.appendChild(stateTd);
const acts = document.createElement('td');
acts.className = 'acts';
const testing = mcpBusy.has(s.name);
const test = rowButton(testing ? 'testing…' : 'test',
'start it and report what it answers: the protocol, the tool count, or the reason it failed',
() => testServer(s.name), 'go');
test.disabled = testing || Boolean(s.disabled);
acts.appendChild(test);
acts.appendChild(rowButton('edit',
'change this entry — the form opens with what the file says',
() => editServer(s)));
acts.appendChild(rowButton(s.disabled ? 'on' : 'off',
s.disabled ? 'clear disabled, so the next run starts it' : 'write disabled = true; the entry stays',
() => toggleServer(s.name, s.disabled)));
acts.appendChild(rowButton('remove', 'delete the entry from config.toml',
() => removeServer(s.name), 'bad'));
tr.appendChild(acts);
mcpRows.appendChild(tr);
}
}
async function loadMcp(quiet) {
let r;
try { r = await fetch('/api/mcp'); } catch (e) { mcpSay('the dashboard is not answering', true); return; }
if (r.status === 401) return location.reload();
const data = await r.json().catch(() => ({}));
if (!r.ok) { mcpSay(data.error || ('could not read the entries (' + r.status + ')'), true); return; }
mcpServers = data.servers || [];
mcpFile.textContent = data.config_path || '';
renderMcp();
const problems = data.problems || [];
if (problems.length) mcpSay(problems.join(' · '));
else if (!quiet) mcpSay('');
}
async function toggleServer(name, wasDisabled) {
const r = await write('POST', '/api/mcp/' + encodeURIComponent(name) + '/enabled',
{ enabled: wasDisabled });
const data = await r.json().catch(() => ({}));
if (!r.ok) return mcpSay(data.error || 'could not change it', true);
replaceServer(data);
mcpSay((wasDisabled ? 'enabled ' : 'disabled ') + name);
}
async function testServer(name) {
mcpBusy.add(name);
renderMcp();
let r;
try { r = await write('POST', '/api/mcp/' + encodeURIComponent(name) + '/test'); }
catch (e) { mcpBusy.delete(name); renderMcp(); return mcpSay('the dashboard is not answering', true); }
const data = await r.json().catch(() => ({}));
mcpBusy.delete(name);
if (!r.ok) { renderMcp(); return mcpSay(data.error || 'could not run the test', true); }
data.tested = true;
replaceServer(data);
mcpSay(data.error ? name + ': ' + data.error :
name + ' speaks protocol ' + (data.protocol || '(not reported)') +
' and lists ' + data.tools + ' tool(s)');
}
async function removeServer(name) {
if (!confirm('remove the entry “' + name + '”? the other entries and their comments stay.')) return;
const r = await write('DELETE', '/api/mcp/' + encodeURIComponent(name));
const data = await r.json().catch(() => ({}));
if (!r.ok) return mcpSay(data.error || 'could not remove it', true);
mcpServers = mcpServers.filter(s => s.name !== name);
if (mpName.value.trim() === name) cancelMcpForm();
mcpSay('removed ' + name);
renderMcp();
}
function editServer(s) {
mcpEditingName = s.name;
mpName.value = s.name;
mpName.readOnly = true;
mpTransport.value = s.transport || '';
mpUrl.value = s.url || '';
mpCommand.value = s.program || '';
mpArgs.value = (s.args || []).join(' ');
mpPrefix.value = s.prefix || '';
mpPolicy.value = s.policy || '';
mpToken.value = s.token_env || '';
mpEditing.textContent = 'editing “' + s.name + '”';
mcpSave.textContent = 'save';
mcpForm.hidden = false;
mcpPane.scrollTop = 0;
mpUrl.focus();
}
function cancelMcpForm() {
mcpEditingName = null;
mcpForm.hidden = true;
mcpForm.reset();
mpName.readOnly = false;
mpEditing.textContent = '';
mcpSave.textContent = 'save';
}
mcpForm.addEventListener('submit', async e => {
e.preventDefault();
const args = mpArgs.value.trim();
const body = {
name: mpName.value.trim(),
transport: mpTransport.value || null,
url: mpUrl.value.trim() || null,
command: mpCommand.value.trim() || null,
args: args ? args.split(/\s+/) : null,
prefix: mpPrefix.value.trim() || null,
policy: mpPolicy.value || null,
token_env: mpToken.value.trim() || null,
};
const editing = mcpEditingName;
const r = await write(editing ? 'PUT' : 'POST',
editing ? '/api/mcp/' + encodeURIComponent(editing) : '/api/mcp', body);
const data = await r.json().catch(() => ({}));
if (!r.ok) return mcpSay(data.error || 'could not save it', true);
cancelMcpForm();
replaceServer(data);
mcpSay((editing ? 'updated ' : 'added ') + data.name + ' (' + data.source + ')');
});
document.getElementById('mcpcancel').addEventListener('click', cancelMcpForm);
document.getElementById('mcprefresh').addEventListener('click', () => loadMcp());
document.getElementById('mcpnew').addEventListener('click', () => {
cancelMcpForm();
mcpForm.hidden = false;
mpName.focus();
});
function showMcp(open) { setView(open ? 'mcp' : 'session'); }
mcpBtn.addEventListener('click', () => showMcp(!mcpOpen));
refreshSessions();
loadProblems(true);
})();
</script>
</body>
</html>