pub struct CommonAgentState {
pub system_prompt: String,
pub model: String,
pub root: Option<String>,
pub skip_permissions: bool,
pub output_format: Option<String>,
pub add_dirs: Vec<String>,
pub capture_output: bool,
pub sandbox: Option<SandboxConfig>,
pub max_turns: Option<u32>,
pub env_vars: Vec<(String, String)>,
pub on_spawn_hook: Option<OnSpawnHook>,
}Expand description
Shared configuration state for CLI-based agent providers.
Embed this struct in each provider to avoid duplicating field declarations and trivial setter implementations.
Fields§
§system_prompt: String§model: String§root: Option<String>§skip_permissions: bool§output_format: Option<String>§add_dirs: Vec<String>§capture_output: bool§sandbox: Option<SandboxConfig>§max_turns: Option<u32>§env_vars: Vec<(String, String)>§on_spawn_hook: Option<OnSpawnHook>Optional callback invoked with the OS pid of the spawned agent
subprocess. Threaded through from AgentBuilder::on_spawn /
Agent::set_on_spawn_hook. Providers call
CommonAgentState::notify_spawn right after Command::spawn
so callers can capture the child pid before the terminal wait.
Implementations§
Source§impl CommonAgentState
impl CommonAgentState
pub fn new(default_model: &str) -> Self
Sourcepub fn notify_spawn(&self, child: &Child)
pub fn notify_spawn(&self, child: &Child)
Invoke the registered on_spawn hook with the pid of a freshly
spawned child, if any. Safe to call even when no hook is set.
Sourcepub fn get_base_path(&self) -> &Path
pub fn get_base_path(&self) -> &Path
Get the effective base path (root directory or “.”).
Sourcepub fn make_command(
&self,
binary_name: &str,
agent_args: Vec<String>,
) -> Command
pub fn make_command( &self, binary_name: &str, agent_args: Vec<String>, ) -> Command
Create a Command either directly or wrapped in sandbox.
Standard pattern used by Claude, Copilot, and Gemini. Sets
current_dir, args, and env vars. Providers with custom sandbox
behavior (Codex, Ollama) keep their own make_command().
Sourcepub async fn run_interactive_command(
cmd: &mut Command,
agent_display_name: &str,
) -> Result<()>
pub async fn run_interactive_command( cmd: &mut Command, agent_display_name: &str, ) -> Result<()>
Execute a command interactively (inheriting stdin/stdout/stderr).
Returns ProcessError on non-zero exit.
Sourcepub async fn run_interactive_command_with_hook(
cmd: &mut Command,
agent_display_name: &str,
on_spawn: Option<&OnSpawnHook>,
) -> Result<()>
pub async fn run_interactive_command_with_hook( cmd: &mut Command, agent_display_name: &str, on_spawn: Option<&OnSpawnHook>, ) -> Result<()>
Same as [run_interactive_command], but invokes on_spawn once
with the child’s OS pid right after spawn and before awaiting
the child’s exit — that window is what lets callers register the
child pid with an external process store (e.g. so
zag ps kill self can SIGTERM the agent child rather than the
parent zag process).
Sourcepub async fn run_non_interactive_simple(
&self,
cmd: &mut Command,
agent_display_name: &str,
) -> Result<Option<AgentOutput>>
pub async fn run_non_interactive_simple( &self, cmd: &mut Command, agent_display_name: &str, ) -> Result<Option<AgentOutput>>
Execute a non-interactive command with simple capture-or-passthrough.
If capture_output is set, captures stdout and returns Some(AgentOutput).
Otherwise streams stdout to the terminal and returns None.
Used by Copilot, Gemini, Ollama. Providers with custom output parsing (Claude, Codex) keep their own non-interactive logic.