kaizen-agent 1.59.1 → 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/phone.ts +26 -3
- package/web/board/projects.ts +6 -85
- package/web/board/run-pick.ts +41 -0
- package/web/board/run-view.ts +261 -104
- 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 +6 -2
- 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 +92 -43
- package/web/board.js +44 -43
- package/web/notebook.js +24 -25
- package/web/notes.html +26 -21
- package/web/term.js +1 -1
- package/web/video.html +26 -21
- package/web/video.js +56 -57
package/cli/worktree.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { test, expect, beforeEach } from "bun:test";
|
|
|
3
3
|
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
|
-
import { startWorktree, landWorktree, codeDir, projectFromWorktree, run, type Run } from "./worktree.ts";
|
|
6
|
+
import { startWorktree, landWorktree, codeDir, projectFromWorktree, run, workspaces, workspacesNow, addWorktree, wsOf, adoptWorkspace, type Run } from "./worktree.ts";
|
|
7
7
|
|
|
8
8
|
const ID = "2026-10-17-demo";
|
|
9
9
|
// CI runners have no git identity, and landWorktree's rebase writes commits.
|
|
@@ -113,3 +113,45 @@ test("projectFromWorktree finds the project from inside a run's folder", () => {
|
|
|
113
113
|
expect(projectFromWorktree("/p/.kaizen/wt/2026-10-17-x/cli")).toBe("/p");
|
|
114
114
|
expect(projectFromWorktree("/p/cli")).toBe("/p/cli");
|
|
115
115
|
});
|
|
116
|
+
|
|
117
|
+
test("workspaces: the main checkout, then each worktree; a folder that is not git is one workspace", () => {
|
|
118
|
+
expect(addWorktree(project, "-x", idRun).ok).toBe(false);
|
|
119
|
+
expect(addWorktree(project, "bad..name", idRun)).toMatchObject({ ok: false });
|
|
120
|
+
const r = addWorktree(project, "feat/two", idRun);
|
|
121
|
+
expect(r.ok).toBe(true);
|
|
122
|
+
expect(existsSync(join(project, ".kaizen/wt/feat-two"))).toBe(true);
|
|
123
|
+
expect(addWorktree(project, "feat/two", idRun).ok).toBe(false); // folder exists
|
|
124
|
+
const ws = workspaces(project, idRun);
|
|
125
|
+
expect(ws[0]).toEqual({ path: project, branch: "main", main: true });
|
|
126
|
+
expect(ws.slice(1)).toEqual([{ path: (r as any).path, branch: "feat/two", main: false }]);
|
|
127
|
+
const plain = mkdtempSync(join(tmpdir(), "nogit-"));
|
|
128
|
+
expect(workspaces(plain, idRun)).toEqual([{ path: plain, branch: "", main: true }]);
|
|
129
|
+
// A run's workspace: its worktree while on disk, else the main checkout.
|
|
130
|
+
expect(wsOf(project, { worktree: (r as any).path })).toBe((r as any).path);
|
|
131
|
+
expect(wsOf(project, { worktree: join(project, ".kaizen/wt/gone") })).toBe(project);
|
|
132
|
+
expect(wsOf(project, {})).toBe(project);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("adoptWorkspace: a run started inside another workspace is placed there, with no worktree of its own", () => {
|
|
136
|
+
const r = addWorktree(project, "feat/two", idRun) as { path: string };
|
|
137
|
+
expect(adoptWorkspace(project, ID, project)).toBeNull(); // the main checkout: a normal start
|
|
138
|
+
mkdirSync(join(r.path, "sub"));
|
|
139
|
+
expect(adoptWorkspace(project, ID, join(r.path, "sub"))).toEqual({ ok: true, path: r.path });
|
|
140
|
+
expect(state().workspace).toBe(r.path);
|
|
141
|
+
expect(state().worktree).toBeUndefined(); // land must never remove a folder the user made
|
|
142
|
+
expect(wsOf(project, state())).toBe(r.path);
|
|
143
|
+
expect(codeDir(project, ID)).toBe(project);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("workspacesNow: answers at once, refreshes git in the background, one call at a time", async () => {
|
|
147
|
+
const p = mkdtempSync(join(tmpdir(), "wsnow-"));
|
|
148
|
+
let calls = 0, done!: (o: { ok: boolean; out: string; why: string }) => void;
|
|
149
|
+
const slow = () => { calls++; return new Promise<any>((r) => (done = r)); };
|
|
150
|
+
expect(workspacesNow(p, slow)).toEqual([{ path: p, branch: "", main: true }]); // git still running
|
|
151
|
+
expect(workspacesNow(p, slow)).toEqual([{ path: p, branch: "", main: true }]);
|
|
152
|
+
expect(calls).toBe(1);
|
|
153
|
+
done({ ok: true, out: `worktree ${p}\nHEAD abc\nbranch refs/heads/dev`, why: "" });
|
|
154
|
+
await Bun.sleep(0);
|
|
155
|
+
expect(workspacesNow(p, slow)).toEqual([{ path: p, branch: "dev", main: true }]);
|
|
156
|
+
expect(calls).toBe(1);
|
|
157
|
+
});
|
package/cli/worktree.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// One branch and one git worktree per run, so agents building at the same time never
|
|
2
2
|
// share a working folder. Run notes stay in the project's .kaizen/runs/<id>/; only the
|
|
3
3
|
// code lives in the worktree. Every git call is an argv array, never a shell string.
|
|
4
|
-
import { existsSync, readFileSync, writeFileSync, rmSync } from "node:fs";
|
|
5
|
-
import { join, dirname } from "node:path";
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync, rmSync, realpathSync } from "node:fs";
|
|
5
|
+
import { join, dirname, resolve, sep } from "node:path";
|
|
6
|
+
import { branchesOf } from "./add-project.ts";
|
|
6
7
|
|
|
7
8
|
export type Out = { ok: boolean; out: string; why: string };
|
|
8
9
|
export type Run = (cmd: string[], cwd: string) => Out;
|
|
@@ -126,3 +127,97 @@ export function landWorktree(project: string, id: string, sh: Run = run,
|
|
|
126
127
|
}
|
|
127
128
|
return { ok: false, why: `${base} kept moving; push rejected twice. Worktree kept` };
|
|
128
129
|
}
|
|
130
|
+
|
|
131
|
+
export type Workspace = { path: string; branch: string; main: boolean };
|
|
132
|
+
const listed = new Map<string, { at: number; ws: Workspace[] }>();
|
|
133
|
+
const inside = (p: string, root: string) => p === root || p.startsWith(root + sep);
|
|
134
|
+
// One spelling per folder: git prints real paths, a tmp or 8.3 path may not be one.
|
|
135
|
+
const real = (p: string) => { try { return realpathSync.native(p); } catch { return resolve(p); } };
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A project's workspaces: its main checkout first, then every other git worktree, from
|
|
139
|
+
* `git worktree list --porcelain`. A folder that is not a repository is one workspace.
|
|
140
|
+
* Prunable entries, and detached ones outside the project, are left out. Cached 10 s:
|
|
141
|
+
* /state asks for every known project on each tick.
|
|
142
|
+
*/
|
|
143
|
+
export function workspaces(project: string, sh: Run = run): Workspace[] {
|
|
144
|
+
const hit = listed.get(project);
|
|
145
|
+
if (hit && Date.now() - hit.at < 10_000) return hit.ws;
|
|
146
|
+
const ws = parseWorkspaces(project, existsSync(project) ? sh(["git", "worktree", "list", "--porcelain"], project) : null);
|
|
147
|
+
listed.set(project, { at: Date.now(), ws });
|
|
148
|
+
return ws;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** git off the event loop, with the same 120 s ceiling as run(). */
|
|
152
|
+
export const runAsync = async (cmd: string[], cwd: string): Promise<Out> => {
|
|
153
|
+
try {
|
|
154
|
+
const p = Bun.spawn(cmd, { cwd, env, stdin: "ignore", stdout: "pipe", stderr: "pipe", timeout: 120_000, windowsHide: true });
|
|
155
|
+
const [out, err] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text()]);
|
|
156
|
+
return { ok: (await p.exited) === 0, out: out.trimEnd(), why: err.trim() || `${cmd[0]} did not finish` };
|
|
157
|
+
} catch { return { ok: false, out: "", why: `${cmd[0]} is not installed` }; }
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* workspaces() for /state: never waits on git. A fresh cache answers; a stale one answers
|
|
162
|
+
* and refreshes in the background; none yet answers the one folder until git replies.
|
|
163
|
+
*/
|
|
164
|
+
const refreshing = new Set<string>();
|
|
165
|
+
export function workspacesNow(project: string, sh = runAsync): Workspace[] {
|
|
166
|
+
const hit = listed.get(project);
|
|
167
|
+
if (hit && Date.now() - hit.at < 10_000) return hit.ws;
|
|
168
|
+
if (!refreshing.has(project) && existsSync(project)) {
|
|
169
|
+
refreshing.add(project);
|
|
170
|
+
void sh(["git", "worktree", "list", "--porcelain"], project)
|
|
171
|
+
.then((r) => listed.set(project, { at: Date.now(), ws: parseWorkspaces(project, r) }))
|
|
172
|
+
.finally(() => refreshing.delete(project));
|
|
173
|
+
}
|
|
174
|
+
return hit?.ws ?? [{ path: project, branch: "", main: true }];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function parseWorkspaces(project: string, r: Out | null): Workspace[] {
|
|
178
|
+
const main = { path: project, branch: "", main: true };
|
|
179
|
+
if (!r?.ok) return [main];
|
|
180
|
+
const all = r.out.split(/\n\s*\n/).map((b) => {
|
|
181
|
+
const l = b.split("\n"), v = (k: string) => l.find((x) => x === k || x.startsWith(k + " "))?.slice(k.length + 1);
|
|
182
|
+
return { path: real(v("worktree") ?? ""), branch: (v("branch") ?? "").replace(/^refs\/heads\//, ""), prunable: v("prunable") !== undefined, bare: v("bare") !== undefined };
|
|
183
|
+
});
|
|
184
|
+
// The first entry is the main checkout; the registered folder stands for it (it may sit below the root).
|
|
185
|
+
main.branch = all[0]?.branch ?? "";
|
|
186
|
+
return [main, ...all.slice(1).filter((w) => !w.prunable && !w.bare && w.path !== real(project) && existsSync(w.path) && (w.branch || inside(w.path, real(project))))
|
|
187
|
+
.map((w) => ({ path: w.path, branch: w.branch, main: false }))];
|
|
188
|
+
}
|
|
189
|
+
export const forgetWorkspaces = (project: string) => listed.delete(project);
|
|
190
|
+
/** How old the cached list is, in ms; Infinity when none. */
|
|
191
|
+
export const workspacesAge = (project: string) => { const hit = listed.get(project); return hit ? Date.now() - hit.at : Infinity; };
|
|
192
|
+
|
|
193
|
+
/** The workspace a run belongs to: its recorded worktree (or the workspace it was started in) while that is still on disk, else the main checkout. */
|
|
194
|
+
export const wsOf = (project: string, state: { worktree?: unknown; workspace?: unknown }) => {
|
|
195
|
+
const w = [state.worktree, state.workspace].find((x) => typeof x === "string" && existsSync(x));
|
|
196
|
+
return typeof w === "string" ? real(w) : project;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* `kaizen worktree start` run from inside one of the project's other workspaces: the run is
|
|
201
|
+
* placed there (`workspace` in state.json) and no second worktree is made. It is not recorded
|
|
202
|
+
* as the run's `worktree`: land would then remove a folder and branch the user made.
|
|
203
|
+
*/
|
|
204
|
+
export function adoptWorkspace(project: string, id: string, here: string): { ok: true; path: string } | null {
|
|
205
|
+
if (!SLUG.test(id) || !existsSync(file(project, id))) return null;
|
|
206
|
+
const at = real(here), w = workspaces(project).find((x) => !x.main && x.path !== real(worktreeOf(project, id)) && inside(at, x.path));
|
|
207
|
+
if (!w) return null;
|
|
208
|
+
patchState(project, id, { workspace: w.path });
|
|
209
|
+
return { ok: true, path: w.path };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** A new worktree for `branch` under <project>/.kaizen/wt/, the branch made off `base` (one of branchesOf's) or HEAD. */
|
|
213
|
+
export function addWorktree(project: string, branch: string, sh: Run = run, base?: string): { ok: true; path: string } | { ok: false; why: string } {
|
|
214
|
+
if (!branch || branch.startsWith("-") || branch.length > 200) return { ok: false, why: "not a branch name" };
|
|
215
|
+
if (!sh(["git", "rev-parse", "--is-inside-work-tree"], project).ok) return { ok: false, why: "not a git repository" };
|
|
216
|
+
if (!sh(["git", "check-ref-format", "--branch", branch], project).ok) return { ok: false, why: `"${branch}" is not a valid branch name` };
|
|
217
|
+
if (base !== undefined && (base.startsWith("-") || !branchesOf(project, sh).branches.includes(base))) return { ok: false, why: `"${base}" is not a branch of this project` };
|
|
218
|
+
const path = join(project, ".kaizen", "wt", branch.replace(/[^\w.-]+/g, "-").replace(/^\.+/, ""));
|
|
219
|
+
if (existsSync(path)) return { ok: false, why: "that worktree folder already exists" };
|
|
220
|
+
const add = sh(["git", "worktree", "add", ...(base ? ["--no-track"] : []), "-b", branch, "--", path, ...(base ? [base] : [])], project);
|
|
221
|
+
forgetWorkspaces(project);
|
|
222
|
+
return add.ok ? { ok: true, path: real(path) } : { ok: false, why: add.why };
|
|
223
|
+
}
|
package/cli/writeback.ts
CHANGED
|
@@ -9,7 +9,7 @@ import * as google from "./google.ts";
|
|
|
9
9
|
type Gh = (args: string[]) => Promise<{ code: number; err: string }>;
|
|
10
10
|
const runGh: Gh = async (args) => {
|
|
11
11
|
try {
|
|
12
|
-
const p = Bun.spawn(["gh", ...args], { stdout: "ignore", stderr: "pipe" });
|
|
12
|
+
const p = Bun.spawn(["gh", ...args], { stdout: "ignore", stderr: "pipe", windowsHide: true });
|
|
13
13
|
const err = await new Response(p.stderr).text();
|
|
14
14
|
return { code: await p.exited, err };
|
|
15
15
|
} catch { return { code: 127, err: "The gh command was not found. Install GitHub's CLI and run `gh auth login`." }; }
|
package/package.json
CHANGED
package/skills/kaizen/SKILL.md
CHANGED
|
@@ -140,6 +140,10 @@ an explicit `/kaizen approve` or a clear approval in conversation.
|
|
|
140
140
|
- `approvals.plan` — after the plan, before any code is written. On by default.
|
|
141
141
|
- `approvals.review` — after the review passes, before the work is called done. Off by
|
|
142
142
|
default: with `auto_fix` on, it mostly asks for approval of a report being read anyway.
|
|
143
|
+
When on, a run that changed files is done only once `02-approval.md` holds an
|
|
144
|
+
`accepted:` line (format in `spec-main.md`); `auto` stops here too unless
|
|
145
|
+
`auto_accept` is `true`. The board flags a run marked done without it and refuses
|
|
146
|
+
its commit.
|
|
143
147
|
- `approvals.each_file` — confirm each file edit individually. Off by default; slow.
|
|
144
148
|
|
|
145
149
|
A rejected approval is not a failure, and it is not always the same action. Two shapes:
|
|
@@ -178,7 +182,7 @@ Every iteration is written to `runs/<id>/05-iterations/` so the loop is auditabl
|
|
|
178
182
|
|
|
179
183
|
Each run keeps its own backlog at `runs/<id>/06-backlog.md`. You write it, in the main
|
|
180
184
|
thread, at two writes that already happen: `02-approval.md` at the plan approval
|
|
181
|
-
and `
|
|
185
|
+
and `kaizen done <id>` at the final approval (refused until the user has approved), and only with what the user asked to
|
|
182
186
|
backlog. Open findings, unverified checks and suggestions are offered, never filed by
|
|
183
187
|
themselves. No subagent writes it.
|
|
184
188
|
The full rules are in [`spec-main.md`](spec-main.md).
|
|
@@ -11,6 +11,10 @@ preset: medium
|
|
|
11
11
|
# plan-only | approve | auto | review-only
|
|
12
12
|
mode: approve
|
|
13
13
|
|
|
14
|
+
# With approvals.review on, a run that changed files waits for your approval at the
|
|
15
|
+
# end even in auto mode. true lets auto runs finish without it, marked auto-accepted.
|
|
16
|
+
auto_accept: false
|
|
17
|
+
|
|
14
18
|
approvals:
|
|
15
19
|
# Stop after the plan, before any code is written.
|
|
16
20
|
plan: true
|
|
@@ -135,11 +139,20 @@ agent:
|
|
|
135
139
|
# Where the web board runs the agent it launches.
|
|
136
140
|
# card - inside the board: the card's Terminal tab shows the agent live and
|
|
137
141
|
# takes your typing. The agent lives in the board's process, so
|
|
138
|
-
# stopping or
|
|
139
|
-
#
|
|
142
|
+
# stopping, upgrading or a crash of the board ends it; the next
|
|
143
|
+
# board starts it again in its card, in the same conversation, with
|
|
144
|
+
# its last screen and a line saying the step it was on was cut off.
|
|
145
|
+
# On Windows it runs in a ConPTY console that Windows PowerShell hosts.
|
|
140
146
|
# terminal - a new terminal window (or tmux/herdr tab) per launch.
|
|
141
147
|
# The terminal dashboard always opens terminal windows.
|
|
142
148
|
launch: card
|
|
149
|
+
# Card agents only: what happens to them when the board stops.
|
|
150
|
+
# off - they end and the next board starts them again (above).
|
|
151
|
+
# tmux - they run inside a hidden tmux session on kaizen's own tmux server
|
|
152
|
+
# (tmux -L kaizen, your own sessions untouched) and keep working through
|
|
153
|
+
# a board restart or crash; the next board shows them again mid-step.
|
|
154
|
+
# Linux and macOS with tmux installed; elsewhere it acts as off.
|
|
155
|
+
keep_alive: off
|
|
143
156
|
# Per-tool model and effort for the session the board launches, passed as that
|
|
144
157
|
# tool's own flags (claude --model/--effort, agy --model/--effort, codex -m and
|
|
145
158
|
# model_reasoning_effort, gemini -m, opencode -m). Model names are the tool's own:
|
|
@@ -18,6 +18,7 @@ nearest first, so a change lands globally unless this project keeps its own conf
|
|
|
18
18
|
| `review.executor` | `inline`, `subagent`, `ask` | Who reviews a lite run: this session, a cold reviewer agent, or ask before the review |
|
|
19
19
|
| `approvals.plan` | `true`, `false` | Stop and show the plan before anything is built |
|
|
20
20
|
| `approvals.review` | `true`, `false` | Stop after the review, before the run is called done |
|
|
21
|
+
| `auto_accept` | `false`, `true` | In `auto` mode, finish a run that changed files without the final approval (marked auto-accepted) |
|
|
21
22
|
| `approvals.each_file` | `true`, `false` | Confirm every individual edit |
|
|
22
23
|
| `auto_fix.enabled` | `true`, `false` | Fix findings without asking, or hand every one over |
|
|
23
24
|
| `auto_fix.min_severity` | `critical`, `high`, `medium`, `low` | How bad a finding must be to be fixed automatically |
|
|
@@ -133,7 +133,33 @@ whose changes leave every note true touches nothing and says so in one line.
|
|
|
133
133
|
|
|
134
134
|
## Final approval
|
|
135
135
|
|
|
136
|
-
Controlled by `approvals.review
|
|
136
|
+
Controlled by `approvals.review`. `auto` skips every stop before it, not this one, unless `auto_accept` is on.
|
|
137
|
+
|
|
138
|
+
**The gate is a stop, in every runner.** With `approvals.review` on, a run whose
|
|
139
|
+
`03-impl.md` names changed files is not done until `02-approval.md` holds an
|
|
140
|
+
acceptance line, exactly one of:
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
accepted: <ISO 8601 time> by user via board
|
|
144
|
+
accepted: <ISO 8601 time> by user via chat
|
|
145
|
+
accepted: <ISO 8601 time> auto (auto_accept)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The review ends by writing `stage: "review"`, `awaiting: "approvals.review"` and
|
|
149
|
+
stopping; never write `stage: "done"` in the same step as the review, and never from
|
|
150
|
+
`plan` or `build`. The board's Approve writes the `via board` line itself. On
|
|
151
|
+
`/kaizen approve` or a clear approval of this run in conversation ("approve", "looks
|
|
152
|
+
good, ship it"), finish with `kaizen done <id> --user-approved`, which appends the `via chat`
|
|
153
|
+
line and sets `done`. Without the user's yes run plain `kaizen done <id>`: it refuses and
|
|
154
|
+
tells you to ask. kaizen reads and rewrites a gate-on run marked `done` without the
|
|
155
|
+
`accepted:` line back to `review` / `approvals.review`, so setting `done` early only gets
|
|
156
|
+
it undone. The flag stops forgetting and shortcuts, not forgery. A request that only
|
|
157
|
+
names a later step, such as "commit and push", is not one: ask once whether it
|
|
158
|
+
approves the run. In `auto` mode the run stops there too ("finished, waiting for your
|
|
159
|
+
approval"), unless `auto_accept` is `true`: then append the `auto (auto_accept)` line
|
|
160
|
+
and set `done`. A run that changed no files, or runs with `approvals.review` off, may
|
|
161
|
+
go `done` without the line. A run marked `done` without it shows on the board as
|
|
162
|
+
"done, not approved", and its commit is refused until it is approved.
|
|
137
163
|
|
|
138
164
|
Report: what was built (for a code run, show its Preview proof), verification results, findings fixed, findings still open,
|
|
139
165
|
every criterion the reviewer answered `CANNOT VERIFY` with the check it says a human
|
|
@@ -167,7 +193,7 @@ in *Backlog* above. Check existing entries and do not append a duplicate. Builde
|
|
|
167
193
|
notes outside the approved scope are reported, but are not filed without an explicit
|
|
168
194
|
request.
|
|
169
195
|
|
|
170
|
-
|
|
196
|
+
Finish with `kaizen done <id>` once the user accepts (`--user-approved` for a yes given in chat); do not hand-write `stage: "done"`.
|
|
171
197
|
|
|
172
198
|
**Commit at done, when `git.auto_commit` is `true`.** Setting `stage: "done"` — the
|
|
173
199
|
user approving at review, or an `auto` run finishing — is then the ask to commit, under
|
|
@@ -28,6 +28,7 @@ anything.
|
|
|
28
28
|
| `/kaizen run` | Resume the current run and execute the approved plan |
|
|
29
29
|
| `/kaizen review [target]` | Review-only: audit existing code, no plan, no implementation |
|
|
30
30
|
| `/kaizen status` | List every run grouped waiting-on-you / in flight / done / abandoned, plus open backlog count |
|
|
31
|
+
| `kaizen done <id> [--user-approved]` | Finish a run; refused while the review gate waits on the user, `--user-approved` after a clear yes in chat |
|
|
31
32
|
| `/kaizen backlog` | Print open backlog items across all runs, grouped by source run, rescued items last under `Orphaned` |
|
|
32
33
|
| `/kaizen gather` | Read request sources kaizen cannot read by itself; their requests land in the icebox, nothing starts |
|
|
33
34
|
| `/kaizen discover` | Group what is in the icebox and promote the ideas you pick; nothing starts |
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// The Projects "+" sheet, modelled on Orca's "Add a project": a chooser (existing folder,
|
|
2
|
+
// clone from URL, create new project, new workspace), then one form with a way back.
|
|
3
|
+
// Every call is a JSON POST to the board; the server validates paths, URLs and refs again.
|
|
4
|
+
import { html, modal } from "./dom.ts";
|
|
5
|
+
import { gitProjects, wsHref } from "./workspace.ts";
|
|
6
|
+
|
|
7
|
+
type Start = "folder" | "clone" | "create" | "ws";
|
|
8
|
+
const SEP = (p: string) => (p.includes("\\") ? "\\" : "/");
|
|
9
|
+
|
|
10
|
+
async function call(path: string, body?: object): Promise<{ ok: boolean; d: any }> {
|
|
11
|
+
try {
|
|
12
|
+
const r = await fetch(path, body ? { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) } : undefined);
|
|
13
|
+
const d = await r.json().catch(() => ({}));
|
|
14
|
+
return { ok: r.ok, d: r.ok ? d : { error: d.error || d.why || "that did not work" } };
|
|
15
|
+
} catch {
|
|
16
|
+
return { ok: false, d: { error: "the board is offline" } };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// opts.dir: the project the + was opened for (preselected in New workspace); opts.start skips the chooser.
|
|
21
|
+
export function openAdd(opts: { dir?: string | null; start?: Start } = {}) {
|
|
22
|
+
const dl = modal("");
|
|
23
|
+
const form = dl.querySelector("form")!;
|
|
24
|
+
dl.setAttribute("aria-label", "Add a project");
|
|
25
|
+
const fixed = opts.start === "ws"; // opened from a project row: no chooser to go back to
|
|
26
|
+
const field = (n: string) => form.elements.namedItem(n) as HTMLInputElement;
|
|
27
|
+
const busy = (b: HTMLButtonElement, on: boolean, say: string, idle: string) => ((b.disabled = on), (b.textContent = on ? say : idle));
|
|
28
|
+
const back = fixed ? "" : html`<button type="button" class="btn ghost" data-a="back">Back to add options</button>`;
|
|
29
|
+
const foot = (go: string) => html`<small class="att err" role="alert"></small><div class="row">${back}<button type="button" class="btn ghost" data-a="x">Cancel</button><button class="btn pri" data-a="go">${go}</button></div>`;
|
|
30
|
+
const say = (t: string) => ((form.querySelector(".err") as HTMLElement).textContent = t);
|
|
31
|
+
// A project was added: the sheet says so, then the board shows it (the saved project is what the pages read).
|
|
32
|
+
const landed = (stateDir: string, msg: string) => {
|
|
33
|
+
say(msg);
|
|
34
|
+
try {
|
|
35
|
+
localStorage.setItem("kz-proj", stateDir);
|
|
36
|
+
} catch {}
|
|
37
|
+
setTimeout(() => (location.href = "/?view=board"), 900);
|
|
38
|
+
};
|
|
39
|
+
// The folder dialog; with `name`, the picked folder is a parent and the project's name is appended.
|
|
40
|
+
const pick = async (into: HTMLInputElement, name?: () => string) => {
|
|
41
|
+
const p = await call("/pick-folder", {});
|
|
42
|
+
if (p.d.path) into.value = name ? p.d.path.replace(/[\\/]+$/, "") + SEP(p.d.path) + name() : p.d.path;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const draw = (v: Start | "menu") => {
|
|
46
|
+
const ws = gitProjects();
|
|
47
|
+
if (v === "menu") {
|
|
48
|
+
form.innerHTML = html`<b>Add a project</b><small class="att">Add a project to get started with kaizen.</small><button type="button" class="btn opt" data-go="folder"><b>Existing folder</b><small>A project, a Git repo, or any folder</small></button><small class="att">Other ways to add</small><button type="button" class="btn opt" data-go="clone"><b>Clone from URL</b><small>Clone a remote Git repository</small></button><button type="button" class="btn opt" data-go="create"><b>Create new project</b><small>Start from an empty folder</small></button>${ws.length ? html`<button type="button" class="btn opt" data-go="ws"><b>New workspace</b><small>A branch in its own folder, in a project you have</small></button>` : ""}<div class="row"><button type="button" class="btn ghost" data-a="x">Cancel</button></div>`.toString();
|
|
49
|
+
form.querySelectorAll<HTMLElement>("[data-go]").forEach((b) => (b.onclick = () => draw(b.dataset.go as Start)));
|
|
50
|
+
form.onsubmit = (e) => e.preventDefault();
|
|
51
|
+
} else if (v === "folder") {
|
|
52
|
+
form.innerHTML = html`<b>Existing folder</b><small class="att">Pick a folder, or type its path. A .kaizen folder is added to it.</small><div class="row"><input name="path" placeholder="/path/to/folder" aria-label="Folder" autocomplete="off" spellcheck="false" required><button type="button" class="btn ghost" data-a="pick">Pick…</button></div>${foot("Add project")}`.toString();
|
|
53
|
+
field("path").focus();
|
|
54
|
+
form.onsubmit = async (e) => {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
const b = form.querySelector<HTMLButtonElement>("[data-a=go]")!;
|
|
57
|
+
busy(b, true, "Adding...", "Add project");
|
|
58
|
+
const r = await call("/add-project", { path: field("path").value.trim() });
|
|
59
|
+
busy(b, false, "", "Add project");
|
|
60
|
+
r.ok ? landed(r.d.dir, r.d.already ? "Project already added" : "Project added") : say(r.d.error);
|
|
61
|
+
};
|
|
62
|
+
form.querySelector<HTMLElement>("[data-a=pick]")!.onclick = () => pick(field("path"));
|
|
63
|
+
} else if (v === "clone") {
|
|
64
|
+
form.innerHTML = html`<b>Clone from URL</b><small class="att">Enter the Git URL (https or ssh) and choose where to clone it.</small><input name="url" placeholder="https://github.com/user/repo.git" aria-label="Git URL" autocomplete="off" spellcheck="false" required><div class="row"><input name="to" placeholder="Folder to clone into" aria-label="Clone into" autocomplete="off" spellcheck="false"><button type="button" class="btn ghost" data-a="pick">Pick…</button></div>${foot("Clone")}`.toString();
|
|
65
|
+
field("url").focus();
|
|
66
|
+
let name = "", auto = ""; // the folder this form filled in; one the user typed is left alone
|
|
67
|
+
const check = async () => {
|
|
68
|
+
const u = field("url").value.trim();
|
|
69
|
+
if (!u) return false;
|
|
70
|
+
const r = await call("/clone", { url: u, check: true });
|
|
71
|
+
if (!r.ok) return say(r.d.error), false;
|
|
72
|
+
say("");
|
|
73
|
+
name = r.d.name;
|
|
74
|
+
if (!field("to").value.trim() || field("to").value === auto) field("to").value = auto = r.d.to;
|
|
75
|
+
return true;
|
|
76
|
+
};
|
|
77
|
+
field("url").onchange = check;
|
|
78
|
+
form.querySelector<HTMLElement>("[data-a=pick]")!.onclick = async () => ((await check()) ? pick(field("to"), () => name) : field("url").focus());
|
|
79
|
+
form.onsubmit = async (e) => {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
if (!(await check())) return;
|
|
82
|
+
const b = form.querySelector<HTMLButtonElement>("[data-a=go]")!;
|
|
83
|
+
busy(b, true, "Cloning...", "Clone");
|
|
84
|
+
const r = await call("/clone", { url: field("url").value.trim(), to: field("to").value.trim() || undefined });
|
|
85
|
+
busy(b, false, "", "Clone");
|
|
86
|
+
r.ok ? landed(r.d.dir, "Cloned") : say(r.d.error);
|
|
87
|
+
};
|
|
88
|
+
} else if (v === "create") {
|
|
89
|
+
form.innerHTML = html`<b>Create a new project</b><small class="att">Name it and kaizen will create the folder with a .kaizen inside.</small><input name="name" placeholder="my-project" aria-label="Name" autocomplete="off" spellcheck="false" required><div class="row"><input name="to" placeholder="Folder to create" aria-label="Create in" autocomplete="off" spellcheck="false"><button type="button" class="btn ghost" data-a="pick">Pick…</button></div><label class="att"><input type="checkbox" name="git" checked> Git repository</label>${foot("Create project")}`.toString();
|
|
90
|
+
field("name").focus();
|
|
91
|
+
let auto = "";
|
|
92
|
+
field("name").oninput = async () => {
|
|
93
|
+
const n = field("name").value.trim();
|
|
94
|
+
if (!n || /[\\/:*?"<>|]/.test(n) || (field("to").value.trim() && field("to").value !== auto)) return;
|
|
95
|
+
const r = await call("/new-project", { name: n, check: true });
|
|
96
|
+
if (r.ok && field("name").value.trim() === n) field("to").value = auto = r.d.to;
|
|
97
|
+
};
|
|
98
|
+
form.querySelector<HTMLElement>("[data-a=pick]")!.onclick = () => pick(field("to"), () => field("name").value.trim());
|
|
99
|
+
form.onsubmit = async (e) => {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
const b = form.querySelector<HTMLButtonElement>("[data-a=go]")!;
|
|
102
|
+
busy(b, true, "Creating...", "Create project");
|
|
103
|
+
const r = await call("/new-project", { name: field("name").value.trim(), to: field("to").value.trim() || undefined, git: field("git").checked });
|
|
104
|
+
busy(b, false, "", "Create project");
|
|
105
|
+
if (!r.ok) return say(r.d.error);
|
|
106
|
+
landed(r.d.dir, r.d.git === false ? "Project created, but git init failed" : "Project created");
|
|
107
|
+
};
|
|
108
|
+
} else {
|
|
109
|
+
// New workspace: a project (git ones), a branch name and the branch it starts from.
|
|
110
|
+
const cur = ws.some((p) => p.dir === opts.dir) ? opts.dir : ws[0]?.dir;
|
|
111
|
+
form.innerHTML = html`<b>New workspace</b><small class="att">A new branch in its own folder under .kaizen/wt/.</small><label class="att">Project<select name="project" aria-label="Project">${ws.map((p) => html`<option value="${p.dir}"${p.dir === cur ? " selected" : ""}>${p.name}</option>`)}</select></label><label class="att">Branch name<input name="branch" placeholder="feature/my-branch" aria-label="Branch name" autocomplete="off" spellcheck="false" required></label><label class="att">Base branch<select name="base" aria-label="Base branch"></select></label>${foot("Create workspace")}`.toString();
|
|
112
|
+
field("branch").focus();
|
|
113
|
+
const sel = form.elements.namedItem("base") as HTMLSelectElement;
|
|
114
|
+
const bases = async () => {
|
|
115
|
+
const r = await call("/branches?dir=" + encodeURIComponent(field("project").value));
|
|
116
|
+
const { def = "", branches = [] } = r.ok ? r.d : {};
|
|
117
|
+
sel.innerHTML = (branches as string[]).map((b) => html`<option${b === def ? " selected" : ""}>${b}</option>`.toString()).join("") || `<option value="">current branch</option>`;
|
|
118
|
+
};
|
|
119
|
+
(form.elements.namedItem("project") as HTMLSelectElement).onchange = bases;
|
|
120
|
+
bases();
|
|
121
|
+
form.onsubmit = async (e) => {
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
const dir = field("project").value;
|
|
124
|
+
const b = form.querySelector<HTMLButtonElement>("[data-a=go]")!;
|
|
125
|
+
busy(b, true, "Creating...", "Create workspace");
|
|
126
|
+
const r = await call("/worktree", { dir, branch: field("branch").value.trim(), base: sel.value || undefined });
|
|
127
|
+
busy(b, false, "", "Create workspace");
|
|
128
|
+
r.ok ? (dl.close(), (location.href = wsHref(dir, r.d.path))) : say(r.d.error);
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
form.querySelector<HTMLElement>("[data-a=x]")!.onclick = () => dl.close();
|
|
132
|
+
const bk = form.querySelector<HTMLElement>("[data-a=back]");
|
|
133
|
+
if (bk) bk.onclick = () => draw("menu");
|
|
134
|
+
};
|
|
135
|
+
draw(opts.start ?? "menu");
|
|
136
|
+
}
|
package/web/board/api.ts
CHANGED
|
@@ -95,7 +95,7 @@ export async function load(quiet) {
|
|
|
95
95
|
if (was && was.kind === "idea") follow(was);
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
|
-
if (store.runDoc) openRun(c, true, true);
|
|
98
|
+
if (store.runDoc && c.kind === "run") openRun(c, true, true);
|
|
99
99
|
else if (c.kind === "idea") ideaBody(c);
|
|
100
100
|
}
|
|
101
101
|
}
|
package/web/board/badge.ts
CHANGED
|
@@ -5,12 +5,12 @@ export function waitingCount(cards: BadgeCard[]) {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
// The rail's Projects list draws from the same cards: one fetch feeds both.
|
|
8
|
-
let onCards: ((cards: any[], projects?: any[]) => void) | null = null;
|
|
8
|
+
let onCards: ((cards: any[], projects?: any[], agents?: any[]) => void) | null = null;
|
|
9
9
|
export const onBoardCards = (f: typeof onCards) => { onCards = f; };
|
|
10
10
|
|
|
11
|
-
export function boardBadge(cards: BadgeCard[], projects?: unknown[]) {
|
|
11
|
+
export function boardBadge(cards: BadgeCard[], projects?: unknown[], agents?: unknown[]) {
|
|
12
12
|
generation++;
|
|
13
|
-
onCards?.(cards, projects);
|
|
13
|
+
onCards?.(cards, projects, agents);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
let generation = 0;
|
|
@@ -25,8 +25,8 @@ export async function refreshBoardBadge() {
|
|
|
25
25
|
try {
|
|
26
26
|
const r = await fetch("/state?all=1");
|
|
27
27
|
if (!r.ok) continue;
|
|
28
|
-
const { cards, projects } = await r.json();
|
|
29
|
-
if (!again && current === generation) boardBadge(cards, projects);
|
|
28
|
+
const { cards, projects, rail, agents } = await r.json();
|
|
29
|
+
if (!again && current === generation) boardBadge(cards, [...projects, ...(rail ?? [])], agents);
|
|
30
30
|
} catch { /* keep the last count while the board is offline */ }
|
|
31
31
|
} while (again);
|
|
32
32
|
loading = false;
|
package/web/board/cards.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { answer, decided, resumable, resume } from "./approvals.ts";
|
|
|
13
13
|
import { termsBadge } from "./terms.ts";
|
|
14
14
|
import { boardBadge, waitingCount } from "./badge.ts";
|
|
15
15
|
import { openWorkspace } from "./run-view.ts";
|
|
16
|
+
import { boardMode, drawWsBoard, initWsBoard, syncMode } from "./ws-board-ui.ts";
|
|
16
17
|
|
|
17
18
|
let filter = null;
|
|
18
19
|
let query = ""; // the header filter box, matched against a card's title and request
|
|
@@ -86,6 +87,8 @@ const actionOf = (c) =>
|
|
|
86
87
|
? "Sent to agent"
|
|
87
88
|
: c.status !== "waiting"
|
|
88
89
|
? "Open"
|
|
90
|
+
: c.healed
|
|
91
|
+
? "Approve"
|
|
89
92
|
: { "approvals.plan": "Review plan", findings: "See findings", "approvals.review": "Review work" }[c.awaiting] || "Open";
|
|
90
93
|
|
|
91
94
|
function card(c) {
|
|
@@ -675,6 +678,7 @@ export function render() {
|
|
|
675
678
|
const fk = focusedKey();
|
|
676
679
|
// All projects: only the ones ticked in the filter, or every one when none is.
|
|
677
680
|
const only = store.all && store.shown.size && showable().some((p) => store.shown.has(p.dir));
|
|
681
|
+
syncMode();
|
|
678
682
|
const cs = store.S.cards.filter((c) => c.archived === archive && (!only || store.shown.has(c.state))),
|
|
679
683
|
b = $("board");
|
|
680
684
|
b.innerHTML = "";
|
|
@@ -738,14 +742,17 @@ export function render() {
|
|
|
738
742
|
ns = sp.filter((p) => store.shown.has(p.dir)).length;
|
|
739
743
|
$("show").textContent = ns ? `Showing ${ns} of ${sp.length}` : "Showing all";
|
|
740
744
|
if (!$("showpop").hidden) showList();
|
|
741
|
-
|
|
745
|
+
// Workspaces mode: the same page, a different body.
|
|
746
|
+
const wsm = boardMode() === "ws";
|
|
747
|
+
if (wsm) drawWsBoard((dir) => (!only || store.shown.has(dir)) && (store.all || !store.S.dir || dir === store.S.dir));
|
|
748
|
+
if (!wsm && !cs.length && store.mode !== "new") {
|
|
742
749
|
b.innerHTML = archive
|
|
743
750
|
? '<div class="empty"><div class="mascot"></div><b>Nothing archived</b></div>'
|
|
744
751
|
: '<div class="empty"><div class="mascot"></div><b>Nothing here yet</b><p>Add an idea and kaizen will plan it, build it, and check the result.</p><button class="btn pri" id="newempty">New idea</button></div>';
|
|
745
752
|
if (!archive)
|
|
746
753
|
$("newempty").onclick = newIdea;
|
|
747
754
|
}
|
|
748
|
-
COLS.forEach((name, ci) => {
|
|
755
|
+
(wsm ? [] : COLS).forEach((name, ci) => {
|
|
749
756
|
const s = document.createElement("section");
|
|
750
757
|
const q = query.trim().toLowerCase();
|
|
751
758
|
const bl = ci === 0 && !archive && ideasTab === "backlog";
|
|
@@ -946,7 +953,7 @@ export function render() {
|
|
|
946
953
|
// The tab says how many runs wait on you, or agents wait on input, so a background tab still tells you.
|
|
947
954
|
const nw = waitingCount(store.S.cards);
|
|
948
955
|
document.title = nw ? `(${nw}) kaizen` : "kaizen";
|
|
949
|
-
if (store.all) boardBadge(store.S.cards, store.S.projects);
|
|
956
|
+
if (store.all) boardBadge(store.S.cards, [...store.S.projects, ...(store.S.rail ?? [])], store.S.agents);
|
|
950
957
|
termsBadge();
|
|
951
958
|
stopDictation(false); // forms were just rebuilt; a listener whose field is gone would write into nothing
|
|
952
959
|
if (fk && document.activeElement === document.body) cardEl(fk)?.focus({ preventScroll: true });
|
|
@@ -960,6 +967,7 @@ export function filterBox() {
|
|
|
960
967
|
query = el.value;
|
|
961
968
|
render();
|
|
962
969
|
});
|
|
970
|
+
initWsBoard(render);
|
|
963
971
|
el.addEventListener("keydown", (e) => {
|
|
964
972
|
if (e.key === "Escape") {
|
|
965
973
|
e.stopPropagation();
|
package/web/board/context.ts
CHANGED
package/web/board/fixes.ts
CHANGED
|
@@ -35,7 +35,7 @@ export function fixForm(c) {
|
|
|
35
35
|
return;
|
|
36
36
|
const el = document.createElement("div");
|
|
37
37
|
el.className = "inl fix";
|
|
38
|
-
el.innerHTML = html`<div class="q">Fix findings</div><div class="q dim">Opens your agent in this project, told to fix the ticked findings and recheck them.</div>${c.status === "waiting" ? html`<div class="q dim">
|
|
38
|
+
el.innerHTML = html`<div class="q">Fix findings</div><div class="q dim">Opens your agent in this project, told to fix the ticked findings and recheck them.</div>${c.status === "waiting" ? html`<div class="q dim">An agent is already open on this run; the fix is sent to it when it runs in its card, else another one opens.</div>` : ""}${
|
|
39
39
|
fs
|
|
40
40
|
.map((f) => {
|
|
41
41
|
const x = f.done ? " (closed)" : sent(f) ? " (sent)" : "";
|
|
@@ -73,7 +73,8 @@ export function fixForm(c) {
|
|
|
73
73
|
// Sent findings lock as sent, so a second press cannot open a second agent on them.
|
|
74
74
|
if (r.ok) {
|
|
75
75
|
toast(
|
|
76
|
-
"Fixing " + nums.length + " finding" + (nums.length === 1 ? "" : "s") + ", " +
|
|
76
|
+
"Fixing " + nums.length + " finding" + (nums.length === 1 ? "" : "s") + ", " +
|
|
77
|
+
(r.reused ? "sent to the agent already open in its card" : where(r) + ": " + via(r.agent)),
|
|
77
78
|
);
|
|
78
79
|
if (r.pty) store.wantTerm = key(c);
|
|
79
80
|
nums.forEach((n) => fixSent.add(k(n)));
|
package/web/board/git.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { toast } from "./toast.ts";
|
|
|
11
11
|
export function gitBtn(c) {
|
|
12
12
|
const g = store.runDoc.git,
|
|
13
13
|
k = store.runDoc.commit;
|
|
14
|
+
// Done without the user's acceptance: nothing commits until it is approved.
|
|
15
|
+
if (c.accept === "needs") return "";
|
|
14
16
|
if (c.archived || !g || !g.repo || !(c.status === "done" || c.awaiting === "approvals.review")) return "";
|
|
15
17
|
// A run already pushed keeps saying so; work changed since is offered beside it.
|
|
16
18
|
if (k && k.pushed)
|
package/web/board/home.ts
CHANGED
|
@@ -279,10 +279,14 @@ async function show(id) {
|
|
|
279
279
|
if (c.error) return toast(c.error);
|
|
280
280
|
if (cur?.id !== c.id) attachments = [];
|
|
281
281
|
const same = cur?.id === c.id && cur.messages.length === c.messages.length && !!$("hlog");
|
|
282
|
+
// The list's busy dot is from the last /chats: a turn that ended since redraws it.
|
|
283
|
+
const listed = chats.find((x) => x.id === c.id);
|
|
284
|
+
const ended = listed && listed.busy && !c.busy;
|
|
285
|
+
if (listed) listed.busy = !!c.busy;
|
|
282
286
|
cur = c;
|
|
283
287
|
remoteBusy = !!c.busy;
|
|
284
288
|
remember(c.id);
|
|
285
|
-
if (same) { updateReply(c.messages.at(-1)); syncSendButton(); }
|
|
289
|
+
if (same && !ended) { updateReply(c.messages.at(-1)); syncSendButton(); }
|
|
286
290
|
else draw();
|
|
287
291
|
follow(c.project);
|
|
288
292
|
// A turn started from another tab, or before a reload, is still running: follow it until it saves.
|
|
@@ -389,6 +393,8 @@ export async function openHome() {
|
|
|
389
393
|
if (pending) id = chats.find((c) => c.updated >= pending)?.id;
|
|
390
394
|
} catch (e) {}
|
|
391
395
|
}
|
|
396
|
+
// A new tab has no chat of its own yet: a chat still working is the one to follow.
|
|
397
|
+
if (!id) id = chats.find((c) => c.busy)?.id;
|
|
392
398
|
if (id && chats.some((c) => c.id === id)) await show(id);
|
|
393
399
|
else { remember(null); draw(); }
|
|
394
400
|
}
|