kaizen-agent 1.60.0 → 1.60.2
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/knowledge.ts +1 -1
- package/cli/onboarding.test.ts +70 -0
- package/cli/onboarding.ts +63 -0
- package/cli/pty.test.ts +7 -2
- package/cli/pty.ts +5 -4
- package/cli/state.test.ts +86 -1
- package/cli/state.ts +140 -8
- package/cli/web-decide.test.ts +41 -0
- package/cli/web-pr.test.ts +51 -0
- package/cli/web.ts +150 -23
- package/cli/worktree.test.ts +104 -1
- package/cli/worktree.ts +117 -2
- package/package.json +1 -1
- package/web/board/api.ts +37 -4
- package/web/board/approvals.ts +6 -6
- package/web/board/badge.ts +6 -2
- package/web/board/cards.ts +4 -2
- package/web/board/fixes.ts +1 -1
- package/web/board/git.ts +382 -61
- package/web/board/live.ts +2 -1
- package/web/board/main.ts +2 -0
- package/web/board/onboarding.ts +223 -0
- package/web/board/panel.ts +36 -26
- package/web/board/run-view.ts +93 -9
- 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/store.ts +2 -0
- package/web/board/workspace.ts +94 -3
- package/web/board/ws-board-ui.ts +12 -1
- package/web/board/ws-tabs.test.ts +11 -1
- package/web/board/ws-tabs.ts +4 -1
- package/web/board.html +124 -16
- package/web/board.js +127 -45
- package/web/notebook.js +46 -23
- package/web/notes.html +18 -6
- package/web/term.js +20 -20
- package/web/term.ts +8 -3
- package/web/video.html +18 -6
- package/web/video.js +78 -55
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// Global search: the "Search" entry on top of the side menu, and Ctrl/Cmd+K anywhere, open
|
|
2
|
+
// one palette over workspaces, runs and ideas, chats, agent terminals, projects, pages and
|
|
3
|
+
// actions (modelled on Orca's "Jump to..." palette). Nothing is fetched but /chats; the rest
|
|
4
|
+
// is what the side menu already holds. Stands alone like workspace.ts, so the notebook and
|
|
5
|
+
// video pages carry it too: a pick the page cannot do in place navigates instead.
|
|
6
|
+
import { $, html, raw } from "./dom.ts";
|
|
7
|
+
import { age } from "./labels.ts";
|
|
8
|
+
import { openAdd } from "./add-project.ts";
|
|
9
|
+
import { cardHref, projName, railData, stateOf, titleOf, wsHref, wsLabel, wsOfCard } from "./workspace.ts";
|
|
10
|
+
import { match, type Item } from "./search-match.ts";
|
|
11
|
+
import { leaves, wsKey } from "./ws-tabs.ts";
|
|
12
|
+
|
|
13
|
+
// The pages that can open a thing in place answer this event and cancel it.
|
|
14
|
+
const ask = (name: string, detail: any) => !dispatchEvent(new CustomEvent(name, { cancelable: true, detail }));
|
|
15
|
+
// A menu entry's own click: in place on the board, a page load elsewhere.
|
|
16
|
+
const page = (v: string, href: string) => () => {
|
|
17
|
+
const a = document.querySelector<HTMLElement>(`.rail a.it[data-view="${v}"]`);
|
|
18
|
+
a ? a.click() : (location.href = href);
|
|
19
|
+
};
|
|
20
|
+
const openWs = (dir: string, ws: string) => {
|
|
21
|
+
if (!ask("kz-open-ws", { dir, ws })) location.href = wsHref(dir, ws);
|
|
22
|
+
};
|
|
23
|
+
// The run view's saved layouts (run-view.ts keeps them here per workspace).
|
|
24
|
+
const layouts = (): Record<string, any> => {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(localStorage.getItem("kz-runtabs") || "{}");
|
|
27
|
+
} catch {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
// A tab: the board opens it in place; elsewhere its screen is chosen in storage, then the workspace loads.
|
|
32
|
+
const openTab = (dir: string, ws: string, id: string) => {
|
|
33
|
+
if (ask("kz-open-tab", { dir, ws, id })) return;
|
|
34
|
+
const all = layouts(),
|
|
35
|
+
s = all[wsKey(dir, ws)],
|
|
36
|
+
sc = s?.screens?.find((x) => leaves(x.tree).includes(id));
|
|
37
|
+
if (sc)
|
|
38
|
+
try {
|
|
39
|
+
s.on = sc.id;
|
|
40
|
+
localStorage.setItem("kz-runtabs", JSON.stringify(all));
|
|
41
|
+
} catch {}
|
|
42
|
+
location.href = wsHref(dir, ws);
|
|
43
|
+
};
|
|
44
|
+
// The run view's own tabs worth jumping to; agent tabs are listed with the terminals.
|
|
45
|
+
const TAB_KINDS = ["local", "preview", "note", "history", "shell"];
|
|
46
|
+
const browsed = (k: string) => {
|
|
47
|
+
try {
|
|
48
|
+
return localStorage.getItem("kz-browse:" + k)?.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
49
|
+
} catch {}
|
|
50
|
+
};
|
|
51
|
+
const ICO = {
|
|
52
|
+
ws: '<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"/>',
|
|
53
|
+
run: '<path d="M5 4l14 8-14 8z"/>',
|
|
54
|
+
idea: '<path d="M9 18h6M10 21h4M12 3a6 6 0 0 0-4 10.5c.7.7 1 1.5 1 2.5h6c0-1 .3-1.8 1-2.5A6 6 0 0 0 12 3z"/>',
|
|
55
|
+
chat: '<path d="M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z"/>',
|
|
56
|
+
term: '<path d="M4 17l6-5-6-5M12 19h8"/>',
|
|
57
|
+
proj: '<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>',
|
|
58
|
+
page: '<rect x="4" y="4" width="16" height="16" rx="2"/><path d="M4 9h16"/>',
|
|
59
|
+
act: '<path d="M13 3L5 14h6l-1 7 8-11h-6z"/>',
|
|
60
|
+
tab: '<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 9h8V5"/>',
|
|
61
|
+
plus: '<path d="M12 5v14M5 12h14"/>',
|
|
62
|
+
search: '<circle cx="11" cy="11" r="7"/><path d="M20 20l-4-4"/>',
|
|
63
|
+
};
|
|
64
|
+
const svg = (k: string) => raw(`<svg viewBox="0 0 24 24" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${ICO[k]}</g></svg>`);
|
|
65
|
+
|
|
66
|
+
let chats: any[] = [];
|
|
67
|
+
function items(): Item[] {
|
|
68
|
+
const { cards, projects = [], agents = [] } = railData();
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
const cur = new URLSearchParams(location.search);
|
|
71
|
+
// The workspace open now: named by the address, or the one holding the run it names.
|
|
72
|
+
const curRun = cur.get("id") && cards.find((c) => c.kind === "run" && c.state === cur.get("dir") && c.id === cur.get("id"));
|
|
73
|
+
const curWs = cur.get("ws") ?? (curRun ? wsOfCard(curRun, projects) : null);
|
|
74
|
+
const out: Item[] = [];
|
|
75
|
+
const saved = layouts();
|
|
76
|
+
// Workspaces, the one open now first; then by their latest run.
|
|
77
|
+
const latest = new Map<string, number>();
|
|
78
|
+
for (const c of cards) {
|
|
79
|
+
const k = c.state + "\0" + wsOfCard(c, projects);
|
|
80
|
+
latest.set(k, Math.max(latest.get(k) ?? 0, c.moved ?? 0));
|
|
81
|
+
}
|
|
82
|
+
for (const p of projects) {
|
|
83
|
+
const name = projName(p.dir, projects);
|
|
84
|
+
for (const w of p.workspaces ?? []) {
|
|
85
|
+
const here = cur.get("dir") === p.dir && curWs === w.path;
|
|
86
|
+
const at = latest.get(p.dir + "\0" + w.path);
|
|
87
|
+
out.push({
|
|
88
|
+
group: here ? "Current" : "Workspaces",
|
|
89
|
+
title: wsLabel(w),
|
|
90
|
+
sub: name,
|
|
91
|
+
when: at ? age(at, now) : undefined,
|
|
92
|
+
hay: `${wsLabel(w)} ${name} ${w.path} workspace`,
|
|
93
|
+
at: here ? Infinity : at ?? 0,
|
|
94
|
+
ico: "ws",
|
|
95
|
+
act: () => openWs(p.dir, w.path),
|
|
96
|
+
});
|
|
97
|
+
const k = wsKey(p.dir, w.path),
|
|
98
|
+
lay = saved[k];
|
|
99
|
+
for (const t of lay?.tabs ?? []) {
|
|
100
|
+
if (!TAB_KINDS.includes(t.kind) || lay.hidden?.includes(t.id)) continue;
|
|
101
|
+
const title = (t.kind === "local" && browsed(k)) || t.title;
|
|
102
|
+
out.push({ group: "Tabs", title, sub: `${wsLabel(w)} · ${name}`, hay: `${title} ${t.title} ${t.kind} ${t.note ?? ""} ${wsLabel(w)} ${name} tab`, ico: "tab", act: () => openTab(p.dir, w.path, t.id) });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
out.push({ group: "Projects", title: name, hay: `${name} ${p.dir} project`, ico: "proj", act: () => {
|
|
106
|
+
const main = p.workspaces?.find((w) => w.main) ?? p.workspaces?.[0];
|
|
107
|
+
main ? openWs(p.dir, main.path) : page("board", "/?view=board")();
|
|
108
|
+
} });
|
|
109
|
+
}
|
|
110
|
+
// Runs and ideas, not archived.
|
|
111
|
+
for (const c of cards.filter((c) => !c.archived)) {
|
|
112
|
+
const st = stateOf(c);
|
|
113
|
+
out.push({
|
|
114
|
+
group: c.kind === "run" ? "Runs" : "Ideas",
|
|
115
|
+
title: titleOf(c) || c.id,
|
|
116
|
+
sub: projName(c.state, projects),
|
|
117
|
+
when: c.moved ? age(c.moved, now) : undefined,
|
|
118
|
+
hay: `${titleOf(c)} ${c.id ?? ""} ${c.text ?? ""} ${projName(c.state, projects)} ${st}`,
|
|
119
|
+
at: c.moved ?? 0,
|
|
120
|
+
dot: st,
|
|
121
|
+
ico: c.kind === "run" ? "run" : "idea",
|
|
122
|
+
act: () => {
|
|
123
|
+
if (!ask("kz-open-card", { dir: c.state, id: c.kind === "run" ? c.id : undefined, text: c.text })) location.href = cardHref(c);
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
for (const c of chats) {
|
|
128
|
+
// updated is an ISO date string.
|
|
129
|
+
const at = Date.parse(c.updated) || 0;
|
|
130
|
+
out.push({
|
|
131
|
+
group: "Chats & terminals",
|
|
132
|
+
title: c.title || "Chat",
|
|
133
|
+
sub: c.project ? projName(c.project, projects) : undefined,
|
|
134
|
+
when: at ? age(at, now) : undefined,
|
|
135
|
+
hay: `${c.title} chat ${c.project ?? ""}`,
|
|
136
|
+
at,
|
|
137
|
+
dot: c.busy ? "build" : undefined,
|
|
138
|
+
ico: "chat",
|
|
139
|
+
act: () => {
|
|
140
|
+
try {
|
|
141
|
+
sessionStorage.setItem("kz-chat", c.id);
|
|
142
|
+
} catch {}
|
|
143
|
+
page("home", "/")();
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
for (const a of agents)
|
|
148
|
+
out.push({
|
|
149
|
+
group: "Chats & terminals",
|
|
150
|
+
title: a.name || a.agent || "Terminal",
|
|
151
|
+
sub: projName(a.dir, projects),
|
|
152
|
+
hay: `${a.name} ${a.agent ?? ""} ${a.run ?? ""} ${a.last ?? ""} ${projName(a.dir, projects)} terminal agent`,
|
|
153
|
+
at: a.at ?? a.born ?? 0,
|
|
154
|
+
dot: a.asking ? "wait" : a.busy ? "build" : "done",
|
|
155
|
+
ico: "term",
|
|
156
|
+
act: () => {
|
|
157
|
+
if (!ask("kz-open-term", { dir: a.dir, ws: a.ws, key: a.key })) location.href = wsHref(a.dir, a.ws ?? "");
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
// Pages and actions. Each clicks the side menu's own control, so it behaves the same.
|
|
161
|
+
const click = (id: string) => () => $(id)?.click();
|
|
162
|
+
const acts: [string, string, () => void, string?][] = [
|
|
163
|
+
["Home", "page", page("home", "/"), "chat"],
|
|
164
|
+
["Icebox", "page", page("sources", "/?view=icebox"), "requests sources gathered"],
|
|
165
|
+
["Ideas", "page", page("ideas", "/?view=ideas"), "backlog"],
|
|
166
|
+
["Board", "page", page("board", "/?view=board"), "kanban runs"],
|
|
167
|
+
["Notes", "page", () => (location.href = "/notebook"), "notebook docs"],
|
|
168
|
+
["Settings", "page", page("settings", "/?view=settings"), "preferences config"],
|
|
169
|
+
["New idea", "act", () => ($("newtop") ? $("newtop").click() : (location.href = "/?view=board")), "create add run"],
|
|
170
|
+
["Add a project", "act", () => openAdd({ dir: null }), "clone folder create workspace"],
|
|
171
|
+
["Toggle theme", "act", click("themet"), "dark light"],
|
|
172
|
+
["Collapse or expand menu", "act", click("fold"), "sidebar rail"],
|
|
173
|
+
["Keyboard shortcuts", "act", click("kbd"), "keys help"],
|
|
174
|
+
["Report an issue", "act", () => open("/issue", "_blank", "noopener"), "bug feedback"],
|
|
175
|
+
];
|
|
176
|
+
for (const [title, ico, act, kw] of acts) out.push({ group: "Actions", title, hay: `${title} ${kw ?? ""}`, ico, act });
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const ORDER = ["Current", "Workspaces", "Tabs", "Chats & terminals", "Runs", "Ideas", "Projects", "Actions"];
|
|
181
|
+
// With nothing typed each group shows its most recent few, as Orca's does.
|
|
182
|
+
const CAP = { Workspaces: 5, Tabs: 4, "Chats & terminals": 5, Runs: 5, Ideas: 3, Projects: 5 };
|
|
183
|
+
|
|
184
|
+
let dl: HTMLDialogElement | null = null;
|
|
185
|
+
let shown: Item[] = [];
|
|
186
|
+
let sel = 0;
|
|
187
|
+
function draw() {
|
|
188
|
+
const q = (dl!.querySelector("input") as HTMLInputElement).value;
|
|
189
|
+
const all = items();
|
|
190
|
+
const hit = q.trim() ? match(all, q) : all.slice().sort((a, b) => (b.at ?? 0) - (a.at ?? 0));
|
|
191
|
+
shown = [];
|
|
192
|
+
// Typed: the group holding the best match comes first, so Enter takes it.
|
|
193
|
+
const order = q.trim() ? [...new Set(hit.map((i) => i.group))] : ORDER;
|
|
194
|
+
for (const g of order) {
|
|
195
|
+
const rows = hit.filter((i) => i.group === g);
|
|
196
|
+
shown.push(...rows.slice(0, q.trim() ? 8 : CAP[g] ?? rows.length));
|
|
197
|
+
}
|
|
198
|
+
// Orca offers to create what was typed; here that is a new idea.
|
|
199
|
+
if (q.trim())
|
|
200
|
+
shown.push({ group: "Create", title: `New idea "${q.trim()}"`, hay: "", ico: "plus", act: () => newIdeaWith(q.trim()) });
|
|
201
|
+
sel = Math.min(sel, shown.length - 1);
|
|
202
|
+
const list = dl!.querySelector(".gs-list")!;
|
|
203
|
+
let g = "";
|
|
204
|
+
list.innerHTML = String(
|
|
205
|
+
html`${shown.map((i, n) => {
|
|
206
|
+
const head = i.group !== g ? ((g = i.group), html`<div class="gs-h" role="presentation">${i.group}</div>`) : "";
|
|
207
|
+
return html`${head}<div class="gs-i" role="option" id="gs-${n}" data-n="${n}" aria-selected="${String(n === sel)}">${svg(i.ico)}${i.dot ? html`<span class="si ${i.dot}"></span>` : ""}<span class="gs-t">${i.title}</span>${i.sub ? html`<span class="gs-s">${i.sub}</span>` : ""}${i.when ? html`<span class="gs-w">${i.when}</span>` : ""}</div>`;
|
|
208
|
+
})}${shown.length === 1 && q.trim() ? html`<div class="gs-none">No results</div>` : ""}`,
|
|
209
|
+
);
|
|
210
|
+
mark(sel);
|
|
211
|
+
dl!.querySelector(".gs-live")!.textContent = `${shown.length} result${shown.length === 1 ? "" : "s"} found`;
|
|
212
|
+
}
|
|
213
|
+
// Moves the selection without rebuilding the list.
|
|
214
|
+
function mark(n: number) {
|
|
215
|
+
dl!.querySelector(`#gs-${sel}`)?.setAttribute("aria-selected", "false");
|
|
216
|
+
sel = n;
|
|
217
|
+
const r = dl!.querySelector(`#gs-${n}`);
|
|
218
|
+
r?.setAttribute("aria-selected", "true");
|
|
219
|
+
dl!.querySelector("input")!.setAttribute("aria-activedescendant", "gs-" + n);
|
|
220
|
+
r?.scrollIntoView({ block: "nearest" });
|
|
221
|
+
}
|
|
222
|
+
function newIdeaWith(text: string) {
|
|
223
|
+
if (!$("newtop")) return void (location.href = "/?view=board");
|
|
224
|
+
$("newtop").click();
|
|
225
|
+
const t = document.querySelector<HTMLTextAreaElement>("dialog[open] textarea");
|
|
226
|
+
if (t) (t.value = text), t.dispatchEvent(new Event("input", { bubbles: true }));
|
|
227
|
+
}
|
|
228
|
+
function pick(n: number) {
|
|
229
|
+
const i = shown[n];
|
|
230
|
+
if (!i) return;
|
|
231
|
+
dl!.close();
|
|
232
|
+
i.act();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function openSearch() {
|
|
236
|
+
if (dl) return dl.querySelector("input")!.focus();
|
|
237
|
+
dl = document.createElement("dialog");
|
|
238
|
+
dl.className = "gs";
|
|
239
|
+
dl.setAttribute("aria-label", "Search");
|
|
240
|
+
dl.innerHTML = String(
|
|
241
|
+
html`<div class="gs-box"><div class="gs-q">${svg("search")}<input type="text" placeholder="Search" aria-label="Search" role="combobox" aria-expanded="true" aria-controls="gs-list" autocomplete="off" spellcheck="false"></div><div class="gs-list" id="gs-list" role="listbox"></div><span class="gs-live" role="status" aria-live="polite"></span></div>`,
|
|
242
|
+
);
|
|
243
|
+
document.body.append(dl);
|
|
244
|
+
const q = dl.querySelector("input")!;
|
|
245
|
+
sel = 0;
|
|
246
|
+
q.oninput = () => ((sel = 0), draw());
|
|
247
|
+
q.onkeydown = (e) => {
|
|
248
|
+
const d = { ArrowDown: 1, ArrowUp: -1 }[e.key] ?? (e.ctrlKey && e.key === "n" ? 1 : e.ctrlKey && e.key === "p" ? -1 : 0);
|
|
249
|
+
if (d) {
|
|
250
|
+
e.preventDefault();
|
|
251
|
+
mark((sel + d + shown.length) % shown.length);
|
|
252
|
+
} else if (e.key === "Enter") {
|
|
253
|
+
e.preventDefault();
|
|
254
|
+
pick(sel);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const list = dl.querySelector<HTMLElement>(".gs-list")!;
|
|
258
|
+
list.onclick = (e) => {
|
|
259
|
+
const r = (e.target as Element).closest<HTMLElement>(".gs-i");
|
|
260
|
+
if (r) pick(+r.dataset.n!);
|
|
261
|
+
};
|
|
262
|
+
list.onpointermove = (e) => {
|
|
263
|
+
const r = (e.target as Element).closest<HTMLElement>(".gs-i");
|
|
264
|
+
if (r && +r.dataset.n! !== sel) mark(+r.dataset.n!);
|
|
265
|
+
};
|
|
266
|
+
dl.onclick = (e) => e.target === dl && dl!.close();
|
|
267
|
+
dl.onclose = () => (dl!.remove(), (dl = null));
|
|
268
|
+
dl.showModal();
|
|
269
|
+
draw();
|
|
270
|
+
// Chats live behind one fetch; the list redraws when they land.
|
|
271
|
+
fetch("/chats")
|
|
272
|
+
.then((r) => r.json())
|
|
273
|
+
.then((d) => {
|
|
274
|
+
chats = d.chats ?? [];
|
|
275
|
+
if (dl) draw();
|
|
276
|
+
})
|
|
277
|
+
.catch(() => {});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const CSS = `dialog.gs{border:0;padding:0;margin:14vh auto auto;background:none;width:min(560px,calc(100vw - 32px));color:var(--ink);overflow:visible}
|
|
281
|
+
dialog.gs::backdrop{background:rgb(0 0 0/.35)}
|
|
282
|
+
.gs-box{display:flex;flex-direction:column;max-height:min(480px,72vh);background:var(--bg);border:1px solid var(--line);border-radius:10px;box-shadow:0 16px 40px rgb(0 0 0/.25);overflow:hidden}
|
|
283
|
+
.gs-q{display:flex;align-items:center;gap:8px;padding:0 12px;border-bottom:1px solid var(--line)}
|
|
284
|
+
.gs-q svg{width:15px;height:15px;color:var(--dim);flex:none}
|
|
285
|
+
.gs-q input{flex:1;min-width:0;height:40px;border:0;outline:0;background:none;color:var(--ink);font:inherit;font-size:var(--fs-l,14px)}
|
|
286
|
+
.gs-list{flex:1;overflow:auto;padding:4px}
|
|
287
|
+
.gs-h{padding:10px 8px 4px;font-size:var(--fs-xs,11px);color:var(--dim)}
|
|
288
|
+
.gs-i{display:flex;align-items:center;gap:8px;height:var(--btn-s,32px);padding:0 var(--padx,8px);border-radius:var(--r-s,4px);cursor:pointer;font-size:var(--fs,13px)}
|
|
289
|
+
.gs-i[aria-selected=true]{background:var(--hover)}
|
|
290
|
+
.gs-i svg{width:var(--ico,14px);height:var(--ico,14px);color:var(--dim);flex:none}
|
|
291
|
+
.gs-i .si{flex:none}
|
|
292
|
+
.gs-t{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
|
|
293
|
+
.gs-s{color:var(--dim);font-size:var(--fs-s,12px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0;flex:0 1 auto}
|
|
294
|
+
.gs-w{margin-left:auto;padding-left:8px;color:var(--dim);font-size:var(--fs-xs,11px);flex:none}
|
|
295
|
+
.gs-none{padding:14px 8px;text-align:center;color:var(--dim);font-size:var(--fs-s,12px)}
|
|
296
|
+
.gs-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
|
|
297
|
+
@media(max-width:640px){.rail a.it.gs-it{display:none}}`;
|
|
298
|
+
|
|
299
|
+
export function initSearch() {
|
|
300
|
+
const st = document.createElement("style");
|
|
301
|
+
st.textContent = CSS;
|
|
302
|
+
document.head.append(st);
|
|
303
|
+
const mac = /Mac|iP(hone|ad)/.test(navigator.platform);
|
|
304
|
+
const it = $("gsearch");
|
|
305
|
+
if (it) it.onclick = (e) => (e.preventDefault(), openSearch());
|
|
306
|
+
// Opened before the menu's data came in: fill in as it lands.
|
|
307
|
+
addEventListener("kz-rail", () => dl && draw());
|
|
308
|
+
// Ctrl/Cmd+K anywhere, and Orca's own Cmd+J (Ctrl+Shift+J is the browser's console).
|
|
309
|
+
addEventListener(
|
|
310
|
+
"keydown",
|
|
311
|
+
(e) => {
|
|
312
|
+
// A terminal keeps its keys: Ctrl+K there is the shell's kill-line.
|
|
313
|
+
if ((e.target as Element)?.closest?.(".xterm")) return;
|
|
314
|
+
const mod = mac ? e.metaKey : e.ctrlKey;
|
|
315
|
+
const k = e.key.toLowerCase();
|
|
316
|
+
if (mod && !e.altKey && ((k === "k" && !e.shiftKey) || (mac && k === "j" && !e.shiftKey))) {
|
|
317
|
+
e.preventDefault();
|
|
318
|
+
e.stopPropagation();
|
|
319
|
+
dl ? dl.close() : openSearch();
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
true,
|
|
323
|
+
);
|
|
324
|
+
}
|
package/web/board/store.ts
CHANGED
|
@@ -19,6 +19,8 @@ export const store = {
|
|
|
19
19
|
// The Ideas column's severity menu, on its Backlog tab.
|
|
20
20
|
sevMenu: false,
|
|
21
21
|
wantTerm: null,
|
|
22
|
+
// The terminal a launch just opened (its pty key), selected in the run workspace once its tab exists.
|
|
23
|
+
wantPty: null as null | { key: string; at: number },
|
|
22
24
|
// Live shells from GET /shells (the footer reads them): tiles on the Terminal page.
|
|
23
25
|
shells: [] as { key: string; dir: string; title: string; agent: string }[],
|
|
24
26
|
// The settings search survives the re-render each save does; the gear button starts it empty.
|
package/web/board/workspace.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { store } from "./store.ts";
|
|
|
7
7
|
import { $, html, modal, raw } from "./dom.ts";
|
|
8
8
|
import { age, need } from "./labels.ts";
|
|
9
9
|
import { openAdd } from "./add-project.ts";
|
|
10
|
+
import { initSearch } from "./search.ts";
|
|
10
11
|
import { agentsHtml, dueWord, forgetAgents, gitDue, settleIn, toggleOpen, wsAgents, type Agent } from "./ws-tabs.ts";
|
|
11
12
|
|
|
12
13
|
const DAY = 864e5;
|
|
@@ -83,6 +84,73 @@ const folded: Set<string> = (() => {
|
|
|
83
84
|
return new Set();
|
|
84
85
|
}
|
|
85
86
|
})();
|
|
87
|
+
// Pinned worktrees (dir\0ws), kept per browser.
|
|
88
|
+
const pins: Set<string> = (() => {
|
|
89
|
+
try {
|
|
90
|
+
return new Set(JSON.parse(localStorage.getItem("kz-ws-pins") || "[]"));
|
|
91
|
+
} catch {
|
|
92
|
+
return new Set();
|
|
93
|
+
}
|
|
94
|
+
})();
|
|
95
|
+
// The right-click menu on a worktree row: update, copy path, copy name, pin, delete.
|
|
96
|
+
function wsMenu(e: MouseEvent, a: HTMLElement) {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
document.getElementById("wsmenu")?.remove();
|
|
99
|
+
const dir = a.dataset.dir!, ws = a.dataset.ws!, key = dir + "\0" + ws;
|
|
100
|
+
const w = last.projects?.find((p) => p.dir === dir)?.workspaces?.find((x) => x.path === ws);
|
|
101
|
+
if (!w) return;
|
|
102
|
+
const name = wsLabel(w);
|
|
103
|
+
const say = (m: string) => {
|
|
104
|
+
const t = $("toast");
|
|
105
|
+
t.textContent = m;
|
|
106
|
+
t.classList.add("on");
|
|
107
|
+
setTimeout(() => t.classList.remove("on"), 4000);
|
|
108
|
+
};
|
|
109
|
+
const copy = (text: string) => navigator.clipboard.writeText(text).then(() => say("Copied"), () => say("Could not copy"));
|
|
110
|
+
const op = async (o: string) => {
|
|
111
|
+
say(o === "update" ? "Updating…" : "Deleting…");
|
|
112
|
+
const r = await fetch("/workspace", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ dir, ws, op: o }) }).catch(() => null);
|
|
113
|
+
const j = await r?.json().catch(() => ({}));
|
|
114
|
+
say(r?.ok ? (o === "update" ? j.out || "Updated" : "Deleted") : j?.error || j?.why || "Failed");
|
|
115
|
+
};
|
|
116
|
+
const items: [string, () => void][] = [
|
|
117
|
+
...(w.main ? [] : ([["Update", () => op("update")]] as [string, () => void][])),
|
|
118
|
+
["Copy path", () => copy(ws)],
|
|
119
|
+
["Copy worktree name", () => copy(name)],
|
|
120
|
+
[pins.has(key) ? "Unpin" : "Pin", () => {
|
|
121
|
+
pins.has(key) ? pins.delete(key) : pins.add(key);
|
|
122
|
+
try {
|
|
123
|
+
localStorage.setItem("kz-ws-pins", JSON.stringify([...pins]));
|
|
124
|
+
} catch {}
|
|
125
|
+
drawList();
|
|
126
|
+
}],
|
|
127
|
+
...(w.main ? [] : ([["Delete", async () => {
|
|
128
|
+
const dl = modal(html`<div class="gdis" style="display:flex;flex-direction:column;gap:12px">
|
|
129
|
+
<b>Delete worktree "${name}"?</b>
|
|
130
|
+
<p>Removes the folder. Refused while it has uncommitted changes. The branch stays.</p>
|
|
131
|
+
<div class="gpath" style="font:12px monospace;overflow-wrap:anywhere">${ws}</div>
|
|
132
|
+
<div class="row"><button class="btn" value="no">Cancel</button><button class="btn danger" value="yes">Delete</button></div>
|
|
133
|
+
</div>`);
|
|
134
|
+
dl.addEventListener("close", () => dl.returnValue === "yes" && op("delete"));
|
|
135
|
+
}]] as [string, () => void][])),
|
|
136
|
+
];
|
|
137
|
+
const m = document.createElement("div");
|
|
138
|
+
m.id = "wsmenu";
|
|
139
|
+
m.style.cssText = `position:fixed;left:${Math.min(e.clientX, innerWidth - 190)}px;top:${Math.min(e.clientY, innerHeight - items.length * 34 - 16)}px;z-index:50;min-width:170px;padding:6px;background:var(--bg-2);border:1px solid var(--line);border-radius:var(--r);box-shadow:0 8px 24px #0004;display:flex;flex-direction:column`;
|
|
140
|
+
for (const [label, fn] of items) {
|
|
141
|
+
const b = document.createElement("button");
|
|
142
|
+
b.type = "button";
|
|
143
|
+
b.textContent = label;
|
|
144
|
+
b.style.cssText = "text-align:left;padding:7px 10px;font-size:13px;color:var(--ink);border-radius:var(--r-s)";
|
|
145
|
+
b.onmouseenter = () => (b.style.background = "var(--hover)");
|
|
146
|
+
b.onmouseleave = () => (b.style.background = "");
|
|
147
|
+
b.onclick = () => (m.remove(), fn());
|
|
148
|
+
m.append(b);
|
|
149
|
+
}
|
|
150
|
+
document.body.append(m);
|
|
151
|
+
const off = () => (m.remove(), removeEventListener("click", off), removeEventListener("keydown", off));
|
|
152
|
+
setTimeout(() => (addEventListener("click", off), addEventListener("keydown", off)));
|
|
153
|
+
}
|
|
86
154
|
// Workspace cards with their agent list open (dir\0ws -> true), kept per browser.
|
|
87
155
|
const wsOpen: Record<string, true> = (() => {
|
|
88
156
|
try {
|
|
@@ -105,6 +173,16 @@ function fold(dir: string) {
|
|
|
105
173
|
} catch {}
|
|
106
174
|
drawList();
|
|
107
175
|
}
|
|
176
|
+
const svg = (d: string) => `<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
|
|
177
|
+
const FA_OPEN = svg("M4 3l4 3 4-3M4 13l4-3 4 3");
|
|
178
|
+
const FA_SHUT = svg("M4 6l4-3 4 3M4 10l4 3 4-3");
|
|
179
|
+
const foldAll = (shut: boolean) => {
|
|
180
|
+
for (const d of last.projects?.map((p) => p.dir) ?? []) shut ? folded.add(d) : folded.delete(d);
|
|
181
|
+
try {
|
|
182
|
+
localStorage.setItem("kz-rail-folded", JSON.stringify([...folded]));
|
|
183
|
+
} catch {}
|
|
184
|
+
drawList();
|
|
185
|
+
};
|
|
108
186
|
// A card's workspace row: its own (a run's worktree) when the project lists it, else the
|
|
109
187
|
// main checkout's, so a run whose worktree is gone, an idea or an old run never vanishes.
|
|
110
188
|
export function wsOfCard(c, projects = last.projects) {
|
|
@@ -115,6 +193,7 @@ export const wsHref = (dir, ws) => `/?view=ws&dir=${encodeURIComponent(dir)}&ws=
|
|
|
115
193
|
export const RANK = { wait: 0, plan: 1, build: 2, review: 3, stalled: 4, idle: 5, done: 6, aband: 7 };
|
|
116
194
|
export const folderOf = (w) => w.path.split(/[\\/]/).pop() || w.path;
|
|
117
195
|
// A worktree's mark on line 2 of its card.
|
|
196
|
+
const PIN = html`<svg viewBox="0 0 24 24" aria-label="Pinned" style="width:12px;height:12px;flex:none;margin-left:4px;color:var(--accent)"><path d="M12 17v5M9 3h6l-1 6 3 3v2H7v-2l3-3z" fill="currentColor" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`;
|
|
118
197
|
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
198
|
let settleT: ReturnType<typeof setTimeout> | undefined;
|
|
120
199
|
let drawn = "";
|
|
@@ -139,7 +218,9 @@ function drawList() {
|
|
|
139
218
|
const rows = p.workspaces
|
|
140
219
|
.map((w) => ({ w, cs: by.get(p.dir + "\0" + w.path) ?? [] }))
|
|
141
220
|
// 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"])
|
|
221
|
+
.filter(({ cs }) => filt[cs.length && cs.every((c) => kindOf(c) === "done") ? "done" : "active"])
|
|
222
|
+
// Pinned worktrees first (a stable sort keeps the rest in git's order).
|
|
223
|
+
.sort((a, b) => +pins.has(p.dir + "\0" + b.w.path) - +pins.has(p.dir + "\0" + a.w.path));
|
|
143
224
|
return { p, rows, top: Math.min(9, ...rows.map((r) => top(r.cs))) };
|
|
144
225
|
})
|
|
145
226
|
.filter((g) => g.rows.length)
|
|
@@ -170,13 +251,17 @@ function drawList() {
|
|
|
170
251
|
const st0 = cs.length ? stateOf([...cs].sort((a, b) => RANK[stateOf(a)] - RANK[stateOf(b)])[0]) : "";
|
|
171
252
|
const st = st0 === "wait" || rows[0]?.st === "asking" ? "wait" : rows.some((r) => r.st === "working") ? "build" : st0 || (rows.length ? "done" : "");
|
|
172
253
|
// 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
|
|
254
|
+
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>${pins.has(dir + "\0" + w.path) ? PIN : ""}</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
255
|
})}`;
|
|
175
256
|
})
|
|
176
257
|
.join("") || `<div class="none">No projects</div>`;
|
|
177
258
|
// The same markup is not written again: hover and focus stay, and a tick that changed nothing costs no layout.
|
|
178
259
|
if (out !== drawn) box.innerHTML = drawn = out;
|
|
179
260
|
markCurrent();
|
|
261
|
+
box.oncontextmenu = (e) => {
|
|
262
|
+
const a = (e.target as HTMLElement).closest<HTMLElement>("a.row.ws");
|
|
263
|
+
if (a) wsMenu(e, a);
|
|
264
|
+
};
|
|
180
265
|
box.onclick = (e) => {
|
|
181
266
|
const t = e.target as HTMLElement;
|
|
182
267
|
const term = t.closest<HTMLElement>("[data-term]");
|
|
@@ -251,15 +336,20 @@ function drawPop(all: Set<string>) {
|
|
|
251
336
|
const dirs = [...all];
|
|
252
337
|
const shown = dirs.filter((d) => projName(d, last.projects).toLowerCase().includes(pq.toLowerCase()));
|
|
253
338
|
const box = (on: boolean, attrs: string, label) => html`<label class="pfrow"><input type="checkbox" ${raw(attrs)}${on ? raw(" checked") : ""}>${label}</label>`;
|
|
339
|
+
const allShut = dirs.length > 0 && dirs.every((d) => folded.has(d));
|
|
254
340
|
const had = document.activeElement?.id;
|
|
255
341
|
p.innerHTML = String(
|
|
256
|
-
html`${dirs.length > 6 ? html`<input class="sel" id="pfq" placeholder="Search projects…" aria-label="Search projects" value="${pq}" autocomplete="off" spellcheck="false">` : ""}
|
|
342
|
+
html`${dirs.length > 6 ? html`<input class="sel" id="pfq" placeholder="Search projects…" aria-label="Search projects" value="${pq}" autocomplete="off" spellcheck="false">` : ""}<div class="pfall">${box(!filt.dirs.length, 'data-all="1"', "All projects")}<button type="button" class="pfb" data-fa="${allShut ? "0" : "1"}" title="${allShut ? "Expand all" : "Collapse all"}" aria-label="${allShut ? "Expand all projects" : "Collapse all projects"}">${raw(allShut ? FA_OPEN : FA_SHUT)}</button></div>${shown.map((d) => box(filt.dirs.includes(d), `data-dir="${encodeURIComponent(d)}"`, html`${logo(d, projName(d, last.projects), last.projects)}<span>${projName(d, last.projects)}</span>`))}<div class="pfh">Show</div>${(["active", "done"] as const).map((k) => box(filt[k], `data-k="${k}"`, { active: "Active runs", done: "Done (last day)" }[k]))}`,
|
|
257
343
|
);
|
|
258
344
|
if (had === "pfq") {
|
|
259
345
|
const q = $("pfq") as HTMLInputElement;
|
|
260
346
|
q.focus();
|
|
261
347
|
q.setSelectionRange(pq.length, pq.length);
|
|
262
348
|
}
|
|
349
|
+
p.onclick = (e) => {
|
|
350
|
+
const b = (e.target as HTMLElement).closest("[data-fa]") as HTMLElement | null;
|
|
351
|
+
if (b) foldAll(b.dataset.fa === "1");
|
|
352
|
+
};
|
|
263
353
|
p.oninput = (e) => {
|
|
264
354
|
const t = e.target as HTMLInputElement;
|
|
265
355
|
if (t.id === "pfq") pq = t.value;
|
|
@@ -285,6 +375,7 @@ const syncSpin = () =>
|
|
|
285
375
|
if (a.animationName?.startsWith("si-") && a.startTime !== 0) a.startTime = 0;
|
|
286
376
|
});
|
|
287
377
|
export function initRail() {
|
|
378
|
+
initSearch();
|
|
288
379
|
let queued = false;
|
|
289
380
|
const hasSi = (n: any) => n.nodeType === 1 && (n.classList.contains("si") || n.querySelector(".si"));
|
|
290
381
|
new MutationObserver((rs) => {
|
package/web/board/ws-board-ui.ts
CHANGED
|
@@ -43,7 +43,18 @@ export function initWsBoard(render: () => void) {
|
|
|
43
43
|
rerender = render;
|
|
44
44
|
addEventListener("kz-view", () => (syncMode(), drawToggle()));
|
|
45
45
|
addEventListener("kz-state", drawToggle);
|
|
46
|
-
|
|
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
|
+
});
|
|
47
58
|
$("board").addEventListener("click", (e: MouseEvent) => {
|
|
48
59
|
const a = (e.target as Element).closest?.("a.wcard") as HTMLAnchorElement;
|
|
49
60
|
if (!a || e.ctrlKey || e.metaKey || e.shiftKey || e.button) return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect, test } from "bun:test";
|
|
2
|
-
import { agentStatus, agentsHtml, forgetAgents, lineOf, settleIn, toggleOpen, wsAgents, SETTLE_MS, awaiting, dueWord, chosen, loopbackUrl, toOpen, stageKeys, stageTabs, finished, historyOf, liveIn, migrate, pickable, wsKey } from "./ws-tabs.ts";
|
|
2
|
+
import { agentStatus, agentsHtml, forgetAgents, lineOf, settleIn, toggleOpen, wsAgents, SETTLE_MS, awaiting, dueWord, chosen, loopbackUrl, toOpen, stageKeys, stageTabs, finished, historyOf, liveIn, migrate, pickable, prune, wsKey } from "./ws-tabs.ts";
|
|
3
3
|
|
|
4
4
|
const run = (id: string, status: string, o: any = {}) => ({ kind: "run", state: "/p/.kaizen", id, status, moved: 1, ws: "/p", ...o });
|
|
5
5
|
const wsOf = (c) => c.ws;
|
|
@@ -169,3 +169,13 @@ test("card html: one agent has no chevron; several group chips; expanded lists r
|
|
|
169
169
|
expect(open).not.toContain("<b>");
|
|
170
170
|
expect(lineOf(rows(ag("z"))[0])).toBe("Done - Claude");
|
|
171
171
|
});
|
|
172
|
+
|
|
173
|
+
test("prune keeps a split node it drops nothing from, so a gutter drag writes to the live layout", () => {
|
|
174
|
+
const inner = { dir: "rows" as const, kids: ["b", "c"], sizes: [1, 1] };
|
|
175
|
+
const tree = { dir: "cols" as const, kids: ["a", inner], sizes: [2, 1] };
|
|
176
|
+
expect(prune(tree, () => true)).toBe(tree);
|
|
177
|
+
const cut = prune(tree, (id) => id !== "c") as any;
|
|
178
|
+
expect(cut).not.toBe(tree);
|
|
179
|
+
expect(cut.kids).toEqual(["a", "b"]);
|
|
180
|
+
expect(cut.sizes).toEqual([2, 1]);
|
|
181
|
+
});
|
package/web/board/ws-tabs.ts
CHANGED
|
@@ -16,7 +16,10 @@ export function prune(n: Node, keep: (id: string) => boolean): Node | null {
|
|
|
16
16
|
const p = prune(k, keep);
|
|
17
17
|
if (p) (kids.push(p), sizes.push(n.sizes[i] ?? 1));
|
|
18
18
|
});
|
|
19
|
-
|
|
19
|
+
if (!kids.length) return null;
|
|
20
|
+
if (kids.length === 1) return kids[0];
|
|
21
|
+
// Nothing dropped: the same node, so a drag holding it keeps writing to the live layout.
|
|
22
|
+
return kids.length === n.kids.length && kids.every((k, i) => k === n.kids[i]) ? n : { dir: n.dir, kids, sizes };
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
// A workspace's key in the saved tab layouts (localStorage kz-runtabs).
|