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.
Files changed (51) hide show
  1. package/cli/hermes.ts +20 -0
  2. package/cli/install.ts +20 -1
  3. package/cli/localsend.ts +61 -4
  4. package/cli/report.ts +7 -4
  5. package/cli/settings.ts +2 -8
  6. package/cli/state.ts +19 -3
  7. package/cli/task-results.ts +133 -0
  8. package/cli/task-service.ts +179 -0
  9. package/cli/tasks.ts +201 -0
  10. package/cli/ui-audit.allow.json +6 -0
  11. package/cli/ui-audit.ts +427 -0
  12. package/cli/web.ts +72 -1
  13. package/cli/whatsapp.ts +112 -0
  14. package/package.json +2 -1
  15. package/skills/kaizen/SKILL.md +4 -0
  16. package/skills/kaizen/adapters.md +4 -0
  17. package/skills/kaizen/spec-build.md +5 -1
  18. package/skills/kaizen/spec-main.md +4 -0
  19. package/skills/kaizen/spec-plan.md +4 -0
  20. package/skills/kaizen/spec-review.md +4 -0
  21. package/skills/kaizen/spec.md +52 -0
  22. package/web/board/add-project.ts +1 -1
  23. package/web/board/badge.ts +70 -8
  24. package/web/board/cards.ts +12 -4
  25. package/web/board/dom.ts +10 -0
  26. package/web/board/icebox.ts +2 -2
  27. package/web/board/keys.ts +1 -1
  28. package/web/board/live.ts +9 -5
  29. package/web/board/phone.ts +4 -3
  30. package/web/board/rich.ts +4 -2
  31. package/web/board/run-view.ts +16 -14
  32. package/web/board/settings-automations.ts +2 -2
  33. package/web/board/settings-skills.ts +2 -2
  34. package/web/board/settings.ts +12 -14
  35. package/web/board/task-page.ts +590 -0
  36. package/web/board/task-results.ts +232 -0
  37. package/web/board/tasks.ts +216 -200
  38. package/web/board/terms.ts +17 -2
  39. package/web/board/views.ts +35 -9
  40. package/web/board/whatsapp-setup.ts +137 -0
  41. package/web/board/workspace.ts +25 -2
  42. package/web/board/zoom.ts +90 -0
  43. package/web/board.html +139 -40
  44. package/web/board.js +355 -141
  45. package/web/notebook.js +367 -153
  46. package/web/notes.html +16 -11
  47. package/web/term.js +1 -1
  48. package/web/video.html +22 -11
  49. package/web/video.js +401 -187
  50. package/web/video.ts +5 -5
  51. package/web/board/new-agent.ts +0 -20
@@ -0,0 +1,232 @@
1
+ // Typed task outputs. Only server-issued artifact routes are embedded; live URLs are
2
+ // separate, mutable references and active HTML/SVG files remain downloads.
3
+ import { html, raw, type Safe } from "./dom.ts";
4
+
5
+ export type TaskArtifact = {
6
+ id: string;
7
+ name: string;
8
+ kind: string;
9
+ mediaType?: string;
10
+ preview?: string | boolean;
11
+ url?: string;
12
+ size?: number;
13
+ missing?: boolean;
14
+ source?: string;
15
+ };
16
+ export type TaskResult = {
17
+ id: string;
18
+ title?: string;
19
+ summary?: string;
20
+ createdAt?: number | string;
21
+ artifacts: TaskArtifact[];
22
+ checks?: (string | { label?: string; outcome?: string; evidence?: string })[];
23
+ limitations?: string[];
24
+ liveUrl?: string;
25
+ storedSize?: number;
26
+ size?: number;
27
+ };
28
+ export const webUrl = (value: unknown) => {
29
+ try {
30
+ const u = new URL(String(value));
31
+ return ["http:", "https:"].includes(u.protocol) && !u.username && !u.password ? u.href : null;
32
+ } catch {
33
+ return null;
34
+ }
35
+ };
36
+ export const storedUrl = (value: unknown) =>
37
+ typeof value === "string" && /^\/task-artifact(?:\?|\/)/.test(value) && !value.includes("\\") && !/[\r\n]/.test(value)
38
+ ? value
39
+ : null;
40
+ export const sizeLabel = (n?: number) =>
41
+ n == null
42
+ ? ""
43
+ : n < 1024
44
+ ? `${n} B`
45
+ : n < 1024 * 1024
46
+ ? `${(n / 1024).toFixed(1)} KB`
47
+ : `${(n / (1024 * 1024)).toFixed(1)} MB`;
48
+ const isImage = (a: TaskArtifact) => /^image\//.test(a.mediaType ?? "") || a.kind === "image" || a.kind === "screenshot";
49
+ export function artifactView(a: TaskArtifact, selected = false): Safe {
50
+ const url = storedUrl(a.url),
51
+ live = a.kind === "website" || a.kind === "app" || a.kind === "link" || a.kind === "live";
52
+ const href = live ? webUrl(a.url) : url;
53
+ const active =
54
+ /^(?:text\/(?:html|javascript|xml)|application\/(?:javascript|xml|xhtml\+xml)|image\/svg\+xml)(?:;|$)/i.test(
55
+ a.mediaType ?? "",
56
+ ) || /\.(html?|svg|m?js|xml)$/i.test(a.name);
57
+ let view: Safe | string = "";
58
+ if (a.missing || !href)
59
+ view = html`<p class="tp-limit">
60
+ ${a.missing ? "This saved file is unavailable." : "No preview is available for this output."} Ask for the file
61
+ again or inspect the technical details.
62
+ </p>`;
63
+ else if (selected && live)
64
+ view = html`<p class="tp-limit">Live preview — this address can change during later work.</p>
65
+ <iframe
66
+ class="tp-web"
67
+ data-live-url="${href}"
68
+ title="Live preview of ${a.name}"
69
+ sandbox="allow-forms allow-scripts allow-popups"
70
+ referrerpolicy="no-referrer"
71
+ ></iframe>
72
+ <p class="dim" data-live-status>Checking preview availability… You can also use Open link.</p>`;
73
+ else if (selected && !active && a.preview !== false && a.preview !== "download" && a.preview !== "none") {
74
+ if (/^image\//.test(a.mediaType ?? "") || a.kind === "image" || a.kind === "screenshot")
75
+ view = html`<div class="tp-zoom" aria-label="${a.name}. Pinch, scroll or double-click to zoom.">
76
+ <img class="tp-image" src="${href}" alt="${a.name}" loading="lazy" draggable="false" />
77
+ <div class="tp-zoom-ctl"><button type="button" class="ib" data-zoom-out aria-label="Zoom out">−</button><button type="button" class="ib" data-zoom-reset aria-label="Reset zoom">100%</button><button type="button" class="ib" data-zoom-in aria-label="Zoom in">+</button></div>
78
+ </div>`;
79
+ else if (/^video\//.test(a.mediaType ?? "") || a.kind === "video")
80
+ view = html`<video class="tp-media" controls preload="metadata" src="${href}">
81
+ Download this video to watch it.
82
+ </video>`;
83
+ else if (/^audio\//.test(a.mediaType ?? "") || a.kind === "audio")
84
+ view = html`<audio class="tp-media" controls preload="metadata" src="${href}">
85
+ Download this audio to listen.
86
+ </audio>`;
87
+ else if (a.mediaType === "application/pdf" || a.kind === "pdf")
88
+ view = html`<iframe class="tp-document" src="${href}" title="${a.name}" sandbox></iframe>
89
+ <p class="dim">Your browser may need you to download this PDF.</p>`;
90
+ else if (/^text\//.test(a.mediaType ?? "") || ["text", "markdown", "document"].includes(a.kind))
91
+ view = html`<pre class="tp-text" data-text-artifact="${href}" aria-label="${a.name}">Loading saved text…</pre>`;
92
+ else view = html`<p class="dim">Preview is unavailable for this format. Download to open it in your app.</p>`;
93
+ } else if (selected && active)
94
+ view = html`<p class="dim">
95
+ Download this file to open it. Executable files are kept separate from this task page.
96
+ </p>`;
97
+ return html`<section class="tp-artifact">
98
+ <div class="tp-artifact-head">
99
+ <span
100
+ >${a.name}<small
101
+ >${live ? "Live link · mutable" : "Saved file"}${a.size != null ? " · " + sizeLabel(a.size) : ""}</small
102
+ ></span
103
+ >${href ? html`<a class="btn" href="${live ? href : href + (href.includes("?") ? "&" : "?") + "download=1"}" target="_blank" rel="noopener noreferrer" ${live ? "" : raw(` download`)}>${live ? "Open link" : "Download"}</a>` : ""}
104
+ </div>
105
+ ${view}
106
+ </section>`;
107
+ }
108
+ export function resultView(result: TaskResult | undefined, artifactId?: string): Safe {
109
+ if (!result)
110
+ return html`<div class="tp-result-empty">
111
+ <h3>Your result will appear here</h3>
112
+ <p>Answer any questions in the conversation. You will confirm a short proposal before production starts.</p>
113
+ </div>`;
114
+ const artifacts = result.artifacts ?? [],
115
+ selected = artifacts.find((a) => a.id === artifactId) ?? artifacts[0];
116
+ const legacy = !result.title || result.title === "Existing result";
117
+ return html`<header class="tp-result-heading">
118
+ ${legacy ? "" : html`<h2>${result.title}</h2>`}
119
+ ${result.summary && !legacy ? html`<p>${result.summary}</p>` : ""}
120
+ </header>
121
+ <div class="tp-split${artifacts.length > 1 ? " has-rail" : ""}">${artifacts.length > 1 ? html`<nav class="tp-rail" role="group" aria-label="Outputs">${artifacts.map((a) => html`<button class="tp-file" type="button" data-artifact="${a.id}" aria-pressed="${String(a.id === selected?.id)}">${isImage(a) ? html`<img src="${storedUrl(a.url)}" alt="" loading="lazy" draggable="false" />` : html`<i>${(a.name.split(".").pop() || "file").slice(0, 4)}</i>`}<span>${a.name}</span></button>`)}</nav>` : ""}<div class="tp-stage">${selected ? artifactView(selected, true) : html`<p class="tp-limit">No saved file was published for this result.</p>`}${result.liveUrl && !artifacts.some((a) => a.url === result.liveUrl) && webUrl(result.liveUrl) ? artifactView({ id: "live", name: "Live website", kind: "website", url: result.liveUrl }, true) : ""}</div></div>`;
122
+ }
123
+ export const savedLine = (r?: TaskResult) =>
124
+ r?.createdAt ? `Saved ${new Date(r.createdAt).toLocaleString()}${(r.storedSize ?? r.size) != null ? " · " + sizeLabel(r.storedSize ?? r.size) + " preserved" : ""}` : "";
125
+ export function checksView(result: TaskResult | undefined): Safe {
126
+ if (!result) return html``;
127
+ return html`<details class="tp-checks"><summary>Checks and limits</summary>
128
+ ${result.checks?.length ? html`<ul>${result.checks.map((c) => html`<li>${typeof c === "string" ? c : [c.label, c.outcome, c.evidence].filter(Boolean).join(" — ")}</li>`)}</ul>` : ""}
129
+ ${result.limitations?.length ? html`<ul>${result.limitations.map((l) => html`<li>${l}</li>`)}</ul>` : ""}
130
+ <p class="dim">Accepting a result does not publish it. A preview alone does not prove that a backend works.</p>
131
+ </details>`;
132
+ }
133
+ export async function loadTextArtifacts(box: HTMLElement) {
134
+ await Promise.all(
135
+ [...box.querySelectorAll<HTMLElement>("[data-text-artifact]")].map(async (el) => {
136
+ try {
137
+ const r = await fetch(el.dataset.textArtifact!);
138
+ if (!r.ok) throw new Error();
139
+ const value = await r.text();
140
+ if (el.isConnected)
141
+ el.textContent =
142
+ value.length > 1_000_000
143
+ ? value.slice(0, 1_000_000) + "\nPreview shortened. Download for the whole file."
144
+ : value;
145
+ } catch {
146
+ if (el.isConnected) el.textContent = "The saved file could not be read. Try Download or refresh the task.";
147
+ }
148
+ }),
149
+ );
150
+ }
151
+
152
+ // The workspace already checks frame headers and exposes local development ports
153
+ // for remote devices. Task previews use those same services, with an opaque sandbox.
154
+ export async function loadLiveArtifacts(box: HTMLElement) {
155
+ await Promise.all(
156
+ [...box.querySelectorAll<HTMLIFrameElement>("iframe[data-live-url]")].map(async (frame) => {
157
+ if (frame.dataset.checked) return;
158
+ frame.dataset.checked = "1";
159
+ const original = webUrl(frame.dataset.liveUrl),
160
+ section = frame.closest(".tp-artifact")!;
161
+ const note = section.querySelector<HTMLElement>("[data-live-status]")!,
162
+ link = section.querySelector<HTMLAnchorElement>("a")!;
163
+ if (!original) {
164
+ frame.hidden = true;
165
+ note.textContent = "The preview address is unavailable.";
166
+ return;
167
+ }
168
+ let url = original;
169
+ try {
170
+ const response = await fetch("/frameable?url=" + encodeURIComponent(original));
171
+ const check = await response.json();
172
+ if (!frame.isConnected) return;
173
+ if (check.frameable === false) {
174
+ frame.hidden = true;
175
+ note.textContent = "This site refuses to appear inside kaizen. Use Open link to view it in another tab.";
176
+ return;
177
+ }
178
+ } catch {
179
+ note.textContent = "Preview availability could not be checked. Use Open link if it does not appear.";
180
+ }
181
+ const local = /^(localhost|127\.0\.0\.1|\[::1\])$/;
182
+ if (local.test(new URL(original).hostname) && !local.test(location.hostname)) {
183
+ frame.hidden = true;
184
+ note.textContent = "Opening this computer’s preview for this device…";
185
+ try {
186
+ const response = await fetch("/expose", {
187
+ method: "POST",
188
+ headers: { "content-type": "application/json" },
189
+ body: JSON.stringify({ url: original }),
190
+ });
191
+ const exposed = await response.json();
192
+ if (!frame.isConnected) return;
193
+ const available = exposed.ok && webUrl(exposed.url);
194
+ if (!available) {
195
+ note.textContent =
196
+ "This preview is on the computer running kaizen and could not be opened for this device. Open the task on that computer.";
197
+ link.textContent = "Open on computer";
198
+ return;
199
+ }
200
+ url = available;
201
+ link.href = url;
202
+ note.textContent = exposed.hint || "Live preview. This address can change during later work.";
203
+ } catch {
204
+ note.textContent =
205
+ "The preview could not be opened for this device. Open the task on the computer running kaizen.";
206
+ link.textContent = "Open on computer";
207
+ return;
208
+ }
209
+ }
210
+ if (!frame.isConnected) return;
211
+ frame.hidden = false;
212
+ frame.src = url;
213
+ frame.addEventListener(
214
+ "load",
215
+ () => {
216
+ if (note.textContent?.startsWith("Checking"))
217
+ note.textContent =
218
+ "Live preview. If it does not appear, use Open link. Some apps require their own browser tab.";
219
+ },
220
+ { once: true },
221
+ );
222
+ frame.addEventListener(
223
+ "error",
224
+ () => {
225
+ frame.hidden = true;
226
+ note.textContent = "The live preview could not be opened. Use Open link or ask for a saved screenshot.";
227
+ },
228
+ { once: true },
229
+ );
230
+ }),
231
+ );
232
+ }