kaizen-agent 1.83.0 → 1.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/accounts.ts +1 -1
- package/cli/add-project.ts +1 -1
- package/cli/phone-setup.ts +1 -1
- package/cli/state.ts +22 -0
- package/cli/ui-audit.ts +1 -1
- package/cli/web.ts +31 -10
- package/package.json +1 -1
- package/web/annotate.js +22 -13
- package/web/board/annotate-lib.ts +4 -0
- package/web/board/annotate.ts +34 -16
- package/web/board/home-ws.ts +254 -0
- package/web/board/main.ts +2 -0
- package/web/board/onboarding.ts +1 -1
- package/web/board/phone-setup.ts +1 -1
- package/web/board/run-view.ts +40 -14
- package/web/board/search.ts +1 -1
- package/web/board/settings-accounts.ts +1 -1
- package/web/board/settings-automations.ts +1 -1
- package/web/board/settings-cleanup.ts +1 -1
- package/web/board/settings-pages.ts +33 -24
- package/web/board/settings.ts +31 -40
- package/web/board/views.ts +1 -1
- package/web/board/whatsapp-setup.ts +1 -1
- package/web/board/workspace.ts +89 -8
- package/web/board/ws-tabs.ts +15 -0
- package/web/board.html +62 -30
- package/web/board.js +214 -210
- package/web/notebook.js +169 -165
- package/web/notes.html +3 -1
- package/web/term.js +56 -56
- package/web/term.ts +63 -13
- package/web/video.html +3 -1
- package/web/video.js +255 -251
package/cli/accounts.ts
CHANGED
|
@@ -146,7 +146,7 @@ export function resolveAccount(cmd: string, wanted?: string, win = process.platf
|
|
|
146
146
|
const a = readAccounts(), id = wanted ?? a.default[cmd];
|
|
147
147
|
if (!id) return {};
|
|
148
148
|
const account = a.accounts.find((x) => x.id === id && x.tool === cmd);
|
|
149
|
-
if (!account) return { error: "That account no longer exists. Pick another in Settings → AI
|
|
149
|
+
if (!account) return { error: "That account no longer exists. Pick another in Settings → AI Accounts." };
|
|
150
150
|
if (win) return { error: "Accounts aren't supported on Windows yet." };
|
|
151
151
|
const dir = accountDir(id);
|
|
152
152
|
if (!existsSync(dir)) return { error: `The folder for ${account.name} is missing.` };
|
package/cli/add-project.ts
CHANGED
|
@@ -60,7 +60,7 @@ export function destDir(raw: unknown, home: string, known: string[] = [], projec
|
|
|
60
60
|
if (low === kz || low.startsWith(kz + sep) || parts.includes(".git") || parts.includes(".kaizen")) return { error: "that folder is kaizen's or git's own" };
|
|
61
61
|
if (winBad(basename(dir))) return { error: `${basename(dir)} cannot be a folder name on Windows` };
|
|
62
62
|
const under = (r: string) => !!r && (dir === canonPath(r) || dir.startsWith(canonPath(r) + sep));
|
|
63
|
-
if (!under(h) && !under(projects)) return { error: "choose a folder inside your home, or set Settings → Projects folder (board.projects_dir) to allow another place" };
|
|
63
|
+
if (!under(h) && !under(projects)) return { error: "choose a folder inside your home, or set Settings → General → Folders → Projects folder (board.projects_dir) to allow another place" };
|
|
64
64
|
const proj = projects ? canonPath(projects) : "";
|
|
65
65
|
for (let a = dirname(dir); ; a = dirname(a)) {
|
|
66
66
|
if (known.includes(a)) return { error: `that folder is inside the project ${a}` };
|
package/cli/phone-setup.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Settings →
|
|
1
|
+
// Settings → Phone and the onboarding phone step: what `kaizen setup` does for the phone,
|
|
2
2
|
// as board routes. GET says where this computer stands, POST connects or logs in.
|
|
3
3
|
import { qrMatrix } from "./qr.ts";
|
|
4
4
|
import { addWebHost, webHosts } from "./state.ts";
|
package/cli/state.ts
CHANGED
|
@@ -423,6 +423,28 @@ export function remember(projectDir: string) {
|
|
|
423
423
|
} catch { /* nothing here is worth an error */ }
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
+
// The sidebar's drag-and-drop rank: `first` (project folders, in the new order) go to the top of
|
|
427
|
+
// the registry, every other line keeps its place after them. Only folders already registered move,
|
|
428
|
+
// nothing is added or dropped, comment lines stay on top; written to a temp file and renamed so a
|
|
429
|
+
// reader never sees half a list. Returns the new order (knownProjects()).
|
|
430
|
+
export function reorderProjects(first: string[]): string[] {
|
|
431
|
+
if (!existsSync(REGISTRY)) return [];
|
|
432
|
+
const lines = readText(REGISTRY).split("\n").map((l) => l.trim()).filter(Boolean);
|
|
433
|
+
const notes = lines.filter((l) => l.startsWith("#")), rows = lines.filter((l) => !l.startsWith("#")).map((l) => ({ l, c: canonPath(l) }));
|
|
434
|
+
const want = first.map(canonPath).filter((d, i, all) => all.indexOf(d) === i);
|
|
435
|
+
const moved = want.flatMap((d) => rows.filter((r) => r.c === d));
|
|
436
|
+
const rest = rows.filter((r) => !moved.includes(r));
|
|
437
|
+
const tmp = `${REGISTRY}.${process.pid}.tmp`;
|
|
438
|
+
writeFileSync(tmp, [...notes, ...[...moved, ...rest].map((r) => r.l)].join("\n") + "\n");
|
|
439
|
+
// A project remember()ed since the read above would be lost by the rename: read again right
|
|
440
|
+
// before it and carry any new line over.
|
|
441
|
+
const seen = new Set(rows.map((r) => r.c));
|
|
442
|
+
const late = readText(REGISTRY).split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("#") && !seen.has(canonPath(l)));
|
|
443
|
+
if (late.length) appendFileSync(tmp, late.join("\n") + "\n");
|
|
444
|
+
renameSync(tmp, REGISTRY);
|
|
445
|
+
return knownProjects();
|
|
446
|
+
}
|
|
447
|
+
|
|
426
448
|
export const SKIP = new Set([
|
|
427
449
|
"windows", "program files", "program files (x86)", "programdata", "$recycle.bin",
|
|
428
450
|
"system volume information", "appdata", "node_modules", "recovery", "perflogs",
|
package/cli/ui-audit.ts
CHANGED
|
@@ -279,7 +279,7 @@ export async function settle(page: Page, ms = 6000) {
|
|
|
279
279
|
// ---- screens and states. `open` runs in the page after load: click() waits for a shown element, then clicks it.
|
|
280
280
|
type Screen = { name: string; url: string; widths?: number[]; open?: string };
|
|
281
281
|
const BARS = [[".rail .top", ".hdr", "#rbar", "#panel>header", ".pstrip"], ["#sback", "#smain h2"]];
|
|
282
|
-
const SETTINGS = ["
|
|
282
|
+
const SETTINGS = ["general", "appearance", "notifications", "keyboard", "terminal", "agents", "models", "accounts", "skills", "runs", "approvals", "autofix", "orchestration", "automations", "git", "integrations", "mobile"];
|
|
283
283
|
|
|
284
284
|
function screens(dir: string, run: string, emptyWs: { dir: string; ws: string }): Screen[] {
|
|
285
285
|
const D = encodeURIComponent(dir);
|
package/cli/web.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { awakeHolder, wantAwake } from "./keep-awake.ts";
|
|
|
5
5
|
import { existsSync, readdirSync, readlinkSync, statSync, lstatSync, realpathSync, readFileSync, watch, appendFileSync, mkdirSync, cpSync, rmSync, writeFileSync, type FSWatcher } from "node:fs";
|
|
6
6
|
import { join, dirname, resolve, sep, basename } from "node:path";
|
|
7
7
|
import {
|
|
8
|
-
home, type Item, type Card, knownProjects, remember, canonPath, locate, label, tilde, searchRoots, findProjects,
|
|
8
|
+
home, type Item, type Card, knownProjects, remember, reorderProjects, canonPath, locate, label, tilde, searchRoots, findProjects,
|
|
9
9
|
readInbox, writeInbox, replaceTask, moveTask, abandonRun, runToTask, launchRun, parseItem, agentChoices, onPath, projectOf, KNOWN_AGENTS, plainModel, short, setArchived, writeNotes,
|
|
10
10
|
appendNote, saveAttachment, pidOnPort, readText, cmdExe, sysExe, powershellExe, runGit, readCommit, commitPush, commitStaged, stageFiles, suggestMessage, notice, notifier, LOGO,
|
|
11
11
|
reviewFindings, pickFindings, backlogItem, startedBacklog, closeBacklog, markBacklogDone, fixPrompt, approvalPrompt, canApproveAwaiting, gateOf, recordAcceptance, healRuns, finishRun, nativePath, closeSessions, sweepSessions, issueUrl,
|
|
@@ -358,6 +358,8 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
358
358
|
// Shells the board started (POST /shell), by /pty key; dead ones drop on the next /shells.
|
|
359
359
|
const shells = new Map<string, { key: string; dir: string; title: string; agent: string; run: string; ws?: string; pid?: number }>();
|
|
360
360
|
const SHELL_CAP = 8;
|
|
361
|
+
// The floating Home workspace's folder: kaizen's own, never a project, so agents start before one is chosen.
|
|
362
|
+
const HOME_WS = join(home, ".kaizen", "home");
|
|
361
363
|
// The argv each of those started with, kept off the page's copy: saveLive writes it so the next board can start them again.
|
|
362
364
|
const shellCmd = new Map<string, string[]>();
|
|
363
365
|
// A terminal shows where its live run builds, not where it launched: tabs follow `run`, the rail `ws`.
|
|
@@ -1003,8 +1005,12 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
1003
1005
|
if (!ptySupported) return bad("terminals need a newer Bun", 501);
|
|
1004
1006
|
let body: any;
|
|
1005
1007
|
try { body = await req.json(); } catch { return bad("json body expected"); }
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
+
// Home: kaizen's own folder, the one place outside a project. No worktree, dev server or run to resume there.
|
|
1009
|
+
const homeWs = body.home === true;
|
|
1010
|
+
if (homeWs && (body.ws != null || body.dev === true || body.resume === true)) return bad("not in the Home workspace", 400);
|
|
1011
|
+
const dir = homeWs ? HOME_WS : canonState(String(body.dir ?? ""));
|
|
1012
|
+
if (!homeWs && (!states(true).includes(dir) || dir === join(home, ".kaizen"))) return bad("choose a project", 404);
|
|
1013
|
+
if (homeWs) mkdirSync(HOME_WS, { recursive: true });
|
|
1008
1014
|
let cmd: string[];
|
|
1009
1015
|
let agent = "";
|
|
1010
1016
|
let bypass = false;
|
|
@@ -1012,7 +1018,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
1012
1018
|
// id is read from that run's state.json, never taken from the page). Claude only: it is
|
|
1013
1019
|
// the agent whose session id runs record. Refused while that session is still running
|
|
1014
1020
|
// elsewhere, since two copies of one conversation overwrite each other's history.
|
|
1015
|
-
const runKey = typeof body.run === "string" && body.run.length <= 2000 ? body.run : "";
|
|
1021
|
+
const runKey = homeWs ? "home" : typeof body.run === "string" && body.run.length <= 2000 && body.run !== "home" ? body.run : "";
|
|
1016
1022
|
if (body.resume === true) {
|
|
1017
1023
|
const id = runKey.startsWith("run:" + dir + ":") ? runKey.slice(dir.length + 5) : "";
|
|
1018
1024
|
let st: any = {};
|
|
@@ -1052,7 +1058,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
1052
1058
|
cmd = acct.dir ? ["env", ...accountEnv(acct), ...line] : line;
|
|
1053
1059
|
} else cmd = process.platform === "win32" ? [powershellExe()] : [process.env.SHELL || "sh", "-l"];
|
|
1054
1060
|
// A workspace folder: only an exact path from this project's own `git worktree list`.
|
|
1055
|
-
let cwd = projectOf(dir);
|
|
1061
|
+
let cwd = homeWs ? HOME_WS : projectOf(dir);
|
|
1056
1062
|
if (body.ws != null) {
|
|
1057
1063
|
// A miss rechecks past a cache older than 1 s: a worktree made since is real, and a
|
|
1058
1064
|
// burst of bad paths runs git at most once a second.
|
|
@@ -1073,7 +1079,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
1073
1079
|
dev = true;
|
|
1074
1080
|
}
|
|
1075
1081
|
for (const k of shells.keys()) if (!ptyState(k)?.alive) shells.delete(k);
|
|
1076
|
-
if ([...shells.values()].filter((x) => x.dir === dir).length >= SHELL_CAP) return bad(`at most ${SHELL_CAP} terminals per project: close one first`, 429);
|
|
1082
|
+
if ([...shells.values()].filter((x) => x.dir === dir).length >= SHELL_CAP) return bad(`at most ${SHELL_CAP} terminals per ${homeWs ? "workspace" : "project"}: close one first`, 429);
|
|
1077
1083
|
const key = "sh-" + crypto.randomUUID().slice(0, 8);
|
|
1078
1084
|
const title = dev ? "dev server" : agent ? KNOWN_AGENTS.find((k) => k.cmd === agent)!.name + (bypass ? " · bypass" : "") : "shell";
|
|
1079
1085
|
// A dev server it starts lets a phone in: Vite refuses a host it does not know (the tailnet name).
|
|
@@ -1093,6 +1099,20 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
1093
1099
|
// The rail's + on a project: a new worktree and branch under <project>/.kaizen/wt/.
|
|
1094
1100
|
// Runs git, so /shell's guards; the branch name is checked by git check-ref-format
|
|
1095
1101
|
// and every call is an argv array.
|
|
1102
|
+
// The sidebar's drag-and-drop rank: {dirs: state dirs, top first}. Only projects the board
|
|
1103
|
+
// already knows move (the registry is never added to here); same guards as /worktree.
|
|
1104
|
+
if (req.method === "POST" && path === "/projects/order") {
|
|
1105
|
+
const refused = strict(req);
|
|
1106
|
+
if (refused) return refused;
|
|
1107
|
+
let body: any;
|
|
1108
|
+
try { body = await req.json(); } catch { return bad("json body expected"); }
|
|
1109
|
+
if (!Array.isArray(body.dirs) || body.dirs.length > 500) return bad("dirs: a list of projects expected");
|
|
1110
|
+
const known = states(true);
|
|
1111
|
+
const dirs = body.dirs.map((d: unknown) => canonState(String(d))).filter((d: string) => known.includes(d) && d !== join(home, ".kaizen"));
|
|
1112
|
+
reorderProjects(dirs.map((d: string) => dirname(d)));
|
|
1113
|
+
changed();
|
|
1114
|
+
return json({ ok: true });
|
|
1115
|
+
}
|
|
1096
1116
|
if (req.method === "POST" && path === "/worktree") {
|
|
1097
1117
|
const refused = strict(req);
|
|
1098
1118
|
if (refused) return refused;
|
|
@@ -1349,7 +1369,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
1349
1369
|
}
|
|
1350
1370
|
return json(usageCache);
|
|
1351
1371
|
}
|
|
1352
|
-
// Settings →
|
|
1372
|
+
// Settings → Phone and the onboarding phone step: where Tailscale stands, connect, log in.
|
|
1353
1373
|
if (path === "/phone/setup") {
|
|
1354
1374
|
if (!local(req)) return bad("cross-origin request refused", 403);
|
|
1355
1375
|
if (req.method === "GET") return json(await readPhone());
|
|
@@ -1362,7 +1382,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
1362
1382
|
if (body?.do === "login") return json(await loginUrl());
|
|
1363
1383
|
return bad("do: connect or login");
|
|
1364
1384
|
}
|
|
1365
|
-
// Settings →
|
|
1385
|
+
// Settings → Phone: WhatsApp bridge status and connect/disconnect.
|
|
1366
1386
|
if (path === "/whatsapp") {
|
|
1367
1387
|
if (!local(req)) return bad("cross-origin request refused", 403);
|
|
1368
1388
|
const wa = await import("./whatsapp.ts");
|
|
@@ -1679,7 +1699,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
1679
1699
|
return json({ accounts: rows, normal, windows: process.platform === "win32", ...(added ? { added } : {}) });
|
|
1680
1700
|
}
|
|
1681
1701
|
|
|
1682
|
-
// Settings → General →
|
|
1702
|
+
// Settings → General → Storage: what `kaizen prune` would remove from this page's project,
|
|
1683
1703
|
// one kind at a time. Deletion is decided here, on the current files, not on the page's counts.
|
|
1684
1704
|
if (path === "/cleanup" && (req.method === "GET" || req.method === "POST")) {
|
|
1685
1705
|
if (!state) return bad("no project", 404);
|
|
@@ -1814,6 +1834,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
1814
1834
|
}
|
|
1815
1835
|
|
|
1816
1836
|
if (req.method === "GET" && path === "/agents") {
|
|
1837
|
+
if (url.searchParams.get("home") === "1") return json(agentChoices(HOME_WS));
|
|
1817
1838
|
const dir = qdir();
|
|
1818
1839
|
if (!dir || !states(true).includes(dir)) return bad("unknown state dir", 404);
|
|
1819
1840
|
return json(agentChoices(projectOf(dir)));
|
|
@@ -2790,7 +2811,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
2790
2811
|
// The + menu's terminals and agents, unless a run's own resume above already brought that agent back.
|
|
2791
2812
|
for (const x of fresh ? saved.shells ?? [] : []) {
|
|
2792
2813
|
try {
|
|
2793
|
-
if (viaRun.has(x.key) || !states(true).includes(x.dir) || !existsSync(x.ws) || !Array.isArray(x.cmd) || !x.cmd.every((a) => typeof a === "string")) continue;
|
|
2814
|
+
if (viaRun.has(x.key) || !(states(true).includes(x.dir) || x.dir === HOME_WS) || !existsSync(x.ws) || !Array.isArray(x.cmd) || !x.cmd.every((a) => typeof a === "string")) continue;
|
|
2794
2815
|
const key = "sh-" + crypto.randomUUID().slice(0, 8);
|
|
2795
2816
|
const cmd = x.sid && /^[\w-]{8,80}$/.test(x.sid) && !x.cmd.includes("--resume") ? [...x.cmd, "--resume", x.sid] : x.cmd;
|
|
2796
2817
|
const pid = startPty(key, cmd, x.ws, undefined, changed, { env: { KAIZEN_TERM: key } });
|
package/package.json
CHANGED
package/web/annotate.js
CHANGED
|
@@ -4,13 +4,17 @@
|
|
|
4
4
|
// its own overlay (and Pause). It talks to the board only by postMessage, signed with the per-open
|
|
5
5
|
// token in its own URL; the board keeps the notes and decides what to do with them.
|
|
6
6
|
(() => {
|
|
7
|
-
|
|
7
|
+
// Framed by the board, or the desktop app's Browser tab (a <webview>, where the page has no parent
|
|
8
|
+
// and the app's preload sets __kzHost and relays the messages).
|
|
9
|
+
const hosted = window.parent !== window || window.__kzHost === true;
|
|
10
|
+
if (window.__kzAnnotate || !hosted) return;
|
|
8
11
|
window.__kzAnnotate = true;
|
|
9
12
|
const script = document.currentScript;
|
|
10
13
|
let token = "";
|
|
11
14
|
try { token = new URL(script.src).searchParams.get("t") || ""; } catch {}
|
|
12
15
|
const parent = window.parent;
|
|
13
|
-
|
|
16
|
+
// `out` marks what the page says, so the webview's relay forwards it and not what the board sends.
|
|
17
|
+
const send = (m) => parent.postMessage({ kz: 1, t: token, out: 1, ...m }, "*");
|
|
14
18
|
|
|
15
19
|
const cfg = { on: false, mode: "element", hide: false, block: true, color: "#3c82f7", components: true };
|
|
16
20
|
let marks = []; // notes the board has: { n, kind, selector, items, pb, page }
|
|
@@ -111,18 +115,22 @@
|
|
|
111
115
|
.b{position:fixed;pointer-events:none;border:2px solid var(--c);background:color-mix(in srgb,var(--c) 14%,transparent);border-radius:2px}
|
|
112
116
|
.b.g{--c:#34c759}.b.sel{border-style:dashed}
|
|
113
117
|
.l{position:fixed;pointer-events:none;background:var(--c);color:#fff;padding:1px 6px;border-radius:3px;white-space:nowrap;max-width:60vw;overflow:hidden;text-overflow:ellipsis}
|
|
114
|
-
.m{position:fixed;width:22px;height:22px;margin:-11px 0 0 -11px;border-radius:50%;background:var(--c);color:#fff;font-weight:600;display:grid;place-items:center;pointer-events:auto;cursor:pointer;box-shadow:0 1px 4px #0006}
|
|
118
|
+
.m{position:fixed;width:22px;height:22px;margin:-11px 0 0 -11px;border-radius:50%;background:var(--c);color:#fff;font-weight:600;border:2px solid #fff;display:grid;place-items:center;pointer-events:auto;cursor:pointer;box-shadow:0 1px 4px #0006}
|
|
115
119
|
.m.g{background:#34c759}
|
|
116
|
-
.c{position:fixed;width:
|
|
117
|
-
.c code{display:block;color:#98989f;margin-bottom:
|
|
118
|
-
.c textarea{width:100%;height:
|
|
119
|
-
.c
|
|
120
|
-
.c
|
|
121
|
-
.c
|
|
122
|
-
.c button
|
|
123
|
-
.
|
|
120
|
+
.c{position:fixed;width:320px;background:#1c1c1e;color:#f2f2f7;border:1px solid #2c2c2e;border-radius:14px;padding:12px;pointer-events:auto;box-shadow:0 12px 36px #000a}
|
|
121
|
+
.c code{display:block;font:12px/1.4 system-ui,sans-serif;color:#98989f;margin-bottom:8px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
122
|
+
.c textarea{display:block;width:100%;height:68px;resize:none;background:#262628;color:inherit;border:1px solid #3a3a3c;border-radius:9px;padding:8px 10px;outline:0}
|
|
123
|
+
.c textarea:focus{border-color:#5a5a5e}
|
|
124
|
+
.c .r{display:flex;gap:6px;margin-top:10px;align-items:center;min-width:0}
|
|
125
|
+
.c select{flex:none;width:76px;background:none;color:#98989f;border:1px solid #3a3a3c;border-radius:999px;padding:3px 4px;font-size:11px;text-overflow:ellipsis}
|
|
126
|
+
.c button{flex:none;background:none;color:#98989f;border:0;border-radius:999px;padding:6px 8px;cursor:pointer}
|
|
127
|
+
.c button:hover{color:#f2f2f7}
|
|
128
|
+
.c button.go,.p button{background:#f59e0b;color:#1c1c1e;font-weight:600;padding:6px 14px}
|
|
129
|
+
.c button.go:hover,.p button:hover{background:#fbb02d;color:#1c1c1e}
|
|
130
|
+
.p button{border:0;border-radius:999px;cursor:pointer;padding:5px 14px}
|
|
131
|
+
.t{position:fixed;width:260px;background:#1c1c1e;color:#f2f2f7;border:1px solid #2c2c2e;border-radius:12px;padding:8px 12px;pointer-events:none;box-shadow:0 8px 28px #0008;white-space:pre-wrap;word-break:break-word}
|
|
124
132
|
.t small{display:block;color:#98989f;margin-top:4px}
|
|
125
|
-
.p{position:fixed;left:50%;bottom:18px;transform:translateX(-50%);background:#1c1c1e;color:#f2f2f7;border:1px solid #
|
|
133
|
+
.p{position:fixed;left:50%;bottom:18px;transform:translateX(-50%);background:#1c1c1e;color:#f2f2f7;border:1px solid #2c2c2e;border-radius:999px;padding:6px 8px 6px 16px;pointer-events:auto;display:flex;gap:8px;align-items:center}
|
|
126
134
|
</style><div id="o"></div>`;
|
|
127
135
|
const layer = root.getElementById("o");
|
|
128
136
|
layer.style.setProperty("--c", cfg.color);
|
|
@@ -288,7 +296,8 @@
|
|
|
288
296
|
const inHost = (e) => e.composedPath && e.composedPath().includes(host);
|
|
289
297
|
const target = (x, y) => { const e = document.elementFromPoint(x, y); return e && e !== host && e !== document.documentElement ? e : null; };
|
|
290
298
|
const rectFor = (els) => union(els.map((e) => e.getBoundingClientRect()));
|
|
291
|
-
const
|
|
299
|
+
const quoted = (e) => { const t = textOf(e).replace(/\s+/g, " ").trim(); return t ? `"${t.slice(0, 60)}${t.length > 60 ? "…" : ""}"` : describe(e); };
|
|
300
|
+
const pickElement = (e) => openComposer({ kind: "element", els: [e], rect: rectFor([e]), label: quoted(e) });
|
|
292
301
|
function commitMulti() { if (!multi.length) return; const els = multi.slice(); openComposer({ kind: "multi", els, rect: rectFor(els), label: `${els.length} elements` }); }
|
|
293
302
|
function areaItems(r) {
|
|
294
303
|
const out = [];
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
export const accept = (e: { source: unknown; origin: string; data: any }, frameWin: unknown, origin: string, token: string) =>
|
|
5
5
|
!!origin && e.source === frameWin && e.origin === origin && !!e.data && e.data.kz === 1 && e.data.t === token;
|
|
6
6
|
|
|
7
|
+
// The desktop app's Browser tab is a <webview>: the page's messages arrive over its IPC channel, from
|
|
8
|
+
// that element only, so the token is all there is to check.
|
|
9
|
+
export const acceptHost = (d: any, token: string) => !!d && d.kz === 1 && d.t === token && !!token;
|
|
10
|
+
|
|
7
11
|
// The page reports its address on the proxy; the board shows the app's own. Anything not on the proxy's
|
|
8
12
|
// origin (a javascript: or data: URL, another site) is null: the page is untrusted and must not set the board's address.
|
|
9
13
|
export const mapUrl = (href: string, origin: string, target: string): string | null => {
|
package/web/board/annotate.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
import { html, raw } from "./dom.ts";
|
|
7
7
|
import { post } from "./api.ts";
|
|
8
8
|
import { toast } from "./toast.ts";
|
|
9
|
-
import {
|
|
9
|
+
import { ico } from "./dom.ts";
|
|
10
|
+
import { accept, acceptHost, mapUrl, safeCrop, MAX_BOARD_NOTES } from "./annotate-lib.ts";
|
|
10
11
|
|
|
11
12
|
type Note = Record<string, any> & { id: string; n: number };
|
|
12
13
|
type Settings = { mode: string; level: string; components: boolean; color: string; clear: boolean; block: boolean };
|
|
@@ -26,11 +27,11 @@ export type Annotator = {
|
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
export function annotator(o: {
|
|
29
|
-
host: HTMLElement; frame: HTMLIFrameElement; wsKey: string; run: () => { dir: string; id: string } | null; onLocation: (u: string) => void; reload: () => void; button: HTMLElement;
|
|
30
|
+
host: HTMLElement; frame: HTMLIFrameElement | HTMLElement; wsKey: string; run: () => { dir: string; id: string } | null; onLocation: (u: string) => void; reload: () => void; button: HTMLElement;
|
|
30
31
|
}): Annotator {
|
|
31
32
|
const sk = "kz-annotate", nk = "kz-ann:" + o.wsKey;
|
|
32
33
|
const S: Settings = read(sk, DEFAULTS);
|
|
33
|
-
let on = false, hide = false, pause = false,
|
|
34
|
+
let on = false, hide = false, pause = false, want = false, listOpen = false;
|
|
34
35
|
let px: { origin: string; token: string; target: string } | null = null;
|
|
35
36
|
let notes: Note[] = [];
|
|
36
37
|
try { notes = JSON.parse(localStorage.getItem(nk) || "[]"); } catch { /* none */ }
|
|
@@ -42,11 +43,18 @@ export function annotator(o: {
|
|
|
42
43
|
const side = document.createElement("div");
|
|
43
44
|
side.className = "annlist";
|
|
44
45
|
side.hidden = true;
|
|
45
|
-
|
|
46
|
-
o.frame.parentElement
|
|
46
|
+
// Both float over the page (board.html .annrow): a dark pill bottom-right, a notes panel on the right.
|
|
47
|
+
const rowEl = o.frame.parentElement!;
|
|
48
|
+
rowEl.append(side, bar);
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
+
// The Browser tab is an iframe, or in the desktop app a <webview> (talks over IPC, not postMessage).
|
|
51
|
+
const web = o.frame.tagName === "WEBVIEW" ? (o.frame as any) : null;
|
|
52
|
+
const frameWin = () => (o.frame as HTMLIFrameElement).contentWindow;
|
|
53
|
+
const say = (m: Record<string, unknown>) => {
|
|
54
|
+
if (!px) return;
|
|
55
|
+
const msg = { kz: 1, t: px.token, ...m };
|
|
56
|
+
if (web) { try { web.send("kz-ann", msg); } catch { /* not loaded yet: the page says ready when it is */ } } else frameWin()?.postMessage(msg, px.origin);
|
|
57
|
+
};
|
|
50
58
|
const cfg = () => ({ on, mode: S.mode, hide, block: S.block, color: S.color, components: S.components });
|
|
51
59
|
const markers = () => notes.map((n) => ({ n: n.n, kind: n.kind, selector: n.selector, items: n.items, pb: n.pb, page: n.page, comment: n.comment, intent: n.intent, severity: n.severity }));
|
|
52
60
|
const push = () => { say({ type: "config", cfg: { ...cfg(), pause } }); say({ type: "markers", list: markers() }); };
|
|
@@ -54,13 +62,18 @@ export function annotator(o: {
|
|
|
54
62
|
const forServer = () => notes.map((n) => ({ ...n }));
|
|
55
63
|
|
|
56
64
|
function draw() {
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
const show = !!px;
|
|
66
|
+
bar.hidden = !show;
|
|
67
|
+
side.hidden = !show || !listOpen;
|
|
68
|
+
rowEl.classList.toggle("lst", show && listOpen);
|
|
59
69
|
o.button.classList.toggle("on", want);
|
|
60
70
|
if (!px) return;
|
|
61
|
-
|
|
71
|
+
// Icon buttons in one dark pill, as in Agentation: modes, then pause, markers, copy, send, clear, notes, settings, close.
|
|
72
|
+
const b = (id: string, icon: string, title: string, active = false, disabled = false, badge = 0) =>
|
|
73
|
+
html`<button type="button" data-a="${id}" title="${title}" aria-label="${title}" class="${active ? "on" : ""}"${raw(disabled ? " disabled" : "")}>${ico(icon)}${badge ? html`<i class="cnt">${badge}</i>` : ""}</button>`;
|
|
74
|
+
const mode = (id: string, icon: string, t: string) => b("mode:" + id, icon, t, on && S.mode === id);
|
|
62
75
|
bar.textContent = "";
|
|
63
|
-
bar.insertAdjacentHTML("beforeend", String(html`${
|
|
76
|
+
bar.insertAdjacentHTML("beforeend", String(html`${mode("element", "a-pick", "Pick an element")}${mode("text", "a-text", "Select text")}${mode("multi", "a-multi", "Pick several elements")}${mode("area", "a-area", "Drag an area")}<span class="sep"></span>${b("pause", "a-pause", "Freeze animations (P)", pause)}${b("hide", "eye", "Show or hide markers (H)", !hide)}${b("copy", "a-copy", "Copy notes as markdown (C)", false, !notes.length)}${b("send", "send", "Type the notes into this run's agent (S)", false, !notes.length)}${b("clear", "trash", "Remove all notes (X)", false, !notes.length)}<span class="sep"></span>${b("list", "note", "Notes list", listOpen, false, notes.length)}${b("set", "gear", "Output detail, colour, behaviour", !!settings)}${b("off", "x", "Close the annotator (the Annotate button brings it back)")}`));
|
|
64
77
|
side.textContent = "";
|
|
65
78
|
if (!notes.length) side.insertAdjacentHTML("beforeend", String(html`<p class="annempty">No notes yet. Pick something on the page and write what should change.</p>`));
|
|
66
79
|
for (const n of notes) {
|
|
@@ -97,15 +110,16 @@ export function annotator(o: {
|
|
|
97
110
|
function setMode(m: string) { S.mode = m; on = true; write(sk, S); push(); draw(); }
|
|
98
111
|
|
|
99
112
|
const act = (a: string) => {
|
|
100
|
-
if (a.startsWith("mode:")) return setMode(a.slice(5));
|
|
113
|
+
if (a.startsWith("mode:")) return on && S.mode === a.slice(5) ? (on = false, push(), draw()) : setMode(a.slice(5));
|
|
101
114
|
if (a === "pick") { on = !on; push(); draw(); }
|
|
102
115
|
else if (a === "pause") { pause = !pause; push(); draw(); }
|
|
103
116
|
else if (a === "hide") { hide = !hide; push(); draw(); }
|
|
104
117
|
else if (a === "copy") void copy();
|
|
105
118
|
else if (a === "send") void sendNotes();
|
|
106
119
|
else if (a === "clear") clear();
|
|
107
|
-
else if (a === "
|
|
108
|
-
else if (a === "
|
|
120
|
+
else if (a === "list") { listOpen = !listOpen; draw(); }
|
|
121
|
+
else if (a === "set") { settings = settings ? null : document.createElement("div"); if (settings) { settings.className = "annset"; listOpen = true; } drawSettings(); draw(); }
|
|
122
|
+
else if (a === "off") { want = false; on = false; pause = false; listOpen = false; px = null; draw(); o.reload(); }
|
|
109
123
|
};
|
|
110
124
|
bar.onclick = (e) => { const a = (e.target as Element).closest<HTMLElement>("[data-a]")?.dataset.a; if (a) act(a); };
|
|
111
125
|
side.onclick = (e) => {
|
|
@@ -147,7 +161,10 @@ export function annotator(o: {
|
|
|
147
161
|
const onMsg = (e: MessageEvent) => {
|
|
148
162
|
if (!px || !o.host.isConnected) return;
|
|
149
163
|
if (!accept(e, frameWin(), px.origin, px.token)) return;
|
|
150
|
-
|
|
164
|
+
handle(e.data);
|
|
165
|
+
};
|
|
166
|
+
const handle = (d: any) => {
|
|
167
|
+
if (!px) return;
|
|
151
168
|
if (d.type === "ready") { on = true; push(); draw(); }
|
|
152
169
|
else if (d.type === "loc") { const u = mapUrl(String(d.href), px.origin, px.target); if (u) o.onLocation(u); }
|
|
153
170
|
else if (d.type === "key") keyAct(String(d.key));
|
|
@@ -163,12 +180,13 @@ export function annotator(o: {
|
|
|
163
180
|
}
|
|
164
181
|
};
|
|
165
182
|
addEventListener("message", onMsg);
|
|
183
|
+
web?.addEventListener("ipc-message", (e: any) => { if (px && o.host.isConnected && e.channel === "kz-ann" && acceptHost(e.args?.[0], px.token)) handle(e.args[0]); });
|
|
166
184
|
|
|
167
185
|
return {
|
|
168
186
|
proxied: () => !!px,
|
|
169
187
|
active: () => on,
|
|
170
188
|
async open(u) {
|
|
171
|
-
if (!want ||
|
|
189
|
+
if (!want || !/^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(:|\/|$)/.test(u)) { px = null; on = false; pause = false; draw(); return null; }
|
|
172
190
|
const r = await post("/annotate/open", { url: u });
|
|
173
191
|
if (!r?.ok) { want = false; px = null; draw(); return null; }
|
|
174
192
|
px = { origin: r.origin, token: r.token, target: new URL(u).origin };
|