import { BACKLOG_SPLIT_SCREEN_TIMEOUT_MS } from "./planning.ts"; import { HUB_DB_BUSY_TIMEOUT_MS } from "./db-timeout.ts"; import { boardColumns } from "../ui/task-board.ts"; import { PEER_PALETTE, peerPaletteThemeCss } from "../ui/peer-palette.ts"; import { PEER_START_RETRY_MS } from "./start-mode.ts"; import { taskProgress } from "../ui/task-progress.ts"; import { officeModel } from "../ui/office-model.ts"; import { OFFICE_PEER_ORDER, ADAPTER_DISPLAY } from "../adapters/registry.ts"; import { needs } from "../ui/needs.ts"; import { roadmapModel } from "../ui/roadmap-model.ts"; import { createHash, randomBytes } from "node:crypto"; import { readFileSync } from "node:fs"; /** What a request's session may do (#269): `settings` while a session opened by `ahub ui --settings` is inside its window. */ export interface DashboardSession { settings: boolean; settingsUntil?: number; liveTest?: true; /** Host-only verified session identity; never browser input or public metadata. */ readonly authorityId?: string } export interface DashboardOptions { snapshot: (after: number, input?: Record, session?: DashboardSession) => unknown | Promise; action: (input: Record, session?: DashboardSession) => unknown | Promise; projects?: () => unknown | Promise; selectedProjectId?: string; /** Injectable clock for expiry tests; production uses wall time. */ now?: () => number; } const TICKET_MS = 60_000; const SESSION_MS = 60 * 60_000; /** How long a session opened by `ahub ui --settings` may change settings that raise authority; it stays an ordinary session after. */ export const SETTINGS_MS = 15 * 60_000; /** The page's view names (index.html DASHBOARD_VIEWS): the only values a snapshot request's `view` may carry to a project hub. */ export const DASHBOARD_VIEWS = ["board", "office", "stream", "agents", "message", "memory", "settings", "roadmap"] as const; export const dashboardView = (value: unknown): typeof DASHBOARD_VIEWS[number] | undefined => (DASHBOARD_VIEWS as readonly unknown[]).includes(value) ? value as typeof DASHBOARD_VIEWS[number] : undefined; const LIMIT = 64; const secret = () => randomBytes(32).toString("hex"); /** The dashboard page with its shared models injected (#935 D2): `ahub ui` serves `html` inlined and hashed, unchanged; the acon * plugin builds its panel from the same `styles` and `script` blocks and the `markup` of the body. */ export function renderDashboard(): { html: string; styles: string[]; markup: string; script: string } { const html = readFileSync(new URL("../ui/index.html", import.meta.url), "utf8") .replace("/* BOARD_MODEL */", () => `const boardColumns = ${boardColumns.toString()}; const peerPalette = ${JSON.stringify(PEER_PALETTE)};`) .replace("/* ADAPTER_DISPLAY */", () => `const adapterDisplay = ${JSON.stringify(ADAPTER_DISPLAY)};`) .replace("/* PEER_PALETTE_CSS */", () => peerPaletteThemeCss()) .replace("/* TASK_PROGRESS_MODEL */", () => `const taskProgress = ${taskProgress.toString()};`) .replace("/* PEER_START_RETRY_MS */", () => `const PEER_START_RETRY_MS = ${PEER_START_RETRY_MS};`) .replace("/* OFFICE_MODEL */", () => `const officeModel = ((OFFICE_PEER_ORDER) => ${officeModel.toString()})(${JSON.stringify(OFFICE_PEER_ORDER)});`) .replace("/* NEEDS_MODEL */", () => `const needs = ${needs.toString()};`) .replace("/* ROADMAP_MODEL */", () => `const roadmapModel = ${roadmapModel.toString()};`); const blocks = (tag: string) => [...html.matchAll(new RegExp(`<${tag}>([\\s\\S]*?)`, "g"))].map((m) => m[1]!); const body = /([\s\S]*)<\/body>/.exec(html)?.[1] ?? ""; return { html, styles: blocks("style"), markup: body.replace(/