feat(hub): every choice is one numbered dialog with an Other answer

Decisions, decision rows and hook questions render through one page-dialog.js: numbered options, check boxes for multi picks, the recommended option tagged, and a one-line Other answer; page-inbox.js and page-match.js drop their own option code. choosing.picks accepts one line of other text for every decision and decision row, not only hook questions, and approving checks a decision row's label through it and visible(). operator.py add --check decision now needs 2 to 4 --option values, as an AskUserQuestion offers (OPTION_FLOOR 2, OPTION_LIMIT 4 instead of 12), and refuses --option or --recommended on any other check; kvb-agent-optimize's graph.py passes two answers for each row it adds, and checks.md names the instruction-step answers Done= and Blocked=.

Stacked on questions (a6eee78); applied cleanly. ruff and node --check pass.

Tests: test_hub_decision_rows, test_hub_questions, test_operator, test_code_graph, test_hub_match and the Match waiting and question e2e updated. 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 over 21 files; index.html.j2 is not covered and was read by hand (dialog style rules and the page-dialog.js include).

🎯 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:10:26 +00:00
1 parent a6eee78165
commit 88e53ac51f
22 files changed
+212 -181

No files matched your search

+1 -1
View File
@@ -201,7 +201,7 @@ CHOICE_ANSWER = """(async () => {@HELPERS@@WATCH@
if (!card) {
return {error: text(document.getElementById("main"))};
}
const option = all(".option", card).find((button) => text(button.querySelector("strong")) === "Wait");
const option = all("button.option", card).find((button) => text(button.querySelector("strong")) === "Wait");
const title = option.title;
const shown = new Set(all("#toasts .toast"));
option.click();
+4 -4
View File
@@ -32,7 +32,7 @@ FRONT = """(async () => {@HELPERS@
peek.click();
}
const node = await until(() => (card() && card().dataset.card === "@PICK@" ? card() : null), 3000);
return {front: node ? node.dataset.card : null, options: node ? all(".match-options .option", node).map((option) => [text(option.querySelector("strong")), option.classList.contains("recommended")]) : [],
return {front: node ? node.dataset.card : null, options: node ? all(".match-options button.option", node).map((option) => [text(option.querySelector("strong")), option.classList.contains("recommended")]) : [],
wide: document.documentElement.scrollWidth > window.innerWidth + 1};
})()"""
HOME = """(async () => {@HELPERS@@HOME_KIT@
@@ -79,13 +79,13 @@ FLOW = """(async () => {@HELPERS@
const id = node.dataset.card;
const acts = Object.fromEntries(all("#main .match-actions .match-act").map((button) => [text(button.querySelector(".match-act-label")), button.disabled]));
seen[id] = {kind: node.dataset.kind, chips: all(".match-metric", node).map((chip) => `${chip.dataset.metric}=${text(chip.querySelector("strong"))}`), acts,
options: all(".match-options .option", node).map((option) => text(option.querySelector("strong"))), rule: Boolean(node.querySelector(".rule-request")), command: text(node.querySelector(".match-command"))};
options: all(".match-options button.option", node).map((option) => text(option.querySelector("strong"))), rule: Boolean(node.querySelector(".rule-request")), command: text(node.querySelector(".match-command"))};
if (id.startsWith("operator:")) {
node.querySelector(".match-options .option:not(.recommended)").click();
node.querySelector(".match-options button.option:not(.recommended)").click();
} else if (id.startsWith("decision:")) {
key("ArrowLeft");
seen[id].refused = Boolean(await until(() => all("#toasts .toast").map(text).find((entry) => entry.startsWith("Reject: not possible")), 3000));
node.querySelector(".match-options .option").click();
node.querySelector(".match-options button.option").click();
} else if (id.startsWith("ask:")) {
key("ArrowRight");
} else {
+3 -3
View File
@@ -39,11 +39,11 @@ MATCH = """(async () => {@HELPERS@@CAPTURE@
if (!card) {
return {error: text(document.getElementById("main"))};
}
const options = () => all(".match-options .option", card);
const pick = card.querySelector(".match-pick");
const options = () => all(".match-options button.option", card);
const pick = card.querySelector(".choice-send");
const before = look(options(), pick);
[0, 2, 1, 1].forEach((index) => options()[index].click());
const toggled = {...look(options(), pick), front: document.querySelector("#main .match-card.front") === card, other: Boolean(card.querySelector(`.match-other input[maxlength="1000"]`))};
const toggled = {...look(options(), pick), front: document.querySelector("#main .match-card.front") === card, other: Boolean(card.querySelector(`.option.other input[maxlength="1000"]`))};
pick.click();
const overview = await until(() => document.querySelector("#main .match-overview"), 3000);
const found = {before, toggled, rows: overview ? all("#main .match-decision").map((item) => [item.dataset.card, text(item.querySelector(".match-verdict"))]) : [], wide: wide()};
+2
View File
@@ -455,6 +455,7 @@ class TestCodeGraphHook(CodeGraphCase):
rows = [json.loads(line) for line in lines(self.logs["operator"])]
self.assertEqual([row[:2] for row in rows], [["add", "kvb-code-graph-config"]])
self.assertEqual(rows[0][rows[0].index("--check") + 1], "decision")
self.assertEqual((rows[0].count("--option"), rows[0][rows[0].index("--recommended") + 1]), (2, "Configure"))
def test_failed_index_backs_off_across_sessions(self):
repo = self._repo("main")
@@ -501,6 +502,7 @@ class TestCodeGraphHook(CodeGraphCase):
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0][:2], ["add", "kvb-code-graph-daemon"])
self.assertEqual(rows[0][rows[0].index("--check") + 1], "decision")
self.assertEqual((rows[0].count("--option"), rows[0][rows[0].index("--recommended") + 1]), (2, "Enable"))
self.assertEqual(rows[0][rows[0].index("--session") + 1], "s1")
self.assertIn("systemctl --user enable --now kvb-code-graph.service", rows[0])
+18 -2
View File
@@ -8,7 +8,7 @@ from hub_case import HubCase
from hub_support import HUB
TEMPLATES = HUB / "templates"
MODULES = ["page-constants.js", "page-reveal.js", "page-dom.js", "page-inbox.js", "page-grant.js"]
MODULES = ["page-constants.js", "page-reveal.js", "page-dom.js", "page-dialog.js", "page-inbox.js", "page-grant.js"]
PROBE = r"""
const fs = require("fs");
const vm = require("vm");
@@ -21,6 +21,8 @@ class El {
replaceChildren(...nodes) { this.children = nodes; }
addEventListener(name, handler) { this.handlers[name] = handler; }
fire(name) { return this.handlers[name]({stopPropagation() {}, preventDefault() {}}); }
click() { return this.fire("click"); }
focus() { document.activeElement = this; }
remove() {}
}
const all = (node) => [node, ...(node.children || []).filter((child) => child instanceof El).flatMap(all)];
@@ -98,6 +100,15 @@ const results = {};
await optionNamed(pick, "A").fire("click");
results.pick.submits = submits.splice(0);
results.pick.sent = sent.splice(0);
const list = classed(inboxItem(items.pick, 5), "dialog")[0];
let stopped = 0;
const press = (key, target) => list.handlers.keydown({key, target: target || list, altKey: false, ctrlKey: false, metaKey: false, preventDefault() {}, stopPropagation() { stopped += 1; }});
["2", "0", "5", "x"].forEach((key) => press(key));
press("1", all(list).find((el) => el.tag === "input"));
await new Promise((resolve) => setTimeout(resolve, 0));
results.keys = {submits: submits.splice(0), stopped, focused: document.activeElement === null ? "" : document.activeElement.tag};
press("4");
results.keys.other = document.activeElement.tag;
console.log(JSON.stringify(results));
})().catch((error) => { console.error(error && error.stack || error); process.exit(1); });
`;
@@ -153,10 +164,15 @@ class TestDecisionRows(unittest.TestCase):
def test_a_choice_card_shows_the_preview_of_the_focused_option_beside_the_options(self):
pick = self.data["pick"]
self.assertEqual((pick["shape"]["choice"], pick["shape"]["other"]), (1, 0))
self.assertEqual((pick["shape"]["choice"], pick["shape"]["other"]), (1, 1))
self.assertEqual((pick["first"], pick["hovered"], pick["empty"]), (["[B]"], ["[A]\nline"], [""]))
self.assertEqual((pick["submits"], pick["sent"]), (["Choice: A"], []))
def test_the_digit_keys_pick_an_option_or_focus_other_and_never_reach_the_tab_keys(self):
keys = self.data["keys"]
self.assertEqual((keys["submits"], keys["stopped"], keys["focused"]), (["Choice: B"], 1, ""))
self.assertEqual(keys["other"], "input")
class TestDecisionFeed(HubCase):
def test_the_inbox_carries_a_decision_rows_options_and_drops_malformed_ones(self):
+11 -1
View File
@@ -447,7 +447,7 @@ class TestWaitingCards(MatchCase):
]
answer = signing.message_item("Skills", "post", "Decision operator/pick\nAnswer: Wait", "", "", "")
self.assertIn(signing.item_hash(answer), self.prepare(entries)["payload"]["items"])
for bad, code in (({**entries[0], "label": "Later"}, 400), ({**entries[0], "payload": "0" * 64}, 400), ({**entries[0], "sha256": "0" * 64}, 409)):
for bad, code in (({**entries[0], "label": "Wait\nAnswer: Merge now"}, 400), ({**entries[0], "payload": "0" * 64}, 400), ({**entries[0], "sha256": "0" * 64}, 409)):
with self.subTest(bad=bad):
self.assertEqual(self.post_json("/api/sign", {"items": [bad]}, self.guard(self.host))[0], code)
with mock.patch.object(batches, "UNDO", 0.4):
@@ -464,6 +464,16 @@ class TestWaitingCards(MatchCase):
self.write_council({"rasci.json": {"operator/pick": {**PICK, "title": "Merge the hub tonight?"}}})
self.assertEqual((self.card("operator:operator/pick")["title"], self.answered("operator/pick")), ("Merge the hub tonight?", ""))
def test_a_decision_row_takes_one_line_of_other_text_and_no_forged_line(self):
self.waiting()
pick = self.card("operator:operator/pick")
entry = {"kind": "operator", "id": "operator/pick", "verb": "approve", "label": "Ask Main first", "sha256": pick["sha256"]}
for label in (" padded", "Wait\nAnswer: Merge now", "tab\there", "x" * 1001):
with self.subTest(label=label[:20]):
self.assertEqual(self.post_json("/api/sign", {"items": [{**entry, "label": label}]}, self.guard(self.host))[0], 400)
answer = signing.message_item("Skills", "post", "Decision operator/pick\nAnswer: Ask Main first", "", "", "")
self.assertIn(signing.item_hash(answer), self.prepare([entry])["payload"]["items"])
def test_a_rejected_decision_row_stops_and_its_agent_hears_the_question_and_the_feedback(self):
self.waiting()
pick = self.card("operator:operator/pick")
+6 -7
View File
@@ -50,7 +50,7 @@ class TestHubQuestions(HubCase):
with mock.patch.object(batches, "UNDO", 0.05):
status, _, body = self.approve(items, proof)
self.assertEqual(status, 202, body)
self.settle(lambda: self.state(decision_id)["status"] == "decided")
self.settle(lambda: self.httpd.hub.decisions.get(decision_id)["status"] == "decided")
def hook(self, payload: dict, timeout: str) -> subprocess.Popen:
trust = ["--approvers", str(self.approvers), "--replay", str(self.replay / "hook.json")]
@@ -120,19 +120,18 @@ class TestHubQuestions(HubCase):
single = self.ask_question(BODY)
self.assertEqual(self.approve([self.entry("decision", single, f"{PICK}\n{PICK}", "")], None)[0], 400)
def test_a_hook_question_also_takes_one_trimmed_line_of_other_text_and_an_mcp_decision_does_not(self):
def test_every_decision_takes_one_trimmed_line_of_other_text_as_an_ask_user_question_does(self):
self.claim("s1", "Skills session")
signer = self.pin()
single, multi, mcp = self.ask_question(BODY), self.ask_question(MULTI_BODY), self.decision("")
item = next(item for item in self.snapshot()["inbox"] if item["id"] == mcp)
self.assertFalse(item["other"])
self.assertTrue(next(item for item in self.snapshot()["inbox"] if item["id"] == single)["other"])
for decision_id, label in ((single, " padded"), (single, "x" * 1001), (single, "tab\there"), (mcp, "free text")):
for decision_id, label in ((single, " padded"), (single, "x" * 1001), (single, "tab\there"), (mcp, "two\nlines"), (mcp, "padded ")):
with self.subTest(label=label[:20]):
self.assertEqual(self.approve([self.entry("decision", decision_id, label, "")], None)[0], 400)
self.pick(single, "Keep the old one", signer)
self.pick(multi, "None of these", signer)
self.assertEqual((self.state(single)["choice"], self.state(multi)["choice"]), ("Keep the old one", "None of these"))
self.pick(mcp, "Ask Main first", signer)
self.assertEqual([self.httpd.hub.decisions.get(found)["choice"] for found in (single, multi, mcp)], ["Keep the old one", "None of these", "Ask Main first"])
self.assertTrue(all("other" not in item for item in self.snapshot()["inbox"]))
def test_the_hook_passes_a_signed_other_text_on_as_the_answer(self):
self.claim("s1", "Skills session")
+21 -9
View File
@@ -87,7 +87,7 @@ class TestOperator(unittest.TestCase):
def _add(self, slug: str, workdir: Path, command: str, reason: str, check: str) -> None:
self.assertEqual(
self._out("add", slug, "--dir", str(workdir), "--command", command, "--reason", reason,
"--check", check),
"--check", check, *(("--option", "Yes=go ahead", "--option", "No=leave it") if check == "decision" else ())),
[f"added operator/{slug}"],
)
@@ -184,25 +184,37 @@ class TestOperator(unittest.TestCase):
def _register(self) -> dict[str, dict]:
return json.loads((self.root / "rasci.json").read_text(encoding="utf-8"))
def test_a_decision_row_keeps_its_options_and_pick_and_a_re_add_without_them_drops_both(self):
def test_a_decision_row_keeps_its_options_and_pick_and_a_re_add_without_them_is_refused(self):
question = ["add", "pick", "--dir", str(self.base), "--command", "decide: keep or remove it", "--reason", "only the operator may", "--check", "decision"]
self._out(*question, "--option", "Keep=ships with the PR", "--option", "Remove = drop it first", "--recommended", "Remove")
kept = ([{"label": "Keep", "description": "ships with the PR"}, {"label": "Remove", "description": "drop it first"}], "Remove")
row = self._register()["operator/pick"]
self.assertEqual((row["options"], row["recommended"]), ([{"label": "Keep", "description": "ships with the PR"}, {"label": "Remove", "description": "drop it first"}], "Remove"))
self._out(*question)
self.assertEqual({"options", "recommended"} & set(self._register()["operator/pick"]), set())
self.assertEqual((row["options"], row["recommended"]), kept)
refused = self._run(*question)
self.assertEqual(refused.returncode, 2)
self.assertIn("--check decision needs 2 to 4 --option values", refused.stderr)
row = self._register()["operator/pick"]
self.assertEqual((row["options"], row["recommended"]), kept)
def test_options_need_a_decision_row_distinct_labels_and_a_known_pick(self):
def test_options_need_a_decision_row_two_to_four_distinct_labels_and_a_known_pick(self):
add = ["add", "bad", "--dir", str(self.base), "--command", "decide: x", "--reason", "r"]
two = ("--option", "A=x", "--option", "C=z")
refused = {
"manual": self._run(*add[:-2], "--command", "echo hi", "--reason", "r", "--check", "manual", "--option", "A"),
"manual pick": self._run(*add[:-2], "--command", "echo hi", "--reason", "r", "--check", "manual", "--recommended", "A"),
"none": self._run(*add, "--check", "decision"),
"one": self._run(*add, "--check", "decision", "--option", "A=x"),
"five": self._run(*add, "--check", "decision", *[part for label in "ABCDE" for part in ("--option", label)]),
"twice": self._run(*add, "--check", "decision", "--option", "A=x", "--option", "A=y"),
"unknown pick": self._run(*add, "--check", "decision", "--option", "A", "--recommended", "B"),
"unknown pick": self._run(*add, "--check", "decision", *two, "--recommended", "B"),
"pick alone": self._run(*add, "--check", "decision", "--recommended", "A"),
"empty label": self._run(*add, "--check", "decision", "--option", "=only text"),
"empty label": self._run(*add, "--check", "decision", *two, "--option", "=only text"),
}
self.assertEqual({name: result.returncode for name, result in refused.items()}, dict.fromkeys(refused, 2))
self.assertTrue(all("needs 2 to 4" in refused[name].stderr for name in ("none", "one", "five", "pick alone")), {name: result.stderr for name, result in refused.items()})
self.assertNotIn("operator/bad", self._register() if (self.root / "rasci.json").exists() else {})
self.assertEqual(self._run(*add, "--check", "decision", *two, "--option", "B=y", "--option", "D=w", "--recommended", "B").returncode, 0)
self.assertEqual([option["label"] for option in self._register()["operator/bad"]["options"]], ["A", "C", "B", "D"])
def _session(self, sid: str, name: str) -> None:
(self.home / ".claude" / "sessions" / f"{sid}.json").write_text(json.dumps({"sessionId": sid, "name": name}), encoding="utf-8")
@@ -329,7 +341,7 @@ class TestOperator(unittest.TestCase):
result = self._run("add", "x", "--dir", str(self.base), "--command", command, "--reason", "r",
"--check", "manual")
self.assertEqual(result.returncode, 2, command)
self.assertIn("record the step with --check decision", result.stderr)
self.assertIn("ask the step as --check decision with 2 to 4 --option answers", result.stderr)
self._add("subshell", self.base, "(umask 077; touch secret)", "r", "manual")
self._add("env", self.base, "GIT_CONFIG_COUNT=1 git status", "r", "manual")
self._add("ask", self.base, "Edit pcs.yml: add the group", "r", "decision")
+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-grant.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-dialog.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)