chatccc 0.2.198 → 0.2.199

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.
Files changed (52) hide show
  1. package/agent-prompts/cursor_specific.md +13 -13
  2. package/bin/cccagent.mjs +17 -17
  3. package/config.sample.json +27 -27
  4. package/package.json +1 -1
  5. package/src/__tests__/agent-reload-config-rpc.test.ts +99 -99
  6. package/src/__tests__/builtin-chat-session.test.ts +277 -277
  7. package/src/__tests__/builtin-cli-json.test.ts +39 -39
  8. package/src/__tests__/builtin-config.test.ts +33 -33
  9. package/src/__tests__/builtin-context.test.ts +163 -163
  10. package/src/__tests__/builtin-file-tools.test.ts +224 -224
  11. package/src/__tests__/builtin-session-select.test.ts +116 -116
  12. package/src/__tests__/builtin-sigint.test.ts +56 -56
  13. package/src/__tests__/cards.test.ts +109 -109
  14. package/src/__tests__/ccc-adapter.test.ts +114 -114
  15. package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
  16. package/src/__tests__/chatgpt-subscription.test.ts +135 -135
  17. package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
  18. package/src/__tests__/claude-raw-stream-log.test.ts +87 -87
  19. package/src/__tests__/codex-raw-stream-log.test.ts +163 -163
  20. package/src/__tests__/config-reload.test.ts +10 -10
  21. package/src/__tests__/config-sample.test.ts +18 -18
  22. package/src/__tests__/cursor-adapter.test.ts +66 -7
  23. package/src/__tests__/feishu-avatar.test.ts +40 -40
  24. package/src/__tests__/jsonl-stream.test.ts +79 -79
  25. package/src/__tests__/orchestrator.test.ts +200 -200
  26. package/src/__tests__/raw-stream-log.test.ts +106 -106
  27. package/src/__tests__/session.test.ts +40 -40
  28. package/src/__tests__/sim-platform.test.ts +12 -12
  29. package/src/__tests__/web-ui.test.ts +209 -209
  30. package/src/adapters/ccc-adapter.ts +121 -121
  31. package/src/adapters/claude-adapter.ts +603 -603
  32. package/src/adapters/codex-adapter.ts +380 -380
  33. package/src/adapters/cursor-adapter.ts +39 -6
  34. package/src/adapters/jsonl-stream.ts +157 -157
  35. package/src/adapters/raw-stream-log.ts +124 -124
  36. package/src/agent-reload-config-rpc.ts +34 -34
  37. package/src/builtin/cli.ts +473 -473
  38. package/src/builtin/context.ts +323 -323
  39. package/src/builtin/file-tools.ts +1072 -1072
  40. package/src/builtin/index.ts +404 -404
  41. package/src/builtin/session-select.ts +48 -48
  42. package/src/builtin/sigint.ts +50 -50
  43. package/src/cards.ts +195 -195
  44. package/src/chatgpt-subscription-rpc.ts +27 -27
  45. package/src/chatgpt-subscription.ts +299 -299
  46. package/src/chrome-devtools-guard.ts +318 -318
  47. package/src/config.ts +125 -125
  48. package/src/feishu-api.ts +49 -49
  49. package/src/orchestrator.ts +179 -179
  50. package/src/runtime-reload.ts +34 -34
  51. package/src/session.ts +141 -141
  52. package/src/web-ui.ts +205 -205
@@ -1,114 +1,114 @@
1
- import { mkdtemp } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
-
5
- import { afterEach, describe, expect, it, vi } from "vitest";
6
-
7
- const streamTextMock = vi.fn();
8
- const generateTextMock = vi.fn();
9
-
10
- vi.mock("@ai-sdk/openai-compatible", () => ({
11
- createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
12
- }));
13
-
14
- vi.mock("ai", () => ({
15
- streamText: streamTextMock,
16
- generateText: generateTextMock,
17
- isLoopFinished: vi.fn(() => ({ loopFinished: true })),
18
- stepCountIs: vi.fn((count: number) => ({ count })),
19
- jsonSchema: vi.fn((schema: unknown) => schema),
20
- tool: vi.fn((definition: unknown) => definition),
21
- }));
22
-
23
- async function* textStream(...chunks: string[]): AsyncIterable<string> {
24
- for (const chunk of chunks) yield chunk;
25
- }
26
-
27
- async function* fullStream(...parts: unknown[]): AsyncIterable<unknown> {
28
- for (const part of parts) yield part;
29
- }
30
-
31
- afterEach(() => {
32
- streamTextMock.mockReset();
33
- generateTextMock.mockReset();
34
- });
35
-
36
- describe("createCccAdapter", () => {
37
- it("creates a persisted ccc session and exposes model/cwd metadata", async () => {
38
- const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
39
- const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-meta-"));
40
- const adapter = createCccAdapter({
41
- apiKey: "sk-test",
42
- contextDir,
43
- model: "deepseek-v4-pro",
44
- });
45
-
46
- const created = await adapter.createSession("F:\\repo");
47
- const info = await adapter.getSessionInfo(created.sessionId);
48
-
49
- expect(created.sessionId).toMatch(/^session-\d{8}-\d{6}-[a-f0-9]{6}$/);
50
- expect(info).toEqual(expect.objectContaining({
51
- sessionId: created.sessionId,
52
- cwd: "F:\\repo",
53
- model: "deepseek-v4-pro",
54
- }));
55
- });
56
-
57
- it("maps ChatSession text chunks to unified assistant text blocks", async () => {
58
- const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
59
- const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-stream-"));
60
- const adapter = createCccAdapter({
61
- apiKey: "sk-test",
62
- contextDir,
63
- model: "deepseek-v4-flash",
64
- });
65
- const { sessionId } = await adapter.createSession("F:\\repo");
66
- streamTextMock.mockReturnValueOnce({ textStream: textStream("hello", " world") });
67
-
68
- const messages = [];
69
- for await (const message of adapter.prompt(sessionId, "hi", "F:\\repo")) {
70
- messages.push(message);
71
- }
72
-
73
- expect(messages).toEqual([
74
- { type: "assistant", blocks: [{ type: "text", text: "hello" }] },
75
- { type: "assistant", blocks: [{ type: "text", text: " world" }] },
76
- ]);
77
- expect(streamTextMock).toHaveBeenCalledWith(expect.objectContaining({
78
- model: { modelId: "deepseek-v4-flash" },
79
- }));
80
- });
81
-
82
- it("maps ChatSession tool events to unified tool blocks", async () => {
83
- const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
84
- const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-tools-"));
85
- const adapter = createCccAdapter({
86
- apiKey: "sk-test",
87
- contextDir,
88
- model: "deepseek-v4-flash",
89
- });
90
- const { sessionId } = await adapter.createSession("F:\\repo");
91
- streamTextMock.mockReturnValueOnce({
92
- fullStream: fullStream(
93
- { type: "tool-call", toolCallId: "call-1", toolName: "read_file", input: { path: "README.md" } },
94
- { type: "tool-result", toolCallId: "call-1", toolName: "read_file", output: { content: "hello" } },
95
- ),
96
- });
97
-
98
- const messages = [];
99
- for await (const message of adapter.prompt(sessionId, "read", "F:\\repo")) {
100
- messages.push(message);
101
- }
102
-
103
- expect(messages).toEqual([
104
- {
105
- type: "assistant",
106
- blocks: [{ type: "tool_use", id: "call-1", name: "read_file", input: { path: "README.md" } }],
107
- },
108
- {
109
- type: "assistant",
110
- blocks: [{ type: "tool_result", tool_use_id: "call-1", content: { content: "hello" }, is_error: false }],
111
- },
112
- ]);
113
- });
114
- });
1
+ import { mkdtemp } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+
5
+ import { afterEach, describe, expect, it, vi } from "vitest";
6
+
7
+ const streamTextMock = vi.fn();
8
+ const generateTextMock = vi.fn();
9
+
10
+ vi.mock("@ai-sdk/openai-compatible", () => ({
11
+ createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
12
+ }));
13
+
14
+ vi.mock("ai", () => ({
15
+ streamText: streamTextMock,
16
+ generateText: generateTextMock,
17
+ isLoopFinished: vi.fn(() => ({ loopFinished: true })),
18
+ stepCountIs: vi.fn((count: number) => ({ count })),
19
+ jsonSchema: vi.fn((schema: unknown) => schema),
20
+ tool: vi.fn((definition: unknown) => definition),
21
+ }));
22
+
23
+ async function* textStream(...chunks: string[]): AsyncIterable<string> {
24
+ for (const chunk of chunks) yield chunk;
25
+ }
26
+
27
+ async function* fullStream(...parts: unknown[]): AsyncIterable<unknown> {
28
+ for (const part of parts) yield part;
29
+ }
30
+
31
+ afterEach(() => {
32
+ streamTextMock.mockReset();
33
+ generateTextMock.mockReset();
34
+ });
35
+
36
+ describe("createCccAdapter", () => {
37
+ it("creates a persisted ccc session and exposes model/cwd metadata", async () => {
38
+ const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
39
+ const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-meta-"));
40
+ const adapter = createCccAdapter({
41
+ apiKey: "sk-test",
42
+ contextDir,
43
+ model: "deepseek-v4-pro",
44
+ });
45
+
46
+ const created = await adapter.createSession("F:\\repo");
47
+ const info = await adapter.getSessionInfo(created.sessionId);
48
+
49
+ expect(created.sessionId).toMatch(/^session-\d{8}-\d{6}-[a-f0-9]{6}$/);
50
+ expect(info).toEqual(expect.objectContaining({
51
+ sessionId: created.sessionId,
52
+ cwd: "F:\\repo",
53
+ model: "deepseek-v4-pro",
54
+ }));
55
+ });
56
+
57
+ it("maps ChatSession text chunks to unified assistant text blocks", async () => {
58
+ const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
59
+ const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-stream-"));
60
+ const adapter = createCccAdapter({
61
+ apiKey: "sk-test",
62
+ contextDir,
63
+ model: "deepseek-v4-flash",
64
+ });
65
+ const { sessionId } = await adapter.createSession("F:\\repo");
66
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("hello", " world") });
67
+
68
+ const messages = [];
69
+ for await (const message of adapter.prompt(sessionId, "hi", "F:\\repo")) {
70
+ messages.push(message);
71
+ }
72
+
73
+ expect(messages).toEqual([
74
+ { type: "assistant", blocks: [{ type: "text", text: "hello" }] },
75
+ { type: "assistant", blocks: [{ type: "text", text: " world" }] },
76
+ ]);
77
+ expect(streamTextMock).toHaveBeenCalledWith(expect.objectContaining({
78
+ model: { modelId: "deepseek-v4-flash" },
79
+ }));
80
+ });
81
+
82
+ it("maps ChatSession tool events to unified tool blocks", async () => {
83
+ const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
84
+ const contextDir = await mkdtemp(join(tmpdir(), "chatccc-ccc-adapter-tools-"));
85
+ const adapter = createCccAdapter({
86
+ apiKey: "sk-test",
87
+ contextDir,
88
+ model: "deepseek-v4-flash",
89
+ });
90
+ const { sessionId } = await adapter.createSession("F:\\repo");
91
+ streamTextMock.mockReturnValueOnce({
92
+ fullStream: fullStream(
93
+ { type: "tool-call", toolCallId: "call-1", toolName: "read_file", input: { path: "README.md" } },
94
+ { type: "tool-result", toolCallId: "call-1", toolName: "read_file", output: { content: "hello" } },
95
+ ),
96
+ });
97
+
98
+ const messages = [];
99
+ for await (const message of adapter.prompt(sessionId, "read", "F:\\repo")) {
100
+ messages.push(message);
101
+ }
102
+
103
+ expect(messages).toEqual([
104
+ {
105
+ type: "assistant",
106
+ blocks: [{ type: "tool_use", id: "call-1", name: "read_file", input: { path: "README.md" } }],
107
+ },
108
+ {
109
+ type: "assistant",
110
+ blocks: [{ type: "tool_result", tool_use_id: "call-1", content: { content: "hello" }, is_error: false }],
111
+ },
112
+ ]);
113
+ });
114
+ });
@@ -1,89 +1,89 @@
1
- import { Readable } from "node:stream";
2
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
-
4
- const mockGetChatGptSubscriptionStatus = vi.hoisted(() => vi.fn());
5
-
6
- vi.mock("../chatgpt-subscription.ts", () => ({
7
- getChatGptSubscriptionStatus: mockGetChatGptSubscriptionStatus,
8
- }));
9
-
10
- import {
11
- CHATGPT_SUBSCRIPTION_PATH,
12
- handleChatGptSubscriptionRequest,
13
- } from "../chatgpt-subscription-rpc.ts";
14
-
15
- function request(path = CHATGPT_SUBSCRIPTION_PATH, method = "POST"): Readable & {
16
- url?: string;
17
- method?: string;
18
- headers: Record<string, string>;
19
- } {
20
- const req = Readable.from([]) as Readable & {
21
- url?: string;
22
- method?: string;
23
- headers: Record<string, string>;
24
- };
25
- req.url = path;
26
- req.method = method;
27
- req.headers = {};
28
- return req;
29
- }
30
-
31
- function response() {
32
- const res = {
33
- statusCode: 0,
34
- headers: {} as Record<string, string>,
35
- body: "",
36
- writeHead(status: number, headers: Record<string, string>) {
37
- this.statusCode = status;
38
- this.headers = headers;
39
- return this;
40
- },
41
- end(chunk?: string) {
42
- this.body += chunk ?? "";
43
- return this;
44
- },
45
- };
46
- return res;
47
- }
48
-
49
- describe("ChatGPT subscription RPC", () => {
50
- beforeEach(() => {
51
- mockGetChatGptSubscriptionStatus.mockReset();
52
- mockGetChatGptSubscriptionStatus.mockResolvedValue({
53
- ok: false,
54
- code: "chrome_cdp_disabled",
55
- reason: "Chrome CDP guard is disabled in ChatCCC config.",
56
- chromeCdp: { enabled: false, port: 15166, status: "skipped" },
57
- });
58
- });
59
-
60
- it("returns the structured subscription lookup JSON", async () => {
61
- const req = request();
62
- const res = response();
63
-
64
- await expect(handleChatGptSubscriptionRequest(req as never, res as never)).resolves.toBe(true);
65
-
66
- expect(res.statusCode).toBe(200);
67
- expect(JSON.parse(res.body)).toEqual({
68
- ok: false,
69
- code: "chrome_cdp_disabled",
70
- reason: "Chrome CDP guard is disabled in ChatCCC config.",
71
- chromeCdp: { enabled: false, port: 15166, status: "skipped" },
72
- });
73
- });
74
-
75
- it("does not handle other paths", async () => {
76
- const res = response();
77
-
78
- await expect(handleChatGptSubscriptionRequest(request("/api/other") as never, res as never)).resolves.toBe(false);
79
- expect(res.body).toBe("");
80
- });
81
-
82
- it("rejects non-POST methods", async () => {
83
- const res = response();
84
-
85
- await expect(handleChatGptSubscriptionRequest(request(CHATGPT_SUBSCRIPTION_PATH, "GET") as never, res as never)).resolves.toBe(true);
86
- expect(res.statusCode).toBe(405);
87
- expect(JSON.parse(res.body)).toMatchObject({ ok: false, code: "method_not_allowed" });
88
- });
89
- });
1
+ import { Readable } from "node:stream";
2
+ import { beforeEach, describe, expect, it, vi } from "vitest";
3
+
4
+ const mockGetChatGptSubscriptionStatus = vi.hoisted(() => vi.fn());
5
+
6
+ vi.mock("../chatgpt-subscription.ts", () => ({
7
+ getChatGptSubscriptionStatus: mockGetChatGptSubscriptionStatus,
8
+ }));
9
+
10
+ import {
11
+ CHATGPT_SUBSCRIPTION_PATH,
12
+ handleChatGptSubscriptionRequest,
13
+ } from "../chatgpt-subscription-rpc.ts";
14
+
15
+ function request(path = CHATGPT_SUBSCRIPTION_PATH, method = "POST"): Readable & {
16
+ url?: string;
17
+ method?: string;
18
+ headers: Record<string, string>;
19
+ } {
20
+ const req = Readable.from([]) as Readable & {
21
+ url?: string;
22
+ method?: string;
23
+ headers: Record<string, string>;
24
+ };
25
+ req.url = path;
26
+ req.method = method;
27
+ req.headers = {};
28
+ return req;
29
+ }
30
+
31
+ function response() {
32
+ const res = {
33
+ statusCode: 0,
34
+ headers: {} as Record<string, string>,
35
+ body: "",
36
+ writeHead(status: number, headers: Record<string, string>) {
37
+ this.statusCode = status;
38
+ this.headers = headers;
39
+ return this;
40
+ },
41
+ end(chunk?: string) {
42
+ this.body += chunk ?? "";
43
+ return this;
44
+ },
45
+ };
46
+ return res;
47
+ }
48
+
49
+ describe("ChatGPT subscription RPC", () => {
50
+ beforeEach(() => {
51
+ mockGetChatGptSubscriptionStatus.mockReset();
52
+ mockGetChatGptSubscriptionStatus.mockResolvedValue({
53
+ ok: false,
54
+ code: "chrome_cdp_disabled",
55
+ reason: "Chrome CDP guard is disabled in ChatCCC config.",
56
+ chromeCdp: { enabled: false, port: 15166, status: "skipped" },
57
+ });
58
+ });
59
+
60
+ it("returns the structured subscription lookup JSON", async () => {
61
+ const req = request();
62
+ const res = response();
63
+
64
+ await expect(handleChatGptSubscriptionRequest(req as never, res as never)).resolves.toBe(true);
65
+
66
+ expect(res.statusCode).toBe(200);
67
+ expect(JSON.parse(res.body)).toEqual({
68
+ ok: false,
69
+ code: "chrome_cdp_disabled",
70
+ reason: "Chrome CDP guard is disabled in ChatCCC config.",
71
+ chromeCdp: { enabled: false, port: 15166, status: "skipped" },
72
+ });
73
+ });
74
+
75
+ it("does not handle other paths", async () => {
76
+ const res = response();
77
+
78
+ await expect(handleChatGptSubscriptionRequest(request("/api/other") as never, res as never)).resolves.toBe(false);
79
+ expect(res.body).toBe("");
80
+ });
81
+
82
+ it("rejects non-POST methods", async () => {
83
+ const res = response();
84
+
85
+ await expect(handleChatGptSubscriptionRequest(request(CHATGPT_SUBSCRIPTION_PATH, "GET") as never, res as never)).resolves.toBe(true);
86
+ expect(res.statusCode).toBe(405);
87
+ expect(JSON.parse(res.body)).toMatchObject({ ok: false, code: "method_not_allowed" });
88
+ });
89
+ });