/** * 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; // useI18n is a hook each component calls locally. Older host dashboards // may not expose it yet; fall back to a shim so the bundle still renders // English against an older host SDK. English fallback strings live // alongside each call site (passed as the third arg of tx()). const useI18n = SDK.useI18n || function () { return { t: { kanban: null }, locale: "en" }; }; // Resolve a translation by dotted path under the kanban namespace // (e.g. "columnLabels.triage"); fall back to the English string passed in. function tx(t, path, fallback, vars) { let node = t && t.kanban; if (node) { const parts = path.split("."); for (let i = 0; i < parts.length; i++) { if (node && typeof node === "object" && parts[i] in node) { node = node[parts[i]]; } else { node = null; break; } } } let str = (typeof node === "string") ? node : fallback; if (vars) { for (const k in vars) { str = str.replace(new RegExp("\\{" + k + "\\}", "g"), vars[k]); } } return str; } // Order matches BOARD_COLUMNS in plugin_api.py. const COLUMN_ORDER = ["triage", "todo", "ready", "running", "blocked", "done"]; // English fallback dictionaries — used when the i18n catalog is missing // a key, and as defaults for the get*() helpers below so callers running // outside any React component (where there's no `t`) still get sane text. const FALLBACK_COLUMN_LABEL = { triage: "Triage", todo: "Todo", ready: "Ready", running: "In Progress", blocked: "Blocked", done: "Done", archived: "Archived", }; const FALLBACK_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 FALLBACK_DESTRUCTIVE = { 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.", }; const FALLBACK_DIAGNOSTIC_EVENT_LABELS = { completion_blocked_hallucination: "⚠ Completion blocked — phantom card ids", suspected_hallucinated_references: "⚠ Prose referenced phantom card ids", }; const DIAGNOSTIC_EVENT_KIND_KEYS = { completion_blocked_hallucination: "completionBlockedHallucination", suspected_hallucinated_references: "suspectedHallucinatedReferences", }; const DESTRUCTIVE_KEYS = { done: "confirmDone", archived: "confirmArchive", blocked: "confirmBlocked", }; function getColumnLabel(t, status) { return tx(t, "columnLabels." + status, FALLBACK_COLUMN_LABEL[status] || status); } function getColumnHelp(t, status) { return tx(t, "columnHelp." + status, FALLBACK_COLUMN_HELP[status] || ""); } function getDestructiveConfirm(t, status) { const key = DESTRUCTIVE_KEYS[status]; if (!key) return null; return tx(t, key, FALLBACK_DESTRUCTIVE[status]); } function getDiagnosticEventLabel(t, kind) { const key = DIAGNOSTIC_EVENT_KIND_KEYS[kind]; if (!key) return null; return tx(t, key, FALLBACK_DIAGNOSTIC_EVENT_LABELS[kind]); } 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", }; function isDiagnosticEvent(kind) { return Object.prototype.hasOwnProperty.call(FALLBACK_DIAGNOSTIC_EVENT_LABELS, kind); } function phantomIdsFromEvent(ev) { if (!ev || !ev.payload) return []; const p = ev.payload; return p.phantom_cards || p.phantom_refs || []; } // Takes an optional `t` so the prompt/alert text is localised. Callers // outside React components can pass null and fall through to English. function withCompletionSummary(patch, count, t) { if (!patch || patch.status !== "done") return patch; const label = count && count > 1 ? `${count} selected task(s)` : "this task"; const value = window.prompt( tx(t, "completionSummary", "Completion summary for {label}. This is stored as the task result.", { label: label }), "", ); if (value === null) return null; const summary = value.trim(); if (!summary) { window.alert(tx(t, "completionSummaryRequired", "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