Feature Request
Integrate with bashrs to validate suggestions for safety before returning them.
Motivation
bashrs can detect dangerous commands:
$ echo 'rm -rf /' | bashrs lint /dev/stdin
✗ 1:1-9 [error] SC2114: CRITICAL: rm -rf on root or root-like path is extremely dangerous
$ echo 'rm target/' | bashrs lint /dev/stdin
⚠ 1:1-10 [warning] IDEM002: Non-idempotent rm - add -f flag
Proposed Integration
Option 1: Runtime validation
Before returning a suggestion, validate it:
fn suggest(&self, prefix: &str) -> Vec<Suggestion> {
let candidates = self.model.predict(prefix);
candidates
.into_iter()
.filter(|s| !is_dangerous_command(&s.command))
.collect()
}
fn is_dangerous_command(cmd: &str) -> bool {
// Use bashrs as library or subprocess
let output = Command::new("bashrs")
.args(["lint", "--format", "json", "/dev/stdin"])
.stdin(Stdio::piped())
.output()?;
// Check for errors
let result: LintResult = serde_json::from_slice(&output.stdout)?;
result.has_errors()
}
Option 2: Build-time integration
Add bashrs as a library dependency:
[dependencies]
bashrs = { version = "6.34", features = ["lint"] }
use bashrs::lint::{lint_command, Severity};
fn is_safe(cmd: &str) -> bool {
let issues = lint_command(cmd);
!issues.iter().any(|i| i.severity == Severity::Error)
}
Option 3: Configurable validation level
# In config
[safety]
validation = "strict" # none, basic, strict
# With strict:
# - Block SC2114 (rm -rf /)
# - Block commands with secrets (#86)
# - Warn on non-idempotent operations
Benefits
- Prevent dangerous suggestions - No more
rm -rf / accidents
- Educate users - Show warnings for risky commands
- Leverage existing analysis - bashrs has 6000+ tests and comprehensive checks
- ShellCheck compatible - Uses standard SC codes
Example Output
$ aprender-shell suggest "rm -rf "
rm -rf ./target 0.85 # ✅ Safe
rm -rf node_modules 0.72 # ✅ Safe
# rm -rf / [blocked - SC2114: dangerous]
Related
Feature Request
Integrate with bashrs to validate suggestions for safety before returning them.
Motivation
bashrs can detect dangerous commands:
Proposed Integration
Option 1: Runtime validation
Before returning a suggestion, validate it:
Option 2: Build-time integration
Add
bashrsas a library dependency:Option 3: Configurable validation level
Benefits
rm -rf /accidentsExample Output
Related