chatccc 0.2.190 → 0.2.192

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 (72) hide show
  1. package/agent-prompts/claude_specific.md +45 -45
  2. package/agent-prompts/codex_specific.md +2 -2
  3. package/agent-prompts/cursor_specific.md +13 -13
  4. package/config.sample.json +14 -14
  5. package/im-skills/feishu-skill/receive-send-file.md +63 -63
  6. package/im-skills/feishu-skill/receive-send-image.md +24 -24
  7. package/im-skills/feishu-skill/skill.md +3 -3
  8. package/im-skills/wechat-file-skill/receive-send-file.md +38 -38
  9. package/im-skills/wechat-file-skill/send-file.mjs +83 -83
  10. package/im-skills/wechat-file-skill/skill.md +10 -10
  11. package/im-skills/wechat-image-skill/skill.md +10 -10
  12. package/im-skills/wechat-video-skill/receive-send-video.md +38 -38
  13. package/im-skills/wechat-video-skill/send-video.mjs +79 -79
  14. package/im-skills/wechat-video-skill/skill.md +10 -10
  15. package/package.json +1 -1
  16. package/scripts/postinstall-sharp-check.mjs +58 -58
  17. package/src/__tests__/agent-delegate-task-rpc.test.ts +165 -165
  18. package/src/__tests__/builtin-chat-session.test.ts +76 -0
  19. package/src/__tests__/builtin-config.test.ts +33 -33
  20. package/src/__tests__/builtin-context.test.ts +126 -0
  21. package/src/__tests__/builtin-sigint.test.ts +56 -0
  22. package/src/__tests__/card-plain-text.test.ts +5 -5
  23. package/src/__tests__/cardkit.test.ts +60 -60
  24. package/src/__tests__/cards.test.ts +77 -77
  25. package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
  26. package/src/__tests__/chatgpt-subscription.test.ts +135 -135
  27. package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
  28. package/src/__tests__/claude-adapter.test.ts +592 -592
  29. package/src/__tests__/codex-reset-actions.test.ts +146 -146
  30. package/src/__tests__/config-reload.test.ts +4 -4
  31. package/src/__tests__/config-sample.test.ts +17 -17
  32. package/src/__tests__/feishu-api.test.ts +60 -60
  33. package/src/__tests__/feishu-platform.test.ts +22 -22
  34. package/src/__tests__/format-message.test.ts +47 -47
  35. package/src/__tests__/orchestrator.test.ts +120 -120
  36. package/src/__tests__/privacy.test.ts +198 -198
  37. package/src/__tests__/raw-stream-log.test.ts +106 -106
  38. package/src/__tests__/session.test.ts +17 -17
  39. package/src/__tests__/shared-prefix.test.ts +36 -36
  40. package/src/__tests__/stream-state.test.ts +42 -42
  41. package/src/__tests__/web-ui.test.ts +209 -209
  42. package/src/adapters/claude-adapter.ts +566 -566
  43. package/src/adapters/claude-session-meta-store.ts +120 -120
  44. package/src/adapters/codex-adapter.ts +30 -30
  45. package/src/adapters/cursor-adapter.ts +46 -46
  46. package/src/adapters/raw-stream-log.ts +124 -124
  47. package/src/adapters/resource-monitor.ts +140 -140
  48. package/src/agent-delegate-task-rpc.ts +153 -153
  49. package/src/agent-delegate-task.ts +81 -81
  50. package/src/agent-stop-stuck.ts +129 -129
  51. package/src/builtin/cli.ts +211 -189
  52. package/src/builtin/context.ts +225 -0
  53. package/src/builtin/index.ts +232 -170
  54. package/src/builtin/sigint.ts +50 -0
  55. package/src/cards.ts +137 -137
  56. package/src/chatgpt-subscription-rpc.ts +27 -27
  57. package/src/chatgpt-subscription.ts +299 -299
  58. package/src/chrome-devtools-guard.ts +318 -318
  59. package/src/codex-reset-actions.ts +184 -184
  60. package/src/config.ts +86 -86
  61. package/src/feishu-platform.ts +20 -20
  62. package/src/format-message.ts +293 -293
  63. package/src/litellm-proxy.ts +374 -374
  64. package/src/orchestrator.ts +143 -143
  65. package/src/privacy.ts +118 -118
  66. package/src/session-chat-binding.ts +6 -6
  67. package/src/session-name.ts +8 -8
  68. package/src/session.ts +98 -98
  69. package/src/shared-prefix.ts +29 -29
  70. package/src/sim-platform.ts +20 -20
  71. package/src/turn-cards.ts +117 -117
  72. package/src/web-ui.ts +205 -205
@@ -1,60 +1,60 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
-
3
- import { updateCardKitCard } from "../cardkit.ts";
4
-
5
- function abortError(): Error {
6
- const err = new Error("aborted");
7
- err.name = "AbortError";
8
- return err;
9
- }
10
-
11
- describe("CardKit request timeout", () => {
12
- afterEach(() => {
13
- vi.useRealTimers();
14
- vi.restoreAllMocks();
15
- vi.unstubAllGlobals();
16
- });
17
-
18
- it("aborts a hung card update so display.cardBusy can be released", async () => {
19
- vi.useFakeTimers();
20
- vi.spyOn(console, "error").mockImplementation(() => {});
21
-
22
- const fetchMock = vi.fn((_url: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => (
23
- new Promise<Response>((_resolve, reject) => {
24
- init?.signal?.addEventListener("abort", () => reject(abortError()));
25
- })
26
- ));
27
- vi.stubGlobal("fetch", fetchMock);
28
-
29
- const update = expect(updateCardKitCard("token", "card-1", "{}", 7))
30
- .rejects.toThrow("updateCard cardId=card-1 seq=7 timeout after 15000ms");
31
- await vi.advanceTimersByTimeAsync(15_000);
32
-
33
- await update;
34
- expect(fetchMock).toHaveBeenCalledWith(
35
- expect.stringContaining("/cardkit/v1/cards/card-1"),
36
- expect.objectContaining({ signal: expect.any(AbortSignal) }),
37
- );
38
- });
39
-
40
- it("also aborts when response body reading hangs", async () => {
41
- vi.useFakeTimers();
42
- vi.spyOn(console, "error").mockImplementation(() => {});
43
-
44
- const fetchMock = vi.fn((_url: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => (
45
- Promise.resolve({
46
- status: 200,
47
- text: () => new Promise<string>((_resolve, reject) => {
48
- init?.signal?.addEventListener("abort", () => reject(abortError()));
49
- }),
50
- } as Response)
51
- ));
52
- vi.stubGlobal("fetch", fetchMock);
53
-
54
- const update = expect(updateCardKitCard("token", "card-2", "{}", 8))
55
- .rejects.toThrow("updateCard cardId=card-2 seq=8 timeout after 15000ms");
56
- await vi.advanceTimersByTimeAsync(15_000);
57
-
58
- await update;
59
- });
60
- });
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { updateCardKitCard } from "../cardkit.ts";
4
+
5
+ function abortError(): Error {
6
+ const err = new Error("aborted");
7
+ err.name = "AbortError";
8
+ return err;
9
+ }
10
+
11
+ describe("CardKit request timeout", () => {
12
+ afterEach(() => {
13
+ vi.useRealTimers();
14
+ vi.restoreAllMocks();
15
+ vi.unstubAllGlobals();
16
+ });
17
+
18
+ it("aborts a hung card update so display.cardBusy can be released", async () => {
19
+ vi.useFakeTimers();
20
+ vi.spyOn(console, "error").mockImplementation(() => {});
21
+
22
+ const fetchMock = vi.fn((_url: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => (
23
+ new Promise<Response>((_resolve, reject) => {
24
+ init?.signal?.addEventListener("abort", () => reject(abortError()));
25
+ })
26
+ ));
27
+ vi.stubGlobal("fetch", fetchMock);
28
+
29
+ const update = expect(updateCardKitCard("token", "card-1", "{}", 7))
30
+ .rejects.toThrow("updateCard cardId=card-1 seq=7 timeout after 15000ms");
31
+ await vi.advanceTimersByTimeAsync(15_000);
32
+
33
+ await update;
34
+ expect(fetchMock).toHaveBeenCalledWith(
35
+ expect.stringContaining("/cardkit/v1/cards/card-1"),
36
+ expect.objectContaining({ signal: expect.any(AbortSignal) }),
37
+ );
38
+ });
39
+
40
+ it("also aborts when response body reading hangs", async () => {
41
+ vi.useFakeTimers();
42
+ vi.spyOn(console, "error").mockImplementation(() => {});
43
+
44
+ const fetchMock = vi.fn((_url: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => (
45
+ Promise.resolve({
46
+ status: 200,
47
+ text: () => new Promise<string>((_resolve, reject) => {
48
+ init?.signal?.addEventListener("abort", () => reject(abortError()));
49
+ }),
50
+ } as Response)
51
+ ));
52
+ vi.stubGlobal("fetch", fetchMock);
53
+
54
+ const update = expect(updateCardKitCard("token", "card-2", "{}", 8))
55
+ .rejects.toThrow("updateCard cardId=card-2 seq=8 timeout after 15000ms");
56
+ await vi.advanceTimersByTimeAsync(15_000);
57
+
58
+ await update;
59
+ });
60
+ });
@@ -1,18 +1,18 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import {
3
- buildProgressCard,
4
- buildHelpCard,
2
+ import {
3
+ buildProgressCard,
4
+ buildHelpCard,
5
5
  buildCdContent,
6
6
  buildCdCard,
7
7
  buildSessionsCard,
8
- buildStatusCard,
9
- buildCodexUsageCard,
10
- buildCodexResetConfirmCard,
11
- buildButtons,
12
- truncateContent,
13
- getToolEmoji,
14
- } from "../cards.ts";
15
- import { ABD_HELP_LINE } from "../shared-prefix.ts";
8
+ buildStatusCard,
9
+ buildCodexUsageCard,
10
+ buildCodexResetConfirmCard,
11
+ buildButtons,
12
+ truncateContent,
13
+ getToolEmoji,
14
+ } from "../cards.ts";
15
+ import { ABD_HELP_LINE } from "../shared-prefix.ts";
16
16
 
17
17
  // ---------------------------------------------------------------------------
18
18
  // truncateContent
@@ -154,23 +154,23 @@ describe("buildHelpCard", () => {
154
154
  expect(parsed.elements[0].text.content).toContain("你好");
155
155
  });
156
156
 
157
- it("includes action buttons", () => {
158
- const card = buildHelpCard("test");
159
- const parsed = JSON.parse(card);
160
- const action = parsed.elements[2];
161
- expect(action.tag).toBe("action");
162
- expect(action.actions).toHaveLength(7);
163
- });
164
-
165
- it("adds ABD prefix help as the final help line", () => {
166
- const card = buildHelpCard("test");
167
- const parsed = JSON.parse(card);
168
- const lines = parsed.elements[1].text.content.split("\n");
169
-
170
- expect(lines).toContain("发送 **/usage** 查看 Codex 5h/周用量,以及查询/使用主动重置卡");
171
- expect(lines.at(-1)).toBe(ABD_HELP_LINE);
172
- });
173
- });
157
+ it("includes action buttons", () => {
158
+ const card = buildHelpCard("test");
159
+ const parsed = JSON.parse(card);
160
+ const action = parsed.elements[2];
161
+ expect(action.tag).toBe("action");
162
+ expect(action.actions).toHaveLength(7);
163
+ });
164
+
165
+ it("adds ABD prefix help as the final help line", () => {
166
+ const card = buildHelpCard("test");
167
+ const parsed = JSON.parse(card);
168
+ const lines = parsed.elements[1].text.content.split("\n");
169
+
170
+ expect(lines).toContain("发送 **/usage** 查看 Codex 5h/周用量,以及查询/使用主动重置卡");
171
+ expect(lines.at(-1)).toBe(ABD_HELP_LINE);
172
+ });
173
+ });
174
174
 
175
175
  // ---------------------------------------------------------------------------
176
176
  // buildCdContent
@@ -425,7 +425,7 @@ describe("buildSessionsCard", () => {
425
425
  // buildStatusCard
426
426
  // ---------------------------------------------------------------------------
427
427
 
428
- describe("buildStatusCard", () => {
428
+ describe("buildStatusCard", () => {
429
429
  it("returns valid JSON with status text", () => {
430
430
  const card = buildStatusCard("一切正常");
431
431
  const parsed = JSON.parse(card);
@@ -445,54 +445,54 @@ describe("buildStatusCard", () => {
445
445
  const action = parsed.elements[2];
446
446
  expect(action.actions[0].text.content).toBe("收起");
447
447
  });
448
- });
449
-
450
- // ---------------------------------------------------------------------------
451
- // buildCodexUsageCard / buildCodexResetConfirmCard
452
- // ---------------------------------------------------------------------------
453
-
454
- describe("Codex usage reset cards", () => {
455
- it("shows the reset button only when reset credits are available", () => {
456
- const card = buildCodexUsageCard("Codex 用量", 2);
457
- const parsed = JSON.parse(card);
458
- const action = parsed.elements.find((element: any) => element.tag === "action");
459
- expect(action.actions[0].text.content).toBe("发起重置");
460
- expect(action.actions[0].value).toEqual({ action: "codex_reset_request", availableCount: 2 });
461
-
462
- const noCreditCard = buildCodexUsageCard("Codex 用量", 0);
463
- const noCreditParsed = JSON.parse(noCreditCard);
464
- expect(noCreditParsed.elements.some((element: any) => element.tag === "action")).toBe(false);
465
- });
466
-
467
- it("builds yes/no confirmation buttons tied to the parent usage card", () => {
468
- const card = buildCodexResetConfirmCard({
469
- availableCount: 2,
470
- parentMessageId: "usage-message",
471
- requestId: "request-1",
472
- });
473
- const parsed = JSON.parse(card);
474
- const action = parsed.elements.find((element: any) => element.tag === "action");
475
-
476
- expect(action.actions[0].text.content).toBe("是,发起重置");
477
- expect(action.actions[0].value).toEqual({
478
- action: "codex_reset_confirm",
479
- decision: "yes",
480
- parentMessageId: "usage-message",
481
- requestId: "request-1",
482
- });
483
- expect(action.actions[1].text.content).toBe("否");
484
- expect(action.actions[1].value).toEqual({
485
- action: "codex_reset_confirm",
486
- decision: "no",
487
- parentMessageId: "usage-message",
488
- requestId: "request-1",
489
- });
490
- });
491
- });
492
-
493
- // ---------------------------------------------------------------------------
494
- // buildButtons
495
- // ---------------------------------------------------------------------------
448
+ });
449
+
450
+ // ---------------------------------------------------------------------------
451
+ // buildCodexUsageCard / buildCodexResetConfirmCard
452
+ // ---------------------------------------------------------------------------
453
+
454
+ describe("Codex usage reset cards", () => {
455
+ it("shows the reset button only when reset credits are available", () => {
456
+ const card = buildCodexUsageCard("Codex 用量", 2);
457
+ const parsed = JSON.parse(card);
458
+ const action = parsed.elements.find((element: any) => element.tag === "action");
459
+ expect(action.actions[0].text.content).toBe("发起重置");
460
+ expect(action.actions[0].value).toEqual({ action: "codex_reset_request", availableCount: 2 });
461
+
462
+ const noCreditCard = buildCodexUsageCard("Codex 用量", 0);
463
+ const noCreditParsed = JSON.parse(noCreditCard);
464
+ expect(noCreditParsed.elements.some((element: any) => element.tag === "action")).toBe(false);
465
+ });
466
+
467
+ it("builds yes/no confirmation buttons tied to the parent usage card", () => {
468
+ const card = buildCodexResetConfirmCard({
469
+ availableCount: 2,
470
+ parentMessageId: "usage-message",
471
+ requestId: "request-1",
472
+ });
473
+ const parsed = JSON.parse(card);
474
+ const action = parsed.elements.find((element: any) => element.tag === "action");
475
+
476
+ expect(action.actions[0].text.content).toBe("是,发起重置");
477
+ expect(action.actions[0].value).toEqual({
478
+ action: "codex_reset_confirm",
479
+ decision: "yes",
480
+ parentMessageId: "usage-message",
481
+ requestId: "request-1",
482
+ });
483
+ expect(action.actions[1].text.content).toBe("否");
484
+ expect(action.actions[1].value).toEqual({
485
+ action: "codex_reset_confirm",
486
+ decision: "no",
487
+ parentMessageId: "usage-message",
488
+ requestId: "request-1",
489
+ });
490
+ });
491
+ });
492
+
493
+ // ---------------------------------------------------------------------------
494
+ // buildButtons
495
+ // ---------------------------------------------------------------------------
496
496
 
497
497
  describe("buildButtons", () => {
498
498
  it("returns action with buttons", () => {
@@ -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 = "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
+ });