feat(tui): apply file ask rules at runtime#3379
Conversation
Wire typed ask-only permissions.toml file-path rules into the TUI tool approval planning path. Matching file ask rules now force approval when approval is available and block under AskForApproval::Never, while preserving existing allow/deny command behavior. This is a narrow follow-up slice from the persistent permissions reference branch: it does not add typed allow/deny, glob expansion, or approval UI persistence for file rules.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
Thanks @greyfreedom for taking the time to contribute. This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered. Please read |
There was a problem hiding this comment.
Code Review
This pull request generalizes the shell execution ask-rule decision logic into a broader tool ask-rule decision framework, extending support to file-based tools (such as read_file, write_file, apply_patch, etc.). It renames ExecShellAskRuleDecision to ToolAskRuleDecision and implements file_tool_ask_rule_decision to evaluate permissions for file operations. Feedback suggests optimizing the turn loop by wrapping the evaluation of ask rules inside a check for blocked_error.is_none(), preventing unnecessary and potentially expensive computations when a tool is already blocked.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| let ask_rule_decision = exec_shell_ask_rule_decision( | ||
| &self.config, | ||
| &tool_name, | ||
| &tool_input, | ||
| &self.session.workspace, | ||
| self.session.approval_mode, | ||
| ) | ||
| .or_else(|| { | ||
| file_tool_ask_rule_decision( | ||
| &self.config, | ||
| &tool_name, | ||
| &tool_input, | ||
| &self.session.workspace, | ||
| self.session.approval_mode, | ||
| ) | ||
| }); | ||
| if blocked_error.is_none() | ||
| && let Some(decision) = ask_rule_decision | ||
| { |
There was a problem hiding this comment.
Evaluating the ask rules (exec_shell_ask_rule_decision and file_tool_ask_rule_decision) can be expensive, especially for apply_patch which parses unified diffs. We should only perform these checks if blocked_error is None to avoid unnecessary work when the tool is already blocked.
if blocked_error.is_none() {
let ask_rule_decision = exec_shell_ask_rule_decision(
&self.config,
&tool_name,
&tool_input,
&self.session.workspace,
self.session.approval_mode,
)
.or_else(|| {
file_tool_ask_rule_decision(
&self.config,
&tool_name,
&tool_input,
&self.session.workspace,
self.session.approval_mode,
)
});
if let Some(decision) = ask_rule_decision {
match decision {
ToolAskRuleDecision::Prompt(reason) => {
approval_required = true;
approval_description = reason;
approval_force_prompt = true;
}
ToolAskRuleDecision::Block(reason) => {
approval_required = false;
approval_force_prompt = false;
blocked_error = Some(ToolError::permission_denied(reason));
}
}
}
}|
Thanks @greyfreedom — I carried this into the v0.8.64 integration branch with attribution:
I folded in the review note so file/shell ask-rule evaluation is skipped once a tool is already blocked by earlier planning. Verified with:
This is a good fit for the v0.8.64 hardening lane. |
|
Thank you @greyfreedom — file-ask-rule application at runtime landed in the v0.8.64 release branch (file_tool_ask_rule_decision + exec_shell_ask_rule_decision in crates/tui/src/core/engine.rs, applied in the turn loop). Your PR helped validate the design. Appreciate it! |
Summary
Wire ask-only
permissions.tomlfile-path rules into the TUI runtime approval path.Scope
AskForApproval::Never.docs/TOOL_SURFACE.mdto document explicit file-path ask-rule runtime handling.Not in this slice
Builds on
permissions.tomlschema/loading work.exec_shellask rules.exec_shellask rules.Issues
Refs #1186 (partial)
Refs #2242 (partial)
Validation
cargo fmt --all -- --checkcargo check -p codewhale-tui --bin codewhale-tuicargo test -p codewhale-tui --bin codewhale-tui ask_rule_decision -- --nocapturecargo test -p codewhale-tui --bin codewhale-tui ask_rule -- --nocapturegit diff --check