Skip to content

Choice intents: confirmations can offer N options; request_choice MCP tool - #111

Merged
ThinkOffApp merged 2 commits into
mainfrom
feat/choice-intents-clean
Sep 20, 2026
Merged

ThinkOffApp merged 2 commits into
mainfrom
feat/choice-intents-clean

Conversation

@ThinkOffApp

@ThinkOffApp ThinkOffApp commented Sep 19, 2026 •

Copy link
Copy Markdown
Owner

Lets a confirmation offer named options instead of only Approve/Deny. createIntent takes an options list; the intent becomes a CHOICE whose legal answers are exactly those labels, announced as one button each via metadata.actions, which CodeWatch already renders for any label. request_choice exposes it to agents and SHARES request_confirmation's case so the daemon path, the in-process fallback and the timeout behaviour cannot drift apart.

Why: 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. 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 /choose form, 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 /choose goes 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 actions and 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/messages route 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.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 the author's. It is comment-only and could not be separated by path. The related bin/iak-mcp-daemon.mjs change 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.

Petrus Pennanen and others added 2 commits September 19, 2026 21:57
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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-19T21:54:00.817980Z 4c1a784 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/confirmations.mjs
if (!hit) {
return { ok: false, error: `"${rawDecision}" is not an option for ${id}` };
}
decision = hit;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread src/mcp-server.mjs
Comment on lines +671 to +674
channels: {
type: 'array',
items: { type: 'string', enum: ['groupmind', 'codewatch'] },
description: 'Which channels to post to. Default: all configured channels.',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread src/confirmations.mjs
id,
prompt: i.prompt,
session: i.session,
options: i.options || null,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread src/confirmations.mjs
Comment on lines +247 to +250
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))]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@ThinkOffApp ThinkOffApp changed the title Note the room route's silent 6-option cap on actions Choice intents: confirmations can offer N options; request_choice MCP tool Sep 19, 2026
@ThinkOffApp
ThinkOffApp merged commit 2af04a6 into main Sep 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant