mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-20 04:00:16 +08:00
fix(claude): persist max effort via env (#2493)
This commit is contained in:
@@ -509,7 +509,7 @@ When editing Claude providers, a set of **quick toggles** is available above the
|
||||
| **Hide Attribution** | Clears commit/PR attribution metadata | Sets `attribution: {commit: "", pr: ""}` |
|
||||
| **Enable Teammates** | Enables the agent teams feature | Sets `env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS = "1"` |
|
||||
| **Enable Tool Search** | Enables tool search functionality | Sets `env.ENABLE_TOOL_SEARCH = "true"` |
|
||||
| **Max Effort** | Sets effort level to max | Sets `effortLevel = "max"` |
|
||||
| **Max Effort** | Sets effort level to max | Sets `env.CLAUDE_CODE_EFFORT_LEVEL = "max"` |
|
||||
| **Disable Auto Upgrade** | Prevents Claude Code auto-updates | Sets `env.DISABLE_AUTOUPDATER = "1"` |
|
||||
|
||||
When a toggle is unchecked, its corresponding config entry is removed entirely. Changes are reflected in the JSON editor in real-time.
|
||||
|
||||
@@ -509,7 +509,7 @@ Claude プロバイダーの編集時、JSON エディタの上部に **クイ
|
||||
| **帰属情報を非表示** | コミット/PR の帰属メタデータをクリア | `attribution: {commit: "", pr: ""}` を設定 |
|
||||
| **チームメイトを有効化** | エージェントチーム機能を有効化 | `env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS = "1"` を設定 |
|
||||
| **ツール検索を有効化** | ツール検索機能を有効化 | `env.ENABLE_TOOL_SEARCH = "true"` を設定 |
|
||||
| **最大強度思考** | エフォートレベルを max に設定 | `effortLevel = "max"` を設定 |
|
||||
| **最大強度思考** | エフォートレベルを max に設定 | `env.CLAUDE_CODE_EFFORT_LEVEL = "max"` を設定 |
|
||||
| **自動アップグレードを無効化** | Claude Code の自動更新を防止 | `env.DISABLE_AUTOUPDATER = "1"` を設定 |
|
||||
|
||||
トグルのチェックを外すと、対応する設定エントリが完全に削除されます。変更は JSON エディタにリアルタイムで反映されます。
|
||||
|
||||
@@ -509,7 +509,7 @@ v3.13.0 起新增的高级选项。默认情况下,CC Switch 会把配置的 `
|
||||
| **隐藏署名** | 清除提交/PR 的署名元数据 | 设置 `attribution: {commit: "", pr: ""}` |
|
||||
| **启用 Teammates** | 启用 Agent 团队功能 | 设置 `env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS = "1"` |
|
||||
| **启用工具搜索** | 启用工具搜索功能 | 设置 `env.ENABLE_TOOL_SEARCH = "true"` |
|
||||
| **最大强度思考** | 将 effort 级别设为 max | 设置 `effortLevel = "max"` |
|
||||
| **最大强度思考** | 将 effort 级别设为 max | 设置 `env.CLAUDE_CODE_EFFORT_LEVEL = "max"` |
|
||||
| **禁用自动更新** | 阻止 Claude Code 自动更新 | 设置 `env.DISABLE_AUTOUPDATER = "1"` |
|
||||
|
||||
取消勾选开关时,对应的配置项会被完全移除。更改会实时反映在 JSON 编辑器中。
|
||||
|
||||
@@ -81,7 +81,7 @@ export function CommonConfigEditor({
|
||||
enableToolSearch:
|
||||
config?.env?.ENABLE_TOOL_SEARCH === "true" ||
|
||||
config?.env?.ENABLE_TOOL_SEARCH === "1",
|
||||
effortMax: config?.effortLevel === "max",
|
||||
effortMax: config?.env?.CLAUDE_CODE_EFFORT_LEVEL === "max",
|
||||
disableAutoUpgrade:
|
||||
config?.env?.DISABLE_AUTOUPDATER === "1" ||
|
||||
config?.env?.DISABLE_AUTOUPDATER === 1,
|
||||
@@ -129,10 +129,12 @@ export function CommonConfigEditor({
|
||||
}
|
||||
break;
|
||||
case "effortMax":
|
||||
if (!config.env) config.env = {};
|
||||
if (checked) {
|
||||
config.effortLevel = "max";
|
||||
config.env.CLAUDE_CODE_EFFORT_LEVEL = "max";
|
||||
} else {
|
||||
delete config.effortLevel;
|
||||
delete config.env.CLAUDE_CODE_EFFORT_LEVEL;
|
||||
if (Object.keys(config.env).length === 0) delete config.env;
|
||||
}
|
||||
break;
|
||||
case "disableAutoUpgrade":
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { CommonConfigEditor } from "@/components/providers/forms/CommonConfigEditor";
|
||||
|
||||
vi.mock("@/components/common/FullScreenPanel", () => ({
|
||||
FullScreenPanel: ({
|
||||
isOpen,
|
||||
title,
|
||||
onClose,
|
||||
children,
|
||||
footer,
|
||||
}: {
|
||||
isOpen: boolean;
|
||||
title: string;
|
||||
onClose: () => void;
|
||||
children: ReactNode;
|
||||
footer?: ReactNode;
|
||||
}) =>
|
||||
isOpen ? (
|
||||
<div data-testid="common-config-panel">
|
||||
<button type="button" onClick={onClose}>
|
||||
panel-close
|
||||
</button>
|
||||
<h2>{title}</h2>
|
||||
<div>{children}</div>
|
||||
<div>{footer}</div>
|
||||
</div>
|
||||
) : null,
|
||||
}));
|
||||
|
||||
vi.mock("@/components/JsonEditor", () => ({
|
||||
default: ({
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
}) => (
|
||||
<textarea
|
||||
aria-label="settings-json-editor"
|
||||
value={value}
|
||||
onChange={(event) => onChange(event.target.value)}
|
||||
/>
|
||||
),
|
||||
}));
|
||||
|
||||
function renderEditor(value: string, onChange = vi.fn()) {
|
||||
render(
|
||||
<CommonConfigEditor
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
useCommonConfig={false}
|
||||
onCommonConfigToggle={() => {}}
|
||||
commonConfigSnippet="{}"
|
||||
onCommonConfigSnippetChange={() => {}}
|
||||
commonConfigError=""
|
||||
onEditClick={() => {}}
|
||||
isModalOpen={false}
|
||||
onModalClose={() => {}}
|
||||
/>,
|
||||
);
|
||||
return onChange;
|
||||
}
|
||||
|
||||
const effortCheckbox = () =>
|
||||
screen.getByRole("checkbox", { name: "claudeConfig.effortMax" });
|
||||
|
||||
describe("CommonConfigEditor max effort toggle", () => {
|
||||
it("does not treat legacy top-level effortLevel=max as checked", () => {
|
||||
renderEditor(JSON.stringify({ effortLevel: "max" }, null, 2));
|
||||
|
||||
expect(effortCheckbox()).not.toBeChecked();
|
||||
});
|
||||
|
||||
it("writes max effort through CLAUDE_CODE_EFFORT_LEVEL env", () => {
|
||||
const onChange = renderEditor("{}");
|
||||
|
||||
fireEvent.click(effortCheckbox());
|
||||
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
const nextConfig = JSON.parse(onChange.mock.calls[0][0]);
|
||||
expect(nextConfig).toEqual({
|
||||
env: {
|
||||
CLAUDE_CODE_EFFORT_LEVEL: "max",
|
||||
},
|
||||
});
|
||||
expect(nextConfig).not.toHaveProperty("effortLevel");
|
||||
});
|
||||
|
||||
it("removes only the CLAUDE_CODE_EFFORT_LEVEL env entry when unchecked", () => {
|
||||
const onChange = renderEditor(
|
||||
JSON.stringify(
|
||||
{
|
||||
effortLevel: "max",
|
||||
env: {
|
||||
CLAUDE_CODE_EFFORT_LEVEL: "max",
|
||||
ENABLE_TOOL_SEARCH: "true",
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
|
||||
fireEvent.click(effortCheckbox());
|
||||
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
const nextConfig = JSON.parse(onChange.mock.calls[0][0]);
|
||||
expect(nextConfig).toEqual({
|
||||
effortLevel: "max",
|
||||
env: {
|
||||
ENABLE_TOOL_SEARCH: "true",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user