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
package/web/board/main.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { initContext } from "./context.ts";
|
|
|
17
17
|
import { cardHref, initFooter, initRail, markCurrent, wsHref } from "./workspace.ts";
|
|
18
18
|
import { go } from "./views.ts";
|
|
19
19
|
import { openWorkspace } from "./run-view.ts";
|
|
20
|
+
import { initOnboarding } from "./onboarding.ts";
|
|
20
21
|
|
|
21
22
|
initPanel();
|
|
22
23
|
initViews();
|
|
@@ -88,3 +89,4 @@ document.addEventListener(
|
|
|
88
89
|
},
|
|
89
90
|
true,
|
|
90
91
|
);
|
|
92
|
+
void initOnboarding();
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// First-run onboarding: one panel over the board with three steps (default agent, look,
|
|
2
|
+
// notifications), then "Add your first project". Where a user got to is kept by the board in
|
|
3
|
+
// ~/.kaizen/onboarding.json (/onboarding), so a skipped or half-done flow can be continued from the
|
|
4
|
+
// side menu's Setup row or the "Continue setup?" popup. Existing users, who have a project, never see it.
|
|
5
|
+
import { html, raw } from "./dom.ts";
|
|
6
|
+
import { openAdd } from "./add-project.ts";
|
|
7
|
+
|
|
8
|
+
type Cfg = { show: boolean; resume: boolean; step: number; total: number; default: string; installed: string[]; agents: { cmd: string; name: string }[]; install: Record<string, { command?: string; docs: string }> };
|
|
9
|
+
// The tools agent.default accepts.
|
|
10
|
+
const PICKABLE = ["claude", "codex", "agy", "opencode", "gemini"];
|
|
11
|
+
const MOD = /Mac|iP(hone|ad)/.test(navigator.platform) ? "⌘" : "Ctrl";
|
|
12
|
+
const NAMES = ["Default agent", "Appearance", "Notifications"];
|
|
13
|
+
const ASKED = "kz-onb-asked";
|
|
14
|
+
|
|
15
|
+
async function call(path: string, body?: object) {
|
|
16
|
+
try {
|
|
17
|
+
const r = await fetch(path, body ? { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) } : undefined);
|
|
18
|
+
return r.ok ? await r.json() : null;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let cfg: Cfg | null = null;
|
|
25
|
+
let dlg: HTMLDialogElement | null = null;
|
|
26
|
+
let step = 0;
|
|
27
|
+
let agent = "";
|
|
28
|
+
let theme = "system";
|
|
29
|
+
let more = false;
|
|
30
|
+
|
|
31
|
+
// The side menu's Setup row follows what is saved.
|
|
32
|
+
const row = (s: number, outcome: string | null) =>
|
|
33
|
+
(window as any).kzSetupRow?.({ resume: outcome === "skipped" || (outcome === null && s > 0), step: s, total: cfg?.total ?? 3 });
|
|
34
|
+
|
|
35
|
+
const save = (patch: { step?: number; outcome?: string | null }) => {
|
|
36
|
+
row(patch.step ?? step, patch.outcome ?? null);
|
|
37
|
+
return call("/onboarding", patch);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function storedTheme() {
|
|
41
|
+
try {
|
|
42
|
+
const t = localStorage.getItem("kz-theme");
|
|
43
|
+
return t === "light" || t === "dark" ? t : "system";
|
|
44
|
+
} catch {
|
|
45
|
+
return "system";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const notif = () => (!("Notification" in window) || !window.isSecureContext ? "na" : Notification.permission);
|
|
49
|
+
|
|
50
|
+
const preview = (k: string) => html`<span class="pv ${k}"><i class="sb"></i><i class="ln"></i><i class="ln s"></i></span>`;
|
|
51
|
+
|
|
52
|
+
function agents() {
|
|
53
|
+
const c = cfg!;
|
|
54
|
+
const all = c.agents.filter((a) => PICKABLE.includes(a.cmd));
|
|
55
|
+
const det = all.filter((a) => c.installed.includes(a.cmd)),
|
|
56
|
+
rest = all.filter((a) => !c.installed.includes(a.cmd));
|
|
57
|
+
const card = (a: { cmd: string; name: string }, off: boolean) =>
|
|
58
|
+
html`<button type="button" class="onb-card" role="radio" aria-checked="${String(agent === a.cmd)}" data-agent="${a.cmd}"><svg><use href="#c-${a.cmd}"/></svg><span>${a.name}${off ? html`<small>Not found</small>` : ""}</span><i class="ck"></i></button>`;
|
|
59
|
+
// The picked agent is not on PATH: how to install it, and that carrying on is fine.
|
|
60
|
+
const sel = all.find((a) => a.cmd === agent && !c.installed.includes(a.cmd));
|
|
61
|
+
const how = sel ? c.install?.[sel.cmd] : null;
|
|
62
|
+
const help = sel
|
|
63
|
+
? html`<div class="onb-panel"><p><b>${sel.name}</b> is not installed yet.${how?.command ? " Run this in a terminal, then open kaizen again." : ""} You can carry on now: kaizen uses it as soon as it is on your PATH.</p>${how?.command ? html`<div class="onb-cmd"><code>${how.command}</code><button type="button" class="btn" data-a="copy" data-cmd="${how.command}">Copy</button></div>` : ""}${how ? html`<a class="onb-lnk" href="${how.docs}" target="_blank" rel="noopener">Install instructions</a>` : ""}</div>`
|
|
64
|
+
: "";
|
|
65
|
+
if (!det.length)
|
|
66
|
+
return html`<p class="onb-note">No agents found on your PATH. Pick the one you will use to see how to install it, or carry on.</p><div class="onb-grid" role="radiogroup" aria-label="Default agent">${all.map((a) => card(a, true))}</div>${help}`;
|
|
67
|
+
return html`<div class="onb-lbl">Detected on your system <span>${det.length}</span></div><div class="onb-grid" role="radiogroup" aria-label="Default agent">${det.map((a) => card(a, false))}${more ? rest.map((a) => card(a, true)) : ""}</div>${rest.length ? html`<button type="button" class="onb-lnk" data-a="more">${more ? "Hide agents" : `Show ${rest.length} more ${rest.length === 1 ? "agent" : "agents"} →`}</button>` : ""}${help}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function looks() {
|
|
71
|
+
const t = (k: string, name: string, hint: string, ic: string) =>
|
|
72
|
+
html`<button type="button" class="onb-card th" role="radio" aria-checked="${String(theme === k)}" data-theme="${k}">${preview(k)}<span class="cap"><b>${raw(ic)}${name}</b><small>${hint}</small></span><i class="ck"></i></button>`;
|
|
73
|
+
const I = (d: string) => `<svg viewBox="0 0 24 24"><path d="${d}"/></svg>`;
|
|
74
|
+
return html`<div class="onb-themes" role="radiogroup" aria-label="Theme">${t("system", "System", "Match OS", I("M3 5h18v11H3zM8 20h8M12 16v4"))}${t("dark", "Dark", "Easy on the eyes", I("M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z"))}${t("light", "Light", "Bright & crisp", I("M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8zM12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M5 19l1.5-1.5M17.5 6.5 19 5"))}</div><p class="onb-note"><svg viewBox="0 0 24 24"><path d="M4 7h10M18 7h2M4 17h2M10 17h10M14 5v4M8 15v4"/></svg><span>Motion, density and more live in <b>Settings</b>.</span></p>`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function alerts() {
|
|
78
|
+
const s = notif();
|
|
79
|
+
const msg = {
|
|
80
|
+
na: "Notifications are not available at this address. Open the board at localhost or over HTTPS to turn them on.",
|
|
81
|
+
default: "Allow notifications so a run that needs you, or an agent that finishes, reaches you in another window.",
|
|
82
|
+
granted: "Notifications are on. kaizen will tell you when a run needs you or an agent is done.",
|
|
83
|
+
denied: "Notifications are blocked for this site. Allow them in your browser's site settings, then come back.",
|
|
84
|
+
}[s];
|
|
85
|
+
return html`<div class="onb-panel"><p>${msg}</p><div class="onb-row">${s === "default" ? html`<button type="button" class="btn pri" data-a="allow">Allow notifications</button>` : ""}${s === "granted" ? html`<button type="button" class="btn" data-a="test">Send test notification</button>` : ""}</div></div>`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const COPY = [
|
|
89
|
+
{ title: "Pick your default agent", sub: "kaizen works with every CLI agent. Choose the one you will reach for most. You can change it any time in Settings.", body: agents },
|
|
90
|
+
{ title: "Choose your look", sub: "Follow your system, or pick light or dark. You can change it any time.", body: looks },
|
|
91
|
+
{ title: "Set up notifications", sub: "kaizen can tell you when a run needs you or an agent is done.", body: alerts },
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
function draw() {
|
|
95
|
+
const c = cfg!,
|
|
96
|
+
last = step === c.total - 1,
|
|
97
|
+
s = COPY[step];
|
|
98
|
+
dlg!.innerHTML = String(html`
|
|
99
|
+
<div class="onb-hd"><pre class="mark"><span>█ █ ▄▀█ █ ▀▀█ █▀▀ █▄ █</span>
|
|
100
|
+
<span>█▀▄ █▀█ █ ▄▀ ██▄ █ ▀█</span>
|
|
101
|
+
<span>█ █ █ █ █ █▄▄ █▄▄ █ █</span></pre></div>
|
|
102
|
+
<div class="onb-prog">${COPY.map((_, i) => html`<button type="button" class="${i === step ? "on" : i < step ? "was" : ""}" data-s="${i}" aria-label="Go to step ${i + 1}: ${NAMES[i]}" title="${NAMES[i]}"></button>`)}<span>${step + 1} of ${c.total}</span></div>
|
|
103
|
+
<div class="onb-main">${step === 0 ? html`<small class="onb-eb">Welcome to kaizen</small>` : ""}<h2>${s.title}</h2><p class="onb-sub">${s.sub}</p>${s.body()}</div>
|
|
104
|
+
<div class="onb-ft"><button type="button" class="onb-lnk" data-a="skip">Skip to project setup</button><span></span>${step > 0 ? html`<button type="button" class="btn" data-a="back">‹ Back</button>` : ""}<button type="button" class="btn pri" data-a="next">${last ? "Add your first project" : "Continue"}<kbd>${MOD} ↵</kbd></button></div>`);
|
|
105
|
+
dlg!.querySelector<HTMLElement>(step === 0 ? ".onb-card[aria-checked=true]" : "[data-a=next]")?.focus();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function close() {
|
|
109
|
+
dlg?.close();
|
|
110
|
+
dlg?.remove();
|
|
111
|
+
dlg = null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// The agent picked on the first step is saved when the user leaves it, by Continue or by a progress bar.
|
|
115
|
+
const keepAgent = () => (step === 0 && agent ? call("/settings", { key: "agent.default", value: agent }) : null);
|
|
116
|
+
|
|
117
|
+
async function next() {
|
|
118
|
+
const c = cfg!;
|
|
119
|
+
await keepAgent();
|
|
120
|
+
if (step < c.total - 1) {
|
|
121
|
+
step++;
|
|
122
|
+
void save({ step });
|
|
123
|
+
return draw();
|
|
124
|
+
}
|
|
125
|
+
void save({ outcome: "done" });
|
|
126
|
+
close();
|
|
127
|
+
openAdd({ start: "folder" });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function ask(title: string, text: string, btns: [string, string, boolean?][]) {
|
|
131
|
+
return new Promise<string>((res) => {
|
|
132
|
+
const d = document.createElement("dialog");
|
|
133
|
+
d.className = "onb-ask";
|
|
134
|
+
d.innerHTML = String(html`<h3>${title}</h3><p>${text}</p><div class="onb-row">${btns.map(([k, l, pri]) => html`<button type="button" class="btn${pri ? " pri" : ""}" data-k="${k}">${l}</button>`)}</div>`);
|
|
135
|
+
d.oncancel = (e) => (e.preventDefault(), d.close(), d.remove(), res(btns[btns.length - 1][0]));
|
|
136
|
+
d.onclick = (e) => {
|
|
137
|
+
const k = (e.target as HTMLElement).closest<HTMLElement>("[data-k]")?.dataset.k;
|
|
138
|
+
if (k) (d.close(), d.remove(), res(k));
|
|
139
|
+
};
|
|
140
|
+
document.body.appendChild(d);
|
|
141
|
+
d.showModal();
|
|
142
|
+
d.querySelector<HTMLElement>(".pri")?.focus();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function skip() {
|
|
147
|
+
if ((await ask("Skip onboarding?", "It won't take long!", [["skip", "Skip"], ["keep", "No, keep going", true]])) !== "skip") return;
|
|
148
|
+
void save({ outcome: "skipped" });
|
|
149
|
+
close();
|
|
150
|
+
openAdd({ start: "folder" });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function open(at: number) {
|
|
154
|
+
if (dlg || !cfg) return;
|
|
155
|
+
step = Math.max(0, Math.min(cfg.total - 1, at));
|
|
156
|
+
agent = PICKABLE.includes(cfg.default) ? cfg.default : (cfg.agents.find((a) => PICKABLE.includes(a.cmd) && cfg!.installed.includes(a.cmd))?.cmd ?? "");
|
|
157
|
+
theme = storedTheme();
|
|
158
|
+
more = false;
|
|
159
|
+
dlg = document.createElement("dialog");
|
|
160
|
+
dlg.className = "onb";
|
|
161
|
+
dlg.setAttribute("aria-label", "Welcome to kaizen");
|
|
162
|
+
dlg.oncancel = (e) => (e.preventDefault(), void skip());
|
|
163
|
+
dlg.onclick = (e) => {
|
|
164
|
+
const t = e.target as HTMLElement;
|
|
165
|
+
const b = t.closest<HTMLElement>("button");
|
|
166
|
+
if (!b) return;
|
|
167
|
+
const d = b.dataset;
|
|
168
|
+
if (d.agent) ((agent = d.agent), draw());
|
|
169
|
+
else if (d.theme) {
|
|
170
|
+
theme = d.theme;
|
|
171
|
+
(window as any).setTheme?.(theme);
|
|
172
|
+
draw();
|
|
173
|
+
} else if (d.s) (void keepAgent(), (step = +d.s), void save({ step }), draw());
|
|
174
|
+
else if (d.a === "more") ((more = !more), draw());
|
|
175
|
+
else if (d.a === "back") (step--, void save({ step }), draw());
|
|
176
|
+
else if (d.a === "next") void next();
|
|
177
|
+
else if (d.a === "skip") void skip();
|
|
178
|
+
else if (d.a === "allow") void Notification.requestPermission().then(draw, draw);
|
|
179
|
+
else if (d.a === "copy") {
|
|
180
|
+
void navigator.clipboard?.writeText(d.cmd ?? "").then(() => (b.textContent = "Copied"), () => (b.textContent = "Select and copy"));
|
|
181
|
+
} else if (d.a === "test") new Notification("kaizen", { body: "This is how kaizen will tell you something needs you.", icon: "/logo.png" });
|
|
182
|
+
};
|
|
183
|
+
// Ctrl/Cmd+Enter always continues; a bare Enter does unless a button (other than a choice card) or field holds focus.
|
|
184
|
+
dlg.onkeydown = (e) => {
|
|
185
|
+
if (e.key !== "Enter" || e.isComposing) return;
|
|
186
|
+
const on = (e.target as HTMLElement).closest("button:not(.onb-card),input,select,textarea");
|
|
187
|
+
if (e.ctrlKey || e.metaKey || !on) (e.preventDefault(), void next());
|
|
188
|
+
};
|
|
189
|
+
document.body.appendChild(dlg);
|
|
190
|
+
dlg.showModal();
|
|
191
|
+
draw();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// The popup for someone who skipped or left it half done: once per browser session.
|
|
195
|
+
async function offer() {
|
|
196
|
+
try {
|
|
197
|
+
if (sessionStorage.getItem(ASKED)) return;
|
|
198
|
+
sessionStorage.setItem(ASKED, "1");
|
|
199
|
+
} catch {}
|
|
200
|
+
const c = cfg!;
|
|
201
|
+
const r = await ask("Continue setup?", c.step > 0 ? `You are on step ${c.step + 1} of ${c.total}. It only takes a minute.` : "You skipped setup. It only takes a minute.", [
|
|
202
|
+
["go", "Continue", true],
|
|
203
|
+
["later", "Not now"],
|
|
204
|
+
["never", "Don't ask again"],
|
|
205
|
+
]);
|
|
206
|
+
if (r === "go") open(c.step);
|
|
207
|
+
else if (r === "never") (void save({ outcome: "dismissed" }), row(0, "dismissed"));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export async function initOnboarding() {
|
|
211
|
+
cfg = await call("/onboarding");
|
|
212
|
+
if (!cfg) return;
|
|
213
|
+
(window as any).kzSetupRow?.(cfg);
|
|
214
|
+
document.getElementById("rsetup")?.addEventListener("click", (e) => (e.preventDefault(), open(cfg!.step)));
|
|
215
|
+
const q = new URLSearchParams(location.search);
|
|
216
|
+
if (q.has("setup")) {
|
|
217
|
+
q.delete("setup");
|
|
218
|
+
history.replaceState(null, "", location.pathname + (q.toString() ? "?" + q : "") + location.hash);
|
|
219
|
+
return open(cfg.resume ? cfg.step : 0);
|
|
220
|
+
}
|
|
221
|
+
if (cfg.show) return open(0);
|
|
222
|
+
if (cfg.resume) void offer();
|
|
223
|
+
}
|
package/web/board/panel.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { chat } from "./chat.ts";
|
|
|
7
7
|
import { stopDictation } from "./dictation.ts";
|
|
8
8
|
import { $, html, raw } from "./dom.ts";
|
|
9
9
|
import { fixForm, fixOff } from "./fixes.ts";
|
|
10
|
-
import {
|
|
10
|
+
import { gitPending, gitShown, gitTab } from "./git.ts";
|
|
11
11
|
import { ICON, WORD, need } from "./labels.ts";
|
|
12
12
|
import { attach, brief, md, planQuestions, preview, progress } from "./markdown.ts";
|
|
13
13
|
import { toast } from "./toast.ts";
|
|
@@ -24,6 +24,7 @@ const TABS = [
|
|
|
24
24
|
["Backlog", "backlog"],
|
|
25
25
|
["Work", "impl"],
|
|
26
26
|
["Review", "review"],
|
|
27
|
+
["Source control", "git"],
|
|
27
28
|
["Preview", "preview"],
|
|
28
29
|
];
|
|
29
30
|
// keepTab: a link already chose the tab.
|
|
@@ -120,19 +121,29 @@ function steps(c) {
|
|
|
120
121
|
STEPS.map((n, i) => `<span class="${i < at ? "ok" : i === at ? "now" : ""}"><i></i>${n}</span>`).join(""),
|
|
121
122
|
)}</span>`;
|
|
122
123
|
}
|
|
123
|
-
// The run workspace's header
|
|
124
|
-
//
|
|
124
|
+
// The run workspace's header: the project beside the picker (runner, agent, mode in its
|
|
125
|
+
// tooltip), then the stage the run is in as one word and a bar that slides to it.
|
|
126
|
+
let lastAt = { id: "", w: 0 };
|
|
125
127
|
function meta(c) {
|
|
126
128
|
let st: any = {};
|
|
127
129
|
try {
|
|
128
130
|
st = JSON.parse(store.runDoc?.state || "{}");
|
|
129
131
|
} catch {}
|
|
130
132
|
const proj = String(c.where || "").split(/[\\/]/).filter(Boolean).pop() || "";
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
const at = c.status === "done" ? 3 : Math.min(3, Math.max(0, (c.column || 1) - 1)),
|
|
134
|
+
word = STEPS[at] + (c.status === "waiting" ? ", needs you" : c.status === "stalled" ? ", stalled" : ""),
|
|
135
|
+
w = c.status === "done" ? 100 : ((at + 0.5) / 4) * 100;
|
|
136
|
+
const from = lastAt.id === c.id ? lastAt.w : 0;
|
|
137
|
+
lastAt = { id: c.id, w };
|
|
138
|
+
if (from !== w)
|
|
139
|
+
requestAnimationFrame(() => {
|
|
140
|
+
const i = $("psub").querySelector(".rprog i") as HTMLElement;
|
|
141
|
+
if (!i) return;
|
|
142
|
+
i.style.width = from + "%";
|
|
143
|
+
i.offsetWidth;
|
|
144
|
+
i.style.width = w + "%";
|
|
145
|
+
});
|
|
146
|
+
return html`<div class="rmeta" title="${[st.runner, st.agent, st.mode].filter(Boolean).join(", ")}">${proj}</div><div class="rprog s-${c.status}" title="${cap(WORD[c.status] || c.status) + (c.awaiting ? `: ${need(c.awaiting)}` : "")}"><span>${word}</span><b><i style="width:${w}%"></i></b></div>`;
|
|
136
147
|
}
|
|
137
148
|
// An idea's panel: its terminal while the run it started is being born there, else its notes.
|
|
138
149
|
export function ideaBody(c) {
|
|
@@ -169,9 +180,11 @@ export async function openRun(c, refresh, again) {
|
|
|
169
180
|
(t) =>
|
|
170
181
|
t[1] === "request" ||
|
|
171
182
|
t[1] === "notes" ||
|
|
172
|
-
(t[1] === "
|
|
173
|
-
?
|
|
174
|
-
:
|
|
183
|
+
(t[1] === "git"
|
|
184
|
+
? gitShown(c)
|
|
185
|
+
: t[1] === "preview"
|
|
186
|
+
? preview(store.runDoc.impl)
|
|
187
|
+
: store.runDoc[t[1]] || (t[1] === "backlog" && c.column === 2 && store.runDoc.progress)),
|
|
175
188
|
);
|
|
176
189
|
if (store.wantTerm === key(c)) store.wantTerm = null;
|
|
177
190
|
// The agent is a centre tab of the run workspace only: the panel never shows a terminal.
|
|
@@ -180,7 +193,7 @@ export async function openRun(c, refresh, again) {
|
|
|
180
193
|
if (view === "run" && store.tab === "preview") store.tab = "review";
|
|
181
194
|
// A tab not written yet falls back to the latest one that is.
|
|
182
195
|
if (store.tab !== "term" && !tabs.some((t) => t[1] === store.tab))
|
|
183
|
-
store.tab = [...tabs].reverse().find((t) => t[1] !== "notes" && !(view === "run" && t[1] === "preview"))[1];
|
|
196
|
+
store.tab = [...tabs].reverse().find((t) => t[1] !== "notes" && t[1] !== "git" && !(view === "run" && t[1] === "preview"))[1];
|
|
184
197
|
if (store.tab !== "term") store.lastTab = store.tab;
|
|
185
198
|
$("panel").classList.toggle("wide", store.tab === "term");
|
|
186
199
|
const pt = $("pterm");
|
|
@@ -212,7 +225,8 @@ export async function openRun(c, refresh, again) {
|
|
|
212
225
|
else if (k === "notes") {
|
|
213
226
|
const ro = c.archived || c.status === "done" || c.status === "abandoned";
|
|
214
227
|
chat(c, doc, ro);
|
|
215
|
-
} else
|
|
228
|
+
} else if (k === "git") gitTab(c, refresh);
|
|
229
|
+
else
|
|
216
230
|
$("pbody").innerHTML = doc
|
|
217
231
|
? raw(md(doc, k === "backlog"))
|
|
218
232
|
: html`<p style="color:var(--dim)">No ${{ request: "request", plan: "plan", impl: "work report", preview: "preview", review: "review", backlog: "backlog" }[k]} yet.</p>`;
|
|
@@ -232,8 +246,9 @@ export async function openRun(c, refresh, again) {
|
|
|
232
246
|
const foot = $("pfoot");
|
|
233
247
|
// A refresh while the commit is being confirmed would wipe the message.
|
|
234
248
|
if (refresh && foot.querySelector(".inl,[data-busy],.more[open]")) return;
|
|
249
|
+
// Git work left on a finished run: the footer points at the Source control tab, which holds it.
|
|
235
250
|
const arch =
|
|
236
|
-
|
|
251
|
+
(k !== "git" && gitPending(c) ? `<button class="btn" data-a="gittab">Source control</button>` : "") +
|
|
237
252
|
(c.archived
|
|
238
253
|
? `<button class="btn pri" data-a="restore">Restore</button>`
|
|
239
254
|
: `<button class="btn ghost" data-a="archive">Archive</button>`);
|
|
@@ -249,23 +264,21 @@ export async function openRun(c, refresh, again) {
|
|
|
249
264
|
else if ((c.status === "waiting" || c.awaiting === "findings") && APPROVAL[c.awaiting]) {
|
|
250
265
|
const sent = decided.has(answer(c)),
|
|
251
266
|
asks = !pq
|
|
252
|
-
? "
|
|
267
|
+
? " Has questions: answer in its terminal."
|
|
253
268
|
: qs.length
|
|
254
|
-
? `
|
|
269
|
+
? ` ${qs.length === 1 ? "1 question" : qs.length + " questions"}.`
|
|
255
270
|
: "";
|
|
256
|
-
// gitBtn's buttons restyled as menu rows.
|
|
257
271
|
const more =
|
|
258
|
-
gitBtn(c).replace(/class="btn( pri)?"/g, "") +
|
|
259
272
|
`<button data-a="archive">Archive</button><hr><button data-a="ab" class="danger">Abandon</button>`;
|
|
260
273
|
foot.innerHTML = html`<span class="note">${sent ? "Sent to your agent." : APPROVAL[c.awaiting] + asks}</span><details class="more"><summary class="btn ghost">More</summary><div class="menu-pop">${raw(more)}</div></details>${raw(rs)}<span class="dec"><button class="btn" data-a="revise"${sent ? " disabled" : ""}>Revise</button><button class="btn pri" data-a="approve"${sent ? " disabled" : ""}>${c.awaiting === "findings" ? "Approve as-is" : "Approve"}</button></span>`;
|
|
261
274
|
} else if (c.status === "waiting")
|
|
262
|
-
foot.innerHTML = html`<span class="note">Waiting
|
|
275
|
+
foot.innerHTML = html`<span class="note">Waiting: ${need(c.awaiting)}.</span>${raw(arch)}<button class="btn ghost" data-a="ab">Abandon</button>${raw(rs)}`;
|
|
263
276
|
else if (c.status === "done" && c.accept === "needs")
|
|
264
277
|
foot.innerHTML = html`<span class="note">Done, not approved: its agent finished without your approval. Nothing is committed until you approve.</span>${raw(arch + rs)}<button class="btn pri" data-a="accept">Approve</button>`;
|
|
265
278
|
else if (c.status === "done") foot.innerHTML = raw(arch + rs);
|
|
266
279
|
else if (c.status === "abandoned") foot.innerHTML = raw(arch);
|
|
267
280
|
else
|
|
268
|
-
foot.innerHTML = html`<span class="note">${c.pty && !c.pty.alive ? "
|
|
281
|
+
foot.innerHTML = html`<span class="note">${c.pty && !c.pty.alive ? "Agent ended early." : c.status === "stalled" ? "Stalled." : ""}</span>${raw(arch)}<button class="btn ghost" data-a="ab">Abandon</button>${resumable(c) ? html`<button class="btn pri" data-a="resume">Resume</button>` : ""}`;
|
|
269
282
|
foot.querySelectorAll("[data-a]").forEach(
|
|
270
283
|
(b) =>
|
|
271
284
|
(b.onclick = () => {
|
|
@@ -274,12 +287,9 @@ export async function openRun(c, refresh, again) {
|
|
|
274
287
|
toggleArchive(c, a === "archive");
|
|
275
288
|
return;
|
|
276
289
|
}
|
|
277
|
-
if (a === "
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
if (a === "commit") {
|
|
282
|
-
confirmCommit(c);
|
|
290
|
+
if (a === "gittab") {
|
|
291
|
+
store.tab = "git";
|
|
292
|
+
openRun(c, true);
|
|
283
293
|
return;
|
|
284
294
|
}
|
|
285
295
|
if (a === "accept") {
|
package/web/board/run-view.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { termLoad } from "./agent-term.ts";
|
|
|
18
18
|
import { load, post } from "./api.ts";
|
|
19
19
|
import { attach, md, preview } from "./markdown.ts";
|
|
20
20
|
import { layout } from "./terms.ts";
|
|
21
|
-
import { cardHref, markCurrent, railData, titleOf, wsHref, wsOfCard } from "./workspace.ts";
|
|
21
|
+
import { cardHref, markCurrent, railData, stateOf, titleOf, wsHref, wsOfCard } from "./workspace.ts";
|
|
22
22
|
import { type Node, awaiting, chosen, finished, historyOf, leaves, liveIn, loopbackUrl, migrate, pickable, prune, reviewing, stageTabs, toOpen, wsKey } from "./ws-tabs.ts";
|
|
23
23
|
import { drawPick, hidePick, initPick, setOpen } from "./run-pick.ts";
|
|
24
24
|
import { age } from "./labels.ts";
|
|
@@ -76,9 +76,13 @@ let target: { screen: string; dir: "cols" | "rows" } | null = null;
|
|
|
76
76
|
function screens(): Screen[] {
|
|
77
77
|
const s = saved(),
|
|
78
78
|
ids = tabs().map((t) => t.id);
|
|
79
|
-
|
|
79
|
+
// In place: the panes on screen hold these objects, and a gutter drag writes its sizes into them.
|
|
80
|
+
s.screens = s.screens.filter((sc) => {
|
|
80
81
|
const tree = prune(sc.tree, (id) => ids.includes(id));
|
|
81
|
-
|
|
82
|
+
if (!tree) return false;
|
|
83
|
+
sc.tree = tree;
|
|
84
|
+
if (!leaves(tree).includes(sc.focus)) sc.focus = leaves(tree)[0];
|
|
85
|
+
return true;
|
|
82
86
|
});
|
|
83
87
|
for (const id of ids)
|
|
84
88
|
if (!s.screens.some((sc) => leaves(sc.tree).includes(id))) {
|
|
@@ -104,7 +108,7 @@ function tabs(): Tab[] {
|
|
|
104
108
|
// Each live run's terminals: its stage terminals ("Build · Claude"), other sessions, shells, the waiting note.
|
|
105
109
|
for (const c of live) {
|
|
106
110
|
const k = key(c),
|
|
107
|
-
runAgent = AGENTS.find((a) => c.tags?.includes(a)) ?? undefined;
|
|
111
|
+
runAgent = AGENTS.find((a) => a === c.pty?.agent) ?? AGENTS.find((a) => c.tags?.includes(a)) ?? undefined;
|
|
108
112
|
for (const t of stageTabs(c, named(runAgent))) out.push({ id: "agent:" + t.key, kind: "agent", agent: runAgent, title: t.title, key: t.key });
|
|
109
113
|
for (const sh of shells.filter((x) => x.run === k)) out.push({ id: "sh:" + sh.key, kind: sh.agent ? "agent" : "shell", agent: sh.agent || undefined, title: sh.title, key: sh.key });
|
|
110
114
|
// The run's own session is running in another terminal: a tab that says so.
|
|
@@ -194,7 +198,10 @@ export async function showRunView(nav = false) {
|
|
|
194
198
|
// session is not open anywhere on the board is resumed here, once per visit.
|
|
195
199
|
if (!noPty) {
|
|
196
200
|
if (!tabs().length && !autoShell.has(k)) return void (autoShell.add(k), newPty());
|
|
197
|
-
|
|
201
|
+
// Not while a launch from the board is coming up: its terminal is not tied to the new run card yet, and
|
|
202
|
+
// resuming the run here would open a second agent on the same session beside it (the stray "Agent" tab).
|
|
203
|
+
const launching = !!store.wantPty && Date.now() - store.wantPty.at < 20_000;
|
|
204
|
+
if (want && want.kind === "run" && !finished(want) && !want.pty && !launching && !shells.some((x) => x.run === key(want)) && !autoShell.has(key(want))) {
|
|
198
205
|
autoShell.add(key(want));
|
|
199
206
|
void openAgent(want, false, false);
|
|
200
207
|
}
|
|
@@ -204,8 +211,13 @@ export async function showRunView(nav = false) {
|
|
|
204
211
|
// The terminal the sidebar asked for, selected once the workspace's tabs are known.
|
|
205
212
|
let wantTerm: string | null = null;
|
|
206
213
|
function showTerm() {
|
|
207
|
-
|
|
214
|
+
// A launch from the board names its terminal (store.wantPty): it is selected once its tab exists,
|
|
215
|
+
// and the ask lapses after a while so a launch that never came up cannot pull focus later.
|
|
216
|
+
const w = store.wantPty && Date.now() - store.wantPty.at < 20_000 ? store.wantPty.key : null;
|
|
217
|
+
if (store.wantPty && !w) store.wantPty = null;
|
|
218
|
+
const t = tabs().find((x) => x.key === (wantTerm || w));
|
|
208
219
|
wantTerm = null;
|
|
220
|
+
if (t && store.wantPty?.key === t.key) store.wantPty = null;
|
|
209
221
|
return !!t && (show(t.id), true);
|
|
210
222
|
}
|
|
211
223
|
const autoShell = new Set<string>();
|
|
@@ -346,6 +358,8 @@ function build(n: Node, sc: Screen): HTMLElement {
|
|
|
346
358
|
sum = n.sizes[i - 1] + n.sizes[i],
|
|
347
359
|
start = horiz ? ra.left : ra.top;
|
|
348
360
|
g.setPointerCapture(e.pointerId);
|
|
361
|
+
// A frame under the pointer (the Browser, Preview) takes the moves for itself: frames ignore it while dragging.
|
|
362
|
+
document.body.classList.add("rdrag");
|
|
349
363
|
g.onpointermove = (m) => {
|
|
350
364
|
const f = Math.min(0.9, Math.max(0.1, ((horiz ? m.clientX : m.clientY) - start) / total));
|
|
351
365
|
n.sizes[i - 1] = sum * f;
|
|
@@ -353,8 +367,10 @@ function build(n: Node, sc: Screen): HTMLElement {
|
|
|
353
367
|
a.style.flexGrow = String(n.sizes[i - 1]);
|
|
354
368
|
b.style.flexGrow = String(n.sizes[i]);
|
|
355
369
|
};
|
|
356
|
-
g.onpointerup = () => {
|
|
357
|
-
g.onpointermove
|
|
370
|
+
g.onpointerup = g.onlostpointercapture = () => {
|
|
371
|
+
if (!g.onpointermove) return;
|
|
372
|
+
document.body.classList.remove("rdrag");
|
|
373
|
+
g.onpointermove = g.onpointerup = g.onlostpointercapture = null;
|
|
358
374
|
shownSig = sc.id + JSON.stringify(sc.tree);
|
|
359
375
|
save();
|
|
360
376
|
};
|
|
@@ -585,7 +601,15 @@ async function closeTab(id: string) {
|
|
|
585
601
|
if (id.startsWith("sh:")) {
|
|
586
602
|
await post("/pty/exit", { key: id.slice(3) });
|
|
587
603
|
shells = shells.filter((x) => "sh:" + x.key !== id);
|
|
588
|
-
} else if (id.startsWith("agent:"))
|
|
604
|
+
} else if (id.startsWith("agent:")) {
|
|
605
|
+
// Closing the tab ends the agent, so the sidebar stops listing it; one mid-turn asks first.
|
|
606
|
+
const k = id.slice(6),
|
|
607
|
+
a = store.S.agents?.find((x) => x.key === k);
|
|
608
|
+
if (a?.busy && !confirm("This agent is still working. End it?")) return;
|
|
609
|
+
s.hidden.push(id);
|
|
610
|
+
await post("/pty/exit", { key: k });
|
|
611
|
+
load(true);
|
|
612
|
+
}
|
|
589
613
|
else if (id.startsWith("wait:")) elsewhere.delete(id.slice(5));
|
|
590
614
|
else s.tabs = s.tabs.filter((t) => t.id !== id);
|
|
591
615
|
save();
|
|
@@ -813,6 +837,52 @@ async function autoBrowse() {
|
|
|
813
837
|
}
|
|
814
838
|
}
|
|
815
839
|
|
|
840
|
+
// A phone's run sheet: drag it down from anywhere its content is at the top, or tap outside it.
|
|
841
|
+
function initSheet() {
|
|
842
|
+
const p = $("panel"),
|
|
843
|
+
b = document.body;
|
|
844
|
+
const on = () => isPhone() && b.classList.contains("runv") && b.classList.contains("rflip");
|
|
845
|
+
const shut = () => $("pclose").click();
|
|
846
|
+
let y0: number | null = null,
|
|
847
|
+
t0 = 0,
|
|
848
|
+
dy = 0;
|
|
849
|
+
const scrolled = (t: EventTarget | null) => ((t as Element).closest?.(".body")?.scrollTop ?? 0) > 0;
|
|
850
|
+
p.addEventListener(
|
|
851
|
+
"touchstart",
|
|
852
|
+
(e) => {
|
|
853
|
+
y0 = on() && e.touches.length === 1 && !scrolled(e.target) ? e.touches[0].clientY : null;
|
|
854
|
+
t0 = Date.now();
|
|
855
|
+
dy = 0;
|
|
856
|
+
},
|
|
857
|
+
{ passive: true },
|
|
858
|
+
);
|
|
859
|
+
p.addEventListener(
|
|
860
|
+
"touchmove",
|
|
861
|
+
(e) => {
|
|
862
|
+
if (y0 === null) return;
|
|
863
|
+
if (scrolled(e.target)) return void (y0 = null);
|
|
864
|
+
dy = e.touches[0].clientY - y0;
|
|
865
|
+
if (dy <= 0) return void (p.style.translate = "");
|
|
866
|
+
e.preventDefault();
|
|
867
|
+
p.style.transition = "none";
|
|
868
|
+
p.style.translate = `0 ${dy}px`;
|
|
869
|
+
},
|
|
870
|
+
{ passive: false },
|
|
871
|
+
);
|
|
872
|
+
const end = () => {
|
|
873
|
+
if (y0 === null) return;
|
|
874
|
+
y0 = null;
|
|
875
|
+
p.style.transition = "";
|
|
876
|
+
if (dy > 100 || (dy > 30 && Date.now() - t0 < 250)) {
|
|
877
|
+
p.style.translate = "0 100%";
|
|
878
|
+
setTimeout(() => (shut(), (p.style.translate = "")), 180);
|
|
879
|
+
} else p.style.translate = "";
|
|
880
|
+
};
|
|
881
|
+
p.addEventListener("touchend", end);
|
|
882
|
+
p.addEventListener("touchcancel", end);
|
|
883
|
+
addEventListener("click", (e) => on() && !(e.target as Element).closest?.("#panel,#rside,dialog,.toast") && shut());
|
|
884
|
+
}
|
|
885
|
+
|
|
816
886
|
export function initRunView() {
|
|
817
887
|
// A phone's sheet closes with the panel's ×, which here hides the sheet rather than closing the card.
|
|
818
888
|
document.addEventListener(
|
|
@@ -825,6 +895,7 @@ export function initRunView() {
|
|
|
825
895
|
},
|
|
826
896
|
true,
|
|
827
897
|
);
|
|
898
|
+
initSheet();
|
|
828
899
|
initPick(pickRun);
|
|
829
900
|
// The sidebar's agent mark: open that workspace with the agent's terminal tab selected.
|
|
830
901
|
addEventListener("kz-open-term", (e: any) => {
|
|
@@ -836,6 +907,19 @@ export function initRunView() {
|
|
|
836
907
|
markCurrent();
|
|
837
908
|
go("ws");
|
|
838
909
|
});
|
|
910
|
+
// Search's Tabs group: open the workspace on the screen holding that tab.
|
|
911
|
+
addEventListener("kz-open-tab", (e: any) => {
|
|
912
|
+
e.preventDefault();
|
|
913
|
+
const { dir, ws, id } = e.detail;
|
|
914
|
+
const k = wsKey(dir, ws),
|
|
915
|
+
s = ALL[k],
|
|
916
|
+
sc = s?.screens?.find((x) => leaves(x.tree).includes(id));
|
|
917
|
+
if (sc) (s.on = sc.id), save();
|
|
918
|
+
if (ctx?.k === k && document.body.classList.contains("runv")) return void draw();
|
|
919
|
+
history.pushState(null, "", wsHref(dir, ws));
|
|
920
|
+
markCurrent();
|
|
921
|
+
go("ws");
|
|
922
|
+
});
|
|
839
923
|
addEventListener("kz-run-preview", openPreview);
|
|
840
924
|
$("pnotes").onclick = () => void projectNotes();
|
|
841
925
|
$("pnlist").onclick = (e) => {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The search palette's matcher, apart from the page so a test can load it.
|
|
2
|
+
export type Item = { group: string; title: string; sub?: string; when?: string; hay: string; at?: number; dot?: string; ico: string; act: () => void };
|
|
3
|
+
|
|
4
|
+
// Every word of the query in the item; a title that starts with it ranks first, then a title
|
|
5
|
+
// holding it, then the rest by recency.
|
|
6
|
+
export function match(list: Item[], q: string): Item[] {
|
|
7
|
+
const words = q.toLowerCase().split(/\s+/).filter(Boolean);
|
|
8
|
+
if (!words.length) return list;
|
|
9
|
+
const lq = q.trim().toLowerCase();
|
|
10
|
+
const score = (i: Item) => {
|
|
11
|
+
const t = i.title.toLowerCase();
|
|
12
|
+
return t.startsWith(lq) ? 0 : t.includes(lq) ? 1 : 2;
|
|
13
|
+
};
|
|
14
|
+
return list
|
|
15
|
+
.filter((i) => {
|
|
16
|
+
const h = (i.title + " " + (i.sub ?? "") + " " + i.hay).toLowerCase();
|
|
17
|
+
return words.every((w) => h.includes(w));
|
|
18
|
+
})
|
|
19
|
+
.sort((a, b) => score(a) - score(b) || (b.at ?? 0) - (a.at ?? 0));
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { match } from "./search-match.ts";
|
|
3
|
+
|
|
4
|
+
const it = (title: string, at = 0, hay = "") => ({ group: "g", title, hay, at, ico: "run", act: () => {} });
|
|
5
|
+
|
|
6
|
+
test("an empty query keeps every item", () => {
|
|
7
|
+
const l = [it("a"), it("b")];
|
|
8
|
+
expect(match(l, " ")).toBe(l);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("every word must be present, in title, sub or keywords", () => {
|
|
12
|
+
const l = [it("Global search", 0, "kaizen"), it("Search tests"), it("Board")];
|
|
13
|
+
expect(match(l, "search kaizen").map((i) => i.title)).toEqual(["Global search"]);
|
|
14
|
+
expect(match(l, "SEARCH").map((i) => i.title).sort()).toEqual(["Global search", "Search tests"]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("title prefix beats title contains beats keywords, then recency", () => {
|
|
18
|
+
const l = [it("Old board", 5, ""), it("Notes", 9, "board"), it("Board new", 1), it("Board recent", 3)];
|
|
19
|
+
expect(match(l, "board").map((i) => i.title)).toEqual(["Board recent", "Board new", "Old board", "Notes"]);
|
|
20
|
+
});
|