kaizen-agent 1.59.2 → 1.60.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 (63) hide show
  1. package/cli/add-project.test.ts +169 -0
  2. package/cli/add-project.ts +132 -0
  3. package/cli/board.test.ts +15 -0
  4. package/cli/chat.ts +1 -1
  5. package/cli/dashboard.ts +6 -2
  6. package/cli/install.test.ts +1 -1
  7. package/cli/install.ts +18 -9
  8. package/cli/pty.test.ts +89 -5
  9. package/cli/pty.ts +126 -9
  10. package/cli/restart.test.ts +169 -0
  11. package/cli/settings.test.ts +35 -0
  12. package/cli/settings.ts +69 -18
  13. package/cli/state.test.ts +119 -3
  14. package/cli/state.ts +171 -13
  15. package/cli/usage.test.ts +130 -1
  16. package/cli/web-accept.test.ts +54 -0
  17. package/cli/web-pr.test.ts +51 -0
  18. package/cli/web-symlink.test.ts +28 -0
  19. package/cli/web.ts +349 -100
  20. package/cli/worktree.test.ts +146 -1
  21. package/cli/worktree.ts +214 -4
  22. package/cli/writeback.ts +1 -1
  23. package/package.json +1 -1
  24. package/skills/kaizen/SKILL.md +5 -1
  25. package/skills/kaizen/config.default.yml +15 -2
  26. package/skills/kaizen/settings.md +1 -0
  27. package/skills/kaizen/spec-main.md +28 -2
  28. package/skills/kaizen-help/SKILL.md +1 -0
  29. package/web/board/add-project.ts +136 -0
  30. package/web/board/api.ts +1 -1
  31. package/web/board/badge.ts +5 -5
  32. package/web/board/cards.ts +11 -3
  33. package/web/board/context.ts +1 -0
  34. package/web/board/fixes.ts +3 -2
  35. package/web/board/git.ts +309 -60
  36. package/web/board/home.ts +7 -1
  37. package/web/board/ideas.ts +20 -3
  38. package/web/board/live.ts +1 -1
  39. package/web/board/main.ts +26 -9
  40. package/web/board/panel.ts +31 -16
  41. package/web/board/projects.ts +6 -85
  42. package/web/board/run-pick.ts +41 -0
  43. package/web/board/run-view.ts +286 -110
  44. package/web/board/search-match.ts +20 -0
  45. package/web/board/search.test.ts +20 -0
  46. package/web/board/search.ts +324 -0
  47. package/web/board/settings.ts +42 -5
  48. package/web/board/store.ts +3 -1
  49. package/web/board/toast.ts +4 -1
  50. package/web/board/views.ts +3 -1
  51. package/web/board/workspace.ts +127 -38
  52. package/web/board/ws-board-ui.ts +95 -0
  53. package/web/board/ws-board.test.ts +71 -0
  54. package/web/board/ws-board.ts +45 -0
  55. package/web/board/ws-tabs.test.ts +181 -0
  56. package/web/board/ws-tabs.ts +173 -0
  57. package/web/board.html +86 -36
  58. package/web/board.js +129 -44
  59. package/web/notebook.js +41 -24
  60. package/web/notes.html +26 -20
  61. package/web/term.js +1 -1
  62. package/web/video.html +26 -20
  63. package/web/video.js +76 -59
@@ -7,7 +7,7 @@ import { chat } from "./chat.ts";
7
7
  import { stopDictation } from "./dictation.ts";
8
8
  import { $, html, raw } from "./dom.ts";
9
9
  import { fixForm, fixOff } from "./fixes.ts";
10
- import { commitPush, confirmCommit, gitBtn } from "./git.ts";
10
+ import { gitPending, gitShown, gitTab } from "./git.ts";
11
11
  import { ICON, WORD, need } from "./labels.ts";
12
12
  import { attach, brief, md, planQuestions, preview, progress } from "./markdown.ts";
13
13
  import { toast } from "./toast.ts";
@@ -24,6 +24,7 @@ const TABS = [
24
24
  ["Backlog", "backlog"],
25
25
  ["Work", "impl"],
26
26
  ["Review", "review"],
27
+ ["Git", "git"],
27
28
  ["Preview", "preview"],
28
29
  ];
29
30
  // keepTab: a link already chose the tab.
@@ -87,7 +88,7 @@ export function open(c, keepTab) {
87
88
  if (!keepTab)
88
89
  store.lastTab = store.tab =
89
90
  c.status === "abandoned" ? "plan" : { 1: "plan", 2: "backlog", 3: "review", 4: "preview" }[c.column] || "request";
90
- openRun(c, false);
91
+ return openRun(c, false);
91
92
  }
92
93
  // A building run's Backlog tab opens with its progress, above the deferred items. The
93
94
  // first draw of a run animates nothing; later ones animate what moved, the bar included.
@@ -136,7 +137,8 @@ function meta(c) {
136
137
  }
137
138
  // An idea's panel: its terminal while the run it started is being born there, else its notes.
138
139
  export function ideaBody(c) {
139
- if (c.pty && view !== "run") showTerm(c); // in the run workspace the agent is a centre tab
140
+ // In the run workspace the agent is a centre tab; on the Ideas page an idea shows its notes only.
141
+ if (c.pty && view !== "run" && view !== "ideas") showTerm(c);
140
142
  else {
141
143
  termStop();
142
144
  chat(c, c.notes, c.archived || c.status !== "idea");
@@ -145,6 +147,8 @@ export function ideaBody(c) {
145
147
  export async function openRun(c, refresh, again) {
146
148
  if (!refresh || !store.runDoc || store.runDoc.id !== c.id || again) {
147
149
  const d = await fetch(`/run/${encodeURIComponent(c.id)}?dir=${encodeURIComponent(c.state)}`).then((r) => r.json());
150
+ // Another card opened while this was fetched: its doc would redraw that card as this run.
151
+ if (store.openKey !== key(c)) return;
148
152
  // A file list being confirmed, or a push under way, keeps the doc it was drawn from.
149
153
  if (refresh && $("pfoot").querySelector(".inl,[data-busy],.more[open]")) return;
150
154
  store.runDoc = d;
@@ -166,9 +170,11 @@ export async function openRun(c, refresh, again) {
166
170
  (t) =>
167
171
  t[1] === "request" ||
168
172
  t[1] === "notes" ||
169
- (t[1] === "preview"
170
- ? preview(store.runDoc.impl)
171
- : store.runDoc[t[1]] || (t[1] === "backlog" && c.column === 2 && store.runDoc.progress)),
173
+ (t[1] === "git"
174
+ ? gitShown(c)
175
+ : t[1] === "preview"
176
+ ? preview(store.runDoc.impl)
177
+ : store.runDoc[t[1]] || (t[1] === "backlog" && c.column === 2 && store.runDoc.progress)),
172
178
  );
173
179
  if (store.wantTerm === key(c)) store.wantTerm = null;
174
180
  // The agent is a centre tab of the run workspace only: the panel never shows a terminal.
@@ -177,7 +183,7 @@ export async function openRun(c, refresh, again) {
177
183
  if (view === "run" && store.tab === "preview") store.tab = "review";
178
184
  // A tab not written yet falls back to the latest one that is.
179
185
  if (store.tab !== "term" && !tabs.some((t) => t[1] === store.tab))
180
- store.tab = [...tabs].reverse().find((t) => t[1] !== "notes" && !(view === "run" && t[1] === "preview"))[1];
186
+ store.tab = [...tabs].reverse().find((t) => t[1] !== "notes" && t[1] !== "git" && !(view === "run" && t[1] === "preview"))[1];
181
187
  if (store.tab !== "term") store.lastTab = store.tab;
182
188
  $("panel").classList.toggle("wide", store.tab === "term");
183
189
  const pt = $("pterm");
@@ -209,12 +215,13 @@ export async function openRun(c, refresh, again) {
209
215
  else if (k === "notes") {
210
216
  const ro = c.archived || c.status === "done" || c.status === "abandoned";
211
217
  chat(c, doc, ro);
212
- } else
218
+ } else if (k === "git") gitTab(c, refresh);
219
+ else
213
220
  $("pbody").innerHTML = doc
214
221
  ? raw(md(doc, k === "backlog"))
215
222
  : html`<p style="color:var(--dim)">No ${{ request: "request", plan: "plan", impl: "work report", preview: "preview", review: "review", backlog: "backlog" }[k]} yet.</p>`;
216
223
  if (k === "backlog") showProgress(c);
217
- if (k === "review") fixForm(c);
224
+ if (k === "review" && !c.healed) fixForm(c);
218
225
  // The notebook's notes that link here, each opening that note: above the run's own notes.
219
226
  if (k === "notes" && store.runDoc.linkedFrom && store.runDoc.linkedFrom.length)
220
227
  $("pbody").insertAdjacentHTML(
@@ -229,8 +236,9 @@ export async function openRun(c, refresh, again) {
229
236
  const foot = $("pfoot");
230
237
  // A refresh while the commit is being confirmed would wipe the message.
231
238
  if (refresh && foot.querySelector(".inl,[data-busy],.more[open]")) return;
239
+ // Git work left on a finished run: the footer points at the Git tab, which holds it.
232
240
  const arch =
233
- gitBtn(c) +
241
+ (k !== "git" && gitPending(c) ? `<button class="btn" data-a="gittab">Git…</button>` : "") +
234
242
  (c.archived
235
243
  ? `<button class="btn pri" data-a="restore">Restore</button>`
236
244
  : `<button class="btn ghost" data-a="archive">Archive</button>`);
@@ -241,6 +249,8 @@ export async function openRun(c, refresh, again) {
241
249
  // Its in-card agent ended on a waiting or done run: reopen that conversation, nothing sent.
242
250
  const rs = c.pty && !c.pty.alive ? `<button class="btn" data-a="resume">Resume session</button>` : "";
243
251
  if (c.archived) foot.innerHTML = raw(arch);
252
+ else if (c.healed && c.awaiting === "approvals.review")
253
+ foot.innerHTML = html`<span class="note">Finished by its agent without your approval. Nothing is committed until you approve.</span>${raw(arch + rs)}<button class="btn pri" data-a="accept">Approve</button>`;
244
254
  else if ((c.status === "waiting" || c.awaiting === "findings") && APPROVAL[c.awaiting]) {
245
255
  const sent = decided.has(answer(c)),
246
256
  asks = !pq
@@ -248,13 +258,13 @@ export async function openRun(c, refresh, again) {
248
258
  : qs.length
249
259
  ? ` Approve first asks you ${qs.length === 1 ? "its question" : "its " + qs.length + " questions"}.`
250
260
  : "";
251
- // gitBtn's buttons restyled as menu rows.
252
261
  const more =
253
- gitBtn(c).replace(/class="btn( pri)?"/g, "") +
254
262
  `<button data-a="archive">Archive</button><hr><button data-a="ab" class="danger">Abandon</button>`;
255
263
  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>`;
256
264
  } else if (c.status === "waiting")
257
265
  foot.innerHTML = html`<span class="note">Waiting on you: ${need(c.awaiting)}. Answer in the ${c.pty && c.pty.alive ? "terminal (button at the top)" : "terminal running this run"}.</span>${raw(arch)}<button class="btn ghost" data-a="ab">Abandon</button>${raw(rs)}`;
266
+ else if (c.status === "done" && c.accept === "needs")
267
+ foot.innerHTML = html`<span class="note">Done, not approved: its agent finished without your approval. Nothing is committed until you approve.</span>${raw(arch + rs)}<button class="btn pri" data-a="accept">Approve</button>`;
258
268
  else if (c.status === "done") foot.innerHTML = raw(arch + rs);
259
269
  else if (c.status === "abandoned") foot.innerHTML = raw(arch);
260
270
  else
@@ -267,12 +277,17 @@ export async function openRun(c, refresh, again) {
267
277
  toggleArchive(c, a === "archive");
268
278
  return;
269
279
  }
270
- if (a === "push") {
271
- commitPush(c, "", b);
280
+ if (a === "gittab") {
281
+ store.tab = "git";
282
+ openRun(c, true);
272
283
  return;
273
284
  }
274
- if (a === "commit") {
275
- confirmCommit(c);
285
+ if (a === "accept") {
286
+ b.disabled = true;
287
+ post("/accept", { dir: c.state, id: c.id }).then((r) => {
288
+ if (r.ok) toast("Approved");
289
+ else b.disabled = false;
290
+ });
276
291
  return;
277
292
  }
278
293
  if (a === "approve") {
@@ -2,9 +2,10 @@ import { store } from "./store.ts";
2
2
  import { startDir } from "./labels.ts";
3
3
  import { load, post } from "./api.ts";
4
4
  import { newIdea, render } from "./cards.ts";
5
- import { $, html, ico, modal } from "./dom.ts";
5
+ import { $, html, ico } from "./dom.ts";
6
6
  import { openSources, srcOpen } from "./icebox.ts";
7
7
  import { toast } from "./toast.ts";
8
+ import { openAdd } from "./add-project.ts";
8
9
  import { view } from "./views.ts";
9
10
 
10
11
  // The picked project outlives a reload. Saved only where the user changes it, so a
@@ -55,90 +56,10 @@ export async function pick(v) {
55
56
  toast("Searching…");
56
57
  const j = await post("/find", {});
57
58
  if (j.ok) toast(j.added ? `Found ${j.added} new project${j.added === 1 ? "" : "s"}` : "No new projects found");
58
- } else if (v === "__new") {
59
- // A name, and where it goes: the projects folder unless typed or picked.
60
- const dl = modal(
61
- `<b>New project</b><input name="name" placeholder="Project name" aria-label="Project name" spellcheck="false" autocomplete="off"><div class="row"><input name="to" placeholder="Folder to create" aria-label="Create in" spellcheck="false" autocomplete="off"><button type="button" class="btn ghost" data-a="pick">Pick…</button></div><div class="row"><button type="button" class="btn ghost" data-a="x">Cancel</button><button class="btn pri">Create</button></div>`,
62
- );
63
- const f = dl.querySelector("form"),
64
- name = f.querySelector("[name=name]"),
65
- to = f.querySelector("[name=to]");
66
- let auto = ""; // the folder this form filled in; one the user typed is left alone
67
- name.oninput = async () => {
68
- const n = name.value.trim();
69
- if (!n || /[\\/:*?"<>|]/.test(n) || (to.value.trim() && to.value !== auto)) return; // a bad name is reported once, at Create
70
- const d = await post("/new-project", { name: n, check: true });
71
- if (d.ok && name.value.trim() === n) to.value = auto = d.to;
72
- };
73
- f.querySelector("[data-a=x]").onclick = () => dl.close();
74
- f.querySelector("[data-a=pick]").onclick = async () => {
75
- const p = await post("/pick-folder", {});
76
- if (p.path)
77
- to.value = p.path.replace(/[\\/]+$/, "") + (p.path.includes("\\") ? "\\" : "/") + (name.value.trim() || "");
78
- };
79
- name.focus();
80
- const dir = await new Promise((done) => {
81
- dl.addEventListener("close", () => done(null));
82
- f.onsubmit = async (e) => {
83
- e.preventDefault();
84
- if (!name.value.trim()) return name.focus();
85
- const j = await post("/new-project", { name: name.value.trim(), to: to.value.trim() || undefined });
86
- if (!j.ok) return;
87
- done(j.dir);
88
- dl.close();
89
- };
90
- });
91
- if (!dir) return;
92
- await post("/cd", { dir });
93
- store.all = false;
94
- store.dir = dir;
95
- keep(dir);
96
- toast("Project created");
97
- } else if (v === "__clone") {
98
- // One form: the link, then where it goes. The folder fills in once the link names a repo.
99
- const dl = modal(
100
- `<b>Clone from GitHub</b><input name="url" placeholder="https://github.com/owner/repo" aria-label="GitHub link (https or ssh)" spellcheck="false" autocomplete="off"><div class="row"><input name="to" placeholder="Folder to clone into" aria-label="Clone into" spellcheck="false" autocomplete="off"><button type="button" class="btn ghost" data-a="pick">Pick…</button></div><div class="row"><button type="button" class="btn ghost" data-a="x">Cancel</button><button class="btn pri">Clone</button></div>`,
101
- );
102
- const f = dl.querySelector("form"),
103
- url = f.querySelector("[name=url]"),
104
- to = f.querySelector("[name=to]");
105
- let name = "",
106
- auto = ""; // the folder this form filled in; one the user typed is left alone
107
- const check = async () => {
108
- const u = url.value.trim();
109
- if (!u) return null;
110
- const d = await post("/clone", { url: u, check: true });
111
- if (!d.ok) return null;
112
- name = d.name;
113
- if (!to.value.trim() || to.value === auto) to.value = auto = d.to;
114
- return d;
115
- };
116
- url.onchange = check;
117
- f.querySelector("[data-a=x]").onclick = () => dl.close();
118
- f.querySelector("[data-a=pick]").onclick = async () => {
119
- if (!(await check())) return url.focus();
120
- const p = await post("/pick-folder", {});
121
- if (p.path) to.value = p.path.replace(/[\\/]+$/, "") + (p.path.includes("\\") ? "\\" : "/") + name;
122
- };
123
- url.focus();
124
- const dir = await new Promise((done) => {
125
- dl.addEventListener("close", () => done(null));
126
- f.onsubmit = async (e) => {
127
- e.preventDefault();
128
- if (!(await check())) return url.focus();
129
- toast("Cloning…");
130
- const j = await post("/clone", { url: url.value.trim(), to: to.value.trim() || undefined });
131
- if (!j.ok) return;
132
- done(j.dir);
133
- dl.close();
134
- };
135
- });
136
- if (!dir) return;
137
- await post("/cd", { dir });
138
- store.all = false;
139
- store.dir = dir;
140
- keep(dir);
141
- toast("Cloned");
59
+ } else if (v === "__new" || v === "__clone") {
60
+ // The same sheet as the side menu's +; it adds the project and reloads onto it.
61
+ openAdd({ start: v === "__new" ? "create" : "clone" });
62
+ return;
142
63
  } else if (v === "all") {
143
64
  store.all = true;
144
65
  keep();
@@ -0,0 +1,41 @@
1
+ // The run picker at the top of the workspace's run panel (#ppick, popover #ppop): the runs not
2
+ // over (waiting on you first), then History. run-view.ts decides which run the panel shows.
3
+ import { $, html } from "./dom.ts";
4
+ import { key } from "./cards.ts";
5
+ import { age } from "./labels.ts";
6
+ import { awaiting, dueWord, gitDue } from "./ws-tabs.ts";
7
+ import { stateOf, titleOf } from "./workspace.ts";
8
+
9
+ let sig = "";
10
+ export const setOpen = (on: boolean) => {
11
+ $("ppop").hidden = !on;
12
+ $("ppick").setAttribute("aria-expanded", String(on));
13
+ };
14
+ export const drawPick = (live: any[], hist: any[], cur: any) => {
15
+ const now = Date.now(),
16
+ other = live.some((c) => c !== cur && awaiting(c)),
17
+ row = (c) => html`<button type="button" role="option" class="pk${c === cur ? " on" : ""}" aria-selected="${String(c === cur)}" data-pk="${key(c)}"><span class="si ${stateOf(c)}"></span><b>${titleOf(c)}</b><small>${gitDue(c) ? `waiting on you · ${dueWord(c)}` : awaiting(c) ? "needs you" : c.status} · ${age(c.moved ?? now, now)}</small></button>`;
18
+ const out = String(html`${live.map(row)}${hist.length ? html`<b class="mh">History</b>${hist.map(row)}` : ""}`);
19
+ const label = String(html`<span class="si ${stateOf(cur)}"></span><b>${titleOf(cur)}</b>${other ? html`<i class="pdot" title="Another run needs you"></i>` : ""}<svg class="fchev" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`);
20
+ if (sig === out + label) return;
21
+ sig = out + label;
22
+ $("ppop").innerHTML = out;
23
+ $("ppick").innerHTML = label;
24
+ };
25
+ export const hidePick = () => ((sig = ""), setOpen(false));
26
+ // Wires the trigger once: a click on a row calls pick(key); Esc and a press outside close it.
27
+ export function initPick(pick: (k: string) => void) {
28
+ $("ppick").onclick = () => setOpen($("ppop").hidden);
29
+ $("ppop").onclick = (e) => {
30
+ const k = (e.target as Element).closest<HTMLElement>("[data-pk]")?.dataset.pk;
31
+ if (!k) return;
32
+ setOpen(false);
33
+ pick(k);
34
+ };
35
+ addEventListener("keydown", (e) => {
36
+ if (e.key === "Escape" && !$("ppop").hidden) (setOpen(false), $("ppick").focus());
37
+ });
38
+ addEventListener("pointerdown", (e) => {
39
+ if (!$("ppop").hidden && !(e.target as Element).closest?.(".pwrap")) setOpen(false);
40
+ });
41
+ }