Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/code/src/main/services/agent/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ For git operations while detached:
id: adapter === "codex" ? "reasoning_effort" : "effort",
name: adapter === "codex" ? "Reasoning Level" : "Effort",
type: "select",
currentValue: adapter === "codex" ? "high" : "medium",
currentValue: "high",
options: effortOpts,
category: "thought_level",
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface SettingsStore {
lastUsedWorkspaceMode: WorkspaceMode;
lastUsedAdapter: AgentAdapter;
lastUsedModel: string | null;
lastUsedReasoningEffort: string | null;
lastUsedCloudRepository: string | null;
lastUsedEnvironments: Record<string, string>;
desktopNotifications: boolean;
Expand Down Expand Up @@ -71,6 +72,7 @@ interface SettingsStore {
setLastUsedWorkspaceMode: (mode: WorkspaceMode) => void;
setLastUsedAdapter: (adapter: AgentAdapter) => void;
setLastUsedModel: (model: string) => void;
setLastUsedReasoningEffort: (effort: string) => void;
setLastUsedCloudRepository: (repo: string | null) => void;
setLastUsedEnvironment: (
repoPath: string,
Expand Down Expand Up @@ -103,6 +105,7 @@ export const useSettingsStore = create<SettingsStore>()(
lastUsedWorkspaceMode: "local",
lastUsedAdapter: "claude",
lastUsedModel: null,
lastUsedReasoningEffort: null,
lastUsedCloudRepository: null,
lastUsedEnvironments: {},
desktopNotifications: true,
Expand Down Expand Up @@ -159,6 +162,8 @@ export const useSettingsStore = create<SettingsStore>()(
setLastUsedWorkspaceMode: (mode) => set({ lastUsedWorkspaceMode: mode }),
setLastUsedAdapter: (adapter) => set({ lastUsedAdapter: adapter }),
setLastUsedModel: (model) => set({ lastUsedModel: model }),
setLastUsedReasoningEffort: (effort) =>
set({ lastUsedReasoningEffort: effort }),
setLastUsedCloudRepository: (repo) =>
set({ lastUsedCloudRepository: repo }),
setLastUsedEnvironment: (repoPath, environmentId) =>
Expand Down Expand Up @@ -208,6 +213,7 @@ export const useSettingsStore = create<SettingsStore>()(
lastUsedWorkspaceMode: state.lastUsedWorkspaceMode,
lastUsedAdapter: state.lastUsedAdapter,
lastUsedModel: state.lastUsedModel,
lastUsedReasoningEffort: state.lastUsedReasoningEffort,
lastUsedCloudRepository: state.lastUsedCloudRepository,
lastUsedEnvironments: state.lastUsedEnvironments,
desktopNotifications: state.desktopNotifications,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function TaskInput({
getLastUsedEnvironment,
defaultInitialTaskMode,
lastUsedInitialTaskMode,
setLastUsedReasoningEffort,
} = useSettingsStore();

const editorRef = useRef<EditorHandle>(null);
Expand Down Expand Up @@ -493,9 +494,10 @@ export function TaskInput({
(value: string) => {
if (thoughtOption) {
setConfigOption(thoughtOption.id, value);
setLastUsedReasoningEffort(value);
}
},
[thoughtOption, setConfigOption],
[thoughtOption, setConfigOption, setLastUsedReasoningEffort],
);

const { isOnline } = useConnectivity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ function getOptionByCategory(
);
}

function flattenValues(
options: Array<{ value?: string; options?: Array<{ value: string }> }>,
): string[] {
return options.flatMap((o) =>
o.options ? o.options.map((go) => go.value) : o.value ? [o.value] : [],
);
}

/**
* Fetches config options (models, modes, effort levels) for the task input
* page via a lightweight tRPC query. No agent session is created.
Expand Down Expand Up @@ -59,8 +67,11 @@ export function usePreviewConfig(
.then((options) => {
if (abort.signal.aborted) return;

const { defaultInitialTaskMode, lastUsedInitialTaskMode } =
useSettingsStore.getState();
const {
defaultInitialTaskMode,
lastUsedInitialTaskMode,
lastUsedReasoningEffort,
} = useSettingsStore.getState();

// Use the mode option's existing currentValue (set by the server
// based on the adapter) when the user hasn't chosen a preference,
Expand All @@ -70,17 +81,11 @@ export function usePreviewConfig(
const serverDefault = modeOpt?.currentValue;
const availableValues: string[] =
modeOpt?.type === "select"
? (
? flattenValues(
modeOpt.options as Array<{
value?: string;
options?: Array<{ value: string }>;
}>
).flatMap((o) =>
o.options
? o.options.map((go) => go.value)
: o.value
? [o.value]
: [],
}>,
)
: [];

Expand All @@ -106,7 +111,29 @@ export function usePreviewConfig(
: opt,
);

setConfigOptions(withMode);
const withEffort = withMode.map((opt) => {
if (opt.category !== "thought_level" || opt.type !== "select") {
return opt;
}
const validValues = flattenValues(
opt.options as Array<{
value?: string;
options?: Array<{ value: string }>;
}>,
);
if (
lastUsedReasoningEffort &&
validValues.includes(lastUsedReasoningEffort)
) {
return {
...opt,
currentValue: lastUsedReasoningEffort,
} as SessionConfigOption;
}
return opt;
});

setConfigOptions(withEffort);
setIsLoading(false);
})
.catch((error) => {
Expand Down Expand Up @@ -141,27 +168,33 @@ export function usePreviewConfig(
? "reasoning_effort"
: "effort";

const defaultEffort = adapter === "codex" ? "high" : "medium";
const { lastUsedReasoningEffort } = useSettingsStore.getState();
const isValidEffort = (effort: unknown): effort is string =>
typeof effort === "string" &&
!!effortOpts?.some((e) => e.value === effort);
if (effortOpts && existingIdx >= 0) {
const currentEffort = updated[existingIdx].currentValue;
const validEffort = effortOpts.some(
(e) => e.value === currentEffort,
)
const nextEffort = isValidEffort(currentEffort)
? currentEffort
: defaultEffort;
: isValidEffort(lastUsedReasoningEffort)
? lastUsedReasoningEffort
: "high";
updated[existingIdx] = {
...updated[existingIdx],
currentValue: validEffort,
currentValue: nextEffort,
options: effortOpts,
} as SessionConfigOption;
} else if (effortOpts && existingIdx === -1) {
const nextEffort = isValidEffort(lastUsedReasoningEffort)
? lastUsedReasoningEffort
: "high";
Comment on lines +171 to +190
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The fallback string "high" is hardcoded twice within the same function — once in the existingIdx >= 0 branch and once in the existingIdx === -1 branch. Extracting it to a local constant keeps the fallback value in one place and makes future changes trivial.

Suggested change
const { lastUsedReasoningEffort } = useSettingsStore.getState();
const isValidEffort = (effort: unknown): effort is string =>
typeof effort === "string" &&
!!effortOpts?.some((e) => e.value === effort);
if (effortOpts && existingIdx >= 0) {
const currentEffort = updated[existingIdx].currentValue;
const validEffort = effortOpts.some(
(e) => e.value === currentEffort,
)
const nextEffort = isValidEffort(currentEffort)
? currentEffort
: defaultEffort;
: isValidEffort(lastUsedReasoningEffort)
? lastUsedReasoningEffort
: "high";
updated[existingIdx] = {
...updated[existingIdx],
currentValue: validEffort,
currentValue: nextEffort,
options: effortOpts,
} as SessionConfigOption;
} else if (effortOpts && existingIdx === -1) {
const nextEffort = isValidEffort(lastUsedReasoningEffort)
? lastUsedReasoningEffort
: "high";
const { lastUsedReasoningEffort } = useSettingsStore.getState();
const defaultEffort = "high";
const isValidEffort = (effort: unknown): effort is string =>
typeof effort === "string" &&
!!effortOpts?.some((e) => e.value === effort);
if (effortOpts && existingIdx >= 0) {
const currentEffort = updated[existingIdx].currentValue;
const nextEffort = isValidEffort(currentEffort)
? currentEffort
: isValidEffort(lastUsedReasoningEffort)
? lastUsedReasoningEffort
: defaultEffort;
updated[existingIdx] = {
...updated[existingIdx],
currentValue: nextEffort,
options: effortOpts,
} as SessionConfigOption;
} else if (effortOpts && existingIdx === -1) {
const nextEffort = isValidEffort(lastUsedReasoningEffort)
? lastUsedReasoningEffort
: defaultEffort;
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/task-detail/hooks/usePreviewConfig.ts
Line: 171-190

Comment:
The fallback string `"high"` is hardcoded twice within the same function — once in the `existingIdx >= 0` branch and once in the `existingIdx === -1` branch. Extracting it to a local constant keeps the fallback value in one place and makes future changes trivial.

```suggestion
          const { lastUsedReasoningEffort } = useSettingsStore.getState();
          const defaultEffort = "high";
          const isValidEffort = (effort: unknown): effort is string =>
            typeof effort === "string" &&
            !!effortOpts?.some((e) => e.value === effort);
          if (effortOpts && existingIdx >= 0) {
            const currentEffort = updated[existingIdx].currentValue;
            const nextEffort = isValidEffort(currentEffort)
              ? currentEffort
              : isValidEffort(lastUsedReasoningEffort)
                ? lastUsedReasoningEffort
                : defaultEffort;
            updated[existingIdx] = {
              ...updated[existingIdx],
              currentValue: nextEffort,
              options: effortOpts,
            } as SessionConfigOption;
          } else if (effortOpts && existingIdx === -1) {
            const nextEffort = isValidEffort(lastUsedReasoningEffort)
              ? lastUsedReasoningEffort
              : defaultEffort;
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

updated = [
...updated,
{
id: effortOptionId,
name: adapter === "codex" ? "Reasoning Level" : "Effort",
type: "select",
currentValue: defaultEffort,
currentValue: nextEffort,
options: effortOpts,
category: "thought_level",
description:
Expand Down
Loading