chatccc 0.2.245 → 0.2.246

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,34 @@
1
- import { afterEach, describe, expect, it } from "vitest";
2
-
3
- import { ChatSession } from "../index.js";
4
- import { config } from "../config.js";
5
-
6
- const originalDeepSeekApiKey = process.env.DEEPSEEK_API_KEY;
7
- const originalDeepCccApiKey = config.apiKey;
8
-
9
- afterEach(() => {
10
- if (originalDeepSeekApiKey === undefined) {
11
- delete process.env.DEEPSEEK_API_KEY;
12
- } else {
13
- process.env.DEEPSEEK_API_KEY = originalDeepSeekApiKey;
14
- }
15
- config.apiKey = originalDeepCccApiKey;
16
- });
17
-
18
- describe("builtin ChatSession config", () => {
19
- it("uses the builtin ~/.deepccc config when no apiKey is passed", () => {
20
- expect(() => new ChatSession()).not.toThrow();
21
- });
22
-
23
- it("allows constructor parameters to override config defaults", () => {
24
- expect(() => new ChatSession({ apiKey: "sk-test" })).not.toThrow();
25
- });
26
- });
1
+ import { afterEach, describe, expect, it } from "vitest";
2
+
3
+ import { ChatSession } from "../index.js";
4
+ import { config, normalizeDeepCccProvider } from "../config.js";
5
+
6
+ const originalDeepSeekApiKey = process.env.DEEPSEEK_API_KEY;
7
+ const originalDeepCccApiKey = config.apiKey;
8
+
9
+ afterEach(() => {
10
+ if (originalDeepSeekApiKey === undefined) {
11
+ delete process.env.DEEPSEEK_API_KEY;
12
+ } else {
13
+ process.env.DEEPSEEK_API_KEY = originalDeepSeekApiKey;
14
+ }
15
+ config.apiKey = originalDeepCccApiKey;
16
+ });
17
+
18
+ describe("builtin ChatSession config", () => {
19
+ it("defaults provider selection to openai and accepts anthropic case-insensitively", () => {
20
+ expect(normalizeDeepCccProvider(undefined)).toBe("openai");
21
+ expect(normalizeDeepCccProvider("")).toBe("openai");
22
+ expect(normalizeDeepCccProvider("OPENAI")).toBe("openai");
23
+ expect(normalizeDeepCccProvider("Anthropic")).toBe("anthropic");
24
+ expect(() => normalizeDeepCccProvider("antropic")).toThrow(/openai.*anthropic/i);
25
+ });
26
+
27
+ it("uses the builtin ~/.deepccc config when no apiKey is passed", () => {
28
+ expect(() => new ChatSession()).not.toThrow();
29
+ });
30
+
31
+ it("allows constructor parameters to override config defaults", () => {
32
+ expect(() => new ChatSession({ apiKey: "sk-test" })).not.toThrow();
33
+ });
34
+ });
@@ -1,195 +1,199 @@
1
- import { mkdtempSync, mkdirSync, rmSync, writeFileSync, existsSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
-
5
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
-
7
- const testHome = vi.hoisted(() => ({ dir: "" }));
8
-
9
- const aiMocks = vi.hoisted(() => ({
10
- streamText: vi.fn(),
11
- generateText: vi.fn(),
12
- }));
13
-
14
- vi.mock("node:os", async () => {
15
- const actual = await vi.importActual<typeof import("node:os")>("node:os");
16
- const [{ mkdtempSync }, { join }] = await Promise.all([import("node:fs"), import("node:path")]);
17
- testHome.dir = mkdtempSync(join(actual.tmpdir(), "chatccc-builtin-perm-"));
18
- return { ...actual, homedir: () => testHome.dir };
19
- });
20
-
21
- vi.mock("@ai-sdk/openai-compatible", () => ({
22
- createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
23
- }));
24
-
25
- vi.mock("ai", () => ({
26
- streamText: aiMocks.streamText,
27
- generateText: aiMocks.generateText,
28
- isLoopFinished: vi.fn(() => ({ loopFinished: true })),
29
- stepCountIs: vi.fn((count: number) => ({ count })),
30
- jsonSchema: vi.fn((schema: unknown) => schema),
31
- tool: vi.fn((definition: unknown) => definition),
32
- }));
33
-
34
- vi.mock("../raw-stream-log.js", () => ({
35
- createRawStreamLog: vi.fn().mockResolvedValue(null),
36
- }));
37
-
38
- import {
39
- PermissionGate,
40
- getAllowRules,
41
- isDangerousCommand,
42
- matchRule,
43
- reloadAllowRules,
44
- } from "../permissions.js";
45
- import { createBuiltinFileTools } from "../file-tools.js";
46
- import { ChatSession } from "../index.js";
47
-
48
- const streamTextMock = aiMocks.streamText;
49
- const generateTextMock = aiMocks.generateText;
50
-
51
- const ALLOW_FILE = () => join(testHome.dir, ".deepccc", "allow.json");
52
-
53
- async function collect(iterable: AsyncIterable<unknown>): Promise<unknown[]> {
54
- const events: unknown[] = [];
55
- for await (const event of iterable) events.push(event);
56
- return events;
57
- }
58
-
59
- async function* textStream(...chunks: string[]): AsyncIterable<string> {
60
- for (const chunk of chunks) yield chunk;
61
- }
62
-
63
- function lastRunCommandExecute(): (input: { command: string }, opts?: unknown) => Promise<unknown> {
64
- const call = streamTextMock.mock.calls.at(-1)?.[0] as { tools?: Record<string, { execute?: unknown }> };
65
- const execute = call?.tools?.run_command?.execute as ((input: { command: string }, opts?: unknown) => Promise<unknown>) | undefined;
66
- if (!execute) throw new Error("streamText was not called with tools.run_command.execute");
67
- return execute;
68
- }
69
-
70
- afterEach(() => {
71
- try {
72
- rmSync(ALLOW_FILE(), { force: true });
73
- } catch {}
74
- reloadAllowRules();
75
- streamTextMock.mockReset();
76
- generateTextMock.mockReset();
77
- });
78
-
79
- beforeEach(() => {
80
- try {
81
- rmSync(join(testHome.dir, ".deepccc"), { recursive: true, force: true });
82
- } catch {}
83
- mkdirSync(join(testHome.dir, ".deepccc"), { recursive: true });
84
- reloadAllowRules();
85
- });
86
-
87
- describe("builtin permissions module", () => {
88
- it("flags destructive commands and ignores normal ones", () => {
89
- expect(isDangerousCommand("rm -rf node_modules")).toBe(true);
90
- expect(isDangerousCommand("git push --force origin main")).toBe(true);
91
- expect(isDangerousCommand("git status")).toBe(false);
92
- expect(isDangerousCommand("npm test")).toBe(false);
93
- });
94
-
95
- it("matches allow/deny rules with wildcards and relative paths", () => {
96
- expect(matchRule("run_command:git status*", "run_command:git status --short")).toBe(true);
97
- expect(matchRule("edit_file:node_modules/**", "edit_file:node_modules/a/b.js")).toBe(true);
98
- expect(matchRule("run_command:npm test", "run_command:npm test extra")).toBe(false);
99
- });
100
-
101
- it("returns empty rules when allow.json is missing", () => {
102
- expect(getAllowRules()).toEqual({ allow: [], deny: [] });
103
- });
104
-
105
- it("loads rules from ~/.deepccc/allow.json", () => {
106
- writeFileSync(ALLOW_FILE(), JSON.stringify({ deny: ["run_command:npm publish*"] }), "utf-8");
107
- reloadAllowRules();
108
- expect(getAllowRules().deny).toEqual(["run_command:npm publish*"]);
109
- });
110
- });
111
-
112
- describe("builtin PermissionGate", () => {
113
- it("bypass mode allows everything", async () => {
114
- const gate = new PermissionGate("bypass");
115
- expect(await gate.check({ tool: "run_command", action: "rm -rf /", reason: "high-risk", detail: "x" })).toBe("allow");
116
- });
117
-
118
- it("ask mode denies high-risk without resolver", async () => {
119
- const gate = new PermissionGate("ask");
120
- expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("deny");
121
- });
122
-
123
- it("ask mode allows non-high-risk operations without asking", async () => {
124
- const resolver = vi.fn();
125
- const gate = new PermissionGate("ask", resolver as never);
126
- expect(await gate.check({ tool: "run_command", action: "npm test", reason: "rule", detail: "x" })).toBe("allow");
127
- expect(await gate.check({ tool: "edit_file", action: "src/a.ts", reason: "rule", detail: "x" })).toBe("allow");
128
- expect(resolver).not.toHaveBeenCalled();
129
- });
130
-
131
- it("follows resolver answer", async () => {
132
- let answer: "allow" | "deny" = "allow";
133
- const gate = new PermissionGate("ask", async () => answer);
134
- expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("allow");
135
- answer = "deny";
136
- expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("deny");
137
- });
138
-
139
- it("deny rule wins over allow rule", async () => {
140
- writeFileSync(
141
- ALLOW_FILE(),
142
- JSON.stringify({ allow: ["run_command:rm -rf /tmp*"], deny: ["run_command:rm -rf /tmp/forbidden*"] }),
143
- "utf-8",
144
- );
145
- reloadAllowRules();
146
- const gate = new PermissionGate("ask");
147
- expect(await gate.check({ tool: "run_command", action: "rm -rf /tmp/forbidden/x", reason: "high-risk", detail: "x" })).toBe("deny");
148
- });
149
- });
150
-
151
- describe("builtin file-tools permission integration", () => {
152
- it("run_command high-risk is denied by default gate", async () => {
153
- const tools = createBuiltinFileTools(testHome.dir, { permissionGate: new PermissionGate("ask") });
154
- const tool = tools.run_command as unknown as {
155
- execute: (input: { command: string }, opts?: unknown) => Promise<unknown>;
156
- };
157
- await expect(tool.execute({ command: "rm -rf node_modules" }, { abortSignal: undefined })).rejects.toThrow(/权限拒绝/);
158
- });
159
-
160
- it("no gate keeps original behavior", async () => {
161
- const tools = createBuiltinFileTools(testHome.dir);
162
- const tool = tools.run_command as unknown as {
163
- execute: (input: { command: string }, opts?: unknown) => Promise<{ exitCode: number | null }>;
164
- };
165
- const result = await tool.execute({ command: "node -e \"console.log('ok')\"" }, { abortSignal: undefined });
166
- expect(result.exitCode).toBe(0);
167
- });
168
- });
169
-
170
- describe("builtin ChatSession permission integration", () => {
171
- it("permissionMode bypass lets high-risk run_command execute", async () => {
172
- const session = new ChatSession(
173
- { apiKey: "sk-test" },
174
- { sessionId: "perm-bypass", permissionMode: "bypass" },
175
- );
176
- streamTextMock.mockReturnValueOnce({ textStream: textStream("hi") });
177
- await collect(session.chat("hi"));
178
-
179
- const result = (await lastRunCommandExecute()({ command: "node -e \"console.log('ok')\"" }, { abortSignal: undefined })) as { exitCode: number };
180
- expect(result.exitCode).toBe(0);
181
- });
182
-
183
- it("default ask mode without resolver denies high-risk run_command", async () => {
184
- const session = new ChatSession(
185
- { apiKey: "sk-test" },
186
- { sessionId: "perm-ask" },
187
- );
188
- streamTextMock.mockReturnValueOnce({ textStream: textStream("hi") });
189
- await collect(session.chat("hi"));
190
-
191
- await expect(
192
- lastRunCommandExecute()({ command: "rm -rf node_modules" }, { abortSignal: undefined }),
193
- ).rejects.toThrow(/权限拒绝/);
194
- });
195
- });
1
+ import { mkdtempSync, mkdirSync, rmSync, writeFileSync, existsSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
+
7
+ const testHome = vi.hoisted(() => ({ dir: "" }));
8
+
9
+ const aiMocks = vi.hoisted(() => ({
10
+ streamText: vi.fn(),
11
+ generateText: vi.fn(),
12
+ }));
13
+
14
+ vi.mock("node:os", async () => {
15
+ const actual = await vi.importActual<typeof import("node:os")>("node:os");
16
+ const [{ mkdtempSync }, { join }] = await Promise.all([import("node:fs"), import("node:path")]);
17
+ testHome.dir = mkdtempSync(join(actual.tmpdir(), "chatccc-builtin-perm-"));
18
+ return { ...actual, homedir: () => testHome.dir };
19
+ });
20
+
21
+ vi.mock("@ai-sdk/openai-compatible", () => ({
22
+ createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
23
+ }));
24
+
25
+ vi.mock("@ai-sdk/anthropic", () => ({
26
+ createAnthropic: vi.fn(() => (modelId: string) => ({ modelId })),
27
+ }));
28
+
29
+ vi.mock("ai", () => ({
30
+ streamText: aiMocks.streamText,
31
+ generateText: aiMocks.generateText,
32
+ isLoopFinished: vi.fn(() => ({ loopFinished: true })),
33
+ stepCountIs: vi.fn((count: number) => ({ count })),
34
+ jsonSchema: vi.fn((schema: unknown) => schema),
35
+ tool: vi.fn((definition: unknown) => definition),
36
+ }));
37
+
38
+ vi.mock("../raw-stream-log.js", () => ({
39
+ createRawStreamLog: vi.fn().mockResolvedValue(null),
40
+ }));
41
+
42
+ import {
43
+ PermissionGate,
44
+ getAllowRules,
45
+ isDangerousCommand,
46
+ matchRule,
47
+ reloadAllowRules,
48
+ } from "../permissions.js";
49
+ import { createBuiltinFileTools } from "../file-tools.js";
50
+ import { ChatSession } from "../index.js";
51
+
52
+ const streamTextMock = aiMocks.streamText;
53
+ const generateTextMock = aiMocks.generateText;
54
+
55
+ const ALLOW_FILE = () => join(testHome.dir, ".deepccc", "allow.json");
56
+
57
+ async function collect(iterable: AsyncIterable<unknown>): Promise<unknown[]> {
58
+ const events: unknown[] = [];
59
+ for await (const event of iterable) events.push(event);
60
+ return events;
61
+ }
62
+
63
+ async function* textStream(...chunks: string[]): AsyncIterable<string> {
64
+ for (const chunk of chunks) yield chunk;
65
+ }
66
+
67
+ function lastRunCommandExecute(): (input: { command: string }, opts?: unknown) => Promise<unknown> {
68
+ const call = streamTextMock.mock.calls.at(-1)?.[0] as { tools?: Record<string, { execute?: unknown }> };
69
+ const execute = call?.tools?.run_command?.execute as ((input: { command: string }, opts?: unknown) => Promise<unknown>) | undefined;
70
+ if (!execute) throw new Error("streamText was not called with tools.run_command.execute");
71
+ return execute;
72
+ }
73
+
74
+ afterEach(() => {
75
+ try {
76
+ rmSync(ALLOW_FILE(), { force: true });
77
+ } catch {}
78
+ reloadAllowRules();
79
+ streamTextMock.mockReset();
80
+ generateTextMock.mockReset();
81
+ });
82
+
83
+ beforeEach(() => {
84
+ try {
85
+ rmSync(join(testHome.dir, ".deepccc"), { recursive: true, force: true });
86
+ } catch {}
87
+ mkdirSync(join(testHome.dir, ".deepccc"), { recursive: true });
88
+ reloadAllowRules();
89
+ });
90
+
91
+ describe("builtin permissions module", () => {
92
+ it("flags destructive commands and ignores normal ones", () => {
93
+ expect(isDangerousCommand("rm -rf node_modules")).toBe(true);
94
+ expect(isDangerousCommand("git push --force origin main")).toBe(true);
95
+ expect(isDangerousCommand("git status")).toBe(false);
96
+ expect(isDangerousCommand("npm test")).toBe(false);
97
+ });
98
+
99
+ it("matches allow/deny rules with wildcards and relative paths", () => {
100
+ expect(matchRule("run_command:git status*", "run_command:git status --short")).toBe(true);
101
+ expect(matchRule("edit_file:node_modules/**", "edit_file:node_modules/a/b.js")).toBe(true);
102
+ expect(matchRule("run_command:npm test", "run_command:npm test extra")).toBe(false);
103
+ });
104
+
105
+ it("returns empty rules when allow.json is missing", () => {
106
+ expect(getAllowRules()).toEqual({ allow: [], deny: [] });
107
+ });
108
+
109
+ it("loads rules from ~/.deepccc/allow.json", () => {
110
+ writeFileSync(ALLOW_FILE(), JSON.stringify({ deny: ["run_command:npm publish*"] }), "utf-8");
111
+ reloadAllowRules();
112
+ expect(getAllowRules().deny).toEqual(["run_command:npm publish*"]);
113
+ });
114
+ });
115
+
116
+ describe("builtin PermissionGate", () => {
117
+ it("bypass mode allows everything", async () => {
118
+ const gate = new PermissionGate("bypass");
119
+ expect(await gate.check({ tool: "run_command", action: "rm -rf /", reason: "high-risk", detail: "x" })).toBe("allow");
120
+ });
121
+
122
+ it("ask mode denies high-risk without resolver", async () => {
123
+ const gate = new PermissionGate("ask");
124
+ expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("deny");
125
+ });
126
+
127
+ it("ask mode allows non-high-risk operations without asking", async () => {
128
+ const resolver = vi.fn();
129
+ const gate = new PermissionGate("ask", resolver as never);
130
+ expect(await gate.check({ tool: "run_command", action: "npm test", reason: "rule", detail: "x" })).toBe("allow");
131
+ expect(await gate.check({ tool: "edit_file", action: "src/a.ts", reason: "rule", detail: "x" })).toBe("allow");
132
+ expect(resolver).not.toHaveBeenCalled();
133
+ });
134
+
135
+ it("follows resolver answer", async () => {
136
+ let answer: "allow" | "deny" = "allow";
137
+ const gate = new PermissionGate("ask", async () => answer);
138
+ expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("allow");
139
+ answer = "deny";
140
+ expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("deny");
141
+ });
142
+
143
+ it("deny rule wins over allow rule", async () => {
144
+ writeFileSync(
145
+ ALLOW_FILE(),
146
+ JSON.stringify({ allow: ["run_command:rm -rf /tmp*"], deny: ["run_command:rm -rf /tmp/forbidden*"] }),
147
+ "utf-8",
148
+ );
149
+ reloadAllowRules();
150
+ const gate = new PermissionGate("ask");
151
+ expect(await gate.check({ tool: "run_command", action: "rm -rf /tmp/forbidden/x", reason: "high-risk", detail: "x" })).toBe("deny");
152
+ });
153
+ });
154
+
155
+ describe("builtin file-tools permission integration", () => {
156
+ it("run_command high-risk is denied by default gate", async () => {
157
+ const tools = createBuiltinFileTools(testHome.dir, { permissionGate: new PermissionGate("ask") });
158
+ const tool = tools.run_command as unknown as {
159
+ execute: (input: { command: string }, opts?: unknown) => Promise<unknown>;
160
+ };
161
+ await expect(tool.execute({ command: "rm -rf node_modules" }, { abortSignal: undefined })).rejects.toThrow(/权限拒绝/);
162
+ });
163
+
164
+ it("no gate keeps original behavior", async () => {
165
+ const tools = createBuiltinFileTools(testHome.dir);
166
+ const tool = tools.run_command as unknown as {
167
+ execute: (input: { command: string }, opts?: unknown) => Promise<{ exitCode: number | null }>;
168
+ };
169
+ const result = await tool.execute({ command: "node -e \"console.log('ok')\"" }, { abortSignal: undefined });
170
+ expect(result.exitCode).toBe(0);
171
+ });
172
+ });
173
+
174
+ describe("builtin ChatSession permission integration", () => {
175
+ it("permissionMode bypass lets high-risk run_command execute", async () => {
176
+ const session = new ChatSession(
177
+ { apiKey: "sk-test" },
178
+ { sessionId: "perm-bypass", permissionMode: "bypass" },
179
+ );
180
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("hi") });
181
+ await collect(session.chat("hi"));
182
+
183
+ const result = (await lastRunCommandExecute()({ command: "node -e \"console.log('ok')\"" }, { abortSignal: undefined })) as { exitCode: number };
184
+ expect(result.exitCode).toBe(0);
185
+ });
186
+
187
+ it("default ask mode without resolver denies high-risk run_command", async () => {
188
+ const session = new ChatSession(
189
+ { apiKey: "sk-test" },
190
+ { sessionId: "perm-ask" },
191
+ );
192
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("hi") });
193
+ await collect(session.chat("hi"));
194
+
195
+ await expect(
196
+ lastRunCommandExecute()({ command: "rm -rf node_modules" }, { abortSignal: undefined }),
197
+ ).rejects.toThrow(/权限拒绝/);
198
+ });
199
+ });
@@ -29,6 +29,10 @@ vi.mock("@ai-sdk/openai-compatible", () => ({
29
29
  createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
30
30
  }));
31
31
 
32
+ vi.mock("@ai-sdk/anthropic", () => ({
33
+ createAnthropic: vi.fn(() => (modelId: string) => ({ modelId })),
34
+ }));
35
+
32
36
  vi.mock("ai", () => ({
33
37
  streamText: aiMocks.streamText,
34
38
  generateText: aiMocks.generateText,
@@ -55,8 +59,8 @@ import { ChatSession } from "../index.js";
55
59
  const streamTextMock = aiMocks.streamText;
56
60
  const generateTextMock = aiMocks.generateText;
57
61
 
58
- const originalRawStreamLogs = structuredClone(config.rawStreamLogs);
59
- const originalStreaming = config.streaming;
62
+ const originalRawStreamLogs = structuredClone(config.rawStreamLogs);
63
+ const originalStreaming = config.streaming;
60
64
  const PRIVACY_FILE = join(privacyState.dir, "privacy.json");
61
65
 
62
66
  function writePrivacy(content: string): void {
@@ -79,18 +83,18 @@ beforeEach(() => {
79
83
  } catch {}
80
84
  reloadPrivacyRules();
81
85
  streamTextMock.mockReset();
82
- generateTextMock.mockReset();
83
- config.rawStreamLogs = structuredClone(originalRawStreamLogs);
84
- config.streaming = true;
86
+ generateTextMock.mockReset();
87
+ config.rawStreamLogs = structuredClone(originalRawStreamLogs);
88
+ config.streaming = true;
85
89
  });
86
90
 
87
91
  afterEach(() => {
88
92
  try {
89
93
  rmSync(PRIVACY_FILE, { force: true });
90
94
  } catch {}
91
- reloadPrivacyRules();
92
- config.streaming = originalStreaming;
93
- });
95
+ reloadPrivacyRules();
96
+ config.streaming = originalStreaming;
97
+ });
94
98
 
95
99
  afterAll(() => {
96
100
  try {
@@ -11,8 +11,8 @@
11
11
  * 非 TTY(管道/CI)或 --plain 回退为纯文本流式输出;--stream-json 机器接口不变。
12
12
  */
13
13
 
14
- import * as readline from "node:readline";
15
- import process from "node:process";
14
+ import * as readline from "node:readline";
15
+ import process from "node:process";
16
16
  import { appendFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
17
17
  import { homedir } from "node:os";
18
18
  import { join, resolve as resolvePath } from "node:path";
@@ -59,6 +59,12 @@ function parsePositiveIntegerOption(name: string, value: string): number {
59
59
  return parsed;
60
60
  }
61
61
 
62
+ function parseProviderOption(value: string): "openai" | "anthropic" {
63
+ const normalized = value.trim().toLowerCase();
64
+ if (normalized === "openai" || normalized === "anthropic") return normalized;
65
+ throw new Error(`--provider must be "openai" or "anthropic", received: ${value}`);
66
+ }
67
+
62
68
  function parseArgs(argv = process.argv.slice(2)): ParsedArgs {
63
69
  const config: ChatSessionConfig = {};
64
70
  const options: ChatSessionOptions = {};
@@ -72,7 +78,10 @@ function parseArgs(argv = process.argv.slice(2)): ParsedArgs {
72
78
  for (let i = 0; i < argv.length; i++) {
73
79
  const arg = argv[i];
74
80
  const next = argv[i + 1];
75
- if (arg === "--model" && next !== undefined) {
81
+ if (arg === "--provider" && next !== undefined) {
82
+ config.provider = parseProviderOption(next);
83
+ i++;
84
+ } else if (arg === "--model" && next !== undefined) {
76
85
  config.model = next;
77
86
  i++;
78
87
  } else if (arg === "--effort" && next !== undefined) {
@@ -132,9 +141,10 @@ function printHelp(appConfig: RuntimeDeps["appConfig"]): void {
132
141
  "Usage: deepccc [options]",
133
142
  "",
134
143
  "Options:",
144
+ ` --provider <name> API protocol: openai or anthropic (current default ${appConfig.provider})`,
135
145
  ` --model <name> Model name (current default ${appConfig.model})`,
136
146
  ` --effort <level> Reasoning effort: none/minimal/low/medium/high/xhigh/max (overrides config.effort)`,
137
- ` --base-url <url> OpenAI-compatible API base URL (current default ${appConfig.baseURL})`,
147
+ ` --base-url <url> Provider API base URL (current default ${appConfig.baseURL})`,
138
148
  " --api-key <key> API key",
139
149
  " --cwd <path> Working directory",
140
150
  " --max-steps <n> Optional tool-step limit. Omit for no step limit",
@@ -375,6 +385,7 @@ async function runRepl(args: ParsedArgs): Promise<void> {
375
385
  }
376
386
 
377
387
  console.log(`${C.dim}DeepCCC agent${C.reset}`);
388
+ console.log(`${C.dim}Provider: ${args.config.provider ?? appConfig.provider}${C.reset}`);
378
389
  console.log(`${C.dim}Model: ${args.config.model ?? appConfig.model}${C.reset}`);
379
390
  console.log(`${C.dim}Directory: ${cwd}${C.reset}`);
380
391
  console.log(`${C.dim}Session: ${resolvedSession.sessionId} (${resolvedSession.mode === "new" ? "new" : "resumed"})${C.reset}`);
@@ -637,11 +648,11 @@ async function main(): Promise<void> {
637
648
 
638
649
  const args = parseArgs();
639
650
 
640
- if (args.streamJson) {
641
- const code = await runStreamJson(args);
642
- process.exitCode = code;
643
- return;
644
- }
651
+ if (args.streamJson) {
652
+ const code = await runStreamJson(args);
653
+ process.exitCode = code;
654
+ return;
655
+ }
645
656
 
646
657
  if (args.help) {
647
658
  const { appConfig } = await loadRuntime();