Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.
TypeScript
fix(byoa): a failing model-list CLI is not a catalog
zhuangxialied458ad4930b2
diff --git a/server/src/__tests__/agents-computer-model-catalog.test.ts b/server/src/__tests__/agents-computer-model-catalog.test.tsindex 9161487..6cc1394 100644--- a/server/src/__tests__/agents-computer-model-catalog.test.ts+++ b/server/src/__tests__/agents-computer-model-catalog.test.ts@@ -121,3 +121,82 @@ test('Antigravity catalog parses tab-separated models, ignores fetching banner,{ id: 'claude-sonnet-4-6', label: 'Claude Sonnet 4.6 (Thinking)', description: null, recommendedFor: ['big'] },])})++// ─── a failing CLI is not a catalog ─────────────────────────────────────────+//+// `runText` folds stderr into stdout and ignores the exit status, so whatever a+// CLI printed instead of a model list lands in the parser. The exit status+// would not have caught it either: measured against a real cursor-agent, an+// account with nothing provisioned prints a sentence and exits 0.++test('Cursor catalog does not turn "no models" prose into a model', () => {+ // Verbatim from `cursor-agent models` on an account with nothing provisioned+ // (exit code 0). This used to parse to a model with the id "No".+ assert.deepEqual(parseListedModels('No models available for this account.\n', 'cursor'), [])+})++test('Antigravity catalog does not turn an error into a model', () => {+ const output = [+ 'Error: not authenticated. Run `antigravity login`.',+ 'Failed to fetch models: connect ETIMEDOUT',+ ].join('\n')+ assert.deepEqual(parseListedModels(output, 'antigravity'), [])+})++test('a model id is the whole column, so prose cannot be one', () => {+ // The rule carries no vendor's error wording on purpose — the next CLI's+ // phrasing, in a locale we have never seen, fails the same test.+ assert.deepEqual(parseListedModels('Es sind keine Modelle verfügbar.', 'cursor'), [])+ assert.deepEqual(parseListedModels('该账户没有可用的模型', 'cursor'), [])+ // …while a genuine id still parses, bare word or not.+ assert.deepEqual(parseListedModels('auto\ngpt-5.5\n', 'cursor').map((m) => m.id), ['auto', 'gpt-5.5'])+})++test('Antigravity catalog reads space-aligned columns, not just tabs', () => {+ // A column separator is a tab OR a run of 2+ spaces; a sentence uses single+ // spaces. Reading the wider separator means the label is the label rather+ // than the whole line repeated.+ assert.deepEqual(parseListedModels('gemini-3.8-flash-high Gemini 3.8 Flash (High)', 'antigravity'), [+ { id: 'gemini-3.8-flash-high', label: 'Gemini 3.8 Flash (High)', description: null, recommendedFor: ['small'] },+ ])+})++async function stubEngineCli(name: string, stdout: string): Promise<{ bin: string; cleanup: () => Promise<void> }> {+ const root = await mkdtemp(join(tmpdir(), `cumora-${name}-catalog-`))+ const bin = join(root, name)+ await writeFile(bin, `#!/bin/sh\necho ${JSON.stringify(stdout)}\nexit 0\n`, { mode: 0o755 })+ return { bin, cleanup: () => rm(root, { recursive: true, force: true }) }+}++test('a CLI that listed nothing offers nothing, not a model named after its excuse', async () => {+ // End to end through the real dispatch. Cursor has no preset — cumora takes+ // its whole catalog from the CLI — so before the fix the picker's only entry+ // was "No", and picking it would have run `--model No`.+ const { bin, cleanup } = await stubEngineCli('cursor-agent', 'No models available for this account.')+ try {+ clearModelCatalogCache()+ const catalog = await discoverEngineModelCatalog('cursor', bin, true)+ assert.deepEqual(catalog.models, [])+ assert.equal(catalog.source, 'presets', 'a CLI that listed nothing was treated as having listed models')+ } finally {+ clearModelCatalogCache()+ await cleanup()+ }+})++test('an engine with a preset keeps it when its CLI fails to list', async () => {+ // Discovered models are merged AHEAD of the preset, so a parsed error line+ // does not just add noise — it takes the top of the picker and drops the+ // engine's real default.+ const { bin, cleanup } = await stubEngineCli('antigravity', 'Error: not authenticated. Run antigravity login.')+ try {+ clearModelCatalogCache()+ const catalog = await discoverEngineModelCatalog('antigravity', bin, true)+ assert.equal(catalog.source, 'presets')+ assert.equal(catalog.models[0]?.id, 'gemini-3.8-flash-high')+ assert.equal(catalog.models.some((model) => /^Error/.test(model.id)), false)+ } finally {+ clearModelCatalogCache()+ await cleanup()+ }+})diff --git a/server/src/agents/computer/model-catalog.ts b/server/src/agents/computer/model-catalog.tsindex c8691cb..ed78d72 100644--- a/server/src/agents/computer/model-catalog.ts+++ b/server/src/agents/computer/model-catalog.ts@@ -216,6 +216,40 @@ function runText(command: string, args: string[]): Promise<string> {})}+/** Split a listing line into its id column and whatever follows. Columns are+ * separated by a tab or a run of two or more spaces — how a CLI lays out a+ * table. Single spaces are how a sentence is written, so prose stays in one+ * piece and `modelIdToken` can reject it whole. */+function splitIdColumn(line: string): [string, string] {+ const stripped = line.replace(/^[*✓>•-]+\s*/, '')+ const sep = stripped.search(/\t| {2,}/)+ if (sep < 0) return [stripped.trim(), '']+ return [stripped.slice(0, sep).trim(), stripped.slice(sep).trim()]+}++/** The model id in a listing line's id column, or null when that column is not+ * an id at all.+ *+ * `runText` folds stderr into stdout and ignores the exit status, so whatever+ * a CLI printed when it could not list models arrives here as if it were a+ * catalog — and the exit status would not have saved us. Measured against a+ * real cursor-agent: an account with nothing provisioned prints+ * "No models available for this account." and exits 0. That line used to+ * become a selectable model with the id "No", merged AHEAD of the built-in+ * preset, so the picker offered "No" and the real defaults vanished.+ *+ * An id occupies its whole column — `auto`, `gpt-5.5`, `gemini-3.8-flash-high`+ * — and prose does not. That test needs no vendor's error wording, which is+ * the point: the next CLI's phrasing, in a locale we have never seen, still+ * fails it. */+function modelIdToken(column: string): string | null {+ if (!column || /\s/.test(column)) return null+ // "Error:", "Warning:" — a bare word wearing sentence punctuation, which can+ // survive the column rule when a CLI aligns its message.+ if (/^[a-z]+[.:,;!?]+$/i.test(column)) return null+ return column.match(/^[a-z0-9][\w./:@+-]*$/i)?.[0] ?? null+}+/** Parse model-list output shared by OpenCode, pi, Cursor and Antigravity. Exported so new* adapters can add fixtures without spawning a real account-bound CLI. */export function parseListedModels(text: string, style: 'provider' | 'pi' | 'cursor' | 'antigravity'): EngineModelOption[] {@@ -237,10 +271,8 @@ export function parseListedModels(text: string, style: 'provider' | 'pi' | 'curs}}} else if (style === 'antigravity') {- const tabIdx = line.indexOf('\t')- const idPart = (tabIdx >= 0 ? line.slice(0, tabIdx) : line).trim()- const labelPart = (tabIdx >= 0 ? line.slice(tabIdx + 1) : idPart).trim()- const candidate = idPart.replace(/^[*✓>•-]+\s*/, '').match(/^([a-z0-9][\w./:@+-]*)/i)?.[1] ?? null+ const [idPart, labelPart] = splitIdColumn(line)+ const candidate = modelIdToken(idPart)if (candidate) {id = candidatelabel = labelPart || candidate@@ -253,7 +285,7 @@ export function parseListedModels(text: string, style: 'provider' | 'pi' | 'cursif (recs.length) recommendedFor = recs}} else {- const candidate = line.replace(/^[*✓>•-]+\s*/, '').match(/^([a-z0-9][\w./:@+-]*)/i)?.[1] ?? null+ const candidate = modelIdToken(splitIdColumn(line)[0])if (candidate && !/^(available|current|default|name|model)$/i.test(candidate)) id = candidate}const normalized = clean(id, 160)