kaizen-agent 1.56.1 → 1.58.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/board.test.ts +56 -0
- package/cli/docs.test.ts +92 -0
- package/cli/docs.ts +84 -0
- package/cli/install.ts +13 -0
- package/cli/project-tree.test.ts +39 -0
- package/cli/pty.test.ts +1 -1
- package/cli/state.test.ts +18 -2
- package/cli/state.ts +21 -17
- package/cli/usage.test.ts +142 -0
- package/cli/usage.ts +66 -0
- package/cli/web.ts +196 -9
- package/package.json +1 -1
- package/skills/kaizen/SKILL.md +1 -1
- package/skills/kaizen/docs.md +6 -1
- package/skills/kaizen/spec-main.md +4 -2
- package/web/board/api.ts +2 -0
- package/web/board/badge.ts +41 -0
- package/web/board/cards.ts +80 -13
- package/web/board/context.ts +247 -0
- package/web/board/home.ts +3 -3
- package/web/board/ideas.ts +173 -0
- package/web/board/keys.ts +2 -5
- package/web/board/labels.ts +4 -0
- package/web/board/live.ts +3 -1
- package/web/board/main.ts +21 -0
- package/web/board/panel.ts +38 -12
- package/web/board/projects.ts +42 -2
- package/web/board/run-view.ts +700 -0
- package/web/board/settings.ts +1 -0
- package/web/board/store.ts +2 -0
- package/web/board/terms.ts +7 -3
- package/web/board/views.ts +21 -4
- package/web/board/workspace.ts +329 -0
- package/web/board.html +199 -35
- package/web/board.js +44 -41
- package/web/notebook.js +24 -23
- package/web/notebook.ts +7 -1
- package/web/notes.html +67 -21
- package/web/term.js +34 -34
- package/web/term.ts +10 -6
- package/web/video.html +65 -21
- package/web/video.js +54 -53
- package/web/video.ts +5 -1
package/web/board/settings.ts
CHANGED
|
@@ -72,6 +72,7 @@ export async function openSettings() {
|
|
|
72
72
|
const nton = notifyOn();
|
|
73
73
|
const ntHelp = !nton ? "Off in this browser" : np === "granted" ? "" : np === "denied" ? "Pop-ups blocked by this browser; the sound still plays" : np ? "Pop-ups wait for the browser to ask; the sound still plays" : "Pop-ups not supported here; the sound still plays";
|
|
74
74
|
$("pbody").innerHTML = html`<div class="sq"><input class="sel" id="sq" type="search" placeholder="Search settings" aria-label="Search settings" spellcheck="false" autocomplete="off" value="${store.setQ}"></div>
|
|
75
|
+
<h3 class="sg">Phone</h3><div class="sgrp">${row("Phone address", cfg?.phoneUrls?.length ? html`<span class="phoneurls">${cfg.phoneUrls.map((url) => html`<a href="${url}" target="_blank" rel="noopener">${url}</a>`)}</span>` : html`<span>Not set</span>`, cfg?.phoneUrls?.length ? "Configured address; Tailscale must be running on both devices." : "Run kaizen setup on this PC to connect your phone.", "phone-url", "phone address url tailscale setup")}</div>
|
|
75
76
|
${
|
|
76
77
|
cfg
|
|
77
78
|
? groups(cfg.rows)
|
package/web/board/store.ts
CHANGED
|
@@ -19,6 +19,8 @@ export const store = {
|
|
|
19
19
|
// The Ideas column's severity menu, on its Backlog tab.
|
|
20
20
|
sevMenu: false,
|
|
21
21
|
wantTerm: null,
|
|
22
|
+
// Live shells from GET /shells (the footer reads them): tiles on the Terminal page.
|
|
23
|
+
shells: [] as { key: string; dir: string; title: string; agent: string }[],
|
|
22
24
|
// The settings search survives the re-render each save does; the gear button starts it empty.
|
|
23
25
|
setQ: "",
|
|
24
26
|
// Settings and the Icebox fill the same panel after a fetch: a fill only lands if no other view
|
package/web/board/terms.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { resume } from "./approvals.ts";
|
|
|
14
14
|
// mode: grid (√n), cols (side by side) or rows (stacked, so borders drag up and down).
|
|
15
15
|
type Lay = { mode: string; order: string[]; hidden: string[]; max: string | null; sizes: Record<string, { c: number[]; r: number[] }> };
|
|
16
16
|
const MODES = [["grid", "Grid", "lgrid"], ["cols", "Side by side", "lcols"], ["rows", "Stacked", "lrows"]];
|
|
17
|
-
const GAP =
|
|
17
|
+
const GAP = 1;
|
|
18
18
|
let lay: Lay = { mode: "grid", order: [], hidden: [], max: null, sizes: {} };
|
|
19
19
|
try {
|
|
20
20
|
lay = { ...lay, ...JSON.parse(localStorage.getItem("kz-terms") || "{}") };
|
|
@@ -46,6 +46,8 @@ const projOf = (c) => String(c.where || "").split(/[\\/]/).filter(Boolean).pop()
|
|
|
46
46
|
function sessions() {
|
|
47
47
|
const m = new Map();
|
|
48
48
|
for (const c of store.S.cards) if (c.pty && !c.archived) m.set(c.pty.key, c);
|
|
49
|
+
// Shells and bare agent sessions a run workspace opened (POST /shell): a tile each too.
|
|
50
|
+
for (const s of store.shells) m.set(s.key, { kind: "shell", text: s.title, where: s.dir.replace(/[\\/]\.kaizen$/, ""), state: s.dir, pty: { key: s.key, alive: true, asking: false } });
|
|
49
51
|
return m;
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -72,6 +74,8 @@ export function termsStop() {
|
|
|
72
74
|
const focusTerm = (k: string) => tiles.get(k)?.el.querySelector<HTMLElement>(".xterm-helper-textarea")?.focus({ preventScroll: true });
|
|
73
75
|
// Ctrl+Shift+M maximises or restores the tile being typed in. Escape belongs to the agent,
|
|
74
76
|
// so the key is read in capture, before xterm sends it on.
|
|
77
|
+
// The footer's /shells read changed the shell list.
|
|
78
|
+
if (typeof window !== "undefined") addEventListener("kz-shells", () => showing && openTerms());
|
|
75
79
|
if (typeof window !== "undefined") addEventListener(
|
|
76
80
|
"keydown",
|
|
77
81
|
(e) => {
|
|
@@ -198,7 +202,7 @@ export function openTerms() {
|
|
|
198
202
|
const hd = t.el.querySelector("header")!;
|
|
199
203
|
hd.title = (c.kind === "run" ? c.id : c.text) + " · " + c.where + (i < 9 ? ` · Alt+${i + 1}` : "");
|
|
200
204
|
// An ended run can be resumed from here; an idea whose agent ended has no run to resume.
|
|
201
|
-
hd.innerHTML = html`<span class="tdot ${st}" role="img" title="${st}" aria-label="${st}"></span><b>${nameOf(c)} - ${projOf(c)}</b>${off ? html`<span class="tend">ended</span>` : ""}<span class="sp"></span>${off && c.kind === "run" ? html`<button class="btn sm" data-a="resume" title="Continue this run's agent">Resume</button>` : ""}
|
|
205
|
+
hd.innerHTML = html`<span class="tdot ${st}" role="img" title="${st}" aria-label="${st}"></span><b>${nameOf(c)} - ${projOf(c)}</b>${off ? html`<span class="tend">ended</span>` : ""}<span class="sp"></span>${off && c.kind === "run" ? html`<button class="btn sm" data-a="resume" title="Continue this run's agent">Resume</button>` : ""}${c.kind === "shell" ? "" : html`<button class="ib sm" data-a="card" title="Open card" aria-label="Open card">${ico("open")}</button>`}<button class="ib sm" data-a="max" title="${lay.max === k ? "Restore" : "Maximise"} (Ctrl+Shift+M)" aria-label="${lay.max === k ? "Restore" : "Maximise"}">${ico(lay.max === k ? "min" : "max")}</button>${off ? "" : html`<button class="ib sm" data-a="hide" title="Hide" aria-label="Hide">${ico("dash")}</button>`}<button class="ib sm" data-a="${off ? "hide" : "exit"}" title="${off ? "Close" : "Exit session"}" aria-label="${off ? "Close" : "Exit session"}">${ico("close")}</button>`.s;
|
|
202
206
|
t.el.classList.toggle("ended", off);
|
|
203
207
|
t.el.classList.toggle("asking", st === "asking");
|
|
204
208
|
t.el.classList.toggle("off", !!one && one !== k);
|
|
@@ -305,7 +309,7 @@ const at = (tr: number[], i: number) => {
|
|
|
305
309
|
S = tr.slice(0, i + 1).reduce((a, b) => a + b, 0);
|
|
306
310
|
return `calc((100% - ${(tr.length - 1) * GAP}px) * ${S / F} + ${i * GAP + GAP / 2}px)`;
|
|
307
311
|
};
|
|
308
|
-
function layout(grid: HTMLElement, c: number[], r: number[], shape: string, spanFrom: number, splits: boolean) {
|
|
312
|
+
export function layout(grid: HTMLElement, c: number[], r: number[], shape: string, spanFrom: number, splits: boolean) {
|
|
309
313
|
grid.querySelectorAll(".tsplit").forEach((s) => s.remove());
|
|
310
314
|
const place = () => {
|
|
311
315
|
grid.style.gridTemplateColumns = c.map((x) => x + "fr").join(" ");
|
package/web/board/views.ts
CHANGED
|
@@ -5,11 +5,13 @@ import { close } from "./panel.ts";
|
|
|
5
5
|
import { openSettings } from "./settings.ts";
|
|
6
6
|
import { openTerms, termsStop } from "./terms.ts";
|
|
7
7
|
import { openHome } from "./home.ts";
|
|
8
|
+
import { initIdeas, openIdeas } from "./ideas.ts";
|
|
9
|
+
import { initRunView, runStop, showRunView } from "./run-view.ts";
|
|
8
10
|
|
|
9
11
|
// ---- views: Home (the chat, at /), the board, Settings and the Icebox as pages in the docked panel, or the Terminal page; each with its own address
|
|
10
12
|
export let view = "board";
|
|
11
13
|
// The board's own area, not the docked panel.
|
|
12
|
-
const AREA = ["board", "terminal", "home"];
|
|
14
|
+
const AREA = ["board", "terminal", "home", "ideas", "run"];
|
|
13
15
|
export const markView = (v) => {
|
|
14
16
|
document
|
|
15
17
|
.querySelectorAll(".rail a.it")
|
|
@@ -17,12 +19,12 @@ export const markView = (v) => {
|
|
|
17
19
|
a.dataset.view === v ? a.setAttribute("aria-current", "page") : a.removeAttribute("aria-current"),
|
|
18
20
|
);
|
|
19
21
|
// The Icebox is titled in the header, top left, like the board.
|
|
20
|
-
document.querySelector(".hdr h1").textContent = v === "sources" ? "Icebox" : v === "terminal" ? "Terminal" : v === "home" ? "Home" : "Board";
|
|
22
|
+
document.querySelector(".hdr h1").textContent = v === "sources" ? "Icebox" : v === "ideas" ? "Ideas" : v === "run" ? "Run" : v === "terminal" ? "Terminal" : v === "home" ? "Home" : "Board";
|
|
21
23
|
};
|
|
22
24
|
export function go(v, push) {
|
|
23
25
|
store.pageGen++;
|
|
24
26
|
if (v === "icebox") v = "sources";
|
|
25
|
-
if (!["settings", "sources", "terminal", "board"].includes(v)) v = "home";
|
|
27
|
+
if (!["settings", "sources", "terminal", "board", "ideas", "run"].includes(v)) v = "home";
|
|
26
28
|
const was = view;
|
|
27
29
|
view = v;
|
|
28
30
|
markView(v);
|
|
@@ -30,13 +32,26 @@ export function go(v, push) {
|
|
|
30
32
|
document.body.classList.toggle("ice", v === "sources");
|
|
31
33
|
document.body.classList.toggle("termv", v === "terminal");
|
|
32
34
|
document.body.classList.toggle("homev", v === "home");
|
|
33
|
-
|
|
35
|
+
document.body.classList.toggle("ideav", v === "ideas");
|
|
36
|
+
document.body.classList.toggle("runv", v === "run");
|
|
37
|
+
// Leaving a workspace: its panel closes as the board's would, its terminals unmount.
|
|
38
|
+
if (was === "run" && v !== "run") {
|
|
39
|
+
runStop();
|
|
40
|
+
view = "board";
|
|
41
|
+
close();
|
|
42
|
+
view = v;
|
|
43
|
+
}
|
|
44
|
+
// The workspace's address names its card: openWorkspace() pushes it.
|
|
45
|
+
if (push && v !== was && v !== "run")
|
|
34
46
|
history.pushState(null, "", v === "home" ? location.pathname : "?view=" + (v === "sources" ? "icebox" : v));
|
|
35
47
|
dispatchEvent(new Event("kz-view"));
|
|
36
48
|
const p = $("panel");
|
|
37
49
|
if (v === "terminal") openTerms();
|
|
38
50
|
else termsStop();
|
|
39
51
|
if (v === "home") openHome();
|
|
52
|
+
if (v === "ideas") openIdeas();
|
|
53
|
+
// After the panel handling below, which closes the board's panel on the way in.
|
|
54
|
+
if (v === "run") queueMicrotask(() => void showRunView());
|
|
40
55
|
// The Terminal page is the board's own area, not the docked panel: the panel closes as on the board.
|
|
41
56
|
if (AREA.includes(v)) {
|
|
42
57
|
if (AREA.includes(was)) {
|
|
@@ -63,6 +78,8 @@ export function go(v, push) {
|
|
|
63
78
|
}
|
|
64
79
|
|
|
65
80
|
export function initViews() {
|
|
81
|
+
initIdeas(go);
|
|
82
|
+
initRunView();
|
|
66
83
|
document.querySelectorAll(".rail a[data-view]").forEach((a) => {
|
|
67
84
|
if (a.dataset.view === "notes" || a.dataset.view === "video") return;
|
|
68
85
|
a.onclick = (e) => {
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// The side menu's live parts on every page (board, notebook, video): the Icebox count,
|
|
2
|
+
// the Ideas entry's source icons and the Projects list; and the board's flat footer
|
|
3
|
+
// (agent usage, terminal count, phone). Stands alone, so the notebook and video
|
|
4
|
+
// bundles can carry it without the board.
|
|
5
|
+
import { onBoardCards } from "./badge.ts";
|
|
6
|
+
import { store } from "./store.ts";
|
|
7
|
+
import { $, html, raw } from "./dom.ts";
|
|
8
|
+
import { age, need } from "./labels.ts";
|
|
9
|
+
|
|
10
|
+
const DAY = 864e5;
|
|
11
|
+
const STAGE = ["idea", "planning", "building", "reviewing", "done"];
|
|
12
|
+
// A card's state icon (.si) and the word under its title.
|
|
13
|
+
export function stateOf(c) {
|
|
14
|
+
if (c.kind === "idea") return "idle";
|
|
15
|
+
if (c.status === "waiting" || (c.pty?.alive && c.pty.asking)) return "wait";
|
|
16
|
+
if (c.status === "done") return "done";
|
|
17
|
+
if (c.status === "abandoned") return "aband";
|
|
18
|
+
if (c.status === "stalled") return "stalled";
|
|
19
|
+
return c.column >= 3 ? "review" : c.column === 2 ? "build" : "plan";
|
|
20
|
+
}
|
|
21
|
+
export function subline(c, now) {
|
|
22
|
+
if (c.kind === "idea") return "idea";
|
|
23
|
+
const t = c.moved ?? now;
|
|
24
|
+
if (c.status === "waiting") return c.awaiting ? `${STAGE[c.column] ?? "waiting"} · ${need(c.awaiting)}` : "waiting on you";
|
|
25
|
+
if (c.status === "done" || c.status === "abandoned") return `${c.status} · ${age(t, now)} ago`;
|
|
26
|
+
if (c.status === "stalled") return `stalled · ${age(t, now)}`;
|
|
27
|
+
return `${STAGE[c.column] ?? c.status} · ${age(t, now)}`;
|
|
28
|
+
}
|
|
29
|
+
export const titleOf = (c) => (c.title || c.text || "").split("\n")[0];
|
|
30
|
+
// Shown in the list: runs not archived, a finished one only for a day. Ideas not started yet
|
|
31
|
+
// live on the Ideas page; one whose agent is starting (it has a terminal) shows here.
|
|
32
|
+
export const listed = (c, now) =>
|
|
33
|
+
!c.archived && (c.kind === "idea" ? !!c.pty : !["done", "abandoned"].includes(c.status) || now - (c.moved ?? 0) < DAY);
|
|
34
|
+
const projName = (dir, projects) => {
|
|
35
|
+
const l = projects?.find((p) => p.dir === dir)?.label || dir.replace(/[\\/]\.kaizen$/, "");
|
|
36
|
+
return l.split(/[\\/]/).pop() || l;
|
|
37
|
+
};
|
|
38
|
+
export const logo = (dir, name, projects) => {
|
|
39
|
+
const ini = html`<span class="plogo" aria-hidden="true">${(name || "?").charAt(0).toUpperCase()}</span>`;
|
|
40
|
+
return projects?.some((p) => p.dir === dir && p.logo)
|
|
41
|
+
? html`<img class="plogo" src="/project-logo?dir=${encodeURIComponent(dir)}" alt="" loading="lazy" onerror="this.outerHTML=this.dataset.f" data-f="${String(ini)}">`
|
|
42
|
+
: ini;
|
|
43
|
+
};
|
|
44
|
+
// A card's address: its run workspace (?view=run&dir=&id=, or &idea= for an idea).
|
|
45
|
+
export const cardHref = (c) =>
|
|
46
|
+
`/?view=run&dir=${encodeURIComponent(c.state)}&` + (c.kind === "run" ? "id=" + encodeURIComponent(c.id) : "idea=" + encodeURIComponent(c.text));
|
|
47
|
+
|
|
48
|
+
// The Projects filter: projects ticked (none = all) and which kinds of card show. Kept per browser.
|
|
49
|
+
type Filt = { dirs: string[]; active: boolean; done: boolean };
|
|
50
|
+
const ALLF: Filt = { dirs: [], active: true, done: true };
|
|
51
|
+
let filt: Filt = (() => {
|
|
52
|
+
try {
|
|
53
|
+
return { ...ALLF, ...JSON.parse(localStorage.getItem("kz-rail-filter") || "{}") };
|
|
54
|
+
} catch {
|
|
55
|
+
return { ...ALLF };
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
const keepFilt = () => {
|
|
59
|
+
try {
|
|
60
|
+
localStorage.setItem("kz-rail-filter", JSON.stringify(filt));
|
|
61
|
+
} catch {}
|
|
62
|
+
};
|
|
63
|
+
const kindOf = (c) => {
|
|
64
|
+
const st = stateOf(c);
|
|
65
|
+
return st === "done" || st === "aband" ? "done" : "active";
|
|
66
|
+
};
|
|
67
|
+
let last: { cards: any[]; projects?: any[] } = { cards: [] };
|
|
68
|
+
// Project groups folded shut in the side menu, kept per browser.
|
|
69
|
+
const folded: Set<string> = (() => {
|
|
70
|
+
try {
|
|
71
|
+
return new Set(JSON.parse(localStorage.getItem("kz-rail-folded") || "[]"));
|
|
72
|
+
} catch {
|
|
73
|
+
return new Set();
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
function fold(dir: string) {
|
|
77
|
+
folded.has(dir) ? folded.delete(dir) : folded.add(dir);
|
|
78
|
+
try {
|
|
79
|
+
localStorage.setItem("kz-rail-folded", JSON.stringify([...folded]));
|
|
80
|
+
} catch {}
|
|
81
|
+
drawList();
|
|
82
|
+
}
|
|
83
|
+
function drawList() {
|
|
84
|
+
const box = $("plist");
|
|
85
|
+
if (!box) return;
|
|
86
|
+
const now = Date.now();
|
|
87
|
+
const groups = new Map<string, any[]>();
|
|
88
|
+
const all = new Set(last.cards.filter((c) => listed(c, now)).map((c) => c.state));
|
|
89
|
+
for (const c of last.cards.filter((c) => listed(c, now) && filt[kindOf(c)] && (!filt.dirs.length || filt.dirs.includes(c.state)))) {
|
|
90
|
+
if (!groups.has(c.state)) groups.set(c.state, []);
|
|
91
|
+
groups.get(c.state)!.push(c);
|
|
92
|
+
}
|
|
93
|
+
// Within a project: waiting, planning, building, reviewing, stalled, ideas, done; newest first in each.
|
|
94
|
+
const RANK = { wait: 0, plan: 1, build: 2, review: 3, stalled: 4, idle: 5, done: 6, aband: 7 };
|
|
95
|
+
const when = (c) => c.moved ?? c.added ?? 0;
|
|
96
|
+
for (const cs of groups.values()) cs.sort((a, b) => RANK[stateOf(a)] - RANK[stateOf(b)] || when(b) - when(a));
|
|
97
|
+
// Projects by their most urgent card: one waiting on you before one only planning, before one with only ideas.
|
|
98
|
+
const top = (cs) => Math.min(...cs.map((c) => RANK[stateOf(c)]));
|
|
99
|
+
const ordered = new Map([...groups].sort((a, b) => top(a[1]) - top(b[1])));
|
|
100
|
+
groups.clear();
|
|
101
|
+
for (const [k, v] of ordered) groups.set(k, v);
|
|
102
|
+
|
|
103
|
+
const f = $("pfilter");
|
|
104
|
+
const on = filt.dirs.some((d) => all.has(d)) || !filt.active || !filt.done;
|
|
105
|
+
f.setAttribute("aria-pressed", String(on));
|
|
106
|
+
f.title = on ? "Filter on: choose projects and kinds" : "Filter projects and kinds";
|
|
107
|
+
if ($("pfpop")) drawPop(all);
|
|
108
|
+
const cur = new URLSearchParams(location.search);
|
|
109
|
+
box.innerHTML =
|
|
110
|
+
[...groups]
|
|
111
|
+
.map(([dir, cs]) => {
|
|
112
|
+
const name = projName(dir, last.projects);
|
|
113
|
+
const shut = folded.has(dir);
|
|
114
|
+
return html`<button type="button" class="proj${shut ? " shut" : ""}" data-fold="${dir}" title="${dir}" aria-expanded="${String(!shut)}"><svg class="fchev" viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>${logo(dir, name, last.projects)}<span>${name}</span><span class="c">${cs.length}</span></button>${shut ? "" : cs.map(
|
|
115
|
+
(c) =>
|
|
116
|
+
html`<a class="row" href="${cardHref(c)}" data-dir="${c.state}" data-id="${c.id ?? ""}" data-text="${c.kind === "idea" ? c.text : ""}" title="${titleOf(c)}"${raw(cur.get("dir") === c.state && (cur.get("id") === c.id || cur.get("idea") === c.text) ? ' aria-current="true"' : "")}><span class="si ${stateOf(c)}"></span><div><b>${titleOf(c)}</b><small>${subline(c, now)}</small></div></a>`,
|
|
117
|
+
)}`;
|
|
118
|
+
})
|
|
119
|
+
.join("") || `<div class="none">No runs</div>`;
|
|
120
|
+
box.onclick = (e) => {
|
|
121
|
+
const d = (e.target as HTMLElement).closest<HTMLElement>("[data-fold]")?.dataset.fold;
|
|
122
|
+
if (d) (e.preventDefault(), fold(d));
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// Moves the side menu's highlight to the card the address names: opening a card in place
|
|
126
|
+
// changes the address without redrawing the list.
|
|
127
|
+
export function markCurrent() {
|
|
128
|
+
const cur = new URLSearchParams(location.search);
|
|
129
|
+
for (const a of document.querySelectorAll<HTMLElement>("#plist a.row")) {
|
|
130
|
+
const on = cur.get("dir") === a.dataset.dir && (cur.get("id") === a.dataset.id || (!!a.dataset.text && cur.get("idea") === a.dataset.text));
|
|
131
|
+
if (on) a.setAttribute("aria-current", "true");
|
|
132
|
+
else a.removeAttribute("aria-current");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
addEventListener("popstate", markCurrent);
|
|
136
|
+
// The pages that can open a card in place (the board) answer this event and cancel it.
|
|
137
|
+
const ask = (name, detail) => !dispatchEvent(new CustomEvent(name, { cancelable: true, detail }));
|
|
138
|
+
|
|
139
|
+
// What the Ideas page reads too: the cards, and /sources (sources plus every icebox signal).
|
|
140
|
+
let srcs: any = null;
|
|
141
|
+
export const railData = () => ({ ...last, srcs });
|
|
142
|
+
const told = () => dispatchEvent(new Event("kz-rail"));
|
|
143
|
+
let srcAt = 0;
|
|
144
|
+
export async function drawSources(force = false) {
|
|
145
|
+
if (!force && Date.now() - srcAt < 30_000) return;
|
|
146
|
+
srcAt = Date.now();
|
|
147
|
+
try {
|
|
148
|
+
const r = await fetch("/sources");
|
|
149
|
+
if (!r.ok) return;
|
|
150
|
+
const d = (srcs = await r.json());
|
|
151
|
+
told();
|
|
152
|
+
const n = (d.icebox ?? []).filter((s) => s.status === "new").length;
|
|
153
|
+
$("ice-n").textContent = n ? String(n) : "";
|
|
154
|
+
$("rail-srcs").innerHTML = (d.sources ?? [])
|
|
155
|
+
.slice(0, 3)
|
|
156
|
+
.map((s) => String(srcIcon(s)))
|
|
157
|
+
.join("");
|
|
158
|
+
} catch {
|
|
159
|
+
/* offline: keep what shows */
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// A source's mark: a social platform's sprite, a sheet's grid, else the site's favicon.
|
|
163
|
+
export const srcIcon = (s) => {
|
|
164
|
+
if (s.social) return html`<svg aria-hidden="true"><use href="#i-b-${s.social}"/></svg>`;
|
|
165
|
+
if (/docs\.google\.com\/spreadsheets|\.(csv|tsv)$/.test(s.url)) return raw(`<svg aria-hidden="true"><use href="#i-sheet"/></svg>`);
|
|
166
|
+
try {
|
|
167
|
+
return html`<img src="${new URL(s.url).origin}/favicon.ico" alt="" loading="lazy" referrerpolicy="no-referrer" onerror="this.remove()">`;
|
|
168
|
+
} catch {
|
|
169
|
+
return raw("");
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// The filter popover: every project listed (search when there are many), All projects, and
|
|
174
|
+
// the kinds of card. Each tick applies at once.
|
|
175
|
+
let pq = "";
|
|
176
|
+
function drawPop(all: Set<string>) {
|
|
177
|
+
const p = $("pfpop");
|
|
178
|
+
const dirs = [...all];
|
|
179
|
+
const shown = dirs.filter((d) => projName(d, last.projects).toLowerCase().includes(pq.toLowerCase()));
|
|
180
|
+
const box = (on: boolean, attrs: string, label) => html`<label class="pfrow"><input type="checkbox" ${raw(attrs)}${on ? raw(" checked") : ""}>${label}</label>`;
|
|
181
|
+
const had = document.activeElement?.id;
|
|
182
|
+
p.innerHTML = String(
|
|
183
|
+
html`${dirs.length > 6 ? html`<input class="sel" id="pfq" placeholder="Search projects…" aria-label="Search projects" value="${pq}" autocomplete="off" spellcheck="false">` : ""}${box(!filt.dirs.length, 'data-all="1"', "All projects")}${shown.map((d) => box(filt.dirs.includes(d), `data-dir="${encodeURIComponent(d)}"`, html`${logo(d, projName(d, last.projects), last.projects)}<span>${projName(d, last.projects)}</span>`))}<div class="pfh">Show</div>${(["active", "done"] as const).map((k) => box(filt[k], `data-k="${k}"`, { active: "Active runs", done: "Done (last day)" }[k]))}`,
|
|
184
|
+
);
|
|
185
|
+
if (had === "pfq") {
|
|
186
|
+
const q = $("pfq") as HTMLInputElement;
|
|
187
|
+
q.focus();
|
|
188
|
+
q.setSelectionRange(pq.length, pq.length);
|
|
189
|
+
}
|
|
190
|
+
p.oninput = (e) => {
|
|
191
|
+
const t = e.target as HTMLInputElement;
|
|
192
|
+
if (t.id === "pfq") pq = t.value;
|
|
193
|
+
else if (t.dataset.all) filt.dirs = [];
|
|
194
|
+
else if (t.dataset.dir) {
|
|
195
|
+
const d = decodeURIComponent(t.dataset.dir);
|
|
196
|
+
filt.dirs = t.checked ? [...new Set([...filt.dirs, d])] : filt.dirs.filter((x) => x !== d);
|
|
197
|
+
} else if (t.dataset.k) filt[t.dataset.k] = t.checked;
|
|
198
|
+
keepFilt();
|
|
199
|
+
drawList();
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function closePop() {
|
|
203
|
+
$("pfpop")?.remove();
|
|
204
|
+
$("pfilter").setAttribute("aria-expanded", "false");
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function initRail() {
|
|
208
|
+
if (!$("plist")) return;
|
|
209
|
+
onBoardCards((cards, projects) => {
|
|
210
|
+
last = { cards, projects: projects ?? last.projects };
|
|
211
|
+
drawList();
|
|
212
|
+
void drawSources();
|
|
213
|
+
onCount?.(cards);
|
|
214
|
+
told();
|
|
215
|
+
});
|
|
216
|
+
$("pfilter").onclick = (e) => {
|
|
217
|
+
e.stopPropagation();
|
|
218
|
+
if ($("pfpop")) return closePop();
|
|
219
|
+
const p = document.createElement("div");
|
|
220
|
+
p.id = "pfpop";
|
|
221
|
+
p.className = "pfpop";
|
|
222
|
+
p.setAttribute("role", "dialog");
|
|
223
|
+
p.setAttribute("aria-label", "Filter the Projects list");
|
|
224
|
+
const r = $("pfilter").getBoundingClientRect();
|
|
225
|
+
p.style.left = r.left + "px";
|
|
226
|
+
p.style.top = r.bottom + 4 + "px";
|
|
227
|
+
document.body.append(p);
|
|
228
|
+
$("pfilter").setAttribute("aria-expanded", "true");
|
|
229
|
+
drawList();
|
|
230
|
+
(p.querySelector("input") as HTMLElement)?.focus();
|
|
231
|
+
};
|
|
232
|
+
addEventListener("pointerdown", (e) => {
|
|
233
|
+
const p = $("pfpop");
|
|
234
|
+
if (p && !p.contains(e.target as Node) && !$("pfilter").contains(e.target as Node)) closePop();
|
|
235
|
+
});
|
|
236
|
+
addEventListener("keydown", (e) => {
|
|
237
|
+
if (e.key === "Escape" && $("pfpop")) {
|
|
238
|
+
closePop();
|
|
239
|
+
$("pfilter").focus();
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
$("padd").onclick = () => {
|
|
243
|
+
// The page's own project when it has one: the run workspace's, or the one project the filter shows.
|
|
244
|
+
const p = new URLSearchParams(location.search);
|
|
245
|
+
const dir = p.get("view") === "run" ? p.get("dir") : filt.dirs.length === 1 ? filt.dirs[0] : null;
|
|
246
|
+
if (!ask("kz-new-idea", { dir })) location.href = "/?view=board";
|
|
247
|
+
};
|
|
248
|
+
$("plist").addEventListener("click", (e) => {
|
|
249
|
+
const a = (e.target as Element).closest?.("a.row") as HTMLAnchorElement;
|
|
250
|
+
if (!a || e.ctrlKey || e.metaKey || e.shiftKey || (e as MouseEvent).button) return;
|
|
251
|
+
if (ask("kz-open-card", { dir: a.dataset.dir, id: a.dataset.id, text: a.dataset.text })) e.preventDefault();
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// ---- footer (board page)
|
|
256
|
+
const meter = (p) => html`<span class="umtr"><i class="${p >= 85 ? "hi" : p >= 50 ? "mid" : ""}" style="width:${Math.min(100, p)}%"></i></span>`;
|
|
257
|
+
const when = (t) => (t ? new Date(t).toLocaleString([], { weekday: "short", hour: "2-digit", minute: "2-digit" }) : "unknown");
|
|
258
|
+
const NAME = { claude: "Claude", codex: "Codex" };
|
|
259
|
+
export function usageChips(list) {
|
|
260
|
+
// The agent's mark and its 5-hour %, coloured as it fills; the full figures on hover/focus.
|
|
261
|
+
const lvl = (p) => (p >= 95 ? " hi" : p >= 80 ? " mid" : "");
|
|
262
|
+
return list
|
|
263
|
+
.filter((u) => NAME[u.agent])
|
|
264
|
+
.map((u) => {
|
|
265
|
+
const mark = html`<svg aria-hidden="true"><use href="#i-${u.agent}"/></svg>`;
|
|
266
|
+
if (u.error) return html`<span class="uchip na" tabindex="0">${mark}<b>–</b><span class="utip" role="tooltip"><b>${NAME[u.agent]}</b>Usage unavailable: ${u.error}</span></span>`;
|
|
267
|
+
const head = u.five ?? u.week;
|
|
268
|
+
const row = (label, w) => (w ? html`<span class="urow"><span>${label}</span><b class="${lvl(w.pct).trim()}">${w.pct}%</b><i><i style="width:${Math.min(100, w.pct)}%" class="${lvl(w.pct).trim()}"></i></i><small>resets ${when(w.resetsAt)}</small></span>` : "");
|
|
269
|
+
return html`<span class="uchip" tabindex="0" aria-label="${NAME[u.agent]} usage">${mark}<b class="${lvl(head?.pct ?? 0).trim()}">${head ? head.pct + "%" : ""}</b><span class="utip" role="tooltip"><b>${NAME[u.agent]}</b>${row("5-hour window", u.five)}${row("Week", u.week)}</span></span>`;
|
|
270
|
+
})
|
|
271
|
+
.join("");
|
|
272
|
+
}
|
|
273
|
+
async function usage(refresh = false) {
|
|
274
|
+
try {
|
|
275
|
+
const r = await fetch("/usage" + (refresh ? "?refresh=1" : ""));
|
|
276
|
+
if (r.ok) $("usage").innerHTML = usageChips(await r.json());
|
|
277
|
+
} catch {}
|
|
278
|
+
}
|
|
279
|
+
async function phone() {
|
|
280
|
+
try {
|
|
281
|
+
const d = await (await fetch("/phone")).json();
|
|
282
|
+
const el = $("phone");
|
|
283
|
+
el.hidden = false;
|
|
284
|
+
const [txt, on, tip] = !d.tailscale
|
|
285
|
+
? ["Tailscale off", false, "Tailscale is not running on this computer"]
|
|
286
|
+
: d.online
|
|
287
|
+
? ["Phone connected", true, "A phone is online on your tailnet"]
|
|
288
|
+
: ["Phone offline", false, d.phones ? "Your phone is not online on the tailnet" : "No phone on your tailnet"];
|
|
289
|
+
el.title = tip;
|
|
290
|
+
el.innerHTML = String(html`<svg aria-hidden="true"><use href="#i-phone"/></svg><span class="ptxt">${txt}</span><span class="dot${on ? "" : " off"}"></span>`);
|
|
291
|
+
} catch {}
|
|
292
|
+
}
|
|
293
|
+
// Live terminals: the board's agent sessions plus the shells /shell started.
|
|
294
|
+
let agentPtys = 0;
|
|
295
|
+
let onCount: ((cards: any[]) => void) | null = null;
|
|
296
|
+
async function terms() {
|
|
297
|
+
let shells = 0;
|
|
298
|
+
try {
|
|
299
|
+
store.shells = await (await fetch("/shells")).json();
|
|
300
|
+
shells = store.shells.length;
|
|
301
|
+
dispatchEvent(new Event("kz-shells"));
|
|
302
|
+
} catch {}
|
|
303
|
+
const n = agentPtys + shells,
|
|
304
|
+
a = $("tcount");
|
|
305
|
+
a.hidden = !n;
|
|
306
|
+
a.querySelector("span").textContent = String(n);
|
|
307
|
+
a.title = `${n} live terminal${n === 1 ? "" : "s"}: show them all`;
|
|
308
|
+
}
|
|
309
|
+
export function initFooter(goTerminal: () => void) {
|
|
310
|
+
if (!$("foot")) return;
|
|
311
|
+
// The Board drawer is position:fixed; it stops above the footer, whose height varies.
|
|
312
|
+
const fh = () => document.documentElement.style.setProperty("--foot-h", $("foot").offsetHeight + "px");
|
|
313
|
+
new ResizeObserver(fh).observe($("foot"));
|
|
314
|
+
fh();
|
|
315
|
+
void usage();
|
|
316
|
+
void phone();
|
|
317
|
+
setInterval(() => void usage(), 5 * 60_000);
|
|
318
|
+
setInterval(() => void phone(), 60_000);
|
|
319
|
+
$("usage-r").onclick = () => void usage(true);
|
|
320
|
+
$("tcount").onclick = (e) => {
|
|
321
|
+
if (e.ctrlKey || e.metaKey || e.shiftKey || e.button) return;
|
|
322
|
+
e.preventDefault();
|
|
323
|
+
goTerminal();
|
|
324
|
+
};
|
|
325
|
+
onCount = (cards) => {
|
|
326
|
+
agentPtys = cards.filter((c) => c.pty?.alive).length;
|
|
327
|
+
void terms();
|
|
328
|
+
};
|
|
329
|
+
}
|