From 5e09595d5533e6926f51817841f16060956c5bba Mon Sep 17 00:00:00 2001 From: Justin John <34035011+justinjohn0306@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:05:57 +0530 Subject: [PATCH] =?UTF-8?q?Let=20Settings=20=E2=86=92=20AI=20choose=20Code?= =?UTF-8?q?x's=20model=20(#2129)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codex now shows the model it uses ("Codex default" until one is chosen) with Change…, like Claude Code (#2109). The choices are its default (no model is passed, so its own settings decide) and the models `codex debug models` lists, in its order, leaving out the ones it hides; over SSH the remote Codex is asked. `ai model Codex` lists and sets them the same way. Until now the model could only be set by adding `cli_model` to config.toml by hand. --- apps/craft-anything-cli/src/ai_cmd.rs | 6 +-- crates/ai/src/cli_agents/adapters.rs | 77 +++++++++++++++++++++++++++ crates/ai/src/lib.rs | 8 +-- crates/ai/src/tests.rs | 7 +++ crates/ui-egui/src/settings_ui.rs | 10 ++-- docs/ROADMAP.md | 3 ++ docs/STATUS.md | 1 + 7 files changed, 100 insertions(+), 12 deletions(-) diff --git a/apps/craft-anything-cli/src/ai_cmd.rs b/apps/craft-anything-cli/src/ai_cmd.rs index f6d0df8d..93aa33b7 100644 --- a/apps/craft-anything-cli/src/ai_cmd.rs +++ b/apps/craft-anything-cli/src/ai_cmd.rs @@ -79,9 +79,9 @@ pub enum AiCommand { /// CLAUDE_CONFIG_DIR), so this AI uses another account: a full path or one under `~/`, on the /// computer it runs on. Leave the path out for its usual folder. Folder { name: String, path: Option }, - /// Set the model an AI uses (Claude Code: the model it's asked for); leave it out to list the - /// ones it can use. `default` for Claude Code passes no `--model`, so it uses the model its own - /// settings name (which may be a custom model), rather than a built-in default. + /// Set the model an AI uses (Claude Code, Codex: the model it's asked for); leave it out to list + /// the ones it can use. `default` for Claude Code or Codex passes no model, so it uses the model + /// its own settings name (which may be a custom model), rather than a built-in default. Model { name: String, model: Option, diff --git a/crates/ai/src/cli_agents/adapters.rs b/crates/ai/src/cli_agents/adapters.rs index ebe63664..3d18026c 100644 --- a/crates/ai/src/cli_agents/adapters.rs +++ b/crates/ai/src/cli_agents/adapters.rs @@ -148,6 +148,11 @@ pub trait AgentAdapter: Send + Sync { fn model_choices(&self, _config: &BackendConfig, _options: &BackendOptions) -> Result, ToolError> { Ok(Vec::new()) } + /// Whether its choices start with `default` ([`crate::anthropic::CLAUDE_CODE_DEFAULT`]): no + /// model is passed, so the agent uses the one its own settings name. + fn offers_own_default(&self) -> bool { + false + } /// Whether this adapter offers context and reasoning controls beyond the model selector. fn supports_model_tuning(&self) -> bool { false @@ -462,6 +467,10 @@ impl AgentAdapter for ClaudeCode { Ok(models) } + fn offers_own_default(&self) -> bool { + true + } + fn args(&self, cx: &ArgsCx) -> Vec { let mut a = cx.options.args.clone(); if cx.question { @@ -891,6 +900,29 @@ impl AgentAdapter for Codex { Some("Run the selected Codex program with `login` in a terminal, choose Sign in with ChatGPT, then test it again in Settings → AI.".into()) } + fn model_in_use(&self, options: Option<&BackendOptions>) -> Option { + Some(options.and_then(|options| options.cli_model.clone()).unwrap_or_else(|| "Codex default".into())) + } + + /// Codex's own catalogue (`codex debug models`): the models it lists rather than hides, after + /// its default (#2109). + fn model_choices(&self, config: &BackendConfig, options: &BackendOptions) -> Result, ToolError> { + let program = super::program_of(config, options)?; + let ask = [program, "debug".into(), "models".into()]; + let p = match config.ssh_host.as_deref().filter(|h| !h.trim().is_empty()) { + Some(h) => Process::new("ssh").args(crate::ssh::ssh_args(h, &ask)), + None => Process::new(&ask[0]).args(&ask[1..]), + }; + let out = p.timeout(Duration::from_secs(15)).stdout_cap(8 * 1024 * 1024).run_checked()?; + let mut models = vec![crate::anthropic::CLAUDE_CODE_DEFAULT.to_string()]; + models.extend(codex_models(&out.stdout_text())); + Ok(models) + } + + fn offers_own_default(&self) -> bool { + true + } + /// `codex exec -` reads the message from stdin, so a long one can't pass Windows' /// command-line limit (os error 206, #528). fn prompt_on_stdin(&self) -> bool { @@ -1020,6 +1052,27 @@ impl AgentAdapter for Codex { } } +/// The models `codex debug models` lists for people to pick (`visibility: "list"`), in its own +/// order (`priority`). Output it can't read lists none, so only the default is offered. +fn codex_models(json: &str) -> Vec { + #[derive(serde::Deserialize)] + struct Catalog { + models: Vec, + } + #[derive(serde::Deserialize)] + struct Entry { + slug: String, + #[serde(default)] + visibility: String, + #[serde(default)] + priority: i64, + } + let Ok(mut c) = serde_json::from_str::(json) else { return Vec::new() }; + c.models.retain(|m| m.visibility == "list" && !m.slug.trim().is_empty()); + c.models.sort_by_key(|m| m.priority); + c.models.into_iter().map(|m| m.slug).collect() +} + /// Unknown output (including future CLI formats) is not a claim that the account is connected. fn codex_login_status(success: bool, stdout: &str, stderr: &str) -> Option { let text = format!("{stdout}\n{stderr}").to_ascii_lowercase(); @@ -1260,6 +1313,30 @@ pub(super) fn remote_failure(host: &str, out: &craft_anything_platform::Output) }) } +#[cfg(test)] +mod codex_model_tests { + use super::{AgentAdapter, Codex, codex_models}; + + /// #2109: Settings offers Codex's listed models in its own order, not the hidden ones, after + /// its default, and shows the default until one is chosen. + #[test] + fn codex_offers_the_models_its_catalogue_lists() { + let json = r#"{"models":[ + {"slug":"hidden-reviewer","visibility":"hide","priority":1}, + {"slug":"second","visibility":"list","priority":4,"display_name":"Second"}, + {"slug":"first","visibility":"list","priority":2}, + {"slug":"","visibility":"list","priority":3} + ]}"#; + assert_eq!(codex_models(json), ["first", "second"]); + assert!(codex_models("not json").is_empty(), "unreadable output lists none: only the default is offered"); + assert!(codex_models(r#"{"models":[{"visibility":"list"}]}"#).is_empty(), "an entry without a slug"); + assert!(Codex.offers_own_default()); + assert_eq!(Codex.model_in_use(None).as_deref(), Some("Codex default")); + let chosen = crate::BackendOptions { cli_model: Some("first".into()), ..Default::default() }; + assert_eq!(Codex.model_in_use(Some(&chosen)).as_deref(), Some("first")); + } +} + #[cfg(test)] mod codex_login_tests { use super::codex_login_status; diff --git a/crates/ai/src/lib.rs b/crates/ai/src/lib.rs index 04e9a1e8..b8e29391 100644 --- a/crates/ai/src/lib.rs +++ b/crates/ai/src/lib.rs @@ -807,10 +807,10 @@ impl AiHub { let Some(b) = cfg.backends.iter_mut().find(|b| b.config.name == name) else { return Ok(false) }; match b.config.kind { BackendKind::AgentCli => { - // Ask the adapter, not the id: Claude Code is also saved as `claude`, and both must - // mean "no --model" when the choice is the default. - let claude_code = cli_agents::adapter_for(&b.config.model).ids().contains(&"claude-code"); - let clear = claude_code && model == crate::anthropic::CLAUDE_CODE_DEFAULT; + // Ask the adapter, not the id: Claude Code is also saved as `claude`, and both, like + // Codex, must mean "no model passed" when the choice is the default. + let own_default = cli_agents::adapter_for(&b.config.model).offers_own_default(); + let clear = own_default && model == crate::anthropic::CLAUDE_CODE_DEFAULT; if model_options::supported(&b.config) && (clear || b.options.cli_model.as_deref() != Some(model)) { b.options.cli_context = None; b.options.cli_reasoning_effort = None; diff --git a/crates/ai/src/tests.rs b/crates/ai/src/tests.rs index f73dbd9e..2d88a7eb 100644 --- a/crates/ai/src/tests.rs +++ b/crates/ai/src/tests.rs @@ -665,6 +665,13 @@ fn an_ais_model_is_changed() { assert_eq!(h.options().get("Claude Code").and_then(|o| o.cli_model.clone()), None); assert!(!h.set_model("Nobody", "m").unwrap()); assert!(h.set_model("Box", " ").is_err()); + // #2109: Codex takes a model the same way, and its default clears it, so no -m is passed. + let codex = BackendConfig { name: "Codex".into(), kind: BackendKind::AgentCli, model: "codex".into(), base_url: None, ssh_host: None, enabled: true }; + h.add_backend(codex, None).unwrap(); + assert!(h.set_model("Codex", "first").unwrap()); + assert_eq!(h.options().get("Codex").and_then(|o| o.cli_model.clone()).as_deref(), Some("first")); + assert!(h.set_model("Codex", crate::anthropic::CLAUDE_CODE_DEFAULT).unwrap()); + assert_eq!(h.options().get("Codex").and_then(|o| o.cli_model.clone()), None); // The Claude Code adapter is also registered as `claude`; the default must clear for that id // too, or a run would pass `--model default` (#470 review). diff --git a/crates/ui-egui/src/settings_ui.rs b/crates/ui-egui/src/settings_ui.rs index b68e3a2f..b902844f 100644 --- a/crates/ui-egui/src/settings_ui.rs +++ b/crates/ui-egui/src/settings_ui.rs @@ -552,13 +552,13 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) { ui.label(RichText::new(tr("Asking for its models…")).color(t.text_faint).size(theme::CAPTION)); } Some((_, Some(models))) => { - // Claude Code with no choice saved passes no `--model`, so it uses - // the model its own settings name: `default` is what's shown. An + // Claude Code or Codex with no choice saved passes no model, so it + // uses the one its own settings name: `default` is what's shown. An // API backend's model is its saved `config.model`. - let claude_code = - b.kind == BackendKind::AgentCli && craft_anything_ai::cli_agents::adapter_for(&b.model).ids().contains(&"claude-code"); + let own_default = + b.kind == BackendKind::AgentCli && craft_anything_ai::cli_agents::adapter_for(&b.model).offers_own_default(); let picked = app.backend_options.get(&b.name).and_then(|o| o.cli_model.clone()).unwrap_or_else(|| { - if claude_code { craft_anything_ai::anthropic::CLAUDE_CODE_DEFAULT.to_string() } else { b.model.clone() } + if own_default { craft_anything_ai::anthropic::CLAUDE_CODE_DEFAULT.to_string() } else { b.model.clone() } }); let shown = |m: &str| { if m == craft_anything_ai::anthropic::CLAUDE_CODE_DEFAULT { diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 4183dbfd..dc0cca4d 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -1038,6 +1038,9 @@ Owner: open · Status: in progress document functions touched by the OpenCode model-selection changes. - [x] Integrate the five-level `Effort` type from #395 for agent variants, and share a strict disk-based selection save between the hub and headless tools, preserving unrelated edits. +- [x] Settings → AI offers no model choice for Codex, so its model can only be set by editing + config.toml (#2109): offer Codex's own listed models (`codex debug models`) and its default + — claimed: justinjohn0306, branch bugfix/r2.2-codex-model-picker - [x] Rebase onto main after #395's squash merge, preserve extra model arguments without a saved selection, and render the remote-host placeholder visibly in the setup instructions. - [x] Hold the UI settings worker's session guard through its disk save so it cannot overwrite diff --git a/docs/STATUS.md b/docs/STATUS.md index 55a71006..415b19ad 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -459,6 +459,7 @@ coverage and secrets passed. The companion CLI was built with locked dependencie | Auto mode | Settings → Safety, on by default. Builder actions go ahead without asking, except a fixed set that is never done unasked (deleting outside the project, system changes, publishing…); questions get "decide yourself"; asset spending stops at the budget. Each project can choose allow, ask or refuse per kind of action instead (`project_approvals_set`, the Approvals menu under the prompt box, or `/approvals publish ask`; read-only `gh … view`/`list` count as commands, not publishing) | Unit tests, UI tests; not tried in a live build | | Generated assets | Off until the person turns them on for a game (the switch on Make and on the project, `project_assets_allow`, `rebuild --generate-assets`, saved in craft.json; turning it on without a fal.ai key asks for one); the brief and the asset tools need both that and a key. `assets_image_generate` (Nano Banana Pro by default) and `assets_model_generate` (picture → Tripo P1 low-poly GLB with a face limit) through the person's key for each asset provider (fal.ai today), with agent apps and API-key builds alike; per-project budget, $5 by default (`[assets] budget_usd` in config.toml); models and prices from the `assets.toml` table (picture model selectable: Nano Banana Pro, FLUX dev or schnell; priced per picture or per megapixel); every call reports its cost | Unit tests; a live 3D generation with a real key (picture, then model) with FLUX dev; Nano Banana Pro not yet run with a real key; an API-key build not yet run with one | | Claude Code builder | Runs the person's own `claude` in headless mode (no `--model` by default, so the model its own settings name applies, custom ones included; a built-in Claude model can be picked instead; high effort unless configured) with our MCP server, a permission-prompt tool and `core_person_ask`; preflights for our CLI (a build stops plainly if it's missing or won't start) and sign-in | Argument and stream-parser tests; live preflight; live builder turns; see [claude-code.md](claude-code.md) | +| Codex model choice | Settings → AI shows the model Codex uses ("Codex default" until one is chosen) with Change…; the choices are Default (its own settings, no `-m`) and the models `codex debug models` lists (not the hidden ones), in its order, over SSH too. `ai model Codex` lists and sets them (#2109) | Unit-tested; listed live with codex-cli 0.163.0 on Windows 11 (default plus three models); a build with a chosen model not run | | DeepSeek Harness builder | Runs the person's own `dsh --profile headless` with the preamble and task on stdin, which answers one task and prints its last message as text. The harness takes its tool servers from profile patch layers and has no per-run flag for one, so our tool server arrives as a generated `--patch` overlay for that run (the run's project, inbox and mode included), under a server name of its own so it doesn't clash with a `craft-anything` entry the person registered; the person's own profile is untouched, a question gets no tool server, and its headless profile keeps no session to resume. Standard npm shims are unwrapped to their interpreter; the desktop app's custom `.cmd` launcher receives only options, avoiding batch newline and command-line length limits. Requires a headless profile with stdin support (0.2.2-rc.1 verified); older versions without it reject the missing task and need updating | Adapter and YAML-overlay tests; live preflight (`ai test`); live builder turns on a website (follow-up build, 3 min 10 s, 100% alike at 1440/768/390 px, Ready) where the builder's own journal entries show `rebuild_check`, `core_unknown_add`, `core_plan_update` and `core_handoff_write` going through our tool server, and that server started with the run's `--project`/`--inbox`. Not checked: resume (none exists) and a build with the harness's desktop profile. Also verified on macOS arm64 (2026-11-07, DSH 0.2.2-rc.1, stored sign-in restored for the headless profile as its README describes): a static website reached Ready with one check pass, and the builder called our MCP tools after renaming a pre-existing `craft-anything` MCP registration to avoid the generated overlay's matching `serverName`; Windows (2026-11-07): the new batch-launch regression failed with the reported startup error before the fix and then passed, including exact UTF-8 and 40,831-character task delivery. A patched Craft CLI chat through the official desktop `dsh.cmd` returned the expected answer with a local authentication overlay; no new GUI or full rebuild run was performed | | Aider builder | Runs the person's own `aider --message-file `, one message per run: the message is written to a private file in the temp folder and removed after the run, so a long one passes Windows' command-line limit (#402); over SSH it still goes in `--message`. Flags stop it asking or acting on its own: no git repository or `.gitignore` change, no update check or release notes, no analytics, Playwright, URL or shell-suggestion prompt, no model-warning page, and plain output. `BROWSER` points at a command that does nothing, so no page can open from a run. Before a run it refuses when no model or key is set up, or an OpenRouter model has no OpenRouter key: both would offer a sign-in and wait five minutes for a browser nobody is at (#72). That check reads Aider's settings (`.aider.conf.yml`, `.env`) where Aider does: in the folder the run starts in (links resolved), at the top of its git repository (a `.git` file, or a `.git` folder with `HEAD`, as GitPython finds it) and in the home folder, plus an `--env-file` from its arguments; the one Aider loads last wins, and a `.env` wins over the environment, as Aider loads it over the environment. An empty `KEY=` in a later file doesn't clear a key set in an earlier one, and `--config` isn't read. Its arguments count `--api-key`, `--set-env` and Aider's dedicated `---api-key` flags; config key lists may be block or flow style. Over SSH the bounded preflight checks the remote environment and home settings, plus a named `--env-file` when supplied. Only the two definite answers refuse (no model or key, or an OpenRouter model without its key); any other check failure is logged and the run starts, so a host without `awk`/`wc`, an unreadable file, or no POSIX `sh` fails later with ssh's or Aider's own error. It sets `BROWSER=true` on the SSH host. Outside a build `--dry-run` keeps a chat from writing files. Aider gets no tool server, and its own reads can't be checked, so a Clean room run is refused (R2.2). A failed flag check keeps this adapter: Aider's plain form reads the message as a file name | Argument, registration and setup-refusal tests, including settings in the project folder, the git repository's top and which file wins (from Aider's `main.py`; not run against a real Aider). Ran Aider 0.86.2 with these exact arguments: no prompt, no browser, reached the model call; the no-model and OpenRouter cases were reproduced (each waited for the sign-in) and are now refused before the run, and also at a real build start with the key unset. Live build (2026-11-07, Linux, Aider 0.86.2 through `rebuild --backend Aider --unattended`, one round, free `nvidia/nemotron-3-ultra-550b-a55b:free` through OpenRouter): a static site reached Ready in about 66 s with four files written in `app/`, no question waited and no browser opened; the file-creation questions took their default on closed stdin. The page only shows an alert where the request asked for a colour change, so the output was not judged. An earlier try with `cohere/north-mini-code:free` looped, wrote nothing and stopped after two turns, and Aider offered to open a help page that opened nothing. Aider reports no token counts, so usage shows 0. Not checked: a stronger or paid model, resume, Windows, macOS. `--message-file` (2026-11-15, Windows 11, Aider 0.86.2, these flags): a 40,000-character file was read and the run went on to the model call; no build was run on Windows. Remote setup regressions run the on-host script with a fixture HOME and cleared environment: absent settings, an unreadable settings file, a host-exported key or model, a saved OpenRouter key, `.env`, a quoted `--env-file`, the last assignment in one dotenv file, and no credentials on the command line. A pre-stopped run returns Cancelled before ssh starts. Only the two definite answers (10 and 11) refuse; 12, 13 and other codes log and proceed. | | GitHub Copilot | Installed `copilot` through ACP by default, with CLI-owned login (no credential import), explicit Craft Anything MCP tool allowlist, model selection and fresh read-only build questions. Target handoff retains the last 128 entries with the active target last; context discovery respects tool cancellation and shared picker warnings name the agent | Authenticated builds, model discovery and real-account session resume confirmed by the person using the app. Target-boundary, cancellation and agent-warning regressions supplement unit tests and an offline CLI 1.0.105 compatibility test covering all five access modes. See [copilot.md](copilot.md) |