kaizen-agent 1.87.2 → 1.87.4
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/activity.ts +86 -0
- package/cli/add-project.ts +64 -1
- package/cli/auto-update.ts +33 -0
- package/cli/browser.ts +21 -0
- package/cli/chat.ts +88 -13
- package/cli/chatgpt.ts +1 -1
- package/cli/dashboard.ts +1 -1
- package/cli/install.ts +65 -36
- package/cli/look.ts +1 -0
- package/cli/models.ts +94 -0
- package/cli/onboarding.ts +9 -4
- package/cli/pty.ts +27 -12
- package/cli/release.ts +13 -1
- package/cli/settings.ts +39 -7
- package/cli/sources.ts +84 -20
- package/cli/state.ts +56 -3
- package/cli/task-service.ts +10 -3
- package/cli/usage.ts +15 -2
- package/cli/web.ts +119 -47
- package/cli/whats-new.json +38 -0
- package/cli/whats-new.ts +43 -0
- package/cli/workers.ts +2 -2
- package/package.json +1 -1
- package/skills/kaizen/config.default.yml +3 -0
- package/skills/kaizen/spec.md +6 -0
- package/skills/kaizen-explore/SKILL.md +7 -0
- package/web/components/home/home-window.tsx +0 -36
- package/web/components/home/index.ts +1 -0
- package/web/components/home/onboarding-dialog.tsx +44 -7
- package/web/components/home/works-flow.tsx +119 -0
- package/web/components/icebox/capture-box.tsx +11 -2
- package/web/components/icebox/request-card.tsx +33 -11
- package/web/components/project/add-project-dialog.tsx +1 -1
- package/web/components/rail/rail-list.tsx +51 -7
- package/web/components/run/doc-body.tsx +43 -0
- package/web/components/settings/agent-rows.tsx +15 -11
- package/web/components/settings/browser-row.tsx +1 -1
- package/web/components/settings/setting-row.tsx +10 -6
- package/web/components/settings/settings-section.tsx +5 -3
- package/web/components/settings/skill-card.tsx +32 -2
- package/web/components/settings/update-bar.tsx +53 -35
- package/web/components/settings/whats-new-card.tsx +70 -0
- package/web/components/shared/picker.tsx +21 -1
- package/web/components/shell/rail.tsx +8 -4
- package/web/dist/annotate.js +1 -1
- package/web/dist/board.css +6 -11
- package/web/dist/board.js +83 -56
- package/web/dist/boot.js +1 -1
- package/web/dist/notebook.css +2 -2
- package/web/dist/notebook.js +34 -34
- package/web/dist/popup.css +1 -1
- package/web/dist/popup.js +1 -1
- package/web/dist/term.js +1 -1
- package/web/dist/ui.css +2 -2
- package/web/dist/video.js +1 -1
- package/web/lib/footer/footer-rules.ts +8 -2
- package/web/lib/footer/footer-store.ts +2 -2
- package/web/lib/home/onboarding.ts +63 -17
- package/web/lib/icebox/icebox-actions.ts +24 -2
- package/web/lib/icebox/icebox-store.ts +7 -1
- package/web/lib/icebox/icebox-view.ts +3 -2
- package/web/lib/icebox/icebox.ts +24 -4
- package/web/lib/icebox/use-ice-keys.ts +5 -0
- package/web/lib/project/add-project.ts +6 -0
- package/web/lib/rail/rules.ts +4 -1
- package/web/lib/run/panel-derive.ts +1 -1
- package/web/lib/run/panel-store.ts +1 -0
- package/web/lib/settings/index.ts +2 -0
- package/web/lib/settings/settings-actions.ts +8 -0
- package/web/lib/settings/settings.ts +6 -4
- package/web/lib/settings/use-model-choices.ts +31 -0
- package/web/lib/settings/whats-new.ts +36 -0
- package/web/pages/board/App.tsx +3 -10
- package/web/pages/icebox-page.tsx +173 -125
- package/web/pages/task-page.tsx +17 -4
- package/web/ui/legacy/board.css +4 -9
package/cli/models.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// The models each agent tool offers, read from the tool itself so a new model shows up
|
|
2
|
+
// without a kaizen release. Each tool has its own source: Claude Code and Codex keep a
|
|
3
|
+
// catalog cache in their home folders, Gemini CLI, Antigravity and OpenCode list them on
|
|
4
|
+
// a `models` command. Nothing here is required: a tool that lists nothing gives [] and
|
|
5
|
+
// the Settings field stays a free text. A listed id must still pass plainModel(), because
|
|
6
|
+
// it ends up in a launch line.
|
|
7
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { commandOf } from "./agent-prefs.ts";
|
|
11
|
+
import { MODEL_FLAGS, onPath, plainModel } from "./state.ts";
|
|
12
|
+
|
|
13
|
+
export type ModelChoice = { id: string; name: string };
|
|
14
|
+
|
|
15
|
+
const dedupe = (rows: ModelChoice[]) => {
|
|
16
|
+
const seen = new Set<string>();
|
|
17
|
+
return rows.filter((m) => plainModel(m.id) && !seen.has(m.id) && !!seen.add(m.id));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Claude Code's catalog (an undocumented cache, one file per account): the newest `*-cc.json`.
|
|
21
|
+
export function parseClaudeCatalog(files: string[]): ModelChoice[] {
|
|
22
|
+
let best: any = null;
|
|
23
|
+
for (const f of files) {
|
|
24
|
+
try { const d = JSON.parse(f); if (Array.isArray(d?.catalog?.config?.models) && (!best || d.fetchedAt > best.fetchedAt)) best = d; } catch { /* not a catalog */ }
|
|
25
|
+
}
|
|
26
|
+
return (best?.catalog?.config?.models ?? [])
|
|
27
|
+
.filter((m: any) => typeof m?.id === "string" && !m.hidden && !m.deprecated)
|
|
28
|
+
.map((m: any) => ({ id: m.id, name: String(m.name ?? m.id) }));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Codex's cache lists hidden models too (internal reviewers): only `list` ones are offered.
|
|
32
|
+
export function parseCodexCache(text: string): ModelChoice[] {
|
|
33
|
+
try {
|
|
34
|
+
return (JSON.parse(text).models ?? [])
|
|
35
|
+
.filter((m: any) => typeof m?.slug === "string" && (m.visibility ?? "list") === "list")
|
|
36
|
+
.map((m: any) => ({ id: m.slug, name: String(m.display_name ?? m.slug) }));
|
|
37
|
+
} catch { return []; }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// `gemini models`: "id (Name)" lines, each followed by indented detail.
|
|
41
|
+
export const parseGemini = (out: string): ModelChoice[] =>
|
|
42
|
+
[...out.matchAll(/^(\S+) \((.+)\)$/gm)].map((m) => ({ id: m[1]!, name: m[2]!.trim() === m[1] ? m[1]! : m[2]!.trim() }));
|
|
43
|
+
|
|
44
|
+
// `agy models`: "id<TAB>Name"; the first line says it is fetching.
|
|
45
|
+
export const parseAgy = (out: string): ModelChoice[] =>
|
|
46
|
+
out.split("\n").filter((l) => l.includes("\t")).map((l) => { const [id, name] = l.split("\t"); return { id: id!.trim(), name: (name ?? id)!.trim() }; });
|
|
47
|
+
|
|
48
|
+
// `opencode models`: one provider/model id per line.
|
|
49
|
+
export const parseOpencode = (out: string): ModelChoice[] =>
|
|
50
|
+
out.split("\n").map((l) => l.trim()).filter((l) => /^\S+\/\S+$/.test(l)).map((id) => ({ id, name: id }));
|
|
51
|
+
|
|
52
|
+
const CLAUDE_ALIASES: ModelChoice[] = [
|
|
53
|
+
{ id: "opus", name: "Opus (latest)" }, { id: "sonnet", name: "Sonnet (latest)" },
|
|
54
|
+
{ id: "haiku", name: "Haiku (latest)" }, { id: "fable", name: "Fable (latest)" },
|
|
55
|
+
];
|
|
56
|
+
const LIST_CMD: Record<string, { args: string[]; parse: (o: string) => ModelChoice[] }> = {
|
|
57
|
+
gemini: { args: ["models"], parse: parseGemini }, agy: { args: ["models"], parse: parseAgy }, opencode: { args: ["models"], parse: parseOpencode },
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
async function run(cmd: string, args: string[]): Promise<string> {
|
|
61
|
+
const bin = onPath(commandOf(cmd));
|
|
62
|
+
if (!bin) return "";
|
|
63
|
+
const p = Bun.spawn([bin, ...args], { stdin: "ignore", stdout: "pipe", stderr: "ignore", timeout: 20_000, windowsHide: true });
|
|
64
|
+
const out = await new Response(p.stdout).text();
|
|
65
|
+
return (await p.exited) === 0 ? out : "";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const readDir = (dir: string, ok: (f: string) => boolean) => {
|
|
69
|
+
try { return readdirSync(dir).filter(ok).map((f) => readFileSync(join(dir, f), "utf8")); } catch { return []; }
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
async function load(cmd: string): Promise<ModelChoice[]> {
|
|
73
|
+
if (cmd === "claude") {
|
|
74
|
+
const dir = join(process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude"), "cache", "model-catalog");
|
|
75
|
+
return [...CLAUDE_ALIASES, ...parseClaudeCatalog(readDir(dir, (f) => f.endsWith("-cc.json")))];
|
|
76
|
+
}
|
|
77
|
+
if (cmd === "codex") {
|
|
78
|
+
const f = join(process.env.CODEX_HOME ?? join(homedir(), ".codex"), "models_cache.json");
|
|
79
|
+
return existsSync(f) ? parseCodexCache(readFileSync(f, "utf8")) : [];
|
|
80
|
+
}
|
|
81
|
+
const l = LIST_CMD[cmd];
|
|
82
|
+
return l ? l.parse(await run(cmd, l.args)) : [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// A model list changes rarely and some tools take seconds to print one: keep it ten minutes.
|
|
86
|
+
const kept = new Map<string, { at: number; rows: Promise<ModelChoice[]> }>();
|
|
87
|
+
export function modelsOf(cmd: string): Promise<ModelChoice[]> {
|
|
88
|
+
if (!MODEL_FLAGS[cmd]) return Promise.resolve([]);
|
|
89
|
+
const hit = kept.get(cmd);
|
|
90
|
+
if (hit && Date.now() - hit.at < 600_000) return hit.rows;
|
|
91
|
+
const rows = load(cmd).then(dedupe, () => []);
|
|
92
|
+
kept.set(cmd, { at: Date.now(), rows });
|
|
93
|
+
return rows;
|
|
94
|
+
}
|
package/cli/onboarding.ts
CHANGED
|
@@ -4,17 +4,21 @@
|
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
|
|
7
|
-
export const STEPS =
|
|
7
|
+
export const STEPS = 5; // how it works, default agent, how much to ask, look and notifications, phone; adding a project is the last button, not a step
|
|
8
8
|
export type Outcome = "done" | "skipped" | "dismissed" | null;
|
|
9
9
|
export type Saved = { step: number; outcome: Outcome };
|
|
10
10
|
|
|
11
|
+
// The new screen an old step lands on: the first one that person has not seen (agent done → how much to ask, and so on).
|
|
12
|
+
const OLD_STEPS = [0, 2, 3, 4];
|
|
11
13
|
const file = (home: string) => join(home, ".kaizen", "onboarding.json");
|
|
12
14
|
const OUTCOMES = ["done", "skipped", "dismissed", null];
|
|
13
15
|
|
|
14
16
|
export function readOnboarding(home: string): Saved | null {
|
|
15
17
|
try {
|
|
16
18
|
const d = JSON.parse(readFileSync(file(home), "utf8"));
|
|
17
|
-
|
|
19
|
+
// A file from before the five steps (no `v`) held an index into four: agent, look, notifications, phone.
|
|
20
|
+
const at = Number.isInteger(d?.step) ? (d.v === 2 ? d.step : (OLD_STEPS[d.step] ?? 0)) : 0;
|
|
21
|
+
const step = Math.max(0, Math.min(STEPS - 1, at));
|
|
18
22
|
return { step, outcome: OUTCOMES.includes(d?.outcome) ? d.outcome : null };
|
|
19
23
|
} catch {
|
|
20
24
|
return null;
|
|
@@ -39,11 +43,12 @@ export function writeOnboarding(home: string, body: unknown): Saved | { error: s
|
|
|
39
43
|
const cur = readOnboarding(home) ?? { step: 0, outcome: null };
|
|
40
44
|
if ("step" in b && !(Number.isInteger(b.step) && (b.step as number) >= 0 && (b.step as number) < STEPS)) return { error: "bad step" };
|
|
41
45
|
if ("outcome" in b && !OUTCOMES.includes(b.outcome as Outcome)) return { error: "bad outcome" };
|
|
42
|
-
|
|
46
|
+
// The furthest step reached is kept: going back a screen, or opening the flow again, does not make setup look not started.
|
|
47
|
+
const next: Saved = { step: "step" in b ? Math.max(cur.step, b.step as number) : cur.step, outcome: "outcome" in b ? (b.outcome as Outcome) : cur.outcome };
|
|
43
48
|
const dir = join(home, ".kaizen");
|
|
44
49
|
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
45
50
|
const tmp = file(home) + ".tmp";
|
|
46
|
-
writeFileSync(tmp, JSON.stringify(next) + "\n");
|
|
51
|
+
writeFileSync(tmp, JSON.stringify({ ...next, v: 2 }) + "\n");
|
|
47
52
|
renameSync(tmp, file(home));
|
|
48
53
|
return next;
|
|
49
54
|
}
|
package/cli/pty.ts
CHANGED
|
@@ -15,7 +15,7 @@ const killWinTree = (pid: number) => {
|
|
|
15
15
|
try { Bun.spawnSync([join(process.env.SystemRoot ?? "C:\\Windows", "System32", "taskkill.exe"), "/T", "/F", "/PID", String(pid)], { stdin: "ignore", stdout: "ignore", stderr: "ignore", timeout: 3000, windowsHide: true }); } catch { /* already gone */ }
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
type Pty = { lastOut?: number; proc: Bun.Subprocess; out: string[]; size: number; listeners: Set<(d: string | null) => void>; exit: number | null; asking: boolean; busy: boolean; quiet?: Timer; total: number; since: number; onChange?: () => void; tmux?: string; last: string; lastAt: number; typedAt: number; born: number; draft?: boolean };
|
|
18
|
+
type Pty = { lastOut?: number; proc: Bun.Subprocess; out: string[]; size: number; listeners: Set<(d: string | null) => void>; exit: number | null; asking: boolean; busy: boolean; quiet?: Timer; total: number; since: number; askedSince: number; askedAt: number; askCheck: number; onChange?: () => void; tmux?: string; last: string; lastAt: number; typedAt: number; born: number; draft?: boolean };
|
|
19
19
|
|
|
20
20
|
// What a page attaching late gets replayed. A full-screen tool redraws often, so the
|
|
21
21
|
// tail of its output is enough to rebuild the screen.
|
|
@@ -53,7 +53,8 @@ const grab = (p: Pty, text: string, every: number) => {
|
|
|
53
53
|
|
|
54
54
|
// A question the agent stopped on: Claude Code's and Codex's approval and choice prompts.
|
|
55
55
|
// ponytail: screen-text heuristic, misses a prompt worded otherwise; read agent hooks if that bites.
|
|
56
|
-
|
|
56
|
+
// `[❯›>]\s*1\.`: a menu's first option, with any number of spaces where colour codes were (Claude Code draws "❯ \x1b[..m1. Yes"). "Allow this" is Claude's read-outside-the-folder question.
|
|
57
|
+
const ASK = /Would you like to|Do you want to|Allow this|[❯›>]\s*1\. |Type something|\(y\/n\)|\[y\/N\]|Press enter to/i;
|
|
57
58
|
// Escape sequences out; a cursor move becomes a space so words drawn apart stay apart.
|
|
58
59
|
// The agent's working line (Claude Code's "✻ Thinking… (12s · ↓ 1.2k tokens)", Codex's
|
|
59
60
|
// "Working (12s • esc to interrupt)", Gemini's "(esc to cancel, 12s)", opencode's "esc interrupt")
|
|
@@ -70,6 +71,8 @@ export const asking = (screen: string) => {
|
|
|
70
71
|
};
|
|
71
72
|
// How long output stays still before the screen is read for a question.
|
|
72
73
|
export const QUIET_MS = 700;
|
|
74
|
+
// How often the screen is read for a question while output keeps arriving.
|
|
75
|
+
export const ASK_EVERY = 400;
|
|
73
76
|
// The latest meaningful line of some terminal output, for the sidebar card: escape sequences, box
|
|
74
77
|
// drawing, spinners and the TUI's own footer lines out. "" when nothing readable is left.
|
|
75
78
|
// ponytail: screen-text heuristic over raw chunks; a TUI that repaints oddly shows an older line.
|
|
@@ -112,13 +115,25 @@ export const ptySupported = WIN || typeof (Bun as any).Terminal === "function";
|
|
|
112
115
|
// outlives the board; null where tmux cannot be used, and the agent runs plainly.
|
|
113
116
|
export function startPty(key: string, cmd: string[], cwd: string, pidFile?: string, onChange?: () => void, opts: { seed?: string; tmux?: string; attach?: boolean; env?: Record<string, string> } = {}): number {
|
|
114
117
|
const dec = new TextDecoder();
|
|
115
|
-
const p: Pty = { proc: null as unknown as Bun.Subprocess, out: opts.seed ? [opts.seed] : [], size: opts.seed?.length ?? 0, listeners: new Set(), exit: null, asking: false, busy: false, total: 0, since: 0, onChange, last: "", lastAt: 0, typedAt: 0, born: Date.now() };
|
|
118
|
+
const p: Pty = { proc: null as unknown as Bun.Subprocess, out: opts.seed ? [opts.seed] : [], size: opts.seed?.length ?? 0, listeners: new Set(), exit: null, asking: false, busy: false, askedSince: -1, askedAt: 0, askCheck: 0, total: 0, since: 0, onChange, last: "", lastAt: 0, typedAt: 0, born: Date.now() };
|
|
116
119
|
// attach: the session already runs (kept from a board before this one); only a client is started.
|
|
117
120
|
if (opts.tmux && tmuxOk()) cmd = opts.attach ? attachCmd(opts.tmux) : tmuxCmd(opts.tmux, cmd);
|
|
118
121
|
const flag = (v: boolean) => { if (p.asking !== v) { p.asking = v; onChange?.(); } };
|
|
119
122
|
// busy: the agent's working line (WORK) drawn in the last QUIET_MS. A working agent redraws it many
|
|
120
123
|
// times a second; other output (a status-line refresh, a repaint on resize or focus) is not work.
|
|
121
124
|
const work = (v: boolean) => { if (p.busy !== v) { p.busy = v; onChange?.(); } };
|
|
125
|
+
// Is the agent waiting on the user? Read the screen's tail for a question. A question stays open while its screen keeps repainting
|
|
126
|
+
// under it (Claude Code's status line animates every ~600 ms, so output is never quiet) and nothing was typed: it ends when a key is
|
|
127
|
+
// typed (writePty clears it), the agent works again (WORK, in push) or exits.
|
|
128
|
+
const check = () => {
|
|
129
|
+
const tail = p.out.slice(-64).join("").slice(-8192);
|
|
130
|
+
grab(p, tail.slice(-4096), 0);
|
|
131
|
+
// Only what came after the user's last keystroke: a question already answered may still be in the tail.
|
|
132
|
+
const n = Math.min(8192, p.total - p.since);
|
|
133
|
+
const q = p.exit === null && n > 0 && asking(tail.slice(-n));
|
|
134
|
+
if (q && !p.asking) { p.askedSince = p.since; p.askedAt = Date.now(); }
|
|
135
|
+
flag(q || (p.asking && p.exit === null && p.since === p.askedSince));
|
|
136
|
+
};
|
|
122
137
|
const push = (d: string) => {
|
|
123
138
|
p.out.push(d);
|
|
124
139
|
p.lastOut = Date.now();
|
|
@@ -126,17 +141,17 @@ export function startPty(key: string, cmd: string[], cwd: string, pidFile?: stri
|
|
|
126
141
|
p.total += d.length;
|
|
127
142
|
while (p.size > CAP && p.out.length > 1) p.size -= p.out.shift()!.length;
|
|
128
143
|
for (const f of p.listeners) f(d);
|
|
129
|
-
if (WORKING.test(d))
|
|
144
|
+
if (WORKING.test(d)) {
|
|
145
|
+
work(p.exit === null);
|
|
146
|
+
// A working line drawn well after the question was raised: the question was answered some other way.
|
|
147
|
+
if (p.asking && Date.now() - p.askedAt > 400) flag(false);
|
|
148
|
+
}
|
|
130
149
|
grab(p, d, 1000);
|
|
150
|
+
// Not only when output goes quiet: look every ASK_EVERY while it flows.
|
|
151
|
+
const now = Date.now();
|
|
152
|
+
if (now - p.askCheck >= ASK_EVERY) { p.askCheck = now; check(); }
|
|
131
153
|
clearTimeout(p.quiet);
|
|
132
|
-
p.quiet = setTimeout(() => {
|
|
133
|
-
work(false);
|
|
134
|
-
const tail = p.out.slice(-8).join("").slice(-4096);
|
|
135
|
-
grab(p, tail, 0);
|
|
136
|
-
// Only what came after the user's last keystroke: a question already answered may still be in the tail.
|
|
137
|
-
const n = Math.min(4096, p.total - p.since);
|
|
138
|
-
flag(p.exit === null && n > 0 && asking(tail.slice(-n)));
|
|
139
|
-
}, QUIET_MS);
|
|
154
|
+
p.quiet = setTimeout(() => { work(false); check(); }, QUIET_MS);
|
|
140
155
|
};
|
|
141
156
|
if (WIN) {
|
|
142
157
|
const ps = winPs();
|
package/cli/release.ts
CHANGED
|
@@ -32,6 +32,9 @@ export function summaryOf(subjects: string[]) {
|
|
|
32
32
|
if (import.meta.main) {
|
|
33
33
|
const args = process.argv.slice(2);
|
|
34
34
|
const forced = ["patch", "minor", "major"].includes(args[0]) ? args.shift() : null;
|
|
35
|
+
// `--no-notes`: publish without a What's New entry for this version (the card then shows nothing for it).
|
|
36
|
+
const noNotes = args.includes("--no-notes");
|
|
37
|
+
if (noNotes) args.splice(args.indexOf("--no-notes"), 1);
|
|
35
38
|
const pkg = JSON.parse(readFileSync("package.json", "utf8"));
|
|
36
39
|
const tagged = (v: string) => sh(["git", "tag", "-l", `v${v}`]) !== "";
|
|
37
40
|
const head = sh(["git", "log", "-1", "--format=%s"]);
|
|
@@ -39,7 +42,9 @@ if (import.meta.main) {
|
|
|
39
42
|
console.error("release: commit or drop your changes first");
|
|
40
43
|
process.exit(1);
|
|
41
44
|
}
|
|
42
|
-
|
|
45
|
+
// An interrupted release leaves its bump commit untagged; later commits on top of it do not make it a new release.
|
|
46
|
+
const bumped = () => { try { return sh(["git", "log", "--format=%s", `${sh(["git", "describe", "--tags", "--abbrev=0"])}..HEAD`]).split("\n").some((m) => m.startsWith(`Release ${pkg.version}:`)); } catch { return head.startsWith(`Release ${pkg.version}:`); } };
|
|
47
|
+
if (bumped() && !tagged(pkg.version) && !forced) {
|
|
43
48
|
console.log(`release: reusing the unpublished bump commit for ${pkg.version}`);
|
|
44
49
|
} else {
|
|
45
50
|
const last = sh(["git", "describe", "--tags", "--abbrev=0"]);
|
|
@@ -50,6 +55,13 @@ if (import.meta.main) {
|
|
|
50
55
|
}
|
|
51
56
|
const level = forced ?? levelOf(log);
|
|
52
57
|
const v = nextVersion(pkg.version, level);
|
|
58
|
+
// What's New (cli/whats-new.json) is written by hand: a version with no entry shows people nothing after they update, so the release
|
|
59
|
+
// stops here, before anything is changed, unless it is told it is fine.
|
|
60
|
+
const { hasEntry } = await import("./whats-new.ts");
|
|
61
|
+
if (!hasEntry(v) && !noNotes) {
|
|
62
|
+
console.error(`release: cli/whats-new.json has no entry for ${v}. Add one (highlights and fixes, newest first) and commit it, or run again with --no-notes.`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
53
65
|
const summary = args.join(" ") || summaryOf(sh(["git", "log", "--reverse", "--format=%s", `${last}..HEAD`]).split("\n")) || "maintenance";
|
|
54
66
|
writeFileSync("package.json", readFileSync("package.json", "utf8").replace(`"version": "${pkg.version}"`, `"version": "${v}"`));
|
|
55
67
|
const note = ".kaizen/notes/Project/Release and testing.md";
|
package/cli/settings.ts
CHANGED
|
@@ -12,7 +12,8 @@ import { status as chatgptStatus } from "./chatgpt.ts";
|
|
|
12
12
|
// `when`: the row only has an effect while that other key holds that value; both
|
|
13
13
|
// settings screens dim it otherwise, and it stays editable (`/kaizen full` overrides
|
|
14
14
|
// the runner for one run, so a subagent model still matters under `runner: lite`).
|
|
15
|
-
|
|
15
|
+
// labels: what an option is called on screen; the value stored in config.yml is the key (see PLAIN below).
|
|
16
|
+
type Setting = { key: string; label: string; group: string; values: string[]; help: string; text?: boolean; folder?: boolean; when?: [string, string]; labels?: Record<string, string> };
|
|
16
17
|
|
|
17
18
|
export type PresetName = "low" | "medium" | "ultra";
|
|
18
19
|
|
|
@@ -23,7 +24,7 @@ export const PRESETS: Record<PresetName, {
|
|
|
23
24
|
}> = {
|
|
24
25
|
low: {
|
|
25
26
|
label: "Low",
|
|
26
|
-
hint: "
|
|
27
|
+
hint: "you approve every step — one session, cheapest, you approve the plan and the result",
|
|
27
28
|
settings: {
|
|
28
29
|
mode: "approve",
|
|
29
30
|
runner: "lite",
|
|
@@ -41,7 +42,7 @@ export const PRESETS: Record<PresetName, {
|
|
|
41
42
|
},
|
|
42
43
|
medium: {
|
|
43
44
|
label: "Medium",
|
|
44
|
-
hint: "balanced (recommended) —
|
|
45
|
+
hint: "balanced (recommended) — separate agents, you approve the plan, problems found are fixed for you",
|
|
45
46
|
settings: {
|
|
46
47
|
mode: "approve",
|
|
47
48
|
runner: "full",
|
|
@@ -58,7 +59,7 @@ export const PRESETS: Record<PresetName, {
|
|
|
58
59
|
},
|
|
59
60
|
ultra: {
|
|
60
61
|
label: "Ultra",
|
|
61
|
-
hint: "
|
|
62
|
+
hint: "hands-off — runs by itself, fixes problems itself (up to 4 rounds) and saves the work in git",
|
|
62
63
|
settings: {
|
|
63
64
|
mode: "auto",
|
|
64
65
|
runner: "full",
|
|
@@ -137,7 +138,7 @@ const SETTINGS: Setting[] = [
|
|
|
137
138
|
{ 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"] },
|
|
138
139
|
{ 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"] },
|
|
139
140
|
// One per tool that takes a model flag; a run freezes its own agent's. Empty: the run's own model.
|
|
140
|
-
...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
|
|
141
|
+
...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 agent left on Same as main. Empty: its own default" : "The tool's own model name, for every stage: it runs them in one session. Empty: its own default" })),
|
|
141
142
|
...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" })),
|
|
142
143
|
...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"] })),
|
|
143
144
|
{ key: "review.write_memory", label: "Remember lessons", group: "Project", values: ["true", "false"], help: "" },
|
|
@@ -148,11 +149,41 @@ const SETTINGS: Setting[] = [
|
|
|
148
149
|
{ key: "sources.agent", label: "Who picks social posts", group: "Board", values: ["ask", "chatgpt", "agent"], help: "X, TikTok, Instagram, Threads" },
|
|
149
150
|
{ key: "sources.model", label: "ChatGPT model for the icebox", group: "Board", values: [], text: true, help: "Gathering social posts, sorting captures, drafting tasks. Empty: plan default" },
|
|
150
151
|
{ key: "sources.effort", label: "ChatGPT effort for the icebox", group: "Board", values: ["low", "medium", "high"], help: "Gathering, sorting and task drafts" },
|
|
152
|
+
{ key: "board.auto_update", label: "Update automatically", group: "Board", values: ["false", "true"], help: "When a newer version is out, no terminal is running and no board page is open, kaizen updates itself and restarts. Off by default." },
|
|
151
153
|
{ key: "board.projects_dir", label: "Projects folder", group: "Board", values: [], text: true, folder: true, help: "Empty: known projects only" },
|
|
152
154
|
{ key: "board.video_dir", label: "Video library folder", group: "Board", values: [], text: true, folder: true, help: "Empty: ~/.kaizen" },
|
|
153
155
|
{ key: "board.chat_hotkey", label: "Popup chat hotkey", group: "Board", values: [], text: true, help: "Hyprland, e.g. SUPER + ALT + SPACE. Empty: none" },
|
|
154
156
|
];
|
|
155
157
|
|
|
158
|
+
// Plain option names and hints, applied to the rows above: they change what is shown, never what config.yml holds, which every
|
|
159
|
+
// older install, the skills and the terminal screen read. A hint names the option as the screen shows it, not the stored word.
|
|
160
|
+
const cap = (vs: string[]) => Object.fromEntries(vs.map((v) => [v, v[0]!.toUpperCase() + v.slice(1)]));
|
|
161
|
+
const SAME_MAIN = { inherit: "Same as main" }, SAME_ABOVE = { default: "Same as above" }, MODELS = cap(["opus", "sonnet", "haiku"]);
|
|
162
|
+
const PLAIN: Record<string, { labels?: Record<string, string>; help?: string }> = {
|
|
163
|
+
preset: { help: "Low: you approve every step, one session, cheapest. Medium: separate agents, you approve the plan. Ultra: runs by itself and saves the work in git. Custom: you changed a setting." },
|
|
164
|
+
mode: { labels: { approve: "Ask me", auto: "Automatic", "plan-only": "Plan only", "review-only": "Review only" }, help: "Ask me: it stops where you approve. Automatic: runs start to finish. Plan only: writes the plan and stops. Review only: checks work that already exists." },
|
|
165
|
+
"approvals.review": { help: "Also for automatic runs: a run that changed files waits for your approval, unless \"Auto runs skip final approval\" is on" },
|
|
166
|
+
auto_accept: { help: "On: an automatic run that changed files finishes without waiting for your approval, and is marked auto-accepted" },
|
|
167
|
+
runner: { labels: { full: "Separate agents", lite: "One session" }, help: "Separate agents: a different agent plans, builds and reviews, so the reviewer starts fresh. One session: the same session does every stage, cheaper." },
|
|
168
|
+
"build.executor": { labels: { subagent: "Own agent", inline: "This session", ask: "Ask me" }, help: "The code is written by its own agent, by this session, or you choose when you approve the plan." },
|
|
169
|
+
"review.executor": { labels: { inline: "This session", subagent: "Fresh agent", ask: "Ask me" }, help: "Who checks the work when everything runs in one session: this session, a fresh agent that did not see the work, or you choose before the review." },
|
|
170
|
+
"git.worktree_per_run": { labels: { ask: "Ask me", true: "Yes", false: "No" }, help: "Yes: each run works in its own branch and folder. No: in the project folder. Ask me: choose each time." },
|
|
171
|
+
"subagents.model": { labels: { ...SAME_MAIN, ...MODELS }, help: "The model for Claude Code's stage agents: planner, builder, reviewer" },
|
|
172
|
+
"subagents.effort": { labels: { ...SAME_MAIN, ...cap(["low", "medium", "high"]) } },
|
|
173
|
+
"subagents.planner": { labels: { ...SAME_ABOVE, ...MODELS }, help: "Same as above uses the Stage model" },
|
|
174
|
+
"subagents.builder": { labels: { ...SAME_ABOVE, ...MODELS }, help: "Also runs the fix rounds. Same as above uses the Stage model" },
|
|
175
|
+
"subagents.reviewer": { labels: { ...SAME_ABOVE, ...MODELS }, help: "Also runs the rechecks. Same as above uses the Stage model" },
|
|
176
|
+
"auto_fix.min_severity": { labels: cap(["critical", "high", "medium", "low"]) },
|
|
177
|
+
"auto_guard.stop_on": { labels: cap(["critical", "high", "medium", "low", "off"]) },
|
|
178
|
+
"orchestration.permissions": { labels: { own: "Normal prompts", bypass: "Skip all prompts" }, help: "Normal prompts: each agent asks as it usually does. Skip all prompts: no worker ever asks, so be sure." },
|
|
179
|
+
"agent.keep_awake": { labels: cap(["off", "auto", "on"]), help: "Auto: while kaizen runs agents. On: while kaizen is open. Linux and macOS" },
|
|
180
|
+
"sources.every": { labels: { off: "Off", "1h": "1h", "6h": "6h", "24h": "24h" } },
|
|
181
|
+
"sources.effort": { labels: cap(["low", "medium", "high"]) },
|
|
182
|
+
};
|
|
183
|
+
for (const s of SETTINGS) Object.assign(s, PLAIN[s.key] ?? {});
|
|
184
|
+
// An option as the screen shows it.
|
|
185
|
+
export const optionLabel = (s: Pick<Setting, "labels">, v: string) => s.labels?.[v] ?? v;
|
|
186
|
+
|
|
156
187
|
// The same rows and the same write the TUI uses, for `kaizen web`'s settings panel:
|
|
157
188
|
// one place decides what a setting is called, what it may be, and how it is saved.
|
|
158
189
|
// `project`: undefined resolves from the cwd as the TUI does; null is All projects
|
|
@@ -182,7 +213,8 @@ export function listSettings(repoRoot: string, project?: string | null) {
|
|
|
182
213
|
// Why a row has no effect right now, or "" while it has one: its `when` is not met.
|
|
183
214
|
function idle(s: Setting, valueOf: (key: string) => string | null) {
|
|
184
215
|
if (!s.when || valueOf(s.when[0]) === s.when[1]) return "";
|
|
185
|
-
|
|
216
|
+
const w = SETTINGS.find((x) => x.key === s.when![0])!;
|
|
217
|
+
return `No effect unless ${w.label} is ${s.when[1] === "true" ? "on" : optionLabel(w, s.when[1])}`;
|
|
186
218
|
}
|
|
187
219
|
|
|
188
220
|
export function setSetting(repoRoot: string, key: string, value: string, project?: string | null) {
|
|
@@ -284,7 +316,7 @@ export async function settings(repoRoot: string, standalone = true) {
|
|
|
284
316
|
const at = s.values.indexOf(v);
|
|
285
317
|
return at < 0 ? v : "▮".repeat(at + 1) + "▯".repeat(s.values.length - at - 1) + " " + v;
|
|
286
318
|
}
|
|
287
|
-
return v;
|
|
319
|
+
return optionLabel(s, v);
|
|
288
320
|
};
|
|
289
321
|
const valueOf = (k: string) => {
|
|
290
322
|
const d = SETTINGS.find((x) => x.key === k)!;
|
package/cli/sources.ts
CHANGED
|
@@ -4,16 +4,20 @@
|
|
|
4
4
|
// Nothing in this file launches anything.
|
|
5
5
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
|
+
import { homedir } from "node:os";
|
|
7
8
|
import { isIP } from "node:net";
|
|
8
9
|
import { createHash } from "node:crypto";
|
|
9
10
|
import { lookup as dnsLookup } from "node:dns/promises";
|
|
10
|
-
import { readInbox, writeInbox, normalise, formatNote, parseItem, readRuns, readText } from "./state.ts";
|
|
11
|
+
import { home, readInbox, writeInbox, normalise, formatNote, parseItem, readRuns, readText } from "./state.ts";
|
|
11
12
|
|
|
12
13
|
export type Last = { at: string; ok: boolean; added: number; note: string };
|
|
13
14
|
export type Source = { url: string; label?: string; category?: string; added: string; last?: Last; seen: string[]; writeback?: boolean; paused?: boolean };
|
|
14
15
|
export type Result = { url: string } & Last;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
// Home's icebox (the global ~/.kaizen) lives in its own folder inside the Home workspace, ~/.kaizen/home/icebox;
|
|
18
|
+
// a project's sits in its .kaizen. Its sources, items and collections all go there.
|
|
19
|
+
export const iceDir = (state: string) => state === join(homedir(), ".kaizen") || state === join(home, ".kaizen") ? join(state, "home", "icebox") : state;
|
|
20
|
+
const file = (state: string) => join(iceDir(state), "sources.json");
|
|
17
21
|
|
|
18
22
|
// Absent is an empty list. A file that is there and does not parse throws, so no
|
|
19
23
|
// caller ever writes a fresh list over one a person may want to repair.
|
|
@@ -26,7 +30,7 @@ export function readSources(state: string): Source[] {
|
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
export function writeSources(state: string, list: Source[]) {
|
|
29
|
-
mkdirSync(state, { recursive: true });
|
|
33
|
+
mkdirSync(iceDir(state), { recursive: true });
|
|
30
34
|
writeFileSync(file(state), JSON.stringify(list, null, 2) + "\n");
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -161,10 +165,10 @@ function clean(raw: string, extra = ""): { text: string; lines: string[] } | nul
|
|
|
161
165
|
export type IceKind = "client" | "finding" | "people";
|
|
162
166
|
export const KINDS: Record<IceKind, string> = { client: "Client", finding: "Finding", people: "People say" };
|
|
163
167
|
export type Sorted = "me" | "agent" | "ai" | "rules";
|
|
164
|
-
export type Link = { url: string; title?: string; summary?: string };
|
|
168
|
+
export type Link = { url: string; title?: string; summary?: string; image?: string };
|
|
165
169
|
export type Signal = { id: string; text: string; notes?: string; source: string; category?: string; at: string; status: "new" | "promoted" | "dismissed" | "done"; idea?: string; replied?: string; images?: string[]; row?: number; run?: string; written?: string; writeError?: string; kind?: IceKind; sorted?: Sorted; board?: string; tags?: string[]; snoozed?: string; link?: Link };
|
|
166
170
|
|
|
167
|
-
const iceFile = (state: string) => join(state, "icebox.json");
|
|
171
|
+
const iceFile = (state: string) => join(iceDir(state), "icebox.json");
|
|
168
172
|
|
|
169
173
|
export function readIcebox(state: string): Signal[] {
|
|
170
174
|
if (!existsSync(iceFile(state))) return [];
|
|
@@ -175,7 +179,7 @@ export function readIcebox(state: string): Signal[] {
|
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
export function writeIcebox(state: string, list: Signal[]) {
|
|
178
|
-
mkdirSync(state, { recursive: true });
|
|
182
|
+
mkdirSync(iceDir(state), { recursive: true });
|
|
179
183
|
writeFileSync(iceFile(state), JSON.stringify(list, null, 2) + "\n");
|
|
180
184
|
}
|
|
181
185
|
|
|
@@ -283,9 +287,14 @@ function addRow(state: string, text: string, notes: string, extra: Partial<Signa
|
|
|
283
287
|
function ruleKind(source: string, onClientBoard: boolean): IceKind {
|
|
284
288
|
return onClientBoard ? "client" : socialOf(source) ? "people" : source !== "manual" ? "client" : "finding";
|
|
285
289
|
}
|
|
290
|
+
// Your own capture that is a link and nothing else.
|
|
291
|
+
const bareLink = (s: Pick<Signal, "source" | "text">) => s.source === "manual" && s.text.trim() === linkIn(s.text);
|
|
286
292
|
// The kind to show. A stored kind someone chose wins; a rule's kind is worked out again,
|
|
287
293
|
// so moving an item onto a client's board changes it.
|
|
288
294
|
export function kindOf(s: Signal, boards: Board[]): IceKind {
|
|
295
|
+
// A link the owner dropped in alone is a Finding even when an AI sorted it before that rule existed; only a person
|
|
296
|
+
// or an agent picking another kind changes it.
|
|
297
|
+
if (s.sorted === "ai" && bareLink(s)) return "finding";
|
|
289
298
|
if (s.kind && s.kind in KINDS && s.sorted !== "rules") return s.kind;
|
|
290
299
|
return ruleKind(s.source, !!s.board && boards.some((b) => b.client && same(b.name, s.board!)));
|
|
291
300
|
}
|
|
@@ -293,7 +302,7 @@ export function kindOf(s: Signal, boards: Board[]): IceKind {
|
|
|
293
302
|
// Boards: where items belong (a client, a topic). A client's board makes its items Client.
|
|
294
303
|
// boards.json is a list of { name, client? }; absent is none.
|
|
295
304
|
export type Board = { name: string; client?: true };
|
|
296
|
-
const boardsFile = (state: string) => join(state, "boards.json");
|
|
305
|
+
const boardsFile = (state: string) => join(iceDir(state), "boards.json");
|
|
297
306
|
const same = (a: string, b: string) => a.toLowerCase() === b.toLowerCase();
|
|
298
307
|
export function readBoards(state: string): Board[] {
|
|
299
308
|
if (!existsSync(boardsFile(state))) return [];
|
|
@@ -302,7 +311,7 @@ export function readBoards(state: string): Board[] {
|
|
|
302
311
|
if (!Array.isArray(list)) throw new Error("boards.json is unreadable");
|
|
303
312
|
return list.filter((b) => b && typeof b.name === "string").map((b) => ({ name: b.name, ...(b.client === true ? { client: true as const } : {}) }));
|
|
304
313
|
}
|
|
305
|
-
const writeBoards = (state: string, list: Board[]) => { mkdirSync(state, { recursive: true }); writeFileSync(boardsFile(state), JSON.stringify(list, null, 2) + "\n"); };
|
|
314
|
+
const writeBoards = (state: string, list: Board[]) => { mkdirSync(iceDir(state), { recursive: true }); writeFileSync(boardsFile(state), JSON.stringify(list, null, 2) + "\n"); };
|
|
306
315
|
// A board name as stored, or why not.
|
|
307
316
|
function boardName(raw: string): { name: string } | { why: string } {
|
|
308
317
|
const name = oneLine(raw);
|
|
@@ -329,7 +338,11 @@ export function removeBoard(state: string, raw: string): string | null {
|
|
|
329
338
|
const list = readBoards(state);
|
|
330
339
|
const b = list.find((x) => same(x.name, oneLine(raw)));
|
|
331
340
|
if (!b) return "no such collection";
|
|
332
|
-
|
|
341
|
+
// Its items go back to the Inbox: a removed collection never takes requests with it.
|
|
342
|
+
const ice = readIcebox(state);
|
|
343
|
+
let moved = false;
|
|
344
|
+
for (const s of ice) if (s.board && same(s.board, b.name)) { delete s.board; moved = true; }
|
|
345
|
+
if (moved) writeIcebox(state, ice);
|
|
333
346
|
writeBoards(state, list.filter((x) => x !== b));
|
|
334
347
|
return null;
|
|
335
348
|
}
|
|
@@ -351,7 +364,8 @@ export function applySort(state: string, id: string, kind: string, tags: string[
|
|
|
351
364
|
const s = ice.find((x) => x.id === id);
|
|
352
365
|
if (!s || (s.sorted ?? "rules") !== "rules") return false;
|
|
353
366
|
const t = cleanTags([...(s.tags ?? []), ...tags]);
|
|
354
|
-
|
|
367
|
+
// A link the owner dropped in alone is something they found: the AI still tags it, but never calls it People say.
|
|
368
|
+
s.kind = bareLink(s) ? "finding" : kind as IceKind;
|
|
355
369
|
s.sorted = "ai";
|
|
356
370
|
if (!("why" in t) && t.tags.length) s.tags = t.tags.slice(0, 8);
|
|
357
371
|
writeIcebox(state, ice);
|
|
@@ -863,23 +877,73 @@ export const due = (s: Source, everyMs: number, now: number) => !s.last || now -
|
|
|
863
877
|
// The first http(s) link in a capture, if any.
|
|
864
878
|
export const linkIn = (text: string) => /https?:\/\/[^\s<>"'`)\]]+/i.exec(text)?.[0]?.replace(/[.,;:!?]+$/, "") ?? null;
|
|
865
879
|
const entities = (s: string) => s.replace(/&#(\d+);/g, (_, n) => String.fromCodePoint(Number(n))).replace(/&#x([\da-f]+);/gi, (_, n) => String.fromCodePoint(parseInt(n, 16))).replace(/"/g, '"').replace(/'|'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/ /g, " ").replace(/&/g, "&");
|
|
880
|
+
// A page's own <meta> tags, by name or property: the preview a site writes for sharing.
|
|
881
|
+
const meta = (html: string, key: string) => {
|
|
882
|
+
for (const tag of html.match(/<meta\b[^>]*>/gi) ?? []) {
|
|
883
|
+
if (new RegExp(`(?:property|name)\\s*=\\s*["']${key}["']`, "i").test(tag)) {
|
|
884
|
+
const c = /content\s*=\s*(?:"([^"]*)"|'([^']*)')/i.exec(tag);
|
|
885
|
+
if (c) return oneLine(entities(c[1] ?? c[2] ?? ""));
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return "";
|
|
889
|
+
};
|
|
890
|
+
// A block page says so in its title; keep nothing from it.
|
|
891
|
+
const BLOCKED = /^(blocked|access denied|just a moment|attention required|are you a robot|403 forbidden)/i;
|
|
892
|
+
// The preview picture a page names, https only, as an absolute address.
|
|
893
|
+
const imageOf = (html: string, base: string) => {
|
|
894
|
+
const raw = meta(html, "og:image:secure_url") || meta(html, "og:image") || meta(html, "twitter:image");
|
|
895
|
+
if (!raw) return "";
|
|
896
|
+
try { const u = new URL(raw, base); return u.protocol === "https:" && u.href.length <= 2000 ? u.href : ""; } catch { return ""; }
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
// Reddit answers a server's fetch with a block page, but every post has a public preview picture at an address built
|
|
900
|
+
// from its id, and its title is in the link's own slug. Null for any other link.
|
|
901
|
+
export function redditPost(url: string): { title: string; image: string } | null {
|
|
902
|
+
const m = /^https:\/\/(?:(?:www|old|new|m)\.)?reddit\.com\/r\/([\w-]+)\/comments\/([a-z0-9]+)(?:\/([^/?#]+))?/i.exec(url);
|
|
903
|
+
if (!m) return null;
|
|
904
|
+
const slug = (m[3] ?? "").replace(/_/g, " ").trim();
|
|
905
|
+
return { title: slug ? `${slug} · r/${m[1]}` : `r/${m[1]}`, image: `https://share.redd.it/preview/post/${m[2]!.toLowerCase()}` };
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// What the kaizen browser read from a link's page afterwards: its first own picture becomes the card's picture,
|
|
909
|
+
// and a better title than a generic one. An item someone removed meanwhile is left alone. Returns whether it wrote.
|
|
910
|
+
export function setLinkMedia(state: string, id: string, m: { title?: string; images: string[] }): boolean {
|
|
911
|
+
const ice = readIcebox(state), s = ice.find((x) => x.id === id);
|
|
912
|
+
const images = pics(m.images);
|
|
913
|
+
if (!s?.link || (!images.length && !m.title)) return false;
|
|
914
|
+
if (images.length) s.link.image = images[0];
|
|
915
|
+
const generic = !s.link.title || /^reddit$/i.test(s.link.title) || s.link.title === redditPost(s.link.url)?.title;
|
|
916
|
+
if (m.title && generic) s.link.title = oneLine(m.title).slice(0, 200);
|
|
917
|
+
writeIcebox(state, ice);
|
|
918
|
+
return true;
|
|
919
|
+
}
|
|
920
|
+
|
|
866
921
|
// What a link is: Firecrawl's title and summary with the user's key, else the page's own
|
|
867
|
-
// <title> through fetchText's guard (public https only, no credentials).
|
|
868
|
-
// a link that cannot be read is kept bare.
|
|
922
|
+
// <title> through fetchText's guard (public https only, no credentials). The page's preview
|
|
923
|
+
// picture (og:image) comes from that same read. Never throws: a link that cannot be read is kept bare.
|
|
869
924
|
export async function readLink(url: string, doFetch?: Fetch, lookup?: Lookup): Promise<Link> {
|
|
925
|
+
let title = "", summary = "", image = "";
|
|
926
|
+
try {
|
|
927
|
+
const r = await fetchText(url, doFetch, lookup, "html");
|
|
928
|
+
if (r.ok) {
|
|
929
|
+
const t = oneLine(entities(/<title\b[^>]*>([\s\S]*?)<\/title>/i.exec(r.body)?.[1] ?? "")).slice(0, 200);
|
|
930
|
+
if (!BLOCKED.test(t)) {
|
|
931
|
+
title = (meta(r.body, "og:title") || t).slice(0, 200);
|
|
932
|
+
summary = meta(r.body, "og:description").slice(0, 1000);
|
|
933
|
+
image = imageOf(r.body, url);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
} catch { /* kept bare */ }
|
|
870
937
|
const { apiKey, scrape } = await import("./research.ts");
|
|
871
938
|
if (apiKey()) {
|
|
872
939
|
try {
|
|
873
940
|
const p = await scrape(url, { formats: ["summary"], timeout: 30_000 });
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
} catch { /* fall through to the page title */ }
|
|
941
|
+
title = oneLine(p.title).slice(0, 200) || title; summary = oneLine(p.summary ?? "").slice(0, 1000) || summary;
|
|
942
|
+
} catch { /* keep the page's own */ }
|
|
877
943
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
return t ? { url, title: t } : { url };
|
|
882
|
-
} catch { return { url }; }
|
|
944
|
+
const rd = redditPost(url);
|
|
945
|
+
if (rd) { image ||= rd.image; if (!title || /^reddit$/i.test(title)) title = rd.title; }
|
|
946
|
+
return { url, ...(title ? { title } : {}), ...(summary ? { summary } : {}), ...(image ? { image } : {}) };
|
|
883
947
|
}
|
|
884
948
|
|
|
885
949
|
// Your own capture, from the board, the terminal or an agent: text, notes, and what you
|