Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f74ee02af1 |
No files matched your search
@@ -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",
|
||||
@@ -115,7 +113,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 +229,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* () {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -2967,6 +2967,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
selectedProvider,
|
||||
setComposerDraftInteractionMode,
|
||||
setThreadError,
|
||||
settings.enableAssistantStreaming,
|
||||
selectedModel,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -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 }));
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
@@ -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({
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ export const ServerSettings = Schema.Struct({
|
||||
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