agent_abstraction/model.rs
1//! Which models each agent offers, so a host can render a picker.
2//!
3//! The catalogue is **advisory and never enforced**. [`crate::Request::model`]
4//! takes any string and this crate does not check it against anything here. A
5//! model that shipped this morning must not be blocked by a list compiled last
6//! month, and a picked model the account cannot reach fails as
7//! [`crate::Error::AgentError`] carrying the provider's own status and wording.
8//! Enforcing the list would trade a clear runtime error for a wrong compile-time
9//! one.
10//!
11//! # A catalogue is not an entitlement
12//!
13//! What an agent *offers* and what an account may *use* are different sets, and
14//! only the account knows the second one. On a Copilot Free plan the picker
15//! lists twenty-three models and permits exactly one:
16//!
17//! ```text
18//! Your Copilot Free plan currently includes only Auto, which automatically
19//! selects the best available model for each task.
20//! ```
21//!
22//! Every other id there is rejected before a request is made, including
23//! `gpt-5.4`, the example in Copilot's own `--help`. So a host should present
24//! this list as choices to try, not as promises, and let the run report what the
25//! account actually allows. [`Model::is_default`] marks the one an agent falls
26//! back to, which is the safe pre-selection.
27//!
28//! # Where the entries come from
29//!
30//! [`Agent::models`] is a compiled-in list with its provenance recorded in
31//! [`Agent::models_verified`], because two of the three agents cannot be asked.
32//! [`Agent::discover_models`] asks the CLI itself where that is possible, and
33//! returns [`crate::Error::Unsupported`] where it is not, rather than quietly
34//! handing back the compiled list under a name that promises freshness.
35
36use std::borrow::Cow;
37
38use serde::{Deserialize, Serialize};
39use serde_json::Value;
40
41use crate::agent::Agent;
42use crate::error::{Error, Result};
43
44/// Whether an id names a specific model or points at whichever is current.
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
46#[serde(rename_all = "snake_case")]
47#[non_exhaustive]
48pub enum Kind {
49 /// Resolves to whatever is newest in a family, so it survives a release.
50 /// Claude's `opus` and Copilot's `auto` are both this.
51 Alias,
52 /// Names one model. Reproducible, and goes stale on its own schedule.
53 Pinned,
54}
55
56/// One model a caller can choose.
57#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
58#[non_exhaustive]
59pub struct Model {
60 /// Exactly what goes to `--model`. Passed through verbatim.
61 pub id: Cow<'static, str>,
62 /// The vendor's own display name, for a picker.
63 pub name: Cow<'static, str>,
64 /// One line on what it is for. Empty when the vendor offers none.
65 pub note: Cow<'static, str>,
66 /// Whether the id tracks a family or names one model.
67 pub kind: Kind,
68 /// Reasoning levels this model accepts, in the vendor's order, for
69 /// [`crate::Request::effort`].
70 ///
71 /// Kept as strings for the same reason ids are, and the three agents make
72 /// the case on their own: Claude documents five levels, Copilot seven, and
73 /// Codex varies them per model, offering `ultra` on its two frontier models
74 /// and not on the rest. A shared enum would have to be edited before a new
75 /// level could even be named.
76 ///
77 /// Empty means a picker has nothing to offer for this model. That covers
78 /// two cases, and the catalogue comments say which applies: the model
79 /// genuinely accepts no level, as Copilot's `auto` does, or the levels are
80 /// simply not established here. Neither is a promise that a level would be
81 /// refused, since nothing in this crate validates against it.
82 pub efforts: Vec<Cow<'static, str>>,
83 /// Whether the agent uses this when the caller names no model.
84 pub is_default: bool,
85}
86
87impl Model {
88 /// Build a catalogue entry from static parts.
89 fn new(
90 id: &'static str,
91 name: &'static str,
92 note: &'static str,
93 kind: Kind,
94 efforts: &[&'static str],
95 is_default: bool,
96 ) -> Model {
97 Model {
98 id: Cow::Borrowed(id),
99 name: Cow::Borrowed(name),
100 note: Cow::Borrowed(note),
101 kind,
102 efforts: efforts.iter().map(|e| Cow::Borrowed(*e)).collect(),
103 is_default,
104 }
105 }
106}
107
108/// How a catalogue was established, so a stale one can be recognised as stale.
109///
110/// Recorded rather than described in prose because the entries below were
111/// gathered three different ways, and the weakest of them is the one a reader
112/// most needs to know about.
113#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
114#[non_exhaustive]
115pub struct Verified {
116 /// Where the list came from.
117 pub source: Source,
118 /// ISO date it was last checked.
119 pub checked: &'static str,
120 /// The CLI release it was checked against.
121 pub against: &'static str,
122}
123
124/// The kind of evidence behind a catalogue.
125#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
126#[serde(rename_all = "snake_case")]
127#[non_exhaustive]
128pub enum Source {
129 /// The CLI itself reported it, and can be asked again at runtime. The
130 /// strongest of the three: it cannot drift without the CLI changing.
131 Cli,
132 /// Read out of the CLI's interactive picker. Accurate when taken, but there
133 /// is no way to re-read it without a terminal, so it ages silently.
134 Picker,
135 /// Taken from vendor documentation. Weakest: it describes the product
136 /// rather than the installed binary, and says nothing about entitlement.
137 Docs,
138}
139
140impl Agent {
141 /// The models this agent offers, best first.
142 ///
143 /// Advisory: this is not enforced, and it does not tell you what an account
144 /// may actually use. See [`Model`] and [`Agent::models_verified`].
145 #[must_use]
146 pub fn models(&self) -> Vec<Model> {
147 match self {
148 Agent::Claude => claude_models(),
149 Agent::Codex => codex_models(),
150 Agent::Copilot => copilot_models(),
151 }
152 }
153
154 /// How this agent's compiled-in catalogue was established, and when.
155 #[must_use]
156 pub fn models_verified(&self) -> Verified {
157 match self {
158 // Mixed: the five aliases were read from the `/model` picker, but
159 // the pinned ids and the `best` / `opusplan` / `[1m]` entries come
160 // from documentation. `source` records the weakest evidence behind
161 // any entry, since that is the one a reader needs to distrust.
162 Agent::Claude => Verified {
163 source: Source::Docs,
164 checked: "2026-07-29",
165 against: "claude 2.1.212",
166 },
167 Agent::Codex => Verified {
168 source: Source::Cli,
169 checked: "2026-07-29",
170 against: "codex-cli 0.145.0",
171 },
172 // Read from the `/model` picker. Copilot has no headless list; see
173 // `discover_models`.
174 Agent::Copilot => Verified {
175 source: Source::Picker,
176 checked: "2026-07-29",
177 against: "Copilot CLI 1.0.75",
178 },
179 }
180 }
181
182 /// Ask the installed CLI what models it has, rather than trusting the
183 /// compiled-in list.
184 ///
185 /// Worth preferring wherever it works: it reflects the binary actually
186 /// present instead of the one this crate was written against.
187 ///
188 /// # Errors
189 /// [`Error::Unsupported`] on an agent with no headless way to answer, which
190 /// today is Claude and Copilot. That is deliberately an error rather than a
191 /// silent fall back to [`Agent::models`]: a caller asking for discovery is
192 /// asking for freshness, and handing back a compiled list without saying so
193 /// answers a question they did not ask. [`Error::NotInstalled`] if the
194 /// binary is missing, [`Error::Spawn`] if it cannot be run, and
195 /// [`Error::Parse`] if its output is not the expected shape.
196 pub async fn discover_models(&self) -> Result<Vec<Model>> {
197 match self {
198 Agent::Codex => discover_codex(self.bin()).await,
199 // Neither can be asked without a terminal, verified against
200 // Copilot CLI 1.0.75 and claude 2.1.212. Copilot has no `models`
201 // subcommand, rejects an unknown `--model` without listing the valid
202 // ones, and its ACP `session/new` reply carries session modes and
203 // permissions but no models. Claude documents its aliases in
204 // `--help` but has no subcommand that enumerates them. In both the
205 // interactive `/model` picker is the only listing.
206 Agent::Claude | Agent::Copilot => Err(Error::Unsupported {
207 agent: *self,
208 what: "listing models without a terminal",
209 }),
210 }
211 }
212}
213
214/// Claude, aliases first.
215///
216/// The aliases are the better picker entries and are listed first for that
217/// reason: they resolve to whatever is current, so they survive a model release
218/// and respect what the account is entitled to, which a pinned id does neither
219/// of. Pinned ids follow for a caller who needs one exact model.
220///
221/// Verified against claude 2.1.212 (`--help`) and the published model list,
222/// 2026-07-29.
223/// Claude's effort levels, verified from `claude --help` on 2.1.212:
224/// `--effort <level>` (low, medium, high, xhigh, max).
225///
226/// Session-level rather than per-model, so every entry carries the same set:
227/// `--help` does not vary the choices by model, and a picker reading
228/// [`Model::efforts`] for the selected model gets the right answer either way.
229const CLAUDE_EFFORTS: &[&str] = &["low", "medium", "high", "xhigh", "max"];
230
231fn claude_models() -> Vec<Model> {
232 let mut models = claude_aliases();
233 models.extend(claude_pinned());
234 models
235}
236
237/// The aliases, which are what the `/model` picker offers.
238fn claude_aliases() -> Vec<Model> {
239 vec![
240 Model::new(
241 "default",
242 "Default",
243 "Whatever is recommended for this account, or the organization default",
244 Kind::Alias,
245 CLAUDE_EFFORTS,
246 true,
247 ),
248 Model::new(
249 "opus",
250 "Opus",
251 "Latest Opus, for complex reasoning",
252 Kind::Alias,
253 CLAUDE_EFFORTS,
254 false,
255 ),
256 Model::new(
257 "sonnet",
258 "Sonnet",
259 "Latest Sonnet, for daily coding",
260 Kind::Alias,
261 CLAUDE_EFFORTS,
262 false,
263 ),
264 Model::new(
265 "haiku",
266 "Haiku",
267 "Fast and efficient, for simple tasks",
268 Kind::Alias,
269 CLAUDE_EFFORTS,
270 false,
271 ),
272 Model::new(
273 "fable",
274 "Fable",
275 "For the hardest and longest-running tasks",
276 Kind::Alias,
277 CLAUDE_EFFORTS,
278 false,
279 ),
280 Model::new(
281 "best",
282 "Best available",
283 "Fable where the organization has it, otherwise the latest Opus",
284 Kind::Alias,
285 CLAUDE_EFFORTS,
286 false,
287 ),
288 // Not models. Accepted by `--model` and offered here for that reason,
289 // but a picker that shows them beside the rest will mislead: one swaps
290 // model mid-session and the others only widen the context window.
291 Model::new(
292 "opusplan",
293 "Opus, then Sonnet",
294 "Opus while planning, Sonnet to execute (a mode, not a model)",
295 Kind::Alias,
296 CLAUDE_EFFORTS,
297 false,
298 ),
299 Model::new(
300 "opus[1m]",
301 "Opus (1M context)",
302 "Opus with a 1M token context window (a variant, not a model)",
303 Kind::Alias,
304 CLAUDE_EFFORTS,
305 false,
306 ),
307 Model::new(
308 "sonnet[1m]",
309 "Sonnet (1M context)",
310 "Sonnet with a 1M token context window (a variant, not a model)",
311 Kind::Alias,
312 CLAUDE_EFFORTS,
313 false,
314 ),
315 ]
316}
317
318/// Pinned ids, which the picker does not list at all.
319///
320/// Its own subtitle says so: "For other/previous model names, specify with
321/// `--model`". They are still worth carrying, because an alias and a pinned id
322/// do not always agree. Verified on 2026-07-29 against claude 2.1.212 by running
323/// both: `--model opus` reported `claude-opus-4-8` in its usage while
324/// `--model claude-opus-5` reported `claude-opus-5`, even though that release's
325/// own notes call Opus 5 "now the default Opus model". An alias is whatever the
326/// account resolves it to, which is not always the newest model.
327fn claude_pinned() -> Vec<Model> {
328 vec![
329 Model::new(
330 "claude-opus-5",
331 "Claude Opus 5",
332 "For complex agentic coding and enterprise work",
333 Kind::Pinned,
334 CLAUDE_EFFORTS,
335 false,
336 ),
337 Model::new(
338 "claude-sonnet-5",
339 "Claude Sonnet 5",
340 "The best combination of speed and intelligence",
341 Kind::Pinned,
342 CLAUDE_EFFORTS,
343 false,
344 ),
345 Model::new(
346 "claude-fable-5",
347 "Claude Fable 5",
348 "Next-generation intelligence for long-running agents",
349 Kind::Pinned,
350 CLAUDE_EFFORTS,
351 false,
352 ),
353 Model::new(
354 "claude-haiku-4-5",
355 "Claude Haiku 4.5",
356 "The fastest model with near-frontier intelligence",
357 Kind::Pinned,
358 CLAUDE_EFFORTS,
359 false,
360 ),
361 ]
362}
363
364/// Codex, in the priority order the CLI itself reports.
365///
366/// Verified by running `codex debug models` against codex-cli 0.145.0 on
367/// 2026-07-29. `codex-auto-review` is reported with `visibility: "hide"` and is
368/// left out for that reason; [`discover_codex`] applies the same filter.
369fn codex_models() -> Vec<Model> {
370 const FULL: &[&str] = &["low", "medium", "high", "xhigh", "max", "ultra"];
371 const TO_MAX: &[&str] = &["low", "medium", "high", "xhigh", "max"];
372 const TO_XHIGH: &[&str] = &["low", "medium", "high", "xhigh"];
373 vec![
374 Model::new(
375 "gpt-5.6-sol",
376 "GPT-5.6-Sol",
377 "Latest frontier agentic coding model.",
378 Kind::Pinned,
379 FULL,
380 true,
381 ),
382 Model::new(
383 "gpt-5.6-terra",
384 "GPT-5.6-Terra",
385 "Balanced agentic coding model for everyday work.",
386 Kind::Pinned,
387 FULL,
388 false,
389 ),
390 Model::new(
391 "gpt-5.6-luna",
392 "GPT-5.6-Luna",
393 "Fast and affordable agentic coding model.",
394 Kind::Pinned,
395 TO_MAX,
396 false,
397 ),
398 Model::new(
399 "gpt-5.5",
400 "GPT-5.5",
401 "Frontier model for complex coding, research, and real-world tasks.",
402 Kind::Pinned,
403 TO_XHIGH,
404 false,
405 ),
406 Model::new(
407 "gpt-5.4",
408 "GPT-5.4",
409 "Strong model for everyday coding.",
410 Kind::Pinned,
411 TO_XHIGH,
412 false,
413 ),
414 Model::new(
415 "gpt-5.4-mini",
416 "GPT-5.4-Mini",
417 "Small, fast, and cost-efficient model for simpler coding tasks.",
418 Kind::Pinned,
419 TO_XHIGH,
420 false,
421 ),
422 ]
423}
424
425/// Copilot, in the order its `/model` picker lists them.
426///
427/// Read from the interactive picker on Copilot CLI 1.0.75, 2026-07-29, because
428/// nothing else enumerates them. Note that the picker lists every model the
429/// product has, not every model the account may use: the same screen carried
430/// "Your Copilot Free plan currently includes only Auto", and on that plan every
431/// id below except `auto` is refused before a request is made.
432/// Copilot's effort levels, verified from `copilot --help` on 1.0.75:
433/// `--effort, --reasoning-effort <level>` (none, minimal, low, medium, high,
434/// xhigh, max).
435///
436/// Two levels wider than Claude's at the bottom, which is why levels are passed
437/// through rather than mapped onto a shared enum.
438///
439/// Applied to the pinned models only. `auto` rejects the flag outright, so
440/// support is not uniform across an agent even when `--help` lists one set, and
441/// these came from `--help` rather than from running each model: a Free plan
442/// permits only `auto`, so there was no way to confirm the rest.
443const COPILOT_EFFORTS: &[&str] = &["none", "minimal", "low", "medium", "high", "xhigh", "max"];
444
445fn copilot_models() -> Vec<Model> {
446 vec![
447 Model::new(
448 "auto",
449 "Auto",
450 "Copilot picks the best available model for each task",
451 Kind::Alias,
452 // Deliberately none. Verified on Copilot CLI 1.0.75 by running it:
453 // Error: Model "auto" does not support reasoning effort
454 // configuration (requested: "low").
455 // It exits 1 rather than ignoring the flag, so offering a level for
456 // `auto` in a picker produces a failed run, not a slower one.
457 &[],
458 true,
459 ),
460 pinned("claude-sonnet-5", "Claude Sonnet 5"),
461 pinned("claude-sonnet-4.6", "Claude Sonnet 4.6"),
462 pinned("claude-sonnet-4.5", "Claude Sonnet 4.5"),
463 pinned("claude-haiku-4.5", "Claude Haiku 4.5"),
464 pinned("claude-fable-5", "Claude Fable 5"),
465 pinned("claude-opus-5", "Claude Opus 5"),
466 pinned("claude-opus-4.8", "Claude Opus 4.8"),
467 pinned("claude-opus-4.8-fast", "Claude Opus 4.8 (fast)"),
468 pinned("claude-opus-4.7", "Claude Opus 4.7"),
469 pinned("claude-opus-4.6", "Claude Opus 4.6"),
470 pinned("claude-opus-4.5", "Claude Opus 4.5"),
471 pinned("gpt-5.6-sol", "GPT-5.6-Sol"),
472 pinned("gpt-5.6-terra", "GPT-5.6-Terra"),
473 pinned("gpt-5.6-luna", "GPT-5.6-Luna"),
474 pinned("gpt-5.5", "GPT-5.5"),
475 pinned("gpt-5.4", "GPT-5.4"),
476 pinned("gpt-5.3-codex", "GPT-5.3-Codex"),
477 pinned("gpt-5.4-mini", "GPT-5.4-Mini"),
478 pinned("gpt-5-mini", "GPT-5 mini"),
479 pinned("gemini-3.1-pro-preview", "Gemini 3.1 Pro (preview)"),
480 pinned("gemini-3.6-flash", "Gemini 3.6 Flash"),
481 pinned("gemini-3.5-flash", "Gemini 3.5 Flash"),
482 pinned("kimi-k2.7-code", "Kimi K2.7 Code"),
483 ]
484}
485
486/// A pinned entry with no vendor description, which is every Copilot model: its
487/// picker shows ids and nothing else.
488fn pinned(id: &'static str, name: &'static str) -> Model {
489 Model::new(id, name, "", Kind::Pinned, COPILOT_EFFORTS, false)
490}
491
492/// Read Codex's own model list.
493///
494/// `codex debug models` prints one JSON document carrying every model plus each
495/// one's full system prompt, so the reply runs to hundreds of kilobytes. Only
496/// the descriptive fields are kept.
497async fn discover_codex(bin: &str) -> Result<Vec<Model>> {
498 let output = tokio::process::Command::new(bin)
499 .args(["debug", "models"])
500 .output()
501 .await
502 .map_err(|source| {
503 if source.kind() == std::io::ErrorKind::NotFound {
504 Error::NotInstalled {
505 agent: Agent::Codex,
506 bin: bin.to_string(),
507 hint: Agent::Codex.install_hint(),
508 }
509 } else {
510 Error::Spawn {
511 bin: bin.to_string(),
512 source,
513 }
514 }
515 })?;
516
517 let stdout = String::from_utf8_lossy(&output.stdout);
518 parse_codex_models(&stdout)
519}
520
521/// Turn `codex debug models` output into catalogue entries.
522///
523/// Split from the spawn so the shape can be tested without a subprocess.
524fn parse_codex_models(stdout: &str) -> Result<Vec<Model>> {
525 let value: Value = serde_json::from_str(stdout.trim()).map_err(|e| Error::Parse {
526 agent: Agent::Codex,
527 detail: format!("`codex debug models` did not return JSON: {e}"),
528 })?;
529 let listed = value
530 .get("models")
531 .and_then(Value::as_array)
532 .ok_or_else(|| Error::Parse {
533 agent: Agent::Codex,
534 detail: "`codex debug models` returned no `models` array".into(),
535 })?;
536
537 // `priority` is the vendor's own display order and is not the array order,
538 // so it is read rather than assumed.
539 let mut ranked: Vec<(u64, Model)> = listed
540 .iter()
541 // `visibility` is how Codex marks its internal models, and
542 // `codex-auto-review` is one. Offering it in a picker hands a user a
543 // model the vendor deliberately withheld.
544 .filter(|m| m.get("visibility").and_then(Value::as_str) != Some("hide"))
545 .filter_map(|m| {
546 let id = m.get("slug").and_then(Value::as_str)?;
547 let model = Model {
548 id: id.to_string().into(),
549 name: m
550 .get("display_name")
551 .and_then(Value::as_str)
552 .unwrap_or(id)
553 .to_string()
554 .into(),
555 note: m
556 .get("description")
557 .and_then(Value::as_str)
558 .unwrap_or_default()
559 .to_string()
560 .into(),
561 kind: Kind::Pinned,
562 efforts: m
563 .get("supported_reasoning_levels")
564 .and_then(Value::as_array)
565 .map(|levels| {
566 levels
567 .iter()
568 .filter_map(|l| l.get("effort").and_then(Value::as_str))
569 .map(|e| Cow::Owned(e.to_string()))
570 .collect()
571 })
572 .unwrap_or_default(),
573 // Codex names a default reasoning level per model but never a
574 // default model, so the top of its own ordering stands in.
575 is_default: false,
576 };
577 let priority = m
578 .get("priority")
579 .and_then(Value::as_u64)
580 .unwrap_or(u64::MAX);
581 Some((priority, model))
582 })
583 .collect();
584
585 if ranked.is_empty() {
586 return Err(Error::Parse {
587 agent: Agent::Codex,
588 detail: "`codex debug models` listed no visible models".into(),
589 });
590 }
591 ranked.sort_by_key(|(priority, _)| *priority);
592
593 let mut models: Vec<Model> = ranked.into_iter().map(|(_, model)| model).collect();
594 if let Some(first) = models.first_mut() {
595 first.is_default = true;
596 }
597 Ok(models)
598}
599
600#[cfg(test)]
601mod tests {
602 use super::*;
603
604 /// Trimmed from real `codex debug models` output (codex-cli 0.145.0). The
605 /// hidden entry and the out-of-order priorities are both as reported.
606 const CODEX_OUTPUT: &str = r#"{"models":[
607 {"slug":"gpt-5.5","display_name":"GPT-5.5","description":"Frontier model.",
608 "default_reasoning_level":"medium","visibility":"list","priority":7,
609 "supported_reasoning_levels":[{"effort":"low"},{"effort":"medium"},{"effort":"high"}]},
610 {"slug":"codex-auto-review","display_name":"Codex Auto Review","description":"Internal.",
611 "visibility":"hide","priority":43,"supported_reasoning_levels":[{"effort":"low"}]},
612 {"slug":"gpt-5.6-sol","display_name":"GPT-5.6-Sol","description":"Latest frontier model.",
613 "default_reasoning_level":"low","visibility":"list","priority":1,
614 "supported_reasoning_levels":[{"effort":"low"},{"effort":"ultra"}]}
615 ]}"#;
616
617 #[test]
618 fn codex_discovery_reads_the_fields_a_picker_needs() {
619 let models = parse_codex_models(CODEX_OUTPUT).expect("should parse");
620 let sol = &models[0];
621 assert_eq!(sol.id, "gpt-5.6-sol");
622 assert_eq!(sol.name, "GPT-5.6-Sol");
623 assert_eq!(sol.note, "Latest frontier model.");
624 assert_eq!(sol.efforts, vec!["low", "ultra"]);
625 }
626
627 /// The array order is not the display order: `gpt-5.5` is listed first and
628 /// carries priority 7, while `gpt-5.6-sol` is listed last at priority 1.
629 #[test]
630 fn codex_discovery_uses_the_vendors_ordering_not_the_array_order() {
631 let models = parse_codex_models(CODEX_OUTPUT).expect("should parse");
632 let ids: Vec<&str> = models.iter().map(|m| m.id.as_ref()).collect();
633 assert_eq!(ids, ["gpt-5.6-sol", "gpt-5.5"]);
634 assert!(
635 models[0].is_default,
636 "the top-priority model is the default"
637 );
638 }
639
640 /// Codex marks its internal models `hide`. Offering one in a picker hands a
641 /// user a model the vendor deliberately withheld.
642 #[test]
643 fn codex_discovery_drops_models_the_vendor_hides() {
644 let models = parse_codex_models(CODEX_OUTPUT).expect("should parse");
645 assert!(
646 !models.iter().any(|m| m.id == "codex-auto-review"),
647 "a hidden model must not reach a picker"
648 );
649 }
650
651 #[test]
652 fn unparseable_output_is_an_error_not_an_empty_list() {
653 assert!(matches!(
654 parse_codex_models("Reading additional input from stdin..."),
655 Err(Error::Parse { .. })
656 ));
657 assert!(
658 matches!(
659 parse_codex_models(r#"{"models":[]}"#),
660 Err(Error::Parse { .. })
661 ),
662 "an empty list means the shape changed, not that Codex has no models"
663 );
664 }
665
666 /// Discovery must not quietly answer with the compiled-in list: a caller
667 /// asking for it is asking for freshness, and a silent fallback answers a
668 /// different question.
669 #[tokio::test]
670 async fn agents_that_cannot_be_asked_say_so() {
671 for agent in [Agent::Claude, Agent::Copilot] {
672 assert!(
673 matches!(
674 agent.discover_models().await,
675 Err(Error::Unsupported { .. })
676 ),
677 "{agent} should report that it cannot enumerate models"
678 );
679 }
680 }
681
682 /// The gap this closes: every Claude and Copilot entry shipped with an
683 /// empty `efforts` while both CLIs document a `--effort` flag, so a picker
684 /// had nothing to offer.
685 #[test]
686 fn every_model_reports_the_levels_its_agent_accepts() {
687 for agent in [Agent::Claude, Agent::Codex, Agent::Copilot] {
688 for model in agent.models() {
689 // `auto` is the documented exception, asserted below.
690 if agent == Agent::Copilot && model.id == "auto" {
691 continue;
692 }
693 assert!(
694 !model.efforts.is_empty(),
695 "{agent} model {} reports no effort levels",
696 model.id
697 );
698 }
699 }
700 }
701
702 /// Support is not uniform across an agent even where `--help` lists one set.
703 /// Copilot exits 1 for an effort on `auto` rather than ignoring it, so
704 /// offering a level there would produce a failed run.
705 #[test]
706 fn copilot_auto_offers_no_levels_because_it_refuses_them() {
707 let models = Agent::Copilot.models();
708 let auto = models.iter().find(|m| m.id == "auto").expect("auto");
709 assert!(
710 auto.efforts.is_empty(),
711 "auto rejects the effort flag outright"
712 );
713 let pinned = models.iter().find(|m| m.id == "gpt-5.5").expect("gpt-5.5");
714 assert!(
715 !pinned.efforts.is_empty(),
716 "pinned models do document levels"
717 );
718 }
719
720 /// Verified from `claude --help` (2.1.212) and `copilot --help` (1.0.75).
721 /// Copilot's set is two wider at the bottom, which is the whole reason
722 /// levels are strings rather than a shared enum.
723 #[test]
724 fn the_documented_level_sets_are_not_interchangeable() {
725 let claude = &Agent::Claude.models()[0].efforts;
726 let copilot_models = Agent::Copilot.models();
727 let copilot = &copilot_models
728 .iter()
729 .find(|m| m.id == "gpt-5.5")
730 .expect("gpt-5.5")
731 .efforts;
732 assert_eq!(claude, &["low", "medium", "high", "xhigh", "max"]);
733 assert_eq!(
734 copilot,
735 &["none", "minimal", "low", "medium", "high", "xhigh", "max"]
736 );
737 assert_ne!(claude, copilot, "a shared enum would have to cover both");
738 }
739
740 /// Codex is the one agent whose levels differ per model, which is why they
741 /// live on the model rather than on the agent.
742 #[test]
743 fn codex_levels_differ_between_its_own_models() {
744 let models = Agent::Codex.models();
745 let by_id = |id: &str| -> Vec<String> {
746 models
747 .iter()
748 .find(|m| m.id == id)
749 .unwrap_or_else(|| panic!("{id} should be catalogued"))
750 .efforts
751 .iter()
752 .map(ToString::to_string)
753 .collect()
754 };
755 assert!(
756 by_id("gpt-5.6-sol").contains(&"ultra".to_string()),
757 "its frontier model offers ultra"
758 );
759 assert!(
760 !by_id("gpt-5.6-luna").contains(&"ultra".to_string()),
761 "its fast model does not"
762 );
763 }
764
765 #[test]
766 fn every_agent_offers_exactly_one_default() {
767 for agent in [Agent::Claude, Agent::Codex, Agent::Copilot] {
768 let defaults = agent.models().iter().filter(|m| m.is_default).count();
769 assert_eq!(defaults, 1, "{agent} should mark exactly one default");
770 }
771 }
772
773 #[test]
774 fn no_catalogue_repeats_an_id() {
775 for agent in [Agent::Claude, Agent::Codex, Agent::Copilot] {
776 let models = agent.models();
777 let mut ids: Vec<&str> = models.iter().map(|m| m.id.as_ref()).collect();
778 ids.sort_unstable();
779 let count = ids.len();
780 ids.dedup();
781 assert_eq!(ids.len(), count, "{agent} has a duplicate model id");
782 }
783 }
784
785 /// The catalogue is a suggestion, not a gate. A model released after this
786 /// list was compiled has to reach the command line untouched.
787 #[test]
788 fn an_unlisted_model_is_still_accepted() {
789 let request = crate::Request::new(Agent::Claude, "hi").model("some-model-from-next-year");
790 let argv = request
791 .argv()
792 .expect("an unlisted model must not be rejected");
793 assert!(
794 argv.windows(2)
795 .any(|w| w[0] == "--model" && w[1] == "some-model-from-next-year"),
796 "the model should reach the command line verbatim: {argv:?}"
797 );
798 }
799}