Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8c9d71187 |
No files matched your search
@@ -90,7 +90,7 @@ const makeClaudeTextGeneration = Effect.gen(function* () {
|
||||
|
||||
const claudeSettings = yield* Effect.map(
|
||||
serverSettingsService.getSettings,
|
||||
(settings) => settings.providers.claudeAgent,
|
||||
(settings) => settings.claude,
|
||||
).pipe(Effect.catch(() => Effect.undefined));
|
||||
|
||||
const runClaudeCommand = Effect.gen(function* () {
|
||||
|
||||
@@ -142,7 +142,7 @@ const makeCodexTextGeneration = Effect.gen(function* () {
|
||||
|
||||
const codexSettings = yield* Effect.map(
|
||||
serverSettingsService.getSettings,
|
||||
(settings) => settings.providers.codex,
|
||||
(settings) => settings.codex,
|
||||
).pipe(Effect.catch(() => Effect.undefined));
|
||||
|
||||
const runCodexCommand = Effect.gen(function* () {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -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* () {
|
||||
|
||||
@@ -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",
|
||||
@@ -91,22 +89,18 @@ export function deriveProviderStartOptions(
|
||||
settings: ServerSettings,
|
||||
): ProviderStartOptions | undefined {
|
||||
const providerOptions: ProviderStartOptions = {
|
||||
...(settings.providers.codex
|
||||
...(settings.codex
|
||||
? {
|
||||
codex: {
|
||||
...(settings.providers.codex.binaryPath
|
||||
? { binaryPath: settings.providers.codex.binaryPath }
|
||||
: {}),
|
||||
...(settings.providers.codex.homePath
|
||||
? { homePath: settings.providers.codex.homePath }
|
||||
: {}),
|
||||
...(settings.codex.binaryPath ? { binaryPath: settings.codex.binaryPath } : {}),
|
||||
...(settings.codex.homePath ? { homePath: settings.codex.homePath } : {}),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...(settings.providers.claudeAgent
|
||||
...(settings.claude?.binaryPath
|
||||
? {
|
||||
claudeAgent: {
|
||||
binaryPath: settings.providers.claudeAgent.binaryPath,
|
||||
binaryPath: settings.claude.binaryPath,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
@@ -115,7 +109,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 +225,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* () {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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,
|
||||
|
||||
@@ -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,13 @@ function createBaseServerConfig(): ServerConfig {
|
||||
],
|
||||
availableEditors: [],
|
||||
settings: {
|
||||
...DEFAULT_SERVER_SETTINGS,
|
||||
...DEFAULT_CLIENT_SETTINGS,
|
||||
claude: { binaryPath: "" },
|
||||
codex: { binaryPath: "", homePath: "" },
|
||||
enableAssistantStreaming: false,
|
||||
defaultThreadEnvMode: "local" as const,
|
||||
customCodexModels: [],
|
||||
customClaudeModels: [],
|
||||
textGenerationModelSelection: { provider: "codex" as const, model: "gpt-5.4-mini" },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
() =>
|
||||
@@ -2967,6 +2972,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
selectedProvider,
|
||||
setComposerDraftInteractionMode,
|
||||
setThreadError,
|
||||
settings.enableAssistantStreaming,
|
||||
selectedModel,
|
||||
],
|
||||
);
|
||||
@@ -3094,7 +3100,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 +3115,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,13 @@ function createBaseServerConfig(): ServerConfig {
|
||||
],
|
||||
availableEditors: [],
|
||||
settings: {
|
||||
claude: { binaryPath: "" },
|
||||
codex: { binaryPath: "", homePath: "" },
|
||||
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) => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"));
|
||||
});
|
||||
|
||||
@@ -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 } : {}),
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
@@ -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 } : {}),
|
||||
};
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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.codex?.binaryPath || settings.codex?.homePath),
|
||||
claudeAgent: Boolean(settings.claude?.binaryPath),
|
||||
});
|
||||
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.codex?.binaryPath ?? "";
|
||||
const codexHomePath = settings.codex?.homePath ?? "";
|
||||
const claudeBinaryPath = settings.claude?.binaryPath ?? "";
|
||||
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.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"] : []),
|
||||
@@ -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,17 +831,10 @@ 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,
|
||||
},
|
||||
claude: { binaryPath: defaults.claude?.binaryPath ?? "" },
|
||||
codex: {
|
||||
binaryPath: defaults.codex?.binaryPath ?? "",
|
||||
homePath: defaults.codex?.homePath ?? "",
|
||||
},
|
||||
});
|
||||
setOpenInstallProviders({
|
||||
@@ -874,15 +852,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.codex?.binaryPath !== defaults.codex?.binaryPath ||
|
||||
settings.codex?.homePath !== defaults.codex?.homePath
|
||||
: settings.claude?.binaryPath !== defaults.claude?.binaryPath;
|
||||
const binaryPathValue =
|
||||
providerSettings.provider === "claudeAgent"
|
||||
? settings.providers.claudeAgent.binaryPath
|
||||
: settings.providers.codex.binaryPath;
|
||||
providerSettings.binaryPathKey === "claudeBinaryPath"
|
||||
? (settings.claude?.binaryPath ?? "")
|
||||
: codexBinaryPath;
|
||||
|
||||
return (
|
||||
<Collapsible
|
||||
@@ -924,26 +900,32 @@ 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.provider === "claudeAgent"
|
||||
? {
|
||||
claude: {
|
||||
...settings.claude,
|
||||
binaryPath: event.target.value,
|
||||
},
|
||||
}
|
||||
: {
|
||||
codex: {
|
||||
...settings.codex,
|
||||
binaryPath: event.target.value,
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
placeholder={providerSettings.binaryPlaceholder}
|
||||
spellCheck={false}
|
||||
@@ -967,12 +949,9 @@ function SettingsRouteView() {
|
||||
value={codexHomePath}
|
||||
onChange={(event) =>
|
||||
updateSettings({
|
||||
providers: {
|
||||
...settings.providers,
|
||||
codex: {
|
||||
...settings.providers.codex,
|
||||
homePath: event.target.value,
|
||||
},
|
||||
codex: {
|
||||
...settings.codex,
|
||||
homePath: event.target.value,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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 },
|
||||
);
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -13,33 +13,30 @@ 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({
|
||||
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),
|
||||
),
|
||||
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,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));
|
||||
Reference in new issue
Block a user