@gorlitzer-labs/seldon 0.17.1 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,351 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
6
- <meta name="theme-color" content="#0e0f0c">
7
- <meta name="apple-mobile-web-app-capable" content="yes">
8
- <link rel="manifest" href="/manifest.webmanifest">
9
- <title>seldon</title>
10
- <style>
11
- :root {
12
- --bg: #f4f2ec; --card: #fffdf8; --ink: #1b1c18; --mute: #6d6c64; --line: #e2dfd5;
13
- --need: #c2410c; --need-bg: #fdecdf; --work: #2f7d4f; --idle: #8b8a80; --fail: #b42318; --accent: #1b1c18;
14
- --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
15
- --sans: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
16
- --r: 14px; --safe-b: env(safe-area-inset-bottom, 0px);
17
- }
18
- @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
19
- --bg: #0e0f0c; --card: #171814; --ink: #ecebe4; --mute: #8f8e85; --line: #2a2b25;
20
- --need: #fb923c; --need-bg: #2a1a0e; --work: #5fbf86; --idle: #77766d; --fail: #f87171; --accent: #ecebe4;
21
- } }
22
- :root[data-theme="dark"] {
23
- --bg: #0e0f0c; --card: #171814; --ink: #ecebe4; --mute: #8f8e85; --line: #2a2b25;
24
- --need: #fb923c; --need-bg: #2a1a0e; --work: #5fbf86; --idle: #77766d; --fail: #f87171; --accent: #ecebe4;
25
- }
26
- * { box-sizing: border-box; }
27
- html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 var(--sans); -webkit-text-size-adjust: 100%; }
28
- button, input, textarea, select { font: inherit; color: inherit; }
29
- button { cursor: pointer; }
30
- .wrap { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + var(--safe-b)); }
31
-
32
- /* top */
33
- header { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px);
34
- padding: calc(10px + env(safe-area-inset-top, 0px)) 0 10px; border-bottom: 1px solid var(--line); }
35
- .top { display: flex; align-items: baseline; gap: 10px; }
36
- .mark { font: 700 13px/1 var(--mono); letter-spacing: .28em; }
37
- .head { flex: 1; min-width: 0; color: var(--mute); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
38
- .live { width: 8px; height: 8px; border-radius: 50%; background: var(--work); align-self: center; transition: opacity .3s; }
39
- .live.stale { background: var(--fail); }
40
- .chips { display: flex; gap: 8px; overflow-x: auto; margin-top: 10px; scrollbar-width: none; }
41
- .chips::-webkit-scrollbar { display: none; }
42
- .chip { flex: none; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
43
- display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
44
- .chip[aria-pressed="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
45
- .chip .n { font: 600 12px var(--mono); }
46
- .chip.need .n { color: var(--need); }
47
- .chip[aria-pressed="true"].need .n { color: inherit; }
48
- .chip .dot { width: 7px; height: 7px; }
49
-
50
- .holds { margin: 12px 0 0; font: 12px var(--mono); color: var(--mute); }
51
- .holds b { color: var(--ink); font-weight: 600; }
52
-
53
- /* projects + lanes */
54
- section.proj { margin-top: 18px; }
55
- .ph { display: flex; align-items: center; gap: 8px; min-height: 44px; }
56
- .ph h2 { margin: 0; font-size: 15px; font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
57
- .ph .at { font: 12px var(--mono); color: var(--mute); flex: none; }
58
- .ph .sp { flex: 1; }
59
- .ghost { min-height: 44px; min-width: 44px; padding: 0 12px; border: 0; background: none; color: var(--mute); font-size: 13px; border-radius: 10px; }
60
- .ghost:active { background: var(--line); }
61
- .card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
62
- .lane { display: grid; grid-template-columns: 22px 1fr auto; gap: 2px 10px; align-items: center; width: 100%; text-align: left;
63
- padding: 12px 14px; min-height: 60px; border: 0; background: none; border-top: 1px solid var(--line); }
64
- .lane:first-child { border-top: 0; }
65
- .lane:active { background: var(--line); }
66
- .lane.needs-you { background: var(--need-bg); }
67
- .lane .g { grid-row: span 2; display: grid; place-items: center; }
68
- .lane .nm { min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
69
- .lane .ag { font: 12px var(--mono); color: var(--mute); }
70
- .lane .dt { grid-column: 2 / 4; min-width: 0; font-size: 13px; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
71
- .lane.needs-you .dt { color: var(--need); font-weight: 600; }
72
- .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--idle); display: inline-block; flex: none; }
73
- .dot.needs-you { background: var(--need); box-shadow: 0 0 0 4px color-mix(in srgb, var(--need) 25%, transparent); animation: pulse 1.6s infinite; }
74
- .dot.working, .dot.running { background: var(--work); }
75
- .dot.failed { background: var(--fail); }
76
- .dot.stopped { background: transparent; border: 2px solid var(--idle); }
77
- @keyframes pulse { 50% { box-shadow: 0 0 0 7px transparent; } }
78
- @media (prefers-reduced-motion: reduce) { .dot.needs-you { animation: none; } }
79
- .empty { padding: 40px 8px; text-align: center; color: var(--mute); }
80
- .empty p { margin: 6px 0; }
81
-
82
- /* fab */
83
- .fab { position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(18px + var(--safe-b)); z-index: 6; min-height: 52px; padding: 0 20px;
84
- border-radius: 999px; border: 0; background: var(--accent); color: var(--bg); font-weight: 650; box-shadow: 0 6px 24px rgb(0 0 0 / .25); }
85
-
86
- /* sheet */
87
- .scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 10; opacity: 0; pointer-events: none; transition: opacity .2s; }
88
- .scrim.on { opacity: 1; pointer-events: auto; }
89
- .sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-width: 640px; margin: 0 auto; max-height: 92dvh; overflow-y: auto;
90
- background: var(--card); border-radius: 18px 18px 0 0; padding: 8px 16px calc(20px + var(--safe-b)); transform: translateY(105%); transition: transform .22s ease-out; }
91
- .sheet.on { transform: none; }
92
- .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
93
- .sheet h3 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
94
- .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 6px 0 14px; font: 12px var(--mono); color: var(--mute); }
95
- .meta .st { display: inline-flex; gap: 6px; align-items: center; color: var(--ink); }
96
- .screen { background: #0b0c0a; color: #d8d6cc; font: 11.5px/1.45 var(--mono); border-radius: 10px; padding: 10px 12px; max-height: 42dvh;
97
- overflow: auto; white-space: pre; margin: 0 0 12px; }
98
- .note { font-size: 13px; color: var(--mute); background: var(--bg); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }
99
- .note code { font: 12px var(--mono); color: var(--ink); overflow-wrap: anywhere; }
100
- .keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
101
- .k { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font: 600 14px var(--mono); }
102
- .k:active { background: var(--line); }
103
- .row { display: flex; gap: 8px; }
104
- .row > * { min-width: 0; }
105
- .in { flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 10px 12px; }
106
- textarea.in { min-height: 96px; resize: vertical; width: 100%; }
107
- select.in { width: 100%; }
108
- .btn { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; }
109
- .btn.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
110
- .btn.danger { color: var(--fail); }
111
- .btn.danger.armed { background: var(--fail); color: #fff; border-color: var(--fail); }
112
- .btn:disabled { opacity: .5; }
113
- .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
114
- .actions .btn { flex: 1 1 30%; }
115
- label.f { display: block; font-size: 12px; color: var(--mute); margin: 12px 0 6px; font-weight: 600; letter-spacing: .02em; }
116
- .seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
117
- .seg button { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font: 13px var(--mono); }
118
- .seg button[aria-pressed="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
119
- .plan { list-style: none; margin: 0; padding: 0; }
120
- .plan li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
121
- .plan li:first-child { border-top: 0; }
122
- .plan .pr { font: 600 11px var(--mono); color: var(--mute); flex: none; width: 22px; }
123
- .plan .tx { flex: 1; min-width: 0; font-size: 14px; }
124
- .plan .on { font: 11px var(--mono); color: var(--work); }
125
- .toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + var(--safe-b)); z-index: 20; max-width: 560px; margin: 0 auto;
126
- background: var(--ink); color: var(--bg); padding: 12px 14px; border-radius: 12px; font-size: 14px; opacity: 0; transform: translateY(8px);
127
- transition: .2s; pointer-events: none; }
128
- .toast.on { opacity: 1; transform: none; }
129
- .toast.err { background: var(--fail); color: #fff; }
130
- </style>
131
- </head>
132
- <body>
133
- <header><div class="wrap" style="padding-bottom:0">
134
- <div class="top"><span class="mark">SELDON</span><span class="head" id="head">…</span><span class="live" id="live" title="live"></span></div>
135
- <div class="chips" id="chips" role="toolbar" aria-label="filter"></div>
136
- <div class="holds" id="holds"></div>
137
- </div></header>
138
- <main class="wrap" id="main"></main>
139
- <button class="fab" data-act="new">+ lane</button>
140
- <div class="scrim" id="scrim" data-act="close"></div>
141
- <div class="sheet" id="sheet" role="dialog" aria-modal="true"><div class="grab"></div><div id="sheetBody"></div></div>
142
- <div class="toast" id="toast" role="status"></div>
143
- <script>
144
- "use strict";
145
- const $ = (id) => document.getElementById(id);
146
- const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
147
- const ago = (ms) => { if (!ms) return ""; const s = Math.max(0, (Date.now() - ms) / 1000 | 0);
148
- return s < 60 ? s + "s" : s < 3600 ? (s / 60 | 0) + "m" : s < 86400 ? (s / 3600 | 0) + "h" : (s / 86400 | 0) + "d"; };
149
- const detail = (l) => l.state === "needs-you" ? "needs you: " + (l.waitingFor || "input") : l.state === "running" ? "running (no state reported)" : l.state;
150
-
151
- let S = null, filter = "all", sheet = null, peekTimer = null, lastNeed = -1;
152
- // The token arrives once in the link seldon serve prints (#t=…), is kept on this device, and
153
- // is taken out of the address bar so it never ends up in a screenshot or a shared URL.
154
- const TOKEN = (() => {
155
- const m = location.hash.match(/[#&]t=([A-Za-z0-9_-]+)/);
156
- try { if (m) localStorage.setItem("seldon-token", m[1]); } catch {}
157
- if (m) history.replaceState(null, "", location.pathname);
158
- try { return m?.[1] || localStorage.getItem("seldon-token") || ""; } catch { return m?.[1] || ""; }
159
- })();
160
- const api = async (path, body) => {
161
- const headers = { "x-seldon-token": TOKEN, ...(body ? { "content-type": "application/json" } : {}) };
162
- const r = await fetch(path, body ? { method: "POST", headers, body: JSON.stringify(body) } : { headers });
163
- const j = await r.json().catch(() => ({ ok: false, error: "bad reply (" + r.status + ")" }));
164
- if (r.status === 403) locked(j.error);
165
- return j;
166
- };
167
- function locked(why) {
168
- $("head").textContent = "locked";
169
- $("main").innerHTML = `<div class="empty"><p><b>This device isn't let in.</b></p><p>${esc(why)}</p>
170
- <p>Open the link <code>seldon serve</code> printed in your terminal (it carries the token).</p></div>`;
171
- throw new Error(why);
172
- }
173
- const toast = (msg, err) => { const t = $("toast"); t.textContent = msg; t.className = "toast on" + (err ? " err" : ""); clearTimeout(toast.t); toast.t = setTimeout(() => t.className = "toast", 2600); };
174
- const allLanes = () => S ? S.groups.flatMap((g) => g.lanes.map((l) => ({ ...l, group: g }))) : [];
175
- const laneBy = (key) => allLanes().find((l) => l.key === key);
176
-
177
- // ---- poll -------------------------------------------------------------------------
178
- async function refresh() {
179
- try {
180
- S = await api("/api/state");
181
- $("live").classList.remove("stale");
182
- render();
183
- const need = allLanes().filter((l) => l.state === "needs-you").length;
184
- if (lastNeed >= 0 && need > lastNeed) alertNeed(need);
185
- lastNeed = need;
186
- document.title = need ? `(${need}) seldon` : "seldon";
187
- if (sheet?.type === "lane") renderLaneSheet(false);
188
- } catch { $("live").classList.add("stale"); }
189
- }
190
- function alertNeed(n) {
191
- navigator.vibrate?.(120);
192
- if (document.hidden && "Notification" in window && Notification.permission === "granted")
193
- new Notification("seldon", { body: n === 1 ? "an agent needs you" : n + " agents need you", tag: "seldon-need" });
194
- }
195
-
196
- // ---- render -----------------------------------------------------------------------
197
- function render() {
198
- $("head").textContent = S.headline;
199
- const lanes = allLanes(), need = lanes.filter((l) => l.state === "needs-you").length;
200
- const chips = [["all", "All", lanes.length, ""], ["need", "Needs you", need, "need"], ["here", "this mac", S.groups.filter((g) => !g.machine).reduce((a, g) => a + g.lanes.length, 0), ""],
201
- ...S.machines.map((m) => ["m:" + m.name, m.name, m.ok ? m.count : "—", m.ok ? "" : "off"])];
202
- $("chips").innerHTML = chips.map(([id, label, n, cls]) =>
203
- `<button class="chip ${cls}" data-act="filter" data-id="${esc(id)}" aria-pressed="${filter === id}">${cls === "off" ? '<span class="dot failed"></span>' : ""}${esc(label)} <span class="n">${esc(n)}</span></button>`).join("");
204
- $("holds").innerHTML = S.holds?.length ? "held: " + S.holds.map((h) => `<b>${esc(h.name)}</b> → ${esc(h.who)}`).join(" · ") : "";
205
-
206
- const groups = S.groups.map((g) => ({ ...g, lanes: g.lanes.filter((l) =>
207
- filter === "need" ? l.state === "needs-you" : filter === "here" ? !g.machine : filter.startsWith("m:") ? g.machine === filter.slice(2) : true) }))
208
- .filter((g) => g.lanes.length);
209
- $("main").innerHTML = groups.length ? groups.map((g) => `
210
- <section class="proj">
211
- <div class="ph"><h2>${esc(g.lanes[0].projectName || g.name.replace(/ @.*/, ""))}</h2>${g.machine ? `<span class="at">@${esc(g.machine)}</span>` : ""}<span class="sp"></span>
212
- <button class="ghost" data-act="plan" data-root="${esc(g.remoteRoot || g.root)}" data-machine="${esc(g.machine || "")}">plan</button>
213
- <button class="ghost" data-act="new" data-root="${esc(g.remoteRoot || g.root)}" data-machine="${esc(g.machine || "")}" aria-label="new lane here">+</button></div>
214
- <div class="card">${g.lanes.map((l) => `
215
- <button class="lane ${esc(l.state)}" data-act="lane" data-key="${esc(l.key)}">
216
- <span class="g"><span class="dot ${esc(l.state)}"></span></span>
217
- <span class="nm">${esc(l.name || l.id || "?")}</span><span class="ag">${esc(l.harness)} ${esc(ago(l.startedAt))}</span>
218
- <span class="dt">${esc(detail(l))}</span>
219
- </button>`).join("")}</div>
220
- </section>`).join("")
221
- : `<div class="empty"><p><b>${filter === "need" ? "Nobody needs you." : "No agents here."}</b></p><p>${filter === "need" ? "You'll get a buzz when one does." : "Start one with + lane."}</p></div>`;
222
- }
223
-
224
- // ---- sheets -----------------------------------------------------------------------
225
- function open(type, data) { sheet = { type, ...data }; $("scrim").classList.add("on"); $("sheet").classList.add("on"); }
226
- function close() { sheet = null; clearInterval(peekTimer); $("scrim").classList.remove("on"); $("sheet").classList.remove("on"); }
227
-
228
- function renderLaneSheet(full = true) {
229
- const l = laneBy(sheet.key);
230
- if (!l) { $("sheetBody").innerHTML = `<h3>Lane ended</h3><p class="note">It is no longer listed.</p>`; return; }
231
- const c = l.caps || {};
232
- const head = `<h3>${esc(l.name || l.id)}</h3>
233
- <div class="meta"><span class="st"><span class="dot ${esc(l.state)}"></span>${esc(detail(l))}</span><span>${esc(l.harness)}</span>
234
- <span>${esc(l.group.lanes[0].projectName || l.group.name)}${l.group.machine ? " @" + esc(l.group.machine) : ""}</span><span>${esc(ago(l.startedAt))}</span></div>`;
235
- if (!full) { $("sheetBody").querySelector(".lanehead").innerHTML = head; return; }
236
- $("sheetBody").innerHTML = `<div class="lanehead">${head}</div>
237
- ${c.peek ? `<pre class="screen" id="screen">reading the screen…</pre>` : ""}
238
- ${c.hint ? `<p class="note">No terminal pane to read for this lane. Open it with <code>${esc(c.hint)}</code>, or from the Claude app via Remote Control.</p>` : ""}
239
- ${c.reply && S.allowReply ? `
240
- <div class="keys">${["1", "2", "3", "y"].map((k) => `<button class="k" data-act="text" data-v="${k}">${k}</button>`).join("")}
241
- ${[["enter", "⏎"], ["esc", "esc"], ["up", "↑"], ["down", "↓"]].map(([k, v]) => `<button class="k" data-act="key" data-v="${k}">${v}</button>`).join("")}</div>
242
- <form class="row" data-form="reply"><input class="in" name="t" placeholder="reply to the agent…" autocomplete="off" enterkeyhint="send"><button class="btn primary">Send</button></form>`
243
- : c.reply ? `<p class="note">Read-only. To answer from here, start it with <code>seldon serve --allow-reply</code>.</p>` : ""}
244
- <div class="actions">
245
- ${c.stop ? `<button class="btn danger" data-act="stop">Stop</button>` : ""}
246
- ${c.resume ? `<button class="btn primary" data-act="resume">Resume</button>` : ""}
247
- ${c.rm ? `<button class="btn danger" data-act="rm">Remove</button>` : ""}
248
- <button class="btn" data-act="close">Close</button>
249
- </div>`;
250
- clearInterval(peekTimer);
251
- if (c.peek) { peek(); peekTimer = setInterval(peek, 2000); }
252
- }
253
- async function peek() {
254
- const el = $("screen"); if (!el || !sheet) return;
255
- const r = await api("/api/peek?key=" + encodeURIComponent(sheet.key));
256
- const atBottom = el.scrollTop + el.clientHeight >= el.scrollHeight - 8;
257
- el.textContent = r.ok ? (r.screen || "(empty)") : r.error;
258
- if (atBottom) el.scrollTop = el.scrollHeight;
259
- }
260
-
261
- function projects() {
262
- return S.groups.map((g) => ({ root: g.remoteRoot || g.root, machine: g.machine || "", label: (g.lanes[0]?.projectName || g.name.replace(/ @.*/, "")) + (g.machine ? " @" + g.machine : "") }));
263
- }
264
- function renderNew(d) {
265
- const ps = projects(); const pick = ps.find((p) => p.root === d.root && p.machine === (d.machine || "")) || ps[0];
266
- sheet.agent = sheet.agent || "claude";
267
- $("sheetBody").innerHTML = `<h3>New lane</h3>
268
- <form data-form="start">
269
- <label class="f">Project</label>
270
- <select class="in" name="p">${ps.map((p, i) => `<option value="${i}" ${p === pick ? "selected" : ""}>${esc(p.label)}</option>`).join("")}</select>
271
- <label class="f">Task</label>
272
- <textarea class="in" name="task" placeholder="fix the save crash">${esc(d.task || "")}</textarea>
273
- <label class="f">Agent</label>
274
- <div class="seg">${["claude", "codex", "opencode"].map((a) => `<button type="button" data-act="agent" data-v="${a}" aria-pressed="${sheet.agent === a}">${a}</button>`).join("")}</div>
275
- <div class="actions"><button class="btn primary">Start lane</button><button type="button" class="btn" data-act="close">Cancel</button></div>
276
- </form>`;
277
- sheet.projects = ps;
278
- }
279
- async function renderPlan() {
280
- $("sheetBody").innerHTML = `<h3>Plan</h3><p class="note">reading docs/QUEUE.md…</p>`;
281
- const r = await api(`/api/plan?root=${encodeURIComponent(sheet.root)}&machine=${encodeURIComponent(sheet.machine || "")}`);
282
- if (sheet?.type !== "plan") return;
283
- const items = r.items;
284
- $("sheetBody").innerHTML = `<h3>Plan</h3><div class="meta"><span>${esc(sheet.root)}${sheet.machine ? " @" + esc(sheet.machine) : ""}</span></div>
285
- ${!r.ok ? `<p class="note">${esc(r.error)}</p>` : items == null ? `<p class="note">No plan here (foundation not installed, or no docs/QUEUE.md).</p>`
286
- : !items.length ? `<p class="note">The plan is empty.</p>`
287
- : `<ul class="plan">${items.map((it, i) => `<li><span class="pr">${esc(it.priority || "")}</span><span class="tx">${esc(it.text)}</span>
288
- ${it.lane ? `<span class="on">● ${esc(it.lane)}</span>` : `<button class="btn" data-act="item" data-i="${i}">Start</button>`}</li>`).join("")}</ul>`}
289
- ${!sheet.machine && items ? `<form class="row" data-form="add" style="margin-top:12px"><input class="in" name="t" placeholder="add to the plan…" autocomplete="off"><button class="btn">Add</button></form>` : ""}
290
- <div class="actions"><button class="btn" data-act="close">Close</button></div>`;
291
- sheet.items = items;
292
- }
293
-
294
- // ---- one listener for everything ----------------------------------------------------
295
- async function doLane(verb, btn) {
296
- if (verb !== "resume" && !btn.classList.contains("armed")) { btn.classList.add("armed"); btn.textContent = "Tap again to " + verb.replace("rm", "remove"); setTimeout(() => { btn.classList.remove("armed"); btn.textContent = verb === "rm" ? "Remove" : "Stop"; }, 3000); return; }
297
- btn.disabled = true;
298
- const r = await api("/api/lane/" + verb, { key: sheet.key });
299
- toast(r.ok ? ({ stop: "Stopped", resume: "Resumed", rm: "Removed" }[verb]) : r.error, !r.ok);
300
- if (r.ok && verb !== "resume") close();
301
- refresh();
302
- }
303
- document.addEventListener("click", async (e) => {
304
- const b = e.target.closest("[data-act]"); if (!b) return;
305
- const a = b.dataset.act;
306
- if (a === "filter") { filter = b.dataset.id; render(); }
307
- else if (a === "lane") { open("lane", { key: b.dataset.key }); renderLaneSheet(); maybeAskNotify(); }
308
- else if (a === "new") { open("new", {}); renderNew({ root: b.dataset.root, machine: b.dataset.machine }); }
309
- else if (a === "plan") { open("plan", { root: b.dataset.root, machine: b.dataset.machine }); renderPlan(); }
310
- else if (a === "close") close();
311
- else if (a === "agent") { sheet.agent = b.dataset.v; b.parentElement.querySelectorAll("button").forEach((x) => x.setAttribute("aria-pressed", x === b)); }
312
- else if (["stop", "resume", "rm"].includes(a)) doLane(a, b);
313
- else if (a === "key") reply({ key: b.dataset.v });
314
- else if (a === "text") reply({ text: b.dataset.v, submit: false });
315
- else if (a === "item") { const it = sheet.items[b.dataset.i]; const { root, machine } = sheet; open("new", {}); renderNew({ root, machine, task: it.text }); }
316
- });
317
- async function reply(what) {
318
- const r = await api("/api/lane/reply", { lane: sheet.key, ...what });
319
- if (!r.ok) toast(r.error, true); else { navigator.vibrate?.(15); setTimeout(peek, 250); }
320
- }
321
- document.addEventListener("submit", async (e) => {
322
- const f = e.target.closest("[data-form]"); if (!f) return;
323
- e.preventDefault();
324
- const kind = f.dataset.form, btn = f.querySelector("button:not([type=button])");
325
- if (kind === "reply") { const t = f.t.value; if (!t) return; f.t.value = ""; return reply({ text: t }); }
326
- if (kind === "add") {
327
- const t = f.t.value.trim(); if (!t) return;
328
- const r = await api("/api/plan/add", { root: sheet.root, text: t });
329
- toast(r.ok ? "Added to the plan" : r.error, !r.ok); if (r.ok) renderPlan(); return;
330
- }
331
- if (kind === "start") {
332
- const p = sheet.projects[f.p.value], task = f.task.value.trim();
333
- if (!p || !task) return toast("pick a project and write a task", true);
334
- btn.disabled = true; btn.textContent = "Starting…";
335
- const r = await api("/api/lane/start", { root: p.root, machine: p.machine || null, task, agent: sheet.agent });
336
- toast(r.ok ? "Started " + (r.slug || "lane") : r.error, !r.ok);
337
- if (r.ok) close(); else { btn.disabled = false; btn.textContent = "Start lane"; }
338
- refresh();
339
- }
340
- });
341
- // Notifications need a secure context (tailscale serve gives one) and a tap to ask.
342
- function maybeAskNotify() {
343
- if ("Notification" in window && Notification.permission === "default" && window.isSecureContext) Notification.requestPermission();
344
- }
345
- document.addEventListener("keydown", (e) => { if (e.key === "Escape" && sheet) close(); });
346
- document.addEventListener("visibilitychange", () => { if (!document.hidden) refresh(); });
347
- refresh();
348
- setInterval(refresh, 3000);
349
- </script>
350
- </body>
351
- </html>