chatccc 0.2.195 → 0.2.197

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 (51) 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 -0
  6. package/src/__tests__/builtin-chat-session.test.ts +277 -181
  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 -196
  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 -113
  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 -0
  19. package/src/__tests__/codex-raw-stream-log.test.ts +120 -0
  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 +99 -2
  23. package/src/__tests__/feishu-avatar.test.ts +40 -40
  24. package/src/__tests__/orchestrator.test.ts +181 -154
  25. package/src/__tests__/raw-stream-log.test.ts +106 -106
  26. package/src/__tests__/session.test.ts +40 -40
  27. package/src/__tests__/sim-platform.test.ts +12 -12
  28. package/src/__tests__/web-ui.test.ts +209 -209
  29. package/src/adapters/ccc-adapter.ts +121 -119
  30. package/src/adapters/claude-adapter.ts +603 -566
  31. package/src/adapters/codex-adapter.ts +57 -32
  32. package/src/adapters/cursor-adapter.ts +182 -57
  33. package/src/adapters/raw-stream-log.ts +124 -124
  34. package/src/agent-reload-config-rpc.ts +34 -0
  35. package/src/builtin/cli.ts +473 -461
  36. package/src/builtin/context.ts +323 -323
  37. package/src/builtin/file-tools.ts +1072 -915
  38. package/src/builtin/index.ts +404 -353
  39. package/src/builtin/session-select.ts +48 -48
  40. package/src/builtin/sigint.ts +50 -50
  41. package/src/cards.ts +195 -195
  42. package/src/chatgpt-subscription-rpc.ts +27 -27
  43. package/src/chatgpt-subscription.ts +299 -299
  44. package/src/chrome-devtools-guard.ts +318 -318
  45. package/src/config.ts +125 -125
  46. package/src/feishu-api.ts +49 -49
  47. package/src/index.ts +8 -13
  48. package/src/orchestrator.ts +166 -145
  49. package/src/runtime-reload.ts +34 -0
  50. package/src/session.ts +132 -130
  51. package/src/web-ui.ts +205 -205
@@ -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 = "GET"): 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-GET methods", async () => {
83
- const res = response();
84
-
85
- await expect(handleChatGptSubscriptionRequest(request(CHATGPT_SUBSCRIPTION_PATH, "POST") 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
+ });
@@ -1,135 +1,135 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- import { config } from "../config.ts";
4
- import { getChatGptSubscriptionStatus } from "../chatgpt-subscription.ts";
5
-
6
- describe("ChatGPT subscription lookup", () => {
7
- beforeEach(() => {
8
- config.chromeDevtools = { enabled: true, port: 15166, chromePath: "" };
9
- });
10
-
11
- it("returns disabled without probing the port when Chrome CDP is off", async () => {
12
- config.chromeDevtools = { enabled: false, port: 15166, chromePath: "" };
13
- const probeChromeCdpImpl = vi.fn();
14
- const fetchImpl = vi.fn() as unknown as typeof fetch;
15
-
16
- await expect(getChatGptSubscriptionStatus({ probeChromeCdpImpl, fetchImpl })).resolves.toMatchObject({
17
- ok: false,
18
- code: "chrome_cdp_disabled",
19
- chromeCdp: { enabled: false, port: 15166, status: "skipped" },
20
- });
21
- expect(probeChromeCdpImpl).not.toHaveBeenCalled();
22
- expect(fetchImpl).not.toHaveBeenCalled();
23
- });
24
-
25
- it("returns occupied when the configured port is not a healthy Chrome CDP endpoint", async () => {
26
- await expect(getChatGptSubscriptionStatus({
27
- probeChromeCdpImpl: vi.fn(async () => "occupied" as const),
28
- })).resolves.toMatchObject({
29
- ok: false,
30
- code: "chrome_cdp_occupied",
31
- reason: expect.stringContaining("not a healthy Chrome CDP endpoint"),
32
- });
33
- });
34
-
35
- it("returns page missing when CDP has no ChatGPT page and cannot create one", async () => {
36
- const fetchImpl = vi.fn(async (url: string | URL | Request) => {
37
- const text = String(url);
38
- if (text.endsWith("/json/list")) return new Response(JSON.stringify([]), { status: 200 });
39
- if (text.includes("/json/new?")) return new Response("nope", { status: 500 });
40
- throw new Error(`unexpected fetch: ${text}`);
41
- }) as unknown as typeof fetch;
42
-
43
- await expect(getChatGptSubscriptionStatus({
44
- fetchImpl,
45
- probeChromeCdpImpl: vi.fn(async () => "healthy" as const),
46
- })).resolves.toMatchObject({
47
- ok: false,
48
- code: "chatgpt_page_missing",
49
- });
50
- });
51
-
52
- it("closes only the temporary ChatGPT page created for this lookup", async () => {
53
- const closed: string[] = [];
54
- const fetchImpl = vi.fn(async (url: string | URL | Request) => {
55
- const text = String(url);
56
- if (text.endsWith("/json/list")) return new Response(JSON.stringify([]), { status: 200 });
57
- if (text.includes("/json/new?")) {
58
- return new Response(JSON.stringify({
59
- id: "temp-page",
60
- type: "page",
61
- url: "https://chatgpt.com/",
62
- webSocketDebuggerUrl: "ws://cdp/temp-page",
63
- }), { status: 200 });
64
- }
65
- if (text.endsWith("/json/close/temp-page")) {
66
- closed.push("temp-page");
67
- return new Response("Target is closing", { status: 200 });
68
- }
69
- throw new Error(`unexpected fetch: ${text}`);
70
- }) as unknown as typeof fetch;
71
-
72
- await expect(getChatGptSubscriptionStatus({
73
- fetchImpl,
74
- probeChromeCdpImpl: vi.fn(async () => "healthy" as const),
75
- evaluateInPage: vi.fn(async () => ({
76
- sessionOk: true,
77
- hasAccessToken: true,
78
- maskedEmail: "gg***@gmail.com",
79
- sessionExpires: "2026-09-20T09:30:07.340Z",
80
- account: {
81
- status: 200,
82
- ok: true,
83
- entitlement: {
84
- has_active_subscription: true,
85
- subscription_plan: "chatgptprolite",
86
- expires_at: "2026-07-12T10:20:11+00:00",
87
- },
88
- last_active_subscription: {
89
- will_renew: false,
90
- purchase_origin_platform: "chatgpt_web",
91
- },
92
- },
93
- })),
94
- now: () => new Date("2026-06-22T00:00:00+08:00"),
95
- })).resolves.toMatchObject({
96
- ok: true,
97
- code: "ok",
98
- subscription: {
99
- plan: "chatgptprolite",
100
- expiresAt: "2026-07-12T10:20:11+00:00",
101
- willRenew: false,
102
- remainingDays: 21,
103
- },
104
- });
105
- expect(closed).toEqual(["temp-page"]);
106
- });
107
-
108
- it("does not close an existing ChatGPT page", async () => {
109
- const fetchImpl = vi.fn(async (url: string | URL | Request) => {
110
- const text = String(url);
111
- if (text.endsWith("/json/list")) {
112
- return new Response(JSON.stringify([{
113
- id: "existing-page",
114
- type: "page",
115
- url: "https://chatgpt.com/",
116
- webSocketDebuggerUrl: "ws://cdp/existing-page",
117
- }]), { status: 200 });
118
- }
119
- if (text.includes("/json/close/")) throw new Error("should not close existing page");
120
- throw new Error(`unexpected fetch: ${text}`);
121
- }) as unknown as typeof fetch;
122
-
123
- await expect(getChatGptSubscriptionStatus({
124
- fetchImpl,
125
- probeChromeCdpImpl: vi.fn(async () => "healthy" as const),
126
- evaluateInPage: vi.fn(async () => ({
127
- sessionOk: true,
128
- hasAccessToken: false,
129
- })),
130
- })).resolves.toMatchObject({
131
- ok: false,
132
- code: "chatgpt_session_missing",
133
- });
134
- });
135
- });
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { config } from "../config.ts";
4
+ import { getChatGptSubscriptionStatus } from "../chatgpt-subscription.ts";
5
+
6
+ describe("ChatGPT subscription lookup", () => {
7
+ beforeEach(() => {
8
+ config.chromeDevtools = { enabled: true, port: 15166, chromePath: "" };
9
+ });
10
+
11
+ it("returns disabled without probing the port when Chrome CDP is off", async () => {
12
+ config.chromeDevtools = { enabled: false, port: 15166, chromePath: "" };
13
+ const probeChromeCdpImpl = vi.fn();
14
+ const fetchImpl = vi.fn() as unknown as typeof fetch;
15
+
16
+ await expect(getChatGptSubscriptionStatus({ probeChromeCdpImpl, fetchImpl })).resolves.toMatchObject({
17
+ ok: false,
18
+ code: "chrome_cdp_disabled",
19
+ chromeCdp: { enabled: false, port: 15166, status: "skipped" },
20
+ });
21
+ expect(probeChromeCdpImpl).not.toHaveBeenCalled();
22
+ expect(fetchImpl).not.toHaveBeenCalled();
23
+ });
24
+
25
+ it("returns occupied when the configured port is not a healthy Chrome CDP endpoint", async () => {
26
+ await expect(getChatGptSubscriptionStatus({
27
+ probeChromeCdpImpl: vi.fn(async () => "occupied" as const),
28
+ })).resolves.toMatchObject({
29
+ ok: false,
30
+ code: "chrome_cdp_occupied",
31
+ reason: expect.stringContaining("not a healthy Chrome CDP endpoint"),
32
+ });
33
+ });
34
+
35
+ it("returns page missing when CDP has no ChatGPT page and cannot create one", async () => {
36
+ const fetchImpl = vi.fn(async (url: string | URL | Request) => {
37
+ const text = String(url);
38
+ if (text.endsWith("/json/list")) return new Response(JSON.stringify([]), { status: 200 });
39
+ if (text.includes("/json/new?")) return new Response("nope", { status: 500 });
40
+ throw new Error(`unexpected fetch: ${text}`);
41
+ }) as unknown as typeof fetch;
42
+
43
+ await expect(getChatGptSubscriptionStatus({
44
+ fetchImpl,
45
+ probeChromeCdpImpl: vi.fn(async () => "healthy" as const),
46
+ })).resolves.toMatchObject({
47
+ ok: false,
48
+ code: "chatgpt_page_missing",
49
+ });
50
+ });
51
+
52
+ it("closes only the temporary ChatGPT page created for this lookup", async () => {
53
+ const closed: string[] = [];
54
+ const fetchImpl = vi.fn(async (url: string | URL | Request) => {
55
+ const text = String(url);
56
+ if (text.endsWith("/json/list")) return new Response(JSON.stringify([]), { status: 200 });
57
+ if (text.includes("/json/new?")) {
58
+ return new Response(JSON.stringify({
59
+ id: "temp-page",
60
+ type: "page",
61
+ url: "https://chatgpt.com/",
62
+ webSocketDebuggerUrl: "ws://cdp/temp-page",
63
+ }), { status: 200 });
64
+ }
65
+ if (text.endsWith("/json/close/temp-page")) {
66
+ closed.push("temp-page");
67
+ return new Response("Target is closing", { status: 200 });
68
+ }
69
+ throw new Error(`unexpected fetch: ${text}`);
70
+ }) as unknown as typeof fetch;
71
+
72
+ await expect(getChatGptSubscriptionStatus({
73
+ fetchImpl,
74
+ probeChromeCdpImpl: vi.fn(async () => "healthy" as const),
75
+ evaluateInPage: vi.fn(async () => ({
76
+ sessionOk: true,
77
+ hasAccessToken: true,
78
+ maskedEmail: "gg***@gmail.com",
79
+ sessionExpires: "2026-09-20T09:30:07.340Z",
80
+ account: {
81
+ status: 200,
82
+ ok: true,
83
+ entitlement: {
84
+ has_active_subscription: true,
85
+ subscription_plan: "chatgptprolite",
86
+ expires_at: "2026-07-12T10:20:11+00:00",
87
+ },
88
+ last_active_subscription: {
89
+ will_renew: false,
90
+ purchase_origin_platform: "chatgpt_web",
91
+ },
92
+ },
93
+ })),
94
+ now: () => new Date("2026-06-22T00:00:00+08:00"),
95
+ })).resolves.toMatchObject({
96
+ ok: true,
97
+ code: "ok",
98
+ subscription: {
99
+ plan: "chatgptprolite",
100
+ expiresAt: "2026-07-12T10:20:11+00:00",
101
+ willRenew: false,
102
+ remainingDays: 21,
103
+ },
104
+ });
105
+ expect(closed).toEqual(["temp-page"]);
106
+ });
107
+
108
+ it("does not close an existing ChatGPT page", async () => {
109
+ const fetchImpl = vi.fn(async (url: string | URL | Request) => {
110
+ const text = String(url);
111
+ if (text.endsWith("/json/list")) {
112
+ return new Response(JSON.stringify([{
113
+ id: "existing-page",
114
+ type: "page",
115
+ url: "https://chatgpt.com/",
116
+ webSocketDebuggerUrl: "ws://cdp/existing-page",
117
+ }]), { status: 200 });
118
+ }
119
+ if (text.includes("/json/close/")) throw new Error("should not close existing page");
120
+ throw new Error(`unexpected fetch: ${text}`);
121
+ }) as unknown as typeof fetch;
122
+
123
+ await expect(getChatGptSubscriptionStatus({
124
+ fetchImpl,
125
+ probeChromeCdpImpl: vi.fn(async () => "healthy" as const),
126
+ evaluateInPage: vi.fn(async () => ({
127
+ sessionOk: true,
128
+ hasAccessToken: false,
129
+ })),
130
+ })).resolves.toMatchObject({
131
+ ok: false,
132
+ code: "chatgpt_session_missing",
133
+ });
134
+ });
135
+ });