// --------------------------------------------------------------------------- // automation/HarnessPanel.tsx — the HARNESS tab (owner item 3, rulings R7/R8, // contract C4 · W36-T31). // // Owner, verbatim (2026-08-18): *"For each of the tenant's Agent, I think we need // another tab beside Properties/Run history. This new module under agent is // supposed to host any file pertaining to the agent skills, router etc. So we // build a user can build a custom harness for each agent through the chat // interface."* // // ⛔⛔ R8 IS THE WHOLE SHAPE AND IT IS ENFORCED ON THE SERVER, NOT HERE. Every save // APPENDS a version; there is no overwrite door and no edit-in-place. A ROLL-BACK // IS A WRITE OF AN OLDER BODY, never a delete — so "restore v1" produces v4 whose // `restoredFrom` is 1, and the history keeps v2 and v3 saying what actually // happened rather than what somebody last wanted it to look like. This panel // paints that model; it does not implement it, and it must never offer a control // whose name implies otherwise ("Replace", "Overwrite", "Discard v2"). // // ⛔ R8 IS DELIBERATELY NOT R9, and the two sit one screen apart. An agent-authored // ACTION's config is agent-only (item 8); a harness file is editable by BOTH the // user and the agent. Do not copy either posture onto the other. // // ⚠ THIS PANEL IS THE ONE PLACE THE CAPS ARE VISIBLE. `limits` rides every C4 // payload precisely so a control can say "this file is full" BEFORE a write fails, // and `trimmed` reports the one cap that acts WITHOUT refusing — history older than // `maxVersions` is gone, and a reader who cannot see that would infer the file was // only ever saved twice. Both are rendered, never inferred. // --------------------------------------------------------------------------- import { useCallback, useEffect, useRef, useState } from "react"; import type { HarnessDoc, HarnessFile, HarnessLimits, HarnessProposal } from "./automationApi"; import { approveHarnessProposal, AutomationError, deleteHarness, getHarnessProposal, listHarness, proposeHarnessVersion, readHarness, rejectHarnessProposal, writeHarness, } from "./automationApi"; import "./automation.css"; /** The files a fresh agent is offered, as NAMES only. Nothing is created until somebody saves. */ const SUGGESTED_PATHS = ["skills/router.md", "skills/recurring.md"]; function kb(bytes: number): string { if (bytes < 1024) return `${bytes} bytes`; return `${(bytes / 1024).toFixed(bytes < 10240 ? 1 : 0)} KB`; } /** * `2026-08-18T14:50:09Z` as something a person reads. ⚠ Falls back to the raw string rather than * to an empty cell: an unparseable stamp is still evidence of WHEN, and a blank reads as "never". */ function when(iso: string): string { if (!iso) return ""; const d = new Date(iso); if (Number.isNaN(d.getTime())) return iso; return d.toLocaleString(undefined, { year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", }); } /** Who wrote it, in words. R8's point is that BOTH may, so the answer is always stated. */ const byline = (author: string, kind: string) => `${kind === "agent" ? "the automation" : author || "a person"}`; type HarnessBusy = "" | "open" | "save" | "delete" | "propose" | "approve" | "reject"; /** Pure review state, exported so the exact approval surface can be rendered and inspected. */ export function HarnessProposalReview({ proposal, busy, onApprove, onReject, }: { proposal: HarnessProposal; busy: HarnessBusy; onApprove: () => void; onReject: () => void; }) { return (

{proposal.summary || `Proposed from version ${proposal.baseVersion}.`} {proposal.provider ? ` Model: ${proposal.provider}.` : ""}