Skip to content

Commit 02f104d

Browse files
committed
fix(web): limit saved ACP presets to Cursor
1 parent 61bf784 commit 02f104d

3 files changed

Lines changed: 59 additions & 33 deletions

File tree

‎apps/web/src/components/chat/TraitsPicker.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function getSelectedTraits(
123123
) {
124124
const caps = getProviderModelCapabilities(models, model, provider, planModeEnabled);
125125
const modelIsUnavailable =
126-
provider === "opencode" &&
126+
(provider === "opencode" || provider === "acpRegistry") &&
127127
!models.some((candidate) => candidate.slug === normalizeModelSlug(model, provider));
128128
const descriptors = modelIsUnavailable
129129
? buildUnavailableModelOptionDescriptors(

‎apps/web/src/modelSelection.test.ts‎

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ function settingsWithProviderInstances(): UnifiedSettings {
5656
return {
5757
...DEFAULT_UNIFIED_SETTINGS,
5858
providerInstances: {
59+
[ProviderInstanceId.make("acpRegistry")]: {
60+
driver: ProviderDriverKind.make("acpRegistry"),
61+
config: { agentId: "cursor" },
62+
},
5963
[ProviderInstanceId.make("claudeAgent")]: {
6064
driver: ProviderDriverKind.make("claudeAgent"),
6165
config: { customModels: [] },
@@ -334,37 +338,40 @@ describe("instance-scoped model selection", () => {
334338
});
335339
});
336340

337-
it("falls back from an explicit non-OpenCode draft with a missing model", () => {
338-
const instanceId = ProviderInstanceId.make("codex");
339-
const driver = ProviderDriverKind.make("codex");
340-
const providers = [provider({ provider: driver, instanceId, models: ["gpt-5.6-sol"] })];
341-
const state = deriveEffectiveComposerModelState({
342-
draft: {
343-
activeProvider: instanceId,
344-
modelSelectionByProvider: {
345-
[instanceId]: createModelSelection(instanceId, "gpt-missing", [
346-
{ id: "effort", value: "max" },
347-
]),
341+
it.each(["codex", "acpRegistry"])(
342+
"falls back from an explicit %s draft with a missing model",
343+
(driverName) => {
344+
const instanceId = ProviderInstanceId.make(driverName);
345+
const driver = ProviderDriverKind.make(driverName);
346+
const providers = [provider({ provider: driver, instanceId, models: ["gpt-5.6-sol"] })];
347+
const state = deriveEffectiveComposerModelState({
348+
draft: {
349+
activeProvider: instanceId,
350+
modelSelectionByProvider: {
351+
[instanceId]: createModelSelection(instanceId, "gpt-missing", [
352+
{ id: "effort", value: "max" },
353+
]),
354+
},
348355
},
349-
},
350-
providers,
351-
selectedProvider: driver,
352-
selectedInstanceId: instanceId,
353-
threadModelSelection: null,
354-
projectModelSelection: null,
355-
settings: settingsWithProviderInstances(),
356-
});
357-
const dispatch = getComposerProviderState({
358-
provider: driver,
359-
model: state.selectedModel,
360-
models: providers[0]!.models,
361-
modelOptions: state.modelOptions?.[instanceId],
362-
planModeEnabled: false,
363-
});
356+
providers,
357+
selectedProvider: driver,
358+
selectedInstanceId: instanceId,
359+
threadModelSelection: null,
360+
projectModelSelection: null,
361+
settings: settingsWithProviderInstances(),
362+
});
363+
const dispatch = getComposerProviderState({
364+
provider: driver,
365+
model: state.selectedModel,
366+
models: providers[0]!.models,
367+
modelOptions: state.modelOptions?.[instanceId],
368+
planModeEnabled: false,
369+
});
364370

365-
expect(state.selectedModel).toBe("gpt-5.6-sol");
366-
expect(dispatch.modelOptionsForDispatch).toBeUndefined();
367-
});
371+
expect(state.selectedModel).toBe("gpt-5.6-sol");
372+
expect(dispatch.modelOptionsForDispatch).toBeUndefined();
373+
},
374+
);
368375

369376
it("preserves an explicit draft OpenCode selection while the catalog is empty", () => {
370377
const instanceId = ProviderInstanceId.make("opencode_work");

‎apps/web/src/modelSelection.ts‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { getComposerProviderState } from "./components/chat/composerProviderStat
1919
import { UnifiedSettings } from "@t3tools/contracts/settings";
2020
import * as Arr from "effect/Array";
2121
import * as Result from "effect/Result";
22+
import * as Predicate from "effect/Predicate";
2223
import {
2324
getDefaultServerModel,
2425
getProviderModels,
@@ -67,15 +68,32 @@ export interface AppModelOption {
6768
isUnavailable?: boolean;
6869
}
6970

71+
function isSavedCursorPreset(
72+
settings: UnifiedSettings,
73+
entry: ProviderInstanceEntry,
74+
selectedModel: string | null | undefined,
75+
): boolean {
76+
if (entry.driverKind !== "acpRegistry") return false;
77+
const config = settings.providerInstances[entry.instanceId]?.config;
78+
if (!Predicate.isObject(config)) return false;
79+
const cursor =
80+
config?.source === "local"
81+
? typeof config.commandPath === "string" &&
82+
/^cursor-agent(\.exe|\.cmd)?$/i.test(config.commandPath.split(/[\\/]/).pop() ?? "")
83+
: config?.agentId === "cursor";
84+
const preset = /^(.*)\[[^\]]*\]$/.exec(selectedModel ?? "");
85+
return cursor && preset !== null && entry.models.some((model) => model.slug === preset[1]);
86+
}
87+
7088
function appendUnavailableDynamicModelSelection(
7189
options: AppModelOption[],
7290
rawModels: ReadonlyArray<ServerProvider["models"][number]>,
7391
provider: ProviderDriverKind,
7492
selectedModel: string | null | undefined,
7593
hiddenModels: ReadonlyArray<string>,
94+
savedCursorPreset = false,
7695
): AppModelOption[] {
77-
if (provider !== "opencode" && provider !== "antigravity" && provider !== "acpRegistry")
78-
return options;
96+
if (provider !== "opencode" && provider !== "antigravity" && !savedCursorPreset) return options;
7997
const slug = normalizeCustomModelSlug(selectedModel);
8098
if (!slug) return options;
8199
if (provider === "antigravity" && slug === ANTIGRAVITY_DEFAULT_MODEL) return options;
@@ -238,6 +256,7 @@ export function getAppModelOptionsForInstance(
238256
entry.driverKind,
239257
selectedModel,
240258
preferences.hiddenModels,
259+
isSavedCursorPreset(settings, entry, selectedModel),
241260
);
242261
}
243262

@@ -279,7 +298,7 @@ export function resolveAppModelSelectionForInstance(
279298
resolutionOptions?.preserveUnavailableSelection &&
280299
(entry.driverKind === "opencode" ||
281300
entry.driverKind === "antigravity" ||
282-
entry.driverKind === "acpRegistry")
301+
isSavedCursorPreset(settings, entry, selectedModel))
283302
) {
284303
const unavailableSelection = normalizeCustomModelSlug(selectedModel);
285304
const hiddenModels = readInstanceModelPreferences(settings, entry.instanceId).hiddenModels;

0 commit comments

Comments
 (0)