Compare commits

...
Author SHA1 Message Date
Cursor AgentandJulius Marminge 83a00449c8 Add React Scan composer menu recordings
Co-authored-by: Julius Marminge <[email protected]>
2026-05-24 16:29:20 +00:00
Cursor AgentandJulius Marminge 669d274bf9 Format composer menu highlight helper
Co-authored-by: Julius Marminge <[email protected]>
2026-05-24 16:26:07 +00:00
Cursor AgentandJulius Marminge 3666f713e4 Avoid composer menu highlight sync effect
Co-authored-by: Julius Marminge <[email protected]>
2026-05-24 16:24:40 +00:00
Adam Buchweitz 4f0f24f055 fix: maintain reasoning selections for multiple providers (#2760) 2026-05-22 07:02:35 -07:00
9 changed files with 169 additions and 50 deletions

No files matched your search

+25 -44
View File
@@ -68,7 +68,10 @@ import { ComposerPrimaryActions } from "./ComposerPrimaryActions";
import { ComposerPendingApprovalPanel } from "./ComposerPendingApprovalPanel";
import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
import { ComposerPlanFollowUpBanner } from "./ComposerPlanFollowUpBanner";
import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
import {
resolveComposerMenuActiveItemId,
resolveComposerMenuNudgedItemId,
} from "./composerMenuHighlight";
import { searchSlashCommandItems } from "./composerSlashCommandSearch";
import {
getComposerProviderState,
@@ -727,9 +730,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
model: selectedModel,
models: selectedProviderModels,
prompt,
modelOptions: composerModelOptions?.[selectedProvider],
modelOptions: composerModelOptions?.[selectedInstanceId],
}),
[composerModelOptions, prompt, selectedModel, selectedProvider, selectedProviderModels],
[
composerModelOptions,
prompt,
selectedInstanceId,
selectedModel,
selectedProvider,
selectedProviderModels,
],
);
const selectedPromptEffort = composerProviderState.promptEffort;
@@ -1018,21 +1028,23 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
const providerTraitsMenuContent = renderProviderTraitsMenuContent({
provider: selectedProvider,
instanceId: selectedInstanceId,
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
...(routeKind === "draft" && draftId ? { draftId } : {}),
model: selectedModel,
models: selectedProviderModels,
modelOptions: composerModelOptions?.[selectedProvider],
modelOptions: composerModelOptions?.[selectedInstanceId],
prompt,
onPromptChange: setPromptFromTraits,
});
const providerTraitsPicker = renderProviderTraitsPicker({
provider: selectedProvider,
instanceId: selectedInstanceId,
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
...(routeKind === "draft" && draftId ? { draftId } : {}),
model: selectedModel,
models: selectedProviderModels,
modelOptions: composerModelOptions?.[selectedProvider],
modelOptions: composerModelOptions?.[selectedInstanceId],
prompt,
onPromptChange: setPromptFromTraits,
});
@@ -1125,35 +1137,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
composerTerminalContextsRef.current = composerTerminalContexts;
}, [composerTerminalContexts, composerTerminalContextsRef]);
// ------------------------------------------------------------------
// Composer menu highlight sync
// ------------------------------------------------------------------
useEffect(() => {
if (!composerMenuOpen) {
setComposerHighlightedItemId(null);
setComposerHighlightedSearchKey(null);
return;
}
const nextActiveItemId = resolveComposerMenuActiveItemId({
items: composerMenuItems,
highlightedItemId: composerHighlightedItemId,
currentSearchKey: composerMenuSearchKey,
highlightedSearchKey: composerHighlightedSearchKey,
});
setComposerHighlightedItemId((existing) =>
existing === nextActiveItemId ? existing : nextActiveItemId,
);
setComposerHighlightedSearchKey((existing) =>
existing === composerMenuSearchKey ? existing : composerMenuSearchKey,
);
}, [
composerHighlightedItemId,
composerHighlightedSearchKey,
composerMenuItems,
composerMenuOpen,
composerMenuSearchKey,
]);
const lastSyncedPendingInputRef = useRef<{
requestId: string | null;
questionId: string | null;
@@ -1567,18 +1550,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
const nudgeComposerMenuHighlight = useCallback(
(key: "ArrowDown" | "ArrowUp") => {
if (composerMenuItems.length === 0) return;
const highlightedIndex = composerMenuItems.findIndex(
(item) => item.id === composerHighlightedItemId,
setComposerHighlightedItemId(
resolveComposerMenuNudgedItemId({
items: composerMenuItems,
activeItemId: activeComposerMenuItem?.id ?? null,
direction: key === "ArrowDown" ? "next" : "previous",
}),
);
const normalizedIndex =
highlightedIndex >= 0 ? highlightedIndex : key === "ArrowDown" ? -1 : 0;
const offset = key === "ArrowDown" ? 1 : -1;
const nextIndex =
(normalizedIndex + offset + composerMenuItems.length) % composerMenuItems.length;
const nextItem = composerMenuItems[nextIndex];
setComposerHighlightedItemId(nextItem?.id ?? null);
setComposerHighlightedSearchKey(composerMenuSearchKey);
},
[composerHighlightedItemId, composerMenuItems],
[activeComposerMenuItem?.id, composerMenuItems, composerMenuSearchKey],
);
const blurMobileComposerAfterSend = useCallback(() => {
@@ -1,5 +1,6 @@
import {
type ProviderDriverKind,
type ProviderInstanceId,
type ProviderOptionDescriptor,
type ProviderOptionSelection,
type ScopedThreadRef,
@@ -196,6 +197,7 @@ export function shouldRenderTraitsControls(input: {
export interface TraitsMenuContentProps {
provider: ProviderDriverKind;
instanceId?: ProviderInstanceId;
models: ReadonlyArray<ServerProviderModel>;
model: string | null | undefined;
prompt: string;
@@ -208,6 +210,7 @@ export interface TraitsMenuContentProps {
export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
provider,
instanceId,
models,
model,
prompt,
@@ -228,11 +231,12 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
return;
}
setProviderModelOptions(threadTarget, provider, nextOptions, {
...(instanceId ? { instanceId } : {}),
model,
persistSticky: true,
});
},
[model, persistence, provider, setProviderModelOptions],
[instanceId, model, persistence, provider, setProviderModelOptions],
);
const {
descriptors,
@@ -343,6 +347,7 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
export const TraitsPicker = memo(function TraitsPicker({
provider,
instanceId,
models,
model,
prompt,
@@ -431,6 +436,7 @@ export const TraitsPicker = memo(function TraitsPicker({
<MenuPopup align="start">
<TraitsMenuContent
provider={provider}
{...(instanceId ? { instanceId } : {})}
models={models}
model={model}
prompt={prompt}
@@ -1,6 +1,9 @@
import { describe, expect, it } from "vitest";
import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
import {
resolveComposerMenuActiveItemId,
resolveComposerMenuNudgedItemId,
} from "./composerMenuHighlight";
describe("resolveComposerMenuActiveItemId", () => {
const items = [{ id: "top" }, { id: "second" }, { id: "third" }] as const;
@@ -49,3 +52,61 @@ describe("resolveComposerMenuActiveItemId", () => {
).toBe("top");
});
});
describe("resolveComposerMenuNudgedItemId", () => {
const items = [{ id: "top" }, { id: "second" }, { id: "third" }] as const;
it("moves from the active item", () => {
expect(
resolveComposerMenuNudgedItemId({
items,
activeItemId: "second",
direction: "next",
}),
).toBe("third");
expect(
resolveComposerMenuNudgedItemId({
items,
activeItemId: "second",
direction: "previous",
}),
).toBe("top");
});
it("wraps around at either edge", () => {
expect(
resolveComposerMenuNudgedItemId({
items,
activeItemId: "third",
direction: "next",
}),
).toBe("top");
expect(
resolveComposerMenuNudgedItemId({
items,
activeItemId: "top",
direction: "previous",
}),
).toBe("third");
});
it("starts from the first visible item when active state is stale", () => {
expect(
resolveComposerMenuNudgedItemId({
items,
activeItemId: "missing",
direction: "next",
}),
).toBe("top");
expect(
resolveComposerMenuNudgedItemId({
items,
activeItemId: "missing",
direction: "previous",
}),
).toBe("third");
});
});
@@ -18,3 +18,20 @@ export function resolveComposerMenuActiveItemId(input: {
return input.items[0]?.id ?? null;
}
export function resolveComposerMenuNudgedItemId(input: {
items: ReadonlyArray<{ id: string }>;
activeItemId: string | null;
direction: "next" | "previous";
}): string | null {
if (input.items.length === 0) {
return null;
}
const activeIndex = input.items.findIndex((item) => item.id === input.activeItemId);
const normalizedIndex = activeIndex >= 0 ? activeIndex : input.direction === "next" ? -1 : 0;
const offset = input.direction === "next" ? 1 : -1;
const nextIndex = (normalizedIndex + offset + input.items.length) % input.items.length;
return input.items[nextIndex]?.id ?? null;
}
@@ -1,5 +1,6 @@
import {
type ProviderDriverKind,
type ProviderInstanceId,
type ProviderOptionSelection,
type ScopedThreadRef,
type ServerProviderModel,
@@ -35,6 +36,7 @@ export type ComposerProviderState = {
type TraitsRenderInput = {
provider: ProviderDriverKind;
instanceId?: ProviderInstanceId;
threadRef?: ScopedThreadRef;
draftId?: DraftId;
model: string;
@@ -76,8 +78,17 @@ function renderTraitsControl(
Component: typeof TraitsMenuContent | typeof TraitsPicker,
input: TraitsRenderInput,
): ReactNode {
const { provider, threadRef, draftId, model, models, modelOptions, prompt, onPromptChange } =
input;
const {
provider,
instanceId,
threadRef,
draftId,
model,
models,
modelOptions,
prompt,
onPromptChange,
} = input;
const hasTarget = threadRef !== undefined || draftId !== undefined;
if (
!hasTarget ||
@@ -88,6 +99,7 @@ function renderTraitsControl(
return (
<Component
provider={provider}
{...(instanceId ? { instanceId } : {})}
models={models}
{...(threadRef ? { threadRef } : {})}
{...(draftId ? { draftId } : {})}
+38
View File
@@ -21,6 +21,7 @@ import { createModelSelection } from "@t3tools/shared/model";
// `stickyModelSelectionByProvider` maps are keyed by `ProviderInstanceId`
// in production; these aliases keep the legacy-key migration tests concise.
const CODEX_INSTANCE = ProviderInstanceId.make("codex");
const CODEX_SECONDARY_INSTANCE = ProviderInstanceId.make("codex_secondary");
const CLAUDE_AGENT_INSTANCE = ProviderInstanceId.make("claudeAgent");
const CURSOR_INSTANCE = ProviderInstanceId.make("cursor");
const CODEX_DRIVER = ProviderDriverKind.make("codex");
@@ -1201,6 +1202,43 @@ describe("composerDraftStore modelSelection", () => {
);
});
it("stores provider option changes on a selected custom instance", () => {
const store = useComposerDraftStore.getState();
store.setProviderModelOptions(
threadRef,
CODEX_DRIVER,
toSelections({ reasoningEffort: "low" }),
{
instanceId: CODEX_SECONDARY_INSTANCE,
model: "gpt-5-codex",
persistSticky: true,
},
);
expect(
draftFor(threadId, TEST_ENVIRONMENT_ID)?.modelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
).toEqual(
expect.objectContaining({
instanceId: CODEX_SECONDARY_INSTANCE,
options: [{ id: "reasoningEffort", value: "low" }],
}),
);
expect(draftFor(threadId, TEST_ENVIRONMENT_ID)?.activeProvider).toBe(CODEX_SECONDARY_INSTANCE);
expect(useComposerDraftStore.getState().stickyActiveProvider).toBe(CODEX_SECONDARY_INSTANCE);
expect(useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_INSTANCE]).toBe(
undefined,
);
expect(
useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
).toEqual(
expect.objectContaining({
instanceId: CODEX_SECONDARY_INSTANCE,
options: [{ id: "reasoningEffort", value: "low" }],
}),
);
});
it("updates only the draft when sticky persistence is disabled", () => {
const store = useComposerDraftStore.getState();
+6 -2
View File
@@ -371,6 +371,7 @@ interface ComposerDraftStoreState {
provider: ProviderDriverKind,
nextProviderOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined,
options?: {
instanceId?: ProviderInstanceId | null | undefined;
model?: string | null | undefined;
persistSticky?: boolean;
},
@@ -2456,7 +2457,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
if (normalizedProvider === null) {
return;
}
const instanceKey = defaultInstanceIdForDriver(normalizedProvider);
const instanceKey = options?.instanceId ?? defaultInstanceIdForDriver(normalizedProvider);
const fallbackModel =
normalizeModelSlug(options?.model, normalizedProvider) ??
DEFAULT_MODEL_BY_PROVIDER[normalizedProvider] ??
@@ -2501,7 +2502,9 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
const { options: _, ...rest } = stickyBase;
nextStickyMap[instanceKey] = rest as ModelSelection;
}
nextStickyActiveProvider = base.activeProvider ?? instanceKey;
nextStickyActiveProvider = options.instanceId
? instanceKey
: (base.activeProvider ?? instanceKey);
}
if (
@@ -2514,6 +2517,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
const nextDraft: ComposerThreadDraftState = {
...base,
...(options?.instanceId ? { activeProvider: instanceKey } : {}),
modelSelectionByProvider: nextMap,
};
const nextDraftsByThreadKey = { ...state.draftsByThreadKey };