pub struct CliBackend {
pub command: String,
pub args: Vec<String>,
pub prompt_mode: PromptMode,
pub prompt_flag: Option<String>,
pub output_format: OutputFormat,
pub env_vars: Vec<(String, String)>,
}Expand description
A CLI backend configuration for executing prompts.
Fields§
§command: StringThe command to execute.
args: Vec<String>Additional arguments before the prompt.
prompt_mode: PromptModeHow to pass the prompt.
prompt_flag: Option<String>Argument flag for prompt (if prompt_mode is Arg).
output_format: OutputFormatOutput format emitted by this backend.
env_vars: Vec<(String, String)>Environment variables to set when spawning the process.
Implementations§
Source§impl CliBackend
impl CliBackend
Sourcepub fn from_config(config: &CliConfig) -> Result<Self, CustomBackendError>
pub fn from_config(config: &CliConfig) -> Result<Self, CustomBackendError>
Creates a backend from configuration.
§Errors
Returns CustomBackendError if backend is “custom” but no command is specified.
Sourcepub fn claude() -> Self
pub fn claude() -> Self
Creates the Claude backend.
Uses --print for headless execution and sends the prompt over stdin.
This avoids Claude’s large-prompt -p behavior, which can stall before
emitting any stream output when asked to read the real prompt from an
intermediate temp-file instruction.
Emits --output-format stream-json for NDJSON streaming output.
Note: --verbose is required when using --output-format stream-json.
Sourcepub fn claude_interactive() -> Self
pub fn claude_interactive() -> Self
Creates the Claude backend for interactive prompt injection.
Runs Claude without -p flag, passing prompt as a positional argument.
Used by SOP runner for interactive command injection.
Note: This is NOT for TUI mode - Ralph’s TUI uses the standard claude()
backend. This is for cases where Claude’s interactive mode is needed.
Uses = syntax for --disallowedTools to prevent variadic consumption
of the positional prompt argument.
Sourcepub fn kiro() -> Self
pub fn kiro() -> Self
Creates the Kiro backend.
Uses kiro-cli in headless mode with all tools trusted.
Sourcepub fn kiro_with_agent(agent: String, extra_args: &[String]) -> Self
pub fn kiro_with_agent(agent: String, extra_args: &[String]) -> Self
Creates the Kiro backend with a specific agent and optional extra args.
Uses kiro-cli with –agent flag to select a specific agent.
Sourcepub fn kiro_acp() -> Self
pub fn kiro_acp() -> Self
Creates the Kiro ACP backend.
Uses kiro-cli with the ACP subcommand for structured JSON-RPC communication over stdio instead of PTY text scraping.
Sourcepub fn kiro_acp_with_options(agent: Option<&str>, model: Option<&str>) -> Self
pub fn kiro_acp_with_options(agent: Option<&str>, model: Option<&str>) -> Self
Creates the Kiro ACP backend with an optional agent and/or model.
Sourcepub fn from_name_with_args(
name: &str,
extra_args: &[String],
) -> Result<Self, CustomBackendError>
pub fn from_name_with_args( name: &str, extra_args: &[String], ) -> Result<Self, CustomBackendError>
Creates a backend from a named backend with additional args.
§Errors
Returns error if the backend name is invalid.
Sourcepub fn from_name(name: &str) -> Result<Self, CustomBackendError>
pub fn from_name(name: &str) -> Result<Self, CustomBackendError>
Creates a backend from a named backend string.
§Errors
Returns error if the backend name is invalid.
Sourcepub fn from_hat_backend(
hat_backend: &HatBackend,
) -> Result<Self, CustomBackendError>
pub fn from_hat_backend( hat_backend: &HatBackend, ) -> Result<Self, CustomBackendError>
Creates a backend from a HatBackend configuration.
§Errors
Returns error if the backend configuration is invalid.
Sourcepub fn copilot() -> Self
pub fn copilot() -> Self
Creates the Copilot backend for autonomous mode.
Uses GitHub Copilot CLI with --allow-all-tools for automated tool approval.
Prompt mode emits JSONL via --output-format json for programmatic parsing.
Sourcepub fn copilot_tui() -> Self
pub fn copilot_tui() -> Self
Creates the Copilot TUI backend for interactive mode.
Runs Copilot in full interactive mode (no -p flag), allowing Copilot’s native TUI to render. The prompt is passed as a positional argument.
Sourcepub fn claude_interactive_teams() -> Self
pub fn claude_interactive_teams() -> Self
Creates the Claude interactive backend with Agent Teams support.
Like claude_interactive() but with reduced --disallowedTools (only TodoWrite)
and CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 env var.
Sourcepub fn for_interactive_prompt(
backend_name: &str,
) -> Result<Self, CustomBackendError>
pub fn for_interactive_prompt( backend_name: &str, ) -> Result<Self, CustomBackendError>
Creates a backend configured for interactive mode with initial prompt.
This factory method returns the correct backend configuration for running an interactive session with an initial prompt. The key differences from headless mode are:
| Backend | Interactive + Prompt |
|---|---|
| Claude | positional arg (no -p flag) |
| Kiro | removes --no-interactive |
| Gemini | uses -i instead of -p |
| Codex | no exec subcommand |
| Amp | removes --dangerously-allow-all |
| Copilot | removes --allow-all-tools |
| OpenCode | run subcommand with positional prompt |
§Errors
Returns CustomBackendError if the backend name is not recognized.
Sourcepub fn kiro_interactive() -> Self
pub fn kiro_interactive() -> Self
Kiro in interactive mode (removes –no-interactive).
Unlike headless kiro(), this allows the user to interact with
Kiro’s TUI while still passing an initial prompt.
Sourcepub fn gemini_interactive() -> Self
pub fn gemini_interactive() -> Self
Gemini in interactive mode with initial prompt (uses -i, not -p).
Critical quirk: Gemini requires -i flag for interactive+prompt mode.
Using -p would make it run headless and exit after one response.
Sourcepub fn codex_interactive() -> Self
pub fn codex_interactive() -> Self
Codex in interactive TUI mode (no exec subcommand).
Unlike headless codex(), this runs without exec and --full-auto
flags, allowing interactive TUI mode.
Sourcepub fn amp_interactive() -> Self
pub fn amp_interactive() -> Self
Amp in interactive mode (removes –dangerously-allow-all).
Unlike headless amp(), this runs without the auto-approve flag,
requiring user confirmation for tool usage.
Sourcepub fn copilot_interactive() -> Self
pub fn copilot_interactive() -> Self
Copilot in interactive mode (removes –allow-all-tools).
Unlike headless copilot(), this runs without the auto-approve flag,
requiring user confirmation for tool usage.
Sourcepub fn opencode() -> Self
pub fn opencode() -> Self
Creates the OpenCode backend for autonomous mode.
Uses OpenCode CLI with run subcommand. The prompt is passed as a
positional argument after the subcommand:
opencode run "prompt text here"Output is plain text (no JSON streaming available).
Sourcepub fn opencode_tui() -> Self
pub fn opencode_tui() -> Self
Creates the OpenCode TUI backend for interactive mode.
Runs OpenCode with run subcommand. The prompt is passed as a
positional argument:
opencode run "prompt text here"Sourcepub fn opencode_interactive() -> Self
pub fn opencode_interactive() -> Self
OpenCode in interactive TUI mode.
Runs OpenCode TUI with an initial prompt via --prompt flag:
opencode --prompt "prompt text here"Unlike opencode() which uses opencode run (headless mode),
this launches the interactive TUI and injects the prompt.
Sourcepub fn pi() -> Self
pub fn pi() -> Self
Creates the Pi backend for headless execution.
Uses -p for print mode with --mode json for NDJSON streaming output.
Emits PiStreamJson output format for structured event parsing.
Sourcepub fn pi_interactive() -> Self
pub fn pi_interactive() -> Self
Creates the Pi backend for interactive mode with initial prompt.
Runs pi TUI without -p or --mode json, passing the prompt as a
positional argument. Used by ralph plan for interactive sessions.
Sourcepub fn roo() -> Self
pub fn roo() -> Self
Creates the Roo backend for headless execution.
Uses --print for non-interactive output and --ephemeral for clean
disk state. Prompts are always passed via --prompt-file (handled in
build_command()). Roo auto-approves tools by default, so no
--trust-all-tools equivalent is needed.
Sourcepub fn roo_interactive() -> Self
pub fn roo_interactive() -> Self
Creates the Roo backend for interactive mode with initial prompt.
Runs roo TUI without --print or --ephemeral, passing the prompt
as a positional argument. Used by ralph plan for interactive sessions.
Sourcepub fn custom(config: &CliConfig) -> Result<Self, CustomBackendError>
pub fn custom(config: &CliConfig) -> Result<Self, CustomBackendError>
Creates a custom backend from configuration.
§Errors
Returns CustomBackendError if no command is specified.
Sourcepub fn build_command(
&self,
prompt: &str,
interactive: bool,
) -> (String, Vec<String>, Option<String>, Option<NamedTempFile>)
pub fn build_command( &self, prompt: &str, interactive: bool, ) -> (String, Vec<String>, Option<String>, Option<NamedTempFile>)
Builds the full command with arguments for execution.
§Arguments
prompt- The prompt text to pass to the agentinteractive- Whether to run in interactive mode (affects agent flags)
Trait Implementations§
Source§impl Clone for CliBackend
impl Clone for CliBackend
Source§fn clone(&self) -> CliBackend
fn clone(&self) -> CliBackend
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CliBackend
impl RefUnwindSafe for CliBackend
impl Send for CliBackend
impl Sync for CliBackend
impl Unpin for CliBackend
impl UnsafeUnpin for CliBackend
impl UnwindSafe for CliBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more