Skip to main content
Blitz
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage
Edit page

005 · Approvals

Approvals and user questions (spec_005_approvals)

Status Implemented. Reverse-engineered from 53f8c53 (2026-09-24) and kept with the code since; its paths checked 2026-09-27 (//tools/specs).
Source pkg/engine/tools/hooks.go, approval_store.go, ask_user.go; approver UI in apps/cli/internal/tui
Tests pkg/engine/tools/approval_test.go, approvals_checkpoints_test.go
Depends on spec_002_config, spec_003_observability (audit)
Used by spec_006_filetools, spec_007_shell, spec_008_web, spec_009_mcp, spec_013_skills, spec_014_agents, spec_023_workers

1. Purpose

Sensitive tool actions (edits, deletions, commands, network, MCP tools, forged tools, skill installs) pass one gate, Hooks.Approve, which fails closed. Front ends supply the interactive approver; remembered and saved rules skip it; unattended runs (jobs) replace it with a permission check.

2. Request and decision

  • APR-01 ApprovalRequest{Tool, Kind, Detail, Diff, Key, KeyLabel, Targets}. Kinds: run_command, write_file, delete_file, network, mcp_tool.
  • APR-02 Key names what a remembered decision covers; empty means it can only be approved once. Targets are what policies match (workspace-relative paths, the command, the URL host or search provider, server:tool); empty targets can’t be matched by permission policies.
  • APR-03 Decisions: deny, once, session (same key until the process exits), always (same key, persisted).
Action Key Label
File edit write:<workspace> file edits in the workspace
File delete delete:<workspace> file deletions in the workspace
Shell command cmd:<workspace>\x00<exact command> this exact command in this workspace
Web fetch web:<host> (per host)
Web search per provider
MCP tool mcp:<server>:<tool>
Forged tool run uc-run:<name>\x00<script sha256>\x00<args> this forged tool, as it is now, with these arguments
Tier-3 skill script none (never rememberable)

3. Evaluation order (Approve)

  • APR-10 Unattended context (tools.Unattended(ctx, decide)): only decide is consulted — auto-approval, session/saved rules and the interactive approver are bypassed and nothing is remembered. Allowed → audit approval unattended-permitted; refused → audit denial unattended-refused and error “ isn’t among this unattended run’s permissions”.
  • APR-11 Otherwise, in order: permission mode bypass → allowed, audit mode-bypass; tools.auto_approve_commands (commands only) → auto-policy; a session rule for the key → session-rule; a saved rule → saved-rule; mode accept-edits and a write or delete (paths were already resolved as writable) → mode-accept-edits; mode dont-ask → denied, mode-dont-ask; no approver → denied, audit no-approver, error suggesting a rule or a permission mode.
  • APR-11a 2026-11-05 (scan N26-engine-tools-1#4: refusals were logged as approvals). Every refusing decision is an audit denial (and a denial in a workflow run’s receipt): deny, no-approver, error, mode-dont-ask, hook-deny and background-refused, as well as rule-deny, unattended-refused and auto-deny.
  • APR-15 Permission rules ([permissions] allow/ask/deny, kind(pattern) or a bare tool name; tools.PermissionRules, live): the gate evaluates them first by the request’s kind and targets — deny if any target matches a deny rule (in every mode, audited rule-deny, also for unattended runs), else ask if any matches an ask rule (MustAsk: straight to the approver, skipping modes, allow rules and remembered approvals; refused in dont-ask, without an approver, and in unattended runs), else allow if every target matches an allow rule (rule-allow; never for unattended runs, which keep exactly their permissions). shell rules are applied by the command policy on every sub-command (deny joins deny, allow joins auto-approve, ask sets MustAsk; an unverifiable command sets MustAsk when ask rules exist). web deny/ask are also applied before allow_domains and fetch grants; mcp deny/ask apply to auto_approve servers; bare tool names, skill and agent deny rules refuse the call before it runs (engine beforeTool). read rules are deny-only and become blocked paths at start. Rules can be added and removed during a session (read rules only by saving; they apply from the next start); saving edits [permissions] in place, in the global settings or the workspace’s own (api.Scope), whose rules add to the global ones; a saved rule applies as the file’s, not also the session’s. Rules are checked before they’re saved (config.ValidatePermissionRule, set by the parser), also in the settings-file editor. [permissions] read_only_defaults (default on; a workspace may set it either way) adds built-in rules (source built-in): allow config.ReadOnlyCommands (ls, pwd, cat, head, tail, wc, stat, du, df, which, grep, rg, diff, git status, git log, git show, git diff, git blame, git rev-parse), and ask for config.ReadOnlyGuards (git … --output, git … --ext-diff, rg … --pre); a redirection to a file still asks (SH-11a). Sources as listed: global, workspace, built-in, flag, session. When the settings change, open workspaces replace their configured and built-in rules (PermissionRules.ReplaceConfigured, Workspace.ReloadPermissions). tools.CheckPermissionRule checks a rule without adding it and says how it matches (prefix, glob, regex, path, name) and whether it applies to a sample (an allow rule to every command in it, ask or deny to any), noting a redirection.
  • APR-15b 2026-11-05 (scan N26-engine-tools-2#4: a patch’s *** Delete File and a writes_workspace script’s removed files were approved as plain writes, so deny delete(…) and ask delete(…) never saw them). A write that deletes files names them in the request (ApprovalRequest.Deletes: apply_patch’s deleted files and moved-away sources, a script’s removed files), and delete rules govern them as well as write rules over all its targets: deny from either wins, then ask from either, and it’s allowed by rules only when both allow.
  • APR-15c 2026-11-05 (scan N26-engine-tools-2#5: deny write(*.pem) matched only top-level files, and deny write(~/proj/secrets/**) never matched, since targets are workspace-relative). read, write and delete patterns take the blocked paths’ forms (spec_006 FS-10): a name without a slash (*.pem, secrets) at any depth; an absolute or ~ location matched against the target’s absolute path (the workspace’s path joined to it; also the location’s link-resolved spelling); a relative path with a slash from the workspace root. A relative pattern doesn’t cover the other allowed roots: name them absolutely.
  • APR-15a Rules follow their files, whoever edits them (the desktop app, /permissions --save, an editor, another process): the engine looks at the global settings, the workspace’s own, the project’s files (.blitz/settings.toml, .blitz/settings.local.toml) and the approvals file every 2 s (settingswatch.go), and applies a change to the live rules (ReplaceConfigured, ReplaceProject, ApprovalStore.Reload). Every tool call reads them, so a turn already running obeys an added or removed rule from its next action; background tasks share them. A project’s loosening settings still wait for trust (spec_031_project_config); jobs keep their own permissions. Watching clients hear of it: WatchTasks sends settings_changed, and the desktop app’s Run settings and Settings › Permissions reload.
  • APR-14a The auto mode (PAR-PERM-20, -21): after deny rules, the automatic allows (allow rules, remembered approvals, auto-approved commands) and permission_request hooks, what would ask the user goes to the reviewer (Hooks.SetReviewer, Engine.review): [permissions.auto] model (else the session’s model) with the request (tool, kind, detail, targets, diff up to 8,000 characters), the last six messages, the workspace and [permissions.auto] environment, asked for {"decision": "allow"|"deny", "reason": …} (parseVerdict reads it in a code fence too). Allow proceeds (auto-allow: <reason> in the audit log), deny returns the reason to the agent (auto-deny); a failure, an answer that isn’t a verdict, or no answer within 2 minutes (reviewTimeout) asks the user (auto-error). An ask rule still asks the user. Its tokens count in the session’s usage. [permissions.auto] comes from the user’s settings only (a project may not set it); it follows accept-edits in Shift+Tab’s cycle.
  • APR-14b 2026-11-07 (the owner: “I checked the boxes, clicked approve, but was then blocked. That shouldn’t happen”). The reviewer reads what the user said in every form, not only their messages: the recent conversation it’s given (recentConversationN, answeredLine in pkg/engine/runtime/review.go) has the agent’s ask_user_question questions (“agent asked the user: …”), the user’s answers (“user answered: …”, several questions’ answers each after its question) and their answer to a plan (“user approved the agent’s plan”, or their feedback). Other tools’ results stay out: they aren’t the user’s words. Before, an answer reached the agent as a tool’s result, which the reviewer skipped, so after “Can you display these as options?” and the user ticking two and approving them, the first edit was denied as “they asked to see options, not changes”.
  • APR-14c 2026-11-08 (the owner, with qwen2.5-coder:7b on Ollama: the agent called create_file for .agents/scratch/recipebook_database.md, auto mode’s reviewer, the same model, denied it as “outside the workspace”, and the model pasted Markdown for the rest of the conversation). Facts before the reviewer: for a write or delete whose targets are all workspace-relative paths that don’t climb out (inWorkspace in pkg/engine/runtime/review.go), the reviewer’s prompt says so, with each full path, and a denial whose reason says the action is outside the workspace or project is no verdict: the user decides, as when the reviewer fails. A local model doesn’t review its own actions: with no reviewer model of its own ([permissions.auto] model, built as the workspace opens) and the workspace’s model on Ollama (localReview in pkg/engine/localmode.go), auto mode is default (ask) instead, when the workspace opens, when its model changes, and when auto is chosen; Settings.mode_note says why, and the desktop’s status bar shows the mode with a warning and says it once in a snackbar, the CLI on start, /mode, /model and /status. A model that doesn’t run here gives auto back, if it was held for this reason; ask chosen by the person stays.
  • APR-14d 2026-11-08 (the owner: “They should be presented with a clickable choice in chat without needing to type anything”). When the reviewer denies an action and someone is there to answer (the chat’s approver, or a background task’s people), they’re asked instead of the agent being refused: the request carries the reviewer’s reason (ApprovalRequest.reviewer_denied), the desktop’s card shows it with Allow anyway and Deny (Deny focused, so a stray Enter doesn’t allow it), and the terminal’s picker shows it with “Yes, allow it anyway” (the cursor on No). The audit log has auto-deny and then the person’s decision. With nobody to ask (a background run, a script without an approver), the denial goes back to the agent as before.
  • APR-14e 2026-11-21 (the owner: “one more mode … for running outside the sandbox, or ‘Unsafe’, or ‘FFAFO’ mode”). unsafe (also fafo, no-sandbox): bypass with the shell’s commands, foreground and background, run outside the OS sandbox (the guard and the scrubbed environment stay); nothing is asked (mode-unsafe in the audit log). Deny rules, guardrails and the file tools’ blocked paths still apply; skill scripts, MCP servers, hooks and language servers run as before. Only the person chooses it, each time: /mode unsafe, --permission-mode unsafe, or the status bar’s menu, which asks first. It’s never kept or restored: a settings file naming it (one the agent’s command could have written) opens the workspace in default with ErrUnsafeChosenEachTime, and the window doesn’t save it. It’s refused while the agent is at work in the workspace (ErrUnsafeWhileAgentWorks: a turn, a background task, or a background process it started), so a command of the agent’s reaching the service can’t switch it; and a blitz the agent’s command started (BLITZ_AGENT set) refuses it for --permission-mode, /mode and /set mode. An agent’s permission_mode of it isn’t applied, the agent’s settings set mode refuses it (only stricter modes, DRV-71), and Shift+Tab never reaches it (from it, Shift+Tab goes to default). While connected to an organization it’s refused (ErrUnsafeNotHere), and a setting asking for it opens in default with the reason. It ranks loosest (above bypass) for Looser. The CLI shows it red and warns on switching; the window marks it red.
  • APR-14 Permission modes (per workspace, shared by every session and client of it): default, accept-edits, auto (APR-14a), plan (every prompt of Workspace.Run is planned — PlanPrompt and WithPlanOnly — while the transcript keeps the text as typed; job runs and read-only/aside turns are unaffected), dont-ask, bypass. The starting mode is [blitz] permission_mode (a workspace’s own settings may set it: the user restricts a workspace there, and the desktop app’s workspace settings keep the mode chosen), else bypass for auto_approve = true, else auto (since 2026-10-18; tools.StartingMode). A project’s files may not set it. A workflow runs in its own mode within the workspace’s (spec_043_workflows WF-21). bypass requires the OS sandbox to be active, at start (otherwise default with a warning, Registry.ModeNote) and when switching (ErrBypassNeedsSandbox). ParsePermissionMode accepts Claude Code’s spellings (acceptEdits, dontAsk, bypassPermissions).
  • APR-14c 2026-11-05 (scan N26-desktop-2#17: the status bar’s mode menu changed the mode for the running workspace only, while Settings › Workspaces kept it, so the workspace reopened in the old mode). A mode picked in the desktop’s status bar is kept as the workspace’s mode (blitz.permission_mode in its own settings), as Settings › Workspaces keeps it (keepPermissionMode): new chats and the workspace after a restart start in it. It’s applied first, so what the service refuses (bypass without the OS sandbox) is neither applied nor kept; a project’s files still can’t set the mode. /mode and Shift+Tab stay for the running workspace only.
  • APR-14b 2026-11-05 (scan N26-engine-tools-1#6: auto_approve = true turned a workspace’s explicit permission_mode = "default" into bypass). auto_approve = true applies only while permission_mode is unset: a mode that is set, default included, is the starting mode.
  • APR-12 Otherwise the approver is asked inside an approval span (time waiting for the user is isolated from tool time; attributes tool, kind, decision). An approver error denies (error). session/always with a key add a session rule; always also saves it (a save failure is reported as “approved, but saving the rule failed”). Deny returns “the user declined this ”.
  • APR-12a 2026-11-05 (scan N26-engine-tools-1#5: the save failure went only to the log). When an always rule can’t be saved, the person is told in the turn’s notices (approvals.save_failed: “Approved, but saving the rule failed, so it lasts only this session: …”) as well as the log.
  • APR-13 Auto-approval and rules never override hard policy: deny rules, the file sandbox and the OS sandbox are checked before approval.

4. Saved rules

  • APR-20 ~/.blitz/approvals.json (tools.approvals_file): {"version":1,"rules":[{key,label,added}]} sorted by key, written atomically (temp + rename) in a 0700 directory. A missing file is empty; a corrupt file is a startup error.
  • APR-21 Rules can be listed, revoked individually, or cleared (/approvals, spec_018_workspace WS-62).

5. Interactive approver (terminal)

  • APR-30 Shows the detail and (for edits) a coloured diff truncated to ui.diff_lines (120); answers y once, s session, a always, n no. Ctrl+C at an approval prompt cancels the whole turn. With no terminal to ask, the request is denied unless covered by config.

6. ask_user_question, plans and the task list

  • APR-41 exit_plan_mode(plan): only while the turn is planning (else an error). Unattended, dont-ask or no prompter → approved: false and “end your turn with the plan as your answer”. Otherwise the plan goes to the user through the question prompter, with options Yes, carry it out / Yes, and accept its file edits without asking / No, keep planning (localized); any other answer is feedback (approved: false, feedback), and the agent revises. On approval the plan is saved to .blitz/plans/<session>-<n>.md (session ID made file-safe; n the first free number), the gate records the mode (default or accept-edits) and planning ends.

  • APR-42 enter_plan_mode(reason?) (registered only with plan_review = agent-decides): refused when no one can review (unattended, dont-ask, no prompter); otherwise the rest of the turn plans.

  • APR-43 todo(items): the whole list, each {content, status} with status pending|in_progress|done (todo, in-progress, completed and the like are normalized); at most 50 items; empty content or an unknown status is an error; more than one in_progress adds a note. The result carries the normalized items, done and total; front ends show it as a checklist (api.Event.Tasks). A foreground sub-agent’s list shows while it runs, then the caller’s again (spec_014_agents AG-31a). The built-in project-setup and project-spec send the list again each time a step starts and ends, and after another agent returns (2026-10-29: a model that only made the list left the checklist on its first step), and ask only with ask_user_question, with options whenever answers are likely, never as a question in their text.

  • APR-40 Args question, options?. Empty question → error. Unattended → error “this run is unattended: no one can answer; decide yourself and say what you assumed”. No prompter → “interactive input is not available; proceed with your best judgement”. Otherwise returns the user’s answer. The prompter shares the front end’s input reader (no competing stdin readers).

  • APR-40a Several questions and multi-select (PAR-TOOL-05): multi_select: true (it needs options) lets the user choose several; questions: [{question, options?, multi_select?}] (at most 8) asks them in turn, instead of question. A multi-select question is marked on the prompter’s context (api.WithMultiSelect, Question.multi_select, TaskRequest.MultiSelect); its answer is the options chosen, one per line, returned as selected and joined in answer (", “). With questions, the result is answers: [{question, answer, selected?}]; an error stops at the question it happened on, with the answers so far. The REPL reads a multi-select answer as numbers or text separated by commas; the desktop app shows checkboxes and Send; stream-json input sends multi_select with the question.

  • APR-40b 2026-11-07 (the owner’s request: “not everyone using this tool is technical”). Explained choices: when the options name technical things (frameworks, libraries, services, architectures), the agent gives choices instead of options, each {label, summary, details, why}: a short plain label for the button, one sentence for its tooltip, a few sentences on what choosing it means for someone non-technical, and why it’s ranked there. They come best first, and order says in a sentence what the ranking rests on (easiest to maintain with AI, the largest community, the project’s ADRs). The tool’s description asks for them. The labels are the question’s options, so a front end that doesn’t know choices still offers them; a blank label is refused. They travel on the prompter’s context (api.WithChoices, api.ChoicesOf), Question.choices and Question.order, and TaskRequest.Choices for a background task’s question. The app shows each as its button (the summary its tooltip, at once on hover), Recommended on the first, and an info button that opens the details and why; a multi-select question’s choices get the same tooltip and details. The terminal prints the order’s reason above the options, and each option’s summary and why under it.