kaizen-agent 1.79.0 → 1.80.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.
Files changed (50) hide show
  1. package/cli/hermes.ts +20 -0
  2. package/cli/install.ts +20 -1
  3. package/cli/localsend.ts +61 -4
  4. package/cli/report.ts +7 -4
  5. package/cli/settings.ts +2 -8
  6. package/cli/state.ts +19 -3
  7. package/cli/task-results.ts +133 -0
  8. package/cli/task-service.ts +180 -0
  9. package/cli/tasks.ts +201 -0
  10. package/cli/ui-audit.allow.json +6 -0
  11. package/cli/ui-audit.ts +427 -0
  12. package/cli/web.ts +72 -1
  13. package/cli/whatsapp.ts +112 -0
  14. package/package.json +2 -1
  15. package/skills/kaizen/SKILL.md +4 -0
  16. package/skills/kaizen/adapters.md +4 -0
  17. package/skills/kaizen/spec-build.md +5 -1
  18. package/skills/kaizen/spec-main.md +4 -0
  19. package/skills/kaizen/spec-plan.md +4 -0
  20. package/skills/kaizen/spec-review.md +4 -0
  21. package/skills/kaizen/spec.md +52 -0
  22. package/web/board/add-project.ts +1 -1
  23. package/web/board/badge.ts +70 -8
  24. package/web/board/cards.ts +4 -2
  25. package/web/board/dom.ts +10 -0
  26. package/web/board/icebox.ts +2 -2
  27. package/web/board/keys.ts +1 -1
  28. package/web/board/live.ts +9 -5
  29. package/web/board/phone.ts +4 -3
  30. package/web/board/rich.ts +4 -2
  31. package/web/board/run-view.ts +16 -14
  32. package/web/board/settings-automations.ts +2 -2
  33. package/web/board/settings-skills.ts +2 -2
  34. package/web/board/settings.ts +12 -14
  35. package/web/board/task-page.ts +672 -0
  36. package/web/board/task-results.ts +235 -0
  37. package/web/board/tasks.ts +214 -200
  38. package/web/board/terms.ts +17 -2
  39. package/web/board/views.ts +35 -9
  40. package/web/board/whatsapp-setup.ts +137 -0
  41. package/web/board/workspace.ts +24 -2
  42. package/web/board.html +62 -35
  43. package/web/board.js +403 -142
  44. package/web/notebook.js +388 -153
  45. package/web/notes.html +21 -11
  46. package/web/term.js +1 -1
  47. package/web/video.html +27 -11
  48. package/web/video.js +415 -180
  49. package/web/video.ts +5 -5
  50. package/web/board/new-agent.ts +0 -20
@@ -1,226 +1,240 @@
1
- // The Ideas page (?view=tasks): every idea and run across projects as one table, with
2
- // source, project, Open/Running/Done and text filters. A card's source is the icebox
3
- // signal it came from (its `idea` text or `run` id); one typed by hand is "Manual".
4
- // The data is the rail's (workspace.ts): no fetch of its own.
1
+ // An attention-first list of durable tasks. Legacy entries are adapted by the server
2
+ // and acquire their stable identity on open, so identical titles stay separate.
5
3
  import { store } from "./store.ts";
6
- import { $, html, ico, pageOf, pager, pagerHtml, raw, wirePager } from "./dom.ts";
7
- import { age, NAMES } from "./labels.ts";
8
- import { key, runPopup } from "./cards.ts";
9
- import { load, post } from "./api.ts";
10
- import { toast } from "./toast.ts";
11
- import { openWorkspace } from "./run-view.ts";
12
- import { open } from "./panel.ts";
13
- import { refreshBoardBadge } from "./badge.ts";
14
- import { cardHref, drawSources, logo, railData, srcIcon, stateOf, titleOf } from "./workspace.ts";
4
+ import { $, html, ico, pageOf, pager, pagerHtml, wirePager } from "./dom.ts";
5
+ import { age } from "./labels.ts";
6
+ import { setTaskAttention } from "./badge.ts";
7
+ import { openTaskRecord, taskStatus, type TaskView } from "./task-page.ts";
15
8
 
16
- const WORDS = { idle: "Task", plan: "Planning", build: "Building", review: "Reviewing", wait: "Waiting on you", done: "Done", aband: "Abandoned", stalled: "Stalled" };
17
- const PLAT = { x: "X", tiktok: "TikTok", instagram: "Instagram", threads: "Threads" };
18
- const SEARCH = raw('<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>');
19
- const AGENTS = ["claude", "codex", "agy", "opencode", "gemini", "cursor"];
20
- // sort: on Open, tasks first or running first (kept per browser).
21
- const f = { src: "all", proj: "", show: "open", q: "", sort: (() => { try { return localStorage.getItem("kz-ideas-sort") || "runs"; } catch { return "runs"; } })() };
22
- let go: (v: string, push?: boolean) => void = () => {};
23
-
24
- const nameOf = (dir, projects) => {
25
- const l = projects?.find((p) => p.dir === dir)?.label || dir.replace(/[\\/]\.kaizen$/, "");
26
- return l.split(/[\\/]/).pop() || l;
27
- };
28
- const srcLabel = (s) => s.label || PLAT[s.social] || (() => { try { return new URL(s.url).hostname.replace(/^www\./, ""); } catch { return s.url; } })();
29
-
30
- // Each card's source url, or "" for a hand-typed one.
31
- function sourcesOf(cards, d) {
32
- const sigs = [...(d?.icebox ?? []), ...(d?.dismissed ?? [])];
33
- const of = new Map<any, string>();
34
- for (const c of cards) {
35
- const s = sigs.find((s) => s.dir === c.state && ((c.kind === "run" && s.run === c.id) || (s.idea && (s.idea === c.text || s.idea === c.title))));
36
- // A hand-added icebox item ("manual") is no outside source either.
37
- of.set(c, /^https?:\/\//.test(s?.source ?? "") ? s.source : "");
38
- }
39
- return of;
9
+ export const TASK_FILTERS = [
10
+ ["all", "All"],
11
+ ["needs-you", "Needs you"],
12
+ ["in-progress", "In progress"],
13
+ ["completed", "Completed"],
14
+ ] as const;
15
+ export function filteredTasks(tasks: TaskView[], filter = "all", query = "", dir = "") {
16
+ const q = query.trim().toLocaleLowerCase();
17
+ const rank = { "needs-you": 0, "in-progress": 1, completed: 2 };
18
+ return tasks
19
+ .filter(
20
+ (t) =>
21
+ (!dir || t.dir === dir) &&
22
+ (filter === "all" || t.attention.category === filter) &&
23
+ (!q ||
24
+ [t.title, t.goal, t.projectName, t.attention.reason, t.attention.action]
25
+ .filter(Boolean)
26
+ .join(" ")
27
+ .toLocaleLowerCase()
28
+ .includes(q)),
29
+ )
30
+ .sort(
31
+ (a, b) =>
32
+ rank[a.attention.category] - rank[b.attention.category] ||
33
+ Number(new Date(b.updatedAt ?? 0)) - Number(new Date(a.updatedAt ?? 0)) ||
34
+ a.id.localeCompare(b.id),
35
+ );
40
36
  }
41
-
42
- // Keyboard: the row picked with the arrow keys (from the search box or the page), Enter acts on it.
43
- let sel = 0;
44
- const pg = pager("ideas");
45
- let shownRows: any[] = [];
46
- // Orca's Tasks shape: a toolbar over a list. The search box, the page's filters and New task
47
- // live in the shared header elsewhere, so they move in here and go back on leaving.
37
+ let items: TaskView[] = [],
38
+ filter = "all",
39
+ sel = 0,
40
+ shown: TaskView[] = [],
41
+ loading = false,
42
+ again = false;
43
+ let sequence = 0,
44
+ loaded = false,
45
+ error = "",
46
+ active = false;
47
+ const pg = pager("tasks");
48
48
  let docked: [Comment, HTMLElement][] = [];
49
49
  function dock() {
50
- if (!$("tk-bar")) $("tasksv").innerHTML = String(html`<div class="tk-bar" id="tk-bar"><div class="tk-row" id="tk-chips"></div><div class="tk-row"><label class="tk-q" id="tk-q">${SEARCH}</label><span id="tk-tools"></span></div></div><div class="tk-list" id="tk-list"></div>`);
50
+ if (!$("tk-bar"))
51
+ $("tasksv").innerHTML = String(
52
+ html`<div class="tk-bar" id="tk-bar">
53
+ <div class="tk-row" id="tk-chips" role="group" aria-label="Task filters"></div>
54
+ <div class="tk-row"><label class="tk-q" id="tk-q">${ico("search")}</label><span id="tk-tools"></span></div>
55
+ </div>
56
+ <div class="tk-list" id="tk-list"></div>`,
57
+ );
51
58
  if (docked.length) return;
52
- for (const [id, to] of [["bq", "tk-q"], ["hx", "tk-tools"], ["newtop", "tk-tools"]]) {
53
- const el = $(id),
54
- mark = new Comment();
59
+ for (const [id, to] of [
60
+ ["bq", "tk-q"],
61
+ ["hx", "tk-tools"],
62
+ ["newtop", "tk-tools"],
63
+ ]) {
64
+ const el = $(id);
65
+ if (!el) continue;
66
+ const mark = new Comment();
55
67
  el.before(mark);
56
68
  docked.push([mark, el]);
57
69
  $(to).append(el);
58
70
  }
71
+ $("hx").innerHTML = String(
72
+ html`<button class="ib" id="tasks-refresh" title="Refresh tasks" aria-label="Refresh tasks">
73
+ ${ico("refresh")}
74
+ </button>`,
75
+ );
76
+ $("tasks-refresh").onclick = () => void refreshTasks();
59
77
  }
60
78
  function undock() {
61
79
  docked.forEach(([mark, el]) => mark.replaceWith(el));
62
80
  docked = [];
63
81
  }
82
+ export async function refreshTasks() {
83
+ if (!active) return;
84
+ if (loading) {
85
+ again = true;
86
+ return;
87
+ }
88
+ loading = true;
89
+ do {
90
+ again = false;
91
+ const gen = ++sequence;
92
+ try {
93
+ const r = await fetch("/tasks?all=1"),
94
+ body = await r.json();
95
+ if (gen !== sequence || !active) continue;
96
+ if (!r.ok) throw new Error(body.why || body.error || "Tasks could not be loaded");
97
+ items = body.tasks ?? [];
98
+ loaded = true;
99
+ error = "";
100
+ setTaskAttention(items);
101
+ dispatchEvent(new CustomEvent("kz-task-list", { detail: items }));
102
+ draw();
103
+ } catch (e) {
104
+ if (active) {
105
+ error = e instanceof Error ? e.message : "Tasks could not be loaded";
106
+ draw();
107
+ }
108
+ }
109
+ } while (again);
110
+ loading = false;
111
+ }
64
112
  function draw() {
65
- const box = $("tasksv");
66
113
  if (!document.body.classList.contains("taskv")) return;
67
114
  dock();
68
- const { cards: all, projects, srcs } = railData();
69
- const cards = all.filter((c) => !c.archived);
70
- const src = sourcesOf(cards, srcs);
71
- const known = new Map<string, any>((srcs?.sources ?? []).map((s) => [s.url, s]));
72
- const present = [...new Set(cards.map((c) => src.get(c)!))];
73
- if (f.src !== "all" && !present.includes(f.src)) f.src = "all";
74
- const dirs = [...new Set(cards.map((c) => c.state))];
75
- // "Showing": the same projects-shown set as the Board and the Icebox (store.shown).
76
- const shownDirs = dirs.filter((d) => store.shown.has(d));
77
- // The Board's header is the Tasks header too (as on the Icebox): its project picker, its
78
- // Showing list and its search box drive this table.
79
- const proj = store.all ? "" : store.S?.dir ?? "";
80
- const q = (($("bq") as HTMLInputElement | null)?.value ?? "").trim().toLowerCase();
81
- const fin = (c) => c.status === "done" || c.status === "abandoned";
82
- const matched = cards
83
- .filter((c) => f.src === "all" || src.get(c) === f.src)
84
- .filter((c) => (proj ? c.state === proj : !shownDirs.length || shownDirs.includes(c.state)))
85
- // Open: tasks not started yet and runs in flight. Running: runs in flight only. Done: finished runs.
86
- .filter((c) => (f.show === "done" ? fin(c) : f.show === "running" ? c.kind === "run" && !fin(c) : !fin(c)))
87
- .filter((c) => !q || (titleOf(c) + " " + nameOf(c.state, projects)).toLowerCase().includes(q))
88
- // On Open, tasks above runs or runs above tasks, as chosen; newest first within each.
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));
115
+ if ($("tk-list").contains(document.activeElement) && document.activeElement !== document.body) return;
116
+ const q = $("bq").value || "",
117
+ dir = !store.all ? (store.S.dir ?? "") : "";
118
+ const scoped = items.filter((t) => !dir || t.dir === dir);
119
+ const matched = filteredTasks(scoped, filter, q);
90
120
  const rows = pageOf(pg, matched);
91
- const now = Date.now();
92
- const seg = (v, l) => html`<button class="tk-chip${f.show === v ? " on" : ""}" data-show="${v}">${l}</button>`;
93
- const srcName = (u) => (u === "all" ? "All sources" : u === "" ? "Manual" : known.get(u) ? srcLabel(known.get(u)) : srcLabel({ url: u }));
94
- const srcMark = (u) => (u === "all" ? raw('<svg><use href="#r-bulb"/></svg>') : u === "" ? ico("pen") : srcIcon(known.get(u) ?? { url: u }));
95
- const srcList = ["all", ...present.filter(Boolean), ...(present.includes("") ? [""] : [])];
96
- // A pop-up picker: a button that opens a short list.
97
- const pop = (id, label, rows) => html`<details class="combo ipop" id="${id}"><summary class="sel">${label}</summary><div class="menu-pop pick-list">${rows}</div></details>`;
98
- const ck = raw('<svg class="ck"><use href="#i-check"/></svg>');
99
- const sources = pop(
100
- "ideas-src",
101
- html`${srcMark(f.src)}<span>${srcName(f.src)}</span>`,
102
- html`${srcList.map((u) => html`<button type="button" role="menuitemradio" data-src="${u}" aria-checked="${String(f.src === u)}">${srcMark(u)}<span>${srcName(u)}</span>${ck}</button>`)}`,
103
- );
104
- // Tasks' own filters, placed in the shared header after its search box.
105
- const sortPop =
106
- f.show === "open"
107
- ? pop(
108
- "ideas-sort",
109
- html`<span>${f.sort === "ideas" ? "Tasks first" : "Running first"}</span>`,
110
- html`${[["ideas", "Tasks first"], ["runs", "Running first"]].map(([v, l]) => html`<button type="button" role="menuitemradio" data-sort="${v}" aria-checked="${String(f.sort === v)}"><span>${l}</span>${ck}</button>`)}`,
111
- )
112
- : "";
113
- // Scope and filters first; search, refresh and New task sit at the right (CSS order).
114
- const chips = html`${seg("open", "Open")}${seg("running", "Running")}${seg("done", "Done")}`;
115
- const extra = html`${sources}${sortPop}<button class="ib" id="ideas-ref" title="Refresh" aria-label="Refresh">${ico("refresh")}</button>`;
116
- const table = !rows.length ? html`<div class="tk-empty">${raw('<svg><use href="#r-bulb"/></svg>')}<p>Nothing matches.</p><span>Try a different search or filter.</span></div>` : html`<table class="itable"><thead><tr><th></th><th>Title / context</th><th>Status</th><th>Updated</th><th></th></tr></thead><tbody>${rows.map((c, i) => {
117
- const name = nameOf(c.state, projects),
118
- st = stateOf(c),
119
- agent = (c.tags ?? []).find((t) => AGENTS.includes(t));
120
- return html`<tr><td>${logo(c.state, name, projects)}</td><td><b>${titleOf(c)}</b><div class="ctx">${name}${agent ? html`<span class="tag">${NAMES[agent]}</span>` : ""}</div></td><td><span class="stc"><span class="si ${st}"></span>${WORDS[st]}</span></td><td class="d">${c.moved || c.added ? age(c.moved || c.added, now) + " ago" : ""}</td><td><div class="acts">${asking === key(c) ? html`<span class="q">Delete?</span><button class="btn ghost" data-keep="1">Keep</button><button class="btn danger" data-yes="${i}">Delete</button>` : html`${c.kind === "idea" ? html`<button class="del" data-i="${i}" title="Delete task" aria-label="Delete task">${ico("trash")}</button>` : ""}<button class="go" data-i="${i}">${c.kind === "idea" ? "Start" : "Open"} ${ico("arrow")}</button>`}</div></td></tr>`;
121
- })}</tbody></table>`;
122
- const hx = $("hx");
123
- // Not while a pop-up in it is open: redrawing would close it under the pointer.
124
- if (!hx.querySelector("details[open]")) hx.innerHTML = String(extra);
125
- $("tk-chips").innerHTML = String(chips);
126
- $("tk-list").innerHTML = String(html`${table}${pagerHtml(pg)}`);
127
- wirePager(pg, () => ((sel = 0), draw()));
128
-
129
- hx.querySelectorAll<HTMLElement>("[data-src]").forEach((b) => (b.onclick = () => ((f.src = b.dataset.src!), (hx.innerHTML = ""), draw())));
130
- hx.querySelectorAll<HTMLElement>("[data-sort]").forEach(
131
- (b) =>
132
- (b.onclick = () => {
133
- f.sort = b.dataset.sort!;
134
- try {
135
- localStorage.setItem("kz-ideas-sort", f.sort);
136
- } catch {}
137
- hx.innerHTML = "";
138
- draw();
139
- }),
121
+ $("tk-chips").innerHTML = String(
122
+ html`${TASK_FILTERS.map(([id, label]) => html`<button type="button" class="tk-chip${filter === id ? " on" : ""}" data-task-filter="${id}" aria-pressed="${String(filter === id)}">${label}<span class="tp-filter-count">${id === "all" ? scoped.length : scoped.filter((t) => t.attention.category === id).length}</span></button>`)}`,
140
123
  );
141
- box.querySelectorAll<HTMLElement>("[data-show]").forEach((b) => (b.onclick = () => ((f.show = b.dataset.show!), (hx.innerHTML = ""), draw())));
142
- $("ideas-ref").onclick = () => (void drawSources(true), void refreshBoardBadge());
143
- box.querySelectorAll<HTMLElement>("button.go").forEach((b) => (b.onclick = () => act(rows[+b.dataset.i!])));
144
- // The trash icon asks in its own row, as the board's card menu does; a redraw keeps the question.
145
- box.querySelectorAll<HTMLElement>("button.del").forEach((b) => (b.onclick = () => ((asking = key(rows[+b.dataset.i!])), draw())));
146
- box.querySelectorAll<HTMLElement>("[data-keep]").forEach((b) => (b.onclick = () => ((asking = null), draw())));
147
- box.querySelectorAll<HTMLElement>("[data-yes]").forEach((b) => (b.onclick = () => del(rows[+b.dataset.yes!])));
148
- // A click moves the highlight to its row too: it marks the keyboard's row, not the panel's.
149
- box.querySelectorAll<HTMLElement>("tbody tr").forEach((tr, i) => (tr.onclick = (e) => !(e.target as Element).closest("button") && ((sel = i), mark(), detail(rows[i]))));
150
- shownRows = rows;
151
- sel = Math.max(0, Math.min(sel, rows.length - 1));
152
- mark();
124
+ const empty = error
125
+ ? html`<p>${error}</p>
126
+ <button class="btn" type="button" id="tasks-retry">Try again</button>`
127
+ : !loaded
128
+ ? html`<p role="status">Loading tasks…</p>`
129
+ : scoped.length
130
+ ? html`<p>No tasks match</p>
131
+ <span>Try another search or show all tasks.</span
132
+ ><button class="btn" type="button" id="tasks-reset">Clear search and filters</button>`
133
+ : html`<p>What would you like to make?</p>
134
+ <span>Describe a goal. Keep the decisions, results and later changes together.</span
135
+ ><button class="btn pri" type="button" id="tasks-first">New task</button>`;
136
+ const list = rows.length
137
+ ? html`<div class="tp-task-list" aria-label="Tasks">
138
+ ${rows.map(
139
+ (t, i) =>
140
+ html`<button type="button" class="tp-task-row${sel === i ? " kb" : ""}" data-task-row="${String(i)}">
141
+ <span class="tp-task-main"
142
+ ><strong>${t.title}</strong
143
+ ><small
144
+ >${
145
+ t.projectName ||
146
+ (t.dir
147
+ ? t.dir
148
+ .replace(/[\\/]\.kaizen$/, "")
149
+ .split(/[\\/]/)
150
+ .pop()
151
+ : "Project needed")
152
+ }${t.currentResultId ? " · Result available" : ""}</small
153
+ ></span
154
+ ><span class="tp-task-attention ${t.attention.category}"
155
+ ><span>${taskStatus(t)}</span><small>${t.attention.action}</small></span
156
+ ><span class="tp-task-age"
157
+ >${t.updatedAt ? age(Number(new Date(t.updatedAt)), Date.now()) + " ago" : ""}</span
158
+ >${ico("arrow")}
159
+ </button>`,
160
+ )}
161
+ </div>`
162
+ : html`<div class="tk-empty">${ico("plus")}${empty}</div>`;
163
+ // List changes never replace a focused row during a background state tick.
164
+ if (!$("tk-list").contains(document.activeElement) || document.activeElement === document.body)
165
+ $("tk-list").innerHTML = String(html`${list}${pagerHtml(pg)}`);
166
+ wirePager(pg, () => {
167
+ sel = 0;
168
+ draw();
169
+ });
170
+ $("tasksv")
171
+ .querySelectorAll<HTMLElement>("[data-task-filter]")
172
+ .forEach(
173
+ (b) =>
174
+ (b.onclick = () => {
175
+ filter = b.dataset.taskFilter!;
176
+ sel = 0;
177
+ pg.at = 0;
178
+ draw();
179
+ }),
180
+ );
181
+ $("tasksv")
182
+ .querySelectorAll<HTMLElement>("[data-task-row]")
183
+ .forEach((b) => (b.onclick = () => void openTaskRecord(rows[Number(b.dataset.taskRow)])));
184
+ $("tasks-first") &&
185
+ ($("tasks-first").onclick = () => dispatchEvent(new CustomEvent("kz-new-task", { cancelable: true })));
186
+ $("tasks-reset") &&
187
+ ($("tasks-reset").onclick = () => {
188
+ filter = "all";
189
+ $("bq").value = "";
190
+ sel = 0;
191
+ draw();
192
+ $("bq").focus();
193
+ });
194
+ $("tasks-retry") && ($("tasks-retry").onclick = () => void refreshTasks());
195
+ shown = rows;
196
+ sel = Math.max(0, Math.min(sel, shown.length - 1));
153
197
  }
154
-
155
- // Start: the run form in a popup (agent pick, then go), then the run workspace. Open: the card.
156
- // Cards of a project this board is not showing go through the board's deep link.
157
- function act(c) {
158
- const here = store.S.cards.find((x) => key(x) === key(c));
159
- if (!here) {
160
- location.href = c.kind === "run" ? cardHref(c) + "&all=1" : `/?all=1&dir=${encodeURIComponent(c.state)}&idea=${encodeURIComponent(c.text)}`;
161
- return;
162
- }
163
- if (c.kind === "run") return openWorkspace(here);
164
- runPopup(here);
165
- }
166
-
167
- // A task is deleted as the board's card menu does it, not recorded anywhere.
168
- let asking: string | null = null;
169
- async function del(c) {
170
- asking = null;
171
- const r = await post("/inbox", { op: "delete", dir: c.state, text: c.text });
172
- if (r.ok) toast("Deleted");
173
- load();
174
- }
175
-
176
- // A row's own click: the card's detail panel over this page. Another project's card goes
177
- // through the board's deep link, which opens the same panel there.
178
- function detail(c) {
179
- const here = store.S.cards.find((x) => key(x) === key(c));
180
- if (here) return open(here);
181
- const e = encodeURIComponent;
182
- location.href = `/?all=1&dir=${e(c.state)}&${c.kind === "run" ? "run=" + e(c.id) : "idea=" + e(c.text)}`;
183
- }
184
-
185
- function mark() {
186
- const trs = [...document.querySelectorAll<HTMLElement>("#tasksv tbody tr")];
187
- trs.forEach((tr, i) => tr.classList.toggle("kb", i === sel));
188
- trs[sel]?.scrollIntoView({ block: "nearest" });
189
- }
190
- addEventListener("keydown", (e) => {
191
- if (!document.body.classList.contains("taskv") || !shownRows.length) return;
192
- const t = e.target as HTMLElement;
193
- // From the search box, or anywhere on the page that is not another field or a menu.
194
- if (t.id !== "bq" && (t.closest("input,textarea,select,[contenteditable],details,dialog") || t.isContentEditable)) return;
195
- if (e.key === "ArrowDown" || e.key === "ArrowUp") {
196
- e.preventDefault();
197
- sel = Math.max(0, Math.min(shownRows.length - 1, sel + (e.key === "ArrowDown" ? 1 : -1)));
198
- mark();
199
- } else if (e.key === "Enter" && !e.isComposing) {
200
- e.preventDefault();
201
- act(shownRows[sel]);
202
- }
203
- });
204
198
  export function openTasks() {
199
+ active = true;
205
200
  $("bq").placeholder = "Search tasks (press /)";
206
- addEventListener("kz-view", () => (undock(), ($("bq").placeholder = "Filter cards (press /)")), { once: true });
207
- void drawSources(true);
201
+ addEventListener(
202
+ "kz-view",
203
+ () => {
204
+ active = false;
205
+ sequence++;
206
+ undock();
207
+ $("bq").placeholder = "Filter cards (press /)";
208
+ },
209
+ { once: true },
210
+ );
208
211
  draw();
212
+ void refreshTasks();
209
213
  }
210
- export function initTasks(goTo: typeof go) {
211
- go = goTo;
212
- addEventListener("kz-rail", draw);
213
- // The shared header's search box, project picker and Showing list.
214
- addEventListener("kz-state", draw);
215
- $("bq")?.addEventListener("input", () => ((sel = 0), draw()));
216
- $("shows")?.addEventListener("click", () => queueMicrotask(draw));
214
+ export function initTasks(_goTo) {
215
+ addEventListener("kz-state", () => {
216
+ if (active) void refreshTasks();
217
+ });
218
+ $("tasksv")?.addEventListener("focusout", () => setTimeout(draw, 0));
219
+ $("bq")?.addEventListener("input", () => {
220
+ sel = 0;
221
+ pg.at = 0;
222
+ draw();
223
+ });
224
+ addEventListener("keydown", (e) => {
225
+ if (!active || !shown.length || e.defaultPrevented) return;
226
+ const t = e.target as HTMLElement;
227
+ if (t.id !== "bq" && t.closest("input,textarea,select,[contenteditable],details,dialog")) return;
228
+ if (["ArrowDown", "ArrowUp"].includes(e.key)) {
229
+ e.preventDefault();
230
+ sel = Math.max(0, Math.min(shown.length - 1, sel + (e.key === "ArrowDown" ? 1 : -1)));
231
+ $("tasksv")
232
+ .querySelectorAll<HTMLElement>("[data-task-row]")
233
+ .forEach((b, i) => b.classList.toggle("kb", i === sel));
234
+ $("tasksv").querySelector(`[data-task-row="${sel}"]`)?.scrollIntoView({ block: "nearest" });
235
+ } else if (e.key === "Enter" && t.id === "bq" && !e.isComposing) {
236
+ e.preventDefault();
237
+ void openTaskRecord(shown[sel]);
238
+ }
239
+ });
217
240
  }
218
-
219
- // A click outside the Tasks header's pop-ups closes them.
220
- addEventListener(
221
- "pointerdown",
222
- (e) => {
223
- if (!(e.target as Element).closest?.("details.ipop")) document.querySelectorAll<HTMLDetailsElement>("details.ipop[open]").forEach((d) => (d.open = false));
224
- },
225
- true,
226
- );
@@ -147,11 +147,26 @@ export function openTerms() {
147
147
  const hid = [...all.keys()].filter((k) => lay.hidden.includes(k) && all.get(k).pty.alive);
148
148
  // The layout switch sits at the right of the page header.
149
149
  $("tmodes").innerHTML = html`${MODES.map(([v, l, i]) => html`<button data-mode="${v}" class="${lay.mode === v ? "on" : ""}" aria-pressed="${String(lay.mode === v)}" title="${l}" aria-label="${l}">${ico(i)}</button>`)}`.s;
150
- bar!.innerHTML = html`${hid.length ? html`<span class="dim">Hidden</span>${hid.map((k) => html`<button class="chip" data-show="${k}" title="Show this terminal">${ico("plus")}${nameOf(all.get(k))} - ${projOf(all.get(k))}</button>`)}` : ""}${phone.matches && keys.length > 1 ? html`<span class="ttabs" role="group" aria-label="Terminals">${keys.map((k) => html`<button class="${k === one ? "on" : ""}" data-pick="${k}" aria-pressed="${String(k === one)}"><span class="tdot ${tst(all.get(k))}"></span>${nameOf(all.get(k))} - ${projOf(all.get(k))}</button>`)}</span>` : ""}`.s;
150
+ bar!.innerHTML = html`${hid.length ? html`<span class="dim">Hidden</span>${hid.map((k) => html`<button class="chip" data-show="${k}" title="Show this terminal">${ico("plus")}${nameOf(all.get(k))} - ${projOf(all.get(k))}</button>`)}` : ""}${phone.matches && keys.length ? html`<span class="ttabs" role="group" aria-label="Terminals">${keys.map((k) => html`<button class="${k === one ? "on" : ""}" data-pick="${k}" aria-pressed="${String(k === one)}"><span class="tdot ${tst(all.get(k))}"></span><span>${nameOf(all.get(k))} - ${projOf(all.get(k))}</span><i class="tx" data-close="${k}" title="Close terminal">×</i></button>`)}</span>` : ""}`.s;
151
151
  termsBadge();
152
152
  bar!.querySelectorAll<HTMLElement>("[data-pick]").forEach(
153
153
  (b) =>
154
- (b.onclick = () => {
154
+ (b.onclick = (e) => {
155
+ const close = (e.target as HTMLElement).closest<HTMLElement>("[data-close]");
156
+ if (close) {
157
+ e.stopPropagation();
158
+ const ck = close.dataset.close!;
159
+ const c = all.get(ck);
160
+ const off = tst(c) === "ended";
161
+ if (off) {
162
+ lay.hidden.push(ck);
163
+ save();
164
+ openTerms();
165
+ } else if (confirm("End this agent session? A run can be resumed from its tile or card.")) {
166
+ post("/pty/exit", { key: ck }).then(() => load(true));
167
+ }
168
+ return;
169
+ }
155
170
  pick = b.dataset.pick!;
156
171
  openTerms();
157
172
  }),
@@ -6,6 +6,7 @@ import { openSettings } from "./settings.ts";
6
6
  import { openTerms, termsStop } from "./terms.ts";
7
7
  import { openHome } from "./home.ts";
8
8
  import { initTasks, openTasks } from "./tasks.ts";
9
+ import { initTaskPage, openTaskPage } from "./task-page.ts";
9
10
  import { initRunView, openWorkspace, runStop, showRunView } from "./run-view.ts";
10
11
  import { initPhone, isPhone, openPhone } from "./phone.ts";
11
12
 
@@ -13,18 +14,41 @@ import { initPhone, isPhone, openPhone } from "./phone.ts";
13
14
  export let view = "board";
14
15
  let boardBack = false;
15
16
  // The board's own area, not the docked panel.
16
- const AREA = ["board", "terminal", "home", "tasks", "run", "chat", "device"];
17
+ const AREA = ["board", "terminal", "home", "tasks", "task", "run", "chat", "device"];
17
18
  export const markView = (v) => {
18
19
  // A phone's run workspace belongs to its Runs tab.
19
- const lit = v === "run" && isPhone() ? "device" : v;
20
+ const lit = v === "task" ? (isPhone() ? "device" : "tasks") : v === "run" && isPhone() ? "device" : v;
20
21
  document
21
22
  .querySelectorAll(".rail a[data-view]")
22
23
  .forEach((a) =>
23
24
  a.dataset.view === lit ? a.setAttribute("aria-current", "page") : a.removeAttribute("aria-current"),
24
25
  );
25
26
  // The Icebox is titled in the header, top left, like the board.
26
- document.querySelector(".hdr h1").textContent = v === "sources" ? "Icebox" : v === "tasks" ? "Tasks" : v === "run" ? "Run" : v === "terminal" ? "Terminal" : v === "home" ? (isPhone() ? "kaizen" : "Home") : v === "chat" ? "Chat" : v === "device" ? "Runs" : "Board";
27
- if (v === "home" && isPhone()) document.querySelector(".hdr h1").innerHTML = '<pre class="mark" role="img" aria-label="kaizen">' + document.querySelector(".rail pre.mark").innerHTML + "</pre>";
27
+ document.querySelector(".hdr h1").textContent =
28
+ v === "sources"
29
+ ? "Icebox"
30
+ : v === "tasks"
31
+ ? "Tasks"
32
+ : v === "task"
33
+ ? "Task"
34
+ : v === "run"
35
+ ? "Run"
36
+ : v === "terminal"
37
+ ? "Terminal"
38
+ : v === "home"
39
+ ? isPhone()
40
+ ? "kaizen"
41
+ : "Home"
42
+ : v === "chat"
43
+ ? "Chat"
44
+ : v === "device"
45
+ ? "Runs"
46
+ : "Board";
47
+ if (v === "home" && isPhone())
48
+ document.querySelector(".hdr h1").innerHTML =
49
+ '<pre class="mark" role="img" aria-label="kaizen">' +
50
+ document.querySelector(".rail pre.mark").innerHTML +
51
+ "</pre>";
28
52
  };
29
53
  export function go(v, push) {
30
54
  store.pageGen++;
@@ -33,10 +57,9 @@ export function go(v, push) {
33
57
  if (v === "icebox") v = "sources";
34
58
  // A workspace address shows in the run view, which resolves it to a card.
35
59
  if (v === "ws") v = "run";
36
- if (!["settings", "sources", "terminal", "board", "tasks", "run", "chat", "device"].includes(v)) v = "home";
37
- // A phone has Home, Chat, Runs, the Icebox and Settings: the board and Tasks are set up on a
38
- // computer, whose Home is the chat.
39
- if (isPhone() ? ["board", "tasks"].includes(v) : v === "chat" || v === "device") v = "home";
60
+ if (!["settings", "sources", "terminal", "board", "tasks", "task", "run", "chat", "device"].includes(v)) v = "home";
61
+ // Phone keeps Runs and Tasks reachable; the desktop board and chat remain desktop views.
62
+ if (isPhone() ? ["board", "sources"].includes(v) : v === "chat" || v === "device") v = "home";
40
63
  const was = view;
41
64
  view = v;
42
65
  markView(v);
@@ -49,6 +72,7 @@ export function go(v, push) {
49
72
  document.body.classList.toggle("phomev", ph || v === "device");
50
73
  document.body.classList.toggle("pdevv", v === "device");
51
74
  document.body.classList.toggle("taskv", v === "tasks");
75
+ document.body.classList.toggle("taskpagev", v === "task");
52
76
  document.body.classList.toggle("runv", v === "run");
53
77
  // Leaving a workspace: its panel closes as the board's would, its terminals unmount.
54
78
  if (was === "run" && v !== "run") {
@@ -58,7 +82,7 @@ export function go(v, push) {
58
82
  view = v;
59
83
  }
60
84
  // The workspace's address names its card: openWorkspace() pushes it.
61
- if (push && v !== was && v !== "run")
85
+ if (push && v !== was && v !== "run" && v !== "task")
62
86
  history.pushState(null, "", v === "home" ? location.pathname : "?view=" + (v === "sources" ? "icebox" : v));
63
87
  dispatchEvent(new Event("kz-view"));
64
88
  const p = $("panel");
@@ -67,6 +91,7 @@ export function go(v, push) {
67
91
  if ((v === "home" && !ph) || v === "chat") openHome();
68
92
  openPhone(ph ? "home" : v === "device" ? "device" : null);
69
93
  if (v === "tasks") openTasks();
94
+ if (v === "task") openTaskPage();
70
95
  // After the panel handling below, which closes the board's panel on the way in.
71
96
  if (v === "run") queueMicrotask(() => void showRunView(true));
72
97
  // The Terminal page is the board's own area, not the docked panel: the panel closes as on the board.
@@ -101,6 +126,7 @@ export function initViews() {
101
126
  $("phone-menu").setAttribute("aria-label", on ? "Hide navigation menu" : "Show navigation menu");
102
127
  };
103
128
  initTasks(go);
129
+ initTaskPage(go);
104
130
  initRunView();
105
131
  initPhone(go, openWorkspace);
106
132
  document.querySelectorAll(".rail a[data-view]").forEach((a) => {