Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [2.9.0] - 2026-11-09

### Changed

- **A new model family no longer needs a release.** Discovery recognised tiered families from a list (`gemini-4-argon`, `claude-sonnet/opus-5-5`) and a fixed tier vocabulary (`low|medium|high|max`). Both are learned from the catalog now: ids that share a base and differ by a thinking suffix group into one family with its variants, and the request path builds `family-<tier>` from what discovery recorded instead of matching a name list. A family that debuts `minimal` — Gemini 4 Hyperion advertises `hyperion-minimal|low|medium|high` — or a name nobody has seen works the day the account lists it.
- **Forward-only stays enforced, generically.** A versioned line still has to be newer than the curated floor, and an unknown suffix is only trusted when the catalog also lists the plain base: without that, `gemini-2.5-flash` and `gemini-2.5-pro` would group as one model with `flash` and `pro` variants.
- `docs/MODEL-VARIANTS.md` and both READMEs describe the rule instead of listing the families it covers.

## [2.8.4] - 2026-11-09

### Fixed
Expand Down
9 changes: 6 additions & 3 deletions README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ quejarse, por eso se queda documentado para quien tenga uno que funcione.
> [!WARNING]
> **Gemini 4 Argon y los dos Claude 5.5 gastan cuota mucho más rápido** que el resto de la lista: un solo turno largo puede costar lo que un día entero de Gemini 3.8 Flash. Trabaja en `low` / `medium` y guarda `high` / `max` para lo difícil.

Los cuatro primeros están hardcodeados. Argon y la familia 5.5 llegan por `model_discovery`,
que registra lo que exponga el catálogo de la cuenta — sin esperar una release. Los límites
de tokens salen del backend.
Los cuatro primeros están hardcodeados. Todo lo demás lo **aprende del catálogo de la cuenta**
`model_discovery`: los ids que comparten base y solo cambian por un sufijo de razonamiento se
vuelven una entrada con sus variantes, y el vocabulario de sufijos sale de lo que anuncia el
backend — así una familia que debute `minimal`, o un nombre que nadie ha visto, funciona sin
publicar el plugin. Las líneas con versión siguen teniendo que ser más nuevas que el piso
curado; el catálogo nunca resucita una generación vieja. Los límites de tokens salen del backend.

<details>
<summary><b>Configuración manual de modelos (Opcional / Avanzado)</b></summary>
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,12 @@ complaint, which is why it stays documented for setups that ship a working one.
> [!WARNING]
> **Gemini 4 Argon and both Claude 5.5 models spend quota much faster** than the rest of the list: a single long turn can cost what a whole day of Gemini 3.8 Flash costs. Work on `low` / `medium` and keep `high` / `max` for the hard problems.

The first four are hardcoded. Argon and the 5.5 family arrive through `model_discovery`,
which registers whatever the account's own catalog exposes — no release needed. Token
limits come from the backend.
The first four are hardcoded. Everything after them is **learned from the account's
catalog** by `model_discovery`: ids that share a base and differ by a thinking suffix
become one entry with its variants, and the suffix vocabulary comes from what the backend
advertises — so a family that debuts `minimal`, or a name nobody has seen yet, works
without a plugin release. Versioned lines still have to be newer than the curated floor;
the catalog never resurrects an older generation. Token limits come from the backend.

<details>
<summary><b>Manual models configuration (Optional / Advanced)</b></summary>
Expand Down
13 changes: 13 additions & 0 deletions docs/MODEL-VARIANTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ Gemini 3 models use string-based thinking levels. Available levels differ by mod

> **Note (2026-10-13):** Gemini 3.7 Flash, Gemini 3.6 Flash and Gemini 3.1 Pro moved to **Google AI Ultra / Enterprise-only** and are no longer registered by this plugin for consumer plans. Gemini 3.8 Flash is the only Gemini model available on consumer plans.
>
## Families are learned, not listed

Discovery groups the catalog by structure, not by name: ids that share a base and differ
only by a thinking suffix (`hyperion-minimal`, `hyperion-low`, ...) become one entry with a
variant per suffix, and the request path builds `family-<tier>` from what discovery
recorded. The suffix vocabulary is the backend's, so a tier that did not exist when this
plugin was built works the day an account lists it.

Two guards keep it forward-only. A versioned line (`gemini-3.5-flash`, `claude-opus-4-6`)
still has to be newer than the curated floor. And an unknown suffix is only read as a tier
when the catalog also lists the plain base, so `gemini-2.5-flash` and `gemini-2.5-pro`
never collapse into one model with `flash` and `pro` variants.

> **Gemini 4 ("Argon") needs no plugin release.** Its ids are `gemini-4-argon-{low,medium,high}` and the grant is **per account** (measured 2026-10-31: a `free-tier` account had it, other accounts only received the `gemini-4-argon-disabled` placeholder). It is deliberately not in the curated catalog: enable [`model_discovery`](CONFIGURATION.md#model-discovery) and one `antigravity-gemini-4-argon` entry with `low`/`medium`/`high` variants is registered for the accounts that have it. Requests must carry the CLI User-Agent, which the plugin sets automatically.

---
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opencode-antigravity-auth",
"version": "2.8.4",
"version": "2.9.0",
"description": "Google Antigravity IDE OAuth auth plugin for OpenCode v2 - access Gemini 4 Argon, 3.8 Flash, and Claude models using Google credentials",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
22 changes: 22 additions & 0 deletions src/plugin/config/model-discovery.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { forgetTieredFamilies } from "./tiered-families"
import { describe, expect, it, vi, beforeEach } from "vitest";

vi.mock("../quota", () => ({
Expand Down Expand Up @@ -246,3 +247,24 @@ describe("collectDiscoveredModels", () => {
expect(fetchAvailableModels).not.toHaveBeenCalled();
});
});

describe("buildDiscoveredModels with a family nobody taught the plugin", () => {
it("groups a new family from the catalog and remembers how it encodes tiers", () => {
const models = buildDiscoveredModels([
"hyperion",
"hyperion-minimal",
"hyperion-low",
"hyperion-medium",
"hyperion-high",
]);
const family = models["antigravity-hyperion"];
expect(family).toBeDefined();
expect(Object.keys(family!.variants ?? {})).toEqual(["minimal", "low", "medium", "high"]);
forgetTieredFamilies();
});

it("does not read two different model lines as tiers", () => {
const models = buildDiscoveredModels(["gemini-2.5-pro", "gemini-2.5-flash"]);
expect(models).toEqual({});
});
});
72 changes: 63 additions & 9 deletions src/plugin/config/model-discovery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { OpencodeModelDefinition, OpencodeModelDefinitions, ModelVariant } from "./models";
import { compareTiers, groupTieredFamilies, rememberTieredFamily } from "./tiered-families.js"
import { OPENCODE_WHITELIST_MODELS } from "./models";
import { fetchAvailableModels } from "../quota";
import { createLogger } from "../logger";
Expand Down Expand Up @@ -231,7 +232,7 @@ export function displayNameForModelId(id: string): string {
export function buildDiscoveredModelDefinition(
id: string,
metadata?: DiscoveredModelMetadata,
tiers?: readonly TierName[],
tiers?: readonly string[],
): OpencodeModelDefinition {
const lower = id.toLowerCase();
const isClaude = lower.startsWith("claude-");
Expand Down Expand Up @@ -287,20 +288,70 @@ export function buildDiscoveredModelDefinition(
* a `low|medium|high` variant picker, and the same for
* `claude-sonnet-5-5-*` / `claude-opus-5-5-*`.
*/
/**
* The same forward-only rule the curated floors encode, applied to families that
* were learned from the catalog: a versioned line has to be newer than the
* curated one, and a line with no version in its name (Argon, Hyperion, Carbon)
* is taken as it comes.
*/
function isForwardOnly(base: string): boolean {
const gemini = /^gemini-(\d+)(?:[.-](\d+))?/.exec(base);
if (gemini) {
const [major, minor] = [Number(gemini[1]), Number(gemini[2] ?? 0)];
const floor = DISCOVERY_GEMINI_FLASH_FLOOR;
return major > floor.major || (major === floor.major && minor > floor.minor);
}
const claude = /^claude-(?:sonnet|opus)-(\d+)(?:-(\d+))?/.exec(base);
if (claude) {
const [major, minor] = [Number(claude[1]), Number(claude[2] ?? 0)];
const floor = DISCOVERY_CLAUDE_FLOOR;
return major > floor.major || (major === floor.major && minor > floor.minor);
}
return true;
}

export function buildDiscoveredModels(
backendIds: Iterable<string>,
metadata: Record<string, DiscoveredModelMetadata> = {},
): OpencodeModelDefinitions {
const groups = new Map<string, { tiers: Set<TierName>; ids: Set<string>; sawTierless: boolean }>();
const groups = new Map<string, { tiers: Set<string>; ids: Set<string>; sawTierless: boolean }>();

for (const rawId of backendIds) {
const id = typeof rawId === "string" ? rawId.trim().toLowerCase() : "";
if (!isDiscoverableModelId(id)) continue;
const all = [...backendIds].map((rawId) => (typeof rawId === "string" ? rawId.trim().toLowerCase() : ""));
// Families the catalog itself splits by tier. Learned from the ids, not from a
// list: a family that debuts a suffix nobody knew (`hyperion-minimal`) groups
// the same way as the curated ones.
const learned = groupTieredFamilies(all);

for (const id of all) {
if (!id) continue;
if (isCoveredByCuratedCatalog(id)) continue;

const family = familyIdOf(id);
const tier = tierOf(id);
const group = groups.get(family) ?? { tiers: new Set<TierName>(), ids: new Set<string>(), sawTierless: false };
let family = familyIdOf(id);
let tier: string | undefined = tierOf(id);
let learnedFamily = false;
for (const [base, tiers] of learned) {
if (id === base) {
family = base;
tier = undefined;
learnedFamily = true;
break;
}
if (id.startsWith(`${base}-`)) {
const suffix = id.slice(base.length + 1);
if (tiers.includes(suffix)) {
family = base;
tier = suffix;
learnedFamily = true;
break;
}
}
}

if (!learnedFamily && !isDiscoverableModelId(id)) continue;
if (learnedFamily && DISCOVERY_DENYLIST.some((pattern) => pattern.test(id))) continue;
if (learnedFamily && !isForwardOnly(family)) continue;

const group = groups.get(family) ?? { tiers: new Set<string>(), ids: new Set<string>(), sawTierless: false };
if (tier) {
group.tiers.add(tier);
} else {
Expand All @@ -312,7 +363,7 @@ export function buildDiscoveredModels(

const discovered: OpencodeModelDefinitions = {};
for (const [family, group] of groups) {
const observedTiers = TIER_ORDER.filter((tier) => group.tiers.has(tier));
const observedTiers = [...group.tiers].sort(compareTiers);
// Limits are declared per concrete id, so take them from whichever id in the
// group actually carries them (they are identical across tiers).
const groupMetadata: DiscoveredModelMetadata | undefined =
Expand All @@ -322,6 +373,9 @@ export function buildDiscoveredModels(
.find((entry): entry is DiscoveredModelMetadata => Boolean(entry && (entry.maxTokens || entry.maxOutputTokens)));
const definition = buildDiscoveredModelDefinition(family, groupMetadata, observedTiers);
discovered[`antigravity-${family}`] = definition;
// The request path builds `family-<tier>` from this, so recording it here is
// what keeps a brand new family working without a release.
if (observedTiers.length > 0) rememberTieredFamily(family, observedTiers);
}
return discovered;
}
Expand Down
43 changes: 43 additions & 0 deletions src/plugin/config/tiered-families.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { beforeEach, describe, expect, test } from "vitest"
import { compareTiers, forgetTieredFamilies, groupTieredFamilies, rememberTieredFamily, tieredFamilyOf } from "./tiered-families"

describe("TieredFamilies.groupTieredFamilies", () => {
test("learns a family from the catalog, including tiers nobody knew", () => {
const grouped = groupTieredFamilies([
"hyperion",
"hyperion-minimal",
"hyperion-low",
"hyperion-medium",
"hyperion-high",
])
expect(grouped.get("hyperion")).toEqual(["minimal", "low", "medium", "high"])
})

test("groups suffixed siblings even when the base is not listed", () => {
const grouped = groupTieredFamilies(["claude-sonnet-5-5-low", "claude-sonnet-5-5-high"])
expect(grouped.get("claude-sonnet-5-5")).toEqual(["low", "high"])
})

test("leaves a one-off suffix alone", () => {
const grouped = groupTieredFamilies(["claude-opus-4-6-thinking", "gemini-3-flash"])
expect(grouped.size).toBe(0)
})
})

describe("TieredFamilies.compareTiers", () => {
test("orders known tiers and keeps unknown ones after them", () => {
const tiers = ["high", "ultra", "minimal", "low"].sort(compareTiers)
expect(tiers).toEqual(["minimal", "low", "high", "ultra"])
})
})

describe("TieredFamilies.tieredFamilyOf", () => {
beforeEach(() => forgetTieredFamilies())

test("resolves the family from a plugin model name or a backend id", () => {
rememberTieredFamily("hyperion", ["minimal", "low", "high"])
expect(tieredFamilyOf("antigravity-hyperion")).toEqual({ base: "hyperion", tiers: ["minimal", "low", "high"] })
expect(tieredFamilyOf("hyperion-high")).toEqual({ base: "hyperion", tiers: ["minimal", "low", "high"] })
expect(tieredFamilyOf("gemini-3.8-flash")).toBeUndefined()
})
})
108 changes: 108 additions & 0 deletions src/plugin/config/tiered-families.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
export * as TieredFamilies from "./tiered-families.js"

/**
* The backend advertises a thinking tier as an id suffix: `gemini-4-argon-high`,
* `claude-sonnet-5-5-max`, and, as new families land, suffixes nobody taught the
* plugin (`hyperion-minimal`).
*
* Two things are learned from the catalog at discovery time instead of being
* listed here:
*
* - the tier vocabulary, so a family that debuts `minimal` or `ultra` shows up;
* - how each family encodes its tiers, so the request path can build the right
* backend id without a hardcoded list of family names.
*/

/** Order used to lay out the variant picker; unknown tiers follow, alphabetically. */
const KNOWN_ORDER = ["minimal", "low", "medium", "high", "max"] as const

/** Lower is cheaper. Unknown tiers sort after the known ones. */
export function compareTiers(a: string, b: string) {
const index = (tier: string) => {
const at = (KNOWN_ORDER as readonly string[]).indexOf(tier.toLowerCase())
return at === -1 ? KNOWN_ORDER.length : at
}
const [ia, ib] = [index(a), index(b)]
return ia === ib ? a.toLowerCase().localeCompare(b.toLowerCase()) : ia - ib
}

/** family base -> tiers it was observed to advertise */
const families = new Map<string, string[]>()

export function rememberTieredFamily(base: string, tiers: readonly string[]) {
const key = base.toLowerCase()
const merged = new Set([...(families.get(key) ?? []), ...tiers.map((tier) => tier.toLowerCase())])
families.set(key, [...merged].sort(compareTiers))
}

export function forgetTieredFamilies() {
families.clear()
}

export interface TieredFamily {
readonly base: string
readonly tiers: readonly string[]
}

/**
* Family a model belongs to, when discovery saw the backend split it by tier.
* `antigravity-gemini-4-argon` resolves to `gemini-4-argon` with its tiers.
*/
export function tieredFamilyOf(model: string): TieredFamily | undefined {
const normalized = model.toLowerCase().replace(/^antigravity-/, "")
const tiers = families.get(normalized)
if (tiers && tiers.length > 0) return { base: normalized, tiers }

// A variant name may arrive with the tier still attached (`gemini-4-argon-high`).
for (const [base, seen] of families) {
const suffix = normalized.startsWith(`${base}-`) ? normalized.slice(base.length + 1) : undefined
if (suffix && seen.includes(suffix)) return { base, tiers: seen }
}
return undefined
}

/**
* Splits catalog ids into `base -> tiers` for every family the backend named more
* than once. A base counts when the catalog lists it on its own (`hyperion`) or
* when at least two ids end in a different single-word suffix
* (`hyperion-low`, `hyperion-high`), which is what keeps one-off ids such as
* `claude-opus-4-6-thinking` from being read as a tier.
*/
export function isKnownTier(suffix: string) {
return (KNOWN_ORDER as readonly string[]).includes(suffix.toLowerCase())
}

export function groupTieredFamilies(ids: Iterable<string>): Map<string, string[]> {
const byId = new Set<string>()
for (const raw of ids) {
const id = typeof raw === "string" ? raw.trim().toLowerCase() : ""
if (id) byId.add(id)
}

const candidates = new Map<string, Set<string>>()
for (const id of byId) {
const cut = id.lastIndexOf("-")
if (cut <= 0) continue
const base = id.slice(0, cut)
const suffix = id.slice(cut + 1)
if (!/^[a-z][a-z0-9]*$/.test(suffix)) continue
// Only a known tier, or a suffix next to a base the catalog lists on its own,
// reads as a tier. Without that, `gemini-2.5-flash` and `gemini-2.5-pro` would
// group as one family with `flash` and `pro` as variants.
if (!isKnownTier(suffix) && !byId.has(base)) continue
const set = candidates.get(base) ?? new Set<string>()
set.add(suffix)
candidates.set(base, set)
}

const grouped = new Map<string, string[]>()
for (const [base, tiers] of candidates) {
const ambiguous = [...tiers].some((tier) => !isKnownTier(tier));
// An unknown suffix is only trusted when the catalog also names the plain base
// (`hyperion` next to `hyperion-ultra`), never on its own.
if (ambiguous && !byId.has(base)) continue;
if (tiers.size < 2 && !byId.has(base)) continue;
grouped.set(base, [...tiers].sort(compareTiers))
}
return grouped
}
Loading
Loading