Skip to content

Commit ff3fb93

Browse files
committed
Review fixes
1 parent b892d2f commit ff3fb93

8 files changed

Lines changed: 36 additions & 18 deletions

File tree

apps/code/src/main/services/agent/schemas.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import type {
22
RequestPermissionRequest,
33
PermissionOption as SdkPermissionOption,
44
} from "@agentclientprotocol/sdk";
5+
import { effortLevelSchema } from "@shared/types.js";
56
import { z } from "zod";
67

8+
export { effortLevelSchema };
9+
export type { EffortLevel } from "@shared/types.js";
10+
711
// Session credentials schema
812
export const credentialsSchema = z.object({
913
apiKey: z.string(),
@@ -46,7 +50,7 @@ export const startSessionInput = z.object({
4650
adapter: z.enum(["claude", "codex"]).optional(),
4751
additionalDirectories: z.array(z.string()).optional(),
4852
customInstructions: z.string().max(2000).optional(),
49-
effort: z.enum(["low", "medium", "high", "max"]).optional(),
53+
effort: effortLevelSchema.optional(),
5054
});
5155

5256
export type StartSessionInput = z.infer<typeof startSessionInput>;
@@ -163,6 +167,7 @@ export const reconnectSessionInput = z.object({
163167
additionalDirectories: z.array(z.string()).optional(),
164168
permissionMode: z.string().optional(),
165169
customInstructions: z.string().max(2000).optional(),
170+
effort: effortLevelSchema.optional(),
166171
});
167172

168173
export type ReconnectSessionInput = z.infer<typeof reconnectSessionInput>;

apps/code/src/main/services/agent/service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
AgentServiceEvent,
3939
type AgentServiceEvents,
4040
type Credentials,
41+
type EffortLevel,
4142
type InterruptReason,
4243
type PromptOutput,
4344
type ReconnectSessionInput,
@@ -201,7 +202,7 @@ interface SessionConfig {
201202
/** Custom instructions injected into the system prompt */
202203
customInstructions?: string;
203204
/** Effort level for Claude sessions */
204-
effort?: "low" | "medium" | "high" | "max";
205+
effort?: EffortLevel;
205206
}
206207

207208
interface ManagedSession {

apps/code/src/renderer/features/message-editor/components/EditorToolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function EditorToolbar({
4444
};
4545

4646
return (
47-
<Flex align="center" gap="3">
47+
<Flex align="center" gap="1">
4848
<input
4949
ref={fileInputRef}
5050
type="file"

apps/code/src/renderer/features/sessions/service/service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ import { getIsOnline } from "@renderer/stores/connectivityStore";
3030
import { trpcClient } from "@renderer/trpc/client";
3131
import { toast } from "@renderer/utils/toast";
3232
import { getCloudUrlFromRegion } from "@shared/constants/oauth";
33-
import type {
34-
CloudTaskUpdatePayload,
35-
ExecutionMode,
36-
Task,
33+
import {
34+
type CloudTaskUpdatePayload,
35+
type EffortLevel,
36+
type ExecutionMode,
37+
effortLevelSchema,
38+
type Task,
3739
} from "@shared/types";
3840
import { ANALYTICS_EVENTS } from "@shared/types/analytics";
3941
import type { AcpMessage, StoredLogEntry } from "@shared/types/session-events";
@@ -539,7 +541,9 @@ export class SessionService {
539541
permissionMode: executionMode,
540542
adapter,
541543
customInstructions: startCustomInstructions || undefined,
542-
effort: reasoningLevel as "low" | "medium" | "high" | "max" | undefined,
544+
effort: effortLevelSchema.safeParse(reasoningLevel).success
545+
? (reasoningLevel as EffortLevel)
546+
: undefined,
543547
});
544548

545549
const session = this.createBaseSession(taskRun.id, taskId, taskTitle);

apps/code/src/shared/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export const executionModeSchema = z.enum([
1010
]);
1111
export type ExecutionMode = z.infer<typeof executionModeSchema>;
1212

13+
// Effort level schema and type - shared between main and renderer
14+
export const effortLevelSchema = z.enum(["low", "medium", "high", "max"]);
15+
export type EffortLevel = z.infer<typeof effortLevelSchema>;
16+
1317
interface UserBasic {
1418
id: number;
1519
uuid: string;

packages/agent/src/adapters/claude/claude-agent.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import {
7373
} from "./tools.js";
7474
import type {
7575
BackgroundTerminal,
76+
EffortLevel,
7677
NewSessionMeta,
7778
Session,
7879
ToolUseCache,
@@ -559,7 +560,9 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
559560
await this.session.query.setModel(sdkModelId);
560561
this.session.modelId = params.value;
561562
} else if (params.configId === "effort") {
562-
this.session.effort = params.value as "low" | "medium" | "high" | "max";
563+
const newEffort = params.value as EffortLevel;
564+
this.session.effort = newEffort;
565+
this.session.queryOptions.effort = newEffort;
563566
}
564567

565568
this.session.configOptions = this.session.configOptions.map((o) =>
@@ -625,12 +628,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
625628

626629
const meta = params._meta as NewSessionMeta | undefined;
627630
const taskId = meta?.persistence?.taskId;
628-
const effort = meta?.claudeCode?.options?.effort as
629-
| "low"
630-
| "medium"
631-
| "high"
632-
| "max"
633-
| undefined;
631+
const effort = meta?.claudeCode?.options?.effort as EffortLevel | undefined;
634632

635633
// We want to create a new session id unless it is resume,
636634
// but not resume + forkSession.
@@ -691,6 +689,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
691689

692690
const session: Session = {
693691
query: q,
692+
queryOptions: options,
694693
input,
695694
cancelled: false,
696695
settingsManager,
@@ -858,7 +857,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
858857
currentModelId: string;
859858
options: SessionConfigSelectOption[];
860859
},
861-
currentEffort: "low" | "medium" | "high" | "max" = "high",
860+
currentEffort: EffortLevel = "high",
862861
): SessionConfigOption[] {
863862
const modeOptions = getAvailableModes().map((mode) => ({
864863
value: mode.id,

packages/agent/src/adapters/claude/session/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
type OnModeChange,
1818
} from "../hooks.js";
1919
import type { CodeExecutionMode } from "../tools.js";
20+
import type { EffortLevel } from "../types.js";
2021
import { DEFAULT_MODEL } from "./models.js";
2122
import type { SettingsManager } from "./settings.js";
2223

@@ -43,7 +44,7 @@ export interface BuildOptionsParams {
4344
onModeChange?: OnModeChange;
4445
onProcessSpawned?: (info: ProcessSpawnedInfo) => void;
4546
onProcessExited?: (pid: number) => void;
46-
effort?: "low" | "medium" | "high" | "max";
47+
effort?: EffortLevel;
4748
}
4849

4950
const BRANCH_NAMING_INSTRUCTIONS = `

packages/agent/src/adapters/claude/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type { BaseSession } from "../base-acp-agent.js";
1313
import type { SettingsManager } from "./session/settings.js";
1414
import type { CodeExecutionMode } from "./tools.js";
1515

16+
export type EffortLevel = "low" | "medium" | "high" | "max";
17+
1618
export type AccumulatedUsage = {
1719
inputTokens: number;
1820
outputTokens: number;
@@ -38,6 +40,8 @@ export type PendingMessage = {
3840

3941
export type Session = BaseSession & {
4042
query: Query;
43+
/** The Options object passed to query() — mutating it affects subsequent prompts */
44+
queryOptions: Options;
4145
input: Pushable<SDKUserMessage>;
4246
settingsManager: SettingsManager;
4347
permissionMode: CodeExecutionMode;
@@ -46,7 +50,7 @@ export type Session = BaseSession & {
4650
taskRunId?: string;
4751
lastPlanFilePath?: string;
4852
lastPlanContent?: string;
49-
effort?: "low" | "medium" | "high" | "max";
53+
effort?: EffortLevel;
5054
configOptions: SessionConfigOption[];
5155
accumulatedUsage: AccumulatedUsage;
5256
promptRunning: boolean;

0 commit comments

Comments
 (0)