feat(hub): answer AskUserQuestion in the hub with a signed pick
The permission hook mirrors every question of an AskUserQuestion call as one hub decision (POST /api/decisions, hooked, multi for multiSelect, recommended from the (Recommended) labels) and waits for its pick. Once the operator's pinned passkey signed the pick of every question, checked locally in signature-counter order, the allow carries updatedInput with the answers, multi picks joined by ', '. A hub that does not answer, an expired decision or a pick whose signature fails leaves the terminal dialog untouched. choosing.picks accepts one label, ordered multi labels joined by a newline, or for a hooked decision one trimmed line of other text; decision_status expires a hooked decision whose wait ran out, and the state view and Match drop expired ones. decision_request shares choice_of with the hook; the answer text moves to signing.choice_text unchanged. Rebased from its lane base2754568ontof95196c: the scan copy's diff against2aea6d1would have reverted the release-flash fix, so the bundle was re-exported against 2754568; conflicts in view.py (reasons next to the decision_status filter) and page-match.js (toggles next to epoch and the ux constants) keep both sides. ruff and node --check pass. Tests: test_hub_questions (210 lines) and test_question_multi_e2e. 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 17 files; index.html.j2 is not covered and was read by hand (one style rule). 🎯 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:
1 parent
f95196ca82
commit
a6eee78165
18 files changed
+763
-64
No files matched your search
@@ -364,6 +364,7 @@ textarea + .mic-auto { display: flex; margin: 4px 0 0 auto; }
|
||||
.option { display: grid; gap: 2px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); text-align: left; cursor: pointer; }
|
||||
.option:hover { background: var(--accent-soft); border-color: var(--accent); }
|
||||
.option.recommended { border-color: var(--ok); box-shadow: inset 3px 0 0 var(--ok); }
|
||||
.option[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
|
||||
.option span { color: var(--muted); font-size: var(--fs-sm); }
|
||||
.option:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
||||
.option.other { display: flex; gap: 6px; align-items: center; cursor: default; }
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
const short = (text) => (text.length > 80 ? `${text.slice(0, 80)}…` : text);
|
||||
const btn = (label, cls, run) => h("button", {type: "button", class: cls, on: {click: run}}, label);
|
||||
const nowSeconds = () => Date.now() / 1000;
|
||||
const PICKED = "\n";
|
||||
const OTHER_LIMIT = 1000;
|
||||
const shownPick = (label) => label.split(PICKED).join(", ");
|
||||
|
||||
function ago(ts) {
|
||||
const diff = ts - nowSeconds();
|
||||
|
||||
@@ -99,12 +99,12 @@
|
||||
openItem(item);
|
||||
return null;
|
||||
}
|
||||
return submit([entryOf(item, "approve", item.recommended)], `Choice: ${item.recommended}`);
|
||||
return submit([entryOf(item, "approve", item.recommended)], `Choice: ${shownPick(item.recommended)}`);
|
||||
}
|
||||
return submit([entryOf(item, "approve", "")], `${item.kind === "operator" ? "Run" : "Grant"}: ${short(item.title)}`);
|
||||
}
|
||||
|
||||
const chooseOne = (item, label) => submit([entryOf(item, "approve", label)], `Choice: ${label}`);
|
||||
const chooseOne = (item, label) => submit([entryOf(item, "approve", label)], `Choice: ${shownPick(label)}`);
|
||||
const asked = (item) => item.kind === "operator" && item.check === "decision";
|
||||
const answers = new Map();
|
||||
const answerOf = (item) => answers.get(keyOf(item)) || item.answered || "";
|
||||
@@ -120,39 +120,73 @@
|
||||
}
|
||||
}
|
||||
|
||||
function otherAnswer(item) {
|
||||
const input = h("input", {class: "field", type: "text", placeholder: "Other answer …", "aria-label": `Other answer to ${item.id}`, disabled: answers.has(keyOf(item))});
|
||||
/**
|
||||
* @param {Object} item a decision row, or a decision the permission hook asked.
|
||||
* @param {Function} send called with the trimmed text once it is not empty.
|
||||
* @returns {HTMLElement} the free-text answer form.
|
||||
*/
|
||||
function otherAnswer(item, send) {
|
||||
const done = answers.has(keyOf(item));
|
||||
const input = h("input", {class: "field", type: "text", placeholder: "Other answer …", "aria-label": `Other answer to ${item.id}`, maxlength: item.kind === "decision" ? OTHER_LIMIT : null, disabled: done});
|
||||
const form = h("form", {class: "option other"}, input,
|
||||
h("button", {type: "submit", class: "btn small", disabled: answers.has(keyOf(item)), ...named("Send", revealed(`Send: your passkey signs this answer, a post to ${item.agent}`))}, icon("bi-send"), "Send"));
|
||||
h("button", {type: "submit", class: "btn small", disabled: done, ...named("Send", revealed(`Send: your passkey signs this answer for ${item.agent}`))}, icon("bi-send"), "Send"));
|
||||
form.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
if (input.value.trim()) {
|
||||
answerRow(item, input.value.trim());
|
||||
send(input.value.trim());
|
||||
}
|
||||
});
|
||||
return form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} item a decision or a decision row; a multi decision takes several options, toggled until Send.
|
||||
* @param {Function} pick called with the answer: one label, or the toggled labels in option order joined by PICKED.
|
||||
* @param {HTMLElement} [other] a free-text answer form.
|
||||
* @returns {HTMLElement} the option buttons with their preview pane.
|
||||
*/
|
||||
function choicePanel(item, pick, other) {
|
||||
const done = Boolean(answerOf(item));
|
||||
const recommended = item.recommended.split(PICKED);
|
||||
const toggled = new Set();
|
||||
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 buttons = item.options.map((option) => h("button", {
|
||||
type: "button", class: `option${option.label === item.recommended ? " recommended" : ""}`, title: revealed(`${option.label}: your passkey signs this answer, a post to ${item.agent}`), disabled: item.held || done,
|
||||
on: {click: () => pick(option.label), focus: () => show(option), mouseenter: () => show(option)},
|
||||
}, h("strong", {}, revealed(option.label)), option.description ? h("span", {}, revealed(option.description)) : null));
|
||||
show(item.options.find((option) => option.label === item.recommended) || item.options[0] || {});
|
||||
const list = h("div", {class: "options"}, buttons, other || null);
|
||||
const send = item.multi ? h("button", {type: "button", class: "btn small primary choice-send", disabled: true, ...named("Send", revealed(`Send the toggled options: your passkey signs this answer for ${item.agent}`))}, icon("bi-send"), "Send") : null;
|
||||
const buttons = item.options.map((option) => {
|
||||
const button = h("button", {
|
||||
type: "button", class: `option${recommended.includes(option.label) ? " recommended" : ""}`, title: revealed(`${option.label}: your passkey signs this answer, a post to ${item.agent}`), disabled: item.held || done,
|
||||
"aria-pressed": item.multi ? "false" : null,
|
||||
on: {click: () => {
|
||||
if (!item.multi) {
|
||||
pick(option.label);
|
||||
return;
|
||||
}
|
||||
toggled.has(option.label) ? toggled.delete(option.label) : toggled.add(option.label);
|
||||
button.setAttribute("aria-pressed", String(toggled.has(option.label)));
|
||||
send.disabled = !toggled.size;
|
||||
}, focus: () => show(option), mouseenter: () => show(option)},
|
||||
}, h("strong", {}, revealed(option.label)), option.description ? h("span", {}, revealed(option.description)) : null);
|
||||
return button;
|
||||
});
|
||||
if (send) {
|
||||
send.addEventListener("click", () => pick(item.options.filter((option) => toggled.has(option.label)).map((option) => option.label).join(PICKED)));
|
||||
}
|
||||
show(item.options.find((option) => recommended.includes(option.label)) || item.options[0] || {});
|
||||
const list = h("div", {class: "options"}, buttons, other || null, send);
|
||||
return pane ? h("div", {class: "choice"}, list, pane) : list;
|
||||
}
|
||||
|
||||
const choiceOf = (item, after) => item.kind === "decision"
|
||||
? choicePanel(item, (label) => { after(); chooseOne(item, label); })
|
||||
: asked(item) ? [answerTo(item), choicePanel(item, (label) => { after(); answerRow(item, label); }, otherAnswer(item))] : null;
|
||||
const choiceOf = (item, after) => {
|
||||
if (item.kind === "decision") {
|
||||
const choose = (label) => { after(); chooseOne(item, label); };
|
||||
return choicePanel(item, choose, item.other ? otherAnswer(item, choose) : null);
|
||||
}
|
||||
return asked(item) ? [answerTo(item), choicePanel(item, (label) => { after(); answerRow(item, label); }, otherAnswer(item, (text) => answerRow(item, text)))] : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} item a decision row of the register.
|
||||
@@ -171,7 +205,7 @@
|
||||
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(`→ ${item.recommended}`)) : null),
|
||||
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),
|
||||
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,
|
||||
@@ -252,7 +286,7 @@
|
||||
} else if (item.kind === "ask") {
|
||||
grant(iconBtn("bi-check-lg", "Grant", "btn small primary", () => approveOne(item)));
|
||||
} else if (item.kind === "decision" && 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)));
|
||||
grant(h("button", {type: "button", class: "btn small primary", ...named(revealed(`Recommendation: ${shownPick(item.recommended)}`)), on: {click: () => approveOne(item)}}, icon("bi-check-lg"), revealed(shownPick(item.recommended))));
|
||||
} else if (item.kind === "operator" && item.runnable) {
|
||||
grant(iconBtn("bi-play-fill", "Run", "btn small primary", () => approveOne(item)));
|
||||
} else if (item.kind === "rule") {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
const CONFETTI = 28;
|
||||
const COMMENTS_KEPT = 5;
|
||||
const PATTERNS = ["dots", "stripes", "waves", "grid", "rings"];
|
||||
const matchView = {cards: null, order: [], marks: new Map(), opened: new Map(), decisions: new Map(), overview: false, front: null, drag: null, dom: null, sig: "", fetched: 0, loading: false, press: null, flying: false, openBefore: 0, epoch: 0};
|
||||
const matchView = {cards: null, order: [], marks: new Map(), opened: new Map(), decisions: new Map(), toggles: new Map(), overview: false, front: null, drag: null, dom: null, sig: "", fetched: 0, loading: false, press: null, flying: false, openBefore: 0, epoch: 0};
|
||||
|
||||
/**
|
||||
* @returns {Promise<void>} settled when this read ends, at once while another runs; a response requested before
|
||||
@@ -274,12 +274,59 @@
|
||||
card.stale ? h("p", {class: "match-stale"}, icon("bi-exclamation-triangle"), revealed(card.stale_reason)) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} card a decision card; a multi one takes several options, toggled here and kept in matchView.toggles across redraws until Pick.
|
||||
* @returns {HTMLElement} its option buttons, and Pick for a multi card.
|
||||
*/
|
||||
function matchOptions(card) {
|
||||
const kept = matchView.decisions.get(cardKey(card));
|
||||
return h("div", {class: "options match-options", role: "group", "aria-label": "Options"}, card.options.map((option) => h("button", {
|
||||
type: "button", class: `option${option.label === card.recommended ? " recommended" : ""}`, "aria-pressed": String(Boolean(kept && kept.label === option.label)),
|
||||
title: revealed(`${option.label}: picked now, sent to ${card.agent || "its agent"} as a post at the release`), on: {click: () => decide(card, "accept", "", option.label)},
|
||||
}, h("strong", {}, revealed(option.label)), option.description ? h("span", {}, revealed(option.description)) : null)));
|
||||
const recommended = card.recommended.split(PICKED);
|
||||
const toggled = matchView.toggles.get(cardKey(card)) || new Set(kept ? kept.label.split(PICKED) : []);
|
||||
const pick = card.multi ? h("button", {type: "button", class: "btn small primary match-pick", disabled: !toggled.size, title: revealed(`Pick: the toggled options, sent to ${card.agent || "its agent"} at the release`)}, icon("bi-check2-square"), "Pick") : null;
|
||||
const buttons = card.options.map((option) => {
|
||||
const button = h("button", {
|
||||
type: "button", class: `option${recommended.includes(option.label) ? " recommended" : ""}`, "aria-pressed": String(toggled.has(option.label)),
|
||||
title: revealed(`${option.label}: ${card.multi ? "toggled now" : "picked now"}, sent to ${card.agent || "its agent"} at the release`),
|
||||
on: {click: () => {
|
||||
if (!card.multi) {
|
||||
decide(card, "accept", "", option.label);
|
||||
return;
|
||||
}
|
||||
toggled.has(option.label) ? toggled.delete(option.label) : toggled.add(option.label);
|
||||
matchView.toggles.set(cardKey(card), toggled);
|
||||
button.setAttribute("aria-pressed", String(toggled.has(option.label)));
|
||||
pick.disabled = !toggled.size;
|
||||
}},
|
||||
}, h("strong", {}, revealed(option.label)), option.description ? h("span", {}, revealed(option.description)) : null);
|
||||
return button;
|
||||
});
|
||||
if (pick) {
|
||||
pick.addEventListener("click", () => {
|
||||
matchView.toggles.delete(cardKey(card));
|
||||
decide(card, "accept", "", card.options.filter((option) => toggled.has(option.label)).map((option) => option.label).join(PICKED));
|
||||
});
|
||||
}
|
||||
return h("div", {class: "options match-options", role: "group", "aria-label": "Options"}, buttons, pick, card.other ? matchOther(card, kept) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} card a decision card of a question the permission hook asked.
|
||||
* @param {Object} [kept] its decision so far; a free-text one fills the field.
|
||||
* @returns {HTMLElement} the one-line free-text answer, picked like an option.
|
||||
*/
|
||||
function matchOther(card, kept) {
|
||||
const free = kept && kept.label && !kept.label.split(PICKED).some((label) => card.options.some((option) => option.label === label));
|
||||
const input = h("input", {class: "field", type: "text", maxlength: OTHER_LIMIT, placeholder: "Other answer …", "aria-label": "Other answer", value: free ? kept.label : null});
|
||||
const form = h("form", {class: "option other match-other"}, input,
|
||||
h("button", {type: "submit", class: "btn small", ...named("Pick", revealed(`Pick: this text, sent to ${card.agent || "its agent"} at the release`))}, icon("bi-send"), "Pick"));
|
||||
form.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
if (input.value.trim()) {
|
||||
matchView.toggles.delete(cardKey(card));
|
||||
decide(card, "accept", "", input.value.trim());
|
||||
}
|
||||
});
|
||||
return form;
|
||||
}
|
||||
|
||||
function matchPayload(card) {
|
||||
@@ -559,7 +606,7 @@
|
||||
});
|
||||
return h("li", {class: "match-decision", "data-card": card.id, "data-verdict": decision.verdict},
|
||||
h("div", {class: "row"}, face(card.agent || "-", false), h("span", {class: "pill", "data-tone": kindTone}, icon(kindIcon), kindName), h("strong", {class: "match-decision-title"}, revealed(card.title)), h("span", {class: "spacer"}),
|
||||
h("span", {class: "pill match-verdict", "data-tone": tone}, icon(mark), decision.label ? revealed(`${word}: ${decision.label}`) : word), decision.verdict === "reject" ? iconBtn("bi-pencil", "Edit feedback", "btn small ghost match-edit", () => rejectCard(card)) : null, flip, back),
|
||||
h("span", {class: "pill match-verdict", "data-tone": tone}, icon(mark), decision.label ? revealed(`${word}: ${shownPick(decision.label)}`) : word), decision.verdict === "reject" ? iconBtn("bi-pencil", "Edit feedback", "btn small ghost match-edit", () => rejectCard(card)) : null, flip, back),
|
||||
decision.verdict === "reject" ? h("pre", {class: "match-decision-feedback"}, revealedLines(decision.feedback === "" ? "no feedback text" : decision.feedback)) : null);
|
||||
}
|
||||
|
||||
@@ -687,7 +734,7 @@
|
||||
matchView.front = front;
|
||||
const act = (cls, iconName, word, hint, disabled, run) => h("button", {type: "button", class: `match-act ${cls}`, disabled, ...named(word, hint), on: {click: run}},
|
||||
h("span", {class: "match-act-face", "aria-hidden": "true"}, icon(iconName)), h("span", {class: "match-act-label"}, word));
|
||||
const hint = front.stale ? `Accept: refused while the card is stale (${front.stale_reason})` : front.kind === "rule" ? "Accept: opens its row, where the passkey signs exactly this rule" : front.kind === "decision" ? (front.recommended ? `Accept: ${front.recommended} (right arrow, swipe right)` : "Accept: pick one of its options") : "Accept (right arrow, swipe right)";
|
||||
const hint = front.stale ? `Accept: refused while the card is stale (${front.stale_reason})` : front.kind === "rule" ? "Accept: opens its row, where the passkey signs exactly this rule" : front.kind === "decision" ? (front.recommended ? `Accept: ${shownPick(front.recommended)} (right arrow, swipe right)` : "Accept: pick one of its options") : "Accept (right arrow, swipe right)";
|
||||
const accept = act("match-accept", "bi-check-lg", "Accept", revealed(hint), Boolean(front.stale) || (front.kind === "decision" && !front.recommended), () => acceptCard(front));
|
||||
const reject = act("match-reject", "bi-x-lg", "Reject", pickOnly(front) ? "Reject: a choice is answered with one of its options" : "Reject with feedback (left arrow, swipe left)", pickOnly(front), () => rejectCard(front));
|
||||
const later = act("match-later", "bi-arrow-up", "Later", "Later: to the back of the stack (up arrow, swipe up)", !rest.length, () => laterCard(front));
|
||||
|
||||
Reference in new issue
Block a user