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
6 changes: 6 additions & 0 deletions apps/code/src/main/services/agent/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import type {
RequestPermissionRequest,
PermissionOption as SdkPermissionOption,
} from "@agentclientprotocol/sdk";
import { effortLevelSchema } from "@shared/types.js";
import { z } from "zod";

export { effortLevelSchema };
export type { EffortLevel } from "@shared/types.js";

// Session credentials schema
export const credentialsSchema = z.object({
apiKey: z.string(),
Expand Down Expand Up @@ -46,6 +50,7 @@ export const startSessionInput = z.object({
adapter: z.enum(["claude", "codex"]).optional(),
additionalDirectories: z.array(z.string()).optional(),
customInstructions: z.string().max(2000).optional(),
effort: effortLevelSchema.optional(),
});

export type StartSessionInput = z.infer<typeof startSessionInput>;
Expand Down Expand Up @@ -162,6 +167,7 @@ export const reconnectSessionInput = z.object({
additionalDirectories: z.array(z.string()).optional(),
permissionMode: z.string().optional(),
customInstructions: z.string().max(2000).optional(),
effort: effortLevelSchema.optional(),
});

export type ReconnectSessionInput = z.infer<typeof reconnectSessionInput>;
Expand Down
7 changes: 7 additions & 0 deletions apps/code/src/main/services/agent/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
AgentServiceEvent,
type AgentServiceEvents,
type Credentials,
type EffortLevel,
type InterruptReason,
type PromptOutput,
type ReconnectSessionInput,
Expand Down Expand Up @@ -200,6 +201,8 @@ interface SessionConfig {
permissionMode?: string;
/** Custom instructions injected into the system prompt */
customInstructions?: string;
/** Effort level for Claude sessions */
effort?: EffortLevel;
}

interface ManagedSession {
Expand Down Expand Up @@ -632,6 +635,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
additionalDirectories,
permissionMode,
customInstructions,
effort,
} = config;

// Preview sessions don't need a real repo — use a temp directory
Expand Down Expand Up @@ -783,6 +787,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
...(additionalDirectories?.length && {
additionalDirectories,
}),
...(effort && { effort }),
plugins,
},
},
Expand Down Expand Up @@ -811,6 +816,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
claudeCode: {
options: {
...(additionalDirectories?.length && { additionalDirectories }),
...(effort && { effort }),
plugins,
},
},
Expand Down Expand Up @@ -1551,6 +1557,7 @@ For git operations while detached:
"permissionMode" in params ? params.permissionMode : undefined,
customInstructions:
"customInstructions" in params ? params.customInstructions : undefined,
effort: "effort" in params ? params.effort : undefined,
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ModelSelector } from "@features/sessions/components/ModelSelector";
import { ReasoningLevelSelector } from "@features/sessions/components/ReasoningLevelSelector";
import { Paperclip } from "@phosphor-icons/react";
import { Flex, IconButton, Tooltip } from "@radix-ui/themes";
import { useRef } from "react";
Expand Down Expand Up @@ -68,14 +67,7 @@ export function EditorToolbar({
</IconButton>
</Tooltip>
{!hideSelectors && (
<>
<ModelSelector
taskId={taskId}
adapter={adapter}
disabled={disabled}
/>
<ReasoningLevelSelector taskId={taskId} disabled={disabled} />
</>
<ModelSelector taskId={taskId} adapter={adapter} disabled={disabled} />
)}
</Flex>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Select, Text } from "@radix-ui/themes";
import { getSessionService } from "../service/service";
import {
flattenSelectOptions,
useAdapterForTask,
useSessionForTask,
useThoughtLevelConfigOptionForTask,
} from "../stores/sessionStore";
Expand All @@ -17,6 +18,7 @@ export function ReasoningLevelSelector({
}: ReasoningLevelSelectorProps) {
const session = useSessionForTask(taskId);
const thoughtOption = useThoughtLevelConfigOptionForTask(taskId);
const adapter = useAdapterForTask(taskId);

if (!thoughtOption) {
return null;
Expand Down Expand Up @@ -57,7 +59,7 @@ export function ReasoningLevelSelector({
}}
>
<Text size="1" style={{ fontFamily: "var(--font-mono)" }}>
Reasoning: {activeLabel}
{adapter === "codex" ? "Reasoning" : "Effort"}: {activeLabel}
</Text>
</Select.Trigger>
<Select.Content position="popper" sideOffset={4}>
Expand Down
13 changes: 9 additions & 4 deletions apps/code/src/renderer/features/sessions/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import { getIsOnline } from "@renderer/stores/connectivityStore";
import { trpcClient } from "@renderer/trpc/client";
import { toast } from "@renderer/utils/toast";
import { getCloudUrlFromRegion } from "@shared/constants/oauth";
import type {
CloudTaskUpdatePayload,
ExecutionMode,
Task,
import {
type CloudTaskUpdatePayload,
type EffortLevel,
type ExecutionMode,
effortLevelSchema,
type Task,
} from "@shared/types";
import { ANALYTICS_EVENTS } from "@shared/types/analytics";
import type { AcpMessage, StoredLogEntry } from "@shared/types/session-events";
Expand Down Expand Up @@ -539,6 +541,9 @@ export class SessionService {
permissionMode: executionMode,
adapter,
customInstructions: startCustomInstructions || undefined,
effort: effortLevelSchema.safeParse(reasoningLevel).success
? (reasoningLevel as EffortLevel)
: undefined,
});

const session = this.createBaseSession(taskRun.id, taskId, taskTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const TaskInputEditor = forwardRef<
</Flex>

<Flex justify="between" align="center" px="3" pb="3">
<Flex align="center" gap="1">
<Flex align="center" gap="3">
<EditorToolbar
disabled={isCreatingTask}
adapter={adapter}
Expand Down
4 changes: 4 additions & 0 deletions apps/code/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const executionModeSchema = z.enum([
]);
export type ExecutionMode = z.infer<typeof executionModeSchema>;

// Effort level schema and type - shared between main and renderer
export const effortLevelSchema = z.enum(["low", "medium", "high", "max"]);
export type EffortLevel = z.infer<typeof effortLevelSchema>;

interface UserBasic {
id: number;
uuid: string;
Expand Down
30 changes: 29 additions & 1 deletion packages/agent/src/adapters/claude/claude-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {
} from "./tools.js";
import type {
BackgroundTerminal,
EffortLevel,
NewSessionMeta,
Session,
ToolUseCache,
Expand Down Expand Up @@ -558,6 +559,10 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
const sdkModelId = toSdkModelId(params.value);
await this.session.query.setModel(sdkModelId);
this.session.modelId = params.value;
} else if (params.configId === "effort") {
const newEffort = params.value as EffortLevel;
this.session.effort = newEffort;
this.session.queryOptions.effort = newEffort;
}

this.session.configOptions = this.session.configOptions.map((o) =>
Expand Down Expand Up @@ -623,6 +628,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {

const meta = params._meta as NewSessionMeta | undefined;
const taskId = meta?.persistence?.taskId;
const effort = meta?.claudeCode?.options?.effort as EffortLevel | undefined;

// We want to create a new session id unless it is resume,
// but not resume + forkSession.
Expand Down Expand Up @@ -673,6 +679,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
onModeChange: this.createOnModeChange(),
onProcessSpawned: this.options?.onProcessSpawned,
onProcessExited: this.options?.onProcessExited,
effort,
});

// Use the same abort controller that buildSessionOptions gave to the query
Expand All @@ -682,6 +689,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {

const session: Session = {
query: q,
queryOptions: options,
input,
cancelled: false,
settingsManager,
Expand All @@ -693,6 +701,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
cachedReadTokens: 0,
cachedWriteTokens: 0,
},
effort,
configOptions: [],
promptRunning: false,
pendingMessages: new Map(),
Expand Down Expand Up @@ -790,7 +799,11 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
),
};

const configOptions = this.buildConfigOptions(permissionMode, modelOptions);
const configOptions = this.buildConfigOptions(
permissionMode,
modelOptions,
effort ?? "high",
);
session.configOptions = configOptions;

if (!creationOpts.skipBackgroundFetches) {
Expand Down Expand Up @@ -844,6 +857,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
currentModelId: string;
options: SessionConfigSelectOption[];
},
currentEffort: EffortLevel = "high",
): SessionConfigOption[] {
const modeOptions = getAvailableModes().map((mode) => ({
value: mode.id,
Expand Down Expand Up @@ -871,6 +885,20 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
category: "model" as SessionConfigOptionCategory,
description: "Choose which model Claude should use",
},
{
id: "effort",
name: "Effort",
type: "select",
currentValue: currentEffort,
options: [
{ value: "low", name: "Low" },
{ value: "medium", name: "Medium" },
{ value: "high", name: "High" },
{ value: "max", name: "Max" },
],
category: "thought_level" as SessionConfigOptionCategory,
description: "Controls how much effort Claude puts into its response",
},
];
}

Expand Down
6 changes: 6 additions & 0 deletions packages/agent/src/adapters/claude/session/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
type OnModeChange,
} from "../hooks.js";
import type { CodeExecutionMode } from "../tools.js";
import type { EffortLevel } from "../types.js";
import { DEFAULT_MODEL } from "./models.js";
import type { SettingsManager } from "./settings.js";

Expand All @@ -43,6 +44,7 @@ export interface BuildOptionsParams {
onModeChange?: OnModeChange;
onProcessSpawned?: (info: ProcessSpawnedInfo) => void;
onProcessExited?: (pid: number) => void;
effort?: EffortLevel;
}

const BRANCH_NAMING_INSTRUCTIONS = `
Expand Down Expand Up @@ -295,6 +297,10 @@ export function buildSessionOptions(params: BuildOptionsParams): Options {
options.additionalDirectories = params.additionalDirectories;
}

if (params.effort) {
options.effort = params.effort;
}

clearStatsigCache();
return options;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/agent/src/adapters/claude/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import type { BaseSession } from "../base-acp-agent.js";
import type { SettingsManager } from "./session/settings.js";
import type { CodeExecutionMode } from "./tools.js";

export type EffortLevel = "low" | "medium" | "high" | "max";

export type AccumulatedUsage = {
inputTokens: number;
outputTokens: number;
Expand All @@ -38,6 +40,8 @@ export type PendingMessage = {

export type Session = BaseSession & {
query: Query;
/** The Options object passed to query() — mutating it affects subsequent prompts */
queryOptions: Options;
input: Pushable<SDKUserMessage>;
settingsManager: SettingsManager;
permissionMode: CodeExecutionMode;
Expand All @@ -46,6 +50,7 @@ export type Session = BaseSession & {
taskRunId?: string;
lastPlanFilePath?: string;
lastPlanContent?: string;
effort?: EffortLevel;
configOptions: SessionConfigOption[];
accumulatedUsage: AccumulatedUsage;
promptRunning: boolean;
Expand Down
Loading