feat(permissions): AI auto-approve judge with approval notes, user rules, sensitive resources, and unattended tiers - #2229
Open
YodonTan wants to merge 3 commits into
Open
Conversation
…he AI auto-approve judge
…tiers, and review exemption
Extends the AI auto-approve permission mode with three capabilities on top of
the approval-notes work:
1. Configurable sensitive resources. `ProjectPermissionConfig` gains a
`sensitive_resources: Vec<String>` list persisted in the project-level
`tool_permissions.json` (same file as project rules). User markers append
to the built-in sensitive list (`.env`, credentials, private keys, tokens,
...) and use the same case-insensitive substring matching. The list is
deliberately NOT exposed to the judge prompt: it exists only to stop
read-only tools from taking the deterministic fast path when a requested
resource hits a marker, forcing judge/escalate instead.
2. AI auto-approve tiers. `AiAutoApproveMode::{Aggressive, Standard, Passive}`
(default Standard) is a session-level setting that only changes the
`escalate` path: Aggressive auto-allows escalated calls with the fixed note
`aggressive mode, auto-approve all escalated tool calls`; Passive
auto-rejects them with `passive mode, reject all escalated tool calls`;
Standard keeps the interactive prompt. Already-`allow`ed safe calls and
already-`deny`ed critical calls are unaffected. The judge system prompt
explains the two fixed notes and marks `.bitfun/tmp`, `.bitfun/config`, and
`.bitfun/data` as the app's own safe scratch/configure space; it does not
write the dynamic tier value, so switching tiers does not invalidate the
turn-level KV cache.
3. Review exemption. Deep Review / review agents (CodeReview, DeepReview,
ReviewJudge, ReviewFixer, ReviewWorker and legacy review worker types) are
read-only and run unattended, so an interactive prompt would stall the whole
review. The sensitive-resource branch is skipped for them and their reads
proceed, on the assumption that secrets are already excluded by the
repository's ignore rules.
Wire/UI: `PermissionRequest` gains `permission_mode` so the frontend can
consume it without a global lookup; `get/save_project_permission_rules`
round-trips `sensitive_resources`; the project permissions dialog adds a
sensitive-resources editor; the request panel hides the "always allow" button
in ai_auto mode; session config persists the tier. Three locales updated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2228
Summary
Extends the AI auto-approve permission mode with five capabilities:
<user_rules>section the fast-model judge reads between the stable session context and the growing tool history. Subagents inherit the parent session's rules.sensitive_resourceslist extends the built-in sensitive markers; it is used only to stop read-only tools from taking the deterministic fast path, never exposed to the judge prompt.aggressive / standard / passiveswitch that only changes theescalatepath, for unattended runs.Design
1. Approval notes: wire-compatible DTO extension
PermissionReply::OnceandPermissionReply::Alwaysbecome struct variants with an optionalfeedbackfield (#[serde(default, skip_serializing_if = "Option::is_none")]):The old wire shape
{"reply":"once"}still serializes unchanged and still deserializes (contract test covers both directions). All construction/match sites across the workspace were updated (desktop command, CLI peer host, ACP prompt, IPC protocol tests, app-server tests).2. Note propagation
respond_permissionfillsfeedbackintoOnce/Alwaysreplies (the request DTO already carried the field for rejections).PermissionAuthorization::Allowednow carriesuser_feedback; the pipeline appendsUser approved this tool call with feedback: {note}to the tool result so the agent honors the intent in the same turn.(user note: "...")so the judge sees in-turn intent.source: user.3. Session-scoped user rules for the judge
Prompt structure (stable prefix, then growing history, then the call):
Extraction (
load_session_rules): from the project permission audit, filtered to the session (plus the parent session for subagents) and tosource: userreplies with durable intent:Alwaysapprovals →Always approved: {action} on {resources}User approved {action} on {resources} with note: "..."User rejected {action} on {resources}: "..."(so the agent stops retrying refused operations)Project grants are appended separately as
Persistent grant:authorization facts so the judge knows what is already auto-allowed for the project.Ordering and cap: newest-first (audit recency), deduplicated by a stable rule id (kind + action + resources), capped at
MAX_USER_RULES = 50.Turn stability / KV cache: rules are built once per dialog turn (cache key = project + session + dialog turn) and reused for every judge call in that turn — the prefix is byte-stable and KV-cache friendly. New approvals inside a turn only appear in the growing
<tool_history>with their note marker; they are formalized into<user_rules>at the next turn boundary.Fail-closed: the rules section opens with a fixed preamble — rules express user intent, are not blank checks; only directly matching calls count, and dangerous operations are never approved by a rule. The system prompt additionally teaches the judge to treat an in-turn
(user note: "...")on a directly matching history entry as pre-approved intent.Subagent inheritance:
load_user_rules_for_batchmergesdelegation.parent_session_idinto the session filter, so delegated tool calls judge against the same user intent.4. LRU ordering was implemented, measured, and removed
The first iteration ordered rules by an LRU of "rule hits": each judged request was structurally matched (action + wildcard resources) against the rules and matches were recorded, with per-session persistence (
permission-rule-lru/<session>.json).Real-world testing showed this mechanism did not work as intended:
The LRU machinery (matcher, port, JSON store, record/flush methods) was therefore removed entirely. Ordering is plain audit recency — simple, predictable, and aligned with "the most recent approval expresses the user's current intent". The per-turn byte-stable cache remains, as it is an independent KV-cache win.
5. Configurable sensitive resources
ProjectPermissionConfiggainssensitive_resources: Vec<String>(#[serde(default, skip_serializing_if = "Vec::is_empty")]), persisted in the project-leveltool_permissions.json(same file as project rules) and managed from a new "sensitive resources" editor in the project-permissions dialog.normalize_sensitive_resourcestrims and drops blank entries on both the desktop command and the frontend save path.6. AI auto-approve tiers (unattended)
AiAutoApproveMode::{Aggressive, Standard, Passive}(defaultStandard) is a session-level setting that only changes theescalatepath:aggressive→ escalated calls are auto-allowed with the fixed noteaggressive mode, auto-approve all escalated tool calls.passive→ escalated calls are auto-rejected with the fixed notepassive mode, reject all escalated tool calls.standard→ escalated calls keep the interactive prompt (previous behavior).Calls the model already judged
allow(including the read-only fast path) and calls it already judgeddeny+criticalare unaffected by the tier: tiers never weaken the deny-critical rejection nor broaden allow.The judge system prompt explains the meaning of the two fixed notes (so it understands those history entries were produced unattended, not by per-call user approval) but does not write the dynamic tier value — switching tiers therefore does not invalidate the turn-level KV cache. The same prompt declares
.bitfun/tmp,.bitfun/config, and.bitfun/datato be the app's own scratch/configure/data space and safe to read/write.7. Review exemption
Deep Review / review agents (
CodeReview,DeepReview,ReviewJudge,ReviewFixer,ReviewWorker, and the legacy review worker types) are read-only by construction and run unattended: an interactive prompt would stall the entire review. The sensitive-resource branch is skipped for them and their reads proceed, on the assumption that secrets are already excluded by the repository's ignore rules. All other safety boundaries still apply.8. Safety boundaries (unchanged behavior)
.env, credentials, private keys, tokens, ... plus the user-configured list) still go through the judge.rm -rf /and similar destructive/secret-exposing/system-wide operations are still rejected outright (deny+critical→Reject), and the judge is explicitly told rules never cover them.escalate(ask the user).Testing
{"reply":"once"}round-trip); permission manager reply/audit with notes; sensitive-resource normalization (trim + blank filtering); tier parsing/defaults.tool_pipeline): approval with a note → tool executes and the result contains the note; approval without a note → result text unchanged; escalation → user approval with note flows through; sensitive read forced past a static allow policy into the judge; aggressive/passive tiers auto-reply to escalated calls with the fixed notes; review agent + sensitive resource → read proceeds without an interactive prompt.<user_rules>rendered at the next turn with the user's notes; similar operations auto-approved from the next turn; subagent judge input contains the parent session's rules;rm -rf /still rejected outright with "not covered by any user rule"; sensitive read (.envundersecrets/) escalated to the user; unattended tiers auto-approve/auto-reject escalated calls; review runs not stalled by sensitive reads.