chatccc 0.2.252 → 0.2.253
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 +1 -1
- package/bin/cccagent.mjs +12 -3
- package/bin/chatccc.mjs +15 -6
- 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 +76 -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 +571 -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/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 +804 -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 +833 -0
- package/dist/src/litellm-proxy.js +300 -0
- package/dist/src/orchestrator.js +2078 -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 +2144 -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} +749 -823
- 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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DEFAULT_BUILTIN_CONTEXT_DIR, getBuiltinContextSession, latestBuiltinSessionForCwd, newBuiltinSessionId, normalizeBuiltinSessionId, } from "./context.js";
|
|
2
|
+
export function resolveBuiltinSession(options) {
|
|
3
|
+
const contextDir = options.contextDir ?? DEFAULT_BUILTIN_CONTEXT_DIR;
|
|
4
|
+
if (options.resume === true) {
|
|
5
|
+
const latest = latestBuiltinSessionForCwd(options.cwd, contextDir);
|
|
6
|
+
if (!latest) {
|
|
7
|
+
throw new Error(`No resumable DeepCCC session found for cwd: ${options.cwd}`);
|
|
8
|
+
}
|
|
9
|
+
return { mode: "resumed", sessionId: latest.sessionId };
|
|
10
|
+
}
|
|
11
|
+
if (typeof options.resume === "string") {
|
|
12
|
+
const sessionId = normalizeBuiltinSessionId(options.resume);
|
|
13
|
+
const existing = getBuiltinContextSession(sessionId, contextDir);
|
|
14
|
+
if (!existing) {
|
|
15
|
+
throw new Error(`DeepCCC session not found: ${sessionId}`);
|
|
16
|
+
}
|
|
17
|
+
return { mode: "resumed", sessionId };
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
mode: "new",
|
|
21
|
+
sessionId: newBuiltinSessionId(options.now, options.randomSuffix),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const CTRL_C_CONFIRM_WINDOW_MS = 2000;
|
|
2
|
+
export function createCtrlCState(options = {}) {
|
|
3
|
+
const windowMs = options.windowMs ?? CTRL_C_CONFIRM_WINDOW_MS;
|
|
4
|
+
const now = options.now ?? Date.now;
|
|
5
|
+
let pending = null;
|
|
6
|
+
let lastPressAt = 0;
|
|
7
|
+
return {
|
|
8
|
+
press(isGenerating) {
|
|
9
|
+
const action = isGenerating ? "interrupt" : "exit";
|
|
10
|
+
const current = now();
|
|
11
|
+
const isConfirmed = pending === action && current - lastPressAt <= windowMs;
|
|
12
|
+
if (isConfirmed) {
|
|
13
|
+
pending = null;
|
|
14
|
+
lastPressAt = 0;
|
|
15
|
+
return action;
|
|
16
|
+
}
|
|
17
|
+
pending = action;
|
|
18
|
+
lastPressAt = current;
|
|
19
|
+
return isGenerating ? "arm-interrupt" : "arm-exit";
|
|
20
|
+
},
|
|
21
|
+
reset() {
|
|
22
|
+
pending = null;
|
|
23
|
+
lastPressAt = 0;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skills.ts — 多来源技能扫描(DeepCCC 统一入口)
|
|
3
|
+
*
|
|
4
|
+
* 并行扫描 Claude / Codex / Cursor / DeepCCC 四套目录式技能
|
|
5
|
+
* (<name>/SKILL.md + YAML frontmatter,三套生态同构)。
|
|
6
|
+
*
|
|
7
|
+
* 同名优先级(高 → 低):deepccc > codex > cursor > claude;
|
|
8
|
+
* 同来源内:project(项目级)> global(用户级)。
|
|
9
|
+
* 目录列表按低 → 高排列,扫描时后者覆盖前者,天然实现优先级。
|
|
10
|
+
*
|
|
11
|
+
* 热加载:SKILL.md 内容带 mtime 缓存,文件变化时自动重读;
|
|
12
|
+
* 目录枚举每次都做(新技能目录立即被发现)。因此"创建技能 →
|
|
13
|
+
* 下一次对话自动生效",无需重启,也无需常驻 watcher。
|
|
14
|
+
*/
|
|
15
|
+
import { readdirSync } from "node:fs";
|
|
16
|
+
import { readFile, stat } from "node:fs/promises";
|
|
17
|
+
import { homedir } from "node:os";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
/** 解析 SKILL.md frontmatter(兼容 CRLF),返回 name + description;无 frontmatter 返回 null */
|
|
20
|
+
export function parseSkillFrontmatter(content) {
|
|
21
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/.exec(content);
|
|
22
|
+
if (!match)
|
|
23
|
+
return null;
|
|
24
|
+
const fm = match[1];
|
|
25
|
+
const nameMatch = /^name:\s*(.+?)\s*$/m.exec(fm);
|
|
26
|
+
if (!nameMatch)
|
|
27
|
+
return null;
|
|
28
|
+
const descMatch = /^description:\s*(.+?)\s*$/m.exec(fm);
|
|
29
|
+
return {
|
|
30
|
+
name: nameMatch[1].trim(),
|
|
31
|
+
description: descMatch?.[1].trim() ?? "",
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// mtime 热加载缓存:同一进程内重复扫描命中缓存(stat 校验),文件变化自动重读
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
const skillFileCache = new Map();
|
|
38
|
+
async function readSkillFile(skillPath) {
|
|
39
|
+
let st;
|
|
40
|
+
try {
|
|
41
|
+
st = await stat(skillPath);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if (!st.isFile())
|
|
47
|
+
return null;
|
|
48
|
+
const cached = skillFileCache.get(skillPath);
|
|
49
|
+
if (cached && cached.mtimeMs === st.mtimeMs)
|
|
50
|
+
return cached.content;
|
|
51
|
+
const content = await readFile(skillPath, "utf8");
|
|
52
|
+
skillFileCache.set(skillPath, { mtimeMs: st.mtimeMs, content });
|
|
53
|
+
return content;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 扫描多个 skill 目录(并行读取),按 name 去重。
|
|
57
|
+
* 同名技能:后面的 spec(高优先级)覆盖前面的(低优先级)。
|
|
58
|
+
* 隐藏目录(.system 等)和无 SKILL.md 的目录会被跳过;缺失目录跳过。
|
|
59
|
+
*/
|
|
60
|
+
export async function scanSkillsDirs(dirs) {
|
|
61
|
+
const byName = new Map();
|
|
62
|
+
for (const spec of dirs) {
|
|
63
|
+
let entries;
|
|
64
|
+
try {
|
|
65
|
+
entries = readdirSync(spec.dir, { withFileTypes: true });
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
continue; // 目录不存在或不可读:跳过
|
|
69
|
+
}
|
|
70
|
+
// 目录内所有候选 SKILL.md 并行读取(读文件是扫描的瓶颈)
|
|
71
|
+
const results = await Promise.all(entries
|
|
72
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
|
|
73
|
+
.map(async (entry) => {
|
|
74
|
+
const skillPath = join(spec.dir, entry.name, "SKILL.md");
|
|
75
|
+
const content = await readSkillFile(skillPath);
|
|
76
|
+
if (content === null)
|
|
77
|
+
return null;
|
|
78
|
+
const parsed = parseSkillFrontmatter(content);
|
|
79
|
+
if (!parsed)
|
|
80
|
+
return null;
|
|
81
|
+
return { ...parsed, skillPath };
|
|
82
|
+
}));
|
|
83
|
+
for (const result of results) {
|
|
84
|
+
if (!result)
|
|
85
|
+
continue;
|
|
86
|
+
byName.set(result.name, {
|
|
87
|
+
name: result.name,
|
|
88
|
+
description: result.description,
|
|
89
|
+
skillPath: result.skillPath,
|
|
90
|
+
source: spec.source,
|
|
91
|
+
scope: spec.scope,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return [...byName.values()];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 默认技能扫描目录(按优先级从低到高排列,扫描时后者覆盖前者):
|
|
99
|
+
* claude(global→project) < cursor(global→project) < codex(global→project) < deepccc(global→project)
|
|
100
|
+
* 其中 codex 全局包含 ~/.codex/skills(CLI 旧路径)与 ~/.agents/skills(标准全局目录)。
|
|
101
|
+
*/
|
|
102
|
+
export function buildDefaultSkillDirs(cwd) {
|
|
103
|
+
const h = homedir();
|
|
104
|
+
return [
|
|
105
|
+
{ dir: join(h, ".claude", "skills"), source: "claude", scope: "global" },
|
|
106
|
+
{ dir: join(cwd, ".claude", "skills"), source: "claude", scope: "project" },
|
|
107
|
+
{ dir: join(h, ".cursor", "skills"), source: "cursor", scope: "global" },
|
|
108
|
+
{ dir: join(cwd, ".cursor", "skills"), source: "cursor", scope: "project" },
|
|
109
|
+
{ dir: join(h, ".codex", "skills"), source: "codex", scope: "global" },
|
|
110
|
+
{ dir: join(h, ".agents", "skills"), source: "codex", scope: "global" },
|
|
111
|
+
{ dir: join(cwd, ".codex", "skills"), source: "codex", scope: "project" },
|
|
112
|
+
{ dir: join(h, ".deepccc", "skills"), source: "deepccc", scope: "global" },
|
|
113
|
+
{ dir: join(cwd, ".deepccc", "skills"), source: "deepccc", scope: "project" },
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 把技能绝对路径转成 prompt 展示形式:主目录下的路径缩写为 `~/...`(跨机器、
|
|
118
|
+
* 跨用户稳定,避免用户名/盘符差异导致 system 前缀变化破坏缓存命中);
|
|
119
|
+
* 分隔符统一为 `/`。主目录外的路径保持绝对路径(仅统一分隔符)。
|
|
120
|
+
*/
|
|
121
|
+
export function normalizeSkillPathForPrompt(skillPath) {
|
|
122
|
+
const home = homedir().replace(/[\\/]+$/, "").replace(/\\/g, "/");
|
|
123
|
+
const normalized = skillPath.replace(/\\/g, "/");
|
|
124
|
+
if (normalized === home)
|
|
125
|
+
return "~";
|
|
126
|
+
if (normalized.startsWith(home + "/")) {
|
|
127
|
+
return "~" + normalized.slice(home.length);
|
|
128
|
+
}
|
|
129
|
+
return normalized;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 生成 skill 索引提示词(注入 system prompt)。
|
|
133
|
+
* 索引只含 name + description + 来源 + 路径,并指示模型在任务匹配时
|
|
134
|
+
* 先用 read_file 读取 SKILL.md 全文再执行;同时声明"创建技能"约定
|
|
135
|
+
* (模型在对话中应把新技能创建到 ~/.deepccc/skills 或项目 .deepccc/skills)。
|
|
136
|
+
* 路径经 normalizeSkillPathForPrompt 缩写,保持跨机器前缀稳定。
|
|
137
|
+
*/
|
|
138
|
+
export function buildSkillsIndexPrompt(skills) {
|
|
139
|
+
if (skills.length === 0)
|
|
140
|
+
return "";
|
|
141
|
+
const lines = [
|
|
142
|
+
"## 可用技能",
|
|
143
|
+
"技能会从 Claude/Codex/Cursor/DeepCCC 技能目录并行扫描。",
|
|
144
|
+
"名称冲突时:DeepCCC > Codex > Cursor > Claude 优先;同一来源内,项目级优先于全局。",
|
|
145
|
+
"当用户请求匹配某个技能的描述时,先用 read_file 读取其完整 SKILL.md,然后严格按其指令执行。",
|
|
146
|
+
"",
|
|
147
|
+
...skills.map((s) => `- **${s.name}** [${s.source}:${s.scope}] (\`${normalizeSkillPathForPrompt(s.skillPath)}\`): ${s.description || "(无描述)"}`),
|
|
148
|
+
"",
|
|
149
|
+
"## 创建技能",
|
|
150
|
+
"当用户要求创建技能时,按 Codex 风格的目录技能创建:",
|
|
151
|
+
"~/.deepccc/skills/<name>/SKILL.md(全局,默认)或 <cwd>/.deepccc/skills/<name>/SKILL.md(项目级,仅当用户明确要求项目级技能时)。",
|
|
152
|
+
"SKILL.md 格式:",
|
|
153
|
+
"```",
|
|
154
|
+
"---",
|
|
155
|
+
"name: <skill-name>",
|
|
156
|
+
"description: <one-line description>",
|
|
157
|
+
"---",
|
|
158
|
+
"",
|
|
159
|
+
"<instructions>",
|
|
160
|
+
"```",
|
|
161
|
+
"新技能会在下一条消息自动生效(热加载);无需重启。",
|
|
162
|
+
];
|
|
163
|
+
return lines.join("\n");
|
|
164
|
+
}
|
|
165
|
+
/** 生成 Codex 结构的新技能 SKILL.md 模板(供 CLI skill create / 对话创建约定共用) */
|
|
166
|
+
export function buildSkillTemplate(name, description) {
|
|
167
|
+
return [
|
|
168
|
+
"---",
|
|
169
|
+
`name: ${name}`,
|
|
170
|
+
`description: ${description}`,
|
|
171
|
+
"---",
|
|
172
|
+
"",
|
|
173
|
+
`# ${name}`,
|
|
174
|
+
"",
|
|
175
|
+
"<skill instructions>",
|
|
176
|
+
"",
|
|
177
|
+
].join("\n");
|
|
178
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-tools.ts — websearch / webfetch 内置工具(agent 端联网,业界主流做法)
|
|
3
|
+
*
|
|
4
|
+
* 与 Claude Code 的 WebSearch/WebFetch、Codex 的 web search 相同形态:
|
|
5
|
+
* 模型通过 function calling 调用,agent 进程执行 HTTP 请求,结果回填上下文。
|
|
6
|
+
* 两者都是只读外部网络操作,不触碰本地文件系统,无需权限询问。
|
|
7
|
+
*
|
|
8
|
+
* - websearch:DuckDuckGo HTML 端点(免 API key),返回标题 + URL + 摘要
|
|
9
|
+
* - webfetch:HTTP GET + HTML 转纯文本,控制大小与超时
|
|
10
|
+
*
|
|
11
|
+
* 零新依赖:使用 Node 20 内置 fetch / AbortSignal / Buffer。
|
|
12
|
+
* 解析逻辑拆成纯函数导出,便于单测;fetch 可通过 options 注入 mock。
|
|
13
|
+
*/
|
|
14
|
+
export const WEB_SEARCH_TIMEOUT_MS = 15_000;
|
|
15
|
+
export const WEB_FETCH_TIMEOUT_MS = 20_000;
|
|
16
|
+
export const WEB_SEARCH_DEFAULT_RESULTS = 5;
|
|
17
|
+
export const WEB_SEARCH_MAX_RESULTS = 10;
|
|
18
|
+
export const WEB_FETCH_DEFAULT_CHARS = 10_000;
|
|
19
|
+
export const WEB_FETCH_MAX_CHARS = 100_000;
|
|
20
|
+
/** webfetch 读取响应体的大小上限(超出即截断),防止把整个大文件拉进上下文 */
|
|
21
|
+
export const WEB_FETCH_MAX_BYTES = 512 * 1024;
|
|
22
|
+
const SEARCH_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36";
|
|
23
|
+
function normalizeMaxResults(value) {
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
return WEB_SEARCH_DEFAULT_RESULTS;
|
|
26
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
27
|
+
throw new Error("maxResults must be a positive integer when provided");
|
|
28
|
+
}
|
|
29
|
+
return Math.min(value, WEB_SEARCH_MAX_RESULTS);
|
|
30
|
+
}
|
|
31
|
+
function normalizeMaxChars(value) {
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return WEB_FETCH_DEFAULT_CHARS;
|
|
34
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
35
|
+
throw new Error("maxChars must be a positive integer when provided");
|
|
36
|
+
}
|
|
37
|
+
return Math.min(value, WEB_FETCH_MAX_CHARS);
|
|
38
|
+
}
|
|
39
|
+
function buildSignal(timeoutMs, abortSignal) {
|
|
40
|
+
const signals = [AbortSignal.timeout(timeoutMs)];
|
|
41
|
+
if (abortSignal)
|
|
42
|
+
signals.push(abortSignal);
|
|
43
|
+
return signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
44
|
+
}
|
|
45
|
+
function decodeEntities(s) {
|
|
46
|
+
return s
|
|
47
|
+
.replace(/</gi, "<")
|
|
48
|
+
.replace(/>/gi, ">")
|
|
49
|
+
.replace(/"/gi, '"')
|
|
50
|
+
.replace(/�?39;/gi, "'")
|
|
51
|
+
.replace(/ /gi, " ")
|
|
52
|
+
.replace(/&#(\d+);/g, (_, n) => {
|
|
53
|
+
try {
|
|
54
|
+
return String.fromCodePoint(Number(n));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return "";
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, h) => {
|
|
61
|
+
try {
|
|
62
|
+
return String.fromCodePoint(parseInt(h, 16));
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return "";
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
.replace(/&/gi, "&");
|
|
69
|
+
}
|
|
70
|
+
function stripTags(s) {
|
|
71
|
+
return decodeEntities(s.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim());
|
|
72
|
+
}
|
|
73
|
+
/** 提取 <title> 文本(用于 webfetch 结果),无则返回空字符串 */
|
|
74
|
+
export function extractHtmlTitle(html) {
|
|
75
|
+
const m = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
|
|
76
|
+
return m ? stripTags(m[1]) : "";
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* HTML 转纯文本:
|
|
80
|
+
* 去掉 script/style/noscript/svg/注释 → 块级元素补换行 → 去标签 → 解实体 → 压缩空白。
|
|
81
|
+
*/
|
|
82
|
+
export function htmlToPlainText(html) {
|
|
83
|
+
let text = html
|
|
84
|
+
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, " ")
|
|
85
|
+
.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, " ")
|
|
86
|
+
.replace(/<noscript\b[^>]*>[\s\S]*?<\/noscript>/gi, " ")
|
|
87
|
+
.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gi, " ")
|
|
88
|
+
.replace(/<!--[\s\S]*?-->/g, " ")
|
|
89
|
+
.replace(/<\/(p|div|li|tr|h[1-6]|pre|blockquote|section|article|table|ul|ol|header|footer|nav|dl|dd|dt)>/gi, "\n")
|
|
90
|
+
.replace(/<(br|hr)\s*\/?>/gi, "\n")
|
|
91
|
+
.replace(/<[^>]+>/g, "");
|
|
92
|
+
text = decodeEntities(text);
|
|
93
|
+
return text
|
|
94
|
+
.split("\n")
|
|
95
|
+
.map((line) => line.replace(/\s+/g, " ").trim())
|
|
96
|
+
.filter((line, i, arr) => line !== "" || (i > 0 && arr[i - 1] !== ""))
|
|
97
|
+
.join("\n")
|
|
98
|
+
.trim();
|
|
99
|
+
}
|
|
100
|
+
/** 解码 DuckDuckGo 结果链接:/l/?uddg=<encoded> 还原为目标 URL */
|
|
101
|
+
export function decodeDdgHref(href) {
|
|
102
|
+
let h = href.trim();
|
|
103
|
+
if (h.startsWith("//"))
|
|
104
|
+
h = "https:" + h;
|
|
105
|
+
try {
|
|
106
|
+
const u = new URL(h);
|
|
107
|
+
if (u.hostname === "duckduckgo.com" && u.pathname.startsWith("/l/")) {
|
|
108
|
+
const uddg = u.searchParams.get("uddg");
|
|
109
|
+
if (uddg)
|
|
110
|
+
return decodeURIComponent(uddg);
|
|
111
|
+
}
|
|
112
|
+
return u.toString();
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return h;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 解析 DuckDuckGo HTML 搜索结果页(html.duckduckgo.com/html)。
|
|
120
|
+
* 提取 result__a(标题 + href)与 result__snippet(摘要)。
|
|
121
|
+
*/
|
|
122
|
+
export function parseDuckDuckGoHtml(html) {
|
|
123
|
+
const results = [];
|
|
124
|
+
const titleRe = /<a[^>]*class="result__a"[^>]*href="([^"]*)"[^>]*>([\s\S]*?)<\/a>/gi;
|
|
125
|
+
const snippetRe = /<a[^>]*class="result__snippet"[^>]*>([\s\S]*?)<\/a>/gi;
|
|
126
|
+
const titleMatches = [...html.matchAll(titleRe)];
|
|
127
|
+
const snippetMatches = [...html.matchAll(snippetRe)];
|
|
128
|
+
titleMatches.forEach((m, i) => {
|
|
129
|
+
const title = stripTags(m[2]);
|
|
130
|
+
const url = decodeDdgHref(m[1]);
|
|
131
|
+
const snippet = snippetMatches[i] ? stripTags(snippetMatches[i][1]) : "";
|
|
132
|
+
if (!title && !url)
|
|
133
|
+
return;
|
|
134
|
+
results.push({ title, url, snippet });
|
|
135
|
+
});
|
|
136
|
+
return results;
|
|
137
|
+
}
|
|
138
|
+
/** 读取响应体并限制字节数(超出截断),避免整页大文件进入上下文 */
|
|
139
|
+
async function readBodyWithLimit(res, maxBytes) {
|
|
140
|
+
if (!res.body) {
|
|
141
|
+
const text = await res.text();
|
|
142
|
+
return { text, truncated: Buffer.byteLength(text, "utf8") > maxBytes };
|
|
143
|
+
}
|
|
144
|
+
const reader = res.body.getReader();
|
|
145
|
+
const chunks = [];
|
|
146
|
+
let total = 0;
|
|
147
|
+
let truncated = false;
|
|
148
|
+
for (;;) {
|
|
149
|
+
const { done, value } = await reader.read();
|
|
150
|
+
if (done)
|
|
151
|
+
break;
|
|
152
|
+
if (!value)
|
|
153
|
+
continue;
|
|
154
|
+
if (total + value.byteLength > maxBytes) {
|
|
155
|
+
const remaining = maxBytes - total;
|
|
156
|
+
if (remaining > 0)
|
|
157
|
+
chunks.push(value.subarray(0, remaining));
|
|
158
|
+
truncated = true;
|
|
159
|
+
await reader.cancel().catch(() => { });
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
chunks.push(value);
|
|
163
|
+
total += value.byteLength;
|
|
164
|
+
}
|
|
165
|
+
return { text: Buffer.concat(chunks.map((c) => Buffer.from(c))).toString("utf8"), truncated };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* websearch:DuckDuckGo HTML 搜索(免 API key),返回标题 + URL + 摘要。
|
|
169
|
+
* 网络失败抛错(成为 tool-error),搜索无结果返回空数组(不是错误)。
|
|
170
|
+
*/
|
|
171
|
+
export async function webSearchForTool(input, options = {}) {
|
|
172
|
+
const query = input.query?.trim();
|
|
173
|
+
if (!query)
|
|
174
|
+
throw new Error("query is required");
|
|
175
|
+
const maxResults = normalizeMaxResults(input.maxResults);
|
|
176
|
+
const startedAt = Date.now();
|
|
177
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
178
|
+
const url = `https://html.duckduckgo.com/html/?q=${encodeURIComponent(query)}`;
|
|
179
|
+
const res = await fetchImpl(url, {
|
|
180
|
+
headers: {
|
|
181
|
+
"User-Agent": SEARCH_UA,
|
|
182
|
+
Accept: "text/html,application/xhtml+xml",
|
|
183
|
+
},
|
|
184
|
+
redirect: "follow",
|
|
185
|
+
signal: buildSignal(options.timeoutMs ?? WEB_SEARCH_TIMEOUT_MS, options.abortSignal),
|
|
186
|
+
});
|
|
187
|
+
if (!res.ok) {
|
|
188
|
+
throw new Error(`web search failed: HTTP ${res.status} ${res.statusText}`);
|
|
189
|
+
}
|
|
190
|
+
const { text } = await readBodyWithLimit(res, WEB_FETCH_MAX_BYTES);
|
|
191
|
+
const all = parseDuckDuckGoHtml(text);
|
|
192
|
+
const results = all.slice(0, maxResults);
|
|
193
|
+
return {
|
|
194
|
+
query,
|
|
195
|
+
results,
|
|
196
|
+
truncated: all.length > results.length,
|
|
197
|
+
durationMs: Date.now() - startedAt,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* webfetch:HTTP GET + HTML 转纯文本。
|
|
202
|
+
* 只允许 http/https(防 file:// 等本地协议),非 2xx 抛错。
|
|
203
|
+
*/
|
|
204
|
+
export async function webFetchForTool(input, options = {}) {
|
|
205
|
+
const raw = input.url?.trim();
|
|
206
|
+
if (!raw)
|
|
207
|
+
throw new Error("url is required");
|
|
208
|
+
let parsed;
|
|
209
|
+
try {
|
|
210
|
+
parsed = new URL(raw);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
throw new Error(`invalid URL: ${raw}`);
|
|
214
|
+
}
|
|
215
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
216
|
+
throw new Error(`unsupported protocol: ${parsed.protocol} (only http/https allowed)`);
|
|
217
|
+
}
|
|
218
|
+
const maxChars = normalizeMaxChars(input.maxChars);
|
|
219
|
+
const startedAt = Date.now();
|
|
220
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
221
|
+
const res = await fetchImpl(parsed.toString(), {
|
|
222
|
+
headers: {
|
|
223
|
+
"User-Agent": SEARCH_UA,
|
|
224
|
+
Accept: "text/html,application/xhtml+xml,text/plain;q=0.9,*/*;q=0.8",
|
|
225
|
+
},
|
|
226
|
+
redirect: "follow",
|
|
227
|
+
signal: buildSignal(options.timeoutMs ?? WEB_FETCH_TIMEOUT_MS, options.abortSignal),
|
|
228
|
+
});
|
|
229
|
+
if (!res.ok) {
|
|
230
|
+
throw new Error(`HTTP ${res.status} ${res.statusText} for ${parsed.toString()}`);
|
|
231
|
+
}
|
|
232
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
233
|
+
const { text: body, truncated: bodyTruncated } = await readBodyWithLimit(res, WEB_FETCH_MAX_BYTES);
|
|
234
|
+
const title = extractHtmlTitle(body);
|
|
235
|
+
const plain = htmlToPlainText(body);
|
|
236
|
+
const text = plain.length > maxChars ? plain.slice(0, maxChars) : plain;
|
|
237
|
+
return {
|
|
238
|
+
url: parsed.toString(),
|
|
239
|
+
contentType,
|
|
240
|
+
title,
|
|
241
|
+
text,
|
|
242
|
+
chars: text.length,
|
|
243
|
+
truncated: bodyTruncated || plain.length > maxChars,
|
|
244
|
+
durationMs: Date.now() - startedAt,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// adapter-interface.ts — 统一的 AI 工具适配器接口和归一化消息类型
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// 所有 AI 工具适配器(Claude SDK、Cursor CLI、Codex CLI 等)都必须实现
|
|
5
|
+
// ToolAdapter 接口。归一化消息类型 UnifiedBlock 屏蔽了各工具的差异,
|
|
6
|
+
// 使 session.ts 不需要关心底层是哪个 AI 工具。
|
|
7
|
+
// =============================================================================
|
|
8
|
+
/** 从 [User message]...[/User message] 包装中提取原始消息并识别 /plan /ask 前缀 */
|
|
9
|
+
export function parseUserCommand(userText) {
|
|
10
|
+
const match = userText.match(/\[User message\]\n(.*?)\n\[\/User message\]/s);
|
|
11
|
+
if (!match)
|
|
12
|
+
return { original: "", mode: null };
|
|
13
|
+
const original = match[1].trimStart();
|
|
14
|
+
if (original.startsWith("/plan"))
|
|
15
|
+
return { original, mode: "plan" };
|
|
16
|
+
if (original.startsWith("/ask"))
|
|
17
|
+
return { original, mode: "ask" };
|
|
18
|
+
return { original, mode: null };
|
|
19
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ChatSession } from "../../deepccc-agent/src/index.js";
|
|
2
|
+
import { config as deepCccConfig } from "../../deepccc-agent/src/config.js";
|
|
3
|
+
import { getBuiltinContextSession, newBuiltinSessionId, normalizeBuiltinSessionId, } from "../../deepccc-agent/src/context.js";
|
|
4
|
+
import { config, CCC_SESSION_PREFIX } from "../config.js";
|
|
5
|
+
function toChatSessionOptions(sessionId, cwd, options) {
|
|
6
|
+
return {
|
|
7
|
+
cwd,
|
|
8
|
+
persist: true,
|
|
9
|
+
sessionId,
|
|
10
|
+
contextDir: options.contextDir,
|
|
11
|
+
compactAtTokens: options.compactAtTokens,
|
|
12
|
+
keepRecentMessages: options.keepRecentMessages,
|
|
13
|
+
compactionTimeoutMs: options.compactionTimeoutMs,
|
|
14
|
+
maxSteps: options.maxSteps,
|
|
15
|
+
// chatccc 无终端可交互,且对齐 claude/codex 适配器的 bypass 模式:
|
|
16
|
+
// 高危命令不询问,全部放行(与独立 deepccc CLI 的 ask 模式不同)
|
|
17
|
+
permissionMode: "bypass",
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function createCccAdapter(options = {}) {
|
|
21
|
+
if (!options.apiKey?.trim()) {
|
|
22
|
+
throw new Error("ChatCCC 未配置 CCC Agent API Key。请先填写 ccc.DEEPSEEK_API_KEY 后再启用 CCC Agent。");
|
|
23
|
+
}
|
|
24
|
+
const chatConfig = {
|
|
25
|
+
apiKey: options.apiKey,
|
|
26
|
+
...(options.provider !== undefined ? { provider: options.provider } : {}),
|
|
27
|
+
...(options.baseURL !== undefined ? { baseURL: options.baseURL } : {}),
|
|
28
|
+
...(options.model !== undefined ? { model: options.model } : {}),
|
|
29
|
+
...(options.effort !== undefined ? { effort: options.effort } : {}),
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
displayName: "CCC Agent",
|
|
33
|
+
sessionDescPrefix: CCC_SESSION_PREFIX,
|
|
34
|
+
// Non-streaming DeepCCC emits its reply only after the provider request finishes,
|
|
35
|
+
// so unchanged output cannot distinguish a slow request from a stalled response.
|
|
36
|
+
responseStallDetectionEnabled: deepCccConfig.streaming,
|
|
37
|
+
async createSession(cwd) {
|
|
38
|
+
const sessionId = newBuiltinSessionId();
|
|
39
|
+
const session = new ChatSession(chatConfig, toChatSessionOptions(sessionId, cwd, options));
|
|
40
|
+
session.reset();
|
|
41
|
+
return { sessionId };
|
|
42
|
+
},
|
|
43
|
+
async *prompt(sessionId, userText, cwd, signal, _promptOptions) {
|
|
44
|
+
const normalizedSessionId = normalizeBuiltinSessionId(sessionId);
|
|
45
|
+
const session = new ChatSession(chatConfig, toChatSessionOptions(normalizedSessionId, cwd, options));
|
|
46
|
+
for await (const event of session.chat(userText, signal)) {
|
|
47
|
+
if (event.type === "status") {
|
|
48
|
+
yield {
|
|
49
|
+
type: "assistant",
|
|
50
|
+
blocks: [{
|
|
51
|
+
type: "agent_status",
|
|
52
|
+
status: event.phase === "compacting" ? "compacting" : "responding",
|
|
53
|
+
}],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else if (event.type === "text") {
|
|
57
|
+
yield {
|
|
58
|
+
type: "assistant",
|
|
59
|
+
blocks: [{ type: "text", text: event.text }],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
else if (event.type === "tool_use") {
|
|
63
|
+
yield {
|
|
64
|
+
type: "assistant",
|
|
65
|
+
blocks: [{
|
|
66
|
+
type: "tool_use",
|
|
67
|
+
id: event.id,
|
|
68
|
+
name: event.name,
|
|
69
|
+
input: event.input,
|
|
70
|
+
}],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
else if (event.type === "tool_result") {
|
|
74
|
+
yield {
|
|
75
|
+
type: "assistant",
|
|
76
|
+
blocks: [{
|
|
77
|
+
type: "tool_result",
|
|
78
|
+
tool_use_id: event.tool_use_id,
|
|
79
|
+
content: event.content,
|
|
80
|
+
is_error: event.is_error,
|
|
81
|
+
}],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
else if (event.type === "done" && !signal?.aborted) {
|
|
85
|
+
yield {
|
|
86
|
+
type: "assistant",
|
|
87
|
+
blocks: [],
|
|
88
|
+
isFinalResponse: true,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
else if (event.type === "error") {
|
|
92
|
+
throw new Error(event.message);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
async getSessionInfo(sessionId) {
|
|
97
|
+
const normalizedSessionId = normalizeBuiltinSessionId(sessionId);
|
|
98
|
+
const info = getBuiltinContextSession(normalizedSessionId, options.contextDir);
|
|
99
|
+
if (!info)
|
|
100
|
+
return undefined;
|
|
101
|
+
return {
|
|
102
|
+
sessionId: info.sessionId,
|
|
103
|
+
cwd: info.cwd,
|
|
104
|
+
lastModified: info.updatedAt,
|
|
105
|
+
model: options.model ?? config.ccc.model,
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
async closeSession(_sessionId) {
|
|
109
|
+
// ChatSession uses one request-scoped stream per prompt. AbortSignal handles cancellation.
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|