@devries-cameron20 / t3code-1 / commits / 2c1160783e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(settings): drop the legacy per-driver providers map (#17300)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 8, 2026 at 14:18 UTC 2c1160783ea4b4dcc1c1f1ab04639ffc0aaa289d
32 files changed +602 -1073
apps/server/src/orchestration-v2/CursorOrchestratorV2.live.test.ts
+7 -2
@@ -7,6 +7,8 @@ import {
7 CommandId,
8 MessageId,
9 ProjectId,
10 + ProviderDriverKind,
11 + ProviderInstanceId,
12 ThreadId,
13 type OrchestrationV2ThreadProjection,
14 } from "@t3tools/contracts";
@@ -60,8 +62,11 @@ const layerVcsDriverRegistry = VcsDriverRegistry.layer.pipe(
62 const layerCheckpointStore = CheckpointStore.layer.pipe(Layer.provide(layerVcsDriverRegistry));
63
64 const layerServerSettings = ServerSettings.layerTest({
63 - providers: {
64 - cursor: { enabled: true },
65 + providerInstances: {
66 + [ProviderInstanceId.make("cursor")]: {
67 + driver: ProviderDriverKind.make("cursor"),
68 + enabled: true,
69 + },
70 },
71 });
72 const layerBackgroundPolicy = BackgroundPolicy.layer.pipe(
apps/server/src/orchestration-v2/GrokOrchestratorV2.live.test.ts
+7 -2
@@ -8,6 +8,8 @@ import {
8 MessageId,
9 type OrchestrationV2ThreadProjection,
10 ProjectId,
11 + ProviderDriverKind,
12 + ProviderInstanceId,
13 ThreadId,
14 } from "@t3tools/contracts";
15 import * as Console from "effect/Console";
@@ -59,8 +61,11 @@ const layerVcsDriverRegistry = VcsDriverRegistry.layer.pipe(
61 const layerCheckpointStore = CheckpointStore.layer.pipe(Layer.provide(layerVcsDriverRegistry));
62
63 const layerServerSettings = ServerSettings.layerTest({
62 - providers: {
63 - grok: { enabled: true },
64 + providerInstances: {
65 + [ProviderInstanceId.make("grok")]: {
66 + driver: ProviderDriverKind.make("grok"),
67 + enabled: true,
68 + },
69 },
70 });
71 const layerBackgroundPolicy = BackgroundPolicy.layer.pipe(
apps/server/src/project/AgentSessionScanner.test.ts
+13 -7
@@ -59,13 +59,19 @@ const layerScannerTest = (input: ScannerTestInput) =>
59 Layer.provide(
60 Layer.mergeAll(
61 ServerSettings.layerTest({
62 - providers: {
63 - claudeAgent: { homePath: input.claudeHomePath },
64 - codex: { homePath: input.codexHomePath },
62 + // Default slots point at the fixture homes; explicit test instances
63 + // replace a slot with the same id.
64 + providerInstances: {
65 + [ProviderInstanceId.make("claudeAgent")]: {
66 + driver: ProviderDriverKind.make("claudeAgent"),
67 + config: { homePath: input.claudeHomePath },
68 + },
69 + [ProviderInstanceId.make("codex")]: {
70 + driver: ProviderDriverKind.make("codex"),
71 + config: { homePath: input.codexHomePath },
72 + },
73 + ...input.providerInstances,
74 },
66 - ...(input.providerInstances === undefined
67 - ? {}
68 - : { providerInstances: input.providerInstances }),
75 }),
76 ServerConfig.layerTest(
77 input.claudeHomePath,
@@ -533,7 +539,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
539 }),
540 );
541
536 - it.effect("uses explicit provider instance homes instead of overridden legacy homes", () =>
542 + it.effect("uses explicit default-slot homes instead of the fixture homes", () =>
543 Effect.gen(function* () {
544 const path = yield* Path.Path;
545 const claudeHomePath = yield* makeTempDir("t3code-claude-legacy-");
apps/server/src/project/AgentSessionScanner.ts
+6 -7
@@ -1102,16 +1102,15 @@ export const make = Effect.gen(function* () {
1102 instanceId: ProviderInstanceId.make(instanceId),
1103 config,
1104 }));
1105 + // The built-in default instance runs with default config when settings
1106 + // have no entry for it.
1107 if (!Object.hasOwn(settings.providerInstances, source)) {
1106 - const legacyInstance = {
1108 + const defaultInstance = {
1109 instanceId: ProviderInstanceId.make(source),
1108 - config: {
1109 - driver: ProviderDriverKind.make(source),
1110 - config: settings.providers[source],
1111 - },
1110 + config: { driver: ProviderDriverKind.make(source) },
1111 };
1113 - if (resolveProviderInstanceEnabled(legacyInstance.config)) {
1114 - instances.push(legacyInstance);
1112 + if (resolveProviderInstanceEnabled(defaultInstance.config)) {
1113 + instances.push(defaultInstance);
1114 }
1115 }
1116
apps/server/src/provider/Drivers/AcpRegistryDriver.ts
+1
@@ -467,6 +467,7 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
467 metadata: {
468 displayName: "ACP Registry",
469 supportsMultipleInstances: true,
470 + hasDefaultInstance: false,
471 },
472 configSchema: AcpRegistrySettings,
473 defaultConfig: () => decodeSettings({}),
apps/server/src/provider/ProviderInstanceRegistryHydration.ts
+10 -54
@@ -2,28 +2,10 @@
2 * ProviderInstanceRegistryHydration — derive a `ProviderInstanceConfigMap`
3 * from `ServerSettings` and keep `ProviderInstanceRegistry` in sync with it.
4 *
5 - * The server still reads two shapes:
6 - *
7 - * 1. `settings.providerInstances` — the new driver-agnostic map the
8 - * registry expects. Keyed by `ProviderInstanceId`, values are
9 - * `ProviderInstanceConfig` envelopes.
10 - * 2. `settings.providers.<kind>` — the legacy single-instance-per-driver
11 - * fields (`providers.codex`, `providers.claudeAgent`, …). These are
12 - * the source of truth for every deployment that hasn't been migrated
13 - * yet to an explicit `providerInstances` entry.
14 - *
15 - * This module bridges (2) into (1) and wires the resulting map into a
16 - * mutable registry. For every built-in driver whose id is not already
17 - * present in `providerInstances` (keyed on
18 - * `defaultInstanceIdForDriver(driverKind)` — literally the driver kind as a
19 - * routing slug), we synthesize an envelope from the legacy field. The
20 - * registry decodes both flavours through the same `configSchema` and ends
21 - * up with one uniform `ProviderInstance` per entry.
22 - *
23 - * Explicit `providerInstances` entries always win — users can already
24 - * override the legacy `providers.<kind>` blob by authoring a
25 - * `providerInstances.codex` entry with a matching driver, and we don't
26 - * want the synthesized envelope to silently stomp their config.
5 + * `settings.providerInstances` is the source of truth. Every built-in driver
6 + * with a default instance also runs at `defaultInstanceIdForDriver(kind)`
7 + * when that slot has no entry, using the driver's default config, so a fresh
8 + * install shows its built-in providers without writing settings first.
9 *
10 * Hot-reload
11 * ----------
@@ -76,17 +58,9 @@ type ProviderInstanceRegistryHydrationEnv =
58 | ServerConfig.ServerConfig;
59
60 /**
79 - * Synthesize a `ProviderInstanceConfigMap` from a `ServerSettings` snapshot.
80 - *
81 - * Strategy:
82 - * 1. Copy all explicit `settings.providerInstances` entries verbatim.
83 - * 2. For each built-in driver whose `defaultInstanceIdForDriver(id)` key
84 - * is *not* already in the explicit map, synthesize an entry from the
85 - * matching legacy `settings.providers.<kind>` blob.
86 - *
87 - * The returned map is the input the registry consumes; pure & exported
88 - * separately so the hydration logic can be exercised by unit tests
89 - * without layering.
61 + * Explicit `providerInstances` entries plus an implicit default instance for
62 + * each built-in driver whose default slot is empty. Pure so the hydration
63 + * rule can be tested without layers.
64 */
65 export const deriveProviderInstanceConfigMap = (
66 settings: ServerSettings,
@@ -94,28 +68,10 @@ export const deriveProviderInstanceConfigMap = (
68 const merged: Record<string, ProviderInstanceConfig> = { ...settings.providerInstances };
69
70 for (const driver of BUILT_IN_DRIVERS) {
71 + if (driver.metadata.hasDefaultInstance === false) continue;
72 const instanceId = defaultInstanceIdForDriver(driver.driverKind);
98 - if (instanceId in merged) {
99 - // Explicit `providerInstances` entry for this slot — user-authored
100 - // config always wins over the legacy mirror.
101 - continue;
102 - }
103 -
104 - // Only built-in drivers have a legacy mirror; the registry's
105 - // `providers` struct is keyed on the same literal slug as
106 - // `driverKind`. Access is dynamic (the driver kind is a branded string),
107 - // but it's constrained to `keyof settings.providers` by the union of
108 - // built-in driver kinds.
109 - const legacyKey = driver.driverKind as keyof ServerSettings["providers"];
110 - const legacyConfig = settings.providers[legacyKey];
111 - if (legacyConfig === undefined) {
112 - continue;
113 - }
114 -
115 - merged[instanceId] = {
116 - driver: driver.driverKind,
117 - config: legacyConfig,
118 - };
73 + if (instanceId in merged) continue;
74 + merged[instanceId] = { driver: driver.driverKind };
75 }
76
77 return merged as ProviderInstanceConfigMap;
apps/server/src/provider/ProviderRegistry.test.ts
+33 -35
@@ -68,6 +68,17 @@ const decodeServerSettings = Schema.decodeSync(ServerSettings);
68 const encodeServerSettings = Schema.encodeSync(ServerSettings);
69 const encodedDefaultServerSettings = encodeServerSettings(DEFAULT_SERVER_SETTINGS);
70
71 +/** Default slots that settings mark disabled, so their probes never spawn. */
72 +const disabledDefaultSlots = (
73 + ...drivers: ReadonlyArray<string>
74 +): ContractServerSettings["providerInstances"] =>
75 + Object.fromEntries(
76 + drivers.map((driver) => [
77 + ProviderInstanceId.make(driver),
78 + { driver: ProviderDriverKind.make(driver), enabled: false },
79 + ]),
80 + );
81 +
82 const defaultClaudeSettings: ClaudeSettings = Schema.decodeSync(ClaudeSettings)({});
83 const defaultCodexSettings: CodexSettings = Schema.decodeSync(CodexSettings)({});
84 const decodeCodexSettings = Schema.decodeSync(CodexSettings);
@@ -2663,24 +2674,18 @@ it.layer(
2674 const serverSettings = yield* makeMutableServerSettingsService(
2675 decodeServerSettings(
2676 deepMerge(encodedDefaultServerSettings, {
2666 - providers: {
2667 - // Disable every built-in probe that would otherwise spawn
2668 - // on the CI host. `enabled: false` short-circuits each
2669 - // driver's probe *before* it touches the spawner, so the
2670 - // test environment stays isolated from the dev
2671 - // machine's PATH.
2672 - codex: { enabled: false },
2673 - claudeAgent: { enabled: false },
2674 - cursor: { enabled: false },
2675 - grok: { enabled: false },
2676 - opencode: { enabled: false },
2677 - },
2677 // `providerInstances` keys are branded `ProviderInstanceId`;
2678 // the branded index signature rejects plain string literals
2679 // at the TS level even though the runtime schema happily
2680 // accepts + decodes them. Cast the patch to `unknown` so
2681 // the `Schema.decodeSync` below does the real validation.
2682 providerInstances: {
2683 + // Disable every built-in probe that would otherwise spawn
2684 + // on the CI host. `enabled: false` short-circuits each
2685 + // driver's probe *before* it touches the spawner, so the
2686 + // test environment stays isolated from the dev
2687 + // machine's PATH.
2688 + ...disabledDefaultSlots("codex", "claudeAgent", "cursor", "grok", "opencode"),
2689 // Matches the shape the user had in `.t3/dev/settings.json`
2690 // when the bug was reported: a custom enabled Codex instance
2691 // pointing at a binary the server has to actually spawn.
@@ -2781,12 +2786,13 @@ it.layer(
2786 const mutableServerSettings = yield* makeMutableServerSettingsService(
2787 decodeServerSettings(
2788 deepMerge(encodedDefaultServerSettings, {
2784 - providers: {
2785 - codex: { enabled: true, binaryPath: firstMissing },
2786 - claudeAgent: { enabled: false },
2787 - cursor: { enabled: false },
2788 - grok: { enabled: false },
2789 - opencode: { enabled: false },
2789 + providerInstances: {
2790 + ...disabledDefaultSlots("claudeAgent", "cursor", "grok", "opencode"),
2791 + [ProviderInstanceId.make("codex")]: {
2792 + driver: ProviderDriverKind.make("codex"),
2793 + enabled: true,
2794 + config: { binaryPath: firstMissing },
2795 + },
2796 },
2797 }),
2798 ),
@@ -2871,8 +2877,13 @@ it.layer(
2877 ),
2878 );
2879 yield* serverSettings.updateSettings({
2874 - providers: {
2875 - codex: { enabled: true, binaryPath: secondMissing },
2880 + providerInstances: {
2881 + ...disabledDefaultSlots("claudeAgent", "cursor", "grok", "opencode"),
2882 + [ProviderInstanceId.make("codex")]: {
2883 + driver: ProviderDriverKind.make("codex"),
2884 + enabled: true,
2885 + config: { binaryPath: secondMissing },
2886 + },
2887 },
2888 });
2889 // Start the lazy stream only after publishing. A watcher that did
@@ -2900,14 +2911,8 @@ it.layer(
2911 const serverSettings = yield* makeMutableServerSettingsService(
2912 decodeServerSettings(
2913 deepMerge(encodedDefaultServerSettings, {
2903 - providers: {
2904 - codex: { enabled: false },
2905 - claudeAgent: { enabled: false },
2906 - cursor: { enabled: false },
2907 - grok: { enabled: false },
2908 - opencode: { enabled: false },
2909 - },
2914 providerInstances: {
2915 + ...disabledDefaultSlots("codex", "claudeAgent", "cursor", "grok", "opencode"),
2916 ghost_main: {
2917 driver: "ghostDriver",
2918 displayName: "A fork-only driver we don't ship",
@@ -2971,14 +2976,7 @@ it.layer(
2976 const serverSettings = yield* makeMutableServerSettingsService(
2977 decodeServerSettings(
2978 deepMerge(encodedDefaultServerSettings, {
2974 - providers: {
2975 - codex: {
2976 - enabled: false,
2977 - },
2978 - grok: {
2979 - enabled: false,
2980 - },
2981 - },
2979 + providerInstances: disabledDefaultSlots("codex", "grok"),
2980 }),
2981 ),
2982 );
apps/server/src/provider/providerInstallation.test.ts
+24 -3
@@ -147,7 +147,14 @@ describe("provider installation routing", () => {
147 it.effect("keeps external installs manual without hiding shared install status", () =>
148 Effect.gen(function* () {
149 const harness = yield* makeHarness({
150 - settings: { providers: { antigravity: { binaryPath: "/external/agy" } } },
150 + settings: {
151 + providerInstances: {
152 + [ProviderInstanceId.make("antigravity")]: {
153 + driver: ProviderDriverKind.make("antigravity"),
154 + config: { binaryPath: "/external/agy" },
155 + },
156 + },
157 + },
158 });
159 const start = yield* Effect.flip(harness.router.start({ instanceId }));
160 const remove = yield* Effect.flip(harness.router.remove({ instanceId }));
@@ -164,7 +171,14 @@ describe("provider installation routing", () => {
171 const codexId = ProviderInstanceId.make("codex");
172 const harness = yield* makeHarness({
173 instance: instance(ProviderDriverKind.make("codex"), codexId),
167 - settings: { providers: { codex: { setupMode: "managed" } } },
174 + settings: {
175 + providerInstances: {
176 + [ProviderInstanceId.make("codex")]: {
177 + driver: ProviderDriverKind.make("codex"),
178 + config: { setupMode: "managed" },
179 + },
180 + },
181 + },
182 });
183 assert.equal((yield* harness.router.start({ instanceId: codexId })).driver, "codex");
184 yield* harness.router.cancel({ instanceId: codexId, operationId: "operation" });
@@ -180,7 +194,14 @@ describe("provider installation routing", () => {
194 const codexId = ProviderInstanceId.make("codex");
195 const harness = yield* makeHarness({
196 instance: instance(ProviderDriverKind.make("codex"), codexId),
183 - settings: { providers: { codex: { setupMode: "existing" } } },
197 + settings: {
198 + providerInstances: {
199 + [ProviderInstanceId.make("codex")]: {
200 + driver: ProviderDriverKind.make("codex"),
201 + config: { setupMode: "existing" },
202 + },
203 + },
204 + },
205 });
206 assert.include(
207 (yield* Effect.flip(harness.router.start({ instanceId: codexId }))).detail,
apps/server/src/server.ts
+1 -2
@@ -583,8 +583,7 @@ const layerRuntimeCoreDependenciesBase = Layer.mergeAll(
583 // The instance registry is the new routing keystone — text generation,
584 // adapter lookup, and runtime ingestion all resolve `ProviderInstanceId`
585 // through this layer. Built-in drivers come from `BUILT_IN_DRIVERS`;
586 - // `providerInstances` hydration merges `settings.providers.<kind>`
587 - // with explicit `providerInstances` entries on boot.
586 + // hydration adds their default instances to `providerInstances` on boot.
587 Layer.provideMerge(ProviderInstanceRegistryHydration.layer),
588 Layer.provideMerge(
589 Layer.mergeAll(
apps/server/src/serverSettings.test.ts
+107 -306
@@ -327,13 +327,6 @@ it.layer(NodeServices.layer)("server settings", (it) => {
327
328 it.effect("decodes nested settings patches", () =>
329 Effect.gen(function* () {
330 - assert.deepEqual(
331 - yield* decodeSettingsPatch({ providers: { codex: { binaryPath: "/tmp/codex" } } }),
332 - {
333 - providers: { codex: { binaryPath: "/tmp/codex" } },
334 - },
335 - );
336 -
330 assert.deepEqual(
331 yield* decodeSettingsPatch({
332 textGenerationModelSelection: {
@@ -374,16 +367,7 @@ it.layer(NodeServices.layer)("server settings", (it) => {
367 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
368
369 yield* serverSettings.updateSettings({
377 - providers: {
378 - codex: {
379 - binaryPath: "/usr/local/bin/codex",
380 - homePath: "/Users/julius/.codex",
381 - },
382 - claudeAgent: {
383 - binaryPath: "/usr/local/bin/claude",
384 - customModels: ["claude-custom"],
385 - },
386 - },
370 + observability: { otlpTracesUrl: "http://localhost:4318/v1/traces" },
371 textGenerationModelSelection: {
372 instanceId: ProviderInstanceId.make("codex"),
373 model: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection.model,
@@ -399,32 +383,14 @@ it.layer(NodeServices.layer)("server settings", (it) => {
383 });
384
385 const next = yield* serverSettings.updateSettings({
402 - providers: {
403 - codex: {
404 - binaryPath: "/opt/homebrew/bin/codex",
405 - },
406 - },
386 + observability: { otlpMetricsUrl: "http://localhost:4318/v1/metrics" },
387 textGenerationModelSelection: {
388 options: [{ id: "fastMode", value: false }],
389 },
390 });
391
412 - assert.deepEqual(next.providers.codex, {
413 - enabled: true,
414 - binaryPath: "/opt/homebrew/bin/codex",
415 - homePath: "/Users/julius/.codex",
416 - shadowHomePath: "",
417 - launchArgs: "",
418 - customModels: [],
419 - });
420 - assert.deepEqual(next.providers.claudeAgent, {
421 - enabled: true,
422 - binaryPath: "/usr/local/bin/claude",
423 - homePath: "",
424 - customModels: ["claude-custom"],
425 - launchArgs: "",
426 - autoCompactWindow: "",
427 - });
392 + assert.equal(next.observability.otlpTracesUrl, "http://localhost:4318/v1/traces");
393 + assert.equal(next.observability.otlpMetricsUrl, "http://localhost:4318/v1/metrics");
394 assert.deepEqual(
395 next.textGenerationModelSelection,
396 createModelSelection(
@@ -521,18 +487,11 @@ it.layer(NodeServices.layer)("server settings", (it) => {
487 const changes = yield* serverSettings.subscribeChanges;
488
489 yield* serverSettings.updateSettings({
524 - providers: {
525 - codex: {
526 - binaryPath: "/usr/local/bin/codex-next",
527 - },
528 - },
490 + addProjectBaseDirectory: "~/next",
491 });
492
493 const firstChange = yield* changes.pipe(Stream.runHead, Effect.timeout("1 second"));
532 - assert.equal(
533 - Option.getOrUndefined(firstChange)?.providers.codex.binaryPath,
534 - "/usr/local/bin/codex-next",
535 - );
494 + assert.equal(Option.getOrUndefined(firstChange)?.addProjectBaseDirectory, "~/next");
495 }),
496 ).pipe(Effect.provide(layerServerSettings())),
497 );
@@ -654,19 +613,18 @@ it.layer(NodeServices.layer)("server settings", (it) => {
613 );
614
615 it.effect(
657 - "uses explicit provider instance enabled state over legacy provider enabled state",
616 + "keeps a custom instance's selection when the driver's default instance is disabled",
617 () =>
618 Effect.gen(function* () {
619 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
620 const instanceId = ProviderInstanceId.make("claude_openrouter");
621
622 const next = yield* serverSettings.updateSettings({
664 - providers: {
665 - claudeAgent: {
623 + providerInstances: {
624 + [ProviderInstanceId.make("claudeAgent")]: {
625 + driver: ProviderDriverKind.make("claudeAgent"),
626 enabled: false,
627 },
668 - },
669 - providerInstances: {
628 [instanceId]: {
629 driver: ProviderDriverKind.make("claudeAgent"),
630 enabled: true,
@@ -700,6 +658,10 @@ it.layer(NodeServices.layer)("server settings", (it) => {
658 const fallbackInstanceId = ProviderInstanceId.make(fallbackId);
659 const selection = { instanceId: writerId, model: "claude-sonnet-4-6" };
660 const providerInstances = {
661 + [ProviderInstanceId.make("claudeAgent")]: {
662 + driver: ProviderDriverKind.make("claudeAgent"),
663 + enabled: false,
664 + },
665 [fallbackInstanceId]: {
666 driver: ProviderDriverKind.make("codex"),
667 enabled: true,
@@ -713,11 +675,6 @@ it.layer(NodeServices.layer)("server settings", (it) => {
675 };
676
677 yield* serverSettings.updateSettings({
716 - providers: Object.fromEntries(
717 - Object.keys(DEFAULT_SERVER_SETTINGS.providers).map(
718 - (provider) => [provider, { enabled: false }] as const,
719 - ),
720 - ),
678 providerInstances,
679 textGenerationModelSelection: selection,
680 });
@@ -754,7 +711,7 @@ it.layer(NodeServices.layer)("server settings", (it) => {
711 ).pipe(Effect.provide(layerServerSettings())),
712 );
713
757 - it.effect("skips explicitly disabled instances when choosing a legacy fallback", () =>
714 + it.effect("skips explicitly disabled default instances when choosing a fallback", () =>
715 Effect.gen(function* () {
716 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
717 const next = yield* serverSettings.updateSettings({
@@ -933,242 +890,188 @@ it.layer(NodeServices.layer)("server settings", (it) => {
890 }).pipe(Effect.provide(layerServerSettings())),
891 );
892
936 - it.effect("enables previously used providers from sparse settings files", () =>
893 + it.effect("moves customized legacy provider settings into default instances on load", () =>
894 Effect.gen(function* () {
895 const serverConfig = yield* ServerConfig.ServerConfig;
896 const fileSystem = yield* FileSystem.FileSystem;
897 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
898 yield* fileSystem.writeFileString(
899 serverConfig.settingsPath,
943 - '{"providers":{"opencode":{"serverUrl":"http://127.0.0.1:4096"}}}',
900 + JSON.stringify({
901 + addProjectBaseDirectory: "~/Development",
902 + providers: {
903 + codex: { binaryPath: "/opt/guard/bin/codex" },
904 + claudeAgent: { enabled: false },
905 + cursor: { enabled: false },
906 + grok: { enabled: false },
907 + opencode: { enabled: false },
908 + },
909 + }),
910 );
945 - yield* recordProviderUsage("opencode");
911
912 const settings = yield* serverSettings.getSettings;
913
949 - assert.isFalse(settings.providers.grok.enabled);
950 - assert.isTrue(settings.providers.opencode.enabled);
951 - assert.isFalse(settings.providers.cursor.enabled);
952 - assert.equal(settings.providers.opencode.serverUrl, "http://127.0.0.1:4096");
914 + assert.deepEqual(settings.providerInstances, {
915 + [ProviderInstanceId.make("codex")]: {
916 + driver: ProviderDriverKind.make("codex"),
917 + config: { binaryPath: "/opt/guard/bin/codex" },
918 + },
919 + [ProviderInstanceId.make("claudeAgent")]: {
920 + driver: ProviderDriverKind.make("claudeAgent"),
921 + enabled: false,
922 + config: {},
923 + },
924 + });
925 + // The file is rewritten once: instances persist and the retired map is gone.
926 + const persisted = JSON.parse(yield* fileSystem.readFileString(serverConfig.settingsPath));
927 + assert.isUndefined(persisted.providers);
928 + assert.equal(persisted.addProjectBaseDirectory, "~/Development");
929 + assert.deepEqual(persisted.providerInstances.codex, {
930 + driver: "codex",
931 + config: { binaryPath: "/opt/guard/bin/codex" },
932 + });
933 }).pipe(Effect.provide(layerServerSettings())),
934 );
935
956 - it.effect("preserves existing provider instances without explicit enabled flags", () =>
936 + it.effect("keeps an explicit default instance over the legacy blob for its driver", () =>
937 Effect.gen(function* () {
938 const serverConfig = yield* ServerConfig.ServerConfig;
939 const fileSystem = yield* FileSystem.FileSystem;
940 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
941 yield* fileSystem.writeFileString(
942 serverConfig.settingsPath,
963 - '{"providerInstances":{"cursor_work":{"driver":"cursor","config":{}},"grok":{"driver":"grok","config":{}},"opencode_work":{"driver":"opencode","config":{"serverUrl":"http://127.0.0.1:4096"}},"opencode_unused":{"driver":"opencode","config":{}}}}',
943 + JSON.stringify({
944 + providers: { codex: { binaryPath: "/legacy/codex" } },
945 + providerInstances: {
946 + codex: { driver: "codex", enabled: true, config: { binaryPath: "/explicit/codex" } },
947 + },
948 + }),
949 );
965 - yield* recordProviderUsage("cursor", "cursor_work");
966 - yield* recordProviderUsage("grok", null);
967 - yield* recordProviderUsage("opencode", "opencode_work");
950
951 const settings = yield* serverSettings.getSettings;
952
971 - assert.isTrue(settings.providers.cursor.enabled);
972 - assert.isTrue(settings.providerInstances[ProviderInstanceId.make("cursor_work")]?.enabled);
973 - assert.isTrue(settings.providerInstances[ProviderInstanceId.make("grok")]?.enabled);
974 - assert.isTrue(settings.providerInstances[ProviderInstanceId.make("opencode_work")]?.enabled);
975 - const unused = settings.providerInstances[ProviderInstanceId.make("opencode_unused")];
976 - assert.isDefined(unused);
977 - assert.isFalse(resolveProviderInstanceEnabled(unused));
953 + assert.deepEqual(settings.providerInstances[ProviderInstanceId.make("codex")], {
954 + driver: ProviderDriverKind.make("codex"),
955 + enabled: true,
956 + config: { binaryPath: "/explicit/codex" },
957 + });
958 }).pipe(Effect.provide(layerServerSettings())),
959 );
960
981 - it.effect("preserves explicit provider disables in existing settings files", () =>
961 + it.effect("enables previously used optional providers while migrating legacy settings", () =>
962 Effect.gen(function* () {
963 const serverConfig = yield* ServerConfig.ServerConfig;
964 const fileSystem = yield* FileSystem.FileSystem;
965 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
966 yield* fileSystem.writeFileString(
967 serverConfig.settingsPath,
988 - '{"providers":{"grok":{"enabled":false},"opencode":{"enabled":false},"cursor":{"enabled":false}},"providerInstances":{"grok":{"driver":"grok","enabled":false,"config":{}},"opencode":{"driver":"opencode","config":{"enabled":false}},"cursor":{"driver":"cursor","enabled":false,"config":{}}}}',
968 + JSON.stringify({
969 + providers: { opencode: { serverUrl: "http://127.0.0.1:4096" }, cursor: {} },
970 + providerInstances: {
971 + cursor_work: { driver: "cursor", config: {} },
972 + opencode_unused: { driver: "opencode", config: {} },
973 + },
974 + }),
975 );
990 - yield* recordProviderUsage("grok");
976 yield* recordProviderUsage("opencode");
992 - yield* recordProviderUsage("cursor");
977 + yield* recordProviderUsage("grok", null);
978 + yield* recordProviderUsage("cursor", "cursor_work");
979
980 const settings = yield* serverSettings.getSettings;
981
996 - assert.isFalse(settings.providers.grok.enabled);
997 - assert.isFalse(settings.providers.opencode.enabled);
998 - assert.isFalse(settings.providers.cursor.enabled);
999 - assert.isFalse(settings.providerInstances[ProviderInstanceId.make("grok")]?.enabled);
1000 - assert.isFalse(settings.providerInstances[ProviderInstanceId.make("opencode")]?.enabled);
1001 - assert.isFalse(settings.providerInstances[ProviderInstanceId.make("cursor")]?.enabled);
982 + assert.deepEqual(settings.providerInstances[ProviderInstanceId.make("opencode")], {
983 + driver: ProviderDriverKind.make("opencode"),
984 + enabled: true,
985 + config: { serverUrl: "http://127.0.0.1:4096" },
986 + });
987 + // Used without any legacy blob or instance: the slot is created enabled.
988 + assert.isTrue(settings.providerInstances[ProviderInstanceId.make("grok")]?.enabled);
989 + assert.isTrue(settings.providerInstances[ProviderInstanceId.make("cursor_work")]?.enabled);
990 + // Using any cursor instance counts as opting into the driver.
991 + assert.isTrue(settings.providerInstances[ProviderInstanceId.make("cursor")]?.enabled);
992 + const unused = settings.providerInstances[ProviderInstanceId.make("opencode_unused")];
993 + assert.isDefined(unused);
994 + assert.isFalse(resolveProviderInstanceEnabled(unused));
995 }).pipe(Effect.provide(layerServerSettings())),
996 );
997
1005 - it.effect("skips a disabled provider instance when picking the text generation fallback", () =>
998 + it.effect("keeps explicit legacy disables even when provider history shows use", () =>
999 Effect.gen(function* () {
1000 const serverConfig = yield* ServerConfig.ServerConfig;
1001 const fileSystem = yield* FileSystem.FileSystem;
1002 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1010 - // The Providers UI writes providerInstances only, so the legacy providers
1011 - // map decodes to defaults where codex is enabled and listed first.
1003 yield* fileSystem.writeFileString(
1004 serverConfig.settingsPath,
1014 - '{"providerInstances":{"codex":{"driver":"codex","enabled":false,"config":{}}}}',
1005 + JSON.stringify({ providers: { grok: { enabled: false, binaryPath: "/opt/grok" } } }),
1006 );
1007 + yield* recordProviderUsage("grok");
1008
1009 const settings = yield* serverSettings.getSettings;
1010
1019 - assert.equal(settings.textGenerationModelSelection.instanceId, "claudeAgent");
1011 + assert.deepEqual(settings.providerInstances[ProviderInstanceId.make("grok")], {
1012 + driver: ProviderDriverKind.make("grok"),
1013 + enabled: false,
1014 + config: { binaryPath: "/opt/grok" },
1015 + });
1016 }).pipe(Effect.provide(layerServerSettings())),
1017 );
1018
1023 - it.effect("keeps unused providers disabled in existing sparse settings files", () =>
1019 + it.effect("runs provider history only for files that still carry the legacy map", () =>
1020 Effect.gen(function* () {
1021 const serverConfig = yield* ServerConfig.ServerConfig;
1022 const fileSystem = yield* FileSystem.FileSystem;
1023 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1024 yield* fileSystem.writeFileString(serverConfig.settingsPath, "{}");
1029 -
1030 - const settings = yield* serverSettings.getSettings;
1031 -
1032 - assert.isFalse(settings.providers.grok.enabled);
1033 - assert.isFalse(settings.providers.opencode.enabled);
1034 - assert.isFalse(settings.providers.cursor.enabled);
1035 - }).pipe(Effect.provide(layerServerSettings())),
1036 - );
1037 -
1038 - it.effect("preserves provider history when no settings file exists", () =>
1039 - Effect.gen(function* () {
1040 - const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1025 yield* recordProviderUsage("grok");
1026
1027 const settings = yield* serverSettings.getSettings;
1028
1045 - assert.isTrue(settings.providers.grok.enabled);
1046 - assert.isFalse(settings.providers.opencode.enabled);
1047 - assert.isFalse(settings.providers.cursor.enabled);
1029 + assert.deepEqual(settings.providerInstances, {});
1030 }).pipe(Effect.provide(layerServerSettings())),
1031 );
1032
1051 - it.effect("preserves provider history when the settings file is invalid", () =>
1033 + it.effect("migrates legacy providers from an invalid file without rewriting it", () =>
1034 Effect.gen(function* () {
1035 const serverConfig = yield* ServerConfig.ServerConfig;
1036 const fileSystem = yield* FileSystem.FileSystem;
1037 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1056 - yield* fileSystem.writeFileString(serverConfig.settingsPath, "{invalid json");
1057 - yield* recordProviderUsage("cursor");
1038 + const raw = '{"addProjectBaseDirectory":42,"providers":{"codex":{"binaryPath":"/x"}}}';
1039 + yield* fileSystem.writeFileString(serverConfig.settingsPath, raw);
1040
1041 const settings = yield* serverSettings.getSettings;
1042
1061 - assert.isTrue(settings.providers.cursor.enabled);
1062 - assert.isFalse(settings.providers.grok.enabled);
1063 - assert.isFalse(settings.providers.opencode.enabled);
1043 + // The readable provider settings still apply, but the file stays for the user to repair.
1044 + assert.deepEqual(settings.providerInstances[ProviderInstanceId.make("codex")], {
1045 + driver: ProviderDriverKind.make("codex"),
1046 + config: { binaryPath: "/x" },
1047 + });
1048 + assert.equal(yield* fileSystem.readFileString(serverConfig.settingsPath), raw);
1049 }).pipe(Effect.provide(layerServerSettings())),
1050 );
1051
1067 - it.effect("preserves valid provider flags when another settings field is invalid", () =>
1052 + it.effect("skips a disabled provider instance when picking the text generation fallback", () =>
1053 Effect.gen(function* () {
1054 const serverConfig = yield* ServerConfig.ServerConfig;
1055 const fileSystem = yield* FileSystem.FileSystem;
1056 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1057 yield* fileSystem.writeFileString(
1058 serverConfig.settingsPath,
1074 - '{"addProjectBaseDirectory":42,"providers":{"cursor":{"enabled":false},"grok":{"enabled":true}}}',
1059 + '{"providerInstances":{"codex":{"driver":"codex","enabled":false,"config":{}}}}',
1060 );
1076 - yield* recordProviderUsage("cursor");
1077 -
1078 - const settings = yield* serverSettings.getSettings;
1079 -
1080 - assert.isFalse(settings.providers.cursor.enabled);
1081 - assert.isTrue(settings.providers.grok.enabled);
1082 - assert.isFalse(settings.providers.opencode.enabled);
1083 - }).pipe(Effect.provide(layerServerSettings())),
1084 - );
1085 -
1086 - it.effect("restores providers from persisted runtime sessions", () =>
1087 - Effect.gen(function* () {
1088 - const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1089 - const sql = yield* SqlClient.SqlClient;
1090 - yield* sql`
1091 - INSERT INTO provider_session_runtime (
1092 - thread_id,
1093 - provider_name,
1094 - provider_instance_id,
1095 - adapter_key,
1096 - status,
1097 - last_seen_at
1098 - )
1099 - VALUES (
1100 - ${"thread-opencode-runtime"},
1101 - ${"opencode"},
1102 - ${"opencode"},
1103 - ${"opencode"},
1104 - ${"ready"},
1105 - ${"2026-08-25T00:00:00.000Z"}
1106 - )
1107 - `;
1061
1062 const settings = yield* serverSettings.getSettings;
1063
1111 - assert.isFalse(settings.providers.grok.enabled);
1112 - assert.isTrue(settings.providers.opencode.enabled);
1113 - assert.isFalse(settings.providers.cursor.enabled);
1114 - }).pipe(Effect.provide(layerServerSettings())),
1115 - );
1116 -
1117 - it.effect("persists explicit disables after a provider has been used", () =>
1118 - Effect.gen(function* () {
1119 - const serverConfig = yield* ServerConfig.ServerConfig;
1120 - const fileSystem = yield* FileSystem.FileSystem;
1121 - const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1122 - yield* recordProviderUsage("grok");
1123 -
1124 - assert.isTrue((yield* serverSettings.getSettings).providers.grok.enabled);
1125 -
1126 - const settings = yield* serverSettings.updateSettings({
1127 - providers: { grok: { enabled: false } },
1128 - });
1129 - assert.isFalse(settings.providers.grok.enabled);
1130 -
1131 - const raw = yield* fileSystem.readFileString(serverConfig.settingsPath);
1132 - assert.isFalse(JSON.parse(raw).providers.grok.enabled);
1133 - }).pipe(Effect.provide(layerServerSettings())),
1134 - );
1135 -
1136 - it.effect("persists explicit provider enables before their first use", () =>
1137 - Effect.gen(function* () {
1138 - const serverConfig = yield* ServerConfig.ServerConfig;
1139 - const fileSystem = yield* FileSystem.FileSystem;
1140 - const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1141 -
1142 - yield* serverSettings.updateSettings({
1143 - providers: {
1144 - cursor: { enabled: true },
1145 - grok: { enabled: true },
1146 - opencode: { enabled: true },
1147 - },
1148 - });
1149 - yield* serverSettings.updateSettings({ addProjectBaseDirectory: "~/Development" });
1150 -
1151 - const raw = yield* fileSystem.readFileString(serverConfig.settingsPath);
1152 - const persisted = JSON.parse(raw);
1153 - assert.isTrue(persisted.providers.cursor.enabled);
1154 - assert.isTrue(persisted.providers.grok.enabled);
1155 - assert.isTrue(persisted.providers.opencode.enabled);
1064 + assert.equal(settings.textGenerationModelSelection.instanceId, "claudeAgent");
1065 }).pipe(Effect.provide(layerServerSettings())),
1066 );
1067
1159 - it.effect("keeps optional providers disabled after a new installation writes settings", () =>
1068 + it.effect("keeps a default-off provider's new instance disabled and sparse on disk", () =>
1069 Effect.gen(function* () {
1070 const serverConfig = yield* ServerConfig.ServerConfig;
1071 const fileSystem = yield* FileSystem.FileSystem;
1072 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1073
1165 - const initial = yield* serverSettings.getSettings;
1166 - assert.isFalse(initial.providers.grok.enabled);
1167 - assert.isFalse(initial.providers.opencode.enabled);
1168 - assert.isFalse(initial.providers.cursor.enabled);
1169 -
1074 const next = yield* serverSettings.updateSettings({
1171 - addProjectBaseDirectory: "~/Development",
1075 providerInstances: {
1076 [ProviderInstanceId.make("grok")]: {
1077 driver: ProviderDriverKind.make("grok"),
@@ -1177,18 +1080,11 @@ it.layer(NodeServices.layer)("server settings", (it) => {
1080 },
1081 });
1082
1180 - assert.isFalse(next.providers.grok.enabled);
1181 - assert.isFalse(next.providers.opencode.enabled);
1182 - assert.isFalse(next.providers.cursor.enabled);
1083 const grok = next.providerInstances[ProviderInstanceId.make("grok")];
1084 assert.isDefined(grok);
1085 assert.isFalse(resolveProviderInstanceEnabled(grok));
1186 -
1187 - const raw = yield* fileSystem.readFileString(serverConfig.settingsPath);
1188 - const persisted = JSON.parse(raw);
1189 - assert.isFalse(persisted.providers.cursor.enabled);
1190 - assert.isFalse(persisted.providers.grok.enabled);
1191 - assert.isFalse(persisted.providers.opencode.enabled);
1086 + const persisted = JSON.parse(yield* fileSystem.readFileString(serverConfig.settingsPath));
1087 + assert.isUndefined(persisted.providers);
1088 assert.isUndefined(persisted.providerInstances.grok.enabled);
1089 }).pipe(Effect.provide(layerServerSettings())),
1090 );
@@ -1252,54 +1148,6 @@ it.layer(NodeServices.layer)("server settings", (it) => {
1148 }).pipe(Effect.provide(layerServerSettings())),
1149 );
1150
1255 - it.effect("trims provider path settings when updates are applied", () =>
1256 - Effect.gen(function* () {
1257 - const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1258 -
1259 - const next = yield* serverSettings.updateSettings({
1260 - providers: {
1261 - codex: {
1262 - binaryPath: " /opt/homebrew/bin/codex ",
1263 - homePath: " ",
1264 - },
1265 - claudeAgent: {
1266 - binaryPath: " /opt/homebrew/bin/claude ",
1267 - },
1268 - opencode: {
1269 - binaryPath: " /opt/homebrew/bin/opencode ",
1270 - serverUrl: " http://127.0.0.1:4096 ",
1271 - serverPassword: " secret-password ",
1272 - },
1273 - },
1274 - });
1275 -
1276 - assert.deepEqual(next.providers.codex, {
1277 - enabled: true,
1278 - binaryPath: "/opt/homebrew/bin/codex",
1279 - homePath: "",
1280 - shadowHomePath: "",
1281 - launchArgs: "",
1282 - customModels: [],
1283 - });
1284 - assert.deepEqual(next.providers.claudeAgent, {
1285 - enabled: true,
1286 - binaryPath: "/opt/homebrew/bin/claude",
1287 - homePath: "",
1288 - customModels: [],
1289 - launchArgs: "",
1290 - autoCompactWindow: "",
1291 - });
1292 - assert.deepEqual(next.providers.opencode, {
1293 - // OpenCode is disabled by default; this update only touches paths.
1294 - enabled: false,
1295 - binaryPath: "/opt/homebrew/bin/opencode",
1296 - serverUrl: "http://127.0.0.1:4096",
1297 - serverPassword: "secret-password",
1298 - customModels: [],
1299 - });
1300 - }).pipe(Effect.provide(layerServerSettings())),
1301 - );
1302 -
1151 it.effect("trims observability settings when updates are applied", () =>
1152 Effect.gen(function* () {
1153 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
@@ -1322,51 +1170,20 @@ it.layer(NodeServices.layer)("server settings", (it) => {
1170 }).pipe(Effect.provide(layerServerSettings())),
1171 );
1172
1325 - it.effect("defaults blank binary paths to provider executables", () =>
1326 - Effect.gen(function* () {
1327 - const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1328 -
1329 - const next = yield* serverSettings.updateSettings({
1330 - providers: {
1331 - codex: {
1332 - binaryPath: " ",
1333 - },
1334 - claudeAgent: {
1335 - binaryPath: "",
1336 - },
1337 - },
1338 - });
1339 -
1340 - assert.equal(next.providers.codex.binaryPath, "codex");
1341 - assert.equal(next.providers.claudeAgent.binaryPath, "claude");
1342 - }).pipe(Effect.provide(layerServerSettings())),
1343 - );
1344 -
1345 - it.effect("writes non-default settings and explicit optional provider defaults to disk", () =>
1173 + it.effect("writes only non-default settings to disk", () =>
1174 Effect.gen(function* () {
1175 const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
1176 const serverConfig = yield* ServerConfig.ServerConfig;
1177 const fileSystem = yield* FileSystem.FileSystem;
1350 - const next = yield* serverSettings.updateSettings({
1178 + yield* serverSettings.updateSettings({
1179 addProjectBaseDirectory: "~/Development",
1180 observability: {
1181 otlpTracesUrl: "http://localhost:4318/v1/traces",
1182 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
1183 },
1356 - providers: {
1357 - codex: {
1358 - binaryPath: "/opt/homebrew/bin/codex",
1359 - },
1360 - opencode: {
1361 - serverUrl: "http://127.0.0.1:4096",
1362 - serverPassword: "secret-password",
1363 - },
1364 - },
1184 automaticGitFetchInterval: Duration.seconds(10),
1185 });
1186
1368 - assert.equal(next.providers.codex.binaryPath, "/opt/homebrew/bin/codex");
1369 -
1187 const raw = yield* fileSystem.readFileString(serverConfig.settingsPath);
1188 assert.deepEqual(JSON.parse(raw), {
1189 addProjectBaseDirectory: "~/Development",
@@ -1374,22 +1191,6 @@ it.layer(NodeServices.layer)("server settings", (it) => {
1191 otlpTracesUrl: "http://localhost:4318/v1/traces",
1192 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
1193 },
1377 - providers: {
1378 - codex: {
1379 - binaryPath: "/opt/homebrew/bin/codex",
1380 - },
1381 - cursor: {
1382 - enabled: false,
1383 - },
1384 - grok: {
1385 - enabled: false,
1386 - },
1387 - opencode: {
1388 - enabled: false,
1389 - serverUrl: "http://127.0.0.1:4096",
1390 - serverPassword: "secret-password",
1391 - },
1392 - },
1194 backgroundActivity: {
1195 schemaVersion: 1,
1196 profile: "custom",
apps/server/src/serverSettings.ts
+102 -67
@@ -23,6 +23,8 @@ import {
23 type ProviderInstanceEnvironmentVariable,
24 type UsageLimitSourceConfig,
25 type ProviderInstanceMutation,
26 + defaultInstanceIdForDriver,
27 + isProviderDriverKind,
28 ProviderDriverKind,
29 ProviderInstanceId,
30 resolveProviderInstanceEnabled,
@@ -384,69 +386,110 @@ const ServerSettingsJson = fromLenientJson(
386 }),
387 );
388 const decodeServerSettingsJsonExit = Schema.decodeUnknownExit(ServerSettingsJson);
387 -const PersistedOptionalProviderSettings = Schema.Struct({
388 - providers: Schema.optionalKey(
389 - Schema.Struct({
390 - cursor: Schema.optionalKey(Schema.Struct({ enabled: Schema.optionalKey(Schema.Boolean) })),
391 - grok: Schema.optionalKey(Schema.Struct({ enabled: Schema.optionalKey(Schema.Boolean) })),
392 - opencode: Schema.optionalKey(Schema.Struct({ enabled: Schema.optionalKey(Schema.Boolean) })),
393 - }),
394 - ),
395 -});
396 -const decodePersistedOptionalProviderSettingsJsonExit = Schema.decodeUnknownExit(
397 - fromLenientJson(PersistedOptionalProviderSettings),
389 +/**
390 + * The retired `providers.<kind>` map, read without its old schemas. Before
391 + * `providerInstances` existed each built-in driver had one blob there; it
392 + * now only feeds `migrateLegacyProviderSettings`.
393 + */
394 +const LegacyProviderSettingsJson = fromLenientJson(
395 + Schema.Struct({
396 + providers: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
397 + }),
398 );
399 +const decodeLegacyProviderSettingsJsonExit = Schema.decodeUnknownExit(LegacyProviderSettingsJson);
400
400 -function restoreUsedProviders(
401 +// Drivers that start disabled, so a session in the history means the user
402 +// turned them on before the instance kept an explicit flag.
403 +const HISTORY_RESTORED_DRIVERS: ReadonlySet<ProviderDriverKind> = new Set(
404 + ["cursor", "grok", "opencode"].map((driver) => ProviderDriverKind.make(driver)),
405 +);
406 +
407 +/**
408 + * Move each customized legacy `providers.<kind>` blob into the driver's
409 + * default `providerInstances` slot. An explicit instance already in that slot
410 + * wins. Blobs that match a fresh install (empty, or only an `enabled` flag
411 + * equal to the driver default) carry nothing and are dropped.
412 + *
413 + * A cursor/grok/opencode slot without an `enabled` flag is enabled when
414 + * provider history shows the driver was used, which is how those drivers
415 + * were opted into before they had an explicit flag. Callers run this only
416 + * while the settings file still has the retired map, so it happens once.
417 + */
418 +function migrateLegacyProviderSettings(
419 settings: ServerSettings,
402 - persisted: typeof PersistedOptionalProviderSettings.Type,
420 + legacyProviders: Readonly<Record<string, unknown>>,
421 providerHistory: ReadonlyArray<{
422 readonly providerName: string;
423 readonly providerInstanceId: string | null;
424 }>,
425 ): ServerSettings {
408 - const usedProviders = new Set(providerHistory.map(({ providerName }) => providerName));
409 - const usedProviderInstances = new Set(
426 + // History rows are raw SQL text; compare them as strings.
427 + const usedProviders = new Set<string>(providerHistory.map(({ providerName }) => providerName));
428 + const usedProviderInstances = new Set<string>(
429 providerHistory.map(
430 ({ providerName, providerInstanceId }) => providerInstanceId ?? providerName,
431 ),
432 );
414 - const providerInstances = Object.fromEntries(
415 - Object.entries(settings.providerInstances).map(([instanceId, instance]) => [
416 - instanceId,
433 +
434 + const providerInstances: Record<ProviderInstanceId, ProviderInstanceConfig> = {};
435 + for (const [instanceId, instance] of Object.entries(settings.providerInstances) as Array<
436 + [ProviderInstanceId, ProviderInstanceConfig]
437 + >) {
438 + providerInstances[instanceId] =
439 instance.enabled === undefined &&
418 - (instance.driver === "cursor" ||
419 - instance.driver === "grok" ||
420 - instance.driver === "opencode") &&
440 + HISTORY_RESTORED_DRIVERS.has(instance.driver) &&
441 usedProviderInstances.has(instanceId)
442 ? { ...instance, enabled: true }
423 - : instance,
424 - ]),
425 - );
443 + : instance;
444 + }
445 +
446 + // History restores a never-configured cursor/grok/opencode slot too.
447 + const legacyEntries = new Map(Object.entries(legacyProviders));
448 + for (const driver of HISTORY_RESTORED_DRIVERS) {
449 + if (!legacyEntries.has(driver)) legacyEntries.set(driver, {});
450 + }
451 + for (const [kind, blob] of legacyEntries) {
452 + if (!isProviderDriverKind(kind) || blob === null || typeof blob !== "object") continue;
453 + if (Array.isArray(blob)) continue;
454 + const driver = kind;
455 + const instanceId = defaultInstanceIdForDriver(driver);
456 + if (Object.hasOwn(providerInstances, instanceId)) continue;
457 +
458 + const { enabled: rawEnabled, ...config } = blob as Record<string, unknown>;
459 + const explicitEnabled = typeof rawEnabled === "boolean" ? rawEnabled : undefined;
460 + const enabled =
461 + explicitEnabled ??
462 + (HISTORY_RESTORED_DRIVERS.has(driver) && usedProviders.has(driver) ? true : undefined);
463 + const driverDefault = resolveProviderInstanceEnabled({ driver, config: {} });
464 + if (Object.keys(config).length === 0 && (enabled === undefined || enabled === driverDefault)) {
465 + continue;
466 + }
467 + providerInstances[instanceId] = {
468 + driver,
469 + ...(enabled === undefined ? {} : { enabled }),
470 + config,
471 + } satisfies ProviderInstanceConfig;
472 + }
473
474 return {
475 ...settings,
429 - providers: {
430 - ...settings.providers,
431 - cursor: {
432 - ...settings.providers.cursor,
433 - enabled: persisted.providers?.cursor?.enabled ?? usedProviders.has("cursor"),
434 - },
435 - grok: {
436 - ...settings.providers.grok,
437 - enabled: persisted.providers?.grok?.enabled ?? usedProviders.has("grok"),
438 - },
439 - opencode: {
440 - ...settings.providers.opencode,
441 - enabled: persisted.providers?.opencode?.enabled ?? usedProviders.has("opencode"),
442 - },
443 - },
476 providerInstances,
477 };
478 }
479
480 const ACP_REGISTRY_DRIVER = ProviderDriverKind.make("acpRegistry");
481
482 +const TEXT_GENERATION_FALLBACK_DRIVERS = [
483 + "codex",
484 + "claudeAgent",
485 + "cursor",
486 + "grok",
487 + "muse",
488 + "pi",
489 + "opencode",
490 + "antigravity",
491 +].map((driver) => ProviderDriverKind.make(driver));
492 +
493 /** ACP Registry instances reject every application text-generation operation. */
494 function selectionSupportsTextGeneration(
495 settings: ServerSettings,
@@ -463,14 +506,13 @@ function resolveTextGenerationProvider(settings: ServerSettings): ServerSettings
506 }
507
508 function fallbackTextGenerationProvider(settings: ServerSettings): ServerSettings {
466 - // Same precedence as isModelSelectionProviderEnabled: an explicit provider
467 - // instance wins over the legacy providers map, which decodes to defaults
468 - // (codex enabled) when the Providers UI has only written providerInstances.
469 - const fallbackEntry = Object.entries(settings.providers).find(([driver, provider]) => {
470 - const instance = settings.providerInstances[ProviderInstanceId.make(driver)];
471 - return instance === undefined ? provider.enabled : resolveProviderInstanceEnabled(instance);
472 - });
473 - const fallback = fallbackEntry ? ProviderDriverKind.make(fallbackEntry[0]) : undefined;
509 + // The built-in default instances in preference order. A slot without an
510 + // explicit instance uses its driver's default enabled state.
511 + const fallback = TEXT_GENERATION_FALLBACK_DRIVERS.find((driver) =>
512 + resolveProviderInstanceEnabled(
513 + settings.providerInstances[defaultInstanceIdForDriver(driver)] ?? { driver, config: {} },
514 + ),
515 + );
516 if (!fallback) {
517 return settings;
518 }
@@ -497,17 +539,6 @@ const ATOMIC_SETTINGS_KEYS: ReadonlySet<string> = new Set([
539 "pullRequestMergeMethod",
540 ]);
541
500 -// Preserve both enabled states because provider history cannot recover a new opt-in.
501 -const PERSISTED_SERVER_SETTINGS_DEFAULTS = {
502 - ...DEFAULT_SERVER_SETTINGS,
503 - providers: {
504 - ...DEFAULT_SERVER_SETTINGS.providers,
505 - cursor: { ...DEFAULT_SERVER_SETTINGS.providers.cursor, enabled: undefined },
506 - grok: { ...DEFAULT_SERVER_SETTINGS.providers.grok, enabled: undefined },
507 - opencode: { ...DEFAULT_SERVER_SETTINGS.providers.opencode, enabled: undefined },
508 - },
509 -};
510 -
542 function stripDefaultServerSettings(current: unknown, defaults: unknown): unknown | undefined {
543 if (Array.isArray(current) || Array.isArray(defaults)) {
544 return Equal.equals(current, defaults) ? undefined : current;
@@ -671,7 +702,7 @@ const make = Effect.gen(function* () {
702 const writeSettingsAtomically = Effect.fnUntraced(
703 function* (settings: ServerSettings) {
704 const sparseSettingsJson = yield* encodeServerSettingsJson(
674 - stripDefaultServerSettings(settings, PERSISTED_SERVER_SETTINGS_DEFAULTS) ?? {},
705 + stripDefaultServerSettings(settings, DEFAULT_SERVER_SETTINGS) ?? {},
706 );
707
708 return yield* writeFileStringAtomically({
@@ -740,7 +771,7 @@ const make = Effect.gen(function* () {
771
772 const loadSettingsFromDisk = Effect.gen(function* () {
773 let settings = DEFAULT_SERVER_SETTINGS;
743 - let persisted: typeof PersistedOptionalProviderSettings.Type = {};
774 + let legacyProviders: Readonly<Record<string, unknown>> | undefined;
775 // A file that failed to decode must stay on disk for the user to repair;
776 // the fold below only writes when it started from the file's real contents.
777 let settingsFileTrusted = true;
@@ -748,12 +779,12 @@ const make = Effect.gen(function* () {
779 if (yield* readConfigExists) {
780 const raw = yield* readRawConfig;
781 const decoded = decodeServerSettingsJsonExit(raw);
751 - const persistedSettings = decodePersistedOptionalProviderSettingsJsonExit(raw);
752 - if (persistedSettings._tag === "Success") {
753 - persisted = persistedSettings.value;
782 + const legacySettings = decodeLegacyProviderSettingsJsonExit(raw);
783 + if (legacySettings._tag === "Success") {
784 + legacyProviders = legacySettings.value.providers;
785 }
755 - if (decoded._tag === "Failure" || persistedSettings._tag === "Failure") {
756 - const failure = decoded._tag === "Failure" ? decoded : persistedSettings;
786 + if (decoded._tag === "Failure" || legacySettings._tag === "Failure") {
787 + const failure = decoded._tag === "Failure" ? decoded : legacySettings;
788 settingsFileTrusted = false;
789 if (failure._tag === "Failure") {
790 yield* Effect.logWarning("failed to parse settings.json, using defaults", {
@@ -817,14 +848,18 @@ const make = Effect.gen(function* () {
848 );
849
850 const loaded = foldProviderInstanceEnabledFlags(
820 - restoreUsedProviders(settings, persisted, providerHistory),
851 + legacyProviders === undefined
852 + ? settings
853 + : migrateLegacyProviderSettings(settings, legacyProviders, providerHistory),
854 );
855 const folded = settingsFileTrusted
856 ? foldLegacyProjectSettings(loaded, legacyProjectRows)
857 : loaded;
858 // Only rewrite a file that decoded cleanly; an untrusted one stays for the user to repair.
859 const migrated = settingsFileTrusted ? yield* moveInlineBitbucketTokens(folded) : folded;
827 - if (migrated !== loaded) {
860 + // A file still carrying the retired `providers` map is rewritten once so
861 + // the migrated instances persist and the old key disappears.
862 + if (migrated !== loaded || (settingsFileTrusted && legacyProviders !== undefined)) {
863 yield* writeSettingsAtomically(migrated);
864 }
865 return migrated;
apps/server/src/terminal/Manager.test.ts
+21 -23
@@ -2272,7 +2272,7 @@ it.layer(
2272 ),
2273 );
2274
2275 - it.effect("resolves the legacy Codex default instance", () =>
2275 + it.effect("resolves the Codex default slot", () =>
2276 Effect.gen(function* () {
2277 const path = yield* Path.Path;
2278 const serverSettings = yield* ServerSettings.ServerSettingsService;
@@ -2283,18 +2283,22 @@ it.layer(
2283 env: undefined,
2284 });
2285
2286 - expect(environment.CODEX_HOME).toMatch(/[\\/][.]codex-legacy$/);
2286 + expect(environment.CODEX_HOME).toMatch(/[\\/][.]codex-default$/);
2287 }).pipe(
2288 Effect.provide(
2289 ServerSettings.ServerSettingsService.layerTest({
2290 - providerInstances: {},
2291 - providers: { codex: { homePath: "~/.codex-legacy" } },
2290 + providerInstances: {
2291 + [ProviderInstanceId.make("codex")]: {
2292 + driver: ProviderDriverKind.make("codex"),
2293 + config: { homePath: "~/.codex-default" },
2294 + },
2295 + },
2296 }),
2297 ),
2298 ),
2299 );
2300
2297 - it.effect("resolves the legacy Claude default instance", () =>
2301 + it.effect("resolves the Claude default slot", () =>
2302 Effect.gen(function* () {
2303 const path = yield* Path.Path;
2304 const serverSettings = yield* ServerSettings.ServerSettingsService;
@@ -2305,18 +2309,22 @@ it.layer(
2309 env: undefined,
2310 });
2311
2308 - expect(environment.CLAUDE_CONFIG_DIR).toMatch(/[\\/][.]claude-legacy$/);
2312 + expect(environment.CLAUDE_CONFIG_DIR).toMatch(/[\\/][.]claude-default$/);
2313 }).pipe(
2314 Effect.provide(
2315 ServerSettings.ServerSettingsService.layerTest({
2312 - providerInstances: {},
2313 - providers: { claudeAgent: { homePath: "~/.claude-legacy" } },
2316 + providerInstances: {
2317 + [ProviderInstanceId.make("claudeAgent")]: {
2318 + driver: ProviderDriverKind.make("claudeAgent"),
2319 + config: { homePath: "~/.claude-default" },
2320 + },
2321 + },
2322 }),
2323 ),
2324 ),
2325 );
2326
2319 - it.effect("prefers an explicit default instance over legacy provider settings", () =>
2327 + it.effect("resolves an empty Codex default slot with default config", () =>
2328 Effect.gen(function* () {
2329 const path = yield* Path.Path;
2330 const serverSettings = yield* ServerSettings.ServerSettingsService;
@@ -2324,26 +2332,16 @@ it.layer(
2332 serverSettings,
2333 path,
2334 rawProviderInstanceId: "codex",
2327 - env: undefined,
2335 + env: { CODEX_HOME: "/inherited/codex-home" },
2336 });
2337
2330 - expect(environment.CODEX_HOME).toMatch(/[\\/][.]codex-explicit$/);
2338 + expect(environment.CODEX_HOME).toBe("/inherited/codex-home");
2339 }).pipe(
2332 - Effect.provide(
2333 - ServerSettings.ServerSettingsService.layerTest({
2334 - providers: { codex: { homePath: "~/.codex-legacy" } },
2335 - providerInstances: {
2336 - [ProviderInstanceId.make("codex")]: {
2337 - driver: "codex",
2338 - config: { homePath: "~/.codex-explicit" },
2339 - },
2340 - },
2341 - }),
2342 - ),
2340 + Effect.provide(ServerSettings.ServerSettingsService.layerTest({ providerInstances: {} })),
2341 ),
2342 );
2343
2346 - it.effect("keeps unknown provider instance ids unavailable after legacy hydration", () =>
2344 + it.effect("keeps unknown provider instance ids unavailable after default-slot hydration", () =>
2345 Effect.gen(function* () {
2346 const path = yield* Path.Path;
2347 const serverSettings = yield* ServerSettings.ServerSettingsService;
apps/server/src/usage/UsageService.test.ts
+97 -92
@@ -73,9 +73,15 @@ const setup = Effect.gen(function* () {
73 home,
74 transcript: NodePath.join(transcriptDir, "session.jsonl"),
75 settings: {
76 - providers: {
77 - claudeAgent: { homePath: NodePath.join(home, "claude") },
78 - codex: { homePath: NodePath.join(home, "codex") },
76 + providerInstances: {
77 + [ProviderInstanceId.make("claudeAgent")]: {
78 + driver: ProviderDriverKind.make("claudeAgent"),
79 + config: { homePath: NodePath.join(home, "claude") },
80 + },
81 + [ProviderInstanceId.make("codex")]: {
82 + driver: ProviderDriverKind.make("codex"),
83 + config: { homePath: NodePath.join(home, "codex") },
84 + },
85 },
86 },
87 };
@@ -227,98 +233,86 @@ function cursorSource(summary: { readonly sources: readonly UsageSource[] }) {
233 }
234
235 describe("UsageService", () => {
230 - it.live.each([
231 - { explicitDefault: true, label: "explicit" },
232 - { explicitDefault: false, label: "legacy" },
233 - ])(
234 - "reads shared managed $label default and disabled extra account history once",
235 - ({ explicitDefault }) =>
236 - Effect.gen(function* () {
237 - const { home, settings } = yield* setup;
238 - const summary = yield* Effect.gen(function* () {
239 - for (const [id, output] of [
240 - ["codex", 17],
241 - ["codex-personal", 23],
242 - ] as const) {
243 - const sessions = NodePath.join(home, "shared-codex", "sessions");
244 - yield* Effect.promise(async () => {
245 - await NodeFSP.mkdir(sessions, { recursive: true });
246 - await NodeFSP.writeFile(
247 - NodePath.join(sessions, `${id}-rollout.jsonl`),
248 - [
249 - { type: "session_meta", payload: { id } },
250 - { type: "turn_context", payload: { model: "gpt-5.6-sol" } },
251 - {
252 - type: "event_msg",
253 - timestamp: "2026-08-01T10:00:00Z",
254 - payload: {
255 - type: "token_count",
256 - info: { last_token_usage: { input_tokens: 10, output_tokens: output } },
257 - },
236 + it.live("reads shared managed default and disabled extra account history once", () =>
237 + Effect.gen(function* () {
238 + const { home, settings } = yield* setup;
239 + const summary = yield* Effect.gen(function* () {
240 + for (const [id, output] of [
241 + ["codex", 17],
242 + ["codex-personal", 23],
243 + ] as const) {
244 + const sessions = NodePath.join(home, "shared-codex", "sessions");
245 + yield* Effect.promise(async () => {
246 + await NodeFSP.mkdir(sessions, { recursive: true });
247 + await NodeFSP.writeFile(
248 + NodePath.join(sessions, `${id}-rollout.jsonl`),
249 + [
250 + { type: "session_meta", payload: { id } },
251 + { type: "turn_context", payload: { model: "gpt-5.6-sol" } },
252 + {
253 + type: "event_msg",
254 + timestamp: "2026-08-01T10:00:00Z",
255 + payload: {
256 + type: "token_count",
257 + info: { last_token_usage: { input_tokens: 10, output_tokens: output } },
258 },
259 - ]
260 - .map((line) => encodeUnknownJsonString(line))
261 - .join("\n") + "\n",
262 - );
263 - });
264 - }
265 - const service = yield* UsageService.make;
266 - return yield* service.readSummary(WINDOW);
267 - }).pipe(
268 - // Scoped inside the state directory, so pending cache writes land
269 - // before it is removed.
270 - Effect.scoped,
271 - Effect.provide(
272 - layerService({
273 - prefix: "usage-managed-accounts",
274 - home,
275 - settings: {
276 - ...settings,
277 - providers: {
278 - ...settings.providers,
279 - codex: { setupMode: "managed", homePath: NodePath.join(home, "shared-codex") },
259 },
281 - providerInstances: {
282 - ...(explicitDefault
283 - ? {
284 - [ProviderInstanceId.make("codex")]: {
285 - driver: ProviderDriverKind.make("codex"),
286 - config: {
287 - setupMode: "managed",
288 - homePath: NodePath.join(home, "shared-codex"),
289 - },
290 - },
291 - }
292 - : {}),
293 - [ProviderInstanceId.make("codex-personal")]: {
294 - driver: ProviderDriverKind.make("codex"),
295 - enabled: false,
296 - config: {
297 - setupMode: "managed",
298 - homePath: NodePath.join(home, "shared-codex"),
299 - shadowHomePath: NodePath.join(home, "personal-shadow"),
300 - },
301 - environment: [
302 - {
303 - name: "CODEX_HOME",
304 - value: NodePath.join(home, "ignored-environment"),
305 - sensitive: false,
306 - },
307 - ],
260 + ]
261 + .map((line) => encodeUnknownJsonString(line))
262 + .join("\n") + "\n",
263 + );
264 + });
265 + }
266 + const service = yield* UsageService.make;
267 + return yield* service.readSummary(WINDOW);
268 + }).pipe(
269 + // Scoped inside the state directory, so pending cache writes land
270 + // before it is removed.
271 + Effect.scoped,
272 + Effect.provide(
273 + layerService({
274 + prefix: "usage-managed-accounts",
275 + home,
276 + settings: {
277 + ...settings,
278 + providerInstances: {
279 + ...settings.providerInstances,
280 + [ProviderInstanceId.make("codex")]: {
281 + driver: ProviderDriverKind.make("codex"),
282 + config: {
283 + setupMode: "managed",
284 + homePath: NodePath.join(home, "shared-codex"),
285 + },
286 + },
287 + [ProviderInstanceId.make("codex-personal")]: {
288 + driver: ProviderDriverKind.make("codex"),
289 + enabled: false,
290 + config: {
291 + setupMode: "managed",
292 + homePath: NodePath.join(home, "shared-codex"),
293 + shadowHomePath: NodePath.join(home, "personal-shadow"),
294 },
295 + environment: [
296 + {
297 + name: "CODEX_HOME",
298 + value: NodePath.join(home, "ignored-environment"),
299 + sensitive: false,
300 + },
301 + ],
302 },
303 },
311 - }),
312 - ),
313 - );
314 - assert.strictEqual(totalOutputTokens(summary), 40);
315 - assert.strictEqual(
316 - summary.sources.filter(
317 - (source) => source.fingerprint.provider === "codex" && source.status === "ok",
318 - ).length,
319 - 1,
320 - );
321 - }).pipe(Effect.scoped),
304 + },
305 + }),
306 + ),
307 + );
308 + assert.strictEqual(totalOutputTokens(summary), 40);
309 + assert.strictEqual(
310 + summary.sources.filter(
311 + (source) => source.fingerprint.provider === "codex" && source.status === "ok",
312 + ).length,
313 + 1,
314 + );
315 + }).pipe(Effect.scoped),
316 );
317 it.live("omits Cursor account usage when no file login is saved", () =>
318 Effect.gen(function* () {
@@ -788,6 +782,7 @@ describe("UsageService", () => {
782 settings: {
783 ...settings,
784 providerInstances: {
785 + ...settings.providerInstances,
786 [ProviderInstanceId.make("claude-work")]: {
787 driver: ProviderDriverKind.make("claudeAgent"),
788 enabled: false,
@@ -847,7 +842,7 @@ describe("UsageService", () => {
842 );
843
844 it.live(
850 - "uses explicit account settings before environment and legacy homes, then refreshes them",
845 + "uses explicit account settings before environment and default homes, then refreshes them",
846 () =>
847 Effect.gen(function* () {
848 const { transcript, settings, home } = yield* setup;
@@ -884,6 +879,7 @@ describe("UsageService", () => {
879 );
880 yield* settingsService.updateSettings({
881 providerInstances: {
882 + ...settings.providerInstances,
883 [ProviderInstanceId.make("claudeAgent")]: {
884 driver: ProviderDriverKind.make("claudeAgent"),
885 config: { homePath: "" },
@@ -912,6 +908,7 @@ describe("UsageService", () => {
908 settings: {
909 ...settings,
910 providerInstances: {
911 + ...settings.providerInstances,
912 [ProviderInstanceId.make("claudeAgent")]: {
913 driver: ProviderDriverKind.make("claudeAgent"),
914 config: { homePath: configured },
@@ -1271,7 +1268,15 @@ describe("UsageService", () => {
1268 layerService({
1269 prefix: "usage-service-cleanup-test",
1270 home,
1274 - settings: { providers: { ...settings.providers, claudeAgent: { homePath: alias } } },
1271 + settings: {
1272 + providerInstances: {
1273 + ...settings.providerInstances,
1274 + [ProviderInstanceId.make("claudeAgent")]: {
1275 + driver: ProviderDriverKind.make("claudeAgent"),
1276 + config: { homePath: alias },
1277 + },
1278 + },
1279 + },
1280 ratesDocument: {
1281 "claude-fable-5": { input_cost_per_token: 1e-5, output_cost_per_token: 5e-5 },
1282 },
apps/server/src/usage/UsageService.ts
+3 -6
@@ -351,18 +351,15 @@ export const make = Effect.gen(function* () {
351 }> = [];
352 const seen = new Set<string>();
353 for (const driver of ["claudeAgent", "codex", "grok"] as const) {
354 - // Disabled accounts still have history. Explicit default slots replace
355 - // the legacy settings, just as they do in the provider registry.
354 + // Disabled accounts still have history. An unconfigured default slot
355 + // runs with default config, just as it does in the provider registry.
356 const instances: Array<
357 Pick<ProviderInstanceConfig, "config" | "environment"> & { instanceId: ProviderInstanceId }
358 > = Object.entries(settings.providerInstances)
359 .filter(([, instance]) => instance.driver === driver)
360 .map(([id, instance]) => ({ ...instance, instanceId: ProviderInstanceId.make(id) }));
361 if (!Object.hasOwn(settings.providerInstances, driver)) {
362 - instances.push({
363 - config: settings.providers[driver],
364 - instanceId: ProviderInstanceId.make(driver),
365 - });
362 + instances.push({ instanceId: ProviderInstanceId.make(driver) });
363 }
364 for (const instance of instances) {
365 const environment = mergeProviderInstanceEnvironment(instance.environment, hostEnvironment);
apps/web/src/components/onboarding/WelcomeWizard.tsx
+1 -4
@@ -898,8 +898,7 @@ function OnboardingCodexSetup({
898 const settings = serverConfig.settings;
899 const instance = settings.providerInstances[instanceId] ?? {
900 driver: ProviderDriverKind.make("codex"),
901 - enabled: settings.providers.codex.enabled,
902 - config: createdAccount ? { enabled: true, setupMode: "managed" } : settings.providers.codex,
901 + config: createdAccount ? { enabled: true, setupMode: "managed" } : {},
902 };
903 const mode = readCodexSetupMode(instance.config);
904 const existingChosen =
@@ -915,8 +914,6 @@ function OnboardingCodexSetup({
914 patch: buildProviderInstanceUpdatePatch({
915 settings,
916 instanceId,
918 - driver: ProviderDriverKind.make("codex"),
919 - isDefault: instanceId === defaultInstanceIdForDriver(ProviderDriverKind.make("codex")),
917 instance: {
918 ...instance,
919 enabled: true,
apps/web/src/components/settings/AddProviderInstanceDialog.tsx
+6 -11
@@ -7,7 +7,6 @@ import { CheckIcon } from "lucide-react";
7 import { useMemo, useState } from "react";
8 import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
9 import {
10 - DEFAULT_UNIFIED_SETTINGS,
10 type AcpRegistrySearchAgent,
11 AuthProvidersManageScope,
12 ProviderInstanceId,
@@ -21,7 +20,6 @@ import {
20 useEnvironmentSettings,
21 usePersistEnvironmentProviderInstanceMutation,
22 } from "../../hooks/useSettings";
24 -import * as Equal from "effect/Equal";
23
24 import { cn } from "../../lib/utils";
25 import { normalizeProviderAccentColor } from "../../providerInstances";
@@ -139,15 +137,12 @@ export function AddProviderInstanceDialog({
137 const [isSaving, setIsSaving] = useState(false);
138 const [createdInstanceId, setCreatedInstanceId] = useState<ProviderInstanceId | null>(null);
139
142 - const existingIds = useMemo(() => {
143 - const ids = new Set(["codex", "claudeAgent", ...Object.keys(settings.providerInstances ?? {})]);
144 - const defaults = DEFAULT_UNIFIED_SETTINGS.providers as Record<string, unknown>;
145 - // Reserve configured legacy slots too, so adding an account cannot replace them.
146 - for (const [kind, config] of Object.entries(settings.providers ?? {})) {
147 - if (!Equal.equals(config, defaults[kind])) ids.add(kind);
148 - }
149 - return ids;
150 - }, [settings.providerInstances, settings.providers]);
140 + // Codex and Claude run at their default slots before they are configured, so
141 + // those ids stay reserved; other unconfigured default slots are free to take.
142 + const existingIds = useMemo(
143 + () => new Set(["codex", "claudeAgent", ...Object.keys(settings.providerInstances ?? {})]),
144 + [settings.providerInstances],
145 + );
146
147 const driverOption = providerClients.get(driver) ?? DEFAULT_DRIVER_OPTION;
148 const isAcpRegistry = driver === ACP_REGISTRY_DRIVER_KIND;
apps/web/src/components/settings/ProviderSettingsPanel.environment.test.tsx
+8 -8
@@ -276,12 +276,13 @@ describe("EnvironmentProviderSettings routing", () => {
276 it("keeps legacy provider configuration visible when disabled", () => {
277 settingsState.value = {
278 ...DEFAULT_UNIFIED_SETTINGS,
279 - providers: {
280 - ...DEFAULT_UNIFIED_SETTINGS.providers,
281 - grok: {
282 - ...DEFAULT_UNIFIED_SETTINGS.providers.grok,
279 + providerInstances: {
280 + [ProviderInstanceId.make("grok")]: {
281 + driver: ProviderDriverKind.make("grok"),
282 enabled: false,
284 - binaryPath: "/custom/grok",
283 + config: {
284 + binaryPath: "/custom/grok",
285 + },
286 },
287 },
288 };
@@ -516,9 +517,8 @@ describe("EnvironmentProviderSettings routing", () => {
517
518 const [resetMutation, resetPatch] = settingsState.mutateProviderInstance.mock.lastCall ?? [];
519 expect(resetMutation).toEqual({ operation: "remove", instanceId: codexId });
519 - expect(Object.keys(resetPatch ?? {}).sort()).toEqual(["providers"]);
520 - expect(resetPatch).not.toHaveProperty("favorites");
521 - expect(resetPatch).not.toHaveProperty("providerModelPreferences");
520 + // Removing the instance is the whole reset; shared preferences stay untouched.
521 + expect(resetPatch ?? {}).toEqual({});
522 });
523
524 it("updates one provider instance without sending a stale whole map", async () => {
apps/web/src/components/settings/ProviderSettingsPanel.tsx
+22 -64
@@ -147,6 +147,7 @@ function providerConfigString(config: unknown, key: string): string | null {
147
148 const PROVIDER_SETTINGS = providerClients.definitions.map((definition) => ({
149 provider: definition.driverKind,
150 + hasDefaultInstance: definition.hasDefaultInstance !== false,
151 }));
152
153 function configuredBinaryPath(config: unknown): string {
@@ -757,57 +758,29 @@ export function EnvironmentProviderSettings({
758 );
759
760 for (const providerSettings of visibleProviderSettings) {
760 - type LegacyProviderSettings = (typeof settings.providers)[keyof typeof settings.providers];
761 - const legacyProviders = settings.providers as Record<string, LegacyProviderSettings>;
762 - const defaultLegacyProviders = DEFAULT_UNIFIED_SETTINGS.providers as Record<
763 - string,
764 - LegacyProviderSettings
765 - >;
761 const driver = providerSettings.provider;
762 const defaultInstanceId = defaultInstanceIdForDriver(driver);
763 const explicitInstance = settings.providerInstances?.[defaultInstanceId];
769 - // A remote device may run a server version whose settings predate this
770 - // driver, so the legacy mirror can be absent. Without either an explicit
771 - // instance or a legacy blob there is nothing to render for the slot.
772 - const legacyConfig = legacyProviders[providerSettings.provider];
773 - const defaultLegacyConfig = defaultLegacyProviders[providerSettings.provider];
774 - // The envelope is the single enabled flag: keep the legacy in-config
775 - // flag out of the synthesized blob, or an explicit `enabled: false`
776 - // would keep winning over the envelope and the Switch could never
777 - // turn a default-off provider on.
778 - const synthesizedInstance = (): ProviderInstanceConfig | undefined => {
779 - if (legacyConfig === undefined) {
780 - return undefined;
781 - }
782 - const { enabled: legacyEnabled, ...legacyConfigRest } = legacyConfig;
783 - return {
784 - driver,
785 - enabled: legacyEnabled,
786 - config: legacyConfigRest,
787 - } satisfies ProviderInstanceConfig;
788 - };
789 - const effectiveInstance: ProviderInstanceConfig | undefined =
790 - explicitInstance ?? synthesizedInstance();
791 - // Only the default slot depends on the legacy blob; custom instances for
792 - // the driver must still render even when the slot has nothing to show.
793 - if (effectiveInstance !== undefined) {
794 - const isDirty =
795 - explicitInstance !== undefined || !Equal.equals(legacyConfig, defaultLegacyConfig);
796 - if (
797 - driver === "codex" ||
764 + // An unconfigured default slot runs with the driver's default config.
765 + const effectiveInstance: ProviderInstanceConfig = explicitInstance ?? { driver };
766 + const isDirty = explicitInstance !== undefined;
767 + // Drivers without a default instance list only their configured instances.
768 + const hasDefaultSlot = providerSettings.hasDefaultInstance || explicitInstance !== undefined;
769 + if (
770 + hasDefaultSlot &&
771 + (driver === "codex" ||
772 driver === "claudeAgent" ||
773 isDirty ||
774 resolveProviderInstanceEnabled(effectiveInstance) ||
801 - defaultInstanceId === targetInstanceId
802 - ) {
803 - rows.push({
804 - instanceId: defaultInstanceId,
805 - instance: effectiveInstance,
806 - driver,
807 - isDefault: true,
808 - isDirty,
809 - });
810 - }
775 + defaultInstanceId === targetInstanceId)
776 + ) {
777 + rows.push({
778 + instanceId: defaultInstanceId,
779 + instance: effectiveInstance,
780 + driver,
781 + isDefault: true,
782 + isDirty,
783 + });
784 }
785 for (const [id, instance] of instancesByDriver.get(providerSettings.provider) ?? []) {
786 if (id === defaultInstanceId) continue;
@@ -847,8 +820,6 @@ export function EnvironmentProviderSettings({
820 settings,
821 instanceId: row.instanceId,
822 instance: next,
850 - driver: row.driver,
851 - isDefault: row.isDefault,
823 textGenerationModelSelection: options?.textGenerationModelSelection,
824 });
825 const result = await persistProviderInstance(
@@ -947,23 +918,10 @@ export function EnvironmentProviderSettings({
918 };
919
920 const resetDefaultInstance = async (driverKind: ProviderDriverKind) => {
950 - type LegacyProviderSettings = (typeof settings.providers)[keyof typeof settings.providers];
951 - const defaultLegacyProviders = DEFAULT_UNIFIED_SETTINGS.providers as Record<
952 - string,
953 - LegacyProviderSettings | undefined
954 - >;
955 - const defaultInstanceId = defaultInstanceIdForDriver(driverKind);
956 - const defaultLegacyProvider = defaultLegacyProviders[driverKind];
957 - if (defaultLegacyProvider === undefined) return;
958 - const result = await persistProviderInstance(
959 - { operation: "remove", instanceId: defaultInstanceId },
960 - {
961 - providers: {
962 - ...settings.providers,
963 - [driverKind]: defaultLegacyProvider,
964 - } as typeof settings.providers,
965 - },
966 - );
921 + const result = await persistProviderInstance({
922 + operation: "remove",
923 + instanceId: defaultInstanceIdForDriver(driverKind),
924 + });
925 if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
926 const error = squashAtomCommandFailure(result);
927 toastManager.add({
apps/web/src/components/settings/SettingsPanels.logic.test.ts
+8 -38
@@ -190,57 +190,27 @@ describe("formatDiagnosticsDescription", () => {
190 });
191
192 describe("buildProviderInstanceUpdatePatch", () => {
193 - it("promotes an edited default provider into providerInstances and resets the legacy provider", () => {
193 + it("replaces one instance and keeps the others", () => {
194 const instanceId = ProviderInstanceId.make("codex");
195 - const nextInstance = {
195 + const otherId = ProviderInstanceId.make("codex_personal");
196 + const other = {
197 driver: ProviderDriverKind.make("codex"),
197 - enabled: true,
198 - config: {
199 - binaryPath: "/opt/t3/codex",
200 - },
198 + config: { homePath: "/Users/example/.codex-personal" },
199 } satisfies ProviderInstanceConfig;
202 -
203 - const patch = buildProviderInstanceUpdatePatch({
204 - settings: {
205 - ...DEFAULT_SERVER_SETTINGS,
206 - providers: {
207 - ...DEFAULT_SERVER_SETTINGS.providers,
208 - codex: {
209 - ...DEFAULT_SERVER_SETTINGS.providers.codex,
210 - binaryPath: "/legacy/codex",
211 - },
212 - },
213 - },
214 - instanceId,
215 - instance: nextInstance,
216 - driver: ProviderDriverKind.make("codex"),
217 - isDefault: true,
218 - });
219 -
220 - expect(patch.providerInstances?.[instanceId]).toEqual(nextInstance);
221 - expect(patch.providers?.codex).toEqual(DEFAULT_SERVER_SETTINGS.providers.codex);
222 - });
223 -
224 - it("updates custom instances without touching legacy provider settings", () => {
225 - const instanceId = ProviderInstanceId.make("codex_personal");
200 const nextInstance = {
201 driver: ProviderDriverKind.make("codex"),
202 enabled: true,
229 - config: {
230 - homePath: "/Users/example/.codex-personal",
231 - },
203 + config: { binaryPath: "/opt/t3/codex" },
204 } satisfies ProviderInstanceConfig;
205
206 const patch = buildProviderInstanceUpdatePatch({
235 - settings: DEFAULT_SERVER_SETTINGS,
207 + settings: { providerInstances: { [otherId]: other } },
208 instanceId,
209 instance: nextInstance,
238 - driver: ProviderDriverKind.make("codex"),
239 - isDefault: false,
210 });
211
242 - expect(patch.providerInstances?.[instanceId]).toEqual(nextInstance);
243 - expect(patch.providers).toBeUndefined();
212 + expect(patch.providerInstances).toEqual({ [otherId]: other, [instanceId]: nextInstance });
213 + expect(patch).not.toHaveProperty("textGenerationModelSelection");
214 });
215 });
216
apps/web/src/components/settings/SettingsPanels.logic.ts
+1 -18
@@ -1,7 +1,6 @@
1 import type {
2 BackgroundActivityProfile,
3 BackgroundActivitySettings,
4 - ProviderDriverKind,
4 ProviderInstanceConfig,
5 PreviewViewportSetting,
6 ProviderInstanceId,
@@ -255,30 +254,14 @@ export function formatDiagnosticsDescription(input: {
254 }
255
256 export function buildProviderInstanceUpdatePatch(input: {
258 - readonly settings: Pick<ServerSettings, "providers" | "providerInstances">;
257 + readonly settings: Pick<ServerSettings, "providerInstances">;
258 readonly instanceId: ProviderInstanceId;
259 readonly instance: ProviderInstanceConfig;
261 - readonly driver: ProviderDriverKind;
262 - readonly isDefault: boolean;
260 readonly textGenerationModelSelection?:
261 | ServerSettings["textGenerationModelSelection"]
262 | undefined;
263 }): Partial<UnifiedSettings> {
267 - type LegacyProviderSettings = ServerSettings["providers"][keyof ServerSettings["providers"]];
268 - const legacyProviderDefaults = DEFAULT_UNIFIED_SETTINGS.providers as Record<
269 - string,
270 - LegacyProviderSettings | undefined
271 - >;
272 - const legacyProviderDefault = input.isDefault ? legacyProviderDefaults[input.driver] : undefined;
264 return {
274 - ...(legacyProviderDefault !== undefined
275 - ? {
276 - providers: {
277 - ...input.settings.providers,
278 - [input.driver]: legacyProviderDefault,
279 - } as ServerSettings["providers"],
280 - }
281 - : {}),
265 providerInstances: {
266 ...input.settings.providerInstances,
267 [input.instanceId]: input.instance,
apps/web/src/modelSelection.test.ts
+4 -7
@@ -636,14 +636,11 @@ describe("instance-scoped model selection", () => {
636 const nativeModel = "gemini-3.1-pro";
637 const settings: UnifiedSettings = {
638 ...DEFAULT_UNIFIED_SETTINGS,
639 - providers: {
640 - ...DEFAULT_UNIFIED_SETTINGS.providers,
641 - antigravity: {
642 - ...DEFAULT_UNIFIED_SETTINGS.providers.antigravity,
643 - customModels: ["api-only-model"],
644 - },
645 - },
639 providerInstances: {
640 + [ProviderInstanceId.make("antigravity")]: {
641 + driver,
642 + config: { customModels: ["api-only-model"] },
643 + },
644 [customId]: { driver, config: { customModels: ["unknown-model"] } },
645 },
646 };
apps/web/src/modelSelection.ts
+3 -14
@@ -66,15 +66,7 @@ function readInstanceCustomModels(
66 return readCustomModelEntries(value);
67 }
68 }
69 - const defaultInstanceId = defaultInstanceIdForDriver(driverKind);
70 - if (instanceId !== defaultInstanceId) {
71 - return [];
72 - }
73 - const legacyProviders = settings.providers as Record<
74 - string,
75 - { readonly customModels: ReadonlyArray<unknown> } | undefined
76 - >;
77 - return readCustomModelEntries(legacyProviders[driverKind]?.customModels ?? []);
69 + return [];
70 }
71
72 export interface AppModelOption {
@@ -228,11 +220,8 @@ function getAppModelOptions(
220 * come from the instance's own `entry.models` snapshot (rather than the
221 * first-matching-kind fallback in `getProviderModels`), so each custom
222 * instance gets the precise model list its driver reported. Custom model
231 - * slugs come from the instance's own `providerInstances[id].config.customModels`
232 - * when present, falling back to the legacy per-kind
233 - * `settings.providers[driverKind].customModels` bucket for default
234 - * instances only. This keeps two instances of the same kind from leaking
235 - * custom slugs into each other. Custom rows reported by the server are
223 + * slugs come from the instance's own `providerInstances[id].config.customModels`,
224 + * so two instances of the same kind never leak custom slugs into each other. Custom rows reported by the server are
225 * ignored so a slug removed in Settings disappears without waiting for the
226 * next provider probe.
227 */
apps/web/src/onboarding/providerReadiness.logic.test.ts
+36 -30
@@ -196,11 +196,12 @@ describe("resolveOnboardingProviderLoginCommand", () => {
196 readyCodex,
197 {
198 ...DEFAULT_SERVER_SETTINGS,
199 - providers: {
200 - ...DEFAULT_SERVER_SETTINGS.providers,
201 - codex: {
202 - ...DEFAULT_SERVER_SETTINGS.providers.codex,
203 - binaryPath: "C:\\Program Files\\Codex & Tools\\codex.exe",
199 + providerInstances: {
200 + [ProviderInstanceId.make("codex")]: {
201 + driver: ProviderDriverKind.make("codex"),
202 + config: {
203 + binaryPath: "C:\\Program Files\\Codex & Tools\\codex.exe",
204 + },
205 },
206 },
207 },
@@ -221,11 +222,12 @@ describe("resolveOnboardingProviderLoginCommand", () => {
222 provider,
223 {
224 ...DEFAULT_SERVER_SETTINGS,
224 - providers: {
225 - ...DEFAULT_SERVER_SETTINGS.providers,
226 - claudeAgent: {
227 - ...DEFAULT_SERVER_SETTINGS.providers.claudeAgent,
228 - binaryPath: "/opt/Claude Tools/$current/claude",
225 + providerInstances: {
226 + [ProviderInstanceId.make("claude")]: {
227 + driver: ProviderDriverKind.make("claudeAgent"),
228 + config: {
229 + binaryPath: "/opt/Claude Tools/$current/claude",
230 + },
231 },
232 },
233 },
@@ -246,11 +248,12 @@ describe("resolveOnboardingProviderLoginCommand", () => {
248 readyCodex,
249 {
250 ...DEFAULT_SERVER_SETTINGS,
249 - providers: {
250 - ...DEFAULT_SERVER_SETTINGS.providers,
251 - codex: {
252 - ...DEFAULT_SERVER_SETTINGS.providers.codex,
253 - binaryPath,
251 + providerInstances: {
252 + [ProviderInstanceId.make("codex")]: {
253 + driver: ProviderDriverKind.make("codex"),
254 + config: {
255 + binaryPath,
256 + },
257 },
258 },
259 },
@@ -265,11 +268,12 @@ describe("resolveOnboardingProviderLoginCommand", () => {
268 readyCodex,
269 {
270 ...DEFAULT_SERVER_SETTINGS,
268 - providers: {
269 - ...DEFAULT_SERVER_SETTINGS.providers,
270 - codex: {
271 - ...DEFAULT_SERVER_SETTINGS.providers.codex,
272 - binaryPath: "/opt/codex\\work/codex",
271 + providerInstances: {
272 + [ProviderInstanceId.make("codex")]: {
273 + driver: ProviderDriverKind.make("codex"),
274 + config: {
275 + binaryPath: "/opt/codex\\work/codex",
276 + },
277 },
278 },
279 },
@@ -284,11 +288,12 @@ describe("resolveOnboardingProviderLoginCommand", () => {
288 readyCodex,
289 {
290 ...DEFAULT_SERVER_SETTINGS,
287 - providers: {
288 - ...DEFAULT_SERVER_SETTINGS.providers,
289 - codex: {
290 - ...DEFAULT_SERVER_SETTINGS.providers.codex,
291 - binaryPath: "C:\\Tools\\codex.exe",
291 + providerInstances: {
292 + [ProviderInstanceId.make("codex")]: {
293 + driver: ProviderDriverKind.make("codex"),
294 + config: {
295 + binaryPath: "C:\\Tools\\codex.exe",
296 + },
297 },
298 },
299 },
@@ -303,11 +308,12 @@ describe("resolveOnboardingProviderLoginCommand", () => {
308 readyCodex,
309 {
310 ...DEFAULT_SERVER_SETTINGS,
306 - providers: {
307 - ...DEFAULT_SERVER_SETTINGS.providers,
308 - codex: {
309 - ...DEFAULT_SERVER_SETTINGS.providers.codex,
310 - binaryPath: "/opt/Codex Tools/codex",
311 + providerInstances: {
312 + [ProviderInstanceId.make("codex")]: {
313 + driver: ProviderDriverKind.make("codex"),
314 + config: {
315 + binaryPath: "/opt/Codex Tools/codex",
316 + },
317 },
318 },
319 },
apps/web/src/onboarding/providerReadiness.logic.ts
+2 -6
@@ -112,17 +112,13 @@ export function resolveOnboardingProviderLoginCommand(
112 const instance = settings.providerInstances[provider.instanceId];
113
114 if (provider.driver === "claudeAgent") {
115 - const config = decodeClaudeSettings(
116 - instance ? (instance.config ?? {}) : settings.providers.claudeAgent,
117 - );
115 + const config = decodeClaudeSettings(instance?.config ?? {});
116 const binaryPath = Option.isSome(config) ? config.value.binaryPath : "claude";
117 return `${quoteProviderBinary(binaryPath, "claude", platform)} auth login`;
118 }
119
120 if (provider.driver === "codex") {
123 - const config = decodeCodexSettings(
124 - instance ? (instance.config ?? {}) : settings.providers.codex,
125 - );
121 + const config = decodeCodexSettings(instance?.config ?? {});
122 const binaryPath = Option.isSome(config) ? config.value.binaryPath : "codex";
123 return `${quoteProviderBinary(binaryPath, "codex", platform)} login`;
124 }
apps/web/src/providerInstances.test.ts
+7 -19
@@ -143,7 +143,6 @@ describe("applyProviderInstanceSettings", () => {
143 enabled: false,
144 },
145 },
146 - providers: {} as never,
146 });
147
148 expect(entry?.enabled).toBe(false);
@@ -158,7 +157,6 @@ describe("applyProviderInstanceSettings", () => {
157 ]);
158 const [entry] = applyProviderInstanceSettings(entries, {
159 providerInstances: {},
161 - providers: {} as never,
160 });
161
162 expect(entry?.enabled).toBe(false);
@@ -175,7 +173,6 @@ describe("applyProviderInstanceSettings", () => {
173 ]);
174 const [entry] = applyProviderInstanceSettings(entries, {
175 providerInstances: {},
178 - providers: {} as never,
176 });
177
178 expect(entry?.enabled).toBe(false);
@@ -197,7 +194,6 @@ describe("applyProviderInstanceSettings", () => {
194 enabled: false,
195 },
196 },
200 - providers: {} as never,
197 });
198
199 expect(entry?.enabled).toBe(false);
@@ -213,26 +209,22 @@ describe("applyProviderInstanceSettings", () => {
209 ]);
210 const [entry] = applyProviderInstanceSettings(entries, {
211 providerInstances: {},
216 - providers: {} as never,
212 });
213
214 expect(entry?.isDefault).toBe(true);
215 expect(entry?.enabled).toBe(false);
216 });
217
223 - it("uses legacy settings for a built-in default instance", () => {
218 + it("uses the driver default for an unconfigured built-in default instance", () => {
219 const entries = deriveProviderInstanceEntries([
225 - provider({
226 - provider: ProviderDriverKind.make("codex"),
227 - instanceId: "codex",
228 - }),
220 + provider({ provider: ProviderDriverKind.make("codex"), instanceId: "codex", enabled: false }),
221 + provider({ provider: ProviderDriverKind.make("grok"), instanceId: "grok", enabled: true }),
222 ]);
230 - const [entry] = applyProviderInstanceSettings(entries, {
231 - providerInstances: {},
232 - providers: { codex: { enabled: false } } as never,
233 - });
223 + const [codex, grok] = applyProviderInstanceSettings(entries, { providerInstances: {} });
224
235 - expect(entry?.enabled).toBe(false);
225 + // Settings decide over a stale probe: Codex starts on, Grok starts off.
226 + expect(codex?.enabled).toBe(true);
227 + expect(grok?.enabled).toBe(false);
228 });
229 });
230
@@ -261,7 +253,6 @@ describe("deriveProviderEntriesByEnvironment", () => {
253 agentId,
254 [snapshot],
255 {
264 - providers: {} as never,
256 providerInstances: {
257 [instanceId]: {
258 driver: ProviderDriverKind.make("acpRegistry"),
@@ -629,7 +620,6 @@ describe("provider icon metadata", () => {
620 const registryConfig = { agentId: "swe-agent", registryIconUrl: iconUrl };
621 const brandedEntries = applyProviderInstanceSettings(snapshots, {
622 providerInstances: { [instanceId]: { driver, enabled: true, config: registryConfig } },
632 - providers: {} as never,
623 });
624 expect(brandedEntries[0]?.acpRegistryAgentId).toBe("swe-agent");
625 expect(brandedEntries[0]?.acpRegistryIconUrl).toBe(iconUrl);
@@ -642,7 +632,6 @@ describe("provider icon metadata", () => {
632 config: { ...registryConfig, source: "local", commandPath: "dsh" },
633 },
634 },
645 - providers: {} as never,
635 });
636 expect(localEntry?.acpRegistryAgentId).toBeUndefined();
637 expect(localEntry?.acpRegistryIconUrl).toBeUndefined();
@@ -651,7 +640,6 @@ describe("provider icon metadata", () => {
640
641 const [restoredEntry] = applyProviderInstanceSettings(localEntry ? [localEntry] : [], {
642 providerInstances: { [instanceId]: { driver, enabled: true, config: registryConfig } },
654 - providers: {} as never,
643 });
644 expect(restoredEntry?.acpRegistryAgentId).toBe("swe-agent");
645 expect(restoredEntry?.acpRegistryIconUrl).toBe(iconUrl);
apps/web/src/providerInstances.ts
+9 -19
@@ -15,6 +15,7 @@
15 import {
16 DEFAULT_MODEL_BY_PROVIDER,
17 defaultInstanceIdForDriver,
18 + isUnconfiguredDefaultInstanceEnabled,
19 resolveProviderInstanceEnabled,
20 type ModelSelection,
21 type ProviderDriverKind,
@@ -153,11 +154,7 @@ export function deriveProviderInstanceEntries(
154 */
155 export function deriveProviderEntriesByEnvironment(
156 providersByEnvironment: Iterable<
156 - readonly [
157 - string,
158 - ReadonlyArray<ServerProvider>,
159 - Pick<ServerSettings, "providerInstances" | "providers">?,
160 - ]
157 + readonly [string, ReadonlyArray<ServerProvider>, Pick<ServerSettings, "providerInstances">?]
158 >,
159 ): ReadonlyMap<string, ReadonlyMap<string, ProviderInstanceEntry>> {
160 const byEnvironment = new Map<string, ReadonlyMap<string, ProviderInstanceEntry>>();
@@ -178,30 +175,23 @@ export function deriveProviderEntriesByEnvironment(
175 * settings write, so picker visibility must follow settings rather than waiting
176 * for probe reconciliation.
177 *
181 - * Only built-in default instances have a legacy `providers` entry. Every
182 - * other instance exists through `providerInstances`; if it is absent there,
183 - * its streamed snapshot is stale (for example immediately after deletion)
184 - * and is treated as disabled.
178 + * A built-in default instance without a `providerInstances` entry keeps its
179 + * streamed state, since the server runs it with default config. Any other
180 + * instance missing from `providerInstances` is stale (for example
181 + * immediately after deletion) and is treated as disabled.
182 */
183 export function applyProviderInstanceSettings(
184 entries: ReadonlyArray<ProviderInstanceEntry>,
188 - settings: Pick<ServerSettings, "providerInstances" | "providers">,
185 + settings: Pick<ServerSettings, "providerInstances">,
186 ): ReadonlyArray<ProviderInstanceEntry> {
190 - const legacyProviders = settings.providers as Readonly<
191 - Record<string, { readonly enabled?: boolean } | undefined>
192 - >;
193 -
187 return entries.map((entry) => {
188 const explicitInstance = Object.hasOwn(settings.providerInstances, entry.instanceId)
189 ? settings.providerInstances[entry.instanceId]
190 : undefined;
198 - const legacyProvider = Object.hasOwn(legacyProviders, entry.driverKind)
199 - ? legacyProviders[entry.driverKind]
200 - : undefined;
191 const enabled = explicitInstance
192 ? resolveProviderInstanceEnabled(explicitInstance)
203 - : entry.isDefault && legacyProvider
204 - ? (legacyProvider.enabled ?? entry.enabled)
193 + : entry.isDefault
194 + ? isUnconfiguredDefaultInstanceEnabled(entry.instanceId)
195 : false;
196 if (entry.driverKind !== "acpRegistry" || explicitInstance === undefined) {
197 return enabled === entry.enabled ? entry : { ...entry, enabled };
docs/internals/adding-a-provider.md
+3 -2
@@ -103,8 +103,9 @@ produce catches them.
103
104 ## Where a driver plugs in
105
106 -- **Contracts:** settings schema and patch, default model, and display name in
107 - [`packages/contracts`](../../packages/contracts/src). New providers are off by default.
106 +- **Contracts:** settings schema, default model, and display name in
107 + [`packages/contracts`](../../packages/contracts/src). Instances store that config in
108 + `providerInstances`. New providers are off by default.
109 - **Server:** the driver in [`provider/Drivers`](../../apps/server/src/provider/Drivers) and its entry
110 in [`builtInDrivers.ts`](../../apps/server/src/provider/builtInDrivers.ts). Also its position in
111 the [status order](../../apps/server/src/provider/providerStatusCache.ts), a compatibility policy
packages/contracts/src/settings.test.ts
+7 -100
@@ -208,17 +208,6 @@ describe("custom model settings", () => {
208 { slug: "named", name: "Named", capabilities },
209 ]);
210 });
211 -
212 - it("accepts entries at the settings patch boundary", () => {
213 - expect(
214 - decodeServerSettingsPatch({
215 - providers: { codex: { customModels: [{ slug: "x", capabilities }] } },
216 - }).providers?.codex?.customModels,
217 - ).toEqual([{ slug: "x", capabilities }]);
218 - expect(() =>
219 - decodeServerSettingsPatch({ providers: { codex: { customModels: [{ name: "no slug" }] } } }),
220 - ).toThrow();
221 - });
211 });
212
213 describe("ClaudeSettings auto-compaction", () => {
@@ -239,15 +228,6 @@ describe("ClaudeSettings auto-compaction", () => {
228 expect(() => decodeClaudeSettings({ autoCompactWindow: value })).toThrow();
229 },
230 );
242 -
243 - it("rejects an unsupported threshold at the settings patch boundary", () => {
244 - expect(() =>
245 - decodeServerSettingsPatch({ providers: { claudeAgent: { autoCompactWindow: "300k" } } }),
246 - ).toThrow();
247 - expect(
248 - decodeServerSettingsPatch({ providers: { claudeAgent: { autoCompactWindow: "300000" } } }),
249 - ).toBeDefined();
250 - });
231 });
232
233 describe("ClientSettings notifications", () => {
@@ -752,9 +732,6 @@ describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
732 it("decodes a fully empty config (legacy on-disk shape) without complaint", () => {
733 const decoded = decodeServerSettings({});
734 expect(decoded.providerInstances).toEqual({});
755 - // Legacy `providers` struct is still hydrated with its per-driver defaults
756 - // so existing call sites keep working through the migration.
757 - expect(decoded.providers.codex.enabled).toBe(true);
735 });
736
737 it("decodes a multi-instance map mixing first-party and fork drivers", () => {
@@ -803,7 +780,6 @@ describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
780 describe("provider enabled defaults", () => {
781 it("keeps Muse disabled until a configured instance opts in", () => {
782 const muse = ProviderDriverKind.make("muse");
806 - expect(decodeServerSettings({}).providers.muse.enabled).toBe(false);
783 expect(resolveProviderInstanceEnabled({ driver: muse, config: {} })).toBe(false);
784 expect(resolveProviderInstanceEnabled({ driver: muse, enabled: true, config: {} })).toBe(true);
785 expect(
@@ -812,26 +788,13 @@ describe("provider enabled defaults", () => {
788 });
789
790 it("enables only the stable bindings by default", () => {
815 - const decoded = decodeServerSettings({});
816 - expect(decoded.providers.codex.enabled).toBe(true);
817 - expect(decoded.providers.claudeAgent.enabled).toBe(true);
818 - expect(decoded.providers.cursor.enabled).toBe(false);
819 - expect(decoded.providers.grok.enabled).toBe(false);
820 - expect(decoded.providers.opencode.enabled).toBe(false);
821 - });
822 -
823 - it("keeps Cursor enabled when an existing user explicitly opted in", () => {
824 - const cursor = ProviderDriverKind.make("cursor");
825 - const cursorId = ProviderInstanceId.make("cursor");
826 - const decoded = decodeServerSettings({
827 - providers: { cursor: { enabled: true } },
828 - providerInstances: {
829 - [cursorId]: { driver: cursor, enabled: true, config: {} },
830 - },
831 - });
832 -
833 - expect(decoded.providers.cursor.enabled).toBe(true);
834 - expect(resolveProviderInstanceEnabled(decoded.providerInstances[cursorId]!)).toBe(true);
791 + const enabledByDefault = (driver: string) =>
792 + resolveProviderInstanceEnabled({ driver: ProviderDriverKind.make(driver), config: {} });
793 + expect(enabledByDefault("codex")).toBe(true);
794 + expect(enabledByDefault("claudeAgent")).toBe(true);
795 + for (const driver of ["cursor", "grok", "muse", "pi", "opencode", "antigravity"]) {
796 + expect(enabledByDefault(driver)).toBe(false);
797 + }
798 });
799
800 it("resolves instance enabled state with explicit false winning", () => {
@@ -903,42 +866,6 @@ describe("ServerSettings worktree defaults", () => {
866 });
867 });
868
906 -describe("ServerSettings Cursor legacy settings", () => {
907 - it("preserves V1 Cursor CLI settings when reading and writing shared settings", () => {
908 - const decoded = decodeServerSettings({
909 - providers: {
910 - cursor: {
911 - enabled: true,
912 - binaryPath: "cursor-agent",
913 - apiEndpoint: "http://127.0.0.1:3774",
914 - },
915 - },
916 - });
917 -
918 - expect(decoded.providers.cursor.enabled).toBe(true);
919 - expect(encodeServerSettings(decoded).providers?.cursor).toMatchObject({
920 - binaryPath: "cursor-agent",
921 - apiEndpoint: "http://127.0.0.1:3774",
922 - });
923 - });
924 -
925 - it("ignores obsolete Cursor CLI settings in patches", () => {
926 - const patch = decodeServerSettingsPatch({
927 - providers: {
928 - cursor: {
929 - enabled: true,
930 - binaryPath: "cursor-agent",
931 - apiEndpoint: "http://127.0.0.1:3774",
932 - },
933 - },
934 - });
935 -
936 - expect(patch.providers?.cursor?.enabled).toBe(true);
937 - expect(patch.providers?.cursor).not.toHaveProperty("binaryPath");
938 - expect(patch.providers?.cursor).not.toHaveProperty("apiEndpoint");
939 - });
940 -});
941 -
869 describe("ServerSettings.sourceControlWritingStyle", () => {
870 it("defaults all style settings for legacy configs", () => {
871 const settings = decodeServerSettings({});
@@ -1011,13 +938,6 @@ describe("ServerSettingsPatch string normalization", () => {
938 observability: {
939 otlpTracesUrl: " http://localhost:4318/v1/traces ",
940 },
1014 - providers: {
1015 - codex: {
1016 - binaryPath: " /opt/homebrew/bin/codex ",
1017 - homePath: " ~/.codex ",
1018 - launchArgs: " --strict-config --enable foo ",
1019 - },
1020 - },
941 providerInstances: {
942 codex_personal: {
943 driver: " codex ",
@@ -1030,9 +950,6 @@ describe("ServerSettingsPatch string normalization", () => {
950 expect(patch.addProjectBaseDirectory).toBe("~/Development");
951 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
952 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
1033 - expect(patch.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
1034 - expect(patch.providers?.codex?.homePath).toBe("~/.codex");
1035 - expect(patch.providers?.codex?.launchArgs).toBe("--strict-config --enable foo");
953 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
954 "codex",
955 );
@@ -1049,19 +966,9 @@ describe("ServerSettingsPatch string normalization", () => {
966 const encoded = encodeServerSettings({
967 ...defaultSettings,
968 addProjectBaseDirectory: " ~/Development ",
1052 - providers: {
1053 - ...defaultSettings.providers,
1054 - codex: {
1055 - ...defaultSettings.providers.codex,
1056 - binaryPath: " /opt/homebrew/bin/codex ",
1057 - launchArgs: " --strict-config ",
1058 - },
1059 - },
969 });
970
971 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
1063 - expect(encoded.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
1064 - expect(encoded.providers?.codex?.launchArgs).toBe("--strict-config");
972 });
973 });
974
packages/contracts/src/settings.ts
+30 -106
@@ -40,7 +40,7 @@ import {
40 import {
41 ProviderInstanceConfig,
42 ProviderInstanceId,
43 - type ProviderDriverKind,
43 + ProviderDriverKind,
44 } from "./providerInstance.ts";
45 import { PullRequestMergeMethod } from "./pullRequest.ts";
46
@@ -1457,22 +1457,6 @@ export const ServerSettings = Schema.Struct({
1457 Schema.withDecodingDefault(Effect.succeed(null)),
1458 ),
1459
1460 - // Legacy single-instance-per-driver settings. Continues to be the source
1461 - // of truth until `providerInstances` (below) lands per-driver migration
1462 - // shims and the server starts hydrating instances from it. Driver-specific
1463 - // schemas live here for the duration of the migration; once each driver
1464 - // owns its config in its own package, this struct shrinks to nothing and
1465 - // is removed entirely.
1466 - providers: Schema.Struct({
1467 - codex: CodexSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
1468 - claudeAgent: ClaudeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
1469 - cursor: CursorSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
1470 - grok: GrokSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
1471 - muse: MuseSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
1472 - pi: PiSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
1473 - opencode: OpenCodeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
1474 - antigravity: AntigravitySettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
1475 - }).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
1460 // New driver-agnostic instance map. Keyed by `ProviderInstanceId`; values
1461 // are `ProviderInstanceConfig` envelopes. The driver-specific config blob
1462 // is `Schema.Unknown` at this layer so envelopes with unknown drivers
@@ -1512,8 +1496,8 @@ export const DEFAULT_SERVER_SETTINGS: ServerSettings = Schema.decodeSync(ServerS
1496 /**
1497 * Read the legacy `enabled` flag embedded in a provider instance config
1498 * blob. The envelope-level `ProviderInstanceConfig.enabled` is the single
1515 - * flag going forward; this reader exists for legacy `providers.<kind>`
1516 - * blobs and old settings files that still carry the flag in-config.
1499 + * flag going forward; this reader exists for old settings files that still
1500 + * carry the flag in-config.
1501 */
1502 export const providerInstanceConfigEnabledFlag = (config: unknown): boolean | undefined => {
1503 if (config === null || typeof config !== "object" || Array.isArray(config)) {
@@ -1524,18 +1508,34 @@ export const providerInstanceConfigEnabledFlag = (config: unknown): boolean | un
1508 };
1509
1510 /**
1527 - * Default enabled state for a built-in driver when neither the envelope nor
1528 - * the config blob carries a flag. Derived from the driver's settings schema
1529 - * through `DEFAULT_SERVER_SETTINGS`, so the schema's decoding default stays
1530 - * the single source of truth. Unknown (fork) drivers default to enabled.
1511 + * Built-in drivers that stay off until the user turns them on. Matches the
1512 + * `enabled` decoding default of each driver's settings schema.
1513 */
1532 -const defaultEnabledForDriver = (driver: ProviderDriverKind): boolean => {
1533 - const legacyDefaults = DEFAULT_SERVER_SETTINGS.providers as Record<
1534 - string,
1535 - { readonly enabled?: boolean } | undefined
1536 - >;
1537 - return legacyDefaults[driver]?.enabled ?? true;
1538 -};
1514 +const DEFAULT_DISABLED_PROVIDER_DRIVERS: ReadonlySet<ProviderDriverKind> = new Set(
1515 + ["cursor", "grok", "muse", "pi", "opencode", "antigravity"].map((driver) =>
1516 + ProviderDriverKind.make(driver),
1517 + ),
1518 +);
1519 +
1520 +/** Built-in drivers whose default instance runs before the user configures it. */
1521 +const DEFAULT_ENABLED_DEFAULT_INSTANCES: ReadonlySet<ProviderInstanceId> = new Set(
1522 + ["codex", "claudeAgent"].map((instanceId) => ProviderInstanceId.make(instanceId)),
1523 +);
1524 +
1525 +/**
1526 + * Whether the built-in default instance at `instanceId` is enabled while
1527 + * settings have no `providerInstances` entry for it. Only Codex and Claude
1528 + * start on; any other id without an entry has no running instance.
1529 + */
1530 +export const isUnconfiguredDefaultInstanceEnabled = (instanceId: ProviderInstanceId): boolean =>
1531 + DEFAULT_ENABLED_DEFAULT_INSTANCES.has(instanceId);
1532 +
1533 +/**
1534 + * Default enabled state for a driver when neither the envelope nor the config
1535 + * blob carries a flag. Unknown (fork) drivers default to enabled.
1536 + */
1537 +const defaultEnabledForDriver = (driver: ProviderDriverKind): boolean =>
1538 + !DEFAULT_DISABLED_PROVIDER_DRIVERS.has(driver);
1539
1540 /**
1541 * Resolve whether a configured provider instance is enabled. An explicit
@@ -1608,70 +1608,6 @@ const ModelSelectionPatch = Schema.Struct({
1608 options: Schema.optionalKey(ProviderOptionSelections),
1609 });
1610
1611 -const CodexSettingsPatch = Schema.Struct({
1612 - enabled: Schema.optionalKey(Schema.Boolean),
1613 - binaryPath: Schema.optionalKey(TrimmedString),
1614 - homePath: Schema.optionalKey(TrimmedString),
1615 - shadowHomePath: Schema.optionalKey(TrimmedString),
1616 - launchArgs: Schema.optionalKey(TrimmedString),
1617 - customModels: Schema.optionalKey(Schema.Array(CustomModelSetting)),
1618 -});
1619 -
1620 -const ClaudeSettingsPatch = Schema.Struct({
1621 - enabled: Schema.optionalKey(Schema.Boolean),
1622 - binaryPath: Schema.optionalKey(TrimmedString),
1623 - homePath: Schema.optionalKey(TrimmedString),
1624 - customModels: Schema.optionalKey(Schema.Array(CustomModelSetting)),
1625 - launchArgs: Schema.optionalKey(TrimmedString),
1626 - // Validated at the patch boundary so a typo fails the one update with a
1627 - // schema error instead of a generic whole-settings failure.
1628 - autoCompactWindow: Schema.optionalKey(
1629 - TrimmedString.check(Schema.isPattern(CLAUDE_AUTO_COMPACT_WINDOW_PATTERN)),
1630 - ),
1631 -});
1632 -
1633 -const CursorSettingsPatch = Schema.Struct({
1634 - enabled: Schema.optionalKey(Schema.Boolean),
1635 - customModels: Schema.optionalKey(Schema.Array(CustomModelSetting)),
1636 -});
1637 -
1638 -const GrokSettingsPatch = Schema.Struct({
1639 - enabled: Schema.optionalKey(Schema.Boolean),
1640 - binaryPath: Schema.optionalKey(TrimmedString),
1641 - customModels: Schema.optionalKey(Schema.Array(CustomModelSetting)),
1642 -});
1643 -
1644 -const AntigravitySettingsPatch = Schema.Struct({
1645 - enabled: Schema.optionalKey(Schema.Boolean),
1646 - authMethod: Schema.optionalKey(AntigravityAuthMethod),
1647 - apiKey: Schema.optionalKey(TrimmedString),
1648 - gcpProject: Schema.optionalKey(TrimmedString),
1649 - gcpLocation: Schema.optionalKey(TrimmedString),
1650 - binaryPath: Schema.optionalKey(TrimmedString),
1651 - customModels: Schema.optionalKey(Schema.Array(CustomModelSetting)),
1652 -});
1653 -
1654 -const MuseSettingsPatch = Schema.Struct({
1655 - enabled: Schema.optionalKey(Schema.Boolean),
1656 - binaryPath: Schema.optionalKey(TrimmedString),
1657 - customModels: Schema.optionalKey(Schema.Array(CustomModelSetting)),
1658 -});
1659 -
1660 -const PiSettingsPatch = Schema.Struct({
1661 - enabled: Schema.optionalKey(Schema.Boolean),
1662 - binaryPath: Schema.optionalKey(TrimmedString),
1663 - launchArgs: Schema.optionalKey(TrimmedString),
1664 - customModels: Schema.optionalKey(Schema.Array(CustomModelSetting)),
1665 -});
1666 -
1667 -const OpenCodeSettingsPatch = Schema.Struct({
1668 - enabled: Schema.optionalKey(Schema.Boolean),
1669 - binaryPath: Schema.optionalKey(TrimmedString),
1670 - serverUrl: Schema.optionalKey(TrimmedString),
1671 - serverPassword: Schema.optionalKey(TrimmedString),
1672 - customModels: Schema.optionalKey(Schema.Array(CustomModelSetting)),
1673 -});
1674 -
1611 export const ServerSettingsPatch = Schema.Struct({
1612 worktreeCleanup: Schema.optionalKey(
1613 Schema.NullOr(
@@ -1791,18 +1727,6 @@ export const ServerSettingsPatch = Schema.Struct({
1727 tokens: Schema.optionalKey(Schema.Record(GitHubHost, TrimmedString)),
1728 }),
1729 ),
1794 - providers: Schema.optionalKey(
1795 - Schema.Struct({
1796 - codex: Schema.optionalKey(CodexSettingsPatch),
1797 - claudeAgent: Schema.optionalKey(ClaudeSettingsPatch),
1798 - cursor: Schema.optionalKey(CursorSettingsPatch),
1799 - grok: Schema.optionalKey(GrokSettingsPatch),
1800 - muse: Schema.optionalKey(MuseSettingsPatch),
1801 - pi: Schema.optionalKey(PiSettingsPatch),
1802 - opencode: Schema.optionalKey(OpenCodeSettingsPatch),
1803 - antigravity: Schema.optionalKey(AntigravitySettingsPatch),
1804 - }),
1805 - ),
1730 // Whole-map replacement for the new instance config. Patching individual
1731 // entries is intentionally out of scope: the map is small, and partial
1732 // patches risk leaving driver-specific config in a half-merged state.
packages/provider-core/src/server/driver.ts
+8 -5
@@ -58,6 +58,12 @@ export interface ProviderDriverMetadata {
58 * rejects multi-instance configurations with a clear error.
59 */
60 readonly supportsMultipleInstances?: boolean;
61 + /**
62 + * Whether the server runs an instance at `defaultInstanceIdForDriver(kind)`
63 + * even when settings have no entry for it. Defaults to `true`; drivers that
64 + * need user input before they can run (such as the ACP Registry) opt out.
65 + */
66 + readonly hasDefaultInstance?: boolean;
67 }
68
69 export type ProviderWorkspaceSnapshot = ServerProvider &
@@ -188,11 +194,8 @@ export interface ProviderDriver<Config, R = never> {
194 */
195 readonly configSchema: Schema.Codec<Config, unknown>;
196 /**
191 - * Default config payload used when the legacy
192 - * `ServerSettings.providers.<kind>` entry is empty or when the driver
193 - * is auto-bootstrapped without user configuration. Returning a typed
194 - * default keeps the migration path simple — no special-casing needed
195 - * to construct a "blank" instance.
197 + * Config used when an instance has no config blob, such as the default
198 + * instance of a driver the user never configured.
199 */
200 readonly defaultConfig: () => Config;
201 /**
packages/shared/src/projectSettings.test.ts
+13 -2
@@ -2,6 +2,7 @@ import {
2 DEFAULT_SERVER_SETTINGS,
3 PROJECT_SCOPED_SERVER_SETTING_KEYS,
4 ProjectId,
5 + ProviderDriverKind,
6 ProviderInstanceId,
7 } from "@t3tools/contracts";
8 import { describe, expect, it } from "vite-plus/test";
@@ -78,7 +79,12 @@ describe("resolveProjectSettings", () => {
79 it("keeps the environment text generation model when the override's provider is disabled", () => {
80 const disabledSelection = createModelSelection(ProviderInstanceId.make("claudeAgent"), "opus");
81 const settings = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
81 - providers: { claudeAgent: { enabled: false } },
82 + providerInstances: {
83 + [ProviderInstanceId.make("claudeAgent")]: {
84 + driver: ProviderDriverKind.make("claudeAgent"),
85 + enabled: false,
86 + },
87 + },
88 projectSettingsOverrides: {
89 [projectId]: { textGenerationModelSelection: disabledSelection },
90 },
@@ -128,7 +134,12 @@ describe("resolveProjectSettings", () => {
134 it("keeps the environment default model when the override's provider is disabled", () => {
135 const disabledSelection = createModelSelection(ProviderInstanceId.make("claudeAgent"), "opus");
136 const settings = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
131 - providers: { claudeAgent: { enabled: false } },
137 + providerInstances: {
138 + [ProviderInstanceId.make("claudeAgent")]: {
139 + driver: ProviderDriverKind.make("claudeAgent"),
140 + enabled: false,
141 + },
142 + },
143 projectSettingsOverrides: { [projectId]: { defaultModelSelection: disabledSelection } },
144 });
145 const resolved = resolveProjectSettings(settings, projectId);
packages/shared/src/serverSettings.ts
+2 -14
@@ -1,13 +1,12 @@
1 import {
2 - isProviderDriverKind,
2 isProviderAvailable,
3 + isUnconfiguredDefaultInstanceEnabled,
4 resolveProviderInstanceEnabled,
5 isProviderTextGenerationCapable,
6 type ModelSelection,
7 type ProjectId,
8 type ProjectScopedServerSettingKey,
9 type ProjectSettingsOverrides,
10 - type ProviderDriverKind,
10 type ServerProvider,
11 ServerSettings,
12 type ServerSettingsPatch,
@@ -59,14 +58,6 @@ export function resolveProjectAutoPull(
58 );
59 }
60
62 -type LegacyProviderSettings = ServerSettings["providers"][keyof ServerSettings["providers"]];
63 -
64 -const getLegacyProviderSettings = (
65 - settings: ServerSettings,
66 - provider: ProviderDriverKind,
67 -): LegacyProviderSettings | undefined =>
68 - (settings.providers as Record<string, LegacyProviderSettings | undefined>)[provider];
69 -
61 export function isModelSelectionProviderEnabled(
62 settings: ServerSettings,
63 selection: ModelSelection,
@@ -76,10 +67,7 @@ export function isModelSelectionProviderEnabled(
67 return resolveProviderInstanceEnabled(instanceConfig);
68 }
69
79 - return (
80 - isProviderDriverKind(selection.instanceId) &&
81 - getLegacyProviderSettings(settings, selection.instanceId)?.enabled === true
82 - );
70 + return isUnconfiguredDefaultInstanceEnabled(selection.instanceId);
71 }
72
73 export function resolveSourceControlWriterModelSelection(