chatccc 0.2.252 → 0.2.254
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.
- package/README.md +10 -1
- package/bin/cccagent.mjs +12 -3
- package/bin/chatccc.mjs +15 -6
- package/config.sample.json +2 -1
- package/deepccc-agent/README.md +40 -35
- package/deepccc-agent/os-prompts/darwin.md +8 -8
- package/deepccc-agent/os-prompts/linux.md +8 -8
- package/deepccc-agent/os-prompts/win32.md +11 -11
- package/deepccc-agent/package.json +65 -65
- package/dist/deepccc-agent/src/cli.js +634 -0
- package/dist/deepccc-agent/src/config.js +81 -0
- package/dist/deepccc-agent/src/context.js +348 -0
- package/dist/deepccc-agent/src/file-log.js +34 -0
- package/dist/deepccc-agent/src/file-tools.js +1208 -0
- package/dist/deepccc-agent/src/index.js +601 -0
- package/dist/deepccc-agent/src/permissions.js +170 -0
- package/dist/deepccc-agent/src/privacy.js +124 -0
- package/dist/deepccc-agent/src/proc-tree-kill.js +60 -0
- package/dist/deepccc-agent/src/progress/cards-helpers.js +70 -0
- package/dist/deepccc-agent/src/progress/reducer.js +102 -0
- package/dist/deepccc-agent/src/progress/terminal-renderer.js +264 -0
- package/dist/deepccc-agent/src/progress/view.js +30 -0
- package/dist/deepccc-agent/src/raw-stream-log.js +106 -0
- package/dist/deepccc-agent/src/session-search.js +276 -0
- package/dist/deepccc-agent/src/session-select.js +23 -0
- package/dist/deepccc-agent/src/sigint.js +26 -0
- package/dist/deepccc-agent/src/skills.js +178 -0
- package/dist/deepccc-agent/src/web-tools.js +246 -0
- package/dist/src/adapters/adapter-interface.js +19 -0
- package/dist/src/adapters/ccc-adapter.js +112 -0
- package/dist/src/adapters/claude-adapter.js +497 -0
- package/dist/src/adapters/claude-session-meta-store.js +92 -0
- package/dist/src/adapters/codex-adapter.js +279 -0
- package/dist/src/adapters/codex-session-meta-store.js +94 -0
- package/dist/src/adapters/cursor-adapter.js +491 -0
- package/dist/src/adapters/cursor-session-meta-store.js +116 -0
- package/dist/src/adapters/jsonl-stream.js +104 -0
- package/{src/adapters/proc-tree-kill.ts → dist/src/adapters/proc-tree-kill.js} +94 -97
- package/dist/src/adapters/raw-stream-log.js +106 -0
- package/dist/src/adapters/resource-monitor.js +113 -0
- package/dist/src/agent-activity.js +133 -0
- package/dist/src/agent-delegate-task-rpc.js +129 -0
- package/dist/src/agent-delegate-task.js +48 -0
- package/dist/src/agent-file-rpc.js +152 -0
- package/dist/src/agent-image-rpc.js +148 -0
- package/dist/src/agent-platform-routing.js +13 -0
- package/dist/src/agent-reload-config-rpc.js +23 -0
- package/dist/src/agent-rpc-body.js +87 -0
- package/dist/src/agent-stop-stuck.js +110 -0
- package/dist/src/agent-team/application/board-service.js +142 -0
- package/dist/src/agent-team/application/main-agent-service.js +151 -0
- package/dist/src/agent-team/domain/board.js +69 -0
- package/dist/src/agent-team/http/board-routes.js +213 -0
- package/dist/src/agent-team/infrastructure/filesystem-browser.js +112 -0
- package/dist/src/agent-team/infrastructure/main-agent-session-runtime.js +30 -0
- package/dist/src/agent-team/main-agent-bootstrap.js +15 -0
- package/dist/src/agent-team/repositories/board-repository.js +10 -0
- package/dist/src/agent-team/repositories/feishu-p2p-contact-store.js +64 -0
- package/dist/src/agent-team/repositories/json-board-repository.js +209 -0
- package/dist/src/agent-team/repositories/main-agent-binding-repository.js +84 -0
- package/dist/src/agent-team/sync/board-sync-adapter.js +1 -0
- package/dist/src/agent-team/web/agent-team-page.js +219 -0
- package/dist/src/agent-tool.js +10 -0
- package/dist/src/card-action-routing.js +7 -0
- package/dist/src/card-plain-text.js +101 -0
- package/dist/src/cardkit.js +158 -0
- package/dist/src/cards.js +573 -0
- package/dist/src/chatgpt-subscription-rpc.js +18 -0
- package/dist/src/chatgpt-subscription.js +199 -0
- package/dist/src/chrome-devtools-guard.js +238 -0
- package/dist/src/claude-sdk-installer.js +249 -0
- package/dist/src/codex-reset-actions.js +143 -0
- package/dist/src/config-utils.js +149 -0
- package/dist/src/config.js +808 -0
- package/dist/src/cursor-usage.js +77 -0
- package/dist/src/exit-banner.js +28 -0
- package/dist/src/feishu-api.js +1404 -0
- package/dist/src/feishu-message-ingress.js +137 -0
- package/dist/src/feishu-platform.js +97 -0
- package/dist/src/format-message.js +252 -0
- package/dist/src/git-command.js +155 -0
- package/dist/src/im-skills.js +121 -0
- package/dist/src/index.js +835 -0
- package/dist/src/litellm-proxy.js +300 -0
- package/dist/src/orchestrator.js +2096 -0
- package/dist/src/package-root.js +26 -0
- package/dist/src/platform-adapter.js +7 -0
- package/dist/src/platform-startup.js +6 -0
- package/dist/src/privacy.js +100 -0
- package/dist/src/progress/reducer.js +102 -0
- package/dist/src/progress/terminal-renderer.js +264 -0
- package/dist/src/progress/view.js +30 -0
- package/dist/src/response-stall.js +14 -0
- package/dist/src/runtime-entry.js +13 -0
- package/dist/src/runtime-reload.js +19 -0
- package/dist/src/session-chat-binding.js +183 -0
- package/dist/src/session-name.js +7 -0
- package/dist/src/session.js +2147 -0
- package/dist/src/shared-prefix.js +16 -0
- package/dist/src/shared.js +493 -0
- package/dist/src/sim-agent.js +105 -0
- package/dist/src/sim-platform.js +142 -0
- package/dist/src/sim-store.js +231 -0
- package/dist/src/simplify.js +99 -0
- package/dist/src/startup-lifecycle.js +209 -0
- package/dist/src/stream-state.js +141 -0
- package/dist/src/terminal-error.js +100 -0
- package/dist/src/trace.js +50 -0
- package/dist/src/turn-cards.js +92 -0
- package/dist/src/update-command-guard.js +114 -0
- package/{src/web-ui.ts → dist/src/web-ui.js} +753 -839
- package/dist/src/wechat-platform.js +545 -0
- package/package.json +76 -74
- package/deepccc-agent/LICENSE +0 -201
- package/deepccc-agent/bin/deepccc.mjs +0 -26
- package/deepccc-agent/docs/cache-hit-rate-1.jpg +0 -0
- package/deepccc-agent/docs/cache-hit-rate-2.jpg +0 -0
- package/deepccc-agent/package-lock.json +0 -2027
- package/deepccc-agent/src/__tests__/chat-session.test.ts +0 -877
- package/deepccc-agent/src/__tests__/cli-json.test.ts +0 -49
- package/deepccc-agent/src/__tests__/config.test.ts +0 -34
- package/deepccc-agent/src/__tests__/context.test.ts +0 -341
- package/deepccc-agent/src/__tests__/file-tools.test.ts +0 -240
- package/deepccc-agent/src/__tests__/permissions.test.ts +0 -199
- package/deepccc-agent/src/__tests__/privacy.test.ts +0 -318
- package/deepccc-agent/src/__tests__/progress-reducer.test.ts +0 -121
- package/deepccc-agent/src/__tests__/session-search.test.ts +0 -262
- package/deepccc-agent/src/__tests__/session-select.test.ts +0 -116
- package/deepccc-agent/src/__tests__/sigint.test.ts +0 -56
- package/deepccc-agent/src/__tests__/skills.test.ts +0 -284
- package/deepccc-agent/src/__tests__/terminal-renderer.test.ts +0 -247
- package/deepccc-agent/src/__tests__/web-tools.test.ts +0 -220
- package/deepccc-agent/src/cli.ts +0 -682
- package/deepccc-agent/src/config.ts +0 -101
- package/deepccc-agent/src/context.ts +0 -465
- package/deepccc-agent/src/file-log.ts +0 -38
- package/deepccc-agent/src/file-tools.ts +0 -1493
- package/deepccc-agent/src/index.ts +0 -710
- package/deepccc-agent/src/permissions.ts +0 -226
- package/deepccc-agent/src/privacy.ts +0 -141
- package/deepccc-agent/src/proc-tree-kill.ts +0 -61
- package/deepccc-agent/src/progress/cards-helpers.ts +0 -76
- package/deepccc-agent/src/progress/reducer.ts +0 -113
- package/deepccc-agent/src/progress/terminal-renderer.ts +0 -294
- package/deepccc-agent/src/progress/view.ts +0 -77
- package/deepccc-agent/src/raw-stream-log.ts +0 -124
- package/deepccc-agent/src/session-search.ts +0 -370
- package/deepccc-agent/src/session-select.ts +0 -48
- package/deepccc-agent/src/sigint.ts +0 -50
- package/deepccc-agent/src/skills.ts +0 -205
- package/deepccc-agent/src/web-tools.ts +0 -313
- package/deepccc-agent/tsconfig.build.json +0 -13
- package/deepccc-agent/tsconfig.json +0 -13
- package/deepccc-agent/vitest.config.ts +0 -7
- package/src/__tests__/adapter-interface.test.ts +0 -152
- package/src/__tests__/agent-activity.test.ts +0 -86
- package/src/__tests__/agent-delegate-task-rpc.test.ts +0 -165
- package/src/__tests__/agent-image-rpc.test.ts +0 -34
- package/src/__tests__/agent-platform-routing.test.ts +0 -26
- package/src/__tests__/agent-reload-config-rpc.test.ts +0 -99
- package/src/__tests__/agent-rpc-body.test.ts +0 -42
- package/src/__tests__/builtin-chat-session.test.ts +0 -532
- package/src/__tests__/builtin-cli-json.test.ts +0 -39
- package/src/__tests__/builtin-config.test.ts +0 -26
- package/src/__tests__/builtin-context.test.ts +0 -319
- package/src/__tests__/builtin-file-tools.test.ts +0 -240
- package/src/__tests__/builtin-permissions.test.ts +0 -219
- package/src/__tests__/builtin-session-search.test.ts +0 -262
- package/src/__tests__/builtin-session-select.test.ts +0 -116
- package/src/__tests__/builtin-sigint.test.ts +0 -56
- package/src/__tests__/builtin-skills.test.ts +0 -284
- package/src/__tests__/builtin-web-tools.test.ts +0 -220
- package/src/__tests__/card-action-routing.test.ts +0 -18
- package/src/__tests__/card-plain-text.test.ts +0 -45
- package/src/__tests__/cardkit.test.ts +0 -60
- package/src/__tests__/cards.test.ts +0 -607
- package/src/__tests__/ccc-adapter.test.ts +0 -194
- package/src/__tests__/chatgpt-subscription-rpc.test.ts +0 -89
- package/src/__tests__/chatgpt-subscription.test.ts +0 -135
- package/src/__tests__/chrome-devtools-guard.test.ts +0 -165
- package/src/__tests__/claude-adapter.test.ts +0 -614
- package/src/__tests__/claude-raw-stream-log.test.ts +0 -96
- package/src/__tests__/claude-sdk-installer.test.ts +0 -285
- package/src/__tests__/codex-adapter.test.ts +0 -331
- package/src/__tests__/codex-raw-stream-log.test.ts +0 -170
- package/src/__tests__/codex-reset-actions.test.ts +0 -146
- package/src/__tests__/config-reload.test.ts +0 -284
- package/src/__tests__/config-sample.test.ts +0 -97
- package/src/__tests__/config-utils.test.ts +0 -40
- package/src/__tests__/config.test.ts +0 -395
- package/src/__tests__/crash-logging.test.ts +0 -360
- package/src/__tests__/cursor-adapter.test.ts +0 -890
- package/src/__tests__/cursor-session-meta-store.test.ts +0 -212
- package/src/__tests__/feishu-api.test.ts +0 -60
- package/src/__tests__/feishu-avatar.test.ts +0 -504
- package/src/__tests__/feishu-message-ingress.test.ts +0 -138
- package/src/__tests__/feishu-platform.test.ts +0 -75
- package/src/__tests__/fixtures/codex_simple_text.jsonl +0 -4
- package/src/__tests__/fixtures/codex_with_tool.jsonl +0 -6
- package/src/__tests__/fixtures/cursor_partial_only.jsonl +0 -5
- package/src/__tests__/fixtures/cursor_partial_with_final.jsonl +0 -13
- package/src/__tests__/fixtures/cursor_with_tool_call.jsonl +0 -12
- package/src/__tests__/format-message.test.ts +0 -316
- package/src/__tests__/git-command.test.ts +0 -288
- package/src/__tests__/im-skills.test.ts +0 -125
- package/src/__tests__/jsonl-stream.test.ts +0 -79
- package/src/__tests__/orchestrator.test.ts +0 -1268
- package/src/__tests__/package-files.test.ts +0 -24
- package/src/__tests__/platform-startup.test.ts +0 -19
- package/src/__tests__/privacy.test.ts +0 -198
- package/src/__tests__/proc-tree-kill.test.ts +0 -108
- package/src/__tests__/progress-reducer.test.ts +0 -121
- package/src/__tests__/raw-stream-log.test.ts +0 -106
- package/src/__tests__/response-stall.test.ts +0 -49
- package/src/__tests__/restart.test.ts +0 -232
- package/src/__tests__/session-ccc-config.test.ts +0 -66
- package/src/__tests__/session.test.ts +0 -3004
- package/src/__tests__/shared-prefix.test.ts +0 -36
- package/src/__tests__/sim-agent.test.ts +0 -174
- package/src/__tests__/sim-platform.test.ts +0 -93
- package/src/__tests__/sim-store.test.ts +0 -214
- package/src/__tests__/simplify.test.ts +0 -283
- package/src/__tests__/startup-lifecycle.test.ts +0 -231
- package/src/__tests__/stop-session.test.ts +0 -162
- package/src/__tests__/stream-state.test.ts +0 -164
- package/src/__tests__/terminal-error.test.ts +0 -54
- package/src/__tests__/terminal-renderer.test.ts +0 -247
- package/src/__tests__/update-command-guard.test.ts +0 -144
- package/src/__tests__/web-ui.test.ts +0 -438
- package/src/__tests__/wechat-platform.test.ts +0 -111
- package/src/adapters/adapter-interface.ts +0 -217
- package/src/adapters/ccc-adapter.ts +0 -150
- package/src/adapters/claude-adapter.ts +0 -673
- package/src/adapters/claude-session-meta-store.ts +0 -120
- package/src/adapters/codex-adapter.ts +0 -426
- package/src/adapters/codex-session-meta-store.ts +0 -131
- package/src/adapters/cursor-adapter.ts +0 -681
- package/src/adapters/cursor-session-meta-store.ts +0 -154
- package/src/adapters/jsonl-stream.ts +0 -157
- package/src/adapters/raw-stream-log.ts +0 -124
- package/src/adapters/resource-monitor.ts +0 -141
- package/src/agent-activity.ts +0 -175
- package/src/agent-delegate-task-rpc.ts +0 -153
- package/src/agent-delegate-task.ts +0 -91
- package/src/agent-file-rpc.ts +0 -172
- package/src/agent-image-rpc.ts +0 -168
- package/src/agent-platform-routing.ts +0 -28
- package/src/agent-reload-config-rpc.ts +0 -34
- package/src/agent-rpc-body.ts +0 -92
- package/src/agent-stop-stuck.ts +0 -129
- package/src/card-action-routing.ts +0 -14
- package/src/card-plain-text.ts +0 -108
- package/src/cardkit.ts +0 -179
- package/src/cards.ts +0 -684
- package/src/chatgpt-subscription-rpc.ts +0 -27
- package/src/chatgpt-subscription.ts +0 -299
- package/src/chrome-devtools-guard.ts +0 -318
- package/src/claude-sdk-installer.ts +0 -324
- package/src/codex-reset-actions.ts +0 -184
- package/src/config-utils.ts +0 -211
- package/src/config.ts +0 -1063
- package/src/cursor-usage.ts +0 -128
- package/src/exit-banner.ts +0 -33
- package/src/feishu-api.ts +0 -1616
- package/src/feishu-message-ingress.ts +0 -195
- package/src/feishu-platform.ts +0 -159
- package/src/format-message.ts +0 -293
- package/src/git-command.ts +0 -202
- package/src/im-skills.ts +0 -149
- package/src/index.ts +0 -1089
- package/src/litellm-proxy.ts +0 -374
- package/src/orchestrator.ts +0 -2543
- package/src/platform-adapter.ts +0 -70
- package/src/platform-startup.ts +0 -16
- package/src/privacy.ts +0 -118
- package/src/progress/reducer.ts +0 -113
- package/src/progress/terminal-renderer.ts +0 -294
- package/src/progress/view.ts +0 -77
- package/src/response-stall.ts +0 -28
- package/src/runtime-reload.ts +0 -34
- package/src/session-chat-binding.ts +0 -292
- package/src/session-name.ts +0 -8
- package/src/session.ts +0 -2659
- package/src/shared-prefix.ts +0 -29
- package/src/shared.ts +0 -552
- package/src/sim-agent.ts +0 -167
- package/src/sim-platform.ts +0 -177
- package/src/sim-store.ts +0 -317
- package/src/simplify.ts +0 -120
- package/src/startup-lifecycle.ts +0 -250
- package/src/stream-state.ts +0 -177
- package/src/terminal-error.ts +0 -129
- package/src/trace.ts +0 -51
- package/src/turn-cards.ts +0 -118
- package/src/update-command-guard.ts +0 -165
- package/src/wechat-platform.ts +0 -680
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
// =============================================================================
|
|
2
|
-
// adapter-interface.ts — 统一的 AI 工具适配器接口和归一化消息类型
|
|
3
|
-
// =============================================================================
|
|
4
|
-
// 所有 AI 工具适配器(Claude SDK、Cursor CLI、Codex CLI 等)都必须实现
|
|
5
|
-
// ToolAdapter 接口。归一化消息类型 UnifiedBlock 屏蔽了各工具的差异,
|
|
6
|
-
// 使 session.ts 不需要关心底层是哪个 AI 工具。
|
|
7
|
-
// =============================================================================
|
|
8
|
-
|
|
9
|
-
// ---------------------------------------------------------------------------
|
|
10
|
-
// UnifiedBlock — 归一化后的消息块
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
export interface UnifiedThinkingBlock {
|
|
14
|
-
type: "thinking";
|
|
15
|
-
thinking: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface UnifiedTextBlock {
|
|
19
|
-
type: "text";
|
|
20
|
-
text: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 适配器明确告知"这是一段完整的最终文本"(覆盖语义,而非追加)。
|
|
25
|
-
*
|
|
26
|
-
* 背景:Cursor CLI 在 `--stream-partial-output` 模式下,先发若干条 partial assistant
|
|
27
|
-
* 消息(每条只是 delta 增量),流结束时再发一条 final assistant 消息(完整文本)。
|
|
28
|
-
* 若把 final 也按 `text` 追加到 finalText,最终会出现"partial 累加 + final 完整"
|
|
29
|
-
* 共两段重复内容。因此 cursor-adapter 把 final 这条标记为 text_final,
|
|
30
|
-
* 由 session.ts 累积到独立字段 finalCompleteText(覆盖语义),最终发送时
|
|
31
|
-
* 由 pickFinalReply 在两者之间挑选。
|
|
32
|
-
*
|
|
33
|
-
* 对没有 partial/final 双轨的适配器(如 Claude SDK),永远不会 emit 此类型。
|
|
34
|
-
*
|
|
35
|
-
* 命名注意:此处的 "final" 指"完整/最终版本"(与 partial delta 相对),
|
|
36
|
-
* 不等于 stream-state / AccumulatorState 中的 finalReply / finalText。
|
|
37
|
-
* 后者命名含 "final" 但实际语义是"本轮所有文本的累积",属历史遗留命名,
|
|
38
|
-
* 详见 session.ts 的 AccumulatorState 注释和 stream-state.ts 的 StreamState 注释。
|
|
39
|
-
*/
|
|
40
|
-
export interface UnifiedTextFinalBlock {
|
|
41
|
-
type: "text_final";
|
|
42
|
-
text: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface UnifiedToolUseBlock {
|
|
46
|
-
type: "tool_use";
|
|
47
|
-
/** 工具调用 ID,用于与 tool_result 对应(Claude SDK 会提供,Cursor 旧格式可能无) */
|
|
48
|
-
id?: string;
|
|
49
|
-
name: string;
|
|
50
|
-
input: unknown;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface UnifiedToolResultBlock {
|
|
54
|
-
type: "tool_result";
|
|
55
|
-
tool_use_id: string;
|
|
56
|
-
content: unknown;
|
|
57
|
-
is_error?: boolean;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface UnifiedRedactedThinkingBlock {
|
|
61
|
-
type: "redacted_thinking";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface UnifiedSearchResultBlock {
|
|
65
|
-
type: "search_result";
|
|
66
|
-
query: string;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface UnifiedCompactBoundaryBlock {
|
|
70
|
-
type: "compact_boundary";
|
|
71
|
-
trigger: "manual" | "auto";
|
|
72
|
-
pre_tokens: number;
|
|
73
|
-
post_tokens?: number;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface UnifiedAgentStatusBlock {
|
|
77
|
-
type: "agent_status";
|
|
78
|
-
status: "compacting" | "responding";
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export type UnifiedBlock =
|
|
82
|
-
| UnifiedAgentStatusBlock
|
|
83
|
-
| UnifiedThinkingBlock
|
|
84
|
-
| UnifiedTextBlock
|
|
85
|
-
| UnifiedTextFinalBlock
|
|
86
|
-
| UnifiedToolUseBlock
|
|
87
|
-
| UnifiedToolResultBlock
|
|
88
|
-
| UnifiedRedactedThinkingBlock
|
|
89
|
-
| UnifiedSearchResultBlock
|
|
90
|
-
| UnifiedCompactBoundaryBlock;
|
|
91
|
-
|
|
92
|
-
// ---------------------------------------------------------------------------
|
|
93
|
-
// UnifiedStreamMessage — 一次 SDK/CLI 事件对应的归一化消息
|
|
94
|
-
// ---------------------------------------------------------------------------
|
|
95
|
-
|
|
96
|
-
export interface UnifiedStreamMessage {
|
|
97
|
-
type: "assistant" | "user" | "system";
|
|
98
|
-
blocks: UnifiedBlock[];
|
|
99
|
-
/**
|
|
100
|
-
* 适配器确认本事件代表一条完整、权威的最终回复,而不是流式文本片段。
|
|
101
|
-
*
|
|
102
|
-
* response-stall 终止与最终事件可能在同一事件循环边界竞态;只有该标记
|
|
103
|
-
* 为 true 时,上层才允许把已经触发的超时改判为正常完成。
|
|
104
|
-
*/
|
|
105
|
-
isFinalResponse?: boolean;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// ---------------------------------------------------------------------------
|
|
109
|
-
// CreateSessionResult
|
|
110
|
-
// ---------------------------------------------------------------------------
|
|
111
|
-
|
|
112
|
-
export interface CreateSessionResult {
|
|
113
|
-
sessionId: string;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// ---------------------------------------------------------------------------
|
|
117
|
-
// SessionInfo — 会话元数据(/state、/cd 等命令使用)
|
|
118
|
-
// ---------------------------------------------------------------------------
|
|
119
|
-
|
|
120
|
-
export interface SessionInfo {
|
|
121
|
-
sessionId: string;
|
|
122
|
-
cwd?: string;
|
|
123
|
-
summary?: string;
|
|
124
|
-
lastModified?: number;
|
|
125
|
-
/**
|
|
126
|
-
* 会话实际使用的模型展示名(如 Cursor 的 `Composer 2 Fast`)。
|
|
127
|
-
* - Cursor adapter:从 cursor-agent system/init 事件学习并持久化到 store
|
|
128
|
-
* - Claude adapter:留空(model 由 ChatCCC 配置 `CLAUDE_MODEL` 决定,不从 SDK 取)
|
|
129
|
-
* 上层 /state、/sessions 渲染时按 tool 决定显示哪一来源。
|
|
130
|
-
*/
|
|
131
|
-
model?: string;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export interface ToolProcessInfo {
|
|
135
|
-
/** Root PID returned by child_process.spawn. With shell:true this is the shell wrapper PID. */
|
|
136
|
-
pid: number;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export interface ToolPromptOptions {
|
|
140
|
-
/** Called once a CLI-backed prompt process has been spawned. */
|
|
141
|
-
onProcessStart?: (info: ToolProcessInfo) => void;
|
|
142
|
-
/** Called when the adapter leaves the prompt process scope normally or by abort. */
|
|
143
|
-
onProcessExit?: (info: ToolProcessInfo) => void;
|
|
144
|
-
/** Called when the adapter creates an SDK session internally.
|
|
145
|
-
* The callback receives a close function that terminates the underlying
|
|
146
|
-
* subprocess. Used by stop-stuck-loop to kill the CLI process immediately. */
|
|
147
|
-
onSessionCreated?: (closeSession: () => void) => void;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// ---------------------------------------------------------------------------
|
|
151
|
-
// ToolAdapter — 统一的 AI 工具适配器接口
|
|
152
|
-
// ---------------------------------------------------------------------------
|
|
153
|
-
|
|
154
|
-
export interface ToolAdapter {
|
|
155
|
-
/** 日志/展示用名称,如 "Claude" */
|
|
156
|
-
readonly displayName: string;
|
|
157
|
-
|
|
158
|
-
/** 群描述中会话 ID 的前缀,如 "Claude Session:" */
|
|
159
|
-
readonly sessionDescPrefix: string;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Whether ChatCCC may infer a stalled response from unchanged streamed output.
|
|
163
|
-
* Defaults to true. Adapters that only emit output after a request completes must disable it.
|
|
164
|
-
*/
|
|
165
|
-
readonly responseStallDetectionEnabled?: boolean;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* 创建新会话,返回会话 ID。
|
|
169
|
-
* 适配器内部需处理后台流消费(静默消费 stream 中除 init 外的所有事件)。
|
|
170
|
-
* signal 用于上层在长期收不到 init 事件时终止底层 SDK/CLI。
|
|
171
|
-
*/
|
|
172
|
-
createSession(cwd: string, signal?: AbortSignal): Promise<CreateSessionResult>;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* 向已有会话发送提示文本,返回归一化消息的异步迭代器。
|
|
176
|
-
* 消费者遍历结束后(或提前中止时)适配器自动关闭底层会话。
|
|
177
|
-
*/
|
|
178
|
-
prompt(
|
|
179
|
-
sessionId: string,
|
|
180
|
-
userText: string,
|
|
181
|
-
cwd: string,
|
|
182
|
-
signal?: AbortSignal,
|
|
183
|
-
options?: ToolPromptOptions,
|
|
184
|
-
): AsyncIterable<UnifiedStreamMessage>;
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* 查询会话元数据。会话不存在时返回 undefined。
|
|
188
|
-
*/
|
|
189
|
-
getSessionInfo(sessionId: string): Promise<SessionInfo | undefined>;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* 关闭/清理会话(/stop 或中断时调用)。
|
|
193
|
-
* 对于流式结束后自动关闭的适配器(如 Claude SDK),此为 no-op。
|
|
194
|
-
*/
|
|
195
|
-
closeSession(sessionId: string): Promise<void>;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// ---------------------------------------------------------------------------
|
|
199
|
-
// parseUserCommand — 从包装后的 userText 中提取原始用户消息并判断模式
|
|
200
|
-
// ---------------------------------------------------------------------------
|
|
201
|
-
|
|
202
|
-
export interface UserCommand {
|
|
203
|
-
/** 原始用户消息(去除包装) */
|
|
204
|
-
original: string;
|
|
205
|
-
/** 检测到的模式:plan / ask / null(普通消息) */
|
|
206
|
-
mode: "plan" | "ask" | null;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/** 从 [User message]...[/User message] 包装中提取原始消息并识别 /plan /ask 前缀 */
|
|
210
|
-
export function parseUserCommand(userText: string): UserCommand {
|
|
211
|
-
const match = userText.match(/\[User message\]\n(.*?)\n\[\/User message\]/s);
|
|
212
|
-
if (!match) return { original: "", mode: null };
|
|
213
|
-
const original = match[1].trimStart();
|
|
214
|
-
if (original.startsWith("/plan")) return { original, mode: "plan" };
|
|
215
|
-
if (original.startsWith("/ask")) return { original, mode: "ask" };
|
|
216
|
-
return { original, mode: null };
|
|
217
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { ChatSession, type ChatSessionConfig, type ChatSessionOptions } from "../../deepccc-agent/src/index.ts";
|
|
2
|
-
import { config as deepCccConfig } from "../../deepccc-agent/src/config.ts";
|
|
3
|
-
import {
|
|
4
|
-
getBuiltinContextSession,
|
|
5
|
-
newBuiltinSessionId,
|
|
6
|
-
normalizeBuiltinSessionId,
|
|
7
|
-
} from "../../deepccc-agent/src/context.ts";
|
|
8
|
-
import { config, CCC_SESSION_PREFIX } from "../config.ts";
|
|
9
|
-
import type {
|
|
10
|
-
CreateSessionResult,
|
|
11
|
-
SessionInfo,
|
|
12
|
-
ToolAdapter,
|
|
13
|
-
ToolPromptOptions,
|
|
14
|
-
UnifiedStreamMessage,
|
|
15
|
-
} from "./adapter-interface.ts";
|
|
16
|
-
|
|
17
|
-
export interface CccAdapterOptions extends ChatSessionConfig {
|
|
18
|
-
contextDir?: string;
|
|
19
|
-
compactAtTokens?: number;
|
|
20
|
-
keepRecentMessages?: number;
|
|
21
|
-
compactionTimeoutMs?: number;
|
|
22
|
-
maxSteps?: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function toChatSessionOptions(
|
|
26
|
-
sessionId: string,
|
|
27
|
-
cwd: string,
|
|
28
|
-
options: CccAdapterOptions,
|
|
29
|
-
): ChatSessionOptions {
|
|
30
|
-
return {
|
|
31
|
-
cwd,
|
|
32
|
-
persist: true,
|
|
33
|
-
sessionId,
|
|
34
|
-
contextDir: options.contextDir,
|
|
35
|
-
compactAtTokens: options.compactAtTokens,
|
|
36
|
-
keepRecentMessages: options.keepRecentMessages,
|
|
37
|
-
compactionTimeoutMs: options.compactionTimeoutMs,
|
|
38
|
-
maxSteps: options.maxSteps,
|
|
39
|
-
// chatccc 无终端可交互,且对齐 claude/codex 适配器的 bypass 模式:
|
|
40
|
-
// 高危命令不询问,全部放行(与独立 deepccc CLI 的 ask 模式不同)
|
|
41
|
-
permissionMode: "bypass",
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function createCccAdapter(options: CccAdapterOptions = {}): ToolAdapter {
|
|
46
|
-
if (!options.apiKey?.trim()) {
|
|
47
|
-
throw new Error("ChatCCC 未配置 CCC Agent API Key。请先填写 ccc.DEEPSEEK_API_KEY 后再启用 CCC Agent。");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const chatConfig: ChatSessionConfig = {
|
|
51
|
-
apiKey: options.apiKey,
|
|
52
|
-
...(options.provider !== undefined ? { provider: options.provider } : {}),
|
|
53
|
-
...(options.baseURL !== undefined ? { baseURL: options.baseURL } : {}),
|
|
54
|
-
...(options.model !== undefined ? { model: options.model } : {}),
|
|
55
|
-
...(options.effort !== undefined ? { effort: options.effort } : {}),
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
displayName: "CCC Agent",
|
|
60
|
-
sessionDescPrefix: CCC_SESSION_PREFIX,
|
|
61
|
-
// Non-streaming DeepCCC emits its reply only after the provider request finishes,
|
|
62
|
-
// so unchanged output cannot distinguish a slow request from a stalled response.
|
|
63
|
-
responseStallDetectionEnabled: deepCccConfig.streaming,
|
|
64
|
-
|
|
65
|
-
async createSession(cwd: string): Promise<CreateSessionResult> {
|
|
66
|
-
const sessionId = newBuiltinSessionId();
|
|
67
|
-
const session = new ChatSession(
|
|
68
|
-
chatConfig,
|
|
69
|
-
toChatSessionOptions(sessionId, cwd, options),
|
|
70
|
-
);
|
|
71
|
-
session.reset();
|
|
72
|
-
return { sessionId };
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
async *prompt(
|
|
76
|
-
sessionId: string,
|
|
77
|
-
userText: string,
|
|
78
|
-
cwd: string,
|
|
79
|
-
signal?: AbortSignal,
|
|
80
|
-
_promptOptions?: ToolPromptOptions,
|
|
81
|
-
): AsyncIterable<UnifiedStreamMessage> {
|
|
82
|
-
const normalizedSessionId = normalizeBuiltinSessionId(sessionId);
|
|
83
|
-
const session = new ChatSession(
|
|
84
|
-
chatConfig,
|
|
85
|
-
toChatSessionOptions(normalizedSessionId, cwd, options),
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
for await (const event of session.chat(userText, signal)) {
|
|
89
|
-
if (event.type === "status") {
|
|
90
|
-
yield {
|
|
91
|
-
type: "assistant",
|
|
92
|
-
blocks: [{
|
|
93
|
-
type: "agent_status",
|
|
94
|
-
status: event.phase === "compacting" ? "compacting" : "responding",
|
|
95
|
-
}],
|
|
96
|
-
};
|
|
97
|
-
} else if (event.type === "text") {
|
|
98
|
-
yield {
|
|
99
|
-
type: "assistant",
|
|
100
|
-
blocks: [{ type: "text", text: event.text }],
|
|
101
|
-
};
|
|
102
|
-
} else if (event.type === "tool_use") {
|
|
103
|
-
yield {
|
|
104
|
-
type: "assistant",
|
|
105
|
-
blocks: [{
|
|
106
|
-
type: "tool_use",
|
|
107
|
-
id: event.id,
|
|
108
|
-
name: event.name,
|
|
109
|
-
input: event.input,
|
|
110
|
-
}],
|
|
111
|
-
};
|
|
112
|
-
} else if (event.type === "tool_result") {
|
|
113
|
-
yield {
|
|
114
|
-
type: "assistant",
|
|
115
|
-
blocks: [{
|
|
116
|
-
type: "tool_result",
|
|
117
|
-
tool_use_id: event.tool_use_id,
|
|
118
|
-
content: event.content,
|
|
119
|
-
is_error: event.is_error,
|
|
120
|
-
}],
|
|
121
|
-
};
|
|
122
|
-
} else if (event.type === "done" && !signal?.aborted) {
|
|
123
|
-
yield {
|
|
124
|
-
type: "assistant",
|
|
125
|
-
blocks: [],
|
|
126
|
-
isFinalResponse: true,
|
|
127
|
-
};
|
|
128
|
-
} else if (event.type === "error") {
|
|
129
|
-
throw new Error(event.message);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
async getSessionInfo(sessionId: string): Promise<SessionInfo | undefined> {
|
|
135
|
-
const normalizedSessionId = normalizeBuiltinSessionId(sessionId);
|
|
136
|
-
const info = getBuiltinContextSession(normalizedSessionId, options.contextDir);
|
|
137
|
-
if (!info) return undefined;
|
|
138
|
-
return {
|
|
139
|
-
sessionId: info.sessionId,
|
|
140
|
-
cwd: info.cwd,
|
|
141
|
-
lastModified: info.updatedAt,
|
|
142
|
-
model: options.model ?? config.ccc.model,
|
|
143
|
-
};
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
async closeSession(_sessionId: string): Promise<void> {
|
|
147
|
-
// ChatSession uses one request-scoped stream per prompt. AbortSignal handles cancellation.
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
}
|