kaizen-agent 1.63.0 → 1.64.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +10 -10
  2. package/agents/kaizen-planner.md +2 -2
  3. package/cli/backlog.test.ts +1 -1
  4. package/cli/board.test.ts +24 -24
  5. package/cli/dashboard.ts +15 -15
  6. package/cli/handoff.test.ts +133 -0
  7. package/cli/handoff.ts +122 -0
  8. package/cli/install.ts +31 -5
  9. package/cli/notes.test.ts +3 -3
  10. package/cli/notes.ts +1 -1
  11. package/cli/pty.ts +16 -2
  12. package/cli/resources.test.ts +50 -0
  13. package/cli/resources.ts +113 -0
  14. package/cli/restart.test.ts +28 -1
  15. package/cli/settings.ts +8 -5
  16. package/cli/sources.test.ts +32 -32
  17. package/cli/sources.ts +15 -15
  18. package/cli/state.test.ts +74 -51
  19. package/cli/state.ts +77 -49
  20. package/cli/usage.test.ts +11 -0
  21. package/cli/web.ts +139 -38
  22. package/cli/workers.ts +11 -4
  23. package/cli/worktree.test.ts +174 -1
  24. package/cli/worktree.ts +190 -35
  25. package/commands/kaizen-discover.md +1 -1
  26. package/package.json +1 -1
  27. package/skills/kaizen/README.md +2 -2
  28. package/skills/kaizen/SKILL.md +2 -2
  29. package/skills/kaizen/config.default.yml +32 -22
  30. package/skills/kaizen/discover.md +8 -8
  31. package/skills/kaizen/gather.md +2 -2
  32. package/skills/kaizen/settings.md +3 -0
  33. package/skills/kaizen/spec-build.md +13 -0
  34. package/skills/kaizen/spec-main.md +13 -0
  35. package/skills/kaizen/spec-plan.md +1 -1
  36. package/skills/kaizen/spec.md +1 -1
  37. package/skills/kaizen-help/SKILL.md +2 -2
  38. package/web/board/api.ts +10 -10
  39. package/web/board/cards.ts +47 -46
  40. package/web/board/git.ts +4 -4
  41. package/web/board/icebox.ts +14 -14
  42. package/web/board/keys.ts +3 -3
  43. package/web/board/labels.ts +2 -2
  44. package/web/board/live.ts +3 -3
  45. package/web/board/main.ts +1 -1
  46. package/web/board/markdown.ts +1 -1
  47. package/web/board/panel.ts +17 -17
  48. package/web/board/phone.ts +10 -12
  49. package/web/board/projects.ts +6 -6
  50. package/web/board/resources.ts +152 -0
  51. package/web/board/run-view.ts +5 -5
  52. package/web/board/search.ts +11 -11
  53. package/web/board/settings-cleanup.ts +42 -0
  54. package/web/board/settings-pages.ts +1 -1
  55. package/web/board/settings.ts +13 -0
  56. package/web/board/store.ts +1 -1
  57. package/web/board/{ideas.ts → tasks.ts} +22 -22
  58. package/web/board/terms.ts +3 -3
  59. package/web/board/views.ts +23 -12
  60. package/web/board/workspace.ts +9 -7
  61. package/web/board/ws-board-ui.ts +1 -1
  62. package/web/board/ws-board.test.ts +1 -1
  63. package/web/board/ws-board.ts +1 -1
  64. package/web/board/ws-tabs.test.ts +10 -2
  65. package/web/board/ws-tabs.ts +10 -9
  66. package/web/board.html +46 -34
  67. package/web/board.js +107 -97
  68. package/web/notebook.js +22 -22
  69. package/web/notebook.ts +5 -5
  70. package/web/notes-lib.ts +2 -2
  71. package/web/notes.html +12 -11
  72. package/web/term-font.test.ts +22 -0
  73. package/web/term-font.ts +30 -0
  74. package/web/term.js +38 -38
  75. package/web/term.ts +13 -2
  76. package/web/video.html +12 -11
  77. package/web/video.js +48 -48
package/web/board/keys.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { store } from "./store.ts";
2
2
  import { load } from "./api.ts";
3
- import { focusedKey, formPopup, key, nav, newIdea, render, runPopup } from "./cards.ts";
3
+ import { focusedKey, formPopup, key, nav, newTask, render, runPopup } from "./cards.ts";
4
4
  import { $ } from "./dom.ts";
5
5
  import { iceNav, srcOpen } from "./icebox.ts";
6
6
  import { close, openRun } from "./panel.ts";
@@ -38,7 +38,7 @@ export function initKeys() {
38
38
  $("sq").focus();
39
39
  return;
40
40
  }
41
- if (e.key === "/" && (view === "board" || view === "ideas") && $("bq")) {
41
+ if (e.key === "/" && (view === "board" || view === "tasks") && $("bq")) {
42
42
  e.preventDefault();
43
43
  $("bq").focus();
44
44
  return;
@@ -54,7 +54,7 @@ export function initKeys() {
54
54
  // The Terminal page has no cards to move between; its keys are the terminals'.
55
55
  if (view === "terminal") return;
56
56
  if (e.key === "n" && !document.querySelector("dialog[open]")) {
57
- newIdea();
57
+ newTask();
58
58
  }
59
59
  if (e.key === "a") {
60
60
  store.all = !store.all;
@@ -16,11 +16,11 @@ export const NAMES = {
16
16
  unrechecked: "fix not rechecked",
17
17
  };
18
18
  export const MARKS = { claude: 1, codex: 1, agy: 1, opencode: 1, gemini: 1, cursor: 1, full: 1, lite: 1 };
19
- // The new-idea picker's starting project: the one asked for if it is offered, else none
19
+ // The new-task picker's starting project: the one asked for if it is offered, else none
20
20
  // when a choice is required, else the first offered.
21
21
  export const startDir = (offered: string[], want: string | null, choose: boolean) =>
22
22
  want && offered.includes(want) ? want : choose ? null : (offered[0] ?? null);
23
- export const COLS = ["Ideas", "Planning", "Building", "Review", "Done"];
23
+ export const COLS = ["Tasks", "Planning", "Building", "Review", "Done"];
24
24
  // state.ts statuses onto the icon set in the <defs> above.
25
25
  export const ICON = {
26
26
  idea: "idea",
package/web/board/live.ts CHANGED
@@ -33,7 +33,7 @@ function listen() {
33
33
  // Back to the project picked last time, unless the URL says which view it wants. A
34
34
  // plain fetch: a project that is gone should fall back to all, not raise a toast.
35
35
  // A page named in the address shows from the first paint; it is filled once the board has loaded.
36
- const v0 = ((v) => (v === "icebox" ? "sources" : v === "ws" ? "run" : v))(new URLSearchParams(location.search).get("view"));
36
+ const v0 = ((v) => (v === "icebox" ? "sources" : v === "ws" ? "run" : v === "ideas" ? "tasks" : v))(new URLSearchParams(location.search).get("view"));
37
37
 
38
38
  export function initLive() {
39
39
  addEventListener("kz-view", () => { if (pendingReload && !document.body.classList.contains("homev")) location.reload(); });
@@ -41,13 +41,13 @@ export function initLive() {
41
41
  addEventListener("focus", () => load(true));
42
42
  addEventListener("visibilitychange", flushLoad);
43
43
  // No view in the address is Home.
44
- const first = ["settings", "sources", "terminal", "board", "ideas", "run"].includes(v0) ? v0 : "home";
44
+ const first = ["settings", "sources", "terminal", "board", "tasks", "run"].includes(v0) ? v0 : "home";
45
45
  markView(first);
46
46
  document.body.classList.toggle("paged", first !== "board");
47
47
  document.body.classList.toggle("ice", v0 === "sources");
48
48
  document.body.classList.toggle("termv", v0 === "terminal");
49
49
  document.body.classList.toggle("homev", first === "home");
50
- document.body.classList.toggle("ideav", first === "ideas");
50
+ document.body.classList.toggle("taskv", first === "tasks");
51
51
  document.body.classList.toggle("runv", first === "run");
52
52
  (async () => {
53
53
  let d;
package/web/board/main.ts CHANGED
@@ -31,7 +31,7 @@ filterBox();
31
31
  statusSheet();
32
32
  initRail();
33
33
  initFooter(() => go("terminal", true));
34
- // The rail's rows and + open a card or the new-idea form here, on the board, when it has them.
34
+ // The rail's rows and + open a card or the new-task form here, on the board, when it has them.
35
35
  // A row of another project than the one picked switches the board to that project first.
36
36
  addEventListener("kz-open-card", (e: any) => {
37
37
  const { dir, id, text } = e.detail;
@@ -57,7 +57,7 @@ export function planQuestions(src) {
57
57
  const qs = out.filter((x) => x.options.length);
58
58
  return qs.length || !said ? qs : null;
59
59
  }
60
- // An idea is one inbox line, so a structured request arrives as one wall:
60
+ // A task is one inbox line, so a structured request arrives as one wall:
61
61
  // "Fix x Problem: … Scope: … Acceptance criteria: (1) … (2) …". Split it, for display
62
62
  // only, into the text before the first label and one part per label; inline (1) (2)
63
63
  // become a numbered list. Fewer than two labels is plain text and is left whole.
@@ -44,8 +44,8 @@ const readable = (t) =>
44
44
  let keepNext = false;
45
45
  export function open(c, keepTab) {
46
46
  // A run is worked on in its workspace, which docks this panel; so is everything on a phone.
47
- // Ideas keep the panel on the Board and Ideas pages. An archived run has no workspace row: it stays here to be restored.
48
- const here = view === "board" || view === "ideas";
47
+ // Tasks keep the panel on the Board and Tasks pages. An archived run has no workspace row: it stays here to be restored.
48
+ const here = view === "board" || view === "tasks";
49
49
  if (view !== "run" && (isPhone() || !here || (c.kind === "run" && !c.archived))) {
50
50
  keepNext = !!keepTab;
51
51
  return void openWorkspace(c);
@@ -64,15 +64,15 @@ export function open(c, keepTab) {
64
64
  $("pterm").hidden = true;
65
65
  if (c.kind === "idea") {
66
66
  store.runDoc = null;
67
- $("psub").innerHTML = c.status === "starting" && !c.archived ? steps(c) : html`<span class="pst"><span class="st d-idea"><svg><use href="#s-idea"/></svg></span>Idea</span><span class="pst dim">${c.where.split(/[\\/]/).pop() || c.where}</span>`;
67
+ $("psub").innerHTML = c.status === "starting" && !c.archived ? steps(c) : html`<span class="pst"><span class="st d-idea"><svg><use href="#s-idea"/></svg></span>Task</span><span class="pst dim">${c.where.split(/[\\/]/).pop() || c.where}</span>`;
68
68
  $("ptabs").innerHTML = "";
69
- ideaBody(c);
69
+ taskBody(c);
70
70
  const foot = $("pfoot");
71
71
  foot.innerHTML = c.archived
72
72
  ? `<button class="btn pri" data-a="restore">Restore</button>`
73
73
  : c.status === "idea"
74
74
  ? `<button class="btn ghost danger" data-a="delete">Delete</button><button class="btn ghost" data-a="archive">Archive</button><span class="dec"><button class="btn" data-a="reject">Reject</button><button class="btn" data-a="edit">Edit</button><button class="btn pri" data-a="run">Run</button></span>`
75
- : `<span class="note">${c.pty ? "Starting: the agent runs below." : "Starting: a run was launched for this idea. No terminal with your agent? Run it again."}</span><span class="dec"><button class="btn" data-a="run">Run again</button></span>`;
75
+ : `<span class="note">${c.pty ? "Starting: the agent runs below." : "Starting: a run was launched for this task. No terminal with your agent? Run it again."}</span><span class="dec"><button class="btn" data-a="run">Run again</button></span>`;
76
76
  foot.querySelectorAll("[data-a]").forEach(
77
77
  (b) =>
78
78
  (b.onclick = () => {
@@ -148,10 +148,10 @@ function meta(c) {
148
148
  });
149
149
  return html`<div class="rmeta" title="${[st.runner, st.agent, st.mode].filter(Boolean).join(", ")}">${proj}</div><div class="rprog s-${c.status}" title="${cap(WORD[c.status] || c.status) + (c.awaiting ? `: ${need(c.awaiting)}` : "")}"><span>${word}</span><b><i style="width:${w}%"></i></b></div>`;
150
150
  }
151
- // An idea's panel: its terminal while the run it started is being born there, else its notes.
152
- export function ideaBody(c) {
153
- // In the run workspace the agent is a centre tab; on the Ideas page an idea shows its notes only.
154
- if (c.pty && view !== "run" && view !== "ideas") showTerm(c);
151
+ // A task's panel: its terminal while the run it started is being born there, else its notes.
152
+ export function taskBody(c) {
153
+ // In the run workspace the agent is a centre tab; on the Tasks page a task shows its notes only.
154
+ if (c.pty && view !== "run" && view !== "tasks") showTerm(c);
155
155
  else {
156
156
  termStop();
157
157
  chat(c, c.notes, c.archived || c.status !== "idea");
@@ -272,7 +272,7 @@ export async function openRun(c, refresh, again) {
272
272
  ? ` ${qs.length === 1 ? "1 question" : qs.length + " questions"}.`
273
273
  : "";
274
274
  const more =
275
- `<button data-a="archive">Archive</button>${c.column === 1 ? `<button data-a="toidea">Back to idea</button>` : ""}<hr><button data-a="ab" class="danger">Abandon</button>`;
275
+ `<button data-a="archive">Archive</button>${c.column === 1 ? `<button data-a="toidea">Back to task</button>` : ""}<hr><button data-a="ab" class="danger">Abandon</button>`;
276
276
  foot.innerHTML = html`<span class="note">${sent ? "Sent to your agent." : APPROVAL[c.awaiting] + asks}</span><details class="more"><summary class="btn ghost">More</summary><div class="menu-pop">${raw(more)}</div></details>${raw(rs)}<span class="dec"><button class="btn" data-a="revise"${sent ? " disabled" : ""}>Revise</button><button class="btn pri" data-a="approve"${sent ? " disabled" : ""}>${c.awaiting === "findings" ? "Approve as-is" : "Approve"}</button></span>`;
277
277
  } else if (c.status === "waiting")
278
278
  foot.innerHTML = html`<span class="note">Waiting: ${need(c.awaiting)}.</span>${raw(arch)}<button class="btn ghost" data-a="ab">Abandon</button>${raw(rs)}`;
@@ -317,8 +317,8 @@ export async function openRun(c, refresh, again) {
317
317
  return;
318
318
  }
319
319
  if (a === "toidea") {
320
- post("/to-idea", { dir: c.state, id: c.id }).then((r) => {
321
- if (r.ok) toast("Back in Ideas");
320
+ post("/to-task", { dir: c.state, id: c.id }).then((r) => {
321
+ if (r.ok) toast("Back in Tasks");
322
322
  load();
323
323
  });
324
324
  return;
@@ -335,15 +335,15 @@ export function deep() {
335
335
  const p = new URLSearchParams(location.search),
336
336
  d = p.get("dir"),
337
337
  id = p.get("run"),
338
- idea = p.get("idea");
338
+ task = p.get("idea");
339
339
  // A workspace address (?view=run&idea=) is the run view's own, not a note's deep link.
340
- if ((!id && idea === null) || p.get("view") === "run") return;
340
+ if ((!id && task === null) || p.get("view") === "run") return;
341
341
  history.replaceState(null, "", location.pathname + "?all=1");
342
342
  const c = store.S.cards.find(
343
- (x) => x.state === d && (id ? x.kind === "run" && x.id === id : x.kind === "idea" && x.text === idea),
343
+ (x) => x.state === d && (id ? x.kind === "run" && x.id === id : x.kind === "idea" && x.text === task),
344
344
  );
345
345
  if (!c) {
346
- toast(id ? "That run was not found" : "That idea was not found");
346
+ toast(id ? "That run was not found" : "That task was not found");
347
347
  return;
348
348
  }
349
349
  const m = /^(finding|backlog)-(\d+)$/.exec(p.get("item") || "");
@@ -394,7 +394,7 @@ export async function toggleArchive(c, archived) {
394
394
  load();
395
395
  }
396
396
  export function close() {
397
- if (view !== "board" && view !== "run" && view !== "ideas") return;
397
+ if (view !== "board" && view !== "run" && view !== "tasks") return;
398
398
  const k = store.openKey;
399
399
  stopDictation(true);
400
400
  termStop();
@@ -1,11 +1,11 @@
1
1
  // ---- Phones: their own Home (devices, recent runs, usage) and the Runs page (this
2
- // machine's runs grouped waiting / active / done). The board, Ideas and Icebox are set up
2
+ // machine's runs grouped waiting / active / done). The board, Tasks and Icebox are set up
3
3
  // on a computer; a phone has Home, Chat, Runs and Settings.
4
4
  import { runPopup } from "./cards.ts";
5
5
  import { $, html, raw } from "./dom.ts";
6
6
  import { cardHref, logo, railData, stateOf, subline, titleOf, usageChips, wsHref } from "./workspace.ts";
7
7
  import { toast } from "./toast.ts";
8
- import { agentStatus, wsKey, type Agent, type Status } from "./ws-tabs.ts";
8
+ import { agentStatus, wsKey, WORD, DOT, type Agent, type Status } from "./ws-tabs.ts";
9
9
 
10
10
  export const isPhone = () => matchMedia("(max-width:640px)").matches;
11
11
 
@@ -17,8 +17,8 @@ let allDevices = false;
17
17
 
18
18
  const chev = raw(`<svg class="pchev" viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg>`);
19
19
  const runs = () => railData().cards.filter((c) => c.kind === "run" && !c.archived);
20
- // Ideas not started yet: a phone has no Ideas page, so the Runs page lists them.
21
- const ideas = () => railData().cards.filter((c) => c.kind === "idea" && !c.archived);
20
+ // Tasks not started yet: a phone has no Tasks page, so the Runs page lists them.
21
+ const tasks = () => railData().cards.filter((c) => c.kind === "idea" && !c.archived);
22
22
  const rowKey = (c) => (c.kind === "run" ? c.id : c.text);
23
23
  const projName = (dir: string) => {
24
24
  const l = railData().projects?.find((p) => p.dir === dir)?.label || dir.replace(/[\\/]\.kaizen$/, "");
@@ -31,9 +31,7 @@ function row(c, now: number) {
31
31
  }
32
32
 
33
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 };
34
+ const RANK: Record<Status, number> = { conflict: 0, failed: 0, asking: 1, working: 2, done: 3 };
37
35
  const agentIco = (a: Agent) => {
38
36
  const id = "i-" + (a.agent || "").toLowerCase();
39
37
  return raw(`<svg class="pag-ico" aria-hidden="true"><use href="#${document.getElementById(id) ? id : "i-ai"}"/></svg>`);
@@ -54,7 +52,7 @@ function agentCards(now: number) {
54
52
  const asking = groups.filter((g) => g.rows[0].st === "asking").length;
55
53
  const cards = groups.map(({ k, rows }) => {
56
54
  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>`;
55
+ return html`<button type="button" class="pag${st === "asking" || DOT[st] === "fail" ? " 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
56
  });
59
57
  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
58
  }
@@ -132,8 +130,8 @@ function device() {
132
130
  const active = all.filter((c) => !wait.includes(c) && !done.includes(c));
133
131
  const group = (title: string, cs: any[], shut = false) =>
134
132
  cs.length ? html`<details class="pgrp"${raw(shut ? "" : " open")}><summary>${title}<span>${cs.length}</span></summary><div class="plist2">${cs.map((c) => row(c, now))}</div></details>` : "";
135
- const idle = ideas().sort((a, b) => (b.moved ?? b.added ?? 0) - (a.moved ?? a.added ?? 0));
136
- return html`${group("Waiting on you", wait)}${group("Active", active)}${group("Ideas", idle)}${group("Done", done, true)}${all.length || idle.length ? "" : html`<p class="pnote">No runs yet.</p>`}`;
133
+ const idle = tasks().sort((a, b) => (b.moved ?? b.added ?? 0) - (a.moved ?? a.added ?? 0));
134
+ return html`${group("Waiting on you", wait)}${group("Active", active)}${group("Tasks", idle)}${group("Done", done, true)}${all.length || idle.length ? "" : html`<p class="pnote">No runs yet.</p>`}`;
137
135
  }
138
136
 
139
137
  function draw() {
@@ -206,10 +204,10 @@ export function initPhone(go: (v: string, push?: boolean) => void, openRun: (c)
206
204
  if (a.dataset.dev) return (e.preventDefault(), go("device", true));
207
205
  if (a.getAttribute("aria-disabled")) return e.preventDefault();
208
206
  if (a.classList.contains("prow")) {
209
- const c = [...runs(), ...ideas()].find((x) => x.state === a.dataset.dir && rowKey(x) === a.dataset.id);
207
+ const c = [...runs(), ...tasks()].find((x) => x.state === a.dataset.dir && rowKey(x) === a.dataset.id);
210
208
  if (!c) return;
211
209
  e.preventDefault();
212
- // An idea not started has nothing in a workspace yet: pick its agent and mode instead.
210
+ // A task not started has nothing in a workspace yet: pick its agent and mode instead.
213
211
  if (c.kind === "idea" && c.status === "idea") runPopup(c);
214
212
  else openRun(c);
215
213
  }
@@ -1,7 +1,7 @@
1
1
  import { store } from "./store.ts";
2
2
  import { startDir } from "./labels.ts";
3
3
  import { load, post } from "./api.ts";
4
- import { newIdea, render } from "./cards.ts";
4
+ import { newTask, render } from "./cards.ts";
5
5
  import { $, html, ico } from "./dom.ts";
6
6
  import { openSources, srcOpen } from "./icebox.ts";
7
7
  import { toast } from "./toast.ts";
@@ -75,11 +75,11 @@ export async function pick(v) {
75
75
  if (view === "sources") openSources();
76
76
  }
77
77
  // Known projects, plus any folder a card comes from that is not one (the global inbox).
78
- // New idea in All projects: the projects being shown, else every one.
78
+ // New task in All projects: the projects being shown, else every one.
79
79
  export let newDir = null;
80
80
  // Same combo as the header's project picker: a button, then a searchable list.
81
- export function ideaCombo(f, choose = false) {
82
- const ps = ideaDirs(),
81
+ export function taskCombo(f, choose = false) {
82
+ const ps = taskDirs(),
83
83
  btn = f.querySelector("#newdir"),
84
84
  pp = f.querySelector("#ndc .menu-pop"),
85
85
  q = pp.querySelector("input"),
@@ -174,7 +174,7 @@ export function projectPicker(host: HTMLElement, ps: { dir: string; label: strin
174
174
  if (e.key === "Enter") box.querySelector<HTMLElement>("button")?.click();
175
175
  };
176
176
  }
177
- function ideaDirs() {
177
+ function taskDirs() {
178
178
  const sp = showable(),
179
179
  pick = sp.filter((p) => store.shown.has(p.dir));
180
180
  return pick.length ? pick : sp;
@@ -273,5 +273,5 @@ export function initProjects() {
273
273
  $("show").setAttribute("aria-expanded", false);
274
274
  }
275
275
  });
276
- $("newtop").onclick = newIdea;
276
+ $("newtop").onclick = newTask;
277
277
  }
@@ -0,0 +1,152 @@
1
+ // The footer's resource monitor, left of the terminal button: memory, storage and every
2
+ // live terminal by workspace. Modelled on Orca's Resource Manager status segment.
3
+ import { $, html } from "./dom.ts";
4
+
5
+ const size = (n: number) => {
6
+ if (n < 1024 ** 2) return `${Math.round(n / 1024)} KB`;
7
+ if (n < 1024 ** 3) return `${Math.round(n / 1024 ** 2)} MB`;
8
+ return `${(n / 1024 ** 3).toFixed(1)} GB`;
9
+ };
10
+
11
+ let res: any = null, disk: any = null, confirm = "", failed = "", timer: any = null;
12
+
13
+ // Recent memory use, kept in this page only: it starts empty on each load.
14
+ const history: number[] = [];
15
+ let diskOpen = false;
16
+ try { diskOpen = localStorage.getItem("kz-res-disk") === "1"; } catch {}
17
+
18
+ // The largest rows, the rest folded into one, so the bar stays readable.
19
+ const top = (rows: any[]) => {
20
+ const head = rows.slice(0, 4).map((r) => [r.name, r.bytes] as [string, number]), left = rows.slice(4).reduce((n, r) => n + r.bytes, 0);
21
+ return left ? [...head, ["Other", left] as [string, number]] : head;
22
+ };
23
+
24
+ // A segmented bar with its legend beside the values, so identity is never colour alone.
25
+ const split = (parts: [string, number][], rows = true) => {
26
+ const sum = parts.reduce((n, p) => n + p[1], 0) || 1;
27
+ return html`<div class="rseg">${parts.map(([n, v], i) => html`<i class="s${i}" style="flex:${v} 0 2px" title="${n}: ${size(v)}"></i>`)}</div>
28
+ ${rows && parts.map(([n, v], i) => html`<div class="rsrow"><span><u class="s${i}"></u>${n}</span><em>${Math.round((v / sum) * 100)}%</em><b>${size(v)}</b></div>`)}`;
29
+ };
30
+
31
+ function spark() {
32
+ if (history.length < 2) return "";
33
+ const x = (i: number) => (i / (history.length - 1)) * 100, y = (v: number) => 36 - v * 0.34;
34
+ const line = history.map((v, i) => `${x(i).toFixed(1)},${y(v).toFixed(1)}`).join(" ");
35
+ return html`<svg class="rspark" viewBox="0 0 100 36" preserveAspectRatio="none" role="img" aria-label="Memory use over recent minutes"><polygon points="0,36 ${line} 100,36"></polygon><polyline points="${line}" vector-effect="non-scaling-stroke"></polyline></svg>`;
36
+ }
37
+
38
+ const pop = () => document.getElementById("respop");
39
+
40
+ function draw() {
41
+ const box = pop();
42
+ if (!box || !res) return;
43
+ const pct = Math.round((res.system.used / res.system.total) * 100);
44
+ const groups = new Map<string, any[]>();
45
+ for (const t of res.terminals) {
46
+ const g = `${t.project || "Other"} / ${t.ws.split(/[\\/]/).pop() || "main"}`;
47
+ (groups.get(g) ?? groups.set(g, []).get(g)!).push(t);
48
+ }
49
+ const row = (t: any) => html`<div class="rsrow"><span title="${t.title}">${t.title}</span><b>${t.rss == null ? "–" : size(t.rss)}</b>${
50
+ confirm === t.key
51
+ ? html`<button type="button" data-keep>Keep</button><button type="button" class="yes" data-kill="${t.key}">Kill</button>`
52
+ : html`${t.dir ? html`<button type="button" data-open="${t.key}">Open</button>` : ""}<button type="button" class="kill" data-ask="${t.key}" aria-label="Kill ${t.title}">Kill</button>`
53
+ }</div>`;
54
+ const other = Math.max(0, res.system.used - res.kaizen), free = Math.max(0, res.system.total - res.system.used);
55
+ const mem = html`
56
+ <h3>Memory</h3>
57
+ <div class="rhero"><b>${pct}%</b><span>${size(res.system.used)} of ${size(res.system.total)} used</span></div>
58
+ ${spark()}
59
+ ${split([["Kaizen and its terminals", res.kaizen], ["Other apps", other], ["Free", free]])}`;
60
+ const rest = html`
61
+ <h3><button type="button" class="rfold" data-fold aria-expanded="${diskOpen}"><span>${diskOpen ? "▾" : "▸"}</span> Storage</button><button type="button" data-rescan>${disk?.scanning ? "Scanning…" : "Rescan"}</button></h3>
62
+ ${disk?.at ? html`<div class="rhero"><b>${size(disk.total)}</b><span>used by kaizen</span></div>${split(top(disk.rows), diskOpen)}` : html`<div class="rnote">Scanning…</div>`}
63
+ <h3>Terminals (${res.terminals.length})</h3>
64
+ ${failed ? html`<div class="rnote" role="alert">${failed}</div>` : ""}
65
+ ${res.terminals.length ? [...groups].map(([g, ts]) => html`<div class="rgrp">${g}</div>${ts.map(row)}`) : html`<div class="rnote">No live terminals.</div>`}`;
66
+ // Memory changes on every poll; the rest stays put, or a row's button would lose focus.
67
+ for (const [id, m] of [["resm", mem], ["resr", rest]] as const) {
68
+ let el = document.getElementById(id);
69
+ if (!el) { el = document.createElement("div"); el.id = id; box.append(el); }
70
+ const text = String(m);
71
+ if (el.dataset.was !== text) { el.dataset.was = text; el.innerHTML = text; }
72
+ }
73
+ }
74
+
75
+ async function load() {
76
+ try {
77
+ res = await (await fetch("/resources")).json();
78
+ history.push((res.system.used / res.system.total) * 100);
79
+ if (history.length > 60) history.shift();
80
+ const b = $("res");
81
+ b.querySelector("span").textContent = size(res.kaizen);
82
+ b.title = `Kaizen uses ${size(res.kaizen)} of memory`;
83
+ draw();
84
+ } catch { /* board restarting */ }
85
+ }
86
+
87
+ async function loadDisk(refresh = false) {
88
+ try {
89
+ disk = await (await fetch("/resources/storage" + (refresh ? "?refresh=1" : ""))).json();
90
+ draw();
91
+ } catch { /* board restarting */ }
92
+ }
93
+
94
+ function close() {
95
+ pop()?.remove();
96
+ confirm = failed = "";
97
+ $("res").setAttribute("aria-expanded", "false");
98
+ clearInterval(timer);
99
+ timer = setInterval(load, 15_000);
100
+ }
101
+
102
+ function open() {
103
+ const box = document.createElement("div");
104
+ box.id = "respop";
105
+ box.setAttribute("role", "dialog");
106
+ box.setAttribute("aria-label", "Resources");
107
+ document.body.append(box);
108
+ $("res").setAttribute("aria-expanded", "true");
109
+ box.onclick = (e) => void click(e);
110
+ draw();
111
+ void load();
112
+ void loadDisk();
113
+ clearInterval(timer);
114
+ timer = setInterval(() => { void load(); if (disk?.scanning || !disk?.at) void loadDisk(); }, 3000);
115
+ }
116
+
117
+ async function click(e: MouseEvent) {
118
+ const b = (e.target as HTMLElement).closest("button");
119
+ if (!b) return;
120
+ const d = b.dataset;
121
+ if ("fold" in d) {
122
+ diskOpen = !diskOpen;
123
+ try { localStorage.setItem("kz-res-disk", diskOpen ? "1" : "0"); } catch {}
124
+ return draw();
125
+ }
126
+ if ("rescan" in d) return void loadDisk(true);
127
+ if ("keep" in d) { confirm = ""; return draw(); }
128
+ if (d.ask) { confirm = d.ask; failed = ""; return draw(); }
129
+ if (d.open) {
130
+ const t = res.terminals.find((x: any) => x.key === d.open);
131
+ if (!t) return;
132
+ close();
133
+ if (dispatchEvent(new CustomEvent("kz-open-term", { cancelable: true, detail: { dir: t.dir, ws: t.ws, key: t.key } }))) location.href = `/?view=ws&dir=${encodeURIComponent(t.dir)}&ws=${encodeURIComponent(t.ws)}`;
134
+ return;
135
+ }
136
+ if (d.kill) {
137
+ confirm = "";
138
+ const r = await fetch("/pty/kill", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ key: d.kill }) }).catch(() => null);
139
+ failed = r?.ok ? "" : "Could not kill that terminal.";
140
+ await load();
141
+ draw();
142
+ }
143
+ }
144
+
145
+ export function initResources() {
146
+ const b = $("res");
147
+ b.onclick = () => (pop() ? close() : open());
148
+ addEventListener("pointerdown", (e) => { if (pop() && !(e.target as Element).closest("#respop,#res")) close(); });
149
+ addEventListener("keydown", (e) => { if (e.key === "Escape" && pop()) close(); });
150
+ void load();
151
+ timer = setInterval(load, 15_000);
152
+ }
@@ -1,4 +1,4 @@
1
- // The workspace centre (?view=ws&dir=&ws=; a run's or idea's old address resolves to its
1
+ // The workspace centre (?view=ws&dir=&ws=; a run's or task's old address resolves to its
2
2
  // workspace and picks that run in the panel): a tab bar over one folder holding terminals and the
3
3
  // Browser, never runs. Agent terminals are tabs, named by stage for a run's ("Build · Claude"),
4
4
  // beside shells started with POST /shell {ws}, the project's localhost, the Preview, project
@@ -137,7 +137,7 @@ export async function showRunView(nav = false) {
137
137
  const p = new URLSearchParams(location.search),
138
138
  dir = p.get("dir"),
139
139
  id = p.get("id"),
140
- idea = p.get("idea");
140
+ task = p.get("idea");
141
141
  let ws = p.get("ws"),
142
142
  want: any = null; // the card the address names, whose tab is selected
143
143
  // A project this board is not showing: a deep link names its project, switched to once, as a rail click does.
@@ -150,10 +150,10 @@ export async function showRunView(nav = false) {
150
150
  if (p.get("view") === "ws" && ws) {
151
151
  if (await away()) return showRunView(nav);
152
152
  } else {
153
- const find = (cs) => cs.find((x) => x.state === dir && (id ? x.kind === "run" && x.id === id : x.kind === "idea" && x.text === idea));
153
+ const find = (cs) => cs.find((x) => x.state === dir && (id ? x.kind === "run" && x.id === id : x.kind === "idea" && x.text === task));
154
154
  const c = find(store.S.cards);
155
- // A launched idea becomes a run: its agent session moves to the run's card, and the view follows.
156
- const pk = idea && (c ?? card)?.kind === "idea" && (c ?? card)?.pty?.key;
155
+ // A launched task becomes a run: its agent session moves to the run's card, and the view follows.
156
+ const pk = task && (c ?? card)?.kind === "idea" && (c ?? card)?.pty?.key;
157
157
  const run = pk && store.S.cards.find((x) => x.kind === "run" && x.state === dir && (x.pty?.key === pk || x.pty?.all?.includes(pk)));
158
158
  if (run) {
159
159
  history.replaceState(null, "", cardHref(run));
@@ -1,5 +1,5 @@
1
1
  // Global search: the "Search" entry on top of the side menu, and Ctrl/Cmd+K anywhere, open
2
- // one palette over workspaces, runs and ideas, chats, agent terminals, projects, pages and
2
+ // one palette over workspaces, runs and tasks, chats, agent terminals, projects, pages and
3
3
  // actions (modelled on Orca's "Jump to..." palette). Nothing is fetched but /chats; the rest
4
4
  // is what the side menu already holds. Stands alone like workspace.ts, so the notebook and
5
5
  // video pages carry it too: a pick the page cannot do in place navigates instead.
@@ -14,7 +14,7 @@ import { leaves, wsKey } from "./ws-tabs.ts";
14
14
  const ask = (name: string, detail: any) => !dispatchEvent(new CustomEvent(name, { cancelable: true, detail }));
15
15
  // A menu entry's own click: in place on the board, a page load elsewhere.
16
16
  const page = (v: string, href: string) => () => {
17
- const a = document.querySelector<HTMLElement>(`.rail a.it[data-view="${v}"]`);
17
+ const a = document.querySelector<HTMLElement>(`.rail a[data-view="${v}"]`);
18
18
  a ? a.click() : (location.href = href);
19
19
  };
20
20
  const openWs = (dir: string, ws: string) => {
@@ -107,11 +107,11 @@ function items(): Item[] {
107
107
  main ? openWs(p.dir, main.path) : page("board", "/?view=board")();
108
108
  } });
109
109
  }
110
- // Runs and ideas, not archived.
110
+ // Runs and tasks, not archived.
111
111
  for (const c of cards.filter((c) => !c.archived)) {
112
112
  const st = stateOf(c);
113
113
  out.push({
114
- group: c.kind === "run" ? "Runs" : "Ideas",
114
+ group: c.kind === "run" ? "Runs" : "Tasks",
115
115
  title: titleOf(c) || c.id,
116
116
  sub: projName(c.state, projects),
117
117
  when: c.moved ? age(c.moved, now) : undefined,
@@ -162,11 +162,11 @@ function items(): Item[] {
162
162
  const acts: [string, string, () => void, string?][] = [
163
163
  ["Home", "page", page("home", "/"), "chat"],
164
164
  ["Icebox", "page", page("sources", "/?view=icebox"), "requests sources gathered"],
165
- ["Ideas", "page", page("ideas", "/?view=ideas"), "backlog"],
165
+ ["Tasks", "page", page("tasks", "/?view=tasks"), "backlog"],
166
166
  ["Board", "page", page("board", "/?view=board"), "kanban runs"],
167
167
  ["Notes", "page", () => (location.href = "/notebook"), "notebook docs"],
168
168
  ["Settings", "page", page("settings", "/?view=settings"), "preferences config"],
169
- ["New idea", "act", () => ($("newtop") ? $("newtop").click() : (location.href = "/?view=board")), "create add run"],
169
+ ["New task", "act", () => ($("newtop") ? $("newtop").click() : (location.href = "/?view=board")), "create add run"],
170
170
  ["Add a project", "act", () => openAdd({ dir: null }), "clone folder create workspace"],
171
171
  ["Toggle theme", "act", click("themet"), "dark light"],
172
172
  ["Collapse or expand menu", "act", click("fold"), "sidebar rail"],
@@ -177,9 +177,9 @@ function items(): Item[] {
177
177
  return out;
178
178
  }
179
179
 
180
- const ORDER = ["Current", "Workspaces", "Tabs", "Chats & terminals", "Runs", "Ideas", "Projects", "Actions"];
180
+ const ORDER = ["Current", "Workspaces", "Tabs", "Chats & terminals", "Runs", "Tasks", "Projects", "Actions"];
181
181
  // With nothing typed each group shows its most recent few, as Orca's does.
182
- const CAP = { Workspaces: 5, Tabs: 4, "Chats & terminals": 5, Runs: 5, Ideas: 3, Projects: 5 };
182
+ const CAP = { Workspaces: 5, Tabs: 4, "Chats & terminals": 5, Runs: 5, Tasks: 3, Projects: 5 };
183
183
 
184
184
  let dl: HTMLDialogElement | null = null;
185
185
  let shown: Item[] = [];
@@ -195,9 +195,9 @@ function draw() {
195
195
  const rows = hit.filter((i) => i.group === g);
196
196
  shown.push(...rows.slice(0, q.trim() ? 8 : CAP[g] ?? rows.length));
197
197
  }
198
- // Orca offers to create what was typed; here that is a new idea.
198
+ // Orca offers to create what was typed; here that is a new task.
199
199
  if (q.trim())
200
- shown.push({ group: "Create", title: `New idea "${q.trim()}"`, hay: "", ico: "plus", act: () => newIdeaWith(q.trim()) });
200
+ shown.push({ group: "Create", title: `New task "${q.trim()}"`, hay: "", ico: "plus", act: () => newTaskWith(q.trim()) });
201
201
  sel = Math.min(sel, shown.length - 1);
202
202
  const list = dl!.querySelector(".gs-list")!;
203
203
  let g = "";
@@ -219,7 +219,7 @@ function mark(n: number) {
219
219
  dl!.querySelector("input")!.setAttribute("aria-activedescendant", "gs-" + n);
220
220
  r?.scrollIntoView({ block: "nearest" });
221
221
  }
222
- function newIdeaWith(text: string) {
222
+ function newTaskWith(text: string) {
223
223
  if (!$("newtop")) return void (location.href = "/?view=board");
224
224
  $("newtop").click();
225
225
  const t = document.querySelector<HTMLTextAreaElement>("dialog[open] textarea");
@@ -0,0 +1,42 @@
1
+ import { post } from "./api.ts";
2
+ import { $, html } from "./dom.ts";
3
+ import { toast } from "./toast.ts";
4
+
5
+ // Settings → General → Cleanup: the two halves of `kaizen prune`, one button each, so
6
+ // clearing dead launch records never takes run history with it.
7
+ export type Cleanup = { project: string | null; keep: number; records: { abandoned: number; unowned: number; gone: number }; runs: number; rescued: number };
8
+
9
+ const total = (d: Cleanup) => d.records.abandoned + d.records.unowned + d.records.gone;
10
+ const btn = (id: string, text: string, n: number) => html`<button type="button" class="btn" id="${id}"${n ? "" : " disabled"}>${text}</button>`;
11
+
12
+ export const cleanupRows = (d: Cleanup) => [
13
+ {
14
+ label: "Clean launch records",
15
+ control: btn("s-clean-records", "Clean up", total(d)),
16
+ hint: `${total(d)} older than a week: ${d.records.abandoned} abandoned · ${d.records.unowned} unowned · ${d.records.gone} run gone`,
17
+ id: "s-clean-records",
18
+ q: "cleanup clean launch records sessions prune",
19
+ },
20
+ {
21
+ label: "Delete old runs",
22
+ control: btn("s-clean-runs", "Delete", d.runs),
23
+ hint: `${d.runs} finished runs beyond the newest ${d.keep}${d.rescued ? `; ${d.rescued} open backlog items move to backlog.md` : ""}`,
24
+ id: "s-clean-runs",
25
+ q: "cleanup delete old runs prune history",
26
+ },
27
+ ];
28
+
29
+ export function wireCleanup(d: Cleanup, redraw: () => Promise<unknown>) {
30
+ const where = d.project ? ` in ${d.project}` : "";
31
+ const go = (id: string, what: string, ask: string) => {
32
+ const b = $(id);
33
+ if (b) b.onclick = async () => {
34
+ if (!confirm(ask)) return;
35
+ const j = await post("/cleanup", { what });
36
+ toast(j.error ?? `Removed ${j.removed}`);
37
+ await redraw();
38
+ };
39
+ };
40
+ go("s-clean-records", "records", `Delete ${total(d)} launch records${where}?`);
41
+ go("s-clean-runs", "runs", `Permanently delete ${d.runs} finished runs${where}? Their plans, reviews and reports go, and this cannot be undone.`);
42
+ }
@@ -41,7 +41,7 @@ const PLACES: [RegExp, string, string][] = [
41
41
  [/^git\./, "git", "Git"],
42
42
  [/^ui\./, "terminal", "Terminal"],
43
43
  [/^board\.chat_hotkey$/, "shortcuts", "Shortcuts"],
44
- [/^board\./, "general", "Board"],
44
+ [/^board\./, "general", "App"],
45
45
  [/^(review\.|state\.)/, "general", "Project"],
46
46
  ];
47
47
  // A setting nobody has placed yet still shows, on General.