diff --git a/apps/server/src/review/ReviewService.test.ts b/apps/server/src/review/ReviewService.test.ts index b4dc68d229..aae041b7ee 100644 --- a/apps/server/src/review/ReviewService.test.ts +++ b/apps/server/src/review/ReviewService.test.ts @@ -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 = []; + const thread = makeThread({}); + const clientModel = { + instanceId: "claudeAgent", + model: "claude-opus-5", + options: [], + } as unknown as NonNullable; + + 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 = []; + 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; diff --git a/apps/server/src/review/ReviewService.ts b/apps/server/src/review/ReviewService.ts index 0b3880b7af..5b7a557b1a 100644 --- a/apps/server/src/review/ReviewService.ts +++ b/apps/server/src/review/ReviewService.ts @@ -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". diff --git a/apps/web/src/components/reviewSweep/ReviewSweepView.tsx b/apps/web/src/components/reviewSweep/ReviewSweepView.tsx index f3fc595637..da36508066 100644 --- a/apps/web/src/components/reviewSweep/ReviewSweepView.tsx +++ b/apps/web/src/components/reviewSweep/ReviewSweepView.tsx @@ -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)` : ""} - {modelsByEnvironment.map((entry) => ( -
- {entry.label}: {entry.model} ยท {entry.threads}{" "} - {entry.threads === 1 ? "thread" : "threads"} + {modelsByEnvironment.length > 1 ? ( +
+ Across{" "} + {modelsByEnvironment.map((entry, index) => ( + + {index > 0 ? ", " : ""} + {entry.label} ({entry.threads}) + + ))}
- ))} + ) : null} +
+ Review with + {activeInstanceId !== null ? ( + { + setSweepModelSelection(createModelSelection(instanceId, model)); + }} + /> + ) : ( + server default + )} +
{reviewedCount >= SWEEP_COST_NOTE_THRESHOLD ? (
Heads up: {reviewedCount} model calls may take a few minutes and use noticeable credits. - You can change the model under Settings โ†’ Models.
- ) : ( -
Model is configurable under Settings โ†’ Models (text generation).
- )} + ) : null}