pub trait AgentRunner: Send + Sync {
// Required methods
fn build_command(
&self,
model: Option<&str>,
timeout_cmd: &str,
sys_file: &str,
msg_file: &str,
permissions: &PermissionRules,
) -> String;
fn parse_response(&self, raw: &str) -> Result<ParsedResponse, AgentError>;
fn stream_events(&self, event: &Value) -> Vec<StreamEvent>;
fn classify_error(
&self,
exit_code: i32,
stdout: &str,
stderr: &str,
) -> AgentError;
fn router_command(
&self,
prompt: &str,
model: Option<&str>,
) -> Result<Command>;
// Provided methods
fn extract_text(&self, raw: &str) -> Result<String, AgentError> { ... }
fn classify_error_with_elapsed(
&self,
exit_code: i32,
stdout: &str,
stderr: &str,
elapsed_secs: Option<u64>,
) -> AgentError { ... }
fn available_models(&self) -> Vec<String> { ... }
fn free_models(&self) -> Vec<String> { ... }
fn router_transcript(&self) -> RouterTranscript { ... }
}Expand description
Per-agent runner trait.
Each agent implements this to handle its specific CLI invocation, output parsing, and error classification.
Required Methods§
Sourcefn build_command(
&self,
model: Option<&str>,
timeout_cmd: &str,
sys_file: &str,
msg_file: &str,
permissions: &PermissionRules,
) -> String
fn build_command( &self, model: Option<&str>, timeout_cmd: &str, sys_file: &str, msg_file: &str, permissions: &PermissionRules, ) -> String
Build the CLI command string for the legacy tmux runner.
The returned string is embedded into a shell command that captures
output in the tmux session. The permissions struct carries unified
rules that each agent translates to its own CLI flags.
Sourcefn parse_response(&self, raw: &str) -> Result<ParsedResponse, AgentError>
fn parse_response(&self, raw: &str) -> Result<ParsedResponse, AgentError>
Parse raw stdout into a ParsedResponse.
Returns Ok(ParsedResponse) on success, Err(AgentError) if the
output indicates an error or cannot be parsed.
Sourcefn stream_events(&self, event: &Value) -> Vec<StreamEvent>
fn stream_events(&self, event: &Value) -> Vec<StreamEvent>
Transcript steps for one parsed line of this agent’s NDJSON output
Sourcefn classify_error(
&self,
exit_code: i32,
stdout: &str,
stderr: &str,
) -> AgentError
fn classify_error( &self, exit_code: i32, stdout: &str, stderr: &str, ) -> AgentError
Classify an error from exit code + stdout + stderr into an AgentError.
Called when the agent process exits with a non-zero code, or when parse_response fails to find a valid result.
Sourcefn router_command(&self, prompt: &str, model: Option<&str>) -> Result<Command>
fn router_command(&self, prompt: &str, model: Option<&str>) -> Result<Command>
Build a minimal CLI command for LLM-based routing.
The command should run the agent with prompt as the sole task and
return structured (JSON or NDJSON) output on stdout. Used by the router
to classify tasks without launching a full agent session.
Provided Methods§
Sourcefn extract_text(&self, raw: &str) -> Result<String, AgentError>
fn extract_text(&self, raw: &str) -> Result<String, AgentError>
Extract the raw inner text from an agent output envelope, without
attempting to parse it as an AgentResponse.
Use this in the review pipeline so that a ReviewResponse JSON can be
recovered even when the text doesn’t match the task AgentResponse schema.
- For Claude/Kimi/MiniMax: strips the
--output-format stream-jsonNDJSON wrapper and returns the"result"field of the final"type":"result"line. - For Codex: returns the text of the last
agent_messageitem. - For OpenCode: concatenates all
textevents. - Default: returns
rawunchanged (safe fallback for unknown agents).
Returns Err(AgentError) only for terminal errors (rate limit, auth, etc.)
that should abort the review pipeline entirely.
Sourcefn classify_error_with_elapsed(
&self,
exit_code: i32,
stdout: &str,
stderr: &str,
elapsed_secs: Option<u64>,
) -> AgentError
fn classify_error_with_elapsed( &self, exit_code: i32, stdout: &str, stderr: &str, elapsed_secs: Option<u64>, ) -> AgentError
Classify error with elapsed session time (for accurate timeout reporting).
Sourcefn available_models(&self) -> Vec<String>
fn available_models(&self) -> Vec<String>
Models available for this agent (for intra-agent failover).
Sourcefn free_models(&self) -> Vec<String>
fn free_models(&self) -> Vec<String>
Free/fallback models for last-resort failover.
Sourcefn router_transcript(&self) -> RouterTranscript
fn router_transcript(&self) -> RouterTranscript
Router stdout shape. The router matches on this instead of agent names
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".