A full-featured CRM built with React, shadcn/ui, and Supabase.
feat(harness): render portable session board + opt-in statusline
Jeromeb74928aac853
diff --git a/.claude/hooks/cleanup-session.mjs b/.claude/hooks/cleanup-session.mjsindex 9b7f2aed..59ac3dfd 100755--- a/.claude/hooks/cleanup-session.mjs+++ b/.claude/hooks/cleanup-session.mjs@@ -42,6 +42,12 @@ try {// file lives inside it and logging would recreate it).removeWorktreesUnder(ctx.worktreeBase);rmSync(join(REPO, "test-results"), { recursive: true, force: true });+ // This session's rendered board only (render-status.mjs). Per-session subdir,+ // so a concurrent session's board under .harness/<other-short> is left intact.+ rmSync(join(REPO, ".harness", ctx.sessionShort), {+ recursive: true,+ force: true,+ });rmSync(ctx.worktreeBase, { recursive: true, force: true });} catch (e) {ctx.error(`skipped: ${e?.message ?? e}`);diff --git a/.claude/hooks/render-status.mjs b/.claude/hooks/render-status.mjsnew file mode 100755index 00000000..1ce6a84e--- /dev/null+++ b/.claude/hooks/render-status.mjs@@ -0,0 +1,186 @@+#!/usr/bin/env node+// SubagentStop - render a portable harness board from the session's cheap state+// (tickets, review flags, progress log, live worktrees) into+// <REPO>/.harness/<SESSION_SHORT_ID>/{STATUS.md,TICKETS.md,status.json}.+//+// Why: on the VS Code extension the /tmp worktrees are invisible, and on any+// surface the raw `harness-progress.log` tail drowns the chat. `.harness/` sits+// in the project dir, gitignored, so it shows in the VS Code Explorer AND the+// desktop file browser (which renders Markdown as a formatted preview). The+// developer sees who is doing what without the log tail polluting the chat.+//+// Gated to #technical-harness runs: renders ONLY when the technical-only+// harness-progress.log exists (orchestrator.md writes it under PERSONA: technical),+// so a normal / web-chat run never drops a board into the repo. Per-session+// subdir (SESSION_SHORT_ID) keeps concurrent sessions from colliding. No-op under+// a managed launcher (owns its own UI). Never throws: a view must not break a run.++import {+ existsSync,+ mkdirSync,+ readFileSync,+ readdirSync,+ statSync,+ writeFileSync,+} from "node:fs";+import { join } from "node:path";+import { createHookContext } from "./lib/context.mjs";+import { REPO } from "./lib/paths.mjs";+import { reviewsDir } from "./lib/reviews.mjs";++if (process.env.CHAT_SESSION_DIR) process.exit(0);++let input = {};+try {+ input = JSON.parse(readFileSync(0, "utf8"));+} catch {+ process.exit(0);+}+const ctx = createHookContext(input, "render-status");++const progressLog = join(ctx.sessionDir, "harness-progress.log");+// No technical progress log → not a #technical-harness run → stay inert.+if (!existsSync(progressLog)) process.exit(0);++const WT_RE = /^(TASK-\d+|simple|_session)$/;+const TICKET_RE = /^TASK-\d+\.json$/;++// Tickets live in the session dir itself or a `tickets/` subdir - try both.+function readTickets() {+ for (const dir of [ctx.ticketsDir, ctx.sessionDir]) {+ if (!existsSync(dir)) continue;+ const files = readdirSync(dir).filter((f) => TICKET_RE.test(f));+ if (!files.length) continue;+ return files.sort().map((f) => {+ try {+ const t = JSON.parse(readFileSync(join(dir, f), "utf8"));+ return {+ id: t.id || f.replace(/\.json$/, ""),+ title: t.title || t.description || "",+ status: t.status || "planned",+ acceptanceCriteria: t.acceptance_criteria || [],+ files: t.files_to_modify || [],+ dependencies: t.dependencies || [],+ };+ } catch {+ return {+ id: f.replace(/\.json$/, ""),+ title: "",+ status: "unreadable",+ };+ }+ });+ }+ return [];+}++// A live worktree dir under the session base means work still in flight (the+// merger's cleanup-worktree removes it on merge).+function liveWorktrees() {+ if (!existsSync(ctx.worktreeBase)) return [];+ return readdirSync(ctx.worktreeBase, { withFileTypes: true })+ .filter((d) => d.isDirectory() && WT_RE.test(d.name))+ .map((d) => d.name)+ .sort();+}++const approved = (id) =>+ existsSync(join(reviewsDir(ctx), `${id}-quality-reviewer`));++function recentActivity(max = 25) {+ const lines = readFileSync(progressLog, "utf8")+ .split("\n")+ .filter((l) => l.trim());+ return lines.slice(-max);+}++const cell = (s) => String(s ?? "").replace(/\|/g, "\\|");++function build() {+ const tickets = readTickets();+ const worktrees = liveWorktrees();+ const activeTasks = worktrees.filter((w) => /^TASK-\d+$/.test(w));+ const merged = tickets.filter((t) => t.status === "merged").length;+ const updated = new Date(statSync(progressLog).mtime).toISOString();+ const activity = recentActivity();++ // STATUS.md - the live board.+ const statusMd = [+ `# ⚙ Harness session \`${ctx.sessionShort}\``,+ `_updated ${updated}_`,+ "",+ `**${merged}/${tickets.length} merged** · ${activeTasks.length} in flight`,+ "",+ "## Tickets",+ tickets.length+ ? "| Ticket | Status | Review | Title |"+ : "_no tickets yet_",+ tickets.length ? "|---|---|---|---|" : "",+ ...tickets.map(+ (t) =>+ `| ${t.id} | ${t.status} | ${approved(t.id) ? "✅" : ""} | ${cell(t.title)} |`,+ ),+ "",+ "## Live worktrees",+ worktrees.length+ ? worktrees.map((w) => `- \`${w}\``).join("\n")+ : "_none (nothing in flight)_",+ "",+ "## Recent activity",+ "```",+ ...activity,+ "```",+ "",+ ]+ .filter((l) => l !== "")+ .join("\n");++ // TICKETS.md - full ticket detail for the plan gate.+ const ticketsMd = [+ `# Tickets: session \`${ctx.sessionShort}\``,+ "",+ ...tickets.flatMap((t) => [+ `## ${t.id} · ${t.title}`,+ `- **Status:** ${t.status}${approved(t.id) ? " (reviewed ✅)" : ""}`,+ `- **Depends on:** ${t.dependencies?.length ? t.dependencies.join(", ") : "(none)"}`,+ `- **Files:** ${t.files?.length ? t.files.map((f) => `\`${f}\``).join(", ") : "(none)"}`,+ "- **Acceptance criteria:**",+ ...(t.acceptanceCriteria?.length+ ? t.acceptanceCriteria.map((c) => ` - ${c}`)+ : [" - (none)"]),+ "",+ ]),+ ].join("\n");++ // status.json - compact, for the opt-in statusline.+ const statusJson = {+ short: ctx.sessionShort,+ updated,+ tickets: {+ total: tickets.length,+ merged,+ inProgress: activeTasks.length,+ },+ active: activeTasks.map((task) => ({ task })),+ last: activity[activity.length - 1] || "",+ };++ return { statusMd, ticketsMd, statusJson };+}++try {+ const { statusMd, ticketsMd, statusJson } = build();+ const outDir = join(REPO, ".harness", ctx.sessionShort);+ mkdirSync(outDir, { recursive: true });+ writeFileSync(join(outDir, "STATUS.md"), statusMd);+ writeFileSync(join(outDir, "TICKETS.md"), ticketsMd);+ writeFileSync(+ join(outDir, "status.json"),+ JSON.stringify(statusJson, null, 2),+ );+ ctx.log(`rendered board -> ${outDir}`);+} catch (e) {+ ctx.log(`skipped: ${e?.message ?? e}`);+}++process.exit(0);diff --git a/.claude/hooks/test/cleanup-session.test.mjs b/.claude/hooks/test/cleanup-session.test.mjsindex 3bdeae42..0010d341 100644--- a/.claude/hooks/test/cleanup-session.test.mjs+++ b/.claude/hooks/test/cleanup-session.test.mjs@@ -86,6 +86,19 @@ describe("cleanup-session", () => {expect(existsSync(promoteLock)).toBe(true);});+ test("removes only THIS session's rendered board, leaving other sessions'", () => {+ const { app, run } = setup();+ const mine = join(app, ".harness", SHORT);+ const other = join(app, ".harness", "beef9999");+ mkdirSync(mine, { recursive: true });+ mkdirSync(other, { recursive: true });+ writeFileSync(join(mine, "STATUS.md"), "# mine\n");+ writeFileSync(join(other, "STATUS.md"), "# other\n");+ run();+ expect(existsSync(mine)).toBe(false);+ expect(existsSync(other)).toBe(true);+ });+test("leaves the main repo worktree intact", () => {const { app, run, worktreeList } = setup();run();diff --git a/.claude/hooks/test/render-status.test.mjs b/.claude/hooks/test/render-status.test.mjsnew file mode 100644index 00000000..d4a9cad0--- /dev/null+++ b/.claude/hooks/test/render-status.test.mjs@@ -0,0 +1,140 @@+// Tests for render-status.mjs: the SubagentStop hook that renders a portable+// harness board (STATUS.md / TICKETS.md / status.json) under <REPO>/.harness/<short>+// from the session's cheap state. Uses APP_DIR + HARNESS_TMP_ROOT so the hook+// reads a throwaway repo and a fake session dir, same pattern as the other tests.++import { spawnSync } from "node:child_process";+import {+ existsSync,+ mkdirSync,+ mkdtempSync,+ readFileSync,+ rmSync,+ writeFileSync,+} from "node:fs";+import { tmpdir } from "node:os";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";+import { afterEach, describe, expect, test } from "vitest";++const HERE = dirname(fileURLToPath(import.meta.url));+const HOOK = join(HERE, "..", "render-status.mjs");+const SESSION_ID = "cafe1234-1111-2222-3333-444455556666";+const SHORT = SESSION_ID.split("-")[0];+const sanitize = (p) => p.replace(/\//g, "_");++let TMP = null;+afterEach(() => {+ if (TMP) rmSync(TMP, { recursive: true, force: true });+ TMP = null;+});++// A throwaway repo + a fake session dir populated with the sources the hook reads:+// a technical progress log (the gate), two tickets, one review flag, one live+// worktree dir. `run()` fires the SubagentStop hook.+const setup = ({ withProgressLog = true } = {}) => {+ TMP = mkdtempSync(join(tmpdir(), "render-status-test-"));+ const app = join(TMP, "app");+ const tmpRoot = join(TMP, "wtroot");+ const base = join(tmpRoot, sanitize(app), SESSION_ID);+ mkdirSync(join(base, "tickets"), { recursive: true });+ mkdirSync(join(base, "reviews"), { recursive: true });+ mkdirSync(app, { recursive: true });++ if (withProgressLog) {+ writeFileSync(+ join(base, "harness-progress.log"),+ "12:00:01 plan ready (2 tickets)\n12:03:11 TASK-001 developer DONE\n12:05:42 TASK-001 merged\n",+ );+ }+ writeFileSync(+ join(base, "tickets", "TASK-001.json"),+ JSON.stringify({+ id: "TASK-001",+ title: "Rename the Add contact button",+ status: "merged",+ acceptance_criteria: ["button reads New contact"],+ files_to_modify: ["src/contacts/Button.tsx"],+ dependencies: [],+ }),+ );+ writeFileSync(+ join(base, "tickets", "TASK-002.json"),+ JSON.stringify({+ id: "TASK-002",+ title: "Add a Last activity column",+ status: "planned",+ acceptance_criteria: ["column visible", "sorted desc"],+ files_to_modify: ["src/contacts/List.tsx"],+ dependencies: ["TASK-001"],+ }),+ );+ // TASK-001 reviewed (flag present); TASK-002 still in flight (live worktree).+ writeFileSync(join(base, "reviews", "TASK-001-quality-reviewer"), "");+ mkdirSync(join(base, "TASK-002"), { recursive: true });++ const env = { ...process.env, APP_DIR: app, HARNESS_TMP_ROOT: tmpRoot };+ delete env.CHAT_SESSION_DIR;+ delete env.TICKETS_DIR;+ const run = (extraEnv = {}) =>+ spawnSync("node", [HOOK], {+ input: JSON.stringify({ session_id: SESSION_ID }),+ env: { ...env, ...extraEnv },+ encoding: "utf8",+ });+ const outDir = join(app, ".harness", SHORT);+ return { app, base, outDir, run };+};++describe("render-status", () => {+ test("renders STATUS.md with ticket table, verdict and live worktree", () => {+ const { outDir, run } = setup();+ const r = run();+ expect(r.status).toBe(0);+ const md = readFileSync(join(outDir, "STATUS.md"), "utf8");+ expect(md).toContain(SHORT);+ expect(md).toContain("1/2 merged");+ expect(md).toContain("TASK-001");+ expect(md).toContain("merged");+ expect(md).toContain("✅"); // TASK-001 review flag present+ expect(md).toContain("TASK-002");+ // TASK-002 has a live worktree dir → shown as in flight.+ expect(md).toContain("`TASK-002`");+ // The recent-activity block echoes the progress log.+ expect(md).toContain("TASK-001 merged");+ });++ test("renders TICKETS.md with full per-ticket detail", () => {+ const { outDir, run } = setup();+ run();+ const md = readFileSync(join(outDir, "TICKETS.md"), "utf8");+ expect(md).toContain("## TASK-002 · Add a Last activity column");+ expect(md).toContain("column visible");+ expect(md).toContain("src/contacts/List.tsx");+ expect(md).toContain("Depends on:** TASK-001");+ });++ test("writes status.json with correct counts and active tasks", () => {+ const { outDir, run } = setup();+ run();+ const s = JSON.parse(readFileSync(join(outDir, "status.json"), "utf8"));+ expect(s.short).toBe(SHORT);+ expect(s.tickets).toEqual({ total: 2, merged: 1, inProgress: 1 });+ expect(s.active).toEqual([{ task: "TASK-002" }]);+ expect(s.last).toContain("TASK-001 merged");+ });++ test("is inert when there is no technical progress log", () => {+ const { app, run } = setup({ withProgressLog: false });+ const r = run();+ expect(r.status).toBe(0);+ expect(existsSync(join(app, ".harness"))).toBe(false);+ });++ test("is a no-op under a managed launcher (CHAT_SESSION_DIR set)", () => {+ const { app, run } = setup();+ const r = run({ CHAT_SESSION_DIR: "/tmp/managed-session-xyz" });+ expect(r.status).toBe(0);+ expect(existsSync(join(app, ".harness"))).toBe(false);+ });+});diff --git a/.claude/scripts/harness-statusline.mjs b/.claude/scripts/harness-statusline.mjsnew file mode 100755index 00000000..021d1134--- /dev/null+++ b/.claude/scripts/harness-statusline.mjs@@ -0,0 +1,74 @@+#!/usr/bin/env node+// Claude Code statusLine command: one compact line summarizing the active+// #technical-harness run, read from <REPO>/.harness/<short>/status.json (written+// by the render-status SubagentStop hook). Prints nothing when no harness run is+// active, so it is safe to leave configured. The statusLine payload JSON arrives+// on stdin; we need session_id to find the right session's board.+//+// NOT wired into the committed settings.json on purpose: statusLine is a personal+// choice and a project-level one would override your own global statusline (same+// reasoning as the opt-in concise-dev output style in AGENTS.md). To use it, add+// to your own .claude/settings.local.json:+//+// "statusLine": {+// "type": "command",+// "command": "$CLAUDE_PROJECT_DIR/.claude/scripts/harness-statusline.mjs"+// }+//+// To KEEP your existing statusline as well, point HARNESS_STATUSLINE_BASE at its+// command: this script runs it (same stdin), then appends the harness segment.++import { readFileSync } from "node:fs";+import { join } from "node:path";+import { execSync } from "node:child_process";+import { REPO } from "../hooks/lib/paths.mjs";++let raw = "";+try {+ raw = readFileSync(0, "utf8");+} catch {+ raw = "";+}+let payload = {};+try {+ payload = JSON.parse(raw);+} catch {+ payload = {};+}++const sessionId =+ payload.session_id || process.env.CLAUDE_CODE_SESSION_ID || "";+const short = sessionId.split("-")[0];++// Optional: compose with an existing statusline command.+let prefix = "";+const base = process.env.HARNESS_STATUSLINE_BASE;+if (base) {+ try {+ prefix = execSync(base, { input: raw, encoding: "utf8" }).trim();+ } catch {+ prefix = "";+ }+}++function harnessSegment(shortId) {+ if (!shortId) return "";+ let s;+ try {+ s = JSON.parse(+ readFileSync(join(REPO, ".harness", shortId, "status.json"), "utf8"),+ );+ } catch {+ return "";+ }+ const t = s.tickets || {};+ const parts = [`⚙ ${t.merged ?? 0}/${t.total ?? 0}`];+ const active = (s.active || []).map((a) => `▸${a.task}`).join(" ");+ if (active) parts.push(active);+ if (s.last) parts.push(String(s.last).slice(0, 40));+ return parts.join(" · ");+}++const out = [prefix, harnessSegment(short)].filter(Boolean).join(" ");+// A CLI status command whose job is to print one line to stdout.+if (out) process.stdout.write(out + "\n");diff --git a/.claude/settings.json b/.claude/settings.jsonindex 4923ba4a..d134ba0f 100644--- a/.claude/settings.json+++ b/.claude/settings.json@@ -235,6 +235,16 @@"timeout": 30}]+ },+ {+ "matcher": "developer|simple-developer|test-writer|quality-reviewer|merger|planner|orchestrator",+ "hooks": [+ {+ "type": "command",+ "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/render-status.mjs",+ "timeout": 15+ }+ ]}]},diff --git a/.gitignore b/.gitignoreindex 168883cf..d3bd7e33 100644--- a/.gitignore+++ b/.gitignore@@ -44,6 +44,8 @@ public/r/# Harness scratch (promotion lock; worktrees + test-results also cleaned at SessionEnd).promote.lock+# Rendered per-session harness board (render-status hook; cleaned at SessionEnd)+/.harness/# Playwrightnode_modules/diff --git a/CLAUDE.md b/CLAUDE.mdindex e7f37064..b84c0fdc 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -30,7 +30,7 @@ Off by default. `#harness` (or "use the agent team" / "with the harness") routes`#technical-harness` is the same opt-in for a real developer: it appends a `PERSONA: technical` line (see `orchestrator.md` -> "`PERSONA: technical`"), which (1) uses the full technical register (file paths, `TASK-XXX`, git terms, `database`/`migration`/`Supabase`), (2) reports the mechanical truth (per-ticket status, branches, SHAs, verdicts, ADR paths), (3) stops at `session/<id>` (no promotion, no migration round; you promote and migrate yourself), and (4) appends every step to `<session_dir>/harness-progress.log`.-**Live progress in the chat (technical runs).** The report lands only at the end (possibly as a `task-notification`), so feed the log live: dispatch the orchestrator with `run_in_background: true`, then `Monitor({command: "tail -n +1 -F <session_dir>/harness-progress.log", description: "harness progress", persistent: true})` (real `<session_dir>`; `-F` tolerates a missing file). Do nothing else while it runs. The authoritative end signal is the `task-notification`, not the log: on it, `TaskStop` the monitor, relay the report, and run `/harness-diff` on the session branch it stopped on.+**Live progress (technical runs).** The report lands only at the end (possibly as a `task-notification`), so surface a live view WITHOUT flooding the chat with a raw log tail. The `render-status` SubagentStop hook renders `.harness/<SESSION_SHORT_ID>/{STATUS.md,TICKETS.md,status.json}` (gitignored, per-session, cleaned at SessionEnd) from the live session state after every agent stop. Tell the user to open `.harness/<SESSION_SHORT_ID>/STATUS.md` in a Markdown preview: it lists tickets (status + review verdict), live worktrees (who is working where), and recent activity, and updates itself as agents finish. It renders on the desktop app AND the VS Code extension (it lives in the project dir, not the `/tmp` worktrees), and `TICKETS.md` is the readable plan. An opt-in compact statusline is available (`.claude/scripts/harness-statusline.mjs`; wire it in your own `settings.local.json`, see its header) - not committed, since it would override a personal statusline. Dispatch the orchestrator with `run_in_background: true`. Prefer the board; a raw `Monitor({command: "tail -n +1 -F <session_dir>/harness-progress.log", ...})` terminal feed stays available but noisier. The authoritative end signal is the `task-notification`, not the log: on it, `TaskStop` any monitor, relay the report, and run `/harness-diff` on the session branch it stopped on.## Agents