feat(orchestrator): show firewall and hub rules in one table with hits

One rule table replaces the two lists: each allow, ask and deny rule shows its hits from the extracted dry-run matcher, ask patterns the matcher never grants read never granted instead of unused, and the table scrolls in its own container below 600 px. Tests run once on unify/skills-20261114 after the merge (operator order 2026-11-14).

🎯 Fix: 85 %
💥 Break: 10 %
💸 Tokens: 100 %
⏱️ Velocity: 103 %
🛡️ Security: 100 %
🏆 Score: 74
🚦 Gate: ⛔ fix 85 % < 90, break 10 % > 5; velocity 103 % > 100: ask the operator before the commit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-14 21:29:42 +00:00
1 parent 48f26b678a
commit 23a7d2dc1d
9 files changed
+377 -85

No files matched your search

+126 -20
View File
@@ -1,11 +1,20 @@
const FIREWALL_LISTS = {"permissions.allow": "Allow", "permissions.ask": "Ask", "permissions.deny": "Deny", "sandbox.filesystem.allowWrite": "Sandbox: write", "sandbox.filesystem.denyRead": "Sandbox: no read", "sandbox.network.allowedDomains": "Sandbox: domain"};
const LIST_TONES = {allow: "ok", ask: "warn", deny: "bad"};
const ROW_FILTERS = [["allow", "Allow"], ["ask", "Ask"], ["deny", "Deny"], ["sandbox", "Sandbox"], ["signed", "Signed"]];
const ACTION_ORDER = ["deny", "ask", "allow", "sandbox", "signed"];
const ENTRY_HINTS = {
allow: "Claude Code runs a matching call without asking, so it never reaches the ask ledger.",
ask: "Claude Code asks before a matching call; the ask reaches the Agent Orchestrator.",
deny: "Claude Code refuses a matching call, so it never reaches the ask ledger.",
sandbox: "Bounds what a sandboxed command may write, read or reach.",
};
const HUB_SOURCE = "hub";
const SETTINGS_RESULTS = {done: ["written", "ok"], refused: ["refused", "bad"], failed: ["failed", "bad"]};
const EVERY_AGENT = "*";
const TARGET_GONE = "gone";
const TARGET_PICK = "";
const SESSION_KEY = /^(?!-)[A-Za-z0-9_-]{1,128}$/;
const firewall = {data: null, busy: false, staged: {}, dom: null, targets: new Set(), picks: {}};
const firewall = {data: null, busy: false, staged: {}, dom: null, targets: new Set(), picks: {}, shown: new Set(ROW_FILTERS.map(([id]) => id)), open: new Set()};
const knownAgents = () => Object.keys(people()).filter((key) => key !== HUMAN && SESSION_KEY.test(key)).sort();
const firewallGroups = () => (firewall.data ? firewall.data.groups : []);
@@ -270,24 +279,121 @@
drawFirewall();
}
function entryRow(path, list, entry) {
const last = list.split(".").pop();
const tone = Object.hasOwn(LIST_TONES, last) ? LIST_TONES[last] : "neutral";
const editable = Object.hasOwn(FIREWALL_LISTS, list);
return h("li", {"data-entry": entry, "data-list": list}, h("div", {class: "row"}, pill(FIREWALL_LISTS[list] || list, tone), h("code", {}, revealed(entry)), h("span", {class: "spacer"}),
editable ? iconBtn("bi-dash-circle", "Remove", "btn small ghost", () => stageChange(path, {list, op: "remove", entry}), `Remove: stage the removal of ${revealed(entry)} from ${list}`) : null));
/**
* @param {Object} file a settings file as /api/firewall lists it.
* @returns {Object[]} one row per permissions entry and sandbox value: filter, action, tone, tool, pattern, list, entry (null for a sandbox value no list holds), hits and never.
*/
function fileRows(file) {
const permissions = file.groups.flatMap((group) => group.entries.map((entry) => ({filter: entry.list, action: FIREWALL_LISTS[`permissions.${entry.list}`], tone: LIST_TONES[entry.list], tool: group.tool, pattern: entry.spec, list: `permissions.${entry.list}`, entry: entry.entry, hits: entry.hits, never: entry.never})));
const sandbox = file.sandbox.flatMap((entry) => {
const base = {filter: "sandbox", action: FIREWALL_LISTS[entry.key] || "Sandbox", tone: "info", tool: entry.key.replace(/^sandbox\./, ""), list: entry.key, hits: null, never: ""};
return entry.values ? entry.values.map((value) => ({...base, pattern: value, entry: value})) : [{...base, pattern: JSON.stringify(entry.value), entry: null}];
});
return [...permissions, ...sandbox];
}
function fileCard(file) {
const groups = file.groups.map((group) => h("details", {class: "fw-group", open: true, "data-tool": group.tool, "data-prefix": group.prefix},
h("summary", {}, h("strong", {}, group.tool), group.prefix ? h("code", {}, group.prefix) : null, counter(group.entries.length)),
h("ul", {class: "mini"}, group.entries.map((entry) => entryRow(file.path, `permissions.${entry.list}`, entry.entry)))));
const sandbox = file.sandbox.map((entry) => (entry.values
? h("details", {class: "fw-group", "data-key": entry.key}, h("summary", {}, h("strong", {}, entry.key), counter(entry.values.length)), h("ul", {class: "mini"}, entry.values.map((value) => entryRow(file.path, entry.key, value))))
: h("div", {class: "rule-row", "data-key": entry.key}, h("strong", {}, entry.key), h("code", {}, JSON.stringify(entry.value)))));
const status = file.error ? pill(file.error, "bad") : file.exists ? pill(`sha256 ${file.sha256.slice(0, 12)}`, "neutral") : pill("missing: a change creates it", "warn");
return h("section", {class: "fw-file", "data-file": file.path, "aria-label": file.path}, h("div", {class: "row"}, h("code", {class: "fw-path"}, file.path), status),
groups.length ? groups : h("p", {class: "muted"}, "No permission entries."), sandbox.length ? h("h4", {}, "Sandbox") : null, sandbox);
/**
* @returns {Object[]} one row per stored hub rule, with the hits /api/firewall counted for it; pending until the next fetch counts a new rule.
*/
function signedRows() {
const counted = firewall.data.rules;
return state.rules.map((rule) => ({filter: "signed", action: `Grant ${rule.kind}`, tone: "ok", tool: rule.tool, pattern: rule.pattern, rule, ...(Object.hasOwn(counted, rule.id) ? counted[rule.id] : {hits: null, never: "", pending: true})}));
}
const fileStatus = (file) => (file.error ? pill(file.error, "bad") : file.exists ? pill(`sha256 ${file.sha256.slice(0, 12)}`, "neutral") : pill("missing: a change creates it", "warn"));
const byAction = (one, two) => ACTION_ORDER.indexOf(one.filter) - ACTION_ORDER.indexOf(two.filter);
function sourceGroups() {
return [{id: HUB_SOURCE, label: "Hub rules", file: false, status: null, rows: signedRows()}, ...firewall.data.files.map((file) => ({id: file.path, label: file.path, file: true, status: fileStatus(file), rows: fileRows(file)}))];
}
function hitsCell(row) {
if (row.pending) {
return h("span", {class: "muted", title: "Counted with the next refresh"}, "…");
}
if (row.never) {
return h("span", {class: "muted", title: `The matcher never grants a command that ${row.never}`}, `never granted: ${row.never}`);
}
if (row.hits === null) {
return h("span", {class: "muted", title: "Only asks reach the ledger the hits come from"}, "not seen");
}
return row.hits ? h("strong", {}, String(row.hits)) : ["0 ", h("span", {class: "pill", "data-tone": "warn", title: "No ask of the counted days matched this entry"}, "unused")];
}
function actionCell(row) {
const rule = row.rule;
const action = h("span", {class: "pill", "data-tone": row.tone, title: rule ? RULE_HINTS[rule.kind] : ENTRY_HINTS[row.filter]}, row.action);
if (!rule) {
return action;
}
const until = `until ${absolute.format(stampOf(rule.expires))}`;
return [action, rule.expires <= nowSeconds() ? pill("expired", "bad") : null, h("span", {class: "pill", "data-tone": rule.enabled ? "ok" : "neutral", title: until}, rule.enabled ? "active" : "off")];
}
function changeCell(group, row) {
const rule = row.rule;
if (rule) {
return [btn(rule.enabled ? "Turn off" : "Turn on", "btn small", () => changeRule(rule, rule.enabled ? "disable" : "enable")), btn("Delete", "btn small danger", () => {
if (window.confirm("Delete rule?")) {
changeRule(rule, "delete");
}
})];
}
const editable = row.entry !== null && Object.hasOwn(FIREWALL_LISTS, row.list);
return editable ? iconBtn("bi-dash-circle", "Remove", "btn small ghost", () => stageChange(group.id, {list: row.list, op: "remove", entry: row.entry}), `Remove: stage the removal of ${revealed(row.entry)} from ${row.list}`) : null;
}
/**
* @param {Object} group the source the row belongs to: id, label and file, false for the hub rules.
* @param {Object} row a row of fileRows() or signedRows().
* @returns {HTMLTableRowElement} the row: action, tool, pattern, scope, source, hits and its change buttons.
*/
function ruleRow(group, row) {
const rule = row.rule;
const pattern = [h("code", {}, revealed(row.pattern)), rule && rule.kind !== "decision" ? h("span", {class: "muted"}, " in ", h("code", {}, rule.scope ? revealed(rule.scope) : "–")) : null];
const source = rule ? h("span", {class: "muted"}, rule.signed ? "Hub, passkey-signed" : "Hub, unsigned: has no effect") : h("code", {class: "fw-path"}, revealed(group.label));
return h("tr", {"data-filter": row.filter, "data-list": row.list, "data-entry": row.entry, "data-rule": rule ? rule.id : null, "data-unused": row.hits === 0},
h("td", {}, actionCell(row)), h("td", {}, row.tool ? h("code", {}, revealed(row.tool)) : "–"), h("td", {}, pattern),
h("td", {}, rule ? targetPill(rule.agents) : h("span", {class: "muted"}, "file")), h("td", {}, source),
h("td", {class: "fw-hits"}, hitsCell(row)), h("td", {class: "fw-change"}, changeCell(group, row)));
}
function sourceBody(group) {
const rows = group.rows.filter((row) => firewall.shown.has(row.filter)).sort(byAction);
if (!rows.length && group.rows.length) {
return null;
}
const open = firewall.open.has(group.id);
const unused = rows.filter((row) => row.hits === 0).length;
const fold = h("button", {type: "button", class: "fw-fold", "aria-expanded": String(open), on: {click: () => {
if (open) {
firewall.open.delete(group.id);
} else {
firewall.open.add(group.id);
}
drawFirewall();
}}}, icon(open ? "bi-chevron-down" : "bi-chevron-right"), group.file ? h("code", {class: "fw-path"}, revealed(group.label)) : h("strong", {}, group.label), counter(rows.length), unused ? pill(`${unused} unused`, "warn") : null);
return h("tbody", {"data-source": group.id}, h("tr", {class: "fw-source"}, h("th", {colspan: 7, scope: "rowgroup"}, h("div", {class: "row"}, fold, group.status))), open ? rows.map((row) => ruleRow(group, row)) : []);
}
function filterChips() {
return h("div", {class: "chips", role: "group", "aria-label": "Show rules"}, ROW_FILTERS.map(([id, label]) => h("button", {type: "button", class: "chip", "data-filter": id, "aria-pressed": String(firewall.shown.has(id)), on: {click: () => {
if (firewall.shown.has(id)) {
firewall.shown.delete(id);
} else {
firewall.shown.add(id);
}
drawFirewall();
}}}, label)));
}
function ruleTable() {
const bodies = sourceGroups().map(sourceBody).filter(Boolean);
if (!bodies.length) {
return h("p", {class: "muted"}, "No rule matches the chosen chips.");
}
const head = h("thead", {}, h("tr", {}, ["Action", "Tool", "Pattern", "Scope", "Source", `Hits (${firewall.data.days} days)`].map((label) => h("th", {scope: "col"}, label)), h("th", {scope: "col", "aria-label": "Change"})));
return h("div", {class: "fw-table-wrap"}, h("table", {class: "fw-table", "aria-label": "Firewall rules"}, head, bodies));
}
function addForm(files) {
@@ -325,10 +431,10 @@
return h("section", {class: "card"}, h("p", {class: "muted"}, "Loading the settings …"));
}
const files = data.files;
return h("section", {class: "card stack-tight", "aria-label": "Claude settings"}, h("h3", {}, "Claude settings"),
h("p", {class: "muted"}, "Permissions and sandbox entries of the listed settings files, grouped by tool and prefix as the host read them. A change shows as a diff, is signed with your passkey and is written by the host, never by an agent."),
return h("section", {class: "card stack-tight fw-rules", "aria-label": "Firewall rules"}, h("h3", {}, "Firewall rules"),
h("p", {class: "muted"}, `Every rule in one table: the hub rules and the permissions and sandbox entries of the listed settings files as the host read them, one folded group per source. Hits count the asks of the last ${data.days} days a rule matches, with the matcher of the rule request dry run; allow, deny and sandbox entries never reach the ask ledger and show not seen. A settings change shows as a diff, is signed with your passkey and is written by the host, never by an agent.`),
data.error ? h("p", {class: "muted"}, data.error) : null,
files.map(fileCard), files.length ? addForm(files) : null, stagedList());
filterChips(), ruleTable(), files.length ? addForm(files) : null, stagedList());
}
function diffLines(text) {
+14 -25
View File
@@ -14,6 +14,18 @@
return signed ? sendJson(`/api/rules/${encodeURIComponent(rule.id)}/enable`, {proof: signed.proof}) : null;
}
/**
* @param {Object} rule the stored rule.
* @param {string} verb enable, disable or delete.
*/
async function changeRule(rule, verb) {
const result = verb === "enable" ? await turnOn(rule) : await send(`/api/rules/${encodeURIComponent(rule.id)}/${verb}`, "", "application/json");
if (result && !result.ok) {
toast("Rule not changed", fail(result), false);
}
await load();
}
function rulesScreen() {
const kind = h("select", {class: "field", "aria-label": "Kind"}, Object.entries(RULE_KINDS).map(([value, label]) => h("option", {value}, label)));
const target = targetSelect("Applies to", null);
@@ -63,29 +75,6 @@
toast(result.ok ? "Rule created" : "Rule not created", result.ok ? [] : fail(result), result.ok);
await load();
});
const change = async (rule, verb) => {
const result = verb === "enable" ? await turnOn(rule) : await send(`/api/rules/${encodeURIComponent(rule.id)}/${verb}`, "", "application/json");
if (result && !result.ok) {
toast("Rule not changed", fail(result), false);
}
await load();
};
const now = nowSeconds();
const list = state.rules.length ? h("div", {class: "mini"}, state.rules.map((rule) => h("div", {class: "rule-row"},
pill(rule.kind, KIND_TONES[rule.kind]),
targetPill(rule.agents),
rule.tool ? h("code", {}, revealed(rule.tool)) : null,
h("code", {}, revealed(rule.pattern)),
rule.kind === "decision" ? null : h("code", {title: "Directory"}, rule.scope ? revealed(rule.scope) : "–"),
pill(rule.signed ? "signed" : "unsigned: has no effect", rule.signed ? "ok" : "bad"),
rule.expires <= now ? pill("expired", "bad") : h("span", {class: "muted"}, `until ${absolute.format(stampOf(rule.expires))}`),
rule.enabled ? pill("active", "ok") : pill("off", "neutral"),
h("span", {class: "spacer"}),
btn(rule.enabled ? "Turn off" : "Turn on", "btn small", () => change(rule, rule.enabled ? "disable" : "enable")),
btn("Delete", "btn small danger", () => {
if (window.confirm("Delete rule?")) {
change(rule, "delete");
}
})))) : h("p", {class: "muted"}, "No rule yet. Every automatic grant shows up in the stream and can be undone for 3 s.");
return h("div", {class: "stack"}, h("h2", {class: "title"}, "Firewall"), h("h3", {}, "Hub rules for automatic grants"), list, h("div", {class: "card"}, hint, form), ...firewallSections());
const [table, ...rest] = firewallSections();
return h("div", {class: "stack"}, h("h2", {class: "title"}, "Firewall"), table, h("div", {class: "card"}, h("h3", {}, "New hub rule for automatic grants"), hint, form), ...rest);
}
+13 -4
View File
@@ -2,11 +2,20 @@
.fw-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: 10px; align-items: end; }
.fw-form label { display: grid; gap: 4px; min-width: 0; color: var(--muted); font-size: var(--fs-sm); }
.fw-form .field { width: 100%; min-width: 0; }
.fw-file { display: grid; gap: 8px; min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.fw-file > .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.fw-path { overflow-wrap: anywhere; }
.fw-group > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; cursor: pointer; }
.fw-group code, .fw-patterns code { overflow-wrap: anywhere; }
.fw-patterns code { overflow-wrap: anywhere; }
.fw-rules { grid-template-columns: minmax(0, 1fr); }
.fw-table-wrap { min-width: 0; max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.fw-table { width: 100%; min-width: 600px; border-collapse: collapse; font-size: var(--fs-sm); }
.fw-table th, .fw-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.fw-table thead th { background: var(--sunken); color: var(--muted); font-weight: 650; white-space: nowrap; }
.fw-table td { overflow-wrap: anywhere; }
.fw-table td .pill { margin: 0 4px 2px 0; }
.fw-source > th { background: var(--sunken); font-weight: 560; }
.fw-source .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.fw-fold { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; padding: 0; border: 0; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.fw-hits { white-space: nowrap; font-variant-numeric: tabular-nums; }
.fw-change { white-space: nowrap; text-align: right; }
.fw-diff { max-height: 50vh; margin: 4px 0 0; padding: 8px; overflow: auto; border-radius: 8px; background: var(--sunken); font-size: var(--fs-sm); white-space: pre-wrap; overflow-wrap: anywhere; }
.fw-diff .add { color: var(--ok); }
.fw-diff .del { color: var(--bad); }