kaizen-agent 1.51.0 → 1.53.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/README.md +4 -4
- package/cli/chat-window.py +37 -0
- package/cli/chat.test.ts +274 -0
- package/cli/chat.ts +322 -0
- package/cli/install.ts +76 -1
- package/cli/settings.ts +25 -0
- package/cli/state.ts +2 -2
- package/cli/web.ts +156 -26
- package/package.json +1 -1
- package/skills/kaizen/config.default.yml +4 -0
- package/web/board/api.ts +2 -0
- package/web/board/home.ts +415 -0
- package/web/board/live.ts +13 -5
- package/web/board/projects.ts +1 -1
- package/web/board/views.ts +14 -8
- package/web/board.html +66 -4
- package/web/board.js +37 -34
- package/web/notebook.js +1 -1
- package/web/notes.html +7 -4
- package/web/popup.html +141 -0
- package/web/term.js +1 -1
- package/web/video.html +7 -4
- package/web/video.js +1 -1
package/README.md
CHANGED
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
<a href="https://www.npmjs.com/package/kaizen-agent"><img alt="npm" src="https://img.shields.io/npm/v/kaizen-agent?style=for-the-badge&color=000&labelColor=1c1c1e&logo=npm"></a>
|
|
12
12
|
<a href="https://github.com/hfadhlullah/kaizen/stargazers"><img alt="Stars" src="https://img.shields.io/github/stars/hfadhlullah/kaizen?style=for-the-badge&logo=github&color=000&labelColor=1c1c1e"></a>
|
|
13
13
|
<img alt="Bun 1.1+" src="https://img.shields.io/badge/Bun-1.1%2B-000?style=for-the-badge&logo=bun&logoColor=white">
|
|
14
|
-
<img alt="macOS · Linux · Windows
|
|
14
|
+
<img alt="macOS · Linux · Windows" src="https://img.shields.io/badge/macOS_·_Linux_·_Windows-000?style=for-the-badge">
|
|
15
15
|
<a href="LICENSE"><img alt="License MIT" src="https://img.shields.io/badge/license-MIT-000?style=for-the-badge"></a>
|
|
16
16
|
</p>
|
|
17
17
|
|
|
18
|
-
> **kaizen runs inside an AI agent; it is not one.** The agent does the work; kaizen gives it a plan, an approval stop and an independent review. It works with Claude Code, Codex, Antigravity and Gemini CLI, and the installer offers to set one up if you have none. A run costs several times a single prompt, so it is meant for work where being wrong is expensive.
|
|
18
|
+
> **kaizen runs inside an AI agent; it is not one.** The agent does the work; kaizen gives it a plan, an approval stop and an independent review. It works with Claude Code, Codex, Antigravity and Gemini CLI, and the installer offers to set one up if you have none. A run costs several times a single prompt, so it is meant for work where being wrong is expensive.
|
|
19
19
|
|
|
20
20
|
<br>
|
|
21
21
|
|
|
@@ -56,7 +56,7 @@ None of this is a lack of intelligence. It is a missing workflow. Many assistant
|
|
|
56
56
|
```bash
|
|
57
57
|
curl -fsSL https://bun.sh/install | bash && ~/.bun/bin/bunx kaizen-agent
|
|
58
58
|
```
|
|
59
|
-
On Windows
|
|
59
|
+
On Windows, in PowerShell:
|
|
60
60
|
```powershell
|
|
61
61
|
irm bun.sh/install.ps1 | iex; & "$env:USERPROFILE\.bun\bin\bunx.exe" kaizen-agent
|
|
62
62
|
```
|
|
@@ -75,7 +75,7 @@ None of this is a lack of intelligence. It is a missing workflow. Many assistant
|
|
|
75
75
|
| Runtime | [Bun](https://bun.sh) 1.1 or newer. The installer above gets it. |
|
|
76
76
|
| Agent | Claude Code, Codex, Antigravity or Gemini CLI. Claude Code gets the full flow with separate subagents; the others run every stage in one session. |
|
|
77
77
|
| Git | Needed for the board's commit and push. Optional otherwise. |
|
|
78
|
-
| OS | macOS, Linux
|
|
78
|
+
| OS | macOS, Linux, Windows. |
|
|
79
79
|
| Phone app | [Tailscale](https://tailscale.com/download) on the PC and the phone, same account. |
|
|
80
80
|
|
|
81
81
|
## How it works
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# `kaizen chat`'s window: a see-through WebKitGTK window, so the popup shows
|
|
2
|
+
# only its bubbles over the desktop. Chromium app windows always paint a
|
|
3
|
+
# background; this is used when python3 has GTK 3 and WebKit2GTK 4.1.
|
|
4
|
+
import sys
|
|
5
|
+
import gi
|
|
6
|
+
gi.require_version("Gtk", "3.0")
|
|
7
|
+
gi.require_version("Gdk", "3.0")
|
|
8
|
+
gi.require_version("WebKit2", "4.1")
|
|
9
|
+
from gi.repository import GLib, Gdk, Gtk, WebKit2
|
|
10
|
+
|
|
11
|
+
if len(sys.argv) > 1 and sys.argv[1] == "--check":
|
|
12
|
+
sys.exit(0)
|
|
13
|
+
GLib.set_prgname("kaizen-chat")
|
|
14
|
+
win = Gtk.Window(title="kaizen chat")
|
|
15
|
+
win.set_default_size(420, 600)
|
|
16
|
+
win.set_decorated(False)
|
|
17
|
+
win.set_app_paintable(True)
|
|
18
|
+
visual = win.get_screen().get_rgba_visual()
|
|
19
|
+
if visual:
|
|
20
|
+
win.set_visual(visual)
|
|
21
|
+
view = WebKit2.WebView()
|
|
22
|
+
clear = Gdk.RGBA()
|
|
23
|
+
clear.parse("rgba(0,0,0,0)")
|
|
24
|
+
view.set_background_color(clear)
|
|
25
|
+
# The page's drag handle: the compositor moves the window while the button is held.
|
|
26
|
+
def on_message(_manager, _result):
|
|
27
|
+
win.begin_move_drag(1, 0, 0, Gtk.get_current_event_time())
|
|
28
|
+
manager = view.get_user_content_manager()
|
|
29
|
+
manager.connect("script-message-received::kaizen", on_message)
|
|
30
|
+
manager.register_script_message_handler("kaizen")
|
|
31
|
+
# window.close() from the page (Esc) closes the window.
|
|
32
|
+
view.connect("close", lambda *_: win.destroy())
|
|
33
|
+
view.load_uri(sys.argv[1])
|
|
34
|
+
win.add(view)
|
|
35
|
+
win.connect("destroy", Gtk.main_quit)
|
|
36
|
+
win.show_all()
|
|
37
|
+
Gtk.main()
|
package/cli/chat.test.ts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// Home's chat: a fake `codex` on PATH stands in for the agent, prints the JSONL that
|
|
2
|
+
// `codex exec --json` prints, and records the argv, working folder and stdin it was given.
|
|
3
|
+
import { test, expect, beforeEach, afterEach } from "bun:test";
|
|
4
|
+
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, chmodSync } from "node:fs";
|
|
5
|
+
import { join, delimiter } from "node:path";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { sendChat, readChat, listChats, deleteChat, stopChat, parseLine, takeMoves, type Event, type Board, type Upload } from "./chat.ts";
|
|
8
|
+
|
|
9
|
+
let root = "", base = "", bin = "", projA = "", projD = "", board: Board, created: string[] = [], runs: string[][] = [];
|
|
10
|
+
const PATH = process.env.PATH;
|
|
11
|
+
const posix = process.platform !== "win32";
|
|
12
|
+
|
|
13
|
+
function fake(body: string) {
|
|
14
|
+
writeFileSync(join(bin, "codex"), `#!/bin/sh\nprintf '%s\\n' "$@" > "${bin}/argv"\npwd > "${bin}/cwd"\ncat > "${bin}/stdin"\n${body}\n`);
|
|
15
|
+
chmodSync(join(bin, "codex"), 0o755);
|
|
16
|
+
}
|
|
17
|
+
const say = (text: string) => `cat <<'J'
|
|
18
|
+
{"type":"thread.started","thread_id":"T1"}
|
|
19
|
+
{"type":"turn.started"}
|
|
20
|
+
{"type":"item.started","item":{"id":"i0","type":"command_execution","command":"/usr/bin/zsh -lc ls"}}
|
|
21
|
+
{"type":"item.completed","item":{"id":"i0","type":"command_execution","command":"/usr/bin/zsh -lc ls","exit_code":0,"status":"completed"}}
|
|
22
|
+
{"type":"item.started","item":{"id":"i1","type":"agent_message"}}
|
|
23
|
+
{"type":"item.completed","item":{"id":"i1","type":"agent_message","text":${JSON.stringify(text)}}}
|
|
24
|
+
{"type":"turn.completed"}
|
|
25
|
+
J`;
|
|
26
|
+
const argv = () => readFileSync(join(bin, "argv"), "utf8").trim().split("\n");
|
|
27
|
+
|
|
28
|
+
function turn(id: string | null, text: string, project: string | null = null, uploads: Upload[] = []) {
|
|
29
|
+
const events: Event[] = [];
|
|
30
|
+
return new Promise<{ events: Event[]; why: string | null; id: string }>((res) => {
|
|
31
|
+
const why = sendChat(base, id, text, project, board, (e) => {
|
|
32
|
+
events.push(e);
|
|
33
|
+
if (e.t === "done") res({ events, why: null, id: (events[0] as any).id });
|
|
34
|
+
}, false, uploads);
|
|
35
|
+
if (why) res({ events, why, id: "" });
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
root = mkdtempSync(join(tmpdir(), "kaizen-chat-"));
|
|
41
|
+
base = join(root, "home", ".kaizen");
|
|
42
|
+
projA = join(root, "A", ".kaizen");
|
|
43
|
+
projD = join(root, "D", ".kaizen");
|
|
44
|
+
for (const d of [base, projA, projD]) mkdirSync(d, { recursive: true });
|
|
45
|
+
bin = join(root, "bin");
|
|
46
|
+
mkdirSync(bin);
|
|
47
|
+
process.env.PATH = bin + delimiter + PATH;
|
|
48
|
+
created = [];
|
|
49
|
+
runs = [];
|
|
50
|
+
board = {
|
|
51
|
+
agents: ["claude", "codex"],
|
|
52
|
+
run: async (dir, runner, agent, text) => { runs.push([dir, runner, agent, text]); return { agent }; },
|
|
53
|
+
projects: [{ dir: projA, label: "A" }, { dir: projD, label: "D" }],
|
|
54
|
+
create: async (name) => {
|
|
55
|
+
if (name.includes("/")) return { error: "bad name" };
|
|
56
|
+
const d = join(root, name, ".kaizen");
|
|
57
|
+
mkdirSync(d, { recursive: true });
|
|
58
|
+
created.push(d);
|
|
59
|
+
return { dir: d };
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
afterEach(() => { process.env.PATH = PATH; });
|
|
64
|
+
|
|
65
|
+
test.if(posix)("a message streams the reply, saves both sides, runs in the chat's project, and resumes its thread", async () => {
|
|
66
|
+
fake(say("Hi."));
|
|
67
|
+
const { events, why, id } = await turn(null, "say hi", projA);
|
|
68
|
+
expect(why).toBeNull();
|
|
69
|
+
expect(events.map((e) => e.t)).toEqual(["chat", "status", "status", "step", "status", "text", "done"]);
|
|
70
|
+
expect((events[2] as any).text).toBe("Running ls");
|
|
71
|
+
expect((events[3] as any).step).toEqual({ kind: "cmd", text: "ls", ok: true });
|
|
72
|
+
const c = readChat(base, id)!;
|
|
73
|
+
expect(c).toMatchObject({ thread: "T1", project: projA });
|
|
74
|
+
expect(c.messages.map((m) => [m.role, m.text])).toEqual([["user", "say hi"], ["agent", "Hi."]]);
|
|
75
|
+
expect(c.messages[1].activity).toBeUndefined();
|
|
76
|
+
expect(readFileSync(join(bin, "cwd"), "utf8").trim()).toBe(join(root, "A"));
|
|
77
|
+
const stdin = readFileSync(join(bin, "stdin"), "utf8");
|
|
78
|
+
expect(stdin).toContain(`Project of this chat: A (${join(root, "A")})`);
|
|
79
|
+
expect(stdin).toContain(`- D — ${join(root, "D")}`);
|
|
80
|
+
expect(stdin.endsWith("say hi")).toBe(true);
|
|
81
|
+
expect(argv()).toContain("workspace-write");
|
|
82
|
+
expect(argv().slice(argv().indexOf("-m"), argv().indexOf("-m") + 4)).toEqual(["-m", "gpt-6-luna", "-c", "model_reasoning_effort=medium"]);
|
|
83
|
+
expect(argv()).not.toContain("resume");
|
|
84
|
+
expect(listChats(base).map((x) => [x.id, x.project])).toEqual([[id, projA]]);
|
|
85
|
+
|
|
86
|
+
fake(say("Again."));
|
|
87
|
+
await turn(id, "again");
|
|
88
|
+
expect(argv().slice(argv().indexOf("-m"), argv().indexOf("-m") + 4)).toEqual(["-m", "gpt-6-luna", "-c", "model_reasoning_effort=medium"]);
|
|
89
|
+
expect(argv().slice(-3)).toEqual(["resume", "T1", "-"]);
|
|
90
|
+
expect(readChat(base, id)!.messages).toHaveLength(4);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test.if(posix)("no project: a read-only scratch folder outside every project", async () => {
|
|
94
|
+
fake(say("Which project?"));
|
|
95
|
+
const { id } = await turn(null, "hello");
|
|
96
|
+
expect(readChat(base, id)!.project).toBeUndefined();
|
|
97
|
+
expect(readFileSync(join(bin, "cwd"), "utf8").trim()).toBe(join(base, "chats", "scratch"));
|
|
98
|
+
expect(argv()).toContain("workspace-write");
|
|
99
|
+
expect(argv().join(" ")).toContain(`--add-dir ${join(root, "A")} --add-dir ${join(root, "D")}`);
|
|
100
|
+
expect(readFileSync(join(bin, "stdin"), "utf8")).toContain("Project of this chat: none");
|
|
101
|
+
// A project the page names that the board does not list is not taken.
|
|
102
|
+
const r = await turn(null, "hi", join(root, "elsewhere", ".kaizen"));
|
|
103
|
+
expect(readChat(base, r.id)!.project).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test.if(posix)("uploaded images reach Codex and other files remain readable after reload", async () => {
|
|
107
|
+
fake(say("I can see both files."));
|
|
108
|
+
const image = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 1, 2, 3, 4]);
|
|
109
|
+
const { id } = await turn(null, "", projA, [
|
|
110
|
+
{ name: "../reference.png", bytes: image },
|
|
111
|
+
{ name: "brief.txt", bytes: new TextEncoder().encode("hello") },
|
|
112
|
+
]);
|
|
113
|
+
const c = readChat(base, id)!;
|
|
114
|
+
expect(c.title).toBe("../reference.png");
|
|
115
|
+
expect(c.messages[0].files?.map((f) => [f.name, f.image])).toEqual([["_reference.png", true], ["brief.txt", false]]);
|
|
116
|
+
for (const f of c.messages[0].files!) expect(existsSync(f.path)).toBe(true);
|
|
117
|
+
expect(argv()).toContain("-i");
|
|
118
|
+
expect(argv()[argv().indexOf("-i") + 1]).toBe(c.messages[0].files![0].path);
|
|
119
|
+
expect(readFileSync(join(bin, "stdin"), "utf8")).toContain(c.messages[0].files![1].path);
|
|
120
|
+
fake(say("Again."));
|
|
121
|
+
await turn(id, "check this too", null, [{ name: "more.png", bytes: image }]);
|
|
122
|
+
expect(argv().slice(-5)).toEqual(["resume", "T1", "-i", readChat(base, id)!.messages[2].files![0].path, "-"]);
|
|
123
|
+
expect(deleteChat(base, id)).toBeNull();
|
|
124
|
+
expect(existsSync(c.messages[0].files![0].path)).toBe(false);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test.if(posix)("the agent switches the chat to a listed project; the move line is not shown and the next turn runs there", async () => {
|
|
128
|
+
fake(say(`Switching to D.\n[[kaizen:project ${join(root, "D")}]]`));
|
|
129
|
+
const { events, id } = await turn(null, "let's work on D", projA);
|
|
130
|
+
expect(events.filter((e) => e.t === "text")).toEqual([{ t: "text", text: "Switching to D." }]);
|
|
131
|
+
expect(events.find((e) => e.t === "project")).toEqual({ t: "project", dir: projD });
|
|
132
|
+
expect(readChat(base, id)!.project).toBe(projD);
|
|
133
|
+
expect(readChat(base, id)!.messages[1].steps!.at(-1)).toEqual({ kind: "project", text: "Switched to D", ok: true });
|
|
134
|
+
fake(say("Here."));
|
|
135
|
+
await turn(id, "go on");
|
|
136
|
+
expect(readFileSync(join(bin, "cwd"), "utf8").trim()).toBe(join(root, "D"));
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test.if(posix)("a switched chat can continue the pending request in the same reply", async () => {
|
|
140
|
+
fake(say("Switching.\n[[kaizen:project D]]"));
|
|
141
|
+
const { id } = await turn(null, "check the latest build in D", projA);
|
|
142
|
+
fake(say("The latest build changed the shop."));
|
|
143
|
+
await new Promise<void>((res) => sendChat(base, id, "Continue the pending request.", null, board, (e) => {
|
|
144
|
+
if (e.t === "done") res();
|
|
145
|
+
}, true));
|
|
146
|
+
const c = readChat(base, id)!;
|
|
147
|
+
expect(c.messages).toHaveLength(2);
|
|
148
|
+
expect(c.messages[1].text).toBe("Switching.\n\nThe latest build changed the shop.");
|
|
149
|
+
expect(c.messages[1].activity).toBeUndefined();
|
|
150
|
+
expect(readFileSync(join(bin, "cwd"), "utf8").trim()).toBe(join(root, "D"));
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test.if(posix)("a switch to a path the board does not list is refused and the chat stays", async () => {
|
|
154
|
+
fake(say("[[kaizen:project /etc]]"));
|
|
155
|
+
const { events, id } = await turn(null, "go to etc", projA);
|
|
156
|
+
expect(events.some((e) => e.t === "project")).toBe(false);
|
|
157
|
+
expect(readChat(base, id)!.project).toBe(projA);
|
|
158
|
+
expect(readChat(base, id)!.messages[1].steps!.at(-1)).toMatchObject({ kind: "project", ok: false });
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test.if(posix)("the agent creates a new project through the board's rules and moves there", async () => {
|
|
162
|
+
fake(say("Creating it.\n[[kaizen:new-project Shop]]"));
|
|
163
|
+
const { events, id } = await turn(null, "start a shop app");
|
|
164
|
+
const d = join(root, "Shop", ".kaizen");
|
|
165
|
+
expect(created).toEqual([d]);
|
|
166
|
+
expect(events.find((e) => e.t === "project")).toEqual({ t: "project", dir: d });
|
|
167
|
+
expect(readChat(base, id)!.project).toBe(d);
|
|
168
|
+
fake(say("[[kaizen:new-project ../x]]"));
|
|
169
|
+
const r = await turn(null, "bad");
|
|
170
|
+
expect(readChat(base, r.id)!.messages[1].steps!.at(-1)).toMatchObject({ kind: "project", ok: false });
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("chat ids that could leave chats/ are refused before any disk access", () => {
|
|
174
|
+
for (const bad of ["../x", "a/b", "..", "", "x".repeat(81)]) {
|
|
175
|
+
expect(readChat(base, bad)).toBeNull();
|
|
176
|
+
expect(deleteChat(base, bad)).toBe("bad chat id");
|
|
177
|
+
}
|
|
178
|
+
expect(existsSync(join(base, "chats"))).toBe(false);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test.if(posix)("too many attachments are refused before a chat is created", async () => {
|
|
182
|
+
fake(say("should not run"));
|
|
183
|
+
const { why } = await turn(null, "files", projA, Array.from({ length: 6 }, (_, i) => ({ name: `${i}.txt`, bytes: new Uint8Array([i]) })));
|
|
184
|
+
expect(why).toMatch(/up to 5 files/);
|
|
185
|
+
expect(listChats(base)).toEqual([]);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test.if(posix)("stop kills the agent and keeps what was said so far", async () => {
|
|
189
|
+
fake(`echo '{"type":"thread.started","thread_id":"T2"}'\necho '{"type":"item.started","item":{"type":"command_execution","command":"/bin/sh -lc ls"}}'\necho '{"type":"item.completed","item":{"type":"agent_message","text":"Working"}}'\nsleep 30`);
|
|
190
|
+
const events: Event[] = [];
|
|
191
|
+
await new Promise<void>((res) => sendChat(base, null, "long job", projA, board, (e) => {
|
|
192
|
+
events.push(e);
|
|
193
|
+
if (e.t === "status") expect(readChat(base, (events[0] as any).id)!.messages[1].activity).toBe("Running ls");
|
|
194
|
+
if (e.t === "text") stopChat(base, (events[0] as any).id);
|
|
195
|
+
if (e.t === "done") res();
|
|
196
|
+
}));
|
|
197
|
+
const c = readChat(base, (events[0] as any).id)!;
|
|
198
|
+
expect(c.messages[1]).toMatchObject({ role: "agent", text: "Working", error: "Stopped." });
|
|
199
|
+
expect(c.messages[1].activity).toBeUndefined();
|
|
200
|
+
expect(listChats(base)[0].busy).toBe(false);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test.if(posix)("a turn persists activity and finishes independently of the page", async () => {
|
|
204
|
+
fake(`echo '{"type":"item.started","item":{"type":"command_execution","command":"/bin/sh -lc build"}}'\nsleep 0.05\necho '{"type":"item.completed","item":{"type":"agent_message","text":"Built."}}'`);
|
|
205
|
+
let id = "";
|
|
206
|
+
await new Promise<void>((res) => sendChat(base, null, "build", projA, board, (e) => {
|
|
207
|
+
if (e.t === "chat") id = e.id;
|
|
208
|
+
if (e.t === "status") expect(readChat(base, id)!.messages.at(-1)?.activity).toBe("Running build");
|
|
209
|
+
if (e.t === "done") res();
|
|
210
|
+
}));
|
|
211
|
+
expect(readChat(base, id)!.messages.at(-1)).toMatchObject({ text: "Built." });
|
|
212
|
+
expect(readChat(base, id)!.messages.at(-1)?.activity).toBeUndefined();
|
|
213
|
+
expect(listChats(base)[0].busy).toBe(false);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test.if(posix)("a failed turn reports the agent's error", async () => {
|
|
217
|
+
fake(`echo '{"type":"turn.failed","error":{"message":"model not supported"}}'; exit 1`);
|
|
218
|
+
const { events } = await turn(null, "x");
|
|
219
|
+
expect(events.find((e) => e.t === "error")).toEqual({ t: "error", error: "model not supported" });
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test("no codex on PATH: a message says how to get it", async () => {
|
|
223
|
+
process.env.PATH = bin;
|
|
224
|
+
const { why } = await turn(null, "hi");
|
|
225
|
+
expect(why).toMatch(/needs Codex/);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("parseLine and takeMoves", () => {
|
|
229
|
+
expect(parseLine("not json")).toBeNull();
|
|
230
|
+
expect(parseLine(`{"type":"turn.started"}`)).toEqual({ t: "status", text: "Thinking…" });
|
|
231
|
+
expect(parseLine(`{"type":"item.started","item":{"type":"mcp_tool_call","server":"docs","tool":"search"}}`))
|
|
232
|
+
.toEqual({ t: "status", text: "Using docs search" });
|
|
233
|
+
expect(parseLine(`{"type":"item.started","item":{"type":"web_search"}}`))
|
|
234
|
+
.toEqual({ t: "status", text: "Searching the web…" });
|
|
235
|
+
expect(parseLine(`{"type":"item.completed","item":{"type":"web_search","status":"completed"}}`))
|
|
236
|
+
.toEqual({ t: "step", step: { kind: "tool", text: "Web search", ok: true } });
|
|
237
|
+
expect(parseLine(`{"type":"item.completed","item":{"type":"error","message":"metadata"}}`)).toBeNull();
|
|
238
|
+
expect(parseLine(JSON.stringify({ type: "item.completed", item: { type: "command_execution", command: `/bin/bash -lc "cat a.md"`, exit_code: 1 } })))
|
|
239
|
+
.toEqual({ t: "step", step: { kind: "cmd", text: "cat a.md", ok: false } });
|
|
240
|
+
expect(parseLine(`{"type":"item.completed","item":{"type":"file_change","changes":[{"path":"a.ts"}],"status":"completed"}}`))
|
|
241
|
+
.toEqual({ t: "step", step: { kind: "edit", text: "a.ts", ok: true } });
|
|
242
|
+
expect(takeMoves("ok\n\n[[kaizen:project A]]\n")).toEqual({ text: "ok", move: { op: "project", arg: "A" }, run: null });
|
|
243
|
+
// Only a line of its own counts: a move quoted inside a sentence is text.
|
|
244
|
+
expect(takeMoves("write `[[kaizen:project A]]` to move").move).toBeNull();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test.if(posix)("every listed project is writable without a switch; the chat's own folder is not repeated", async () => {
|
|
248
|
+
fake(say("Read D."));
|
|
249
|
+
await turn(null, "what is in D", projA);
|
|
250
|
+
expect(argv().filter((a, i) => argv()[i - 1] === "--add-dir")).toEqual([join(root, "D")]);
|
|
251
|
+
const stdin = readFileSync(join(bin, "stdin"), "utf8");
|
|
252
|
+
expect(stdin).toContain("you do not need to switch");
|
|
253
|
+
expect(stdin).toContain("installed: claude, codex");
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test.if(posix)("a run line starts a kaizen run in the named project; the chat stays where it is", async () => {
|
|
257
|
+
fake(say(`Starting it.\n[[kaizen:run ${join(root, "D")} | full | claude | add a dark mode]]`));
|
|
258
|
+
const { events, id } = await turn(null, "1, full, claude", projA);
|
|
259
|
+
expect(events.filter((e) => e.t === "text")).toEqual([{ t: "text", text: "Starting it." }]);
|
|
260
|
+
expect(runs).toEqual([[projD, "full", "claude", "add a dark mode"]]);
|
|
261
|
+
expect(events.find((e) => e.t === "run")).toEqual({ t: "run", dir: projD });
|
|
262
|
+
const c = readChat(base, id)!;
|
|
263
|
+
expect(c.project).toBe(projA);
|
|
264
|
+
expect(c.messages[1].steps!.at(-1)).toEqual({ kind: "project", text: "Started a full run in D with claude", ok: true });
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test.if(posix)("a run line with an unlisted project, unknown runner or missing agent is refused", async () => {
|
|
268
|
+
for (const line of ["/etc | lite | claude | x", "D | auto | claude | x", "D | lite | gemini | x", "D | lite | claude | "]) {
|
|
269
|
+
fake(say(`[[kaizen:run ${line}]]`));
|
|
270
|
+
const { id } = await turn(null, "go", projA);
|
|
271
|
+
expect(readChat(base, id)!.messages[1].steps!.at(-1)).toMatchObject({ kind: "project", ok: false });
|
|
272
|
+
}
|
|
273
|
+
expect(runs).toEqual([]);
|
|
274
|
+
});
|