chatccc 0.2.196 → 0.2.198

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 (53) 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 +2 -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 +163 -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 +167 -113
  23. package/src/__tests__/feishu-avatar.test.ts +40 -40
  24. package/src/__tests__/jsonl-stream.test.ts +79 -0
  25. package/src/__tests__/orchestrator.test.ts +181 -154
  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 -119
  31. package/src/adapters/claude-adapter.ts +603 -566
  32. package/src/adapters/codex-adapter.ts +65 -52
  33. package/src/adapters/cursor-adapter.ts +269 -276
  34. package/src/adapters/jsonl-stream.ts +157 -0
  35. package/src/adapters/raw-stream-log.ts +124 -124
  36. package/src/agent-reload-config-rpc.ts +34 -0
  37. package/src/builtin/cli.ts +473 -461
  38. package/src/builtin/context.ts +323 -323
  39. package/src/builtin/file-tools.ts +1072 -915
  40. package/src/builtin/index.ts +404 -353
  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/index.ts +8 -13
  50. package/src/orchestrator.ts +166 -145
  51. package/src/runtime-reload.ts +34 -0
  52. package/src/session.ts +141 -141
  53. package/src/web-ui.ts +205 -205
@@ -1,119 +1,121 @@
1
- import { ChatSession, type ChatSessionConfig, type ChatSessionOptions } from "../builtin/index.ts";
2
- import {
3
- getBuiltinContextSession,
4
- newBuiltinSessionId,
5
- normalizeBuiltinSessionId,
6
- } from "../builtin/context.ts";
7
- import { config, CCC_SESSION_PREFIX } from "../config.ts";
8
- import type {
9
- CreateSessionResult,
10
- SessionInfo,
11
- ToolAdapter,
12
- ToolPromptOptions,
13
- UnifiedStreamMessage,
14
- } from "./adapter-interface.ts";
15
-
16
- export interface CccAdapterOptions extends ChatSessionConfig {
17
- contextDir?: string;
18
- compactAtTokens?: number;
19
- keepRecentMessages?: number;
20
- }
21
-
22
- function toChatSessionOptions(
23
- sessionId: string,
24
- cwd: string,
25
- options: CccAdapterOptions,
26
- ): ChatSessionOptions {
27
- return {
28
- cwd,
29
- persist: true,
30
- sessionId,
31
- contextDir: options.contextDir,
32
- compactAtTokens: options.compactAtTokens,
33
- keepRecentMessages: options.keepRecentMessages,
34
- };
35
- }
36
-
37
- export function createCccAdapter(options: CccAdapterOptions = {}): ToolAdapter {
38
- const chatConfig: ChatSessionConfig = {
39
- ...(options.apiKey !== undefined ? { apiKey: options.apiKey } : {}),
40
- ...(options.baseURL !== undefined ? { baseURL: options.baseURL } : {}),
41
- ...(options.model !== undefined ? { model: options.model } : {}),
42
- };
43
-
44
- return {
45
- displayName: "CCC Agent",
46
- sessionDescPrefix: CCC_SESSION_PREFIX,
47
-
48
- async createSession(cwd: string): Promise<CreateSessionResult> {
49
- const sessionId = newBuiltinSessionId();
50
- const session = new ChatSession(
51
- chatConfig,
52
- toChatSessionOptions(sessionId, cwd, options),
53
- );
54
- session.reset();
55
- return { sessionId };
56
- },
57
-
58
- async *prompt(
59
- sessionId: string,
60
- userText: string,
61
- cwd: string,
62
- signal?: AbortSignal,
63
- _promptOptions?: ToolPromptOptions,
64
- ): AsyncIterable<UnifiedStreamMessage> {
65
- const normalizedSessionId = normalizeBuiltinSessionId(sessionId);
66
- const session = new ChatSession(
67
- chatConfig,
68
- toChatSessionOptions(normalizedSessionId, cwd, options),
69
- );
70
-
71
- for await (const event of session.chat(userText, signal)) {
72
- if (event.type === "text") {
73
- yield {
74
- type: "assistant",
75
- blocks: [{ type: "text", text: event.text }],
76
- };
77
- } else if (event.type === "tool_use") {
78
- yield {
79
- type: "assistant",
80
- blocks: [{
81
- type: "tool_use",
82
- id: event.id,
83
- name: event.name,
84
- input: event.input,
85
- }],
86
- };
87
- } else if (event.type === "tool_result") {
88
- yield {
89
- type: "assistant",
90
- blocks: [{
91
- type: "tool_result",
92
- tool_use_id: event.tool_use_id,
93
- content: event.content,
94
- is_error: event.is_error,
95
- }],
96
- };
97
- } else if (event.type === "error") {
98
- throw new Error(event.message);
99
- }
100
- }
101
- },
102
-
103
- async getSessionInfo(sessionId: string): Promise<SessionInfo | undefined> {
104
- const normalizedSessionId = normalizeBuiltinSessionId(sessionId);
105
- const info = getBuiltinContextSession(normalizedSessionId, options.contextDir);
106
- if (!info) return undefined;
107
- return {
108
- sessionId: info.sessionId,
109
- cwd: info.cwd,
110
- lastModified: info.updatedAt,
111
- model: options.model ?? config.ccc.model,
112
- };
113
- },
114
-
115
- async closeSession(_sessionId: string): Promise<void> {
116
- // ChatSession uses one request-scoped stream per prompt. AbortSignal handles cancellation.
117
- },
118
- };
119
- }
1
+ import { ChatSession, type ChatSessionConfig, type ChatSessionOptions } from "../builtin/index.ts";
2
+ import {
3
+ getBuiltinContextSession,
4
+ newBuiltinSessionId,
5
+ normalizeBuiltinSessionId,
6
+ } from "../builtin/context.ts";
7
+ import { config, CCC_SESSION_PREFIX } from "../config.ts";
8
+ import type {
9
+ CreateSessionResult,
10
+ SessionInfo,
11
+ ToolAdapter,
12
+ ToolPromptOptions,
13
+ UnifiedStreamMessage,
14
+ } from "./adapter-interface.ts";
15
+
16
+ export interface CccAdapterOptions extends ChatSessionConfig {
17
+ contextDir?: string;
18
+ compactAtTokens?: number;
19
+ keepRecentMessages?: number;
20
+ maxSteps?: number;
21
+ }
22
+
23
+ function toChatSessionOptions(
24
+ sessionId: string,
25
+ cwd: string,
26
+ options: CccAdapterOptions,
27
+ ): ChatSessionOptions {
28
+ return {
29
+ cwd,
30
+ persist: true,
31
+ sessionId,
32
+ contextDir: options.contextDir,
33
+ compactAtTokens: options.compactAtTokens,
34
+ keepRecentMessages: options.keepRecentMessages,
35
+ maxSteps: options.maxSteps,
36
+ };
37
+ }
38
+
39
+ export function createCccAdapter(options: CccAdapterOptions = {}): ToolAdapter {
40
+ const chatConfig: ChatSessionConfig = {
41
+ ...(options.apiKey !== undefined ? { apiKey: options.apiKey } : {}),
42
+ ...(options.baseURL !== undefined ? { baseURL: options.baseURL } : {}),
43
+ ...(options.model !== undefined ? { model: options.model } : {}),
44
+ };
45
+
46
+ return {
47
+ displayName: "CCC Agent",
48
+ sessionDescPrefix: CCC_SESSION_PREFIX,
49
+
50
+ async createSession(cwd: string): Promise<CreateSessionResult> {
51
+ const sessionId = newBuiltinSessionId();
52
+ const session = new ChatSession(
53
+ chatConfig,
54
+ toChatSessionOptions(sessionId, cwd, options),
55
+ );
56
+ session.reset();
57
+ return { sessionId };
58
+ },
59
+
60
+ async *prompt(
61
+ sessionId: string,
62
+ userText: string,
63
+ cwd: string,
64
+ signal?: AbortSignal,
65
+ _promptOptions?: ToolPromptOptions,
66
+ ): AsyncIterable<UnifiedStreamMessage> {
67
+ const normalizedSessionId = normalizeBuiltinSessionId(sessionId);
68
+ const session = new ChatSession(
69
+ chatConfig,
70
+ toChatSessionOptions(normalizedSessionId, cwd, options),
71
+ );
72
+
73
+ for await (const event of session.chat(userText, signal)) {
74
+ if (event.type === "text") {
75
+ yield {
76
+ type: "assistant",
77
+ blocks: [{ type: "text", text: event.text }],
78
+ };
79
+ } else if (event.type === "tool_use") {
80
+ yield {
81
+ type: "assistant",
82
+ blocks: [{
83
+ type: "tool_use",
84
+ id: event.id,
85
+ name: event.name,
86
+ input: event.input,
87
+ }],
88
+ };
89
+ } else if (event.type === "tool_result") {
90
+ yield {
91
+ type: "assistant",
92
+ blocks: [{
93
+ type: "tool_result",
94
+ tool_use_id: event.tool_use_id,
95
+ content: event.content,
96
+ is_error: event.is_error,
97
+ }],
98
+ };
99
+ } else if (event.type === "error") {
100
+ throw new Error(event.message);
101
+ }
102
+ }
103
+ },
104
+
105
+ async getSessionInfo(sessionId: string): Promise<SessionInfo | undefined> {
106
+ const normalizedSessionId = normalizeBuiltinSessionId(sessionId);
107
+ const info = getBuiltinContextSession(normalizedSessionId, options.contextDir);
108
+ if (!info) return undefined;
109
+ return {
110
+ sessionId: info.sessionId,
111
+ cwd: info.cwd,
112
+ lastModified: info.updatedAt,
113
+ model: options.model ?? config.ccc.model,
114
+ };
115
+ },
116
+
117
+ async closeSession(_sessionId: string): Promise<void> {
118
+ // ChatSession uses one request-scoped stream per prompt. AbortSignal handles cancellation.
119
+ },
120
+ };
121
+ }