kaizen-agent 1.64.2 → 1.65.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/install.ts +18 -1
- package/cli/roadmap.ts +74 -0
- package/cli/skills.ts +3 -3
- package/cli/web.ts +55 -1
- package/commands/kaizen-concept.md +6 -0
- package/commands/kaizen-plan.md +1 -1
- package/commands/kaizen-roadmap.md +6 -0
- package/package.json +4 -2
- package/skills/kaizen/SKILL.md +19 -5
- package/skills/kaizen/config.default.yml +2 -2
- package/skills/kaizen/roadmap.md +25 -0
- package/skills/kaizen/settings.md +4 -0
- package/skills/kaizen/spec-main.md +27 -0
- package/skills/kaizen/spec-plan.md +37 -11
- package/skills/kaizen-concept/SKILL.md +262 -0
- package/skills/kaizen-concept/skill.json +1 -0
- package/skills/kaizen-help/SKILL.md +14 -89
- package/skills/media/kaizen-book/skill.json +1 -1
- package/skills/media/kaizen-deck/SKILL.md +2 -3
- package/skills/media/kaizen-deck/skill.json +1 -1
- package/skills/media/kaizen-video/SKILL.md +2 -2
- package/skills/media/kaizen-video/examples/{notula-promo → meeting-promo}/promo.json +3 -3
- package/skills/media/kaizen-video/examples/{notula-promo → meeting-promo}/record.json +1 -1
- package/skills/media/kaizen-video/examples/{notula-promo → meeting-promo}/seed.php +1 -1
- package/skills/media/kaizen-video/examples/{notula-promo → meeting-promo}/seed.py +1 -1
- package/skills/media/kaizen-video/references/licensing.md +1 -1
- package/skills/media/kaizen-video/references/promo.md +2 -2
- package/skills/media/kaizen-video/skill.json +1 -1
- package/skills/optional/kaizen-computer/skill.json +1 -1
- package/web/board/chat.ts +4 -3
- package/web/board/run-view.ts +18 -3
- package/web/board/settings-skills.ts +2 -2
- package/web/board/ws-tabs.ts +9 -0
- package/web/board.html +1 -1
- package/web/board.js +102 -102
- package/web/notebook.js +1 -1
- package/web/term.js +1 -1
- package/web/video.js +1 -1
- package/cli/__pycache__/computer-helper.cpython-314.pyc +0 -0
- package/cli/accounts.test.ts +0 -126
- package/cli/add-project.test.ts +0 -169
- package/cli/agent-prefs.test.ts +0 -127
- package/cli/automations.test.ts +0 -167
- package/cli/backlog.test.ts +0 -133
- package/cli/board.test.ts +0 -381
- package/cli/browser.test.ts +0 -132
- package/cli/chat.test.ts +0 -274
- package/cli/chatgpt.test.ts +0 -158
- package/cli/computer.test.ts +0 -155
- package/cli/docs.test.ts +0 -94
- package/cli/handoff.test.ts +0 -133
- package/cli/html.test.ts +0 -19
- package/cli/install.test.ts +0 -237
- package/cli/knowledge.test.ts +0 -179
- package/cli/localsend.test.ts +0 -84
- package/cli/logo.test.ts +0 -18
- package/cli/notes.test.ts +0 -249
- package/cli/onboarding.test.ts +0 -70
- package/cli/project-tree.test.ts +0 -40
- package/cli/pty.test.ts +0 -330
- package/cli/release.test.ts +0 -12
- package/cli/report.test.ts +0 -59
- package/cli/resources.test.ts +0 -50
- package/cli/restart.test.ts +0 -222
- package/cli/settings.test.ts +0 -153
- package/cli/setup.test.ts +0 -78
- package/cli/shell-agent.test.ts +0 -23
- package/cli/skills.test.ts +0 -89
- package/cli/sources.test.ts +0 -851
- package/cli/state.test.ts +0 -1639
- package/cli/term-image.test.ts +0 -23
- package/cli/usage.test.ts +0 -291
- package/cli/versions.test.ts +0 -154
- package/cli/video.test.ts +0 -545
- package/cli/web-accept.test.ts +0 -55
- package/cli/web-decide.test.ts +0 -54
- package/cli/web-pr.test.ts +0 -52
- package/cli/web-skills.test.ts +0 -32
- package/cli/web-symlink.test.ts +0 -29
- package/cli/workers.test.ts +0 -319
- package/cli/worktree.test.ts +0 -452
- package/cli/writeback.test.ts +0 -102
- package/skills/media/kaizen-video/scripts/__pycache__/intake.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/make_film.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/make_tiktok.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/render_cut.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/sfx.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/srt.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/transcribe.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/vo.cpython-314.pyc +0 -0
- package/web/board/search.test.ts +0 -20
- package/web/board/settings-pages.test.ts +0 -28
- package/web/board/settings-voice.test.ts +0 -18
- package/web/board/toast.test.ts +0 -77
- package/web/board/ws-board.test.ts +0 -77
- package/web/board/ws-name.test.ts +0 -10
- package/web/board/ws-tabs.test.ts +0 -213
- package/web/term-font.test.ts +0 -22
package/cli/web-decide.test.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
|
|
6
|
-
// A decision goes to the agent already open in the run's card; only with none does a new one start.
|
|
7
|
-
test.skipIf(process.platform === "win32")("board /decide reuses the run's open agent", async () => {
|
|
8
|
-
const home = realpathSync(mkdtempSync(join(tmpdir(), "kz-dec-")));
|
|
9
|
-
const proj = join(home, "proj"), st = join(proj, ".kaizen"), bin = join(home, "bin"), d = join(st, "runs", "2026-10-30-r");
|
|
10
|
-
mkdirSync(d, { recursive: true });
|
|
11
|
-
mkdirSync(bin);
|
|
12
|
-
mkdirSync(join(home, ".kaizen"));
|
|
13
|
-
writeFileSync(join(home, ".kaizen", "projects"), proj + "\n");
|
|
14
|
-
writeFileSync(join(st, "config.yml"), "agent:\n launch: card\n");
|
|
15
|
-
// A stand-in agent that stays open and saves what is typed into it.
|
|
16
|
-
writeFileSync(join(bin, "claude"), `#!/bin/sh\ncat > "${join(home, "typed")}"\n`);
|
|
17
|
-
chmodSync(join(bin, "claude"), 0o755);
|
|
18
|
-
const waiting = (awaiting: string) => writeFileSync(join(d, "state.json"), JSON.stringify({ id: "2026-10-30-r", agent: "claude", stage: "plan", awaiting }));
|
|
19
|
-
waiting("approvals.plan");
|
|
20
|
-
const port = 20000 + Math.floor(Math.random() * 20000);
|
|
21
|
-
mkdirSync(join(home, ".claude"), { recursive: true }); // an agent, or `kaizen web` stops at its no-agent notice
|
|
22
|
-
const p = Bun.spawn([process.execPath, join(import.meta.dir, "install.ts"), "web", "--foreground", "--no-open", "--port", String(port)],
|
|
23
|
-
{ env: { ...process.env, HOME: home, USERPROFILE: home, KAIZEN_HOME: join(home, "kz"), PATH: `${bin}:${process.env.PATH}` }, stdout: "ignore", stderr: "ignore" });
|
|
24
|
-
try {
|
|
25
|
-
const base = `http://127.0.0.1:${port}`;
|
|
26
|
-
for (let i = 0; i < 100; i++) { try { if ((await fetch(base + "/")).ok) break; } catch { /* not up yet */ } await Bun.sleep(100); }
|
|
27
|
-
const decide = async (awaiting: string) => (await fetch(base + "/decide", { method: "POST", headers: { origin: base, "content-type": "application/json" }, body: JSON.stringify({ dir: st, id: "2026-10-30-r", awaiting }) })).json() as any;
|
|
28
|
-
const first = await decide("approvals.plan");
|
|
29
|
-
expect(first.ok).toBe(true);
|
|
30
|
-
expect(first.pty).toBeTruthy();
|
|
31
|
-
await Bun.sleep(300);
|
|
32
|
-
waiting("approvals.plan");
|
|
33
|
-
const second = await decide("approvals.plan");
|
|
34
|
-
expect(second).toMatchObject({ ok: true, pty: first.pty, reused: true });
|
|
35
|
-
let typed = "";
|
|
36
|
-
for (let i = 0; i < 30 && !typed.includes("2026-10-30-r"); i++) { await Bun.sleep(100); try { typed = readFileSync(join(home, "typed"), "utf8"); } catch { /* not yet */ } }
|
|
37
|
-
expect(typed).toContain("2026-10-30-r");
|
|
38
|
-
expect(readFileSync(join(d, "terminals.json"), "utf8").split(first.pty).length).toBeGreaterThan(1);
|
|
39
|
-
// A plain tab has no session record: the run's Claude session finds it, a wrong one does not.
|
|
40
|
-
const sessions = join(st, "sessions"), pid = readFileSync(join(sessions, `${first.pty}.pid`), "utf8").trim();
|
|
41
|
-
rmSync(join(sessions, `${first.pty}.json`));
|
|
42
|
-
mkdirSync(join(home, ".claude", "sessions"), { recursive: true });
|
|
43
|
-
writeFileSync(join(home, ".claude", "sessions", `${pid}.json`), JSON.stringify({ pid: Number(pid), sessionId: "sess-plain-tab" }));
|
|
44
|
-
const session = (s: string) => writeFileSync(join(d, "state.json"), JSON.stringify({ id: "2026-10-30-r", agent: "claude", stage: "plan", awaiting: "approvals.plan", session: s }));
|
|
45
|
-
session("sess-plain-tab");
|
|
46
|
-
expect(await decide("approvals.plan")).toMatchObject({ ok: true, pty: first.pty, reused: true });
|
|
47
|
-
session("sess-another-one");
|
|
48
|
-
const fresh = await decide("approvals.plan");
|
|
49
|
-
expect(fresh.reused).toBeUndefined();
|
|
50
|
-
expect(fresh.pty).not.toBe(first.pty);
|
|
51
|
-
} finally {
|
|
52
|
-
p.kill();
|
|
53
|
-
}
|
|
54
|
-
}, 20000);
|
package/cli/web-pr.test.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { mkdtempSync, mkdirSync, realpathSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
|
|
6
|
-
// The Git tab's /pr takes the runs /commit takes: finished (or at the final approval),
|
|
7
|
-
// never the global state dir, and create/merge only once the final approval is given.
|
|
8
|
-
test.skipIf(process.platform === "win32")("board /pr refuses unfinished, unapproved and global runs", async () => {
|
|
9
|
-
const home = realpathSync(mkdtempSync(join(tmpdir(), "kz-pr-")));
|
|
10
|
-
const proj = join(home, "proj"), st = join(proj, ".kaizen");
|
|
11
|
-
mkdirSync(join(proj, "cli"), { recursive: true });
|
|
12
|
-
writeFileSync(join(proj, "cli", "a.ts"), "");
|
|
13
|
-
mkdirSync(join(home, ".kaizen", "runs", "2026-10-30-global"), { recursive: true });
|
|
14
|
-
writeFileSync(join(home, ".kaizen", "runs", "2026-10-30-global", "state.json"), JSON.stringify({ stage: "done" }));
|
|
15
|
-
writeFileSync(join(home, ".kaizen", "projects"), proj + "\n");
|
|
16
|
-
const mk = (id: string, state: object) => {
|
|
17
|
-
const d = join(st, "runs", id);
|
|
18
|
-
mkdirSync(d, { recursive: true });
|
|
19
|
-
writeFileSync(join(d, "state.json"), JSON.stringify(state));
|
|
20
|
-
writeFileSync(join(d, "03-impl.md"), "## Changed\n- `cli/a.ts`\n");
|
|
21
|
-
};
|
|
22
|
-
mkdirSync(st, { recursive: true });
|
|
23
|
-
writeFileSync(join(st, "config.yml"), "approvals:\n review: true\n");
|
|
24
|
-
mk("2026-10-30-building", { stage: "build" });
|
|
25
|
-
mk("2026-10-30-unapproved", { stage: "done" }); // done with changed files, no accepted: line
|
|
26
|
-
const port = 20000 + Math.floor(Math.random() * 20000);
|
|
27
|
-
mkdirSync(join(home, ".claude"), { recursive: true }); // an agent, or `kaizen web` stops at its no-agent notice
|
|
28
|
-
const p = Bun.spawn([process.execPath, join(import.meta.dir, "install.ts"), "web", "--foreground", "--no-open", "--port", String(port)],
|
|
29
|
-
{ env: { ...process.env, HOME: home, USERPROFILE: home, KAIZEN_HOME: join(home, "kz") }, stdout: "ignore", stderr: "ignore" });
|
|
30
|
-
try {
|
|
31
|
-
const base = `http://127.0.0.1:${port}`;
|
|
32
|
-
for (let i = 0; i < 100; i++) { try { if ((await fetch(base + "/")).ok) break; } catch { /* not up yet */ } await Bun.sleep(100); }
|
|
33
|
-
const pr = async (dir: string, id: string, op: string) => {
|
|
34
|
-
const r = await fetch(base + "/pr", { method: "POST", headers: { origin: base, "content-type": "application/json" }, body: JSON.stringify({ dir, id, op, title: "feat: x" }) });
|
|
35
|
-
return { status: r.status, body: await r.json() };
|
|
36
|
-
};
|
|
37
|
-
for (const op of ["create", "merge", "remove"]) {
|
|
38
|
-
expect((await pr(st, "2026-10-30-building", op)).status).toBe(409);
|
|
39
|
-
expect((await pr(join(home, ".kaizen"), "2026-10-30-global", op)).status).toBe(409);
|
|
40
|
-
}
|
|
41
|
-
for (const op of ["create", "merge"]) {
|
|
42
|
-
const r = await pr(st, "2026-10-30-unapproved", op);
|
|
43
|
-
expect(r.status).toBe(409);
|
|
44
|
-
expect(JSON.stringify(r.body)).toContain("not approved");
|
|
45
|
-
}
|
|
46
|
-
// remove is not gated on the approval, but a run with no worktree has nothing to remove.
|
|
47
|
-
const rm = await pr(st, "2026-10-30-unapproved", "remove");
|
|
48
|
-
expect(rm.status).toBe(409);
|
|
49
|
-
expect(JSON.stringify(rm.body)).toContain("no worktree");
|
|
50
|
-
expect((await pr(st, "../x", "create")).status).toBe(400);
|
|
51
|
-
} finally { p.kill(); }
|
|
52
|
-
}, 30000);
|
package/cli/web-skills.test.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
|
|
6
|
-
// Turning an off-by-default skill on needs the one-time token from GET /skills; a bare
|
|
7
|
-
// POST with confirm:true (what curl sends) is refused, and a token works once.
|
|
8
|
-
test("board refuses to turn Desktop control on without the page's one-time token", async () => {
|
|
9
|
-
const home = realpathSync(mkdtempSync(join(tmpdir(), "kz-sk-")));
|
|
10
|
-
mkdirSync(join(home, ".claude"), { recursive: true });
|
|
11
|
-
mkdirSync(join(home, ".kaizen"), { recursive: true });
|
|
12
|
-
const port = 20000 + Math.floor(Math.random() * 20000);
|
|
13
|
-
const p = Bun.spawn([process.execPath, join(import.meta.dir, "install.ts"), "web", "--foreground", "--no-open", "--port", String(port)],
|
|
14
|
-
{ env: { ...process.env, HOME: home, USERPROFILE: home, KAIZEN_HOME: join(home, "kz") }, stdout: "ignore", stderr: "ignore" });
|
|
15
|
-
try {
|
|
16
|
-
const base = `http://127.0.0.1:${port}`;
|
|
17
|
-
for (let i = 0; i < 100; i++) { try { if ((await fetch(base + "/")).ok) break; } catch { /* not up yet */ } await Bun.sleep(100); }
|
|
18
|
-
const post = (body: object) => fetch(base + "/skills", { method: "POST", headers: { origin: base, "content-type": "application/json" }, body: JSON.stringify({ id: "kaizen-computer", on: true, ...body }) });
|
|
19
|
-
const on = () => existsSync(join(home, ".kaizen", "skills-on.json")) && readFileSync(join(home, ".kaizen", "skills-on.json"), "utf8").includes("kaizen-computer");
|
|
20
|
-
expect((await post({ confirm: true })).status).toBe(400);
|
|
21
|
-
const { token } = await (await fetch(base + "/skills")).json() as { token: string };
|
|
22
|
-
expect((await post({ confirm: true, token: "wrong" })).status).toBe(400);
|
|
23
|
-
expect(on()).toBe(false);
|
|
24
|
-
const t2 = (await (await fetch(base + "/skills")).json() as { token: string }).token;
|
|
25
|
-
expect(t2).not.toBe(token);
|
|
26
|
-
expect((await post({ confirm: true, token })).status).toBe(400); // an older token is dead
|
|
27
|
-
const t3 = (await (await fetch(base + "/skills")).json() as { token: string }).token;
|
|
28
|
-
expect((await post({ confirm: true, token: t3 })).status).toBe(200);
|
|
29
|
-
expect(on()).toBe(true);
|
|
30
|
-
expect((await post({ confirm: true, token: t3 })).status).toBe(400); // spent: a token works once
|
|
31
|
-
} finally { p.kill(); }
|
|
32
|
-
}, 20000);
|
package/cli/web-symlink.test.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { mkdtempSync, mkdirSync, symlinkSync, writeFileSync, realpathSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
|
|
6
|
-
// A project registered under its realpath must still be reached by the symlink spelling
|
|
7
|
-
// the board was offered; a dir that was never registered stays refused.
|
|
8
|
-
test.skipIf(process.platform === "win32")("board accepts a symlink spelling of a registered project", async () => {
|
|
9
|
-
const home = realpathSync(mkdtempSync(join(tmpdir(), "kz-sym-")));
|
|
10
|
-
const real = join(home, "real", "proj"), link = join(home, "link");
|
|
11
|
-
mkdirSync(join(real, ".kaizen"), { recursive: true });
|
|
12
|
-
mkdirSync(join(home, ".kaizen"), { recursive: true });
|
|
13
|
-
mkdirSync(join(home, "other", ".kaizen"), { recursive: true });
|
|
14
|
-
symlinkSync(real, link);
|
|
15
|
-
writeFileSync(join(home, ".kaizen", "projects"), real + "\n");
|
|
16
|
-
const port = 20000 + Math.floor(Math.random() * 20000);
|
|
17
|
-
mkdirSync(join(home, ".claude"), { recursive: true }); // an agent, or `kaizen web` stops at its no-agent notice
|
|
18
|
-
const p = Bun.spawn([process.execPath, join(import.meta.dir, "install.ts"), "web", "--foreground", "--no-open", "--port", String(port)],
|
|
19
|
-
{ env: { ...process.env, HOME: home, USERPROFILE: home, KAIZEN_HOME: join(home, "kz") }, stdout: "ignore", stderr: "ignore" });
|
|
20
|
-
try {
|
|
21
|
-
const base = `http://127.0.0.1:${port}`;
|
|
22
|
-
for (let i = 0; i < 100; i++) { try { if ((await fetch(base + "/")).ok) break; } catch { /* not up yet */ } await Bun.sleep(100); }
|
|
23
|
-
const post = (dir: string) => fetch(base + "/cd", { method: "POST", headers: { origin: base, "content-type": "application/json" }, body: JSON.stringify({ dir }) });
|
|
24
|
-
const ok = await post(join(link, ".kaizen"));
|
|
25
|
-
expect(ok.status).toBe(200);
|
|
26
|
-
const no = await post(join(home, "other", ".kaizen"));
|
|
27
|
-
expect(no.status).toBe(404);
|
|
28
|
-
} finally { p.kill(); }
|
|
29
|
-
}, 20000);
|
package/cli/workers.test.ts
DELETED
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
// Orchestration against throwaway git repos: nothing here touches a real project or agent folder.
|
|
2
|
-
import { afterAll, expect, test } from "bun:test";
|
|
3
|
-
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { delimiter, dirname, join } from "node:path";
|
|
6
|
-
import { readReport, signalOf } from "./report.ts";
|
|
7
|
-
import { workerStale, init, launchOf, merge, readWorkers, report, requested, requestStart, resolve, setRun, startWorker, statusText, type Status } from "./workers.ts";
|
|
8
|
-
|
|
9
|
-
const win = process.platform === "win32";
|
|
10
|
-
const t = win ? test.skip : test;
|
|
11
|
-
const roots: string[] = [];
|
|
12
|
-
afterAll(() => { for (const r of roots) rmSync(r, { recursive: true, force: true }); });
|
|
13
|
-
|
|
14
|
-
const g = (cwd: string, ...a: string[]) => {
|
|
15
|
-
const r = Bun.spawnSync(["git", ...a], { cwd, stdin: "ignore" });
|
|
16
|
-
if (r.exitCode !== 0) throw new Error(`git ${a.join(" ")}: ${r.stderr.toString()}`);
|
|
17
|
-
return r.stdout.toString().trim();
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// A repo with a run worktree on kaizen/<id>, a plan with two workers, and an approval that records the split.
|
|
21
|
-
let n = 0;
|
|
22
|
-
function fixture(o: { state?: object; plan?: string; approved?: boolean } = {}) {
|
|
23
|
-
const project = mkdtempSync(join(tmpdir(), "kaizen-workers-"));
|
|
24
|
-
roots.push(project);
|
|
25
|
-
const id = `2026-10-31-t${++n}`;
|
|
26
|
-
g(project, "init", "-q", "-b", "main");
|
|
27
|
-
g(project, "config", "user.email", "t@t"); g(project, "config", "user.name", "t");
|
|
28
|
-
writeFileSync(join(project, "a.txt"), "one\ntwo\nthree\n");
|
|
29
|
-
g(project, "add", "."); g(project, "commit", "-qm", "base");
|
|
30
|
-
const wt = join(project, ".kaizen", "wt", id), branch = `kaizen/${id}`;
|
|
31
|
-
g(project, "worktree", "add", "-q", "-b", branch, wt);
|
|
32
|
-
const dir = join(project, ".kaizen", "runs", id);
|
|
33
|
-
mkdirSync(dir, { recursive: true });
|
|
34
|
-
writeFileSync(join(dir, "state.json"), JSON.stringify({ id, stage: "build", runner: "full", agent: "claude", orchestration: "on", worktree: wt, branch, ...o.state }));
|
|
35
|
-
writeFileSync(join(dir, "01-plan.md"), o.plan ?? "# Plan\n\n## Workers\n- w1 — left half — owns: src/left, a.txt\n- w2 — right half — owns: src/right\n\n## Goal\nx\n");
|
|
36
|
-
if (o.approved !== false) writeFileSync(join(dir, "02-approval.md"), "# Approval\n\nworkers: approved\n");
|
|
37
|
-
return { project, id, wt, branch, dir };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Marks a worker with a status and, when asked, gives it a real worktree and a committed change.
|
|
41
|
-
function setup(f: ReturnType<typeof fixture>, status: Status | Status[], edits?: Record<string, [string, string]>) {
|
|
42
|
-
expect(init(f.project, f.id)).toEqual({ ok: true, n: 2 });
|
|
43
|
-
const w = readWorkers(f.project, f.id)!;
|
|
44
|
-
w.workers.forEach((x, i) => {
|
|
45
|
-
x.status = Array.isArray(status) ? status[i]! : status;
|
|
46
|
-
g(f.project, "worktree", "add", "-q", "-b", x.branch, x.worktree, f.branch);
|
|
47
|
-
const e = edits?.[x.id];
|
|
48
|
-
if (e) { mkdirSync(dirname(join(x.worktree, e[0])), { recursive: true }); writeFileSync(join(x.worktree, e[0]), e[1]); g(x.worktree, "add", "."); g(x.worktree, "commit", "-qm", x.id); }
|
|
49
|
-
});
|
|
50
|
-
writeFileSync(join(f.dir, "workers.json"), JSON.stringify(w));
|
|
51
|
-
}
|
|
52
|
-
const head = (f: ReturnType<typeof fixture>) => g(f.wt, "rev-parse", "HEAD");
|
|
53
|
-
|
|
54
|
-
t("G-01 off: init writes nothing, status says off, the board finds nothing to start", () => {
|
|
55
|
-
const f = fixture({ state: { orchestration: undefined } });
|
|
56
|
-
expect(resolve(f.project, f.id).on).toBe(false);
|
|
57
|
-
const r = init(f.project, f.id);
|
|
58
|
-
expect(r.ok).toBe(false);
|
|
59
|
-
expect(existsSync(join(f.dir, "workers.json"))).toBe(false);
|
|
60
|
-
expect(statusText(f.project, f.id)).toContain("orchestration is off");
|
|
61
|
-
expect(requested(f.project)).toEqual([]);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
t("G-02 lite, Windows and no worktree each resolve off with a reason", () => {
|
|
65
|
-
expect(resolve(...(([f]) => [f.project, f.id] as const)([fixture({ state: { runner: "lite" } })]))).toMatchObject({ on: false, why: expect.stringContaining("lite") });
|
|
66
|
-
const w = fixture();
|
|
67
|
-
expect(resolve(w.project, w.id, "win32")).toMatchObject({ on: false, why: expect.stringContaining("Windows") });
|
|
68
|
-
const n = fixture({ state: { worktree: undefined, branch: undefined } });
|
|
69
|
-
expect(resolve(n.project, n.id)).toMatchObject({ on: false, why: expect.stringContaining("no worktree") });
|
|
70
|
-
expect(resolve(w.project, w.id)).toMatchObject({ on: true });
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
t("G-03 a worker has no bypass flag under own, even with global bypass; with bypass it is flagged and titled", () => {
|
|
74
|
-
const f = fixture();
|
|
75
|
-
const prefs = join(f.project, "agents.json");
|
|
76
|
-
writeFileSync(prefs, JSON.stringify({ permissions: "bypass", agents: { claude: { command: "/bin/sh" } } }));
|
|
77
|
-
process.env.KAIZEN_AGENT_PREFS = prefs;
|
|
78
|
-
try {
|
|
79
|
-
init(f.project, f.id);
|
|
80
|
-
const x = readWorkers(f.project, f.id)!.workers[0]!;
|
|
81
|
-
const own = launchOf(f.project, f.id, x, "own");
|
|
82
|
-
if (typeof own === "string") throw new Error(own);
|
|
83
|
-
expect(own.argv.join(" ")).not.toContain("dangerously");
|
|
84
|
-
expect([own.bypass, own.title]).toEqual([false, "Worker w1"]);
|
|
85
|
-
const by = launchOf(f.project, f.id, x, "bypass");
|
|
86
|
-
if (typeof by === "string") throw new Error(by);
|
|
87
|
-
expect(by.argv).toContain("--dangerously-skip-permissions");
|
|
88
|
-
expect([by.bypass, by.title]).toEqual([true, "Worker w1 · bypass"]);
|
|
89
|
-
} finally { delete process.env.KAIZEN_AGENT_PREFS; }
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
t("G-04 merge refuses unless every worker succeeded, and merges nothing", () => {
|
|
93
|
-
for (const bad of ["failed", "blocked", "unverified", "running", "requested"] as Status[]) {
|
|
94
|
-
const f = fixture();
|
|
95
|
-
setup(f, ["succeeded", bad], { w1: ["src-left.txt", "l"] });
|
|
96
|
-
const before = head(f), r = merge(f.project, f.id);
|
|
97
|
-
expect(r.ok).toBe(false);
|
|
98
|
-
expect(!r.ok && r.why).toContain(`w2 is ${bad}`);
|
|
99
|
-
expect(head(f)).toBe(before);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
t("merge: two succeeded workers land on the run's branch and their folders go", () => {
|
|
104
|
-
const f = fixture();
|
|
105
|
-
setup(f, "succeeded", { w1: ["src/left/l.txt", "left"], w2: ["src/right/r.txt", "right"] });
|
|
106
|
-
const r = merge(f.project, f.id);
|
|
107
|
-
expect(r.ok).toBe(true);
|
|
108
|
-
expect(readFileSync(join(f.wt, "src/left/l.txt"), "utf8")).toBe("left");
|
|
109
|
-
expect(readFileSync(join(f.wt, "src/right/r.txt"), "utf8")).toBe("right");
|
|
110
|
-
const w = readWorkers(f.project, f.id)!;
|
|
111
|
-
expect([w.merge?.status, ...w.workers.map((x) => x.status)]).toEqual(["merged", "merged", "merged"]);
|
|
112
|
-
expect(existsSync(w.workers[0]!.worktree)).toBe(false);
|
|
113
|
-
expect(g(f.project, "branch", "--list", w.workers[0]!.branch)).toBe("");
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
t("G-05 a conflict leaves the run's branch where it was, marks it, names the files and sets the blocker", () => {
|
|
117
|
-
const f = fixture();
|
|
118
|
-
setup(f, "succeeded", { w1: ["a.txt", "one\nLEFT\nthree\n"], w2: ["src/right/f.txt", "RIGHT"] });
|
|
119
|
-
// the run's own branch moved on and now clashes with w2's file
|
|
120
|
-
mkdirSync(join(f.wt, "src", "right"), { recursive: true });
|
|
121
|
-
writeFileSync(join(f.wt, "src", "right", "f.txt"), "RUN"); g(f.wt, "add", "."); g(f.wt, "commit", "-qm", "run");
|
|
122
|
-
const before = head(f), r = merge(f.project, f.id);
|
|
123
|
-
expect(r.ok).toBe(false);
|
|
124
|
-
expect(head(f)).toBe(before);
|
|
125
|
-
expect(g(f.wt, "status", "--porcelain")).toBe("");
|
|
126
|
-
const w = readWorkers(f.project, f.id)!;
|
|
127
|
-
expect(w.workers[1]!.status).toBe("conflict");
|
|
128
|
-
expect(w.merge).toMatchObject({ status: "conflict", sha0: before, conflicts: ["src/right/f.txt"] });
|
|
129
|
-
expect(readReport(join(f.project, ".kaizen"), f.id)?.blocked?.question).toContain("src/right/f.txt");
|
|
130
|
-
expect(readFileSync(new URL("./workers.ts", import.meta.url), "utf8")).not.toMatch(/"-X|--strategy|"-s"/);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
t("G-06 settings changed after init do not reach the run; the cap holds", () => {
|
|
134
|
-
const f = fixture();
|
|
135
|
-
init(f.project, f.id);
|
|
136
|
-
mkdirSync(join(f.project, ".kaizen"), { recursive: true });
|
|
137
|
-
writeFileSync(join(f.project, ".kaizen", "config.yml"), "orchestration:\n enabled: false\n max_workers: 1\n permissions: bypass\n");
|
|
138
|
-
setRun(f.project, f.id, "off") ?? null; // refused: it has workers
|
|
139
|
-
expect(statusText(f.project, f.id)).toContain("max 3 · permissions own · model inherit (frozen)");
|
|
140
|
-
// a hand-edited file with a fourth worker: the fourth start is refused
|
|
141
|
-
const w = readWorkers(f.project, f.id)!;
|
|
142
|
-
for (const id of ["w3", "w4"]) w.workers.push({ ...w.workers[0]!, id, status: "planned", after: [] });
|
|
143
|
-
w.workers[0]!.status = w.workers[1]!.status = w.workers[2]!.status = "running";
|
|
144
|
-
writeFileSync(join(f.dir, "workers.json"), JSON.stringify(w));
|
|
145
|
-
const r = requestStart(f.project, f.id, "w4", 100);
|
|
146
|
-
expect(r.ok).toBe(false);
|
|
147
|
-
expect(r.why).toContain("most allowed is 3");
|
|
148
|
-
expect(readWorkers(f.project, f.id)!.workers[3]!.status).toBe("planned");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
t("G-07 overlapping ownership and an unrecorded approval are refused", () => {
|
|
152
|
-
const o = fixture({ plan: "## Workers\n- w1 — a — owns: src\n- w2 — b — owns: src/deep/file.ts\n" });
|
|
153
|
-
const r = init(o.project, o.id);
|
|
154
|
-
expect(!r.ok && r.why).toContain("both own");
|
|
155
|
-
expect(existsSync(join(o.dir, "workers.json"))).toBe(false);
|
|
156
|
-
const u = fixture({ approved: false });
|
|
157
|
-
const r2 = init(u.project, u.id);
|
|
158
|
-
expect(!r2.ok && r2.why).toContain("approved");
|
|
159
|
-
expect(existsSync(join(u.dir, "workers.json"))).toBe(false);
|
|
160
|
-
const m = fixture({ plan: "## Workers\n- x1 — a — owns: a\n- w2 — b — owns: b\n" });
|
|
161
|
-
expect(init(m.project, m.id).ok).toBe(false);
|
|
162
|
-
const big = fixture({ plan: "## Workers\n- w1 — a — owns: a\n- w2 — b — owns: b\n- w3 — c — owns: c\n- w4 — d — owns: d\n" });
|
|
163
|
-
const r4 = init(big.project, big.id);
|
|
164
|
-
expect(!r4.ok && r4.why).toContain("most allowed is 3");
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
t("G-08 start times out cleanly with no board and puts the worker back to planned; only the board scan starts workers", () => {
|
|
168
|
-
const f = fixture();
|
|
169
|
-
init(f.project, f.id);
|
|
170
|
-
const r = requestStart(f.project, f.id, "w1", 400);
|
|
171
|
-
expect(r).toEqual({ ok: false, why: "the board did not start it: is `kaizen web` running?" });
|
|
172
|
-
expect(readWorkers(f.project, f.id)!.workers[0]!.status).toBe("planned");
|
|
173
|
-
expect(requested(f.project)).toEqual([]);
|
|
174
|
-
const web = readFileSync(new URL("./web.ts", import.meta.url), "utf8");
|
|
175
|
-
expect(web.match(/startWorker\(/g)?.length).toBe(1);
|
|
176
|
-
const cli = readFileSync(new URL("./workers.ts", import.meta.url), "utf8");
|
|
177
|
-
expect(cli).not.toContain("startPty");
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
t("G-09 done refuses a dirty worktree; cleanup uses branch -d, never -D", () => {
|
|
181
|
-
const f = fixture();
|
|
182
|
-
setup(f, "running");
|
|
183
|
-
const x = readWorkers(f.project, f.id)!.workers[0]!;
|
|
184
|
-
writeFileSync(join(x.worktree, "new.txt"), "x");
|
|
185
|
-
const why = report(f.project, f.id, "w1", "done", { outcome: "succeeded", summary: "done" });
|
|
186
|
-
expect(why).toContain("commit first");
|
|
187
|
-
g(x.worktree, "add", "."); g(x.worktree, "commit", "-qm", "w1");
|
|
188
|
-
expect(report(f.project, f.id, "w1", "done", { outcome: "bogus", summary: "x" })).toContain("succeeded or failed");
|
|
189
|
-
expect(report(f.project, f.id, "w1", "done", { outcome: "succeeded", summary: "done" })).toBeNull();
|
|
190
|
-
expect(readWorkers(f.project, f.id)!.workers[0]!.status).toBe("succeeded");
|
|
191
|
-
const src = readFileSync(new URL("./workers.ts", import.meta.url), "utf8");
|
|
192
|
-
expect(src).toContain('"branch", "-d"');
|
|
193
|
-
expect(src).not.toContain('"-D"');
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
t("G-10 a blocked worker lights the run's existing blocker signal", () => {
|
|
197
|
-
const f = fixture();
|
|
198
|
-
setup(f, "running");
|
|
199
|
-
expect(report(f.project, f.id, "w2", "blocked", { text: "which table?" })).toBeNull();
|
|
200
|
-
const st = join(f.project, ".kaizen"), rep = readReport(st, f.id);
|
|
201
|
-
expect(rep?.blocked?.question).toBe("w2: which table?");
|
|
202
|
-
expect(signalOf({ stage: "build" }, rep, undefined, Date.now(), 5)).toBe("blocked");
|
|
203
|
-
expect(report(f.project, f.id, "w2", "unblock")).toBeNull();
|
|
204
|
-
expect(readReport(st, f.id)?.blocked).toBeUndefined();
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
t("worker model: the run's own agent's name, frozen at init; empty keeps the line; a tool with no model flag ignores it and says so", () => {
|
|
208
|
-
const f = fixture();
|
|
209
|
-
const cfg = join(f.project, ".kaizen", "config.yml");
|
|
210
|
-
writeFileSync(cfg, "orchestration:\n worker_model:\n claude: haiku\n cursor: whatever\n codex: gpt-x\n");
|
|
211
|
-
expect(resolve(f.project, f.id).model).toBe("haiku"); // claude is this run's agent, not codex
|
|
212
|
-
init(f.project, f.id);
|
|
213
|
-
writeFileSync(cfg, "orchestration:\n worker_model:\n claude: opus\n");
|
|
214
|
-
expect(readWorkers(f.project, f.id)!.frozen.model).toBe("haiku");
|
|
215
|
-
expect(statusText(f.project, f.id)).toContain("model haiku (frozen)");
|
|
216
|
-
expect(resolve(f.project, f.id).model).toBe("opus");
|
|
217
|
-
writeFileSync(cfg, "orchestration:\n worker_model:\n claude: not a model\n");
|
|
218
|
-
expect(resolve(f.project, f.id).model).toBe("");
|
|
219
|
-
writeFileSync(cfg, "orchestration:\n worker_model:\n claude: \"\"\n");
|
|
220
|
-
expect(resolve(f.project, f.id).model).toBe("");
|
|
221
|
-
|
|
222
|
-
const prefs = join(f.project, "agents.json");
|
|
223
|
-
writeFileSync(prefs, JSON.stringify({ agents: { claude: { command: "/bin/sh" }, cursor: { command: "/bin/sh" } } }));
|
|
224
|
-
process.env.KAIZEN_AGENT_PREFS = prefs;
|
|
225
|
-
try {
|
|
226
|
-
const x = readWorkers(f.project, f.id)!.workers[0]!;
|
|
227
|
-
const go = (pick: string) => { const l = launchOf(f.project, f.id, x, "own", undefined, pick); if (typeof l === "string") throw new Error(l); return l; };
|
|
228
|
-
const inh = go("");
|
|
229
|
-
expect(inh.argv).not.toContain("--model");
|
|
230
|
-
expect(inh.model).toBeUndefined();
|
|
231
|
-
const pick = go("sonnet");
|
|
232
|
-
expect(pick.argv.slice(pick.argv.indexOf("--model"), pick.argv.indexOf("--model") + 2)).toEqual(["--model", "sonnet"]);
|
|
233
|
-
expect([pick.model, pick.modelNote]).toEqual(["sonnet", undefined]);
|
|
234
|
-
const st = JSON.parse(readFileSync(join(f.dir, "state.json"), "utf8"));
|
|
235
|
-
writeFileSync(join(f.dir, "state.json"), JSON.stringify({ ...st, agent: "cursor" }));
|
|
236
|
-
const none = launchOf(f.project, f.id, x, "own", undefined, "haiku");
|
|
237
|
-
if (typeof none === "string") throw new Error(none);
|
|
238
|
-
expect(none.argv).not.toContain("--model");
|
|
239
|
-
expect(none.model).toBeUndefined();
|
|
240
|
-
expect(none.modelNote).toContain("takes no model flag");
|
|
241
|
-
} finally { delete process.env.KAIZEN_AGENT_PREFS; }
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
t("fix 1: a worker with after: branches off the worker it follows and sees its code", () => {
|
|
245
|
-
const f = fixture({ plan: "## Workers\n- w1 — left — owns: src/left\n- w2 — right — owns: src/right — after: w1\n" });
|
|
246
|
-
expect(init(f.project, f.id)).toEqual({ ok: true, n: 2 });
|
|
247
|
-
const w = readWorkers(f.project, f.id)!, [a, b] = w.workers as [typeof w.workers[0], typeof w.workers[0]];
|
|
248
|
-
g(f.project, "worktree", "add", "-q", "-b", a.branch, a.worktree, f.branch);
|
|
249
|
-
mkdirSync(join(a.worktree, "src"), { recursive: true });
|
|
250
|
-
writeFileSync(join(a.worktree, "src", "left"), "L"); g(a.worktree, "add", "."); g(a.worktree, "commit", "-qm", "w1");
|
|
251
|
-
a.status = "succeeded"; b.status = "requested"; b.requestedAt = Date.now();
|
|
252
|
-
writeFileSync(join(f.dir, "workers.json"), JSON.stringify(w));
|
|
253
|
-
// CI has no agent installed: a stand-in on PATH, so the start gets as far as the branch.
|
|
254
|
-
const bin = join(f.project, "bin"), path = process.env.PATH;
|
|
255
|
-
mkdirSync(bin);
|
|
256
|
-
writeFileSync(join(bin, "claude"), "#!/bin/sh\n", { mode: 0o755 });
|
|
257
|
-
writeFileSync(join(bin, "claude.cmd"), "@echo off\n");
|
|
258
|
-
process.env.PATH = `${bin}${delimiter}${path}`;
|
|
259
|
-
let r: ReturnType<typeof startWorker>;
|
|
260
|
-
try { r = startWorker(f.project, f.id, "w2"); } finally { process.env.PATH = path; }
|
|
261
|
-
expect(r.ok).toBe(true);
|
|
262
|
-
expect(readFileSync(join(b.worktree, "src", "left"), "utf8")).toBe("L");
|
|
263
|
-
// its own commit on top merges cleanly, and w1's code is not counted as w2's stray paths
|
|
264
|
-
mkdirSync(join(b.worktree, "src"), { recursive: true });
|
|
265
|
-
writeFileSync(join(b.worktree, "src", "right"), "R"); g(b.worktree, "add", "."); g(b.worktree, "commit", "-qm", "w2");
|
|
266
|
-
b.status = "succeeded";
|
|
267
|
-
writeFileSync(join(f.dir, "workers.json"), JSON.stringify(w));
|
|
268
|
-
expect(merge(f.project, f.id).ok).toBe(true);
|
|
269
|
-
expect(readFileSync(join(f.wt, "src", "right"), "utf8")).toBe("R");
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
t("fix 2: a stale request is not started by the board", () => {
|
|
273
|
-
const f = fixture();
|
|
274
|
-
init(f.project, f.id);
|
|
275
|
-
const w = readWorkers(f.project, f.id)!;
|
|
276
|
-
w.workers[0]!.status = "requested"; w.workers[0]!.requestedAt = Date.now() - 3_600_000;
|
|
277
|
-
writeFileSync(join(f.dir, "workers.json"), JSON.stringify(w));
|
|
278
|
-
expect(requested(f.project)).toEqual([]);
|
|
279
|
-
const r = startWorker(f.project, f.id, "w1");
|
|
280
|
-
expect(!r.ok && r.why).toContain("stale");
|
|
281
|
-
expect(existsSync(w.workers[0]!.worktree)).toBe(false);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
t("fix 3: merge refuses a branch that changed paths it does not own", () => {
|
|
285
|
-
const f = fixture();
|
|
286
|
-
setup(f, "succeeded", { w1: ["src/left", "l"], w2: ["elsewhere.txt", "x"] });
|
|
287
|
-
const before = head(f), r = merge(f.project, f.id);
|
|
288
|
-
expect(!r.ok && r.why).toContain("w2 changed paths it does not own (elsewhere.txt)");
|
|
289
|
-
expect(head(f)).toBe(before);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
t("fix 4: setRun writes state.json whole, with no temp file left", () => {
|
|
293
|
-
const f = fixture();
|
|
294
|
-
expect(setRun(f.project, f.id, "off")).toBeNull();
|
|
295
|
-
expect(JSON.parse(readFileSync(join(f.dir, "state.json"), "utf8")).orchestration).toBe("off");
|
|
296
|
-
expect(readdirSync(f.dir).filter((n) => n.endsWith(".tmp"))).toEqual([]);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
t("fix 5: merge says what cleanup left behind", () => {
|
|
300
|
-
const f = fixture();
|
|
301
|
-
setup(f, "succeeded", { w1: ["src/left", "l"], w2: ["src/right", "r"] });
|
|
302
|
-
const x = readWorkers(f.project, f.id)!.workers[0]!;
|
|
303
|
-
writeFileSync(join(x.worktree, "untracked.txt"), "u");
|
|
304
|
-
const r = merge(f.project, f.id);
|
|
305
|
-
expect(r.ok && r.left.length).toBe(2);
|
|
306
|
-
expect(r.ok && r.left.join("\n")).toContain("w1 folder");
|
|
307
|
-
expect(r.ok && r.left.join("\n")).toContain("w1 branch");
|
|
308
|
-
expect(existsSync(x.worktree)).toBe(true);
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
test("a live worker gone quiet reads stale; a busy, asking or done one does not", () => {
|
|
312
|
-
const run = { status: "running" }, old = { alive: true, lastOut: 0 }, t = 11 * 60_000;
|
|
313
|
-
expect(workerStale(run, old, t, 5)).toBe(true);
|
|
314
|
-
expect(workerStale(run, { ...old, busy: true }, t, 5)).toBe(false);
|
|
315
|
-
expect(workerStale(run, { ...old, asking: true }, t, 5)).toBe(false);
|
|
316
|
-
expect(workerStale(run, { alive: true, lastOut: t - 60_000 }, t, 5)).toBe(false);
|
|
317
|
-
expect(workerStale({ status: "succeeded" }, old, t, 5)).toBe(false);
|
|
318
|
-
expect(workerStale(run, null, t, 5)).toBe(false);
|
|
319
|
-
});
|