feat(webui): bindings dashboard UI; fix app-wide Preact render regression

Completes t2db.8's remaining UI half. Mirrors ui/src/mappings/ exactly:
bindings.jsx (list + editor), binding-editor.jsx (pure StatusPill/
BindingRow), bindings.css, wired into main.jsx's route table with a new
icon. API helpers (bindingCreate/Update/Delete/Approve) added to
api.jsx following the existing mapping* pattern.

CRITICAL FIX, found via real browser verification (AGENTS.md's UI rule),
not by inspection: every JSX-based page in this app -- dashboard, tasks,
logs, captures, mappings, skills, workflows, memory, curators, channels,
settings, and now bindings -- silently rendered the literal text
"[object Object]" instead of its content. Root cause: main.jsx's router
passed each page's Preact VNode into dom.jsx's mount()/append(), which
only knows how to append real DOM Nodes or stringify everything else --
so a VNode object became exactly that string. Confirmed this predates
tonight's work entirely: extracted and served the already-committed
ui/dist bundle in isolation and reproduced the identical failure on the
stock dashboard, unrelated to any change here.

Fix: main.jsx's show() now detects a Preact VNode vs. a real DOM Node
(the unused `soon: true`/comingSoon() fallback) and calls Preact's own
render() for the former, leaving the generic mount() helper and its
other four vanilla-DOM call sites untouched. Verified every single page
renders correctly post-fix via a throwaway, fully-isolated webui.Server
harness (temp SQLite, no real config/forge/network calls) driven by
Playwright -- not assumed from the source diff alone.

Also found and fixed a second real bug the same way: editing a binding
without retyping its secret (the intended "leave blank to keep the
current one" UX, matching UpdateBinding's own documented COALESCE
contract) was rejected with 400, because the API handler validated
edits with the create-time Validate(), which unconditionally required
a full-length secret. Root-cause fix: split Binding.Validate() (create,
unchanged) from a new ValidateForUpdate() (skips the length floor only
when the secret is empty -- preserving the existing one -- still
enforces it on a genuinely-supplied new secret). Full state machine
(draft -> edit -> pending_approval -> approve -> armed -> delete)
verified end-to-end in the browser afterward.

Filed archie-core-mlro separately for the Pill component's pre-existing
duplication across 11 files -- not fixed here, out of scope for this
ticket, following this session's established discipline.
This commit is contained in:
sam committed 2026-09-03 06:17:24 +10:00
1 parent 2e5e5dbc7a
commit 4fa478a2de
9 files changed
+440 -10

No files matched your search

+38
View File
@@ -162,6 +162,44 @@ export const api = {
if (!res.ok) throw new ApiError(await errorMessage(res), res.status);
return res.json();
},
bindings: () => req("/api/bindings"),
bindingCreate: async (binding) => {
const res = await fetch("/api/bindings", {
method: "POST",
headers: { Accept: "application/json", "Content-Type": "application/json", "X-Archie-CSRF": "1" },
body: JSON.stringify(binding),
signal: AbortSignal.timeout(15000),
});
if (!res.ok) throw new ApiError(await errorMessage(res), res.status);
return res.json();
},
bindingUpdate: async (id, binding) => {
const res = await fetch(`/api/bindings/${id}`, {
method: "PATCH",
headers: { Accept: "application/json", "Content-Type": "application/json", "X-Archie-CSRF": "1" },
body: JSON.stringify(binding),
signal: AbortSignal.timeout(15000),
});
if (!res.ok) throw new ApiError(await errorMessage(res), res.status);
return res.json();
},
bindingDelete: async (id) => {
const res = await fetch(`/api/bindings/${id}`, {
method: "DELETE",
headers: { Accept: "application/json", "X-Archie-CSRF": "1" },
signal: AbortSignal.timeout(15000),
});
if (!res.ok) throw new ApiError(await errorMessage(res), res.status);
},
bindingApprove: async (id) => {
const res = await fetch(`/api/bindings/${id}/approve`, {
method: "POST",
headers: { Accept: "application/json", "X-Archie-CSRF": "1" },
signal: AbortSignal.timeout(15000),
});
if (!res.ok) throw new ApiError(await errorMessage(res), res.status);
return res.json();
},
memory: () => req("/api/memory"),
chatSessions: () => req("/api/chat/sessions"),
chatMessages: (id) => req(`/api/chat/sessions/${encodeURIComponent(id)}/messages`),
+1
View File
@@ -19,6 +19,7 @@ const paths = {
curators: '<circle cx="12" cy="12" r="8"/><path d="M12 8v4l3 2"/>',
captures: '<path d="M12 3v11M12 14l-4-4M12 14l4-4"/><path d="M4 14v4a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-4"/>',
mappings: '<circle cx="5" cy="7" r="2"/><circle cx="5" cy="17" r="2"/><circle cx="19" cy="12" r="2"/><path d="M7 7l10 5M7 17l10-5"/>',
bindings: '<rect x="3" y="9" width="8" height="6" rx="2.5"/><rect x="13" y="9" width="8" height="6" rx="2.5"/><path d="M9 12h6"/>',
settings: '<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-2.9 1.2V21a2 2 0 1 1-4 0v-.1A1.7 1.7 0 0 0 7 19.4a1.7 1.7 0 0 0-1.9.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1A1.7 1.7 0 0 0 3 15H3a2 2 0 1 1 0-4h.1A1.7 1.7 0 0 0 4.6 7a1.7 1.7 0 0 0-.3-1.9l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1A1.7 1.7 0 0 0 9 3.6V3a2 2 0 1 1 4 0v.1A1.7 1.7 0 0 0 15 4.6h.1a1.7 1.7 0 0 0 1.9-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.9V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z"/>',
search: '<circle cx="11" cy="11" r="7"/><path d="M20 20l-3.6-3.6"/>',
moon: '<path d="M20 14.5A8.5 8.5 0 0 1 9.5 4a8.5 8.5 0 1 0 10.5 10.5z"/>',
+49
View File
@@ -0,0 +1,49 @@
import { h } from "preact";
/**
* Pure rendering logic for the bindings editor, split out from
* bindings.jsx so it is unit-testable without the page's fetch wiring,
* mirroring mappings/mapping-editor.jsx.
*/
function Pill({ text, kind = "idle" }) {
return <span className={`pill pill-${kind}`}>{text}</span>;
}
const STATUS_LABELS = {
draft: "draft",
pending_approval: "pending approval",
armed: "armed",
};
const STATUS_KINDS = {
draft: "idle",
pending_approval: "warn",
armed: "ok",
};
/** Renders a binding's Status as a labeled pill -- draft/pending_approval/armed. */
export function StatusPill({ status }) {
return <Pill text={STATUS_LABELS[status] || status} kind={STATUS_KINDS[status] || "idle"} />;
}
/** One saved binding's summary row for the bindings list. */
export function BindingRow({ binding: b, onEdit, onApprove, onDelete }) {
const repoPin = b.owner && b.repo ? `${b.owner}/${b.repo}` : "—";
return (
<tr>
<td>{b.name}</td>
<td className="mono">{b.matcher?.source || "—"}</td>
<td>{b.workflow}</td>
<td className="mono">{repoPin}</td>
<td><StatusPill status={b.status} /></td>
<td>
<button className="btn btn-small" type="button" onClick={() => onEdit?.(b)}>Edit</button>
{b.status === "pending_approval" && (
<button className="btn btn-small btn-primary" type="button" onClick={() => onApprove?.(b)}>Approve</button>
)}
<button className="btn btn-small" type="button" onClick={() => onDelete?.(b)}>Delete</button>
</td>
</tr>
);
}
+32
View File
@@ -0,0 +1,32 @@
/* Playbook binding editor: tie a matcher, a field mapping, and a
workflow together, gated by an explicit approval state machine. */
.binding-form {
margin-bottom: var(--sp-4);
padding: var(--sp-4);
}
.binding-form-row {
display: flex;
flex-direction: column;
gap: var(--sp-1);
margin-bottom: var(--sp-3);
font-size: var(--text-sm);
color: var(--fg-subtle);
}
.binding-input,
.binding-select {
padding: var(--sp-2);
border: 1px solid var(--border-strong);
border-radius: var(--radius-sm);
background: var(--bg-raised);
color: var(--fg);
font: inherit;
}
.binding-error {
color: var(--danger, #e5484d);
font-size: var(--text-sm);
margin-bottom: var(--sp-3);
}
+221
View File
@@ -0,0 +1,221 @@
import { h } from "preact";
import { useState, useEffect } from "preact/hooks";
import "./bindings.css";
import { api } from "../base/api.jsx";
import { BindingRow } from "./binding-editor.jsx";
export function Empty({ title, detail }) {
return (
<div className="empty">
<div className="empty-title">{title}</div>
{detail && <div>{detail}</div>}
</div>
);
}
/**
* Playbook bindings (t2db.8): tie a matcher + payload mapping + workflow
* together, with a draft -> pending_approval -> armed state machine so
* nothing self-arms. See docs/architecture/bindings.md and
* docs/prds/payload-field-mapping.md. Owner/Repo optionally pin a
* multi-repo deployment's dispatch target (archie-core-t2db.8's backend
* fix, commit ac42f64).
*/
export function bindingsPage(query) {
return <BindingsApp query={query} />;
}
function emptyEditor() {
return {
id: null,
name: "",
source: "",
mappingId: "",
workflow: "",
owner: "",
repo: "",
secret: "",
actionError: null,
};
}
function BindingsApp({ query }) {
const [bindings, setBindings] = useState([]);
const [mappings, setMappings] = useState([]);
const [workflows, setWorkflows] = useState([]);
const [loadError, setLoadError] = useState(null);
const [editor, setEditor] = useState(null);
const load = async () => {
try {
const [bRes, mRes, wRes] = await Promise.all([api.bindings(), api.mappings(), api.workflows()]);
setBindings(bRes.bindings || []);
setMappings(mRes.mappings || []);
setWorkflows((wRes.definitions || []).filter((d) => d.enabled));
setLoadError(null);
} catch (err) {
setLoadError(String(err.message || err));
}
};
useEffect(() => {
load();
}, []);
const startCreate = () => {
setEditor(emptyEditor());
};
const startEdit = (b) => {
setEditor({
id: b.id,
name: b.name,
source: b.matcher?.source || "",
mappingId: b.mapping_id ? String(b.mapping_id) : "",
workflow: b.workflow || "",
owner: b.owner || "",
repo: b.repo || "",
secret: "",
actionError: null,
});
};
const cancel = () => setEditor(null);
const save = async () => {
const body = {
name: editor.name,
matcher: { source: editor.source },
mapping_id: Number(editor.mappingId) || 0,
workflow: editor.workflow,
owner: editor.owner,
repo: editor.repo,
secret: editor.secret,
};
try {
if (editor.id) {
await api.bindingUpdate(editor.id, body);
} else {
await api.bindingCreate(body);
}
setEditor(null);
await load();
} catch (err) {
setEditor((prev) => ({ ...prev, actionError: String(err.message || err) }));
}
};
const approve = async (b) => {
try {
await api.bindingApprove(b.id);
await load();
} catch (err) {
setLoadError(String(err.message || err));
}
};
const remove = async (b) => {
if (!window.confirm(`Delete binding "${b.name}"?`)) return;
try {
await api.bindingDelete(b.id);
await load();
} catch (err) {
setLoadError(String(err.message || err));
}
};
const renderList = () => (
<div>
<div className="page-head">
<div>
<h1 className="page-title">Playbook bindings</h1>
<p className="page-sub">Tie a matcher, a field mapping, and a workflow together. New and edited bindings need explicit approval before they can fire.</p>
</div>
<div className="page-actions">
<button className="btn btn-primary" type="button" onClick={startCreate}>New binding</button>
</div>
</div>
{loadError ? (
<Empty title="Cannot reach archied" detail={loadError} />
) : bindings.length ? (
<div className="card">
<div className="table-scroll">
<table className="table">
<thead>
<tr>
{["Name", "Source", "Workflow", "Repo pin", "Status", ""].map((h, i) => (
<th key={i}>{h}</th>
))}
</tr>
</thead>
<tbody>
{bindings.map((b) => (
<BindingRow key={b.id} binding={b} onEdit={() => startEdit(b)} onApprove={() => approve(b)} onDelete={() => remove(b)} />
))}
</tbody>
</table>
</div>
</div>
) : (
<Empty title="No bindings yet" detail="Create one from a saved field mapping to turn a captured webhook into a workflow." />
)}
</div>
);
const renderEditor = () => (
<div>
<div className="page-head">
<div>
<h1 className="page-title">{editor.id ? "Edit binding" : "New binding"}</h1>
</div>
<div className="page-actions">
<button className="btn" type="button" onClick={cancel}>Cancel</button>
<button className="btn btn-primary" type="button" onClick={save}>Save</button>
</div>
</div>
{editor.actionError && <div className="binding-error">{editor.actionError}</div>}
<div className="card binding-form">
<label className="binding-form-row">
Name
<input className="binding-input" value={editor.name} onInput={(e) => setEditor((p) => ({ ...p, name: e.target.value }))} />
</label>
<label className="binding-form-row">
Source (the path segment senders POST to, e.g. "sentry")
<input className="binding-input" value={editor.source} onInput={(e) => setEditor((p) => ({ ...p, source: e.target.value }))} />
</label>
<label className="binding-form-row">
Field mapping
<select className="binding-select" value={editor.mappingId} onChange={(e) => setEditor((p) => ({ ...p, mappingId: e.target.value }))}>
<option value="">— pick a saved mapping —</option>
{mappings.map((m) => (
<option key={m.id} value={m.id}>{m.name}</option>
))}
</select>
</label>
<label className="binding-form-row">
Workflow
<select className="binding-select" value={editor.workflow} onChange={(e) => setEditor((p) => ({ ...p, workflow: e.target.value }))}>
<option value="">— pick a workflow —</option>
{workflows.map((w) => (
<option key={w.id} value={w.id}>{w.name}</option>
))}
</select>
</label>
<label className="binding-form-row">
Repo pin -- owner (optional; leave both blank for the single-configured-repo default)
<input className="binding-input" value={editor.owner} onInput={(e) => setEditor((p) => ({ ...p, owner: e.target.value }))} />
</label>
<label className="binding-form-row">
Repo pin -- repo
<input className="binding-input" value={editor.repo} onInput={(e) => setEditor((p) => ({ ...p, repo: e.target.value }))} />
</label>
<label className="binding-form-row">
Shared secret ({editor.id ? "leave blank to keep the current secret" : "senders sign with this via HMAC-SHA256"})
<input className="binding-input" type="password" value={editor.secret} onInput={(e) => setEditor((p) => ({ ...p, secret: e.target.value }))} />
</label>
</div>
</div>
);
return editor ? renderEditor() : renderList();
}
+20 -1
View File
@@ -1,4 +1,5 @@
import "./css/_main.css";
import { render } from "preact";
import { el, mount } from "./base/dom.jsx";
import { icon } from "./base/icons.jsx";
import { dashboardPage } from "./dashboard/dashboard.jsx";
@@ -11,6 +12,7 @@ import { settingsPage } from "./settings/settings.jsx";
import { logsPage } from "./logs/logs.jsx";
import { capturesPage } from "./captures/captures.jsx";
import { mappingsPage } from "./mappings/mappings.jsx";
import { bindingsPage } from "./bindings/bindings.jsx";
import { memoryPage } from "./memory/memory.jsx";
import { chatPage } from "./chat/chat.jsx";
@@ -29,6 +31,7 @@ const routes = [
{ path: "/logs", label: "Logs", icon: "logs", view: logsPage },
{ path: "/captures", label: "Event inspector", icon: "captures", view: capturesPage },
{ path: "/mappings", label: "Field mappings", icon: "mappings", view: mappingsPage },
{ path: "/bindings", label: "Playbook bindings", icon: "bindings", view: bindingsPage },
{ path: "/skills", label: "Skills", icon: "skills", view: skillsPage },
{ path: "/workflows", label: "Workflows", icon: "workflows", view: workflowsPage },
{ path: "/memory", label: "Memory", icon: "memory", view: memoryPage },
@@ -219,7 +222,23 @@ function start() {
toggleChat(true);
return;
}
mount(outlet, route.view ? route.view(new URLSearchParams(query)) : comingSoon(route));
// Every registered page returns a Preact VNode (all views import `h`
// from "preact"), which mount()/append() cannot render -- append()
// only knows real DOM Nodes and strings, so a bare VNode object became
// the literal text "[object Object]". Preact's own render() diffs and
// mounts a VNode correctly, including running the previous page's
// effect-cleanup on unmount. comingSoon() (the `!route.view` fallback,
// currently unused -- no route declares `soon: true`) still returns a
// real DOM Node, so it keeps going through mount() -- render() and
// mount()/replaceChildren() should not alternate on the same outlet
// across navigations, since Preact tracks its own vdom state on the
// container node; if a `soon: true` route is ever added, revisit this.
const rendered = route.view ? route.view(new URLSearchParams(query)) : comingSoon(route);
if (rendered instanceof Node) {
mount(outlet, rendered);
} else {
render(rendered, outlet);
}
// Navigating to a page dismisses the chat drawer; the operator has moved on.
toggleChat(false);
}