/** * Hermes Kanban — Dashboard Plugin * * Board view for the multi-agent collaboration board backed by * ~/.hermes/kanban.db. Calls the plugin's backend at /api/plugins/kanban/ * and tails task_events over a WebSocket for live updates. * * Plain IIFE, no build step. Uses window.__HERMES_PLUGIN_SDK__ for React + * shadcn primitives; HTML5 drag-and-drop for card movement on desktop and * a pointer-based fallback for touch. */ (function () { "use strict"; const SDK = window.__HERMES_PLUGIN_SDK__; if (!SDK) return; const { React } = SDK; const h = React.createElement; const { Card, CardContent, Badge, Button, Input, Label, Select, SelectOption, } = SDK.components; const { useState, useEffect, useCallback, useMemo, useRef } = SDK.hooks; const { cn, timeAgo } = SDK.utils; // Order matches BOARD_COLUMNS in plugin_api.py. const COLUMN_ORDER = ["triage", "todo", "ready", "running", "blocked", "done"]; const COLUMN_LABEL = { triage: "Triage", todo: "Todo", ready: "Ready", running: "In Progress", blocked: "Blocked", done: "Done", archived: "Archived", }; const COLUMN_HELP = { triage: "Raw ideas — a specifier will flesh out the spec", todo: "Waiting on dependencies or unassigned", ready: "Assigned and waiting for a dispatcher tick", running: "Claimed by a worker — in-flight", blocked: "Worker asked for human input", done: "Completed", archived: "Archived", }; const COLUMN_DOT = { triage: "hermes-kanban-dot-triage", todo: "hermes-kanban-dot-todo", ready: "hermes-kanban-dot-ready", running: "hermes-kanban-dot-running", blocked: "hermes-kanban-dot-blocked", done: "hermes-kanban-dot-done", archived: "hermes-kanban-dot-archived", }; const DESTRUCTIVE_TRANSITIONS = { done: "Mark this task as done? The worker's claim is released and dependent children become ready.", archived: "Archive this task? It disappears from the default board view.", blocked: "Mark this task as blocked? The worker's claim is released.", }; // Diagnostic kind labels for the events-tab callout. Event kinds emitted // by the kernel get a human-readable header when we detect them in the // events list; add new entries here as new diagnostic event kinds land. const DIAGNOSTIC_EVENT_LABELS = { completion_blocked_hallucination: "⚠ Completion blocked — phantom card ids", suspected_hallucinated_references: "⚠ Prose referenced phantom card ids", }; function isDiagnosticEvent(kind) { return Object.prototype.hasOwnProperty.call(DIAGNOSTIC_EVENT_LABELS, kind); } function phantomIdsFromEvent(ev) { if (!ev || !ev.payload) return []; const p = ev.payload; return p.phantom_cards || p.phantom_refs || []; } function withCompletionSummary(patch, count) { if (!patch || patch.status !== "done") return patch; const label = count && count > 1 ? `${count} selected task(s)` : "this task"; const value = window.prompt( `Completion summary for ${label}. This is stored as the task result.`, "", ); if (value === null) return null; const summary = value.trim(); if (!summary) { window.alert("Completion summary is required before marking a task done."); return null; } return Object.assign({}, patch, { result: summary, summary }); } const API = "/api/plugins/kanban"; const MIME_TASK = "text/x-hermes-task"; // Docs link — surfaced as a `?` icon next to the board switcher and as // `title=` hints on unlabelled controls. Kept in one place so rebrands or // path changes are a single edit. const DOCS_URL = "https://hermes-agent.nousresearch.com/docs/user-guide/features/kanban"; const DOCS_TUTORIAL_URL = "https://hermes-agent.nousresearch.com/docs/user-guide/features/kanban-tutorial"; // localStorage key for the user's selected board. Independent of the // CLI's on-disk ``/kanban/current`` pointer so browser users // can inspect any board without shifting the CLI's active board out // from under a terminal they left open. const LS_BOARD_KEY = "hermes.kanban.selectedBoard"; function readSelectedBoard() { try { const v = window.localStorage.getItem(LS_BOARD_KEY); return (v || "").trim() || null; } catch (_e) { return null; } } function writeSelectedBoard(slug) { try { // Persist the user's dashboard-side board pin even for "default". // Previously this stripped "default" to keep localStorage empty, // but the fetch layer read that absence as "no opinion" and fell // through to the server-side ``current`` file — which the board // switcher also writes. Result: selecting the default tab after // creating a new board with "switch" checked showed the new // board's (wrong) data because the URL omitted ``?board=`` and // the backend happily returned whichever board was "current". // Persisting every selection keeps the dashboard's board opinion // independent of the CLI's active board, which was the original // design intent. Regression: #20879. if (slug) window.localStorage.setItem(LS_BOARD_KEY, slug); else window.localStorage.removeItem(LS_BOARD_KEY); } catch (_e) { /* ignore quota / private mode */ } } function withBoard(url, board) { // Always append ?board= when we have one picked — including // "default". Omitting the param would fall through to the backend's // resolution chain (env var → ``current`` file → default), which // means the dashboard's tab selection gets silently overridden by // whatever board the CLI or "switch" checkbox last activated. // Regression: #20879. if (!board) return url; const sep = url.indexOf("?") >= 0 ? "&" : "?"; return `${url}${sep}board=${encodeURIComponent(board)}`; } // The SDK's Select component fires ``onValueChange(value)`` directly // (it's a shadcn-style popup, not a native