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
package/web/board/git.ts CHANGED
@@ -1,76 +1,325 @@
1
1
  import { store } from "./store.ts";
2
2
  import { post } from "./api.ts";
3
3
  import { key } from "./cards.ts";
4
- import { $, html } from "./dom.ts";
4
+ import { $, html, raw } from "./dom.ts";
5
5
  import { commitMsg } from "./markdown.ts";
6
6
  import { openRun } from "./panel.ts";
7
7
  import { toast } from "./toast.ts";
8
8
 
9
- // Commit and push, for a finished run in a project with a git remote. What the board
10
- // did is recorded per run, so the settled label outlives later changes to the tree.
11
- export function gitBtn(c) {
9
+ // The run's Git tab, laid out like Orca's Source Control panel: the branch and its pull
10
+ // request at the top, the run's changed files and the message, then one split button
11
+ // whose label is the next step (commit, push, open the PR, merge it, remove the worktree)
12
+ // with the other steps in its menu, each unavailable one saying why. A run built in the
13
+ // project's own checkout (no worktree) only commits and pushes.
14
+
15
+ // What the user typed and which inline confirm is open, per run: a refresh redraws the tab.
16
+ const ui = new Map<string, { msg?: string; title?: string; body?: string; draft?: boolean; ask?: string }>();
17
+ const st = (c) => {
18
+ let u = ui.get(key(c));
19
+ if (!u) ui.set(key(c), (u = {}));
20
+ return u;
21
+ };
22
+
23
+ // Commits only after the final approval, and only on a finished run.
24
+ export const gitShown = (c) => {
25
+ const g = store.runDoc && store.runDoc.git;
26
+ return (
27
+ !!(g && g.repo) && !c.archived && c.accept !== "needs" && (c.status === "done" || c.awaiting === "approvals.review")
28
+ );
29
+ };
30
+ // Something is left to do: the footer points at the tab.
31
+ export const gitPending = (c) => {
32
+ if (!gitShown(c)) return false;
12
33
  const g = store.runDoc.git,
13
- k = store.runDoc.commit;
14
- if (c.archived || !g || !g.repo || !(c.status === "done" || c.awaiting === "approvals.review")) return "";
15
- // A run already pushed keeps saying so; work changed since is offered beside it.
16
- if (k && k.pushed)
17
- return (
18
- html`<button class="btn" disabled title="${k.sha}">Committed &amp; pushed</button>` +
19
- (g.files.length
20
- ? `<button class="btn" data-a="commit">Commit new changes</button>`
21
- : g.ahead > 0
22
- ? `<button class="btn" data-a="push">Push</button>`
23
- : "")
24
- );
25
- if (g.files.length) return `<button class="btn pri" data-a="commit">Commit &amp; push</button>`;
26
- if (g.ahead > 0) return `<button class="btn pri" data-a="push">Push</button>`;
27
- // None of its files changed and level with the remote: it was committed and pushed
28
- // somewhere else. With no record and no report, nothing says it was ever committed.
29
- return k || store.runDoc.impl ? `<button class="btn" disabled>Committed &amp; pushed</button>` : "";
34
+ b = store.runDoc.branch;
35
+ return (
36
+ g.files.length > 0 ||
37
+ (b
38
+ ? (b.upstream && g.ahead > 0) ||
39
+ (b.pr && b.pr.state === "OPEN") ||
40
+ (b.landed && !b.pr) ||
41
+ (b.pr && b.pr.state === "MERGED")
42
+ : g.ahead > 0)
43
+ );
44
+ };
45
+
46
+ // Every step, in the order the primary button walks them. `why` is set when the step is
47
+ // unavailable; the menu shows it under the label, as Orca does.
48
+ function steps(c) {
49
+ const g = store.runDoc.git,
50
+ b = store.runDoc.branch,
51
+ pr = b && b.pr,
52
+ files = g.files.length,
53
+ open = pr && pr.state === "OPEN";
54
+ const s = [
55
+ { a: "commit", label: "Commit & push", why: files ? "" : "No changes to commit" },
56
+ {
57
+ a: "push",
58
+ label: "Push",
59
+ why: files
60
+ ? "Commit changes first"
61
+ : b && !b.upstream
62
+ ? "Not published yet: Create PR pushes it"
63
+ : g.ahead > 0
64
+ ? ""
65
+ : "Nothing to push",
66
+ },
67
+ ];
68
+ if (!b) return s;
69
+ const noGh = b.gh ? "" : "Needs the GitHub CLI (gh) and a GitHub remote";
70
+ const prWhy =
71
+ noGh ||
72
+ (files
73
+ ? "Commit changes first"
74
+ : pr && pr.state !== "CLOSED"
75
+ ? `Pull request #${pr.number} is ${pr.state === "MERGED" ? "merged" : "open"}`
76
+ : "");
77
+ s.push(
78
+ { a: "pr", label: b.upstream && g.ahead === 0 ? "Create PR" : "Push & create PR", why: prWhy },
79
+ { a: "draft", label: "Create draft PR", why: prWhy },
80
+ {
81
+ a: "merge",
82
+ label: "Merge PR",
83
+ why:
84
+ noGh ||
85
+ (!open
86
+ ? "No open pull request"
87
+ : pr.draft
88
+ ? "Draft: mark it ready on GitHub first"
89
+ : files
90
+ ? "Commit changes first"
91
+ : g.ahead > 0
92
+ ? "Push first"
93
+ : ""),
94
+ },
95
+ {
96
+ a: "remove",
97
+ label: "Remove workspace",
98
+ why: files ? "Commit or discard the changes first" : b.landed ? "" : "Merge the pull request first",
99
+ },
100
+ );
101
+ return s;
30
102
  }
31
- export function confirmCommit(c, msg) {
103
+
104
+ const PR_WORD = { OPEN: "Open", MERGED: "Merged", CLOSED: "Closed" };
105
+
106
+ export function gitTab(c, refresh) {
107
+ const body = $("pbody");
108
+ // A refresh while the user types or a step runs would lose the text or the busy label.
109
+ if (
110
+ refresh &&
111
+ body.querySelector(".gitp") &&
112
+ (body.querySelector(".gitp [data-busy]") || body.querySelector(".gitp")!.contains(document.activeElement))
113
+ )
114
+ return;
32
115
  const g = store.runDoc.git,
33
- foot = $("pfoot");
34
- foot.innerHTML = html`<div class="inl" style="flex:1"><div class="q">Commit ${g.files.length} changed file${g.files.length === 1 ? "" : "s"} on ${g.branch || "this branch"} and push to ${g.remote}?</div><div class="q dim">Only the files this run's report names.${g.others ? ` ${g.others} other changed file${g.others === 1 ? " is" : "s are"} left alone.` : ""}</div><pre class="files">${g.files.join("\n")}</pre>${g.shared && g.shared.length ? html`<div class="q">These files also hold other runs' changes, and a file is committed whole:</div><pre class="files">${g.shared.join("\n")}</pre>` : ""}<textarea aria-label="Commit message" placeholder="Describe what changed">${msg || commitMsg(store.runDoc.impl) || c.title || c.text}</textarea><div class="q dim" id="clong" hidden>The first line is over 72 characters; logs will cut it short.</div><div class="row"><button class="btn ghost" data-a="c">Cancel</button><button class="btn pri" data-a="s">Commit &amp; push</button></div></div>`;
35
- const inp = foot.querySelector("textarea"),
36
- go = foot.querySelector("[data-a=s]");
37
- inp.focus();
38
- // Tall enough to show the whole message, up to half the window.
39
- const fit = () => {
40
- inp.style.height = "auto";
41
- inp.style.height = Math.min(inp.scrollHeight + 2, innerHeight / 2) + "px";
42
- $("clong").hidden = inp.value.split("\n")[0].length <= 72;
43
- };
44
- inp.oninput = fit;
45
- fit();
46
- foot.querySelector("[data-a=c]").onclick = () => {
47
- foot.innerHTML = "";
48
- openRun(c, true);
49
- };
50
- go.onclick = () => {
51
- if (!inp.value.trim()) {
52
- toast("A commit message is required");
53
- return;
54
- }
55
- commitPush(c, inp.value, go);
56
- };
57
- inp.onkeydown = (e) => {
58
- if (e.key === "Enter" && !e.shiftKey) {
59
- e.preventDefault();
60
- go.click();
61
- }
62
- };
116
+ b = store.runDoc.branch,
117
+ pr = b && b.pr,
118
+ u = st(c),
119
+ all = steps(c),
120
+ next = all.find((x) => !x.why && x.a !== "draft"),
121
+ files = g.files.length,
122
+ target = b ? `origin/${b.base}` : `${g.remote}/${g.branch || "HEAD"}`;
123
+ if (u.msg === undefined) u.msg = commitMsg(store.runDoc.impl) || c.title || c.text || "";
124
+ const chip = pr
125
+ ? html`<a
126
+ class="gchip ${pr.state.toLowerCase()}${pr.draft ? " draft" : ""}"
127
+ href="${pr.url}"
128
+ target="_blank"
129
+ rel="noopener"
130
+ title="Open on GitHub"
131
+ ><svg><use href="#t-git" /></svg>#${pr.number}
132
+ ${pr.draft && pr.state === "OPEN" ? "Draft" : PR_WORD[pr.state] || pr.state}</a
133
+ >`
134
+ : b && b.checking
135
+ ? html`<span class="gchip dim">Checking PR…</span>`
136
+ : b && b.gh && !all.find((x) => x.a === "pr").why
137
+ ? html`<button class="gchip" data-a="pr">
138
+ <svg><use href="#t-git" /></svg>Create PR
139
+ </button>`
140
+ : "";
141
+ const k = store.runDoc.commit;
142
+ const empty = files
143
+ ? ""
144
+ : html`<div class="gempty">
145
+ <b
146
+ >${pr && pr.state === "MERGED" ? "Merged" : b && b.landed ? "On " + b.base : g.ahead > 0 && (!b || b.upstream) ? "Not pushed yet" : "No changes to commit"}</b
147
+ ><span
148
+ >${
149
+ pr && pr.state === "MERGED"
150
+ ? `Pull request #${pr.number} is merged into ${b.base}. The worktree and its branch can go.`
151
+ : b && b.landed
152
+ ? `Every commit of ${b.branch} is on ${b.base}. The worktree can go.`
153
+ : g.ahead > 0 && (!b || b.upstream)
154
+ ? `${g.ahead} commit${g.ahead === 1 ? "" : "s"} ahead of ${target}.`
155
+ : pr && pr.state === "OPEN"
156
+ ? `Pull request #${pr.number} is open against ${b.base}.`
157
+ : b && !b.upstream
158
+ ? `${b.branch} is not on GitHub yet. Create PR pushes it and opens the pull request.`
159
+ : `Up to date with ${target}.`
160
+ }</span
161
+ >${k && k.sha ? html`<span class="dim">Last commit <code>${k.sha}</code>${k.pushed ? " pushed" : " not pushed"}.</span>` : ""}
162
+ </div>`;
163
+ const changes = files
164
+ ? html`<div class="gsec">
165
+ <div class="ghd">Changes <span class="n">${files}</span></div>
166
+ <pre class="files">${g.files.join("\n")}</pre>
167
+ ${g.others ? html`<div class="dim">${g.others} other changed file${g.others === 1 ? " is" : "s are"} left alone: they are not this run's.</div>` : ""}${
168
+ g.shared && g.shared.length
169
+ ? html`<div class="dim">These files also hold other runs' changes, and a file is committed whole:</div>
170
+ <pre class="files">${g.shared.join("\n")}</pre>`
171
+ : ""
172
+ }<textarea id="gmsg" aria-label="Commit message" placeholder="feat(area): what changed">${u.msg}</textarea>
173
+ <div class="dim" id="glong" hidden>The first line is over 72 characters; logs will cut it short.</div>
174
+ </div>`
175
+ : "";
176
+ // The inline confirm or form the last click opened, in place of the split button.
177
+ const ask =
178
+ u.ask === "pr" || u.ask === "draft"
179
+ ? html`<div class="gsec gform">
180
+ <div class="ghd">${u.ask === "draft" ? "Draft pull request" : "Pull request"} into ${b.base}</div>
181
+ <input
182
+ id="gtitle"
183
+ aria-label="Title"
184
+ value="${u.title ?? (commitMsg(store.runDoc.impl) || c.title || "").split("\n")[0]}"
185
+ /><textarea id="gbody" aria-label="Description">${u.body ?? `Run ${c.id}.`}</textarea>
186
+ <div class="row">
187
+ <button class="btn ghost" data-a="cancel">Cancel</button
188
+ ><button class="btn pri" data-a="go-${u.ask}">
189
+ ${b.upstream && g.ahead === 0 ? "" : "Push & "}${u.ask === "draft" ? "create draft PR" : "create PR"}
190
+ </button>
191
+ </div>
192
+ </div>`
193
+ : u.ask === "merge"
194
+ ? html`<div class="gsec gform">
195
+ <div class="ghd">Merge #${pr.number} into ${b.base} by rebase?</div>
196
+ <div class="dim">The worktree stays until you remove it.</div>
197
+ <div class="row">
198
+ <button class="btn ghost" data-a="cancel">Cancel</button
199
+ ><button class="btn pri" data-a="go-merge">Merge PR</button>
200
+ </div>
201
+ </div>`
202
+ : u.ask === "remove"
203
+ ? html`<div class="gsec gform">
204
+ <div class="ghd">Remove the worktree and delete ${b.branch}?</div>
205
+ <div class="dim">Its work is on ${b.base}. The branch is deleted here and on GitHub.</div>
206
+ <div class="row">
207
+ <button class="btn ghost" data-a="cancel">Cancel</button
208
+ ><button class="btn danger" data-a="go-remove">Remove workspace</button>
209
+ </div>
210
+ </div>`
211
+ : "";
212
+ const menu = all
213
+ .map(
214
+ (x) =>
215
+ html`<button data-a="${x.a}" ${x.why ? " disabled" : ""}>
216
+ <span>${x.label}</span>${x.why ? html`<small>${x.why}</small>` : ""}
217
+ </button>`,
218
+ )
219
+ .concat(
220
+ pr
221
+ ? [
222
+ html`<hr />
223
+ <a href="${pr.url}" target="_blank" rel="noopener">Open PR on GitHub</a>`,
224
+ ]
225
+ : [],
226
+ );
227
+ const split = ask
228
+ ? ""
229
+ : html`<div class="split gsplit">
230
+ <button class="btn ${next ? "pri" : ""}" data-a="${next ? next.a : ""}" ${next ? "" : " disabled"}>
231
+ ${next ? next.label : "Up to date"}</button
232
+ ><button class="btn ${next ? "pri" : ""} gmore" aria-label="More git actions" aria-haspopup="menu">
233
+ <svg><use href="#i-chev" /></svg>
234
+ </button>
235
+ <div class="menu-pop" role="menu" hidden>${raw(menu.join(""))}</div>
236
+ </div>`;
237
+ body.innerHTML = html`<div class="gitp">
238
+ <div class="ghead">
239
+ ${chip}
240
+ <div class="gbr" title="${g.branch}">${b ? b.branch : g.branch || "HEAD"}</div>
241
+ <div class="gto">→ ${target}</div>
242
+ </div>
243
+ ${changes}${empty}${ask}${split}
244
+ </div>`;
245
+ wire(c, body.querySelector(".gitp"));
246
+ }
247
+
248
+ function wire(c, el) {
249
+ const u = st(c),
250
+ inp = el.querySelector("#gmsg");
251
+ if (inp) {
252
+ const fit = () => {
253
+ inp.style.height = "auto";
254
+ inp.style.height = Math.min(inp.scrollHeight + 2, innerHeight / 2) + "px";
255
+ $("glong").hidden = inp.value.split("\n")[0].length <= 72;
256
+ };
257
+ inp.oninput = () => {
258
+ u.msg = inp.value;
259
+ fit();
260
+ };
261
+ fit();
262
+ }
263
+ el.querySelector("#gtitle")?.addEventListener("input", (e) => (u.title = e.target.value));
264
+ el.querySelector("#gbody")?.addEventListener("input", (e) => (u.body = e.target.value));
265
+ const more = el.querySelector(".gmore"),
266
+ pop = el.querySelector(".gsplit .menu-pop");
267
+ if (more)
268
+ more.onclick = (e) => {
269
+ e.stopPropagation();
270
+ pop.hidden = !pop.hidden;
271
+ if (!pop.hidden) addEventListener("click", () => (pop.hidden = true), { once: true });
272
+ };
273
+ el.querySelectorAll("[data-a]").forEach((b) => {
274
+ if (!b.dataset.a) return;
275
+ b.onclick = () => act(c, b.dataset.a, b);
276
+ });
63
277
  }
64
- export async function commitPush(c, message, b) {
278
+
279
+ const BUSY = {
280
+ commit: "Pushing…",
281
+ push: "Pushing…",
282
+ "go-pr": "Creating PR…",
283
+ "go-draft": "Creating PR…",
284
+ "go-merge": "Merging…",
285
+ "go-remove": "Removing…",
286
+ };
287
+
288
+ async function act(c, a, b) {
289
+ const u = st(c);
290
+ if (a === "cancel") return ((u.ask = undefined), gitTab(c, false));
291
+ // Steps that need a second look open their form or confirm first.
292
+ if (a === "pr" || a === "draft" || a === "merge" || a === "remove") return ((u.ask = a), gitTab(c, false));
293
+ if (a === "commit" && !(u.msg || "").trim()) return toast("A commit message is required");
65
294
  b.disabled = true;
66
295
  b.dataset.busy = 1;
67
- b.textContent = "Pushing…";
68
- const r = await post("/commit", { dir: c.state, id: c.id, message, files: store.runDoc.git.files });
69
- if (r.ok) toast("Committed & pushed " + r.sha);
70
- $("pfoot").innerHTML = "";
296
+ b.textContent = BUSY[a] || "Working…";
297
+ const base = { dir: c.state, id: c.id };
298
+ const r =
299
+ a === "commit" || a === "push"
300
+ ? await post("/commit", { ...base, message: a === "commit" ? u.msg : "", files: store.runDoc.git.files })
301
+ : a === "go-pr" || a === "go-draft"
302
+ ? await post("/pr", {
303
+ ...base,
304
+ op: "create",
305
+ title: u.title ?? $("gtitle").value,
306
+ body: u.body ?? $("gbody").value,
307
+ draft: a === "go-draft",
308
+ })
309
+ : await post("/pr", { ...base, op: a === "go-merge" ? "merge" : "remove" });
310
+ if (r.ok) {
311
+ toast(
312
+ a === "commit" || a === "push"
313
+ ? "Committed & pushed " + r.sha
314
+ : a === "go-merge"
315
+ ? "Merged"
316
+ : a === "go-remove"
317
+ ? "Worktree removed"
318
+ : "Pull request #" + r.pr.number + " opened",
319
+ );
320
+ ui.delete(key(c));
321
+ }
71
322
  if (store.openKey !== key(c)) return;
323
+ delete b.dataset.busy;
72
324
  await openRun(c, false);
73
- // A refused message comes back for another try, beside the current file list.
74
- if (!r.ok && message && store.openKey === key(c) && store.runDoc.git.files && store.runDoc.git.files.length)
75
- confirmCommit(c, message);
76
325
  }
package/web/board/home.ts CHANGED
@@ -279,10 +279,14 @@ async function show(id) {
279
279
  if (c.error) return toast(c.error);
280
280
  if (cur?.id !== c.id) attachments = [];
281
281
  const same = cur?.id === c.id && cur.messages.length === c.messages.length && !!$("hlog");
282
+ // The list's busy dot is from the last /chats: a turn that ended since redraws it.
283
+ const listed = chats.find((x) => x.id === c.id);
284
+ const ended = listed && listed.busy && !c.busy;
285
+ if (listed) listed.busy = !!c.busy;
282
286
  cur = c;
283
287
  remoteBusy = !!c.busy;
284
288
  remember(c.id);
285
- if (same) { updateReply(c.messages.at(-1)); syncSendButton(); }
289
+ if (same && !ended) { updateReply(c.messages.at(-1)); syncSendButton(); }
286
290
  else draw();
287
291
  follow(c.project);
288
292
  // A turn started from another tab, or before a reload, is still running: follow it until it saves.
@@ -389,6 +393,8 @@ export async function openHome() {
389
393
  if (pending) id = chats.find((c) => c.updated >= pending)?.id;
390
394
  } catch (e) {}
391
395
  }
396
+ // A new tab has no chat of its own yet: a chat still working is the one to follow.
397
+ if (!id) id = chats.find((c) => c.busy)?.id;
392
398
  if (id && chats.some((c) => c.id === id)) await show(id);
393
399
  else { remember(null); draw(); }
394
400
  }
@@ -6,6 +6,8 @@ import { store } from "./store.ts";
6
6
  import { $, html, ico, raw } from "./dom.ts";
7
7
  import { age, NAMES } from "./labels.ts";
8
8
  import { key, runPopup } from "./cards.ts";
9
+ import { load, post } from "./api.ts";
10
+ import { toast } from "./toast.ts";
9
11
  import { openWorkspace } from "./run-view.ts";
10
12
  import { open } from "./panel.ts";
11
13
  import { refreshBoardBadge } from "./badge.ts";
@@ -86,12 +88,13 @@ function draw() {
86
88
  html`${[["ideas", "Ideas 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>`)}`,
87
89
  )
88
90
  : "";
89
- const extra = html`<span class="iseg">${seg("open", "Open")}${seg("running", "Running")}${seg("done", "Done")}</span>${sortPop}${sources}<button class="ib" id="ideas-ref" title="Refresh" aria-label="Refresh">${ico("refresh")}</button>`;
91
+ // Scope and filters first; search, refresh and New idea sit at the right (CSS order).
92
+ const extra = html`${sources}<span class="iseg">${seg("open", "Open")}${seg("running", "Running")}${seg("done", "Done")}</span>${sortPop}<button class="ib" id="ideas-ref" title="Refresh" aria-label="Refresh">${ico("refresh")}</button>`;
90
93
  const table = 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) => {
91
94
  const name = nameOf(c.state, projects),
92
95
  st = stateOf(c),
93
96
  agent = (c.tags ?? []).find((t) => AGENTS.includes(t));
94
- 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><button class="go" data-i="${i}">${c.kind === "idea" ? "Start" : "Open"} ${ico("arrow")}</button></td></tr>`;
97
+ 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 idea" aria-label="Delete idea">${ico("trash")}</button>` : ""}<button class="go" data-i="${i}">${c.kind === "idea" ? "Start" : "Open"} ${ico("arrow")}</button>`}</div></td></tr>`;
95
98
  })}</tbody></table>${rows.length ? "" : html`<p class="none">Nothing matches.</p>`}`;
96
99
  const hx = $("hx");
97
100
  // Not while a pop-up in it is open: redrawing would close it under the pointer.
@@ -113,7 +116,12 @@ function draw() {
113
116
  hx.querySelectorAll<HTMLElement>("[data-show]").forEach((b) => (b.onclick = () => ((f.show = b.dataset.show!), (hx.innerHTML = ""), draw())));
114
117
  $("ideas-ref").onclick = () => (void drawSources(true), void refreshBoardBadge());
115
118
  box.querySelectorAll<HTMLElement>("button.go").forEach((b) => (b.onclick = () => act(rows[+b.dataset.i!])));
116
- box.querySelectorAll<HTMLElement>("tbody tr").forEach((tr, i) => (tr.onclick = (e) => !(e.target as Element).closest("button") && detail(rows[i])));
119
+ // The trash icon asks in its own row, as the board's card menu does; a redraw keeps the question.
120
+ box.querySelectorAll<HTMLElement>("button.del").forEach((b) => (b.onclick = () => ((asking = key(rows[+b.dataset.i!])), draw())));
121
+ box.querySelectorAll<HTMLElement>("[data-keep]").forEach((b) => (b.onclick = () => ((asking = null), draw())));
122
+ box.querySelectorAll<HTMLElement>("[data-yes]").forEach((b) => (b.onclick = () => del(rows[+b.dataset.yes!])));
123
+ // A click moves the highlight to its row too: it marks the keyboard's row, not the panel's.
124
+ box.querySelectorAll<HTMLElement>("tbody tr").forEach((tr, i) => (tr.onclick = (e) => !(e.target as Element).closest("button") && ((sel = i), mark(), detail(rows[i]))));
117
125
  shownRows = rows;
118
126
  sel = Math.max(0, Math.min(sel, rows.length - 1));
119
127
  mark();
@@ -131,6 +139,15 @@ function act(c) {
131
139
  runPopup(here);
132
140
  }
133
141
 
142
+ // An idea is deleted as the board's card menu does it, not recorded anywhere.
143
+ let asking: string | null = null;
144
+ async function del(c) {
145
+ asking = null;
146
+ const r = await post("/inbox", { op: "delete", dir: c.state, text: c.text });
147
+ if (r.ok) toast("Deleted");
148
+ load();
149
+ }
150
+
134
151
  // A row's own click: the card's detail panel over this page. Another project's card goes
135
152
  // through the board's deep link, which opens the same panel there.
136
153
  function detail(c) {
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))(new URLSearchParams(location.search).get("view"));
36
+ const v0 = ((v) => (v === "icebox" ? "sources" : v === "ws" ? "run" : 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(); });
package/web/board/main.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  // tick that reloads the board. See design.md for the visual rules.
7
7
  import { initPanel } from "./panel.ts";
8
8
  import { initViews } from "./views.ts";
9
- import { initProjects } from "./projects.ts";
9
+ import { initProjects, pick } from "./projects.ts";
10
10
  import { initUpdate } from "./update.ts";
11
11
  import { initKeys } from "./keys.ts";
12
12
  import { filterBox, statusSheet } from "./cards.ts";
@@ -14,10 +14,9 @@ import { initLive } from "./live.ts";
14
14
  import { store } from "./store.ts";
15
15
  import { initViewer } from "./viewer.ts";
16
16
  import { initContext } from "./context.ts";
17
- import { initFooter, initRail } from "./workspace.ts";
17
+ import { cardHref, initFooter, initRail, markCurrent, wsHref } from "./workspace.ts";
18
18
  import { go } from "./views.ts";
19
19
  import { openWorkspace } from "./run-view.ts";
20
- import { newIdea } from "./cards.ts";
21
20
 
22
21
  initPanel();
23
22
  initViews();
@@ -32,17 +31,35 @@ statusSheet();
32
31
  initRail();
33
32
  initFooter(() => go("terminal", true));
34
33
  // The rail's rows and + open a card or the new-idea form here, on the board, when it has them.
34
+ // A row of another project than the one picked switches the board to that project first.
35
35
  addEventListener("kz-open-card", (e: any) => {
36
36
  const { dir, id, text } = e.detail;
37
- const c = store.S.cards.find((x) => x.state === dir && (id ? x.kind === "run" && x.id === id : x.kind === "idea" && x.text === text));
38
- if (!c) return;
37
+ const find = () =>
38
+ store.S.cards.find(
39
+ (x) => x.state === dir && (id ? x.kind === "run" && x.id === id : x.kind === "idea" && x.text === text),
40
+ );
41
+ const c = find();
42
+ if (c) {
43
+ e.preventDefault();
44
+ return openWorkspace(c);
45
+ }
46
+ if (!dir || dir === store.dir) return;
39
47
  e.preventDefault();
40
- openWorkspace(c);
48
+ const href = cardHref({ state: dir, kind: id ? "run" : "idea", id, text });
49
+ pick(dir)
50
+ .then(() => {
51
+ const c = find();
52
+ if (c) openWorkspace(c);
53
+ else location.href = href;
54
+ })
55
+ .catch(() => (location.href = href));
41
56
  });
42
- addEventListener("kz-new-idea", (e) => {
43
- // A modal over whatever page is showing: the idea appears in the menu and Ideas by the usual refresh.
57
+ // A workspace row opens in place: the run view resolves it (showRunView).
58
+ addEventListener("kz-open-ws", (e: any) => {
44
59
  e.preventDefault();
45
- newIdea({ dir: e.detail?.dir ?? null });
60
+ history.pushState(null, "", wsHref(e.detail.dir, e.detail.ws));
61
+ markCurrent();
62
+ go("ws");
46
63
  });
47
64
 
48
65
  // One popup at a time: a press anywhere first shuts every open popup it is not inside,