Skip to content

Commit cf03583

Browse files
fix(settings): use branded driver kinds and instance ids in default resolution
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f693770 commit cf03583

2 files changed

Lines changed: 27 additions & 26 deletions

File tree

‎apps/server/src/serverSettings.ts‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ const decodeLegacyProviderSettingsJsonExit = Schema.decodeUnknownExit(LegacyProv
400400

401401
// Drivers that start disabled, so a session in the history means the user
402402
// turned them on before the instance kept an explicit flag.
403-
const HISTORY_RESTORED_DRIVERS = ["cursor", "grok", "opencode"] as const;
403+
const HISTORY_RESTORED_DRIVERS: ReadonlySet<ProviderDriverKind> = new Set(
404+
["cursor", "grok", "opencode"].map((driver) => ProviderDriverKind.make(driver)),
405+
);
404406

405407
/**
406408
* Move each customized legacy `providers.<kind>` blob into the driver's
@@ -421,25 +423,25 @@ function migrateLegacyProviderSettings(
421423
readonly providerInstanceId: string | null;
422424
}>,
423425
): ServerSettings {
424-
const usedProviders = new Set(providerHistory.map(({ providerName }) => providerName));
425-
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>(
426429
providerHistory.map(
427430
({ providerName, providerInstanceId }) => providerInstanceId ?? providerName,
428431
),
429432
);
430-
const isHistoryRestored = (driver: string) =>
431-
(HISTORY_RESTORED_DRIVERS as ReadonlyArray<string>).includes(driver);
432433

433-
const providerInstances: Record<string, ProviderInstanceConfig> = Object.fromEntries(
434-
Object.entries(settings.providerInstances).map(([instanceId, instance]) => [
435-
instanceId,
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] =
436439
instance.enabled === undefined &&
437-
isHistoryRestored(instance.driver) &&
440+
HISTORY_RESTORED_DRIVERS.has(instance.driver) &&
438441
usedProviderInstances.has(instanceId)
439442
? { ...instance, enabled: true }
440-
: instance,
441-
]),
442-
);
443+
: instance;
444+
}
443445

444446
// History restores a never-configured cursor/grok/opencode slot too.
445447
const legacyEntries = new Map(Object.entries(legacyProviders));
@@ -457,7 +459,7 @@ function migrateLegacyProviderSettings(
457459
const explicitEnabled = typeof rawEnabled === "boolean" ? rawEnabled : undefined;
458460
const enabled =
459461
explicitEnabled ??
460-
(isHistoryRestored(driver) && usedProviders.has(driver) ? true : undefined);
462+
(HISTORY_RESTORED_DRIVERS.has(driver) && usedProviders.has(driver) ? true : undefined);
461463
const driverDefault = resolveProviderInstanceEnabled({ driver, config: {} });
462464
if (Object.keys(config).length === 0 && (enabled === undefined || enabled === driverDefault)) {
463465
continue;
@@ -471,7 +473,7 @@ function migrateLegacyProviderSettings(
471473

472474
return {
473475
...settings,
474-
providerInstances: providerInstances as ServerSettings["providerInstances"],
476+
providerInstances,
475477
};
476478
}
477479

‎packages/contracts/src/settings.ts‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
import {
4141
ProviderInstanceConfig,
4242
ProviderInstanceId,
43-
type ProviderDriverKind,
43+
ProviderDriverKind,
4444
} from "./providerInstance.ts";
4545
import { PullRequestMergeMethod } from "./pullRequest.ts";
4646

@@ -1511,25 +1511,24 @@ export const providerInstanceConfigEnabledFlag = (config: unknown): boolean | un
15111511
* Built-in drivers that stay off until the user turns them on. Matches the
15121512
* `enabled` decoding default of each driver's settings schema.
15131513
*/
1514-
const DEFAULT_DISABLED_PROVIDER_DRIVERS: ReadonlySet<string> = new Set([
1515-
"cursor",
1516-
"grok",
1517-
"muse",
1518-
"pi",
1519-
"opencode",
1520-
"antigravity",
1521-
]);
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+
);
15221519

15231520
/** Built-in drivers whose default instance runs before the user configures it. */
1524-
const DEFAULT_ENABLED_PROVIDER_DRIVERS: ReadonlySet<string> = new Set(["codex", "claudeAgent"]);
1521+
const DEFAULT_ENABLED_DEFAULT_INSTANCES: ReadonlySet<ProviderInstanceId> = new Set(
1522+
["codex", "claudeAgent"].map((instanceId) => ProviderInstanceId.make(instanceId)),
1523+
);
15251524

15261525
/**
15271526
* Whether the built-in default instance at `instanceId` is enabled while
15281527
* settings have no `providerInstances` entry for it. Only Codex and Claude
15291528
* start on; any other id without an entry has no running instance.
15301529
*/
1531-
export const isUnconfiguredDefaultInstanceEnabled = (instanceId: string): boolean =>
1532-
DEFAULT_ENABLED_PROVIDER_DRIVERS.has(instanceId);
1530+
export const isUnconfiguredDefaultInstanceEnabled = (instanceId: ProviderInstanceId): boolean =>
1531+
DEFAULT_ENABLED_DEFAULT_INSTANCES.has(instanceId);
15331532

15341533
/**
15351534
* Default enabled state for a driver when neither the envelope nor the config

0 commit comments

Comments
 (0)