kaizen-agent 1.79.1 → 1.81.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/hermes.ts +20 -0
- package/cli/install.ts +20 -1
- package/cli/localsend.ts +61 -4
- package/cli/report.ts +7 -4
- package/cli/settings.ts +2 -8
- package/cli/state.ts +19 -3
- package/cli/task-results.ts +133 -0
- package/cli/task-service.ts +179 -0
- package/cli/tasks.ts +201 -0
- package/cli/ui-audit.allow.json +6 -0
- package/cli/ui-audit.ts +427 -0
- package/cli/web.ts +72 -1
- package/cli/whatsapp.ts +112 -0
- package/package.json +2 -1
- package/skills/kaizen/SKILL.md +4 -0
- package/skills/kaizen/adapters.md +4 -0
- package/skills/kaizen/spec-build.md +5 -1
- package/skills/kaizen/spec-main.md +4 -0
- package/skills/kaizen/spec-plan.md +4 -0
- package/skills/kaizen/spec-review.md +4 -0
- package/skills/kaizen/spec.md +52 -0
- package/web/board/add-project.ts +1 -1
- package/web/board/badge.ts +70 -8
- package/web/board/cards.ts +12 -4
- package/web/board/dom.ts +10 -0
- package/web/board/icebox.ts +2 -2
- package/web/board/keys.ts +1 -1
- package/web/board/live.ts +9 -5
- package/web/board/phone.ts +4 -3
- package/web/board/rich.ts +4 -2
- package/web/board/run-view.ts +16 -14
- package/web/board/settings-automations.ts +2 -2
- package/web/board/settings-skills.ts +2 -2
- package/web/board/settings.ts +12 -14
- package/web/board/task-page.ts +590 -0
- package/web/board/task-results.ts +232 -0
- package/web/board/tasks.ts +216 -200
- package/web/board/terms.ts +17 -2
- package/web/board/views.ts +35 -9
- package/web/board/whatsapp-setup.ts +137 -0
- package/web/board/workspace.ts +25 -2
- package/web/board/zoom.ts +90 -0
- package/web/board.html +139 -40
- package/web/board.js +355 -141
- package/web/notebook.js +367 -153
- package/web/notes.html +16 -11
- package/web/term.js +1 -1
- package/web/video.html +22 -11
- package/web/video.js +401 -187
- package/web/video.ts +5 -5
- package/web/board/new-agent.ts +0 -20
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// The WhatsApp card: Settings → Mobile. Walks the user through linking WhatsApp Web,
|
|
2
|
+
// displaying a QR code that connects to the background Baileys bridge.
|
|
3
|
+
import { html, raw } from "./dom.ts";
|
|
4
|
+
|
|
5
|
+
type WAStatus = {
|
|
6
|
+
installed: boolean;
|
|
7
|
+
running: boolean;
|
|
8
|
+
connected: boolean;
|
|
9
|
+
user: string | null;
|
|
10
|
+
qrSvg: string | null;
|
|
11
|
+
error: string | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
async function callWA(body?: object) {
|
|
15
|
+
try {
|
|
16
|
+
const r = await fetch(
|
|
17
|
+
"/whatsapp",
|
|
18
|
+
body
|
|
19
|
+
? {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: { "content-type": "application/json" },
|
|
22
|
+
body: JSON.stringify(body),
|
|
23
|
+
}
|
|
24
|
+
: undefined
|
|
25
|
+
);
|
|
26
|
+
return await r.json();
|
|
27
|
+
} catch {
|
|
28
|
+
return { error: "The board did not answer." };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function mountWhatsApp(el: HTMLElement) {
|
|
33
|
+
let s: WAStatus | null = null,
|
|
34
|
+
err = "",
|
|
35
|
+
busy = false,
|
|
36
|
+
timer: any = null;
|
|
37
|
+
|
|
38
|
+
const draw = () => {
|
|
39
|
+
if (!s) return;
|
|
40
|
+
const e = err ? html`<p class="ph-err" role="alert">${err}</p>` : "";
|
|
41
|
+
if (s.connected) {
|
|
42
|
+
el.innerHTML = String(html`
|
|
43
|
+
<div class="ph-on">
|
|
44
|
+
<div>
|
|
45
|
+
<p class="ph-h">WhatsApp Bridge</p>
|
|
46
|
+
<p class="ph-st"><i class="ph-dot on"></i> Connected as <b>${s.user || "WhatsApp"}</b></p>
|
|
47
|
+
<p class="ph-note">Kaizen can send files and videos directly to your WhatsApp in the background.</p>
|
|
48
|
+
<div class="ph-row" style="margin-top:12px">
|
|
49
|
+
<button type="button" class="btn" data-wa="disconnect">${busy ? "Disconnecting…" : "Unlink WhatsApp"}</button>
|
|
50
|
+
</div>
|
|
51
|
+
${e}
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (s.qrSvg) {
|
|
59
|
+
el.innerHTML = String(html`
|
|
60
|
+
<div class="ph-on">
|
|
61
|
+
<div class="ph-qr" aria-label="WhatsApp QR code">${raw(s.qrSvg)}</div>
|
|
62
|
+
<div>
|
|
63
|
+
<p class="ph-h">Link WhatsApp</p>
|
|
64
|
+
<ol class="ph-steps">
|
|
65
|
+
<li>Open WhatsApp on your phone</li>
|
|
66
|
+
<li>Tap <b>Settings</b> or <b>⋮</b> > <b>Linked Devices</b></li>
|
|
67
|
+
<li>Tap <b>Link a Device</b> and scan this QR code</li>
|
|
68
|
+
</ol>
|
|
69
|
+
<div class="ph-row" style="margin-top:12px">
|
|
70
|
+
<button type="button" class="btn" data-wa="check">Refresh</button>
|
|
71
|
+
<button type="button" class="btn" data-wa="disconnect">Cancel</button>
|
|
72
|
+
</div>
|
|
73
|
+
${e}
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
el.innerHTML = String(html`
|
|
81
|
+
<div>
|
|
82
|
+
<p class="ph-h">WhatsApp Bridge</p>
|
|
83
|
+
<p>Send finished videos and files straight to your phone's WhatsApp without opening any app.</p>
|
|
84
|
+
<div class="ph-row" style="margin-top:12px">
|
|
85
|
+
<button type="button" class="btn pri" data-wa="connect">${busy ? "Starting…" : "Link WhatsApp"}</button>
|
|
86
|
+
</div>
|
|
87
|
+
${e}
|
|
88
|
+
</div>
|
|
89
|
+
`);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const load = async () => {
|
|
93
|
+
const r = await callWA();
|
|
94
|
+
if (r.error && !r.installed) err = r.error;
|
|
95
|
+
else s = r;
|
|
96
|
+
draw();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
el.innerHTML = `<p class="ph-wait">Checking WhatsApp…</p>`;
|
|
100
|
+
await load();
|
|
101
|
+
|
|
102
|
+
// Poll while waiting for connection or QR scan
|
|
103
|
+
const poll = async () => {
|
|
104
|
+
if (!el.isConnected) {
|
|
105
|
+
clearInterval(timer);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (s && !s.connected && (s.qrSvg || busy)) {
|
|
109
|
+
const r = await callWA();
|
|
110
|
+
if (!r.error) {
|
|
111
|
+
s = r;
|
|
112
|
+
draw();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
timer = setInterval(poll, 2500);
|
|
117
|
+
|
|
118
|
+
el.onclick = async (ev) => {
|
|
119
|
+
const a = (ev.target as HTMLElement).closest<HTMLElement>("[data-wa]")?.dataset.wa;
|
|
120
|
+
if (!a || busy) return;
|
|
121
|
+
err = "";
|
|
122
|
+
if (a === "check") return load();
|
|
123
|
+
busy = true;
|
|
124
|
+
draw();
|
|
125
|
+
if (a === "connect") {
|
|
126
|
+
const r = await callWA({ op: "connect" });
|
|
127
|
+
busy = false;
|
|
128
|
+
if (r.error) err = r.error;
|
|
129
|
+
else s = r;
|
|
130
|
+
draw();
|
|
131
|
+
} else if (a === "disconnect") {
|
|
132
|
+
await callWA({ op: "disconnect" });
|
|
133
|
+
busy = false;
|
|
134
|
+
await load();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
package/web/board/workspace.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// the Tasks entry's source icons and the Projects list; and the board's flat footer
|
|
3
3
|
// (agent usage, terminal count, phone). Stands alone, so the notebook and video
|
|
4
4
|
// bundles can carry it without the board.
|
|
5
|
-
import { onBoardCards } from "./badge.ts";
|
|
5
|
+
import { onBoardCards, attentionTasks, setTaskAttention, taskForCard } from "./badge.ts";
|
|
6
6
|
import { store } from "./store.ts";
|
|
7
7
|
import { $, html, modal, raw } from "./dom.ts";
|
|
8
8
|
import { initResources } from "./resources.ts";
|
|
@@ -15,6 +15,9 @@ const DAY = 864e5;
|
|
|
15
15
|
const STAGE = ["idea", "planning", "building", "reviewing", "done"];
|
|
16
16
|
// A card's state icon (.si) and the word under its title.
|
|
17
17
|
export function stateOf(c) {
|
|
18
|
+
const task = taskForCard(c);
|
|
19
|
+
// Only a task that is really working spins; a saved goal is idle, a finished run keeps its own state.
|
|
20
|
+
if (task && !(c.kind === "run" && (c.status === "done" || c.status === "abandoned") && task.attention.category !== "needs-you")) return task.attention.category === "needs-you" ? "wait" : task.attention.category === "completed" ? "done" : ["interrupted", "failed"].includes(task.status ?? "") ? "stalled" : task.status === "draft" ? "idle" : "build";
|
|
18
21
|
// A task whose agent is working is a run being born: show it as planning.
|
|
19
22
|
if (c.kind === "idea") return !c.pty?.alive ? "idle" : c.pty.asking ? "wait" : c.pty.busy ? "plan" : "idle";
|
|
20
23
|
if (c.status === "waiting" || (c.pty?.alive && c.pty.asking)) return "wait";
|
|
@@ -24,6 +27,8 @@ export function stateOf(c) {
|
|
|
24
27
|
return c.column >= 3 ? "review" : c.column === 2 ? "build" : "plan";
|
|
25
28
|
}
|
|
26
29
|
export function subline(c, now) {
|
|
30
|
+
const task = taskForCard(c);
|
|
31
|
+
if (task) return task.attention.reason + " · " + task.attention.action;
|
|
27
32
|
// An idle agent and no run yet: it answered, or waits for the user.
|
|
28
33
|
if (c.kind === "idea") return !c.pty?.alive ? "idea" : c.pty.asking ? "waiting on you" : c.pty.busy ? "planning · starting" : "agent · open";
|
|
29
34
|
const t = c.moved ?? now;
|
|
@@ -199,6 +204,15 @@ const PIN = html`<svg viewBox="0 0 24 24" aria-label="Pinned" style="width:12px;
|
|
|
199
204
|
const WT = html`<svg viewBox="0 0 24 24" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="6" cy="6" r="2"/><circle cx="6" cy="18" r="2"/><circle cx="18" cy="8" r="2"/><path d="M6 8v8M18 10c0 4-6 3-12 6"/></g></svg>`;
|
|
200
205
|
let settleT: ReturnType<typeof setTimeout> | undefined;
|
|
201
206
|
let drawn = "";
|
|
207
|
+
let tasksReadAt = 0, tasksReading = false;
|
|
208
|
+
async function readTaskAttention() {
|
|
209
|
+
if (tasksReading || Date.now() - tasksReadAt < 2000) return;
|
|
210
|
+
tasksReading = true; tasksReadAt = Date.now();
|
|
211
|
+
try { const r = await fetch("/tasks?all=1"); if (r.ok) { const body = await r.json(); setTaskAttention(body.tasks ?? []); } } catch { /* retain the latest persisted projection */ }
|
|
212
|
+
finally { tasksReading = false; }
|
|
213
|
+
}
|
|
214
|
+
const taskLinks = (dir: string, w: any, cards: any[]) => (attentionTasks ?? []).filter((t) => t.dir === dir && !t.legacy && t.attention.category !== "completed" && (cards.some((c) => taskForCard(c)?.id === t.id) || (w.main && !(t.runs ?? t.runIds ?? []).length))).sort((a: any, b: any) => (a.created ?? 0) - (b.created ?? 0)).map((t) => html`<a class="rtask" href="/?view=task&task=${encodeURIComponent(t.id)}&dir=${encodeURIComponent(t.dir)}" data-task-id="${t.id}" data-task-dir="${t.dir}" title="${t.attention.reason} · ${t.attention.action}"><span class="si ${t.attention.category === "needs-you" ? "wait" : t.attention.category === "completed" ? "done" : ["interrupted", "failed"].includes(t.status ?? "") ? "stalled" : t.status === "draft" ? "idle" : "build"}"></span><span><b>${t.title}</b><small>${t.attention.reason}</small></span></a>`);
|
|
215
|
+
|
|
202
216
|
export const wsLabel = (w) => w.branch || (w.main ? "workspace" : w.path.split(/[\\/]/).pop());
|
|
203
217
|
function drawList() {
|
|
204
218
|
const box = $("plist");
|
|
@@ -253,7 +267,7 @@ function drawList() {
|
|
|
253
267
|
const st0 = cs.length ? stateOf([...cs].sort((a, b) => RANK[stateOf(a)] - RANK[stateOf(b)])[0]) : "";
|
|
254
268
|
const st = st0 === "wait" || rows[0]?.st === "asking" ? "wait" : rows.some((r) => r.st === "working") ? "build" : st0 || (rows.length ? "done" : "");
|
|
255
269
|
// The agent buttons are siblings of the link (a button inside a link is invalid).
|
|
256
|
-
return html`<div class="wsr wsc"><a class="row ws" href="${wsHref(dir, w.path)}" data-dir="${dir}" data-ws="${w.path}" title="${w.path}"><span class="si ${st || "none"}"></span><div class="wl"><span class="l1"><b>${wsLabel(w)}</b>${pins.has(dir + "\0" + w.path) ? PIN : ""}</span><span class="l2"><span>${folderOf(w)}</span>${w.main ? "" : WT}</span></div></a>${agentsHtml(rows, now, !!wsOpen[dir + "\0" + w.path], dir, w.path)}</div
|
|
270
|
+
return html`<div class="wsr wsc"><a class="row ws" href="${wsHref(dir, w.path)}" data-dir="${dir}" data-ws="${w.path}" title="${w.path}"><span class="si ${st || "none"}"></span><div class="wl"><span class="l1"><b>${wsLabel(w)}</b>${pins.has(dir + "\0" + w.path) ? PIN : ""}</span><span class="l2"><span>${folderOf(w)}</span>${w.main ? "" : WT}</span></div></a>${agentsHtml(rows, now, !!wsOpen[dir + "\0" + w.path], dir, w.path)}</div>${taskLinks(dir, w, cs)}`;
|
|
257
271
|
})}${shut ? "" : raw("</div>")}`;
|
|
258
272
|
})
|
|
259
273
|
.join("") || `<div class="none">No projects</div>`;
|
|
@@ -266,6 +280,12 @@ function drawList() {
|
|
|
266
280
|
};
|
|
267
281
|
box.onclick = (e) => {
|
|
268
282
|
const t = e.target as HTMLElement;
|
|
283
|
+
const task = t.closest<HTMLElement>("[data-task-id]");
|
|
284
|
+
if (task) {
|
|
285
|
+
if (e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
286
|
+
if (ask("kz-open-task", { id: task.dataset.taskId, dir: task.dataset.taskDir })) e.preventDefault();
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
269
289
|
const term = t.closest<HTMLElement>("[data-term]");
|
|
270
290
|
if (term) return void (e.preventDefault(), openTerm(term.dataset.dir!, term.dataset.ws!, term.dataset.term!));
|
|
271
291
|
const tog = t.closest<HTMLElement>("[data-wopen]");
|
|
@@ -389,10 +409,13 @@ export function initRail() {
|
|
|
389
409
|
});
|
|
390
410
|
}).observe(document.body, { childList: true, subtree: true });
|
|
391
411
|
if (!$("plist")) return;
|
|
412
|
+
addEventListener("kz-task-attention", drawList);
|
|
413
|
+
void readTaskAttention();
|
|
392
414
|
onBoardCards((cards, projects, agents) => {
|
|
393
415
|
last = { cards, projects: projects ?? last.projects, agents: agents ?? [] };
|
|
394
416
|
drawList();
|
|
395
417
|
void drawSources();
|
|
418
|
+
void readTaskAttention();
|
|
396
419
|
onCount?.(cards);
|
|
397
420
|
dispatchEvent(new Event("kz-cards"));
|
|
398
421
|
told();
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Pinch, wheel, drag and double-click zoom for a task result image. One box, one image:
|
|
2
|
+
// the image fills the box (object-fit: contain) and a transform moves it.
|
|
3
|
+
const MIN = 1, MAX = 8;
|
|
4
|
+
|
|
5
|
+
export function wireZoom(root: ParentNode) {
|
|
6
|
+
root.querySelectorAll<HTMLElement>(".tp-zoom:not([data-zoom])").forEach((box) => {
|
|
7
|
+
const img = box.querySelector<HTMLElement>("img");
|
|
8
|
+
if (!img) return;
|
|
9
|
+
box.dataset.zoom = "1";
|
|
10
|
+
let s = 1, x = 0, y = 0;
|
|
11
|
+
const pts = new Map<number, { x: number; y: number }>();
|
|
12
|
+
let pinch = 0, moved = false;
|
|
13
|
+
const label = box.querySelector<HTMLElement>("[data-zoom-reset]");
|
|
14
|
+
const apply = () => {
|
|
15
|
+
const w = box.clientWidth, h = box.clientHeight;
|
|
16
|
+
x = Math.min(0, Math.max(w - w * s, x));
|
|
17
|
+
y = Math.min(0, Math.max(h - h * s, y));
|
|
18
|
+
img.style.transform = `translate(${x}px,${y}px) scale(${s})`;
|
|
19
|
+
box.classList.toggle("zoomed", s > 1.001);
|
|
20
|
+
if (label) label.textContent = Math.round(s * 100) + "%";
|
|
21
|
+
};
|
|
22
|
+
// Scale about a point in box coordinates, so what is under the fingers stays there.
|
|
23
|
+
const zoomAt = (px: number, py: number, next: number) => {
|
|
24
|
+
next = Math.min(MAX, Math.max(MIN, next));
|
|
25
|
+
x = px - ((px - x) * next) / s;
|
|
26
|
+
y = py - ((py - y) * next) / s;
|
|
27
|
+
s = next;
|
|
28
|
+
apply();
|
|
29
|
+
};
|
|
30
|
+
const local = (e: { clientX: number; clientY: number }) => {
|
|
31
|
+
const r = box.getBoundingClientRect();
|
|
32
|
+
return { x: e.clientX - r.left, y: e.clientY - r.top };
|
|
33
|
+
};
|
|
34
|
+
const centre = () => {
|
|
35
|
+
const [a, b] = [...pts.values()];
|
|
36
|
+
return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2, d: Math.hypot(a.x - b.x, a.y - b.y) };
|
|
37
|
+
};
|
|
38
|
+
box.addEventListener("wheel", (e) => {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
const p = local(e);
|
|
41
|
+
// A trackpad pinch arrives as a wheel with ctrlKey and small deltas.
|
|
42
|
+
zoomAt(p.x, p.y, s * Math.exp(-e.deltaY * (e.ctrlKey ? 0.01 : 0.0015)));
|
|
43
|
+
}, { passive: false });
|
|
44
|
+
box.addEventListener("pointerdown", (e) => {
|
|
45
|
+
if ((e.target as HTMLElement).closest("button")) return;
|
|
46
|
+
box.setPointerCapture(e.pointerId);
|
|
47
|
+
pts.set(e.pointerId, local(e));
|
|
48
|
+
moved = false;
|
|
49
|
+
if (pts.size === 2) pinch = centre().d;
|
|
50
|
+
});
|
|
51
|
+
box.addEventListener("pointermove", (e) => {
|
|
52
|
+
const prev = pts.get(e.pointerId);
|
|
53
|
+
if (!prev) return;
|
|
54
|
+
const now = local(e);
|
|
55
|
+
if (pts.size === 2) {
|
|
56
|
+
const before = centre();
|
|
57
|
+
pts.set(e.pointerId, now);
|
|
58
|
+
const after = centre();
|
|
59
|
+
x += after.x - before.x;
|
|
60
|
+
y += after.y - before.y;
|
|
61
|
+
if (pinch > 0) zoomAt(after.x, after.y, s * (after.d / pinch));
|
|
62
|
+
pinch = after.d;
|
|
63
|
+
moved = true;
|
|
64
|
+
} else if (s > 1) {
|
|
65
|
+
x += now.x - prev.x;
|
|
66
|
+
y += now.y - prev.y;
|
|
67
|
+
pts.set(e.pointerId, now);
|
|
68
|
+
moved = true;
|
|
69
|
+
apply();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const up = (e: PointerEvent) => {
|
|
73
|
+
pts.delete(e.pointerId);
|
|
74
|
+
pinch = 0;
|
|
75
|
+
};
|
|
76
|
+
box.addEventListener("pointerup", up);
|
|
77
|
+
box.addEventListener("pointercancel", up);
|
|
78
|
+
box.addEventListener("dblclick", (e) => {
|
|
79
|
+
if ((e.target as HTMLElement).closest("button") || moved) return;
|
|
80
|
+
const p = local(e);
|
|
81
|
+
if (s > 1) zoomAt(p.x, p.y, 1);
|
|
82
|
+
else zoomAt(p.x, p.y, 2.5);
|
|
83
|
+
});
|
|
84
|
+
box.querySelector("[data-zoom-in]")?.addEventListener("click", () => zoomAt(box.clientWidth / 2, box.clientHeight / 2, s * 1.5));
|
|
85
|
+
box.querySelector("[data-zoom-out]")?.addEventListener("click", () => zoomAt(box.clientWidth / 2, box.clientHeight / 2, s / 1.5));
|
|
86
|
+
label?.addEventListener("click", () => zoomAt(box.clientWidth / 2, box.clientHeight / 2, 1));
|
|
87
|
+
new ResizeObserver(apply).observe(box);
|
|
88
|
+
apply();
|
|
89
|
+
});
|
|
90
|
+
}
|