@devries-cameron20 / t3code Mirror · read-only / commits / 2993dfc069
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 05:30 UTC

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

Co-authored-by: Bil0000 <62337003+Bil0000@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Bilal Bakr committed Oct 17, 2026 at 08:43 UTC 2993dfc069115ed590d00741dd58013889387793
7 files changed +419 -26
apps/web/src/components/ChatView.tsx
+6
@@ -5671,6 +5671,12 @@ export default function ChatView(props: ChatViewProps) {
5671 "modelPicker.toggle": ({ event }) => {
5672 if (!event.repeat) composerRef.current?.toggleModelPicker();
5673 },
5674 + "composer.increaseEffort": ({ event }) => {
5675 + if (!event.repeat) composerRef.current?.stepReasoningEffort(1);
5676 + },
5677 + "composer.decreaseEffort": ({ event }) => {
5678 + if (!event.repeat) composerRef.current?.stepReasoningEffort(-1);
5679 + },
5680 "composer.host": openComposerControl("composer.host"),
5681 "composer.effort": openComposerControl("composer.effort"),
5682 "composer.mode": openComposerControl("composer.mode"),
apps/web/src/components/chat/ChatComposer.tsx
+45
@@ -305,6 +305,7 @@ import {
305 import {
306 getComposerPromptInjectionState,
307 getComposerProviderState,
308 + getComposerReasoningStep,
309 renderProviderTraitsMenuContent,
310 renderProviderTraitsPicker,
311 } from "./composerProviderState";
@@ -1435,6 +1436,7 @@ export interface ChatComposerHandle {
1436 sourceAnchor: AssistantCitationSourceAnchor,
1437 ) => boolean;
1438 openModelPicker: () => void;
1439 + stepReasoningEffort: (direction: 1 | -1) => void;
1440 toggleModelPicker: () => void;
1441 openControl: (command: KeybindingCommand) => void;
1442 isModelPickerOpen: () => boolean;
@@ -6040,6 +6042,44 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
6042 { ensureLeadingBoundary: true, citationCommentAnchor: sourceAnchor },
6043 ),
6044 openModelPicker: openModelPickerStable,
6045 + stepReasoningEffort: (direction) => {
6046 + if (
6047 + noProviderAvailable ||
6048 + isComposerApprovalState ||
6049 + pendingUserInputs.length > 0 ||
6050 + // A queued-message edit draft is discarded when the edit ends.
6051 + isEditingQueuedMessage
6052 + ) {
6053 + return;
6054 + }
6055 + const change = getComposerReasoningStep({
6056 + provider: selectedProvider,
6057 + instanceId: selectedInstanceId,
6058 + model: selectedModel,
6059 + models: selectedProviderModels,
6060 + modelOptions: composerModelOptions?.[selectedInstanceId],
6061 + reportedModelSelection,
6062 + prompt: promptRef.current,
6063 + cursor: readComposerSnapshotStable().expandedCursor,
6064 + planModeEnabled: settings.planModeEnabled,
6065 + direction,
6066 + });
6067 + if (!change) return;
6068 + if (change.modelOptions) {
6069 + useComposerDraftStore
6070 + .getState()
6071 + .setProviderModelOptions(composerDraftTarget, selectedProvider, change.modelOptions, {
6072 + instanceId: selectedInstanceId,
6073 + model: selectedModel,
6074 + persistSticky: true,
6075 + });
6076 + }
6077 + if (change.prompt !== promptRef.current) {
6078 + applyPromptReplacementStable(0, promptRef.current.length, change.prompt, {
6079 + expandedCursorAfterReplace: change.cursor,
6080 + });
6081 + }
6082 + },
6083 toggleModelPicker: () => {
6084 if (isComposerModelPickerOpen) {
6085 setIsComposerModelPickerOpen(false);
@@ -6179,6 +6219,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
6219 addComposerAttachments,
6220 foldPastedText,
6221 composerDraftTarget,
6222 + composerModelOptions,
6223 + isEditingQueuedMessage,
6224 composerCursor,
6225 activePendingProgress,
6226 composerTerminalContexts,
@@ -6207,6 +6249,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
6249 resetComposerTrigger,
6250 setComposerTrigger,
6251 selectedModel,
6252 + selectedInstanceId,
6253 + reportedModelSelection,
6254 + settings.planModeEnabled,
6255 selectedModelOptionsForDispatch,
6256 selectedModelSelection,
6257 multipleModelSelections,
apps/web/src/components/chat/TraitsPicker.tsx
+114 -25
@@ -91,6 +91,14 @@ type TraitsPersistence =
91
92 const ULTRATHINK_PROMPT_PREFIX = "Ultrathink:\n";
93
94 +const REASONING_SELECT_DESCRIPTOR_IDS: ReadonlySet<string> = new Set([
95 + "reasoningEffort",
96 + "reasoning",
97 + "effort",
98 + "variant",
99 + "thinking",
100 +]);
101 +
102 function DefaultBadge() {
103 return (
104 <Badge variant="outline" size="sm" className="min-w-0">
@@ -253,6 +261,97 @@ function getTraitsSectionVisibility(input: {
261 };
262 }
263
264 +function getTraitSelectChange(
265 + selected: ReturnType<typeof getSelectedTraits>,
266 + descriptor: Extract<ProviderOptionDescriptor, { type: "select" }>,
267 + prompt: string,
268 + value: string,
269 +) {
270 + if (!value) return null;
271 + if (descriptor.promptInjectedValues?.includes(value)) {
272 + return {
273 + prompt:
274 + prompt.trim().length === 0
275 + ? ULTRATHINK_PROMPT_PREFIX
276 + : applyClaudePromptEffortPrefix(prompt, "ultrathink"),
277 + };
278 + }
279 + const isPrimary = descriptor.id === selected.primarySelectDescriptor?.id;
280 + if (isPrimary && selected.ultrathinkInBodyText) return null;
281 + return {
282 + prompt:
283 + isPrimary && selected.ultrathinkPromptControlled
284 + ? prompt.replace(/^Ultrathink:\s*/i, "")
285 + : prompt,
286 + modelOptions: buildProviderOptionSelectionsFromDescriptors(
287 + replaceDescriptorCurrentValue(selected.descriptors, descriptor.id, value),
288 + ),
289 + };
290 +}
291 +
292 +/**
293 + * `modelOptions` must already carry the composer's implicit defaults (see
294 + * `withImplicitFastModeDefault`) so the persisted selection matches what the
295 + * picker would write.
296 + */
297 +export function getReasoningTraitStep(input: {
298 + provider: ProviderDriverKind;
299 + instanceId: ProviderInstanceId;
300 + model: string;
301 + models: ReadonlyArray<ServerProviderModel>;
302 + modelOptions: ProviderOptions | undefined;
303 + reportedModelSelection: ModelSelection | null | undefined;
304 + prompt: string;
305 + planModeEnabled: boolean;
306 + direction: 1 | -1;
307 +}) {
308 + const selected = getSelectedTraits(
309 + input.provider,
310 + input.models,
311 + input.model,
312 + input.prompt,
313 + input.modelOptions,
314 + true,
315 + input.planModeEnabled,
316 + );
317 + if (selected.modelIsUnavailable || selected.ultrathinkInBodyText) return null;
318 + const descriptor = selected.selectDescriptors.find((entry) =>
319 + REASONING_SELECT_DESCRIPTOR_IDS.has(entry.id),
320 + );
321 + if (!descriptor || descriptor.options.length < 2) return null;
322 + const isPrimary = descriptor.id === selected.primarySelectDescriptor?.id;
323 + const current =
324 + isPrimary && selected.ultrathinkPromptControlled
325 + ? "ultrathink"
326 + : getDescriptorStringValue(
327 + descriptor,
328 + { instanceId: input.instanceId, model: input.model, options: input.modelOptions ?? [] },
329 + input.reportedModelSelection,
330 + );
331 + const ordered = input.direction > 0 ? descriptor.options : descriptor.options.toReversed();
332 + // A reported value outside the catalog, such as OpenCode's "default", steps
333 + // from the catalog default, or from the end when there is none.
334 + const position =
335 + [current, getDescriptorStringValue(descriptor)]
336 + .map((value) => ordered.findIndex((option) => option.id === value))
337 + .find((index) => index >= 0) ?? -1;
338 + for (const option of [
339 + ...ordered.slice(position + 1),
340 + ...ordered.slice(0, Math.max(position, 0)),
341 + ]) {
342 + const change = getTraitSelectChange(selected, descriptor, input.prompt, option.id);
343 + if (!change) return null;
344 + if ("modelOptions" in change) {
345 + return change.modelOptions
346 + ? { prompt: change.prompt, modelOptions: change.modelOptions }
347 + : null;
348 + }
349 + // A slash command refuses the Ultrathink prefix, so skip that level.
350 + if (change.prompt.startsWith(ULTRATHINK_PROMPT_PREFIX)) return change;
351 + }
352 + return null;
353 +}
354 +
355 export function shouldRenderTraitsControls(input: {
356 provider: ProviderDriverKind;
357 models: ReadonlyArray<ServerProviderModel>;
@@ -311,6 +410,15 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
410 persistSticky: true,
411 });
412 };
413 + const selected = getTraitsSectionVisibility({
414 + provider,
415 + models,
416 + model,
417 + prompt,
418 + modelOptions,
419 + allowPromptInjectedEffort,
420 + planModeEnabled,
421 + });
422 const {
423 descriptors,
424 selectDescriptors,
@@ -320,15 +428,7 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
428 ultrathinkInBodyText,
429 hasAnyControls,
430 modelIsUnavailable,
323 - } = getTraitsSectionVisibility({
324 - provider,
325 - models,
326 - model,
327 - prompt,
328 - modelOptions,
329 - allowPromptInjectedEffort,
330 - planModeEnabled,
331 - });
431 + } = selected;
432 const updateDescriptors = (nextDescriptors: ReadonlyArray<ProviderOptionDescriptor>) => {
433 updateModelOptions(buildProviderOptionSelectionsFromDescriptors(nextDescriptors));
434 };
@@ -337,21 +437,10 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
437 descriptor: Extract<ProviderOptionDescriptor, { type: "select" }>,
438 value: string,
439 ) => {
340 - if (!value) return;
341 - if (descriptor.promptInjectedValues?.includes(value)) {
342 - const nextPrompt =
343 - prompt.trim().length === 0
344 - ? ULTRATHINK_PROMPT_PREFIX
345 - : applyClaudePromptEffortPrefix(prompt, "ultrathink");
346 - onPromptChange(nextPrompt);
347 - return;
348 - }
349 - if (ultrathinkInBodyText && descriptor.id === primarySelectDescriptor?.id) return;
350 - if (ultrathinkPromptControlled && descriptor.id === primarySelectDescriptor?.id) {
351 - const stripped = prompt.replace(/^Ultrathink:\s*/i, "");
352 - onPromptChange(stripped);
353 - }
354 - updateDescriptors(replaceDescriptorCurrentValue(descriptors, descriptor.id, value));
440 + const change = getTraitSelectChange(selected, descriptor, prompt, value);
441 + if (!change) return;
442 + if (change.prompt !== prompt) onPromptChange(change.prompt);
443 + if ("modelOptions" in change) updateModelOptions(change.modelOptions);
444 };
445
446 if (!hasAnyControls) {
@@ -534,7 +623,7 @@ export function buildTraitsTriggerDisplay(input: {
623 if (
624 reasoningLabelIndex === -1 &&
625 descriptor.type === "select" &&
537 - ["reasoningEffort", "reasoning", "effort", "variant", "thinking"].includes(descriptor.id)
626 + REASONING_SELECT_DESCRIPTOR_IDS.has(descriptor.id)
627 ) {
628 reasoningLabelIndex = labels.length;
629 }
apps/web/src/components/chat/composerProviderState.test.tsx
+186
@@ -1,6 +1,7 @@
1 import { describe, expect, it } from "vite-plus/test";
2 import {
3 ProviderDriverKind,
4 + ProviderInstanceId,
5 type ProviderOptionDescriptor,
6 type ProviderOptionSelection,
7 type ServerProviderModel,
@@ -10,6 +11,7 @@ import { getProviderModelCapabilities } from "../../providerModels";
11 import {
12 getComposerPromptInjectionState,
13 getComposerProviderState,
14 + getComposerReasoningStep,
15 renderProviderTraitsMenuContent,
16 renderProviderTraitsPicker,
17 withImplicitFastModeDefault,
@@ -486,3 +488,187 @@ describe("provider traits render guards", () => {
488 expect(renderProviderTraitsMenuContent(args)).toBeNull();
489 });
490 });
491 +
492 +describe("getComposerReasoningStep", () => {
493 + const LEVELS = [
494 + { id: "low", label: "Low" },
495 + { id: "medium", label: "Medium", isDefault: true },
496 + { id: "high", label: "High" },
497 + ];
498 + const INSTANCE = ProviderInstanceId.make("codex");
499 + const CLAUDE = {
500 + provider: ProviderDriverKind.make("claudeAgent"),
501 + instanceId: ProviderInstanceId.make("claudeAgent"),
502 + models: modelWith([
503 + selectDescriptor(
504 + "effort",
505 + [
506 + { id: "medium", label: "Medium" },
507 + { id: "high", label: "High", isDefault: true },
508 + { id: "ultrathink", label: "Ultrathink" },
509 + ],
510 + ["ultrathink"],
511 + ),
512 + ]),
513 + };
514 +
515 + function step(input: Partial<Parameters<typeof getComposerReasoningStep>[0]>) {
516 + return getComposerReasoningStep({
517 + provider: PROVIDER,
518 + instanceId: INSTANCE,
519 + model: MODEL,
520 + models: modelWith([selectDescriptor("reasoningEffort", LEVELS)]),
521 + modelOptions: undefined,
522 + prompt: "Fix the bug",
523 + cursor: 0,
524 + planModeEnabled: true,
525 + direction: 1,
526 + ...input,
527 + });
528 + }
529 +
530 + it("walks the catalog order, wrapping at both ends and keeping the other traits", () => {
531 + const models = modelWith([
532 + selectDescriptor("contextWindow", [
533 + { id: "200k", label: "200k", isDefault: true },
534 + { id: "1m", label: "1M" },
535 + ]),
536 + selectDescriptor("reasoningEffort", LEVELS),
537 + ]);
538 + for (const [from, direction, to] of [
539 + ["low", -1, "high"],
540 + ["low", 1, "medium"],
541 + ["high", 1, "low"],
542 + ["high", -1, "medium"],
543 + ] as const) {
544 + expect(
545 + step({
546 + models,
547 + modelOptions: selections(["contextWindow", "1m"], ["reasoningEffort", from]),
548 + direction,
549 + }),
550 + `${from} by ${direction}`,
551 + ).toStrictEqual({
552 + prompt: "Fix the bug",
553 + cursor: 0,
554 + modelOptions: selections(["contextWindow", "1m"], ["reasoningEffort", to]),
555 + });
556 + }
557 + });
558 +
559 + it("adds and strips the Ultrathink prefix while the caret stays on the same character", () => {
560 + for (const { prompt, modelOptions, direction, expected } of [
561 + {
562 + prompt: " Fix the bug \n",
563 + modelOptions: selections(["effort", "high"]),
564 + direction: 1,
565 + expected: { prompt: "Ultrathink:\nFix the bug", cursor: 20 },
566 + },
567 + {
568 + // The prefix, not the draft's Medium, is the current level.
569 + prompt: "Ultrathink:\n Fix the bug",
570 + modelOptions: selections(["effort", "medium"]),
571 + direction: -1,
572 + expected: {
573 + prompt: "Fix the bug",
574 + cursor: 8,
575 + modelOptions: selections(["effort", "high"]),
576 + },
577 + },
578 + ] as const) {
579 + const result = step({
580 + ...CLAUDE,
581 + prompt,
582 + cursor: prompt.indexOf("bug"),
583 + modelOptions,
584 + direction,
585 + });
586 + expect(result).toStrictEqual(expected);
587 + expect(result?.prompt.slice(result.cursor)).toMatch(/^bug/);
588 + }
589 + // A caret in leading whitespace must not land inside the new prefix.
590 + expect(
591 + step({ ...CLAUDE, prompt: " Fix", modelOptions: selections(["effort", "high"]) })?.cursor,
592 + ).toBe("Ultrathink:\n".length);
593 + });
594 +
595 + it("skips Ultrathink for slash commands and does nothing when the prompt locks it", () => {
596 + expect(
597 + step({ ...CLAUDE, prompt: "/review", modelOptions: selections(["effort", "high"]) }),
598 + ).toStrictEqual({
599 + prompt: "/review",
600 + cursor: 0,
601 + modelOptions: selections(["effort", "medium"]),
602 + });
603 + for (const [prompt, direction] of [
604 + ["Please ultrathink harder", 1],
605 + ["Ultrathink:\nPlease ultrathink harder", -1],
606 + ] as const) {
607 + expect(
608 + step({ ...CLAUDE, prompt, modelOptions: selections(["effort", "high"]), direction }),
609 + prompt,
610 + ).toBeNull();
611 + }
612 + });
613 +
614 + it("keeps a provider-default Fast mode off unless the user chose it", () => {
615 + const cursor = {
616 + provider: ProviderDriverKind.make("cursor"),
617 + instanceId: ProviderInstanceId.make("cursor"),
618 + models: modelWith([
619 + selectDescriptor("reasoning", LEVELS),
620 + booleanDescriptor("fastMode", true),
621 + ]),
622 + };
623 +
624 + expect(step({ ...cursor, modelOptions: undefined })?.modelOptions).toStrictEqual(
625 + selections(["reasoning", "high"], ["fastMode", false]),
626 + );
627 + expect(
628 + step({ ...cursor, modelOptions: selections(["fastMode", true]) })?.modelOptions,
629 + ).toStrictEqual(selections(["reasoning", "high"], ["fastMode", true]));
630 + });
631 +
632 + it("steps from the provider-reported level for the same instance and model", () => {
633 + const reported = {
634 + instanceId: INSTANCE,
635 + model: MODEL,
636 + options: selections(["reasoningEffort", "high"]),
637 + };
638 + for (const { label, modelOptions, reportedModelSelection, to } of [
639 + { label: "reported", modelOptions: undefined, reportedModelSelection: reported, to: "low" },
640 + {
641 + label: "other instance",
642 + modelOptions: undefined,
643 + reportedModelSelection: { ...reported, instanceId: ProviderInstanceId.make("codex-work") },
644 + to: "high",
645 + },
646 + {
647 + label: "other model",
648 + modelOptions: undefined,
649 + reportedModelSelection: { ...reported, model: "other-model" },
650 + to: "high",
651 + },
652 + {
653 + label: "explicit draft",
654 + modelOptions: selections(["reasoningEffort", "low"]),
655 + reportedModelSelection: reported,
656 + to: "medium",
657 + },
658 + {
659 + // OpenCode reports "default" when no variant was chosen.
660 + label: "reported value outside the catalog",
661 + modelOptions: undefined,
662 + reportedModelSelection: {
663 + ...reported,
664 + options: selections(["reasoningEffort", "default"]),
665 + },
666 + to: "high",
667 + },
668 + ]) {
669 + expect(step({ modelOptions, reportedModelSelection })?.modelOptions, label).toStrictEqual(
670 + selections(["reasoningEffort", to]),
671 + );
672 + }
673 + });
674 +});
apps/web/src/components/chat/composerProviderState.tsx
+61 -1
@@ -19,7 +19,12 @@ import type { ReactNode } from "react";
19 import type { DraftId } from "../../composerDraftStore";
20 import { getProviderModelCapabilities } from "../../providerModels";
21 import type { ComposerControlSize } from "./ComposerControl";
22 -import { shouldRenderTraitsControls, TraitsMenuContent, TraitsPicker } from "./TraitsPicker";
22 +import {
23 + getReasoningTraitStep,
24 + shouldRenderTraitsControls,
25 + TraitsMenuContent,
26 + TraitsPicker,
27 +} from "./TraitsPicker";
28
29 export type ComposerProviderStateInput = {
30 provider: ProviderDriverKind;
@@ -157,6 +162,61 @@ export function getComposerProviderState(input: ComposerProviderStateInput): Com
162 };
163 }
164
165 +/**
166 + * `cursor` is an expanded caret in `prompt`; the result's `cursor` keeps it on
167 + * the same character when the Ultrathink prefix is added or removed.
168 + */
169 +export function getComposerReasoningStep(input: {
170 + provider: ProviderDriverKind;
171 + instanceId: ProviderInstanceId;
172 + model: string;
173 + models: ReadonlyArray<ServerProviderModel>;
174 + modelOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined;
175 + reportedModelSelection?: ModelSelection | null | undefined;
176 + prompt: string;
177 + cursor: number;
178 + planModeEnabled: boolean;
179 + direction: 1 | -1;
180 +}): {
181 + prompt: string;
182 + cursor: number;
183 + modelOptions?: ReadonlyArray<ProviderOptionSelection>;
184 +} | null {
185 + const { prompt, cursor } = input;
186 + const { selections } = resolveComposerOptionSelections(
187 + input.models,
188 + input.model,
189 + input.provider,
190 + input.modelOptions,
191 + input.planModeEnabled,
192 + );
193 + const step = getReasoningTraitStep({
194 + provider: input.provider,
195 + instanceId: input.instanceId,
196 + model: input.model,
197 + models: input.models,
198 + modelOptions: selections,
199 + reportedModelSelection: input.reportedModelSelection,
200 + prompt,
201 + planModeEnabled: input.planModeEnabled,
202 + direction: input.direction,
203 + });
204 + if (!step) return null;
205 + const modelOptions = "modelOptions" in step ? { modelOptions: step.modelOptions } : {};
206 + if (step.prompt === prompt) return { prompt, cursor, ...modelOptions };
207 + // Adding the prefix also trims the prompt, so the kept text starts right after the prefix.
208 + const keptStart = "modelOptions" in step ? 0 : step.prompt.length - prompt.trim().length;
209 + const offset =
210 + "modelOptions" in step
211 + ? step.prompt.length - prompt.length
212 + : keptStart - (prompt.length - prompt.trimStart().length);
213 + return {
214 + prompt: step.prompt,
215 + cursor: Math.min(step.prompt.length, Math.max(keptStart, cursor + offset)),
216 + ...modelOptions,
217 + };
218 +}
219 +
220 function renderTraitsControl(
221 Component: typeof TraitsMenuContent | typeof TraitsPicker,
222 input: TraitsRenderInput,
docs/user/keybindings.md
+5
@@ -29,6 +29,11 @@ workspace, and `mod+shift+g` for the Git branch. The workspace menu includes the
29 current checkout, a new worktree, and the previous worktree when available.
30 Use `mod+shift+l` to reuse the previous worktree directly.
31
32 +To change effort one step without opening the picker, bind
33 +**Composer: Increase Effort** and **Composer: Decrease Effort** in Keybindings.
34 +Both are unbound by default. Increase wraps from the highest level to the
35 +lowest, and decrease wraps from the lowest level to the highest.
36 +
37 In the model picker, press Left in an empty search field or Shift+Tab to reach
38 the provider list. Use Up/Down to move and Enter to choose. Right returns to
39 model search. `mod+shift+up` and `mod+shift+down` switch providers directly and clear the
packages/contracts/src/keybindings.ts
+2
@@ -93,6 +93,8 @@ export const STATIC_KEYBINDING_COMMANDS = [
93 "composer.host",
94 "composer.cycleHost",
95 "composer.effort",
96 + "composer.increaseEffort",
97 + "composer.decreaseEffort",
98 "composer.mode",
99 "composer.workspace",
100 "composer.previousWorktree",