Skip to content

Commit a3ad38a

Browse files
t3dotggclaude
andcommitted
fix(server): stop probing Grok, Cursor, and OpenCode unless turned on
Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent fe281c5 commit a3ad38a

12 files changed

Lines changed: 269 additions & 23 deletions

File tree

‎apps/server/src/provider/Layers/GrokProvider.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ describe("buildInitialGrokProviderSnapshot", () => {
2323
}),
2424
);
2525

26-
it.effect("returns a pending snapshot by default", () =>
26+
it.effect("returns a disabled snapshot by default — Grok is opt-in", () =>
2727
Effect.gen(function* () {
2828
const snapshot = yield* buildInitialGrokProviderSnapshot(decodeGrokSettings({}));
29+
expect(snapshot.enabled).toBe(false);
30+
expect(snapshot.status).toBe("disabled");
31+
}),
32+
);
33+
34+
it.effect("returns a pending snapshot when enabled", () =>
35+
Effect.gen(function* () {
36+
const snapshot = yield* buildInitialGrokProviderSnapshot(
37+
decodeGrokSettings({ enabled: true }),
38+
);
2939
expect(snapshot.enabled).toBe(true);
3040
expect(snapshot.installed).toBe(true);
3141
expect(snapshot.status).toBe("warning");

‎apps/server/src/provider/Layers/ProviderInstanceRegistryLive.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,32 @@ describe("ProviderInstanceRegistryLive — multi-instance codex slice", () => {
223223
}).pipe(Effect.provide(testLayer)),
224224
);
225225

226+
it.live("treats an explicit in-config enabled:false as disabling despite the envelope", () =>
227+
Effect.gen(function* () {
228+
// Old settings files can carry both flags with conflicting values.
229+
// The explicit false must win so a user's disable is never undone.
230+
const staleId = ProviderInstanceId.make("codex_stale");
231+
const configMap: ProviderInstanceConfigMap = {
232+
[staleId]: {
233+
driver: ProviderDriverKind.make("codex"),
234+
enabled: true,
235+
config: makeCodexConfig({ enabled: false }),
236+
},
237+
};
238+
239+
const { registry } = yield* makeProviderInstanceRegistry({
240+
drivers: [CodexDriver],
241+
configMap,
242+
});
243+
244+
const instance = yield* registry.getInstance(staleId);
245+
expect(instance).toBeDefined();
246+
expect(instance!.enabled).toBe(false);
247+
const snapshot = yield* instance!.snapshot.getSnapshot;
248+
expect(snapshot.enabled).toBe(false);
249+
}).pipe(Effect.provide(testLayer)),
250+
);
251+
226252
it.live(
227253
"shadows instances whose driver is not registered in this build without failing boot",
228254
() =>

‎apps/server/src/provider/Layers/ProviderInstanceRegistryLive.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*/
3535
import {
3636
defaultInstanceIdForDriver,
37+
providerInstanceConfigEnabledFlag,
3738
ProviderInstanceId,
3839
type ProviderInstanceConfig,
3940
type ProviderInstanceConfigMap,
@@ -93,12 +94,20 @@ interface RegistryState {
9394
const entryEqual = (a: ProviderInstanceConfig, b: ProviderInstanceConfig): boolean =>
9495
Equal.equals(a, b);
9596

96-
const decodedConfigEnabled = (config: unknown): boolean | undefined => {
97-
if (!config || typeof config !== "object" || globalThis.Array.isArray(config)) {
98-
return undefined;
97+
/**
98+
* Resolve an entry's enabled state. An explicit false on either the
99+
* envelope or the raw config blob wins (most restrictive) — old settings
100+
* files can carry both flags with conflicting values, and a user's disable
101+
* must never be silently undone. Otherwise the envelope flag wins, then the
102+
* decoded config's flag (which carries the driver schema's default for
103+
* built-ins and forks alike), then enabled by default.
104+
*/
105+
const resolveEntryEnabled = (entry: ProviderInstanceConfig, typedConfig: unknown): boolean => {
106+
const rawConfigEnabled = providerInstanceConfigEnabledFlag(entry.config);
107+
if (entry.enabled === false || rawConfigEnabled === false) {
108+
return false;
99109
}
100-
const enabled = (config as { readonly enabled?: unknown }).enabled;
101-
return typeof enabled === "boolean" ? enabled : undefined;
110+
return entry.enabled ?? providerInstanceConfigEnabledFlag(typedConfig) ?? true;
102111
};
103112

104113
/**
@@ -171,7 +180,7 @@ const buildEntry = <R>(input: {
171180
displayName: entry.displayName,
172181
accentColor: entry.accentColor,
173182
environment: entry.environment ?? [],
174-
enabled: entry.enabled ?? decodedConfigEnabled(typedConfig) ?? true,
183+
enabled: resolveEntryEnabled(entry, typedConfig),
175184
config: typedConfig,
176185
})
177186
.pipe(Effect.provideService(Scope.Scope, childScope), Effect.result);

‎apps/server/src/serverSettings.test.ts‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,59 @@ it.layer(NodeServices.layer)("server settings", (it) => {
487487
}).pipe(Effect.provide(makeServerSettingsLayer())),
488488
);
489489

490+
it.effect("folds a legacy in-config enabled flag into the envelope on load", () =>
491+
Effect.gen(function* () {
492+
const serverConfig = yield* ServerConfig.ServerConfig;
493+
const fileSystem = yield* FileSystem.FileSystem;
494+
const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
495+
// Old settings files can carry both flags with conflicting values.
496+
// The explicit false must win so a user's disable sticks.
497+
yield* fileSystem.writeFileString(
498+
serverConfig.settingsPath,
499+
'{"providerInstances":{"grok":{"driver":"grok","enabled":true,"config":{"enabled":false}},"codex_work":{"driver":"codex","config":{"enabled":true,"homePath":"~/.codex"}}}}',
500+
);
501+
502+
const settings = yield* serverSettings.getSettings;
503+
504+
const grokId = ProviderInstanceId.make("grok");
505+
const codexWorkId = ProviderInstanceId.make("codex_work");
506+
assert.deepEqual(settings.providerInstances[grokId], {
507+
driver: ProviderDriverKind.make("grok"),
508+
enabled: false,
509+
config: {},
510+
});
511+
// A lone in-config flag is lifted to the envelope and stripped.
512+
assert.deepEqual(settings.providerInstances[codexWorkId], {
513+
driver: ProviderDriverKind.make("codex"),
514+
enabled: true,
515+
config: { homePath: "~/.codex" },
516+
});
517+
}).pipe(Effect.provide(makeServerSettingsLayer())),
518+
);
519+
520+
it.effect("folds in-config enabled flags arriving through updates", () =>
521+
Effect.gen(function* () {
522+
const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
523+
const grokId = ProviderInstanceId.make("grok");
524+
525+
const next = yield* serverSettings.updateSettings({
526+
providerInstances: {
527+
[grokId]: {
528+
driver: ProviderDriverKind.make("grok"),
529+
enabled: true,
530+
config: { enabled: false, binaryPath: "/opt/grok" },
531+
},
532+
},
533+
});
534+
535+
assert.deepEqual(next.providerInstances[grokId], {
536+
driver: ProviderDriverKind.make("grok"),
537+
enabled: false,
538+
config: { binaryPath: "/opt/grok" },
539+
});
540+
}).pipe(Effect.provide(makeServerSettingsLayer())),
541+
);
542+
490543
it.effect("trims provider path settings when updates are applied", () =>
491544
Effect.gen(function* () {
492545
const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
@@ -524,7 +577,8 @@ it.layer(NodeServices.layer)("server settings", (it) => {
524577
launchArgs: "",
525578
});
526579
assert.deepEqual(next.providers.opencode, {
527-
enabled: true,
580+
// OpenCode is disabled by default; this update only touches paths.
581+
enabled: false,
528582
binaryPath: "/opt/homebrew/bin/opencode",
529583
serverUrl: "http://127.0.0.1:4096",
530584
serverPassword: "secret-password",

‎apps/server/src/serverSettings.ts‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,57 @@ const decodeServerSettings = Schema.decodeUnknownEffect(ServerSettings);
6161
const textEncoder = new TextEncoder();
6262
const textDecoder = new TextDecoder();
6363

64+
/**
65+
* Fold the legacy in-config `enabled` flag into the envelope-level
66+
* `ProviderInstanceConfig.enabled` and strip it from the config blob, so
67+
* explicit provider instances carry exactly one enabled flag. Old settings
68+
* files can hold both flags with conflicting values; an explicit false on
69+
* either side wins so a user's disable is never silently undone. Runs on
70+
* every load and update — the file converges on the next write.
71+
*/
72+
const foldProviderInstanceEnabledFlags = (settings: ServerSettings): ServerSettings => {
73+
let changed = false;
74+
const providerInstances: Record<string, ProviderInstanceConfig> = {};
75+
for (const [instanceId, instance] of Object.entries(settings.providerInstances)) {
76+
const config = instance.config;
77+
if (
78+
config === null ||
79+
typeof config !== "object" ||
80+
Array.isArray(config) ||
81+
!("enabled" in config)
82+
) {
83+
providerInstances[instanceId] = instance;
84+
continue;
85+
}
86+
const { enabled: configEnabled, ...restConfig } = config as Record<string, unknown>;
87+
const resolved =
88+
typeof configEnabled === "boolean"
89+
? instance.enabled === false || configEnabled === false
90+
? false
91+
: (instance.enabled ?? configEnabled)
92+
: instance.enabled;
93+
changed = true;
94+
providerInstances[instanceId] = {
95+
...instance,
96+
...(resolved === undefined ? {} : { enabled: resolved }),
97+
config: restConfig,
98+
} satisfies ProviderInstanceConfig;
99+
}
100+
if (!changed) {
101+
return settings;
102+
}
103+
return {
104+
...settings,
105+
providerInstances: providerInstances as ServerSettings["providerInstances"],
106+
};
107+
};
108+
64109
const normalizeServerSettings = (
65110
settings: ServerSettings,
66111
): Effect.Effect<ServerSettings, ServerSettingsError> =>
67112
encodeServerSettings(settings).pipe(
68113
Effect.flatMap(decodeServerSettings),
114+
Effect.map(foldProviderInstanceEnabledFlags),
69115
Effect.mapError(
70116
(cause) =>
71117
new ServerSettingsError({
@@ -303,7 +349,7 @@ const make = Effect.gen(function* () {
303349
});
304350
return DEFAULT_SERVER_SETTINGS;
305351
}
306-
return decoded.value;
352+
return foldProviderInstanceEnabledFlags(decoded.value);
307353
});
308354

309355
const settingsCache = yield* Cache.make<typeof cacheKey, ServerSettings, ServerSettingsError>({

‎apps/web/src/components/settings/ProviderInstanceCard.tsx‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as Result from "effect/Result";
1515
import { useState, type ReactNode } from "react";
1616
import {
1717
isProviderDriverKind,
18+
resolveProviderInstanceEnabled,
1819
type ProviderInstanceConfig,
1920
type ProviderInstanceEnvironmentVariable,
2021
type ProviderInstanceId,
@@ -368,12 +369,10 @@ interface ProviderInstanceCardProps {
368369
* notice instead of editable fields, so fork instances round-trip
369370
* without accidentally destroying their config.
370371
* - The enabled Switch writes to the envelope's `instance.enabled`
371-
* field; the server's registry consults this at `entry.enabled ?? true`
372-
* before materializing the instance, and the probe also checks its
373-
* driver-specific `config.enabled`. We treat the envelope flag as the
374-
* single source of truth from the UI — built-in cards used to write
375-
* the inner flag, but on the promotion-to-instance path every edit
376-
* flows through the envelope.
372+
* field, which is the single enabled flag: the server folds any legacy
373+
* driver-specific `config.enabled` into the envelope on load and both
374+
* sides resolve through `resolveProviderInstanceEnabled` (an explicit
375+
* false wins, then envelope, then config, then the driver default).
377376
*/
378377
export function ProviderInstanceCard({
379378
instanceId,
@@ -394,7 +393,7 @@ export function ProviderInstanceCard({
394393
onRunUpdate,
395394
isUpdating = false,
396395
}: ProviderInstanceCardProps) {
397-
const enabled = instance.enabled ?? true;
396+
const enabled = resolveProviderInstanceEnabled(instance);
398397
// The server-reported status wins when present; otherwise fall back to
399398
// "disabled"/"warning" based on the local `enabled` flag so the dot
400399
// reflects the persisted intent even before the first probe completes.

‎apps/web/src/components/settings/ProviderSettingsPanel.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ProviderDriverKind,
1313
type ProviderInstanceConfig,
1414
type ProviderInstanceId,
15+
resolveProviderInstanceEnabled,
1516
} from "@t3tools/contracts";
1617
import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
1718
import {
@@ -838,7 +839,7 @@ export function EnvironmentProviderSettings({
838839
}))
839840
}
840841
onUpdate={(next) => {
841-
const wasEnabled = row.instance.enabled ?? true;
842+
const wasEnabled = resolveProviderInstanceEnabled(row.instance);
842843
const isDisabling = next.enabled === false && wasEnabled;
843844
const shouldClearTextGen = isDisabling && textGenInstanceId === row.instanceId;
844845
if (shouldClearTextGen) {

‎apps/web/src/providerInstances.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
DEFAULT_MODEL_BY_PROVIDER,
1717
defaultInstanceIdForDriver,
1818
PROVIDER_DISPLAY_NAMES,
19+
resolveProviderInstanceEnabled,
1920
type ModelSelection,
2021
type ProviderDriverKind,
2122
ProviderInstanceId,
@@ -220,7 +221,7 @@ export function applyProviderInstanceSettings(
220221
return entries.map((entry) => {
221222
const explicitInstance = settings.providerInstances?.[entry.instanceId];
222223
const enabled = explicitInstance
223-
? (explicitInstance.enabled ?? true)
224+
? resolveProviderInstanceEnabled(explicitInstance)
224225
: entry.isDefault
225226
? (legacyProviders[entry.driverKind]?.enabled ?? entry.enabled)
226227
: false;

‎docs/user/install.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ to use, then authenticate it.
6262
| Grok Build | [Grok Build CLI](https://x.ai/cli) | `grok` | `grok login` |
6363
| OpenCode | [OpenCode](https://opencode.ai) | `opencode` | `opencode auth login` |
6464

65+
Codex and Claude are on by default. Cursor, Grok Build, and OpenCode are off by default; turn
66+
them on in **Settings** → the provider's card when you want to use them.
67+
6568
Cursor is the one to watch: install Cursor CLI, which provides the `cursor-agent` binary that
6669
T3 Code looks for, but authenticate with `agent login`, not `cursor-agent login`.
6770

‎packages/contracts/src/settings.test.ts‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { describe, expect, it } from "vite-plus/test";
22
import * as Schema from "effect/Schema";
33

4-
import { ProviderInstanceId } from "./providerInstance.ts";
4+
import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
55
import {
66
ClientSettingsSchema,
77
ClientSettingsPatch,
88
DEFAULT_SERVER_SETTINGS,
9+
defaultEnabledForDriver,
10+
resolveProviderInstanceEnabled,
911
ServerSettings,
1012
ServerSettingsPatch,
1113
} from "./settings.ts";
@@ -177,6 +179,46 @@ describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
177179
});
178180
});
179181

182+
describe("provider enabled defaults", () => {
183+
it("enables only the stable bindings by default", () => {
184+
const decoded = decodeServerSettings({});
185+
expect(decoded.providers.codex.enabled).toBe(true);
186+
expect(decoded.providers.claudeAgent.enabled).toBe(true);
187+
expect(decoded.providers.cursor.enabled).toBe(false);
188+
expect(decoded.providers.grok.enabled).toBe(false);
189+
expect(decoded.providers.opencode.enabled).toBe(false);
190+
});
191+
192+
it("derives per-driver defaults from the settings schemas", () => {
193+
expect(defaultEnabledForDriver(ProviderDriverKind.make("codex"))).toBe(true);
194+
expect(defaultEnabledForDriver(ProviderDriverKind.make("grok"))).toBe(false);
195+
// Unknown fork drivers stay enabled; their own build decides otherwise.
196+
expect(defaultEnabledForDriver(ProviderDriverKind.make("ollama"))).toBe(true);
197+
});
198+
199+
it("resolves instance enabled state with explicit false winning", () => {
200+
const grok = ProviderDriverKind.make("grok");
201+
const codex = ProviderDriverKind.make("codex");
202+
// No flags anywhere: driver default applies.
203+
expect(resolveProviderInstanceEnabled({ driver: grok, config: {} })).toBe(false);
204+
expect(resolveProviderInstanceEnabled({ driver: codex, config: {} })).toBe(true);
205+
// Envelope flag wins over the driver default.
206+
expect(resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: {} })).toBe(true);
207+
expect(resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: {} })).toBe(
208+
false,
209+
);
210+
// Legacy in-config flag fills in when the envelope is silent.
211+
expect(resolveProviderInstanceEnabled({ driver: grok, config: { enabled: true } })).toBe(true);
212+
// Conflicting flags: the explicit false wins, whichever side it is on.
213+
expect(
214+
resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: { enabled: false } }),
215+
).toBe(false);
216+
expect(
217+
resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: { enabled: true } }),
218+
).toBe(false);
219+
});
220+
});
221+
180222
describe("ServerSettings worktree defaults", () => {
181223
it("defaults start-from-origin on for legacy configs", () => {
182224
expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);

0 commit comments

Comments
 (0)