kaizen-agent 1.59.2 → 1.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +82 -3
- package/cli/pty.ts +122 -6
- 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-symlink.test.ts +28 -0
- package/cli/web.ts +320 -100
- package/cli/worktree.test.ts +43 -1
- package/cli/worktree.ts +97 -2
- 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 +2 -0
- 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 +18 -3
- package/web/board/projects.ts +6 -85
- package/web/board/run-pick.ts +41 -0
- package/web/board/run-view.ts +261 -106
- 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 +125 -38
- package/web/board/ws-board-ui.ts +84 -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 +171 -0
- package/web/board/ws-tabs.ts +170 -0
- package/web/board.html +80 -36
- package/web/board.js +44 -43
- package/web/notebook.js +24 -25
- package/web/notes.html +25 -20
- package/web/term.js +1 -1
- package/web/video.html +25 -20
- package/web/video.js +56 -57
package/web/board/settings.ts
CHANGED
|
@@ -26,6 +26,7 @@ export async function openSettings() {
|
|
|
26
26
|
if (!$("panel").classList.contains("open") || $("ptitle").textContent !== "Settings") {
|
|
27
27
|
$("pbody").innerHTML = SKEL;
|
|
28
28
|
$("psub").textContent = "";
|
|
29
|
+
store.setScope = store.all ? "all" : store.dir || store.S.dir || "all";
|
|
29
30
|
}
|
|
30
31
|
termStop();
|
|
31
32
|
store.openKey = null;
|
|
@@ -37,9 +38,14 @@ export async function openSettings() {
|
|
|
37
38
|
$("ptabs").innerHTML = "";
|
|
38
39
|
$("pfoot").innerHTML = "";
|
|
39
40
|
const cur = document.documentElement.dataset.theme || "system";
|
|
40
|
-
|
|
41
|
-
.then((r) => r.json())
|
|
41
|
+
let cfg = await fetch("/settings?scope=" + encodeURIComponent(store.setScope))
|
|
42
|
+
.then((r) => (r.ok ? r.json() : null))
|
|
42
43
|
.catch(() => null);
|
|
44
|
+
// A project the board no longer knows: fall back to All projects.
|
|
45
|
+
if (!cfg && store.setScope !== "all") {
|
|
46
|
+
store.setScope = "all";
|
|
47
|
+
return openSettings();
|
|
48
|
+
}
|
|
43
49
|
const gg = await fetch("/google")
|
|
44
50
|
.then((r) => r.json())
|
|
45
51
|
.catch(() => ({}));
|
|
@@ -65,20 +71,40 @@ export async function openSettings() {
|
|
|
65
71
|
return html`<span class="step" id="${id}" role="group" aria-labelledby="${id}-l"><button id="${id}-prev" aria-label="Previous">‹</button><output aria-live="polite">${on === "" ? "—" : on}</output><button id="${id}-next" aria-label="Next">›</button></span>`;
|
|
66
72
|
};
|
|
67
73
|
// `off`: the row has no effect while another setting stands as it is; dimmed, still editable.
|
|
74
|
+
const onOff = (v) => (v === "true" ? "on" : v === "false" ? "off" : v === "" ? "—" : v);
|
|
75
|
+
const scoped = cfg && cfg.scope !== "all";
|
|
76
|
+
// What else a row says about its scope: projects that set it otherwise, or a Reset
|
|
77
|
+
// for a value this project sets itself.
|
|
78
|
+
const scopeNote = (r, id) =>
|
|
79
|
+
r.own
|
|
80
|
+
? html`Set for this project · <button class="sreset" id="${id}-reset" type="button">Reset</button>`
|
|
81
|
+
: r.overrides?.length
|
|
82
|
+
? r.overrides.map((o) => `${o.label}: ${onOff(o.value)}`).join(", ")
|
|
83
|
+
: "";
|
|
68
84
|
const row = (label, control, hint, id, q, off = false) =>
|
|
69
85
|
html`<div class="srow${off ? " off" : ""}" data-q="${q.toLowerCase()}"><label for="${id}" id="${id}-l">${label}</label>${control}${hint ? html`<p class="hint">${hint}</p>` : ""}</div>`;
|
|
70
86
|
const hadFocus = document.activeElement?.id === "sq";
|
|
71
87
|
const np = typeof Notification === "undefined" ? null : Notification.permission;
|
|
72
88
|
const nton = notifyOn();
|
|
73
89
|
const ntHelp = !nton ? "Off in this browser" : np === "granted" ? "" : np === "denied" ? "Pop-ups blocked by this browser; the sound still plays" : np ? "Pop-ups wait for the browser to ask; the sound still plays" : "Pop-ups not supported here; the sound still plays";
|
|
90
|
+
const scopeRow = cfg
|
|
91
|
+
? html`<div class="sgrp">${row(
|
|
92
|
+
"Settings for",
|
|
93
|
+
html`<select class="sel" id="s-scope">${[{ dir: "all", label: "All projects" }, ...cfg.projects].map((p) => html`<option value="${p.dir}"${p.dir === cfg.scope ? " selected" : ""}>${p.label}</option>`)}</select>`,
|
|
94
|
+
scoped ? "This project's own .kaizen/config.yml; anything it does not set comes from All projects." : "~/.kaizen/config.yml; a project's own config wins where it sets a value.",
|
|
95
|
+
"s-scope",
|
|
96
|
+
"settings for scope project all projects",
|
|
97
|
+
)}</div>`
|
|
98
|
+
: "";
|
|
74
99
|
$("pbody").innerHTML = html`<div class="sq"><input class="sel" id="sq" type="search" placeholder="Search settings" aria-label="Search settings" spellcheck="false" autocomplete="off" value="${store.setQ}"></div>
|
|
100
|
+
${scopeRow}
|
|
75
101
|
<h3 class="sg">Phone</h3><div class="sgrp">${row("Phone address", cfg?.phoneUrls?.length ? html`<span class="phoneurls">${cfg.phoneUrls.map((url) => html`<a href="${url}" target="_blank" rel="noopener">${url}</a>`)}</span>` : html`<span>Not set</span>`, cfg?.phoneUrls?.length ? "Configured address; Tailscale must be running on both devices." : "Run kaizen setup on this PC to connect your phone.", "phone-url", "phone address url tailscale setup")}</div>
|
|
76
102
|
${
|
|
77
103
|
cfg
|
|
78
104
|
? groups(cfg.rows)
|
|
79
105
|
.map(
|
|
80
106
|
([g, rows]) =>
|
|
81
|
-
html`<h3 class="sg">${g}</h3><div class="sgrp">${rows
|
|
107
|
+
html`<h3 class="sg">${g}${scoped && g === "Board" ? " · all projects" : ""}</h3><div class="sgrp">${rows
|
|
82
108
|
.map((r) => {
|
|
83
109
|
const id = "s-" + r.key.replace(/\./g, "-");
|
|
84
110
|
return row(
|
|
@@ -88,7 +114,7 @@ export async function openSettings() {
|
|
|
88
114
|
? html`<span class="fpick"><input class="sel" id="${id}" value="${r.value}" placeholder="not set" spellcheck="false"><button class="btn" id="${id}-pick" type="button">Browse…</button></span>`
|
|
89
115
|
: html`<input class="sel" id="${id}" value="${r.value}" placeholder="not set" spellcheck="false">`
|
|
90
116
|
: ctl(id, r.values, r.value),
|
|
91
|
-
[r.help, r.idle].filter(Boolean).join(" · "),
|
|
117
|
+
((t, n) => (t && n ? html`${t} · ${n}` : n || t))([r.help, r.idle].filter(Boolean).join(" · "), scopeNote(r, id)),
|
|
92
118
|
id,
|
|
93
119
|
[r.label, r.help, r.key, g, ...r.values].join(" "),
|
|
94
120
|
!!r.idle,
|
|
@@ -203,12 +229,23 @@ export async function openSettings() {
|
|
|
203
229
|
} catch (e) {}
|
|
204
230
|
playSound(v);
|
|
205
231
|
});
|
|
232
|
+
if (cfg)
|
|
233
|
+
$("s-scope").onchange = (e) => {
|
|
234
|
+
store.setScope = e.target.value;
|
|
235
|
+
openSettings();
|
|
236
|
+
};
|
|
206
237
|
if (cfg)
|
|
207
238
|
cfg.rows.forEach((r) => {
|
|
208
239
|
const el = $("s-" + r.key.replace(/\./g, "-"));
|
|
240
|
+
if (r.own)
|
|
241
|
+
$(el.id + "-reset").onclick = async () => {
|
|
242
|
+
const j = await post("/settings", { key: r.key, scope: cfg.scope, reset: true });
|
|
243
|
+
toast(j.ok ? "Reset to All projects" : j.error || "Could not reset");
|
|
244
|
+
openSettings();
|
|
245
|
+
};
|
|
209
246
|
const save = async (v) => {
|
|
210
247
|
const f = document.activeElement?.id;
|
|
211
|
-
const j = await post("/settings", { key: r.key, value: v });
|
|
248
|
+
const j = await post("/settings", { key: r.key, value: v, scope: cfg.scope });
|
|
212
249
|
if (j.ok) toast("Saved");
|
|
213
250
|
await refocus(f);
|
|
214
251
|
};
|
package/web/board/store.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// panel's tab and doc, and the page filters. Everything else lives in the module that
|
|
3
3
|
// owns it.
|
|
4
4
|
export const store = {
|
|
5
|
-
S: { project: null, projects: [], cards: [], now: Date.now(), all: false },
|
|
5
|
+
S: { project: null, projects: [], cards: [], now: Date.now(), all: false, dir: null as string | null },
|
|
6
6
|
all: new URLSearchParams(location.search).get("all") !== "0",
|
|
7
7
|
// The project this page picked; null is wherever the board started.
|
|
8
8
|
dir: null,
|
|
@@ -23,6 +23,8 @@ export const store = {
|
|
|
23
23
|
shells: [] as { key: string; dir: string; title: string; agent: string }[],
|
|
24
24
|
// The settings search survives the re-render each save does; the gear button starts it empty.
|
|
25
25
|
setQ: "",
|
|
26
|
+
// Settings' scope: "all" or a project's state dir. Set on opening; never moves the board.
|
|
27
|
+
setScope: "all",
|
|
26
28
|
// Settings and the Icebox fill the same panel after a fetch: a fill only lands if no other view
|
|
27
29
|
// or fill started since, or a slow answer paints one page under the other's title.
|
|
28
30
|
pageGen: 0,
|
package/web/board/toast.ts
CHANGED
|
@@ -44,7 +44,10 @@ let actx;
|
|
|
44
44
|
export function playSound(name = soundPick()) {
|
|
45
45
|
try {
|
|
46
46
|
if (SAMPLES.includes(name)) {
|
|
47
|
-
new Audio(`/sounds/${name}.mp3`)
|
|
47
|
+
const a = new Audio(`/sounds/${name}.mp3`);
|
|
48
|
+
// The samples peak at 0 dBFS and clip on desktop speakers at full volume; about -9 dB.
|
|
49
|
+
a.volume = 0.35;
|
|
50
|
+
a.play().catch(() => {});
|
|
48
51
|
return;
|
|
49
52
|
}
|
|
50
53
|
if (!NOTES[name]) return;
|
package/web/board/views.ts
CHANGED
|
@@ -27,6 +27,8 @@ export const markView = (v) => {
|
|
|
27
27
|
export function go(v, push) {
|
|
28
28
|
store.pageGen++;
|
|
29
29
|
if (v === "icebox") v = "sources";
|
|
30
|
+
// A workspace address shows in the run view, which resolves it to a card.
|
|
31
|
+
if (v === "ws") v = "run";
|
|
30
32
|
if (!["settings", "sources", "terminal", "board", "ideas", "run", "chat", "device"].includes(v)) v = "home";
|
|
31
33
|
// A phone has Home, Chat, Runs and Settings: the board, Ideas and the Icebox are set up on a computer,
|
|
32
34
|
// whose Home is the chat.
|
|
@@ -61,7 +63,7 @@ export function go(v, push) {
|
|
|
61
63
|
openPhone(ph ? "home" : v === "device" ? "device" : null);
|
|
62
64
|
if (v === "ideas") openIdeas();
|
|
63
65
|
// After the panel handling below, which closes the board's panel on the way in.
|
|
64
|
-
if (v === "run") queueMicrotask(() => void showRunView());
|
|
66
|
+
if (v === "run") queueMicrotask(() => void showRunView(true));
|
|
65
67
|
// The Terminal page is the board's own area, not the docked panel: the panel closes as on the board.
|
|
66
68
|
if (AREA.includes(v)) {
|
|
67
69
|
if (AREA.includes(was)) {
|
package/web/board/workspace.ts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
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 { agentsHtml, dueWord, forgetAgents, gitDue, settleIn, toggleOpen, wsAgents, type Agent } from "./ws-tabs.ts";
|
|
9
11
|
|
|
10
12
|
const DAY = 864e5;
|
|
11
13
|
const STAGE = ["idea", "planning", "building", "reviewing", "done"];
|
|
@@ -14,7 +16,7 @@ export function stateOf(c) {
|
|
|
14
16
|
// An idea whose agent is working is a run being born: show it as planning.
|
|
15
17
|
if (c.kind === "idea") return !c.pty?.alive ? "idle" : c.pty.asking ? "wait" : c.pty.busy ? "plan" : "idle";
|
|
16
18
|
if (c.status === "waiting" || (c.pty?.alive && c.pty.asking)) return "wait";
|
|
17
|
-
if (c.status === "done") return "done";
|
|
19
|
+
if (c.status === "done") return c.accept === "needs" || gitDue(c) ? "wait" : "done";
|
|
18
20
|
if (c.status === "abandoned") return "aband";
|
|
19
21
|
if (c.status === "stalled") return "stalled";
|
|
20
22
|
return c.column >= 3 ? "review" : c.column === 2 ? "build" : "plan";
|
|
@@ -24,6 +26,9 @@ export function subline(c, now) {
|
|
|
24
26
|
if (c.kind === "idea") return !c.pty?.alive ? "idea" : c.pty.asking ? "waiting on you" : c.pty.busy ? "planning · starting" : "agent · open";
|
|
25
27
|
const t = c.moved ?? now;
|
|
26
28
|
if (c.status === "waiting") return c.awaiting ? `${STAGE[c.column] ?? "waiting"} · ${need(c.awaiting)}` : "waiting on you";
|
|
29
|
+
if (c.accept === "needs") return "done, not approved";
|
|
30
|
+
if (gitDue(c)) return `waiting on you · ${dueWord(c)}`;
|
|
31
|
+
if (c.accept === "auto") return `auto-accepted · ${age(t, now)} ago`;
|
|
27
32
|
if (c.status === "done" || c.status === "abandoned") return `${c.status} · ${age(t, now)} ago`;
|
|
28
33
|
if (c.status === "stalled") return `stalled · ${age(t, now)}`;
|
|
29
34
|
return `${STAGE[c.column] ?? c.status} · ${age(t, now)}`;
|
|
@@ -33,7 +38,7 @@ export const titleOf = (c) => (c.title || c.text || "").split("\n")[0];
|
|
|
33
38
|
// live on the Ideas page; one whose agent is starting (it has a terminal) shows here.
|
|
34
39
|
export const listed = (c, now) =>
|
|
35
40
|
!c.archived && (c.kind === "idea" ? !!c.pty : !["done", "abandoned"].includes(c.status) || now - (c.moved ?? 0) < DAY);
|
|
36
|
-
const projName = (dir, projects) => {
|
|
41
|
+
export const projName = (dir, projects) => {
|
|
37
42
|
const l = projects?.find((p) => p.dir === dir)?.label || dir.replace(/[\\/]\.kaizen$/, "");
|
|
38
43
|
return l.split(/[\\/]/).pop() || l;
|
|
39
44
|
};
|
|
@@ -66,7 +71,10 @@ const kindOf = (c) => {
|
|
|
66
71
|
const st = stateOf(c);
|
|
67
72
|
return st === "done" || st === "aband" ? "done" : "active";
|
|
68
73
|
};
|
|
69
|
-
let last: { cards: any[]; projects?: any[] } = { cards: [] };
|
|
74
|
+
let last: { cards: any[]; projects?: any[]; agents?: Agent[] } = { cards: [] };
|
|
75
|
+
// Projects that are git repositories (the main checkout has a branch): where a workspace can be made.
|
|
76
|
+
export const gitProjects = () =>
|
|
77
|
+
(last.projects ?? []).filter((p) => p.workspaces?.some((w) => w.branch)).map((p) => ({ dir: p.dir as string, name: projName(p.dir, last.projects) }));
|
|
70
78
|
// Project groups folded shut in the side menu, kept per browser.
|
|
71
79
|
const folded: Set<string> = (() => {
|
|
72
80
|
try {
|
|
@@ -75,6 +83,21 @@ const folded: Set<string> = (() => {
|
|
|
75
83
|
return new Set();
|
|
76
84
|
}
|
|
77
85
|
})();
|
|
86
|
+
// Workspace cards with their agent list open (dir\0ws -> true), kept per browser.
|
|
87
|
+
const wsOpen: Record<string, true> = (() => {
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(localStorage.getItem("kz-wsopen") || "{}");
|
|
90
|
+
} catch {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
})();
|
|
94
|
+
function toggleList(dir: string, ws: string) {
|
|
95
|
+
toggleOpen(wsOpen, dir, ws);
|
|
96
|
+
try {
|
|
97
|
+
localStorage.setItem("kz-wsopen", JSON.stringify(wsOpen));
|
|
98
|
+
} catch {}
|
|
99
|
+
drawList();
|
|
100
|
+
}
|
|
78
101
|
function fold(dir: string) {
|
|
79
102
|
folded.has(dir) ? folded.delete(dir) : folded.add(dir);
|
|
80
103
|
try {
|
|
@@ -82,55 +105,103 @@ function fold(dir: string) {
|
|
|
82
105
|
} catch {}
|
|
83
106
|
drawList();
|
|
84
107
|
}
|
|
108
|
+
// A card's workspace row: its own (a run's worktree) when the project lists it, else the
|
|
109
|
+
// main checkout's, so a run whose worktree is gone, an idea or an old run never vanishes.
|
|
110
|
+
export function wsOfCard(c, projects = last.projects) {
|
|
111
|
+
const ws = projects?.find((p) => p.dir === c.state)?.workspaces ?? [];
|
|
112
|
+
return ws.find((w) => w.path === c.ws)?.path ?? ws.find((w) => w.main)?.path ?? c.ws ?? "";
|
|
113
|
+
}
|
|
114
|
+
export const wsHref = (dir, ws) => `/?view=ws&dir=${encodeURIComponent(dir)}&ws=${encodeURIComponent(ws)}`;
|
|
115
|
+
export const RANK = { wait: 0, plan: 1, build: 2, review: 3, stalled: 4, idle: 5, done: 6, aband: 7 };
|
|
116
|
+
export const folderOf = (w) => w.path.split(/[\\/]/).pop() || w.path;
|
|
117
|
+
// A worktree's mark on line 2 of its card.
|
|
118
|
+
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>`;
|
|
119
|
+
let settleT: ReturnType<typeof setTimeout> | undefined;
|
|
120
|
+
let drawn = "";
|
|
121
|
+
export const wsLabel = (w) => w.branch || (w.main ? "workspace" : w.path.split(/[\\/]/).pop());
|
|
85
122
|
function drawList() {
|
|
86
123
|
const box = $("plist");
|
|
87
124
|
if (!box) return;
|
|
88
125
|
const now = Date.now();
|
|
89
|
-
const
|
|
90
|
-
const all = new Set(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
126
|
+
const projects = (last.projects ?? []).filter((p) => p.workspaces?.length);
|
|
127
|
+
const all = new Set(projects.map((p) => p.dir));
|
|
128
|
+
// Cards by project and workspace: each lands on a row, the main checkout when its own is not listed.
|
|
129
|
+
const by = new Map<string, any[]>();
|
|
130
|
+
for (const c of last.cards.filter((c) => listed(c, now))) {
|
|
131
|
+
const k = c.state + "\0" + wsOfCard(c);
|
|
132
|
+
if (!by.has(k)) by.set(k, []);
|
|
133
|
+
by.get(k)!.push(c);
|
|
94
134
|
}
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
135
|
+
const top = (cs) => (cs.length ? Math.min(...cs.map((c) => RANK[stateOf(c)])) : 9);
|
|
136
|
+
const groups = projects
|
|
137
|
+
.filter((p) => !filt.dirs.length || filt.dirs.includes(p.dir))
|
|
138
|
+
.map((p) => {
|
|
139
|
+
const rows = p.workspaces
|
|
140
|
+
.map((w) => ({ w, cs: by.get(p.dir + "\0" + w.path) ?? [] }))
|
|
141
|
+
// An empty workspace or one with a run going is active; one holding only finished runs is done.
|
|
142
|
+
.filter(({ cs }) => filt[cs.length && cs.every((c) => kindOf(c) === "done") ? "done" : "active"]);
|
|
143
|
+
return { p, rows, top: Math.min(9, ...rows.map((r) => top(r.cs))) };
|
|
144
|
+
})
|
|
145
|
+
.filter((g) => g.rows.length)
|
|
146
|
+
// Projects by their most urgent card; the picker's order otherwise.
|
|
147
|
+
.sort((a, b) => a.top - b.top);
|
|
104
148
|
|
|
105
149
|
const f = $("pfilter");
|
|
106
150
|
const on = filt.dirs.some((d) => all.has(d)) || !filt.active || !filt.done;
|
|
107
151
|
f.setAttribute("aria-pressed", String(on));
|
|
108
152
|
f.title = on ? "Filter on: choose projects and kinds" : "Filter projects and kinds";
|
|
109
153
|
if ($("pfpop")) drawPop(all);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
154
|
+
// Agents are read from this tick's payload; one held at "working" through the 3 s settle redraws when it ends.
|
|
155
|
+
forgetAgents(last.agents ?? []);
|
|
156
|
+
clearTimeout(settleT);
|
|
157
|
+
const wait = settleIn(last.agents ?? [], now);
|
|
158
|
+
if (wait < Infinity) settleT = setTimeout(drawList, wait + 20);
|
|
159
|
+
const out =
|
|
160
|
+
groups
|
|
161
|
+
.map(({ p, rows }) => {
|
|
162
|
+
const dir = p.dir,
|
|
163
|
+
name = projName(dir, last.projects),
|
|
164
|
+
shut = folded.has(dir);
|
|
165
|
+
// A + for a new worktree on git projects (the main checkout has a branch).
|
|
166
|
+
const git = p.workspaces.some((w) => w.branch);
|
|
167
|
+
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 }) => {
|
|
168
|
+
// The dot: the most urgent run there, or an agent asking (amber) or working (spinner).
|
|
169
|
+
const rows = wsAgents(last.agents ?? [], dir, w.path, wsOfCard, now);
|
|
170
|
+
const st0 = cs.length ? stateOf([...cs].sort((a, b) => RANK[stateOf(a)] - RANK[stateOf(b)])[0]) : "";
|
|
171
|
+
const st = st0 === "wait" || rows[0]?.st === "asking" ? "wait" : rows.some((r) => r.st === "working") ? "build" : st0 || (rows.length ? "done" : "");
|
|
172
|
+
// The agent buttons are siblings of the link (a button inside a link is invalid).
|
|
173
|
+
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>`;
|
|
174
|
+
})}`;
|
|
120
175
|
})
|
|
121
|
-
.join("") || `<div class="none">No
|
|
176
|
+
.join("") || `<div class="none">No projects</div>`;
|
|
177
|
+
// The same markup is not written again: hover and focus stay, and a tick that changed nothing costs no layout.
|
|
178
|
+
if (out !== drawn) box.innerHTML = drawn = out;
|
|
179
|
+
markCurrent();
|
|
122
180
|
box.onclick = (e) => {
|
|
123
|
-
const
|
|
181
|
+
const t = e.target as HTMLElement;
|
|
182
|
+
const term = t.closest<HTMLElement>("[data-term]");
|
|
183
|
+
if (term) return void (e.preventDefault(), openTerm(term.dataset.dir!, term.dataset.ws!, term.dataset.term!));
|
|
184
|
+
const tog = t.closest<HTMLElement>("[data-wopen]");
|
|
185
|
+
if (tog) return void (e.preventDefault(), toggleList(tog.dataset.dir!, tog.dataset.ws!));
|
|
186
|
+
const add = t.closest<HTMLElement>("[data-wadd]")?.dataset.wadd;
|
|
187
|
+
if (add) return void (e.preventDefault(), openAdd({ dir: add, start: "ws" }));
|
|
188
|
+
const d = t.closest<HTMLElement>("[data-fold]")?.dataset.fold;
|
|
124
189
|
if (d) (e.preventDefault(), fold(d));
|
|
125
190
|
};
|
|
126
191
|
}
|
|
192
|
+
// An agent's mark: the board opens that terminal tab in its workspace; the notebook and video pages open the workspace.
|
|
193
|
+
const openTerm = (dir: string, ws: string, key: string) => {
|
|
194
|
+
if (!ask("kz-open-term", { dir, ws, key })) location.href = wsHref(dir, ws);
|
|
195
|
+
};
|
|
127
196
|
// Moves the side menu's highlight to the card the address names: opening a card in place
|
|
128
197
|
// changes the address without redrawing the list.
|
|
129
198
|
export function markCurrent() {
|
|
130
199
|
const cur = new URLSearchParams(location.search);
|
|
200
|
+
// A run's address (old links, notifications) lights its workspace.
|
|
201
|
+
const c = cur.get("id") && last.cards.find((x) => x.kind === "run" && x.state === cur.get("dir") && x.id === cur.get("id"));
|
|
202
|
+
const ws = cur.get("ws") ?? (c ? wsOfCard(c) : null);
|
|
131
203
|
for (const a of document.querySelectorAll<HTMLElement>("#plist a.row")) {
|
|
132
|
-
|
|
133
|
-
if (on) a.setAttribute("aria-current", "true");
|
|
204
|
+
if (cur.get("dir") === a.dataset.dir && ws === a.dataset.ws) a.setAttribute("aria-current", "true");
|
|
134
205
|
else a.removeAttribute("aria-current");
|
|
135
206
|
}
|
|
136
207
|
}
|
|
@@ -206,10 +277,27 @@ function closePop() {
|
|
|
206
277
|
$("pfilter").setAttribute("aria-expanded", "false");
|
|
207
278
|
}
|
|
208
279
|
|
|
280
|
+
// Rows are redrawn on every refresh, which restarts a CSS animation from 0deg: the state
|
|
281
|
+
// icons jumped back mid-turn. Pinning each to the page clock's origin keeps them in phase
|
|
282
|
+
// (the si-* animations have no delay for this to cancel).
|
|
283
|
+
const syncSpin = () =>
|
|
284
|
+
document.getAnimations().forEach((a: any) => {
|
|
285
|
+
if (a.animationName?.startsWith("si-") && a.startTime !== 0) a.startTime = 0;
|
|
286
|
+
});
|
|
209
287
|
export function initRail() {
|
|
288
|
+
let queued = false;
|
|
289
|
+
const hasSi = (n: any) => n.nodeType === 1 && (n.classList.contains("si") || n.querySelector(".si"));
|
|
290
|
+
new MutationObserver((rs) => {
|
|
291
|
+
if (queued || !rs.some((r) => [...r.addedNodes].some(hasSi))) return;
|
|
292
|
+
queued = true;
|
|
293
|
+
requestAnimationFrame(() => {
|
|
294
|
+
queued = false;
|
|
295
|
+
syncSpin();
|
|
296
|
+
});
|
|
297
|
+
}).observe(document.body, { childList: true, subtree: true });
|
|
210
298
|
if (!$("plist")) return;
|
|
211
|
-
onBoardCards((cards, projects) => {
|
|
212
|
-
last = { cards, projects: projects ?? last.projects };
|
|
299
|
+
onBoardCards((cards, projects, agents) => {
|
|
300
|
+
last = { cards, projects: projects ?? last.projects, agents: agents ?? [] };
|
|
213
301
|
drawList();
|
|
214
302
|
void drawSources();
|
|
215
303
|
onCount?.(cards);
|
|
@@ -242,16 +330,15 @@ export function initRail() {
|
|
|
242
330
|
$("pfilter").focus();
|
|
243
331
|
}
|
|
244
332
|
});
|
|
333
|
+
// The sheet: add a folder, clone, create, or start a workspace; the current project is preselected.
|
|
245
334
|
$("padd").onclick = () => {
|
|
246
|
-
// The page's own project when it has one: the run workspace's, or the one project the filter shows.
|
|
247
335
|
const p = new URLSearchParams(location.search);
|
|
248
|
-
|
|
249
|
-
if (!ask("kz-new-idea", { dir })) location.href = "/?view=board";
|
|
336
|
+
openAdd({ dir: ["run", "ws"].includes(p.get("view")) ? p.get("dir") : filt.dirs.length === 1 ? filt.dirs[0] : null });
|
|
250
337
|
};
|
|
251
338
|
$("plist").addEventListener("click", (e) => {
|
|
252
339
|
const a = (e.target as Element).closest?.("a.row") as HTMLAnchorElement;
|
|
253
340
|
if (!a || e.ctrlKey || e.metaKey || e.shiftKey || (e as MouseEvent).button) return;
|
|
254
|
-
if (ask("kz-open-
|
|
341
|
+
if (ask("kz-open-ws", { dir: a.dataset.dir, ws: a.dataset.ws })) e.preventDefault();
|
|
255
342
|
});
|
|
256
343
|
}
|
|
257
344
|
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
addEventListener("kz-rail", () => boardMode() === "ws" && !document.body.classList.contains("paged") && render());
|
|
47
|
+
$("board").addEventListener("click", (e: MouseEvent) => {
|
|
48
|
+
const a = (e.target as Element).closest?.("a.wcard") as HTMLAnchorElement;
|
|
49
|
+
if (!a || e.ctrlKey || e.metaKey || e.shiftKey || e.button) return;
|
|
50
|
+
if (!dispatchEvent(new CustomEvent("kz-open-ws", { cancelable: true, detail: { dir: a.dataset.dir, ws: a.dataset.ws } }))) e.preventDefault();
|
|
51
|
+
});
|
|
52
|
+
syncMode();
|
|
53
|
+
drawToggle();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// `inScope(dir)` is the board's project scope (single project, or the Showing filter).
|
|
57
|
+
export function drawWsBoard(inScope: (dir: string) => boolean) {
|
|
58
|
+
const b = $("board"),
|
|
59
|
+
now = store.S.now || Date.now(),
|
|
60
|
+
{ cards, projects } = railData(),
|
|
61
|
+
q = ($("bq").value || "").trim().toLowerCase();
|
|
62
|
+
syncMode();
|
|
63
|
+
b.removeAttribute("aria-busy");
|
|
64
|
+
const cols: string[][] = WS_COLS.map(() => []);
|
|
65
|
+
for (const { dir, w, cs } of groupWs(cards, projects, wsOfCard)) {
|
|
66
|
+
const name = projName(dir, projects);
|
|
67
|
+
const { col, open, last } = columnOf(cs, dir, w.path, wsOfCard, stateOf);
|
|
68
|
+
// Neither the project filter nor search hides a workspace waiting on the user (In review).
|
|
69
|
+
if (col !== 2 && !inScope(dir)) continue;
|
|
70
|
+
if (q && col !== 2 && !`${wsLabel(w)} ${name} ${cs.map(titleOf).join(" ")}`.toLowerCase().includes(q)) continue;
|
|
71
|
+
const lead = [...open].sort((x, y) => RANK[stateOf(x)] - RANK[stateOf(y)])[0] ?? last;
|
|
72
|
+
// An idea whose agent asks adds the waiting dot; its column never changes.
|
|
73
|
+
const asks = cs.some((c) => c.kind === "idea" && stateOf(c) === "wait");
|
|
74
|
+
const st = asks ? "wait" : lead ? stateOf(lead) : "idle";
|
|
75
|
+
cols[col].push(
|
|
76
|
+
String(
|
|
77
|
+
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>`,
|
|
78
|
+
),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
b.innerHTML = cols
|
|
82
|
+
.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>`)
|
|
83
|
+
.join("");
|
|
84
|
+
}
|
|
@@ -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
|
+
}
|