kaizen-agent 1.70.0 → 1.72.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 +2 -2
- package/cli/annotate-proxy.ts +5 -0
- package/cli/automations.ts +10 -3
- package/cli/browser.ts +1 -1
- package/cli/chat.ts +9 -1
- package/cli/chatgpt.ts +2 -1
- package/cli/docs.ts +1 -1
- package/cli/google.ts +2 -1
- package/cli/handoff.ts +1 -1
- package/cli/install.ts +63 -17
- package/cli/knowledge.ts +1 -1
- package/cli/notes.ts +10 -1
- package/cli/preflight.ts +149 -0
- package/cli/rea.ts +199 -0
- package/cli/settings.ts +5 -1
- package/cli/sources.ts +3 -2
- package/cli/state.ts +43 -5
- package/cli/versions.ts +1 -1
- package/cli/video.ts +1 -1
- package/cli/web.ts +111 -28
- package/cli/workers.ts +20 -7
- package/cli/worktree.ts +65 -21
- package/package.json +1 -1
- package/skills/kaizen/SKILL.md +12 -8
- package/skills/kaizen/config.default.yml +18 -2
- package/skills/kaizen/settings.md +3 -1
- package/skills/kaizen/spec-build.md +13 -2
- package/skills/kaizen/spec-main.md +15 -0
- package/skills/kaizen/spec-plan.md +4 -1
- package/skills/kaizen-help/SKILL.md +2 -0
- package/skills/media/kaizen-game/SKILL.md +96 -0
- package/skills/media/kaizen-game/assets/gdd.css +12 -0
- package/skills/media/kaizen-game/references/build.md +81 -0
- package/skills/media/kaizen-game/references/content.md +32 -0
- package/skills/media/kaizen-game/references/design.md +81 -0
- package/skills/media/kaizen-game/references/ship.md +34 -0
- package/skills/media/kaizen-game/references/verify.md +33 -0
- package/skills/media/kaizen-game/scripts/check.sh +13 -0
- package/skills/media/kaizen-game/scripts/frames.mjs +34 -0
- package/skills/media/kaizen-game/scripts/gdd-pdf.mjs +19 -0
- package/skills/media/kaizen-game/scripts/pw.mjs +18 -0
- package/skills/media/kaizen-game/scripts/serve.mjs +53 -0
- package/skills/media/kaizen-game/scripts/serve.test.mjs +18 -0
- package/skills/media/kaizen-game/scripts/setup.sh +9 -0
- package/skills/media/kaizen-game/scripts/smoke.mjs +40 -0
- package/skills/media/kaizen-game/skill.json +1 -0
- package/web/board/git.ts +23 -6
- package/web/board/icebox.ts +6 -3
- package/web/board/markdown.ts +7 -2
- package/web/board/run-view.ts +1 -1
- package/web/board/settings-orchestration.ts +1 -1
- package/web/board/settings-pages.ts +1 -0
- package/web/board/settings-skills.ts +28 -2
- package/web/board/settings.ts +2 -2
- package/web/board.html +1 -1
- package/web/board.js +96 -82
- package/web/notebook.js +1 -1
- package/web/term.js +48 -48
- package/web/term.ts +16 -4
- package/web/video.js +1 -1
package/cli/rea.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// REA (npm `rea-agents`, github.com/morluto/rea): reverse-engineering tools as an MCP server,
|
|
2
|
+
// turned on from Settings → Skills. Kaizen never writes an agent's config itself: REA's own
|
|
3
|
+
// `setup`, `uninstall` and `doctor` do, through `npx` pinned to an exact version. Kaizen keeps
|
|
4
|
+
// only its switch in ~/.kaizen/rea.json and reads agent configs to see what is registered.
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { SKILL_HOMES } from "./skills.ts";
|
|
8
|
+
|
|
9
|
+
export type Run = (argv: string[]) => Promise<{ ok: boolean; out: string }>;
|
|
10
|
+
export type Reg = { client: string; version: string | null };
|
|
11
|
+
export type Saved = { on: boolean; version: string; clients: string[] };
|
|
12
|
+
|
|
13
|
+
const VERSION = /^\d+\.\d+\.\d+$/;
|
|
14
|
+
export const okVersion = (v: unknown): v is string => typeof v === "string" && VERSION.test(v);
|
|
15
|
+
|
|
16
|
+
// The agent home folders kaizen knows (SKILL_HOMES) and their REA client ids.
|
|
17
|
+
const CLIENT: Record<string, string> = { ".claude": "claude_code", ".codex": "codex", ".agents": "antigravity", ".opencode": "opencode", ".cursor": "cursor", ".gemini": "gemini_cli" };
|
|
18
|
+
export const reaClients = (home: string) => SKILL_HOMES.filter((h) => existsSync(join(home, h.dir)) && CLIENT[h.dir]).map((h) => ({ agent: h.name, client: CLIENT[h.dir]! }));
|
|
19
|
+
|
|
20
|
+
const npx = process.platform === "win32" ? "npx.cmd" : "npx";
|
|
21
|
+
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
22
|
+
const pkg = (version: string) => `rea-agents@${version}`;
|
|
23
|
+
|
|
24
|
+
// Up to 5 minutes: a first npx run downloads REA (about 50 MB). A missing npx is a failure, not a throw.
|
|
25
|
+
export const run: Run = async (argv) => {
|
|
26
|
+
try {
|
|
27
|
+
const p = Bun.spawn(argv, { stdout: "pipe", stderr: "pipe", stdin: "ignore", windowsHide: true });
|
|
28
|
+
const timer = setTimeout(() => p.kill(), 5 * 60_000);
|
|
29
|
+
const [out, err, code] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited]);
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
return { ok: code === 0, out: out || err };
|
|
32
|
+
} catch (e: any) { return { ok: false, out: `${argv[0]} not found: ${e?.message ?? e}` }; }
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// REA prints one JSON document with --json; anything before it is noise.
|
|
36
|
+
export function parse(out: string): any {
|
|
37
|
+
const at = out.indexOf("{");
|
|
38
|
+
try { return JSON.parse(at < 0 ? out : out.slice(at)); } catch { return null; }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The files a setup plan names: any string under a path-like key, deduplicated.
|
|
42
|
+
export function planFiles(j: any): string[] {
|
|
43
|
+
const found = new Set<string>();
|
|
44
|
+
const walk = (v: any, key = "") => {
|
|
45
|
+
if (typeof v === "string") { if (/(^|_)(path|file|target|config)s?$/i.test(key) && /[\\/]/.test(v)) found.add(v); return; }
|
|
46
|
+
if (Array.isArray(v)) return v.forEach((x) => walk(x, key));
|
|
47
|
+
if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) walk(x, k);
|
|
48
|
+
};
|
|
49
|
+
walk(j);
|
|
50
|
+
return [...found];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// What doctor says is missing: every check object that failed, by its name or message.
|
|
54
|
+
export function doctorMissing(j: any): string[] {
|
|
55
|
+
const out = new Set<string>();
|
|
56
|
+
const walk = (v: any) => {
|
|
57
|
+
if (Array.isArray(v)) return v.forEach(walk);
|
|
58
|
+
if (!v || typeof v !== "object") return;
|
|
59
|
+
const bad = v.ok === false || v.passed === false || /^(fail|failed|error|missing)$/i.test(String(v.status ?? ""));
|
|
60
|
+
if (bad && (v.name || v.id || v.message)) out.add(String(v.name ?? v.id ?? v.message).slice(0, 80));
|
|
61
|
+
for (const x of Object.values(v)) if (x && typeof x === "object") walk(x);
|
|
62
|
+
};
|
|
63
|
+
if (j) for (const k of ["scope_checks", "informational_checks", "providerInspections", "checks"]) walk(j[k]);
|
|
64
|
+
return [...out];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Where each client keeps REA's entry. Read only, to show the switch and the installed
|
|
68
|
+
// version without running npx; REA itself writes them. A missing file is simply "not here".
|
|
69
|
+
const CONFIGS: Record<string, (home: string) => string[]> = {
|
|
70
|
+
claude_code: (h) => [join(process.env.CLAUDE_CONFIG_DIR ?? h, ".claude.json")],
|
|
71
|
+
codex: (h) => [join(process.env.CODEX_HOME ?? join(h, ".codex"), "config.toml")],
|
|
72
|
+
gemini_cli: (h) => [join(h, ".gemini", "settings.json")],
|
|
73
|
+
antigravity: (h) => [join(h, ".gemini", "antigravity", "mcp_config.json")],
|
|
74
|
+
cursor: (h) => [join(h, ".cursor", "mcp.json")],
|
|
75
|
+
opencode: (h) => [join(h, ".config", "opencode", "opencode.json"), join(h, ".config", "opencode", "opencode.jsonc")],
|
|
76
|
+
};
|
|
77
|
+
export function reaRegistered(home: string): Reg[] {
|
|
78
|
+
return reaClients(home).flatMap(({ client }) => {
|
|
79
|
+
for (const f of CONFIGS[client]!(home)) {
|
|
80
|
+
let t: string;
|
|
81
|
+
try { t = readFileSync(f, "utf8"); } catch { continue; }
|
|
82
|
+
const v = /rea-agents@(\d+\.\d+\.\d+)/.exec(t)?.[1];
|
|
83
|
+
// A pinned npx entry gives the version; a global install (`"command": "rea"`) only the
|
|
84
|
+
// server's key: a JSON `"rea": {` or a TOML `[mcp_servers.rea]`.
|
|
85
|
+
if (v || /["']rea["']\s*:\s*\{/.test(t) || /^\[mcp_servers\.rea\]/m.test(t)) return [{ client, version: v ?? null }];
|
|
86
|
+
}
|
|
87
|
+
return [];
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const file = (home: string) => join(home, ".kaizen", "rea.json");
|
|
92
|
+
export function reaSaved(home: string): Saved | null {
|
|
93
|
+
try {
|
|
94
|
+
const j = JSON.parse(readFileSync(file(home), "utf8"));
|
|
95
|
+
return j && j.on === true && okVersion(j.version) && Array.isArray(j.clients) ? { on: true, version: j.version, clients: j.clients.filter((c: unknown) => typeof c === "string") } : null;
|
|
96
|
+
} catch { return null; }
|
|
97
|
+
}
|
|
98
|
+
function save(home: string, s: Saved | null) {
|
|
99
|
+
if (!s) return rmSync(file(home), { force: true });
|
|
100
|
+
mkdirSync(join(home, ".kaizen"), { recursive: true });
|
|
101
|
+
writeFileSync(file(home) + ".tmp", JSON.stringify(s, null, 2));
|
|
102
|
+
renameSync(file(home) + ".tmp", file(home));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const validClients = (home: string, clients: string[]) => {
|
|
106
|
+
const known = new Set(reaClients(home).map((c) => c.client));
|
|
107
|
+
return clients.length > 0 && clients.every((c) => known.has(c));
|
|
108
|
+
};
|
|
109
|
+
const clientArgs = (clients: string[]) => clients.flatMap((c) => ["--client", c]);
|
|
110
|
+
// REA's own words when a step did not go through: its message, else the first line it printed.
|
|
111
|
+
const reason = (j: any, out: string) => String(j?.message ?? j?.error ?? j?.reason ?? (out.trim().split("\n")[0] || "REA did not answer")).slice(0, 300);
|
|
112
|
+
|
|
113
|
+
export async function reaLatest(sh: Run = run): Promise<string | null> {
|
|
114
|
+
const r = await sh([npm, "view", "rea-agents", "version"]);
|
|
115
|
+
const v = r.out.trim().split("\n").pop()?.trim();
|
|
116
|
+
return r.ok && okVersion(v) ? v : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// The dry run: what `setup` would change, nothing written.
|
|
120
|
+
export async function reaPlan(home: string, version: string, clients: string[], sh: Run = run) {
|
|
121
|
+
if (!okVersion(version) || !validClients(home, clients)) return { ok: false as const, why: "no REA version or agent to set up" };
|
|
122
|
+
const r = await sh([npx, "-y", pkg(version), "setup", ...clientArgs(clients), "--dry-run", "--json"]);
|
|
123
|
+
const j = parse(r.out);
|
|
124
|
+
if (!r.ok || !j || j.status !== "planned") return { ok: false as const, why: reason(j, r.out) };
|
|
125
|
+
return { ok: true as const, version, clients, files: planFiles(j) };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Applies a plan the user saw. Saved only when REA says it is done.
|
|
129
|
+
export async function reaApply(home: string, version: string, clients: string[], sh: Run = run) {
|
|
130
|
+
if (!okVersion(version) || !validClients(home, clients)) return { ok: false as const, why: "no REA version or agent to set up" };
|
|
131
|
+
const r = await sh([npx, "-y", pkg(version), "setup", ...clientArgs(clients), "--yes", "--json"]);
|
|
132
|
+
const j = parse(r.out);
|
|
133
|
+
if (!r.ok || !j || /^(needs_confirmation|needs_human|cancelled|planned)$/.test(String(j.status)) || j.reason === "conflict") return { ok: false as const, why: reason(j, r.out) };
|
|
134
|
+
save(home, { on: true, version, clients });
|
|
135
|
+
return { ok: true as const, version };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Off: REA's own uninstall, whoever set REA up. What it leaves (a Claude local or profile
|
|
139
|
+
// registration, which REA does not touch) is named with the command that removes it.
|
|
140
|
+
export async function reaRemove(home: string, sh: Run = run) {
|
|
141
|
+
const version = reaSaved(home)?.version ?? reaRegistered(home).find((r) => r.version)?.version ?? (await reaLatest(sh));
|
|
142
|
+
if (!okVersion(version)) return { ok: false as const, why: "can't tell which REA to run: npm is unreachable" };
|
|
143
|
+
const r = await sh([npx, "-y", pkg(version), "uninstall", "--json"]);
|
|
144
|
+
if (!r.ok) return { ok: false as const, why: reason(parse(r.out), r.out) };
|
|
145
|
+
save(home, null);
|
|
146
|
+
const left = reaRegistered(home).map((x) => x.client);
|
|
147
|
+
return { ok: true as const, left, ...(left.includes("claude_code") ? { hint: "claude mcp remove --scope user rea" } : {}) };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Doctor runs npx, so it is cached and never awaited by the page: the first look starts it.
|
|
151
|
+
const doctorCache = new Map<string, { at: number; p: Promise<{ healthy: boolean; missing: string[] } | null>; v?: { healthy: boolean; missing: string[] } | null }>();
|
|
152
|
+
export function reaDoctor(version: string, sh: Run = run, now = Date.now()) {
|
|
153
|
+
const hit = doctorCache.get(version);
|
|
154
|
+
if (hit && now - hit.at < 10 * 60_000) return hit.v;
|
|
155
|
+
const entry: { at: number; p: Promise<any>; v?: any } = { at: now, p: Promise.resolve(null) };
|
|
156
|
+
entry.p = sh([npx, "-y", pkg(version), "doctor", "--json"]).then((r) => {
|
|
157
|
+
const j = parse(r.out);
|
|
158
|
+
entry.v = j ? { healthy: j.healthy === true, missing: doctorMissing(j) } : null;
|
|
159
|
+
return entry.v;
|
|
160
|
+
});
|
|
161
|
+
doctorCache.set(version, entry);
|
|
162
|
+
return hit?.v;
|
|
163
|
+
}
|
|
164
|
+
export const forgetDoctor = () => doctorCache.clear();
|
|
165
|
+
|
|
166
|
+
const latestCache = { at: 0, v: null as string | null, p: null as Promise<string | null> | null };
|
|
167
|
+
function cachedLatest(sh: Run, now: number) {
|
|
168
|
+
if (now - latestCache.at > 60 * 60_000 && !latestCache.p) {
|
|
169
|
+
latestCache.p = reaLatest(sh).then((v) => { latestCache.v = v; latestCache.at = Date.now(); latestCache.p = null; return v; });
|
|
170
|
+
}
|
|
171
|
+
return latestCache.v;
|
|
172
|
+
}
|
|
173
|
+
export const forgetLatest = () => { latestCache.at = 0; latestCache.v = null; latestCache.p = null; };
|
|
174
|
+
|
|
175
|
+
const newer = (a: string, b: string) => {
|
|
176
|
+
const x = a.split(".").map(Number), y = b.split(".").map(Number);
|
|
177
|
+
for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i]! > y[i]!;
|
|
178
|
+
return false;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// The row on Settings → Skills. Off and never set up: no npx, no npm, nothing run.
|
|
182
|
+
export function reaRow(home: string, sh: Run = run, now = Date.now()) {
|
|
183
|
+
const saved = reaSaved(home), reg = reaRegistered(home);
|
|
184
|
+
const on = !!saved || reg.length > 0;
|
|
185
|
+
const installed = saved?.version ?? reg.find((r) => r.version)?.version ?? null;
|
|
186
|
+
const latest = on ? cachedLatest(sh, now) : null;
|
|
187
|
+
const doc = on && installed ? reaDoctor(installed, sh, now) : null;
|
|
188
|
+
const regd = new Set(reg.map((r) => r.client));
|
|
189
|
+
const note = !on ? undefined
|
|
190
|
+
: `REA ${installed ?? "(version unknown)"}${!saved ? " · set up outside kaizen" : ""}${latest && installed && newer(latest, installed) ? ` · ${latest} available` : ""}${doc === undefined ? " · checking what it needs…" : ""}`;
|
|
191
|
+
return {
|
|
192
|
+
id: "rea", title: "Reverse engineering (REA)", group: "optional", offByDefault: true, status: "beta",
|
|
193
|
+
description: "Lets agents study apps, binaries, packages and file formats whose source isn't here, through REA's MCP tools.",
|
|
194
|
+
off: !on, needs: (doc?.missing ?? []).map((name) => ({ name, found: false })),
|
|
195
|
+
agents: reaClients(home).map((c) => ({ agent: c.agent, state: regd.has(c.client) ? "installed" : "missing" })),
|
|
196
|
+
...(note ? { note } : {}),
|
|
197
|
+
rea: { installed, latest, update: !!(latest && installed && newer(latest, installed)), outside: on && !saved, clients: reaClients(home).map((c) => c.client) },
|
|
198
|
+
};
|
|
199
|
+
}
|
package/cli/settings.ts
CHANGED
|
@@ -117,6 +117,9 @@ const SETTINGS: Setting[] = [
|
|
|
117
117
|
{ key: "agent.heartbeat_minutes", label: "Agent heartbeat", group: "Board", values: ["2", "5", "10", "30"], help: "Minutes. A card says stale after two quiet intervals" },
|
|
118
118
|
{ key: "subagents.model", label: "Claude Code", group: "Agents", values: ["inherit", "opus", "sonnet", "haiku"], help: "Its stage subagents: planner, builder, reviewer", when: ["runner", "full"] },
|
|
119
119
|
{ key: "subagents.effort", label: "Claude Code effort", group: "Agents", values: ["inherit", "low", "medium", "high"], help: "Planner, builder, reviewer", when: ["runner", "full"] },
|
|
120
|
+
{ key: "subagents.planner", label: "Claude Code planner", group: "Agents", values: ["default", "opus", "sonnet", "haiku"], help: "default: the model above", when: ["runner", "full"] },
|
|
121
|
+
{ key: "subagents.builder", label: "Claude Code builder", group: "Agents", values: ["default", "opus", "sonnet", "haiku"], help: "Also runs the fix rounds. default: the model above", when: ["runner", "full"] },
|
|
122
|
+
{ key: "subagents.reviewer", label: "Claude Code reviewer", group: "Agents", values: ["default", "opus", "sonnet", "haiku"], help: "Also runs the rechecks. default: the model above", when: ["runner", "full"] },
|
|
120
123
|
{ key: "auto_fix.enabled", label: "Fix findings automatically", group: "Auto-fix", values: ["true", "false"], help: "" },
|
|
121
124
|
{ key: "auto_fix.min_severity", label: "Lowest severity to fix", group: "Auto-fix", values: ["critical", "high", "medium", "low"], help: "", when: ["auto_fix.enabled", "true"] },
|
|
122
125
|
{ key: "auto_fix.max_iterations", label: "Max fix rounds", group: "Auto-fix", values: ["1", "2", "3", "4", "5"], help: "", when: ["auto_fix.enabled", "true"] },
|
|
@@ -131,7 +134,8 @@ const SETTINGS: Setting[] = [
|
|
|
131
134
|
{ key: "orchestration.max_workers", label: "Max workers per run", group: "Orchestration", values: ["1", "2", "3", "4", "5", "6"], help: "Total per run", when: ["orchestration.enabled", "true"] },
|
|
132
135
|
{ key: "orchestration.permissions", label: "Worker permissions", group: "Orchestration", values: ["own", "bypass"], help: "own: each agent's own prompts. Bypass skips every prompt in every worker", when: ["orchestration.enabled", "true"] },
|
|
133
136
|
// One per tool that takes a model flag; a run freezes its own agent's. Empty: the run's own model.
|
|
134
|
-
...KNOWN_AGENTS.filter((a) => MODEL_FLAGS[a.cmd]
|
|
137
|
+
...KNOWN_AGENTS.filter((a) => MODEL_FLAGS[a.cmd]).map((a): Setting => ({ key: `agent.model.${a.cmd}`, label: `Model: ${a.name}`, group: "Agents", values: [], text: true, help: a.cmd === "claude" ? "The session kaizen launches, and every stage subagent left on inherit. Empty: its own default" : "The tool's own model name, for every stage: it runs them in one session. Empty: its own default" })),
|
|
138
|
+
...KNOWN_AGENTS.filter((a) => MODEL_FLAGS[a.cmd]).map((a): Setting => ({ key: `agent.handoff_model.${a.cmd}`, label: `Handoff model: ${a.name}`, group: "Agents", values: [], text: true, help: "The second agent a worktree run hands off to. Empty: the run's own model" })),
|
|
135
139
|
...KNOWN_AGENTS.filter((a) => MODEL_FLAGS[a.cmd]).map((a): Setting => ({ key: `orchestration.worker_model.${a.cmd}`, label: `Worker model: ${a.name}`, group: "Orchestration", values: [], text: true, help: "The tool's own model name. Empty: the run's own model", when: ["orchestration.enabled", "true"] })),
|
|
136
140
|
{ key: "review.write_memory", label: "Remember lessons", group: "Project", values: ["true", "false"], help: "" },
|
|
137
141
|
{ key: "review.memory_max_lines", label: "Memory size cap", group: "Project", values: ["50", "100", "200", "400"], help: "" },
|
package/cli/sources.ts
CHANGED
|
@@ -361,10 +361,11 @@ function isPrivate(addr: string): boolean {
|
|
|
361
361
|
if (isIP(a) === 4) {
|
|
362
362
|
const [x, y] = a.split(".").map(Number) as [number, number];
|
|
363
363
|
return x === 0 || x === 10 || x === 127 || (x === 172 && y >= 16 && y <= 31) || (x === 192 && y === 168)
|
|
364
|
-
|| (x === 169 && y === 254) || (x === 100 && y >= 64 && y <= 127)
|
|
364
|
+
|| (x === 169 && y === 254) || (x === 100 && y >= 64 && y <= 127)
|
|
365
|
+
|| (x === 192 && y === 0 && a.startsWith("192.0.0.")) || (x === 198 && (y === 18 || y === 19)) || x >= 224; // protocol block, benchmarking, multicast, reserved, broadcast
|
|
365
366
|
}
|
|
366
367
|
if (isIP(a) !== 6) return true; // not an address at all
|
|
367
|
-
return a === "::1" || a === "::" || /^fe[89ab]/.test(a) || /^f[cd]/.test(a);
|
|
368
|
+
return a === "::1" || a === "::" || /^fe[89ab]/.test(a) || /^f[cd]/.test(a) || /^ff/.test(a) || a.startsWith("64:ff9b:");
|
|
368
369
|
}
|
|
369
370
|
|
|
370
371
|
type Lookup = (host: string, opts: { all: true }) => Promise<{ address: string }[]>;
|
package/cli/state.ts
CHANGED
|
@@ -129,6 +129,39 @@ export function agentFlags(projectDir: string, cmd: string, configText?: string,
|
|
|
129
129
|
];
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
// subagents.<key> through the config chain, project first. inherit, default and empty
|
|
133
|
+
// count as unset, so they fall through to the next file.
|
|
134
|
+
function subagentSetting(projectDir: string, key: string): string | null {
|
|
135
|
+
const re = new RegExp(`^subagents:\\n(?:[ \\t#][^\\n]*\\n|\\n)*?[ \\t]+${key}:[ \\t]*["']?([^"'\\s#]*)`, "m");
|
|
136
|
+
for (const t of configTexts(projectDir)) {
|
|
137
|
+
const v = re.exec(t)?.[1];
|
|
138
|
+
if (v && v !== "inherit" && v !== "default") return v;
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type SubagentStage = "planner" | "builder" | "reviewer";
|
|
144
|
+
export const SUBAGENT_STAGES: SubagentStage[] = ["planner", "builder", "reviewer"];
|
|
145
|
+
|
|
146
|
+
// The model a Claude Code stage subagent runs on: its own subagents.<stage>, else
|
|
147
|
+
// subagents.model. Null: inherit the session's.
|
|
148
|
+
export function subagentModel(projectDir: string, stage?: SubagentStage): string | null {
|
|
149
|
+
const v = (stage && subagentSetting(projectDir, stage)) || subagentSetting(projectDir, "model");
|
|
150
|
+
return v && plainModel(v) ? v : null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// What a Claude Code launch carries so its subagents get subagents.model and .effort
|
|
154
|
+
// even when the agent forgets to pass them. Claude Code reads these as defaults: a model
|
|
155
|
+
// on the Agent call, or a model:/effort: line in the agent file, still wins.
|
|
156
|
+
export function subagentEnv(projectDir: string, cmd: string): string[] {
|
|
157
|
+
if (cmd !== "claude") return [];
|
|
158
|
+
const m = subagentModel(projectDir), e = subagentSetting(projectDir, "effort");
|
|
159
|
+
return [
|
|
160
|
+
...(m ? [`CLAUDE_CODE_SUBAGENT_MODEL=${m}`] : []),
|
|
161
|
+
...(e && /^(low|medium|high|xhigh|max)$/.test(e) ? [`CLAUDE_CODE_SUBAGENT_EFFORT=${e}`] : []),
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
|
|
132
165
|
// What the board's Run form offers: the installed tools, the one it would pick, and
|
|
133
166
|
// each one's configured model to start the field from.
|
|
134
167
|
export function agentChoices(projectDir: string) {
|
|
@@ -1580,7 +1613,7 @@ function isSession(pid: number, s: Session): boolean | null {
|
|
|
1580
1613
|
}
|
|
1581
1614
|
const ps = onPath("ps");
|
|
1582
1615
|
if (!ps) return null;
|
|
1583
|
-
const m = /^\s*(\S+)\s+(.*)$/.exec(Bun.spawnSync([ps, "-o", "etime=,args=", "-p", String(pid)], { stdin: "ignore", timeout: 5000 }).stdout.toString().trim());
|
|
1616
|
+
const m = /^\s*(\S+)\s+(.*)$/.exec(Bun.spawnSync([ps, "-o", "etime=,args=", "-p", String(pid)], { stdin: "ignore", timeout: 5000, windowsHide: true }).stdout.toString().trim());
|
|
1584
1617
|
if (!m) return null;
|
|
1585
1618
|
// etime is [[dd-]hh:]mm:ss
|
|
1586
1619
|
const [d, rest] = m[1].includes("-") ? m[1].split("-") : ["0", m[1]];
|
|
@@ -1753,15 +1786,18 @@ export function sessionLaunch(projectDir: string, cmd: string, base: string[], p
|
|
|
1753
1786
|
// time, in Claude's own config. Best effort: any failure just means Claude asks.
|
|
1754
1787
|
export function trustFolder(dir: string, cfg = join(process.env.CLAUDE_CONFIG_DIR ?? homedir(), ".claude.json")) {
|
|
1755
1788
|
try {
|
|
1756
|
-
const top = Bun.spawnSync(["git", "-C", dir, "rev-parse", "--show-toplevel"], { stderr: "ignore" });
|
|
1789
|
+
const top = Bun.spawnSync(["git", "-C", dir, "rev-parse", "--show-toplevel"], { stderr: "ignore", windowsHide: true });
|
|
1757
1790
|
// Claude Code keys its projects with forward slashes on Windows, as git prints them.
|
|
1758
1791
|
const found = top.success ? top.stdout.toString().trim() || dir : dir;
|
|
1759
1792
|
const root = process.platform === "win32" ? found.replace(/\\/g, "/") : found;
|
|
1760
1793
|
const d = JSON.parse(readFileSync(cfg, "utf8"));
|
|
1761
1794
|
if (d.projects?.[root]?.hasTrustDialogAccepted) return;
|
|
1795
|
+
// A repo that brings its own hooks, MCP servers or settings is the case the dialog is for: let Claude ask.
|
|
1796
|
+
if ([".mcp.json", join(".claude", "settings.json"), join(".claude", "settings.local.json")].some((x) => existsSync(join(root, x)))) return;
|
|
1762
1797
|
d.projects ??= {};
|
|
1763
1798
|
d.projects[root] = { ...d.projects[root], hasTrustDialogAccepted: true };
|
|
1764
|
-
|
|
1799
|
+
// Keep the file's own mode: it holds account data, and a fresh .tmp would take the umask's.
|
|
1800
|
+
writeFileSync(cfg + ".tmp", JSON.stringify(d, null, 2), { mode: statSync(cfg).mode & 0o777 });
|
|
1765
1801
|
renameSync(cfg + ".tmp", cfg);
|
|
1766
1802
|
} catch { /* Claude asks as before */ }
|
|
1767
1803
|
}
|
|
@@ -1818,7 +1854,8 @@ export function launchRun(it: Item, from: string, run?: string, pick: { agent?:
|
|
|
1818
1854
|
const manual = manualCommand(projectDir, commandOf(agent.cmd, prefs), prompt, flags, acct.dir ? `${acct.envVar}=${shq(acct.dir)}` : "");
|
|
1819
1855
|
// Only what is started carries env: the returned `cmd` reaches the page.
|
|
1820
1856
|
// A run the board knows hears which one it is; a new run has no id yet and passes --run.
|
|
1821
|
-
const
|
|
1857
|
+
const vars = [...(run ? [`KAIZEN_RUN_ID=${run}`, ...stageEnv(projectDir, run)] : []), ...subagentEnv(projectDir, agent.cmd), ...accountEnv(acct)];
|
|
1858
|
+
const identity = vars.length && process.platform !== "win32" ? ["env", ...vars] : [];
|
|
1822
1859
|
const started = [...identity, ...withEnv(s.fullCmd, agent.cmd, prefs)];
|
|
1823
1860
|
const drop = () => { if (s.record) rmSync(s.record, { force: true }); };
|
|
1824
1861
|
|
|
@@ -1934,7 +1971,8 @@ export function gitStatus(projectDir: string): GitStatus {
|
|
|
1934
1971
|
// The path of a `git status --porcelain` line; for a rename, the new one.
|
|
1935
1972
|
// ponytail: only the surrounding quotes are undone, so a name git escapes (non-ASCII,
|
|
1936
1973
|
// a quote, a backslash) never matches a report; read `status -z` if that comes up.
|
|
1937
|
-
|
|
1974
|
+
// " -> " separates a rename or copy only; an untracked file may be named `a -> b`.
|
|
1975
|
+
const statusPath = (line: string) => (/[RC]/.test(line.slice(0, 2)) ? line.slice(3).split(" -> ").pop()! : line.slice(3)).replace(/^"|"$/g, "");
|
|
1938
1976
|
|
|
1939
1977
|
// What a run reported changing: 03-impl.md and its fix rounds, the parts of them that
|
|
1940
1978
|
// list changes (`named`), and when the newest of them was written.
|
package/cli/versions.ts
CHANGED
|
@@ -42,7 +42,7 @@ function writeStore(place: string, name: string, s: Store) {
|
|
|
42
42
|
// Returns { value } when it ran, null when another holder had the lock.
|
|
43
43
|
function locked<T>(place: string, name: string, fn: () => T): { value: T } | null {
|
|
44
44
|
const lock = join(place, "videos", name, ".versions.lock");
|
|
45
|
-
try { if (Date.now() - statSync(lock).mtimeMs > 60_000)
|
|
45
|
+
try { if (Date.now() - statSync(lock).mtimeMs > 60_000) { const aside = `${lock}.${process.pid}.stale`; renameSync(lock, aside); unlinkSync(aside); } } catch { /* none */ }
|
|
46
46
|
let fd: number;
|
|
47
47
|
try { fd = openSync(lock, "wx"); } catch { return null; }
|
|
48
48
|
try { return { value: fn() }; } finally { closeSync(fd); try { unlinkSync(lock); } catch { /* gone */ } }
|
package/cli/video.ts
CHANGED
|
@@ -63,7 +63,7 @@ function seconds(f: string): number | null {
|
|
|
63
63
|
let key: string;
|
|
64
64
|
try { key = `${f}:${statSync(f).mtimeMs}`; } catch { return null; }
|
|
65
65
|
if (!probed.has(key)) {
|
|
66
|
-
const r = spawnSync("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", f], { encoding: "utf8" });
|
|
66
|
+
const r = spawnSync("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", f], { encoding: "utf8", windowsHide: true });
|
|
67
67
|
const n = parseFloat(r.stdout ?? "");
|
|
68
68
|
probed.set(key, Number.isFinite(n) ? Math.round(n) : null);
|
|
69
69
|
}
|