Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): fix the antigravity misroute and surface real refresh errors
Adam Eivy571101b78957
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 651d88d2bd..a9d52ab698 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -6,6 +6,8 @@## Cursor Agent provider- **[issue-3615] "Refresh Models" now works for Cursor, and pulls your account's real catalog.** The Cursor providers shipped with a hand-curated 27-model slice, and the Refresh button was hidden for them because nothing on the server could answer — so the only way to reach a model Cursor offers you but PortOS didn't list was to type the id into the provider's model list yourself. Refresh now asks the binary directly (`cursor-agent models`) and stores everything it reports: 177 ids on a current account, including the `-fast` priority-compute twin of most tiers, and Cursor's own `auto` router at the top. Because that catalog varies by account, plan, and binary version, it's the only authoritative answer — which is also why a refresh that can't reach `cursor-agent` (not installed, or not on the server's PATH) reports the failure and leaves your existing list untouched, rather than quietly re-saving the shipped 27 and telling you it refreshed. The button appears for both the CLI and TUI providers, since `--model` applies to interactive sessions too.+- **A failed "Refresh Models" now tells you what actually went wrong.** Every refresh failure — any provider, not just Cursor — used to surface as "Provider not found or not an API type", which is simply false when the provider exists and its type is fine; the real reason (the binary isn't on the server's PATH, the endpoint timed out, that CLI has no catalog to fetch) only ever reached the server log. The toast now carries the actual message. A model list that comes back legitimately empty still saves as empty — an empty answer and a failed one stay distinguishable, which is the whole reason a failed probe refuses to fall back to the shipped list.+- **A provider whose *name* mentions another vendor is no longer refreshed against the wrong catalog.** Refresh picked its fetcher by checking the display name for vendor words before checking which binary the provider actually runs. So naming a Cursor provider "Cursor Claude Opus", or an Antigravity provider "Antigravity Claude Sonnet 4.6" — the natural name for a second provider pinned to that model, and Antigravity's own catalog does list Claude models — silently replaced its model list with Anthropic's, ids those tools reject. In the Antigravity case it also dropped the "use agy's own configured default" entry while the provider was still set to it, which blanked the model dropdown and read as though nothing was selected. The binary a provider runs now decides, and only falls back to the name when no binary matches.## Added- **Cursor's agent CLI ships as a provider, in both CLI and TUI flavors.** `cursor-agent` is a harness-capable coding agent, but PortOS had no entry for it — using it meant hand-rolling a custom provider and guessing at its flags. It now ships as `cursor-cli` (headless one-shot) and `cursor-tui` (interactive PTY), mirroring the Codex/Antigravity/Grok/Kimi pairs. Both ship disabled, so nothing changes until you enable them, and once enabled they're selectable anywhere a process provider is — CoS agents, runners, pipeline stages, TUI sessions. The headless path runs `cursor-agent --print` with the prompt on stdin; the TUI path runs the interactive agent. Both inject `--force`, which is doing more work than the name suggests: besides auto-approving tool calls, it clears Cursor's workspace-trust gate, and without it `cursor-agent` prints "Workspace Trust Required" and exits — which in a fresh CoS worktree is every single run. The model list is a 27-entry slice of the account catalog (Composer, Claude, GPT, Gemini families), each id verified against the live binary; the default is Cursor's own `auto` router, so unlike Grok/Kimi/Antigravity no configured-default sentinel was needed. Cursor bakes reasoning effort into the model id (`…-thinking-high`, `…-xhigh`, `…-max`) rather than exposing a flag, so no Effort control is offered for it. Existing installs pick the pair up on restart via migration `231-cursor-providers`. If your account offers a model outside the shipped 27 (the full catalog runs to 177 ids, most of them `-fast` twins), "Refresh Models" pulls the whole list from the binary — see above.diff --git a/client/src/utils/providers.js b/client/src/utils/providers.jsindex efb02fe1c5..87db00b417 100644--- a/client/src/utils/providers.js+++ b/client/src/utils/providers.js@@ -187,7 +187,7 @@ export const supportsModelRefresh = (provider) => {// result — every arm here returns true — but the mirror is only readable, and// only stays checkable, if it matches the dispatch it claims to mirror.if (isCursorCommand(command)) return true;- if (name.includes('antigravity') || isAntigravityCommand(command)) return true;+ if (isAntigravityCommand(command)) return true;// Deliberately the RAW command string, not a basename: the server's claude// and gemini arms compare `provider.command === 'claude'` exactly. Matching// on basename here would re-open the same 404 in a new place — a renamed,@@ -195,6 +195,7 @@ export const supportsModelRefresh = (provider) => {// still refuses. Widening BOTH sides is tracked separately; until then the// mirror stays faithful rather than optimistic.return name.includes('claude') || command === 'claude'+ || name.includes('antigravity')|| name.includes('gemini') || command === 'gemini';}diff --git a/client/src/utils/providers.test.js b/client/src/utils/providers.test.jsindex d286ef9de3..8ff690bea0 100644--- a/client/src/utils/providers.test.js+++ b/client/src/utils/providers.test.js@@ -755,6 +755,17 @@ describe('supportsModelRefresh', () => {expect(supportsModelRefresh({ id: 'cursor-tui', type: 'tui', command: '/home/x/.local/bin/cursor-agent', name: 'renamed' })).toBe(true);});+ // Pins the `id === '<vendor>-tui'` half of each TUI arm's OR. Every other case+ // here matches on the COMMAND, so deleting those id clauses left the suite+ // green while a shipped TUI provider repointed at a wrapper script silently+ // lost its button (the server's TUI arms still serve it via the same id test).+ it('offers it for a shipped cursor-tui / antigravity-tui repointed at a wrapper', () => {+ expect(supportsModelRefresh({ id: 'cursor-tui', type: 'tui', command: '/opt/bin/cursor-wrap', name: 'Cursor Agent TUI' })).toBe(true);+ expect(supportsModelRefresh({ id: 'antigravity-tui', type: 'tui', command: '/opt/bin/agy-wrap', name: 'Antigravity TUI' })).toBe(true);+ // …but an unshipped id with an unrelated command still gets nothing.+ expect(supportsModelRefresh({ id: 'custom-tui', type: 'tui', command: '/opt/bin/cursor-wrap', name: 'Custom' })).toBe(false);+ });+it('does not offer it for a provider merely NAMED cursor, or for the GUI binary', () => {// "cursor" is an ordinary English word, and a bare `cursor` is the GUI// editor launcher — neither reaches the server's command-keyed arm.@@ -821,8 +832,9 @@ describe('supportsModelRefresh', () => {// Command-only, and ABOVE the name tests — the server orders it that way// so a renamed "Cursor Claude Opus" reaches the cursor fetcher.if (isCursorCommand(p.command)) return true;+ if (isAntigravityCommand(p.command)) return true;if (name.includes('claude') || p.command === 'claude') return true;- if (name.includes('antigravity') || isAntigravityCommand(p.command)) return true;+ if (name.includes('antigravity')) return true;if (name.includes('gemini') || p.command === 'gemini') return true;return false; // server throws → route 404s}diff --git a/server/lib/aiToolkit/internal/antigravity.test.js b/server/lib/aiToolkit/internal/antigravity.test.jsnew file mode 100644index 0000000000..c1d0ee6507--- /dev/null+++ b/server/lib/aiToolkit/internal/antigravity.test.js@@ -0,0 +1,75 @@+import { describe, it, expect } from 'vitest';+import { ANTIGRAVITY_CONFIGURED_DEFAULT, isAntigravityCommand, parseAntigravityModelList } from './antigravity.js';+// The toolkit SOURCE may not import out to server/lib (see ../CLAUDE.md); a test+// may, and this is the only way to actually pin the duplication it documents.+import { isAntigravityCommand as upstreamIsAntigravityCommand } from '../../antigravity.js';++// `agy models` prints one bare id per line. Shape reproduced from the real+// binary: a blank line, the ids, and (on some builds) a status/banner line the+// filter has to reject.+const REAL_OUTPUT = `+gemini-3.1-pro-high+gemini-3.1-pro+claude-sonnet-4-6+gpt-5.2-codex++`;++describe('parseAntigravityModelList', () => {+ // Success-path coverage for the parser extracted out of providers.js. Without+ // it, `agy models` had no test that ever fed the filter real output — only a+ // spawn-failure case — so narrowing the character class or dropping the+ // sentinel filter would have kept the whole suite green.+ it('extracts bare ids and drops blank lines', () => {+ expect(parseAntigravityModelList(REAL_OUTPUT)).toEqual([+ 'gemini-3.1-pro-high',+ 'gemini-3.1-pro',+ 'claude-sonnet-4-6',+ 'gpt-5.2-codex',+ ]);+ });++ it('drops banner/status prose — anything that is not a bare id', () => {+ const out = parseAntigravityModelList('Available models:\ngemini-3.1-pro\nTip: use --model <id>\n');+ expect(out).toEqual(['gemini-3.1-pro']);+ });++ it('drops the configured-default sentinel so the caller can re-prepend it once', () => {+ // The caller does `[SENTINEL, ...new Set(listed)]`. If the filter let the+ // sentinel through, it would appear twice on any build that lists it.+ const out = parseAntigravityModelList(`${ANTIGRAVITY_CONFIGURED_DEFAULT}\ngemini-3.1-pro\n`);+ expect(out).toEqual(['gemini-3.1-pro']);+ expect(out).not.toContain(ANTIGRAVITY_CONFIGURED_DEFAULT);+ });++ it('handles CRLF line endings', () => {+ expect(parseAntigravityModelList('gemini-3.1-pro\r\nclaude-sonnet-4-6\r\n'))+ .toEqual(['gemini-3.1-pro', 'claude-sonnet-4-6']);+ });++ it('accepts the punctuation real ids use, and rejects ids with spaces', () => {+ expect(parseAntigravityModelList('gpt-5.2-codex\nqwen2.5:7b\nvendor/model\nnot an id\n'))+ .toEqual(['gpt-5.2-codex', 'qwen2.5:7b', 'vendor/model']);+ });++ it('returns an empty list for blank and non-string input', () => {+ // The caller turns empty into a THROW, so this must not invent entries.+ expect(parseAntigravityModelList('')).toEqual([]);+ expect(parseAntigravityModelList('\n\n')).toEqual([]);+ expect(parseAntigravityModelList(null)).toEqual([]);+ expect(parseAntigravityModelList(undefined)).toEqual([]);+ });+});++describe('vendored copy stays in sync with server/lib/antigravity.js', () => {+ it('agrees with upstream on every command-matching case', () => {+ const cases = [+ 'agy', 'antigravity', '/opt/homebrew/bin/agy', 'C:\\Tools\\agy.exe', 'AGY',+ 'agy.cmd', 'claude', 'cursor-agent', '',+ ];+ for (const c of cases) {+ expect(isAntigravityCommand(c), `disagreement on ${JSON.stringify(c)}`)+ .toBe(upstreamIsAntigravityCommand(c));+ }+ });+});diff --git a/server/lib/aiToolkit/providers.js b/server/lib/aiToolkit/providers.jsindex eaee9eb963..f972aedd2f 100644--- a/server/lib/aiToolkit/providers.js+++ b/server/lib/aiToolkit/providers.js@@ -783,7 +783,21 @@ export function createProviderService(config = {}) {}} catch (error) {console.error(`Failed to refresh models for ${provider.name}:`, error.message);- return null;+ // RETHROW rather than collapsing to null. `null` means one specific+ // thing here — "no refreshable branch matched" — and the route turns it+ // into `404 Provider not found or not an API type`. Folding a fetcher+ // failure into that same null made the user's toast read "Provider not+ // found or not an API type" when the provider exists and its type is+ // fine, burying the actual cause (`'cursor-agent models' failed: …+ // ENOENT`) in the server log. That defeats the whole point of the+ // throw-don't-fall-back posture in `_execCliModelList`: it goes to the+ // trouble of refusing to persist a plausible-looking default precisely+ // so the user learns WHY the refresh failed.+ // 502, not 500: the failure is an upstream/vendor probe, not a bug here.+ // The other caller (localLlm's post-install fan-out) already catches and+ // logs per provider, so it is unaffected.+ error.status = error.status || 502;+ throw error;}if (models === null) {@@ -879,16 +893,29 @@ export function createProviderService(config = {}) {return await this._fetchCursorModels(provider);}+ // Antigravity's COMMAND test is hoisted for the same reason, and split from+ // its name test below to do it. It is path/exe-tolerant (`isAntigravityCommand`,+ // not `command === 'agy'`) so a provider configured with the absolute binary+ // path still refreshes; matches the TUI branch in refreshProviderModels.+ // Left fused below the claude name test, an `agy` provider named+ // "Antigravity Claude Sonnet 4.6" — the natural name for a second agy+ // provider, since agy's own catalog carries claude ids — got Anthropic's+ // static list persisted onto it AND lost the `antigravity-configured-default`+ // sentinel from `models` while `defaultModel` still pointed at it, which+ // blanks the model <select> and reads as "unset".+ if (isAntigravityCommand(provider.command)) {+ return await this._fetchAntigravityModels(provider);+ }+if (providerName.includes('claude') || provider.command === 'claude') {return await this._fetchAnthropicModels(provider);}- // Path/exe-tolerant (`isAntigravityCommand`, not `command === 'agy'`) so a- // provider configured with the absolute binary path still refreshes —- // otherwise the client's `isAntigravityProvider` gate offers the Refresh- // button and every click falls through to the throw below. Matches the- // TUI branch in refreshProviderModels.- if (providerName.includes('antigravity') || isAntigravityCommand(provider.command)) {+ // The NAME tests stay below the command tests above: they are the weaker+ // signal, so they only get a say once no command has claimed the provider.+ // `name: 'Claude via Antigravity'` + `command: 'claude'` therefore still+ // reaches Anthropic, which is the right answer for a claude binary.+ if (providerName.includes('antigravity')) {return await this._fetchAntigravityModels(provider);}@@ -896,7 +923,11 @@ export function createProviderService(config = {}) {return await this._fetchGeminiModels(provider);}- throw new Error('Model refresh not supported for this CLI provider');+ // 400, not the rethrow's 502 default: nothing upstream failed — this CLI+ // simply has no fetcher, which is a bad request, not a bad gateway.+ const unsupported = new Error('Model refresh not supported for this CLI provider');+ unsupported.status = 400;+ throw unsupported;},/**diff --git a/server/lib/aiToolkit/providers.test.js b/server/lib/aiToolkit/providers.test.jsindex cfc395f751..319adc016c 100644--- a/server/lib/aiToolkit/providers.test.js+++ b/server/lib/aiToolkit/providers.test.js@@ -620,11 +620,13 @@ describe('Provider Service', () => {});const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});- const result = await providerService.refreshProviderModels('antigravity-cli');+ // Throws with the REAL reason (and a 502) rather than collapsing to null,+ // which the route would have reported as "Provider not found or not an+ // API type" — misleading, since the provider exists and its type is fine.+ await expect(providerService.refreshProviderModels('antigravity-cli'))+ .rejects.toThrow(/'\/nonexistent\/path\/to\/agy models' failed/);errSpy.mockRestore();- // null = "nothing to persist"; the routes layer turns this into an error.- expect(result).toBeNull();// And the previously-stored list is untouched on disk.const after = await providerService.getProviderById('antigravity-cli');expect(after.models).toEqual(stored);@@ -883,6 +885,77 @@ describe('Provider Service', () => {expect(updated.models).toContain('gpt-5.3-codex-low-fast');});+ // Pins the `provider.id === CURSOR_TUI_ID` half of the TUI arm's OR. Every+ // other test reaches that arm via the COMMAND (writeFakeCursor's script is+ // named `cursor-agent`), so deleting the id clause left the whole suite+ // green while this case — a shipped cursor-tui the user repointed at a+ // wrapper script — silently lost its refresh.+ it.skipIf(process.platform === 'win32')('refreshes a shipped cursor-tui repointed at a wrapper command', async () => {+ const cursorPath = await writeFakeCursor(SAMPLE);+ const wrapper = join(TEST_DATA_DIR, 'cursor-wrap');+ await writeFile(wrapper, `#!/bin/sh\nexec "${cursorPath}" "$@"\n`);+ await chmod(wrapper, 0o755);++ await writeFile(join(TEST_DATA_DIR, 'providers.json'), JSON.stringify({+ activeProvider: 'cursor-tui',+ providers: {+ 'cursor-tui': {+ id: 'cursor-tui', name: 'Cursor Agent TUI', type: 'tui',+ command: wrapper, models: ['auto'], defaultModel: 'auto',+ },+ },+ }, null, 2));++ const updated = await providerService.refreshProviderModels('cursor-tui');+ expect(updated, 'the id clause on the TUI arm no longer matches').not.toBeNull();+ expect(updated.models).toContain('gpt-5.3-codex-low');+ });++ // The mirror of the cursor ordering fix, for antigravity: its COMMAND test+ // used to sit fused to its name test BELOW the claude name test, so an `agy`+ // provider named "Antigravity Claude Sonnet 4.6" (a natural name — agy's own+ // catalog carries claude ids) got Anthropic's static list persisted onto it+ // and lost the configured-default sentinel while defaultModel still pointed+ // at it, blanking the model <select>.+ it('routes an agy provider on its command even when the NAME says claude', async () => {+ const stored = ['antigravity-configured-default', 'gemini-3.1-pro-high'];+ await writeFile(join(TEST_DATA_DIR, 'providers.json'), JSON.stringify({+ activeProvider: 'antigravity-cli',+ providers: {+ 'antigravity-cli': {+ id: 'antigravity-cli', name: 'Antigravity Claude Sonnet 4.6', type: 'cli',+ command: '/nonexistent/path/to/agy', contextWindow: 1048576,+ models: [...stored], defaultModel: 'antigravity-configured-default',+ },+ },+ }, null, 2));++ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});+ const err = await providerService.refreshProviderModels('antigravity-cli').catch(e => e);+ errSpy.mockRestore();++ // Reached the AGY fetcher (which then failed on the bogus path) rather+ // than _fetchAnthropicModels, which would have succeeded and persisted+ // claude ids onto an agy provider.+ expect(err.message).toMatch(/agy models' failed/);+ const after = await providerService.getProviderById('antigravity-cli');+ expect(after.models).toEqual(stored);+ expect(after.models[0]).toBe('antigravity-configured-default');+ });++ // The name test still applies once no command has claimed the provider, and+ // a `claude` command still beats an "antigravity" name — the split must not+ // invert that.+ it('still routes a claude-commanded provider named "antigravity" to Anthropic', async () => {+ const p = await providerService.createProvider({+ name: 'Claude via Antigravity', type: 'cli', command: 'claude', models: ['x'],+ });+ const updated = await providerService.refreshProviderModels(p.id);+ expect(updated).not.toBeNull();+ expect(updated.models).toContain('claude-opus-5');+ expect(updated.models).not.toContain('antigravity-configured-default');+ });+// A failed `cursor-agent models` probe must be distinguishable from a real// fetch. Returning the shipped 27-id seed here would persist it and toast// "Models refreshed", so a user whose service PATH can't resolve the binary@@ -899,11 +972,14 @@ describe('Provider Service', () => {});const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});- const result = await providerService.refreshProviderModels(p.id);+ // The thrown message names the binary and the spawn failure, so the user's+ // toast says why — not "Provider not found or not an API type".+ const err = await providerService.refreshProviderModels(p.id).catch(e => e);errSpy.mockRestore();- // null = "nothing to persist"; the routes layer turns this into an error.- expect(result).toBeNull();+ expect(err).toBeInstanceOf(Error);+ expect(err.message).toMatch(/'\/nonexistent\/path\/to\/cursor-agent models' failed/);+ expect(err.status).toBe(502);const after = await providerService.getProviderById(p.id);expect(after.models).toEqual(stored);});@@ -922,10 +998,10 @@ describe('Provider Service', () => {});const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});- const result = await providerService.refreshProviderModels(p.id);+ await expect(providerService.refreshProviderModels(p.id))+ .rejects.toThrow(/returned no model ids/);errSpy.mockRestore();- expect(result).toBeNull();const after = await providerService.getProviderById(p.id);expect(after.models).toEqual(stored);});@@ -961,15 +1037,14 @@ describe('Provider Service', () => {});const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});- const result = await providerService.refreshProviderModels(p.id);- // Snapshot the calls BEFORE restoring — mockRestore() also resets the- // spy, so reading mock.calls afterwards always sees an empty array.- const logged = errSpy.mock.calls.flat().join(' ');+ const err = await providerService.refreshProviderModels(p.id).catch(e => e);errSpy.mockRestore();- // Falls through to the 'not supported for this CLI provider' throw.- expect(result).toBeNull();- expect(logged).toMatch(/not supported/i);+ // Falls through to the 'not supported for this CLI provider' throw — 400,+ // not the 502 default, because nothing upstream failed.+ expect(err).toBeInstanceOf(Error);+ expect(err.message).toMatch(/not supported/i);+ expect(err.status).toBe(400);});});@@ -1015,7 +1090,7 @@ describe('Provider Service', () => {expect(updated.models).toEqual(['model-a', 'model-b']);});- it('returns null when the generic endpoint rejects (timeout / unreachable)', async () => {+ it('throws the reason when the generic endpoint rejects (timeout / unreachable)', async () => {vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new DOMException('The operation was aborted.', 'TimeoutError')));const p = await providerService.createProvider({@@ -1024,8 +1099,14 @@ describe('Provider Service', () => {endpoint: 'https://dead.example.com/v1',});- const result = await providerService.refreshProviderModels(p.id);- expect(result).toBeNull();+ // Surfaced, not collapsed to null — `null` means "no refreshable branch+ // matched" and the route renders it as "Provider not found or not an API+ // type", which is false here: the provider exists and IS an API type.+ // Pairs with the next test: a FAILED fetch throws, a legitimately EMPTY+ // one persists. Those two must never share a return value.+ const err = await providerService.refreshProviderModels(p.id).catch(e => e);+ expect(err).toBeInstanceOf(Error);+ expect(err.status).toBe(502);});it('persists a legitimately empty model list rather than treating it as a failed fetch', async () => {