Skip to content

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

offer Refresh Models on Kilo and Grok provider cards (#7505)

[._.]/ Adam Eivy1343987f86ef
diff --git a/server/routes/providers.js b/server/routes/providers.js
index df4597362d..7ed3e28e9a 100644
--- a/server/routes/providers.js
+++ b/server/routes/providers.js
@@ -19,7 +19,7 @@ import { asyncHandler, ServerError } from '../lib/errorHandler.js';
import { testVision, runVisionTestSuite, checkVisionHealth } from '../services/visionTest.js';
import { auditModelPins, clearModelPin } from '../services/modelPinAudit.js';
import { providerCreateSchema, providerSchema, providerActiveSchema, validate } from '../lib/aiToolkit/validation.js';
-import { withRefreshCapability } from '../lib/aiToolkit/internal/modelFetchers.js';
+import { canRefreshModels, withRefreshCapability } from '../lib/aiToolkit/internal/modelFetchers.js';
import { ALLOWED_COMMANDS } from '../cos-runner/allowedCommands.js';
import { onClientDisconnect, openSseStream } from '../lib/sseDownload.js';
import { createInstallLogger } from '../lib/installLogger.js';
@@ -43,8 +43,7 @@ import {
getProviderRuntimeStatus,
getProviderRuntimeStatuses,
} from '../services/providerRuntimeInstaller.js';
-import { refreshHarnessModels, usesHarnessCatalog } from '../services/harnesses.js';
-import { providerRuntimeKey } from '../lib/providerPrerequisites.js';
+import { harnessCatalogRuntime, refreshHarnessModels } from '../services/harnesses.js';
import { streamHarnessAction } from '../services/harnessActionStream.js';
import { getProviderReadinessMap, resetProviderReadinessCache, servedModelId } from '../services/providerReadiness.js';
import { getLlamaServerEndpoint, relaunchLlamaServerWithAlias } from '../services/llamaServerManager.js';
@@ -143,11 +142,6 @@ const withTuiLaunchCommand = (provider) => {
return launch ? { ...provider, tuiCommandLine: launch.commandLine } : provider;
};
-// Reuse the harness catalog only for wrappers the managed OpenCode refresh
-// can update; custom binaries and declared backends keep their own catalogs.
-const refreshesOpenCodeCatalog = (provider) =>
- providerRuntimeKey(provider) === 'opencode' && usesHarnessCatalog(provider);
-
/**
* The shape a provider takes on its way OUT to the client: secrets stripped,
* plus the derived `canRefreshModels` flag the AI Providers page reads to
@@ -182,7 +176,11 @@ const presentProvider = (provider, capabilities = captureSystemCapabilities()) =
const publicReviewPostures = publicReviewPosturesForProvider(provider);
return sanitizeProvider({
...decorated,
- canRefreshModels: decorated.canRefreshModels || refreshesOpenCodeCatalog(provider),
+ // The UNION of the two refresh paths, because the button asks only
+ // whether SOME path can serve this record. Which one actually serves it is
+ // decided in `POST /:id/refresh-models`, and the two must stay in step or
+ // a card offers a button the route refuses.
+ canRefreshModels: decorated.canRefreshModels || Boolean(harnessCatalogRuntime(provider)),
publicReviewPostures,
publicReviewEnforcedPostures: enforcedPublicReviewPosturesForProvider(provider),
publicReviewSupported: publicReviewPostures.includes(PUBLIC_REVIEW_NO_TOOL_POSTURE),
@@ -916,12 +914,19 @@ export function createPortOSProviderRoutes(aiToolkit) {
router.post('/:id/refresh-models', asyncHandler(async (req, res) => {
const stored = await providerService.getProviderById(req.params.id);
if (!stored) throw new ServerError('Provider not found', { status: 404 });
+ // A record can match BOTH paths — `cursor-cli` and `antigravity-cli` do
+ // today — so the precedence is fixed here: the TOOLKIT FETCHER WINS, and
+ // the harness catalog serves only records no fetcher claims. The fetcher
+ // table keys on the launch command (and, failing that, the display name),
+ // which is a per-record answer; routing a record the table already claims
+ // to its harness instead would silently move where its catalog comes from.
+ const harness = canRefreshModels(stored) ? null : harnessCatalogRuntime(stored);
let provider;
- if (refreshesOpenCodeCatalog(stored)) {
+ if (harness) {
// Scoped to THIS record: the harness is probed once per bootstrap
// credential (services/harnesses.js), and a card's button must not spawn
// another record's credential CLI to answer for its own.
- const result = await refreshHarnessModels('opencode', { providerId: stored.id });
+ const result = await refreshHarnessModels(harness.id, { providerId: stored.id });
if (!result.ok || !result.updated.includes(stored.id)) {
throw new ServerError(result.reason || 'No models matched this provider’s namespace; its catalog was preserved.', { status: 502 });
}
diff --git a/server/routes/providers.refreshModels.test.js b/server/routes/providers.refreshModels.test.js
index 823463a15a..9a1066671f 100644
--- a/server/routes/providers.refreshModels.test.js
+++ b/server/routes/providers.refreshModels.test.js
@@ -93,3 +93,94 @@ it('does not offer harness refresh for a hand-declared OpenCode backend', async
const res = await request(app).get('/api/providers/example-custom');
expect(res.body.canRefreshModels).toBe(false);
});
+
+describe('harness-catalog refresh is generic over the runtimes that list models', () => {
+ // The bug #7505 fixed: these cards offered no Refresh Models button at all,
+ // because the route asked `providerRuntimeKey === 'opencode'` while
+ // `refreshHarnessModels` was already generic over every runtime declaring
+ // `modelsArgs`. `kilo` and `grok` are the two the literal excluded and that
+ // no `MODEL_FETCHERS` row claims.
+ it.each([
+ { id: 'kilo-cli', name: 'Kilo Code CLI', command: 'kilo', runtime: 'kilo' },
+ { id: 'kilo-tui', name: 'Kilo Code TUI', command: 'kilo', runtime: 'kilo', type: 'tui' },
+ { id: 'grok-cli', name: 'Grok Build CLI', command: 'grok', runtime: 'grok' },
+ { id: 'grok-tui', name: 'Grok Build TUI', command: 'grok', runtime: 'grok', type: 'tui' },
+ ])('offers the button and refreshes $id through its own harness', async ({ id, name, command, runtime, type = 'cli' }) => {
+ const provider = { id, name, type, command, models: [`${runtime}/old`] };
+ const refreshed = { ...provider, models: [`${runtime}/new`] };
+ const service = {
+ getProviderById: vi.fn().mockResolvedValueOnce(provider).mockResolvedValueOnce(provider).mockResolvedValue(refreshed),
+ refreshProviderModels: vi.fn(),
+ };
+ refreshHarnessModels.mockResolvedValue({ ok: true, updated: [id] });
+ const app = appWith(service);
+
+ expect((await request(app).get(`/api/providers/${id}`)).body.canRefreshModels).toBe(true);
+ const res = await request(app).post(`/api/providers/${id}/refresh-models`);
+
+ expect(res.status).toBe(200);
+ expect(res.body.models).toEqual([`${runtime}/new`]);
+ // Scoped to this record, not the whole harness — the per-credential
+ // bucketing #7506 added must survive on the widened path too.
+ expect(refreshHarnessModels).toHaveBeenCalledWith(runtime, { providerId: id });
+ expect(service.refreshProviderModels).not.toHaveBeenCalled();
+ });
+
+ // The precedence this route fixes: a record can match BOTH paths, and the
+ // toolkit's per-record fetcher wins. `cursor-cli` and `antigravity-cli` are
+ // in the harness-catalog set AND claimed by a `MODEL_FETCHERS` row — widening
+ // the predicate must not move them off the fetcher they refresh through today.
+ it.each([
+ { id: 'cursor-cli', name: 'Cursor Agent CLI', command: 'cursor-agent' },
+ { id: 'antigravity-cli', name: 'Antigravity CLI', command: 'agy' },
+ { id: 'pi-cli', name: 'Pi Coding Agent CLI', command: 'pi' },
+ // The weak `cliNameMatch` column claims this one by DISPLAY NAME alone;
+ // it is still a fetcher claim, so it still outranks the harness path.
+ { id: 'renamed-kilo', name: 'My Claude via Kilo', command: 'kilo' },
+ ])('routes $id to its toolkit fetcher, not the harness catalog', async ({ id, name, command }) => {
+ const provider = { id, name, type: 'cli', command, models: ['old'] };
+ const service = {
+ getProviderById: vi.fn().mockResolvedValue(provider),
+ refreshProviderModels: vi.fn().mockResolvedValue({ ...provider, models: ['new'] }),
+ };
+ refreshHarnessModels.mockClear();
+ const app = appWith(service);
+
+ const res = await request(app).post(`/api/providers/${id}/refresh-models`);
+
+ expect(res.status).toBe(200);
+ expect(res.body.models).toEqual(['new']);
+ expect(service.refreshProviderModels).toHaveBeenCalledWith(id);
+ expect(refreshHarnessModels).not.toHaveBeenCalled();
+ });
+
+ // `usesHarnessCatalog` is the other half of the predicate, and widening the
+ // runtime half must not reach past it: a wrapper pointed at a gateway or a
+ // local daemon serves ids its harness never prints.
+ it.each([
+ { label: 'a gateway-backed wrapper', provider: { id: 'kilo-openrouter', name: 'Kilo OpenRouter', command: 'kilo', gatewayBacked: 'openrouter' } },
+ { label: 'a local-daemon wrapper', provider: { id: 'kilo-ollama', name: 'Kilo Ollama', command: 'kilo', ollamaBacked: true } },
+ ])('never refreshes $label from the harness catalog', async ({ provider }) => {
+ const stored = { type: 'cli', models: ['old'], ...provider };
+ const service = {
+ getProviderById: vi.fn().mockResolvedValue(stored),
+ refreshProviderModels: vi.fn().mockResolvedValue({ ...stored, models: ['new'] }),
+ };
+ refreshHarnessModels.mockClear();
+ const app = appWith(service);
+
+ await request(app).post(`/api/providers/${stored.id}/refresh-models`);
+
+ expect(refreshHarnessModels).not.toHaveBeenCalled();
+ });
+
+ // A custom binary resolves to no runtime row at all, so neither half applies.
+ it('offers no refresh for a custom binary with no runtime row', async () => {
+ const provider = { id: 'example-custom-binary', name: 'Example Harness', type: 'cli', command: 'example-harness' };
+ const app = appWith({ getProviderById: vi.fn().mockResolvedValue(provider) });
+
+ const res = await request(app).get('/api/providers/example-custom-binary');
+
+ expect(res.body.canRefreshModels).toBe(false);
+ });
+});
diff --git a/server/services/harnesses.js b/server/services/harnesses.js
index 4ecc01f21f..e910399790 100644
--- a/server/services/harnesses.js
+++ b/server/services/harnesses.js
@@ -130,6 +130,30 @@ export function __resetLatestVersionCache() {
export const usesHarnessCatalog = (provider) =>
!getOpencodeLocalProviderNamespace(provider) && !declaresOwnOpencodeProvider(provider);
+/**
+ * The harness runtime whose OWN catalog feeds this provider's models, or
+ * `null` for a record that keeps a catalog of its own.
+ *
+ * The full precondition for {@link refreshHarnessModels} in one place: the
+ * binary this record launches must know how to enumerate its models
+ * (`modelsArgs`), and the record must be a plain wrapper rather than one
+ * pointed at a local daemon or a hosted gateway ({@link usesHarnessCatalog}).
+ * A custom binary resolves to no runtime row at all and answers `null` on the
+ * first question.
+ *
+ * Lives here rather than beside its caller because the answer is exactly the
+ * set this refresh may rewrite, and TWO places ask it: the provider card's
+ * Refresh Models button (`server/routes/providers.js`) and the seed pin in
+ * this module's tests. Those used to be separate transcriptions, and the route's
+ * copy asked a third, narrower question — `providerRuntimeKey(provider) ===
+ * 'opencode'` — so Kilo and Grok cards offered no button for a catalog their
+ * harness could already print (#7505).
+ */
+export const harnessCatalogRuntime = (provider) => {
+ const runtime = getProviderRuntime(providerRuntimeKey(provider));
+ return runtime?.modelsArgs && usesHarnessCatalog(provider) ? runtime : null;
+};
+
/**
* Does this record hand-declare its own OpenCode provider entries?
*
diff --git a/server/services/harnesses.test.js b/server/services/harnesses.test.js
index 477421a2ed..4d0d37cc15 100644
--- a/server/services/harnesses.test.js
+++ b/server/services/harnesses.test.js
@@ -26,12 +26,12 @@ import { prepareCliSpawn } from '../lib/bufferedSpawn.js';
import {
__resetLatestVersionCache,
getLatestPublishedVersion,
+ harnessCatalogRuntime,
listHarnesses,
refreshHarnessModels,
usesHarnessCatalog,
} from './harnesses.js';
-import { __resetRuntimeStatusCache, PROVIDER_RUNTIMES } from './providerRuntimeInstaller.js';
-import { providerRuntimeKey } from '../lib/providerPrerequisites.js';
+import { __resetRuntimeStatusCache } from './providerRuntimeInstaller.js';
const OPENCODE_MODELS = 'opencode/big-pickle\nopencode/mimo-v2.5-free\n';
@@ -70,11 +70,11 @@ describe('the shipped records a harness refresh may rewrite', () => {
new URL('../../data.reference/providers.json', import.meta.url), 'utf8',
)),
);
+ // The PRODUCTION predicate, not a transcription of it: this list is the
+ // set a refresh may rewrite, so a widening of `harnessCatalogRuntime` has
+ // to move it here on purpose (#7505 widened it from an `opencode` literal).
const rewritable = Object.values(seed.providers)
- .filter((provider) => {
- const runtime = PROVIDER_RUNTIMES.find((row) => [row.id, ...row.aliases].includes(providerRuntimeKey(provider)));
- return Boolean(runtime?.modelsArgs) && usesHarnessCatalog(provider);
- })
+ .filter((provider) => harnessCatalogRuntime(provider))
.map((provider) => provider.id)
.sort();