Compare commits

..
Author SHA1 Message Date
Cursor Agent e35da91f49 Fix stale assistantDeliveryMode references after delivery mode refactor
- Remove assertion for assistantDeliveryMode in decider test (field no longer emitted)
- Remove stale settings.enableAssistantStreaming from onSendOrRetry dependency array
2026-03-25 20:37:13 +00:00
35 changed files with 516 additions and 344 deletions

No files matched your search

@@ -67,7 +67,7 @@ import {
type TestProviderAdapterHarness,
} from "./TestProviderAdapter.integration.ts";
import { deriveServerPaths, ServerConfig } from "../src/config.ts";
import { ServerSettingsService } from "../src/serverSettings.ts";
import { ServerSettingsLive } from "../src/serverSettings.ts";
function runGit(cwd: string, args: ReadonlyArray<string>) {
return execFileSync("git", args, {
@@ -296,7 +296,10 @@ export const makeOrchestrationIntegrationHarness = (
providerLayer,
RuntimeReceiptBusLive,
);
const serverSettingsLayer = ServerSettingsService.layerTest();
const serverSettingsLayer = ServerSettingsLive.pipe(
Layer.provide(ServerConfig.layerTest(workspaceDir, rootDir)),
Layer.provide(NodeServices.layer),
);
const runtimeIngestionLayer = ProviderRuntimeIngestionLive.pipe(
Layer.provideMerge(runtimeServicesLayer),
Layer.provideMerge(serverSettingsLayer),
@@ -6,10 +6,8 @@ import { expect } from "vitest";
import { ServerConfig } from "../../config.ts";
import { TextGeneration } from "../Services/TextGeneration.ts";
import { ClaudeTextGenerationLive } from "./ClaudeTextGeneration.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
const ClaudeTextGenerationTestLayer = ClaudeTextGenerationLive.pipe(
Layer.provideMerge(ServerSettingsService.layerTest()),
Layer.provideMerge(
ServerConfig.layerTest(process.cwd(), {
prefix: "t3code-claude-text-generation-test-",
@@ -27,7 +27,6 @@ import {
sanitizePrTitle,
toJsonSchemaObject,
} from "../Utils.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
const CLAUDE_TIMEOUT_MS = 180_000;
@@ -41,7 +40,6 @@ const ClaudeOutputEnvelope = Schema.Struct({
const makeClaudeTextGeneration = Effect.gen(function* () {
const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const serverSettingsService = yield* Effect.service(ServerSettingsService);
const readStreamAsString = <E>(
operation: string,
@@ -88,14 +86,9 @@ const makeClaudeTextGeneration = Effect.gen(function* () {
...(normalizedOptions?.fastMode ? { fastMode: true } : {}),
};
const claudeSettings = yield* Effect.map(
serverSettingsService.getSettings,
(settings) => settings.providers.claudeAgent,
).pipe(Effect.catch(() => Effect.undefined));
const runClaudeCommand = Effect.gen(function* () {
const command = ChildProcess.make(
claudeSettings?.binaryPath || "claude",
"claude",
[
"-p",
"--output-format",
@@ -7,7 +7,6 @@ import { ServerConfig } from "../../config.ts";
import { CodexTextGenerationLive } from "./CodexTextGeneration.ts";
import { TextGenerationError } from "../Errors.ts";
import { TextGeneration } from "../Services/TextGeneration.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
const DEFAULT_TEST_MODEL_SELECTION = {
provider: "codex" as const,
@@ -15,7 +14,6 @@ const DEFAULT_TEST_MODEL_SELECTION = {
};
const CodexTextGenerationTestLayer = CodexTextGenerationLive.pipe(
Layer.provideMerge(ServerSettingsService.layerTest()),
Layer.provideMerge(
ServerConfig.layerTest(process.cwd(), {
prefix: "t3code-codex-text-generation-test-",
@@ -26,7 +26,6 @@ import {
sanitizePrTitle,
toJsonSchemaObject,
} from "../Utils.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
const CODEX_GIT_TEXT_GENERATION_REASONING_EFFORT = "low";
const CODEX_TIMEOUT_MS = 180_000;
@@ -36,7 +35,6 @@ const makeCodexTextGeneration = Effect.gen(function* () {
const path = yield* Path.Path;
const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const serverConfig = yield* Effect.service(ServerConfig);
const serverSettingsService = yield* Effect.service(ServerSettingsService);
type MaterializedImageAttachments = {
readonly imagePaths: ReadonlyArray<string>;
@@ -140,11 +138,6 @@ const makeCodexTextGeneration = Effect.gen(function* () {
);
const outputPath = yield* writeTempFile(operation, "codex-output", "");
const codexSettings = yield* Effect.map(
serverSettingsService.getSettings,
(settings) => settings.providers.codex,
).pipe(Effect.catch(() => Effect.undefined));
const runCodexCommand = Effect.gen(function* () {
const normalizedOptions = normalizeCodexModelOptions(
modelSelection.model,
@@ -153,7 +146,7 @@ const makeCodexTextGeneration = Effect.gen(function* () {
const reasoningEffort =
modelSelection.options?.reasoningEffort ?? CODEX_GIT_TEXT_GENERATION_REASONING_EFFORT;
const command = ChildProcess.make(
codexSettings?.binaryPath || "codex",
"codex",
[
"exec",
"--ephemeral",
@@ -172,7 +165,6 @@ const makeCodexTextGeneration = Effect.gen(function* () {
"-",
],
{
env: codexSettings?.homePath ? { CODEX_HOME: codexSettings.homePath } : {},
cwd,
shell: process.platform === "win32",
stdin: {
@@ -20,7 +20,11 @@ import { GitCoreLive } from "./GitCore.ts";
import { GitCore } from "../Services/GitCore.ts";
import { makeGitManager } from "./GitManager.ts";
import { ServerConfig } from "../../config.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
const DEFAULT_TEST_MODEL_SELECTION = {
provider: "codex",
model: "gpt-5.4-mini",
} as const;
interface FakeGhScenario {
prListSequence?: string[];
@@ -462,6 +466,7 @@ function runStackedAction(
{
...input,
actionId: input.actionId ?? "test-action-id",
modelSelection: DEFAULT_TEST_MODEL_SELECTION,
},
options,
);
@@ -488,8 +493,6 @@ function makeManager(input?: {
prefix: "t3-git-manager-test-",
});
const serverSettingsLayer = ServerSettingsService.layerTest();
const gitCoreLayer = GitCoreLive.pipe(
Layer.provideMerge(NodeServices.layer),
Layer.provideMerge(ServerConfigLayer),
@@ -499,7 +502,6 @@ function makeManager(input?: {
Layer.succeed(GitHubCli, gitHubCli),
Layer.succeed(TextGeneration, textGeneration),
gitCoreLayer,
serverSettingsLayer,
).pipe(Layer.provideMerge(NodeServices.layer));
return makeGitManager.pipe(
+3 -12
View File
@@ -19,7 +19,6 @@ import {
import { GitCore } from "../Services/GitCore.ts";
import { GitHubCli } from "../Services/GitHubCli.ts";
import { TextGeneration } from "../Services/TextGeneration.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
const COMMIT_TIMEOUT_MS = 10 * 60_000;
const MAX_PROGRESS_TEXT_LENGTH = 500;
@@ -359,7 +358,6 @@ export const makeGitManager = Effect.gen(function* () {
const gitCore = yield* GitCore;
const gitHubCli = yield* GitHubCli;
const textGeneration = yield* TextGeneration;
const serverSettingsService = yield* ServerSettingsService;
const createProgressEmitter = (
input: { cwd: string; action: "commit" | "commit_push" | "commit_push_pr" },
@@ -1175,13 +1173,6 @@ export const makeGitManager = Effect.gen(function* () {
let commitMessageForStep = input.commitMessage;
let preResolvedCommitSuggestion: CommitAndBranchSuggestion | undefined = undefined;
const modelSelection = yield* serverSettingsService.getSettings.pipe(
Effect.map((settings) => settings.textGenerationModelSelection),
Effect.mapError((cause) =>
gitManagerError("runStackedAction", "Failed to get server settings.", cause),
),
);
if (input.featureBranch) {
currentPhase = "branch";
yield* progress.emit({
@@ -1190,7 +1181,7 @@ export const makeGitManager = Effect.gen(function* () {
label: "Preparing feature branch...",
});
const result = yield* runFeatureBranchStep(
modelSelection,
input.modelSelection,
input.cwd,
initialStatus.branch,
input.commitMessage,
@@ -1207,7 +1198,7 @@ export const makeGitManager = Effect.gen(function* () {
currentPhase = "commit";
const commit = yield* runCommitStep(
modelSelection,
input.modelSelection,
input.cwd,
input.action,
currentBranch,
@@ -1246,7 +1237,7 @@ export const makeGitManager = Effect.gen(function* () {
Effect.flatMap(() =>
Effect.gen(function* () {
currentPhase = "pr";
return yield* runPrStep(modelSelection, input.cwd, currentBranch);
return yield* runPrStep(input.modelSelection, input.cwd, currentBranch);
}),
),
)
+11 -22
View File
@@ -23,7 +23,6 @@ import {
Cache,
Cause,
Deferred,
Duration,
Effect,
Exit,
FileSystem,
@@ -43,7 +42,6 @@ import {
} from "effect";
import * as Semaphore from "effect/Semaphore";
import { ServerConfig } from "./config";
import { fromLenientJson } from "@t3tools/shared/schemaJson";
export class KeybindingsConfigError extends Schema.TaggedErrorClass<KeybindingsConfigError>()(
"KeybindingsConfigParseError",
@@ -410,7 +408,7 @@ function encodeWhenAst(node: KeybindingWhenNode): string {
const DEFAULT_RESOLVED_KEYBINDINGS = compileResolvedKeybindingsConfig(DEFAULT_KEYBINDINGS);
const RawKeybindingsEntries = fromLenientJson(Schema.Array(Schema.Unknown));
const RawKeybindingsEntries = Schema.fromJsonString(Schema.Array(Schema.Unknown));
const KeybindingsConfigJson = Schema.fromJsonString(KeybindingsConfig);
const PrettyJsonString = SchemaGetter.parseJson<string>().compose(
SchemaGetter.stringifyJson({ space: 2 }),
@@ -819,25 +817,16 @@ const makeKeybindings = Effect.gen(function* () {
const revalidateAndEmitSafely = revalidateAndEmit.pipe(Effect.ignoreCause({ log: true }));
// Debounce watch events so the file is fully written before we read it.
// Editors emit multiple events per save (truncate, write, rename) and
// `fs.watch` can fire before the content has been flushed to disk.
const debouncedKeybindingsEvents = fs.watch(keybindingsConfigDir).pipe(
Stream.filter((event) => {
return (
event.path === keybindingsConfigFile ||
event.path === keybindingsConfigPath ||
path.resolve(keybindingsConfigDir, event.path) === keybindingsConfigPathResolved
);
}),
Stream.debounce(Duration.millis(100)),
);
yield* Stream.runForEach(debouncedKeybindingsEvents, () => revalidateAndEmitSafely).pipe(
Effect.ignoreCause({ log: true }),
Effect.forkIn(watcherScope),
Effect.asVoid,
);
yield* Stream.runForEach(fs.watch(keybindingsConfigDir), (event) => {
const isTargetConfigEvent =
event.path === keybindingsConfigFile ||
event.path === keybindingsConfigPath ||
path.resolve(keybindingsConfigDir, event.path) === keybindingsConfigPathResolved;
if (!isTargetConfigEvent) {
return Effect.void;
}
return revalidateAndEmitSafely;
}).pipe(Effect.ignoreCause({ log: true }), Effect.forkIn(watcherScope), Effect.asVoid);
});
const start = Effect.gen(function* () {
-2
View File
@@ -28,7 +28,6 @@ import { ServerLoggerLive } from "./serverLogger";
import { AnalyticsServiceLayerLive } from "./telemetry/Layers/AnalyticsService";
import { AnalyticsService } from "./telemetry/Services/AnalyticsService";
import { readBootstrapEnvelope } from "./bootstrap";
import { ServerSettingsLive } from "./serverSettings";
export class StartupError extends Data.TaggedError("StartupError")<{
readonly message: string;
@@ -298,7 +297,6 @@ const LayerLive = (input: CliInput) =>
Layer.provideMerge(SqlitePersistence.layerConfig),
Layer.provideMerge(ServerLoggerLive),
Layer.provideMerge(AnalyticsServiceLayerLive),
Layer.provideMerge(ServerSettingsLive),
Layer.provideMerge(ServerConfigLive(input)),
);
@@ -17,6 +17,7 @@ import { Effect, Exit, Layer, ManagedRuntime, PubSub, Scope, Stream } from "effe
import { afterEach, describe, expect, it, vi } from "vitest";
import { deriveServerPaths, ServerConfig } from "../../config.ts";
import { ServerSettingsLive } from "../../serverSettings.ts";
import { TextGenerationError } from "../../git/Errors.ts";
import { ProviderAdapterRequestError } from "../../provider/Errors.ts";
import { OrchestrationEventStoreLive } from "../../persistence/Layers/OrchestrationEventStore.ts";
@@ -34,7 +35,6 @@ import { ProviderCommandReactorLive } from "./ProviderCommandReactor.ts";
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
import { ProviderCommandReactor } from "../Services/ProviderCommandReactor.ts";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { ServerSettingsService } from "../../serverSettings.ts";
const asProjectId = (value: string): ProjectId => ProjectId.makeUnsafe(value);
const asApprovalRequestId = (value: string): ApprovalRequestId =>
@@ -215,7 +215,7 @@ describe("ProviderCommandReactor", () => {
Layer.provideMerge(
Layer.succeed(TextGeneration, { generateBranchName } as unknown as TextGenerationShape),
),
Layer.provideMerge(ServerSettingsService.layerTest()),
Layer.provideMerge(ServerSettingsLive),
Layer.provideMerge(ServerConfig.layerTest(process.cwd(), baseDir)),
Layer.provideMerge(NodeServices.layer),
);
@@ -1,6 +1,7 @@
import {
type ChatAttachment,
CommandId,
DEFAULT_GIT_TEXT_GENERATION_MODEL_BY_PROVIDER,
EventId,
type ModelSelection,
type OrchestrationEvent,
@@ -361,11 +362,9 @@ const make = Effect.gen(function* () {
if (!thread) {
return;
}
yield* ensureSessionForThread(
input.threadId,
input.createdAt,
input.modelSelection !== undefined ? { modelSelection: input.modelSelection } : {},
);
yield* ensureSessionForThread(input.threadId, input.createdAt, {
...(input.modelSelection !== undefined ? { modelSelection: input.modelSelection } : {}),
});
if (input.modelSelection !== undefined) {
threadModelSelections.set(input.threadId, input.modelSelection);
}
@@ -434,10 +433,10 @@ const make = Effect.gen(function* () {
cwd,
message: input.messageText,
...(attachments.length > 0 ? { attachments } : {}),
modelSelection: yield* Effect.map(
serverSettingsService.getSettings,
(settings) => settings.textGenerationModelSelection,
),
modelSelection: {
provider: "codex",
model: DEFAULT_GIT_TEXT_GENERATION_MODEL_BY_PROVIDER.codex,
},
})
.pipe(
Effect.catch((error) =>
@@ -681,11 +680,9 @@ const make = Effect.gen(function* () {
return;
}
const cachedModelSelection = threadModelSelections.get(event.payload.threadId);
yield* ensureSessionForThread(
event.payload.threadId,
event.occurredAt,
cachedModelSelection !== undefined ? { modelSelection: cachedModelSelection } : {},
);
yield* ensureSessionForThread(event.payload.threadId, event.occurredAt, {
...(cachedModelSelection !== undefined ? { modelSelection: cachedModelSelection } : {}),
});
return;
}
case "thread.turn-start-requested":
@@ -1045,10 +1045,10 @@ const make = Effect.gen(function* () {
yield* rememberAssistantMessageId(thread.id, turnId, assistantMessageId);
}
const assistantDeliveryMode: AssistantDeliveryMode = yield* Effect.map(
serverSettingsService.getSettings,
(settings) => (settings.enableAssistantStreaming ? "streaming" : "buffered"),
);
const serverSettings = yield* serverSettingsService.getSettings;
const assistantDeliveryMode: AssistantDeliveryMode = serverSettings.enableAssistantStreaming
? "streaming"
: "buffered";
if (assistantDeliveryMode === "buffered") {
const spillChunk = yield* appendBufferedAssistantText(assistantMessageId, assistantDelta);
if (spillChunk.length > 0) {
@@ -188,7 +188,6 @@ describe("decider project scripts", () => {
if (turnStartEvent?.type !== "thread.turn-start-requested") {
return;
}
expect(turnStartEvent.payload.assistantDeliveryMode).toBe("buffered");
expect(turnStartEvent.payload).toMatchObject({
threadId: ThreadId.makeUnsafe("thread-1"),
messageId: asMessageId("message-user-1"),
+4
View File
@@ -27,6 +27,7 @@ import { makeEventNdjsonLogger } from "./provider/Layers/EventNdjsonLogger";
import { TerminalManagerLive } from "./terminal/Layers/Manager";
import { KeybindingsLive } from "./keybindings";
import { ServerSettingsLive } from "./serverSettings";
import { GitManagerLive } from "./git/Layers/GitManager";
import { GitCoreLive } from "./git/Layers/GitCore";
import { GitHubCliLive } from "./git/Layers/GitHubCli";
@@ -108,11 +109,13 @@ export function makeServerRuntimeServicesLayer() {
);
const runtimeIngestionLayer = ProviderRuntimeIngestionLive.pipe(
Layer.provideMerge(runtimeServicesLayer),
Layer.provideMerge(ServerSettingsLive),
);
const providerCommandReactorLayer = ProviderCommandReactorLive.pipe(
Layer.provideMerge(runtimeServicesLayer),
Layer.provideMerge(GitCoreLive),
Layer.provideMerge(textGenerationLayer),
Layer.provideMerge(ServerSettingsLive),
);
const checkpointReactorLayer = CheckpointReactorLive.pipe(
Layer.provideMerge(runtimeServicesLayer),
@@ -137,5 +140,6 @@ export function makeServerRuntimeServicesLayer() {
gitManagerLayer,
terminalLayer,
KeybindingsLive,
ServerSettingsLive,
).pipe(Layer.provideMerge(NodeServices.layer));
}
+17 -41
View File
@@ -19,7 +19,6 @@ import {
import {
Cache,
Deferred,
Duration,
Effect,
Exit,
FileSystem,
@@ -35,7 +34,6 @@ import {
} from "effect";
import * as Semaphore from "effect/Semaphore";
import { ServerConfig } from "./config";
import { fromLenientJson } from "@t3tools/shared/schemaJson";
export class ServerSettingsError extends Schema.TaggedErrorClass<ServerSettingsError>()(
"ServerSettingsError",
@@ -72,16 +70,7 @@ export interface ServerSettingsShape {
export class ServerSettingsService extends ServiceMap.Service<
ServerSettingsService,
ServerSettingsShape
>()("t3/serverSettings/ServerSettingsService") {
static readonly layerTest = (overrides: Partial<ServerSettings> = {}) =>
Layer.succeed(ServerSettingsService, {
start: Effect.void,
ready: Effect.void,
getSettings: Effect.succeed({ ...DEFAULT_SERVER_SETTINGS, ...overrides }),
updateSettings: () => Effect.succeed({ ...DEFAULT_SERVER_SETTINGS, ...overrides }),
streamChanges: Stream.empty,
} satisfies ServerSettingsShape);
}
>()("t3/serverSettings/ServerSettingsService") {}
/**
* Derive `ProviderStartOptions` from server settings.
@@ -91,22 +80,18 @@ export function deriveProviderStartOptions(
settings: ServerSettings,
): ProviderStartOptions | undefined {
const providerOptions: ProviderStartOptions = {
...(settings.providers.codex
...(settings.codexBinaryPath || settings.codexHomePath
? {
codex: {
...(settings.providers.codex.binaryPath
? { binaryPath: settings.providers.codex.binaryPath }
: {}),
...(settings.providers.codex.homePath
? { homePath: settings.providers.codex.homePath }
: {}),
...(settings.codexBinaryPath ? { binaryPath: settings.codexBinaryPath } : {}),
...(settings.codexHomePath ? { homePath: settings.codexHomePath } : {}),
},
}
: {}),
...(settings.providers.claudeAgent
...(settings.claudeBinaryPath
? {
claudeAgent: {
binaryPath: settings.providers.claudeAgent.binaryPath,
binaryPath: settings.claudeBinaryPath,
},
}
: {}),
@@ -115,7 +100,7 @@ export function deriveProviderStartOptions(
return Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
}
const ServerSettingsJson = fromLenientJson(ServerSettings);
const ServerSettingsJson = Schema.fromJsonString(ServerSettings);
const PrettyJsonString = SchemaGetter.parseJson<string>().compose(
SchemaGetter.stringifyJson({ space: 2 }),
);
@@ -231,25 +216,16 @@ const makeServerSettings = Effect.gen(function* () {
const revalidateAndEmitSafely = revalidateAndEmit.pipe(Effect.ignoreCause({ log: true }));
// Debounce watch events so the file is fully written before we read it.
// Editors emit multiple events per save (truncate, write, rename) and
// `fs.watch` can fire before the content has been flushed to disk.
const debouncedSettingsEvents = fs.watch(settingsDir).pipe(
Stream.filter((event) => {
return (
event.path === settingsFile ||
event.path === settingsPath ||
pathService.resolve(settingsDir, event.path) === settingsPathResolved
);
}),
Stream.debounce(Duration.millis(100)),
);
yield* Stream.runForEach(debouncedSettingsEvents, () => revalidateAndEmitSafely).pipe(
Effect.ignoreCause({ log: true }),
Effect.forkIn(watcherScope),
Effect.asVoid,
);
yield* Stream.runForEach(fs.watch(settingsDir), (event) => {
const isTargetEvent =
event.path === settingsFile ||
event.path === settingsPath ||
pathService.resolve(settingsDir, event.path) === settingsPathResolved;
if (!isTargetEvent) {
return Effect.void;
}
return revalidateAndEmitSafely;
}).pipe(Effect.ignoreCause({ log: true }), Effect.forkIn(watcherScope), Effect.asVoid);
});
const start = Effect.gen(function* () {
-2
View File
@@ -53,7 +53,6 @@ import { GitCore } from "./git/Services/GitCore.ts";
import { GitCommandError, GitManagerError } from "./git/Errors.ts";
import { MigrationError } from "@effect/sql-sqlite-bun/SqliteMigrator";
import { AnalyticsService } from "./telemetry/Services/AnalyticsService.ts";
import { ServerSettingsService } from "./serverSettings.ts";
const asEventId = (value: string): EventId => EventId.makeUnsafe(value);
const asProviderItemId = (value: string): ProviderItemId => ProviderItemId.makeUnsafe(value);
@@ -546,7 +545,6 @@ describe("WebSocket Server", () => {
Layer.provideMerge(runtimeLayer),
Layer.provideMerge(providerHealthLayer),
Layer.provideMerge(openLayer),
Layer.provideMerge(ServerSettingsService.layerTest()),
Layer.provideMerge(serverConfigLayer),
Layer.provideMerge(AnalyticsService.layerTest),
Layer.provideMerge(NodeServices.layer),
+266
View File
@@ -0,0 +1,266 @@
import { describe, expect, it } from "vitest";
import {
DEFAULT_SIDEBAR_PROJECT_SORT_ORDER,
DEFAULT_SIDEBAR_THREAD_SORT_ORDER,
DEFAULT_TIMESTAMP_FORMAT,
} from "./appSettings";
import {
getAppModelOptions,
getCustomModelOptionsByProvider,
getCustomModelsByProvider,
getCustomModelsForProvider,
getDefaultCustomModelsForProvider,
MODEL_PROVIDER_SETTINGS,
normalizeCustomModelSlugs,
patchCustomModels,
resolveAppModelSelectionState,
resolveAppModelSelection,
} from "./modelSelection";
describe("normalizeCustomModelSlugs", () => {
it("normalizes aliases, removes built-ins, and deduplicates values", () => {
expect(
normalizeCustomModelSlugs([
" custom/internal-model ",
"gpt-5.3-codex",
"5.3",
"custom/internal-model",
"",
null,
]),
).toEqual(["custom/internal-model"]);
});
it("normalizes provider-specific aliases for claude", () => {
expect(normalizeCustomModelSlugs(["sonnet"], "claudeAgent")).toEqual([]);
expect(normalizeCustomModelSlugs(["claude/custom-sonnet"], "claudeAgent")).toEqual([
"claude/custom-sonnet",
]);
});
});
describe("getAppModelOptions", () => {
it("appends saved custom models after the built-in options", () => {
const options = getAppModelOptions("codex", ["custom/internal-model"]);
expect(options.map((option) => option.slug)).toEqual([
"gpt-5.4",
"gpt-5.4-mini",
"gpt-5.3-codex",
"gpt-5.3-codex-spark",
"gpt-5.2-codex",
"gpt-5.2",
"custom/internal-model",
]);
});
it("keeps the currently selected custom model available even if it is no longer saved", () => {
const options = getAppModelOptions("codex", [], "custom/selected-model");
expect(options.at(-1)).toEqual({
slug: "custom/selected-model",
name: "custom/selected-model",
isCustom: true,
});
});
it("keeps a saved custom provider model available as an exact slug option", () => {
const options = getAppModelOptions("claudeAgent", ["claude/custom-opus"], "claude/custom-opus");
expect(options.some((option) => option.slug === "claude/custom-opus" && option.isCustom)).toBe(
true,
);
});
});
describe("resolveAppModelSelection", () => {
it("preserves saved custom model slugs instead of falling back to the default", () => {
expect(
resolveAppModelSelection(
"codex",
{ codex: ["galapagos-alpha"], claudeAgent: [] },
"galapagos-alpha",
),
).toBe("galapagos-alpha");
});
it("falls back to the provider default when no model is selected", () => {
expect(resolveAppModelSelection("codex", { codex: [], claudeAgent: [] }, "")).toBe("gpt-5.4");
});
it("resolves display names through the shared resolver", () => {
expect(resolveAppModelSelection("codex", { codex: [], claudeAgent: [] }, "GPT-5.3 Codex")).toBe(
"gpt-5.3-codex",
);
});
it("resolves aliases through the shared resolver", () => {
expect(resolveAppModelSelection("claudeAgent", { codex: [], claudeAgent: [] }, "sonnet")).toBe(
"claude-sonnet-4-6",
);
});
it("resolves transient selected custom models included in app model options", () => {
expect(
resolveAppModelSelection("codex", { codex: [], claudeAgent: [] }, "custom/selected-model"),
).toBe("custom/selected-model");
});
});
describe("timestamp format defaults", () => {
it("defaults timestamp format to locale", () => {
expect(DEFAULT_TIMESTAMP_FORMAT).toBe("locale");
});
});
describe("sidebar sort defaults", () => {
it("defaults project sorting to updated_at", () => {
expect(DEFAULT_SIDEBAR_PROJECT_SORT_ORDER).toBe("updated_at");
});
it("defaults thread sorting to updated_at", () => {
expect(DEFAULT_SIDEBAR_THREAD_SORT_ORDER).toBe("updated_at");
});
});
describe("provider-specific custom models", () => {
it("includes provider-specific custom slugs in non-codex model lists", () => {
const claudeOptions = getAppModelOptions("claudeAgent", ["claude/custom-opus"]);
expect(claudeOptions.some((option) => option.slug === "claude/custom-opus")).toBe(true);
});
});
describe("provider-indexed custom model settings", () => {
const settings = {
customCodexModels: ["custom/codex-model"],
customClaudeModels: ["claude/custom-opus"],
} as const;
it("exports one provider config per provider", () => {
expect(MODEL_PROVIDER_SETTINGS.map((config) => config.provider)).toEqual([
"codex",
"claudeAgent",
]);
});
it("reads custom models for each provider", () => {
expect(getCustomModelsForProvider(settings, "codex")).toEqual(["custom/codex-model"]);
expect(getCustomModelsForProvider(settings, "claudeAgent")).toEqual(["claude/custom-opus"]);
});
it("reads default custom models for each provider", () => {
const defaults = {
customCodexModels: ["default/codex-model"],
customClaudeModels: ["claude/default-opus"],
} as const;
expect(getDefaultCustomModelsForProvider(defaults, "codex")).toEqual(["default/codex-model"]);
expect(getDefaultCustomModelsForProvider(defaults, "claudeAgent")).toEqual([
"claude/default-opus",
]);
});
it("patches custom models for codex", () => {
expect(patchCustomModels("codex", ["custom/codex-model"])).toEqual({
customCodexModels: ["custom/codex-model"],
});
});
it("patches custom models for claude", () => {
expect(patchCustomModels("claudeAgent", ["claude/custom-opus"])).toEqual({
customClaudeModels: ["claude/custom-opus"],
});
});
it("builds a complete provider-indexed custom model record", () => {
expect(getCustomModelsByProvider(settings)).toEqual({
codex: ["custom/codex-model"],
claudeAgent: ["claude/custom-opus"],
});
});
it("builds provider-indexed model options including custom models", () => {
const modelOptionsByProvider = getCustomModelOptionsByProvider(settings);
expect(
modelOptionsByProvider.codex.some((option) => option.slug === "custom/codex-model"),
).toBe(true);
expect(
modelOptionsByProvider.claudeAgent.some((option) => option.slug === "claude/custom-opus"),
).toBe(true);
});
it("normalizes and deduplicates custom model options per provider", () => {
const modelOptionsByProvider = getCustomModelOptionsByProvider({
customCodexModels: [" custom/codex-model ", "gpt-5.4", "custom/codex-model"],
customClaudeModels: [" sonnet ", "claude/custom-opus", "claude/custom-opus"],
});
expect(
modelOptionsByProvider.codex.filter((option) => option.slug === "custom/codex-model"),
).toHaveLength(1);
expect(modelOptionsByProvider.codex.some((option) => option.slug === "gpt-5.4")).toBe(true);
expect(
modelOptionsByProvider.claudeAgent.filter((option) => option.slug === "claude/custom-opus"),
).toHaveLength(1);
expect(
modelOptionsByProvider.claudeAgent.some((option) => option.slug === "claude-sonnet-4-6"),
).toBe(true);
});
});
describe("resolveAppModelSelectionState", () => {
it("falls back to the default git-writing codex selection", () => {
expect(
resolveAppModelSelectionState({
customCodexModels: [],
customClaudeModels: [],
textGenerationModelSelection: undefined,
}),
).toEqual({
provider: "codex",
model: "gpt-5.4-mini",
});
});
it("preserves the selected provider and resolves saved custom models", () => {
expect(
resolveAppModelSelectionState({
customCodexModels: [],
customClaudeModels: ["claude/custom-haiku"],
textGenerationModelSelection: {
provider: "claudeAgent",
model: "claude/custom-haiku",
},
}),
).toEqual({
provider: "claudeAgent",
model: "claude/custom-haiku",
});
});
it("normalizes provider options against the resolved model capabilities", () => {
expect(
resolveAppModelSelectionState({
customCodexModels: [],
customClaudeModels: [],
textGenerationModelSelection: {
provider: "claudeAgent",
model: "claude-haiku-4-5",
options: {
effort: "max",
thinking: false,
fastMode: true,
},
},
}),
).toEqual({
provider: "claudeAgent",
model: "claude-haiku-4-5",
options: {
thinking: false,
},
});
});
});
+3
View File
@@ -8,8 +8,11 @@
* Also re-exports type aliases and schema constants consumed by components
* that only need the type (e.g. `TimestampFormat`).
*/
import { DEFAULT_SERVER_SETTINGS, type ServerSettings } from "@t3tools/contracts";
import { useSettings, useUpdateSettings, type UnifiedSettings } from "./hooks/useSettings";
import {
DEFAULT_CLIENT_SETTINGS,
type ClientSettings,
type TimestampFormat,
type SidebarProjectSortOrder,
type SidebarThreadSortOrder,
+8 -4
View File
@@ -12,7 +12,6 @@ import {
WS_CHANNELS,
WS_METHODS,
OrchestrationSessionStatus,
DEFAULT_SERVER_SETTINGS,
} from "@t3tools/contracts";
import { RouterProvider, createMemoryHistory } from "@tanstack/react-router";
import { HttpResponse, http, ws } from "msw";
@@ -31,7 +30,6 @@ import { isMacPlatform } from "../lib/utils";
import { getRouter } from "../router";
import { useStore } from "../store";
import { estimateTimelineMessageHeight } from "./timelineHeight";
import { DEFAULT_CLIENT_SETTINGS } from "~/clientSettings";
const THREAD_ID = "thread-browser-test" as ThreadId;
const UUID_ROUTE_RE = /^\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
@@ -120,8 +118,14 @@ function createBaseServerConfig(): ServerConfig {
],
availableEditors: [],
settings: {
...DEFAULT_SERVER_SETTINGS,
...DEFAULT_CLIENT_SETTINGS,
claudeBinaryPath: "",
codexBinaryPath: "",
codexHomePath: "",
enableAssistantStreaming: false,
defaultThreadEnvMode: "local" as const,
customCodexModels: [],
customClaudeModels: [],
textGenerationModelSelection: { provider: "codex" as const, model: "gpt-5.4-mini" },
},
};
}
+9 -4
View File
@@ -121,7 +121,11 @@ import { SidebarTrigger } from "./ui/sidebar";
import { newCommandId, newMessageId, newThreadId } from "~/lib/utils";
import { readNativeApi } from "~/nativeApi";
import { useAppSettings } from "../appSettings";
import { getCustomModelOptionsByProvider, resolveAppModelSelection } from "../modelSelection";
import {
getCustomModelOptionsByProvider,
getCustomModelsByProvider,
resolveAppModelSelection,
} from "../modelSelection";
import { isTerminalFocused } from "../lib/terminalFocus";
import {
type ComposerImageAttachment,
@@ -606,12 +610,13 @@ export default function ChatView({ threadId }: ChatViewProps) {
: null;
const selectedProvider: ProviderKind =
lockedProvider ?? selectedProviderByThreadId ?? threadProvider ?? "codex";
const customModelsByProvider = useMemo(() => getCustomModelsByProvider(settings), [settings]);
const { modelOptions: composerModelOptions, selectedModel } = useEffectiveComposerModelState({
threadId,
selectedProvider,
threadModelSelection: activeThread?.modelSelection,
projectModelSelection: activeProject?.defaultModelSelection,
settings,
customModelsByProvider,
});
const composerProviderState = useMemo(
() =>
@@ -3094,7 +3099,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
scheduleComposerFocus();
return;
}
const resolvedModel = resolveAppModelSelection(provider, settings, model);
const resolvedModel = resolveAppModelSelection(provider, customModelsByProvider, model);
const nextModelSelection: ModelSelection = {
provider,
model: resolvedModel,
@@ -3109,7 +3114,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
scheduleComposerFocus,
setComposerDraftModelSelection,
setStickyComposerModelSelection,
settings,
customModelsByProvider,
],
);
const setPromptFromTraits = useCallback(
@@ -20,6 +20,7 @@ import {
resolveQuickAction,
summarizeGitResult,
} from "./GitActionsControl.logic";
import { useAppSettings } from "~/appSettings";
import { Button } from "~/components/ui/button";
import { Checkbox } from "~/components/ui/checkbox";
import {
@@ -204,6 +205,7 @@ function GitQuickActionIcon({ quickAction }: { quickAction: GitQuickAction }) {
}
export default function GitActionsControl({ gitCwd, activeThreadId }: GitActionsControlProps) {
const { settings } = useAppSettings();
const threadToastData = useMemo(
() => (activeThreadId ? { threadId: activeThreadId } : undefined),
[activeThreadId],
@@ -259,6 +261,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
gitRunStackedActionMutationOptions({
cwd: gitCwd,
queryClient,
modelSelection: settings.textGenerationModelSelection,
}),
);
const pullMutation = useMutation(gitPullMutationOptions({ cwd: gitCwd, queryClient }));
@@ -54,13 +54,14 @@ function createBaseServerConfig(): ServerConfig {
],
availableEditors: [],
settings: {
claudeBinaryPath: "",
codexBinaryPath: "",
codexHomePath: "",
enableAssistantStreaming: false,
defaultThreadEnvMode: "local" as const,
customCodexModels: [],
customClaudeModels: [],
textGenerationModelSelection: { provider: "codex" as const, model: "gpt-5.4-mini" },
providers: {
codex: { binaryPath: "", homePath: "", customModels: [] },
claudeAgent: { binaryPath: "", customModels: [] },
},
},
};
}
@@ -5,7 +5,6 @@ import {
ClaudeModelOptions,
CodexModelOptions,
DEFAULT_MODEL_BY_PROVIDER,
DEFAULT_SERVER_SETTINGS,
ProjectId,
ThreadId,
} from "@t3tools/contracts";
@@ -22,7 +21,6 @@ import {
useComposerThreadDraft,
useEffectiveComposerModelState,
} from "../../composerDraftStore";
import { DEFAULT_CLIENT_SETTINGS } from "~/clientSettings";
// ── Claude TraitsPicker tests ─────────────────────────────────────────
@@ -40,10 +38,7 @@ function ClaudeTraitsPickerHarness(props: {
selectedProvider: "claudeAgent",
threadModelSelection: props.fallbackModelSelection,
projectModelSelection: null,
settings: {
...DEFAULT_SERVER_SETTINGS,
...DEFAULT_CLIENT_SETTINGS,
},
customModelsByProvider: { codex: [], claudeAgent: [] },
});
const handlePromptChange = useCallback(
(nextPrompt: string) => {
+9 -6
View File
@@ -31,7 +31,6 @@ import {
import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
import { createDebouncedStorage, createMemoryStorage } from "./lib/storage";
import { UnifiedSettings } from "./appSettings";
export const COMPOSER_DRAFT_STORAGE_KEY = "t3code:composer-drafts:v1";
const COMPOSER_DRAFT_STORAGE_VERSION = 3;
@@ -617,7 +616,7 @@ export function deriveEffectiveComposerModelState(input: {
selectedProvider: ProviderKind;
threadModelSelection: ModelSelection | null | undefined;
projectModelSelection: ModelSelection | null | undefined;
settings: UnifiedSettings;
customModelsByProvider: Record<ProviderKind, readonly string[]>;
}): EffectiveComposerModelState {
const baseModel = resolveModelSlugForProvider(
input.selectedProvider,
@@ -627,7 +626,11 @@ export function deriveEffectiveComposerModelState(input: {
);
const activeSelection = input.draft?.modelSelectionByProvider?.[input.selectedProvider];
const selectedModel = activeSelection?.model
? resolveAppModelSelection(input.selectedProvider, input.settings, activeSelection.model)
? resolveAppModelSelection(
input.selectedProvider,
input.customModelsByProvider,
activeSelection.model,
)
: baseModel;
const modelOptions =
modelSelectionByProviderToOptions(input.draft?.modelSelectionByProvider) ??
@@ -2157,7 +2160,7 @@ export function useEffectiveComposerModelState(input: {
selectedProvider: ProviderKind;
threadModelSelection: ModelSelection | null | undefined;
projectModelSelection: ModelSelection | null | undefined;
settings: UnifiedSettings;
customModelsByProvider: Record<ProviderKind, readonly string[]>;
}): EffectiveComposerModelState {
const draft = useComposerThreadDraft(input.threadId);
@@ -2168,11 +2171,11 @@ export function useEffectiveComposerModelState(input: {
selectedProvider: input.selectedProvider,
threadModelSelection: input.threadModelSelection,
projectModelSelection: input.projectModelSelection,
settings: input.settings,
customModelsByProvider: input.customModelsByProvider,
}),
[
draft,
input.settings,
input.customModelsByProvider,
input.projectModelSelection,
input.selectedProvider,
input.threadModelSelection,
+4
View File
@@ -32,6 +32,10 @@ describe("git mutation options", () => {
const options = gitRunStackedActionMutationOptions({
cwd: "/repo/a",
queryClient,
modelSelection: {
provider: "codex",
model: "gpt-5.4",
},
});
expect(options.mutationKey).toEqual(gitMutationKeys.runStackedAction("/repo/a"));
});
+3 -1
View File
@@ -1,4 +1,4 @@
import { type GitStackedAction } from "@t3tools/contracts";
import { type GitStackedAction, type ModelSelection } from "@t3tools/contracts";
import { mutationOptions, queryOptions, type QueryClient } from "@tanstack/react-query";
import { ensureNativeApi } from "../nativeApi";
@@ -112,6 +112,7 @@ export function gitCheckoutMutationOptions(input: {
export function gitRunStackedActionMutationOptions(input: {
cwd: string | null;
queryClient: QueryClient;
modelSelection: ModelSelection;
}) {
return mutationOptions({
mutationKey: gitMutationKeys.runStackedAction(input.cwd),
@@ -133,6 +134,7 @@ export function gitRunStackedActionMutationOptions(input: {
return api.git.runStackedAction({
actionId,
cwd: input.cwd,
modelSelection: input.modelSelection,
action,
...(commitMessage ? { commitMessage } : {}),
...(featureBranch ? { featureBranch } : {}),
+1 -7
View File
@@ -6,13 +6,6 @@ export const serverQueryKeys = {
config: () => ["server", "config"] as const,
};
/**
* Server config query options.
*
* `staleTime` is kept short so that push-driven `invalidateQueries` calls in
* the EventRouter always trigger a refetch, and so the query re-fetches when
* the component re-mounts (e.g. navigating away from settings and back).
*/
export function serverConfigQueryOptions() {
return queryOptions({
queryKey: serverQueryKeys.config(),
@@ -20,5 +13,6 @@ export function serverConfigQueryOptions() {
const api = ensureNativeApi();
return api.server.getConfig();
},
staleTime: Infinity,
});
}
+63 -16
View File
@@ -10,13 +10,19 @@ import {
resolveSelectableModel,
} from "@t3tools/shared/model";
import { getComposerProviderState } from "./components/chat/composerProviderRegistry";
import { UnifiedSettings } from "./appSettings";
const MAX_CUSTOM_MODEL_COUNT = 32;
export const MAX_CUSTOM_MODEL_LENGTH = 256;
export type CustomModelSettings = {
customCodexModels: readonly string[];
customClaudeModels: readonly string[];
};
export type ProviderCustomModelConfig = {
provider: ProviderKind;
settingsKey: keyof CustomModelSettings;
defaultSettingsKey: keyof CustomModelSettings;
title: string;
description: string;
placeholder: string;
@@ -32,6 +38,8 @@ export interface AppModelOption {
const PROVIDER_CUSTOM_MODEL_CONFIG: Record<ProviderKind, ProviderCustomModelConfig> = {
codex: {
provider: "codex",
settingsKey: "customCodexModels",
defaultSettingsKey: "customCodexModels",
title: "Codex",
description: "Save additional Codex model slugs for the picker and `/model` command.",
placeholder: "your-codex-model-slug",
@@ -39,6 +47,8 @@ const PROVIDER_CUSTOM_MODEL_CONFIG: Record<ProviderKind, ProviderCustomModelConf
},
claudeAgent: {
provider: "claudeAgent",
settingsKey: "customClaudeModels",
defaultSettingsKey: "customClaudeModels",
title: "Claude",
description: "Save additional Claude model slugs for the picker and `/model` command.",
placeholder: "your-claude-model-slug",
@@ -82,9 +92,41 @@ export function normalizeCustomModelSlugs(
return normalizedModels;
}
export function getAppModelOptions(
settings: UnifiedSettings,
export function getCustomModelsForProvider(
settings: CustomModelSettings,
provider: ProviderKind,
): readonly string[] {
return settings[PROVIDER_CUSTOM_MODEL_CONFIG[provider].settingsKey];
}
export function getDefaultCustomModelsForProvider(
defaults: CustomModelSettings,
provider: ProviderKind,
): readonly string[] {
return defaults[PROVIDER_CUSTOM_MODEL_CONFIG[provider].defaultSettingsKey];
}
export function patchCustomModels(
provider: ProviderKind,
models: string[],
): Partial<CustomModelSettings> {
return {
[PROVIDER_CUSTOM_MODEL_CONFIG[provider].settingsKey]: models,
};
}
export function getCustomModelsByProvider(
settings: CustomModelSettings,
): Record<ProviderKind, readonly string[]> {
return {
codex: getCustomModelsForProvider(settings, "codex"),
claudeAgent: getCustomModelsForProvider(settings, "claudeAgent"),
};
}
export function getAppModelOptions(
provider: ProviderKind,
customModels: readonly string[],
selectedModel?: string | null,
): AppModelOption[] {
const options: AppModelOption[] = getModelOptions(provider).map(({ slug, name }) => ({
@@ -95,7 +137,6 @@ export function getAppModelOptions(
const seen = new Set(options.map((option) => option.slug));
const trimmedSelectedModel = selectedModel?.trim().toLowerCase();
const customModels = settings.providers[provider].customModels;
for (const slug of normalizeCustomModelSlugs(customModels, provider)) {
if (seen.has(slug)) {
continue;
@@ -130,51 +171,57 @@ export function getAppModelOptions(
export function resolveAppModelSelection(
provider: ProviderKind,
settings: UnifiedSettings,
customModels: Record<ProviderKind, readonly string[]>,
selectedModel: string | null | undefined,
): string {
const options = getAppModelOptions(settings, provider, selectedModel);
const customModelsForProvider = customModels[provider];
const options = getAppModelOptions(provider, customModelsForProvider, selectedModel);
return resolveSelectableModel(provider, selectedModel, options) ?? getDefaultModel(provider);
}
export function getCustomModelOptionsByProvider(
settings: UnifiedSettings,
settings: CustomModelSettings,
selectedProvider?: ProviderKind | null,
selectedModel?: string | null,
): Record<ProviderKind, ReadonlyArray<{ slug: string; name: string }>> {
const customModelsByProvider = getCustomModelsByProvider(settings);
return {
codex: getAppModelOptions(
settings,
"codex",
customModelsByProvider.codex,
selectedProvider === "codex" ? selectedModel : undefined,
),
claudeAgent: getAppModelOptions(
settings,
"claudeAgent",
customModelsByProvider.claudeAgent,
selectedProvider === "claudeAgent" ? selectedModel : undefined,
),
};
}
export function resolveAppModelSelectionState(settings: UnifiedSettings): ModelSelection {
export function resolveAppModelSelectionState(
settings: CustomModelSettings & {
textGenerationModelSelection: ModelSelection | undefined;
},
): ModelSelection {
const selection = settings.textGenerationModelSelection ?? {
provider: "codex" as const,
model: DEFAULT_GIT_TEXT_GENERATION_MODEL_BY_PROVIDER.codex,
};
const model = resolveAppModelSelection(selection.provider, settings, selection.model);
const provider = selection.provider;
const customModelsByProvider = getCustomModelsByProvider(settings);
const model = resolveAppModelSelection(provider, customModelsByProvider, selection.model);
const { modelOptionsForDispatch } = getComposerProviderState({
provider: selection.provider,
provider,
model,
prompt: "",
modelOptions: {
[selection.provider]: selection.options,
[provider]: selection.options,
},
});
return {
provider: selection.provider,
provider,
model,
...(modelOptionsForDispatch ? { options: modelOptionsForDispatch } : {}),
};
-6
View File
@@ -263,14 +263,8 @@ function EventRouter() {
// don't produce duplicate toasts.
let subscribed = false;
const unsubServerConfigUpdated = onServerConfigUpdated((payload) => {
// Invalidate the config query so active observers refetch fresh data.
void queryClient.invalidateQueries({ queryKey: serverQueryKeys.config() });
if (!subscribed) return;
// Only show keybindings toasts for keybindings changes (no settings in payload)
if (payload.settings) return;
const issue = payload.issues.find((entry) => entry.kind.startsWith("keybindings."));
if (!issue) {
toastManager.add({
+45 -81
View File
@@ -7,8 +7,10 @@ import { getModelOptions, normalizeModelSlug } from "@t3tools/shared/model";
import { useAppSettings } from "../appSettings";
import {
getCustomModelOptionsByProvider,
getCustomModelsForProvider,
MAX_CUSTOM_MODEL_LENGTH,
MODEL_PROVIDER_SETTINGS,
patchCustomModels,
resolveAppModelSelectionState,
} from "../modelSelection";
import { APP_VERSION } from "../branding";
@@ -59,9 +61,11 @@ const TIMESTAMP_FORMAT_LABELS = {
"24-hour": "24-hour",
} as const;
type InstallBinarySettingsKey = "claudeBinaryPath" | "codexBinaryPath";
type InstallProviderSettings = {
provider: ProviderKind;
title: string;
binaryPathKey: InstallBinarySettingsKey;
binaryPlaceholder: string;
binaryDescription: ReactNode;
homePathKey?: "codexHomePath";
@@ -73,6 +77,7 @@ const INSTALL_PROVIDER_SETTINGS: readonly InstallProviderSettings[] = [
{
provider: "codex",
title: "Codex",
binaryPathKey: "codexBinaryPath",
binaryPlaceholder: "Codex binary path",
binaryDescription: (
<>
@@ -86,6 +91,7 @@ const INSTALL_PROVIDER_SETTINGS: readonly InstallProviderSettings[] = [
{
provider: "claudeAgent",
title: "Claude",
binaryPathKey: "claudeBinaryPath",
binaryPlaceholder: "Claude binary path",
binaryDescription: (
<>
@@ -189,8 +195,8 @@ function SettingsRouteView() {
const [isOpeningKeybindings, setIsOpeningKeybindings] = useState(false);
const [openKeybindingsError, setOpenKeybindingsError] = useState<string | null>(null);
const [openInstallProviders, setOpenInstallProviders] = useState<Record<ProviderKind, boolean>>({
codex: Boolean(settings.providers.codex.binaryPath || settings.providers.codex.homePath),
claudeAgent: Boolean(settings.providers.claudeAgent.binaryPath),
codex: Boolean(settings.codexBinaryPath || settings.codexHomePath),
claudeAgent: Boolean(settings.claudeBinaryPath),
});
const [selectedCustomModelProvider, setSelectedCustomModelProvider] =
useState<ProviderKind>("codex");
@@ -205,7 +211,9 @@ function SettingsRouteView() {
>({});
const [showAllCustomModels, setShowAllCustomModels] = useState(false);
const codexHomePath = settings.providers.codex.homePath;
const codexBinaryPath = settings.codexBinaryPath;
const codexHomePath = settings.codexHomePath;
const claudeBinaryPath = settings.claudeBinaryPath;
const keybindingsConfigPath = serverConfigQuery.data?.keybindingsConfigPath ?? null;
const availableEditors = serverConfigQuery.data?.availableEditors;
@@ -223,11 +231,9 @@ function SettingsRouteView() {
)!;
const selectedCustomModelInput = customModelInputByProvider[selectedCustomModelProvider];
const selectedCustomModelError = customModelErrorByProvider[selectedCustomModelProvider] ?? null;
const totalCustomModels =
settings.providers.codex.customModels.length +
settings.providers.claudeAgent.customModels.length;
const totalCustomModels = settings.customCodexModels.length + settings.customClaudeModels.length;
const savedCustomModelRows = MODEL_PROVIDER_SETTINGS.flatMap((providerSettings) =>
settings.providers[providerSettings.provider].customModels.map((slug) => ({
getCustomModelsForProvider(settings, providerSettings.provider).map((slug) => ({
key: `${providerSettings.provider}:${slug}`,
provider: providerSettings.provider,
providerTitle: providerSettings.title,
@@ -238,9 +244,9 @@ function SettingsRouteView() {
? savedCustomModelRows
: savedCustomModelRows.slice(0, 5);
const isInstallSettingsDirty =
settings.providers.claudeAgent.binaryPath !== defaults.providers.claudeAgent.binaryPath ||
settings.providers.codex.binaryPath !== defaults.providers.codex.binaryPath ||
settings.providers.codex.homePath !== defaults.providers.codex.homePath;
settings.claudeBinaryPath !== defaults.claudeBinaryPath ||
settings.codexBinaryPath !== defaults.codexBinaryPath ||
settings.codexHomePath !== defaults.codexHomePath;
const changedSettingLabels = [
...(theme !== "system" ? ["Theme"] : []),
...(settings.timestampFormat !== defaults.timestampFormat ? ["Time format"] : []),
@@ -256,8 +262,7 @@ function SettingsRouteView() {
JSON.stringify(defaults.textGenerationModelSelection ?? null)
? ["Git writing model"]
: []),
...(settings.providers.codex.customModels.length > 0 ||
settings.providers.claudeAgent.customModels.length > 0
...(settings.customCodexModels.length > 0 || settings.customClaudeModels.length > 0
? ["Custom models"]
: []),
...(isInstallSettingsDirty ? ["Provider installs"] : []),
@@ -289,7 +294,7 @@ function SettingsRouteView() {
const addCustomModel = useCallback(
(provider: ProviderKind) => {
const customModelInput = customModelInputByProvider[provider];
const customModels = settings.providers[provider].customModels;
const customModels = getCustomModelsForProvider(settings, provider);
const normalized = normalizeModelSlug(customModelInput, provider);
if (!normalized) {
setCustomModelErrorByProvider((existing) => ({
@@ -320,15 +325,7 @@ function SettingsRouteView() {
return;
}
updateSettings({
providers: {
...settings.providers,
[provider]: {
...settings.providers[provider],
customModels: [...customModels, normalized],
},
},
});
updateSettings(patchCustomModels(provider, [...customModels, normalized]));
setCustomModelInputByProvider((existing) => ({
...existing,
[provider]: "",
@@ -343,16 +340,13 @@ function SettingsRouteView() {
const removeCustomModel = useCallback(
(provider: ProviderKind, slug: string) => {
const customModels = settings.providers[provider].customModels;
updateSettings({
providers: {
...settings.providers,
[provider]: {
...settings.providers[provider],
customModels: customModels.filter((model) => model !== slug),
},
},
});
const customModels = getCustomModelsForProvider(settings, provider);
updateSettings(
patchCustomModels(
provider,
customModels.filter((model) => model !== slug),
),
);
setCustomModelErrorByProvider((existing) => ({
...existing,
[provider]: null,
@@ -705,17 +699,8 @@ function SettingsRouteView() {
label="custom models"
onClick={() => {
updateSettings({
providers: {
...settings.providers,
codex: {
...settings.providers.codex,
customModels: defaults.providers.codex.customModels,
},
claudeAgent: {
...settings.providers.claudeAgent,
customModels: defaults.providers.claudeAgent.customModels,
},
},
customCodexModels: defaults.customCodexModels,
customClaudeModels: defaults.customClaudeModels,
});
setCustomModelErrorByProvider({});
setShowAllCustomModels(false);
@@ -846,18 +831,9 @@ function SettingsRouteView() {
label="provider installs"
onClick={() => {
updateSettings({
providers: {
...settings.providers,
claudeAgent: {
...settings.providers.claudeAgent,
binaryPath: defaults.providers.claudeAgent.binaryPath,
},
codex: {
...settings.providers.codex,
binaryPath: defaults.providers.codex.binaryPath,
homePath: defaults.providers.codex.homePath,
},
},
claudeBinaryPath: defaults.claudeBinaryPath,
codexBinaryPath: defaults.codexBinaryPath,
codexHomePath: defaults.codexHomePath,
});
setOpenInstallProviders({
codex: false,
@@ -874,15 +850,13 @@ function SettingsRouteView() {
const isOpen = openInstallProviders[providerSettings.provider];
const isDirty =
providerSettings.provider === "codex"
? settings.providers.codex.binaryPath !==
defaults.providers.codex.binaryPath ||
settings.providers.codex.homePath !== defaults.providers.codex.homePath
: settings.providers.claudeAgent.binaryPath !==
defaults.providers.claudeAgent.binaryPath;
? settings.codexBinaryPath !== defaults.codexBinaryPath ||
settings.codexHomePath !== defaults.codexHomePath
: settings.claudeBinaryPath !== defaults.claudeBinaryPath;
const binaryPathValue =
providerSettings.provider === "claudeAgent"
? settings.providers.claudeAgent.binaryPath
: settings.providers.codex.binaryPath;
providerSettings.binaryPathKey === "claudeBinaryPath"
? claudeBinaryPath
: codexBinaryPath;
return (
<Collapsible
@@ -924,26 +898,22 @@ function SettingsRouteView() {
<div className="border-t border-border/70 px-4 py-4">
<div className="space-y-3">
<label
htmlFor={`provider-install-${providerSettings.provider}-binary-path`}
htmlFor={`provider-install-${providerSettings.binaryPathKey}`}
className="block"
>
<span className="block text-xs font-medium text-foreground">
{providerSettings.title} binary path
</span>
<Input
id={`provider-install-${providerSettings.provider}-binary-path`}
id={`provider-install-${providerSettings.binaryPathKey}`}
className="mt-1"
value={binaryPathValue}
onChange={(event) =>
updateSettings({
providers: {
...settings.providers,
[providerSettings.provider]: {
...settings.providers[providerSettings.provider],
binaryPath: event.target.value,
},
},
})
updateSettings(
providerSettings.binaryPathKey === "claudeBinaryPath"
? { claudeBinaryPath: event.target.value }
: { codexBinaryPath: event.target.value },
)
}
placeholder={providerSettings.binaryPlaceholder}
spellCheck={false}
@@ -967,13 +937,7 @@ function SettingsRouteView() {
value={codexHomePath}
onChange={(event) =>
updateSettings({
providers: {
...settings.providers,
codex: {
...settings.providers.codex,
homePath: event.target.value,
},
},
codexHomePath: event.target.value,
})
}
placeholder={providerSettings.homePlaceholder}
+8
View File
@@ -357,6 +357,10 @@ describe("wsNativeApi", () => {
actionId: "action-1",
cwd: "/repo",
action: "commit",
modelSelection: {
provider: "codex",
model: "gpt-5.4-mini",
},
});
expect(requestMock).toHaveBeenCalledWith(
@@ -365,6 +369,10 @@ describe("wsNativeApi", () => {
actionId: "action-1",
cwd: "/repo",
action: "commit",
modelSelection: {
provider: "codex",
model: "gpt-5.4-mini",
},
},
{ timeoutMs: null },
);
+15
View File
@@ -74,4 +74,19 @@ describe("GitRunStackedActionInput", () => {
expect(parsed.actionId).toBe("action-1");
expect(parsed.action).toBe("commit");
});
it("accepts git text generation as a modelSelection", () => {
const parsed = decodeRunStackedActionInput({
actionId: "action-1",
cwd: "/repo",
action: "commit_push_pr",
modelSelection: {
provider: "claudeAgent",
model: "claude-haiku-4-5",
},
});
expect(parsed.modelSelection?.provider).toBe("claudeAgent");
expect(parsed.modelSelection?.model).toBe("claude-haiku-4-5");
});
});
+2
View File
@@ -1,5 +1,6 @@
import { Schema } from "effect";
import { NonNegativeInt, PositiveInt, TrimmedNonEmptyString } from "./baseSchemas";
import { ModelSelection } from "./orchestration";
const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
@@ -79,6 +80,7 @@ export const GitRunStackedActionInput = Schema.Struct({
filePaths: Schema.optional(
Schema.Array(TrimmedNonEmptyStringSchema).check(Schema.isMinLength(1)),
),
modelSelection: ModelSelection,
});
export type GitRunStackedActionInput = typeof GitRunStackedActionInput.Type;
+5 -19
View File
@@ -10,36 +10,22 @@ import { ModelSelection, ProviderKind } from "./orchestration";
export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
export type ThreadEnvMode = typeof ThreadEnvMode.Type;
export const CodexSettings = Schema.Struct({
binaryPath: Schema.String.pipe(Schema.withDecodingDefault(() => "")),
homePath: Schema.String.pipe(Schema.withDecodingDefault(() => "")),
customModels: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(() => [])),
});
export type CodexSettings = typeof CodexSettings.Type;
export const ClaudeSettings = Schema.Struct({
binaryPath: Schema.String.pipe(Schema.withDecodingDefault(() => "")),
customModels: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(() => [])),
});
export type ClaudeSettings = typeof ClaudeSettings.Type;
export const ServerSettings = Schema.Struct({
claudeBinaryPath: Schema.String.pipe(Schema.withDecodingDefault(() => "")),
codexBinaryPath: Schema.String.pipe(Schema.withDecodingDefault(() => "")),
codexHomePath: Schema.String.pipe(Schema.withDecodingDefault(() => "")),
enableAssistantStreaming: Schema.Boolean.pipe(Schema.withDecodingDefault(() => false)),
defaultThreadEnvMode: ThreadEnvMode.pipe(
Schema.withDecodingDefault(() => "local" as const satisfies ThreadEnvMode),
),
customCodexModels: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(() => [])),
customClaudeModels: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(() => [])),
textGenerationModelSelection: ModelSelection.pipe(
Schema.withDecodingDefault(() => ({
provider: "codex" as const,
model: DEFAULT_GIT_TEXT_GENERATION_MODEL_BY_PROVIDER.codex,
})),
),
// Provider specific settings
providers: Schema.Struct({
codex: CodexSettings.pipe(Schema.withDecodingDefault(() => ({}))),
claudeAgent: ClaudeSettings.pipe(Schema.withDecodingDefault(() => ({}))),
}).pipe(Schema.withDecodingDefault(() => ({}))),
});
export type ServerSettings = typeof ServerSettings.Type;
+1 -63
View File
@@ -1,14 +1,4 @@
import {
Cause,
Effect,
Exit,
Option,
Result,
Schema,
SchemaGetter,
SchemaIssue,
SchemaTransformation,
} from "effect";
import { Cause, Exit, Result, Schema, SchemaIssue } from "effect";
export const decodeJsonResult = <S extends Schema.Codec<unknown, unknown, never, never>>(
schema: S,
@@ -42,55 +32,3 @@ export const formatSchemaError = (cause: Cause.Cause<Schema.SchemaError>) => {
? SchemaIssue.makeFormatterDefault()(squashed.issue)
: Cause.pretty(cause);
};
/**
* A `Getter` that parses a lenient JSON string (tolerating trailing commas
* and JS-style comments) into an unknown value.
*
* Mirrors `SchemaGetter.parseJson()` but uses `parseLenientJson` instead
* of `JSON.parse`.
*/
const parseLenientJsonGetter = SchemaGetter.onSome((input: string) =>
Effect.try({
try: () => {
// Strip single-line comments — alternation preserves quoted strings.
let stripped = input.replace(
/("(?:[^"\\]|\\.)*")|\/\/[^\n]*/g,
(match, stringLiteral: string | undefined) => (stringLiteral ? match : ""),
);
// Strip multi-line comments.
stripped = stripped.replace(
/("(?:[^"\\]|\\.)*")|\/\*[\s\S]*?\*\//g,
(match, stringLiteral: string | undefined) => (stringLiteral ? match : ""),
);
// Strip trailing commas before `}` or `]`.
stripped = stripped.replace(/,(\s*[}\]])/g, "$1");
return Option.some(JSON.parse(stripped));
},
catch: (e) => new SchemaIssue.InvalidValue(Option.some(input), { message: String(e) }),
}),
);
/**
* Schema transformation: lenient JSONC string ↔ unknown.
*
* Same API as `SchemaTransformation.fromJsonString`, but the decode side
* strips trailing commas and JS-style comments before parsing.
* Encoding produces strict JSON via `JSON.stringify`.
*/
export const fromLenientJsonString = new SchemaTransformation.Transformation(
parseLenientJsonGetter,
SchemaGetter.stringifyJson(),
);
/**
* Build a schema that decodes a lenient JSON string into `A`.
*
* Drop-in replacement for `Schema.fromJsonString(schema)` that tolerates
* trailing commas and comments in the input.
*/
export const fromLenientJson = <S extends Schema.Top>(schema: S) =>
Schema.String.pipe(Schema.decodeTo(schema, fromLenientJsonString));