feat(orchestrator): bulk grant mode, continuous review diff and an inbox denial reason (020)

A Direct/Select switch in the header (ids grant-direct, grant-select; ViewStore approval.mode) decides whether a grant button acts at once or adds its item to a selection that a tray grants under one passkey signature; rules and red gates still act at once. The review sheet shows every file in one scrolling stack whose next file opens as the previous one ends (openOnScroll moves to page-diff.js and serves Match too). The grant bar boots before the header is measured, so --head counts it. The inbox denial sheet takes an optional reason for every requester; it shares page-inbox.js hunks with the selection code, so both land in this one commit.

Fix stays below 90: the header ids and the measure order fix e2e failures of the aborted final run of 2026-11-17 that the master gate has not rerun yet. Accepted MEDUSA false positives (security.py accept after kvb-think-criticize, 2026-11-17): page-inbox.js PQC007 EXA010; page-match.js EXA010.

🎯 Fix: 85 %
💥 Break: 5 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 81
🚦 Gate: ⛔ fix 85 % < 90

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-17 19:09:46 +00:00
1 parent 88a2d88e47
commit 65d00c0d2c
22 files changed
+763 -65

No files matched your search

+103
View File
@@ -0,0 +1,103 @@
# 020 - Bulk grant mode and continuous diff
## User Story
As the operator, I want one switch at the top right that turns every grant
button of the hub into "add to selection", with one tray that grants the
selection under one passkey signature, and a review diff that runs on into
the next file as I scroll, so that I can review and grant many items in one
pass.
## Decisions (operator-confirmed 2026-11-17; do not re-litigate)
1. **Continuous diff**: the review sheet stacks every file in one scroll; a
file opens when the end of the file before it comes into view (as
`openOnScroll` does in the Match deck); the tree marks the file in view
and a click in the tree scrolls to that file. Rejected: overscroll
advance (trackpad inertia skips files), a "Next file" button (not
automatic).
2. **Mode switch**: a segmented control "Direct | Select" in the header
tools at the top right; Direct keeps today's behaviour. Rejected: a
switch per view.
3. **What collects**: in Select, every grant button toggles its item into
one shared selection (pressed state): inbox rows, Home, stream rows, the
review sheet and the key `a`. A grant of an item `selectable()` refuses
(red-gate review, rule request, decision without a recommendation,
operator row without a command) stays direct and its title says why.
Deny always acts at once with its reason; the Match deck and the palette
keep their own confirmed release. Rejected: a unified tray where denials
collect too.
4. **Tray**: in Select, beside the switch: `n selected` with Grant n,
Deny n, Grant all green and Clear. Grant and Deny open the existing
selection sheet that lists every entry and full command; one passkey
signs, then 3 s remain to undo. The selection is the inbox selection
(`ui.selected`), kept in page memory until granted, denied or cleared.
5. **Memory**: the mode lives in the hub view store (`approval.mode`,
`direct` or `select`, default `direct`), like the legend toggles.
Rejected: per browser only.
6. **Trust unchanged**: nothing is granted without the passkey signature
over exactly the listed items; server and signing path stay as they are.
Rejected: a trust window of direct grants without a prompt.
7. **Timing**: after 018, reject-with-reason and the score chips.
## Approach
```mermaid
flowchart TD
subgraph P["🧭 0 · Preparation"]
P1["📋 Write requirement"] --> P2{"✅ Operator approves?"}
P2 -- "✏️ corrections" --> P1
end
P2 -- "🤖 yes" --> A1
subgraph A["📜 A · Continuous diff"]
A1["🧾 Stack files, open on scroll, tree follows"] --> A2{"🧪 Unit and E2E green?"}
A2 -- "🔴 no: fix" --> A1
end
A2 -- "🟢 yes" --> B1
subgraph B["🧺 B · Bulk mode"]
B1["🎚️ Switch, view store key, tray, grants toggle the selection"] --> B2{"🧪 Unit and E2E green?"}
B2 -- "🔴 no: fix" --> B1
B2 -- "🟢 yes" --> BF{"💬 Operator feedback on screenshots?"}
BF -- "✏️ changes" --> A1
end
BF -- "👍 fits" --> D1["🏁 Review, commit with operator OK, hand-over"]
```
## Acceptance Criteria
### Continuous diff
- [ ] A review of 3 files shows file 1 open, files 2 and 3 closed; scrolling
the diff pane to the end of file 1 opens file 2 without a click, and
the tree marks the file in view.
- [ ] A click on file 3 in the tree scrolls file 3 to the top of the pane
and opens it.
### Bulk mode
- [ ] The header tools hold a "Direct | Select" switch; its state is stored
as `approval.mode` in the view store, survives a reload, and the store
refuses any value but `direct` or `select`.
- [ ] In Select, the grant button of a green review, an ask and a runnable
operator row (inbox, Home, stream, review sheet, key `a`) sends nothing
to `/api/sign` and adds the item to the selection; a second press
removes it; the tray counts it.
- [ ] Tray "Grant n" opens the selection sheet with exactly the selected
entries; one passkey signature covers them all, and after the undo time
each is granted.
- [ ] In Select, the grant of a red-gate review and Accept on a rule request
act directly as in Direct; Deny acts at once in both modes.
- [ ] In Direct, every grant button acts as today and the tray is hidden.
### Tests
- [ ] Unit: view store validation of `approval.mode`; page vm: a grant in
Select toggles `ui.selected` without a post, a grant in Direct posts, a
grant of a non-selectable item stays direct, the tray counts.
- [ ] Integration: n/a: the server and the signing path stay unchanged
(decision 6).
- [ ] E2E: Chromium and Firefox at 1920, 1366 and 390: the continuous diff
opens file 2 on scroll and jumps to file 3 from the tree; the switch
persists over a reload; three grants in Select give a tray of 3;
Grant 3 makes one signed post listing 3 items; Direct posts at once; no
horizontal scroll; screenshots for the checkpoint.
+1
View File
@@ -23,4 +23,5 @@ skill defines the format.
- [017 - Legend Toggle](017-legend-toggle.md)
- [018 - Gibberlink](018-gibberlink.md)
- [019 - Reveal withheld diff content](019-reveal-withheld-diff.md)
- [020 - Bulk grant mode and continuous diff](020-bulk-grant-mode.md)
- [021 - TokenEconomizer by default](021-tokeneconomizer-by-default.md)
@@ -20,7 +20,9 @@ VIEW = {
"home": {"pins": []},
"kanban": {"hidden": []},
"legend": {"views": {}, "tiles": {}},
"approval": {"mode": "direct"},
}
APPROVAL_MODES = ("direct", "select")
LEGEND_PANELS = (
"agents/orbit", "agents/chord", "agents/swimlane", "artifacts/orbit", "artifacts/chord", "artifacts/swimlane",
"tasks/rasci", "tasks/gantt", "tasks/burn", "resources-hardware", "resources-tokens", "resources-combined",
@@ -174,8 +176,11 @@ def valid_view(raw: object) -> dict:
home = section(data["home"], "home", tuple(VIEW["home"]))
kanban = section(data["kanban"], "kanban", tuple(VIEW["kanban"]))
legend = section(data["legend"], "legend", tuple(VIEW["legend"]))
approval = section(data["approval"], "approval", tuple(VIEW["approval"]))
if not isinstance(resources["tokens"], str) or resources["tokens"] not in TOKEN_MODES:
raise ToolError(f"resources.tokens must be one of {', '.join(TOKEN_MODES)}")
if not isinstance(approval["mode"], str) or approval["mode"] not in APPROVAL_MODES:
raise ToolError(f"approval.mode must be one of {', '.join(APPROVAL_MODES)}")
pinned = pins(home["pins"])
keys = {f"{pin['kind']}:{pin['id']}" for pin in pinned}
tiles = legend_flags(legend["tiles"], "legend.tiles", PIN_KEY.fullmatch, "pin keys kind:id")
@@ -193,6 +198,7 @@ def valid_view(raw: object) -> dict:
"views": legend_flags(legend["views"], "legend.views", LEGEND_PANELS.__contains__, f"panels of {', '.join(LEGEND_PANELS)}"),
"tiles": {key: shown for key, shown in tiles.items() if key in keys},
},
"approval": {"mode": approval["mode"]},
}
+14
View File
@@ -59,6 +59,10 @@ h1 { margin: 0; font-size: var(--fs-lg); font-weight: 680; letter-spacing: -.01e
.badge.urgent { background: var(--accent); color: var(--on-accent); }
.badge.alarm { background: var(--alarm); color: #fff; }
.tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; }
.grant-bar, .grant-tray { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; }
.grant-tray[hidden] { display: none; }
.grant-bar .segmented button { display: inline-flex; align-items: center; gap: 6px; }
.grant-count { color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
.banner { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-5); background: var(--alarm); color: #fff; font-weight: 650; }
.banner[hidden] { display: none; }
.banner .text { flex: 1; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@@ -86,6 +90,7 @@ main { min-width: 0; min-height: calc(100vh - var(--head) - var(--sp-6) - var(--
.sheet { padding: 0; }
.sheet-box { min-height: 100%; border-radius: 0; }
.settings .grid { grid-template-columns: minmax(0, 1fr); }
.grant-label { display: none; }
}
.stack { display: grid; gap: 26px; }
.group-title { display: flex; align-items: center; gap: 10px; margin: 0; font-size: var(--fs-sm); font-weight: 650; color: var(--muted); letter-spacing: .02em; text-transform: uppercase; }
@@ -165,6 +170,11 @@ pre.notes { max-height: 260px; margin: 12px 0 0; padding: 10px 12px; overflow: a
.diff-head .path { overflow-wrap: anywhere; font-weight: 600; }
.pad { margin: 0; padding: 18px 16px; }
.diff-scroll { overflow: auto; max-height: 70vh; }
.review-stack { position: relative; overflow: auto; max-height: 70vh; overscroll-behavior: contain; }
.review-file + .review-file { border-top: 1px solid var(--line); }
.review-file > summary.diff-head { position: sticky; top: 0; z-index: 1; cursor: pointer; list-style: none; }
.review-file > summary.diff-head::-webkit-details-marker { display: none; }
.diff-wide { overflow-x: auto; }
table.diff { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: var(--fs-sm); line-height: 1.5; }
table.diff td { padding: 0 10px; vertical-align: top; }
table.diff td.num { width: 1%; min-width: 44px; color: var(--faint); text-align: right; user-select: none; white-space: nowrap; font-variant-numeric: tabular-nums; }
@@ -457,6 +467,7 @@ pre.notes { margin: 0; padding: 8px 10px; background: var(--sunken); border-radi
<header class="top">
<div class="brand"><span class="logo" aria-hidden="true"></span><div class="brand-text"><h1>Agent Orchestrator</h1><span class="sky-note" id="sky-note"></span></div></div>
<div class="tools">
<div class="grant-bar" id="grant-bar"></div>
<button type="button" class="btn small ghost icon-only spot-toggle" id="radio-open" title="Radio: post, call or a message to all, with Record, the radio settings and the stations" aria-label="Radio" aria-controls="radio-spot" aria-expanded="false"><svg class="bi" aria-hidden="true" focusable="false"><use href="#bi-broadcast-pin"></use></svg></button>
<button type="button" class="btn small ghost icon-only" id="bubbles-toggle" title="Speech bubbles" aria-label="Speech bubbles" aria-pressed="false" aria-controls="bubbles"><svg class="bi" aria-hidden="true" focusable="false"><use href="#bi-chat-quote"></use></svg></button>
<button type="button" class="btn small ghost icon-only" id="palette-open" title="Commands (Ctrl+K)" aria-label="Commands"><svg class="bi" aria-hidden="true" focusable="false"><use href="#bi-command"></use></svg></button>
@@ -557,6 +568,8 @@ pre.notes { margin: 0; padding: 8px 10px; background: var(--sunken); border-radi
{% include "page-inbox.js" %}
{% include "page-grant.js" %}
{% include "page-console.js" %}
{% include "page-deny.js" %}
@@ -646,6 +659,7 @@ pre.notes { margin: 0; padding: 8px 10px; background: var(--sunken); border-radi
{% include "page-home.js" %}
{% include "page-legend.js" %}
{% include "page-rules.js" %}
{% include "page-firewall.js" %}
+1
View File
@@ -51,6 +51,7 @@
ratesBar();
notifyLabel();
announce();
grantBoot();
measure();
homeBoot();
legendBoot();
+21
View File
@@ -40,6 +40,27 @@
}}}, icon("bi-eye"), words);
}
/**
* @param {Element} body the scrolling element that holds the files.
* @param {string} selector the files: details elements in reading order.
* Opens the first closed file once the open file before it ends inside the visible part of body.
*/
function openOnScroll(body, selector) {
const files = [...body.querySelectorAll(selector)];
const view = body.getBoundingClientRect();
for (let index = 0; index < files.length - 1; index += 1) {
const file = files[index];
if (!file.open) {
return;
}
const next = files[index + 1];
if (!next.open && file.getBoundingClientRect().bottom <= view.bottom + 8) {
next.open = true;
return;
}
}
}
function diffOf(item) {
if (!item || typeof item.diff !== "number" || !["review", "ask"].includes(item.kind)) {
return null;
+79
View File
@@ -0,0 +1,79 @@
const GRANT_SELECT = "select";
const GRANT_MODES = [
["direct", "Direct", "bi-lightning-charge", "Direct: every grant button grants at once"],
[GRANT_SELECT, "Select", "bi-check2-square", "Select: every grant button adds its item to the selection; the tray grants the selection under one passkey signature"],
];
const DIRECT_WHY = {rule: "a rule is accepted one at a time", review: "a red gate is never granted in a selection"};
const grantView = {modes: [], tray: null, sig: ""};
const grantMode = () => (typeof ViewStore === "object" && ViewStore ? ViewStore.get("approval.mode") : "direct");
const collecting = (item) => grantMode() === GRANT_SELECT && selectable(item);
function regrant() {
render(false);
drawStream();
}
function collect(item) {
const key = keyOf(item);
if (ui.selected.has(key)) {
ui.selected.delete(key);
} else {
ui.selected.add(key);
}
regrant();
}
/**
* @param button - the grant button of item.
* @param item - a waiting inbox item.
* @returns button; in Select it shows whether item is in the selection, or why its grant still acts at once.
*/
function grantPress(button, item) {
if (grantMode() !== GRANT_SELECT) {
return button;
}
if (!selectable(item)) {
button.setAttribute("title", `${button.getAttribute("title")}: acts at once, ${DIRECT_WHY[item.kind]}`);
return button;
}
const picked = ui.selected.has(keyOf(item));
button.setAttribute("aria-pressed", String(picked));
button.setAttribute("title", picked ? "In the selection: press to take it out" : "Select: press to add it to the selection; the tray grants it");
return button;
}
function drawGrant() {
if (!grantView.tray) {
return;
}
const mode = grantMode();
const chosen = state.inbox.filter((item) => ui.selected.has(keyOf(item)));
const sig = JSON.stringify([mode, chosen.map(keyOf), state.inbox.map((item) => [keyOf(item), isGreen(item), item.held]), ui.busy]);
if (sig === grantView.sig) {
return;
}
grantView.sig = sig;
for (const button of grantView.modes) {
button.setAttribute("aria-pressed", String(button.dataset.mode === mode));
}
grantView.tray.hidden = mode !== GRANT_SELECT;
grantView.tray.replaceChildren(...(mode === GRANT_SELECT ? [
h("span", {class: "grant-count", "aria-live": "polite"}, `${chosen.length} selected`),
...selectionButtons(state.inbox),
h("button", {type: "button", class: "btn small ghost", ...named("Clear", "Clear: empty the selection"), disabled: !chosen.length, on: {click: () => {
ui.selected.clear();
regrant();
}}}, icon("bi-x-lg"), "Clear"),
] : []));
}
function grantBoot() {
const bar = document.getElementById("grant-bar");
grantView.modes = GRANT_MODES.map(([mode, label, name, hint]) => h("button", {type: "button", id: `grant-${mode}`, "data-mode": mode, ...named(label, hint), on: {click: () => ViewStore.set("approval.mode", mode)}},
icon(name), h("span", {class: "grant-label"}, label)));
grantView.tray = h("div", {class: "grant-tray", role: "group", "aria-label": "Selection"});
bar.replaceChildren(h("div", {class: "segmented", role: "group", "aria-label": "Grant mode"}, grantView.modes), grantView.tray);
ViewStore.on("approval", regrant);
drawGrant();
}
+36 -22
View File
@@ -87,6 +87,10 @@
}
function approveOne(item) {
if (collecting(item)) {
collect(item);
return null;
}
if (item.kind === "rule") {
return acceptRule(item);
}
@@ -100,14 +104,14 @@
return submit([entryOf(item, "approve", "")], `${item.kind === "operator" ? "Run" : "Grant"}: ${short(item.title)}`);
}
const rejectOne = (item) => submit([entryOf(item, "reject", "")], `Denial: ${short(item.title)}`);
const chooseOne = (item, label) => submit([entryOf(item, "approve", label)], `Choice: ${label}`);
const denialOf = (item) => (item.deniable ? {...entryOf(item, "reject", ""), channel: "post", reason: "", to: item.to} : item.kind === "review" ? entryOf(item, "reject", "") : null);
const pickable = (item) => !item.held && (selectable(item) || denialOf(item) !== null);
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));
function bulk(items, label, deny) {
const usable = items.filter(deny ? (item) => denialOf(item) !== null : selectable);
const usable = items.filter(deny ? deniable : selectable);
if (!usable.length) {
toast(`${label}: nothing to ${deny ? "deny" : "grant"}`, [], false);
return;
@@ -119,15 +123,29 @@
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 reason = deny ? h("textarea", {class: "field", maxlength: DENY_REASON, rows: 3, placeholder: "e.g. make the gate green first"}) : null;
confirm.addEventListener("click", () => {
closeSheet();
submit(usable.map((item) => (deny ? denialOf(item) : entryOf(item, "approve", item.kind === "decision" ? item.recommended : ""))), `${label}: ${usable.length} entries`);
submit(usable.map((item) => (deny ? denialOf(item, reason.value) : entryOf(item, "approve", item.kind === "decision" ? item.recommended : ""))), `${label}: ${usable.length} entries`);
});
const note = deny
? "Every entry and every full command that gets denied; each requester gets its denial 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 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.";
openSheet(label, [h("p", {class: "muted"}, note), h("ul", {class: "mini"}, rows), h("div", {class: "actions"}, h("span", {class: "spacer"}), btn("Cancel", "btn ghost", closeSheet), confirm)], false);
confirm.focus();
openSheet(label, [h("p", {class: "muted"}, note), h("ul", {class: "mini"}, rows), ...(deny ? [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();
}
function selectionButtons(items) {
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);
return [
h("button", {type: "button", class: "btn small soft", ...named(`Grant selection (${grantable.length})`), disabled: !grantable.length || ui.busy, on: {click: () => bulk(chosen, "Grant selection", false)}}, icon("bi-check2-square"), String(grantable.length)),
h("button", {type: "button", class: "btn small danger", ...named(`Deny selection (${denials.length})`, `Deny selection (${denials.length}): each requester gets its denial and an optional reason by post, one passkey signature, 3 s to undo`), disabled: !denials.length || ui.busy, on: {click: () => bulk(chosen, "Deny selection", true)}}, icon("bi-x-square"), String(denials.length)),
h("button", {type: "button", class: "btn small primary", ...named(`Grant all green (${green.length})`), disabled: !green.length || ui.busy, on: {click: () => bulk(green, "Grant all green", false)}}, icon("bi-check2-all"), String(green.length)),
];
}
async function mark(item, until, pinned) {
@@ -168,16 +186,18 @@
return [h("span", {class: "muted"}, "takes effect …")];
}
const buttons = [];
const grant = (button) => buttons.push(grantPress(button, item));
if (item.kind === "review") {
buttons.push(iconBtn("bi-check-lg", "Grant", "btn small primary", () => approveOne(item)), iconBtn("bi-x-lg", "Deny", "btn small danger", () => rejectOne(item)));
grant(iconBtn("bi-check-lg", "Grant", "btn small primary", () => approveOne(item)));
buttons.push(denySplit(item));
} else if (item.kind === "ask") {
buttons.push(iconBtn("bi-check-lg", "Grant", "btn small primary", () => approveOne(item)));
grant(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(revealed(`Recommendation: ${item.recommended}`)), on: {click: () => approveOne(item)}}, icon("bi-check-lg"), revealed(item.recommended)));
grant(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)));
grant(iconBtn("bi-play-fill", "Run", "btn small primary", () => approveOne(item)));
} else if (item.kind === "rule") {
buttons.push(h("button", {type: "button", class: "btn small primary", ...named("Accept", "Accept: the passkey signs exactly this rule, then it applies"), on: {click: () => approveOne(item)}}, icon("bi-shield-check"), "Accept"));
grant(h("button", {type: "button", class: "btn small primary", ...named("Accept", "Accept: the passkey signs exactly this rule, then it applies"), on: {click: () => approveOne(item)}}, icon("bi-shield-check"), "Accept"));
}
if (item.deniable) {
buttons.push(denySplit(item));
@@ -248,28 +268,22 @@
ui.selected.delete(key);
}
}
const sig = JSON.stringify([items.map(withoutOutput), [...ui.selected], ui.cursor, ui.snoozed, ui.busy, Math.floor(nowSeconds() / 60), diffView.version, state.messages.map((message) => message.id)]);
const mode = grantMode();
const sig = JSON.stringify([mode, items.map(withoutOutput), [...ui.selected], ui.cursor, ui.snoozed, ui.busy, Math.floor(nowSeconds() / 60), diffView.version, state.messages.map((message) => message.id)]);
if (sig === inboxSig) {
repaintConsoles(items);
return;
}
inboxSig = sig;
const green = items.filter(isGreen);
const chosen = items.filter((item) => ui.selected.has(keyOf(item)));
const hidden = state.inbox.length - waitingCount();
const snoozed = h("input", {type: "checkbox", checked: ui.snoozed, on: {change: (event) => {
ui.snoozed = event.target.checked;
drawInbox();
}}});
const deniable = chosen.filter((item) => denialOf(item) !== null);
const grantable = chosen.filter(selectable);
const choose = h("button", {type: "button", class: "btn small soft", ...named(`Grant selection (${grantable.length})`), disabled: !grantable.length || ui.busy, on: {click: () => bulk(chosen, "Grant selection", false)}}, icon("bi-check2-square"), String(grantable.length));
const deny = h("button", {type: "button", class: "btn small danger", ...named(`Deny selection (${deniable.length})`, `Deny selection (${deniable.length}): each requester gets its denial by post, one passkey signature, 3 s to undo`), disabled: !deniable.length || ui.busy, on: {click: () => bulk(chosen, "Deny selection", true)}}, icon("bi-x-square"), String(deniable.length));
const all = h("button", {type: "button", class: "btn small primary", ...named(`Grant all green (${green.length})`), disabled: !green.length || ui.busy, on: {click: () => bulk(green, "Grant all green", false)}}, icon("bi-check2-all"), String(green.length));
Panels.keepFocus(inboxSlot, () => inboxDom.replaceChildren(
h("div", {class: "inbox-head"}, h("h2", {class: "group-title"}, "Waits on Operator", counter(waitingCount())), h("span", {class: "spacer"}),
hidden ? h("label", {class: "check"}, snoozed, `${hidden} snoozed`) : null, inboxSlot),
h("div", {class: "inbox-actions"}, choose, deny, all),
mode === GRANT_SELECT ? null : h("div", {class: "inbox-actions"}, selectionButtons(items)),
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);
+2 -18
View File
@@ -118,22 +118,6 @@
}
}
function openOnScroll(body) {
const files = [...body.querySelectorAll(".match-file")];
const view = body.getBoundingClientRect();
for (let index = 0; index < files.length - 1; index += 1) {
const file = files[index];
if (!file.open) {
return;
}
const next = files[index + 1];
if (!next.open && file.getBoundingClientRect().bottom <= view.bottom + 8) {
next.open = true;
return;
}
}
}
function closeComment(card) {
const open = card.querySelector(".match-comment");
if (open) {
@@ -228,11 +212,11 @@
const files = card.files || [];
const list = files.length ? h("ol", {class: "match-files", "aria-label": `Files: ${files.length}`}, files.map((file, index) => fileBlock(card, file, index))) : h("p", {class: "muted"}, card.kind === "commit" ? "No diff shipped with this stage." : "Its command names no file.");
const body = h("div", {class: "match-body"}, matchCommand(card), list);
body.addEventListener("scroll", () => openOnScroll(body), {passive: true});
body.addEventListener("scroll", () => openOnScroll(body, ".match-file"), {passive: true});
const article = h("article", {class: "card match-card front", "data-card": card.id, "data-kind": card.kind, "data-stale": String(Boolean(card.stale)), "aria-label": `${card.kind} card of ${card.agent || "an agent"}`},
matchHead(card), body);
markable(article, card);
window.setTimeout(() => openOnScroll(body), 0);
window.setTimeout(() => openOnScroll(body, ".match-file"), 0);
return article;
}
+33 -7
View File
@@ -1,3 +1,5 @@
const REVIEW_FILE = ".review-file";
function fileList(id) {
if (!files.has(id)) {
files.set(id, "loading");
@@ -77,7 +79,7 @@
return h("span", {class: "stat"}, h("span", {class: "add"}, `+${file.added}`), h("span", {class: "del"}, `-${file.removed}`));
}
function pick(index, list) {
function markFile(index) {
ui.file = index;
for (const entry of reviewDom.tree.querySelectorAll(".file-entry")) {
if (Number(entry.dataset.index) === index) {
@@ -86,7 +88,26 @@
entry.removeAttribute("aria-current");
}
}
reviewDom.diff.replaceChildren(diffPane(list));
}
function pick(index) {
const stack = reviewDom.diff.querySelector(".review-stack");
const file = stack ? stack.querySelector(`${REVIEW_FILE}[data-index="${index}"]`) : null;
if (file) {
file.open = true;
stack.scrollTop = file.offsetTop;
markFile(index);
}
}
function followScroll(stack) {
openOnScroll(stack, REVIEW_FILE);
const top = stack.getBoundingClientRect().top;
const files = [...stack.querySelectorAll(REVIEW_FILE)];
const shown = files.filter((file) => file.getBoundingClientRect().top <= top + 24).pop() || files[0];
if (shown && Number(shown.dataset.index) !== ui.file) {
markFile(Number(shown.dataset.index));
}
}
function branch(node, list) {
@@ -105,7 +126,7 @@
const [letter, tone] = FILE_STATUS[file.status] || ["?", "neutral"];
items.push(h("li", {}, h("button", {
type: "button", class: "file-entry", "data-index": index, "aria-current": index === ui.file ? "true" : null,
title: file.old ? `${file.old} → ${file.path}` : file.path, on: {click: () => pick(index, list)},
title: file.old ? `${file.old} → ${file.path}` : file.path, on: {click: () => pick(index)},
}, h("span", {class: "letter", "data-tone": tone}, letter), h("span", {class: "name"}, name), stat(file))));
}
return h("ul", {class: "tree-list"}, items);
@@ -135,15 +156,20 @@
if (!Array.isArray(list) || !list.length) {
return h("p", {class: "muted pad"}, list === "loading" ? "Loading changes …" : "No diff available.");
}
const file = list[Math.min(ui.file, list.length - 1)];
const stack = h("div", {class: "review-stack"}, list.map((file, index) => reviewFile(file, index)));
stack.addEventListener("scroll", () => followScroll(stack), {passive: true});
return stack;
}
function reviewFile(file, index) {
const [letter, tone] = FILE_STATUS[file.status] || ["?", "neutral"];
return h("div", {},
h("div", {class: "diff-head"},
return h("details", {class: "review-file", "data-index": index, open: index === ui.file},
h("summary", {class: "diff-head"},
h("span", {class: "letter", "data-tone": tone}, letter),
h("code", {class: "path"}, file.old ? `${file.old} → ${file.path}` : file.path),
file.tags.map((tag) => pill(tag, "neutral")),
h("span", {class: "spacer"}),
stat(file)),
file.detail ? h("p", {class: "muted pad"}, file.detail) : null,
file.lines.length ? h("div", {class: "diff-scroll"}, h("table", {class: "diff"}, h("tbody", {}, file.lines.map(diffRow)))) : null);
file.lines.length ? h("div", {class: "diff-wide"}, h("table", {class: "diff"}, h("tbody", {}, file.lines.map(diffRow)))) : null);
}
+1
View File
@@ -95,6 +95,7 @@
drawHierarchy(force);
drawToolbar();
drawInbox();
drawGrant();
drawRadio();
drawTasks();
drawMatch(false);
+5 -2
View File
@@ -33,7 +33,7 @@ INBOX_PICK = """(async () => {@HELPERS@
const send = window.fetch.bind(window);
window.fetch = (path, init) => {
if (["/api/sign", "/api/inbox/approve"].includes(String(path))) {
posted.push([String(path), JSON.parse(init.body).items.map((item) => [item.id, item.verb, item.channel || null])]);
posted.push([String(path), JSON.parse(init.body).items.map((item) => [item.id, item.verb, item.channel || null, item.reason])]);
}
return send(path, init);
};
@@ -62,12 +62,15 @@ INBOX_PICK = """(async () => {@HELPERS@
all("#main .inbox-actions button").find((button) => name(button).startsWith("Deny selection")).click();
await until(() => document.querySelector(".sheet-box .actions"), 4000);
const listed = all(".sheet-box ul.mini > li strong").map(text);
const reason = document.querySelector(".sheet-box .deny-reason textarea");
const reasoned = Boolean(reason && document.activeElement === reason);
reason.value = "rebase first";
const confirm = all(".sheet-box .actions button").find((button) => text(button).startsWith("Deny "));
const label = text(confirm);
const shown = new Set(all("#toasts .toast"));
confirm.click();
const toast = await until(() => all("#toasts .toast").filter((node) => !shown.has(node)).map(text).find((entry) => entry.startsWith("Deny selection")), 15000);
return {title, before, moved: Math.abs(after - before), focused, buttons, listed, label, toast, posted, wide: document.documentElement.scrollWidth > window.innerWidth + 1};
return {title, before, moved: Math.abs(after - before), focused, buttons, listed, label, reasoned, toast, posted, wide: document.documentElement.scrollWidth > window.innerWidth + 1};
})()""".replace("@HELPERS@", HELPERS)
LAYOUT = """(async () => {@HELPERS@@LABELS@
await until(() => document.querySelector("#main .console") && rowOf("Rule request"), 8000);
+1 -1
View File
@@ -324,7 +324,7 @@ CANCELED = """() => {
}"""
JUMPED = {
"hash": "#stream", "focused": True, "tabs": [[tab, True, True] for tab in ("#home", "#stream/inbox", "#agents/orbit", "#artifacts/tree", "#tasks/list", "#resources")], "closed": [True, "false"],
"header": [["radio-open", "Radio", ""], ["bubbles-toggle", "Speech bubbles", ""], ["palette-open", "Commands", ""], ["settings-open", "Settings", ""]], "radioTab": False,
"header": [["grant-direct", "Direct", "Direct"], ["grant-select", "Select", "Select"], ["radio-open", "Radio", ""], ["bubbles-toggle", "Speech bubbles", ""], ["palette-open", "Commands", ""], ["settings-open", "Settings", ""]], "radioTab": False,
}
GEAR_SAVE = """(async () => {@HELPERS@@CLASHES@
const spot = document.getElementById("radio-spot");
+269
View File
@@ -0,0 +1,269 @@
from __future__ import annotations
import html
import json
import os
import shutil
import sys
import unittest
from pathlib import Path
from unittest import mock
HERE = Path(__file__).resolve().parent
sys.path[:0] = [str(HERE.parent), str(HERE)]
import hub_e2e_kit as base
from hub_e2e_kit import WIDTHS
from hub_support import ASK
from kvb_orchestrator import batches
OUT = Path(os.environ.get("E2E_OUT", "/tmp/bulk-grant-shots"))
FILES = ("src/app.py", "src/view.js", "docs/notes.md")
ROWS = 80
COMMON = """
const row = (ref) => document.querySelector(`#main .inbox-list > li[data-ref="${ref}"]`);
const modeButton = (mode) => document.querySelector(`#grant-bar button[data-mode="${mode}"]`);
const tray = () => document.querySelector("#grant-bar .grant-tray");
const count = () => text(document.querySelector("#grant-bar .grant-count"));
const grantOf = (ref) => row(ref) && row(ref).querySelector(".item-actions button.primary");
const wide = () => document.documentElement.scrollWidth > innerWidth + 1;
const switchState = () => [modeButton("direct").getAttribute("aria-pressed"), modeButton("select").getAttribute("aria-pressed"), tray().hidden, Boolean(document.querySelector("#main .inbox-actions"))];
const storedMode = async (mode) => {
const end = Date.now() + 6000;
while (Date.now() < end) {
const view = await (await fetch("/api/view", {cache: "no-store"})).json();
if (view.approval.mode === mode) {
return true;
}
await sleep(200);
}
return false;
};
const key = (value) => document.body.dispatchEvent(new KeyboardEvent("keydown", {key: value, bubbles: true}));
"""
DIFF = """(async () => {@HELPERS@@COMMON@
if (!(await until(() => row("@REVIEW@"), 8000))) {
return {error: text(document.getElementById("main"))};
}
row("@REVIEW@").querySelector(".headline").click();
const stack = await until(() => {
const found = document.querySelector("#sheet .review-stack");
return found && all(".review-file", found).length === 3 ? found : null;
}, 8000);
if (!stack) {
return {error: text(document.getElementById("sheet"))};
}
const files = () => all(".review-file", stack);
const state = () => ({opened: files().map((file) => file.open), marked: all("#sheet .file-entry[aria-current='true']").map((entry) => Number(entry.dataset.index))});
const first = state();
const [one, two] = files();
stack.scrollTop = one.offsetTop + one.offsetHeight - stack.clientHeight + 4;
await until(() => files()[1].open, 4000);
await sleep(300);
const ended = state();
stack.scrollTop = two.offsetTop;
await until(() => state().marked[0] === 1, 4000);
await sleep(200);
const second = state();
document.querySelector('#sheet .file-entry[data-index="2"]').click();
await sleep(400);
const three = files()[2];
const atTop = Math.abs(three.getBoundingClientRect().top - stack.getBoundingClientRect().top) <= 2 || stack.scrollTop >= stack.scrollHeight - stack.clientHeight - 1;
return {first, ended, second, jumped: {...state(), atTop}, wide: wide()};
})()"""
MODE = """(async () => {@HELPERS@@COMMON@
key("Escape");
await until(() => document.getElementById("sheet").hidden, 4000);
const before = switchState();
modeButton("select").click();
const kept = await storedMode("select");
await until(() => !tray().hidden, 4000);
return {before, kept, after: switchState(), wide: wide()};
})()"""
COLLECT = """(async () => {@HELPERS@@COMMON@
const posted = [];
const send = window.fetch.bind(window);
window.fetch = (path, init) => {
if (["/api/sign", "/api/inbox/approve"].includes(String(path))) {
posted.push(String(path));
}
return send(path, init);
};
if (!(await until(() => row("@REVIEW@") && row("@ASK@") && row("@RUN@") && !tray().hidden, 8000))) {
return {error: text(document.getElementById("main"))};
}
const restored = switchState();
const counts = [];
const press = async (ref, expected) => {
grantOf(ref).click();
await until(() => count() === expected, 3000);
counts.push(count());
};
await press("@REVIEW@", "1 selected");
await press("@ASK@", "2 selected");
await press("@REVIEW@", "1 selected");
await press("@REVIEW@", "2 selected");
if (document.activeElement) {
document.activeElement.blur();
}
for (let step = 0; step < 40 && !row("@RUN@").classList.contains("cursor"); step += 1) {
const cursor = document.querySelector("#main .inbox-list > li.cursor");
key(cursor && Number(cursor.dataset.index) > Number(row("@RUN@").dataset.index) ? "k" : "j");
await sleep(60);
}
key("a");
await until(() => count() === "3 selected", 3000);
counts.push(count());
const pressed = ["@REVIEW@", "@ASK@", "@RUN@"].map((ref) => grantOf(ref).getAttribute("aria-pressed"));
const labels = all("#grant-bar .grant-tray button").map(name);
return {restored, counts, pressed, labels, posted, wide: wide()};
})()"""
SHEET = """(async () => {@HELPERS@@COMMON@
all("#grant-bar .grant-tray button").find((button) => name(button) === "Grant selection (3)").click();
await until(() => document.querySelector(".sheet-box .actions"), 4000);
const confirm = all(".sheet-box .actions button").find((button) => text(button).startsWith("Grant "));
return {listed: all(".sheet-box ul.mini > li strong").map(text), label: text(confirm), wide: wide()};
})()"""
CONFIRM = """(async () => {@HELPERS@@COMMON@
navigator.credentials.get = @SIGNS@ ? navigator.credentials.get.bind(navigator.credentials) : () => Promise.reject(new DOMException("The operator canceled.", "NotAllowedError"));
const posted = [];
const send = window.fetch.bind(window);
window.fetch = (path, init) => {
if (["/api/sign", "/api/inbox/approve"].includes(String(path))) {
posted.push([String(path), JSON.parse(init.body).items.map((item) => `${item.kind}:${item.id}:${item.verb}`).sort()]);
}
return send(path, init);
};
const shown = new Set(all("#toasts .toast"));
all(".sheet-box .actions button").find((button) => text(button).startsWith("Grant ")).click();
const toast = await until(() => all("#toasts .toast").filter((node) => !shown.has(node)).map(text).find((entry) => entry.startsWith("Grant selection")), 15000);
await sleep(@SIGNS@ ? 2500 : 300);
return {posted, toast, count: count(), wide: wide()};
})()"""
DIRECT = """(async () => {@HELPERS@@COMMON@
const posted = [];
const send = window.fetch.bind(window);
window.fetch = (path, init) => {
if (String(path) === "/api/sign") {
posted.push(JSON.parse(init.body).items.map((item) => `${item.kind}:${item.id}`));
return Promise.resolve(new Response("held by the e2e", {status: 503}));
}
return send(path, init);
};
modeButton("direct").click();
const kept = await storedMode("direct");
await until(() => tray().hidden && document.querySelector("#main .inbox-actions"), 4000);
const spare = await until(() => grantOf("@SPARE@"), 4000);
const pressed = spare.getAttribute("aria-pressed");
spare.click();
await until(() => posted.length, 4000);
return {kept, after: switchState(), pressed, posted, wide: wide()};
})()"""
def probe(template: str, **values: str) -> str:
found = template.replace("@HELPERS@", base.HELPERS).replace("@COMMON@", COMMON)
for name, value in values.items():
found = found.replace(f"@{name}@", value)
return found
def review_page() -> str:
sections = []
for path in FILES:
rows = "".join(f'<tr class="add"><td class="num"></td><td class="num">{line}</td><td class="sign">+</td><td class="code">{html.escape(path)} line {line}</td></tr>' for line in range(1, ROWS + 1))
sections.append(f'<details class="file" data-path="{path}"><summary><span class="badge added" title="added">A</span><span class="path">{path}</span>'
f'<span class="stat"><span class="add">+{ROWS}</span><span class="del">&minus;0</span></span></summary><table class="diff"><tbody>{rows}</tbody></table></details>')
return f'<!DOCTYPE html><html><body><section class="group" id="staged" data-files="3">{"".join(sections)}</section></body></html>'
@unittest.skipUnless(shutil.which(os.environ.get("CHROMIUM", "chromium")), "no Chromium")
class TestBulkGrant(base.OrchestratorE2ECase):
def setUp(self):
super().setUp()
OUT.mkdir(parents=True, exist_ok=True)
page = self.page("three-files.html", review_page())
rows = {}
self.sets = {}
for width, _ in WIDTHS:
review = self.review(f"feat: three files {width}", f"feature/bulk-{width}", page)
ask = self.create_ask({**ASK, "command": f"make deploy-{width}", "timeout": 3600})
task = f"operator/bulk-{width}"
rows[task] = {"title": f"echo bulk {width}", "workdir": "/repo", "description": "bulk", "check": "manual", "status": "queued", "roles": {"Operator": "R", "Skills session": "A"}}
self.sets[width] = {"REVIEW": f"review:{review}", "ASK": f"ask:{ask}", "RUN": f"operator:{task}"}
self.spare = f"review:{self.review('feat: spare', 'feature/bulk-spare', page)}"
self.write_council({"rasci.json": rows})
def review(self, title: str, branch: str, page: str) -> str:
arguments = {**self.arguments(title, "", page), "worktree": f"/repo/.worktrees/{branch}", "branch": branch, "agent": "Skills"}
result = self.tool("review_request", arguments)
self.assertFalse(result["isError"], result)
return result["structuredContent"]["id"]
def steps(self, browser: str, signs: bool) -> list[dict]:
local = f"http://localhost:{self.port}/"
flag = "true" if signs else "false"
steps = []
for width, height in WIDTHS:
ids = self.sets[width]
shot = str(OUT / f"{browser}-{width}")
steps += [
{"width": width, "height": height, "url": f"{local}?{width}#stream/inbox", "wait": 1200, "probe": probe(DIFF, **ids), "shot": f"{shot}-continuous-diff.png"},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(MODE), "shot": None},
{"width": width, "height": height, "url": f"{local}?{width}-kept#stream/inbox", "wait": 1200, "probe": probe(COLLECT, **ids), "shot": f"{shot}-select-tray.png"},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(SHEET), "shot": f"{shot}-grant-sheet.png"},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(CONFIRM, SIGNS=flag), "shot": None},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(DIRECT, SPARE=self.spare), "shot": f"{shot}-direct.png"},
]
return steps
def check(self, data: dict, browser: str, signs: bool) -> None:
self.assertEqual([error for error in data["errors"] if "(style-src-elem)" not in error and "/favicon.ico" not in error], [])
results = iter(data["results"])
for width, _ in WIDTHS:
ids = self.sets[width]
diff, mode, collect, sheet, confirm, direct = (next(results) for _ in range(6))
with self.subTest(browser=browser, width=width):
self.assertNotIn("error", diff, diff)
self.assertEqual(diff["first"], {"opened": [True, False, False], "marked": [0]}, diff)
self.assertEqual(diff["ended"]["opened"], [True, True, False], diff)
self.assertEqual(diff["second"], {"opened": [True, True, False], "marked": [1]}, diff)
self.assertEqual(diff["jumped"], {"opened": [True, True, True], "marked": [2], "atTop": True}, diff)
self.assertEqual((mode["before"], mode["kept"], mode["after"]), (["true", "false", True, True], True, ["false", "true", False, False]), mode)
self.assertNotIn("error", collect, collect)
self.assertEqual(collect["restored"], ["false", "true", False, False], collect)
self.assertEqual(collect["counts"], ["1 selected", "2 selected", "1 selected", "2 selected", "3 selected"], collect)
self.assertEqual((collect["pressed"], collect["posted"]), (["true"] * 3, []), collect)
self.assertEqual((collect["labels"][0], collect["labels"][-1]), ("Grant selection (3)", "Clear"), collect)
self.assertEqual((sheet["label"], len(sheet["listed"])), ("Grant 3", 3), sheet)
items = sorted(f"{ref}:approve" for ref in ids.values())
self.assertEqual(confirm["posted"], [["/api/sign", items], *([["/api/inbox/approve", items]] if signs else [])], confirm)
self.assertEqual(confirm["count"], "0 selected" if signs else "3 selected", confirm)
self.assertEqual(direct["kept"], True, direct)
self.assertEqual(direct["after"], ["true", "false", True, True], direct)
self.assertEqual((direct["pressed"], direct["posted"]), (None, [[self.spare]]), direct)
self.assertFalse(any(found["wide"] for found in (diff, mode, collect, sheet, confirm, direct)), width)
def granted(self) -> None:
reviews = [ids["REVIEW"].split(":", 1)[1] for ids in self.sets.values()]
asks = [ids["ASK"].split(":", 1)[1] for ids in self.sets.values()]
self.settle(lambda: all(self.status(review) == "approved" for review in reviews))
self.assertEqual([self.ask_status(ask, "0") for ask in asks], ["allowed"] * len(asks))
self.assertEqual(self.status(self.spare.split(":", 1)[1]), "pending")
def test_chromium_continuous_diff_select_tray_one_signature_and_direct_at_three_widths(self):
with mock.patch.object(batches, "UNDO", 0.3):
data = self.drive(self.steps("chromium", True), self.authenticator())
(OUT / "chromium-bulk-grant.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
self.check(data, "chromium", True)
self.granted()
@unittest.skipUnless(shutil.which(os.environ.get("FIREFOX", "firefox")), "no Firefox")
def test_firefox_continuous_diff_select_tray_and_direct_at_three_widths_unsigned(self):
data = self.drive(self.steps("firefox", False), None, "bidi.mjs", os.environ.get("FIREFOX", "firefox"))
(OUT / "firefox-bulk-grant.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
self.check(data, "firefox", False)
if __name__ == "__main__":
unittest.main()
+3 -4
View File
@@ -50,8 +50,7 @@ class TestHubInbox(base.OrchestratorE2ECase):
def layout(self, probe: dict) -> None:
self.assertNotIn("error", probe)
self.assertEqual(sorted(probe["kinds"]), ["Ask", "Operator", "Operator", "Review", "Rule request"])
self.assertIn(["Deny", "Deny via …"], probe["splits"])
self.assertEqual(len(probe["splits"]), 4)
self.assertEqual(probe["splits"], [["Deny", "Deny via …"]] * 5)
self.assertEqual(probe["fields"], ["Kind", "Tool (glob)", "Pattern (glob)", "Directory (glob)", "Expires on"])
self.assertEqual(probe["dry"], "Dry run: the rule would have granted 1 of 1 asks from the last 7 days.")
self.assertEqual(probe["accept"], 1)
@@ -163,9 +162,9 @@ class TestHubInbox(base.OrchestratorE2ECase):
self.assertGreater(found["before"], 0, found)
self.assertEqual((found["moved"], found["focused"], found["wide"]), (0, True, False), found)
self.assertTrue({"Grant selection (1)", "Deny selection (2)"} <= set(found["buttons"]), found["buttons"])
self.assertEqual((sorted(found["listed"]), found["label"]), (sorted([found["title"], "pick a name"]), "Deny 2"))
self.assertEqual((sorted(found["listed"]), found["label"], found["reasoned"]), (sorted([found["title"], "pick a name"]), "Deny 2", True))
task = f"operator/row-{found['title'][-2:]}"
items = sorted([[task, "reject", "post"], ["operator/name", "reject", "post"]])
items = sorted([[task, "reject", "post", "rebase first"], ["operator/name", "reject", "post", "rebase first"]])
self.assertEqual([[path, sorted(entries)] for path, entries in found["posted"]], [["/api/sign", items], *([["/api/inbox/approve", items]] if signs else [])])
self.assertIn("takes effect" if signs else "not signed", found["toast"])
denied += [task, "operator/name"]
+1 -1
View File
@@ -139,7 +139,7 @@ class TestOrchestratorE2E(base.OrchestratorE2ECase):
with self.subTest(url=step["url"], width=step["width"]):
self.assertNotIn("error", probe)
self.assertEqual((probe["title"], probe["h1"]), ("(2) Agent Orchestrator", "Agent Orchestrator"))
self.assertEqual(probe["header"], ["radio-open", "bubbles-toggle", "palette-open", "settings-open"])
self.assertEqual(probe["header"], ["grant-direct", "grant-select", "radio-open", "bubbles-toggle", "palette-open", "settings-open"])
self.assertEqual((probe["tabs"], probe["subs"]), (TABS, SUBS))
self.assertEqual(probe["badges"], {"tab-home": None, "tab-stream": None, "tab-rules": None, "tab-agents": "1", "tab-artifacts": None, "tab-tasks": "2", "tab-resources": None})
self.assertEqual(probe["banner"], "MAYDAY · Docs: disk full")
+6 -5
View File
@@ -10,7 +10,7 @@ import unittest
from unittest import mock
from hub_case import HubCase
from hub_support import ASK, CLIENT, Key, key, signing, verifier
from hub_support import ASK, CLIENT, PAGE, Key, key, signing, verifier
from kvb_orchestrator import batches, skill_scripts
PUSH = "git push"
@@ -90,21 +90,22 @@ class TestHubDeny(HubCase):
row = {"title": PUSH, "workdir": "/repo", "description": "ship", "check": "manual", "status": "queued", "roles": {"Operator": "R", "Skills session": "A"}}
self.write_council({"rasci.json": {"operator/push": row}})
ask_id = self.create_ask(ASK)
review_id = self.request("feat: deny me", "")
review_id = self.tool("review_request", {**self.arguments("feat: deny me", "", self.page("bundle.html", PAGE)), "agent": "Skills"})["structuredContent"]["id"]
digest = hashlib.sha256(PUSH.encode()).hexdigest()
entries = [
self.denial("ask", ask_id, "", "post", ""),
self.denial("operator", "operator/push", digest, "post", ""),
{**self.entry("review", review_id, "", ""), "verb": "reject"},
self.denial("review", review_id, "", "post", "rebase first"),
]
with mock.patch.object(batches, "UNDO", 0.05):
self.assertEqual(self.approve(entries, self.signed(entries, self.pin()))[0], 202)
self.settle(lambda: self.ask_status(ask_id, "0") == "denied")
self.settle(lambda: (skill_scripts.RASCI, ["set", "operator/push", "--status", "stopped"]) in self.scripts.calls)
self.settle(lambda: self.tool("review_wait", {"id": review_id, "timeout_seconds": 0})["structuredContent"]["status"] == "rejected")
self.settle(lambda: len(self.radio()) >= 2)
self.assertEqual(sorted(sent[:3] for sent in self.radio()), [["post", "--to", "Skills session"]] * 2)
self.settle(lambda: len(self.radio()) >= 3)
self.assertEqual(sorted(sent[:3] for sent in self.radio()), [["post", "--to", "Skills session"]] * 3)
self.assertTrue(all("Denied by the operator: " in sent[-1] for sent in self.radio()), self.radio())
self.assertIn("Denied by the operator: commit feat: deny me", next(sent[-1] for sent in self.radio() if "Reason: rebase first" in sent[-1]))
self.assertFalse({ask_id, review_id} & {item["id"] for item in self.snapshot()["inbox"]})
def test_every_class_but_mayday_reaches_the_agent_or_all(self):
+171
View File
@@ -0,0 +1,171 @@
from __future__ import annotations
import json
import subprocess
import unittest
from hub_support import HUB
TEMPLATES = HUB / "templates"
MODULES = ["page-constants.js", "page-reveal.js", "page-dom.js", "page-inbox.js", "page-grant.js"]
PROBE = r"""
const fs = require("fs");
const vm = require("vm");
const [dir, names] = [process.argv[1], JSON.parse(process.argv[2])];
class El {
constructor(tag) { Object.assign(this, {tag, children: [], attrs: {}, dataset: {}, style: {}, handlers: {}, hidden: false, textContent: ""}); }
setAttribute(key, value) {
this.attrs[key] = String(value);
if (key.startsWith("data-")) {
this.dataset[key.slice(5).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())] = String(value);
}
}
getAttribute(key) { return Object.hasOwn(this.attrs, key) ? this.attrs[key] : null; }
append(...nodes) { this.children.push(...nodes); }
replaceChildren(...nodes) { this.children = nodes; }
addEventListener(name, handler) { this.handlers[name] = handler; }
click() { this.handlers.click({stopPropagation() {}, preventDefault() {}}); }
remove() {}
}
const all = (node) => [node, ...(node.children || []).filter((child) => child instanceof El).flatMap(all)];
const text = (node) => (typeof node === "string" ? node : (node.children || []).map(text).join(""));
const buttons = (node) => all(node).filter((el) => el.tag === "button");
const document = {
currentScript: null, body: new El("body"), hidden: false, activeElement: null,
getElementById: (id) => Object.assign(new El("div"), {textContent: id === "emoji-bases" ? "[]" : ""}),
createElement: (tag) => new El(tag), createElementNS: (ns, tag) => new El(tag),
};
const now = 1_800_000_000;
const base = {agent: "Store", to: "Store", detail: "", green: false, gate: "", score: "", warnings: [], options: [], recommended: "", command: "", directory: "/repo", sha256: "s", runnable: false, deniable: false, job: null, rule: null, dry_run: null, diff: null, pinned: false, until: 0, held: false, ts: now};
const items = {
green: {...base, kind: "review", id: "r-green", title: "feat: green", gate: "pass", green: true},
red: {...base, kind: "review", id: "r-red", title: "feat: red", gate: "fail"},
ask: {...base, kind: "ask", id: "a-1", title: "git push: ask", command: "git push"},
run: {...base, kind: "operator", id: "operator/run", title: "make install", command: "make install", runnable: true, deniable: true},
pick: {...base, kind: "decision", id: "d-1", title: "Which?", recommended: "A", options: [{label: "A", description: ""}]},
rule: {...base, kind: "rule", id: "1123456789abcdef", title: "Rule ask Bash make deploy"},
};
const mode = {value: "select"};
const sets = [];
const listeners = [];
const context = {
console, document, JSON, Math, Date, Intl, Promise, Set, Map, Number, String, Array, Object, RegExp, Boolean, Error, setTimeout,
Node: El, Element: El, HTMLElement: El,
window: {location: {hash: "", hostname: "localhost", port: "8737", pathname: "/"}, setTimeout: () => 0, clearTimeout: () => {}, setInterval: () => 0, clearInterval: () => {}, getSelection: () => "", matchMedia: () => ({matches: false})},
state: {inbox: [], radio: [], messages: [], settings: {}, now},
ui: {screen: "inbox", busy: false, selected: new Set(), cursor: 0, snoozed: false, asOf: null},
known: {batches: new Set()},
ViewStore: {get: (path) => (path === "approval.mode" ? mode.value : null), set: (path, value) => { sets.push([path, value]); mode.value = value; }, on: (path, callback) => listeners.push([path, callback])},
denySplit: () => new El("deny"), jobOpen: () => false, load: async () => {}, openItem: () => {},
items, mode, sets, listeners, all, text, buttons,
};
const source = names.map((name) => fs.readFileSync(`${dir}/${name}`, "utf8")).join("\n");
const probe = `
const proofs = [];
const accepts = [];
let renders = 0;
let streams = 0;
proofFor = async (entries) => { proofs.push(entries.map((entry) => entry.kind + ":" + entry.id)); return null; };
acceptRule = (item) => { accepts.push(item.id); };
render = () => { renders += 1; };
drawStream = () => { streams += 1; };
toast = () => ({remove() {}});
const results = {};
const take = () => ({selected: [...ui.selected].sort(), proofs: proofs.splice(0), accepts: accepts.splice(0), renders, streams});
const press = (item) => {
const first = actionsFor(item)[0];
return {pressed: first.getAttribute("aria-pressed"), title: first.getAttribute("title")};
};
(async () => {
state.inbox = Object.values(items).map((item) => ({...item}));
const of = (key) => state.inbox.find((item) => item.id === items[key].id);
results.unpressed = press(of("green"));
await approveOne(of("green"));
results.added = take();
results.pressed = press(of("green"));
await approveOne(of("green"));
results.removed = take();
for (const key of ["green", "ask", "run", "pick"]) {
await approveOne(of(key));
}
results.collected = take();
await approveOne(of("red"));
results.red = {...take(), press: press(of("red"))};
await approveOne(of("rule"));
results.rule = {...take(), press: press(of("rule"))};
grantBoot();
const bar = grantView.tray;
const modes = grantView.modes;
results.tray = {hidden: bar.hidden, text: text(bar), labels: buttons(bar).map((button) => button.getAttribute("aria-label")), modes: modes.map((button) => [button.dataset.mode, button.getAttribute("aria-pressed")]), listen: listeners.map(([path]) => path)};
buttons(bar).pop().click();
results.cleared = take();
modes[0].click();
results.switched = sets.splice(0);
drawGrant();
results.direct_tray = {hidden: bar.hidden, children: bar.children.length, modes: modes.map((button) => button.getAttribute("aria-pressed"))};
results.direct_press = press(of("green"));
await approveOne(of("green"));
results.direct = take();
console.log(JSON.stringify(results));
})().catch((error) => { console.error(error && error.stack || error); process.exit(1); });
`;
vm.runInNewContext(`${source}\n${probe}`, {...context, process});
"""
class TestGrantMode(unittest.TestCase):
@classmethod
def setUpClass(cls):
done = subprocess.run(["node", "-e", PROBE, str(TEMPLATES), json.dumps(MODULES)], capture_output=True, text=True, timeout=60, check=False)
if done.returncode != 0:
raise AssertionError(done.stderr[-4000:])
cls.data = json.loads(done.stdout)
def test_a_grant_in_select_toggles_the_selection_without_a_signature(self):
self.assertEqual(self.data["added"]["selected"], ["review:r-green"])
self.assertEqual(self.data["added"]["proofs"], [])
self.assertEqual((self.data["added"]["renders"], self.data["added"]["streams"]), (1, 1))
self.assertEqual(self.data["removed"]["selected"], [])
self.assertEqual(self.data["removed"]["proofs"], [])
def test_every_selectable_kind_collects_in_select(self):
self.assertEqual(self.data["collected"]["selected"], ["ask:a-1", "decision:d-1", "operator:operator/run", "review:r-green"])
self.assertEqual(self.data["collected"]["proofs"], [])
def test_the_grant_button_shows_whether_its_item_is_selected(self):
self.assertEqual(self.data["unpressed"]["pressed"], "false")
self.assertTrue(self.data["unpressed"]["title"].startswith("Select: "), self.data["unpressed"])
self.assertEqual(self.data["pressed"]["pressed"], "true")
def test_a_red_gate_and_a_rule_stay_direct_in_select_and_say_why(self):
self.assertEqual(self.data["red"]["proofs"], [["review:r-red"]])
self.assertEqual(self.data["red"]["press"]["pressed"], None)
self.assertEqual(self.data["red"]["press"]["title"], "Grant: acts at once, a red gate is never granted in a selection")
self.assertEqual(self.data["rule"]["accepts"], ["1123456789abcdef"])
self.assertEqual(self.data["rule"]["proofs"], [])
self.assertTrue(self.data["rule"]["press"]["title"].endswith(": acts at once, a rule is accepted one at a time"), self.data["rule"])
def test_the_tray_counts_the_selection_and_holds_its_actions(self):
tray = self.data["tray"]
self.assertFalse(tray["hidden"])
self.assertTrue(tray["text"].startswith("4 selected"), tray)
self.assertEqual(tray["labels"], ["Grant selection (4)", "Deny selection (2)", "Grant all green (1)", "Clear"])
self.assertEqual(tray["modes"], [["direct", "false"], ["select", "true"]])
self.assertEqual(tray["listen"], ["approval"])
def test_clear_empties_the_selection(self):
self.assertEqual(self.data["cleared"]["selected"], [])
def test_the_switch_stores_the_mode_in_the_view_store(self):
self.assertEqual(self.data["switched"], [["approval.mode", "direct"]])
def test_direct_hides_the_tray_and_grants_at_once(self):
self.assertEqual(self.data["direct_tray"], {"hidden": True, "children": 0, "modes": ["true", "false"]})
self.assertEqual(self.data["direct_press"]["pressed"], None)
self.assertEqual(self.data["direct_press"]["title"], "Grant")
self.assertEqual(self.data["direct"]["proofs"], [["review:r-green"]])
self.assertEqual(self.data["direct"]["selected"], [])
if __name__ == "__main__":
unittest.main()
+2 -2
View File
@@ -7,7 +7,7 @@ import unittest
from hub_support import HUB
TEMPLATES = HUB / "templates"
MODULES = ["page-constants.js", "page-reveal.js", "page-dom.js", "page-api.js", "page-passkey.js", "page-inbox.js", "page-console.js", "page-rule-request.js", "page-load.js"]
MODULES = ["page-constants.js", "page-reveal.js", "page-dom.js", "page-api.js", "page-passkey.js", "page-inbox.js", "page-grant.js", "page-console.js", "page-rule-request.js", "page-load.js"]
GONE = "operator/gui-agentbox-merge-push"
NOTICE = "already done or removed elsewhere"
PROBE = r"""
@@ -95,7 +95,7 @@ const grantBoth = () => submit(state.inbox.map((item) => entryOf(item, "approve"
(async () => {
await scenario("run_sign_404", ["gone", "kept"], {"/api/sign": missing}, () => approveOne(state.inbox[0]));
await scenario("run_approve_404", ["gone", "kept"], {"/api/sign": reply(200, '{"payload": null}'), "/api/inbox/approve": missing}, () => approveOne(state.inbox[0]));
await scenario("deny_404", ["gone", "kept"], {"/api/sign": missing}, () => rejectOne(state.inbox[0]));
await scenario("deny_404", ["gone", "kept"], {"/api/sign": missing}, () => submit([denialOf(state.inbox[0], "")], "Denial: " + short(state.inbox[0].title)));
await scenario("dismiss_404", ["closed", "kept"], {"/api/inbox/dismiss": missing}, () => dismissJob(state.inbox[0].job));
await scenario("rule_404", ["rule", "kept"], {["/api/rule-requests/" + items.rule.id + "/sign"]: missing}, () => acceptRule(state.inbox[0]));
await scenario("run_409", ["gone", "kept"], {"/api/sign": reply(409, '{"id": "operator/kept", "status": "changed"}')}, () => approveOne(state.inbox[1]));
+1 -1
View File
@@ -24,7 +24,7 @@ hub_limits = importlib.import_module("hub_limits")
approval = importlib.import_module("approval")
TEMPLATES = HUB / "templates"
DIFFS = TEMPLATES / "diffs.js"
PAGE_MODULES = ["page-constants.js", "page-reveal.js", "page-dom.js", "page-diff.js", "page-inbox.js", "page-stream.js", "page-screens.js", "page-keyboard.js"]
PAGE_MODULES = ["page-constants.js", "page-reveal.js", "page-dom.js", "page-diff.js", "page-inbox.js", "page-grant.js", "page-stream.js", "page-screens.js", "page-keyboard.js"]
SECRET = 'api_key = "plain-example-words"'
ARMOURED = "before\n-----BEGIN EXAMPLE-----\nplain words only\n-----END EXAMPLE-----\nafter\n"
WITHHELD = "content withheld"
+6 -1
View File
@@ -35,6 +35,7 @@ FULL = {
"home": {"pins": [{"kind": "panel", "id": "resources-hardware", "w": 12, "h": 4}, {"kind": "task", "id": "work/feature", "w": 1, "h": 12}]},
"kanban": {"hidden": ["line"]},
"legend": {"views": {"resources-tokens": False, "tasks/burn": True}, "tiles": {"panel:resources-hardware": False}},
"approval": {"mode": "select"},
}
PIN ={"kind": "panel", "id": "resources-hardware", "w": 6, "h": 3}
EMBEDDED = re.compile(r'<script nonce="[^"]+" id="view" type="application/json">(.*?)</script>')
@@ -291,7 +292,7 @@ class TestViewDocument(unittest.TestCase):
def test_the_defaults_and_a_full_document_pass_unchanged(self):
self.assertEqual(valid_view(copy.deepcopy(VIEW)), VIEW)
self.assertEqual(valid_view(copy.deepcopy(FULL)), FULL)
self.assertEqual(VIEW, {"resources": {"hidden": [], "tokens": "interval", "combined": False, "combinedHidden": []}, "burn": {"overlays": []}, "home": {"pins": []}, "kanban": {"hidden": []}, "legend": {"views": {}, "tiles": {}}})
self.assertEqual(VIEW, {"resources": {"hidden": [], "tokens": "interval", "combined": False, "combinedHidden": []}, "burn": {"overlays": []}, "home": {"pins": []}, "kanban": {"hidden": []}, "legend": {"views": {}, "tiles": {}}, "approval": {"mode": "direct"}})
def test_unknown_or_missing_keys_and_malformed_values_are_refused(self):
def changed(section: str | None, key: str | None, value: object) -> dict:
@@ -342,6 +343,10 @@ class TestViewDocument(unittest.TestCase):
"legend shown as text": changed("legend", "tiles", {"panel:resources-hardware": "false"}),
"legend tile key without kind": changed("legend", "tiles", {"resources-hardware": False}),
"legend tile key with a space": changed("legend", "tiles", {"panel:resources hardware": False}),
"approval section missing": {key: value for key, value in FULL.items() if key != "approval"},
"approval unknown key": changed("approval", "batch", True),
"approval mode unknown": changed("approval", "mode", "auto"),
"approval mode not text": changed("approval", "mode", True),
}
for name, doc in cases.items():
with self.subTest(case=name), self.assertRaises(ToolError):
+1 -1
View File
@@ -10,7 +10,7 @@ from pathlib import Path
from hub_support import signing
TEMPLATES = Path(__file__).resolve().parent.parent / "orchestrator" / "templates"
MODULES = ["page-constants.js", "glossary.js", "ancestry.js", "page-reveal.js", "page-dom.js", "page-diff.js", "page-rule-request.js", "page-inbox.js", "page-firewall.js", "page-review.js", "page-cleanup.js", "page-offices.js", "page-ancestry.js", "page-tasks-prio.js"]
MODULES = ["page-constants.js", "glossary.js", "ancestry.js", "page-reveal.js", "page-dom.js", "page-diff.js", "page-rule-request.js", "page-inbox.js", "page-grant.js", "page-firewall.js", "page-review.js", "page-cleanup.js", "page-offices.js", "page-ancestry.js", "page-tasks-prio.js"]
RLO, ZWSP, LRI, SEPARATOR, CARRIAGE = chr(0x202E), chr(0x200B), chr(0x2066), chr(0x2028), chr(0x0D)
FILLER, NBSP, CGJ, VS15, VS16 = chr(0x3164), chr(0xA0), chr(0x34F), chr(0xFE0E), chr(0xFE0F)
HIDDEN = (RLO, ZWSP, LRI, SEPARATOR, CARRIAGE, FILLER, NBSP, CGJ, VS16)