feat(hub): Select collects option picks, rules and red-gate reviews too

In Select mode every grant button and every option pick toggles its item into the selection (operator 2026-11-20): a decision or decision row keeps the option picked for it and picking it again takes it out; a rule request or red-gate review joins the selection as a solo item. Grant n signs every batchable item under one passkey signature, then asks one more signature per rule and red-gate review, one after the other, since the server accepts neither inside a batch; the sheet's note counts them. Requirement 020 decision 3 and its acceptance criteria follow.

Stacked on allow (aa4a337). The one conflict in page-inbox.js keeps the ux reason chips in the deny sheet next to the new solo note. node --check and ruff pass.

Tests: test_hub_grant_mode (pick collects with its label, rule and red-gate review get their own signature after the batch). Written, not run: the full suite runs once on master after all bundles (operator order).

Security: MEDUSA over the staged tree on master: 100, no findings, all 5 files covered. The server checks are unchanged.

🎯 Fix: 90 %
💥 Break: 5 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 86
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-22 15:55:43 +00:00
1 parent aa4a337c9a
commit 14bb4f38df
5 files changed
+191 -66

No files matched your search

+46 -13
View File
@@ -1,41 +1,74 @@
const GRANT_SELECT = "select";
const GRANT_MODES = {
direct: ["Direct", "bi-lightning-charge", "Direct mode", "Direct: every grant button grants at once"],
[GRANT_SELECT]: ["Select", "bi-check2-square", "Select mode", "Select: every grant button adds its item to the selection; Grant grants the selection under one passkey signature"],
[GRANT_SELECT]: ["Select", "bi-check2-square", "Select mode", "Select: every grant button and option adds its item to the selection; Grant grants the selection under one passkey signature, each rule and red-gate review under its own"],
};
const PICKED_HINT = "In the selection: take it out with ✕ in the Grant menu";
const DIRECT_WHY = {rule: "a rule is accepted one at a time", review: "a red gate is never granted in a selection"};
const SOLO_HINT = "Select: press to add it to the selection; Grant asks its own passkey signature for it";
const grantView = {tray: null, sig: "", open: false};
const choices = new Map();
const grantMode = () => (typeof ViewStore === "object" && ViewStore ? ViewStore.get("approval.mode") : "direct");
const collecting = (item) => grantMode() === GRANT_SELECT && selectable(item);
const chosenLabel = (item) => (ui.selected.has(keyOf(item)) ? choices.get(keyOf(item)) : undefined);
const solo = (item) => !item.held && (item.kind === "rule" || (item.kind === "review" && item.gate !== "pass"));
const batchable = (item) => selectable(item) || (!item.held && chosenLabel(item) !== undefined);
const collectable = (item) => batchable(item) || solo(item);
const collecting = (item) => grantMode() === GRANT_SELECT && collectable(item);
const picking = (item) => grantMode() === GRANT_SELECT && !item.held;
/**
* @param {Object} item a batchable inbox item.
* @returns {string} the label its grant carries: the picked option, else a decision's recommendation, else "".
*/
function labelOf(item) {
const label = chosenLabel(item);
if (label !== undefined) {
return label;
}
return item.kind === "decision" ? item.recommended : "";
}
function regrant() {
render(false);
drawStream();
}
function collect(item) {
const key = keyOf(item);
function flip(key) {
choices.delete(key);
if (ui.selected.has(key)) {
ui.selected.delete(key);
} else {
ui.selected.add(key);
}
}
function collect(item) {
flip(keyOf(item));
regrant();
}
/**
* @param {Object} item a decision or a decision row.
* @param {string} label the picked answer; picking the same answer again takes the item out of the selection.
*/
function collectPick(item, label) {
const key = keyOf(item);
if (chosenLabel(item) === label) {
collect(item);
return;
}
choices.set(key, label);
ui.selected.add(key);
regrant();
}
/**
* @param button - the grant button of item.
* @param item - a waiting inbox item.
* @returns button; a picked item's button turns pale green and disabled, and in Select it says why a grant still acts at once.
* @returns button; a picked item's button turns pale green and disabled, and in Select a rule or red-gate review says it gets its own signature.
*/
function grantPress(button, item) {
const select = grantMode() === GRANT_SELECT;
if (!selectable(item)) {
if (select) {
button.setAttribute("title", `${button.getAttribute("title")}: acts at once, ${DIRECT_WHY[item.kind]}`);
}
if (!collectable(item)) {
return button;
}
const picked = ui.selected.has(keyOf(item));
@@ -44,10 +77,10 @@
button.setAttribute("class", `${button.getAttribute("class")} picked`);
button.setAttribute("title", PICKED_HINT);
}
if (select) {
if (grantMode() === GRANT_SELECT) {
button.setAttribute("aria-pressed", String(picked));
if (!picked) {
button.setAttribute("title", "Select: press to add it to the selection; Grant grants it");
button.setAttribute("title", solo(item) ? SOLO_HINT : "Select: press to add it to the selection; Grant grants it");
}
}
return button;
+26 -23
View File
@@ -104,7 +104,9 @@
return submit([entryOf(item, "approve", "")], `${item.kind === "operator" ? "Run" : "Grant"}: ${short(item.title)}`);
}
const chooseOne = (item, label) => submit([entryOf(item, "approve", label)], `Choice: ${shownPick(label)}`);
const chooseOne = (item, label) => (picking(item) ? collectPick(item, label) : submit([entryOf(item, "approve", label)], `Choice: ${shownPick(label)}`));
const answerPick = (item, label) => (picking(item) ? collectPick(item, label) : answerRow(item, label));
const grantSolo = (item) => (item.kind === "rule" ? acceptRule(item) : submit([entryOf(item, "approve", "")], `Grant: ${short(item.title)}`));
const asked = (item) => item.kind === "operator" && item.check === "decision";
const answers = new Map();
const answerOf = (item) => answers.get(keyOf(item)) || item.answered || "";
@@ -136,13 +138,14 @@
*/
const choiceOf = (item, after) => {
if (item.kind === "decision") {
return choiceDialog(item, {pick: (label) => { after(); chooseOne(item, label); }, toggled: new Set(), chosen: "", locked: item.held, hint: signsFor(item), group: "", other: OTHER_PROMPT});
return choiceDialog(item, {pick: (label) => { after(); chooseOne(item, label); }, toggled: new Set(), chosen: ui.selected.has(keyOf(item)) ? labelOf(item) : "", locked: item.held, hint: signsFor(item), group: "", other: OTHER_PROMPT});
}
if (item.kind === "ask") {
return choiceDialog(askDialog(item.id), {pick: (answer, typed) => { after(); answerAsk(item, answer, typed); }, toggled: new Set(), chosen: ui.selected.has(keyOf(item)) ? ALLOW : "", locked: item.held, hint: `your passkey signs it, the answer goes to ${item.to || "its session"}`, group: "", other: TELL});
}
const told = answerOf(item);
return asked(item) ? [answerTo(item), choiceDialog(item, {pick: (label) => { after(); answerRow(item, label); }, toggled: new Set(), chosen: told, locked: item.held || Boolean(told), hint: signsFor(item), group: "", other: OTHER_PROMPT})] : null;
const shown = told || (ui.selected.has(keyOf(item)) ? labelOf(item) : "");
return asked(item) ? [answerTo(item), choiceDialog(item, {pick: (label) => { after(); answerPick(item, label); }, toggled: new Set(), chosen: shown, locked: item.held || Boolean(told), hint: signsFor(item), group: "", other: OTHER_PROMPT})] : null;
};
/**
@@ -153,29 +156,37 @@
const deniable = (item) => item.deniable || item.kind === "review";
const denialOf = (item, reason) => ({...entryOf(item, "reject", ""), channel: "post", reason, to: item.to});
const pickable = (item) => !item.held && (selectable(item) || deniable(item));
const pickable = (item) => !item.held && (collectable(item) || deniable(item));
function bulk(items, label, deny) {
const usable = items.filter(deny ? deniable : selectable);
if (!usable.length) {
const usable = items.filter(deny ? deniable : batchable);
const alone = deny ? [] : items.filter(solo);
if (!usable.length && !alone.length) {
toast(`${label}: nothing to ${deny ? "deny" : "grant"}`, [], false);
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"}, revealed(`→ ${shownPick(item.recommended)}`)) : null),
const rows = [...usable, ...alone].map((item) => h("li", {},
h("div", {class: "row"}, pill(ITEM_LABELS[item.kind], KIND_TONES[item.kind]), !deny && labelOf(item) ? h("span", {class: "muted"}, revealed(`→ ${shownPick(labelOf(item))}`)) : 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}`);
const confirm = h("button", {type: "button", class: deny ? "btn danger" : "btn primary"}, `${deny ? "Deny" : "Grant"} ${usable.length + alone.length}`);
const reason = deny ? h("textarea", {class: "field", maxlength: DENY_REASON, rows: 3, placeholder: "e.g. make the gate green first"}) : null;
confirm.addEventListener("click", () => {
confirm.addEventListener("click", async () => {
closeSheet();
submit(usable.map((item) => (deny ? denialOf(item, reason.value) : entryOf(item, "approve", item.kind === "decision" ? item.recommended : ""))), `${label}: ${usable.length} entries`);
if (usable.length && !(await submit(usable.map((item) => (deny ? denialOf(item, reason.value) : entryOf(item, "approve", labelOf(item)))), `${label}: ${usable.length} entries`))) {
return;
}
for (const item of alone) {
if (!(await grantSolo(item))) {
return;
}
}
});
const note = deny
? "Every entry and every full command that gets denied; each requester gets its denial and the reason by post. After the click the passkey signs the whole selection once; then 3 s remain to undo."
: "Every entry and every full command that gets granted. After the click the passkey signs the whole selection once; then 3 s remain to undo.";
: `Every entry and every full command that gets granted. After the click the passkey signs the whole selection once; then 3 s remain to undo.${alone.length ? ` Each rule and each red-gate review then asks its own signature, one after the other (${alone.length}).` : ""}`;
openSheet(label, [h("p", {class: "muted"}, note), h("ul", {class: "mini"}, rows), ...(deny ? [reasonChips(reason), h("label", {class: "deny-reason"}, "Reason (optional, every requester reads it)", reason)] : []),
h("div", {class: "actions"}, h("span", {class: "spacer"}), btn("Cancel", "btn ghost", closeSheet), confirm)], false);
(reason || confirm).focus();
@@ -188,7 +199,7 @@
const green = items.filter(isGreen);
const chosen = items.filter((item) => ui.selected.has(keyOf(item)));
const denials = chosen.filter(deniable);
const grantable = chosen.filter(selectable);
const grantable = chosen.filter(collectable);
return {
chosen,
grant: h("button", {type: "button", class: "btn small primary", ...named(`Grant selection (${grantable.length})`), disabled: !grantable.length || ui.busy, on: {click: () => bulk(chosen, "Grant selection", false)}}, icon("bi-check2-square"), `Grant ${grantable.length}`),
@@ -217,11 +228,7 @@
return;
}
const key = keyOf(item);
if (ui.selected.has(key)) {
ui.selected.delete(key);
} else {
ui.selected.add(key);
}
flip(key);
ui.cursor = Math.max(visibleInbox().findIndex((entry) => keyOf(entry) === key), 0);
drawInbox();
drawGrant();
@@ -317,7 +324,7 @@
}
}
const mode = grantMode();
const sig = JSON.stringify([mode, items.map(withoutOutput), [...ui.selected], [...answers], ui.cursor, ui.snoozed, ui.busy, Math.floor(nowSeconds() / 60), diffView.version, state.messages.map((message) => message.id)]);
const sig = JSON.stringify([mode, items.map(withoutOutput), [...ui.selected], [...choices], [...answers], ui.cursor, ui.snoozed, ui.busy, Math.floor(nowSeconds() / 60), diffView.version, state.messages.map((message) => message.id)]);
if (sig === inboxSig) {
repaintConsoles(items);
return;
@@ -334,10 +341,6 @@
onLocalhost() ? "" : h("p", {class: "muted"}, "The passkey signs grants only under ", localLink()),
items.length ? h("ol", {class: "inbox-list"}, items.map(inboxItem)) : emptyState("All done", "Nothing is waiting for you right now.")));
settleConsoles(items);
const current = inboxDom.querySelector(`.item[data-index="${ui.cursor}"]`);
if (current && document.activeElement === document.body) {
current.scrollIntoView({block: "nearest"});
}
}
function openItem(item) {
+24 -6
View File
@@ -11,18 +11,36 @@
h("p", {class: "muted"}, RULE_HINTS[rule.kind]));
}
/**
* @param {Object} item a rule request.
* @param {string} label the toast and passkey prompt label.
* @returns {Promise<Object|null>} the accept body with the rule and its passkey assertion, null when the server refused or the operator cancelled.
*/
async function signRule(item, label) {
const prepared = await sendJson(`/api/rule-requests/${encodeURIComponent(item.id)}/sign`, {});
if (!prepared.ok || !prepared.data) {
if (!closeGone(prepared, [keyOf(item)], label)) {
toast(`${label}: not possible`, fail(prepared), false);
}
return null;
}
const signed = await assertion(prepared.data, label);
return signed ? {rule: prepared.data.payload, assertion: signed} : null;
}
/**
* @param {Object} item a rule request.
* @returns {Promise<boolean>} whether the rule was created.
*/
async function acceptRule(item) {
const label = `Rule: ${short(item.title)}`;
ui.busy = true;
const prepared = await sendJson(`/api/rule-requests/${encodeURIComponent(item.id)}/sign`, {});
const signed = prepared.ok && prepared.data ? await assertion(prepared.data, label) : null;
if ((!prepared.ok || !prepared.data) && !closeGone(prepared, [keyOf(item)], label)) {
toast(`${label}: not possible`, fail(prepared), false);
}
const result = signed ? await sendJson(`/api/rule-requests/${encodeURIComponent(item.id)}/accept`, {rule: prepared.data.payload, assertion: signed}) : null;
const body = await signRule(item, label);
const result = body ? await sendJson(`/api/rule-requests/${encodeURIComponent(item.id)}/accept`, body) : null;
ui.busy = false;
if (result && !closeGone(result, [keyOf(item)], label)) {
toast(result.ok ? `Created: ${short(item.title)}` : `${label}: not created`, result.ok ? [] : fail(result), result.ok);
}
await load();
return Boolean(result && result.ok);
}