diff --git a/packages/types/src/__tests__/experiment.test.ts b/packages/types/src/__tests__/experiment.test.ts new file mode 100644 index 0000000000..0ef4ed2e02 --- /dev/null +++ b/packages/types/src/__tests__/experiment.test.ts @@ -0,0 +1,19 @@ +import { experimentIds, experimentIdsSchema, experimentsSchema } from "../experiment.js" + +describe("dynamicThinkingEffort experiment", () => { + it("is part of the experiment id enum", () => { + expect(experimentIds).toContain("dynamicThinkingEffort") + expect(experimentIdsSchema.safeParse("dynamicThinkingEffort").success).toBe(true) + }) + + it("parses enabled and disabled states", () => { + expect(experimentsSchema.parse({ dynamicThinkingEffort: true })).toEqual({ dynamicThinkingEffort: true }) + expect(experimentsSchema.parse({ dynamicThinkingEffort: false })).toEqual({ dynamicThinkingEffort: false }) + expect(experimentsSchema.parse({})).toEqual({}) + }) + + it("rejects non-boolean values", () => { + expect(experimentsSchema.safeParse({ dynamicThinkingEffort: "yes" }).success).toBe(false) + expect(experimentIdsSchema.safeParse("dynamic-thinking-effort").success).toBe(false) + }) +}) diff --git a/packages/types/src/experiment.ts b/packages/types/src/experiment.ts index 5d511859b1..f4b3a1c0a8 100644 --- a/packages/types/src/experiment.ts +++ b/packages/types/src/experiment.ts @@ -12,6 +12,7 @@ export const experimentIds = [ "runSlashCommand", "customTools", "parallelToolExecution", + "dynamicThinkingEffort", ] as const export const experimentIdsSchema = z.enum(experimentIds) @@ -28,6 +29,7 @@ export const experimentsSchema = z.object({ runSlashCommand: z.boolean().optional(), customTools: z.boolean().optional(), parallelToolExecution: z.boolean().optional(), + dynamicThinkingEffort: z.boolean().optional(), }) export type Experiments = z.infer diff --git a/scripts/stryker-diff.mjs b/scripts/stryker-diff.mjs index dd64f4e774..a6efa72b54 100644 --- a/scripts/stryker-diff.mjs +++ b/scripts/stryker-diff.mjs @@ -57,8 +57,15 @@ export const PACKAGE_CONFIGS = [ root: "src", sourceRoot: "src/", vitestConfig: "vitest.config.ts", - vitestRelated: false, - discoverRelatedTests: true, + + // Use plugin-side related-test discovery: with an explicit STRYKER_TEST_FILES + // list, stryker-js 10.0.0 plans static mutants with runtime activation + // (stryker-mutator/stryker-js#6144, #6209), which the vitest plugin can only + // apply after top-level code has run, producing false Survived results. + // Revert to vitestRelated: false / discoverRelatedTests: true once the + // upstream planner fix lands. + vitestRelated: true, + discoverRelatedTests: false, // CI build/coverage tooling under src/scripts is excluded like the other build scripts: // it is not shipped runtime code and is covered by src/scripts/__tests__/merge-lcov.spec.mjs. excludedPaths: [ diff --git a/scripts/stryker-diff.test.mjs b/scripts/stryker-diff.test.mjs index 22284e598d..ef1a55509d 100644 --- a/scripts/stryker-diff.test.mjs +++ b/scripts/stryker-diff.test.mjs @@ -254,8 +254,12 @@ describe("buildManifest", () => { assert.equal(webview.runRoot, ".") assert.equal(webview.discoverRelatedTests, true) assert.equal(webview.vitestRelated, false) - assert.equal(extension.discoverRelatedTests, true) - assert.equal(extension.vitestRelated, false) + + // The extension entry uses plugin-side related discovery while stryker-js 10.0.0 + // plans static mutants with runtime activation when given explicit test files + // (stryker-mutator/stryker-js#6144, #6209); see the entry comment in stryker-diff.mjs. + assert.equal(extension.discoverRelatedTests, false) + assert.equal(extension.vitestRelated, true) const types = manifest.packages.find(({ id }) => id === "types") assert.equal(types.discoverRelatedTests, undefined) assert.equal(types.vitestRelated, undefined) diff --git a/src/api/index.ts b/src/api/index.ts index d61eea033f..197080e131 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -7,6 +7,7 @@ import { retiredProviderIdentifiers, type ProviderSettings, type ModelInfo, + type ReasoningEffortExtended, type ModelRecord, } from "@roo-code/types" @@ -119,6 +120,14 @@ export interface ApiHandlerCreateMessageMetadata { * when the user clicks stop, preventing wasted API tokens/compute on the provider side. */ abortSignal?: AbortSignal + /** + * Per-request thinking effort override (DTE series 2/5). + * When defined, takes precedence over the settings-derived `reasoningEffort` + * wherever the effective effort is resolved (see `resolveEffectiveReasoningEffort`). + * Task-scoped and transient: it applies to this request only (the next request + * after being set — no mid-stream effect) and is never persisted to settings. + */ + reasoningEffort?: ReasoningEffortExtended } /** diff --git a/src/api/transform/__tests__/dte-effective-reasoning-effort.spec.ts b/src/api/transform/__tests__/dte-effective-reasoning-effort.spec.ts new file mode 100644 index 0000000000..f126cae97c --- /dev/null +++ b/src/api/transform/__tests__/dte-effective-reasoning-effort.spec.ts @@ -0,0 +1,58 @@ +// npx vitest run src/api/transform/__tests__/dte-effective-reasoning-effort.spec.ts + +import { ADAPTIVE_OUTPUT_CONFIG_EFFORTS, resolveEffectiveReasoningEffort } from "../reasoning" + +describe("DTE series 2/5 — resolveEffectiveReasoningEffort", () => { + const settingsEffort = "high" + const modelDefault = "medium" + + it("returns the per-request override when present (strongest precedence)", () => { + expect( + resolveEffectiveReasoningEffort({ + override: "xhigh", + settingsReasoningEffort: settingsEffort, + modelDefaultEffort: modelDefault, + }), + ).toBe("xhigh") + }) + + it("lets the override win even when it is out-of-range for the adaptive envelope", () => { + // "minimal" is a valid override value but outside the adaptive envelope set; + // resolution still returns it — envelope gating is the caller's concern. + expect( + resolveEffectiveReasoningEffort({ + override: "minimal", + settingsReasoningEffort: settingsEffort, + modelDefaultEffort: modelDefault, + }), + ).toBe("minimal") + }) + + it("falls back to the settings value when no override is present", () => { + expect( + resolveEffectiveReasoningEffort({ settingsReasoningEffort: "low", modelDefaultEffort: modelDefault }), + ).toBe("low") + }) + + it("preserves the settings 'disable' sentinel when no override is present", () => { + expect( + resolveEffectiveReasoningEffort({ settingsReasoningEffort: "disable", modelDefaultEffort: modelDefault }), + ).toBe("disable") + }) + + it("an explicit override wins over a settings 'disable' sentinel", () => { + expect(resolveEffectiveReasoningEffort({ override: "low", settingsReasoningEffort: "disable" })).toBe("low") + }) + + it("falls back to the model default when neither override nor settings is set", () => { + expect(resolveEffectiveReasoningEffort({ modelDefaultEffort: "low" })).toBe("low") + }) + + it("returns undefined when nothing is set", () => { + expect(resolveEffectiveReasoningEffort({})).toBeUndefined() + }) + + it("exposes exactly the in-range adaptive envelope efforts", () => { + expect([...ADAPTIVE_OUTPUT_CONFIG_EFFORTS]).toEqual(["low", "medium", "high", "xhigh", "max"]) + }) +}) diff --git a/src/api/transform/reasoning.ts b/src/api/transform/reasoning.ts index 3d3c68c03a..e1bb697aa5 100644 --- a/src/api/transform/reasoning.ts +++ b/src/api/transform/reasoning.ts @@ -33,6 +33,53 @@ export type AnthropicProviderReasoningParams = export type OpenAiReasoningParams = { reasoning_effort: OpenAI.Chat.ChatCompletionCreateParams["reasoning_effort"] } +/** + * DTE series 2/5 — effort levels accepted by the Claude 4.7+ adaptive-thinking + * `output_config.effort` envelope. Efforts outside this set (e.g. "none", + * "minimal", "disable") omit the envelope so the API applies its own default. + * @internal Exported for focused implementation tests. + */ +export const ADAPTIVE_OUTPUT_CONFIG_EFFORTS: readonly ReasoningEffortExtended[] = [ + "low", + "medium", + "high", + "xhigh", + "max", +] + +/** + * DTE series 2/5 — resolves the effective thinking effort for a single request. + * + * Resolution order (strongest first): + * 1. `override` — the per-request task-local effort + * (`ApiHandlerCreateMessageMetadata.reasoningEffort`), + * 2. `settingsReasoningEffort` — the settings-derived value, + * 3. `modelDefaultEffort` — the model's default effort. + * + * This is the single shared resolution point for the per-request override: + * providers that resolve the effective effort through it inherit the override + * without duplicating precedence logic. The override is transient (next request + * only) and never persisted to settings. + * @internal Exported for focused implementation tests. + */ +export const resolveEffectiveReasoningEffort = ({ + override, + settingsReasoningEffort, + modelDefaultEffort, +}: { + override?: ReasoningEffortExtended + settingsReasoningEffort?: ReasoningEffortExtended | "disable" + modelDefaultEffort?: ReasoningEffortExtended +}): ReasoningEffortExtended | "disable" | undefined => { + if (override !== undefined) { + return override + } + if (settingsReasoningEffort !== undefined) { + return settingsReasoningEffort + } + return modelDefaultEffort +} + // Valid Gemini thinking levels for effort-based reasoning const GEMINI_THINKING_LEVELS = ["minimal", "low", "medium", "high"] as const diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index dc7880644c..e564e780c8 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -21,6 +21,7 @@ import { type TaskMetadata, type TaskEvents, type ProviderSettings, + type ReasoningEffortExtended, type TokenUsage, type ToolUsage, type ToolName, @@ -417,6 +418,10 @@ export class Task extends EventEmitter implements TaskLike { // API apiConfiguration: ProviderSettings api: ApiHandler + // DTE series 2/5: task-local thinking effort override. Transient per-task state — + // never persisted to settings; cleared on dispose (see dispose()). + private runtimeThinkingEffort?: ReasoningEffortExtended + private runtimeThinkingEffortSource?: string /** * Units of in-flight API work: a request from setup through its retries and * background usage drain, or a manual condense. Work can hold any handler it @@ -2478,6 +2483,12 @@ export class Task extends EventEmitter implements TaskLike { * Updates the API configuration and rebuilds the API handler. * There is no tool-protocol switching or tool parser swapping. * + * DTE series 2/5: when a task-local thinking effort override is active + * (`setRuntimeThinkingEffort`), the incoming configuration's `reasoningEffort` + * becomes the new restore value and the override is re-applied on top of the + * fresh in-memory copy — clearing the override later restores the NEW profile's + * value, not a stale one. + * * @param newApiConfiguration - The new API configuration to use */ public updateApiConfiguration(newApiConfiguration: ProviderSettings): void { @@ -2485,9 +2496,17 @@ export class Task extends EventEmitter implements TaskLike { // VS Code LM / GitHub Copilot own host listeners, so the old one is // released — immediately when idle, or when the last request, retry, // background drain, or condense that leased it settles. + // DTE series 2/5: apiConfiguration stays the profile-derived projection; + // an active task-local override is applied to the rebuilt handler only, so + // a profile switch keeps the override live and clearing it later restores + // the NEW profile's value (it is the configuration itself now). const previousApi = this.api this.apiConfiguration = newApiConfiguration - this.api = buildApiHandler(this.apiConfiguration) + this.api = buildApiHandler( + this.runtimeThinkingEffort !== undefined + ? { ...newApiConfiguration, reasoningEffort: this.runtimeThinkingEffort } + : newApiConfiguration, + ) this.retireApi(previousApi) // Refresh only the soft tool-repetition limit from the new profile so an @@ -2504,6 +2523,64 @@ export class Task extends EventEmitter implements TaskLike { this.toolRepetitionDetector.updateLimits(this.toolRepetitionSoftLimit, this.consecutiveMistakeLimit) } + /** + * DTE series 2/5: sets — or clears with `undefined` — the task-local thinking + * effort override. + * + * Resolution order for the affected requests (strongest first): this + * task-local override → settings `reasoningEffort` → model default. The + * override applies to the NEXT API request only (no mid-stream effect): it + * is passed per request as `metadata.reasoningEffort` and applied to the + * rebuilt API handler. `apiConfiguration` itself stays the profile-derived + * projection — the override never enters it — so the webview state (which + * posts the active task's `apiConfiguration`) and any profile save built + * from it can never carry the task-local effort. `undefined` clears the + * override and rebuilds the handler from the projection. + * + * @param effort - The task-local effort, or `undefined` to clear. + * @param source - Optional provenance label (UI wiring lands in a later PR). + */ + public setRuntimeThinkingEffort(effort: ReasoningEffortExtended | undefined, source?: string): void { + const wasActive = this.runtimeThinkingEffort !== undefined + this.runtimeThinkingEffort = effort + this.runtimeThinkingEffortSource = effort === undefined ? undefined : source + + if (effort === undefined && !wasActive) { + // Already inactive: nothing to clear. + return + } + + // Rebuild the handler with the effective effort applied. The projection + // (this.apiConfiguration) is untouched, so clearing needs no restore: the + // handler is simply rebuilt from the profile-derived configuration. The + // replaced handler is retired like any other swap: handlers with host + // listeners must not leak when the effort changes. + const previousApi = this.api + this.api = buildApiHandler( + effort !== undefined ? { ...this.apiConfiguration, reasoningEffort: effort } : this.apiConfiguration, + ) + this.retireApi(previousApi) + } + + /** + * DTE series 2/5: reads the current task-local thinking effort override. + */ + public getRuntimeThinkingEffort(): { effort?: ReasoningEffortExtended; source?: string } { + return { + effort: this.runtimeThinkingEffort, + source: this.runtimeThinkingEffortSource, + } + } + + /** + * DTE series 2/5: metadata fragment carrying the active task-local effort + * override on a single request. Empty when no override is active, so the + * existing settings resolution applies unchanged. + */ + private getRuntimeThinkingEffortMetadata(): Pick { + return this.runtimeThinkingEffort !== undefined ? { reasoningEffort: this.runtimeThinkingEffort } : {} + } + /** * Marks the start of in-flight API work. The returned release is idempotent; * the last release disposes every handler replaced while work was running. @@ -2683,6 +2760,8 @@ export class Task extends EventEmitter implements TaskLike { parallelToolCalls: true, } : {}), + // DTE series 2/5: carry the active task-local effort override. + ...this.getRuntimeThinkingEffortMetadata(), } // Generate environment details to include in the condensed summary const environmentDetails = await getEnvironmentDetails(this, true) @@ -3618,6 +3697,10 @@ export class Task extends EventEmitter implements TaskLike { } } + /** + * Centralized task teardown: releases task resources and resets transient + * task-local state. + */ public dispose(): Promise { if (this.disposalPromise) { return this.disposalPromise @@ -3729,6 +3812,16 @@ export class Task extends EventEmitter implements TaskLike { console.error("Error reverting diff changes:", error) } + // Clear the DTE runtime-effort override so a retained disposed task never + // reports a stale override. The fields are cleared directly instead of via + // setRuntimeThinkingEffort: that setter rebuilds the handler, and during + // disposal the rebuild would (a) create a replacement handler this pass has + // already collected and disposed, and (b) retire the just-disposed handler a + // second time. `apiConfiguration` never carries the override (it stays the + // profile-derived projection), so there is nothing to restore. + this.runtimeThinkingEffort = undefined + this.runtimeThinkingEffortSource = undefined + await pendingCleanup await this.diffReversionPromise } @@ -4266,7 +4359,6 @@ export class Task extends EventEmitter implements TaskLike { // under the canonical name slip past a name comparison. The first call wins. const idAlreadyUsed = this.assistantMessageContent.some( (entry) => - // Stryker disable next-line ConditionalExpression: equivalent mutant, only tool_use and mcp_tool_use entries carry an id, so the type check cannot change entry.id === event.id (entry.type === "tool_use" || entry.type === "mcp_tool_use") && (entry as { id?: string }).id === event.id, ) @@ -4319,7 +4411,6 @@ export class Task extends EventEmitter implements TaskLike { // keep the deprecated single-entry-per-ID lookup. let streamingKey: string | undefined - // Stryker disable next-line ConditionalExpression: equivalent mutant, event.name is always a string here, so the legacy nameless branch is unreachable if (event.name !== undefined) { streamingKey = NativeToolCallParser.makeStreamingKey(event.id, event.name) } else { @@ -4336,7 +4427,6 @@ export class Task extends EventEmitter implements TaskLike { } const partialToolUse = - // Stryker disable next-line ConditionalExpression: equivalent mutant, streamingKey is always a string here (makeStreamingKey), so the null side is unreachable streamingKey === undefined ? null : NativeToolCallParser.processStreamingChunk( @@ -4345,7 +4435,6 @@ export class Task extends EventEmitter implements TaskLike { nativeToolCallParserScope, ) - // Stryker disable next-line ConditionalExpression, EqualityOperator: equivalent mutants, streamingKey is always defined here, so both conditions reduce to the partialToolUse check if (partialToolUse && streamingKey !== undefined) { // Reuse the compound key built above: it is exactly the key the start event // registered under, so the delta lookup needs no second encoding. @@ -4742,7 +4831,7 @@ export class Task extends EventEmitter implements TaskLike { if (event.type === "tool_call_end") { // Create compound key for deduplication (same pattern as streaming handler). // End events carry the tool name; fall back to the id for events that don't. - // Stryker disable next-line LogicalOperator: equivalent mutant, finalizeRawChunks emits end events with a string name, so the ?? event.id fallback is unreachable + let eventName = event.name ?? event.id let dedupKey = NativeToolCallParser.makeStreamingKey(event.id, eventName) @@ -4759,13 +4848,12 @@ export class Task extends EventEmitter implements TaskLike { // name (provider quirk), the compound-key lookup above misses and both the // parser entry and the dedup tracking would stay stale. Resolve the tracked // entry by id and target the real compound key for finalization and cleanup. - // Stryker disable next-line ConditionalExpression, LogicalOperator, EqualityOperator: equivalent mutants, the both-miss case is unreachable via the raw-chunk pipeline + if (finalToolUse === null && toolUseIndex === undefined) { const resolved = NativeToolCallParser.getStreamingToolCallById( event.id, nativeToolCallParserScope, ) - // Stryker disable next-line ConditionalExpression: unreachable defensive region — getStreamingToolCallById can only resolve when the both-miss case above is reachable, which the raw-chunk pipeline cannot produce (see the directive there). if (resolved) { eventName = resolved.name dedupKey = NativeToolCallParser.makeStreamingKey(resolved.id, resolved.name) @@ -5459,6 +5547,8 @@ export class Task extends EventEmitter implements TaskLike { parallelToolCalls: true, } : {}), + // DTE series 2/5: carry the active task-local effort override. + ...this.getRuntimeThinkingEffortMetadata(), } try { @@ -5737,6 +5827,8 @@ export class Task extends EventEmitter implements TaskLike { parallelToolCalls: true, } : {}), + // DTE series 2/5: carry the active task-local effort override. + ...this.getRuntimeThinkingEffortMetadata(), } // Only generate environment details when context management will actually run. @@ -5906,6 +5998,8 @@ export class Task extends EventEmitter implements TaskLike { taskId: this.taskId, suppressPreviousResponseId: this.skipPrevResponseIdOnce, abortSignal, + // DTE series 2/5: carry the active task-local effort override for this request. + ...this.getRuntimeThinkingEffortMetadata(), // Include tools whenever they are present. ...(shouldIncludeTools ? { diff --git a/src/core/task/__tests__/Task.runtime-thinking-effort.test.ts b/src/core/task/__tests__/Task.runtime-thinking-effort.test.ts new file mode 100644 index 0000000000..d42586731d --- /dev/null +++ b/src/core/task/__tests__/Task.runtime-thinking-effort.test.ts @@ -0,0 +1,348 @@ +// npx vitest run src/core/task/__tests__/Task.runtime-thinking-effort.test.ts +// +// DTE series 2/5 — task-local thinking effort state on Task: +// setRuntimeThinkingEffort / getRuntimeThinkingEffort, the in-memory +// effective-effort handler rebuild (the profile-derived apiConfiguration +// projection never carries the override). + +import { ProviderSettings, type ReasoningEffortExtended } from "@roo-code/types" +import { providerIdentifiers } from "@roo-code/types/provider-identifiers" + +import { Task } from "../Task" +import { ClineProvider } from "../../webview/ClineProvider" +import { buildApiHandler } from "../../../api" +import { disposeApiHandler } from "../../../api/dispose-api-handler" + +// Mock dependencies (same lightweight set as Task.throttle.test.ts) +vi.mock("../../webview/ClineProvider") +vi.mock("../../../integrations/terminal/TerminalRegistry", () => ({ + TerminalRegistry: { + releaseTerminalsForTask: vi.fn(), + }, +})) +vi.mock("../../ignore/RooIgnoreController") +vi.mock("../../protect/RooProtectedController") +vi.mock("../../context-tracking/FileContextTracker") +vi.mock("../../../integrations/editor/DiffViewProvider") +vi.mock("../../tools/ToolRepetitionDetector") +vi.mock("../../../api/dispose-api-handler", () => ({ disposeApiHandler: vi.fn() })) +vi.mock("../../../api", () => ({ + // Returns a fresh handler object per call so tests can assert on the exact + // configuration each rebuild received (via vi.mocked(buildApiHandler).mock.calls). + buildApiHandler: vi.fn((configuration: { apiModelId?: string }) => ({ + getModel: () => ({ info: {}, id: configuration.apiModelId ?? "test-model" }), + })), +})) + +// Mock TelemetryService +vi.mock("@roo-code/telemetry", () => ({ + TelemetryService: { + instance: { + captureTaskCreated: vi.fn(), + captureTaskRestarted: vi.fn(), + }, + }, +})) + +// Mock task persistence to avoid disk writes +vi.mock("../../task-persistence", async (importOriginal) => ({ + ...(await importOriginal()), + readApiMessages: vi.fn().mockResolvedValue([]), + saveApiMessages: vi.fn().mockResolvedValue(undefined), + readTaskMessages: vi.fn().mockResolvedValue([]), + saveTaskMessages: vi.fn().mockResolvedValue(undefined), + taskMetadata: vi.fn().mockResolvedValue({ + historyItem: { + id: "test-task-id", + number: 1, + task: "Test task", + ts: Date.now(), + totalCost: 0.01, + tokensIn: 100, + tokensOut: 50, + }, + tokenUsage: { + totalTokensIn: 100, + totalTokensOut: 50, + totalCost: 0.01, + contextTokens: 150, + totalCacheWrites: 0, + totalCacheReads: 0, + }, + }), +})) + +// Typed access to the intentionally-private DTE state, mirroring the +// getTaskTestAccess pattern in Task.spec.ts (single double assertion, documented). +type RuntimeThinkingEffortAccess = { + runtimeThinkingEffort?: ReasoningEffortExtended + runtimeThinkingEffortSource?: string + getRuntimeThinkingEffortMetadata: () => { reasoningEffort?: ReasoningEffortExtended } +} + +function getPrivateAccess(task: Task): RuntimeThinkingEffortAccess { + return task as unknown as RuntimeThinkingEffortAccess +} + +const SETTINGS_EFFORT: ReasoningEffortExtended = "low" + +describe("Task runtime thinking effort (DTE series 2/5)", () => { + let mockProvider: Record + let mockApiConfiguration: ProviderSettings + let task: Task + + beforeEach(() => { + vi.clearAllMocks() + vi.useFakeTimers() + + mockProvider = { + context: { + globalStorageUri: { fsPath: "/test/path" }, + }, + getState: vi.fn().mockResolvedValue({ mode: "code" }), + log: vi.fn(), + postStateToWebview: vi.fn().mockResolvedValue(undefined), + postStateToWebviewWithoutTaskHistory: vi.fn().mockResolvedValue(undefined), + postStateToWebviewThrottled: vi.fn().mockResolvedValue(undefined), + flushPostStateToWebviewThrottled: vi.fn().mockResolvedValue(undefined), + updateTaskHistory: vi.fn().mockResolvedValue(undefined), + } + + mockApiConfiguration = { + apiProvider: providerIdentifiers.anthropic, + apiModelId: "claude-opus-4-7", + apiKey: "test-key", + reasoningEffort: SETTINGS_EFFORT, + } as ProviderSettings + + // mockProvider is a minimal structural double (ClineProvider is auto-mocked + // by the vi.mock above); the task only touches the members supplied here. + task = new Task({ + provider: mockProvider as unknown as ClineProvider, + apiConfiguration: mockApiConfiguration, + startTask: false, + }) + }) + + afterEach(async () => { + vi.useRealTimers() + if (task) { + await task.dispose().catch(() => {}) + } + }) + + describe("dispose", () => { + it("clears an active override without rebuilding or double-disposing the handler", async () => { + task.setRuntimeThinkingEffort("xhigh", "test-source") + const access = getPrivateAccess(task) + const handlerBefore = (task as unknown as { api: unknown }).api + const buildsBefore = vi.mocked(buildApiHandler).mock.calls.length + vi.mocked(disposeApiHandler).mockClear() + + await task.dispose() + + expect(access.runtimeThinkingEffort).toBeUndefined() + expect(access.runtimeThinkingEffortSource).toBeUndefined() + // A disposed task never serves another request: disposal must not rebuild + // a replacement handler it would then have to collect and dispose. + expect(vi.mocked(buildApiHandler).mock.calls.length).toBe(buildsBefore) + // The handler the task owned is disposed exactly once, not retired a + // second time by the clearing path. + const disposedHandlers = vi.mocked(disposeApiHandler).mock.calls.map(([api]) => api) + expect(disposedHandlers.filter((api) => api === handlerBefore)).toHaveLength(1) + }) + }) + + describe("setRuntimeThinkingEffort", () => { + it("stores effort + source and rebuilds the handler with the override applied", () => { + task.setRuntimeThinkingEffort("xhigh", "test-source") + + expect(task.getRuntimeThinkingEffort()).toEqual({ effort: "xhigh", source: "test-source" }) + expect(getPrivateAccess(task).runtimeThinkingEffort).toBe("xhigh") + expect(getPrivateAccess(task).runtimeThinkingEffortSource).toBe("test-source") + + // The settings object the provider handed in is never mutated. + expect(mockApiConfiguration).toEqual( + expect.objectContaining({ + reasoningEffort: SETTINGS_EFFORT, + }), + ) + // The handler is rebuilt with the override applied (last build call)... + const lastCall = vi.mocked(buildApiHandler).mock.calls.at(-1) + expect(lastCall?.[0]).toEqual(expect.objectContaining({ reasoningEffort: "xhigh" })) + // ...from a fresh copy, not the settings object itself. + expect(lastCall?.[0]).not.toBe(mockApiConfiguration) + }) + + it("replaces effort + source when re-set while active and restores on clear", () => { + task.setRuntimeThinkingEffort("high", "first") + task.setRuntimeThinkingEffort("medium", "second") + + expect(task.getRuntimeThinkingEffort()).toEqual({ effort: "medium", source: "second" }) + const lastSet = vi.mocked(buildApiHandler).mock.calls.at(-1) + expect(lastSet?.[0]).toEqual(expect.objectContaining({ reasoningEffort: "medium" })) + + // Clearing rebuilds from the profile projection, not the intermediate effort. + task.setRuntimeThinkingEffort(undefined) + const lastClear = vi.mocked(buildApiHandler).mock.calls.at(-1) + expect(lastClear?.[0]).toEqual(expect.objectContaining({ reasoningEffort: SETTINGS_EFFORT })) + }) + + it("restores the settings-derived effort when cleared with undefined", () => { + task.setRuntimeThinkingEffort("max") + const lastSet = vi.mocked(buildApiHandler).mock.calls.at(-1) + expect(lastSet?.[0]).toEqual(expect.objectContaining({ reasoningEffort: "max" })) + + // A label passed on the clearing call must not survive into source. + task.setRuntimeThinkingEffort(undefined, "stale-source") + + expect(task.getRuntimeThinkingEffort()).toEqual({ effort: undefined, source: undefined }) + // The profile effort survives the set/clear cycle with the rest of the + // configuration intact. + expect(task.apiConfiguration).toEqual( + expect.objectContaining({ + apiProvider: providerIdentifiers.anthropic, + apiModelId: "claude-opus-4-7", + apiKey: "test-key", + reasoningEffort: SETTINGS_EFFORT, + }), + ) + // The handler is rebuilt from the projection. + const lastCall = vi.mocked(buildApiHandler).mock.calls.at(-1) + expect(lastCall?.[0]).toEqual(expect.objectContaining({ reasoningEffort: SETTINGS_EFFORT })) + }) + + it("never lets the override enter apiConfiguration (webview projection + profile save contract)", () => { + // ClineProvider.getStateToPostToWebview posts the active task's + // apiConfiguration object to the webview, and SettingsView returns it on + // save (upsertApiConfiguration -> saveConfig). If the override entered the + // projection, any settings save during an active override would persist the + // task-local effort into the selected profile. + task.setRuntimeThinkingEffort("xhigh", "test-ui") + + expect(task.apiConfiguration).toBe(mockApiConfiguration) + expect(task.apiConfiguration.reasoningEffort).toBe(SETTINGS_EFFORT) + + // A profile switch while active keeps the projection profile-pure too. + const newConfig = { + apiProvider: providerIdentifiers.anthropic, + apiModelId: "claude-opus-4-8", + apiKey: "test-key", + reasoningEffort: "medium", + } as ProviderSettings + task.updateApiConfiguration(newConfig) + expect(task.apiConfiguration).toBe(newConfig) + expect(task.apiConfiguration.reasoningEffort).toBe("medium") + + task.setRuntimeThinkingEffort(undefined) + expect(task.apiConfiguration.reasoningEffort).toBe("medium") + }) + + it("is a no-op when cleared while inactive (no handler rebuild)", () => { + const callsBefore = vi.mocked(buildApiHandler).mock.calls.length + + task.setRuntimeThinkingEffort(undefined) + + expect(vi.mocked(buildApiHandler).mock.calls.length).toBe(callsBefore) + expect(task.getRuntimeThinkingEffort()).toEqual({ effort: undefined, source: undefined }) + expect(task.apiConfiguration).toBe(mockApiConfiguration) + }) + + it("never writes to the provider or persisted settings", () => { + task.setRuntimeThinkingEffort("xhigh") + task.setRuntimeThinkingEffort(undefined) + + // Nothing is posted to the webview and the handed-in settings object is intact. + expect(mockProvider.postStateToWebview).not.toHaveBeenCalled() + expect(mockApiConfiguration).toEqual( + expect.objectContaining({ + apiProvider: providerIdentifiers.anthropic, + apiModelId: "claude-opus-4-7", + apiKey: "test-key", + reasoningEffort: SETTINGS_EFFORT, + }), + ) + }) + }) + + describe("updateApiConfiguration while an override is active", () => { + it("keeps the override applied over the new profile and restores the new profile on clear", () => { + task.setRuntimeThinkingEffort("xhigh", "test-source") + + // A profile switch lands a different settings-derived effort while the override is active. + const newConfig = { + apiProvider: providerIdentifiers.anthropic, + apiModelId: "claude-opus-4-8", + apiKey: "test-key-2", + reasoningEffort: "medium", + } as ProviderSettings + task.updateApiConfiguration(newConfig) + + // The override remains active... + expect(task.getRuntimeThinkingEffort()).toEqual({ effort: "xhigh", source: "test-source" }) + // ...and the handler was rebuilt over the NEW profile with the override applied. + const lastCall = vi.mocked(buildApiHandler).mock.calls.at(-1) + expect(lastCall?.[0]).toEqual( + expect.objectContaining({ apiModelId: "claude-opus-4-8", reasoningEffort: "xhigh" }), + ) + expect(lastCall?.[0]).not.toBe(newConfig) + + // Clearing restores the NEW profile's effort, not the stale original one. + task.setRuntimeThinkingEffort(undefined) + expect(task.apiConfiguration).toEqual( + expect.objectContaining({ + apiModelId: "claude-opus-4-8", + apiKey: "test-key-2", + }), + ) + const lastCallAfterClear = vi.mocked(buildApiHandler).mock.calls.at(-1) + expect(lastCallAfterClear?.[0]).toEqual(expect.objectContaining({ reasoningEffort: "medium" })) + }) + + it("replaces the configuration as usual while inactive", () => { + const newConfig = { + apiProvider: providerIdentifiers.anthropic, + apiModelId: "claude-opus-4-8", + apiKey: "test-key-2", + reasoningEffort: "medium", + } as ProviderSettings + + task.updateApiConfiguration(newConfig) + + expect(task.apiConfiguration).toBe(newConfig) + expect(task.apiConfiguration.reasoningEffort).toBe("medium") + const lastCall = vi.mocked(buildApiHandler).mock.calls.at(-1) + expect(lastCall?.[0]).toBe(newConfig) + }) + }) + + describe("request metadata fragment", () => { + it("is empty while inactive and carries the override while active", () => { + // Key absence, not toEqual({}): toEqual ignores keys whose value is undefined, + // so only an absence assertion kills the always-consequent metadata mutant. + expect(getPrivateAccess(task).getRuntimeThinkingEffortMetadata()).not.toHaveProperty("reasoningEffort") + + task.setRuntimeThinkingEffort("high") + expect(getPrivateAccess(task).getRuntimeThinkingEffortMetadata()).toEqual({ reasoningEffort: "high" }) + + task.setRuntimeThinkingEffort("low") + expect(getPrivateAccess(task).getRuntimeThinkingEffortMetadata()).toEqual({ reasoningEffort: "low" }) + + task.setRuntimeThinkingEffort(undefined) + expect(getPrivateAccess(task).getRuntimeThinkingEffortMetadata()).not.toHaveProperty("reasoningEffort") + }) + }) + + describe("dispose", () => { + it("clears the task-local override and restores the settings-derived API configuration at task end", async () => { + task.setRuntimeThinkingEffort("xhigh", "source") + await task.dispose() + + expect(task.getRuntimeThinkingEffort()).toEqual({ effort: undefined, source: undefined }) + const access = getPrivateAccess(task) + expect(access.runtimeThinkingEffort).toBeUndefined() + expect(access.runtimeThinkingEffortSource).toBeUndefined() + expect(task.apiConfiguration.reasoningEffort).toBe(SETTINGS_EFFORT) + }) + }) +}) diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index 93543435e2..9d3cb36e97 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -283,6 +283,7 @@ vi.mock("../../task/Task", () => ({ apiConversationHistory: [], overwriteClineMessages: vi.fn(), overwriteApiConversationHistory: vi.fn(), + apiConfiguration: options?.apiConfiguration, getTaskNumber: vi.fn().mockReturnValue(0), setTaskNumber: vi.fn(), setParentTask: vi.fn(), @@ -431,6 +432,7 @@ describe("ClineProvider", () => { apiConversationHistory: [], overwriteClineMessages: vi.fn(), overwriteApiConversationHistory: vi.fn(), + apiConfiguration: options?.apiConfiguration, getTaskNumber: vi.fn().mockReturnValue(0), setTaskNumber: vi.fn(), setParentTask: vi.fn(), @@ -2067,6 +2069,42 @@ describe("ClineProvider", () => { }, ) + test("getStateToPostToWebview posts the active task's apiConfiguration object to the webview", async () => { + await provider.resolveWebviewView(mockWebviewView) + await provider.contextProxy.setProviderSettings({ + apiProvider: providerIdentifiers.anthropic, + apiModelId: "claude-opus-4-7", + reasoningEffort: "low", + }) + + const taskConfiguration = { + apiProvider: providerIdentifiers.anthropic, + apiModelId: "claude-opus-4-8", + reasoningEffort: "high", + } as ProviderSettings + const mockCline = new Task({ ...defaultTaskOptions, apiConfiguration: taskConfiguration }) + await provider.addClineToStack(mockCline) + + try { + // The webview projection is the ACTIVE TASK's apiConfiguration object itself: + // SettingsView buffers it into cachedState and returns it on save + // (upsertApiConfiguration -> saveConfig). That is why the task-local thinking + // effort override must never enter apiConfiguration (asserted at the Task + // layer in Task.runtime-thinking-effort.test.ts): a settings save during an + // active override would otherwise persist the override into the profile. + const posted = await provider.getStateToPostToWebview() + // The webview projection is the ACTIVE TASK's apiConfiguration object itself: + // SettingsView buffers it into cachedState and returns it on save + // (upsertApiConfiguration -> saveConfig). That is why the task-local thinking + // effort override must never enter apiConfiguration (asserted at the Task + // layer in Task.runtime-thinking-effort.test.ts): a settings save during an + // active override would otherwise persist the override into the profile. + expect(posted.apiConfiguration).toBe(taskConfiguration) + } finally { + await provider.removeClineFromStack() + } + }) + test("getState returns the saved destructive command guard setting", async () => { await provider.contextProxy.setValue("destructiveCommandGuardEnabled", true) @@ -2168,6 +2206,38 @@ describe("ClineProvider", () => { expect(state.destructiveCommandGuardEnabled).toBe(false) }) + test("getStateToPostToWebview returns the saved dynamicThinkingEffort experiment when enabled", async () => { + await provider.resolveWebviewView(mockWebviewView) + await provider.contextProxy.setValue("experiments", { + ...experimentDefault, + dynamicThinkingEffort: true, + }) + + const state = await provider.getStateToPostToWebview() + + expect(state.experiments).toEqual({ ...experimentDefault, dynamicThinkingEffort: true }) + }) + + test("getStateToPostToWebview returns the saved dynamicThinkingEffort experiment when explicitly disabled", async () => { + await provider.resolveWebviewView(mockWebviewView) + await provider.contextProxy.setValue("experiments", { + ...experimentDefault, + dynamicThinkingEffort: false, + }) + + const state = await provider.getStateToPostToWebview() + + expect(state.experiments).toEqual({ ...experimentDefault, dynamicThinkingEffort: false }) + }) + + test("getStateToPostToWebview defaults dynamicThinkingEffort to false when experiments are unset", async () => { + await provider.resolveWebviewView(mockWebviewView) + + const state = await provider.getStateToPostToWebview() + + expect(state.experiments).toEqual({ ...experimentDefault, dynamicThinkingEffort: false }) + }) + test("getStateToPostToWebview returns the saved blanket auto-deny setting", async () => { await provider.resolveWebviewView(mockWebviewView) await provider.contextProxy.setValue("alwaysDenyUnapprovedCommands", true) diff --git a/src/core/webview/__tests__/webviewMessageHandler.spec.ts b/src/core/webview/__tests__/webviewMessageHandler.spec.ts index d5c72de742..b96ef7fd4d 100644 --- a/src/core/webview/__tests__/webviewMessageHandler.spec.ts +++ b/src/core/webview/__tests__/webviewMessageHandler.spec.ts @@ -84,6 +84,7 @@ import * as copilotProvider from "../../../api/providers/github-copilot" import { webviewMessageHandler } from "../webviewMessageHandler" import { registerCopilotModelBroadcast } from "../../../services/language-models/copilotModelBroadcast" import type { ClineProvider } from "../ClineProvider" +import { experimentDefault } from "../../../shared/experiments" import { flushModels, getModels } from "../../../api/providers/fetchers/modelCache" import { getLMStudioModels } from "../../../api/providers/fetchers/lmstudio" import { getCommands } from "../../../services/command/commands" @@ -2971,6 +2972,60 @@ describe("webviewMessageHandler - telemetrySetting", () => { }) }) +describe("webviewMessageHandler - experiments", () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it("persists dynamicThinkingEffort true merged with the saved experiments", async () => { + vi.mocked(mockClineProvider.contextProxy.getValue).mockImplementation((key: string) => + key === "experiments" ? { preventFocusDisruption: true } : undefined, + ) + + await webviewMessageHandler(mockClineProvider, { + type: "updateSettings", + updatedSettings: { experiments: { dynamicThinkingEffort: true } }, + }) + + expect(mockClineProvider.contextProxy.setValue).toHaveBeenCalledWith("experiments", { + preventFocusDisruption: true, + dynamicThinkingEffort: true, + }) + expect(mockClineProvider.postStateToWebview).toHaveBeenCalledTimes(1) + }) + + it("persists dynamicThinkingEffort false over a previously enabled value", async () => { + vi.mocked(mockClineProvider.contextProxy.getValue).mockImplementation((key: string) => + key === "experiments" ? { dynamicThinkingEffort: true } : undefined, + ) + + await webviewMessageHandler(mockClineProvider, { + type: "updateSettings", + updatedSettings: { experiments: { dynamicThinkingEffort: false } }, + }) + + expect(mockClineProvider.contextProxy.setValue).toHaveBeenCalledWith("experiments", { + dynamicThinkingEffort: false, + }) + expect(mockClineProvider.postStateToWebview).toHaveBeenCalledTimes(1) + }) + + it("persists the experiment defaults when no experiments are saved yet", async () => { + vi.mocked(mockClineProvider.contextProxy.getValue).mockReturnValue(undefined) + + await webviewMessageHandler(mockClineProvider, { + type: "updateSettings", + updatedSettings: { experiments: {} }, + }) + + expect(mockClineProvider.contextProxy.setValue).toHaveBeenCalledWith("experiments", { + ...experimentDefault, + dynamicThinkingEffort: false, + }) + expect(mockClineProvider.postStateToWebview).toHaveBeenCalledTimes(1) + }) +}) + describe("webviewMessageHandler - collapseCommandOutputByDefault", () => { beforeEach(() => { vi.clearAllMocks() diff --git a/src/shared/__tests__/experiments.spec.ts b/src/shared/__tests__/experiments.spec.ts index f2261a5c09..920aa6ec48 100644 --- a/src/shared/__tests__/experiments.spec.ts +++ b/src/shared/__tests__/experiments.spec.ts @@ -2,7 +2,7 @@ import type { ExperimentId } from "@roo-code/types" -import { EXPERIMENT_IDS, experimentConfigsMap, experiments as Experiments } from "../experiments" +import { EXPERIMENT_IDS, experimentConfigsMap, experimentDefault, experiments as Experiments } from "../experiments" describe("experiments", () => { describe("PREVENT_FOCUS_DISRUPTION", () => { @@ -22,6 +22,7 @@ describe("experiments", () => { runSlashCommand: false, customTools: false, parallelToolExecution: false, + dynamicThinkingEffort: false, } expect(Experiments.isEnabled(experiments, EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION)).toBe(false) }) @@ -33,6 +34,7 @@ describe("experiments", () => { runSlashCommand: false, customTools: false, parallelToolExecution: false, + dynamicThinkingEffort: false, } expect(Experiments.isEnabled(experiments, EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION)).toBe(true) }) @@ -44,6 +46,7 @@ describe("experiments", () => { runSlashCommand: false, customTools: false, parallelToolExecution: false, + dynamicThinkingEffort: false, } expect(Experiments.isEnabled(experiments, EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION)).toBe(false) }) @@ -66,4 +69,28 @@ describe("experiments", () => { expect(Experiments.isEnabled({ parallelToolExecution: true }, "parallelToolExecution")).toBe(true) }) }) + + describe("DYNAMIC_THINKING_EFFORT", () => { + it("is configured correctly", () => { + expect(EXPERIMENT_IDS.DYNAMIC_THINKING_EFFORT).toBe("dynamicThinkingEffort") + expect(experimentConfigsMap.DYNAMIC_THINKING_EFFORT).toMatchObject({ + enabled: false, + }) + // Hidden from the Settings panel until the set_thinking_effort tool exists. + expect(experimentConfigsMap.DYNAMIC_THINKING_EFFORT.showInSettings).toBe(false) + }) + + it("is disabled by default", () => { + expect(experimentDefault.dynamicThinkingEffort).toBe(false) + expect(Experiments.isEnabled({}, "dynamicThinkingEffort")).toBe(false) + }) + + it("returns true when enabled", () => { + expect(Experiments.isEnabled({ dynamicThinkingEffort: true }, "dynamicThinkingEffort")).toBe(true) + }) + + it("returns false when explicitly disabled", () => { + expect(Experiments.isEnabled({ dynamicThinkingEffort: false }, "dynamicThinkingEffort")).toBe(false) + }) + }) }) diff --git a/src/shared/experiments.ts b/src/shared/experiments.ts index ae538b9138..0c2efa9e14 100644 --- a/src/shared/experiments.ts +++ b/src/shared/experiments.ts @@ -6,6 +6,7 @@ export const EXPERIMENT_IDS = { RUN_SLASH_COMMAND: "runSlashCommand", CUSTOM_TOOLS: "customTools", PARALLEL_TOOL_EXECUTION: "parallelToolExecution", + DYNAMIC_THINKING_EFFORT: "dynamicThinkingEffort", } as const satisfies Record type _AssertExperimentIds = AssertEqual>> @@ -25,6 +26,10 @@ export const experimentConfigsMap: Record = { CUSTOM_TOOLS: { enabled: false }, // TODO: add i18n keys (settings:experimental.PARALLEL_TOOL_EXECUTION.name/.description) in the same PR that sets showInSettings: true PARALLEL_TOOL_EXECUTION: { enabled: false, showInSettings: false }, + // TODO: set showInSettings: true in the PR that registers the set_thinking_effort + // native tool (definition + handler); until then the toggle would only persist a + // flag with no model-facing effect. + DYNAMIC_THINKING_EFFORT: { enabled: false, showInSettings: false }, } export const experimentDefault = Object.fromEntries( diff --git a/webview-ui/playwright/gallery/stories.tsx b/webview-ui/playwright/gallery/stories.tsx index 08d680678a..b72f06a830 100644 --- a/webview-ui/playwright/gallery/stories.tsx +++ b/webview-ui/playwright/gallery/stories.tsx @@ -377,6 +377,11 @@ export const stories: Record = { const { UISettingsStory } = await import("@/components/settings/__tests__/UISettings.visual.fixture") return }, + "experimental-settings": async () => { + const { ExperimentalSettingsStory } = + await import("@/components/settings/__tests__/ExperimentalSettings.visual.fixture") + return + }, "ui-settings-long-locale": async () => { const [{ UISettingsStory }, { default: i18next }] = await Promise.all([ import("@/components/settings/__tests__/UISettings.visual.fixture"), diff --git a/webview-ui/src/components/settings/__tests__/ExperimentalSettings.spec.tsx b/webview-ui/src/components/settings/__tests__/ExperimentalSettings.spec.tsx index b31f87dc7e..d5214401d8 100644 --- a/webview-ui/src/components/settings/__tests__/ExperimentalSettings.spec.tsx +++ b/webview-ui/src/components/settings/__tests__/ExperimentalSettings.spec.tsx @@ -32,4 +32,20 @@ describe("ExperimentalSettings", () => { expect(screen.getByText("settings:experimental.CUSTOM_TOOLS.name")).toBeInTheDocument() expect(screen.queryByText("settings:experimental.PARALLEL_TOOL_EXECUTION.name")).not.toBeInTheDocument() }) + + it("hides the dynamic thinking effort toggle until the set_thinking_effort tool is registered", () => { + // The flag persists and round-trips, but the tool is not in getNativeTools() + // yet, so the toggle must not render - not even when the flag is enabled. + const { unmount } = render( + , + ) + expect(screen.queryByText("settings:experimental.DYNAMIC_THINKING_EFFORT.name")).not.toBeInTheDocument() + unmount() + + render() + expect(screen.queryByText("settings:experimental.DYNAMIC_THINKING_EFFORT.name")).not.toBeInTheDocument() + }) }) diff --git a/webview-ui/src/components/settings/__tests__/ExperimentalSettings.visual.fixture.tsx b/webview-ui/src/components/settings/__tests__/ExperimentalSettings.visual.fixture.tsx new file mode 100644 index 0000000000..15ff6d87b2 --- /dev/null +++ b/webview-ui/src/components/settings/__tests__/ExperimentalSettings.visual.fixture.tsx @@ -0,0 +1,31 @@ +import { useState } from "react" + +import type { Experiments } from "@roo-code/types" + +import { EXPERIMENT_IDS, experimentDefault } from "@roo/experiments" + +import { ExperimentalSettings } from "../ExperimentalSettings" +import { AppProviders } from "../../../../playwright/AppProviders" + +export function ExperimentalSettingsStory() { + // PREVENT_FOCUS_DISRUPTION stands in for the enabled-toggle state: the + // dynamicThinkingEffort toggle is hidden (showInSettings: false) until the + // set_thinking_effort tool is registered. + const [experiments, setExperiments] = useState({ + ...experimentDefault, + [EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION]: true, + }) + + return ( + +
+ setExperiments((current) => ({ ...current, [id]: enabled }))} + /> +
+
+ ) +} diff --git a/webview-ui/src/components/settings/__tests__/ExperimentalSettings.visual.tsx b/webview-ui/src/components/settings/__tests__/ExperimentalSettings.visual.tsx new file mode 100644 index 0000000000..8a12ebf3ae --- /dev/null +++ b/webview-ui/src/components/settings/__tests__/ExperimentalSettings.visual.tsx @@ -0,0 +1,12 @@ +import { expect, test } from "../../../../playwright/coverage-fixture" +import { mountedStory } from "../../../../playwright/mounted-story" +import { applyVisualTheme, visualThemes } from "../../../../playwright/themes" + +for (const theme of visualThemes) { + test(`renders the experimental settings section in the VS Code ${theme.name} theme`, async ({ mount, page }) => { + const component = mountedStory(await mount("experimental-settings")) + await applyVisualTheme(page, theme) + const story = component.getByTestId("experimental-settings-story") + await expect(story).toHaveScreenshot(`experimental-settings-${theme.name}.png`) + }) +} diff --git a/webview-ui/src/components/settings/__tests__/SettingsView.spec.tsx b/webview-ui/src/components/settings/__tests__/SettingsView.spec.tsx index 0835f255f9..a565b7ff0a 100644 --- a/webview-ui/src/components/settings/__tests__/SettingsView.spec.tsx +++ b/webview-ui/src/components/settings/__tests__/SettingsView.spec.tsx @@ -5,6 +5,7 @@ import { act } from "@testing-library/react" import { vscode } from "@/utils/vscode" import { DEFAULT_CHECKPOINT_TIMEOUT_SECONDS, type ProviderSettings } from "@roo-code/types" +import { experimentDefault } from "@roo/experiments" import type { ApiOptionsProps } from "../ApiOptions" import SettingsView from "../SettingsView" @@ -873,6 +874,47 @@ describe("SettingsView - Duplicate Commands", () => { }) }) +describe("SettingsView - Experimental Settings", () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it("does not render the dynamic thinking effort toggle while the tool is unregistered", () => { + const { activateTab, getSettingsContent } = renderSettingsView({ + experiments: { ...experimentDefault, dynamicThinkingEffort: true }, + }) + activateTab("experimental") + expect( + within(getSettingsContent()).queryByText("settings:experimental.DYNAMIC_THINKING_EFFORT.name"), + ).not.toBeInTheDocument() + }) + + it("keeps dynamicThinkingEffort in the updateSettings payload while its toggle is hidden", () => { + // Hiding the toggle (set_thinking_effort tool not registered yet) must not + // drop the flag from the save payload: the experiments object round-trips + // wholesale, so a persisted value survives until the tool PR resurfaces it. + const { activateTab, getSettingsContent } = renderSettingsView({ experiments: experimentDefault }) + activateTab("experimental") + expect( + within(getSettingsContent()).queryByText("settings:experimental.DYNAMIC_THINKING_EFFORT.name"), + ).not.toBeInTheDocument() + // Dirty the form via a visible experimental toggle (save posts only when dirty). + const visibleLabel = within(getSettingsContent()) + .getByText("settings:experimental.PREVENT_FOCUS_DISRUPTION.name") + .closest("label")! + fireEvent.click(within(visibleLabel).getByRole("checkbox")) + fireEvent.click(screen.getByTestId("save-button")) + expect(vscode.postMessage).toHaveBeenCalledWith( + expect.objectContaining({ + type: "updateSettings", + updatedSettings: expect.objectContaining({ + experiments: expect.objectContaining({ dynamicThinkingEffort: false }), + }), + }), + ) + }) +}) + describe("SettingsView - Blanket Auto-Deny", () => { beforeEach(() => { vi.clearAllMocks() diff --git a/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-dark.png b/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-dark.png new file mode 100644 index 0000000000..d9fc3eb6d7 Binary files /dev/null and b/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-dark.png differ diff --git a/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-high-contrast-light.png b/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-high-contrast-light.png new file mode 100644 index 0000000000..8509ec40f6 Binary files /dev/null and b/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-high-contrast-light.png differ diff --git a/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-high-contrast.png b/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-high-contrast.png new file mode 100644 index 0000000000..5aaefe1c19 Binary files /dev/null and b/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-high-contrast.png differ diff --git a/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-light.png b/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-light.png new file mode 100644 index 0000000000..81f1fcfb2d Binary files /dev/null and b/webview-ui/src/components/settings/__tests__/__screenshots__/experimental-settings-light.png differ diff --git a/webview-ui/src/i18n/locales/ca/settings.json b/webview-ui/src/i18n/locales/ca/settings.json index d39d8edd6a..9d375a1c41 100644 --- a/webview-ui/src/i18n/locales/ca/settings.json +++ b/webview-ui/src/i18n/locales/ca/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Eines actualitzades correctament", "refreshError": "Error en actualitzar les eines", "toolParameters": "Paràmetres" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Esforç de pensament dinàmic", + "description": "Activa l'eina set_thinking_effort perquè el model decideixi el seu esforç de pensament per pas. El control manual al xat sempre està disponible. (experimental)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/de/settings.json b/webview-ui/src/i18n/locales/de/settings.json index 983db1df5d..76708625c3 100644 --- a/webview-ui/src/i18n/locales/de/settings.json +++ b/webview-ui/src/i18n/locales/de/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Tools erfolgreich aktualisiert", "refreshError": "Fehler beim Aktualisieren der Tools", "toolParameters": "Parameter" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Dynamische Denkintensität", + "description": "Aktiviert das set_thinking_effort-Tool, damit das Modell die Denkintensität pro Schritt selbst bestimmt. Die manuelle Anpassung im Chat ist immer verfügbar. (experimentell)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/en/settings.json b/webview-ui/src/i18n/locales/en/settings.json index ea924ce79e..864b5f7616 100644 --- a/webview-ui/src/i18n/locales/en/settings.json +++ b/webview-ui/src/i18n/locales/en/settings.json @@ -1090,6 +1090,10 @@ "refreshSuccess": "Tools refreshed successfully", "refreshError": "Failed to refresh tools", "toolParameters": "Parameters" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Dynamic thinking effort", + "description": "Enables the set_thinking_effort tool so the model can decide its thinking effort per step. The manual in-chat control is always available. (experimental)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/es/settings.json b/webview-ui/src/i18n/locales/es/settings.json index 57612bf3e5..d0e160f77c 100644 --- a/webview-ui/src/i18n/locales/es/settings.json +++ b/webview-ui/src/i18n/locales/es/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Herramientas actualizadas correctamente", "refreshError": "Error al actualizar las herramientas", "toolParameters": "Parámetros" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Esfuerzo de pensamiento dinámico", + "description": "Habilita la herramienta set_thinking_effort para que el modelo decida su esfuerzo de pensamiento por paso. El control manual en el chat siempre está disponible. (experimental)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/fr/settings.json b/webview-ui/src/i18n/locales/fr/settings.json index a91a5137d3..aa8fa65762 100644 --- a/webview-ui/src/i18n/locales/fr/settings.json +++ b/webview-ui/src/i18n/locales/fr/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Outils actualisés avec succès", "refreshError": "Échec de l'actualisation des outils", "toolParameters": "Paramètres" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Effort de réflexion dynamique", + "description": "Active l'outil set_thinking_effort afin que le modèle décide de son effort de réflexion à chaque étape. Le contrôle manuel dans le chat est toujours disponible. (expérimental)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/hi/settings.json b/webview-ui/src/i18n/locales/hi/settings.json index bc6e973623..f77d1b9f3f 100644 --- a/webview-ui/src/i18n/locales/hi/settings.json +++ b/webview-ui/src/i18n/locales/hi/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "टूल्स सफलतापूर्वक रिफ्रेश हुए", "refreshError": "टूल्स रिफ्रेश करने में विफल", "toolParameters": "पैरामीटर्स" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "डायनामिक चिंतन प्रयास", + "description": "set_thinking_effort टूल सक्षम करता है ताकि मॉडल हर चरण में अपना चिंतन प्रयास स्वयं तय कर सके। चैट में मैन्युअल नियंत्रण हमेशा उपलब्ध है। (प्रयोगात्मक)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/id/settings.json b/webview-ui/src/i18n/locales/id/settings.json index 3ed57f373e..8fd847c54d 100644 --- a/webview-ui/src/i18n/locales/id/settings.json +++ b/webview-ui/src/i18n/locales/id/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Tool berhasil direfresh", "refreshError": "Gagal merefresh tool", "toolParameters": "Parameter" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Usaha berpikir dinamis", + "description": "Mengaktifkan alat set_thinking_effort agar model dapat memutuskan usaha berpikirnya per langkah. Kontrol manual di obrolan selalu tersedia. (eksperimental)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/it/settings.json b/webview-ui/src/i18n/locales/it/settings.json index b708304e63..ac00c6b464 100644 --- a/webview-ui/src/i18n/locales/it/settings.json +++ b/webview-ui/src/i18n/locales/it/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Strumenti aggiornati con successo", "refreshError": "Impossibile aggiornare gli strumenti", "toolParameters": "Parametri" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Sforzo di pensiero dinamico", + "description": "Abilita lo strumento set_thinking_effort in modo che il modello decida lo sforzo di pensiero per ogni passaggio. Il controllo manuale nella chat è sempre disponibile. (sperimentale)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/ja/settings.json b/webview-ui/src/i18n/locales/ja/settings.json index f6959b50dc..c6b058aca6 100644 --- a/webview-ui/src/i18n/locales/ja/settings.json +++ b/webview-ui/src/i18n/locales/ja/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "ツールが正常に更新されました", "refreshError": "ツールの更新に失敗しました", "toolParameters": "パラメーター" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "ダイナミック思考強度", + "description": "set_thinking_effort ツールを有効にし、ステップごとにモデルが思考強度を決定できるようにします。チャット内での手動調整は常に利用可能です。(実験的機能)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/ko/settings.json b/webview-ui/src/i18n/locales/ko/settings.json index 6cadbd8a3b..64ea4b1899 100644 --- a/webview-ui/src/i18n/locales/ko/settings.json +++ b/webview-ui/src/i18n/locales/ko/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "도구가 성공적으로 새로고침되었습니다", "refreshError": "도구 새로고침에 실패했습니다", "toolParameters": "매개변수" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "동적 사고 노력", + "description": "set_thinking_effort 도구를 활성화하여 단계별로 모델이 사고 노력을 결정하도록 합니다. 채팅에서 수동 조정은 항상 사용 가능합니다. (실험적 기능)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/nl/settings.json b/webview-ui/src/i18n/locales/nl/settings.json index 992e9c53e0..8496de259d 100644 --- a/webview-ui/src/i18n/locales/nl/settings.json +++ b/webview-ui/src/i18n/locales/nl/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Tools succesvol vernieuwd", "refreshError": "Fout bij vernieuwen van tools", "toolParameters": "Parameters" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Dynamisch denkwerk", + "description": "Schakelt het set_thinking_effort-gereedschap in zodat het model per stap het denkwerk zelf kan bepalen. De handmatige aanpassing in het gesprek is altijd beschikbaar. (experimenteel)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/pl/settings.json b/webview-ui/src/i18n/locales/pl/settings.json index 459675b0e1..667192e055 100644 --- a/webview-ui/src/i18n/locales/pl/settings.json +++ b/webview-ui/src/i18n/locales/pl/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Narzędzia odświeżone pomyślnie", "refreshError": "Nie udało się odświeżyć narzędzi", "toolParameters": "Parametry" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Dynamiczny wysiłek myślowy", + "description": "Włącza narzędzie set_thinking_effort, aby model samodzielnie decydował o wysiłku myślowym na każdym kroku. Ręczna regulacja w czacie jest zawsze dostępna. (eksperymentalne)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/pt-BR/settings.json b/webview-ui/src/i18n/locales/pt-BR/settings.json index 500babaaa8..a3196afa3a 100644 --- a/webview-ui/src/i18n/locales/pt-BR/settings.json +++ b/webview-ui/src/i18n/locales/pt-BR/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Ferramentas atualizadas com sucesso", "refreshError": "Falha ao atualizar ferramentas", "toolParameters": "Parâmetros" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Esforço de pensamento dinâmico", + "description": "Ativa a ferramenta set_thinking_effort para que o modelo decida seu esforço de pensamento em cada etapa. O controle manual na conversa está sempre disponível. (experimental)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/ru/settings.json b/webview-ui/src/i18n/locales/ru/settings.json index 053ff0684d..28ecae1edd 100644 --- a/webview-ui/src/i18n/locales/ru/settings.json +++ b/webview-ui/src/i18n/locales/ru/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Инструменты успешно обновлены", "refreshError": "Не удалось обновить инструменты", "toolParameters": "Параметры" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Динамическое усилие размышления", + "description": "Включает инструмент set_thinking_effort, чтобы модель самостоятельно определяла усилие размышления на каждом шаге. Ручное управление в чате всегда доступно. (экспериментальная функция)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/tr/settings.json b/webview-ui/src/i18n/locales/tr/settings.json index b37f28d44d..7730add503 100644 --- a/webview-ui/src/i18n/locales/tr/settings.json +++ b/webview-ui/src/i18n/locales/tr/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Araçlar başarıyla yenilendi", "refreshError": "Araçlar yenilenemedi", "toolParameters": "Parametreler" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Dinamik düşünme çabası", + "description": "set_thinking_effort aracını etkinleştirir; böylece model her adımda kendi düşünme çabasını belirler. Sohbetteki manuel kontrol her zaman kullanılabilir. (deneysel)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/vi/settings.json b/webview-ui/src/i18n/locales/vi/settings.json index 94843217ae..adc5a92eca 100644 --- a/webview-ui/src/i18n/locales/vi/settings.json +++ b/webview-ui/src/i18n/locales/vi/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "Làm mới công cụ thành công", "refreshError": "Không thể làm mới công cụ", "toolParameters": "Thông số" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "Nỗ lực suy nghĩ động", + "description": "Bật công cụ set_thinking_effort để mô hình tự quyết định nỗ lực suy nghĩ của từng bước. Điều chỉnh thủ công trong trò chuyện luôn khả dụng. (thực nghiệm)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/zh-CN/settings.json b/webview-ui/src/i18n/locales/zh-CN/settings.json index 8be0fe1532..44faa03ad4 100644 --- a/webview-ui/src/i18n/locales/zh-CN/settings.json +++ b/webview-ui/src/i18n/locales/zh-CN/settings.json @@ -1010,6 +1010,10 @@ "refreshSuccess": "工具刷新成功", "refreshError": "工具刷新失败", "toolParameters": "参数" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "动态思考强度", + "description": "启用 set_thinking_effort 工具,让模型按步骤自行决定思考强度。对话中的手动调整随时可用。 (实验性功能)" } }, "promptCaching": { diff --git a/webview-ui/src/i18n/locales/zh-TW/settings.json b/webview-ui/src/i18n/locales/zh-TW/settings.json index 65eb5c67a5..67dc6f89f7 100644 --- a/webview-ui/src/i18n/locales/zh-TW/settings.json +++ b/webview-ui/src/i18n/locales/zh-TW/settings.json @@ -1037,6 +1037,10 @@ "refreshSuccess": "工具重新整理成功", "refreshError": "工具重新整理失敗", "toolParameters": "參數" + }, + "DYNAMIC_THINKING_EFFORT": { + "name": "動態思考強度", + "description": "啟用 set_thinking_effort 工具,讓模型自行決定每一步的思考強度。對話中的手動調整隨時可用。(實驗性)" } }, "promptCaching": {