Skip to content

armgit / kanzo

Public Imported from GitHub
0

Self-hosted, sharable kanban for humans and agents. One 4.7 MB binary, 5 MB of RAM, 10 to 60 tokens per agent reply, starts in 3 ms, zero setup.

Add the board page

emanuele-ema093a3fec087
diff --git a/src/index.html b/src/index.html
index 75e4c20..49f1a7c 100644
--- a/src/index.html
+++ b/src/index.html
@@ -1,6 +1,856 @@
<!doctype html>
<html lang="en">
+<head>
<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kanzo</title>
-<p>Kanzo is running. The board page comes next; the JSON API is at /api.</p>
+<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect x='1' y='2' width='4' height='12' rx='1' fill='%233b5bdb'/%3E%3Crect x='6' y='2' width='4' height='8' rx='1' fill='%233b5bdb' opacity='.7'/%3E%3Crect x='11' y='2' width='4' height='5' rx='1' fill='%233b5bdb' opacity='.4'/%3E%3C/svg%3E">
+<style>
+:root {
+ --bg: #f7f7f5; --sidebar: #efefeb; --col: #ededea; --card: #ffffff; --panel: #ffffff;
+ --text: #1f1f1c; --muted: #6d6d66; --faint: #9b9b93; --border: #dfdfd9; --hover: #e4e4df;
+ --accent: #3b5bdb; --accent-text: #ffffff; --danger: #c92a2a; --shadow: 0 1px 2px rgba(0,0,0,.06);
+ --drop: #3b5bdb; --code: #f1f1ed;
+ color-scheme: light dark;
+}
+@media (prefers-color-scheme: dark) {
+ :root {
+ --bg: #181817; --sidebar: #131312; --col: #1e1e1c; --card: #272725; --panel: #20201e;
+ --text: #e9e9e4; --muted: #a3a39b; --faint: #74746d; --border: #33332f; --hover: #2c2c29;
+ --accent: #7d93ff; --accent-text: #0f1530; --danger: #ff8787; --shadow: 0 1px 2px rgba(0,0,0,.3);
+ --drop: #7d93ff; --code: #2c2c29;
+ }
+}
+* { box-sizing: border-box; }
+html, body { height: 100%; margin: 0; }
+body {
+ background: var(--bg); color: var(--text);
+ font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
+ display: grid; grid-template-columns: 220px 1fr; overflow: hidden;
+}
+button, input, textarea, select { font: inherit; color: inherit; }
+button { cursor: pointer; }
+.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
+
+/* Sidebar */
+aside {
+ background: var(--sidebar); border-right: 1px solid var(--border);
+ display: flex; flex-direction: column; min-height: 0; padding: 14px 8px;
+}
+.brand { font-weight: 650; font-size: 15px; padding: 2px 10px 14px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
+.brand svg { width: 16px; height: 16px; }
+.nav { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 1px; }
+.nav a {
+ display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px;
+ color: inherit; text-decoration: none; white-space: nowrap;
+}
+.nav a:hover { background: var(--hover); }
+.nav a.active { background: var(--card); box-shadow: var(--shadow); font-weight: 550; }
+.nav a .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
+.nav a .count { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
+.nav .label { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 14px 10px 4px; }
+.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
+.ghost {
+ background: none; border: 0; color: var(--muted); text-align: left;
+ padding: 6px 10px; border-radius: 6px; width: 100%;
+}
+.ghost:hover { background: var(--hover); color: var(--text); }
+form.new-project { display: flex; flex-direction: column; gap: 6px; padding: 8px 6px; }
+form.new-project .row { display: flex; gap: 6px; }
+input.field, textarea.field, select.field {
+ background: var(--card); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; width: 100%;
+ outline: none;
+}
+.field:focus { border-color: var(--accent); }
+.btn {
+ border: 1px solid var(--border); background: var(--card); border-radius: 6px; padding: 5px 12px;
+}
+.btn:hover { background: var(--hover); }
+.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 550; }
+.btn.primary:hover { filter: brightness(1.08); }
+.btn.danger { color: var(--danger); }
+
+/* Main board */
+main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
+header {
+ display: flex; align-items: baseline; gap: 12px; padding: 16px 20px 12px; flex-wrap: wrap;
+}
+header h1 { font-size: 18px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
+header .sub { color: var(--muted); }
+header .sub a { color: inherit; }
+.columns {
+ flex: 1; min-height: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr);
+ gap: 12px; padding: 0 20px 20px; overflow-x: auto;
+}
+.column {
+ background: var(--col); border-radius: 10px; display: flex; flex-direction: column; min-height: 0;
+}
+.column h2 {
+ font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
+ margin: 0; padding: 12px 12px 8px; display: flex; align-items: center; gap: 8px;
+}
+.column h2 .count { color: var(--faint); font-weight: 500; }
+.cards { flex: 0 1 auto; overflow-y: auto; padding: 2px 8px 8px; display: flex; flex-direction: column; gap: 6px; min-height: 8px; }
+.card {
+ background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
+ box-shadow: var(--shadow); cursor: grab; user-select: none;
+}
+.card:hover { border-color: var(--faint); }
+.card.open { border-color: var(--accent); }
+.card.dragging { opacity: .4; }
+.card .title { overflow-wrap: anywhere; }
+.card .meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; color: var(--faint); font-size: 12px; }
+.card .meta .spacer { flex: 1; }
+.tag {
+ display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted);
+ border: 1px solid var(--border); border-radius: 99px; padding: 0 7px 0 6px;
+}
+.tag .dot { width: 6px; height: 6px; }
+.drop-line { height: 2px; background: var(--drop); border-radius: 2px; margin: -4px 2px; }
+.add { padding: 0 8px 8px; }
+.add form { display: flex; flex-direction: column; gap: 6px; }
+.add textarea { resize: none; min-height: 54px; }
+.add .row { display: flex; gap: 6px; align-items: center; }
+.add .row select { flex: 1; min-width: 0; }
+.empty {
+ margin: auto; text-align: center; color: var(--muted); max-width: 360px; padding: 40px 20px;
+}
+.empty h1 { color: var(--text); font-size: 18px; }
+
+/* Task panel */
+.panel {
+ position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); background: var(--panel);
+ border-left: 1px solid var(--border); box-shadow: -8px 0 30px rgba(0,0,0,.12);
+ display: flex; flex-direction: column; transform: translateX(100%); transition: transform .16s ease-out;
+ z-index: 10;
+}
+.panel.shown { transform: none; }
+.panel .top { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
+.panel .top .key { color: var(--muted); }
+.panel .top .spacer { flex: 1; }
+.panel .body { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; flex: 1; }
+.panel .title-input {
+ font-size: 18px; font-weight: 650; border: 1px solid transparent; background: none; padding: 4px 6px;
+ margin: -4px -6px; border-radius: 6px; width: calc(100% + 12px); resize: none; overflow: hidden; outline: none;
+}
+.panel .title-input:hover { border-color: var(--border); }
+.panel .title-input:focus { border-color: var(--accent); background: var(--card); }
+.props { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; align-items: center; color: var(--muted); }
+.props select { width: auto; padding: 3px 6px; }
+.props span { color: var(--text); }
+.section h3 {
+ font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px;
+ display: flex; align-items: center; gap: 8px; font-weight: 600;
+}
+.section h3 .ghost { width: auto; padding: 0 6px; font-size: 12px; text-transform: none; letter-spacing: 0; }
+.desc textarea { min-height: 200px; resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
+.desc .actions { display: flex; gap: 6px; margin-top: 6px; }
+.desc .view { cursor: text; border-radius: 6px; padding: 2px 0; min-height: 24px; }
+.desc .placeholder { color: var(--faint); }
+.comment { border-top: 1px solid var(--border); padding: 10px 0; }
+.comment:first-child { border-top: 0; padding-top: 0; }
+.comment .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
+.comment .who b { color: var(--text); font-weight: 600; }
+.new-comment textarea { min-height: 64px; resize: vertical; }
+.new-comment .actions { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; color: var(--faint); font-size: 12px; }
+
+/* Rendered Markdown */
+.md > :first-child { margin-top: 0; }
+.md > :last-child { margin-bottom: 0; }
+.md p, .md ul, .md ol, .md pre, .md blockquote { margin: 0 0 .6em; }
+.md h1, .md h2, .md h3, .md h4 { margin: .8em 0 .4em; font-size: 15px; }
+.md h1 { font-size: 17px; }
+.md ul, .md ol { padding-left: 1.3em; }
+.md li.check { list-style: none; margin-left: -1.3em; }
+.md code { background: var(--code); border-radius: 4px; padding: 1px 4px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }
+.md pre { background: var(--code); border-radius: 6px; padding: 8px 10px; overflow-x: auto; }
+.md pre code { padding: 0; background: none; }
+.md blockquote { border-left: 3px solid var(--border); padding-left: 10px; color: var(--muted); }
+.md a { color: var(--accent); }
+
+.toast {
+ position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
+ padding: 8px 14px; border-radius: 8px; z-index: 20; box-shadow: 0 4px 16px rgba(0,0,0,.2);
+}
+.offline { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 4px 12px; border-radius: 99px; font-size: 12px; z-index: 20; }
+[hidden] { display: none !important; }
+
+@media (max-width: 700px) {
+ body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
+ aside { border-right: 0; border-bottom: 1px solid var(--border); padding: 8px; }
+ .brand { padding-bottom: 6px; }
+ .nav { flex-direction: row; overflow-x: auto; }
+ .nav .label { display: none; }
+ #new-project-toggle, form.new-project { display: none; }
+ .columns { grid-auto-columns: minmax(78vw, 1fr); padding: 0 12px 12px; }
+ header { padding: 12px; }
+}
+</style>
+</head>
+<body>
+<aside>
+ <div class="brand">
+ <svg viewBox="0 0 16 16" aria-hidden="true"><rect x="1" y="2" width="4" height="12" rx="1" fill="var(--accent)"/><rect x="6" y="2" width="4" height="8" rx="1" fill="var(--accent)" opacity=".7"/><rect x="11" y="2" width="4" height="5" rx="1" fill="var(--accent)" opacity=".4"/></svg>
+ Kanzo
+ </div>
+ <nav class="nav" id="nav"></nav>
+ <button class="ghost" id="new-project-toggle">+ New project</button>
+ <form class="new-project" id="new-project" hidden>
+ <input class="field" name="slug" placeholder="slug, e.g. api" required autocomplete="off" pattern="[a-zA-Z0-9][a-zA-Z0-9\-]{0,31}" title="Letters, digits and -, up to 32">
+ <input class="field" name="name" placeholder="Name (optional)" autocomplete="off">
+ <input class="field" name="repo" placeholder="GitHub owner/repo (optional)" autocomplete="off">
+ <div class="row">
+ <button class="btn primary" type="submit">Create</button>
+ <button class="btn" type="button" id="new-project-cancel">Cancel</button>
+ </div>
+ </form>
+</aside>
+
+<main>
+ <header id="header"></header>
+ <div class="columns" id="columns"></div>
+</main>
+
+<div class="panel" id="panel" aria-hidden="true">
+ <div class="top">
+ <span class="key mono" id="p-key"></span>
+ <span id="p-project"></span>
+ <span class="spacer"></span>
+ <button class="ghost" style="width:auto" id="p-close" title="Close (Esc)">✕</button>
+ </div>
+ <div class="body">
+ <textarea class="title-input" id="p-title" rows="1" spellcheck="false"></textarea>
+ <div class="props">
+ Status <span><select class="field" id="p-status"></select></span>
+ Created <span id="p-created"></span>
+ Updated <span id="p-updated"></span>
+ </div>
+ <div class="section desc">
+ <h3>Description <button class="ghost" id="p-desc-edit">Edit</button></h3>
+ <div class="view md" id="p-desc-view" title="Click to edit"></div>
+ <div id="p-desc-editor" hidden>
+ <textarea class="field" id="p-desc" placeholder="Markdown"></textarea>
+ <div class="actions">
+ <button class="btn primary" id="p-desc-save">Save</button>
+ <button class="btn" id="p-desc-cancel">Cancel</button>
+ </div>
+ </div>
+ </div>
+ <div class="section">
+ <h3>Comments <span class="count" id="p-comment-count"></span></h3>
+ <div id="p-comments"></div>
+ <form class="new-comment" id="p-comment-form">
+ <textarea class="field" id="p-comment" placeholder="Add a comment (Markdown)"></textarea>
+ <div class="actions"><span>⌘↵ to send</span><button class="btn primary" type="submit">Comment</button></div>
+ </form>
+ </div>
+ <div><button class="btn danger" id="p-delete">Delete task</button></div>
+ </div>
+</div>
+
+<div class="offline" id="offline" hidden>Board not reachable — is kanzo running?</div>
+
+<script>
+"use strict";
+
+const $ = (sel, root = document) => root.querySelector(sel);
+const STATUS_COLORS = ["#8a8a83", "#3b82f6", "#e8a317", "#2f9e44", "#ae3ec9", "#e8590c"];
+
+const state = {
+ project: "all", // slug or "all"
+ board: null, // last /api/board reply
+ changes: null, // change counter seen last
+ task: null, // open task id
+ dragging: null, // id of the card being dragged
+ dropped: false, // the current drag ended in a drop
+ layout: "", // key of the rendered column layout
+};
+
+// ---------- helpers ----------
+
+async function api(method, path, body) {
+ const res = await fetch("/api" + path, {
+ method,
+ headers: body ? { "Content-Type": "application/json" } : {},
+ body: body ? JSON.stringify(body) : undefined,
+ });
+ const data = await res.json().catch(() => ({}));
+ if (!res.ok) throw new Error(data.error || res.statusText);
+ return data;
+}
+
+function el(tag, attrs = {}, ...children) {
+ const node = document.createElement(tag);
+ for (const [k, v] of Object.entries(attrs)) {
+ if (v == null || v === false) continue;
+ if (k.startsWith("on")) node.addEventListener(k.slice(2), v);
+ else if (k === "class") node.className = v;
+ else node.setAttribute(k, v === true ? "" : v);
+ }
+ node.append(...children.flat().filter((c) => c != null && c !== false));
+ return node;
+}
+
+let toastTimer;
+function toast(message) {
+ document.querySelector(".toast")?.remove();
+ const t = el("div", { class: "toast" }, message);
+ document.body.append(t);
+ clearTimeout(toastTimer);
+ toastTimer = setTimeout(() => t.remove(), 3500);
+}
+
+function projectColor(slug) {
+ let h = 0;
+ for (const c of slug) h = (h * 31 + c.charCodeAt(0)) % 360;
+ return `hsl(${h} 55% 52%)`;
+}
+
+function statusColor(status) {
+ const i = state.board ? state.board.statuses.indexOf(status) : 0;
+ return STATUS_COLORS[Math.max(i, 0) % STATUS_COLORS.length];
+}
+
+const key = (t) => `${t.project}#${t.id}`;
+
+function parseTime(ts) {
+ return new Date(ts.replace(" ", "T"));
+}
+
+function ago(ts) {
+ const s = (Date.now() - parseTime(ts)) / 1000;
+ if (s < 60) return "just now";
+ if (s < 3600) return `${Math.floor(s / 60)}m ago`;
+ if (s < 86400) return `${Math.floor(s / 3600)}h ago`;
+ if (s < 86400 * 7) return `${Math.floor(s / 86400)}d ago`;
+ return parseTime(ts).toLocaleDateString();
+}
+
+function timeEl(ts) {
+ return el("time", { datetime: ts, title: parseTime(ts).toLocaleString() }, ago(ts));
+}
+
+// ---------- Markdown (small, escapes everything first) ----------
+
+function escapeHtml(s) {
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
+}
+
+function inline(s) {
+ const codes = [];
+ s = s.replace(/`([^`]+)`/g, (_, c) => `\u0000${codes.push(c) - 1}\u0000`);
+ s = s
+ .replace(/\[([^\]]+)\]\(((?:https?:\/\/|mailto:)[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noopener">$1</a>')
+ .replace(/(^|[\s(])(https?:\/\/[^\s<)]+)/g, '$1<a href="$2" target="_blank" rel="noopener">$2</a>')
+ .replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>")
+ .replace(/(^|[^\w*])\*(?!\s)(.+?)\*(?!\w)/g, "$1<em>$2</em>")
+ .replace(/(^|[^\w])_(?!\s)(.+?)_(?!\w)/g, "$1<em>$2</em>")
+ .replace(/~~(.+?)~~/g, "<del>$1</del>");
+ return s.replace(/\u0000(\d+)\u0000/g, (_, i) => `<code>${codes[i]}</code>`);
+}
+
+function markdown(src) {
+ const lines = escapeHtml(src.replace(/\r\n?/g, "\n")).split("\n");
+ const out = [];
+ let para = [];
+ let list = null; // { type: "ul" | "ol", items: [] }
+ const flushPara = () => { if (para.length) out.push(`<p>${inline(para.join("<br>"))}</p>`); para = []; };
+ const flushList = () => {
+ if (!list) return;
+ out.push(`<${list.type}>${list.items.join("")}</${list.type}>`);
+ list = null;
+ };
+ for (let i = 0; i < lines.length; i++) {
+ const line = lines[i];
+ let m;
+ if ((m = line.match(/^\s*```/))) {
+ flushPara(); flushList();
+ const code = [];
+ while (++i < lines.length && !/^\s*```/.test(lines[i])) code.push(lines[i]);
+ out.push(`<pre><code>${code.join("\n")}</code></pre>`);
+ } else if ((m = line.match(/^(#{1,6})\s+(.*)$/))) {
+ flushPara(); flushList();
+ const n = Math.min(m[1].length, 4);
+ out.push(`<h${n}>${inline(m[2])}</h${n}>`);
+ } else if ((m = line.match(/^\s*(?:[-*+]|(\d+)[.)])\s+(.*)$/))) {
+ flushPara();
+ const type = m[1] ? "ol" : "ul";
+ if (list && list.type !== type) flushList();
+ list = list || { type, items: [] };
+ const check = m[2].match(/^\[( |x|X)\]\s+(.*)$/);
+ list.items.push(check
+ ? `<li class="check"><input type="checkbox" disabled ${check[1] === " " ? "" : "checked"}> ${inline(check[2])}</li>`
+ : `<li>${inline(m[2])}</li>`);
+ } else if ((m = line.match(/^&gt;\s?(.*)$/))) {
+ flushPara(); flushList();
+ const quote = [m[1]];
+ while (i + 1 < lines.length && (m = lines[i + 1].match(/^&gt;\s?(.*)$/))) { quote.push(m[1]); i++; }
+ out.push(`<blockquote>${inline(quote.join("<br>"))}</blockquote>`);
+ } else if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(line)) {
+ flushPara(); flushList();
+ out.push("<hr>");
+ } else if (line.trim() === "") {
+ flushPara(); flushList();
+ } else if (list && /^\s{2,}\S/.test(line)) {
+ list.items[list.items.length - 1] = list.items[list.items.length - 1].replace(/<\/li>$/, ` ${inline(line.trim())}</li>`);
+ } else {
+ flushList();
+ para.push(line);
+ }
+ }
+ flushPara(); flushList();
+ return out.join("");
+}
+
+// ---------- board ----------
+
+async function loadBoard() {
+ try {
+ const board = await api("GET", "/board?project=" + encodeURIComponent(state.project));
+ state.board = board;
+ state.changes = board.changes;
+ $("#offline").hidden = true;
+ render();
+ } catch (e) {
+ if (state.project !== "all" && /no project/.test(e.message)) {
+ setProject("all");
+ } else {
+ toast(e.message);
+ }
+ }
+}
+
+// The address is #project or #project/task-id, so a task can be linked to.
+function updateHash() {
+ const hash = "#" + state.project + (state.task ? "/" + state.task : "");
+ if (location.hash !== hash) history.replaceState(null, "", hash);
+}
+
+function readHash() {
+ const [slug, task] = decodeURIComponent(location.hash.slice(1)).split("/");
+ return { slug: slug || null, task: Number(task) || null };
+}
+
+function setProject(slug) {
+ state.project = slug;
+ try { localStorage.setItem("kanzo.project", slug); } catch {}
+ updateHash();
+ state.layout = "";
+ loadBoard();
+}
+
+function render() {
+ renderNav();
+ renderHeader();
+ renderColumns();
+}
+
+function renderNav() {
+ const { projects } = state.board;
+ const open = projects.reduce((n, p) => n + p.open, 0);
+ const link = (slug, name, count, color) =>
+ el("a", { href: "#" + slug, class: state.project === slug ? "active" : null,
+ onclick: (e) => { e.preventDefault(); setProject(slug); } },
+ color ? el("span", { class: "dot", style: `background:${color}` }) : null,
+ el("span", { class: "name" }, name),
+ el("span", { class: "count" }, String(count)));
+ $("#nav").replaceChildren(
+ link("all", "All projects", open),
+ projects.length ? el("div", { class: "label" }, "Projects") : null,
+ ...projects.map((p) => link(p.slug, p.name, p.open, projectColor(p.slug))),
+ );
+}
+
+function currentProject() {
+ return state.board.projects.find((p) => p.slug === state.project) || null;
+}
+
+function renderHeader() {
+ const p = currentProject();
+ const { projects, tasks } = state.board;
+ const header = $("#header");
+ if (!projects.length) { header.replaceChildren(); return; }
+ if (!p) {
+ header.replaceChildren(el("h1", {}, "All projects"),
+ el("span", { class: "sub" }, `${tasks.length} tasks across ${projects.length} projects`));
+ return;
+ }
+ header.replaceChildren(
+ el("h1", {}, p.name),
+ el("span", { class: "sub mono" }, p.slug),
+ p.repo ? el("span", { class: "sub" }, el("a", { href: `https://github.com/${p.repo}`, target: "_blank", rel: "noopener" }, p.repo)) : null,
+ );
+}
+
+function renderColumns() {
+ const { statuses, projects, tasks } = state.board;
+ const columns = $("#columns");
+ if (!projects.length) {
+ state.layout = "";
+ columns.style.display = "flex";
+ columns.replaceChildren(el("div", { class: "empty" },
+ el("h1", {}, "Welcome to Kanzo"),
+ el("p", {}, "Create your first project in the sidebar. Link it to a GitHub repo and agents working in that repo will find it on their own."),
+ el("button", { class: "btn primary", onclick: showNewProject }, "New project")));
+ return;
+ }
+ columns.style.display = "";
+
+ // Build the columns once per layout so a refresh never wipes a half-typed task.
+ const layout = statuses.join(",") + "|" + state.project;
+ if (state.layout !== layout) {
+ state.layout = layout;
+ columns.replaceChildren(...statuses.map((status, i) => {
+ const col = el("section", { class: "column", "data-status": status },
+ el("h2", {}, el("span", { class: "dot", style: `background:${statusColor(status)}` }), status,
+ el("span", { class: "count" })),
+ el("div", { class: "cards" }),
+ );
+ if (i === 0) col.append(addTaskForm());
+ wireDrop(col, col.querySelector(".cards"), status);
+ return col;
+ }));
+ }
+
+ // During a drag the DOM is being moved by hand; refresh once it ends.
+ if (state.dragging) return;
+ const all = state.project === "all";
+ for (const status of statuses) {
+ const col = columns.querySelector(`[data-status="${CSS.escape(status)}"]`);
+ const mine = tasks.filter((t) => t.status === status);
+ col.querySelector("h2 .count").textContent = mine.length ? String(mine.length) : "";
+ col.querySelector(".cards").replaceChildren(...mine.map((t) => card(t, all)));
+ }
+ const select = columns.querySelector(".add select");
+ if (select) fillProjectSelect(select);
+}
+
+function card(t, showProject) {
+ const node = el("div", { class: "card" + (state.task === t.id ? " open" : ""), draggable: "true", "data-id": t.id,
+ onclick: () => openTask(t.id) },
+ el("div", { class: "title" }, t.title),
+ el("div", { class: "meta" },
+ el("span", { class: "mono" }, key(t)),
+ showProject ? el("span", { class: "tag" }, el("span", { class: "dot", style: `background:${projectColor(t.project)}` }), t.project) : null,
+ el("span", { class: "spacer" }),
+ t.description ? el("span", { title: "Has a description" }, "≡") : null,
+ t.comments ? el("span", { title: `${t.comments} comments` }, `💬 ${t.comments}`) : null,
+ ));
+ node.addEventListener("dragstart", (e) => {
+ state.dragging = t.id;
+ e.dataTransfer.effectAllowed = "move";
+ e.dataTransfer.setData("text/plain", String(t.id));
+ requestAnimationFrame(() => node.classList.add("dragging"));
+ });
+ node.addEventListener("dragend", () => {
+ node.classList.remove("dragging");
+ document.querySelectorAll(".drop-line").forEach((d) => d.remove());
+ state.dragging = null;
+ // A drop reloads once the move is saved; a cancelled drag puts the card back.
+ if (!state.dropped) loadBoard();
+ state.dropped = false;
+ });
+ return node;
+}
+
+// The whole column takes drops; cards land in its list.
+function wireDrop(col, list, status) {
+ const line = el("div", { class: "drop-line" });
+ const cardAfter = (y) => {
+ const cards = [...list.querySelectorAll(".card:not(.dragging)")];
+ return cards.find((c) => { const r = c.getBoundingClientRect(); return y < r.top + r.height / 2; }) || null;
+ };
+ col.addEventListener("dragover", (e) => {
+ if (!state.dragging) return;
+ e.preventDefault();
+ e.dataTransfer.dropEffect = "move";
+ const after = cardAfter(e.clientY);
+ if (after) list.insertBefore(line, after); else list.append(line);
+ });
+ col.addEventListener("dragleave", (e) => {
+ if (!col.contains(e.relatedTarget)) line.remove();
+ });
+ col.addEventListener("drop", async (e) => {
+ e.preventDefault();
+ const id = state.dragging;
+ if (!id) return;
+ const after = cardAfter(e.clientY);
+ const dragged = document.querySelector(`.card[data-id="${id}"]`);
+ if (dragged) list.insertBefore(dragged, line.parentNode === list ? line : null);
+ line.remove();
+ state.dropped = true;
+ const before = after ? Number(after.dataset.id) : null;
+ try {
+ await api("POST", `/tasks/${id}/move`, { status, before });
+ if (state.task === id) refreshTask();
+ } catch (err) { toast(err.message); }
+ loadBoard();
+ });
+}
+
+function fillProjectSelect(select) {
+ const { projects } = state.board;
+ const keep = select.value || localStorageGet("kanzo.newTaskProject");
+ select.replaceChildren(...projects.map((p) => el("option", { value: p.slug }, p.name)));
+ if (projects.some((p) => p.slug === keep)) select.value = keep;
+}
+
+function localStorageGet(k) {
+ try { return localStorage.getItem(k); } catch { return null; }
+}
+
+function addTaskForm() {
+ const wrap = el("div", { class: "add" });
+ const toggle = el("button", { class: "ghost", onclick: () => { toggle.hidden = true; form.hidden = false; title.focus(); } }, "+ Add task");
+ const title = el("textarea", { class: "field", placeholder: "Task title", rows: "2" });
+ const select = state.project === "all" ? el("select", { class: "field", title: "Project" }) : null;
+ const close = () => { form.hidden = true; toggle.hidden = false; title.value = ""; };
+ const form = el("form", { hidden: true },
+ title,
+ el("div", { class: "row" },
+ select,
+ el("button", { class: "btn primary", type: "submit" }, "Add"),
+ el("button", { class: "btn", type: "button", onclick: close }, "Cancel")));
+ form.addEventListener("submit", async (e) => {
+ e.preventDefault();
+ const text = title.value.trim();
+ if (!text) return;
+ const project = select ? select.value : state.project;
+ if (!project) { toast("Create a project first"); return; }
+ try {
+ if (select) try { localStorage.setItem("kanzo.newTaskProject", project); } catch {}
+ await api("POST", "/tasks", { project, title: text });
+ title.value = "";
+ title.focus();
+ loadBoard();
+ } catch (err) { toast(err.message); }
+ });
+ title.addEventListener("keydown", (e) => {
+ if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); form.requestSubmit(); }
+ if (e.key === "Escape") { e.stopPropagation(); close(); }
+ });
+ wrap.append(toggle, form);
+ wrap.open = () => toggle.click();
+ return wrap;
+}
+
+// ---------- new project ----------
+
+function showNewProject() {
+ $("#new-project-toggle").hidden = true;
+ $("#new-project").hidden = false;
+ $("#new-project [name=slug]").focus();
+}
+
+function hideNewProject() {
+ $("#new-project").reset();
+ $("#new-project").hidden = true;
+ $("#new-project-toggle").hidden = false;
+}
+
+$("#new-project-toggle").addEventListener("click", showNewProject);
+$("#new-project-cancel").addEventListener("click", hideNewProject);
+$("#new-project").addEventListener("submit", async (e) => {
+ e.preventDefault();
+ const f = new FormData(e.target);
+ try {
+ const p = await api("POST", "/projects", { slug: f.get("slug"), name: f.get("name"), repo: f.get("repo") || null });
+ hideNewProject();
+ setProject(p.slug);
+ } catch (err) { toast(err.message); }
+});
+
+// ---------- task panel ----------
+
+const panel = $("#panel");
+let panelTask = null;
+
+async function openTask(id) {
+ state.task = id;
+ document.querySelectorAll(".card.open").forEach((c) => c.classList.remove("open"));
+ document.querySelector(`.card[data-id="${id}"]`)?.classList.add("open");
+ closeDescEditor();
+ $("#p-comment").value = "";
+ updateHash();
+ await refreshTask();
+ if (state.task !== id) return;
+ panel.classList.add("shown");
+ panel.setAttribute("aria-hidden", "false");
+}
+
+function closeTask() {
+ state.task = null;
+ panelTask = null;
+ updateHash();
+ panel.classList.remove("shown");
+ panel.setAttribute("aria-hidden", "true");
+ document.querySelectorAll(".card.open").forEach((c) => c.classList.remove("open"));
+}
+
+async function refreshTask() {
+ if (!state.task) return;
+ let data;
+ try {
+ data = await api("GET", `/tasks/${state.task}`);
+ } catch (e) {
+ if (/no task/.test(e.message)) { toast("That task was deleted"); closeTask(); }
+ return;
+ }
+ const { task, comments } = data;
+ panelTask = task;
+ $("#p-key").textContent = key(task);
+ $("#p-project").replaceChildren(el("span", { class: "tag" },
+ el("span", { class: "dot", style: `background:${projectColor(task.project)}` }), task.project));
+ const title = $("#p-title");
+ if (document.activeElement !== title) { title.value = task.title; fitTitle(); }
+ const status = $("#p-status");
+ const statuses = state.board ? state.board.statuses : [task.status];
+ status.replaceChildren(...statuses.map((s) => el("option", { value: s }, s)));
+ if (!statuses.includes(task.status)) status.append(el("option", { value: task.status }, task.status));
+ status.value = task.status;
+ $("#p-created").replaceChildren(timeEl(task.created_at));
+ $("#p-updated").replaceChildren(timeEl(task.updated_at));
+ if ($("#p-desc-editor").hidden) renderDesc(task.description);
+ $("#p-comment-count").textContent = comments.length ? String(comments.length) : "";
+ $("#p-comments").replaceChildren(...comments.map((c) => {
+ const body = el("div", { class: "md" });
+ body.innerHTML = markdown(c.body);
+ return el("div", { class: "comment" }, el("div", { class: "who" }, el("b", {}, c.author), " · ", timeEl(c.created_at)), body);
+ }));
+}
+
+function renderDesc(text) {
+ const view = $("#p-desc-view");
+ if (text) view.innerHTML = markdown(text);
+ else view.replaceChildren(el("span", { class: "placeholder" }, "No description. Click to add one."));
+}
+
+function fitTitle() {
+ const t = $("#p-title");
+ t.style.height = "auto";
+ t.style.height = t.scrollHeight + "px";
+}
+
+async function patchTask(fields) {
+ if (!panelTask) return;
+ try {
+ await api("PATCH", `/tasks/${panelTask.id}`, fields);
+ await refreshTask();
+ loadBoard();
+ } catch (e) { toast(e.message); refreshTask(); }
+}
+
+$("#p-close").addEventListener("click", closeTask);
+$("#p-title").addEventListener("input", fitTitle);
+$("#p-title").addEventListener("keydown", (e) => {
+ if (e.key === "Enter") { e.preventDefault(); e.target.blur(); }
+ if (e.key === "Escape") { e.stopPropagation(); e.target.value = panelTask.title; e.target.blur(); }
+});
+$("#p-title").addEventListener("blur", (e) => {
+ const v = e.target.value.trim();
+ if (panelTask && v && v !== panelTask.title) patchTask({ title: v });
+ else if (panelTask) { e.target.value = panelTask.title; fitTitle(); }
+});
+$("#p-status").addEventListener("change", (e) => patchTask({ status: e.target.value }));
+
+function openDescEditor() {
+ $("#p-desc").value = panelTask ? panelTask.description : "";
+ $("#p-desc-view").hidden = true;
+ $("#p-desc-edit").hidden = true;
+ $("#p-desc-editor").hidden = false;
+ $("#p-desc").focus();
+}
+
+function closeDescEditor() {
+ $("#p-desc-editor").hidden = true;
+ $("#p-desc-view").hidden = false;
+ $("#p-desc-edit").hidden = false;
+ if (panelTask) renderDesc(panelTask.description);
+}
+
+$("#p-desc-edit").addEventListener("click", openDescEditor);
+$("#p-desc-view").addEventListener("click", (e) => { if (!e.target.closest("a")) openDescEditor(); });
+$("#p-desc-cancel").addEventListener("click", closeDescEditor);
+$("#p-desc-save").addEventListener("click", async () => {
+ const description = $("#p-desc").value;
+ closeDescEditor();
+ await patchTask({ description });
+});
+$("#p-desc").addEventListener("keydown", (e) => {
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); $("#p-desc-save").click(); }
+ if (e.key === "Escape") { e.stopPropagation(); closeDescEditor(); }
+});
+
+$("#p-comment-form").addEventListener("submit", async (e) => {
+ e.preventDefault();
+ const body = $("#p-comment").value.trim();
+ if (!body || !panelTask) return;
+ try {
+ await api("POST", `/tasks/${panelTask.id}/comments`, { body });
+ $("#p-comment").value = "";
+ await refreshTask();
+ loadBoard();
+ } catch (err) { toast(err.message); }
+});
+$("#p-comment").addEventListener("keydown", (e) => {
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); $("#p-comment-form").requestSubmit(); }
+});
+
+$("#p-delete").addEventListener("click", async () => {
+ if (!panelTask) return;
+ const extra = panelTask.comments ? ` and its ${panelTask.comments} comment${panelTask.comments > 1 ? "s" : ""}` : "";
+ if (!confirm(`Delete ${key(panelTask)}${extra}? This cannot be undone.`)) return;
+ try {
+ await api("DELETE", `/tasks/${panelTask.id}`);
+ closeTask();
+ loadBoard();
+ } catch (err) { toast(err.message); }
+});
+
+// ---------- keyboard, polling, start ----------
+
+document.addEventListener("keydown", (e) => {
+ const typing = e.target.closest("input, textarea, select");
+ if (e.key === "Escape" && state.task && !typing) closeTask();
+ if (e.key === "n" && !typing && !e.metaKey && !e.ctrlKey) {
+ const add = $("#columns .add");
+ if (add) { e.preventDefault(); add.open(); }
+ }
+});
+
+window.addEventListener("hashchange", () => {
+ const { slug, task } = readHash();
+ if ((slug || "all") !== state.project) setProject(slug || "all");
+ if (task && task !== state.task) openTask(task);
+ else if (!task && state.task) closeTask();
+});
+
+// Agents change the board through `kanzo mcp`; a cheap counter tells us when.
+setInterval(async () => {
+ if (document.hidden) return;
+ try {
+ const { changes } = await api("GET", "/changes");
+ $("#offline").hidden = true;
+ if (changes !== state.changes) {
+ state.changes = changes;
+ await loadBoard();
+ if (state.task) refreshTask();
+ }
+ } catch {
+ $("#offline").hidden = false;
+ }
+}, 2000);
+
+// Relative times ("5m ago") drift; refresh them now and then.
+setInterval(() => {
+ document.querySelectorAll("time[datetime]").forEach((t) => { t.textContent = ago(t.getAttribute("datetime")); });
+}, 60000);
+
+{
+ const { slug, task } = readHash();
+ state.project = slug || localStorageGet("kanzo.project") || "all";
+ loadBoard().then(() => { if (task) openTask(task); });
+}
+</script>
+</body>
</html>