Repository navigation
Choice intents: confirmations can offer N options; request_choice MCP tool - #111
Conversation
decideIntent validated the answer against a fixed approve/deny vocabulary BEFORE looking the intent up, so no other answer could ever be legal and a multi-option button could not exist. Look the intent up first: what counts as a legal answer depends on the intent. createIntent now takes `options`. When present the intent is a CHOICE whose legal answers are exactly those labels, announced as one button each via metadata.actions, which CodeWatch already renders for any label. The option list is an ALLOW-LIST, not a hint. `/choose <id> <value>` matches against the declared options and stores the declared spelling, so the tail of a chat message can never smuggle a value the requester did not offer, and the requester compares against the list it supplied rather than the phone's casing. approve/deny are not a back door into a choice intent, and a choice is not a back door into a plain confirmation. A choice never runs a bound typed action. The executor branch treats everything that is not 'deny' as an approval, so letting a choice reach it would make picking an option execute whatever action was attached. The announcement always spells out the typed `/choose` form too: the buttons need a client that renders them, and a phone that cannot must still be able to answer, or a choice intent is unanswerable on the surface it was built for. Authorisation is unchanged - /choose goes through the same ownerSet gate as /approve, asserted by a test that has an agent try to answer one. The approve/deny log line is kept byte-identical because the suite asserts it. request_choice exposes this to agents. It SHARES request_confirmation's case rather than copying it, so the daemon path, the in-process fallback and the timeout behaviour cannot drift apart between the two tools. Validation is repeated in the MCP handler because the caller is an agent composing a picker, and "needs at least two distinct options" is only actionable if it names the call that was wrong. For the same reason POST /intent answers 400 rather than 500 for a malformed option list: a 500 reads as a broken daemon and sends someone hunting a typo in the wrong codebase. Suite: 324 passing. NOTE: src/confirmations.mjs carries a five-line comment about the chat-reply poller's intervalMs cost that was already staged in this working tree and is not mine. It is comment-only and could not be separated from these hunks by path. The related bin/iak-mcp-daemon.mjs change that makes that interval configurable is deliberately NOT in this commit - it is someone's unfinished work and is left staged where it was found. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Verified on GroupMind origin/main 159b16b while answering a question about a different route. The generic /api/v1/messages route carries actions inside caller metadata and does not cap them, which is the route this announcer uses. The per-room route reads a TOP-LEVEL actions and does .slice(0, 6), so a choice announced through it would render six buttons while accepting nine answers, with no error anywhere. No cap imposed: it would be wrong for the route in use. Documented so that moving the announcer does not walk into it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c1a784048
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!hit) { | ||
| return { ok: false, error: `"${rawDecision}" is not an option for ${id}` }; | ||
| } | ||
| decision = hit; |
There was a problem hiding this comment.
Escape choice values before rendering them
When a choice label containing HTML is selected, this assignment stores that arbitrary label as i.decision, but renderIntentsHtml later interpolates the decision directly into el.innerHTML at line 1021. For example, selecting an option such as <img src=x onerror=...> executes its handler whenever the confirmations page refreshes; because that script runs on the daemon origin, it can also POST decisions for other pending intents. Render the label with textContent or HTML-escape it before interpolation.
Useful? React with 👍 / 👎.
| channels: { | ||
| type: 'array', | ||
| items: { type: 'string', enum: ['groupmind', 'codewatch'] }, | ||
| description: 'Which channels to post to. Default: all configured channels.', |
There was a problem hiding this comment.
Support choice payloads on the CodeWatch channel
When request_choice uses channels: ['codewatch']—or defaults to all configured channels in a CodeWatch-only setup—the legacy makeCodewatchAnnouncer still sends only {id, prompt, session} and renders Approve/Deny actions. Both returned values are rejected by the new choice allow-list, so the request cannot be answered and blocks until timeout. Either forward/render the named options on this channel or reject/exclude CodeWatch for choice requests.
Useful? React with 👍 / 👎.
| id, | ||
| prompt: i.prompt, | ||
| session: i.session, | ||
| options: i.options || null, |
There was a problem hiding this comment.
Include choice options in the intent list response
Adding options only to getIntent does not expose them through GET /intents, because that endpoint serializes listIntents, which still omits the field. Consequently the callback link included in GroupMind opens a page that always renders Approve/Deny; for a choice intent both buttons are rejected as undeclared values, making the built-in tap-to-decide flow unusable. listIntents and the HTML renderer need to carry and render the option buttons.
Useful? React with 👍 / 👎.
| const cleanOptions = Array.isArray(options) | ||
| // One line each, no blanks, no duplicates: a label is posted verbatim as | ||
| // `/choose <id> <label>`, so a newline would split the command. | ||
| ? [...new Set(options.map((o) => String(o).replace(/[\r\n]+/g, ' ').trim()).filter(Boolean))] |
There was a problem hiding this comment.
Reject options that collide case-insensitively
The Set removes only exact duplicates, while decideIntent resolves choices with a case-insensitive find. Thus options such as main and MAIN pass the two-option validation, but selecting either always returns the first label, making the second choice unreachable; this is especially relevant to the advertised branch-picker use case, where names may differ only by case. Deduplicate/reject labels using the same normalization used for matching, or prefer exact matches before case-insensitive fallback.
Useful? React with 👍 / 👎.
Lets a confirmation offer named options instead of only Approve/Deny.
createIntenttakes anoptionslist; the intent becomes a CHOICE whose legal answers are exactly those labels, announced as one button each viametadata.actions, which CodeWatch already renders for any label.request_choiceexposes it to agents and SHARESrequest_confirmation's case so the daemon path, the in-process fallback and the timeout behaviour cannot drift apart.Why:
decideIntentvalidated the answer against a fixed approve/deny vocabulary BEFORE looking the intent up, so no other answer could ever be legal and a multi-option button could not exist. The lookup now comes first - what counts as a legal answer depends on the intent.The option list is an ALLOW-LIST, not a hint.
/choose <id> <value>matches the declared options and stores the declared spelling, so the tail of a chat message cannot smuggle a value the requester never offered. approve/deny are not a back door into a choice, and a choice is not a back door into a plain confirmation. A choice never runs a bound typed action, because the executor branch treats everything that is not 'deny' as an approval. Every announcement also spells out the typed/chooseform, so a phone that cannot render buttons can still answer. POST /intent answers 400, not 500, for a malformed option list: a 500 sends someone hunting a typo in the wrong codebase.Verified: suite 324 passing at the time of the commit, including a test that has an agent try to answer a choice, asserting
/choosegoes through the same ownerSet gate as/approve. The approve/deny log line is kept byte-identical because the suite asserts it.Second commit documents, without changing behaviour, that the per-room route reads a top-level
actionsand does.slice(0, 6), so a choice announced through it would render six buttons while accepting nine answers with no error anywhere. The generic/api/v1/messagesroute this announcer uses carries actions in caller metadata and does not cap them, so no cap is imposed here - it would be wrong for the route in use.Follow-up named in the commit:
src/confirmations.mjscarries a five-line comment about the chat-reply poller'sintervalMscost that was already staged in this working tree and is not the author's. It is comment-only and could not be separated by path. The relatedbin/iak-mcp-daemon.mjschange that makes that interval configurable is deliberately NOT included - it is someone's unfinished work, left staged where it was found.🤖 Generated with Claude Code
Note: the commit says 324 tests because that was the suite size on the original base; on current main the full suite is 340 passing after rebase.