Review with the user's last-used model, pickable in the modal
The server's textGenerationModelSelection is tuned for commit messages and PR bodies — the wrong default for reasoning over a thread. The sweep now sends an explicit modelSelection, defaulting to the composer picker's sticky (last-used) model, and the launch modal embeds the same ProviderModelPicker so it can be changed per run. The server falls back to its text-gen setting only when a client sends no selection. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
900a40ecd4
commit
a8c3047710
5 files changed
+154
-12
No files matched your search
@@ -644,6 +644,51 @@ describe("ReviewService", () => {
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
it.effect("summarizeThread uses the client's model selection when provided", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const workspaceRoot = yield* fs.makeTempDirectoryScoped({ prefix: "t3-review-workspace-" });
|
||||
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-review-base-" });
|
||||
const reviewCalls: Array<TextGeneration.ThreadReviewGenerationInput> = [];
|
||||
const thread = makeThread({});
|
||||
const clientModel = {
|
||||
instanceId: "claudeAgent",
|
||||
model: "claude-opus-5",
|
||||
options: [],
|
||||
} as unknown as NonNullable<TextGeneration.ThreadReviewGenerationInput["modelSelection"]>;
|
||||
|
||||
yield* Effect.gen(function* () {
|
||||
const review = yield* ReviewService.ReviewService;
|
||||
return yield* review.summarizeThread({
|
||||
threadId: thread.id,
|
||||
canSettleNow: true,
|
||||
modelSelection: clientModel,
|
||||
});
|
||||
}).pipe(Effect.provide(makeLayer({ workspaceRoot, baseDir, thread, reviewCalls })));
|
||||
|
||||
assert.strictEqual(reviewCalls[0]?.modelSelection.model, "claude-opus-5");
|
||||
assert.strictEqual(reviewCalls[0]?.modelSelection.instanceId, "claudeAgent");
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
it.effect("summarizeThread falls back to the server text-gen model", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const workspaceRoot = yield* fs.makeTempDirectoryScoped({ prefix: "t3-review-workspace-" });
|
||||
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-review-base-" });
|
||||
const reviewCalls: Array<TextGeneration.ThreadReviewGenerationInput> = [];
|
||||
const thread = makeThread({});
|
||||
|
||||
yield* Effect.gen(function* () {
|
||||
const review = yield* ReviewService.ReviewService;
|
||||
return yield* review.summarizeThread({ threadId: thread.id, canSettleNow: true });
|
||||
}).pipe(Effect.provide(makeLayer({ workspaceRoot, baseDir, thread, reviewCalls })));
|
||||
|
||||
// No client model → whatever the server settings carry.
|
||||
assert.ok((reviewCalls[0]?.modelSelection.model.length ?? 0) > 0);
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
it.effect("summarizeThread treats a queued turn start as active", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
|
||||
@@ -368,7 +368,10 @@ export const make = Effect.gen(function* () {
|
||||
const canSettleNow = input.canSettleNow && !serverSideActive;
|
||||
const isActive = !canSettleNow;
|
||||
|
||||
const { textGenerationModelSelection: modelSelection } = yield* serverSettings.getSettings.pipe(
|
||||
// The client picks the model (defaulting to the user's last-used model
|
||||
// from the composer picker); the server's text-generation setting is
|
||||
// only the fallback for older clients that don't send one.
|
||||
const settings = yield* serverSettings.getSettings.pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new TextGenerationError({
|
||||
@@ -378,6 +381,7 @@ export const make = Effect.gen(function* () {
|
||||
}),
|
||||
),
|
||||
);
|
||||
const modelSelection = input.modelSelection ?? settings.textGenerationModelSelection;
|
||||
|
||||
// Deeper investigation: live PR state + recent comments, when the
|
||||
// thread has a branch. Failures degrade to "no PR context".
|
||||
|
||||
@@ -3,7 +3,9 @@ import {
|
||||
scopedThreadKey,
|
||||
scopeProjectRef,
|
||||
} from "@t3tools/client-runtime/environment";
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { hasQueuedTurnStart } from "@t3tools/client-runtime/state/thread-settled";
|
||||
import { createModelSelection } from "@t3tools/shared/model";
|
||||
import { Link } from "@tanstack/react-router";
|
||||
import {
|
||||
ArchiveIcon,
|
||||
@@ -21,7 +23,15 @@ import { useMemo, useState } from "react";
|
||||
|
||||
import { cn } from "~/lib/utils";
|
||||
import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
|
||||
import { useClientSettings } from "../../hooks/useSettings";
|
||||
import { useClientSettings, usePrimarySettings } from "../../hooks/useSettings";
|
||||
import { getCustomModelOptionsByInstance } from "../../modelSelection";
|
||||
import {
|
||||
applyProviderInstanceSettings,
|
||||
deriveProviderInstanceEntries,
|
||||
sortProviderInstanceEntries,
|
||||
} from "../../providerInstances";
|
||||
import { primaryServerProvidersAtom } from "../../state/server";
|
||||
import { ProviderModelPicker } from "../chat/ProviderModelPicker";
|
||||
import {
|
||||
applyAllSweepRecommendations,
|
||||
applySweepSettle,
|
||||
@@ -29,7 +39,9 @@ import {
|
||||
dismissSweepItem,
|
||||
isSweepCandidate,
|
||||
mergeSweepItem,
|
||||
readSweepModelSelection,
|
||||
retrySweepItem,
|
||||
setSweepModelSelection,
|
||||
runMergeQueue,
|
||||
sortSweepCandidates,
|
||||
startReviewSweep,
|
||||
@@ -403,6 +415,32 @@ export function SweepPreRunSummary({ onStarted }: { onStarted?: () => void } = {
|
||||
// auto-settle changes which threads count as unsettled.
|
||||
const candidateVersion = useReviewSweepStore((state) => state.candidateVersion);
|
||||
|
||||
// Review model: defaults to the composer's last-used pick, overridable
|
||||
// here. Re-read on candidateVersion so the trigger reflects changes.
|
||||
const serverProviders = useAtomValue(primaryServerProvidersAtom);
|
||||
const settings = usePrimarySettings();
|
||||
const selectedModel = useMemo(
|
||||
() => readSweepModelSelection(),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- module-level source
|
||||
[candidateVersion],
|
||||
);
|
||||
const instanceEntries = useMemo(
|
||||
() =>
|
||||
sortProviderInstanceEntries(
|
||||
applyProviderInstanceSettings(deriveProviderInstanceEntries(serverProviders), settings),
|
||||
),
|
||||
[serverProviders, settings],
|
||||
);
|
||||
const activeInstanceId = selectedModel?.instanceId ?? instanceEntries[0]?.instanceId ?? null;
|
||||
const activeModel = selectedModel?.model ?? instanceEntries[0]?.models[0]?.slug ?? "";
|
||||
const modelOptionsByInstance = useMemo(
|
||||
() =>
|
||||
activeInstanceId === null
|
||||
? new Map()
|
||||
: getCustomModelOptionsByInstance(settings, serverProviders, activeInstanceId, activeModel),
|
||||
[activeInstanceId, activeModel, serverProviders, settings],
|
||||
);
|
||||
|
||||
const { candidateCount, reviewedCount, modelsByEnvironment } = useMemo(() => {
|
||||
const now = sweepNowIso();
|
||||
const candidates = sortSweepCandidates(
|
||||
@@ -471,20 +509,41 @@ export function SweepPreRunSummary({ onStarted }: { onStarted?: () => void } = {
|
||||
? ` (${candidateCount - SWEEP_MAX_THREADS} least-recently-active skipped)`
|
||||
: ""}
|
||||
</div>
|
||||
{modelsByEnvironment.map((entry) => (
|
||||
<div key={entry.environmentId} className="truncate">
|
||||
{entry.label}: <span className="text-foreground">{entry.model}</span> · {entry.threads}{" "}
|
||||
{entry.threads === 1 ? "thread" : "threads"}
|
||||
{modelsByEnvironment.length > 1 ? (
|
||||
<div className="truncate">
|
||||
Across{" "}
|
||||
{modelsByEnvironment.map((entry, index) => (
|
||||
<span key={entry.environmentId}>
|
||||
{index > 0 ? ", " : ""}
|
||||
{entry.label} ({entry.threads})
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
) : null}
|
||||
<div className="flex items-center gap-2 pt-0.5">
|
||||
<span className="shrink-0">Review with</span>
|
||||
{activeInstanceId !== null ? (
|
||||
<ProviderModelPicker
|
||||
activeInstanceId={activeInstanceId}
|
||||
model={activeModel}
|
||||
lockedProvider={null}
|
||||
instanceEntries={instanceEntries}
|
||||
modelOptionsByInstance={modelOptionsByInstance}
|
||||
triggerVariant="outline"
|
||||
triggerClassName="min-w-0 max-w-none shrink-0 text-foreground/90 hover:text-foreground"
|
||||
onInstanceModelChange={(instanceId, model) => {
|
||||
setSweepModelSelection(createModelSelection(instanceId, model));
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<span className="text-foreground">server default</span>
|
||||
)}
|
||||
</div>
|
||||
{reviewedCount >= SWEEP_COST_NOTE_THRESHOLD ? (
|
||||
<div className="text-warning-foreground">
|
||||
Heads up: {reviewedCount} model calls may take a few minutes and use noticeable credits.
|
||||
You can change the model under Settings → Models.
|
||||
</div>
|
||||
) : (
|
||||
<div>Model is configurable under Settings → Models (text generation).</div>
|
||||
)}
|
||||
) : null}
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
DEFAULT_RUNTIME_MODE,
|
||||
type EnvironmentId,
|
||||
type ModelSelection,
|
||||
type ProjectId,
|
||||
type ReviewThreadSummaryResult,
|
||||
type ScopedThreadRef,
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
import { create } from "zustand";
|
||||
|
||||
import { stackedThreadToast, toastManager } from "./components/ui/toast";
|
||||
import { useComposerDraftStore } from "./composerDraftStore";
|
||||
import { getClientSettings } from "./hooks/useSettings";
|
||||
import { newMessageId } from "~/lib/utils";
|
||||
import { appAtomRegistry } from "./rpc/atomRegistry";
|
||||
@@ -51,6 +53,29 @@ export function publishSweepChangeRequestStates(
|
||||
useReviewSweepStore.getState().bumpCandidateVersion();
|
||||
}
|
||||
|
||||
/** Model the next run will use. Defaults to the composer's last-used
|
||||
(sticky) selection so reviews run on the model the user actually picks
|
||||
for work, not the server's commit-message text-gen default. Overridable
|
||||
in the launch modal. */
|
||||
let sweepModelSelection: ModelSelection | null = null;
|
||||
|
||||
export function readSweepModelSelection(): ModelSelection | null {
|
||||
return sweepModelSelection ?? readStickyComposerModelSelection();
|
||||
}
|
||||
|
||||
export function setSweepModelSelection(selection: ModelSelection | null): void {
|
||||
sweepModelSelection = selection;
|
||||
useReviewSweepStore.getState().bumpCandidateVersion();
|
||||
}
|
||||
|
||||
/** The composer picker's last-used model, if any. */
|
||||
function readStickyComposerModelSelection(): ModelSelection | null {
|
||||
const store = useComposerDraftStore.getState();
|
||||
const activeProvider = store.stickyActiveProvider;
|
||||
if (activeProvider === null) return null;
|
||||
return store.stickyModelSelectionByProvider[activeProvider] ?? null;
|
||||
}
|
||||
|
||||
const SWEEP_CONCURRENCY = 3;
|
||||
/** Soft cap so a giant backlog doesn't spawn an unbounded number of LLM
|
||||
generations in one click. */
|
||||
@@ -204,12 +229,17 @@ async function reviewOne(runId: number, item: SweepItem): Promise<void> {
|
||||
|
||||
const shell = readThreadShell(item.ref);
|
||||
const canSettleNow = shell !== null && canSettle(shell, { now: new Date().toISOString() });
|
||||
const modelSelection = readSweepModelSelection();
|
||||
const result = await runAtomCommand(
|
||||
appAtomRegistry,
|
||||
reviewEnvironment.summarizeThread,
|
||||
{
|
||||
environmentId: item.ref.environmentId,
|
||||
input: { threadId: item.ref.threadId, canSettleNow },
|
||||
input: {
|
||||
threadId: item.ref.threadId,
|
||||
canSettleNow,
|
||||
...(modelSelection !== null ? { modelSelection } : {}),
|
||||
},
|
||||
},
|
||||
{ reportFailure: false, reportDefect: false },
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
import { ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
|
||||
import { GitCommandError, TextGenerationError } from "./git.ts";
|
||||
import { ModelSelection } from "./orchestration.ts";
|
||||
import { VcsError } from "./vcs.ts";
|
||||
|
||||
export const ReviewDiffPreviewInput = Schema.Struct({
|
||||
@@ -41,6 +42,9 @@ export const ReviewThreadSummaryInput = Schema.Struct({
|
||||
pending approvals, or pending user input). The server never recommends
|
||||
settling when this is false, regardless of what the model says. */
|
||||
canSettleNow: Schema.Boolean,
|
||||
/** Model to run the review with. Defaults to the server's
|
||||
textGenerationModelSelection when omitted (older clients). */
|
||||
modelSelection: Schema.optionalKey(ModelSelection),
|
||||
});
|
||||
export type ReviewThreadSummaryInput = typeof ReviewThreadSummaryInput.Type;
|
||||
|
||||
|
||||
Reference in new issue
Block a user