Repository navigation
ADFA-7147 AI-Core: let "Always Allow" cover a contributed tool declared read-only - #167
davidschachterADFA wants to merge 1 commit into
Conversation
…ed read-only Step 1 of ADFA-7147. Every contributed tool asked for approval on every call, with no "Always Allow": ContributedToolHandler set allowsSessionApproval to false for all of them. A tool its provider declares read-only (ToolSpec.isReadOnly) may now be allowed for the session. Consent stays explicit: one approval per tool per session, and the dialog still names the source plugin. A tool that may change something is still confirmed on every call. requiresApproval stays true for every contributed tool, so a provider still cannot skip the dialog. For the SQLite debugger's eight read-only tools that means at most eight taps a session instead of one per call. AI-Agent-MCP declares read-only only the debugger entry's readOnlyHint tools (addons#166); every other MCP server's tools stay not read-only, so they keep asking every time. Two guards, because the declaration is the provider's own claim: - A contributed tool's grant is keyed by provider and the tool's own name (ToolHandler.sessionApprovalKey), not by the registered name. That name is first come, first served, so after the sources change it can pass to another plugin's tool, which would have inherited the grant. - A grant is checked against the handler when used, not only when made, so a tool re-registered as not read-only asks again. Built-in tools keep their name-keyed grants unchanged. Limitation: providerId is what the registering plugin declares, so a plugin that registers under another's id can still take over its grants, as it can take over its registration today. Closing that needs the host to vouch for the source, which is step 2 of ADFA-7147. Tests: four new ToolApprovalManagerTest cases run real ContributedToolHandlers through ensureApproved, and two ContributedToolHandlerTest cases cover the declaration and the key. Each guard was reverted on its own and its tests failed; the full AI-Core suite (1347 tests) passes with the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA
left a comment
There was a problem hiding this comment.
CRITICAL
- none
IMPORTANT
- ContributedToolHandler.kt:72 - Always Allow now depends on an unshown, host-unverified read-only claim by the provider; owner decision
MINOR
- ContributedToolHandler.kt:79 - grant key omits description/schema, so a redefined tool inherits it
- ToolApprovalManager.kt:164 - grants are never cleared across chat sessions; tooltip says they are
NITPICK - none
Review of fb59c32 (base main, not stacked, no existing approvals or review threads, so nothing to re-check from earlier rounds). Rules applied: the repo CLAUDE.md, plugins/README.md, plugins/AI-Core/README.md and the plugin-review skill for plugin criteria only (rubric not scored). None of them states an approve/request-changes rule, so the pr-review default applied. By that default one IMPORTANT would be REQUEST_CHANGES, but this PR is authored by the account posting this review and GitHub refuses that, so it is submitted as COMMENT. The verdict was computed but not submitted. I read the code around the change (ToolSourceRegistryImpl, ApprovalDialogFragment, ChatViewModel, ToolSpec use) and AI-Agent-MCP#166 was not needed.
What checked out: the two guards in the description hold as written (key is per provider and tool; grant is rechecked against the handler on use), requiresApproval stays true, and the new tests exercise ensureApproved with real handlers. Static review only; no Gradle run and no device.
Leads considered and not posted: a revived grant when read-only flips back (the user approved the read-only state, so no new power); a read-only change between dialog and answer (the handler's tool is an immutable value, so unreachable); : delimiter collisions (a provider can already claim any id, so no capability is added); test-coverage gaps.
| * declaration is the provider's own claim, so it can widen nothing beyond that one choice. | ||
| */ | ||
| override val allowsSessionApproval: Boolean = false | ||
| override val allowsSessionApproval: Boolean get() = readOnly |
There was a problem hiding this comment.
IMPORTANT: "Always Allow" now rests on a read-only claim the user is never shown and nothing in the host checks.
readOnly is copied from the provider's ToolSpec.isReadOnly (ToolSourceRegistryImpl:168). The dialog (ApprovalDialogFragment) prints the source label, description and args, but nothing says "read-only" or that this is the provider's own declaration, so the user cannot weigh what the Always Allow button is asking of them. A read-only-declared tool still runs outside PathGuard and may read project files or reach the network. After one tap, a prompt-injected model can call it with any arguments, because the grant ignores args (the dialog's own tooltip says so). Before this change a provider could not buy that by declaring a flag.
This is the reversal the ticket says AI-Core's owner decides, so it needs that decision on record before merge. If it goes ahead, have the dialog say the tool is declared read-only by the plugin, and tell the user the grant covers every argument.
| * "Always Allow". [toolName] alone could hand the grant to another plugin's tool that takes | ||
| * the name over after the sources change. | ||
| */ | ||
| override val sessionApprovalKey: String = "contributed:${tool.providerId}:${tool.name}" |
There was a problem hiding this comment.
MINOR: the grant key is provider and tool name only, so it does not cover what the user approved (description, schema, read-only flag).
The user taps Always Allow on query from provider P, having read one description and one schema. P (or an MCP server behind it, via notifyToolsChanged) republishes query with a different description and schema and still isReadOnly = true. The new ContributedToolHandler produces the same key, so it runs with no dialog. The PR's "key by what the dialog showed" reasoning stops at the name. It is MINOR because the provider is already trusted for its own tools and this needs a mid-session redefinition, which no current in-repo provider does.
Fold a hash of description and parameters schema into the key, so a changed tool asks again. The comment above (what the dialog showed) is also loose: the dialog title is the registered toolName, not tool.name.
| } else { | ||
| Log.d(TAG, "Approval granted (session) for $toolName") | ||
| sessionApprovedTools.add(toolName) | ||
| sessionApprovedTools.add(grantKey(toolName, handler)) |
There was a problem hiding this comment.
MINOR: a session grant outlives the chat session, and the dialog tooltip promises otherwise.
The defect is partly outside this diff: clearSessionApprovals() (line 225) has no caller anywhere in plugins/AI-Core, and ChatViewModel.createNewSession, switchToSession and importSession never clear it. So "Always Allow" lasts for the whole ChatViewModel, across every chat in the project. The tooltip text in AiCorePlugin.kt (~line 644) says the grant is "by tool name only" and "forgotten when the session ends", which no longer matches for contributed tools (keyed by provider and tool) and is not true for chats. Built-ins already behave this way, so it is MINOR, but this PR newly extends the lifetime to plugin-run tools, and the README and PR description both say "per session".
Either call clearSessionApprovals() when the chat session changes, or word the README and tooltip as "until the IDE closes this chat panel".
ADFA-7147
Step 1 of ADFA-7147. AI-Core's owner decides whether this lands: it reverses AI-Core's current rule that every contributed tool is confirmed on every call, which the ticket records was chosen so that a plugin cannot opt out by asking.
What it does
ToolSpec.isReadOnly) now offers the dialog's existing "Always Allow" choice (ContributedToolHandler.allowsSessionApproval = readOnly, wasfalse). Consent stays explicit: one approval per tool per session, and the dialog still names the source plugin.requiresApprovalstaystruefor every contributed tool, so a provider still cannot skip the dialog.Two guards, because "read-only" is the provider's own claim
ToolHandler.sessionApprovalKey,contributed:<providerId>:<name>), not by the registered name. Registered names are first come, first served, so after the sources change a name can pass to another plugin's tool, which would otherwise inherit the grant.Limitation:
providerIdis what the registering plugin declares (ToolSourceRegistryImpl), so a plugin that registers under another plugin's id can take over its grants, as it can take over its registration today. Closing that needs the host to vouch for the source: step 2 of ADFA-7147.Effect on the SQLite debugger: none until #166 lands (and the Code on the Go release it needs). #166 declares read-only only the automatic debugger entry's
readOnlyHinttools, eight of them, so the debugger would then ask at most eight times a session instead of once per call. Every other MCP server's tools stay not read-only and keep asking on every call. This PR does not depend on #166 and builds againstmain.Acceptance criteria: this step does not meet AC1 of ADFA-7147 (the debugger still asks once per tool per session). AC2 holds. AC3 is covered by the tests below, which go through
ToolApprovalManager.ensureApproved.Tests: four new
ToolApprovalManagerTestcases with realContributedToolHandlers (read-only grant remembered; not-read-only asks again; another provider's tool with the same name asks again; a grant lapses when read-only is dropped), and twoContributedToolHandlerTestcases (the declaration and the key). Each guard was reverted on its own and its tests failed.../../gradlew testDebugUnitTest assemblePlugininplugins/AI-Corepasses (1,347 tests), andaddons checkpasses.Not verified on a device.
Screens: no layout change; the approval dialog shows its existing "Always Allow" button for read-only contributed tools.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn