Skip to content

feat(command-risk): parse commands with a real shell AST #286

Closed

Description

@mrnasil

Follow-up to the embedded-shell spike (#280). crates/command-risk classifies shell commands with its own tokenizer (tokenize.rs) and path rules (paths.rs). A parser-grade front-end would judge what actually runs.

What a real AST gains

  • Compound commands and lists with exact precedence (a && b || c; d), subshells and groups.
  • Quoting resolved exactly (single, double, ANSI-C, escapes) instead of heuristics.
  • Substitutions as structure: $(…) and backticks are already assessed as commands since fix(command-risk): a command substitution is judged by the command it runs #282; an AST also covers nested quoting inside them and $((…)) arithmetic.
  • Typed redirects (2>&1, >|, &>, <<<), heredoc bodies treated as data, not commands.
  • Assignment propagation (DIR=/ ; rm -rf $DIR).

Plan

  • Optional feature parser in whycodes-command-risk pulling a Rust POSIX shell parser crate; on ParseError fall back to the tokenizer so nothing gets less strict.
  • Lower the AST to the existing Segment shape so paths.rs stays the parser-independent catastrophic tier.
  • Corpus tests: the four cases above plus the existing assess.rs suite must keep every verdict (no regressions to Safe).
  • Benchmark before/after (scripts/check_bench_ceilings.py has no entry for this yet; add one if the parser costs more than ~1 ms per command).

Split out of #267.

🤖 Generated with Claude Code

Activity

  1. added a commit that references this issue on Oct 16, 2026
    cb114de
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions