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.
- package/cli/add-project.test.ts +169 -0
- package/cli/add-project.ts +132 -0
- package/cli/board.test.ts +15 -0
- package/cli/chat.ts +1 -1
- package/cli/dashboard.ts +6 -2
- package/cli/install.test.ts +1 -1
- package/cli/install.ts +18 -9
- package/cli/pty.test.ts +89 -5
- package/cli/pty.ts +126 -9
- package/cli/restart.test.ts +169 -0
- package/cli/settings.test.ts +35 -0
- package/cli/settings.ts +69 -18
- package/cli/state.test.ts +119 -3
- package/cli/state.ts +171 -13
- package/cli/usage.test.ts +130 -1
- package/cli/web-accept.test.ts +54 -0
- package/cli/web-pr.test.ts +51 -0
- package/cli/web-symlink.test.ts +28 -0
- package/cli/web.ts +349 -100
- package/cli/worktree.test.ts +146 -1
- package/cli/worktree.ts +214 -4
- package/cli/writeback.ts +1 -1
- package/package.json +1 -1
- package/skills/kaizen/SKILL.md +5 -1
- package/skills/kaizen/config.default.yml +15 -2
- package/skills/kaizen/settings.md +1 -0
- package/skills/kaizen/spec-main.md +28 -2
- package/skills/kaizen-help/SKILL.md +1 -0
- package/web/board/add-project.ts +136 -0
- package/web/board/api.ts +1 -1
- package/web/board/badge.ts +5 -5
- package/web/board/cards.ts +11 -3
- package/web/board/context.ts +1 -0
- package/web/board/fixes.ts +3 -2
- package/web/board/git.ts +309 -60
- package/web/board/home.ts +7 -1
- package/web/board/ideas.ts +20 -3
- package/web/board/live.ts +1 -1
- package/web/board/main.ts +26 -9
- package/web/board/panel.ts +31 -16
- package/web/board/projects.ts +6 -85
- package/web/board/run-pick.ts +41 -0
- package/web/board/run-view.ts +286 -110
- package/web/board/search-match.ts +20 -0
- package/web/board/search.test.ts +20 -0
- package/web/board/search.ts +324 -0
- package/web/board/settings.ts +42 -5
- package/web/board/store.ts +3 -1
- package/web/board/toast.ts +4 -1
- package/web/board/views.ts +3 -1
- package/web/board/workspace.ts +127 -38
- package/web/board/ws-board-ui.ts +95 -0
- package/web/board/ws-board.test.ts +71 -0
- package/web/board/ws-board.ts +45 -0
- package/web/board/ws-tabs.test.ts +181 -0
- package/web/board/ws-tabs.ts +173 -0
- package/web/board.html +86 -36
- package/web/board.js +129 -44
- package/web/notebook.js +41 -24
- package/web/notes.html +26 -20
- package/web/term.js +1 -1
- package/web/video.html +26 -20
- package/web/video.js +76 -59
package/web/board/workspace.ts
CHANGED
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
// bundles can carry it without the board.
|
|
5
5
|
import { onBoardCards } from "./badge.ts";
|
|
6
6
|
import { store } from "./store.ts";
|
|
7
|
-
import { $, html, raw } from "./dom.ts";
|
|
7
|
+
import { $, html, modal, raw } from "./dom.ts";
|
|
8
8
|
import { age, need } from "./labels.ts";
|
|
9
|
+
import { openAdd } from "./add-project.ts";
|
|
10
|
+
import { initSearch } from "./search.ts";
|
|
11
|
+
import { agentsHtml, dueWord, forgetAgents, gitDue, settleIn, toggleOpen, wsAgents, type Agent } from "./ws-tabs.ts";
|
|
9
12
|
|
|
10
13
|
const DAY = 864e5;
|
|
11
14
|
const STAGE = ["idea", "planning", "building", "reviewing", "done"];
|
|
@@ -14,7 +17,7 @@ export function stateOf(c) {
|
|
|
14
17
|
// An idea whose agent is working is a run being born: show it as planning.
|
|
15
18
|
if (c.kind === "idea") return !c.pty?.alive ? "idle" : c.pty.asking ? "wait" : c.pty.busy ? "plan" : "idle";
|
|
16
19
|
if (c.status === "waiting" || (c.pty?.alive && c.pty.asking)) return "wait";
|
|
17
|
-
if (c.status === "done") return "done";
|
|
20
|
+
if (c.status === "done") return c.accept === "needs" || gitDue(c) ? "wait" : "done";
|
|
18
21
|
if (c.status === "abandoned") return "aband";
|
|
19
22
|
if (c.status === "stalled") return "stalled";
|
|
20
23
|
return c.column >= 3 ? "review" : c.column === 2 ? "build" : "plan";
|
|
@@ -24,6 +27,9 @@ export function subline(c, now) {
|
|
|
24
27
|
if (c.kind === "idea") return !c.pty?.alive ? "idea" : c.pty.asking ? "waiting on you" : c.pty.busy ? "planning · starting" : "agent · open";
|
|
25
28
|
const t = c.moved ?? now;
|
|
26
29
|
if (c.status === "waiting") return c.awaiting ? `${STAGE[c.column] ?? "waiting"} · ${need(c.awaiting)}` : "waiting on you";
|
|
30
|
+
if (c.accept === "needs") return "done, not approved";
|
|
31
|
+
if (gitDue(c)) return `waiting on you · ${dueWord(c)}`;
|
|
32
|
+
if (c.accept === "auto") return `auto-accepted · ${age(t, now)} ago`;
|
|
27
33
|
if (c.status === "done" || c.status === "abandoned") return `${c.status} · ${age(t, now)} ago`;
|
|
28
34
|
if (c.status === "stalled") return `stalled · ${age(t, now)}`;
|
|
29
35
|
return `${STAGE[c.column] ?? c.status} · ${age(t, now)}`;
|
|
@@ -33,7 +39,7 @@ export const titleOf = (c) => (c.title || c.text || "").split("\n")[0];
|
|
|
33
39
|
// live on the Ideas page; one whose agent is starting (it has a terminal) shows here.
|
|
34
40
|
export const listed = (c, now) =>
|
|
35
41
|
!c.archived && (c.kind === "idea" ? !!c.pty : !["done", "abandoned"].includes(c.status) || now - (c.moved ?? 0) < DAY);
|
|
36
|
-
const projName = (dir, projects) => {
|
|
42
|
+
export const projName = (dir, projects) => {
|
|
37
43
|
const l = projects?.find((p) => p.dir === dir)?.label || dir.replace(/[\\/]\.kaizen$/, "");
|
|
38
44
|
return l.split(/[\\/]/).pop() || l;
|
|
39
45
|
};
|
|
@@ -66,7 +72,10 @@ const kindOf = (c) => {
|
|
|
66
72
|
const st = stateOf(c);
|
|
67
73
|
return st === "done" || st === "aband" ? "done" : "active";
|
|
68
74
|
};
|
|
69
|
-
let last: { cards: any[]; projects?: any[] } = { cards: [] };
|
|
75
|
+
let last: { cards: any[]; projects?: any[]; agents?: Agent[] } = { cards: [] };
|
|
76
|
+
// Projects that are git repositories (the main checkout has a branch): where a workspace can be made.
|
|
77
|
+
export const gitProjects = () =>
|
|
78
|
+
(last.projects ?? []).filter((p) => p.workspaces?.some((w) => w.branch)).map((p) => ({ dir: p.dir as string, name: projName(p.dir, last.projects) }));
|
|
70
79
|
// Project groups folded shut in the side menu, kept per browser.
|
|
71
80
|
const folded: Set<string> = (() => {
|
|
72
81
|
try {
|
|
@@ -75,6 +84,21 @@ const folded: Set<string> = (() => {
|
|
|
75
84
|
return new Set();
|
|
76
85
|
}
|
|
77
86
|
})();
|
|
87
|
+
// Workspace cards with their agent list open (dir\0ws -> true), kept per browser.
|
|
88
|
+
const wsOpen: Record<string, true> = (() => {
|
|
89
|
+
try {
|
|
90
|
+
return JSON.parse(localStorage.getItem("kz-wsopen") || "{}");
|
|
91
|
+
} catch {
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
})();
|
|
95
|
+
function toggleList(dir: string, ws: string) {
|
|
96
|
+
toggleOpen(wsOpen, dir, ws);
|
|
97
|
+
try {
|
|
98
|
+
localStorage.setItem("kz-wsopen", JSON.stringify(wsOpen));
|
|
99
|
+
} catch {}
|
|
100
|
+
drawList();
|
|
101
|
+
}
|
|
78
102
|
function fold(dir: string) {
|
|
79
103
|
folded.has(dir) ? folded.delete(dir) : folded.add(dir);
|
|
80
104
|
try {
|
|
@@ -82,55 +106,103 @@ function fold(dir: string) {
|
|
|
82
106
|
} catch {}
|
|
83
107
|
drawList();
|
|
84
108
|
}
|
|
109
|
+
// A card's workspace row: its own (a run's worktree) when the project lists it, else the
|
|
110
|
+
// main checkout's, so a run whose worktree is gone, an idea or an old run never vanishes.
|
|
111
|
+
export function wsOfCard(c, projects = last.projects) {
|
|
112
|
+
const ws = projects?.find((p) => p.dir === c.state)?.workspaces ?? [];
|
|
113
|
+
return ws.find((w) => w.path === c.ws)?.path ?? ws.find((w) => w.main)?.path ?? c.ws ?? "";
|
|
114
|
+
}
|
|
115
|
+
export const wsHref = (dir, ws) => `/?view=ws&dir=${encodeURIComponent(dir)}&ws=${encodeURIComponent(ws)}`;
|
|
116
|
+
export const RANK = { wait: 0, plan: 1, build: 2, review: 3, stalled: 4, idle: 5, done: 6, aband: 7 };
|
|
117
|
+
export const folderOf = (w) => w.path.split(/[\\/]/).pop() || w.path;
|
|
118
|
+
// A worktree's mark on line 2 of its card.
|
|
119
|
+
const WT = html`<svg viewBox="0 0 24 24" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="6" cy="6" r="2"/><circle cx="6" cy="18" r="2"/><circle cx="18" cy="8" r="2"/><path d="M6 8v8M18 10c0 4-6 3-12 6"/></g></svg>`;
|
|
120
|
+
let settleT: ReturnType<typeof setTimeout> | undefined;
|
|
121
|
+
let drawn = "";
|
|
122
|
+
export const wsLabel = (w) => w.branch || (w.main ? "workspace" : w.path.split(/[\\/]/).pop());
|
|
85
123
|
function drawList() {
|
|
86
124
|
const box = $("plist");
|
|
87
125
|
if (!box) return;
|
|
88
126
|
const now = Date.now();
|
|
89
|
-
const
|
|
90
|
-
const all = new Set(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
127
|
+
const projects = (last.projects ?? []).filter((p) => p.workspaces?.length);
|
|
128
|
+
const all = new Set(projects.map((p) => p.dir));
|
|
129
|
+
// Cards by project and workspace: each lands on a row, the main checkout when its own is not listed.
|
|
130
|
+
const by = new Map<string, any[]>();
|
|
131
|
+
for (const c of last.cards.filter((c) => listed(c, now))) {
|
|
132
|
+
const k = c.state + "\0" + wsOfCard(c);
|
|
133
|
+
if (!by.has(k)) by.set(k, []);
|
|
134
|
+
by.get(k)!.push(c);
|
|
94
135
|
}
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
136
|
+
const top = (cs) => (cs.length ? Math.min(...cs.map((c) => RANK[stateOf(c)])) : 9);
|
|
137
|
+
const groups = projects
|
|
138
|
+
.filter((p) => !filt.dirs.length || filt.dirs.includes(p.dir))
|
|
139
|
+
.map((p) => {
|
|
140
|
+
const rows = p.workspaces
|
|
141
|
+
.map((w) => ({ w, cs: by.get(p.dir + "\0" + w.path) ?? [] }))
|
|
142
|
+
// An empty workspace or one with a run going is active; one holding only finished runs is done.
|
|
143
|
+
.filter(({ cs }) => filt[cs.length && cs.every((c) => kindOf(c) === "done") ? "done" : "active"]);
|
|
144
|
+
return { p, rows, top: Math.min(9, ...rows.map((r) => top(r.cs))) };
|
|
145
|
+
})
|
|
146
|
+
.filter((g) => g.rows.length)
|
|
147
|
+
// Projects by their most urgent card; the picker's order otherwise.
|
|
148
|
+
.sort((a, b) => a.top - b.top);
|
|
104
149
|
|
|
105
150
|
const f = $("pfilter");
|
|
106
151
|
const on = filt.dirs.some((d) => all.has(d)) || !filt.active || !filt.done;
|
|
107
152
|
f.setAttribute("aria-pressed", String(on));
|
|
108
153
|
f.title = on ? "Filter on: choose projects and kinds" : "Filter projects and kinds";
|
|
109
154
|
if ($("pfpop")) drawPop(all);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
155
|
+
// Agents are read from this tick's payload; one held at "working" through the 3 s settle redraws when it ends.
|
|
156
|
+
forgetAgents(last.agents ?? []);
|
|
157
|
+
clearTimeout(settleT);
|
|
158
|
+
const wait = settleIn(last.agents ?? [], now);
|
|
159
|
+
if (wait < Infinity) settleT = setTimeout(drawList, wait + 20);
|
|
160
|
+
const out =
|
|
161
|
+
groups
|
|
162
|
+
.map(({ p, rows }) => {
|
|
163
|
+
const dir = p.dir,
|
|
164
|
+
name = projName(dir, last.projects),
|
|
165
|
+
shut = folded.has(dir);
|
|
166
|
+
// A + for a new worktree on git projects (the main checkout has a branch).
|
|
167
|
+
const git = p.workspaces.some((w) => w.branch);
|
|
168
|
+
return html`<div class="pgrp"><button type="button" class="proj${shut ? " shut" : ""}" data-fold="${dir}" title="${dir}" aria-expanded="${String(!shut)}">${logo(dir, name, last.projects)}<span class="pname">${name}</span><svg class="fchev" viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>${git ? html`<button type="button" class="wadd" data-wadd="${dir}" title="New workspace in ${name}" aria-label="New workspace in ${name}"><svg aria-hidden="true"><use href="#i-plus"/></svg></button>` : ""}</div>${shut ? "" : rows.map(({ w, cs }) => {
|
|
169
|
+
// The dot: the most urgent run there, or an agent asking (amber) or working (spinner).
|
|
170
|
+
const rows = wsAgents(last.agents ?? [], dir, w.path, wsOfCard, now);
|
|
171
|
+
const st0 = cs.length ? stateOf([...cs].sort((a, b) => RANK[stateOf(a)] - RANK[stateOf(b)])[0]) : "";
|
|
172
|
+
const st = st0 === "wait" || rows[0]?.st === "asking" ? "wait" : rows.some((r) => r.st === "working") ? "build" : st0 || (rows.length ? "done" : "");
|
|
173
|
+
// The agent buttons are siblings of the link (a button inside a link is invalid).
|
|
174
|
+
return html`<div class="wsr wsc"><a class="row ws" href="${wsHref(dir, w.path)}" data-dir="${dir}" data-ws="${w.path}" title="${w.path}"><span class="si ${st || "none"}"></span><div class="wl"><span class="l1"><b>${wsLabel(w)}</b></span><span class="l2"><span>${folderOf(w)}</span>${w.main ? "" : WT}</span></div></a>${agentsHtml(rows, now, !!wsOpen[dir + "\0" + w.path], dir, w.path)}</div>`;
|
|
175
|
+
})}`;
|
|
120
176
|
})
|
|
121
|
-
.join("") || `<div class="none">No
|
|
177
|
+
.join("") || `<div class="none">No projects</div>`;
|
|
178
|
+
// The same markup is not written again: hover and focus stay, and a tick that changed nothing costs no layout.
|
|
179
|
+
if (out !== drawn) box.innerHTML = drawn = out;
|
|
180
|
+
markCurrent();
|
|
122
181
|
box.onclick = (e) => {
|
|
123
|
-
const
|
|
182
|
+
const t = e.target as HTMLElement;
|
|
183
|
+
const term = t.closest<HTMLElement>("[data-term]");
|
|
184
|
+
if (term) return void (e.preventDefault(), openTerm(term.dataset.dir!, term.dataset.ws!, term.dataset.term!));
|
|
185
|
+
const tog = t.closest<HTMLElement>("[data-wopen]");
|
|
186
|
+
if (tog) return void (e.preventDefault(), toggleList(tog.dataset.dir!, tog.dataset.ws!));
|
|
187
|
+
const add = t.closest<HTMLElement>("[data-wadd]")?.dataset.wadd;
|
|
188
|
+
if (add) return void (e.preventDefault(), openAdd({ dir: add, start: "ws" }));
|
|
189
|
+
const d = t.closest<HTMLElement>("[data-fold]")?.dataset.fold;
|
|
124
190
|
if (d) (e.preventDefault(), fold(d));
|
|
125
191
|
};
|
|
126
192
|
}
|
|
193
|
+
// An agent's mark: the board opens that terminal tab in its workspace; the notebook and video pages open the workspace.
|
|
194
|
+
const openTerm = (dir: string, ws: string, key: string) => {
|
|
195
|
+
if (!ask("kz-open-term", { dir, ws, key })) location.href = wsHref(dir, ws);
|
|
196
|
+
};
|
|
127
197
|
// Moves the side menu's highlight to the card the address names: opening a card in place
|
|
128
198
|
// changes the address without redrawing the list.
|
|
129
199
|
export function markCurrent() {
|
|
130
200
|
const cur = new URLSearchParams(location.search);
|
|
201
|
+
// A run's address (old links, notifications) lights its workspace.
|
|
202
|
+
const c = cur.get("id") && last.cards.find((x) => x.kind === "run" && x.state === cur.get("dir") && x.id === cur.get("id"));
|
|
203
|
+
const ws = cur.get("ws") ?? (c ? wsOfCard(c) : null);
|
|
131
204
|
for (const a of document.querySelectorAll<HTMLElement>("#plist a.row")) {
|
|
132
|
-
|
|
133
|
-
if (on) a.setAttribute("aria-current", "true");
|
|
205
|
+
if (cur.get("dir") === a.dataset.dir && ws === a.dataset.ws) a.setAttribute("aria-current", "true");
|
|
134
206
|
else a.removeAttribute("aria-current");
|
|
135
207
|
}
|
|
136
208
|
}
|
|
@@ -206,10 +278,28 @@ function closePop() {
|
|
|
206
278
|
$("pfilter").setAttribute("aria-expanded", "false");
|
|
207
279
|
}
|
|
208
280
|
|
|
281
|
+
// Rows are redrawn on every refresh, which restarts a CSS animation from 0deg: the state
|
|
282
|
+
// icons jumped back mid-turn. Pinning each to the page clock's origin keeps them in phase
|
|
283
|
+
// (the si-* animations have no delay for this to cancel).
|
|
284
|
+
const syncSpin = () =>
|
|
285
|
+
document.getAnimations().forEach((a: any) => {
|
|
286
|
+
if (a.animationName?.startsWith("si-") && a.startTime !== 0) a.startTime = 0;
|
|
287
|
+
});
|
|
209
288
|
export function initRail() {
|
|
289
|
+
initSearch();
|
|
290
|
+
let queued = false;
|
|
291
|
+
const hasSi = (n: any) => n.nodeType === 1 && (n.classList.contains("si") || n.querySelector(".si"));
|
|
292
|
+
new MutationObserver((rs) => {
|
|
293
|
+
if (queued || !rs.some((r) => [...r.addedNodes].some(hasSi))) return;
|
|
294
|
+
queued = true;
|
|
295
|
+
requestAnimationFrame(() => {
|
|
296
|
+
queued = false;
|
|
297
|
+
syncSpin();
|
|
298
|
+
});
|
|
299
|
+
}).observe(document.body, { childList: true, subtree: true });
|
|
210
300
|
if (!$("plist")) return;
|
|
211
|
-
onBoardCards((cards, projects) => {
|
|
212
|
-
last = { cards, projects: projects ?? last.projects };
|
|
301
|
+
onBoardCards((cards, projects, agents) => {
|
|
302
|
+
last = { cards, projects: projects ?? last.projects, agents: agents ?? [] };
|
|
213
303
|
drawList();
|
|
214
304
|
void drawSources();
|
|
215
305
|
onCount?.(cards);
|
|
@@ -242,16 +332,15 @@ export function initRail() {
|
|
|
242
332
|
$("pfilter").focus();
|
|
243
333
|
}
|
|
244
334
|
});
|
|
335
|
+
// The sheet: add a folder, clone, create, or start a workspace; the current project is preselected.
|
|
245
336
|
$("padd").onclick = () => {
|
|
246
|
-
// The page's own project when it has one: the run workspace's, or the one project the filter shows.
|
|
247
337
|
const p = new URLSearchParams(location.search);
|
|
248
|
-
|
|
249
|
-
if (!ask("kz-new-idea", { dir })) location.href = "/?view=board";
|
|
338
|
+
openAdd({ dir: ["run", "ws"].includes(p.get("view")) ? p.get("dir") : filt.dirs.length === 1 ? filt.dirs[0] : null });
|
|
250
339
|
};
|
|
251
340
|
$("plist").addEventListener("click", (e) => {
|
|
252
341
|
const a = (e.target as Element).closest?.("a.row") as HTMLAnchorElement;
|
|
253
342
|
if (!a || e.ctrlKey || e.metaKey || e.shiftKey || (e as MouseEvent).button) return;
|
|
254
|
-
if (ask("kz-open-
|
|
343
|
+
if (ask("kz-open-ws", { dir: a.dataset.dir, ws: a.dataset.ws })) e.preventDefault();
|
|
255
344
|
});
|
|
256
345
|
}
|
|
257
346
|
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// The Board page's Workspaces mode: four columns of workspace cards (ws-board.ts places
|
|
2
|
+
// them) drawn into #board, and the Workspaces | Runs switch in the header.
|
|
3
|
+
import { store } from "./store.ts";
|
|
4
|
+
import { $, html } from "./dom.ts";
|
|
5
|
+
import { RANK, logo, projName, railData, stateOf, subline, titleOf, wsHref, wsLabel, wsOfCard } from "./workspace.ts";
|
|
6
|
+
import { WS_COLS, cardLine, columnOf, groupWs } from "./ws-board.ts";
|
|
7
|
+
|
|
8
|
+
const KEY = "kz-board-mode";
|
|
9
|
+
export const boardMode = (): "ws" | "runs" => {
|
|
10
|
+
try {
|
|
11
|
+
return localStorage.getItem(KEY) === "runs" ? "runs" : "ws";
|
|
12
|
+
} catch {
|
|
13
|
+
return "ws";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
let rerender = () => {};
|
|
17
|
+
// The body class and the search box's hint follow the mode (not on other pages, which own them).
|
|
18
|
+
export function syncMode() {
|
|
19
|
+
const ws = boardMode() === "ws";
|
|
20
|
+
document.body.classList.toggle("wsb", ws);
|
|
21
|
+
if (!document.body.classList.contains("paged")) $("bq").placeholder = ws ? "Search workspaces (press /)" : "Filter cards (press /)";
|
|
22
|
+
}
|
|
23
|
+
function drawToggle() {
|
|
24
|
+
const hx = $("hx");
|
|
25
|
+
if (document.body.classList.contains("paged") || !hx) return;
|
|
26
|
+
const m = boardMode();
|
|
27
|
+
hx.innerHTML = String(
|
|
28
|
+
html`<span class="bar" id="bmode" role="group" aria-label="Board mode"><button data-m="ws" class="${m === "ws" ? "on" : ""}" aria-pressed="${m === "ws"}">Workspaces</button><button data-m="runs" class="${m === "runs" ? "on" : ""}" aria-pressed="${m === "runs"}">Runs</button></span>`,
|
|
29
|
+
);
|
|
30
|
+
hx.querySelectorAll<HTMLElement>("[data-m]").forEach(
|
|
31
|
+
(b) =>
|
|
32
|
+
(b.onclick = () => {
|
|
33
|
+
try {
|
|
34
|
+
localStorage.setItem(KEY, b.dataset.m!);
|
|
35
|
+
} catch {}
|
|
36
|
+
syncMode();
|
|
37
|
+
drawToggle();
|
|
38
|
+
rerender();
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
export function initWsBoard(render: () => void) {
|
|
43
|
+
rerender = render;
|
|
44
|
+
addEventListener("kz-view", () => (syncMode(), drawToggle()));
|
|
45
|
+
addEventListener("kz-state", drawToggle);
|
|
46
|
+
// A render publishes the cards, which raises kz-rail at once: that one is its own echo, not
|
|
47
|
+
// news, and answering it rendered again forever. Fresh rail data (a fetch) still redraws.
|
|
48
|
+
let drawing = false;
|
|
49
|
+
addEventListener("kz-rail", () => {
|
|
50
|
+
if (drawing || boardMode() !== "ws" || document.body.classList.contains("paged")) return;
|
|
51
|
+
drawing = true;
|
|
52
|
+
try {
|
|
53
|
+
render();
|
|
54
|
+
} finally {
|
|
55
|
+
drawing = false;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
$("board").addEventListener("click", (e: MouseEvent) => {
|
|
59
|
+
const a = (e.target as Element).closest?.("a.wcard") as HTMLAnchorElement;
|
|
60
|
+
if (!a || e.ctrlKey || e.metaKey || e.shiftKey || e.button) return;
|
|
61
|
+
if (!dispatchEvent(new CustomEvent("kz-open-ws", { cancelable: true, detail: { dir: a.dataset.dir, ws: a.dataset.ws } }))) e.preventDefault();
|
|
62
|
+
});
|
|
63
|
+
syncMode();
|
|
64
|
+
drawToggle();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// `inScope(dir)` is the board's project scope (single project, or the Showing filter).
|
|
68
|
+
export function drawWsBoard(inScope: (dir: string) => boolean) {
|
|
69
|
+
const b = $("board"),
|
|
70
|
+
now = store.S.now || Date.now(),
|
|
71
|
+
{ cards, projects } = railData(),
|
|
72
|
+
q = ($("bq").value || "").trim().toLowerCase();
|
|
73
|
+
syncMode();
|
|
74
|
+
b.removeAttribute("aria-busy");
|
|
75
|
+
const cols: string[][] = WS_COLS.map(() => []);
|
|
76
|
+
for (const { dir, w, cs } of groupWs(cards, projects, wsOfCard)) {
|
|
77
|
+
const name = projName(dir, projects);
|
|
78
|
+
const { col, open, last } = columnOf(cs, dir, w.path, wsOfCard, stateOf);
|
|
79
|
+
// Neither the project filter nor search hides a workspace waiting on the user (In review).
|
|
80
|
+
if (col !== 2 && !inScope(dir)) continue;
|
|
81
|
+
if (q && col !== 2 && !`${wsLabel(w)} ${name} ${cs.map(titleOf).join(" ")}`.toLowerCase().includes(q)) continue;
|
|
82
|
+
const lead = [...open].sort((x, y) => RANK[stateOf(x)] - RANK[stateOf(y)])[0] ?? last;
|
|
83
|
+
// An idea whose agent asks adds the waiting dot; its column never changes.
|
|
84
|
+
const asks = cs.some((c) => c.kind === "idea" && stateOf(c) === "wait");
|
|
85
|
+
const st = asks ? "wait" : lead ? stateOf(lead) : "idle";
|
|
86
|
+
cols[col].push(
|
|
87
|
+
String(
|
|
88
|
+
html`<a class="wcard" href="${wsHref(dir, w.path)}" data-dir="${dir}" data-ws="${w.path}"><span class="si ${st}"></span><span class="wmain"><b>${wsLabel(w)}${w.main ? html`<i class="wtag">primary</i>` : ""}</b><small>${logo(dir, name, projects)}${name}</small><code>${cardLine(lead, lead ? stateOf(lead) : "", lead ? subline(lead, now) : "")}</code></span></a>`,
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
b.innerHTML = cols
|
|
93
|
+
.map((l, i) => `<section><h2>${WS_COLS[i]} <i>${l.length || ""}</i></h2><div class="wlist">${l.join("") || '<p class="wempty">Empty</p>'}</div></section>`)
|
|
94
|
+
.join("");
|
|
95
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { cardLine, columnOf, groupWs } from "./ws-board.ts";
|
|
3
|
+
|
|
4
|
+
const D = "/p/.kaizen";
|
|
5
|
+
const run = (id: string, status: string, o: any = {}) => ({ kind: "run", state: D, id, status, moved: 1, column: 1, ws: "/p", ...o });
|
|
6
|
+
const wsOf = (c) => c.ws;
|
|
7
|
+
// stateOf as workspace.ts has it, for the fields these tests use.
|
|
8
|
+
const stateOf = (c) =>
|
|
9
|
+
c.kind === "idea" ? (c.pty?.asking ? "wait" : "idle")
|
|
10
|
+
: c.status === "waiting" || (c.pty?.alive && c.pty.asking) ? "wait"
|
|
11
|
+
: c.status === "done" ? (c.accept === "needs" ? "wait" : "done")
|
|
12
|
+
: c.status === "abandoned" ? "aband" : c.status === "stalled" ? "stalled"
|
|
13
|
+
: c.column >= 3 ? "review" : c.column === 2 ? "build" : "plan";
|
|
14
|
+
const col = (cs: any[], ws = "/p") => columnOf(cs, D, ws, wsOf, stateOf).col;
|
|
15
|
+
|
|
16
|
+
test("no runs, only ideas, an asking idea: Todo", () => {
|
|
17
|
+
expect(col([])).toBe(0);
|
|
18
|
+
expect(col([{ kind: "idea", state: D, text: "t", ws: "/p" }])).toBe(0);
|
|
19
|
+
expect(col([{ kind: "idea", state: D, text: "t", ws: "/p", pty: { alive: true, asking: true } }])).toBe(0);
|
|
20
|
+
});
|
|
21
|
+
test("building, planning: In progress; stalled too", () => {
|
|
22
|
+
expect(col([run("a", "building", { column: 2 })])).toBe(1);
|
|
23
|
+
expect(col([run("a", "planning", { column: 1 })])).toBe(1);
|
|
24
|
+
expect(col([run("a", "stalled", { column: 2 })])).toBe(1);
|
|
25
|
+
});
|
|
26
|
+
test("waiting on approval, done not accepted, running review: In review", () => {
|
|
27
|
+
expect(col([run("a", "waiting", { awaiting: "plan" })])).toBe(2);
|
|
28
|
+
expect(col([run("a", "done", { accept: "needs" })])).toBe(2);
|
|
29
|
+
expect(col([run("a", "running", { column: 3 })])).toBe(2);
|
|
30
|
+
});
|
|
31
|
+
test("one run waiting and one building: In review", () => {
|
|
32
|
+
expect(col([run("a", "building", { column: 2 }), run("b", "waiting")])).toBe(2);
|
|
33
|
+
});
|
|
34
|
+
test("done clean: Done; a new building run after it: In progress", () => {
|
|
35
|
+
expect(col([run("a", "done")])).toBe(3);
|
|
36
|
+
expect(col([run("a", "done"), run("b", "building", { column: 2 })])).toBe(1);
|
|
37
|
+
});
|
|
38
|
+
test("abandoned only: Todo; newest finished abandoned over an older done: Todo", () => {
|
|
39
|
+
expect(col([run("a", "abandoned")])).toBe(0);
|
|
40
|
+
expect(col([run("a", "done", { moved: 1 }), run("b", "abandoned", { moved: 2 })])).toBe(0);
|
|
41
|
+
});
|
|
42
|
+
test("archived done still counts: Done; a new run there moves it", () => {
|
|
43
|
+
expect(col([run("a", "done", { archived: true })])).toBe(3);
|
|
44
|
+
expect(col([run("a", "done", { archived: true }), run("b", "building", { column: 2 })])).toBe(1);
|
|
45
|
+
});
|
|
46
|
+
test("another workspace's runs do not count", () => {
|
|
47
|
+
expect(col([run("a", "building", { ws: "/p/wt" })])).toBe(0);
|
|
48
|
+
expect(col([run("a", "building", { column: 2, ws: "/p/wt" })], "/p/wt")).toBe(1);
|
|
49
|
+
});
|
|
50
|
+
test("groupWs: a card whose worktree is gone lands on the main checkout; unlisted projects fall back to cards", () => {
|
|
51
|
+
const projects = [{ dir: D, workspaces: [{ path: "/p", main: true }, { path: "/p/wt" }] }];
|
|
52
|
+
const wsOfP = (c) => (c.ws === "/p/wt" || c.ws === "/p" ? c.ws : "/p");
|
|
53
|
+
const cs = [run("a", "building", { ws: "/gone" }), run("b", "building", { ws: "/p/wt" })];
|
|
54
|
+
const g = groupWs(cs, projects, wsOfP);
|
|
55
|
+
expect(g.map((e) => [e.w.path, e.cs.length])).toEqual([["/p", 1], ["/p/wt", 1]]);
|
|
56
|
+
const f = groupWs([run("x", "done", { state: "/q/.kaizen", ws: "/q" })], projects, wsOf);
|
|
57
|
+
expect(f.map((e) => [e.dir, e.w.path])).toEqual([[D, "/p"], [D, "/p/wt"], ["/q/.kaizen", "/q"]]);
|
|
58
|
+
});
|
|
59
|
+
test("groupWs: a card with no workspace in a listed project goes to the main checkout, or its own row", () => {
|
|
60
|
+
const c = run("a", "building", { ws: "" });
|
|
61
|
+
const g = (ws) => groupWs([c], [{ dir: D, workspaces: ws }], wsOf).map((e) => [e.w.path, e.cs.length]);
|
|
62
|
+
expect(g([{ path: "/p", main: true }, { path: "/p/wt" }])).toEqual([["/p", 1], ["/p/wt", 0]]);
|
|
63
|
+
expect(g([{ path: "/p/wt" }])).toEqual([["/p/wt", 0], ["", 1]]);
|
|
64
|
+
});
|
|
65
|
+
test("cardLine: waiting on you says so with what it waits for", () => {
|
|
66
|
+
expect(cardLine(run("a", "waiting", { awaiting: "plan" }), "wait", "planning · plan approval")).toBe("waiting on you · plan approval");
|
|
67
|
+
expect(cardLine(run("a", "waiting"), "wait", "waiting on you")).toBe("waiting on you");
|
|
68
|
+
expect(cardLine(run("a", "planning"), "wait", "planning · 5m")).toBe("waiting on you");
|
|
69
|
+
expect(cardLine(run("a", "building"), "build", "building · 5m")).toBe("building · 5m");
|
|
70
|
+
expect(cardLine(undefined, "", "")).toBe("no runs");
|
|
71
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The Workspaces board's logic without the DOM, so it is tested alone (ws-board.test.ts):
|
|
2
|
+
// which of Todo / In progress / In review / Done a workspace sits in, from its runs.
|
|
3
|
+
import { finished } from "./ws-tabs.ts";
|
|
4
|
+
|
|
5
|
+
export const WS_COLS = ["Todo", "In progress", "In review", "Done"];
|
|
6
|
+
// A workspace's column from its runs (ideas never move it). Archived runs still count as
|
|
7
|
+
// finished ones, so a workspace whose newest run is done stays Done until a new run starts.
|
|
8
|
+
// Returns the open runs (not finished, not archived) and the newest finished run, for the card.
|
|
9
|
+
export function columnOf(cards: any[], dir: string, ws: string, wsOfCard, stateOf) {
|
|
10
|
+
const runs = cards.filter((c) => c.kind === "run" && c.state === dir && wsOfCard(c) === ws);
|
|
11
|
+
const open = runs.filter((c) => !c.archived && !finished(c));
|
|
12
|
+
const last = runs.filter(finished).sort((a, b) => (b.moved ?? 0) - (a.moved ?? 0))[0];
|
|
13
|
+
const st = open.map(stateOf);
|
|
14
|
+
const col = st.some((s) => s === "wait" || s === "review") ? 2 : open.length ? 1 : last?.status === "done" ? 3 : 0;
|
|
15
|
+
return { col, open, last };
|
|
16
|
+
}
|
|
17
|
+
// One entry per workspace of each project; cards of a project the rail does not list yet
|
|
18
|
+
// get one entry per workspace they name, so the board is not empty before the rail arrives.
|
|
19
|
+
export function groupWs(cards: any[], projects: any[], wsOfCard) {
|
|
20
|
+
const out: { dir: string; w: { path: string; branch?: string; main?: boolean }; cs: any[] }[] = [];
|
|
21
|
+
const listed = new Map<string, Set<string>>();
|
|
22
|
+
for (const p of projects ?? []) {
|
|
23
|
+
if (!p.workspaces?.length) continue;
|
|
24
|
+
listed.set(p.dir, new Set(p.workspaces.map((w) => w.path)));
|
|
25
|
+
for (const w of p.workspaces) out.push({ dir: p.dir, w, cs: cards.filter((c) => c.state === p.dir && wsOfCard(c) === w.path) });
|
|
26
|
+
}
|
|
27
|
+
for (const c of cards) {
|
|
28
|
+
const paths = listed.get(c.state);
|
|
29
|
+
let path = wsOfCard(c);
|
|
30
|
+
if (paths?.has(path)) continue;
|
|
31
|
+
// A card matching no listed workspace (wsOfCard gave "") goes to the main checkout, else its own row.
|
|
32
|
+
if (paths) path = projects.find((p) => p.dir === c.state).workspaces.find((w) => w.main)?.path ?? path;
|
|
33
|
+
let e = out.find((x) => x.dir === c.state && x.w.path === path);
|
|
34
|
+
if (!e) out.push((e = { dir: c.state, w: { path, main: true }, cs: [] }));
|
|
35
|
+
e.cs.push(c);
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
// The words under a workspace card: a run waiting on the user says so, with what it waits for
|
|
40
|
+
// ("waiting on you · plan approval"); otherwise the run's own line.
|
|
41
|
+
export function cardLine(lead: any, leadState: string, sub: string) {
|
|
42
|
+
if (!lead) return "no runs";
|
|
43
|
+
if (leadState !== "wait" || lead.kind !== "run") return sub;
|
|
44
|
+
return lead.status === "waiting" && sub.includes(" · ") ? `waiting on you · ${sub.split(" · ").slice(1).join(" · ")}` : "waiting on you";
|
|
45
|
+
}
|