diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index d2be14b..1e6030a 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -6,13 +6,13 @@ }, "metadata": { "description": "The Antigravity CLI (`agy`) plugin for Claude Code β€” ask, code review, adversarial review, delegate, rescue, web scrape and docβ†’Markdown from inside your editor. Read-only commands really are read-only (agy pinned to Default mode, outside your repo) + secret / SSRF / path guards, background job control. One std-only Rust binary, SHA-256 pinned; macOS / Linux / Windows.", - "version": "0.9.0" + "version": "0.9.1" }, "plugins": [ { "name": "agy", "description": "Use the Google Antigravity CLI (`agy`) from Claude Code: /agy:ask, /agy:review, /agy:adversarial-review, /agy:scrape, /agy:doc-to-md (read-only: agy pinned to Default mode, outside your repo), /agy:rescue and /agy:image (write-capable, with rails), /agy:status, /agy:result, /agy:cancel, /agy:delegate, /agy:research, /agy:setup, /agy:help. Secret-scan + SSRF/path guards; per-call --model resolved against `agy models`. One std-only Rust binary, SHA-256 pinned.", - "version": "0.9.0", + "version": "0.9.1", "author": { "name": "limeflash", "url": "https://github.com/limeflash" diff --git a/CHANGELOG.md b/CHANGELOG.md index 77cea39..e054444 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 > since been substantially rewritten and extended. The earlier entries below > are the original upstream history, preserved for traceability. +## [0.9.1] - 2026-11-25 (limeflash) + +Gemini 4 model aliases, and a rebuild from `main` so the released binaries +match the source again (0.9.0's binaries were built just before the Linux +fix below landed). + +### Added +- **Gemini 4 and any future Gemini code name as `--model` aliases.** agy now + lists Gemini 4 Hydrogen (XHigh / High / Medium / Low), which no alias + reached. Gemini aliases are no longer a fixed list: every kind that + `agy models` lists (`hydrogen`, `flash`, `pro`, and the next code name) is + an alias, with an optional level suffix (`hydrogen-xhigh`, `flash-low`). + `gemini` (`gemini-xhigh`, …) is the newest Gemini of any kind; on a version + tie a big model beats Flash. `/agy:help` shows each kind with its levels. + +### Changed +- The empty-`--model` error suggests `--model gemini` instead of `pro`, + which current agy accounts don't list. + +### Fixed +- Linux: `/agy:cancel` treated an exited-but-not-yet-reaped worker (a + zombie) as alive and waited out its full grace period before giving up; + a zombie now counts as gone. +- Windows: two updates of the same job record at once (a background + worker finishing while `/agy:cancel` runs) could fail with "could not + lock the job record: Access is denied". Job records are now guarded by + an OS file lock instead of a create-and-delete lock file. + +### Tests +- Windows CI: path, file-name and PowerShell 5.1 quirks in the test + harnesses (no change to the plugin's behaviour on Windows). + ## [0.9.0] - 2026-11-24 (limeflash) **Rewritten in Rust, and a read-only escape on agy 1.5.7+ closed.** One diff --git a/Cargo.lock b/Cargo.lock index 1ccb7a0..86e3ab0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 4 [[package]] name = "agy-plugin" -version = "0.9.0" +version = "0.9.1" diff --git a/Cargo.toml b/Cargo.toml index 5173e0f..f35b959 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "agy-plugin" -version = "0.9.0" +version = "0.9.1" edition = "2024" description = "Claude Code plugin runtime for Google's Antigravity CLI (agy): read-only commands that stay read-only, plus background jobs." license = "MIT" diff --git a/README.md b/README.md index a570366..ab80cf8 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Ask questions, get a second opinion on your diff, hand off tasks, read web pages |---|---| | πŸ”’ **Read-only really means read-only** | Commands like `/agy:ask` and `/agy:review` can look, never touch: agy is explicitly forbidden to change files or run commands, and if that can't be guaranteed the plugin refuses to run. | | πŸ›‘οΈ **Nothing sensitive slips out** | Your diff is checked for API keys before it goes to Gemini; web addresses and file paths are checked so agy can't be pointed at your internal network or your `~/.ssh`. | -| 🎯 **Always the newest model** | `--model opus`, `pro`, `flash`, `sonnet` pick the latest model of that family that your account offers. | +| 🎯 **Always the newest model** | `--model gemini` picks the newest Gemini (Gemini 4 Hydrogen today); `hydrogen-xhigh`, `flash`, `opus`, `sonnet` pick the latest of that family your account offers. | | ⏳ **Long jobs in the background** | Start a review or a task, keep working, check back with `/agy:status` and `/agy:result`. | | πŸ“¦ **Tiny and self-contained** | One ~0.6 MB native program with zero third-party dependencies. No Node.js, no Python. Verified by checksum before it runs. | @@ -97,18 +97,23 @@ It checks that `agy` is installed (and offers to install it), logged in, and new ## 🎯 Choosing a model ```text -/agy:ask --model opus "what's wrong with this regex?" -/agy:review --model flash +/agy:review --model gemini +/agy:ask --model hydrogen-xhigh "what's wrong with this regex?" +/agy:review --model flash-low ``` -| Alias | Picks | -|---|---| -| `flash`, `flash-medium`, `flash-low` | newest Gemini Flash (High / Medium / Low) | -| `pro`, `pro-low` | newest Gemini Pro (High / Low) | -| `opus`, `sonnet` | newest Claude Opus / Sonnet (prefers *Thinking*) | -| `gpt-oss` | GPT-OSS 120B | +| Alias | Picks | TodayΒΉ | +|---|---|---| +| `gemini` | newest Gemini of any kind | Gemini 4 Hydrogen (High) | +| `hydrogen` | newest Gemini Hydrogen | Gemini 4 Hydrogen (High) | +| `flash` | newest Gemini Flash | Gemini 3.8 Flash (High) | +| `pro`, `carbon`, … | **any** Gemini kind your account lists | β€” | +| `opus`, `sonnet` | newest Claude Opus / Sonnet (prefers *Thinking*) | Claude Opus 4.6 / Sonnet 4.6 | +| `gpt-oss` | GPT-OSS 120B | GPT-OSS 120B (Medium) | + +**Levels:** add `-xhigh`, `-high` (default), `-medium` or `-low` to any Gemini alias β€” `hydrogen-xhigh`, `flash-low`, `gemini-medium`. When Google ships a new Gemini code name, its alias works right away, no plugin update. -Any exact model name or id from `agy models` works too. `/agy:help` shows what each alias points to right now. Without `--model`, agy uses its own default. +ΒΉ What `agy models` listed on 2026-11-25; your account may differ. Any exact model name or id from `agy models` works too. `/agy:help` shows what each alias points to right now. Without `--model`, agy uses its own default. --- diff --git a/plugins/agy/.claude-plugin/plugin.json b/plugins/agy/.claude-plugin/plugin.json index 1d384e6..cf1d7e3 100644 --- a/plugins/agy/.claude-plugin/plugin.json +++ b/plugins/agy/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "agy", - "version": "0.9.0", + "version": "0.9.1", "description": "Use the Google Antigravity CLI (`agy`) from Claude Code: /agy:ask, /agy:review, /agy:adversarial-review, /agy:scrape, /agy:doc-to-md (read-only: agy pinned to Default mode, outside your repo), /agy:rescue and /agy:image (write-capable, with rails), /agy:status, /agy:result, /agy:cancel, /agy:delegate, /agy:research, /agy:setup, /agy:help. Secret-scan + SSRF/path guards; per-call --model resolved against `agy models`. One std-only Rust binary, SHA-256 pinned.", "author": { "name": "limeflash", diff --git a/plugins/agy/agents/runner.md b/plugins/agy/agents/runner.md index 8ef23b9..4bc3ec0 100644 --- a/plugins/agy/agents/runner.md +++ b/plugins/agy/agents/runner.md @@ -41,9 +41,10 @@ bash "${CLAUDE_PLUGIN_ROOT}/bin/agy-plugin" ask [--model ] '' [-- ``` bash "${CLAUDE_PLUGIN_ROOT}/bin/agy-plugin" ask --model opus 'why does the pagination test flake?' ``` - Aliases (`flash-low`, `flash-medium`, `flash`, `pro-low`, `pro`, `sonnet`, - `opus`, `gpt-oss`) resolve to the newest model of that family that - `agy models` lists; any id or display name from `agy models` is also + Aliases resolve to the newest model of that family that `agy models` + lists: `gemini` (newest Gemini of any kind), any Gemini kind it lists + (`hydrogen`, `flash`, `pro`, …) with an optional level (`hydrogen-xhigh`, + `flash-low`), `opus`, `sonnet`, `gpt-oss`; any id or display name from `agy models` is also accepted. Unknown names fail with exit 64. - If no `--model` was given, omit it; agy uses its current model. - After the prompt, only `--print-timeout` and `--effort` are allowed; any diff --git a/plugins/agy/commands/ask.md b/plugins/agy/commands/ask.md index d7457a9..6145772 100644 --- a/plugins/agy/commands/ask.md +++ b/plugins/agy/commands/ask.md @@ -35,8 +35,9 @@ Only `--print-timeout ` and `--effort ` may follow the prompt argument; any other agy flag is refused (exit 64) because `ask` is read-only. -``: `flash-low`, `flash-medium`, `flash`, `pro-low`, `pro`, `sonnet`, -`opus`, `gpt-oss`. Aliases resolve to the newest model of that family that +``: `gemini` (newest Gemini of any kind), any Gemini kind +`agy models` lists (`hydrogen`, `flash`, `pro`, …) with an optional level +(`hydrogen-xhigh`, `flash-low`), `opus`, `sonnet`, `gpt-oss`. Aliases resolve to the newest model of that family that `agy models` lists; any id or display name from `agy models` is also accepted. Unknown names fail with exit 64. Run `/agy:help` for the table. diff --git a/plugins/agy/commands/delegate.md b/plugins/agy/commands/delegate.md index 8d09c1f..f2a0592 100644 --- a/plugins/agy/commands/delegate.md +++ b/plugins/agy/commands/delegate.md @@ -22,8 +22,9 @@ $ARGUMENTS from the task text. - If no model is given, agy uses whatever model it is currently set to. -``: `flash-low`, `flash-medium`, `flash`, `pro-low`, `pro`, `sonnet`, -`opus`, `gpt-oss` β€” each resolves to the newest model of that family that +``: `gemini` (newest Gemini of any kind), any Gemini kind +`agy models` lists (`hydrogen`, `flash`, `pro`, …) with an optional level +(`hydrogen-xhigh`, `flash-low`), `opus`, `sonnet`, `gpt-oss` β€” each resolves to the newest model of that family that `agy models` lists. Any id or display name from `agy models` is also accepted. Run `/agy:help` for the table. diff --git a/plugins/agy/commands/rescue.md b/plugins/agy/commands/rescue.md index 2bd4c72..9c065c0 100644 --- a/plugins/agy/commands/rescue.md +++ b/plugins/agy/commands/rescue.md @@ -60,8 +60,9 @@ bash "${CLAUDE_PLUGIN_ROOT}/bin/agy-plugin" rescue --background --wait 'fix the bash "${CLAUDE_PLUGIN_ROOT}/bin/agy-plugin" rescue --model opus --print-timeout 20m 'migrate the tests to vitest' ``` -``: `flash-low`, `flash-medium`, `flash`, `pro-low`, `pro`, -`sonnet`, `opus`, `gpt-oss` β€” resolved to the newest model of that +``: `gemini` (newest Gemini of any kind), any Gemini kind +`agy models` lists (`hydrogen`, `flash`, `pro`, …) with an optional level +(`hydrogen-xhigh`, `flash-low`), `opus`, `sonnet`, `gpt-oss` β€” resolved to the newest model of that family that `agy models` lists and passed to agy's `--model` for this run only. Any id or display name from `agy models` is also accepted. diff --git a/plugins/agy/commands/research.md b/plugins/agy/commands/research.md index 94d6fc3..8cbd586 100644 --- a/plugins/agy/commands/research.md +++ b/plugins/agy/commands/research.md @@ -42,8 +42,9 @@ Then invoke the `agy:runner` subagent with that prompt as is given, agy uses whatever model it is currently set to (a reasoning-strong model like `pro` or `opus` works well for research). -``: `flash-low`, `flash-medium`, `flash`, `pro-low`, `pro`, `sonnet`, -`opus`, `gpt-oss` β€” each resolves to the newest model of that family that +``: `gemini` (newest Gemini of any kind), any Gemini kind +`agy models` lists (`hydrogen`, `flash`, `pro`, …) with an optional level +(`hydrogen-xhigh`, `flash-low`), `opus`, `sonnet`, `gpt-oss` β€” each resolves to the newest model of that family that `agy models` lists. Any id or display name from `agy models` is also accepted. Run `/agy:help` for the table. diff --git a/plugins/agy/skills/antigravity-cli/SKILL.md b/plugins/agy/skills/antigravity-cli/SKILL.md index 86b8f3f..baf71b0 100644 --- a/plugins/agy/skills/antigravity-cli/SKILL.md +++ b/plugins/agy/skills/antigravity-cli/SKILL.md @@ -44,10 +44,15 @@ forwarding. ## Model aliases -`flash-low`, `flash-medium` (`flash-med`), `flash` (`flash-high`), -`pro-low`, `pro` (`pro-high`), `sonnet` (`claude-sonnet`), -`opus` (`claude-opus`), `gpt-oss` (`gpt-oss-120b`). Each resolves against -`agy models` to the newest model in its family. Any id or display name that +- `gemini` β€” the newest Gemini of any kind (Gemini 4 Hydrogen today). +- Any Gemini kind that `agy models` lists β€” `hydrogen`, `flash`, `pro`, and + whatever code name Google adds next β€” is an alias by itself. +- Add a level to either: `-xhigh`, `-high` (the default), `-medium` + (`-med`), `-low` β€” e.g. `hydrogen-xhigh`, `flash-low`, `gemini-medium`. +- `opus` (`claude-opus`), `sonnet` (`claude-sonnet`), `gpt-oss` + (`gpt-oss-120b`). + +Each resolves against `agy models` to the newest model in its family. Any id or display name that `agy models` lists is also accepted verbatim. Run `bash "${CLAUDE_PLUGIN_ROOT}/bin/agy-plugin" help` for the diff --git a/scripts/test-launcher.ps1 b/scripts/test-launcher.ps1 index cc75242..2417e31 100644 --- a/scripts/test-launcher.ps1 +++ b/scripts/test-launcher.ps1 @@ -12,25 +12,34 @@ function Fail([string]$m) { [Console]::Error.WriteLine("FAIL: $m"); exit 1 } # own native-argument boundary, which mangles embedded quotes and a # trailing backslash before the launcher ever sees them β€” the test must # exercise the launcher's quoting, not PowerShell's. -# - Under ErrorActionPreference=Stop, PS 5.1 turns any stderr line of a -# native program into a terminating NativeCommandError, and the launcher -# legitimately reports "downloading ..." on stderr: relax it for the call. +# - Start-Process with stdout/stderr redirected to files, not `& powershell +# 2>&1`: when one PowerShell runs another, the parent treats the child's +# stderr as serialized error records (CLIXML) and fails on the launcher's +# plain "checksum mismatch" lines ("Cannot process the XML from the +# 'Error' stream"); PS 5.1 also turns stderr lines into terminating +# NativeCommandErrors under ErrorActionPreference=Stop. Files sidestep both. function Invoke-Launcher([string[]]$launcherArgs, [switch]$MergeStderr) { $quoted = @($launcherArgs | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' ' $script = "& '" + ($launcher -replace "'", "''") + "' $quoted; exit `$LASTEXITCODE" $enc = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($script)) - $old = $ErrorActionPreference - $ErrorActionPreference = 'Continue' + $outFile = Join-Path $work ("out-" + [Guid]::NewGuid() + ".txt") + $errFile = Join-Path $work ("err-" + [Guid]::NewGuid() + ".txt") + # Started from pwsh 7, Windows PowerShell inherits pwsh's PSModulePath and + # loads pwsh's modules (Get-FileHash & co. then fail); let it use its own. + $savedModulePath = $env:PSModulePath + $env:PSModulePath = $null try { - if ($MergeStderr) { - $o = & powershell -NoProfile -ExecutionPolicy Bypass -EncodedCommand $enc 2>&1 | ForEach-Object { "$_" } - } else { - $o = & powershell -NoProfile -ExecutionPolicy Bypass -EncodedCommand $enc 2>$null - } - return @{ Out = ($o -join "`n"); Code = $LASTEXITCODE } + $p = Start-Process -FilePath 'powershell' -Wait -PassThru -NoNewWindow ` + -ArgumentList @('-NoProfile', '-NonInteractive', '-OutputFormat', 'Text', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', $enc) ` + -RedirectStandardOutput $outFile -RedirectStandardError $errFile } finally { - $ErrorActionPreference = $old + $env:PSModulePath = $savedModulePath } + $o = "$(Get-Content -Raw -LiteralPath $outFile)" + $e = "$(Get-Content -Raw -LiteralPath $errFile)" + if ($MergeStderr) { $o = "$o`n$e" } + Remove-Item -Force -LiteralPath $outFile, $errFile -ErrorAction SilentlyContinue + return @{ Out = $o; Err = $e; Code = $p.ExitCode } } $repo = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path) @@ -53,7 +62,7 @@ try { # 1. download + verify + exec, with an argument containing quotes and spaces. $tricky = 'say "hi" to C:\path with spaces\' $r = Invoke-Launcher @('ask', $tricky) - if ($r.Code -ne 0) { Fail "first run exit $($r.Code)" } + if ($r.Code -ne 0) { Fail "first run exit $($r.Code): $($r.Err)" } if (-not ($r.Out -match 'hello from stub')) { Fail "unexpected output: $($r.Out)" } $argv = ((Get-Content -Raw -LiteralPath "$work\record.txt").Split("`t")[1]).Split([char]0x1f) if ($argv[0] -ne 'ask' -or $argv[1] -ne $tricky) { Fail "argv mangled: $($argv -join ' | ')" } @@ -62,7 +71,7 @@ try { # 2. tampered cache is not executed (re-downloaded instead). Set-Content -LiteralPath "$work\cache\9.9.9\$asset" -Value 'garbage' $r = Invoke-Launcher @('version') - if ($r.Code -ne 0) { Fail 're-download failed' } + if ($r.Code -ne 0) { Fail "re-download failed: $($r.Err)" } if ((Get-FileHash -Algorithm SHA256 -LiteralPath "$work\cache\9.9.9\$asset").Hash.ToLowerInvariant() -ne $good) { Fail 'cache not repaired' } Write-Output 'ok 2 tampered cache refused' diff --git a/src/jobs.rs b/src/jobs.rs index 12401dc..c48bffc 100644 --- a/src/jobs.rs +++ b/src/jobs.rs @@ -90,7 +90,7 @@ pub(crate) fn write_atomic(path: &Path, data: &[u8]) -> std::io::Result<()> { f.write_all(data)?; f.sync_all()?; drop(f); - std::fs::rename(&tmp, path) + rename_retrying(&tmp, path) })(); if res.is_err() { let _ = std::fs::remove_file(&tmp); @@ -98,6 +98,23 @@ pub(crate) fn write_atomic(path: &Path, data: &[u8]) -> std::io::Result<()> { res } +/// `rename`, retried briefly on Windows: replacing a file fails there while +/// anything (a concurrent reader, an antivirus scan of the fresh temp file) +/// has it open for a moment. +fn rename_retrying(from: &Path, to: &Path) -> std::io::Result<()> { + let mut tries = 0; + loop { + match std::fs::rename(from, to) { + Err(e) if cfg!(windows) && tries < 50 && from.exists() => { + let _ = e; + tries += 1; + std::thread::sleep(Duration::from_millis(10)); + } + r => return r, + } + } +} + fn write_record(root: &Path, id: &str, rec: &Value) -> Result<(), Fail> { let text = format!("{}\n", json::to_string_pretty(rec)); write_atomic(&record_path(root, id), text.as_bytes()) @@ -130,30 +147,48 @@ pub(crate) fn read_job(root: &Path, id: &str) -> Result, Fail> { .map_err(|e| Fail::runtime(format!("error: job {id} is unreadable: {e}"))) } -/// Run `f` while holding `runtime/.lock` (create-exclusive). A lock -/// older than 30 s is from a crashed process and is broken. +/// Run `f` while holding an exclusive OS lock on `runtime/.lock`. The +/// OS drops the lock when its holder exits, so a crashed process can't leave +/// a job locked; the file itself stays (deleting a lock file that another +/// process is opening races on Windows). fn with_lock(root: &Path, id: &str, f: impl FnOnce() -> Result) -> Result { let lp = lock_path(root, id); if let Some(d) = lp.parent() { std::fs::create_dir_all(d).map_err(|e| io_fail("could not create the job state dir", e))?; } + if std::fs::symlink_metadata(&lp).is_ok_and(|m| !m.is_file()) { + return Err(Fail::runtime(format!( + "error: refusing to use {}: not a regular file", + lp.display() + ))); + } + let mut o = OpenOptions::new(); + o.read(true).write(true).create(true).truncate(false); + #[cfg(unix)] + { + use std::os::unix::fs::OpenOptionsExt; + o.mode(0o600); + } let start = Instant::now(); - loop { - match OpenOptions::new().write(true).create_new(true).open(&lp) { - Ok(mut file) => { - let _ = write!(file, "{}", std::process::id()); - break; + let file = loop { + match o.open(&lp) { + Ok(file) => break file, + // Windows: a 0.9.0 process deleting its lock file leaves it + // "delete pending" for a moment, which reads as access denied. + Err(e) + if cfg!(windows) + && e.kind() == std::io::ErrorKind::PermissionDenied + && start.elapsed() < Duration::from_secs(2) => + { + std::thread::sleep(Duration::from_millis(15)); } - Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => { - let stale = std::fs::metadata(&lp) - .and_then(|m| m.modified()) - .ok() - .and_then(|t| t.elapsed().ok()) - .is_some_and(|age| age > Duration::from_secs(30)); - if stale { - let _ = std::fs::remove_file(&lp); - continue; - } + Err(e) => return Err(io_fail("could not lock the job record", e)), + } + }; + loop { + match file.try_lock() { + Ok(()) => break, + Err(std::fs::TryLockError::WouldBlock) => { if start.elapsed() > Duration::from_secs(10) { return Err(Fail::runtime(format!( "error: job {id} is locked by another process" @@ -161,11 +196,13 @@ fn with_lock(root: &Path, id: &str, f: impl FnOnce() -> Result) -> R } std::thread::sleep(Duration::from_millis(15)); } - Err(e) => return Err(io_fail("could not lock the job record", e)), + Err(std::fs::TryLockError::Error(e)) => { + return Err(io_fail("could not lock the job record", e)); + } } } let res = f(); - let _ = std::fs::remove_file(&lp); + let _ = file.unlock(); res } diff --git a/src/models.rs b/src/models.rs index 796e5c8..dec19db 100644 --- a/src/models.rs +++ b/src/models.rs @@ -4,7 +4,15 @@ //! simplybychris/antigravity-plugin-cc 0.5.0). 0.8.x instead patched the //! "model" field of agy's settings.json under a lock: that flipped the model //! of a TUI open in parallel and broke whenever Google renamed a model. - +//! +//! Gemini aliases are not a fixed list: Google names Gemini models +//! `Gemini ()` and keeps adding kinds (Flash, Pro, +//! and code names like Hydrogen). Any kind that `agy models` lists is an +//! alias β€” `hydrogen`, `flash` β€” optionally with a level suffix +//! (`hydrogen-xhigh`, `flash-low`); `gemini` means the newest Gemini of any +//! kind. + +use std::cmp::Ordering; use std::time::Duration; use crate::agy::{self, Agy}; @@ -30,13 +38,194 @@ impl Model { } } +// ---------------------------------------------------------------- Gemini + +/// Level words accepted in an alias suffix, and the level they mean. +const LEVEL_WORDS: &[(&str, &str)] = &[ + ("xhigh", "xhigh"), + ("high", "high"), + ("medium", "medium"), + ("med", "medium"), + ("low", "low"), +]; + +/// Display order of levels (a level agy invents later sorts last). +const LEVEL_ORDER: &[&str] = &["xhigh", "high", "medium", "low"]; + +/// Kinds that are always shown in the alias table, even when the account +/// doesn't list them, so `pro` explains itself instead of being "unknown". +const WELL_KNOWN_KINDS: &[&str] = &["flash", "pro"]; + +/// A parsed Gemini display name. +#[derive(Clone, Debug, PartialEq, Eq)] +struct GeminiName { + /// "4", "3.8" + version: String, + /// Lowercase, words joined by '-': "hydrogen", "flash", "flash-lite"; + /// empty for a bare "Gemini 4 (High)". + kind: String, + /// Lowercase level from the trailing "(...)", or "" when there is none. + level: String, +} + +fn is_word(w: &str) -> bool { + !w.is_empty() && w.chars().all(|c| c.is_ascii_alphanumeric()) +} + +/// "gemini [] [()]", lowercased. +fn parse_gemini(lower: &str) -> Option { + let rest = lower.strip_prefix("gemini ")?; + let (version, rest) = rest.split_once(' ').unwrap_or((rest, "")); + if !is_version_word(version) { + return None; + } + let (kind_part, level) = match rest.strip_suffix(')') { + Some(head) => { + let (kind_part, level) = match head.rsplit_once(" (") { + Some(split) => split, + None => ("", head.strip_prefix('(')?), + }; + if !is_word(level) { + return None; + } + (kind_part, level) + } + None => (rest, ""), + }; + let words: Vec<&str> = kind_part.split(' ').filter(|w| !w.is_empty()).collect(); + if kind_part.contains(" ") || !words.iter().all(|w| is_word(w)) { + return None; + } + Some(GeminiName { + version: version.to_string(), + kind: words.join("-"), + level: level.to_string(), + }) +} + +/// A Gemini alias: `gemini`, ``, either with `-`. +#[derive(Clone, Debug, PartialEq, Eq)] +struct GeminiAlias { + /// None for `gemini` (any kind). + kind: Option, + /// None = the alias didn't name one (prefer High). + level: Option<&'static str>, +} + +fn level_word(w: &str) -> Option<&'static str> { + LEVEL_WORDS.iter().find(|(k, _)| *k == w).map(|(_, v)| *v) +} + +fn parse_gemini_alias(lc: &str) -> Option { + let (base, level) = match lc.rsplit_once('-') { + Some((b, l)) if !b.is_empty() && level_word(l).is_some() => (b, level_word(l)), + _ => (lc, None), + }; + if !base.split('-').all(is_word) { + return None; + } + let kind = (base != "gemini").then(|| base.to_string()); + Some(GeminiAlias { kind, level }) +} + +/// Preference among levels when the alias names none: High first (agy's +/// usual default), then an unlabelled model, then the rest. +fn default_level_rank(level: &str) -> usize { + match level { + "high" => 0, + "" => 1, + "xhigh" => 2, + "medium" => 3, + "low" => 4, + _ => 5, + } +} + +fn level_order_rank(level: &str) -> usize { + LEVEL_ORDER + .iter() + .position(|l| *l == level) + .unwrap_or(LEVEL_ORDER.len()) +} + +/// Flash / Lite are the small models; for `gemini` a same-version big model +/// wins. +fn is_small_kind(kind: &str) -> bool { + kind.split('-').any(|w| w == "flash" || w == "lite") +} + +/// The newest model matching a Gemini alias. Ties: preferred level, then (for +/// `gemini`) a non-Flash kind, then agy's own listing order. +fn newest_gemini<'a>(models: &'a [Model], alias: &GeminiAlias) -> Option<&'a Model> { + let mut best: Option<(&Model, GeminiName)> = None; + for m in models { + let Some(g) = parse_gemini(&m.name.to_lowercase()) else { + continue; + }; + if alias.kind.as_deref().is_some_and(|k| k != g.kind) { + continue; + } + if alias.level.is_some_and(|l| l != g.level) { + continue; + } + let better = match &best { + None => true, + Some((_, b)) => { + agy::compare_versions(&g.version, &b.version) + .then_with(|| default_level_rank(&b.level).cmp(&default_level_rank(&g.level))) + .then_with(|| { + if alias.kind.is_none() { + is_small_kind(&b.kind).cmp(&is_small_kind(&g.kind)) + } else { + Ordering::Equal + } + }) + == Ordering::Greater + } + }; + if better { + best = Some((m, g)); + } + } + best.map(|(m, _)| m) +} + +fn title_case(kind: &str) -> String { + kind.split('-') + .map(|w| { + let mut c = w.chars(); + match c.next() { + Some(f) => f.to_ascii_uppercase().to_string() + c.as_str(), + None => String::new(), + } + }) + .collect::>() + .join(" ") +} + +fn level_label(level: &str) -> String { + if level == "xhigh" { + "XHigh".to_string() + } else { + title_case(level) + } +} + +fn gemini_description(alias: &GeminiAlias) -> String { + let what = match &alias.kind { + None => "newest Gemini (any kind)".to_string(), + Some(k) => format!("newest Gemini {}", title_case(k)), + }; + match alias.level { + Some(l) => format!("{what} ({})", level_label(l)), + None => what, + } +} + +// ------------------------------------------------- Claude, GPT-OSS (fixed) + #[derive(Clone, Copy, Debug)] enum Family { - /// `gemini ()` - Gemini { - tier: &'static str, - level: &'static str, - }, /// `claude ` with an optional ` (...)` suffix. Claude { kind: &'static str }, /// `gpt-oss 120b` with an optional ` (...)` suffix. @@ -53,49 +242,10 @@ struct AliasRow { const ALIASES: &[AliasRow] = &[ AliasRow { - aliases: &["flash-low"], - family: Family::Gemini { - tier: "flash", - level: "low", - }, - prefer_suffix: None, - description: "newest Gemini Flash (Low)", - }, - AliasRow { - aliases: &["flash-medium", "flash-med"], - family: Family::Gemini { - tier: "flash", - level: "medium", - }, - prefer_suffix: None, - description: "newest Gemini Flash (Medium)", - }, - AliasRow { - aliases: &["flash", "flash-high"], - family: Family::Gemini { - tier: "flash", - level: "high", - }, - prefer_suffix: None, - description: "newest Gemini Flash (High)", - }, - AliasRow { - aliases: &["pro-low"], - family: Family::Gemini { - tier: "pro", - level: "low", - }, - prefer_suffix: None, - description: "newest Gemini Pro (Low)", - }, - AliasRow { - aliases: &["pro", "pro-high"], - family: Family::Gemini { - tier: "pro", - level: "high", - }, - prefer_suffix: None, - description: "newest Gemini Pro (High)", + aliases: &["opus", "claude-opus"], + family: Family::Claude { kind: "opus" }, + prefer_suffix: Some("(thinking)"), + description: "newest Claude Opus", }, AliasRow { aliases: &["sonnet", "claude-sonnet"], @@ -103,12 +253,6 @@ const ALIASES: &[AliasRow] = &[ prefer_suffix: Some("(thinking)"), description: "newest Claude Sonnet", }, - AliasRow { - aliases: &["opus", "claude-opus"], - family: Family::Claude { kind: "opus" }, - prefer_suffix: Some("(thinking)"), - description: "newest Claude Opus", - }, AliasRow { aliases: &["gpt-oss", "gpt-oss-120b"], family: Family::GptOss, @@ -133,16 +277,6 @@ fn optional_paren_suffix(rest: &str) -> bool { impl Family { fn matches(self, lower: &str) -> bool { match self { - Family::Gemini { tier, level } => { - // exactly: "gemini ()" - let Some(rest) = lower.strip_prefix("gemini ") else { - return false; - }; - let Some((ver, rest)) = rest.split_once(' ') else { - return false; - }; - is_version_word_loose(ver) && rest == format!("{tier} ({level})") - } Family::Claude { kind } => { let Some(rest) = lower.strip_prefix("claude ") else { return false; @@ -171,7 +305,7 @@ fn is_version_word_loose(w: &str) -> bool { } /// The family version inside a lowercased display name: its first purely -/// numeric word ("gemini 3.8 flash (high)" -> "3.8"), or "". +/// numeric word ("claude opus 4.6 (thinking)" -> "4.6"), or "". fn family_version(lower: &str) -> &str { lower.split(' ').find(|w| is_version_word(w)).unwrap_or("") } @@ -217,9 +351,9 @@ fn newest_match<'a>(models: &'a [Model], row: &AliasRow) -> Option<&'a Model> { let replace = match &best { None => true, Some((_, bv, bp)) => match agy::compare_versions(&version, bv) { - std::cmp::Ordering::Greater => true, - std::cmp::Ordering::Equal => preferred && !bp, - std::cmp::Ordering::Less => false, + Ordering::Greater => true, + Ordering::Equal => preferred && !bp, + Ordering::Less => false, }, }; if replace { @@ -236,49 +370,167 @@ fn exact_match<'a>(models: &'a [Model], input: &str) -> Option<&'a Model> { .find(|m| m.id.to_lowercase() == want || m.name.to_lowercase() == want) } +/// Gemini kinds `agy models` lists, newest version first (ties: listing +/// order), each with the levels of its newest version. +fn listed_gemini_kinds(models: &[Model]) -> Vec<(String, Vec)> { + let parsed: Vec = models + .iter() + .filter_map(|m| parse_gemini(&m.name.to_lowercase())) + .filter(|g| !g.kind.is_empty()) + .collect(); + let mut kinds: Vec<(String, String)> = Vec::new(); // (kind, newest version) + for g in &parsed { + match kinds.iter_mut().find(|(k, _)| *k == g.kind) { + Some((_, v)) => { + if agy::compare_versions(&g.version, v) == Ordering::Greater { + *v = g.version.clone(); + } + } + None => kinds.push((g.kind.clone(), g.version.clone())), + } + } + // Stable sort: newest version first, listing order within a version. + kinds.sort_by(|a, b| agy::compare_versions(&b.1, &a.1)); + kinds + .into_iter() + .map(|(kind, version)| { + let mut levels: Vec = Vec::new(); + for g in &parsed { + if g.kind == kind + && g.version == version + && !g.level.is_empty() + && !levels.contains(&g.level) + { + levels.push(g.level.clone()); + } + } + levels.sort_by_key(|l| level_order_rank(l)); + (kind, levels) + }) + .collect() +} + +/// Is `input` alias-shaped in a way that needs `agy models` to resolve (as +/// opposed to a model name to pass through unchecked)? +fn needs_listing(input: &str) -> bool { + if alias_row(input).is_some() { + return true; + } + parse_gemini_alias(&input.to_ascii_lowercase()).is_some_and(|a| match a.kind { + None => true, + Some(k) => WELL_KNOWN_KINDS.contains(&k.as_str()), + }) +} + /// Resolve against a model list (pure). Exact ids/names win over aliases. pub(crate) fn resolve_from_list(models: &[Model], input: &str) -> Result { if let Some(m) = exact_match(models, input) { return Ok(m.arg().to_string()); } - match alias_row(input) { - Some(row) => newest_match(models, row) + if let Some(row) = alias_row(input) { + return newest_match(models, row) .map(|m| m.arg().to_string()) .ok_or_else(|| { format!( "error: alias '{input}' has no matching model in `agy models` (expected: {})", row.description ) - }), - None => Err(format!( - "error: unknown model '{input}' (not an alias and not listed by `agy models`)" - )), + }); + } + if let Some(alias) = parse_gemini_alias(&input.to_ascii_lowercase()) { + if let Some(m) = newest_gemini(models, &alias) { + return Ok(m.arg().to_string()); + } + // A kind we know of, or one listed at other levels: say what's missing. + let known = match &alias.kind { + None => true, + Some(k) => { + WELL_KNOWN_KINDS.contains(&k.as_str()) + || listed_gemini_kinds(models).iter().any(|(lk, _)| lk == k) + } + }; + if known { + return Err(format!( + "error: alias '{input}' has no matching model in `agy models` (expected: {})", + gemini_description(&alias) + )); + } } + Err(format!( + "error: unknown model '{input}' (not an alias and not listed by `agy models`)" + )) } +const LEVEL_HINT: &str = "Gemini aliases take a level suffix: -xhigh, -high (the default), -medium, -low\n(e.g. hydrogen-xhigh, flash-low, gemini-medium); `gemini` is the newest Gemini of any kind.\n"; + /// Alias + model table for errors and `help`. pub(crate) fn format_model_table(models: Option<&[Model]>) -> String { let listed = models.filter(|m| !m.is_empty()); + let mut rows: Vec<(String, String)> = Vec::new(); + match listed { + None => { + rows.push(("gemini".into(), "newest Gemini of any kind".into())); + for k in WELL_KNOWN_KINDS { + rows.push(((*k).into(), format!("newest Gemini {}", title_case(k)))); + } + rows.push(( + "".into(), + "newest Gemini of that kind, e.g. hydrogen".into(), + )); + for row in ALIASES { + rows.push((row.aliases.join(", "), row.description.into())); + } + } + Some(ms) => { + let any = GeminiAlias { + kind: None, + level: None, + }; + rows.push(( + "gemini".into(), + newest_gemini(ms, &any) + .map(|m| m.name.clone()) + .unwrap_or_else(|| format!("(not available: {})", gemini_description(&any))), + )); + let mut kinds = listed_gemini_kinds(ms); + for k in WELL_KNOWN_KINDS { + if !kinds.iter().any(|(lk, _)| lk == k) { + kinds.push(((*k).to_string(), Vec::new())); + } + } + for (kind, levels) in kinds { + let alias = GeminiAlias { + kind: Some(kind.clone()), + level: None, + }; + let target = match newest_gemini(ms, &alias) { + Some(m) if levels.len() > 1 => { + format!("{} [levels: {}]", m.name, levels.join(", ")) + } + Some(m) => m.name.clone(), + None => format!("(not available: {})", gemini_description(&alias)), + }; + rows.push((kind, target)); + } + for row in ALIASES { + let target = match newest_match(ms, row) { + Some(m) => m.name.clone(), + None => format!("(not available: {})", row.description), + }; + rows.push((row.aliases.join(", "), target)); + } + } + } let mut out = String::new(); out.push_str(if listed.is_some() { "Aliases (case-insensitive), resolved against `agy models`:\n" } else { "Aliases (case-insensitive). `agy models` could not be read, so they are shown unresolved:\n" }); - for row in ALIASES { - let target = match listed { - None => row.description.to_string(), - Some(ms) => match newest_match(ms, row) { - Some(m) => m.name.clone(), - None => format!("(not available: {})", row.description), - }, - }; - out.push_str(&format!( - " {:<28} -> {}\n", - row.aliases.join(", "), - target - )); + for (alias, target) in rows { + out.push_str(&format!(" {alias:<28} -> {target}\n")); } + out.push_str(LEVEL_HINT); if let Some(ms) = listed { out.push_str( "\nAvailable models (names and ids are accepted verbatim, case-insensitive):\n", @@ -312,7 +564,7 @@ pub(crate) fn resolve(agy: &Agy, input: &str) -> Result { } let models = list_models(agy).filter(|m| !m.is_empty()); let Some(models) = models else { - if alias_row(input).is_some() { + if needs_listing(input) { return Err(Fail::runtime( "error: could not list models with `agy models` (run it directly to see why).\n aliases need that list; pass the full model name instead.", )); @@ -332,7 +584,7 @@ pub(crate) fn resolve(agy: &Agy, input: &str) -> Result { pub(crate) fn empty_value_error(agy: Option<&Agy>) -> Fail { let models = agy.and_then(list_models); Fail::usage(format!( - "error: --model requires a non-empty value (e.g. --model pro)\n{}", + "error: --model requires a non-empty value (e.g. --model gemini)\n{}", format_model_table(models.as_deref()).trim_end() )) } @@ -341,11 +593,18 @@ pub(crate) fn empty_value_error(agy: Option<&Agy>) -> Fail { mod tests { use super::*; + /// `agy models` as agy 1.5.16 printed it on 2026-11-25, plus an older + /// Flash and a non-thinking Sonnet to exercise the tie rules. fn listing() -> Vec { parse_model_list( "Fetching available models...\n\ + gemini-4-hydrogen-high\tGemini 4 Hydrogen (High)\n\ + gemini-4-hydrogen-xhigh\tGemini 4 Hydrogen (XHigh)\n\ + gemini-4-hydrogen-medium\tGemini 4 Hydrogen (Medium)\n\ + gemini-4-hydrogen-low\tGemini 4 Hydrogen (Low)\n\ gemini-3.5-flash-high\tGemini 3.5 Flash (High)\n\ gemini-3.8-flash-high\tGemini 3.8 Flash (High)\n\ + gemini-3.8-flash-medium\tGemini 3.8 Flash (Medium)\n\ gemini-3.8-flash-low\tGemini 3.8 Flash (Low)\r\n\ claude-sonnet-4-6\tClaude Sonnet 4.6\n\ claude-sonnet-4-6-thinking\tClaude Sonnet 4.6 (Thinking)\n\ @@ -358,15 +617,15 @@ mod tests { #[test] fn parses_the_real_agy_1_5_16_listing() { let m = listing(); - assert_eq!(m.len(), 7); + assert_eq!(m.len(), 12); assert_eq!( m[0], Model { - id: "gemini-3.5-flash-high".into(), - name: "Gemini 3.5 Flash (High)".into() + id: "gemini-4-hydrogen-high".into(), + name: "Gemini 4 Hydrogen (High)".into() } ); - assert_eq!(m[2].name, "Gemini 3.8 Flash (Low)", "CRLF stripped"); + assert_eq!(m[7].name, "Gemini 3.8 Flash (Low)", "CRLF stripped"); } #[test] @@ -383,28 +642,91 @@ mod tests { } #[test] - fn aliases_pick_the_newest_in_family() { - let m = listing(); - assert_eq!( - resolve_from_list(&m, "flash").unwrap(), - "gemini-3.8-flash-high" - ); + fn gemini_names_parse() { + let g = |s: &str| parse_gemini(s).map(|g| (g.version, g.kind, g.level)); + let t = |v: &str, k: &str, l: &str| Some((v.into(), k.into(), l.into())); + assert_eq!(g("gemini 4 hydrogen (xhigh)"), t("4", "hydrogen", "xhigh")); + assert_eq!(g("gemini 3.8 flash (high)"), t("3.8", "flash", "high")); assert_eq!( - resolve_from_list(&m, "flash-high").unwrap(), - "gemini-3.8-flash-high" + g("gemini 3.8 flash lite (low)"), + t("3.8", "flash-lite", "low") ); - assert_eq!( - resolve_from_list(&m, "flash-low").unwrap(), - "gemini-3.8-flash-low" + assert_eq!(g("gemini 4 carbon"), t("4", "carbon", "")); + assert_eq!(g("gemini 4 (high)"), t("4", "", "high")); + assert_eq!(g("gemini 4"), t("4", "", "")); + assert_eq!(g("gemini flash (high)"), None, "no version"); + assert_eq!(g("gemini 3.8 flash (high) extra"), None); + assert_eq!(g("gemini 3.8 flash (very high)"), None); + assert_eq!(g("gemini 3.8 fl@sh (high)"), None); + assert_eq!(g("gemini 3. flash (high)"), None, "strict version"); + assert_eq!(g("claude opus 4.6"), None); + } + + #[test] + fn gemini_aliases_parse() { + let a = |s: &str| parse_gemini_alias(s); + let k = |kind: Option<&str>, level: Option<&'static str>| { + Some(GeminiAlias { + kind: kind.map(str::to_string), + level, + }) + }; + assert_eq!(a("gemini"), k(None, None)); + assert_eq!(a("gemini-xhigh"), k(None, Some("xhigh"))); + assert_eq!(a("hydrogen"), k(Some("hydrogen"), None)); + assert_eq!(a("flash-med"), k(Some("flash"), Some("medium"))); + assert_eq!(a("flash-lite"), k(Some("flash-lite"), None)); + assert_eq!(a("flash-lite-low"), k(Some("flash-lite"), Some("low"))); + assert_eq!(a("high"), k(Some("high"), None), "a lone level is a kind"); + assert_eq!(a("-low"), None); + assert_eq!(a("flash--low"), None); + assert_eq!(a("gemini 4 hydrogen"), None); + } + + #[test] + fn aliases_pick_the_newest_in_family() { + let m = listing(); + let r = |s: &str| resolve_from_list(&m, s).unwrap(); + assert_eq!(r("gemini"), "gemini-4-hydrogen-high"); + assert_eq!(r("gemini-low"), "gemini-4-hydrogen-low"); + assert_eq!(r("hydrogen"), "gemini-4-hydrogen-high"); + assert_eq!(r("Hydrogen-XHigh"), "gemini-4-hydrogen-xhigh"); + assert_eq!(r("hydrogen-med"), "gemini-4-hydrogen-medium"); + assert_eq!(r("flash"), "gemini-3.8-flash-high"); + assert_eq!(r("flash-high"), "gemini-3.8-flash-high"); + assert_eq!(r("flash-low"), "gemini-3.8-flash-low"); + assert_eq!(r("OPUS"), "claude-opus-4-6-thinking"); + assert_eq!(r("gpt-oss"), "gpt-oss-120b-medium"); + } + + #[test] + fn a_new_kind_works_without_a_code_change() { + let m = parse_model_list( + "h\tGemini 4 Hydrogen (High)\nc\tGemini 4.1 Carbon (High)\ncl\tGemini 4.1 Carbon (Low)\n", ); - assert_eq!( - resolve_from_list(&m, "OPUS").unwrap(), - "claude-opus-4-6-thinking" + assert_eq!(resolve_from_list(&m, "carbon").unwrap(), "c"); + assert_eq!(resolve_from_list(&m, "carbon-low").unwrap(), "cl"); + assert_eq!(resolve_from_list(&m, "gemini").unwrap(), "c", "4.1 > 4"); + } + + #[test] + fn gemini_ties() { + // Same version: a big model beats Flash for `gemini`; listing order + // decides between two big ones. + let m = parse_model_list( + "f\tGemini 4 Flash (High)\nh\tGemini 4 Hydrogen (High)\nc\tGemini 4 Carbon (High)\n", ); - assert_eq!( - resolve_from_list(&m, "gpt-oss").unwrap(), - "gpt-oss-120b-medium" + assert_eq!(resolve_from_list(&m, "gemini").unwrap(), "h"); + // No level given: High beats XHigh and an unlabelled model. + let m = parse_model_list( + "x\tGemini 4 Neon (XHigh)\nn\tGemini 4 Neon\nh\tGemini 4 Neon (High)\n", ); + assert_eq!(resolve_from_list(&m, "neon").unwrap(), "h"); + let m = parse_model_list("x\tGemini 4 Neon (XHigh)\nl\tGemini 4 Neon (Low)\n"); + assert_eq!(resolve_from_list(&m, "neon").unwrap(), "x"); + // A newer version beats a preferred level. + let m = parse_model_list("a\tGemini 3.8 Flash (High)\nb\tGemini 3.10 Flash (Low)\n"); + assert_eq!(resolve_from_list(&m, "flash").unwrap(), "b", "3.10 > 3.8"); } #[test] @@ -436,6 +758,10 @@ mod tests { resolve_from_list(&m, "GPT-OSS-120B-MEDIUM").unwrap(), "gpt-oss-120b-medium" ); + assert_eq!( + resolve_from_list(&m, "gemini 4 hydrogen (xhigh)").unwrap(), + "gemini-4-hydrogen-xhigh" + ); // An id that is also alias-shaped resolves to itself, not the family. let m2 = parse_model_list( "flash\tSome Custom Model\ngemini-9-flash-high\tGemini 9 Flash (High)\n", @@ -446,29 +772,23 @@ mod tests { #[test] fn unknown_and_unavailable_family_errors() { let m = listing(); + let e = |s: &str| resolve_from_list(&m, s).unwrap_err(); + assert!(e("nope").contains("unknown model 'nope'")); + assert!(e("carbon").contains("unknown model 'carbon'")); + assert!(e("pro").contains("no matching model")); + assert!(e("pro").contains("expected: newest Gemini Pro)")); + assert!(e("pro-low").contains("expected: newest Gemini Pro (Low)")); + assert!(e("flash-xhigh").contains("expected: newest Gemini Flash (XHigh)")); + assert!(e("opus-low").contains("unknown model")); assert!( - resolve_from_list(&m, "nope") + resolve_from_list(&[], "gemini") .unwrap_err() - .contains("unknown model 'nope'") - ); - assert!( - resolve_from_list(&m, "pro") - .unwrap_err() - .contains("no matching model") + .contains("newest Gemini (any kind)") ); } #[test] - fn family_matching_is_exact() { - let f = Family::Gemini { - tier: "flash", - level: "high", - }; - assert!(f.matches("gemini 3.8 flash (high)")); - assert!(!f.matches("gemini 3.8 flash (high) extra")); - assert!(!f.matches("gemini 3.8 flash lite (high)")); - assert!(!f.matches("gemini flash (high)")); - assert!(!f.matches("gemini 4 neon (high)")); + fn claude_and_gpt_family_matching_is_exact() { let c = Family::Claude { kind: "opus" }; assert!(c.matches("claude opus 4.6")); assert!(c.matches("claude opus 4.6 (thinking)")); @@ -484,16 +804,39 @@ mod tests { fn table_shows_resolved_and_unavailable_aliases() { let t = format_model_table(Some(&listing())); assert!(t.starts_with("Aliases (case-insensitive), resolved against `agy models`:\n")); - // Byte-identical to the 0.8.x/0.9-wip bash wrapper's live output. - assert!(t.contains(" flash, flash-high -> Gemini 3.8 Flash (High)\n")); + assert!(t.contains(" gemini -> Gemini 4 Hydrogen (High)\n")); + assert!(t.contains( + " hydrogen -> Gemini 4 Hydrogen (High) [levels: xhigh, high, medium, low]\n" + )); assert!(t.contains( - " pro, pro-high -> (not available: newest Gemini Pro (High))\n" + " flash -> Gemini 3.8 Flash (High) [levels: high, medium, low]\n" )); - assert!(t.contains("-> (not available: newest Gemini Pro (High))")); + assert!( + t.contains(" pro -> (not available: newest Gemini Pro)\n") + ); + assert!(t.contains(" opus, claude-opus -> Claude Opus 4.6 (Thinking)\n")); + assert!( + t.find("hydrogen ").unwrap() < t.find("flash ").unwrap(), + "newest kind first" + ); + assert!(t.contains("level suffix")); assert!(t.contains(" Gemini 3.8 Flash (Low) gemini-3.8-flash-low\n")); let u = format_model_table(None); assert!(u.contains("could not be read")); assert!(u.contains("-> newest Claude Opus")); + assert!(u.contains("")); + } + + #[test] + fn only_alias_shaped_inputs_need_the_listing() { + assert!(needs_listing("gemini")); + assert!(needs_listing("flash-low")); + assert!(needs_listing("opus")); + assert!( + !needs_listing("hydrogen"), + "may be a model name; agy decides" + ); + assert!(!needs_listing("Some Future Model")); } #[cfg(unix)]