Skip to content

Commit 517be31

Browse files
committed
feat(web): add shortcuts to step reasoning effort
1 parent 42da166 commit 517be31

9 files changed

Lines changed: 337 additions & 26 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8090,6 +8090,15 @@ export default function ChatView(props: ChatViewProps) {
80908090
return;
80918091
}
80928092

8093+
if (command === "reasoning.increase" || command === "reasoning.decrease") {
8094+
event.preventDefault();
8095+
event.stopPropagation();
8096+
if (!event.repeat) {
8097+
composerRef.current?.adjustReasoningLevel(command === "reasoning.increase" ? 1 : -1);
8098+
}
8099+
return;
8100+
}
8101+
80938102
if (
80948103
command === "composer.host" ||
80958104
command === "composer.effort" ||

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ import {
294294
ComposerSelectControl,
295295
} from "./ComposerControl";
296296
import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
297+
import { getReasoningLevelChange } from "./TraitsPicker";
297298
import { buildPullRequestReferenceContext } from "../pullRequest/pullRequestDetail.logic";
298299
import {
299300
matchesPullRequestQuery,
@@ -1486,6 +1487,7 @@ export interface ChatComposerHandle {
14861487
sourceAnchor: AssistantCitationSourceAnchor,
14871488
) => boolean;
14881489
openModelPicker: () => void;
1490+
adjustReasoningLevel: (direction: 1 | -1) => void;
14891491
toggleModelPicker: () => void;
14901492
openControl: (command: KeybindingCommand) => void;
14911493
isModelPickerOpen: () => boolean;
@@ -6392,6 +6394,38 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
63926394
{ ensureLeadingBoundary: true, citationCommentAnchor: sourceAnchor },
63936395
),
63946396
openModelPicker: openModelPickerStable,
6397+
adjustReasoningLevel: (direction) => {
6398+
if (noProviderAvailable || isComposerApprovalState || pendingUserInputs.length > 0) return;
6399+
const store = useComposerDraftStore.getState();
6400+
const modelOptions =
6401+
store.getComposerDraft(composerDraftTarget)?.modelSelectionByProvider[selectedInstanceId]
6402+
?.options ?? composerModelOptions?.[selectedInstanceId];
6403+
const change = getReasoningLevelChange({
6404+
provider: selectedProvider,
6405+
instanceId: selectedInstanceId,
6406+
models: selectedProviderModels,
6407+
model: selectedModel,
6408+
modelOptions,
6409+
reportedModelSelection,
6410+
prompt: promptRef.current,
6411+
planModeEnabled: settings.planModeEnabled,
6412+
direction,
6413+
});
6414+
if (!change) return;
6415+
if ("modelOptions" in change) {
6416+
store.setProviderModelOptions(
6417+
composerDraftTarget,
6418+
selectedProvider,
6419+
change.modelOptions,
6420+
{
6421+
instanceId: selectedInstanceId,
6422+
model: selectedModel,
6423+
persistSticky: true,
6424+
},
6425+
);
6426+
}
6427+
if (change.prompt !== promptRef.current) setPromptFromTraitsStable(change.prompt);
6428+
},
63956429
toggleModelPicker: () => {
63966430
if (isComposerModelPickerOpen) {
63976431
setIsComposerModelPickerOpen(false);
@@ -6531,6 +6565,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
65316565
addComposerAttachments,
65326566
foldPastedText,
65336567
composerDraftTarget,
6568+
composerModelOptions,
65346569
composerCursor,
65356570
activePendingProgress,
65366571
composerTerminalContexts,
@@ -6559,6 +6594,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
65596594
resetComposerTrigger,
65606595
setComposerTrigger,
65616596
selectedModel,
6597+
selectedInstanceId,
6598+
reportedModelSelection,
6599+
setPromptFromTraitsStable,
6600+
settings.planModeEnabled,
65626601
selectedModelOptionsForDispatch,
65636602
selectedModelSelection,
65646603
multipleModelSelections,

‎apps/web/src/components/chat/TraitsPicker.test.ts‎

Lines changed: 180 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import {
33
ProviderInstanceId,
44
ProviderDriverKind,
55
type ProviderOptionDescriptor,
6+
type ServerProviderModel,
67
} from "@t3tools/contracts";
7-
import { buildTraitsTriggerDisplay, buildUnavailableModelOptionDescriptors } from "./TraitsPicker";
8+
import {
9+
buildTraitsTriggerDisplay,
10+
buildUnavailableModelOptionDescriptors,
11+
getReasoningLevelChange,
12+
} from "./TraitsPicker";
813

914
function selectDescriptor(
1015
id: string,
@@ -56,6 +61,180 @@ const CONTEXT_WINDOW = selectDescriptor(
5661

5762
const CODEX = ProviderDriverKind.make("codex");
5863

64+
describe("reasoning level shortcuts", () => {
65+
const options = [
66+
{ id: "low", label: "Low" },
67+
{ id: "high", label: "High", isDefault: true },
68+
{ id: "ultrathink", label: "Ultrathink" },
69+
];
70+
const modelWith = (
71+
descriptors: ReadonlyArray<ProviderOptionDescriptor>,
72+
): ServerProviderModel[] => [
73+
{
74+
slug: "test-model",
75+
name: "Test",
76+
isCustom: false,
77+
capabilities: { optionDescriptors: descriptors },
78+
},
79+
];
80+
const input = {
81+
provider: CODEX,
82+
model: "test-model",
83+
models: modelWith([
84+
{ ...selectDescriptor("effort", options, "high"), promptInjectedValues: ["ultrathink"] },
85+
fastModeDescriptor(false),
86+
]),
87+
modelOptions: [{ id: "fastMode", value: true }],
88+
prompt: "Solve this",
89+
planModeEnabled: false,
90+
direction: -1 as const,
91+
};
92+
93+
it("steps from the default and keeps other traits", () => {
94+
expect(getReasoningLevelChange(input)).toEqual({
95+
prompt: "Solve this",
96+
modelOptions: [
97+
{ id: "effort", value: "low" },
98+
{ id: "fastMode", value: true },
99+
],
100+
});
101+
expect(
102+
getReasoningLevelChange({
103+
...input,
104+
models: modelWith([{ id: "effort", label: "Effort", type: "select", options }]),
105+
})?.modelOptions,
106+
).toEqual([{ id: "effort", value: "low" }]);
107+
});
108+
109+
it("steps from the displayed reported value unless the draft overrides it", () => {
110+
const instanceId = ProviderInstanceId.make("custom-codex");
111+
const reportedModelSelection = {
112+
instanceId,
113+
model: "test-model",
114+
options: [{ id: "effort", value: "low" }],
115+
};
116+
const reportedInput = { ...input, instanceId, reportedModelSelection, direction: 1 as const };
117+
expect(getReasoningLevelChange(reportedInput)?.modelOptions).toEqual([
118+
{ id: "effort", value: "high" },
119+
{ id: "fastMode", value: true },
120+
]);
121+
expect(
122+
getReasoningLevelChange({
123+
...reportedInput,
124+
modelOptions: [{ id: "effort", value: "high" }],
125+
}),
126+
).toEqual({ prompt: "Ultrathink:\nSolve this" });
127+
expect(
128+
getReasoningLevelChange({
129+
...reportedInput,
130+
reportedModelSelection: {
131+
...reportedModelSelection,
132+
instanceId: ProviderInstanceId.make("another-codex"),
133+
},
134+
}),
135+
).toEqual({ prompt: "Ultrathink:\nSolve this" });
136+
expect(
137+
getReasoningLevelChange({
138+
...reportedInput,
139+
reportedModelSelection: { ...reportedModelSelection, model: "another-model" },
140+
}),
141+
).toEqual({ prompt: "Ultrathink:\nSolve this" });
142+
});
143+
144+
it("uses a catalog default for an unset OpenCode variant", () => {
145+
expect(
146+
getReasoningLevelChange({
147+
...input,
148+
provider: ProviderDriverKind.make("opencode"),
149+
instanceId: ProviderInstanceId.make("opencode"),
150+
models: modelWith([selectDescriptor("variant", options, "high")]),
151+
})?.modelOptions,
152+
).toEqual([{ id: "variant", value: "low" }]);
153+
});
154+
155+
it("stops at both ends", () => {
156+
expect(
157+
getReasoningLevelChange({ ...input, modelOptions: [{ id: "effort", value: "low" }] }),
158+
).toBeNull();
159+
expect(
160+
getReasoningLevelChange({ ...input, prompt: "Ultrathink:\nSolve this", direction: 1 }),
161+
).toBeNull();
162+
});
163+
164+
it("enters and leaves prompt-controlled ultrathink", () => {
165+
expect(getReasoningLevelChange({ ...input, direction: 1 })).toEqual({
166+
prompt: "Ultrathink:\nSolve this",
167+
});
168+
expect(getReasoningLevelChange({ ...input, prompt: "Ultrathink:\nSolve this" })).toEqual({
169+
prompt: "Solve this",
170+
modelOptions: [
171+
{ id: "effort", value: "high" },
172+
{ id: "fastMode", value: true },
173+
],
174+
});
175+
expect(
176+
getReasoningLevelChange({ ...input, prompt: "Please ultrathink about this" }),
177+
).toBeNull();
178+
});
179+
180+
it("preserves slash commands and can add the prefix to an empty prompt", () => {
181+
expect(getReasoningLevelChange({ ...input, prompt: "/review", direction: 1 })).toEqual({
182+
prompt: "/review",
183+
});
184+
expect(getReasoningLevelChange({ ...input, prompt: "", direction: 1 })).toEqual({
185+
prompt: "Ultrathink:\n",
186+
});
187+
});
188+
189+
it.each([
190+
["codex", "reasoningEffort"],
191+
["claudeAgent", "effort"],
192+
["cursor", "reasoning"],
193+
["grok", "reasoningEffort"],
194+
["opencode", "variant"],
195+
["antigravity", "thinking"],
196+
])("uses %s model choices in catalog order", (provider, id) => {
197+
expect(
198+
getReasoningLevelChange({
199+
...input,
200+
provider: ProviderDriverKind.make(provider),
201+
models: modelWith([CONTEXT_WINDOW, selectDescriptor(id, options, "high")]),
202+
})?.modelOptions,
203+
).toEqual([
204+
{ id: "contextWindow", value: "1m" },
205+
{ id, value: "low" },
206+
]);
207+
});
208+
209+
it.each(["agent", "contextWindow"])("does not change %s options", (id) => {
210+
expect(
211+
getReasoningLevelChange({
212+
...input,
213+
models: modelWith([selectDescriptor(id, options, "high")]),
214+
}),
215+
).toBeNull();
216+
});
217+
218+
it("does nothing without an available effort choice", () => {
219+
expect(getReasoningLevelChange({ ...input, models: [] })).toBeNull();
220+
expect(getReasoningLevelChange({ ...input, models: modelWith([]) })).toBeNull();
221+
expect(
222+
getReasoningLevelChange({
223+
...input,
224+
models: modelWith([selectDescriptor("effort", options, "stale")]),
225+
}),
226+
).toBeNull();
227+
expect(
228+
getReasoningLevelChange({
229+
...input,
230+
provider: ProviderDriverKind.make("opencode"),
231+
models: [],
232+
modelOptions: [{ id: "variant", value: "high" }],
233+
}),
234+
).toBeNull();
235+
});
236+
});
237+
59238
function display(descriptors: ReadonlyArray<ProviderOptionDescriptor>) {
60239
return buildTraitsTriggerDisplay({
61240
provider: CODEX,

0 commit comments

Comments
 (0)