Skip to main content

aft/bash_rewrite/
mod.rs

1//! Bash command rewriter for hoisted bash. Phase 0 stub; Phase 1 Track B fills in.
2//!
3//! When the agent calls `bash("grep -n foo src/")`, the rewriter detects this
4//! pattern, dispatches internally to AFT's `grep` command, and returns the
5//! result with a footer hint nudging the agent to use the `grep` tool directly.
6
7pub mod dispatch;
8pub mod footer;
9pub mod parser;
10pub mod rules;
11
12use crate::context::AppContext;
13use crate::protocol::Response;
14
15/// A `RewriteRule` matches a specific bash invocation pattern and dispatches
16/// internally to an AFT tool.
17pub trait RewriteRule: Send + Sync {
18    fn name(&self) -> &'static str;
19    fn matches(&self, command: &str) -> bool;
20    fn rewrite(
21        &self,
22        command: &str,
23        session_id: Option<&str>,
24        ctx: &AppContext,
25    ) -> Result<Response, String>;
26}
27
28/// Try to rewrite a bash command into an internal AFT tool call.
29/// Returns Some(response) if rewritten, None if no rule matched.
30pub fn try_rewrite(command: &str, session_id: Option<&str>, ctx: &AppContext) -> Option<Response> {
31    dispatch::dispatch(command, session_id, ctx)
32}