Repository navigation
feat(approval): CST shell classifier with a Forbidden tier; shell v2 environment (T6) - #40
Merged
Merged
Conversation
lg2m
force-pushed
the
feat/tool-layer-t6-classifier
branch
from
September 14, 2026 21:01
72311c4 to
11a5398
Compare
Merged
…pendencies for the shell classifier qq-tui already depended on both; qq-core now shares the rows. No new packages enter the lock. Starts tool-layer T6.
…ested rules (T6)
Shell commands are classified over a tree-sitter-bash parse instead of a
hand tokenizer. Two walks: word_only_sequence accepts only
`cmd (&& || ; |) cmd…` of literal words and is the sole path to Allow;
the collector finds every simple command anywhere (subshells, control
flow, $(…), function bodies), peels wrappers (env, nice, nohup, time,
timeout, stdbuf, xargs, sudo/doas/su, sh -c STRING reparsed), and
records redirect targets. Parse errors, dynamic words, unlisted programs,
and constructs classify Prompt. The lattice is Forbidden > Prompt >
Allow, strictest over every simple command.
Rules are a static table (approval/rules.rs) with ~250 match/not_match
examples run as one unit test: Allow for build/test/inspect shapes with
literal argv and workspace-relative operands; Prompt for deletions, git
mutations and remotes, mode changes, in-place edits, installs,
containers, downloads, signals, xargs/tee, redirects, inline
interpreters, paths outside the workspace; Forbidden for rm -rf on root
or home or outside the workspace, privilege escalation, raw device
writes, filesystem formatting, power state, git force-push, recursive
mode changes on root, download piped to an interpreter, dynamic eval,
fork bomb, history/shred, shell-profile and ~/.ssh writes, reverse
shells, and LD_PRELOAD/PATH/GIT_SSH_COMMAND-class env prefixes.
PolicyDecision gains Forbidden { rules }: refused under every mode
including full, unless a grant quotes the exact command string; the
model gets a tool error naming the rule and an alternative. Auto mode
now executes exactly what the classifier allows and asks for the rest.
ShellCommandPreview gains verdict and reasons (additive, protocol
version unchanged pending the release bump) so clients can say why.
tree-sitter and tree-sitter-bash are promoted to workspace dependencies
(qq-tui already had both); the lock gains no package. New
classify_command bench: 3.3 µs simple, 10 µs pipeline, 163 µs for a
1 KiB one-liner (≤ 200 µs gate), 7 ns past the 16 KiB ceiling.
…built-in preference (T6) The shell child now starts from a cleared environment plus PATH HOME LANG TERM TMPDIR; a call names further variables in `env` (≤ 16), each of which must be in `policy.shell_env` or the call fails env_not_allowed before anything runs. Secrets the server holds no longer reach children by accident. policy.shell_env layers like a grant (trust-gated, Remove(...) supported, validated as variable names, ≤ 64). policy.builtin_preference is off | hint (default) | strict and may only tighten across layers. hint appends one `hint: use search instead of grep; …` line when a command's first program has a bounded built-in; strict refuses it before execution with use_builtin — the benchmark arm for measuring what shell habit costs. ShellPolicy travels Runtime → AgentProfile → CompiledAgentPlan → the tool loop → run_shell, mirroring AuditPolicy. qq config show prints both keys. The base agent prompt moves to version 11 (the T2–T6 tool-layer series changed its text without a bump); the golden descriptor digest and the tool-schema hash follow.
lg2m
force-pushed
the
feat/tool-layer-t6-classifier
branch
from
September 14, 2026 21:51
11a5398 to
b0e58fe
Compare
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.
T6: a CST shell classifier with a
Forbiddentier above every approval mode; shell v2 with a cleared environmentSpec: docs/plans/tool-layer.md § D5 (T6) Linear: ENG-776 ADR: docs/adr/0020-shell-forbidden-classifier.md Follows: #37 (T5)
What changed
Safety (user-visible)
tree-sitter-bashand judged on a three-tier lattice —Forbidden > Prompt > Allow— strictest verdict over every simple command anywhere in the tree: subshells,if/forbodies,$(…), function bodies, and wrappers (env -i,nice,nohup,time,timeout,stdbuf,xargs,sudo|doas|su,sh|bash|zsh -c STRINGreparsed) are all seen.Forbiddenis refused under every mode,fullincluded:rm -rfon root/home/outside the workspace,sudo, raw device writes,mkfs/fdisk, power state,git push --force|+ref|--delete|--mirror,chmod -R 777 /,curl | sh, dynamiceval, fork bomb,history -c/shred/crontab -r, writes to shell profiles/~/.ssh//etc, reverse shells,LD_PRELOAD/PATH/GIT_SSH_COMMAND-class env prefixes. The model gets a tool error naming the rule and an alternative. Only a grant quoting the exact command lifts it; prefix grants liftPromptonly.autonow executes exactly what the classifier allows (build/test/inspect shapes with literal argv and workspace-relative operands) and asks for the rest — replacing a substring heuristic that a subshell walked past.ShellCommandPreviewgainsverdictandreasons(rule ids) so the TUI can say why it is asking.Shell v2
PATH HOME LANG TERM TMPDIR. A call names extra variables inenv(≤ 16); each must be inpolicy.shell_envor the call failsenv_not_allowedbefore anything runs. Server secrets no longer leak into children by accident.policy.builtin_preference: off | hint | strict.hint(default) appendshint: use search instead of grep; …when the first program has a bounded built-in;strictrefuses withuse_builtinbefore execution — the ablation arm for measuring what shell habit costs.shell_envis trust-gated, supportsRemove(...));builtin_preferencemay only tighten across layers.qq config showprints both.Rules as data.
approval/rules.rsis a static table;rule_examples_holdruns ~250match/not_matchexamples (~90 Allow, ~75 Prompt, ~80 Forbidden) as one test, so intent and reach are checked together.Plumbing
tree-sitter/tree-sitter-bashpromoted to[workspace.dependencies](qq-tui already had both) — no new package in the lock. Root request closed inroot.md.ShellPolicytravelsRuntime → AgentProfile → CompiledAgentPlan → tool loop → run_shell, mirroringAuditPolicy.AGENT_PROMPT_VERSION10 → 11: T2–T6 changed the prompt text without a bump; this catches up once at the release boundary. Golden descriptor digest and tool-schema hash follow.dangerous_shell_commandtokenizer is removed.How verified
cargo test --workspace: 1389 passed / 0 failed; provider minimal 162; fmt andclippy -D warningsclean.forbidden_commands_are_refused_under_every_mode_unless_quoted_exactly, 2 shell tests (cleared env / allowlist / typed refusals; hint on/off), 1 config layering test + 4 validation cases, 2shell_policytests.rm -rf /as a Prompt example now userm -rf target(it is correctly Forbidden); the T4 end-to-end shell test runs underfull; the headless smoke'sprintf > filebecamecp— a writing redirect now asks underauto, which is the intended behaviour.Measurements
classify_commandsimple / pipeline / wrapped-forbiddenclassify_command1 KiB one-liner (gate ≤ 200 µs)tool_dispatchA/B (12 pairs, idle core, median)Evidence:
target/qq-perf/t6-2026-09-14/.Docs
docs/design/tools.md§ Shell Execution (env, nudge), § Shell Classification (new), § Approval Policy (auto/full), § Workspace Grant Configuration (new keys); ledger receipt.Compatibility
full: Forbidden shapes are now refused. Underauto: commands with$VAR, globs, or writing redirects now ask where the old heuristic ran them.AWS_PROFILEreaching a child must list it inpolicy.shell_envand the call'senv. This is the intended hardening; the error names the fix.ShellCommandPreview.verdict/reasonsare additive withskip_serializing_if; PROTOCOL_VERSION bump deferred to the release PR so one bump covers T6+T7. Store schema unchanged. Prompt version 11.Deviations from the plan (ledger)
PolicyDecision::Forbidden { rules }as its own variant rather thanDeny { reason }.cut … /etc/passwdprompts (outside workspace).Follow-ups
exec. T13: tune the Allow table from the measuredautoprompt rate. Configurable rule overrides only when a user asks.