Skip to main content

classify_bash_command

Function classify_bash_command 

Source
pub fn classify_bash_command(command: &str) -> ToolEffect
Expand description

Classify a bash command by its side-effect severity.

Returns the most dangerous effect found across all pipeline/chain segments:

  1. Raw structural patterns on quote-stripped string → Destructive
  2. Write side-effects (>, >>, | tee) → LocalMutation
  3. Per-segment shlex tokenisation vs DANGER_CHECKS → Destructive
  4. Per-segment allowlist vs READ_ONLY_PREFIXES → ReadOnly / LocalMutation

Segments that fail shlex tokenisation fail-open to LocalMutation.

§Examples

use koda_core::bash_safety::classify_bash_command;
use koda_core::tools::ToolEffect;

assert_eq!(classify_bash_command("ls -la"), ToolEffect::ReadOnly);
assert_eq!(classify_bash_command("git status"), ToolEffect::ReadOnly);
assert_eq!(classify_bash_command("cargo build"), ToolEffect::LocalMutation);
assert_eq!(classify_bash_command("rm -rf /"), ToolEffect::Destructive);