kaizen-agent 1.54.0 → 1.55.0

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.
@@ -8,7 +8,7 @@ import { readInbox, writeInbox, replaceIdea, parseItem } from "./state.ts";
8
8
  import {
9
9
  readSources, addSource, removeSource, ingest, checkUrl, resolvesPublic, exportUrl, fetchText, split, sift,
10
10
  gatherSource, freshImages, gatherAll, due, takeImages, sheetImages, docImages, imagesUrl, SIGN_IN, UNREADABLE, CAP, moveSource, gatherDirs, writeSources,
11
- readIcebox, writeIcebox, promote, markDone, addItem, githubRepo, dismiss, markReplied, setCategory, socialUrl, socialOf, AGENT_ONLY, PLATFORMS,
11
+ readIcebox, writeIcebox, promote, markDone, addItem, githubRepo, dismiss, markReplied, setCategory, setPaused, socialUrl, socialOf, AGENT_ONLY, PLATFORMS,
12
12
  } from "./sources.ts";
13
13
 
14
14
  const root = realpathSync(mkdtempSync(join(tmpdir(), "kaizen-src-"))); // macOS: tmpdir is a symlink into /private
@@ -34,6 +34,15 @@ test("sources: add, list, remove; refuses a duplicate and a bad link", () => {
34
34
  expect(readSources(state)).toEqual([]);
35
35
  });
36
36
 
37
+ test("setPaused: on pauses the source, off clears the flag", () => {
38
+ addSource(state, SHEET);
39
+ expect(setPaused(state, SHEET, true)).toBeNull();
40
+ expect(readSources(state)[0]!.paused).toBe(true);
41
+ expect(setPaused(state, SHEET, false)).toBeNull();
42
+ expect("paused" in readSources(state)[0]!).toBe(false);
43
+ expect(setPaused(state, "https://example.com/none", true)).toBe("no such source");
44
+ });
45
+
37
46
  test("exportUrl: sheet, published sheet, doc, anything else", () => {
38
47
  expect(exportUrl(SHEET)).toEqual({ url: "https://docs.google.com/spreadsheets/d/abc123/export?format=tsv&gid=7", kind: "sheet" });
39
48
  expect(exportUrl("https://docs.google.com/spreadsheets/d/abc123/edit?gid=42").url).toEndWith("gid=42");
package/cli/sources.ts CHANGED
@@ -10,7 +10,7 @@ import { lookup as dnsLookup } from "node:dns/promises";
10
10
  import { readInbox, writeInbox, normalise, formatNote, parseItem, readRuns, readText } from "./state.ts";
11
11
 
12
12
  export type Last = { at: string; ok: boolean; added: number; note: string };
13
- export type Source = { url: string; label?: string; category?: string; added: string; last?: Last; seen: string[]; writeback?: boolean };
13
+ export type Source = { url: string; label?: string; category?: string; added: string; last?: Last; seen: string[]; writeback?: boolean; paused?: boolean };
14
14
  export type Result = { url: string } & Last;
15
15
 
16
16
  const file = (state: string) => join(state, "sources.json");
@@ -94,6 +94,16 @@ export function setWriteback(state: string, url: string, on: boolean): string |
94
94
  return null;
95
95
  }
96
96
 
97
+ // Whether the board's scheduled gather skips this source. Check now still reads it.
98
+ export function setPaused(state: string, url: string, on: boolean): string | null {
99
+ const list = readSources(state);
100
+ const src = list.find((s) => s.url === url);
101
+ if (!src) return "no such source";
102
+ if (on) src.paused = true; else delete src.paused;
103
+ writeSources(state, list);
104
+ return null;
105
+ }
106
+
97
107
  // Drops the entry and its seen list. Items already gathered stay in the icebox.
98
108
  export function removeSource(state: string, url: string): string | null {
99
109
  const list = readSources(state);
package/cli/web.ts CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  launchMode, readSessions, ownerOf, runIndex, resumePrompt, runAgent, firstSession, webHosts,
11
11
  } from "./state.ts";
12
12
  import { attachPty, writePty, resizePty, exitPty, ptyState, ptyKeys, adoptLoginEnv } from "./pty.ts";
13
- import { readSources, addSource, removeSource, moveSource, setCategory, setWriteback, readIcebox, promote, dismiss, restore, addItem, githubRepo, markDone, markReplied, gatherSource, freshImages, gatherAll, gatherDirs, due, socialUrl, socialOf } from "./sources.ts";
13
+ import { readSources, addSource, removeSource, moveSource, setCategory, setWriteback, setPaused, readIcebox, promote, dismiss, restore, addItem, githubRepo, markDone, markReplied, gatherSource, freshImages, gatherAll, gatherDirs, due, socialUrl, socialOf } from "./sources.ts";
14
14
  import { projectLogo, LOGO_TYPES } from "./logo.ts";
15
15
  import * as chatgpt from "./chatgpt.ts";
16
16
  import * as google from "./google.ts";
@@ -354,7 +354,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
354
354
  // Social sources need a reader that picks posts: only ChatGPT can do that unattended.
355
355
  const gpt = await setting("sources.agent") === "chatgpt" && chatgpt.status().connected;
356
356
  for (const s of list) {
357
- if (!due(s, ms, Date.now())) continue;
357
+ if (s.paused || !due(s, ms, Date.now())) continue;
358
358
  if (!socialOf(s.url)) { if ((await gatherSource(dir, s.url)).added) changed(); }
359
359
  else if (gpt) { await chatgpt.gatherSource(dir, s.url, await setting("sources.model"), (await setting("sources.effort")) || "low"); changed(); }
360
360
  }
@@ -1191,6 +1191,9 @@ export async function web(repoDir: string, opts: Opts = {}) {
1191
1191
  } else if (body.op === "writeback") {
1192
1192
  const why = setWriteback(dir, link, body.on === true);
1193
1193
  if (why) return bad(why, 404);
1194
+ } else if (body.op === "paused") {
1195
+ const why = setPaused(dir, link, body.on === true);
1196
+ if (why) return bad(why, 404);
1194
1197
  } else if (body.op === "remove") {
1195
1198
  const why = removeSource(dir, link);
1196
1199
  if (why) return bad(why, 404);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaizen-agent",
3
- "version": "1.54.0",
3
+ "version": "1.55.0",
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": {
@@ -3,9 +3,9 @@ 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, raw, SKEL } from "./dom.ts";
6
+ import { $, dataUrls, html, ico, modal, motion, raw, SKEL } from "./dom.ts";
7
7
  import { ideaCombo, newDir, plogo, setShown, short, showable } from "./projects.ts";
8
- import { toast } from "./toast.ts";
8
+ import { playSound, soundPick, toast } from "./toast.ts";
9
9
  import { go, view } from "./views.ts";
10
10
 
11
11
  // ---- the icebox: requests gathered from request sources, read like an inbox, until
@@ -42,6 +42,13 @@ export let iceForm = null,
42
42
  iceBusy = false,
43
43
  iceNav = null;
44
44
  const iceSel = new Set();
45
+ // The swipe view: one waiting request at a time, decided by drag, button or arrow key.
46
+ // Null when the list shows. It counts this session's decisions, keeps the last dismiss
47
+ // for Undo, and how often each request was skipped (skipped ones go to the back).
48
+ let iceSwipe = null;
49
+ // A rebuild while the card is held would drop the drag: it waits for the release.
50
+ let swHeld = false,
51
+ swLate = false;
45
52
  const PLAT = { x: "X", tiktok: "TikTok", instagram: "Instagram", threads: "Threads" };
46
53
  export const srcOpen = () => $("panel").classList.contains("open") && $("ptitle").textContent === SRC;
47
54
  const ago = (at) => {
@@ -109,6 +116,10 @@ function wirePick(id, set) {
109
116
  };
110
117
  }
111
118
  export async function openSources() {
119
+ if (swHeld) {
120
+ swLate = true;
121
+ return;
122
+ }
112
123
  if (view !== "sources") return;
113
124
  const gen = ++store.pageGen;
114
125
  stopDictation(true);
@@ -217,7 +228,7 @@ export async function openSources() {
217
228
  : html`<span class="src-badge warn"><svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" stroke="currentColor" fill="none" stroke-width="1.8"/><path d="M8 5v3.5M8 11v.1" stroke="currentColor" fill="none" stroke-width="2" stroke-linecap="round"/></svg>Failed: ${s.last.note}</span><span class="hint" style="margin:0">${ago(s.last.at)}</span>`;
218
229
  const kind = st === "sheet" ? "sheet" : st === "doc" ? "doc" : st === "social" ? "at" : "link",
219
230
  bare = s.url.replace(/^https?:\/\/(www\.)?/, "");
220
- return html`<div class="src-card" id="src-card-${i}"><div class="src-hd"><span class="src-ico" title="${st === "social" ? (PLAT[s.social] || "social") : st}">${fav(s.url, kind, s.social)}</span><div class="src-info"><span class="src-title" title="${title}">${title}</span><a class="src-url" href="${s.url}" target="_blank" rel="noopener noreferrer" title="${s.url}"><span>${bare}</span>${ico("ext")}</a></div><div class="src-acts">${s.social ? html`<button class="ib sm" id="src-ag-${i}" data-ag="${i}" aria-label="Gather ${title} with your agent" title="${chatOn ? "Gather with your ChatGPT plan" : "Gather: opens your agent on /kaizen gather"}">${ico("refresh")}</button>` : html`<button class="ib sm" id="src-chk-${i}" data-chk="${i}" aria-label="Check ${title} now" title="Check now">${ico("refresh")}</button>`}<button class="ib sm danger" id="src-rm-${i}" data-rm="${i}" aria-label="Remove ${title}" title="Remove source">${ico("trash")}</button></div></div><div class="src-status">${statusHtml}</div><div class="src-fields"><label class="src-f" title="Category"><span>Category</span><input class="sel" id="src-ct-${i}" data-ct="${i}" data-k="${s.dir + " " + s.url}" value="${s.category || ""}" placeholder="${platOf(s)}" maxlength="40" aria-label="Category of ${title}"><button class="btn sm pri" id="src-cs-${i}" aria-label="Save the category of ${title}" disabled>Save</button></label><label class="src-f" title="Project"><span>Project</span>${plogo(s.dir, s.project || "")}<select class="sel" id="src-mv-${i}" data-mv="${i}" data-k="${s.dir + " " + s.url}" aria-label="Project of ${title}">${opts(s.dir, s.project)}</select><button class="btn sm pri" id="src-mb-${i}" aria-label="Move ${title} to the chosen project" disabled>Move</button></label>${st === "sheet" || /github\.com/.test(s.url) ? html`<label class="src-wb"><input type="checkbox" id="src-wb-${i}" data-wb="${i}"${s.writeback ? " checked" : ""}> Write back</label>` : ""}</div></div>`;
231
+ return html`<div class="src-card" id="src-card-${i}"><div class="src-hd"><span class="src-ico" title="${st === "social" ? (PLAT[s.social] || "social") : st}">${fav(s.url, kind, s.social)}</span><div class="src-info"><span class="src-title" title="${title}">${title}</span><a class="src-url" href="${s.url}" target="_blank" rel="noopener noreferrer" title="${s.url}"><span>${bare}</span>${ico("ext")}</a></div><div class="src-acts">${s.social ? html`<button class="ib sm" id="src-ag-${i}" data-ag="${i}" aria-label="Gather ${title} with your agent" title="${chatOn ? "Gather with your ChatGPT plan" : "Gather: opens your agent on /kaizen gather"}">${ico("refresh")}</button>` : html`<button class="ib sm" id="src-chk-${i}" data-chk="${i}" aria-label="Check ${title} now" title="Check now">${ico("refresh")}</button>`}<button class="ib sm danger" id="src-rm-${i}" data-rm="${i}" aria-label="Remove ${title}" title="Remove source">${ico("trash")}</button></div></div><div class="src-status">${statusHtml}</div><div class="src-fields"><label class="src-f" title="Category"><span>Category</span><input class="sel" id="src-ct-${i}" data-ct="${i}" data-k="${s.dir + " " + s.url}" value="${s.category || ""}" placeholder="${platOf(s)}" maxlength="40" aria-label="Category of ${title}"><button class="btn sm pri" id="src-cs-${i}" aria-label="Save the category of ${title}" disabled>Save</button></label><label class="src-f" title="Project"><span>Project</span>${plogo(s.dir, s.project || "")}<select class="sel" id="src-mv-${i}" data-mv="${i}" data-k="${s.dir + " " + s.url}" aria-label="Project of ${title}">${opts(s.dir, s.project)}</select><button class="btn sm pri" id="src-mb-${i}" aria-label="Move ${title} to the chosen project" disabled>Move</button></label></div><div class="src-sws">${st === "sheet" || /github\.com/.test(s.url) ? html`<label class="src-sw">Write back<button class="chk sm${s.writeback ? " on" : ""}" id="src-wb-${i}" data-wb="${i}" role="switch" aria-checked="${String(!!s.writeback)}" aria-label="Write back to ${title}"></button></label>` : ""}<label class="src-sw" title="Off: the scheduled gather skips this source; Check now still reads it">Auto gather<button class="chk sm${s.paused ? "" : " on"}" id="src-ag-on-${i}" data-ag-on="${i}" role="switch" aria-checked="${String(!s.paused)}" aria-label="Auto gather ${title}"></button></label></div></div>`;
221
232
  });
222
233
  const fails = ((d && d.failed) || []).map((f) => html`<p style="color:var(--dim)">The sources of ${f} could not be read.</p>`);
223
234
  const emptyState = html`<div class="src-empty"><div class="src-empty-ico">${ico("link")}</div><h4>No sources yet</h4></div>`;
@@ -279,6 +290,7 @@ export async function openSources() {
279
290
  });
280
291
  // Rows in the order they are drawn, which is the order j and k walk.
281
292
  const order = [...groups.values()].flat();
293
+ const isWaiting = (it) => !["promoted", "dismissed", "done"].includes(it.status);
282
294
  // A checked request a filter hides is unchecked: a bulk action only ever acts on what shows.
283
295
  {
284
296
  const vis = new Set(order.map((i) => iceKey(ice[i])));
@@ -324,7 +336,7 @@ export async function openSources() {
324
336
  )}`,
325
337
  )
326
338
  : ""}`;
327
- const bar = html`<div class="ice-bar">${order.length ? html`<input type="checkbox" id="ice-all" aria-label="Select every request shown"${nSel && nSel === order.length ? " checked" : ""}>` : ""}<span class="count">${iceCat === "Dismissed" || iceCat === "Done" ? `${order.length} ${iceCat.toLowerCase()}` : `${order.length < waiting ? `${order.length} of ${waiting}` : waiting} waiting`}</span><span class="end"></span>${String(chips) ? html`<details class="ice-filt"><summary class="ib${iceCat || iceSrc ? " on" : ""}" aria-label="Filter requests" title="Filter requests">${ico("filter")}</summary><div class="ice-fpop">${chips}</div></details>` : ""}<button class="btn ghost sm" id="ice-new" title="Add a request by hand">${ico("plus")} Add</button><button class="btn sm" id="src-go"${list.length ? "" : " disabled"}>${ico("refresh")} Gather all</button><button class="btn ghost sm" id="src-tog" aria-expanded="${String(!!srcShow)}" aria-controls="src-sec">${ico("link")} Sources · ${list.length}</button></div>`;
339
+ const bar = html`<div class="ice-bar">${order.length ? html`<input type="checkbox" id="ice-all" aria-label="Select every request shown"${nSel && nSel === order.length ? " checked" : ""}>` : ""}<span class="count">${iceCat === "Dismissed" || iceCat === "Done" ? `${order.length} ${iceCat.toLowerCase()}` : `${order.length < waiting ? `${order.length} of ${waiting}` : waiting} waiting`}</span><span class="end"></span>${String(chips) ? html`<details class="ice-filt"><summary class="ib${iceCat || iceSrc ? " on" : ""}" aria-label="Filter requests" title="Filter requests">${ico("filter")}</summary><div class="ice-fpop">${chips}</div></details>` : ""}${order.some((i) => isWaiting(ice[i])) ? html`<button class="btn ghost sm" id="ice-sw" title="Sort one at a time: swipe right to promote, left to dismiss"><span aria-hidden="true">⇆</span> Swipe</button>` : ""}<button class="btn ghost sm" id="ice-new" title="Add a request by hand">${ico("plus")} Add</button><button class="btn sm" id="src-go"${list.length ? "" : " disabled"}>${ico("refresh")} Gather all</button><button class="btn ghost sm" id="src-tog" aria-expanded="${String(!!srcShow)}" aria-controls="src-sec">${ico("link")} Sources · ${list.length}</button></div>`;
328
340
  const bulk = iceSel.size
329
341
  ? html`<div class="ice-bulk" role="toolbar" aria-label="Selected requests"><span>${iceSel.size} selected</span><span class="end"></span><button class="btn sm" id="ice-bp" title="Promote (p)">${ico("plus")} Promote</button><button class="btn ghost sm" id="ice-bd" title="Dismiss (d)">${ico("x")} Dismiss</button><button class="btn ghost sm" id="ice-bc" title="Clear selection (Esc)">Clear</button></div>`
330
342
  : "";
@@ -347,13 +359,15 @@ export async function openSources() {
347
359
  if (r.wait) return html`<div class="ice-form-acts"><span class="hint">Drafting…</span></div>`;
348
360
  return html`<div class="ice-form"><label for="ice-reply" class="hint" style="margin:0">Your reply${r.note ? ` · ${r.note}` : ""}</label><textarea class="sel" id="ice-reply" rows="3" maxlength="2000" aria-label="Your reply"${r.busy || r.again ? " disabled" : ""}>${r.text}</textarea><span class="hint" id="ice-rn" style="margin:0">${r.again ? "Writing another…" : `${r.text.length} chars`}</span><div class="ice-form-acts"><span class="end"></span>${G.connected ? html`${style(r.busy || r.again)}<button class="btn ghost sm" id="ice-rg"${r.busy || r.again ? " disabled" : ""}>Regenerate</button>` : ""}<button class="btn ghost sm" id="ice-rc"${r.busy ? " disabled" : ""}>Cancel</button><button class="btn pri sm" id="ice-rs"${r.busy || r.again || !r.text.trim() ? " disabled" : ""}>${r.busy ? "Sending…" : "Send reply"}</button></div></div>`;
349
361
  };
362
+ const imgs = (it) =>
363
+ (it.images || []).filter((u) => /^https:\/\//.test(u)).length ? html`<details class="ice-imgs"><summary>Show images (${it.images.filter((u) => /^https:\/\//.test(u)).length}) — loads them from the source's site</summary>${it.images.filter((u) => /^https:\/\//.test(u)).map((u, n) => { const src = `/ice-image?dir=${encodeURIComponent(it.dir)}&id=${encodeURIComponent(it.id)}&i=${n}`; return html`<a href="${src}" target="_blank" rel="noopener noreferrer"><img data-src="${src}" alt="" referrerpolicy="no-referrer"></a>`; })}</details>` : "";
350
364
  const row = (i) => {
351
365
  const it = ice[i],
352
366
  k = iceKey(it),
353
367
  open = iceForm === k;
354
368
  const head = html`<div class="ice-row${iceCur === k ? " cur" : ""}${iceSel.has(k) ? " sel" : ""}" data-i="${i}" data-k="${k}"><input type="checkbox" id="ice-ck-${i}" data-ck="${i}"${iceSel.has(k) ? " checked" : ""} aria-label="Select: ${it.text}"><span class="ice-src" title="${srcName(it)}">${fav(it.source, "link", list.find((x) => x.dir === it.dir && x.url === it.source)?.social)}</span><button class="ice-t" id="ice-o-${i}" data-o="${i}" aria-expanded="${String(open)}" title="${it.text}">${it.text}</button><span class="ice-meta">${many ? html`<span class="nm" title="${it.project || ""}">${plogo(it.dir, it.project || "")}${short(it.project || "")}</span>` : ""}${it.status === "done" && it.written ? html`<span title="Written back ${ago(it.written)}">written back</span>` : ""}${it.status === "done" && it.writeError ? html`<span title="${it.writeError}">write-back failed</span>` : ""}${it.status === "promoted" ? html`<span title="Promoted to Ideas: ${it.idea || ""}">promoted</span>` : ""}${it.replied ? html`<span title="Replied ${ago(it.replied)}">replied</span>` : ""}<span class="ice-age">${ago(it.at)}</span><span class="ice-ra">${it.status === "promoted" || it.status === "done" ? "" : html`<button class="btn ghost sm" id="ice-pr-${i}" data-pr="${i}" title="Promote to Ideas (p)" aria-label="Promote to Ideas: ${it.text}">${ico("plus")}</button>`}${it.status === "promoted" || it.status === "done" ? "" : it.status === "dismissed" ? html`<button class="btn ghost sm" id="ice-rs-${i}" data-rs="${i}" title="Restore to waiting" aria-label="Restore: ${it.text}">Restore</button>` : html`<button class="btn ghost sm" id="ice-ds-${i}" data-ds="${i}" title="Dismiss (d)" aria-label="Dismiss: ${it.text}">${ico("x")}</button>`}</span></span></div>`;
355
369
  const more = open
356
- ? html`<div class="ice-open">${it.notes ? html`<div class="ice-notes">${it.notes}</div>` : ""}${(it.images || []).filter((u) => /^https:\/\//.test(u)).length ? html`<details class="ice-imgs"><summary>Show images (${it.images.filter((u) => /^https:\/\//.test(u)).length}) — loads them from the source's site</summary>${it.images.filter((u) => /^https:\/\//.test(u)).map((u, n) => { const src = `/ice-image?dir=${encodeURIComponent(it.dir)}&id=${encodeURIComponent(it.id)}&i=${n}`; return html`<a href="${src}" target="_blank" rel="noopener noreferrer"><img data-src="${src}" alt="" referrerpolicy="no-referrer"></a>`; })}</details>` : ""}<span class="hint" style="margin:0">From ${srcName(it)} · ${ago(it.at)}${it.post ? html` · <a href="${it.post}" target="_blank" rel="noopener">open post</a>` : ""}</span>${replyBox(it)}${icePro === k ? form(it) : ""}</div>`
370
+ ? html`<div class="ice-open">${it.notes ? html`<div class="ice-notes">${it.notes}</div>` : ""}${imgs(it)}<span class="hint" style="margin:0">From ${srcName(it)} · ${ago(it.at)}${it.post ? html` · <a href="${it.post}" target="_blank" rel="noopener">open post</a>` : ""}</span>${replyBox(it)}${icePro === k ? form(it) : ""}</div>`
357
371
  : "";
358
372
  return html`${head}${more}`;
359
373
  };
@@ -363,6 +377,51 @@ export async function openSources() {
363
377
  : order.length
364
378
  ? html`<div class="ice-list">${[...groups].map(([g, ix]) => html`<div class="ice-cat">${g}<i>${ix.length}</i></div>${ix.map(row)}`)}</div>`
365
379
  : 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
+ // Swipe: the waiting requests the filters show, least skipped first; a restored one
381
+ // comes back on top. Nothing is written by a skip.
382
+ 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))
384
+ : [];
385
+ // The card always names its project: a swipe decides for that project's Ideas.
386
+ const pName = (it) => it.project || store.S.projects.find((p) => p.dir === it.dir)?.label || "";
387
+ const swCard = (i, back) => {
388
+ const it = ice[i];
389
+ return html`<div class="sw-card${back ? " back" : ""}"${back ? raw(' aria-hidden="true"') : raw(' id="sw-card" tabindex="-1" aria-label="Request: swipe or press → to promote, ← to dismiss"')}><div class="sw-hd">${fav(it.source, "link", srcOf(it)?.social)}<span class="sw-src" title="${srcName(it)}">${srcName(it)}</span><span class="sw-proj" title="${pName(it)}">${plogo(it.dir, pName(it))}${short(pName(it))}</span><span class="ice-age">${ago(it.at)}</span></div><p class="sw-t">${it.text}</p>${back ? "" : html`${it.notes ? html`<div class="ice-notes">${it.notes}</div>` : ""}${imgs(it)}${it.post ? html`<a class="hint" href="${it.post}" target="_blank" rel="noopener">open post</a>` : ""}<span class="sw-stamp pro">Promote</span><span class="sw-stamp dis">Dismiss</span>`}</div>`;
390
+ };
391
+ // Icebox zero: the day's streak counts days in a row the stack was emptied, per project
392
+ // filter, in this browser only.
393
+ const swZero = () => {
394
+ const S = iceSwipe;
395
+ if (S.n && S.days === undefined) {
396
+ const key = "kz-ice-streak:" + (dir || "all"),
397
+ day = (t) => new Date(t).toLocaleDateString("sv"),
398
+ today = day(Date.now());
399
+ let st = { last: "", days: 0 };
400
+ try {
401
+ st = JSON.parse(localStorage.getItem(key) || "") || st;
402
+ } catch (e) {}
403
+ if (st.last !== today) st = { last: today, days: st.last === day(Date.now() - 864e5) ? st.days + 1 : 1 };
404
+ try {
405
+ localStorage.setItem(key, JSON.stringify(st));
406
+ } catch (e) {}
407
+ S.days = st.days;
408
+ }
409
+ const s = Math.round((Date.now() - S.t0) / 1000),
410
+ took = s < 60 ? s + " s" : Math.floor(s / 60) + " min " + (s % 60) + " s";
411
+ 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>`;
413
+ };
414
+ const swipe = () => {
415
+ const S = iceSwipe,
416
+ total = S.n + deck.length,
417
+ pop = S.pop;
418
+ 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>`;
420
+ if (!deck.length) return html`<div class="sw" id="sw">${top}${swZero()}</div>`;
421
+ 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>`;
423
+ 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
+ };
366
425
  // The sources, in the right-hand drawer: shut until asked for. Slid in only when opened;
367
426
  // a rebuild while open shows it in place.
368
427
  const drawer = !!srcShow,
@@ -380,7 +439,9 @@ export async function openSources() {
380
439
  ? html`<p style="color:var(--dim)">${d.error}</p>`
381
440
  : !d
382
441
  ? html`<p style="color:var(--dim)">The icebox could not be read.</p>`
383
- : html`${onb}${bar}${bulk}${fails}${inbox}${sec}`;
442
+ : iceSwipe
443
+ ? html`${swipe()}${sec}`
444
+ : html`${onb}${bar}${bulk}${fails}${inbox}${sec}`;
384
445
  if (!d || d.error) return;
385
446
  const body = $("src-sec")?.querySelector(".body");
386
447
  if (body) body.scrollTop = at;
@@ -481,12 +542,13 @@ export async function openSources() {
481
542
  srcShut();
482
543
  }
483
544
  };
484
- $("src-tog").onclick = () => {
545
+ const srcTog = () => {
485
546
  if ($("src-sec").classList.contains("open")) return srcShut();
486
547
  srcShow = true;
487
548
  openSources().then(() => srcShow && $("src-url")?.focus());
488
549
  };
489
- if ($("ice-addsrc")) $("ice-addsrc").onclick = $("src-tog").onclick;
550
+ if ($("src-tog")) $("src-tog").onclick = srcTog;
551
+ if ($("ice-addsrc")) $("ice-addsrc").onclick = srcTog;
490
552
  wirePick("ice-fs", (v) => {
491
553
  iceSrc = v;
492
554
  openSources();
@@ -539,18 +601,26 @@ export async function openSources() {
539
601
  .querySelectorAll("[data-wb]")
540
602
  .forEach((m) => {
541
603
  const s = list[+m.dataset.wb];
542
- m.onchange = () => {
543
- if (m.checked && s.social === undefined && /docs\.google\.com/.test(s.url) && !(d.google || {}).connected) {
604
+ m.onclick = () => {
605
+ const on = !m.classList.contains("on");
606
+ if (on && s.social === undefined && /docs\.google\.com/.test(s.url) && !(d.google || {}).connected) {
544
607
  alert("Connect Google first (Sources header), so kaizen can write to the sheet.");
545
- m.checked = false;
546
- return;
547
- }
548
- if (m.checked && !confirm("When a promoted request's run is done, kaizen will write that back to this source. A closed issue or a changed cell is visible to others. Turn on?")) {
549
- m.checked = false;
550
608
  return;
551
609
  }
552
- act({ op: "writeback", dir: s.dir, url: s.url, on: m.checked }, () =>
553
- toast(m.checked ? "Write back on" : "Write back off"),
610
+ if (on && !confirm("When a promoted request's run is done, kaizen will write that back to this source. A closed issue or a changed cell is visible to others. Turn on?")) return;
611
+ act({ op: "writeback", dir: s.dir, url: s.url, on }, () =>
612
+ toast(on ? "Write back on" : "Write back off"),
613
+ );
614
+ };
615
+ });
616
+ $("pbody")
617
+ .querySelectorAll("[data-ag-on]")
618
+ .forEach((m) => {
619
+ const s = list[+m.dataset.agOn];
620
+ m.onclick = () => {
621
+ const on = !m.classList.contains("on");
622
+ act({ op: "paused", dir: s.dir, url: s.url, on: !on }, () =>
623
+ toast(on ? "Auto gather on" : "Auto gather off"),
554
624
  );
555
625
  };
556
626
  });
@@ -802,10 +872,142 @@ export async function openSources() {
802
872
  if (e.key === "Escape") $("ice-cancel").click();
803
873
  };
804
874
  }
875
+ // Swipe: a decision flies the card off, clicks (when the board's sound is on), then posts.
876
+ const swGo = async (op) => {
877
+ const S = iceSwipe,
878
+ i = deck[0];
879
+ if (!S || S.busy || i === undefined) return;
880
+ const it = ice[i],
881
+ k = iceKey(it);
882
+ if (op === "skip") {
883
+ if (deck.length < 2) return;
884
+ S.skip.set(k, Math.max(...deck.map((x) => S.skip.get(iceKey(ice[x])) || 0)) + 1);
885
+ return openSources();
886
+ }
887
+ S.busy = true;
888
+ const c = $("sw-card");
889
+ if (c && motion()) {
890
+ lift(c);
891
+ const dir = op === "promote" ? 1 : -1;
892
+ await c
893
+ .animate([{ transform: getComputedStyle(c).transform }, { transform: `translateX(${dir * innerWidth}px) rotate(${dir * 30}deg)`, opacity: 0 }], {
894
+ duration: 320,
895
+ easing: "cubic-bezier(.3,.6,.4,1)",
896
+ fill: "forwards",
897
+ })
898
+ .finished.catch(() => {});
899
+ }
900
+ if (soundPick() !== "off") playSound("pop");
901
+ const j = await post("/icebox", { op, dir: it.dir, ids: [it.id] });
902
+ S.busy = false;
903
+ if (j.ok) {
904
+ S.n++;
905
+ op === "promote" ? S.pro++ : S.dis++;
906
+ // Only a dismiss can be undone here: a promote has already made an idea card.
907
+ S.last = op === "dismiss" ? it : null;
908
+ S.pop = true;
909
+ } else toast(`Could not ${op}: ${j.error || "the board did not answer"}`);
910
+ load();
911
+ if (srcOpen()) openSources();
912
+ };
913
+ const swUndo = async () => {
914
+ const S = iceSwipe,
915
+ it = S && S.last;
916
+ if (!it || S.busy) return;
917
+ S.busy = true;
918
+ const j = await post("/icebox", { op: "restore", dir: it.dir, ids: [it.id] });
919
+ S.busy = false;
920
+ if (j.ok) {
921
+ S.n--;
922
+ S.dis--;
923
+ S.last = null;
924
+ S.skip.set(iceKey(it), -1);
925
+ toast("Restored");
926
+ }
927
+ load();
928
+ if (srcOpen()) openSources();
929
+ };
930
+ const swExit = () => {
931
+ iceSwipe = null;
932
+ openSources().then(focusCur);
933
+ };
934
+ if ($("ice-sw"))
935
+ $("ice-sw").onclick = () => {
936
+ iceSwipe = { n: 0, pro: 0, dis: 0, t0: Date.now(), last: null, skip: new Map(), busy: false, pop: false };
937
+ openSources().then(() => $("sw-card")?.focus());
938
+ };
939
+ if ($("sw-x")) $("sw-x").onclick = swExit;
940
+ if ($("sw-back")) $("sw-back").onclick = swExit;
941
+ if ($("sw-d")) $("sw-d").onclick = () => swGo("dismiss");
942
+ if ($("sw-p")) $("sw-p").onclick = () => swGo("promote");
943
+ if ($("sw-s")) $("sw-s").onclick = () => swGo("skip");
944
+ if ($("sw-u")) $("sw-u").onclick = swUndo;
945
+ // A held or flying card is fixed to the window where it sits, so the panel's scroll box
946
+ // and the page's own overflow cannot crop it on the way out.
947
+ const lift = (c) => {
948
+ if (c.classList.contains("lift")) return;
949
+ const r = c.getBoundingClientRect();
950
+ Object.assign(c.style, { left: r.left + "px", top: r.top + "px", width: r.width + "px", height: r.height + "px" });
951
+ c.classList.add("lift");
952
+ };
953
+ const drop = (c) => {
954
+ c.classList.remove("lift");
955
+ for (const k of ["left", "top", "width", "height", "transform"]) c.style.removeProperty(k);
956
+ c.style.removeProperty("--p");
957
+ };
958
+ // Drag: the card follows the pointer and tilts; past 100 px it decides, short of that it
959
+ // springs back. --p (-1..1) fades the stamp in. Controls inside the card still click.
960
+ const card = $("sw-card");
961
+ if (card)
962
+ card.onpointerdown = (e) => {
963
+ if (e.button || e.target.closest("a,button,summary,details")) return;
964
+ const x0 = e.clientX;
965
+ let dx = 0;
966
+ card.setPointerCapture(e.pointerId);
967
+ card.classList.add("drag");
968
+ lift(card);
969
+ swHeld = true;
970
+ card.onpointermove = (m) => {
971
+ dx = m.clientX - x0;
972
+ // Tilt by share of the card's width: a wide desktop card leans as much as a phone one.
973
+ card.style.transform = `translateX(${dx}px) rotate(${(dx / card.offsetWidth) * 18}deg)`;
974
+ card.style.setProperty("--p", String(Math.max(-1, Math.min(1, dx / 100))));
975
+ };
976
+ card.onpointerup = card.onpointercancel = () => {
977
+ card.onpointermove = card.onpointerup = card.onpointercancel = null;
978
+ card.classList.remove("drag");
979
+ swHeld = false;
980
+ const late = swLate;
981
+ swLate = false;
982
+ if (Math.abs(dx) > 100) swGo(dx > 0 ? "promote" : "dismiss");
983
+ else {
984
+ const from = card.style.transform;
985
+ card.style.removeProperty("--p");
986
+ const a = motion() && from ? card.animate([{ transform: from }, { transform: "none" }], { duration: 260, easing: "cubic-bezier(.3,1.4,.5,1)" }) : null;
987
+ card.style.transform = "";
988
+ (a ? a.finished.catch(() => {}) : Promise.resolve()).then(() => {
989
+ drop(card);
990
+ if (late) openSources();
991
+ });
992
+ }
993
+ };
994
+ };
805
995
  // Keys, read by the page's keydown while the icebox shows. True when the key was used.
806
996
  iceNav = (e) => {
807
997
  if (e.altKey || e.ctrlKey || e.metaKey) return false;
808
- const k = e.key,
998
+ const k = e.key;
999
+ if (iceSwipe) {
1000
+ if (k === "Escape" && $("src-sec")?.classList.contains("open")) {
1001
+ srcShut();
1002
+ return true;
1003
+ }
1004
+ const f = { ArrowLeft: () => swGo("dismiss"), ArrowRight: () => swGo("promote"), ArrowDown: () => swGo("skip"), z: swUndo, Escape: swExit }[k];
1005
+ if (!f) return false;
1006
+ e.preventDefault();
1007
+ f();
1008
+ return true;
1009
+ }
1010
+ const
809
1011
  at = order.findIndex((i) => iceKey(ice[i]) === iceCur),
810
1012
  i = order[at];
811
1013
  if (k === "Escape") {
package/web/board.html CHANGED
@@ -485,6 +485,33 @@ aside .foot .more .menu-pop{left:0;right:auto;top:auto;bottom:calc(100% + 4px)}.
485
485
  .ice-row:hover .ice-ra,.ice-row.cur .ice-ra,.ice-row:focus-within .ice-ra{display:flex}
486
486
  .ice-open{display:grid;gap:8px;padding:6px 12px 12px 61px}
487
487
  .ice-zero{padding:40px 16px;text-align:center;border:1px solid var(--line);border-radius:var(--r);background:var(--bg-2)}
488
+ /* Swipe view: one request at a time. On a phone it takes the whole screen. */
489
+ .sw{display:flex;flex-direction:column;gap:14px;width:100%;height:calc(100dvh - var(--sw-top,130px));min-height:420px}
490
+ .sw-top{display:flex;align-items:center;gap:10px}.sw-top .btn{flex-shrink:0}
491
+ .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}
492
+ .sw-of{color:var(--dim);font-size:12px;white-space:nowrap}
493
+ .sw-streak{position:relative;font-size:13px;white-space:nowrap}
494
+ .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}}
495
+ .sw-stack{position:relative;flex:1;display:grid;min-height:300px}
496
+ .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}
497
+ .sw-card.drag{transition:none;cursor:grabbing}.sw-card:focus{outline:none}.sw-card:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
498
+ .sw-card.back{transform:scale(.95) translateY(10px);opacity:.6;pointer-events:none;overflow:hidden}
499
+ .sw-card.lift{position:fixed;z-index:95;margin:0}
500
+ .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}
501
+ .sw-t{font-size:clamp(20px,2vw,34px);line-height:1.45;margin:0;white-space:pre-wrap;overflow-wrap:anywhere}
502
+ .sw-card .ice-notes{max-height:none}
503
+ .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}
504
+ .sw-stamp.pro{left:18px;color:var(--ok);transform:rotate(-12deg);opacity:max(0,var(--p,0))}
505
+ .sw-stamp.dis{right:18px;color:var(--danger);transform:rotate(12deg);opacity:max(0,calc(-1*var(--p,0)))}
506
+ .sw-acts{display:flex;justify-content:center;gap:18px;padding-bottom:4px}
507
+ .sw-b{display:flex;flex-direction:column;align-items:center;gap:4px;background:none;border:0;color:var(--ink);cursor:pointer;font:inherit}
508
+ .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}
509
+ .sw-b span svg{width:20px;height:20px}.sw-b small{color:var(--dim);font-size:11px}
510
+ .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}
511
+ .sw-b:hover:not(:disabled) span{transform:scale(1.08)}.sw-b:disabled{opacity:.35;cursor:default}
512
+ .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)}
513
+ .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}}
514
+ @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}}
488
515
  .ice-zero h4{margin:0 0 6px;font-size:14px;font-weight:600;color:var(--ink)}
489
516
  .ice-zero p{margin:0 auto;font-size:12px;color:var(--dim);line-height:1.5}
490
517
  .ice-open .hint{font-size:12px;color:var(--dim)}
@@ -526,7 +553,9 @@ body:not(.paged) .src-sec,body:not(.paged) .src-scrim{display:none}
526
553
  .src-f .sel:hover,.src-f .sel:focus{border-color:var(--line);background-color:var(--bg)}
527
554
  .src-f .btn{height:26px;padding:0 9px;font-size:12px}.src-f .btn:disabled{display:none}
528
555
  .src-f .plogo{width:16px;height:16px}
529
- .src-wb{grid-column:1/-1;display:flex;align-items:center;gap:6px;font-size:11px;color:var(--dim);cursor:pointer}.src-wb input{accent-color:var(--accent);margin:0}
556
+ .src-sws{display:flex;flex-wrap:wrap;gap:6px 20px;margin-top:10px}.src-sws:empty{display:none}
557
+ .src-sw{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--dim);cursor:pointer}
558
+ .chk.sm{width:34px;height:20px}.chk.sm::after{top:2px;left:2px;width:16px;height:16px}.chk.sm.on::after{transform:translateX(14px)}
530
559
  @media(max-width:640px){.src-fields{grid-template-columns:1fr}}
531
560
  .src-chips{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}
532
561
  .schip{display:inline-flex;align-items:center;gap:5px;height:24px;padding:0 9px;border-radius:var(--r-pill);border:1px solid var(--line);font-size:12px;color:var(--dim);text-decoration:none;cursor:pointer;white-space:nowrap}