Repository navigation
fix(core): hide tools whose rules deny every resource - #47337
rekram1-node wants to merge 2 commits into
Conversation
|
Reproducing exactly this on 2.0.18 with a deny-all-then-narrow-allows ladder (four agents configured this way): actions with trailing narrow allows stay advertised while every call outside the allow is denied at settlement, and the model burns several calls on |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Problem
`Tool.snapshot` decides whether a tool is advertised to the model with `whollyDisabled`, which only peeked at the last rule matching the tool's action and hid the tool iff that rule was `{ resource: "*", effect: "deny" }`. Call-time `Permission.evaluate` matches on action and resource. The two disagree whenever a narrower rule for the action trails a catch-all deny:
```
[*, *, deny], [shell, "git ", deny] -> advertised, but every call is denied
[, , deny], [shell, "rm", ask] -> advertised, but every non-rm call is denied
```
Observed in practice with the built-in `explore` subagent: a user's global `permission.bash = { "rm*": "ask" }` is appended after explore's `{*, *, deny}`, so `shell` shows up in explore's tool list and the model burns calls on `Permission denied: shell` before falling back to grep/glob.
Fix
Define "wholly disabled" via `Permission.evaluate` so the filter cannot drift from call-time semantics: a tool is hidden iff no resource can get past `deny`. Each rule's resource pattern matches itself as a literal under `Wildcard.match`, so the resource patterns of the action's rules form a complete set of probes — a later broader rule overrides a probe exactly when it also covers every resource the probe covers.
Behavior change is limited to rulesets where narrow rules trail a catch-all deny for the same action; a trailing narrow `ask`/`allow` still keeps the tool visible (faithful to `evaluate`), while trailing narrow `deny` rules now hide it.
Note: this does not by itself remove `shell` from `explore` for the `rm*: ask` config above, since `rm foo` genuinely would prompt under those rules. That is a rule merge-order issue (global config appended after built-in agent rules) and will be addressed separately.
Testing