kaizen-agent 1.61.3 → 1.61.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/pty.ts CHANGED
@@ -125,7 +125,7 @@ export function startPty(key: string, cmd: string[], cwd: string, pidFile?: stri
125
125
  const ps = winPs();
126
126
  p.proc = Bun.spawn([ps, "-NoProfile", "-NonInteractive", "-EncodedCommand", conptyHost()], {
127
127
  cwd,
128
- env: { ...colorEnv(), KZ_PTY_CMD: innerCommand(ps, cmd), KZ_PTY_CWD: cwd, KZ_PTY_COLS: "120", KZ_PTY_ROWS: "32" },
128
+ env: { ...colorEnv(), KAIZEN_BOARD_PID: String(process.pid), KZ_PTY_CMD: innerCommand(ps, cmd), KZ_PTY_CWD: cwd, KZ_PTY_COLS: "120", KZ_PTY_ROWS: "32" },
129
129
  stdin: "pipe", stdout: "pipe", stderr: "pipe", windowsHide: true,
130
130
  });
131
131
  const read = async (s: ReadableStream<Uint8Array>) => {
@@ -137,7 +137,7 @@ export function startPty(key: string, cmd: string[], cwd: string, pidFile?: stri
137
137
  read(p.proc.stderr as ReadableStream<Uint8Array>).catch(() => {});
138
138
  } else p.proc = Bun.spawn(cmd, {
139
139
  cwd,
140
- env: { ...colorEnv(), TERM: "xterm-256color", COLORTERM: "truecolor" },
140
+ env: { ...colorEnv(), TERM: "xterm-256color", COLORTERM: "truecolor", KAIZEN_BOARD_PID: String(process.pid) },
141
141
  terminal: { cols: 120, rows: 32, data: (_t, d) => push(dec.decode(d, { stream: true })) },
142
142
  });
143
143
  if (opts.tmux && cmd[0] === tmuxBin()) p.tmux = opts.tmux;
@@ -298,7 +298,8 @@ export function loginEnv(shell = process.env.SHELL): Record<string, string> | nu
298
298
  if (!shell || process.platform === "win32") return null;
299
299
  const MARK = "__kaizen_env__";
300
300
  try {
301
- const r = Bun.spawnSync([shell, "-l", "-i", "-c", `echo ${MARK}; env -0`], { stdin: "ignore", stderr: "ignore", timeout: 5000, killSignal: "SIGKILL" });
301
+ // detached: an interactive shell takes the terminal foreground and never hands it back, which left ctrl-c reaching nothing.
302
+ const r = Bun.spawnSync([shell, "-l", "-i", "-c", `echo ${MARK}; env -0`], { stdin: "ignore", stderr: "ignore", timeout: 5000, killSignal: "SIGKILL", detached: true });
302
303
  const out = r.stdout.toString(), at = out.indexOf(MARK + "\n");
303
304
  if (r.exitCode !== 0 || at < 0) return null;
304
305
  const env: Record<string, string> = {};
@@ -167,3 +167,28 @@ test.skipIf(!posix)("a stopped or crashed board resumes its card agents, once af
167
167
  Bun.spawnSync(["pkill", "-f", `${bin}/claude`]);
168
168
  }
169
169
  }, 40_000);
170
+
171
+ // A phone reaches the board through a proxy pinned to its port, so the board an update
172
+ // starts has to outwait the old one instead of walking to the next port.
173
+ test.skipIf(!posix || !Bun.which("lsof"))("a new board takes over the port of a board slow to stop", async () => {
174
+ const port = 20000 + Math.floor(Math.random() * 20000);
175
+ const home = join(root, "takeover");
176
+ mkdirSync(home, { recursive: true });
177
+ const script = join(home, "old.ts");
178
+ writeFileSync(script, `Bun.serve({ hostname: "127.0.0.1", port: ${port}, fetch: () => new Response("old", { headers: { "x-kaizen-version": "0.0.0" } }) });
179
+ process.on("SIGTERM", () => setTimeout(() => process.exit(0), 1500));
180
+ console.log("up");`);
181
+ const old = Bun.spawn([process.execPath, script], { stdout: "pipe" });
182
+ await new Response(old.stdout).body!.getReader().read();
183
+ const fresh = Bun.spawn([process.execPath, join(import.meta.dir, "install.ts"), "web", "--port", String(port), "--no-open", "--foreground"], {
184
+ cwd: home, env: { ...process.env, HOME: home, USERPROFILE: home }, stdin: "ignore", stdout: "ignore", stderr: "ignore",
185
+ });
186
+ try {
187
+ let version: string | null = null;
188
+ for (let i = 0; i < 60 && (!version || version === "0.0.0"); i++) {
189
+ await Bun.sleep(200);
190
+ version = await fetch(`http://127.0.0.1:${port}/`).then((r) => r.headers.get("x-kaizen-version"), () => null);
191
+ }
192
+ expect(version).toBe(JSON.parse(readFileSync(join(import.meta.dir, "..", "package.json"), "utf8")).version);
193
+ } finally { fresh.kill("SIGKILL"); old.kill("SIGKILL"); }
194
+ }, 20000);
package/cli/web.ts CHANGED
@@ -513,9 +513,17 @@ export async function web(repoDir: string, opts: Opts = {}) {
513
513
  // older kaizen serves 404 for whatever came since; both are ours to stop.
514
514
  const pid = await pidOnPort(port);
515
515
  if (pid && pid !== process.pid) {
516
+ // This shell is a tab of that board: stopping it would end the shell running this.
517
+ if (process.env.KAIZEN_BOARD_PID === String(pid)) { console.log(`\n the board on ${port} hosts this terminal; restart it from a terminal outside the board\n`); process.exit(1); }
516
518
  try { process.kill(pid, "SIGTERM"); console.log(` stopped a ${up ? "stale" : "hung"} board on ${port} (pid ${pid})`); } catch { /* not ours to kill */ }
517
- await Bun.sleep(300);
518
- try { server = serve(port); continue; } catch { /* still held */ }
519
+ // A stopping board saves its agents first and can hold the port for seconds. Walking
520
+ // up now would strand this one on a port the phone's tailscale serve does not proxy.
521
+ for (let waited = 0; waited < 8000 && !server; waited += 200) {
522
+ await Bun.sleep(200);
523
+ if (waited === 5000) try { process.kill(pid, "SIGKILL"); } catch { /* already gone */ }
524
+ try { server = serve(port); } catch { /* still held */ }
525
+ }
526
+ if (server) continue;
519
527
  }
520
528
  console.log(` port ${port} refused by the OS and nothing answers there; trying ${port + 1}`);
521
529
  }
@@ -742,7 +750,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
742
750
  // id is read from that run's state.json, never taken from the page). Claude only: it is
743
751
  // the agent whose session id runs record. Refused while that session is still running
744
752
  // elsewhere, since two copies of one conversation overwrite each other's history.
745
- const runKey = typeof body.run === "string" && body.run.length <= 300 ? body.run : "";
753
+ const runKey = typeof body.run === "string" && body.run.length <= 2000 ? body.run : "";
746
754
  if (body.resume === true) {
747
755
  const id = runKey.startsWith("run:" + dir + ":") ? runKey.slice(dir.length + 5) : "";
748
756
  let st: any = {};
@@ -2022,7 +2030,12 @@ export async function web(repoDir: string, opts: Opts = {}) {
2022
2030
  await new Promise<void>((resolve) => {
2023
2031
  // The card agents are listed for the next board and ended (saveLive); the short wait
2024
2032
  // lets each take its /exit, or be ended with what it started, before this process goes.
2033
+ let stopping = false;
2025
2034
  const stop = () => {
2035
+ // A second ctrl-c, or a shutdown that hangs, still ends the process.
2036
+ if (stopping) process.exit(0);
2037
+ stopping = true;
2038
+ setTimeout(() => process.exit(0), 3000).unref();
2026
2039
  const live = ptyKeys().some((k) => ptyState(k)?.alive);
2027
2040
  saveLive();
2028
2041
  clearInterval(poll); clearInterval(ping); clearInterval(gather); clearInterval(loop); clearInterval(keepList);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaizen-agent",
3
- "version": "1.61.3",
3
+ "version": "1.61.5",
4
4
  "description": "Staged workflow for AI agents — code, writing, research, operations: plan, human approval, build, independent review, bounded fix loop.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -433,6 +433,7 @@ const runHtml = (c) =>
433
433
  export function runPopup(c) {
434
434
  const dl = modal(runHtml(c)),
435
435
  f = dl.querySelector("form");
436
+ dl.classList.toggle("sheet", isPhone());
436
437
  const go = (kind) => {
437
438
  // startRun reads the Yolo switch, so the dialog closes after it has.
438
439
  void startRun(c, kind);
package/web/board/dom.ts CHANGED
@@ -77,3 +77,46 @@ export const motion = () => {
77
77
  // fn as a view transition where the browser has them and motion is on; resolves once the DOM is updated.
78
78
  export const vt = (fn: () => void): Promise<void> =>
79
79
  motion() && document.startViewTransition ? document.startViewTransition(fn).updateCallbackDone : (fn(), Promise.resolve());
80
+
81
+ // Paging for a long list: one state per list, its size remembered per browser.
82
+ const PAGE_SIZES = [5, 25, 50, 100];
83
+ export function pager(id: string) {
84
+ let size = 25;
85
+ try {
86
+ const n = Number(localStorage.getItem("kz-page:" + id));
87
+ if (PAGE_SIZES.includes(n)) size = n;
88
+ } catch {}
89
+ return { id, size, at: 0, total: 0 };
90
+ }
91
+ type Pager = ReturnType<typeof pager>;
92
+ // The page of items showing; a list that shrank pulls the page back into range.
93
+ export function pageOf<T>(p: Pager, items: T[]): T[] {
94
+ p.total = items.length;
95
+ p.at = Math.max(0, Math.min(p.at, Math.ceil(items.length / p.size) - 1));
96
+ return items.slice(p.at * p.size, (p.at + 1) * p.size);
97
+ }
98
+ export function pagerHtml(p: Pager) {
99
+ if (p.total <= PAGE_SIZES[0]) return "";
100
+ const from = p.at * p.size + 1,
101
+ to = Math.min(p.total, from + p.size - 1);
102
+ return html`<div class="kpager" id="pg-${p.id}"><label>Rows<select class="sel" aria-label="Rows per page">${PAGE_SIZES.map((n) => html`<option${n === p.size ? raw(" selected") : ""}>${n}</option>`)}</select></label><span>${from}–${to} of ${p.total}</span><button class="btn sm" type="button" data-to="-1"${p.at ? "" : raw(" disabled")}>Prev</button><button class="btn sm" type="button" data-to="1"${to < p.total ? "" : raw(" disabled")}>Next</button></div>`;
103
+ }
104
+ export function wirePager(p: Pager, redraw: () => void) {
105
+ const box = $("pg-" + p.id);
106
+ if (!box) return;
107
+ box.querySelector("select").onchange = (e) => {
108
+ p.size = +(e.target as HTMLSelectElement).value;
109
+ p.at = 0;
110
+ try {
111
+ localStorage.setItem("kz-page:" + p.id, String(p.size));
112
+ } catch {}
113
+ redraw();
114
+ };
115
+ box.querySelectorAll<HTMLElement>("[data-to]").forEach(
116
+ (b) =>
117
+ (b.onclick = () => {
118
+ p.at += +b.dataset.to!;
119
+ redraw();
120
+ }),
121
+ );
122
+ }
@@ -3,7 +3,7 @@ import { termStop } from "./agent-term.ts";
3
3
  import { load, post } from "./api.ts";
4
4
  import { via } from "./cards.ts";
5
5
  import { mic, stopDictation } from "./dictation.ts";
6
- import { $, dataUrls, html, ico, modal, motion, raw, SKEL } from "./dom.ts";
6
+ import { $, dataUrls, html, ico, modal, motion, pageOf, pager, pagerHtml, raw, SKEL, wirePager } from "./dom.ts";
7
7
  import { ideaCombo, newDir, plogo, setShown, short, showable } from "./projects.ts";
8
8
  import { playSound, soundPick, toast } from "./toast.ts";
9
9
  import { go, view } from "./views.ts";
@@ -22,6 +22,7 @@ const SRC = "Icebox";
22
22
  // The reply style is per project: a promo voice in one need not leak into another's drafts.
23
23
  let iceReply = null;
24
24
  const iceStyle = {};
25
+ const icePg = pager("icebox");
25
26
  const rStyle = (dir) => {
26
27
  if (!iceStyle[dir])
27
28
  try {
@@ -289,7 +290,10 @@ export async function openSources() {
289
290
  groups.get(k).push(i);
290
291
  });
291
292
  // Rows in the order they are drawn, which is the order j and k walk.
292
- const order = [...groups.values()].flat();
293
+ const filtered = [...groups.values()].flat();
294
+ // Only the page: j and k, select-all and bulk actions stay on what shows.
295
+ const order = pageOf(icePg, filtered);
296
+ const onPage = new Set(order);
293
297
  const isWaiting = (it) => !["promoted", "dismissed", "done"].includes(it.status);
294
298
  // A checked request a filter hides is unchecked: a bulk action only ever acts on what shows.
295
299
  {
@@ -375,12 +379,12 @@ export async function openSources() {
375
379
  waiting && !order.length
376
380
  ? html`<div class="ice-zero"><h4>No matches</h4><p style="margin-top:10px"><button class="btn sm" id="ice-unf">Clear filters</button></p></div>`
377
381
  : order.length
378
- ? html`<div class="tk-list ice-list">${[...groups].map(([g, ix]) => html`<div class="ice-cat">${g}<i>${ix.length}</i></div>${ix.map(row)}`)}</div>`
382
+ ? html`<div class="tk-list ice-list">${[...groups].map(([g, ix]) => (ix.some((i) => onPage.has(i)) ? html`<div class="ice-cat">${g}<i>${ix.length}</i></div>${ix.filter((i) => onPage.has(i)).map(row)}` : ""))}${pagerHtml(icePg)}</div>`
379
383
  : html`<div class="ice-zero"><h4>Nothing waiting</h4><p>Requests gathered from your sources wait here until you turn them into ideas.</p>${list.length ? "" : html`<p style="margin-top:10px"><button class="btn sm pri" id="ice-addsrc">${ico("plus")} Add a source</button></p>`}</div>`;
380
384
  // Swipe: the waiting requests the filters show, least skipped first; a restored one
381
385
  // comes back on top. Nothing is written by a skip.
382
386
  const deck = iceSwipe
383
- ? order.filter((i) => isWaiting(ice[i])).sort((a, b) => (iceSwipe.skip.get(iceKey(ice[a])) || 0) - (iceSwipe.skip.get(iceKey(ice[b])) || 0))
387
+ ? filtered.filter((i) => isWaiting(ice[i])).sort((a, b) => (iceSwipe.skip.get(iceKey(ice[a])) || 0) - (iceSwipe.skip.get(iceKey(ice[b])) || 0))
384
388
  : [];
385
389
  // The card always names its project: a swipe decides for that project's Ideas.
386
390
  const pName = (it) => it.project || store.S.projects.find((p) => p.dir === it.dir)?.label || "";
@@ -409,17 +413,17 @@ export async function openSources() {
409
413
  const s = Math.round((Date.now() - S.t0) / 1000),
410
414
  took = s < 60 ? s + " s" : Math.floor(s / 60) + " min " + (s % 60) + " s";
411
415
  const bits = motion() ? html`<div class="sw-confetti" aria-hidden="true">${Array.from({ length: 14 }, (_, n) => raw(`<i style="--x:${(n * 37) % 100}%;--d:${(n % 5) * 0.08}s;--h:${(n * 53) % 360}"></i>`))}</div>` : "";
412
- return html`<div class="sw-zero">${S.n ? bits : ""}<h4>✨ Icebox zero ✨</h4><p>${S.n ? `${S.n} sorted · ${S.pro} promoted · ${S.dis} dismissed · in ${took}` : "Nothing waiting here."}</p>${S.days ? html`<p>🗓 ${S.days}-day streak${S.days > 1 ? " — cleared every day" : ""}</p>` : ""}<p style="margin-top:14px"><button class="btn pri sm" id="sw-back">Back to list</button></p></div>`;
416
+ return html`<div class="sw-zero">${S.n ? bits : ""}<h4>Icebox zero</h4><p>${S.n ? `${S.n} sorted · ${S.pro} promoted · ${S.dis} dismissed · in ${took}` : "Nothing waiting here."}</p>${S.days ? html`<p>${S.days}-day streak${S.days > 1 ? " — cleared every day" : ""}</p>` : ""}<p style="margin-top:14px"><button class="btn pri sm" id="sw-back">Back to list</button></p></div>`;
413
417
  };
414
418
  const swipe = () => {
415
419
  const S = iceSwipe,
416
420
  total = S.n + deck.length,
417
421
  pop = S.pop;
418
422
  S.pop = false;
419
- const top = html`<div class="sw-top"><button class="btn ghost sm" id="sw-x" title="Back to the list (Esc)">← List</button><div class="sw-prog" role="progressbar" aria-valuemin="0" aria-valuemax="${total}" aria-valuenow="${S.n}"><i style="width:${total ? Math.round((S.n / total) * 100) : 100}%"></i></div><span class="sw-of">${deck.length ? `${S.n + 1} of ${total}` : `${total} of ${total}`}</span><span class="sw-streak" title="Sorted this session">🔥 ${S.n}${pop ? html`<b class="sw-plus">+1</b>` : ""}</span></div>`;
423
+ const top = html`<div class="sw-top"><button class="btn ghost sm" id="sw-x" title="Back to the list (Esc)">← List</button><div class="sw-prog" role="progressbar" aria-valuemin="0" aria-valuemax="${total}" aria-valuenow="${S.n}"><i style="width:${total ? Math.round((S.n / total) * 100) : 100}%"></i></div><span class="sw-of">${deck.length ? `${S.n + 1} of ${total}` : `${total} of ${total}`}</span><span class="sw-streak" title="Sorted this session">${S.n} sorted${pop ? html`<b class="sw-plus">+1</b>` : ""}</span></div>`;
420
424
  if (!deck.length) return html`<div class="sw" id="sw">${top}${swZero()}</div>`;
421
425
  const b = (id, cls, icon, label, key, off = false) =>
422
- html`<button class="sw-b ${cls}" id="${id}" aria-label="${label} (${key})" title="${label} (${key})"${off ? " disabled" : ""}><span>${icon}</span><small>${label}</small></button>`;
426
+ html`<button class="sw-b ${cls}" id="${id}" aria-label="${label} (${key})" title="${label} (${key})"${off ? " disabled" : ""}><span>${icon}</span><small>${label}</small><kbd>${key}</kbd></button>`;
423
427
  return html`<div class="sw" id="sw">${top}<div class="sw-stack">${deck[1] !== undefined ? swCard(deck[1], true) : ""}${swCard(deck[0], false)}</div><div class="sw-acts">${b("sw-d", "dis", ico("x"), "Dismiss", "←")}${b("sw-s", "", "↓", "Skip", "↓", deck.length < 2)}${b("sw-u", "", ico("restore"), "Undo", "z", !S.last)}${b("sw-p", "pro", ico("check"), "Promote", "→")}</div></div>`;
424
428
  };
425
429
  // The sources, in the right-hand drawer: shut until asked for. Slid in only when opened;
@@ -708,6 +712,7 @@ export async function openSources() {
708
712
  openSources();
709
713
  };
710
714
  }
715
+ wirePager(icePg, openSources);
711
716
  if ($("ice-all"))
712
717
  $("ice-all").onchange = () => {
713
718
  const k = order.map((i) => iceKey(ice[i]));
@@ -3,7 +3,7 @@
3
3
  // signal it came from (its `idea` text or `run` id); one typed by hand is "Manual".
4
4
  // The data is the rail's (workspace.ts): no fetch of its own.
5
5
  import { store } from "./store.ts";
6
- import { $, html, ico, raw } from "./dom.ts";
6
+ import { $, html, ico, pageOf, pager, pagerHtml, raw, wirePager } from "./dom.ts";
7
7
  import { age, NAMES } from "./labels.ts";
8
8
  import { key, runPopup } from "./cards.ts";
9
9
  import { load, post } from "./api.ts";
@@ -41,6 +41,7 @@ function sourcesOf(cards, d) {
41
41
 
42
42
  // Keyboard: the row picked with the arrow keys (from the search box or the page), Enter acts on it.
43
43
  let sel = 0;
44
+ const pg = pager("ideas");
44
45
  let shownRows: any[] = [];
45
46
  // Orca's Tasks shape: a toolbar over a list. The search box, the page's filters and New idea
46
47
  // live in the shared header elsewhere, so they move in here and go back on leaving.
@@ -78,7 +79,7 @@ function draw() {
78
79
  const proj = store.all ? "" : store.S?.dir ?? "";
79
80
  const q = (($("bq") as HTMLInputElement | null)?.value ?? "").trim().toLowerCase();
80
81
  const fin = (c) => c.status === "done" || c.status === "abandoned";
81
- const rows = cards
82
+ const matched = cards
82
83
  .filter((c) => f.src === "all" || src.get(c) === f.src)
83
84
  .filter((c) => (proj ? c.state === proj : !shownDirs.length || shownDirs.includes(c.state)))
84
85
  // Open: ideas not started yet and runs in flight. Running: runs in flight only. Done: finished runs.
@@ -86,6 +87,7 @@ function draw() {
86
87
  .filter((c) => !q || (titleOf(c) + " " + nameOf(c.state, projects)).toLowerCase().includes(q))
87
88
  // On Open, ideas above runs or runs above ideas, as chosen; newest first within each.
88
89
  .sort((a, b) => (f.show === "open" ? (a.kind === b.kind ? 0 : (a.kind === "idea") === (f.sort === "ideas") ? -1 : 1) : 0) || (b.moved ?? b.added ?? 0) - (a.moved ?? a.added ?? 0));
90
+ const rows = pageOf(pg, matched);
89
91
  const now = Date.now();
90
92
  const seg = (v, l) => html`<button class="tk-chip${f.show === v ? " on" : ""}" data-show="${v}">${l}</button>`;
91
93
  const srcName = (u) => (u === "all" ? "All sources" : u === "" ? "Manual" : known.get(u) ? srcLabel(known.get(u)) : srcLabel({ url: u }));
@@ -121,7 +123,8 @@ function draw() {
121
123
  // Not while a pop-up in it is open: redrawing would close it under the pointer.
122
124
  if (!hx.querySelector("details[open]")) hx.innerHTML = String(extra);
123
125
  $("tk-chips").innerHTML = String(chips);
124
- $("tk-list").innerHTML = String(table);
126
+ $("tk-list").innerHTML = String(html`${table}${pagerHtml(pg)}`);
127
+ wirePager(pg, () => ((sel = 0), draw()));
125
128
 
126
129
  hx.querySelectorAll<HTMLElement>("[data-src]").forEach((b) => (b.onclick = () => ((f.src = b.dataset.src!), (hx.innerHTML = ""), draw())));
127
130
  hx.querySelectorAll<HTMLElement>("[data-sort]").forEach(
@@ -2,7 +2,7 @@ import { store } from "./store.ts";
2
2
  import { showTerm, termStop } from "./agent-term.ts";
3
3
  import { load, post } from "./api.ts";
4
4
  import { APPROVAL, answer, confirmAnswers, confirmRevise, decide, decided, resumable, resume } from "./approvals.ts";
5
- import { cardEl, key, render } from "./cards.ts";
5
+ import { cardEl, key, render, runPopup } from "./cards.ts";
6
6
  import { chat } from "./chat.ts";
7
7
  import { stopDictation } from "./dictation.ts";
8
8
  import { $, html, raw } from "./dom.ts";
@@ -74,6 +74,8 @@ export function open(c, keepTab) {
74
74
  toggleArchive(c, a === "archive");
75
75
  return;
76
76
  }
77
+ // Over the page it is on, as Start does: no trip to the board.
78
+ if (a === "run") return runPopup(c);
77
79
  const k = key(c);
78
80
  // The form lives on the board: the run workspace hands over to it.
79
81
  if (view === "run") go("board", true);
@@ -1,8 +1,11 @@
1
1
  // ---- Phones: their own Home (devices, recent runs, usage) and the Runs page (this
2
2
  // machine's runs grouped waiting / active / done). The board, Ideas and Icebox are set up
3
3
  // on a computer; a phone has Home, Chat, Runs and Settings.
4
+ import { runPopup } from "./cards.ts";
4
5
  import { $, html, raw } from "./dom.ts";
5
- import { cardHref, logo, railData, stateOf, subline, titleOf, usageChips } from "./workspace.ts";
6
+ import { cardHref, logo, railData, stateOf, subline, titleOf, usageChips, wsHref } from "./workspace.ts";
7
+ import { toast } from "./toast.ts";
8
+ import { agentStatus, wsKey, type Agent, type Status } from "./ws-tabs.ts";
6
9
 
7
10
  export const isPhone = () => matchMedia("(max-width:640px)").matches;
8
11
 
@@ -10,6 +13,7 @@ type Computer = { name: string; dns: string; os: string; online: boolean };
10
13
  let net: { self: Computer | null; computers: Computer[]; tailscale: boolean } = { self: null, computers: [], tailscale: false };
11
14
  let usage: any[] = [];
12
15
  let mode: "home" | "device" | null = null;
16
+ let allDevices = false;
13
17
 
14
18
  const chev = raw(`<svg class="pchev" viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg>`);
15
19
  const runs = () => railData().cards.filter((c) => c.kind === "run" && !c.archived);
@@ -26,6 +30,81 @@ function row(c, now: number) {
26
30
  return html`<a class="prow" href="${cardHref(c)}" data-dir="${c.state}" data-id="${rowKey(c)}"><span class="si ${stateOf(c)}"></span><span class="pmain"><b>${titleOf(c)}</b><small>${logo(c.state, name, railData().projects)}${name}</small><code>${subline(c, now)}</code></span></a>`;
27
31
  }
28
32
 
33
+ // Home's slider: one card per workspace with an agent open, those asking first.
34
+ const WORD: Record<Status, string> = { asking: "Asking", working: "Working", done: "Done" };
35
+ const DOT: Record<Status, string> = { asking: "wait", working: "build", done: "done" };
36
+ const RANK: Record<Status, number> = { asking: 0, working: 1, done: 2 };
37
+ const agentIco = (a: Agent) => {
38
+ const id = "i-" + (a.agent || "").toLowerCase();
39
+ return raw(`<svg class="pag-ico" aria-hidden="true"><use href="#${document.getElementById(id) ? id : "i-ai"}"/></svg>`);
40
+ };
41
+ const wsName = (a: Agent) => a.ws?.split(/[\\/]/).pop() || "main";
42
+ const groupKey = (a: Agent) => a.dir + "\n" + (a.ws ?? ""); // a NUL would not survive innerHTML
43
+ function agentGroups(now: number) {
44
+ const groups = new Map<string, { a: Agent; st: Status }[]>();
45
+ for (const a of (railData().agents ?? []) as Agent[]) {
46
+ const k = groupKey(a);
47
+ groups.set(k, [...(groups.get(k) ?? []), { a, st: agentStatus(a, now) }]);
48
+ }
49
+ const list = [...groups].map(([k, rows]) => ({ k, rows: rows.sort((x, y) => RANK[x.st] - RANK[y.st]) }));
50
+ return list.sort((x, y) => RANK[x.rows[0].st] - RANK[y.rows[0].st]);
51
+ }
52
+ function agentCards(now: number) {
53
+ const groups = agentGroups(now);
54
+ const asking = groups.filter((g) => g.rows[0].st === "asking").length;
55
+ const cards = groups.map(({ k, rows }) => {
56
+ const { a, st } = rows[0];
57
+ return html`<button type="button" class="pag${st === "asking" ? " ask" : ""}" data-group="${k}"><span class="pag-st"><i class="si ${DOT[st]}"></i>${rows.length > 1 ? rows.length + " agents" : WORD[st]}<span class="pag-icos">${rows.map((r) => agentIco(r.a))}</span></span><span class="pag-ws">${wsName(a)}</span><small>${projName(a.dir)}</small></button>`;
58
+ });
59
+ return html`<section class="psec2"><div class="pag-h"><h3>Agents${asking ? html`<span class="pag-n">${asking} asking</span>` : ""}</h3><button type="button" class="pag-new">New</button></div>${groups.length ? html`<div class="pslide">${cards}</div>` : html`<p class="pnote">No agents running.</p>`}</section>`;
60
+ }
61
+ function openTerm(a: Agent) {
62
+ if (dispatchEvent(new CustomEvent("kz-open-term", { cancelable: true, detail: { dir: a.dir, ws: a.ws, key: a.key } }))) location.href = wsHref(a.dir, a.ws ?? "");
63
+ }
64
+ // Several agents in a workspace: a sheet picks which terminal to open.
65
+ function pickAgent(rows: { a: Agent; st: Status }[]) {
66
+ const d = document.createElement("dialog");
67
+ d.className = "pagsheet";
68
+ d.innerHTML = String(html`<h4>${wsName(rows[0].a)}</h4>${rows.map(({ a, st }, i) => html`<button type="button" data-i="${String(i)}">${agentIco(a)}${a.name || a.agent || "Terminal"}<i class="si ${DOT[st]}"></i><small>${WORD[st]}</small></button>`)}<button type="button" data-new="1">${agentIco({ agent: "" } as Agent)}New agent</button>`);
69
+ d.addEventListener("click", (e) => {
70
+ const b = (e.target as HTMLElement).closest<HTMLButtonElement>("button");
71
+ d.close();
72
+ if (b?.dataset.new) void newSheet(rows[0].a.dir, rows[0].a.ws);
73
+ else if (b) openTerm(rows[Number(b.dataset.i)].a);
74
+ });
75
+ d.addEventListener("close", () => d.remove());
76
+ document.body.append(d);
77
+ d.showModal();
78
+ }
79
+
80
+ // New: pick a workspace, then an agent or a plain shell. It starts as a tab of that
81
+ // workspace, the same POST the workspace's own + button makes.
82
+ async function newSheet(dir?: string, ws?: string) {
83
+ const spots = (railData().projects ?? []).flatMap((p) => (p.workspaces ?? []).map((w) => ({ dir: p.dir as string, ws: w.path as string, name: w.branch || w.path.split(/[\\/]/).pop() })));
84
+ const first = agentGroups(Date.now())[0]?.rows[0].a;
85
+ const on = spots.find((x) => x.dir === (dir ?? first?.dir) && x.ws === (ws ?? first?.ws)) ?? spots[0];
86
+ if (!on) return toast("Add a project on a computer first");
87
+ const list = await fetch("/agents?dir=" + encodeURIComponent(on.dir)).then((r) => r.json(), () => null);
88
+ const kinds: { cmd: string; name: string }[] = [...(list?.agents ?? []), { cmd: "", name: "Shell" }];
89
+ const d = document.createElement("dialog");
90
+ d.className = "pagsheet";
91
+ d.innerHTML = String(html`<h4>New in</h4><select aria-label="Workspace">${spots.map((x, i) => html`<option value="${String(i)}"${raw(x === on ? " selected" : "")}>${projName(x.dir)} ${x.name}</option>`)}</select>${kinds.map((k, i) => html`<button type="button" data-i="${String(i)}">${k.cmd ? agentIco({ agent: k.cmd } as Agent) : raw(`<svg class="pag-ico" aria-hidden="true"><use href="#i-term"/></svg>`)}${k.name}</button>`)}`);
92
+ d.addEventListener("click", async (e) => {
93
+ const b = (e.target as HTMLElement).closest<HTMLButtonElement>("button");
94
+ if (e.target === d) return d.close();
95
+ if (!b) return;
96
+ const at = spots[Number(d.querySelector("select")!.value)], cmd = kinds[Number(b.dataset.i)].cmd;
97
+ d.close();
98
+ const r = await fetch("/shell", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ dir: at.dir, ws: at.ws, run: wsKey(at.dir, at.ws), ...(cmd ? { agent: cmd } : {}) }) }).catch(() => null);
99
+ const sh = r?.ok ? await r.json() : null;
100
+ if (sh) openTerm({ dir: at.dir, ws: at.ws, key: sh.key } as Agent);
101
+ else toast("No new terminal: " + ((await r?.json().catch(() => null))?.error || "the board did not answer"));
102
+ });
103
+ d.addEventListener("close", () => d.remove());
104
+ document.body.append(d);
105
+ d.showModal();
106
+ }
107
+
29
108
  function home() {
30
109
  const now = Date.now();
31
110
  const all = runs();
@@ -33,12 +112,15 @@ function home() {
33
112
  const waiting = all.filter((c) => stateOf(c) === "wait").length;
34
113
  const projects = new Set(all.map((c) => c.state)).size;
35
114
  const me = net.self?.name || "This computer";
36
- const others = net.computers.map(
115
+ // Two devices show, this computer first; the rest wait behind Show more.
116
+ const others = net.computers.slice(0, allDevices ? undefined : 1).map(
37
117
  (d) =>
38
118
  html`<a class="pdev" href="${d.dns ? "https://" + d.dns + "/" : "#"}" target="_blank" rel="noopener"${raw(d.dns ? "" : ' aria-disabled="true"')}><span class="pico"><svg><use href="#r-desk"/></svg></span><span class="pmain"><b>${d.name}</b><small><i class="pdot${d.online ? " on" : ""}"></i>${d.online ? "Connected" : "Disconnected"}${d.os ? " · " + d.os : ""}</small></span>${chev}</a>`,
39
119
  );
40
120
  const recent = [...all].sort((a, b) => (b.moved ?? 0) - (a.moved ?? 0)).slice(0, 12);
41
- return html`<section class="psec2"><h3>Devices</h3><a class="pdev" href="/?view=device" data-dev="here"><span class="pico"><svg><use href="#r-desk"/></svg></span><span class="pmain"><b>${me}</b><small><i class="pdot on"></i>Connected · ${projects} project${projects === 1 ? "" : "s"} · ${active.length} active${waiting ? html` · <em>${waiting} waiting</em>` : ""}</small></span>${chev}</a>${others}${net.tailscale ? "" : html`<p class="pnote">Tailscale is off on this computer: other devices do not show.</p>`}</section>
121
+ const hidden = net.computers.length - 1;
122
+ const more = hidden > 0 ? html`<button type="button" class="pmore" aria-expanded="${String(allDevices)}"><span>${allDevices ? "Show less" : `Show ${hidden} more`}</span><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg></button>` : "";
123
+ return html`${agentCards(now)}<section class="psec2"><h3>Devices</h3><a class="pdev" href="/?view=device" data-dev="here"><span class="pico"><svg><use href="#r-desk"/></svg></span><span class="pmain"><b>${me}</b><small><i class="pdot on"></i>Connected · ${projects} project${projects === 1 ? "" : "s"} · ${active.length} active${waiting ? html` · <em>${waiting} waiting</em>` : ""}</small></span>${chev}</a>${others}${more}${net.tailscale ? "" : html`<p class="pnote">Tailscale is off on this computer: other devices do not show.</p>`}</section>
42
124
  <section class="psec2"><h3>Runs</h3><div class="plist2">${recent.map((c) => row(c, now))}${recent.length ? "" : html`<p class="pnote">No runs yet.</p>`}</div></section>${usage.length ? html`<section class="psec2"><h3>Usage</h3><div class="pusage">${raw(usageChips(usage))}</div></section>` : ""}`;
43
125
  }
44
126
 
@@ -58,7 +140,10 @@ function draw() {
58
140
  const el = $("phome");
59
141
  if (!el || !mode) return;
60
142
  const keep = mode === "device" ? [...el.querySelectorAll("details")].map((d) => d.open) : [];
143
+ const slid = el.querySelector(".pslide")?.scrollLeft ?? 0;
61
144
  el.innerHTML = String(mode === "home" ? home() : device());
145
+ const slide = el.querySelector(".pslide");
146
+ if (slide) slide.scrollLeft = slid;
62
147
  el.querySelectorAll("details").forEach((d, i) => keep[i] !== undefined && (d.open = keep[i]));
63
148
  }
64
149
 
@@ -102,13 +187,26 @@ export function initPhone(go: (v: string, push?: boolean) => void, openRun: (c)
102
187
  );
103
188
  $("phome")?.addEventListener("click", (e) => {
104
189
  if ((e as MouseEvent).ctrlKey || (e as MouseEvent).metaKey) return;
105
- const a = (e.target as HTMLElement).closest<HTMLAnchorElement>("a");
190
+ const t = e.target as HTMLElement;
191
+ if (t.closest(".pag-new")) return void newSheet();
192
+ if (t.closest(".pmore")) return (allDevices = !allDevices), draw();
193
+ const group = t.closest<HTMLElement>(".pag")?.dataset.group;
194
+ if (group) {
195
+ const rows = agentGroups(Date.now()).find((g) => g.k === group)?.rows;
196
+ if (rows) rows.length > 1 ? pickAgent(rows) : openTerm(rows[0].a);
197
+ return;
198
+ }
199
+ const a = t.closest<HTMLAnchorElement>("a");
106
200
  if (!a) return;
107
201
  if (a.dataset.dev) return (e.preventDefault(), go("device", true));
108
202
  if (a.getAttribute("aria-disabled")) return e.preventDefault();
109
203
  if (a.classList.contains("prow")) {
110
204
  const c = [...runs(), ...ideas()].find((x) => x.state === a.dataset.dir && rowKey(x) === a.dataset.id);
111
- if (c) (e.preventDefault(), openRun(c));
205
+ if (!c) return;
206
+ e.preventDefault();
207
+ // An idea not started has nothing in a workspace yet: pick its agent and mode instead.
208
+ if (c.kind === "idea" && c.status === "idea") runPopup(c);
209
+ else openRun(c);
112
210
  }
113
211
  });
114
212
  }
package/web/board.html CHANGED
@@ -135,7 +135,7 @@ body .rail a.upd::after{left:calc(50% + 6px);top:4px}body .toast{left:16px;botto
135
135
  [data-rail=min] .plist .proj{justify-content:center;margin:10px 0 4px;padding:0}[data-rail=min] .plist .row{grid-template-columns:14px;justify-content:center;padding:0}
136
136
  @media(max-width:640px){.rail .psec,.rail .plist,.rail .rib{display:none}.rail .rbot,[data-rail=min] .rail .rbot{display:contents}.rail a.it[data-view=ideas]{order:3}.rail a.it[data-view=board]{order:4}.rail a.it .n,.rail a.it .srcs{display:none}}
137
137
  /* phones: Home, Chat, Runs, Settings. The board, Ideas and the Icebox are set up on a computer (web/board/phone.ts) */
138
- @media(min-width:641px){.rail .rbot .lbl{display:none}}
138
+ @media(min-width:641px){.rail .rbot .lbl{display:none}.rail .rbot a.it{flex:none;width:var(--btn-xs);height:var(--btn-xs);padding:0;justify-content:center;margin-right:auto}[data-rail=min] .rail .rbot a.it{width:var(--btn-s);height:var(--btn-s);margin-right:0}}
139
139
  .rail a.it.ponly,#phome{display:none}
140
140
  @media(max-width:640px){
141
141
  .rail a.it:is([data-view=board],[data-view=ideas],[data-view=sources]),#foot,#ctx-open,body .rail .rbot .rib{display:none!important}
@@ -162,12 +162,20 @@ html body.runv .app{grid-template-rows:auto minmax(0,1fr)}html body.runv .hdr{di
162
162
  html body.runv #rtabs{padding:0 10px 6px}html body.runv .app{margin:0!important}
163
163
  .srow{grid-template-columns:minmax(0,1fr) auto}.srow select.sel{max-width:52vw}
164
164
  body.phomev .hdr>:not(h1):not(#newtop),body.phomev #board{display:none!important}
165
+ body.phomev:not(.pdevv) #newtop{display:none!important}
165
166
  body.phomev #phome{display:block;flex:1;min-height:0;overflow:auto;padding:4px 16px 24px;animation:fi .2s}
166
167
  }
167
168
  #phome h3{margin:18px 4px 8px;font-size:11px;font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--dim)}
168
169
  #phome .psec2:first-child h3{margin-top:6px}
169
170
  .pdev{display:flex;align-items:center;gap:12px;margin-bottom:8px;padding:10px 12px;border:1px solid var(--line);border-radius:12px;background:var(--bg-2);color:var(--ink);text-decoration:none}
170
171
  .pdev[aria-disabled]{opacity:.6}
172
+ .pslide{display:grid;grid-auto-flow:column;grid-template-rows:repeat(2,auto);grid-auto-columns:min(44vw,164px);gap:8px;overflow-x:auto;scroll-snap-type:x proximity;scroll-padding:0 16px;margin:0 -16px;padding:0 16px 4px;scrollbar-width:none;overscroll-behavior-x:contain}.pslide::-webkit-scrollbar{display:none}
173
+ .pag{all:unset;box-sizing:border-box;cursor:pointer;scroll-snap-align:start;display:flex;flex-direction:column;gap:6px;min-width:0;min-height:92px;padding:10px 12px;border:1px solid var(--line);border-radius:12px;background:var(--bg-2);color:var(--ink);transition:border-color .15s}.pag:active{border-color:var(--ink)}.pag:focus-visible,.pmore:focus-visible{outline:2px solid var(--accent)}.pag.ask{border-color:var(--warn)}
174
+ .pag-st{display:flex;align-items:center;gap:6px;font-size:13px;font-weight:600}.pag-icos{display:flex;gap:4px;margin-left:auto}.pag-ico{width:16px;height:16px;flex:none}.pag-ws{font:12px var(--mono);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.pag small{font-size:12px;color:var(--dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.pag-n{float:right;text-transform:none;letter-spacing:0}
175
+ .pmore{all:unset;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;justify-content:space-between;width:100%;min-height:48px;margin-bottom:8px;padding:0 12px;border:1px solid var(--line);border-radius:12px;background:var(--bg-2);font-size:15px;color:var(--ink);transition:background .15s}.pmore:active{background:var(--hover)}.pmore svg{width:18px;height:18px;fill:none;stroke:var(--dim);stroke-width:2;stroke-linecap:round;stroke-linejoin:round;transition:transform .2s}.pmore[aria-expanded=true] svg{transform:rotate(180deg)}
176
+ .pag-h{display:flex;align-items:center;justify-content:space-between;gap:8px}.pag-h h3{flex:1}.pag-new{all:unset;cursor:pointer;display:flex;align-items:center;min-height:44px;padding:0 4px 0 12px;font-size:14px;font-weight:600;color:var(--ink)}.pag-new:focus-visible{outline:2px solid var(--accent)}.pagsheet select{width:100%;min-height:44px;margin-bottom:8px;font:inherit;color:var(--ink);background:var(--bg);border:1px solid var(--line);border-radius:8px;padding:0 8px}
177
+ .pagsheet{position:fixed;inset:auto 0 0;width:100%;max-width:none;margin:0;padding:12px 16px calc(20px + env(safe-area-inset-bottom));border:0;border-top:1px solid var(--line);border-radius:16px 16px 0 0;background:var(--bg-2);color:var(--ink)}.pagsheet::backdrop{background:rgb(0 0 0/.45)}.pagsheet h4{margin:0 0 8px;font:13px var(--mono)}.pagsheet button{all:unset;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;gap:8px;width:100%;min-height:48px;border-top:1px solid var(--line);font-size:14px}.pagsheet small{margin-left:auto;font-size:12px;color:var(--dim)}
178
+ @media(prefers-reduced-motion:reduce){.pmore svg{transition:none}}
171
179
  .pico{width:36px;height:36px;display:grid;place-items:center;flex:none;border-radius:9px;background:var(--hover);color:var(--dim)}.pico svg{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.8}
172
180
  .pmain{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}
173
181
  .pmain b{font-size:14px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
@@ -442,6 +450,7 @@ dialog.onb-ask h3{margin:0 0 4px;font-size:16px;color:var(--ink-hi)}dialog.onb-a
442
450
  @media(prefers-reduced-motion:reduce){.onb-prog button{transition:none}}
443
451
  dialog.kz.wsnew{width:min(576px,calc(100vw - 32px))}dialog.wsnew .inl{gap:12px;max-height:85dvh;overflow-y:auto}dialog.wsnew .wsfrom{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:-6px}dialog.wsnew .wsfrom i{font-style:normal;opacity:.7}dialog.wsnew .wsbase{display:flex;align-items:center;gap:4px;font-size:12px;color:var(--dim);min-width:0}dialog.wsnew .wsbase select{width:auto;max-width:200px;border:0;background:none;color:var(--ink);font-size:12px;padding:2px}dialog.wsnew .wsadv summary{cursor:pointer;font-size:12px;color:var(--dim);padding:2px 0}dialog.wsnew .wsadv[open] summary{margin-bottom:8px}dialog.wsnew .err:empty{display:none}dialog.wsnew .err:not(:empty){color:var(--danger);border:1px solid color-mix(in srgb,var(--danger) 30%,transparent);background:color-mix(in srgb,var(--danger) 10%,transparent);border-radius:var(--r-s);padding:8px 12px}dialog.wsnew .row{justify-content:flex-end;align-items:center}dialog.wsnew .wskey{order:-1;margin-right:auto;font:11px var(--mono);color:var(--dim)}
444
452
  dialog.kz{border:0;padding:0;background:none;width:min(480px,calc(100vw - 32px));max-height:calc(100dvh - 32px);overflow:visible;color:var(--ink)}dialog.kz::backdrop{background:rgb(0 0 0/.45)}dialog.kz>.inl{background:var(--bg);border:1px solid var(--line);border-radius:12px;padding:16px;gap:10px}dialog.kz .inl input,dialog.kz .inl textarea{background:var(--canvas);border-color:var(--line)}dialog.kz .row input{flex:1;min-width:0}dialog.kz #ndc{align-self:flex-start}dialog.kz .btn.opt{display:flex;flex-direction:column;align-items:flex-start;gap:2px;padding:8px 12px;text-align:left}dialog.kz .btn.opt small{color:var(--dim)}dialog.kz label.att{display:flex;flex-direction:column;gap:4px}dialog.kz label.att:has(input[type=checkbox]){flex-direction:row;align-items:center}dialog.kz select{background:var(--canvas);border:1px solid var(--line);border-radius:var(--r-s);color:var(--ink);padding:6px 8px;font:inherit}dialog.viewer{width:min(1100px,calc(100vw - 32px));height:calc(100dvh - 32px);background:var(--bg);border-radius:var(--r);display:none;flex-direction:column;overflow:hidden}dialog.viewer[open]{display:flex}.viewer-hd{display:flex;gap:12px;align-items:center;padding:8px 12px;border-bottom:1px solid var(--line)}.viewer-hd span{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600}dialog.viewer img{flex:1;min-height:0;width:100%;object-fit:contain}dialog.viewer iframe{flex:1;border:0;width:100%;background:#fff}
453
+ @keyframes sheet-up{from{transform:translateY(100%)}}dialog.kz.sheet{width:100vw;max-width:none;margin:auto 0 0;max-height:85dvh;animation:sheet-up .2s ease-out}dialog.kz.sheet>.inl{border-width:1px 0 0;border-radius:16px 16px 0 0;padding-bottom:calc(16px + env(safe-area-inset-bottom));max-height:85dvh;overflow-y:auto}@media(prefers-reduced-motion:reduce){dialog.kz.sheet{animation:none}}
445
454
  .inl .run-actions{display:grid;gap:8px}.inl .run-actions .row{display:grid;grid-template-columns:repeat(2,minmax(0,1fr))}.inl .run-actions .pri{grid-column:1/-1}
446
455
  .notes{display:flex;flex-direction:column;gap:8px}
447
456
  #pbody img{max-width:100%;border-radius:var(--r-s)}
@@ -492,7 +501,7 @@ body.ideav #ideasv{flex:1;min-height:0;display:flex;flex-direction:column;gap:0;
492
501
  #ideasv #ideas-q{flex:0 1 240px;min-width:140px;border-radius:4px;padding:6px 10px;font-family:var(--mono);font-size:12px}
493
502
  #ideasv .iscroll{flex:1;min-height:0;overflow:auto}
494
503
  .itable{width:100%;border-collapse:collapse}.itable th{text-align:left;font-size:10.5px;letter-spacing:.08em;text-transform:uppercase;color:var(--dim);font-weight:600;padding:8px 12px;border-bottom:1px solid var(--line)}
495
- .itable td{padding:10px 12px;border-bottom:1px solid var(--line);vertical-align:middle}.itable tr:hover td{background:var(--hover)}#ideasv tbody tr{cursor:pointer}.itable tr.kb td{background:var(--hover)}.itable tr.kb td:first-child{box-shadow:inset 2px 0 0 var(--accent)}.itable td:first-child{width:28px;padding-right:0}.itable td.d{color:var(--dim);white-space:nowrap}
504
+ .itable td{padding:10px 12px;border-bottom:1px solid var(--line);vertical-align:middle}.itable tr:hover td{background:var(--hover)}#ideasv tbody tr{cursor:pointer}.itable tr.kb td{background:var(--hover)}.itable td:first-child{width:28px;padding-right:0}.itable td.d{color:var(--dim);white-space:nowrap}
496
505
  .itable .ctx{display:flex;gap:6px;align-items:center;color:var(--dim);font-size:12px;margin-top:3px}.itable .tag{font-size:10.5px;border:1px solid var(--line);border-radius:4px;padding:0 7px}
497
506
  .itable .stc{display:flex;gap:8px;align-items:center;font-size:12px;white-space:nowrap}
498
507
  .itable .go{display:flex;gap:6px;align-items:center;padding:4px 10px;border:1px solid var(--line);border-radius:4px;white-space:nowrap}.itable .go:hover{background:var(--hover)}.itable .go svg{width:13px;height:13px}.itable .acts{display:flex;gap:6px;justify-content:flex-end;align-items:center}.itable .del{display:grid;place-items:center;width:28px;height:28px;border:1px solid transparent;border-radius:4px;background:none;color:var(--dim);cursor:pointer}.itable .del:hover{color:var(--danger);border-color:var(--line)}.itable .del svg{width:15px;height:15px}.itable .acts .q{color:var(--dim);font-size:12px}.itable .acts .btn{padding:4px 10px;font-size:12px}
@@ -503,6 +512,7 @@ body.ideav #ideasv{flex:1;min-height:0;display:flex;flex-direction:column;gap:0;
503
512
  .tk-q{position:relative;flex:1 1 256px;min-width:0;display:block}.tk-q svg{position:absolute;left:10px;top:9px;width:14px;height:14px;color:var(--dim);pointer-events:none}.tk-q #bq{width:100%;max-width:none;height:32px;margin:0;padding-left:32px;font-size:12px}
504
513
  #tk-tools{display:flex;flex:none;align-items:center;gap:8px}#tk-tools #hx{display:flex;margin:0}
505
514
  .tk-list{flex:0 1 auto;min-height:0;overflow:auto;border:1px solid color-mix(in srgb,var(--line) 50%,transparent);border-top:0;border-radius:0 0 var(--r) var(--r);background:var(--bg)}
515
+ .kpager{position:sticky;bottom:0;z-index:1;display:flex;align-items:center;justify-content:flex-end;gap:10px;padding:8px 12px;border-top:1px solid var(--line);background:var(--bg);font-size:var(--fs-s);color:var(--dim)}.kpager label{display:flex;align-items:center;gap:6px;margin-right:auto}.kpager select{width:auto}
506
516
  .tk-empty{display:flex;flex-direction:column;align-items:center;gap:4px;padding:56px 24px;text-align:center;font-size:14px;color:var(--dim)}.tk-empty svg{width:32px;height:32px;margin-bottom:12px;opacity:.6}.tk-empty p{margin:0;font-size:16px;font-weight:500;color:var(--ink)}
507
517
  .itable th{position:sticky;top:0;z-index:1;height:32px;box-sizing:border-box;padding:0 12px;font-size:11px;font-weight:500;background:color-mix(in srgb,var(--hover) 25%,var(--bg))}.itable td{height:48px;box-sizing:border-box;padding:8px 12px;border-bottom:1px solid color-mix(in srgb,var(--line) 30%,transparent)}.itable tr:last-child td{border-bottom:0}.itable b{font-weight:500}
508
518
  @media(max-width:640px){body.ideav #ideasv{padding:10px}.itable th:nth-child(4),.itable td:nth-child(4){display:none}.itable td,.itable th{padding:8px 6px}}
@@ -848,32 +858,32 @@ aside .foot .more .menu-pop{left:0;right:auto;top:auto;bottom:calc(100% + 4px)}.
848
858
  .ice-open{display:grid;gap:8px;padding:6px 12px 12px 61px}
849
859
  .ice-zero{padding:56px 24px;text-align:center;border:1px solid color-mix(in srgb,var(--line) 50%,transparent);border-top:0;border-radius:0 0 var(--r) var(--r)}
850
860
  /* Swipe view: one request at a time. On a phone it takes the whole screen. */
851
- .sw{display:flex;flex-direction:column;gap:14px;width:100%;height:calc(100dvh - var(--sw-top,130px));min-height:420px}
861
+ .sw{display:flex;flex-direction:column;justify-content:center;gap:16px;width:100%;max-width:680px;margin-inline:auto;height:calc(100dvh - var(--sw-top,130px));min-height:420px}
852
862
  .sw-top{display:flex;align-items:center;gap:10px}.sw-top .btn{flex-shrink:0}
853
- .sw-prog{flex:1;height:6px;border-radius:3px;background:var(--line);overflow:hidden}.sw-prog i{display:block;height:100%;background:var(--accent);transition:width .3s}
863
+ .sw-prog{flex:1;height:3px;border-radius:2px;background:var(--line);overflow:hidden}.sw-prog i{display:block;height:100%;background:var(--accent);transition:width .25s ease-out}
854
864
  .sw-of{color:var(--dim);font-size:12px;white-space:nowrap}
855
- .sw-streak{position:relative;font-size:13px;white-space:nowrap}
865
+ .sw-streak{position:relative;color:var(--dim);font-size:12px;white-space:nowrap}
856
866
  .sw-plus{position:absolute;right:-4px;top:-14px;color:var(--ok);font-size:12px;animation:sw-up .8s ease-out forwards}@keyframes sw-up{to{transform:translateY(-14px);opacity:0}}
857
- .sw-stack{position:relative;flex:1;display:grid;min-height:300px}
858
- .sw-card{grid-area:1/1;position:relative;display:flex;flex-direction:column;gap:10px;padding:20px;border:1px solid var(--line);border-radius:var(--r);background:var(--bg-2);box-shadow:0 6px 24px rgb(0 0 0/.12);touch-action:pan-y;user-select:none;cursor:grab;overflow:auto}
867
+ .sw-stack{position:relative;flex:0 1 auto;display:grid;min-height:300px;overflow:visible}
868
+ .sw-card{grid-area:1/1;position:relative;display:flex;flex-direction:column;gap:14px;padding:24px;border:1px solid var(--line);border-radius:12px;background:var(--bg-2);box-shadow:var(--shadow-2);touch-action:pan-y;user-select:none;cursor:grab;overflow:auto}
859
869
  .sw-card.drag{transition:none;cursor:grabbing}.sw-card:focus{outline:none}.sw-card:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
860
- .sw-card.back{transform:scale(.95) translateY(10px);opacity:.6;pointer-events:none;overflow:hidden}
870
+ .sw-card.back{transform:scale(.96) translateY(10px);opacity:.5;pointer-events:none;overflow:hidden}
861
871
  .sw-card.lift{position:fixed;z-index:95;margin:0}
862
872
  .sw-hd{display:flex;align-items:center;gap:8px;color:var(--dim);font-size:12px}.sw-proj{display:inline-flex;align-items:center;gap:5px;padding:2px 8px;border:1px solid var(--line);border-radius:999px;color:var(--ink);max-width:45%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.sw-src{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
863
- .sw-t{font-size:clamp(20px,2vw,34px);line-height:1.45;margin:0;white-space:pre-wrap;overflow-wrap:anywhere}
864
- .sw-card .ice-notes{max-height:none}
873
+ .sw-t{font-size:20px;font-weight:500;line-height:1.5;margin:0;color:var(--ink-hi);white-space:pre-wrap;overflow-wrap:anywhere}
874
+ .sw-card .ice-notes{max-height:none;font-size:14px;line-height:1.65;color:var(--dim)}
865
875
  .sw-stamp{position:absolute;top:18px;padding:4px 12px;border:3px solid;border-radius:8px;font-weight:700;font-size:20px;letter-spacing:.06em;text-transform:uppercase;pointer-events:none;opacity:0}
866
876
  .sw-stamp.pro{left:18px;color:var(--ok);transform:rotate(-12deg);opacity:max(0,var(--p,0))}
867
877
  .sw-stamp.dis{right:18px;color:var(--danger);transform:rotate(12deg);opacity:max(0,calc(-1*var(--p,0)))}
868
- .sw-acts{display:flex;justify-content:center;gap:18px;padding-bottom:4px}
869
- .sw-b{display:flex;flex-direction:column;align-items:center;gap:4px;background:none;border:0;color:var(--ink);cursor:pointer;font:inherit}
870
- .sw-b span{display:grid;place-items:center;width:52px;height:52px;border-radius:50%;border:1px solid var(--line);background:var(--bg-2);font-size:18px;transition:transform .12s}
871
- .sw-b span svg{width:20px;height:20px}.sw-b small{color:var(--dim);font-size:11px}
872
- .sw-b.pro span,.sw-b.dis span{width:62px;height:62px}.sw-b.pro span{color:var(--ok);border-color:currentColor}.sw-b.dis span{color:var(--danger);border-color:currentColor}
873
- .sw-b:hover:not(:disabled) span{transform:scale(1.08)}.sw-b:disabled{opacity:.35;cursor:default}
878
+ .sw-acts{display:grid;grid-template-columns:1fr auto auto 1fr;gap:8px}
879
+ .sw-b{display:flex;align-items:center;justify-content:center;gap:8px;min-height:44px;padding:0 14px;border:1px solid var(--line);border-radius:var(--r-s);background:none;color:var(--ink);cursor:pointer;font:inherit;font-size:var(--fs);transition:background .15s,border-color .15s,color .15s}
880
+ .sw-b span{display:grid;place-items:center}
881
+ .sw-b span svg{width:16px;height:16px}.sw-b small{font-size:inherit}.sw-b kbd{padding:0 5px;border:1px solid var(--line);border-radius:4px;color:var(--dim);font:11px/16px var(--mono)}
882
+ .sw-b.pro{background:var(--ink-hi);border-color:var(--ink-hi);color:var(--bg);font-weight:500}.sw-b.pro kbd{border-color:currentColor;color:inherit;opacity:.6}.sw-b.dis{color:var(--danger)}
883
+ .sw-b:hover:not(:disabled){background:var(--hover)}.sw-b.pro:hover:not(:disabled){background:var(--ink);border-color:var(--ink)}.sw-b:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.sw-b:disabled{opacity:.35;cursor:default}
874
884
  .sw-zero{position:relative;flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;text-align:center;padding:40px 16px;border:1px solid var(--line);border-radius:var(--r);background:var(--bg-2);overflow:hidden}.sw-zero h4{font-size:20px;margin:0}.sw-zero p{margin:0;color:var(--dim)}
875
885
  .sw-confetti i{position:absolute;top:-10px;left:var(--x);width:8px;height:12px;background:hsl(var(--h) 80% 60%);animation:sw-fall 1.6s var(--d) ease-in forwards}@keyframes sw-fall{to{transform:translateY(420px) rotate(540deg);opacity:0}}
876
- @media (max-width:640px){.sw{position:fixed;inset:0;z-index:90;height:auto;min-height:0;padding:max(12px,env(safe-area-inset-top)) 16px max(16px,env(safe-area-inset-bottom));background:var(--bg)}.sw-t{font-size:20px}.sw-acts{gap:22px}}
886
+ @media (max-width:640px){.sw{position:fixed;inset:0;z-index:90;height:auto;min-height:0;justify-content:flex-start;padding:max(12px,env(safe-area-inset-top)) 16px max(16px,env(safe-area-inset-bottom));background:var(--bg)}.sw-stack{flex:1}.sw-t{font-size:18px}.sw-card .ice-notes{font-size:16px}.sw-b kbd{display:none}.sw-acts{grid-template-columns:1fr 1fr}.sw-b{min-height:48px}.sw-b.pro{order:2}.sw-b.dis{order:1}.sw-b:not(.pro):not(.dis){order:3}}@media(prefers-reduced-motion:reduce){.sw-prog i,.sw-b{transition:none}}
877
887
  .ice-zero h4{margin:0 0 6px;font-size:16px;font-weight:500;color:var(--ink)}
878
888
  .ice-zero p{margin:0 auto;font-size:12px;color:var(--dim);line-height:1.5}
879
889
  .ice-open .hint{font-size:12px;color:var(--dim)}