Skip to content

Commit 816662b

Browse files
fix(web): effort steps work from unknown levels and skip Ultrathink for slash commands
- A reported level outside the catalog (OpenCode reports "default" when no variant was chosen) now steps from the catalog default instead of doing nothing. - Slash-command prompts skip the Ultrathink level so stepping still wraps. - The caret never lands inside a newly added Ultrathink prefix. - Stepping is ignored while editing a queued message, whose draft is discarded when the edit ends. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1a2f285 commit 816662b

5 files changed

Lines changed: 87 additions & 46 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6093,7 +6093,15 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
60936093
),
60946094
openModelPicker: openModelPickerStable,
60956095
stepReasoningEffort: (direction) => {
6096-
if (noProviderAvailable || isComposerApprovalState || pendingUserInputs.length > 0) return;
6096+
if (
6097+
noProviderAvailable ||
6098+
isComposerApprovalState ||
6099+
pendingUserInputs.length > 0 ||
6100+
// A queued-message edit draft is discarded when the edit ends.
6101+
isEditingQueuedMessage
6102+
) {
6103+
return;
6104+
}
60976105
const change = getComposerReasoningStep({
60986106
provider: selectedProvider,
60996107
instanceId: selectedInstanceId,
@@ -6102,6 +6110,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
61026110
modelOptions: composerModelOptions?.[selectedInstanceId],
61036111
reportedModelSelection,
61046112
prompt: promptRef.current,
6113+
cursor: readComposerSnapshotStable().expandedCursor,
61056114
planModeEnabled: settings.planModeEnabled,
61066115
direction,
61076116
});
@@ -6117,10 +6126,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
61176126
}
61186127
if (change.prompt !== promptRef.current) {
61196128
applyPromptReplacementStable(0, promptRef.current.length, change.prompt, {
6120-
expandedCursorAfterReplace: Math.max(
6121-
0,
6122-
readComposerSnapshotStable().expandedCursor + change.cursorOffset,
6123-
),
6129+
expandedCursorAfterReplace: change.cursor,
61246130
});
61256131
}
61266132
},
@@ -6264,6 +6270,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
62646270
foldPastedText,
62656271
composerDraftTarget,
62666272
composerModelOptions,
6273+
isEditingQueuedMessage,
62676274
composerCursor,
62686275
activePendingProgress,
62696276
composerTerminalContexts,

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -323,24 +323,33 @@ export function getReasoningTraitStep(input: {
323323
const current =
324324
isPrimary && selected.ultrathinkPromptControlled
325325
? "ultrathink"
326-
: (getDescriptorStringValue(
326+
: getDescriptorStringValue(
327327
descriptor,
328328
{ instanceId: input.instanceId, model: input.model, options: input.modelOptions ?? [] },
329329
input.reportedModelSelection,
330-
) ?? getDescriptorStringValue(descriptor));
331-
const index = descriptor.options.findIndex((option) => option.id === current);
332-
if (index < 0) return null;
333-
const count = descriptor.options.length;
334-
const next = descriptor.options[(index + input.direction + count) % count];
335-
const change = next ? getTraitSelectChange(selected, descriptor, input.prompt, next.id) : null;
336-
if (!change) return null;
337-
if ("modelOptions" in change) {
338-
return change.modelOptions
339-
? { prompt: change.prompt, modelOptions: change.modelOptions }
340-
: null;
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;
341351
}
342-
// A slash command refuses the Ultrathink prefix, so the step would change nothing.
343-
return change.prompt.startsWith(ULTRATHINK_PROMPT_PREFIX) ? change : null;
352+
return null;
344353
}
345354

346355
export function shouldRenderTraitsControls(input: {

‎apps/web/src/components/chat/composerProviderState.test.tsx‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ describe("getComposerReasoningStep", () => {
520520
models: modelWith([selectDescriptor("reasoningEffort", LEVELS)]),
521521
modelOptions: undefined,
522522
prompt: "Fix the bug",
523+
cursor: 0,
523524
planModeEnabled: true,
524525
direction: 1,
525526
...input,
@@ -549,7 +550,7 @@ describe("getComposerReasoningStep", () => {
549550
`${from} by ${direction}`,
550551
).toStrictEqual({
551552
prompt: "Fix the bug",
552-
cursorOffset: 0,
553+
cursor: 0,
553554
modelOptions: selections(["contextWindow", "1m"], ["reasoningEffort", to]),
554555
});
555556
}
@@ -561,7 +562,7 @@ describe("getComposerReasoningStep", () => {
561562
prompt: " Fix the bug \n",
562563
modelOptions: selections(["effort", "high"]),
563564
direction: 1,
564-
expected: { prompt: "Ultrathink:\nFix the bug", cursorOffset: 10 },
565+
expected: { prompt: "Ultrathink:\nFix the bug", cursor: 20 },
565566
},
566567
{
567568
// The prefix, not the draft's Medium, is the current level.
@@ -570,21 +571,36 @@ describe("getComposerReasoningStep", () => {
570571
direction: -1,
571572
expected: {
572573
prompt: "Fix the bug",
573-
cursorOffset: -14,
574+
cursor: 8,
574575
modelOptions: selections(["effort", "high"]),
575576
},
576577
},
577578
] as const) {
578-
const result = step({ ...CLAUDE, prompt, modelOptions, direction });
579+
const result = step({
580+
...CLAUDE,
581+
prompt,
582+
cursor: prompt.indexOf("bug"),
583+
modelOptions,
584+
direction,
585+
});
579586
expect(result).toStrictEqual(expected);
580-
const caret = prompt.indexOf("bug") + (result?.cursorOffset ?? 0);
581-
expect(result?.prompt.slice(caret)).toMatch(/^bug/);
587+
expect(result?.prompt.slice(result.cursor)).toMatch(/^bug/);
582588
}
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);
583593
});
584594

585-
it("does nothing when the Ultrathink prefix cannot be added or removed", () => {
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+
});
586603
for (const [prompt, direction] of [
587-
["/review", 1],
588604
["Please ultrathink harder", 1],
589605
["Ultrathink:\nPlease ultrathink harder", -1],
590606
] as const) {
@@ -639,6 +655,16 @@ describe("getComposerReasoningStep", () => {
639655
reportedModelSelection: reported,
640656
to: "medium",
641657
},
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+
},
642668
]) {
643669
expect(step({ modelOptions, reportedModelSelection })?.modelOptions, label).toStrictEqual(
644670
selections(["reasoningEffort", to]),

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ export function getComposerProviderState(input: ComposerProviderStateInput): Com
163163
}
164164

165165
/**
166-
* `cursorOffset` is the shift an expanded caret needs to stay on the same
167-
* character after the Ultrathink prefix is added or removed; 0 when the prompt
168-
* is unchanged.
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.
169168
*/
170169
export function getComposerReasoningStep(input: {
171170
provider: ProviderDriverKind;
@@ -175,14 +174,15 @@ export function getComposerReasoningStep(input: {
175174
modelOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined;
176175
reportedModelSelection?: ModelSelection | null | undefined;
177176
prompt: string;
177+
cursor: number;
178178
planModeEnabled: boolean;
179179
direction: 1 | -1;
180180
}): {
181181
prompt: string;
182-
cursorOffset: number;
182+
cursor: number;
183183
modelOptions?: ReadonlyArray<ProviderOptionSelection>;
184184
} | null {
185-
const { prompt } = input;
185+
const { prompt, cursor } = input;
186186
const { selections } = resolveComposerOptionSelections(
187187
input.models,
188188
input.model,
@@ -202,19 +202,18 @@ export function getComposerReasoningStep(input: {
202202
direction: input.direction,
203203
});
204204
if (!step) return null;
205-
// Adding the prefix also trims the prompt, so leading whitespace shifts the caret back.
206-
const prefixLength = step.prompt.length - prompt.trim().length;
207-
const leadingWhitespaceLength = prompt.length - prompt.trimStart().length;
208-
const cursorOffset =
209-
step.prompt === prompt
210-
? 0
211-
: "modelOptions" in step
212-
? step.prompt.length - prompt.length
213-
: prefixLength - leadingWhitespaceLength;
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);
214213
return {
215214
prompt: step.prompt,
216-
cursorOffset,
217-
...("modelOptions" in step ? { modelOptions: step.modelOptions } : {}),
215+
cursor: Math.min(step.prompt.length, Math.max(keptStart, cursor + offset)),
216+
...modelOptions,
218217
};
219218
}
220219

‎docs/user/keybindings.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ current checkout, a new worktree, and the previous worktree when available.
3030
Use `mod+shift+l` to reuse the previous worktree directly.
3131

3232
To change effort one step without opening the picker, bind
33-
`composer.increaseEffort` and `composer.decreaseEffort` in Keybindings. Both are
34-
unbound by default. Increase wraps from the highest level to the lowest, and
35-
decrease wraps from the lowest level to the highest.
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.
3636

3737
In the model picker, press Left in an empty search field or Shift+Tab to reach
3838
the provider list. Use Up/Down to move and Enter to choose. Right returns to

0 commit comments

Comments
 (0)