Skip to content

feat(execpolicy): bash arity dictionary for command-prefix allow rules (closes #410)#655

Merged
Hmbown merged 3 commits into
Hmbown:mainfrom
merchloubna70-dot:feat/bash-arity-410
May 5, 2026
Merged

feat(execpolicy): bash arity dictionary for command-prefix allow rules (closes #410)#655
Hmbown merged 3 commits into
Hmbown:mainfrom
merchloubna70-dot:feat/bash-arity-410

Conversation

@merchloubna70-dot

Copy link
Copy Markdown

Summary

  • Adds crates/execpolicy/src/bash_arity.rs with a new BashArityDict struct containing a hand-curated arity table of 160+ entries covering 30+ command families (git, npm, yarn, pnpm, cargo, docker, kubectl, go, pip, gh, rustup, deno, bun, aws, terraform, helm, make, and more)
  • Wires arity-aware prefix matching into crates/tui/src/command_safety.rs via a new public prefix_allow_matches() function
  • Updates crates/tui/src/execpolicy/rules.rs so ExecPolicyConfig::evaluate() uses arity-aware matching for allow rules before falling back to the existing wildcard/regex pattern_matches path
  • Updates crates/execpolicy/src/lib.rs so ExecPolicyEngine uses BashArityDict for trusted-prefix allow matching

Behaviour

# config.toml
auto_allow = ["git status"]
Command Before After
git status allowed allowed
git status -s denied (no match) allowed
git status --porcelain denied (no match) allowed
git push origin main allowed (wrong prefix match) denied (correct)

Existing exact-match allow rules and wildcard rules (cargo *) continue to work unchanged.

Test plan

  • cargo +nightly check passes — 0 errors, 0 warnings
  • BashArityDict unit tests in bash_arity.rs cover classify() and allow_rule_matches() for all major tool families
  • prefix_allow_matches doctest examples cover git/cargo/npm/make
  • New rules.rs tests: test_prefix_rule_allows_git_status_with_flags and test_prefix_rule_allows_cargo_check_variants
  • Existing command_safety.rs classify_command tests and auto_allow_* integration tests all still pass
  • Dictionary covers ≥ 30 common commands (enforced by dict_covers_at_least_30_commands test)

🤖 Generated with Claude Code

macworkers and others added 3 commits May 4, 2026 12:39
All system prompts were English-only, causing DeepSeek V4 to reason
and respond in English even when users wrote in Chinese or other
languages.

Add a Language Mirror section to base.md and base.txt that instructs
the model to detect the user's primary language and use it for both
reasoning (thinking tokens) and the final reply.
base.txt is not referenced via include_str! in prompts.rs.
Only base.md is loaded (BASE_PROMPT). Remove the redundant change
to base.txt as noted by Gemini Code Assist review.
closes Hmbown#410)

Add `crates/execpolicy/src/bash_arity.rs` with a hand-curated `BashArityDict`
struct (160+ entries, 30+ command families: git, npm, yarn, pnpm, cargo,
docker, kubectl, go, pip, gh, rustup, deno, bun, aws, terraform, helm, make).

Wire arity-aware prefix matching into:
- `crates/tui/src/command_safety.rs` — new public `prefix_allow_matches()`
  function so `auto_allow = ["git status"]` matches `git status -s` /
  `git status --porcelain` but NOT `git push`.
- `crates/tui/src/execpolicy/rules.rs` — `ExecPolicyConfig::evaluate()` now
  checks allow rules via `prefix_allow_matches` before falling back to the
  existing regex/wildcard `pattern_matches` path.
- `crates/execpolicy/src/lib.rs` — `ExecPolicyEngine` uses `BashArityDict`
  for trusted-prefix matching; backward-compatible with existing exact-match
  deny rules.

`cargo +nightly check` passes. 0 errors, 0 warnings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@ILoveScratch2

Copy link
Copy Markdown

谁家PR机器人

@Hmbown

Hmbown commented May 5, 2026

Copy link
Copy Markdown
Owner

Triple-check: clean

Verified: BashArityDict is constructed with entries for git (2-arg subcommands), cargo (1-arg subcommands), npm/yarn/pnpm (1-arg subcommands), docker (1-arg subcommands), kubectl (1-2 arg subcommands), aws (2-arg subcommands), and others. allow_rule_matches is called from ExecPolicyEngine::check at lib.rs:236, replacing the old prefix-match-only behavior. Arity-aware matching ensures auto_allow = ["git status"] matches git status -s but not git push. Properly wired. ✅

Hmbown added a commit that referenced this pull request May 5, 2026
47 fmt drifts had accumulated from the squash-merged community PRs on
this branch (#653, #654, #655, #645, #658, #668, #659, #661, #660,
#667, #656). Pure formatting — no behavioural changes — applied via
`cargo fmt --all` to satisfy CI's `cargo fmt --all -- --check` gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Hmbown Hmbown merged commit fb2e61e into Hmbown:main May 5, 2026
1 check passed
MMMarcinho pushed a commit to MMMarcinho/DeepSeek-TUI that referenced this pull request May 6, 2026
MMMarcinho pushed a commit to MMMarcinho/DeepSeek-TUI that referenced this pull request May 6, 2026
47 fmt drifts had accumulated from the squash-merged community PRs on
this branch (Hmbown#653, Hmbown#654, Hmbown#655, Hmbown#645, Hmbown#658, Hmbown#668, Hmbown#659, Hmbown#661, Hmbown#660,
Hmbown#667, Hmbown#656). Pure formatting — no behavioural changes — applied via
`cargo fmt --all` to satisfy CI's `cargo fmt --all -- --check` gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants