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>
60 lines
4.3 KiB
JavaScript
60 lines
4.3 KiB
JavaScript
/**
|
|
* @param {Object} item a decision, a decision row or a decision card: id, options [{label, description, preview}], recommended (labels joined by PICKED), multi.
|
|
* @param {Object} how pick: called with the answer, one label, the toggled labels in option order joined by PICKED, or the trimmed Other text; toggled: the Set of toggled labels of a multi decision, kept by the caller across redraws; chosen: the answer given so far, "" for none; locked: whether the dialog takes no answer; hint: what an answer does, shown in the titles; group: an extra class of the option list.
|
|
* @returns {HTMLElement} the dialog an AskUserQuestion shows: numbered options with their description, the recommended ones tagged, a free-text Other row, Send for a multi decision, and a preview pane beside them once an option has one. The keys 1 to n pick or toggle an option, n + 1 focuses Other.
|
|
*/
|
|
function choiceDialog(item, how) {
|
|
const recommended = item.recommended ? item.recommended.split(PICKED) : [];
|
|
const chosen = how.chosen ? how.chosen.split(PICKED) : [];
|
|
const pane = item.options.some((option) => option.preview) ? h("pre", {class: "choice-preview", "aria-label": "Preview"}) : null;
|
|
const show = (option) => {
|
|
if (pane) {
|
|
pane.textContent = revealedLines(option.preview || "");
|
|
}
|
|
};
|
|
const send = item.multi ? h("button", {type: "button", class: "btn small primary choice-send", disabled: how.locked || !how.toggled.size, ...named("Send", revealed(`Send the toggled options: ${how.hint}`))}, icon("bi-check2-square"), "Send") : null;
|
|
const buttons = item.options.map((option) => {
|
|
const marked = recommended.includes(option.label);
|
|
const button = h("button", {
|
|
type: "button", class: `option${marked ? " recommended" : ""}`, disabled: how.locked, "aria-pressed": String(item.multi ? how.toggled.has(option.label) : chosen.includes(option.label)),
|
|
title: revealed(`${option.label}: ${how.hint}`),
|
|
on: {click: () => {
|
|
if (!item.multi) {
|
|
how.pick(option.label);
|
|
return;
|
|
}
|
|
how.toggled.has(option.label) ? how.toggled.delete(option.label) : how.toggled.add(option.label);
|
|
button.setAttribute("aria-pressed", String(how.toggled.has(option.label)));
|
|
send.disabled = !how.toggled.size;
|
|
}, focus: () => show(option), mouseenter: () => show(option)},
|
|
}, h("strong", {}, revealed(option.label)), marked && !option.label.includes("(Recommended)") ? h("em", {class: "option-tag"}, "Recommended") : null,
|
|
option.description ? h("span", {}, revealed(option.description)) : null);
|
|
return button;
|
|
});
|
|
if (send) {
|
|
send.addEventListener("click", () => how.pick(item.options.filter((option) => how.toggled.has(option.label)).map((option) => option.label).join(PICKED)));
|
|
}
|
|
const typed = chosen.length === 1 && !item.options.some((option) => option.label === chosen[0]) ? chosen[0] : null;
|
|
const input = h("input", {class: "field", type: "text", maxlength: OTHER_LIMIT, placeholder: "Other: type your own answer …", "aria-label": `Other answer to ${item.id}`, value: typed, disabled: how.locked});
|
|
const other = h("form", {class: "option other"}, input,
|
|
h("button", {type: "submit", class: "btn small", disabled: how.locked, ...named("Send", revealed(`Send this text: ${how.hint}`))}, icon("bi-send"), "Send"));
|
|
other.addEventListener("submit", (event) => {
|
|
event.preventDefault();
|
|
if (input.value.trim()) {
|
|
how.pick(input.value.trim());
|
|
}
|
|
});
|
|
const list = h("div", {class: `options dialog${how.group ? ` ${how.group}` : ""}`, role: "group", "aria-label": "Options", "data-multi": item.multi ? "" : null}, buttons, other, send);
|
|
list.addEventListener("keydown", (event) => {
|
|
const index = Number(event.key) - 1;
|
|
if (event.target === input || event.altKey || event.ctrlKey || event.metaKey || !Number.isInteger(index) || index < 0 || index > buttons.length) {
|
|
return;
|
|
}
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
index < buttons.length ? buttons[index].click() : input.focus();
|
|
});
|
|
show(item.options.find((option) => recommended.includes(option.label)) || item.options[0] || {});
|
|
return pane ? h("div", {class: "choice"}, list, pane) : list;
|
|
}
|