feat(hub): the permission hook asks for every tool and signs its whole input
The PermissionRequest hook now registers for every tool (matcher *); make orchestrator-check reports an entry that matches less. What the hub shows and the passkey signs is a Bash call's command when it sets nothing beyond command, description, timeout and run_in_background, else the whole tool input as sorted JSON, so an allow never covers a value the operator did not see (before, an Edit was signed by its file_path alone). The inbox, the stream and Match show an ask like Claude Code's dialog: 1 Yes, 2 No and 'Tell Claude what to do instead', whose text denies with it as the reason. README describes it.
Stacked on dialog (88e53ac); applied cleanly. ruff, node --check and bash -n pass.
Break: an auto-approval rule that matched a non-Bash tool by its path alone no longer matches the JSON summary, so that call asks instead of passing (fails closed). The matcher change takes effect with make orchestrator-hook.
Tests: test_hub_asks, test_hub_decision_rows, test_hub_grant_mode, test_hub_inbox_gone, test_hub_operator_tasks and the Match waiting 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, all 12 files covered.
🎯 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
88e53ac51f
commit
aa4a337c9a
12 files changed
+119
-38
No files matched your search
@@ -11,7 +11,8 @@
|
||||
|
||||
Returns:
|
||||
stdout: the PermissionRequest decision JSON: allow only when a pinned
|
||||
passkey signed exactly this tool, command, cwd, session and ask id;
|
||||
passkey signed exactly this tool, command (summary()), cwd, session
|
||||
and ask id;
|
||||
deny when the operator denied in the Agent Orchestrator, with the
|
||||
reason only when a pinned passkey signed it. Nothing on timeout,
|
||||
error, a missing or invalid signature, a value longer than the hub
|
||||
@@ -66,21 +67,27 @@ ALLOW = {"behavior": "allow"}
|
||||
REASON_LIMIT = 2000
|
||||
FAILURES = (OSError, ValueError, staged_diff.DiffError)
|
||||
QUESTION_TOOL = "AskUserQuestion"
|
||||
SHELL = "Bash"
|
||||
SHELL_KEYS = frozenset({"command", "description", "timeout", "run_in_background"})
|
||||
OPTION_KEYS = ("label", "description", "preview")
|
||||
|
||||
|
||||
def summary(tool_input: object) -> str:
|
||||
if isinstance(tool_input, dict):
|
||||
for key in ("command", "file_path", "url", "pattern", "path"):
|
||||
if isinstance(tool_input.get(key), str):
|
||||
return tool_input[key]
|
||||
return json.dumps(tool_input, ensure_ascii=False)
|
||||
def summary(tool: str, tool_input: object) -> str:
|
||||
"""Returns:
|
||||
What the hub shows and the passkey signs: a Bash call's command when
|
||||
it sets nothing beyond SHELL_KEYS, else the whole input as sorted
|
||||
JSON, so an allow never covers a value the operator did not see.
|
||||
"""
|
||||
if tool == SHELL and isinstance(tool_input, dict) and isinstance(tool_input.get("command"), str) and set(tool_input) <= SHELL_KEYS:
|
||||
return tool_input["command"]
|
||||
return json.dumps(tool_input, ensure_ascii=False, indent=1, sort_keys=True)
|
||||
|
||||
|
||||
def facts(hook: dict) -> dict:
|
||||
tool = str(hook.get("tool_name") or "?")
|
||||
return {
|
||||
"tool": str(hook.get("tool_name") or "?"),
|
||||
"command": summary(hook.get("tool_input")),
|
||||
"tool": tool,
|
||||
"command": summary(tool, hook.get("tool_input")),
|
||||
"cwd": str(hook.get("cwd") or ""),
|
||||
"session": str(hook.get("session_id") or ""),
|
||||
"agent": str(hook.get("agent_type") or ""),
|
||||
@@ -88,15 +95,15 @@ def facts(hook: dict) -> dict:
|
||||
|
||||
|
||||
def commit_target(ask: dict) -> Path | None:
|
||||
return staged_diff.commit_of(ask["command"], ask["cwd"]) if ask["tool"] == "Bash" and ask["cwd"] else None
|
||||
return staged_diff.commit_of(ask["command"], ask["cwd"]) if ask["tool"] == SHELL and ask["cwd"] else None
|
||||
|
||||
|
||||
def tree_target(ask: dict) -> tuple[Path, str, list[str]] | None:
|
||||
return staged_diff.tree_of(ask["command"], ask["cwd"]) if ask["tool"] == "Bash" and ask["cwd"] else None
|
||||
return staged_diff.tree_of(ask["command"], ask["cwd"]) if ask["tool"] == SHELL and ask["cwd"] else None
|
||||
|
||||
|
||||
def unapprovable(ask: dict) -> bool:
|
||||
return ask["tool"] == "Bash" and staged_diff.names_commit(ask["command"]) and commit_target(ask) is None and tree_target(ask) is None
|
||||
return ask["tool"] == SHELL and staged_diff.names_commit(ask["command"]) and commit_target(ask) is None and tree_target(ask) is None
|
||||
|
||||
|
||||
def tree_preview(ask: dict, rules: Path | None) -> dict:
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
const OTHER_PROMPT = "Other: type your own answer …";
|
||||
const ALLOW = "Yes";
|
||||
const TELL = "Tell Claude what to do instead";
|
||||
const askDialog = (id) => ({id, options: [{label: ALLOW, description: "allow this one call"}, {label: "No", description: "deny it"}], recommended: "", multi: false});
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @param {Object} item a decision, a decision row, a decision card or a permission ask: 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, and true for the Other text only; other: the Other field's placeholder; 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) {
|
||||
@@ -20,7 +25,7 @@
|
||||
title: revealed(`${option.label}: ${how.hint}`),
|
||||
on: {click: () => {
|
||||
if (!item.multi) {
|
||||
how.pick(option.label);
|
||||
how.pick(option.label, false);
|
||||
return;
|
||||
}
|
||||
how.toggled.has(option.label) ? how.toggled.delete(option.label) : how.toggled.add(option.label);
|
||||
@@ -32,16 +37,16 @@
|
||||
return button;
|
||||
});
|
||||
if (send) {
|
||||
send.addEventListener("click", () => how.pick(item.options.filter((option) => how.toggled.has(option.label)).map((option) => option.label).join(PICKED)));
|
||||
send.addEventListener("click", () => how.pick(item.options.filter((option) => how.toggled.has(option.label)).map((option) => option.label).join(PICKED), false));
|
||||
}
|
||||
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 input = h("input", {class: "field", type: "text", maxlength: OTHER_LIMIT, placeholder: how.other, "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());
|
||||
how.pick(input.value.trim(), true);
|
||||
}
|
||||
});
|
||||
const list = h("div", {class: `options dialog${how.group ? ` ${how.group}` : ""}`, role: "group", "aria-label": "Options", "data-multi": item.multi ? "" : null}, buttons, other, send);
|
||||
|
||||
@@ -122,17 +122,27 @@
|
||||
|
||||
const signsFor = (item) => `your passkey signs this answer, a post to ${item.agent}`;
|
||||
|
||||
/**
|
||||
* @param {Object} item a permission ask.
|
||||
* @param {string} answer the picked label, or the typed text.
|
||||
* @param {boolean} typed whether answer is typed text, which always denies with it as the reason.
|
||||
*/
|
||||
const answerAsk = (item, answer, typed) => (!typed && answer === ALLOW ? approveOne(item) : denyNow(item, "post", typed ? answer : ""));
|
||||
|
||||
/**
|
||||
* @param {Object} item an inbox item.
|
||||
* @param {Function} after called before a picked answer is sent.
|
||||
* @returns {HTMLElement|Array|null} the choiceDialog() of a decision or a decision row, with its recipient line for a row; null for every other item.
|
||||
* @returns {HTMLElement|Array|null} the choiceDialog() of a decision, a decision row or a permission ask, with its recipient line for a row; null for every other item.
|
||||
*/
|
||||
const choiceOf = (item, after) => {
|
||||
if (item.kind === "decision") {
|
||||
return choiceDialog(item, {pick: (label) => { after(); chooseOne(item, label); }, toggled: new Set(), chosen: "", locked: item.held, hint: signsFor(item), group: ""});
|
||||
return choiceDialog(item, {pick: (label) => { after(); chooseOne(item, label); }, toggled: new Set(), chosen: "", locked: item.held, hint: signsFor(item), group: "", other: OTHER_PROMPT});
|
||||
}
|
||||
if (item.kind === "ask") {
|
||||
return choiceDialog(askDialog(item.id), {pick: (answer, typed) => { after(); answerAsk(item, answer, typed); }, toggled: new Set(), chosen: ui.selected.has(keyOf(item)) ? ALLOW : "", locked: item.held, hint: `your passkey signs it, the answer goes to ${item.to || "its session"}`, group: "", other: TELL});
|
||||
}
|
||||
const told = answerOf(item);
|
||||
return asked(item) ? [answerTo(item), choiceDialog(item, {pick: (label) => { after(); answerRow(item, label); }, toggled: new Set(), chosen: told, locked: item.held || Boolean(told), hint: signsFor(item), group: ""})] : null;
|
||||
return asked(item) ? [answerTo(item), choiceDialog(item, {pick: (label) => { after(); answerRow(item, label); }, toggled: new Set(), chosen: told, locked: item.held || Boolean(told), hint: signsFor(item), group: "", other: OTHER_PROMPT})] : null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -230,8 +240,6 @@
|
||||
if (item.kind === "review") {
|
||||
grant(iconBtn("bi-check-lg", "Grant", "btn small primary", () => approveOne(item)));
|
||||
buttons.push(denySplit(item));
|
||||
} 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: ${shownPick(item.recommended)}`)), on: {click: () => approveOne(item)}}, icon("bi-check-lg"), revealed(shownPick(item.recommended))));
|
||||
} else if (item.kind === "operator" && item.runnable) {
|
||||
|
||||
@@ -287,7 +287,18 @@
|
||||
matchView.toggles.delete(key);
|
||||
decide(card, "accept", "", label);
|
||||
};
|
||||
return choiceDialog({...card, id: card.ref}, {pick, toggled, chosen: kept ? kept.label : "", locked: false, hint: `picked now, sent to ${card.agent || "its agent"} at the release`, group: "match-options"});
|
||||
return choiceDialog({...card, id: card.ref}, {pick, toggled, chosen: kept ? kept.label : "", locked: false, hint: `picked now, sent to ${card.agent || "its agent"} at the release`, group: "match-options", other: OTHER_PROMPT});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} card a permission ask card.
|
||||
* @returns {HTMLElement} its choiceDialog(): Yes accepts, No rejects, typed text rejects with it as the feedback; all sent at the release.
|
||||
*/
|
||||
function matchAsk(card) {
|
||||
const kept = matchView.decisions.get(cardKey(card));
|
||||
const chosen = !kept ? "" : kept.verdict === "accept" ? ALLOW : kept.feedback || "No";
|
||||
const pick = (answer, typed) => (!typed && answer === ALLOW ? acceptCard(card) : decide(card, "reject", typed ? answer : "", ""));
|
||||
return choiceDialog(askDialog(card.ref), {pick, toggled: new Set(), chosen, locked: false, hint: `picked now, sent to ${card.agent || "its session"} at the release`, group: "match-options", other: TELL});
|
||||
}
|
||||
|
||||
function matchPayload(card) {
|
||||
@@ -299,7 +310,7 @@
|
||||
}
|
||||
if (card.kind === "ask") {
|
||||
return h("section", {class: "match-payload"}, h("pre", {class: "match-command"}, h("code", {}, revealed(card.command))), h("p", {class: "match-directory"}, revealed(card.directory)),
|
||||
card.warnings.length ? h("p", {class: "match-warnings"}, card.warnings.map((warning) => pill(warning, "bad"))) : null);
|
||||
card.warnings.length ? h("p", {class: "match-warnings"}, card.warnings.map((warning) => pill(warning, "bad"))) : null, matchAsk(card));
|
||||
}
|
||||
if (card.kind !== "command") {
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user