adding --ollama

This commit is contained in:
pap
2025-08-04 17:48:06 +01:00
parent dc15a5cf0b
commit 2cfb2a2265
9 changed files with 612 additions and 3 deletions
+6
View File
@@ -14,6 +14,12 @@ pub struct Cli {
#[arg(long, short = 'm')]
pub model: Option<String>,
/// Convenience flag to select the local Ollama provider.
/// Equivalent to -c model_provider=ollama; verifies a local Ollama server is running and
/// creates a model_providers.ollama entry in config.toml if missing.
#[arg(long = "ollama", default_value_t = false)]
pub ollama: bool,
/// Select the sandbox policy to use when executing model-generated shell
/// commands.
#[arg(long = "sandbox", short = 's')]
+15 -1
View File
@@ -35,6 +35,7 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
let Cli {
images,
model,
ollama,
config_profile,
full_auto,
dangerously_bypass_approvals_and_sandbox,
@@ -114,6 +115,15 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
sandbox_mode_cli_arg.map(Into::<SandboxMode>::into)
};
// When the user opts into the Ollama provider via `--ollama`, ensure we
// have a configured provider entry and that a local server is running.
if ollama {
if let Err(e) = codex_core::config::ensure_ollama_provider_configured_and_running().await {
eprintln!("{e}");
std::process::exit(1);
}
}
// Load configuration and determine approval policy
let overrides = ConfigOverrides {
model,
@@ -123,7 +133,11 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
approval_policy: Some(AskForApproval::Never),
sandbox_mode,
cwd: cwd.map(|p| p.canonicalize().unwrap_or(p)),
model_provider: None,
model_provider: if ollama {
Some("ollama".to_string())
} else {
None
},
codex_linux_sandbox_exe,
base_instructions: None,
include_plan_tool: None,