use crate::core::{
agent_launch_config::{self, Launch},
agent_runtime::TerminalAgent,
};
use anyhow::{Context, Result};
use portable_pty::CommandBuilder;
use std::path::Path;
pub fn prepare_native_task_scheme(
cwd: &Path,
agent: TerminalAgent,
prompt: Option<&str>,
scheme_id: Option<&str>,
) -> Result<CommandBuilder> {
let mut launch = agent_launch_config::resolve_scheme(agent.kind(), scheme_id)?;
launch.arguments = native_prompt::arguments(&launch, prompt)?;
let mut command = terminal_command(&launch, cwd)?;
if matches!(agent, TerminalAgent::ClaudeTeams) {
command.env("CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS", "1");
}
Ok(command)
}
pub fn terminal_command(launch: &Launch, cwd: &Path) -> Result<portable_pty::CommandBuilder> {
let program = crate::core::tool_detection::resolve_program(&launch.program, cwd)
.context("Configured Agent executable is unavailable; check its launch instruction")?;
let mut command = portable_pty::CommandBuilder::new(program);
command.args(&launch.arguments);
command.cwd(cwd);
command.env("TERM", "xterm-256color");
command.env("COLORTERM", "truecolor");
for name in crate::core::agent_runtime::INHERITED_CONTEXT {
command.env_remove(name);
}
Ok(command)
}
pub mod external_terminal;
#[cfg(feature = "herdr")]
pub(crate) use native_prompt::arguments as initial_task_arguments;
mod native_prompt;