Skip to content
TypeScript

feat(web): step reasoning effort from the keyboard (#19928)

Bilal Bakr2993dfc06911
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index b9e5fc037d8..4c61d0b3b95 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -5671,6 +5671,12 @@ export default function ChatView(props: ChatViewProps) {
"modelPicker.toggle": ({ event }) => {
if (!event.repeat) composerRef.current?.toggleModelPicker();
},
+ "composer.increaseEffort": ({ event }) => {
+ if (!event.repeat) composerRef.current?.stepReasoningEffort(1);
+ },
+ "composer.decreaseEffort": ({ event }) => {
+ if (!event.repeat) composerRef.current?.stepReasoningEffort(-1);
+ },
"composer.host": openComposerControl("composer.host"),
"composer.effort": openComposerControl("composer.effort"),
"composer.mode": openComposerControl("composer.mode"),
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index 120b3677608..4bdb05c42df 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -305,6 +305,7 @@ import {
import {
getComposerPromptInjectionState,
getComposerProviderState,
+ getComposerReasoningStep,
renderProviderTraitsMenuContent,
renderProviderTraitsPicker,
} from "./composerProviderState";
@@ -1435,6 +1436,7 @@ export interface ChatComposerHandle {
sourceAnchor: AssistantCitationSourceAnchor,
) => boolean;
openModelPicker: () => void;
+ stepReasoningEffort: (direction: 1 | -1) => void;
toggleModelPicker: () => void;
openControl: (command: KeybindingCommand) => void;
isModelPickerOpen: () => boolean;
@@ -6040,6 +6042,44 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
{ ensureLeadingBoundary: true, citationCommentAnchor: sourceAnchor },
),
openModelPicker: openModelPickerStable,
+ stepReasoningEffort: (direction) => {
+ if (
+ noProviderAvailable ||
+ isComposerApprovalState ||
+ pendingUserInputs.length > 0 ||
+ // A queued-message edit draft is discarded when the edit ends.
+ isEditingQueuedMessage
+ ) {
+ return;
+ }
+ const change = getComposerReasoningStep({
+ provider: selectedProvider,
+ instanceId: selectedInstanceId,
+ model: selectedModel,
+ models: selectedProviderModels,
+ modelOptions: composerModelOptions?.[selectedInstanceId],
+ reportedModelSelection,
+ prompt: promptRef.current,
+ cursor: readComposerSnapshotStable().expandedCursor,
+ planModeEnabled: settings.planModeEnabled,
+ direction,
+ });
+ if (!change) return;
+ if (change.modelOptions) {
+ useComposerDraftStore
+ .getState()
+ .setProviderModelOptions(composerDraftTarget, selectedProvider, change.modelOptions, {
+ instanceId: selectedInstanceId,
+ model: selectedModel,
+ persistSticky: true,
+ });
+ }
+ if (change.prompt !== promptRef.current) {
+ applyPromptReplacementStable(0, promptRef.current.length, change.prompt, {
+ expandedCursorAfterReplace: change.cursor,
+ });
+ }
+ },
toggleModelPicker: () => {
if (isComposerModelPickerOpen) {
setIsComposerModelPickerOpen(false);
@@ -6179,6 +6219,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
addComposerAttachments,
foldPastedText,
composerDraftTarget,
+ composerModelOptions,
+ isEditingQueuedMessage,
composerCursor,
activePendingProgress,
composerTerminalContexts,
@@ -6207,6 +6249,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
resetComposerTrigger,
setComposerTrigger,
selectedModel,
+ selectedInstanceId,
+ reportedModelSelection,
+ settings.planModeEnabled,
selectedModelOptionsForDispatch,
selectedModelSelection,
multipleModelSelections,
diff --git a/apps/web/src/components/chat/TraitsPicker.tsx b/apps/web/src/components/chat/TraitsPicker.tsx
index c82ff6a67aa..52b80173e95 100644
--- a/apps/web/src/components/chat/TraitsPicker.tsx
+++ b/apps/web/src/components/chat/TraitsPicker.tsx
@@ -91,6 +91,14 @@ type TraitsPersistence =
const ULTRATHINK_PROMPT_PREFIX = "Ultrathink:\n";
+const REASONING_SELECT_DESCRIPTOR_IDS: ReadonlySet<string> = new Set([
+ "reasoningEffort",
+ "reasoning",
+ "effort",
+ "variant",
+ "thinking",
+]);
+
function DefaultBadge() {
return (
<Badge variant="outline" size="sm" className="min-w-0">
@@ -253,6 +261,97 @@ function getTraitsSectionVisibility(input: {
};
}
+function getTraitSelectChange(
+ selected: ReturnType<typeof getSelectedTraits>,
+ descriptor: Extract<ProviderOptionDescriptor, { type: "select" }>,
+ prompt: string,
+ value: string,
+) {
+ if (!value) return null;
+ if (descriptor.promptInjectedValues?.includes(value)) {
+ return {
+ prompt:
+ prompt.trim().length === 0
+ ? ULTRATHINK_PROMPT_PREFIX
+ : applyClaudePromptEffortPrefix(prompt, "ultrathink"),
+ };
+ }
+ const isPrimary = descriptor.id === selected.primarySelectDescriptor?.id;
+ if (isPrimary && selected.ultrathinkInBodyText) return null;
+ return {
+ prompt:
+ isPrimary && selected.ultrathinkPromptControlled
+ ? prompt.replace(/^Ultrathink:\s*/i, "")
+ : prompt,
+ modelOptions: buildProviderOptionSelectionsFromDescriptors(
+ replaceDescriptorCurrentValue(selected.descriptors, descriptor.id, value),
+ ),
+ };
+}
+
+/**
+ * `modelOptions` must already carry the composer's implicit defaults (see
+ * `withImplicitFastModeDefault`) so the persisted selection matches what the
+ * picker would write.
+ */
+export function getReasoningTraitStep(input: {
+ provider: ProviderDriverKind;
+ instanceId: ProviderInstanceId;
+ model: string;
+ models: ReadonlyArray<ServerProviderModel>;
+ modelOptions: ProviderOptions | undefined;
+ reportedModelSelection: ModelSelection | null | undefined;
+ prompt: string;
+ planModeEnabled: boolean;
+ direction: 1 | -1;
+}) {
+ const selected = getSelectedTraits(
+ input.provider,
+ input.models,
+ input.model,
+ input.prompt,
+ input.modelOptions,
+ true,
+ input.planModeEnabled,
+ );
+ if (selected.modelIsUnavailable || selected.ultrathinkInBodyText) return null;
+ const descriptor = selected.selectDescriptors.find((entry) =>
+ REASONING_SELECT_DESCRIPTOR_IDS.has(entry.id),
+ );
+ if (!descriptor || descriptor.options.length < 2) return null;
+ const isPrimary = descriptor.id === selected.primarySelectDescriptor?.id;
+ const current =
+ isPrimary && selected.ultrathinkPromptControlled
+ ? "ultrathink"
+ : getDescriptorStringValue(
+ descriptor,
+ { instanceId: input.instanceId, model: input.model, options: input.modelOptions ?? [] },
+ input.reportedModelSelection,
+ );
+ const ordered = input.direction > 0 ? descriptor.options : descriptor.options.toReversed();
+ // A reported value outside the catalog, such as OpenCode's "default", steps
+ // from the catalog default, or from the end when there is none.
+ const position =
+ [current, getDescriptorStringValue(descriptor)]
+ .map((value) => ordered.findIndex((option) => option.id === value))
+ .find((index) => index >= 0) ?? -1;
+ for (const option of [
+ ...ordered.slice(position + 1),
+ ...ordered.slice(0, Math.max(position, 0)),
+ ]) {
+ const change = getTraitSelectChange(selected, descriptor, input.prompt, option.id);
+ if (!change) return null;
+ if ("modelOptions" in change) {
+ return change.modelOptions
+ ? { prompt: change.prompt, modelOptions: change.modelOptions }
+ : null;
+ }
+ // A slash command refuses the Ultrathink prefix, so skip that level.
+ if (change.prompt.startsWith(ULTRATHINK_PROMPT_PREFIX)) return change;
+ }
+ return null;
+}
+
export function shouldRenderTraitsControls(input: {
provider: ProviderDriverKind;
models: ReadonlyArray<ServerProviderModel>;
@@ -311,6 +410,15 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
persistSticky: true,
});
};
+ const selected = getTraitsSectionVisibility({
+ provider,
+ models,
+ model,
+ prompt,
+ modelOptions,
+ allowPromptInjectedEffort,
+ planModeEnabled,
+ });
const {
descriptors,
selectDescriptors,
@@ -320,15 +428,7 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
ultrathinkInBodyText,
hasAnyControls,
modelIsUnavailable,
- } = getTraitsSectionVisibility({
- provider,
- models,
- model,
- prompt,
- modelOptions,
- allowPromptInjectedEffort,
- planModeEnabled,
- });
+ } = selected;
const updateDescriptors = (nextDescriptors: ReadonlyArray<ProviderOptionDescriptor>) => {
updateModelOptions(buildProviderOptionSelectionsFromDescriptors(nextDescriptors));
};
@@ -337,21 +437,10 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
descriptor: Extract<ProviderOptionDescriptor, { type: "select" }>,
value: string,
) => {
- if (!value) return;
- if (descriptor.promptInjectedValues?.includes(value)) {
- const nextPrompt =
- prompt.trim().length === 0
- ? ULTRATHINK_PROMPT_PREFIX
- : applyClaudePromptEffortPrefix(prompt, "ultrathink");
- onPromptChange(nextPrompt);
- return;
- }
- if (ultrathinkInBodyText && descriptor.id === primarySelectDescriptor?.id) return;
- if (ultrathinkPromptControlled && descriptor.id === primarySelectDescriptor?.id) {
- const stripped = prompt.replace(/^Ultrathink:\s*/i, "");
- onPromptChange(stripped);
- }
- updateDescriptors(replaceDescriptorCurrentValue(descriptors, descriptor.id, value));
+ const change = getTraitSelectChange(selected, descriptor, prompt, value);
+ if (!change) return;
+ if (change.prompt !== prompt) onPromptChange(change.prompt);
+ if ("modelOptions" in change) updateModelOptions(change.modelOptions);
};
if (!hasAnyControls) {
@@ -534,7 +623,7 @@ export function buildTraitsTriggerDisplay(input: {
if (
reasoningLabelIndex === -1 &&
descriptor.type === "select" &&
- ["reasoningEffort", "reasoning", "effort", "variant", "thinking"].includes(descriptor.id)
+ REASONING_SELECT_DESCRIPTOR_IDS.has(descriptor.id)
) {
reasoningLabelIndex = labels.length;
}
diff --git a/apps/web/src/components/chat/composerProviderState.test.tsx b/apps/web/src/components/chat/composerProviderState.test.tsx
index 4fa33309825..d4cf18396ba 100644
--- a/apps/web/src/components/chat/composerProviderState.test.tsx
+++ b/apps/web/src/components/chat/composerProviderState.test.tsx
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vite-plus/test";
import {
ProviderDriverKind,
+ ProviderInstanceId,
type ProviderOptionDescriptor,
type ProviderOptionSelection,
type ServerProviderModel,
@@ -10,6 +11,7 @@ import { getProviderModelCapabilities } from "../../providerModels";
import {
getComposerPromptInjectionState,
getComposerProviderState,
+ getComposerReasoningStep,
renderProviderTraitsMenuContent,
renderProviderTraitsPicker,
withImplicitFastModeDefault,
@@ -486,3 +488,187 @@ describe("provider traits render guards", () => {
expect(renderProviderTraitsMenuContent(args)).toBeNull();
});
});
+
+describe("getComposerReasoningStep", () => {
+ const LEVELS = [
+ { id: "low", label: "Low" },
+ { id: "medium", label: "Medium", isDefault: true },
+ { id: "high", label: "High" },
+ ];
+ const INSTANCE = ProviderInstanceId.make("codex");
+ const CLAUDE = {
+ provider: ProviderDriverKind.make("claudeAgent"),
+ instanceId: ProviderInstanceId.make("claudeAgent"),
+ models: modelWith([
+ selectDescriptor(
+ "effort",
+ [
+ { id: "medium", label: "Medium" },
+ { id: "high", label: "High", isDefault: true },
+ { id: "ultrathink", label: "Ultrathink" },
+ ],
+ ["ultrathink"],
+ ),
+ ]),
+ };
+
+ function step(input: Partial<Parameters<typeof getComposerReasoningStep>[0]>) {
+ return getComposerReasoningStep({
+ provider: PROVIDER,
+ instanceId: INSTANCE,
+ model: MODEL,
+ models: modelWith([selectDescriptor("reasoningEffort", LEVELS)]),
+ modelOptions: undefined,
+ prompt: "Fix the bug",
+ cursor: 0,
+ planModeEnabled: true,
+ direction: 1,
+ ...input,
+ });
+ }
+
+ it("walks the catalog order, wrapping at both ends and keeping the other traits", () => {
+ const models = modelWith([
+ selectDescriptor("contextWindow", [
+ { id: "200k", label: "200k", isDefault: true },
+ { id: "1m", label: "1M" },
+ ]),
+ selectDescriptor("reasoningEffort", LEVELS),
+ ]);
+ for (const [from, direction, to] of [
+ ["low", -1, "high"],
+ ["low", 1, "medium"],
+ ["high", 1, "low"],
+ ["high", -1, "medium"],
+ ] as const) {
+ expect(
+ step({
+ models,
+ modelOptions: selections(["contextWindow", "1m"], ["reasoningEffort", from]),
+ direction,
+ }),
+ `${from} by ${direction}`,
+ ).toStrictEqual({
+ prompt: "Fix the bug",
+ cursor: 0,
+ modelOptions: selections(["contextWindow", "1m"], ["reasoningEffort", to]),
+ });
+ }
+ });
+
+ it("adds and strips the Ultrathink prefix while the caret stays on the same character", () => {
+ for (const { prompt, modelOptions, direction, expected } of [
+ {
+ prompt: " Fix the bug \n",
+ modelOptions: selections(["effort", "high"]),
+ direction: 1,
+ expected: { prompt: "Ultrathink:\nFix the bug", cursor: 20 },
+ },
+ {
+ // The prefix, not the draft's Medium, is the current level.
+ prompt: "Ultrathink:\n Fix the bug",
+ modelOptions: selections(["effort", "medium"]),
+ direction: -1,
+ expected: {
+ prompt: "Fix the bug",
+ cursor: 8,
+ modelOptions: selections(["effort", "high"]),
+ },
+ },
+ ] as const) {
+ const result = step({
+ ...CLAUDE,
+ prompt,
+ cursor: prompt.indexOf("bug"),
+ modelOptions,
+ direction,
+ });
+ expect(result).toStrictEqual(expected);
+ expect(result?.prompt.slice(result.cursor)).toMatch(/^bug/);
+ }
+ // A caret in leading whitespace must not land inside the new prefix.
+ expect(
+ step({ ...CLAUDE, prompt: " Fix", modelOptions: selections(["effort", "high"]) })?.cursor,
+ ).toBe("Ultrathink:\n".length);
+ });
+
+ it("skips Ultrathink for slash commands and does nothing when the prompt locks it", () => {
+ expect(
+ step({ ...CLAUDE, prompt: "/review", modelOptions: selections(["effort", "high"]) }),
+ ).toStrictEqual({
+ prompt: "/review",
+ cursor: 0,
+ modelOptions: selections(["effort", "medium"]),
+ });
+ for (const [prompt, direction] of [
+ ["Please ultrathink harder", 1],
+ ["Ultrathink:\nPlease ultrathink harder", -1],
+ ] as const) {
+ expect(
+ step({ ...CLAUDE, prompt, modelOptions: selections(["effort", "high"]), direction }),
+ prompt,
+ ).toBeNull();
+ }
+ });
+
+ it("keeps a provider-default Fast mode off unless the user chose it", () => {
+ const cursor = {
+ provider: ProviderDriverKind.make("cursor"),
+ instanceId: ProviderInstanceId.make("cursor"),
+ models: modelWith([
+ selectDescriptor("reasoning", LEVELS),
+ booleanDescriptor("fastMode", true),
+ ]),
+ };
+
+ expect(step({ ...cursor, modelOptions: undefined })?.modelOptions).toStrictEqual(
+ selections(["reasoning", "high"], ["fastMode", false]),
+ );
+ expect(
+ step({ ...cursor, modelOptions: selections(["fastMode", true]) })?.modelOptions,
+ ).toStrictEqual(selections(["reasoning", "high"], ["fastMode", true]));
+ });
+
+ it("steps from the provider-reported level for the same instance and model", () => {
+ const reported = {
+ instanceId: INSTANCE,
+ model: MODEL,
+ options: selections(["reasoningEffort", "high"]),
+ };
+ for (const { label, modelOptions, reportedModelSelection, to } of [
+ { label: "reported", modelOptions: undefined, reportedModelSelection: reported, to: "low" },
+ {
+ label: "other instance",
+ modelOptions: undefined,
+ reportedModelSelection: { ...reported, instanceId: ProviderInstanceId.make("codex-work") },
+ to: "high",
+ },
+ {
+ label: "other model",
+ modelOptions: undefined,
+ reportedModelSelection: { ...reported, model: "other-model" },
+ to: "high",
+ },
+ {
+ label: "explicit draft",
+ modelOptions: selections(["reasoningEffort", "low"]),
+ reportedModelSelection: reported,
+ to: "medium",
+ },
+ {
+ // OpenCode reports "default" when no variant was chosen.
+ label: "reported value outside the catalog",
+ modelOptions: undefined,
+ reportedModelSelection: {
+ ...reported,
+ options: selections(["reasoningEffort", "default"]),
+ },
+ to: "high",
+ },
+ ]) {
+ expect(step({ modelOptions, reportedModelSelection })?.modelOptions, label).toStrictEqual(
+ selections(["reasoningEffort", to]),
+ );
+ }
+ });
+});
diff --git a/apps/web/src/components/chat/composerProviderState.tsx b/apps/web/src/components/chat/composerProviderState.tsx
index 05eaa31ba7a..5944b431e51 100644
--- a/apps/web/src/components/chat/composerProviderState.tsx
+++ b/apps/web/src/components/chat/composerProviderState.tsx
@@ -19,7 +19,12 @@ import type { ReactNode } from "react";
import type { DraftId } from "../../composerDraftStore";
import { getProviderModelCapabilities } from "../../providerModels";
import type { ComposerControlSize } from "./ComposerControl";
-import { shouldRenderTraitsControls, TraitsMenuContent, TraitsPicker } from "./TraitsPicker";
+import {
+ getReasoningTraitStep,
+ shouldRenderTraitsControls,
+ TraitsMenuContent,
+ TraitsPicker,
+} from "./TraitsPicker";
export type ComposerProviderStateInput = {
provider: ProviderDriverKind;
@@ -157,6 +162,61 @@ export function getComposerProviderState(input: ComposerProviderStateInput): Com
};
}
+/**
+ * `cursor` is an expanded caret in `prompt`; the result's `cursor` keeps it on
+ * the same character when the Ultrathink prefix is added or removed.
+ */
+export function getComposerReasoningStep(input: {
+ provider: ProviderDriverKind;
+ instanceId: ProviderInstanceId;
+ model: string;
+ models: ReadonlyArray<ServerProviderModel>;
+ modelOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined;
+ reportedModelSelection?: ModelSelection | null | undefined;
+ prompt: string;
+ cursor: number;
+ planModeEnabled: boolean;
+ direction: 1 | -1;
+}): {
+ prompt: string;
+ cursor: number;
+ modelOptions?: ReadonlyArray<ProviderOptionSelection>;
+} | null {
+ const { prompt, cursor } = input;
+ const { selections } = resolveComposerOptionSelections(
+ input.models,
+ input.model,
+ input.provider,
+ input.modelOptions,
+ input.planModeEnabled,
+ );
+ const step = getReasoningTraitStep({
+ provider: input.provider,
+ instanceId: input.instanceId,
+ model: input.model,
+ models: input.models,
+ modelOptions: selections,
+ reportedModelSelection: input.reportedModelSelection,
+ prompt,
+ planModeEnabled: input.planModeEnabled,
+ direction: input.direction,
+ });
+ if (!step) return null;
+ const modelOptions = "modelOptions" in step ? { modelOptions: step.modelOptions } : {};
+ if (step.prompt === prompt) return { prompt, cursor, ...modelOptions };
+ // Adding the prefix also trims the prompt, so the kept text starts right after the prefix.
+ const keptStart = "modelOptions" in step ? 0 : step.prompt.length - prompt.trim().length;
+ const offset =
+ "modelOptions" in step
+ ? step.prompt.length - prompt.length
+ : keptStart - (prompt.length - prompt.trimStart().length);
+ return {
+ prompt: step.prompt,
+ cursor: Math.min(step.prompt.length, Math.max(keptStart, cursor + offset)),
+ ...modelOptions,
+ };
+}
+
function renderTraitsControl(
Component: typeof TraitsMenuContent | typeof TraitsPicker,
input: TraitsRenderInput,
diff --git a/docs/user/keybindings.md b/docs/user/keybindings.md
index 5a0a699e10d..794cac90e7a 100644
--- a/docs/user/keybindings.md
+++ b/docs/user/keybindings.md
@@ -29,6 +29,11 @@ workspace, and `mod+shift+g` for the Git branch. The workspace menu includes the
current checkout, a new worktree, and the previous worktree when available.
Use `mod+shift+l` to reuse the previous worktree directly.
+To change effort one step without opening the picker, bind
+**Composer: Increase Effort** and **Composer: Decrease Effort** in Keybindings.
+Both are unbound by default. Increase wraps from the highest level to the
+lowest, and decrease wraps from the lowest level to the highest.
+
In the model picker, press Left in an empty search field or Shift+Tab to reach
the provider list. Use Up/Down to move and Enter to choose. Right returns to
model search. `mod+shift+up` and `mod+shift+down` switch providers directly and clear the
diff --git a/packages/contracts/src/keybindings.ts b/packages/contracts/src/keybindings.ts
index 4f966ba909f..07cdd6d9dc5 100644
--- a/packages/contracts/src/keybindings.ts
+++ b/packages/contracts/src/keybindings.ts
@@ -93,6 +93,8 @@ export const STATIC_KEYBINDING_COMMANDS = [
"composer.host",
"composer.cycleHost",
"composer.effort",
+ "composer.increaseEffort",
+ "composer.decreaseEffort",
"composer.mode",
"composer.workspace",
"composer.previousWorktree",