Compare commits

..
Author SHA1 Message Date
Cursor Agent f8c9d71187 fix: prevent empty-string binary paths from breaking CLI spawning and migrate old flat binary path keys
- Guard claude branch in deriveProviderStartOptions on binaryPath being truthy,
  not just the claude object existing (which is always truthy due to schema defaults)
- Use || instead of ?? for binaryPath fallbacks in ClaudeTextGeneration and
  CodexTextGeneration so empty strings correctly fall back to default CLI names
- Add explicit migration of old flat keys (claudeBinaryPath, codexBinaryPath,
  codexHomePath) into the new nested codex/claude objects in
  migrateLocalSettingsToServer
2026-03-25 21:07:23 +00:00
Julius Marminge 3f089a454b layers 2026-03-25 13:57:01 -07:00
19 changed files with 143 additions and 62 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 { ServerSettingsLive } from "../src/serverSettings.ts";
import { ServerSettingsService } from "../src/serverSettings.ts";
function runGit(cwd: string, args: ReadonlyArray<string>) {
return execFileSync("git", args, {
@@ -296,10 +296,7 @@ export const makeOrchestrationIntegrationHarness = (
providerLayer,
RuntimeReceiptBusLive,
);
const serverSettingsLayer = ServerSettingsLive.pipe(
Layer.provide(ServerConfig.layerTest(workspaceDir, rootDir)),
Layer.provide(NodeServices.layer),
);
const serverSettingsLayer = ServerSettingsService.layerTest();
const runtimeIngestionLayer = ProviderRuntimeIngestionLive.pipe(
Layer.provideMerge(runtimeServicesLayer),
Layer.provideMerge(serverSettingsLayer),
@@ -6,8 +6,10 @@ 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,6 +27,7 @@ import {
sanitizePrTitle,
toJsonSchemaObject,
} from "../Utils.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
const CLAUDE_TIMEOUT_MS = 180_000;
@@ -40,6 +41,7 @@ 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,
@@ -86,9 +88,14 @@ const makeClaudeTextGeneration = Effect.gen(function* () {
...(normalizedOptions?.fastMode ? { fastMode: true } : {}),
};
const claudeSettings = yield* Effect.map(
serverSettingsService.getSettings,
(settings) => settings.claude,
).pipe(Effect.catch(() => Effect.undefined));
const runClaudeCommand = Effect.gen(function* () {
const command = ChildProcess.make(
"claude",
claudeSettings?.binaryPath || "claude",
[
"-p",
"--output-format",
@@ -7,6 +7,7 @@ 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,
@@ -14,6 +15,7 @@ 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,6 +26,7 @@ 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;
@@ -35,6 +36,7 @@ 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>;
@@ -138,6 +140,11 @@ const makeCodexTextGeneration = Effect.gen(function* () {
);
const outputPath = yield* writeTempFile(operation, "codex-output", "");
const codexSettings = yield* Effect.map(
serverSettingsService.getSettings,
(settings) => settings.codex,
).pipe(Effect.catch(() => Effect.undefined));
const runCodexCommand = Effect.gen(function* () {
const normalizedOptions = normalizeCodexModelOptions(
modelSelection.model,
@@ -146,7 +153,7 @@ const makeCodexTextGeneration = Effect.gen(function* () {
const reasoningEffort =
modelSelection.options?.reasoningEffort ?? CODEX_GIT_TEXT_GENERATION_REASONING_EFFORT;
const command = ChildProcess.make(
"codex",
codexSettings?.binaryPath || "codex",
[
"exec",
"--ephemeral",
@@ -165,6 +172,7 @@ const makeCodexTextGeneration = Effect.gen(function* () {
"-",
],
{
env: codexSettings?.homePath ? { CODEX_HOME: codexSettings.homePath } : {},
cwd,
shell: process.platform === "win32",
stdin: {
+2
View File
@@ -28,6 +28,7 @@ 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;
@@ -297,6 +298,7 @@ const LayerLive = (input: CliInput) =>
Layer.provideMerge(SqlitePersistence.layerConfig),
Layer.provideMerge(ServerLoggerLive),
Layer.provideMerge(AnalyticsServiceLayerLive),
Layer.provideMerge(ServerSettingsLive),
Layer.provideMerge(ServerConfigLive(input)),
);
@@ -17,7 +17,6 @@ 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";
@@ -35,6 +34,7 @@ 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(ServerSettingsLive),
Layer.provideMerge(ServerSettingsService.layerTest()),
Layer.provideMerge(ServerConfig.layerTest(process.cwd(), baseDir)),
Layer.provideMerge(NodeServices.layer),
);
@@ -1,7 +1,6 @@
import {
type ChatAttachment,
CommandId,
DEFAULT_GIT_TEXT_GENERATION_MODEL_BY_PROVIDER,
EventId,
type ModelSelection,
type OrchestrationEvent,
@@ -362,9 +361,11 @@ 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);
}
@@ -433,10 +434,10 @@ const make = Effect.gen(function* () {
cwd,
message: input.messageText,
...(attachments.length > 0 ? { attachments } : {}),
modelSelection: {
provider: "codex",
model: DEFAULT_GIT_TEXT_GENERATION_MODEL_BY_PROVIDER.codex,
},
modelSelection: yield* Effect.map(
serverSettingsService.getSettings,
(settings) => settings.textGenerationModelSelection,
),
})
.pipe(
Effect.catch((error) =>
@@ -680,9 +681,11 @@ 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 serverSettings = yield* serverSettingsService.getSettings;
const assistantDeliveryMode: AssistantDeliveryMode = serverSettings.enableAssistantStreaming
? "streaming"
: "buffered";
const assistantDeliveryMode: AssistantDeliveryMode = yield* Effect.map(
serverSettingsService.getSettings,
(settings) => (settings.enableAssistantStreaming ? "streaming" : "buffered"),
);
if (assistantDeliveryMode === "buffered") {
const spillChunk = yield* appendBufferedAssistantText(assistantMessageId, assistantDelta);
if (spillChunk.length > 0) {
@@ -188,6 +188,7 @@ 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,7 +27,6 @@ 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";
@@ -109,13 +108,11 @@ 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),
@@ -140,6 +137,5 @@ export function makeServerRuntimeServicesLayer() {
gitManagerLayer,
terminalLayer,
KeybindingsLive,
ServerSettingsLive,
).pipe(Layer.provideMerge(NodeServices.layer));
}
+15 -6
View File
@@ -70,7 +70,16 @@ export interface ServerSettingsShape {
export class ServerSettingsService extends ServiceMap.Service<
ServerSettingsService,
ServerSettingsShape
>()("t3/serverSettings/ServerSettingsService") {}
>()("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);
}
/**
* Derive `ProviderStartOptions` from server settings.
@@ -80,18 +89,18 @@ export function deriveProviderStartOptions(
settings: ServerSettings,
): ProviderStartOptions | undefined {
const providerOptions: ProviderStartOptions = {
...(settings.codexBinaryPath || settings.codexHomePath
...(settings.codex
? {
codex: {
...(settings.codexBinaryPath ? { binaryPath: settings.codexBinaryPath } : {}),
...(settings.codexHomePath ? { homePath: settings.codexHomePath } : {}),
...(settings.codex.binaryPath ? { binaryPath: settings.codex.binaryPath } : {}),
...(settings.codex.homePath ? { homePath: settings.codex.homePath } : {}),
},
}
: {}),
...(settings.claudeBinaryPath
...(settings.claude?.binaryPath
? {
claudeAgent: {
binaryPath: settings.claudeBinaryPath,
binaryPath: settings.claude.binaryPath,
},
}
: {}),
+2
View File
@@ -53,6 +53,7 @@ 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);
@@ -545,6 +546,7 @@ 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),
+2 -3
View File
@@ -118,9 +118,8 @@ function createBaseServerConfig(): ServerConfig {
],
availableEditors: [],
settings: {
claudeBinaryPath: "",
codexBinaryPath: "",
codexHomePath: "",
claude: { binaryPath: "" },
codex: { binaryPath: "", homePath: "" },
enableAssistantStreaming: false,
defaultThreadEnvMode: "local" as const,
customCodexModels: [],
+1
View File
@@ -2972,6 +2972,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
selectedProvider,
setComposerDraftInteractionMode,
setThreadError,
settings.enableAssistantStreaming,
selectedModel,
],
);
@@ -54,9 +54,8 @@ function createBaseServerConfig(): ServerConfig {
],
availableEditors: [],
settings: {
claudeBinaryPath: "",
codexBinaryPath: "",
codexHomePath: "",
claude: { binaryPath: "" },
codex: { binaryPath: "", homePath: "" },
enableAssistantStreaming: false,
defaultThreadEnvMode: "local" as const,
customCodexModels: [],
+27
View File
@@ -159,6 +159,33 @@ export function migrateLocalSettingsToServer(): void {
}
}
// Migrate old flat binary-path keys into their new nested shape
const codexBinaryPath = old["codexBinaryPath"];
const codexHomePath = old["codexHomePath"];
const claudeBinaryPath = old["claudeBinaryPath"];
if (
(typeof codexBinaryPath === "string" && codexBinaryPath) ||
(typeof codexHomePath === "string" && codexHomePath)
) {
const existing = (serverPatch["codex"] as Record<string, unknown> | undefined) ?? {};
serverPatch["codex"] = {
...existing,
...(typeof codexBinaryPath === "string" && codexBinaryPath
? { binaryPath: codexBinaryPath }
: {}),
...(typeof codexHomePath === "string" && codexHomePath ? { homePath: codexHomePath } : {}),
};
}
if (typeof claudeBinaryPath === "string" && claudeBinaryPath) {
const existing = (serverPatch["claude"] as Record<string, unknown> | undefined) ?? {};
serverPatch["claude"] = {
...existing,
binaryPath: claudeBinaryPath,
};
}
if (Object.keys(serverPatch).length > 0) {
void ensureNativeApi()
.server.updateSettings(serverPatch as ServerSettingsPatch)
+34 -19
View File
@@ -195,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.codexBinaryPath || settings.codexHomePath),
claudeAgent: Boolean(settings.claudeBinaryPath),
codex: Boolean(settings.codex?.binaryPath || settings.codex?.homePath),
claudeAgent: Boolean(settings.claude?.binaryPath),
});
const [selectedCustomModelProvider, setSelectedCustomModelProvider] =
useState<ProviderKind>("codex");
@@ -211,9 +211,9 @@ function SettingsRouteView() {
>({});
const [showAllCustomModels, setShowAllCustomModels] = useState(false);
const codexBinaryPath = settings.codexBinaryPath;
const codexHomePath = settings.codexHomePath;
const claudeBinaryPath = settings.claudeBinaryPath;
const codexBinaryPath = settings.codex?.binaryPath ?? "";
const codexHomePath = settings.codex?.homePath ?? "";
const claudeBinaryPath = settings.claude?.binaryPath ?? "";
const keybindingsConfigPath = serverConfigQuery.data?.keybindingsConfigPath ?? null;
const availableEditors = serverConfigQuery.data?.availableEditors;
@@ -244,9 +244,9 @@ function SettingsRouteView() {
? savedCustomModelRows
: savedCustomModelRows.slice(0, 5);
const isInstallSettingsDirty =
settings.claudeBinaryPath !== defaults.claudeBinaryPath ||
settings.codexBinaryPath !== defaults.codexBinaryPath ||
settings.codexHomePath !== defaults.codexHomePath;
settings.claude?.binaryPath !== defaults.claude?.binaryPath ||
settings.codex?.binaryPath !== defaults.codex?.binaryPath ||
settings.codex?.homePath !== defaults.codex?.homePath;
const changedSettingLabels = [
...(theme !== "system" ? ["Theme"] : []),
...(settings.timestampFormat !== defaults.timestampFormat ? ["Time format"] : []),
@@ -831,9 +831,11 @@ function SettingsRouteView() {
label="provider installs"
onClick={() => {
updateSettings({
claudeBinaryPath: defaults.claudeBinaryPath,
codexBinaryPath: defaults.codexBinaryPath,
codexHomePath: defaults.codexHomePath,
claude: { binaryPath: defaults.claude?.binaryPath ?? "" },
codex: {
binaryPath: defaults.codex?.binaryPath ?? "",
homePath: defaults.codex?.homePath ?? "",
},
});
setOpenInstallProviders({
codex: false,
@@ -850,12 +852,12 @@ function SettingsRouteView() {
const isOpen = openInstallProviders[providerSettings.provider];
const isDirty =
providerSettings.provider === "codex"
? settings.codexBinaryPath !== defaults.codexBinaryPath ||
settings.codexHomePath !== defaults.codexHomePath
: settings.claudeBinaryPath !== defaults.claudeBinaryPath;
? settings.codex?.binaryPath !== defaults.codex?.binaryPath ||
settings.codex?.homePath !== defaults.codex?.homePath
: settings.claude?.binaryPath !== defaults.claude?.binaryPath;
const binaryPathValue =
providerSettings.binaryPathKey === "claudeBinaryPath"
? claudeBinaryPath
? (settings.claude?.binaryPath ?? "")
: codexBinaryPath;
return (
@@ -910,9 +912,19 @@ function SettingsRouteView() {
value={binaryPathValue}
onChange={(event) =>
updateSettings(
providerSettings.binaryPathKey === "claudeBinaryPath"
? { claudeBinaryPath: event.target.value }
: { codexBinaryPath: event.target.value },
providerSettings.provider === "claudeAgent"
? {
claude: {
...settings.claude,
binaryPath: event.target.value,
},
}
: {
codex: {
...settings.codex,
binaryPath: event.target.value,
},
},
)
}
placeholder={providerSettings.binaryPlaceholder}
@@ -937,7 +949,10 @@ function SettingsRouteView() {
value={codexHomePath}
onChange={(event) =>
updateSettings({
codexHomePath: event.target.value,
codex: {
...settings.codex,
homePath: event.target.value,
},
})
}
placeholder={providerSettings.homePlaceholder}
+14 -3
View File
@@ -10,10 +10,21 @@ 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(() => "")),
});
export type CodexSettings = typeof CodexSettings.Type;
export const ClaudeSettings = Schema.Struct({
binaryPath: 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(() => "")),
codex: CodexSettings.pipe(Schema.withDecodingDefault(() => ({}))),
claude: ClaudeSettings.pipe(Schema.withDecodingDefault(() => ({}))),
enableAssistantStreaming: Schema.Boolean.pipe(Schema.withDecodingDefault(() => false)),
defaultThreadEnvMode: ThreadEnvMode.pipe(
Schema.withDecodingDefault(() => "local" as const satisfies ThreadEnvMode),