kaizen-agent 1.52.0 → 1.53.1
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 +38 -5
- package/cli/chat.ts +56 -13
- package/cli/install.ts +76 -1
- package/cli/settings.ts +25 -0
- package/cli/state.test.ts +10 -1
- package/cli/state.ts +17 -4
- package/cli/web.ts +134 -20
- package/package.json +1 -1
- package/skills/kaizen/config.default.yml +4 -0
- package/web/board/cards.ts +16 -4
- package/web/board/chat.ts +8 -12
- package/web/board/dom.ts +23 -3
- package/web/board/home.ts +18 -2
- package/web/board/settings.ts +16 -4
- package/web/board/toast.ts +45 -0
- package/web/board.html +3 -1
- package/web/board.js +41 -40
- package/web/notebook.js +1 -1
- package/web/popup.html +141 -0
- package/web/term.js +1 -1
- 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
CHANGED
|
@@ -6,7 +6,7 @@ import { join, delimiter } from "node:path";
|
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { sendChat, readChat, listChats, deleteChat, stopChat, parseLine, takeMoves, type Event, type Board, type Upload } from "./chat.ts";
|
|
8
8
|
|
|
9
|
-
let root = "", base = "", bin = "", projA = "", projD = "", board: Board, created: string[] = [];
|
|
9
|
+
let root = "", base = "", bin = "", projA = "", projD = "", board: Board, created: string[] = [], runs: string[][] = [];
|
|
10
10
|
const PATH = process.env.PATH;
|
|
11
11
|
const posix = process.platform !== "win32";
|
|
12
12
|
|
|
@@ -46,7 +46,10 @@ beforeEach(() => {
|
|
|
46
46
|
mkdirSync(bin);
|
|
47
47
|
process.env.PATH = bin + delimiter + PATH;
|
|
48
48
|
created = [];
|
|
49
|
+
runs = [];
|
|
49
50
|
board = {
|
|
51
|
+
agents: ["claude", "codex"],
|
|
52
|
+
run: async (dir, runner, agent, text) => { runs.push([dir, runner, agent, text]); return { agent }; },
|
|
50
53
|
projects: [{ dir: projA, label: "A" }, { dir: projD, label: "D" }],
|
|
51
54
|
create: async (name) => {
|
|
52
55
|
if (name.includes("/")) return { error: "bad name" };
|
|
@@ -76,13 +79,13 @@ test.if(posix)("a message streams the reply, saves both sides, runs in the chat'
|
|
|
76
79
|
expect(stdin).toContain(`- D — ${join(root, "D")}`);
|
|
77
80
|
expect(stdin.endsWith("say hi")).toBe(true);
|
|
78
81
|
expect(argv()).toContain("workspace-write");
|
|
79
|
-
expect(argv().slice(
|
|
82
|
+
expect(argv().slice(argv().indexOf("-m"), argv().indexOf("-m") + 4)).toEqual(["-m", "gpt-6-luna", "-c", "model_reasoning_effort=medium"]);
|
|
80
83
|
expect(argv()).not.toContain("resume");
|
|
81
84
|
expect(listChats(base).map((x) => [x.id, x.project])).toEqual([[id, projA]]);
|
|
82
85
|
|
|
83
86
|
fake(say("Again."));
|
|
84
87
|
await turn(id, "again");
|
|
85
|
-
expect(argv().slice(
|
|
88
|
+
expect(argv().slice(argv().indexOf("-m"), argv().indexOf("-m") + 4)).toEqual(["-m", "gpt-6-luna", "-c", "model_reasoning_effort=medium"]);
|
|
86
89
|
expect(argv().slice(-3)).toEqual(["resume", "T1", "-"]);
|
|
87
90
|
expect(readChat(base, id)!.messages).toHaveLength(4);
|
|
88
91
|
});
|
|
@@ -92,7 +95,8 @@ test.if(posix)("no project: a read-only scratch folder outside every project", a
|
|
|
92
95
|
const { id } = await turn(null, "hello");
|
|
93
96
|
expect(readChat(base, id)!.project).toBeUndefined();
|
|
94
97
|
expect(readFileSync(join(bin, "cwd"), "utf8").trim()).toBe(join(base, "chats", "scratch"));
|
|
95
|
-
expect(argv()).toContain("
|
|
98
|
+
expect(argv()).toContain("workspace-write");
|
|
99
|
+
expect(argv().join(" ")).toContain(`--add-dir ${join(root, "A")} --add-dir ${join(root, "D")}`);
|
|
96
100
|
expect(readFileSync(join(bin, "stdin"), "utf8")).toContain("Project of this chat: none");
|
|
97
101
|
// A project the page names that the board does not list is not taken.
|
|
98
102
|
const r = await turn(null, "hi", join(root, "elsewhere", ".kaizen"));
|
|
@@ -235,7 +239,36 @@ test("parseLine and takeMoves", () => {
|
|
|
235
239
|
.toEqual({ t: "step", step: { kind: "cmd", text: "cat a.md", ok: false } });
|
|
236
240
|
expect(parseLine(`{"type":"item.completed","item":{"type":"file_change","changes":[{"path":"a.ts"}],"status":"completed"}}`))
|
|
237
241
|
.toEqual({ t: "step", step: { kind: "edit", text: "a.ts", ok: true } });
|
|
238
|
-
expect(takeMoves("ok\n\n[[kaizen:project A]]\n")).toEqual({ text: "ok", move: { op: "project", arg: "A" } });
|
|
242
|
+
expect(takeMoves("ok\n\n[[kaizen:project A]]\n")).toEqual({ text: "ok", move: { op: "project", arg: "A" }, run: null });
|
|
239
243
|
// Only a line of its own counts: a move quoted inside a sentence is text.
|
|
240
244
|
expect(takeMoves("write `[[kaizen:project A]]` to move").move).toBeNull();
|
|
241
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
|
+
});
|
package/cli/chat.ts
CHANGED
|
@@ -19,13 +19,19 @@ export type Event =
|
|
|
19
19
|
| { t: "status"; text: string }
|
|
20
20
|
| { t: "step"; step: Step }
|
|
21
21
|
| { t: "project"; dir: string | null }
|
|
22
|
+
| { t: "run"; dir: string }
|
|
22
23
|
| { t: "error"; error: string }
|
|
23
24
|
| { t: "done" };
|
|
24
|
-
// What the board knows, handed in by the server: its projects (state dirs)
|
|
25
|
+
// What the board knows, handed in by the server: its projects (state dirs), how it makes one,
|
|
26
|
+
// the agents installed, and how it starts a kaizen run in a project.
|
|
25
27
|
export type Board = {
|
|
26
28
|
projects: { dir: string; label: string }[];
|
|
27
29
|
create: (name: string) => Promise<{ dir: string } | { error: string }>;
|
|
30
|
+
agents: string[];
|
|
31
|
+
run: (dir: string, runner: "lite" | "full", agent: string, text: string) => Promise<{ agent: string } | { error: string }>;
|
|
28
32
|
};
|
|
33
|
+
// The project folders the agent may write in: every listed one, capped like the brief's list.
|
|
34
|
+
const roots = (board: Board) => board.projects.slice(0, 80).map((p) => dirname(p.dir));
|
|
29
35
|
|
|
30
36
|
export const okId = (id: unknown): id is string => typeof id === "string" && /^[\w-]{1,80}$/.test(id);
|
|
31
37
|
const file = (base: string, id: string) => join(base, "chats", `${id}.json`);
|
|
@@ -60,11 +66,16 @@ export function brief(c: Chat, board: Board) {
|
|
|
60
66
|
const list = board.projects.slice(0, 80).map((p) => `- ${p.label} — ${dirname(p.dir)}`).join("\n");
|
|
61
67
|
return `[kaizen board context, not written by the user]
|
|
62
68
|
You are kaizen's main agent, talking with the user from the kaizen board's Home page.
|
|
63
|
-
Project of this chat: ${here ? `${here.label} (${dirname(here.dir)})` : "none — you are in a scratch folder
|
|
69
|
+
Project of this chat: ${here ? `${here.label} (${dirname(here.dir)})` : "none — you are in a scratch folder"}.
|
|
64
70
|
Projects on the board:
|
|
65
71
|
${list || "(none)"}
|
|
66
|
-
You can
|
|
67
|
-
|
|
72
|
+
You can read, analyse and edit files in any project folder listed above directly by its path; you do not need to switch to it. Do not write outside those folders and your working folder.
|
|
73
|
+
Switching only changes this chat's home project (where you run and which project the board shows). On a line of its own write [[kaizen:project <folder>]] to switch to a listed project, or [[kaizen:new-project <name>]] to create one (a plain folder name). Switch only when the user asks; when what they want fits no listed project, ask whether to create a new one. After a successful move, the board starts one follow-up turn in the new project to finish the pending request; do not ask the user to repeat it.
|
|
74
|
+
When the user asks you to develop, fix, change or enhance something (not a question, analysis or reading), first ask which way, as numbered options, and do nothing until they pick:
|
|
75
|
+
1. Start a kaizen run for it: lite (cheap, one session) or full (independent review), with which agent (installed: ${board.agents.join(", ") || "none"}), in which project.
|
|
76
|
+
2. Let you handle it here in the chat.
|
|
77
|
+
For 1, once they pick, write on a line of its own [[kaizen:run <project folder> | <lite or full> | <agent> | <the request, one line>]]; the board starts the run in that project and it shows there. Do not start it yourself with /kaizen. For 2, do the work directly.
|
|
78
|
+
Keep replies short.
|
|
68
79
|
[end of context]
|
|
69
80
|
|
|
70
81
|
`;
|
|
@@ -141,12 +152,21 @@ export function parseLine(line: string): Event | { t: "thread"; id: string } | n
|
|
|
141
152
|
return null;
|
|
142
153
|
}
|
|
143
154
|
|
|
144
|
-
// The agent's move lines: taken out of what the user reads; the last
|
|
145
|
-
const MOVE = /^[ \t]*\[\[kaizen:(project|new-project)[ \t]+([^\]\n]+?)\]\][ \t]*$/gm;
|
|
155
|
+
// The agent's move and run lines: taken out of what the user reads; the last of each counts.
|
|
156
|
+
const MOVE = /^[ \t]*\[\[kaizen:(project|new-project|run)[ \t]+([^\]\n]+?)\]\][ \t]*$/gm;
|
|
157
|
+
export type RunAsk = { project: string; runner: string; agent: string; text: string };
|
|
146
158
|
export function takeMoves(text: string) {
|
|
147
159
|
let move: { op: "project" | "new-project"; arg: string } | null = null;
|
|
148
|
-
|
|
149
|
-
|
|
160
|
+
let run: RunAsk | null = null;
|
|
161
|
+
const rest = text.replace(MOVE, (_, op, arg) => {
|
|
162
|
+
if (op !== "run") move = { op, arg: arg.trim() };
|
|
163
|
+
else {
|
|
164
|
+
const [project = "", runner = "", agent = "", ...t] = arg.split("|").map((x: string) => x.trim());
|
|
165
|
+
run = { project, runner, agent, text: t.join(" | ").trim() };
|
|
166
|
+
}
|
|
167
|
+
return "";
|
|
168
|
+
}).replace(/\n{3,}/g, "\n\n").trim();
|
|
169
|
+
return { text: rest, move: move as { op: "project" | "new-project"; arg: string } | null, run: run as RunAsk | null };
|
|
150
170
|
}
|
|
151
171
|
|
|
152
172
|
// Not winShim: the message goes in on stdin, so the .cmd shim's newline limit never applies.
|
|
@@ -180,7 +200,7 @@ export function sendChat(base: string, id: string | null, text: string, project:
|
|
|
180
200
|
chat.updated = now;
|
|
181
201
|
save(base, chat);
|
|
182
202
|
|
|
183
|
-
// No project: a scratch folder outside every project
|
|
203
|
+
// No project: a scratch folder outside every project.
|
|
184
204
|
const scratch = join(base, "chats", "scratch");
|
|
185
205
|
if (!chat.project) mkdirSync(scratch, { recursive: true });
|
|
186
206
|
const cwd = chat.project ? dirname(chat.project) : scratch;
|
|
@@ -188,7 +208,9 @@ export function sendChat(base: string, id: string | null, text: string, project:
|
|
|
188
208
|
const env: Record<string, string> = {};
|
|
189
209
|
for (const [k, v] of Object.entries(process.env)) if (v !== undefined && !CHILD_ENV.test(k)) env[k] = v;
|
|
190
210
|
const images = files.filter((f) => f.image).flatMap((f) => ["-i", f.path]);
|
|
191
|
-
|
|
211
|
+
// Every listed project is writable, so the agent works on any of them without a switch.
|
|
212
|
+
const dirs = roots(board).filter((d) => d !== cwd).flatMap((d) => ["--add-dir", d]);
|
|
213
|
+
const argv = [bin, "exec", "--json", "--skip-git-repo-check", "-s", "workspace-write", ...dirs,
|
|
192
214
|
"-m", "gpt-6-luna", "-c", "model_reasoning_effort=medium", ...(chat.thread ? ["resume", chat.thread] : []), ...images, "-"];
|
|
193
215
|
let p;
|
|
194
216
|
try { p = Bun.spawn(argv, { cwd, env, stdin: "pipe", stdout: "pipe", stderr: "pipe" }); }
|
|
@@ -212,6 +234,7 @@ export function sendChat(base: string, id: string | null, text: string, project:
|
|
|
212
234
|
const dec = new TextDecoder();
|
|
213
235
|
let buf = "";
|
|
214
236
|
let move: ReturnType<typeof takeMoves>["move"] = null;
|
|
237
|
+
let run: RunAsk | null = null;
|
|
215
238
|
const take = (line: string) => {
|
|
216
239
|
const e = parseLine(line);
|
|
217
240
|
if (!e) return;
|
|
@@ -219,6 +242,7 @@ export function sendChat(base: string, id: string | null, text: string, project:
|
|
|
219
242
|
if (e.t === "text") {
|
|
220
243
|
const m = takeMoves(e.text);
|
|
221
244
|
if (m.move) move = m.move;
|
|
245
|
+
if (m.run) run = m.run;
|
|
222
246
|
if (!m.text) return;
|
|
223
247
|
e.text = m.text;
|
|
224
248
|
reply.text += (reply.text ? "\n\n" : "") + e.text;
|
|
@@ -244,6 +268,7 @@ export function sendChat(base: string, id: string | null, text: string, project:
|
|
|
244
268
|
reply.error = err || `codex exited with code ${code}`;
|
|
245
269
|
emit({ t: "error", error: reply.error });
|
|
246
270
|
}
|
|
271
|
+
if (run && !stopped) await startRun(reply, run, board, emit);
|
|
247
272
|
if (move && !stopped) await moveChat(chat, reply, move, board, emit);
|
|
248
273
|
} finally {
|
|
249
274
|
delete reply.activity;
|
|
@@ -256,14 +281,32 @@ export function sendChat(base: string, id: string | null, text: string, project:
|
|
|
256
281
|
return null;
|
|
257
282
|
}
|
|
258
283
|
|
|
284
|
+
const findProject = (board: Board, arg: string) => {
|
|
285
|
+
const a = arg.replace(/[\\/]+$/, "");
|
|
286
|
+
return board.projects.find((x) => x.dir === a || dirname(x.dir) === a || x.dir === join(a, ".kaizen"))
|
|
287
|
+
?? board.projects.find((x) => x.label === a || basename(dirname(x.dir)) === a);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// Start the run the user picked: only in a listed project, with an installed agent.
|
|
291
|
+
async function startRun(reply: Msg, ask: RunAsk, board: Board, emit: (e: Event) => void) {
|
|
292
|
+
const step = (text: string, ok: boolean) => { const s: Step = { kind: "project", text, ok }; reply.steps!.push(s); emit({ t: "step", step: s }); };
|
|
293
|
+
const p = findProject(board, ask.project);
|
|
294
|
+
if (!p) return step(`No project ${ask.project} on the board`, false);
|
|
295
|
+
if (ask.runner !== "lite" && ask.runner !== "full") return step(`Unknown runner ${ask.runner}`, false);
|
|
296
|
+
if (!board.agents.includes(ask.agent)) return step(`Agent ${ask.agent} is not installed`, false);
|
|
297
|
+
if (!ask.text) return step("No request for the run", false);
|
|
298
|
+
const r = await board.run(p.dir, ask.runner, ask.agent, ask.text);
|
|
299
|
+
if ("error" in r) return step(`Could not start the run: ${r.error}`, false);
|
|
300
|
+
step(`Started a ${ask.runner} run in ${p.label} with ${r.agent}`, true);
|
|
301
|
+
emit({ t: "run", dir: p.dir });
|
|
302
|
+
}
|
|
303
|
+
|
|
259
304
|
// Apply the agent's move: only to a project the board lists, or one the board's own rules create.
|
|
260
305
|
async function moveChat(chat: Chat, reply: Msg, move: { op: string; arg: string }, board: Board, emit: (e: Event) => void) {
|
|
261
306
|
const step = (text: string, ok: boolean) => { const s: Step = { kind: "project", text, ok }; reply.steps!.push(s); emit({ t: "step", step: s }); };
|
|
262
307
|
let dir: string | null = null;
|
|
263
308
|
if (move.op === "project") {
|
|
264
|
-
const
|
|
265
|
-
const p = board.projects.find((x) => x.dir === a || dirname(x.dir) === a || x.dir === join(a, ".kaizen"))
|
|
266
|
-
?? board.projects.find((x) => x.label === a || basename(dirname(x.dir)) === a);
|
|
309
|
+
const p = findProject(board, move.arg);
|
|
267
310
|
if (!p) return step(`No project ${move.arg} on the board`, false);
|
|
268
311
|
dir = p.dir;
|
|
269
312
|
} else {
|
package/cli/install.ts
CHANGED
|
@@ -460,6 +460,77 @@ if (args.has("prune")) {
|
|
|
460
460
|
process.exit(0);
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
+
// `kaizen chat`: Home's chat in a small window over the desktop, like Hermes's HUD.
|
|
464
|
+
// Bind it to a hotkey: run again while the window is open and it closes.
|
|
465
|
+
if (Bun.argv[2] === "chat") {
|
|
466
|
+
const at = Bun.argv.indexOf("--port");
|
|
467
|
+
const port = at !== -1 ? Number(Bun.argv[at + 1]) || 7420 : 7420;
|
|
468
|
+
const url = `http://127.0.0.1:${port}/`;
|
|
469
|
+
const { current } = await import("./web.ts");
|
|
470
|
+
if (!(await current(url))) await Bun.spawn([process.execPath, Bun.main, "web", "--daemon", "--no-open", "--port", String(port)], { stdout: "ignore", stderr: "inherit" }).exited;
|
|
471
|
+
// Chromium on Wayland ignores --class: the app window's class comes from the URL.
|
|
472
|
+
const isChat = (c: any) => c.class === "kaizen-chat" || String(c.class).startsWith("chrome-127.0.0.1__popup");
|
|
473
|
+
const hypr = !!process.env.HYPRLAND_INSTANCE_SIGNATURE && !!Bun.which("hyprctl");
|
|
474
|
+
const clients = async (): Promise<any[]> => hypr ? await Bun.$`hyprctl clients -j`.quiet().nothrow().json().catch(() => []) : [];
|
|
475
|
+
if (hypr) {
|
|
476
|
+
const { listSettings, bindChatHotkey } = await import("./settings.ts");
|
|
477
|
+
const keys = listSettings(dirname(import.meta.dir)).rows.find((r) => r.key === "board.chat_hotkey")?.value;
|
|
478
|
+
if (keys) bindChatHotkey(String(keys), undefined, true);
|
|
479
|
+
}
|
|
480
|
+
const open = (await clients()).find(isChat);
|
|
481
|
+
// Where the window was left, so the next one opens there.
|
|
482
|
+
const spot = join(home, ".kaizen", "chat-window.json");
|
|
483
|
+
// --show only opens (the board's Pop out), --close only closes (the popup's Back);
|
|
484
|
+
// plain `kaizen chat` toggles, for a hotkey.
|
|
485
|
+
if (open && Bun.argv.includes("--show")) {
|
|
486
|
+
await Bun.$`hyprctl dispatch ${`hl.dsp.focus({ window = "address:${open.address}" })`}`.quiet().nothrow();
|
|
487
|
+
process.exit(0);
|
|
488
|
+
}
|
|
489
|
+
if (!open && Bun.argv.includes("--close")) process.exit(0);
|
|
490
|
+
if (open) {
|
|
491
|
+
try { writeFileSync(spot, JSON.stringify({ x: open.at[0], y: open.at[1] })); } catch {}
|
|
492
|
+
try { process.kill(open.pid, "SIGTERM"); } catch {}
|
|
493
|
+
process.exit(0);
|
|
494
|
+
}
|
|
495
|
+
// A see-through WebKitGTK window when python3 has it; Chromium paints a background.
|
|
496
|
+
const ci = Bun.argv.indexOf("--chat"), chatId = ci !== -1 ? Bun.argv[ci + 1] ?? "" : "";
|
|
497
|
+
const page = `${url}popup${/^[\w.-]+$/.test(chatId) ? `?chat=${chatId}` : ""}`;
|
|
498
|
+
const shell = join(import.meta.dir, "chat-window.py");
|
|
499
|
+
const py = Bun.which("python3");
|
|
500
|
+
const bin = ["chromium", "chromium-browser", "google-chrome", "google-chrome-stable", "microsoft-edge", "brave", "brave-browser"].map((b) => Bun.which(b)).find(Boolean);
|
|
501
|
+
const cmd = py && Bun.spawnSync([py, shell, "--check"], { stdout: "ignore", stderr: "ignore" }).exitCode === 0 ? [py, shell, page]
|
|
502
|
+
// Its own profile, so it is its own process: closing it never takes the browser along.
|
|
503
|
+
: bin ? [bin, `--app=${page}`, `--user-data-dir=${join(home, ".kaizen", "chat-window")}`, "--window-size=420,600"] : null;
|
|
504
|
+
if (!cmd) { console.log(` no Chromium-based browser found; open ${url}popup instead`); process.exit(1); }
|
|
505
|
+
Bun.spawn(cmd, { stdin: "ignore", stdout: "ignore", stderr: "ignore", detached: true }).unref();
|
|
506
|
+
if (hypr) {
|
|
507
|
+
let win: any;
|
|
508
|
+
for (let i = 0; i < 50 && !(win = (await clients()).find(isChat)); i++) await Bun.sleep(100);
|
|
509
|
+
if (win) {
|
|
510
|
+
// Hyprland 0.55+ on a Lua config reads dispatch as Lua; older ones want the classic words.
|
|
511
|
+
const w = `address:${win.address}`;
|
|
512
|
+
const mon = (await Bun.$`hyprctl monitors -j`.quiet().nothrow().json().catch(() => [])).find((m: any) => m.id === win.monitor);
|
|
513
|
+
let x = mon ? mon.x + Math.round(mon.width / mon.scale) - 440 : 100, y = mon ? mon.y + Math.round(mon.height / mon.scale) - 640 : 100;
|
|
514
|
+
// The saved spot, while it is still on a connected monitor.
|
|
515
|
+
const was = (() => { try { return JSON.parse(readFileSync(spot, "utf8")); } catch { return null; } })();
|
|
516
|
+
const mons: any[] = await Bun.$`hyprctl monitors -j`.quiet().nothrow().json().catch(() => []);
|
|
517
|
+
if (Number.isFinite(was?.x) && Number.isFinite(was?.y) && mons.some((m) => was.x >= m.x && was.y >= m.y && was.x < m.x + m.width / m.scale && was.y < m.y + m.height / m.scale)) ({ x, y } = was);
|
|
518
|
+
const steps = [
|
|
519
|
+
[`hl.dsp.window.float({ action = "enable", window = "${w}" })`, `setfloating ${w}`],
|
|
520
|
+
[`hl.dsp.window.pin({ action = "enable", window = "${w}" })`, `pin ${w}`],
|
|
521
|
+
// No border, rounding or shadow: only the bubbles show.
|
|
522
|
+
[`hl.dsp.window.set_prop({ prop = "no_shadow", value = "1", window = "${w}" })`, `setprop ${w} no_shadow 1`],
|
|
523
|
+
[`hl.dsp.window.set_prop({ prop = "border_size", value = "0", window = "${w}" })`, `setprop ${w} border_size 0`],
|
|
524
|
+
[`hl.dsp.window.resize({ x = 420, y = 600, window = "${w}" })`, `resizewindowpixel exact 420 600,${w}`],
|
|
525
|
+
[`hl.dsp.window.move({ x = ${x}, y = ${y}, window = "${w}" })`, `movewindowpixel exact ${x} ${y},${w}`],
|
|
526
|
+
];
|
|
527
|
+
for (const [lua, legacy] of steps)
|
|
528
|
+
if ((await Bun.$`hyprctl dispatch ${lua}`.quiet().nothrow().text()).trim() !== "ok") await Bun.$`hyprctl dispatch ${legacy.split(" ")}`.quiet().nothrow();
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
process.exit(0);
|
|
532
|
+
}
|
|
533
|
+
|
|
463
534
|
if (wantWeb) {
|
|
464
535
|
if (args.has("--shortcut")) { const { shortcut } = await import("./web.ts"); console.log(`\n kaizen web shortcut ${await shortcut()}\n`); process.exit(0); }
|
|
465
536
|
const at = Bun.argv.indexOf("--port");
|
|
@@ -957,8 +1028,12 @@ function installLauncher() {
|
|
|
957
1028
|
? join(process.env.BUN_INSTALL ?? join(home, ".bun"), "bin")
|
|
958
1029
|
: join(home, ".local", "bin");
|
|
959
1030
|
const bin = join(binDir, win ? "kaizen.cmd" : "kaizen");
|
|
1031
|
+
// Windows calls bun by full path: cmd.exe on some machines cannot find bun on PATH
|
|
1032
|
+
// even when PowerShell can, and `kaizen` then fails with "'bun' is not recognized".
|
|
1033
|
+
// POSIX keeps `bun`, since version managers (mise, asdf) put bun under a versioned
|
|
1034
|
+
// path that an upgrade removes.
|
|
960
1035
|
const script = win
|
|
961
|
-
? `@echo off\r\nrem kaizen launcher -- installed by kaizen-agent\r\
|
|
1036
|
+
? `@echo off\r\nrem kaizen launcher -- installed by kaizen-agent\r\n"${process.execPath}" run "${entry}" %*\r\n`
|
|
962
1037
|
: `#!/bin/sh\n# kaizen launcher -- installed by kaizen-agent\nexec bun run ${entry} "$@"\n`;
|
|
963
1038
|
try {
|
|
964
1039
|
if (existsSync(bin) && readFileSync(bin, "utf8") === script) return;
|
package/cli/settings.ts
CHANGED
|
@@ -127,6 +127,7 @@ const SETTINGS: Setting[] = [
|
|
|
127
127
|
{ key: "board.projects_dir", label: "Projects folder", group: "Board", values: [], text: true, folder: true, help: "Empty: known projects only" },
|
|
128
128
|
{ key: "board.video_dir", label: "Video library folder", group: "Board", values: [], text: true, folder: true, help: "Empty: ~/.kaizen" },
|
|
129
129
|
{ key: "board.open", label: "Open the board in", group: "Board", values: ["browser", "app"], help: "" },
|
|
130
|
+
{ key: "board.chat_hotkey", label: "Popup chat hotkey", group: "Board", values: [], text: true, help: "Hyprland, e.g. SUPER + ALT + SPACE. Empty: none" },
|
|
130
131
|
{ key: "ui.mouse", label: "Enable mouse", group: "Terminal", values: ["false", "true"], help: "" },
|
|
131
132
|
];
|
|
132
133
|
|
|
@@ -169,7 +170,9 @@ export function setSetting(repoRoot: string, key: string, value: string) {
|
|
|
169
170
|
updated = write(updated, "preset", detectPreset(updated, defaults), defaults);
|
|
170
171
|
if (read(updated, key) !== value) return { error: `${key} did not save; edit ${tilde(file)} by hand` };
|
|
171
172
|
}
|
|
173
|
+
if (key === "board.chat_hotkey" && !HOTKEY.test(value)) return { error: "keys are words joined by +, e.g. SUPER + ALT + SPACE" };
|
|
172
174
|
writeFileSync(file, updated);
|
|
175
|
+
if (key === "board.chat_hotkey") bindChatHotkey(value);
|
|
173
176
|
return { ok: true };
|
|
174
177
|
}
|
|
175
178
|
|
|
@@ -493,3 +496,25 @@ function tilde(p: string) {
|
|
|
493
496
|
const h = homedir();
|
|
494
497
|
return p.startsWith(h) ? "~" + p.slice(h.length) : p;
|
|
495
498
|
}
|
|
499
|
+
|
|
500
|
+
// `board.chat_hotkey`: the key that toggles `kaizen chat`, written into the Hyprland
|
|
501
|
+
// config as a marked block, unbinding whatever held the key first. Hyprland reloads
|
|
502
|
+
// the file by itself. Elsewhere there is nowhere to bind it; returns where it went.
|
|
503
|
+
const HOTKEY = /^$|^[A-Za-z0-9_]+( *\+ *[A-Za-z0-9_]+)*$/;
|
|
504
|
+
const BEGIN = "kaizen chat hotkey (written by kaizen; change it in kaizen settings)", END = "end kaizen chat hotkey";
|
|
505
|
+
// `missingOnly`: leave a block already there alone (`kaizen chat` applying the default).
|
|
506
|
+
export function bindChatHotkey(keys: string, dir = join(homedir(), ".config", "hypr"), missingOnly = false) {
|
|
507
|
+
if (!HOTKEY.test(keys)) return null;
|
|
508
|
+
const lua = join(dir, "bindings.lua"), conf = join(dir, "hyprland.conf");
|
|
509
|
+
const file = existsSync(lua) ? lua : existsSync(conf) ? conf : null;
|
|
510
|
+
if (!file || (missingOnly && readText(file).includes(BEGIN))) return null;
|
|
511
|
+
const k = keys.split("+").map((x) => x.trim().toUpperCase());
|
|
512
|
+
const cmd = Bun.which("kaizen") ?? "kaizen";
|
|
513
|
+
const c = file === lua ? "--" : "#";
|
|
514
|
+
const body = !keys ? "" : file === lua
|
|
515
|
+
? `pcall(hl.unbind, "${k.join(" + ")}")\no.bind("${k.join(" + ")}", "kaizen chat", "${cmd} chat")`
|
|
516
|
+
: `unbind = ${k.slice(0, -1).join(" ")}, ${k.at(-1)}\nbind = ${k.slice(0, -1).join(" ")}, ${k.at(-1)}, exec, ${cmd} chat`;
|
|
517
|
+
const text = readText(file).replace(new RegExp(`\\n?${c} ${BEGIN.replace(/[()]/g, "\\$&")}[\\s\\S]*?${c} ${END}\\n?`), "\n");
|
|
518
|
+
writeFileSync(file, text.replace(/\n*$/, "\n") + (body ? `\n${c} ${BEGIN}\n${body}\n${c} ${END}\n` : ""));
|
|
519
|
+
return file;
|
|
520
|
+
}
|
package/cli/state.test.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
readRuns, readInbox, writeInbox, replaceIdea, moveIdea, abandonRun, runToIdea, allBacklog, backlog,
|
|
11
11
|
requestTitle, statusOf, columnOf, parseItem, startedRuns, boardCards, parentOf, addCard, readArchive, setArchived,
|
|
12
12
|
requestOf, agentFlags, plainModel, readNotes, writeNotes, manualCommand, parseNotes, formatNote, appendNote, saveAttachment,
|
|
13
|
-
reviewFindings, pickFindings, fixPrompt, approvalPrompt, sessionLaunch, closeSessions, sweepSessions, readSessions, ownerOf, CLOSE_GRACE_MS, gitStatus, runGit, cardsGit, commitPush, readCommit, findTerminal, nativePath, pruneRuns, unrechecked, notice, notifier, notifyArgs, LOGO, type Card,
|
|
13
|
+
reviewFindings, pickFindings, fixPrompt, approvalPrompt, sessionLaunch, closeSessions, sweepSessions, readSessions, ownerOf, CLOSE_GRACE_MS, gitStatus, runGit, cardsGit, commitPush, readCommit, findTerminal, nativePath, pruneRuns, unrechecked, notice, notifier, notifyArgs, winToastArgs, LOGO, type Card,
|
|
14
14
|
} from "./state.ts";
|
|
15
15
|
|
|
16
16
|
let state: string;
|
|
@@ -748,6 +748,15 @@ test("notice: plain words for what a run waits on, done, and nothing for the res
|
|
|
748
748
|
expect(notifyArgs("x")).toEqual(["notify-send", "-a", "kaizen", "-i", LOGO, "kaizen", "x"]);
|
|
749
749
|
});
|
|
750
750
|
|
|
751
|
+
test("winToastArgs carries the body base64, so a quote cannot end the PowerShell string", () => {
|
|
752
|
+
const body = "it's \"done\" — ~/acme\n$(rm)";
|
|
753
|
+
const a = winToastArgs(body);
|
|
754
|
+
expect(a[0]).toMatch(/WindowsPowerShell\\v1\.0\\powershell\.exe$/);
|
|
755
|
+
const b64 = /FromBase64String\('([^']+)'\)/.exec(a.at(-1)!)![1]!;
|
|
756
|
+
expect(Buffer.from(b64, "base64").toString("utf8")).toBe(body);
|
|
757
|
+
expect(a.at(-1)).not.toContain("rm)");
|
|
758
|
+
});
|
|
759
|
+
|
|
751
760
|
test("notifier: only a run seen before, saying something new, and not a done the user just approved", () => {
|
|
752
761
|
const due = notifier(), M = 60_000;
|
|
753
762
|
expect(due("r", "a", false, 0)).toBe(false); // first load, or arrived already waiting
|
package/cli/state.ts
CHANGED
|
@@ -128,7 +128,7 @@ const shq = (a: string) => `'${a.replace(/'/g, `'\\''`)}'`;
|
|
|
128
128
|
// every `key:\n` regex the same silent way, so line endings are made LF here too.
|
|
129
129
|
export const readText = (file: string) => readFileSync(file, "utf8").replace(/^\uFEFF/, "").replace(/\r\n/g, "\n");
|
|
130
130
|
|
|
131
|
-
const onPath = (bin: string) => Bun.which(bin, { PATH: process.env.PATH });
|
|
131
|
+
export const onPath = (bin: string) => Bun.which(bin, { PATH: process.env.PATH });
|
|
132
132
|
|
|
133
133
|
// npm installs a Windows tool as x.cmd with x.ps1 beside it. PowerShell hands a .cmd to
|
|
134
134
|
// cmd.exe, which ends the command line at the first newline -- a prompt with notes lost
|
|
@@ -998,11 +998,24 @@ export const LOGO = join(dirname(import.meta.dir), "assets", "kaizen-logo.png");
|
|
|
998
998
|
export function notifyArgs(body: string) {
|
|
999
999
|
return ["notify-send", "-a", "kaizen", ...(existsSync(LOGO) ? ["-i", LOGO] : []), "kaizen", body];
|
|
1000
1000
|
}
|
|
1001
|
+
// Windows: a toast through PowerShell's WinRT bridge, under PowerShell's own app id
|
|
1002
|
+
// (an unregistered id shows nothing). Windows PowerShell 5.1, not pwsh: 7 has no WinRT
|
|
1003
|
+
// projection. The body travels base64 so no quote can break out. The toast's own sound plays.
|
|
1004
|
+
export function winToastArgs(body: string) {
|
|
1005
|
+
const b64 = Buffer.from(body, "utf8").toString("base64");
|
|
1006
|
+
const ps = `$t=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${b64}'));` +
|
|
1007
|
+
`[void][Windows.UI.Notifications.ToastNotificationManager,Windows.UI.Notifications,ContentType=WindowsRuntime];` +
|
|
1008
|
+
`$x=[Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02);` +
|
|
1009
|
+
`$n=$x.GetElementsByTagName('text');[void]$n.Item(0).AppendChild($x.CreateTextNode('kaizen'));[void]$n.Item(1).AppendChild($x.CreateTextNode($t));` +
|
|
1010
|
+
`[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe').Show([Windows.UI.Notifications.ToastNotification]::new($x))`;
|
|
1011
|
+
return [sysExe("WindowsPowerShell\\v1.0\\powershell.exe"), "-NoProfile", "-NonInteractive", "-Command", ps];
|
|
1012
|
+
}
|
|
1001
1013
|
export function notify(body: string) {
|
|
1002
1014
|
try {
|
|
1003
|
-
|
|
1004
|
-
Bun.
|
|
1005
|
-
|
|
1015
|
+
const win = process.platform === "win32";
|
|
1016
|
+
if (!win && !Bun.which("notify-send")) return;
|
|
1017
|
+
Bun.spawn(win ? winToastArgs(body) : notifyArgs(body), {
|
|
1018
|
+
stdin: "ignore", stdout: "ignore", stderr: "ignore", detached: true, windowsHide: true,
|
|
1006
1019
|
}).unref();
|
|
1007
1020
|
} catch { /* notifications are not worth an exception */ }
|
|
1008
1021
|
}
|