Merge branch 'feature/orchestrator-firewall' into unify/skills-20261112-night
# Conflicts: # orchestrator/Dockerfile # orchestrator/kvb_orchestrator/view.py # orchestrator/templates/index.html.j2 # orchestrator/templates/page-cleanup.js # scripts/orchestrator.sh
This commit is contained in:
commit
d364cfe55f
48 files changed
+3438
-106
No files matched your search
@@ -432,6 +432,8 @@ pre.notes { margin: 0; padding: 8px 10px; background: var(--sunken); border-radi
|
||||
{% include "style-ancestry.css" %}
|
||||
|
||||
{% include "style-home.css" %}
|
||||
|
||||
{% include "style-firewall.css" %}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -467,6 +469,7 @@ pre.notes { margin: 0; padding: 8px 10px; background: var(--sunken); border-radi
|
||||
<div class="bubbles" id="bubbles" aria-hidden="true" hidden><div class="bubble-bar"></div></div>
|
||||
<script nonce="{{ nonce }}" id="state" type="application/json">{{ state | tojson }}</script>
|
||||
<script nonce="{{ nonce }}" id="view" type="application/json">{{ view | tojson }}</script>
|
||||
<script nonce="{{ nonce }}" id="emoji-bases" type="application/json">{{ emoji_bases | tojson }}</script>
|
||||
<script nonce="{{ nonce }}">
|
||||
{% include "ambience.js" %}
|
||||
</script>
|
||||
@@ -520,6 +523,8 @@ pre.notes { margin: 0; padding: 8px 10px; background: var(--sunken); border-radi
|
||||
|
||||
{% include "page-state.js" %}
|
||||
|
||||
{% include "page-reveal.js" %}
|
||||
|
||||
{% include "page-dom.js" %}
|
||||
|
||||
{% include "page-api.js" %}
|
||||
@@ -610,6 +615,8 @@ pre.notes { margin: 0; padding: 8px 10px; background: var(--sunken); border-radi
|
||||
|
||||
{% include "page-rules.js" %}
|
||||
|
||||
{% include "page-firewall.js" %}
|
||||
|
||||
{% include "page-keyboard.js" %}
|
||||
|
||||
{% include "page-popup.js" %}
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
edges.push({child: item.branch, parent: item.parent, source: "staged"});
|
||||
}
|
||||
}
|
||||
const plan = Ancestry.layout(repo.branches.map((entry) => ({id: entry.name, label: entry.name})), edges);
|
||||
const plan = Ancestry.layout(repo.branches.map((entry) => ({id: entry.name, label: revealed(entry.name)})), edges);
|
||||
const dropping = (link) => staged.some((item) => item.drop && item.branch === link.child && item.parent === link.parent);
|
||||
return ancestryChart(plan, `Ancestry of ${repo.name}`, {
|
||||
item: `ancestry:${repo.path}`,
|
||||
@@ -109,7 +109,7 @@
|
||||
class: ["ancestry-edge", link.derived ? "derived" : "", link.source === "staged" ? "pending" : "", dropping(link) ? "dropping" : ""].filter(Boolean).join(" "),
|
||||
d, "data-child": link.child, "data-parent": link.parent, "data-source": link.source,
|
||||
on: {click: () => stageParent(repo.path, link.child, link.parent, link.source !== "staged")},
|
||||
}, s("title", {}, `${link.parent} → ${link.child} · ${link.source}`)),
|
||||
}, s("title", {}, revealed(`${link.parent} → ${link.child} · ${link.source}`))),
|
||||
node: (node) => s("g", {
|
||||
class: "node a-branch ancestry-node", transform: `translate(${fixed(node.x)} ${fixed(node.y)})`, tabindex: 0, role: "button", "aria-label": node.label,
|
||||
"data-repo": repo.path, "data-branch": node.id, "data-generation": node.generation,
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
const waits = locked.includes(item);
|
||||
const kept = held.includes(item);
|
||||
return h("li", {class: waits ? "dry-run locked" : kept ? "dry-run held" : "dry-run", "data-token": waits ? "needed" : null, "data-held": kept && entry ? entry.held : null},
|
||||
h("div", {class: "row"}, h("strong", {}, repo ? repo.name : item.repository), h("code", {}, item.branch), waits ? chip("bi-key", "token needed", "warn") : kept ? chip("bi-folder-symlink", "held by a worktree: not deleted here", "neutral") : null),
|
||||
h("pre", {}, (entry ? entry.plan : [`${item.branch} @ ${item.tip.slice(0, 12)}`]).join("\n")));
|
||||
h("div", {class: "row"}, h("strong", {}, revealed(repo ? repo.name : item.repository)), h("code", {}, revealed(item.branch)), waits ? chip("bi-key", "token needed", "warn") : kept ? chip("bi-folder-symlink", "held by a worktree: not deleted here", "neutral") : null),
|
||||
h("pre", {}, (entry ? entry.plan : [`${item.branch} @ ${item.tip.slice(0, 12)}`]).map(revealed).join("\n")));
|
||||
});
|
||||
const outcome = h("div", {class: "mini", "aria-live": "polite"});
|
||||
const confirm = h("button", {type: "button", class: "btn danger", ...named("Delete", "Delete: hand over to the host with your passkey signature")}, icon("bi-trash3"), "Delete");
|
||||
|
||||
@@ -24,15 +24,15 @@
|
||||
function patchRow(row) {
|
||||
const number = row.new || row.old || null;
|
||||
if (row.kind === "hunk") {
|
||||
return h("tr", {class: "hunk"}, h("td", {colspan: 3}), h("td", {class: "code"}, row.text));
|
||||
return h("tr", {class: "hunk"}, h("td", {colspan: 3}), h("td", {class: "code"}, revealed(row.text)));
|
||||
}
|
||||
return h("tr", {class: row.kind, "data-line": number},
|
||||
h("td", {class: "num"}, row.old), h("td", {class: "num"}, row.new), h("td", {class: "sign"}, SIGNS[row.kind] || " "), h("td", {class: "code"}, row.text));
|
||||
h("td", {class: "num"}, row.old), h("td", {class: "num"}, row.new), h("td", {class: "sign"}, SIGNS[row.kind] || " "), h("td", {class: "code"}, revealed(row.text)));
|
||||
}
|
||||
|
||||
function diffBlock(file) {
|
||||
const tone = DIFF_TONES[file.status] || "neutral";
|
||||
const head = [h("span", {class: "letter", "data-tone": tone}, file.status), h("code", {class: "path"}, file.path),
|
||||
const head = [h("span", {class: "letter", "data-tone": tone}, file.status), h("code", {class: "path"}, revealed(file.path)),
|
||||
file.mode && file.mode !== "100644" ? h("code", {class: "mode", title: `mode: ${file.mode}`}, file.mode) : null, h("span", {class: "spacer"}),
|
||||
file.note ? h("span", {class: "note", title: file.note}, icon("bi-eye-slash"), file.note) : null,
|
||||
file.status === "B" ? icon("bi-file-earmark-binary") : h("span", {class: "stat"}, h("span", {class: "add"}, `+${file.additions}`), h("span", {class: "del"}, `-${file.deletions}`))];
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
const status = (value) => pill((STATUS[value] || [value])[0], (STATUS[value] || [value, "neutral"])[1]);
|
||||
const klass = (value) => pill(CLASSES[value] || value, PILLS[value] || "neutral");
|
||||
const counter = (value) => h("span", {class: "count"}, String(value));
|
||||
const meta = (pairs) => h("dl", {class: "meta"}, pairs.map(([label, value, title]) => h("div", {}, h("dt", {}, label), h("dd", {}, h("code", {title: title || null}, dash(value))))));
|
||||
const meta = (pairs) => h("dl", {class: "meta"}, pairs.map(([label, value, title]) => h("div", {}, h("dt", {}, label), h("dd", {}, h("code", {title: title ? revealed(title) : null}, revealed(dash(value)))))));
|
||||
const emptyState = (title, text) => h("div", {class: "empty"}, h("div", {class: "empty-mark", "aria-hidden": "true"}), h("h2", {}, title), h("p", {}, text));
|
||||
const live = () => ui.preset !== -1 && ui.asOf === null;
|
||||
const alarmRows = () => state.radio.filter((row) => (row.class === "mayday" || row.class === "pan-pan") && row.ts >= state.alarm_since).reverse();
|
||||
@@ -89,7 +89,7 @@
|
||||
s("title", {}, PRESENCE[value][0]), s("rect", {class: "presence-dot", x: fixed(-size * 0.65), y: fixed(-size * 0.65), width: fixed(size * 1.3), height: fixed(size * 1.3), rx: fixed(size * 0.65)}),
|
||||
s("g", {class: "glyph"}, s("use", {href: `#${PRESENCE[value][1]}`, x: fixed(-size / 2), y: fixed(-size / 2), width: fixed(size), height: fixed(size)}))) : null;
|
||||
};
|
||||
const person = (name) => (name && name !== "-" && name !== "all" && name !== HUMAN ? h("button", {type: "button", class: "linkish", title: `Open ${name}`, on: {click: () => openAgent(name)}}, name) : dash(name));
|
||||
const person = (name) => (name && name !== "-" && name !== "all" && name !== HUMAN ? h("button", {type: "button", class: "linkish", title: revealed(`Open ${name}`), on: {click: () => openAgent(name)}}, revealed(name)) : dash(name));
|
||||
const people = () => state.people || {};
|
||||
const labelOf = (key) => (people()[key] || {name: String(key).replace(/^name:/, "")}).name;
|
||||
const nameOf = (key) => (people()[key] || {now: String(key).replace(/^name:/, "")}).now;
|
||||
@@ -147,8 +147,9 @@
|
||||
|
||||
function openSheet(title, body, wide) {
|
||||
const sheet = document.getElementById("sheet");
|
||||
sheet.replaceChildren(h("div", {class: `sheet-box${wide ? " wide" : ""}`, role: "dialog", "aria-modal": "true", "aria-label": title},
|
||||
h("div", {class: "sheet-head"}, h("h2", {class: "panel-title"}, title), h("span", {class: "spacer"}), iconBtn("bi-x-lg", "Close", "btn small ghost", closeSheet)),
|
||||
const shown = revealed(title);
|
||||
sheet.replaceChildren(h("div", {class: `sheet-box${wide ? " wide" : ""}`, role: "dialog", "aria-modal": "true", "aria-label": shown},
|
||||
h("div", {class: "sheet-head"}, h("h2", {class: "panel-title"}, shown), h("span", {class: "spacer"}), iconBtn("bi-x-lg", "Close", "btn small ghost", closeSheet)),
|
||||
h("div", {class: "sheet-body"}, body)));
|
||||
sheet.hidden = false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,384 @@
|
||||
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 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 knownAgents = () => Object.keys(people()).filter((key) => key !== HUMAN && SESSION_KEY.test(key)).sort();
|
||||
const firewallGroups = () => (firewall.data ? firewall.data.groups : []);
|
||||
const settingsFile = (path) => (firewall.data ? firewall.data.files.find((file) => file.path === path) : null);
|
||||
const everyAgent = (agents) => !agents || (agents.length === 1 && agents[0] === EVERY_AGENT);
|
||||
const groupOf = (agents) => firewallGroups().find((entry) => entry.members.join(",") === [...agents].sort().join(","));
|
||||
const firewallPickOf = (key) => (Object.hasOwn(firewall.picks, key) ? firewall.picks[key] : TARGET_PICK);
|
||||
|
||||
function targetLabel(agents) {
|
||||
if (everyAgent(agents)) {
|
||||
return "all agents";
|
||||
}
|
||||
const group = groupOf(agents);
|
||||
return revealed(group ? `group ${group.name}` : agents.map(labelOf).join(", "));
|
||||
}
|
||||
|
||||
const signedMembers = (agents) => agents.map((key) => `${labelOf(key)} (${key})`).join(", ");
|
||||
|
||||
/**
|
||||
* @param {string[]} agents the session ids a payload is signed for.
|
||||
* @returns {string} the scope the passkey prompt names with every session id the signature covers: for all agents, for group X: A (s1), B (s2), for agent A (s1) or for agents A (s1), B (s2).
|
||||
*/
|
||||
function scopeLabel(agents) {
|
||||
if (everyAgent(agents)) {
|
||||
return "for all agents";
|
||||
}
|
||||
const group = groupOf(agents);
|
||||
return group ? `for group ${group.name}: ${signedMembers(agents)}` : `for ${agents.length === 1 ? "agent" : "agents"} ${signedMembers(agents)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} rule a rule as signed: kinds, tool, pattern, scope, expires in epoch seconds and agents.
|
||||
* @returns {string[]} the lines the passkey prompt shows for it: what it grants, in which directory, until when and for which sessions.
|
||||
*/
|
||||
function ruleLines(rule) {
|
||||
const end = new Date(rule.expires * 1000).toISOString().slice(0, 16).replace("T", " ");
|
||||
const days = (Math.max(rule.expires - nowSeconds(), 0) / DAY).toFixed(1);
|
||||
return [`${rule.kinds.join(", ")}${rule.tool ? ` ${rule.tool}` : ""}: ${rule.pattern}`, `in ${rule.scope}`, `until ${end} UTC, in ${days} days`, scopeLabel(Object.hasOwn(rule, "agents") ? rule.agents : [EVERY_AGENT])];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} label what the operator signs.
|
||||
* @param {Object} prepared the hub's offer: payload, the signed rule itself or an approval, and enables, the signed rule an approval turns on.
|
||||
* @returns {string} the passkey prompt's text, with every line of ruleLines() for the rule that takes effect, each line through revealed().
|
||||
*/
|
||||
function promptText(label, prepared) {
|
||||
const rule = prepared.payload && prepared.payload.kind === "rule" ? prepared.payload : prepared.enables;
|
||||
return [label, ...(rule ? ruleLines(rule) : [])].map(revealed).join("\n");
|
||||
}
|
||||
|
||||
const targetPill = (agents) => h("span", {class: "pill", "data-tone": "neutral", "data-agents": JSON.stringify(agents === undefined ? [EVERY_AGENT] : agents), title: "Applies to"}, targetLabel(agents));
|
||||
|
||||
function targetOptions(keyed) {
|
||||
return [
|
||||
...(keyed ? [h("option", {value: TARGET_PICK, disabled: true}, "Pick a target")] : []),
|
||||
h("option", {value: "all"}, "All agents"),
|
||||
...knownAgents().map((key) => h("option", {value: `agent:${key}`}, revealed(`Agent ${labelOf(key)}`))),
|
||||
...firewallGroups().map((group) => h("option", {value: `group:${group.id}`}, revealed(`Group ${group.name}`))),
|
||||
];
|
||||
}
|
||||
|
||||
function fillTargets(select) {
|
||||
const keyed = "targetKey" in select.dataset;
|
||||
const value = keyed ? firewallPickOf(select.dataset.targetKey) : select.value;
|
||||
select.replaceChildren(...targetOptions(keyed));
|
||||
const gone = value !== TARGET_PICK && ![...select.options].some((option) => option.value === value);
|
||||
if (gone) {
|
||||
select.append(h("option", {value: TARGET_GONE, disabled: true}, "Target gone: pick again"));
|
||||
select.value = TARGET_GONE;
|
||||
} else if (value !== TARGET_PICK || keyed) {
|
||||
select.value = value;
|
||||
}
|
||||
const waiting = keyed && value === TARGET_PICK;
|
||||
select.setCustomValidity(gone ? "The chosen group or agent is gone: pick the target again" : waiting ? "Pick a target first" : "");
|
||||
const scope = select.form || select.parentElement;
|
||||
for (const button of scope ? scope.querySelectorAll("[data-sign]") : []) {
|
||||
button.disabled = (gone || waiting) && !select.disabled;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} label the select's accessible name.
|
||||
* @param {string|null} key the rule set whose pick the page keeps across redraws, with no default until the operator picks; null for a select that starts on all agents.
|
||||
* @returns {HTMLSelectElement} the target select.
|
||||
*/
|
||||
function targetSelect(label, key) {
|
||||
const select = h("select", {class: "field", "aria-label": label, "data-target-key": key});
|
||||
fillTargets(select);
|
||||
select.addEventListener("change", () => {
|
||||
if (key !== null) {
|
||||
firewall.picks[key] = select.value;
|
||||
}
|
||||
fillTargets(select);
|
||||
});
|
||||
firewall.targets.add(select);
|
||||
return select;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} value the target select's value: all, agent:<session>, group:<id> or gone.
|
||||
* @returns {string[]|null} the sorted session ids the rule is signed for, ["*"] only for all, null for a gone or unknown target.
|
||||
*/
|
||||
function agentsOf(value) {
|
||||
if (value.startsWith("agent:")) {
|
||||
return [value.slice("agent:".length)];
|
||||
}
|
||||
if (value.startsWith("group:")) {
|
||||
const group = firewallGroups().find((entry) => entry.id === value.slice("group:".length));
|
||||
return group ? group.members : null;
|
||||
}
|
||||
return value === "all" ? [EVERY_AGENT] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} kind the rule kind; a review rule always applies to every agent.
|
||||
* @param {string} value the target select's value.
|
||||
* @returns {string[]|null} the agents to sign; null for a group that is gone, which the hub refuses.
|
||||
*/
|
||||
const ruleAgents = (kind, value) => (kind === "review" ? [EVERY_AGENT] : agentsOf(value));
|
||||
|
||||
async function fetchFirewall() {
|
||||
if (firewall.busy) {
|
||||
return;
|
||||
}
|
||||
firewall.busy = true;
|
||||
try {
|
||||
const response = await fetch("/api/firewall", {cache: "no-store"});
|
||||
if (response.ok) {
|
||||
firewall.data = await response.json();
|
||||
}
|
||||
} catch {
|
||||
ui.offline = true;
|
||||
}
|
||||
firewall.busy = false;
|
||||
drawFirewall();
|
||||
}
|
||||
|
||||
function drawFirewall() {
|
||||
const dom = firewall.dom;
|
||||
if (!dom || !dom.settings.isConnected) {
|
||||
return;
|
||||
}
|
||||
for (const select of [...firewall.targets]) {
|
||||
if (select.isConnected) {
|
||||
fillTargets(select);
|
||||
} else {
|
||||
firewall.targets.delete(select);
|
||||
}
|
||||
}
|
||||
for (const node of document.querySelectorAll("#main [data-agents]")) {
|
||||
node.textContent = targetLabel(JSON.parse(node.dataset.agents));
|
||||
}
|
||||
dom.groups.replaceChildren(groupsCard());
|
||||
dom.sets.replaceChildren(setsCard());
|
||||
dom.patterns.replaceChildren(patternsCard());
|
||||
dom.settings.replaceChildren(settingsCard());
|
||||
}
|
||||
|
||||
function firewallSections() {
|
||||
firewall.dom = {groups: h("div", {}), sets: h("div", {}), patterns: h("div", {}), settings: h("div", {})};
|
||||
window.setTimeout(() => {
|
||||
drawFirewall();
|
||||
fetchFirewall();
|
||||
}, 0);
|
||||
return [firewall.dom.settings, firewall.dom.groups, firewall.dom.sets, firewall.dom.patterns];
|
||||
}
|
||||
|
||||
async function firewallPost(path, payload, label) {
|
||||
const result = await sendJson(path, payload);
|
||||
toast(result.ok ? label : `${label}: not possible`, result.ok ? [] : fail(result), result.ok);
|
||||
await fetchFirewall();
|
||||
return result.ok;
|
||||
}
|
||||
|
||||
function groupsCard() {
|
||||
const name = h("input", {class: "field", type: "text", placeholder: "builders", "aria-label": "Group name"});
|
||||
const members = h("select", {class: "field", multiple: true, size: Math.min(Math.max(knownAgents().length, 2), 6), "aria-label": "Members"}, knownAgents().map((key) => h("option", {value: key}, labelOf(key))));
|
||||
const form = h("form", {class: "fw-form", "aria-label": "New agent group"}, h("label", {}, "Name", name), h("label", {}, "Members", members),
|
||||
h("button", {type: "submit", class: "btn soft", ...named("Add group", "Add group: name the chosen agents as one rule target")}, icon("bi-people"), "Add group"));
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const chosen = [...members.selectedOptions].map((option) => option.value).sort();
|
||||
await firewallPost("/api/firewall/groups", {name: name.value.trim(), members: chosen}, "Group added");
|
||||
});
|
||||
const rows = firewallGroups().map((group) => h("div", {class: "rule-row", "data-group": group.name}, h("strong", {}, revealed(group.name)), h("span", {class: "muted"}, revealed(group.members.map(labelOf).join(", "))), h("span", {class: "spacer"}),
|
||||
iconBtn("bi-trash3", "Delete group", "btn small danger", () => firewallPost(`/api/firewall/groups/${encodeURIComponent(group.id)}/delete`, {}, "Group deleted"), `Delete group ${group.name}: rules signed for it keep their agents`)));
|
||||
return h("section", {class: "card stack-tight", "aria-label": "Agent groups"}, h("h3", {}, "Agent groups"),
|
||||
h("p", {class: "muted"}, "A rule applies to one agent, a group or all agents. A group's members are signed into each rule when you sign it."),
|
||||
rows.length ? h("div", {class: "mini"}, rows) : h("p", {class: "muted"}, "No group yet."), form);
|
||||
}
|
||||
|
||||
function setsCard() {
|
||||
const name = h("input", {class: "field", type: "text", placeholder: "ci", "aria-label": "Set name"});
|
||||
const days = h("input", {class: "field", type: "number", min: 1, max: 366, value: 7, "aria-label": "Days"});
|
||||
const chosen = h("select", {class: "field", multiple: true, size: Math.min(Math.max(state.rules.length, 2), 6), "aria-label": "Rules"}, state.rules.map((rule) => h("option", {value: rule.id}, `${rule.kind} ${rule.tool} ${rule.pattern}`.replace(" ", " "))));
|
||||
const form = h("form", {class: "fw-form", "aria-label": "New rule set"}, h("label", {}, "Name", name), h("label", {}, "Days", days), h("label", {}, "Rules", chosen),
|
||||
h("button", {type: "submit", class: "btn soft", ...named("Save set", "Save set: keep the chosen rules as one named rule set")}, icon("bi-collection"), "Save set"));
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
await firewallPost("/api/firewall/sets", {name: name.value.trim(), days: Number(days.value), rules: [...chosen.selectedOptions].map((option) => option.value)}, "Rule set saved");
|
||||
});
|
||||
const sets = firewall.data ? firewall.data.sets : [];
|
||||
const rows = sets.map((set) => setRow(set));
|
||||
return h("section", {class: "card stack-tight", "aria-label": "Rule sets"}, h("h3", {}, "Rule sets"),
|
||||
h("p", {class: "muted"}, "Take a set over as a whole for one agent, a group or all agents: each of its rules is signed with your passkey for that target."),
|
||||
rows.length ? h("div", {class: "mini"}, rows) : h("p", {class: "muted"}, "No rule set yet."), form);
|
||||
}
|
||||
|
||||
function setRow(set) {
|
||||
const target = targetSelect(`Take over ${set.name} for`, set.id);
|
||||
const take = h("button", {type: "button", class: "btn small soft", "data-sign": "", ...named("Take over", `Take over: sign the ${set.rules.length} rules of ${set.name} for the chosen agents`)}, icon("bi-box-arrow-in-down"), "Take over");
|
||||
take.addEventListener("click", async () => {
|
||||
take.disabled = true;
|
||||
await takeOver(set, agentsOf(target.value));
|
||||
fillTargets(target);
|
||||
});
|
||||
const row = h("div", {class: "rule-row", "data-set": set.name}, h("strong", {}, revealed(set.name)), h("span", {class: "muted"}, `${set.rules.length} rules, ${set.days} days`), h("span", {class: "spacer"}), target, take,
|
||||
iconBtn("bi-trash3", "Delete set", "btn small danger", () => firewallPost(`/api/firewall/sets/${encodeURIComponent(set.id)}/delete`, {}, "Rule set deleted"), `Delete set ${set.name}: its signed rules stay`));
|
||||
fillTargets(target);
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} set the rule set to take over: name, days and rules.
|
||||
* @param {string[]|null} agents the target from agentsOf().
|
||||
*/
|
||||
async function takeOver(set, agents) {
|
||||
if (!agents) {
|
||||
toast(`${set.name}: not taken over`, ["No target picked, or the picked group or agent is gone"], false);
|
||||
return;
|
||||
}
|
||||
const expires = Math.floor(nowSeconds()) + set.days * DAY;
|
||||
let created = 0;
|
||||
for (const rule of set.rules) {
|
||||
const prepared = await sendJson("/api/rules/sign", {...rule, expires, agents: rule.kind === "review" ? [EVERY_AGENT] : agents});
|
||||
const signed = prepared.ok && prepared.data ? await assertion(prepared.data, `Rule set ${set.name}`) : null;
|
||||
const result = signed ? await sendJson("/api/rules", {rule: prepared.data.payload, assertion: signed, enabled: true}) : prepared;
|
||||
created += signed && result.ok ? 1 : 0;
|
||||
}
|
||||
toast(`${set.name}: ${created} of ${set.rules.length} rules signed for ${targetLabel(agents)}`, [], created === set.rules.length);
|
||||
await load();
|
||||
}
|
||||
|
||||
function patternsCard() {
|
||||
const patterns = firewall.data ? firewall.data.patterns : [];
|
||||
return h("section", {class: "card stack-tight", "aria-label": "Never granted"}, h("h3", {}, "Never granted by a rule"),
|
||||
h("p", {class: "muted"}, "An ask rule never grants a command that matches one of these patterns; Claude Code asks instead."),
|
||||
h("ul", {class: "mini fw-patterns"}, patterns.map((pattern) => h("li", {}, h("div", {class: "row"}, pill(pattern.label, "bad"), h("code", {}, pattern.pattern))))));
|
||||
}
|
||||
|
||||
function stageChange(path, change) {
|
||||
const changes = (firewall.staged[path] || []).filter((entry) => !(entry.list === change.list && entry.entry === change.entry));
|
||||
firewall.staged[path] = [...changes, change];
|
||||
drawFirewall();
|
||||
}
|
||||
|
||||
function unstageChange(path, change) {
|
||||
firewall.staged[path] = (firewall.staged[path] || []).filter((entry) => entry !== change);
|
||||
if (!firewall.staged[path].length) {
|
||||
delete firewall.staged[path];
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function addForm(files) {
|
||||
const file = h("select", {class: "field", "aria-label": "Settings file"}, files.map((entry) => h("option", {value: entry.path}, entry.path)));
|
||||
const list = h("select", {class: "field", "aria-label": "List"}, Object.entries(FIREWALL_LISTS).map(([value, label]) => h("option", {value}, `${label} (${value})`)));
|
||||
const entry = h("input", {class: "field", type: "text", placeholder: "Bash(make test:*)", "aria-label": "Entry"});
|
||||
const form = h("form", {class: "fw-form", "aria-label": "Stage a settings change"}, h("label", {}, "File", file), h("label", {}, "List", list), h("label", {}, "Entry", entry),
|
||||
h("button", {type: "submit", class: "btn soft", ...named("Stage", "Stage: add the entry to the list; nothing is written before you sign")}, icon("bi-plus-lg"), "Stage"));
|
||||
form.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
if (entry.value.trim()) {
|
||||
stageChange(file.value, {list: list.value, op: "add", entry: entry.value.trim()});
|
||||
}
|
||||
});
|
||||
return form;
|
||||
}
|
||||
|
||||
const settingsItems = () => Object.entries(firewall.staged).filter(([file]) => settingsFile(file)).map(([file, changes]) => ({kind: "settings", file, base: settingsFile(file).sha256, changes}));
|
||||
|
||||
function stagedList() {
|
||||
const rows = Object.entries(firewall.staged).flatMap(([path, changes]) => changes.map((change) => h("li", {"data-staged": `${change.op} ${change.entry}`}, h("div", {class: "row"},
|
||||
pill(change.op === "add" ? "add" : "remove", change.op === "add" ? "ok" : "bad"), h("code", {}, revealed(`${change.list}: ${change.entry}`)), h("span", {class: "muted"}, revealed(path)), h("span", {class: "spacer"}),
|
||||
iconBtn("bi-x-circle", "Unstage", "btn small ghost", () => unstageChange(path, change), "Unstage: drop this change")))));
|
||||
if (!rows.length) {
|
||||
return h("p", {class: "muted"}, "No staged change.");
|
||||
}
|
||||
const review = h("button", {type: "button", class: "btn primary", ...named("Review and sign", "Review and sign: show the diff, then sign it with your passkey")}, icon("bi-file-diff"), "Review and sign");
|
||||
review.addEventListener("click", reviewSettings);
|
||||
return h("div", {class: "stack-tight"}, h("ul", {class: "mini", "aria-label": "Staged changes"}, rows), h("div", {class: "actions"}, review));
|
||||
}
|
||||
|
||||
function settingsCard() {
|
||||
const data = firewall.data;
|
||||
if (!data) {
|
||||
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."),
|
||||
data.error ? h("p", {class: "muted"}, data.error) : null,
|
||||
files.map(fileCard), files.length ? addForm(files) : null, stagedList());
|
||||
}
|
||||
|
||||
function diffLines(text) {
|
||||
return h("pre", {class: "fw-diff"}, text.split("\n").map((line) => h("span", {class: line.startsWith("+") && !line.startsWith("+++") ? "add" : line.startsWith("-") && !line.startsWith("---") ? "del" : null}, `${revealed(line)}\n`)));
|
||||
}
|
||||
|
||||
async function reviewSettings() {
|
||||
const items = settingsItems();
|
||||
const preview = await sendJson("/api/firewall/preview", {items});
|
||||
if (!preview.ok || !preview.data) {
|
||||
toast("Settings: not possible", fail(preview), false);
|
||||
await fetchFirewall();
|
||||
return;
|
||||
}
|
||||
const outcome = h("div", {class: "mini", "aria-live": "polite"});
|
||||
const confirm = h("button", {type: "button", class: "btn primary", ...named("Sign and apply", "Sign and apply: hand exactly this diff to the host with your passkey signature")}, icon("bi-pen"), "Sign and apply");
|
||||
confirm.addEventListener("click", async () => {
|
||||
confirm.disabled = true;
|
||||
if (!await applySettings(items, outcome)) {
|
||||
confirm.disabled = false;
|
||||
}
|
||||
});
|
||||
openSheet("Settings change", [
|
||||
h("p", {class: "muted"}, "The host writer checks your signature, refuses a file that changed since and writes exactly this change; it keeps every other key and a backup beside the file."),
|
||||
h("div", {class: "stack-tight", "aria-label": "Diff"}, preview.data.diffs.map((entry) => h("div", {"data-diff": entry.file}, h("code", {}, revealed(entry.file)), diffLines(entry.diff)))),
|
||||
outcome,
|
||||
h("div", {class: "actions"}, h("span", {class: "spacer"}), btn("Cancel", "btn ghost", closeSheet), confirm),
|
||||
], true);
|
||||
}
|
||||
|
||||
async function applySettings(items, outcome) {
|
||||
const signed = await proofFor(items, "Settings");
|
||||
if (signed === null) {
|
||||
outcome.replaceChildren(h("p", {class: "muted"}, "Not signed: nothing was handed over."));
|
||||
return false;
|
||||
}
|
||||
const result = await sendJson("/api/firewall/settings", {items, proof: signed.proof});
|
||||
if (!result.ok || !result.data) {
|
||||
toast("Settings: not possible", fail(result), false);
|
||||
outcome.replaceChildren(h("p", {class: "muted"}, `${result.status} ${result.text}`.trim()));
|
||||
return false;
|
||||
}
|
||||
outcome.replaceChildren(h("p", {class: "muted", "data-firewall": result.data.id}, `Signed and handed to the host (job ${result.data.id}); the firewall unit writes now.`));
|
||||
followJob(`/api/firewall/settings/${encodeURIComponent(result.data.id)}`, outcome, Date.now(), (data) => {
|
||||
const {good, lines} = showJob(data, outcome, "file", SETTINGS_RESULTS);
|
||||
toast(`Settings: ${good ? "written" : "not everything written"}`, lines, good);
|
||||
if (good) {
|
||||
firewall.staged = {};
|
||||
}
|
||||
fetchFirewall();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -75,11 +75,11 @@
|
||||
return;
|
||||
}
|
||||
const rows = usable.map((item) => h("li", {},
|
||||
h("div", {class: "row"}, pill(ITEM_LABELS[item.kind], KIND_TONES[item.kind]), item.kind === "decision" && !deny ? h("span", {class: "muted"}, `→ ${item.recommended}`) : null),
|
||||
h("strong", {}, item.title),
|
||||
item.kind === "operator" ? h("div", {class: "command"}, h("code", {}, item.command)) : null,
|
||||
item.kind === "operator" ? h("span", {class: "muted"}, `in ${item.directory}`) : null,
|
||||
item.kind === "ask" ? h("div", {class: "command"}, h("code", {}, item.command)) : null));
|
||||
h("div", {class: "row"}, pill(ITEM_LABELS[item.kind], KIND_TONES[item.kind]), item.kind === "decision" && !deny ? h("span", {class: "muted"}, revealed(`→ ${item.recommended}`)) : null),
|
||||
h("strong", {}, revealed(item.title)),
|
||||
item.kind === "operator" ? h("div", {class: "command"}, h("code", {}, revealed(item.command))) : null,
|
||||
item.kind === "operator" ? h("span", {class: "muted"}, revealed(`in ${item.directory}`)) : null,
|
||||
item.kind === "ask" ? h("div", {class: "command"}, h("code", {}, revealed(item.command))) : null));
|
||||
const confirm = h("button", {type: "button", class: deny ? "btn danger" : "btn primary"}, `${deny ? "Deny" : "Grant"} ${usable.length}`);
|
||||
confirm.addEventListener("click", () => {
|
||||
closeSheet();
|
||||
@@ -135,7 +135,7 @@
|
||||
} else if (item.kind === "ask") {
|
||||
buttons.push(iconBtn("bi-check-lg", "Grant", "btn small primary", () => approveOne(item)));
|
||||
} else if (item.kind === "decision" && item.recommended) {
|
||||
buttons.push(h("button", {type: "button", class: "btn small primary", ...named(`Recommendation: ${item.recommended}`), on: {click: () => approveOne(item)}}, icon("bi-check-lg"), item.recommended));
|
||||
buttons.push(h("button", {type: "button", class: "btn small primary", ...named(revealed(`Recommendation: ${item.recommended}`)), on: {click: () => approveOne(item)}}, icon("bi-check-lg"), revealed(item.recommended)));
|
||||
} else if (item.kind === "operator" && item.runnable) {
|
||||
buttons.push(iconBtn("bi-play-fill", "Run", "btn small primary", () => approveOne(item)));
|
||||
} else if (item.kind === "rule") {
|
||||
@@ -166,18 +166,18 @@
|
||||
item.until ? pill(`until ${absolute.format(stampOf(item.until))}`, "neutral") : null),
|
||||
h("div", {class: "entry-body"},
|
||||
h("div", {class: "route"},
|
||||
h("button", {type: "button", class: "linkish headline", title: "Open", on: {click: () => openItem(item)}}, item.kind === "operator" ? item.id : item.kind === "ask" ? item.title.split(": ")[0] : item.title),
|
||||
h("button", {type: "button", class: "linkish headline", title: "Open", on: {click: () => openItem(item)}}, revealed(item.kind === "operator" ? item.id : item.kind === "ask" ? item.title.split(": ")[0] : item.title)),
|
||||
item.agent ? [face(item.agent, false), person(item.agent)] : null),
|
||||
item.kind === "review" ? h("div", {class: "muted"}, item.detail, item.score ? ` · ${item.score}` : "") : null,
|
||||
commanded ? h("div", {class: "command", "data-path": item.directory || "-"}, h("code", {}, item.command), copyButton(item.command)) : null,
|
||||
commanded ? h("span", {class: "muted"}, `in ${dash(item.directory)}`) : null,
|
||||
item.kind === "operator" && item.detail && item.detail !== "-" ? h("p", {class: "text reason"}, item.detail) : null,
|
||||
item.kind === "review" ? h("div", {class: "muted"}, revealed(item.detail), item.score ? revealed(` · ${item.score}`) : "") : null,
|
||||
commanded ? h("div", {class: "command", "data-path": item.directory || "-"}, h("code", {}, revealed(item.command)), copyButton(item.command)) : null,
|
||||
commanded ? h("span", {class: "muted"}, revealed(`in ${dash(item.directory)}`)) : null,
|
||||
item.kind === "operator" && item.detail && item.detail !== "-" ? h("p", {class: "text reason"}, revealed(item.detail)) : null,
|
||||
diffBlocks(item),
|
||||
item.job ? consoleOf(item.job) : null,
|
||||
item.kind === "rule" ? ruleRequestBody(item) : null,
|
||||
item.kind === "decision" ? h("div", {class: "options"}, item.options.map((option) => h("button", {
|
||||
type: "button", class: `option${option.label === item.recommended ? " recommended" : ""}`, title: `${option.label}: your passkey signs this answer, a post to ${item.agent}`, disabled: item.held, on: {click: () => chooseOne(item, option.label)},
|
||||
}, h("strong", {}, option.label), option.description ? h("span", {}, option.description) : null))) : null,
|
||||
type: "button", class: `option${option.label === item.recommended ? " recommended" : ""}`, title: revealed(`${option.label}: your passkey signs this answer, a post to ${item.agent}`), disabled: item.held, on: {click: () => chooseOne(item, option.label)},
|
||||
}, h("strong", {}, revealed(option.label)), option.description ? h("span", {}, revealed(option.description)) : null))) : null,
|
||||
feedbackList(keyOf(item))),
|
||||
h("div", {class: "item-actions line-actions"},
|
||||
actionsFor(item),
|
||||
@@ -246,8 +246,8 @@
|
||||
}
|
||||
const body = [
|
||||
h("div", {class: "who"}, pill(ITEM_LABELS[item.kind], KIND_TONES[item.kind]), item.agent ? face(item.agent, false) : null, item.agent ? person(item.agent) : null, when(item.ts)),
|
||||
h("p", {class: "text"}, item.title),
|
||||
item.command ? h("div", {class: "command"}, h("code", {}, item.command), copyButton(item.command)) : null,
|
||||
h("p", {class: "text"}, revealed(item.title)),
|
||||
item.command ? h("div", {class: "command"}, h("code", {}, revealed(item.command)), copyButton(item.command)) : null,
|
||||
item.kind === "rule" ? ruleRequestBody(item) : null,
|
||||
meta([["Directory", item.directory], ["Warnings", item.warnings.join(", ")], ["Id", item.id]]),
|
||||
item.kind === "decision" ? h("div", {class: "options"}, item.options.map((option) => h("button", {
|
||||
@@ -255,7 +255,7 @@
|
||||
closeSheet();
|
||||
chooseOne(item, option.label);
|
||||
}},
|
||||
}, h("strong", {}, option.label), option.description ? h("span", {}, option.description) : null))) : null,
|
||||
}, h("strong", {}, revealed(option.label)), option.description ? h("span", {}, revealed(option.description)) : null))) : null,
|
||||
h("div", {class: "actions"}, h("span", {class: "spacer"}), actionsFor(item).map((node) => {
|
||||
node.addEventListener("click", closeSheet);
|
||||
return node;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
toast(`${label}: not signed`, ["No passkey pinned: Settings → Register passkey"], false);
|
||||
return null;
|
||||
}
|
||||
const prompt = h("div", {class: "toast wait passkey-prompt", id: "passkey-prompt", role: "status", "aria-live": "polite"}, h("strong", {}, "Passkey signs"), h("pre", {}, promptText(label, prepared)));
|
||||
document.body.append(prompt);
|
||||
try {
|
||||
const credential = await navigator.credentials.get({publicKey: {
|
||||
challenge: unb64url(prepared.challenge),
|
||||
@@ -29,6 +31,8 @@
|
||||
} catch (error) {
|
||||
toast(`${label}: not signed`, [`${(error && error.name) || error}: KeePassXC locked or canceled; nothing was sent.`], false);
|
||||
return null;
|
||||
} finally {
|
||||
prompt.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
const UNSEEN = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Zs}\p{Default_Ignorable_Code_Point}]/gu;
|
||||
const EMOJI_BASES = new Set(JSON.parse(document.getElementById("emoji-bases").textContent));
|
||||
const PRESENTATION = new Set([0xFE0E, 0xFE0F]);
|
||||
|
||||
/**
|
||||
* @param {string} text the text a match sits in.
|
||||
* @param {number} offset the UTF-16 index of the match.
|
||||
* @returns {number} the code point right before offset, NaN at the start.
|
||||
*/
|
||||
const codePointBefore = (text, offset) => {
|
||||
const pair = offset > 1 ? text.codePointAt(offset - 2) : 0;
|
||||
return pair > 0xFFFF ? pair : text.charCodeAt(offset - 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} text a text a passkey prompt, a signed-item preview or an inbox diff shows.
|
||||
* @returns {string} the text with every control, format, line or paragraph separator, space separator but the space and default-ignorable character but the tab shown as ⟨U+XXXX⟩, the set signing.unseen() refuses, except a variation selector right after a code point of EMOJI_BASES, the pair signing.presented() accepts, so no text hides, reorders or splits what the passkey signs.
|
||||
*/
|
||||
const revealed = (text) => String(text).replace(UNSEEN, (char, offset, whole) => (char === "\t" || char === " " || (PRESENTATION.has(char.codePointAt(0)) && EMOJI_BASES.has(codePointBefore(whole, offset))) ? char : `⟨U+${char.codePointAt(0).toString(16).toUpperCase().padStart(4, "0")}⟩`));
|
||||
|
||||
/**
|
||||
* @param {string} text a text of several lines a signed-item preview shows.
|
||||
* @returns {string} each line through revealed(), joined by real line breaks.
|
||||
*/
|
||||
const revealedLines = (text) => String(text).split("\n").map(revealed).join("\n");
|
||||
@@ -44,7 +44,7 @@
|
||||
const head = h("article", {class: "card"},
|
||||
h("div", {class: "card-head"}, h("div", {}, h("p", {class: "muted"}, "submitted ", when(review.created_ts))), h("div", {class: "who"}, status(review.status || "pending"), review.gate ? pill(review.gate === "pass" ? "Gate green" : "Gate red", review.gate === "pass" ? "ok" : "bad") : null)),
|
||||
meta([["Repo", review.worktree], ["Branch", review.branch], ["Tree", (review.tree || "").slice(0, 12), review.tree], ["Score", review.score]]),
|
||||
review.notes ? h("pre", {class: "notes"}, review.notes) : null,
|
||||
review.notes ? h("pre", {class: "notes"}, revealedLines(review.notes)) : null,
|
||||
h("div", {class: "actions"},
|
||||
h("a", {class: "btn ghost icon-only", href: `/reviews/${encodeURIComponent(review.id)}/page`, target: "_blank", rel: "noopener noreferrer", ...named("Open full page", "Open full page (new tab)")}, icon("bi-box-arrow-up-right")),
|
||||
h("span", {class: "spacer"}),
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
const dry = item.dry_run;
|
||||
const pairs = [["Kind", RULE_KINDS[rule.kind]], rule.kind === "ask" ? ["Tool (glob)", rule.tool] : null, ["Pattern (glob)", rule.pattern], rule.kind === "decision" ? null : ["Directory (glob)", rule.scope], ["Expires on", absolute.format(stampOf(rule.expires))]];
|
||||
return h("div", {class: "rule-request"},
|
||||
item.detail ? h("p", {class: "text"}, item.detail) : null,
|
||||
item.detail ? h("p", {class: "text"}, revealed(item.detail)) : null,
|
||||
meta(pairs.filter(Boolean)),
|
||||
h("p", {class: "muted dry-run-count"}, "Dry run: the rule would have granted ", h("strong", {}, `${dry.matched} of ${dry.total}`), ` ${COUNTED[rule.kind]} from the last ${dry.days} days.`),
|
||||
h("p", {class: "muted"}, RULE_HINTS[rule.kind]));
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
const RULE_KINDS = {ask: "Ask: tool + command pattern", review: "Review: branch pattern + gate green", decision: "Decision: take the recommendation"};
|
||||
const RULE_HINTS = {
|
||||
ask: "Grants matching asks in matching directories, never a command with a warning (rm -r, push, --force, sudo, pipes into a shell …). The passkey signs the rule once; the hook checks signature and pattern itself.",
|
||||
review: "Grants reviews of matching branches and worktrees, only when their gate is green. The passkey signs the rule once; the commit skill checks signature and pattern itself.",
|
||||
ask: "Grants matching asks in matching directories, never a command with a warning (rm -r, push, --force, sudo, pipes into a shell …). The passkey signs the rule and the agents it applies to once; the hook checks signature, pattern and agent itself.",
|
||||
review: "Grants reviews of matching branches and worktrees, only when their gate is green, for every agent: a review names no session. The passkey signs the rule once; the commit skill checks signature and pattern itself.",
|
||||
decision: "Takes the recommended option in decisions of matching agents. The passkey signs the rule once; the decisions themselves stay unsigned.",
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} rule the stored rule to turn on again, which widens what agents may do.
|
||||
* @returns {Promise<Object|null>} the hub's answer, null when the operator did not sign.
|
||||
*/
|
||||
async function turnOn(rule) {
|
||||
const signed = await proofFor([{kind: "enable", rule: rule.id}], "Turn on rule");
|
||||
return signed ? sendJson(`/api/rules/${encodeURIComponent(rule.id)}/enable`, {proof: signed.proof}) : null;
|
||||
}
|
||||
|
||||
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);
|
||||
const targetField = h("label", {}, "Applies to", target);
|
||||
const tool = h("input", {class: "field", type: "text", placeholder: "Bash", value: "Bash"});
|
||||
const pattern = h("input", {class: "field", type: "text", placeholder: "make test*"});
|
||||
const scope = h("input", {class: "field", type: "text", value: "*", placeholder: "/home/…/Repositories/*"});
|
||||
@@ -19,12 +30,15 @@
|
||||
const sync = () => {
|
||||
toolField.hidden = kind.value !== "ask";
|
||||
scopeField.hidden = kind.value === "decision";
|
||||
targetField.hidden = kind.value === "review";
|
||||
target.disabled = targetField.hidden;
|
||||
fillTargets(target);
|
||||
pattern.placeholder = {ask: "make test*", review: "feature/*", decision: "* (agent pattern)"}[kind.value];
|
||||
hint.textContent = RULE_HINTS[kind.value];
|
||||
};
|
||||
kind.addEventListener("change", sync);
|
||||
sync();
|
||||
const form = h("form", {class: "rule-form"}, h("label", {}, "Kind", kind), toolField, h("label", {}, "Pattern (glob)", pattern), scopeField, h("label", {}, "Expires on", expires), h("label", {class: "check"}, enabled, "active"), h("button", {type: "submit", class: "btn primary"}, "Create rule"));
|
||||
const form = h("form", {class: "rule-form"}, h("label", {}, "Kind", kind), targetField, toolField, h("label", {}, "Pattern (glob)", pattern), scopeField, h("label", {}, "Expires on", expires), h("label", {class: "check"}, enabled, "active"), h("button", {type: "submit", class: "btn primary", "data-sign": ""}, "Create rule"));
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const end = Date.parse(`${expires.value}T23:59:59`) / 1000;
|
||||
@@ -34,6 +48,7 @@
|
||||
pattern: pattern.value.trim() || (kind.value === "decision" ? "*" : ""),
|
||||
scope: kind.value === "decision" ? "*" : scope.value.trim(),
|
||||
expires: Number.isFinite(end) ? end : 0,
|
||||
agents: ruleAgents(kind.value, target.value),
|
||||
};
|
||||
const prepared = await sendJson("/api/rules/sign", fields);
|
||||
if (!prepared.ok || !prepared.data) {
|
||||
@@ -49,18 +64,19 @@
|
||||
await load();
|
||||
});
|
||||
const change = async (rule, verb) => {
|
||||
const result = await send(`/api/rules/${encodeURIComponent(rule.id)}/${verb}`, "", "application/json");
|
||||
if (!result.ok) {
|
||||
toast("Rule not changed", [`${result.status} ${result.text}`.trim()], false);
|
||||
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]),
|
||||
rule.tool ? h("code", {}, rule.tool) : null,
|
||||
h("code", {}, rule.pattern),
|
||||
rule.kind === "decision" ? null : h("code", {title: "Directory"}, rule.scope || "–"),
|
||||
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"),
|
||||
@@ -71,5 +87,5 @@
|
||||
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 rules for automatic grants"), list, h("div", {class: "card"}, hint, form));
|
||||
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());
|
||||
}
|
||||
@@ -51,9 +51,9 @@
|
||||
const setValue = h("button", {type: "button", class: "btn small primary", ...named("Set business value", "Set the business value as Operator, signed with the passkey; WSJF uses it instead of the median")}, icon("bi-gem"), "Set business value");
|
||||
const sync = () => {
|
||||
pin.disabled = !prioText(prio.value);
|
||||
pinCode.textContent = pin.disabled ? `Enter a priority from 1 to ${PRIO_MAX}` : shownArgv(prioArgv());
|
||||
estimateCode.textContent = shownArgv(estimateArgv());
|
||||
valueCode.textContent = shownArgv(valueArgv());
|
||||
pinCode.textContent = pin.disabled ? `Enter a priority from 1 to ${PRIO_MAX}` : revealed(shownArgv(prioArgv()));
|
||||
estimateCode.textContent = revealed(shownArgv(estimateArgv()));
|
||||
valueCode.textContent = revealed(shownArgv(valueArgv()));
|
||||
};
|
||||
for (const field of [prio, value, complexity, alone]) {
|
||||
field.addEventListener("input", sync);
|
||||
@@ -96,7 +96,7 @@
|
||||
function taskJobs(row) {
|
||||
const jobs = state.jobs.filter((job) => job.kind === "task" && job.task === row.task).slice(-5).reverse();
|
||||
return jobs.length ? [h("h3", {}, "Signed changes", counter(jobs.length)), h("ul", {class: "mini"}, jobs.map((job) => h("li", {"data-job": job.status},
|
||||
h("div", {class: "row"}, h("code", {}, job.command), status(job.status)),
|
||||
h("div", {class: "row"}, h("code", {}, revealed(job.command)), status(job.status)),
|
||||
job.status === "refused" || job.status === "failed" ? h("pre", {class: "notes"}, job.output) : null)))] : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
.stack-tight { display: grid; gap: 10px; min-width: 0; }
|
||||
.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-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); }
|
||||
.rule-row select.field { width: auto; max-width: 100%; min-width: 0; }
|
||||
.passkey-prompt { position: fixed; top: 18px; left: 50%; z-index: 60; width: min(440px, calc(100vw - 36px)); transform: translateX(-50%); }
|
||||
Reference in new issue
Block a user