chatccc 0.2.224 → 0.2.226

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 (68) hide show
  1. package/.agents/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  2. package/.claude/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  3. package/.cursor/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  4. package/README.md +90 -90
  5. package/package.json +1 -1
  6. package/src/__tests__/agent-activity.test.ts +76 -76
  7. package/src/__tests__/builtin-chat-session.test.ts +350 -350
  8. package/src/__tests__/builtin-config.test.ts +26 -37
  9. package/src/__tests__/builtin-context.test.ts +163 -163
  10. package/src/__tests__/builtin-file-tools.test.ts +275 -275
  11. package/src/__tests__/builtin-permissions.test.ts +211 -0
  12. package/src/__tests__/builtin-session-select.test.ts +116 -116
  13. package/src/__tests__/builtin-skills.test.ts +141 -141
  14. package/src/__tests__/card-action-routing.test.ts +18 -18
  15. package/src/__tests__/ccc-adapter.test.ts +136 -136
  16. package/src/__tests__/claude-adapter.test.ts +614 -614
  17. package/src/__tests__/codex-adapter.test.ts +58 -58
  18. package/src/__tests__/codex-raw-stream-log.test.ts +170 -170
  19. package/src/__tests__/cursor-adapter.test.ts +268 -268
  20. package/src/__tests__/feishu-avatar.test.ts +164 -164
  21. package/src/__tests__/feishu-message-ingress.test.ts +138 -138
  22. package/src/__tests__/package-files.test.ts +24 -24
  23. package/src/__tests__/progress-reducer.test.ts +110 -110
  24. package/src/__tests__/response-stall.test.ts +49 -49
  25. package/src/__tests__/sim-platform.test.ts +16 -16
  26. package/src/__tests__/startup-lifecycle.test.ts +231 -231
  27. package/src/__tests__/stop-session.test.ts +34 -34
  28. package/src/__tests__/terminal-renderer.test.ts +247 -143
  29. package/src/__tests__/update-command-guard.test.ts +144 -144
  30. package/src/__tests__/web-ui.test.ts +326 -323
  31. package/src/adapters/adapter-interface.ts +18 -18
  32. package/src/adapters/ccc-adapter.ts +131 -128
  33. package/src/adapters/claude-adapter.ts +620 -620
  34. package/src/adapters/codex-adapter.ts +426 -426
  35. package/src/adapters/cursor-adapter.ts +681 -681
  36. package/src/agent-activity.ts +170 -170
  37. package/src/agent-delegate-task.ts +91 -91
  38. package/src/builtin/cli.ts +598 -514
  39. package/src/builtin/config.ts +84 -0
  40. package/src/builtin/context.ts +323 -323
  41. package/src/builtin/file-log.ts +38 -0
  42. package/src/builtin/file-tools.ts +1407 -1320
  43. package/src/builtin/index.ts +437 -426
  44. package/src/builtin/permissions.ts +226 -0
  45. package/src/builtin/privacy.ts +141 -0
  46. package/src/builtin/proc-tree-kill.ts +61 -0
  47. package/src/builtin/progress/cards-helpers.ts +76 -0
  48. package/src/builtin/progress/reducer.ts +108 -0
  49. package/src/builtin/progress/terminal-renderer.ts +294 -0
  50. package/src/builtin/progress/view.ts +77 -0
  51. package/src/builtin/raw-stream-log.ts +124 -0
  52. package/src/builtin/session-select.ts +48 -48
  53. package/src/builtin/skills.ts +108 -108
  54. package/src/card-action-routing.ts +14 -14
  55. package/src/feishu-api.ts +193 -193
  56. package/src/feishu-message-ingress.ts +195 -195
  57. package/src/index.ts +306 -306
  58. package/src/orchestrator.ts +2388 -2388
  59. package/src/platform-adapter.ts +6 -6
  60. package/src/progress/reducer.ts +108 -108
  61. package/src/progress/terminal-renderer.ts +294 -190
  62. package/src/progress/view.ts +77 -77
  63. package/src/response-stall.ts +28 -28
  64. package/src/session-chat-binding.ts +82 -82
  65. package/src/startup-lifecycle.ts +250 -250
  66. package/src/stream-state.ts +18 -18
  67. package/src/update-command-guard.ts +165 -165
  68. package/src/web-ui.ts +18 -2
@@ -1,165 +1,165 @@
1
- import {
2
- existsSync,
3
- mkdirSync,
4
- readFileSync,
5
- renameSync,
6
- rmSync,
7
- writeFileSync,
8
- } from "node:fs";
9
- import { homedir } from "node:os";
10
- import { dirname, join } from "node:path";
11
-
12
- export const UPDATE_COMMAND_GUARD_FILE = join(
13
- homedir(),
14
- ".chatccc",
15
- "state",
16
- "update-command-guard.json",
17
- );
18
-
19
- const UPDATE_COMMAND_GUARD_VERSION = 1;
20
- const DEFAULT_MAX_PROCESSED_IDS = 100;
21
-
22
- interface ProcessedUpdateCommand {
23
- id: string;
24
- recordedAt: number;
25
- }
26
-
27
- interface UpdateCommandGuardState {
28
- version: 1;
29
- processed: ProcessedUpdateCommand[];
30
- }
31
-
32
- export type UpdateCommandGuardResult =
33
- | { allowed: true; reason: "accepted" | "missing_id" }
34
- | { allowed: false; reason: "duplicate_id" | "state_write_failed" };
35
-
36
- export interface AcquireUpdateCommandGuardOptions {
37
- filePath?: string;
38
- commandId?: string;
39
- now?: number;
40
- maxEntries?: number;
41
- warn?: (message: string) => void;
42
- }
43
-
44
- function asRecord(value: unknown): Record<string, unknown> | undefined {
45
- return typeof value === "object" && value !== null
46
- ? value as Record<string, unknown>
47
- : undefined;
48
- }
49
-
50
- /** 从飞书事件信封中读取重投时保持不变的 event_id。 */
51
- export function extractFeishuEventId(data: unknown): string | undefined {
52
- const envelope = asRecord(data);
53
- const event = asRecord(envelope?.event);
54
- const header = asRecord(envelope?.header) ?? asRecord(event?.header);
55
- const context = asRecord(event?.context);
56
- const candidates = [header?.event_id, envelope?.event_id, event?.event_id, context?.event_id];
57
- for (const candidate of candidates) {
58
- if (typeof candidate === "string" && candidate.trim()) return candidate.trim();
59
- }
60
- return undefined;
61
- }
62
-
63
- /** 分隔文字消息和卡片回调 ID 的命名空间。 */
64
- export function buildUpdateCommandId(
65
- source: "message" | "card",
66
- id: string | undefined,
67
- ): string | undefined {
68
- const normalized = id?.trim();
69
- return normalized ? `${source}:${normalized}` : undefined;
70
- }
71
-
72
- function emptyState(): UpdateCommandGuardState {
73
- return { version: UPDATE_COMMAND_GUARD_VERSION, processed: [] };
74
- }
75
-
76
- function parseState(raw: string, maxEntries: number): UpdateCommandGuardState {
77
- const parsed = JSON.parse(raw) as Partial<UpdateCommandGuardState>;
78
- if (parsed.version !== UPDATE_COMMAND_GUARD_VERSION || !Array.isArray(parsed.processed)) {
79
- throw new Error("invalid update command guard schema");
80
- }
81
-
82
- const processed = parsed.processed.map((entry) => {
83
- if (
84
- typeof entry !== "object"
85
- || entry === null
86
- || typeof entry.id !== "string"
87
- || entry.id.length === 0
88
- || typeof entry.recordedAt !== "number"
89
- || !Number.isFinite(entry.recordedAt)
90
- || entry.recordedAt < 0
91
- ) {
92
- throw new Error("invalid processed update command entry");
93
- }
94
- return { id: entry.id, recordedAt: entry.recordedAt };
95
- });
96
-
97
- return {
98
- version: UPDATE_COMMAND_GUARD_VERSION,
99
- processed: processed.slice(-maxEntries),
100
- };
101
- }
102
-
103
- function loadState(
104
- filePath: string,
105
- maxEntries: number,
106
- warn: (message: string) => void,
107
- ): UpdateCommandGuardState {
108
- if (!existsSync(filePath)) return emptyState();
109
- try {
110
- return parseState(readFileSync(filePath, "utf8"), maxEntries);
111
- } catch (err) {
112
- warn(`[UPDATE-GUARD] 状态文件损坏,将重建 ${filePath}: ${(err as Error).message}`);
113
- return emptyState();
114
- }
115
- }
116
-
117
- /**
118
- * 原子写入更新命令 ID。写失败时调用方必须拒绝更新:只有先落盘,
119
- * 新进程才能识别飞书在旧进程退出后重投的同一条 `/update`。
120
- */
121
- function persistState(filePath: string, state: UpdateCommandGuardState): void {
122
- mkdirSync(dirname(filePath), { recursive: true });
123
- const tempPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
124
- try {
125
- writeFileSync(tempPath, `${JSON.stringify(state, null, 2)}\n`, "utf8");
126
- renameSync(tempPath, filePath);
127
- } catch (err) {
128
- try { rmSync(tempPath, { force: true }); } catch {}
129
- throw err;
130
- }
131
- }
132
-
133
- /**
134
- * 获取 `/update` 执行资格。只比较稳定消息/事件 ID,因此用户主动发送的
135
- * 不同 `/update` 消息仍可立即执行。
136
- */
137
- export function acquireUpdateCommandGuard(
138
- options: AcquireUpdateCommandGuardOptions = {},
139
- ): UpdateCommandGuardResult {
140
- const filePath = options.filePath ?? UPDATE_COMMAND_GUARD_FILE;
141
- const commandId = options.commandId?.trim() || undefined;
142
- const now = options.now ?? Date.now();
143
- const maxEntries = Number.isInteger(options.maxEntries) && (options.maxEntries ?? 0) > 0
144
- ? options.maxEntries!
145
- : DEFAULT_MAX_PROCESSED_IDS;
146
- const warn = options.warn ?? ((message: string) => console.warn(message));
147
-
148
- // 模拟注入等没有稳定事件 ID 的入口无法做跨重启判断,保持原有行为。
149
- if (!commandId) return { allowed: true, reason: "missing_id" };
150
-
151
- const state = loadState(filePath, maxEntries, warn);
152
- if (state.processed.some((entry) => entry.id === commandId)) {
153
- return { allowed: false, reason: "duplicate_id" };
154
- }
155
-
156
- state.processed.push({ id: commandId, recordedAt: now });
157
- state.processed = state.processed.slice(-maxEntries);
158
- try {
159
- persistState(filePath, state);
160
- } catch (err) {
161
- warn(`[UPDATE-GUARD] 无法写入状态文件 ${filePath}: ${(err as Error).message}`);
162
- return { allowed: false, reason: "state_write_failed" };
163
- }
164
- return { allowed: true, reason: "accepted" };
165
- }
1
+ import {
2
+ existsSync,
3
+ mkdirSync,
4
+ readFileSync,
5
+ renameSync,
6
+ rmSync,
7
+ writeFileSync,
8
+ } from "node:fs";
9
+ import { homedir } from "node:os";
10
+ import { dirname, join } from "node:path";
11
+
12
+ export const UPDATE_COMMAND_GUARD_FILE = join(
13
+ homedir(),
14
+ ".chatccc",
15
+ "state",
16
+ "update-command-guard.json",
17
+ );
18
+
19
+ const UPDATE_COMMAND_GUARD_VERSION = 1;
20
+ const DEFAULT_MAX_PROCESSED_IDS = 100;
21
+
22
+ interface ProcessedUpdateCommand {
23
+ id: string;
24
+ recordedAt: number;
25
+ }
26
+
27
+ interface UpdateCommandGuardState {
28
+ version: 1;
29
+ processed: ProcessedUpdateCommand[];
30
+ }
31
+
32
+ export type UpdateCommandGuardResult =
33
+ | { allowed: true; reason: "accepted" | "missing_id" }
34
+ | { allowed: false; reason: "duplicate_id" | "state_write_failed" };
35
+
36
+ export interface AcquireUpdateCommandGuardOptions {
37
+ filePath?: string;
38
+ commandId?: string;
39
+ now?: number;
40
+ maxEntries?: number;
41
+ warn?: (message: string) => void;
42
+ }
43
+
44
+ function asRecord(value: unknown): Record<string, unknown> | undefined {
45
+ return typeof value === "object" && value !== null
46
+ ? value as Record<string, unknown>
47
+ : undefined;
48
+ }
49
+
50
+ /** 从飞书事件信封中读取重投时保持不变的 event_id。 */
51
+ export function extractFeishuEventId(data: unknown): string | undefined {
52
+ const envelope = asRecord(data);
53
+ const event = asRecord(envelope?.event);
54
+ const header = asRecord(envelope?.header) ?? asRecord(event?.header);
55
+ const context = asRecord(event?.context);
56
+ const candidates = [header?.event_id, envelope?.event_id, event?.event_id, context?.event_id];
57
+ for (const candidate of candidates) {
58
+ if (typeof candidate === "string" && candidate.trim()) return candidate.trim();
59
+ }
60
+ return undefined;
61
+ }
62
+
63
+ /** 分隔文字消息和卡片回调 ID 的命名空间。 */
64
+ export function buildUpdateCommandId(
65
+ source: "message" | "card",
66
+ id: string | undefined,
67
+ ): string | undefined {
68
+ const normalized = id?.trim();
69
+ return normalized ? `${source}:${normalized}` : undefined;
70
+ }
71
+
72
+ function emptyState(): UpdateCommandGuardState {
73
+ return { version: UPDATE_COMMAND_GUARD_VERSION, processed: [] };
74
+ }
75
+
76
+ function parseState(raw: string, maxEntries: number): UpdateCommandGuardState {
77
+ const parsed = JSON.parse(raw) as Partial<UpdateCommandGuardState>;
78
+ if (parsed.version !== UPDATE_COMMAND_GUARD_VERSION || !Array.isArray(parsed.processed)) {
79
+ throw new Error("invalid update command guard schema");
80
+ }
81
+
82
+ const processed = parsed.processed.map((entry) => {
83
+ if (
84
+ typeof entry !== "object"
85
+ || entry === null
86
+ || typeof entry.id !== "string"
87
+ || entry.id.length === 0
88
+ || typeof entry.recordedAt !== "number"
89
+ || !Number.isFinite(entry.recordedAt)
90
+ || entry.recordedAt < 0
91
+ ) {
92
+ throw new Error("invalid processed update command entry");
93
+ }
94
+ return { id: entry.id, recordedAt: entry.recordedAt };
95
+ });
96
+
97
+ return {
98
+ version: UPDATE_COMMAND_GUARD_VERSION,
99
+ processed: processed.slice(-maxEntries),
100
+ };
101
+ }
102
+
103
+ function loadState(
104
+ filePath: string,
105
+ maxEntries: number,
106
+ warn: (message: string) => void,
107
+ ): UpdateCommandGuardState {
108
+ if (!existsSync(filePath)) return emptyState();
109
+ try {
110
+ return parseState(readFileSync(filePath, "utf8"), maxEntries);
111
+ } catch (err) {
112
+ warn(`[UPDATE-GUARD] 状态文件损坏,将重建 ${filePath}: ${(err as Error).message}`);
113
+ return emptyState();
114
+ }
115
+ }
116
+
117
+ /**
118
+ * 原子写入更新命令 ID。写失败时调用方必须拒绝更新:只有先落盘,
119
+ * 新进程才能识别飞书在旧进程退出后重投的同一条 `/update`。
120
+ */
121
+ function persistState(filePath: string, state: UpdateCommandGuardState): void {
122
+ mkdirSync(dirname(filePath), { recursive: true });
123
+ const tempPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
124
+ try {
125
+ writeFileSync(tempPath, `${JSON.stringify(state, null, 2)}\n`, "utf8");
126
+ renameSync(tempPath, filePath);
127
+ } catch (err) {
128
+ try { rmSync(tempPath, { force: true }); } catch {}
129
+ throw err;
130
+ }
131
+ }
132
+
133
+ /**
134
+ * 获取 `/update` 执行资格。只比较稳定消息/事件 ID,因此用户主动发送的
135
+ * 不同 `/update` 消息仍可立即执行。
136
+ */
137
+ export function acquireUpdateCommandGuard(
138
+ options: AcquireUpdateCommandGuardOptions = {},
139
+ ): UpdateCommandGuardResult {
140
+ const filePath = options.filePath ?? UPDATE_COMMAND_GUARD_FILE;
141
+ const commandId = options.commandId?.trim() || undefined;
142
+ const now = options.now ?? Date.now();
143
+ const maxEntries = Number.isInteger(options.maxEntries) && (options.maxEntries ?? 0) > 0
144
+ ? options.maxEntries!
145
+ : DEFAULT_MAX_PROCESSED_IDS;
146
+ const warn = options.warn ?? ((message: string) => console.warn(message));
147
+
148
+ // 模拟注入等没有稳定事件 ID 的入口无法做跨重启判断,保持原有行为。
149
+ if (!commandId) return { allowed: true, reason: "missing_id" };
150
+
151
+ const state = loadState(filePath, maxEntries, warn);
152
+ if (state.processed.some((entry) => entry.id === commandId)) {
153
+ return { allowed: false, reason: "duplicate_id" };
154
+ }
155
+
156
+ state.processed.push({ id: commandId, recordedAt: now });
157
+ state.processed = state.processed.slice(-maxEntries);
158
+ try {
159
+ persistState(filePath, state);
160
+ } catch (err) {
161
+ warn(`[UPDATE-GUARD] 无法写入状态文件 ${filePath}: ${(err as Error).message}`);
162
+ return { allowed: false, reason: "state_write_failed" };
163
+ }
164
+ return { allowed: true, reason: "accepted" };
165
+ }
package/src/web-ui.ts CHANGED
@@ -1004,6 +1004,19 @@ header .badge{font-size:13px;padding:4px 12px;border-radius:12px;font-weight:500
1004
1004
  <label>备选模型(选填)</label>
1005
1005
  <input type="text" id="field-CHATCCC_CCC_ALTERNATIVE_MODEL" placeholder="加入 /model 列表,便于会话内切换">
1006
1006
  </div>
1007
+ <div class="form-group">
1008
+ <label>Effort(推理强度,选填)</label>
1009
+ <select id="field-CHATCCC_CCC_EFFORT">
1010
+ <option value="">(留空/默认,服务端 medium)</option>
1011
+ <option value="none">none - 直接作答,最省 token</option>
1012
+ <option value="minimal">minimal</option>
1013
+ <option value="low">low</option>
1014
+ <option value="medium">medium</option>
1015
+ <option value="high">high</option>
1016
+ <option value="xhigh">xhigh</option>
1017
+ <option value="max">max - 最强推理</option>
1018
+ </select>
1019
+ </div>
1007
1020
  </fieldset>
1008
1021
  </div>
1009
1022
 
@@ -1196,7 +1209,7 @@ const AGENT_FIELDS = {
1196
1209
  claude: ['CHATCCC_ANTHROPIC_MODEL','CHATCCC_ANTHROPIC_SUBAGENT_MODEL','CHATCCC_ANTHROPIC_EFFORT','CHATCCC_ANTHROPIC_API_KEY','CHATCCC_ANTHROPIC_BASE_URL','CHATCCC_ANTHROPIC_MAX_TURN'],
1197
1210
  cursor: ['CHATCCC_CURSOR_PATH','CHATCCC_CURSOR_MODEL','CHATCCC_CURSOR_ALTERNATIVE_MODEL','CHATCCC_CURSOR_AVATAR_BATTERY_MODE','CHATCCC_CURSOR_ON_DEMAND_MONTHLY_BUDGET'],
1198
1211
  codex: ['CHATCCC_CODEX_PATH','CHATCCC_CODEX_MODEL','CHATCCC_CODEX_ALTERNATIVE_MODEL','CHATCCC_CODEX_EFFORT','CHATCCC_CODEX_FAST_MODE'],
1199
- ccc: ['CHATCCC_CCC_API_KEY','CHATCCC_CCC_BASE_URL','CHATCCC_CCC_MODEL','CHATCCC_CCC_ALTERNATIVE_MODEL']
1212
+ ccc: ['CHATCCC_CCC_API_KEY','CHATCCC_CCC_BASE_URL','CHATCCC_CCC_MODEL','CHATCCC_CCC_ALTERNATIVE_MODEL','CHATCCC_CCC_EFFORT']
1200
1213
  };
1201
1214
  const FEISHU_FIELDS = ['CHATCCC_APP_ID','CHATCCC_APP_SECRET'];
1202
1215
  const WEB_UI_FIELDS = ['CHATCCC_WEB_UI_OPEN_ON_START'];
@@ -1531,6 +1544,7 @@ function renderStep2() {
1531
1544
  prefillNested('field-CHATCCC_CCC_BASE_URL', c.ccc.DEEPSEEK_BASE_URL);
1532
1545
  prefillNested('field-CHATCCC_CCC_MODEL', c.ccc.model);
1533
1546
  prefillNested('field-CHATCCC_CCC_ALTERNATIVE_MODEL', c.ccc.alternativeModel);
1547
+ prefillNested('field-CHATCCC_CCC_EFFORT', c.ccc.effort);
1534
1548
  }
1535
1549
 
1536
1550
  // 按已有 config 决定每个 Agent 默认是否开启:优先 enabled 字段,缺省时按"任一字段非空"
@@ -1706,6 +1720,7 @@ function renderStep3() {
1706
1720
  lines.push('<div class="config-row"><span class="key">Base URL</span><span class="val">' + (vars.CHATCCC_CCC_BASE_URL || '(留空)') + '</span></div>');
1707
1721
  lines.push('<div class="config-row"><span class="key">模型</span><span class="val">' + (vars.CHATCCC_CCC_MODEL || '(留空)') + '</span></div>');
1708
1722
  lines.push('<div class="config-row"><span class="key">备选模型</span><span class="val">' + (vars.CHATCCC_CCC_ALTERNATIVE_MODEL || '(留空)') + '</span></div>');
1723
+ lines.push('<div class="config-row"><span class="key">Effort</span><span class="val">' + (vars.CHATCCC_CCC_EFFORT || '(留空)') + '</span></div>');
1709
1724
  }
1710
1725
  });
1711
1726
  document.getElementById('review-content').innerHTML = lines.join('');
@@ -1999,7 +2014,7 @@ function editSection(section) {
1999
2014
  'CHATCCC_CODEX_PATH': 'CLI 路径', 'CHATCCC_CODEX_MODEL': '模型', 'CHATCCC_CODEX_ALTERNATIVE_MODEL': '备选模型', 'CHATCCC_CODEX_EFFORT': 'Effort',
2000
2015
  'CHATCCC_CODEX_FAST_MODE': 'Fast 模式',
2001
2016
  'CHATCCC_CCC_API_KEY': 'API Key', 'CHATCCC_CCC_BASE_URL': 'Base URL',
2002
- 'CHATCCC_CCC_MODEL': '模型', 'CHATCCC_CCC_ALTERNATIVE_MODEL': '备选模型'
2017
+ 'CHATCCC_CCC_MODEL': '模型', 'CHATCCC_CCC_ALTERNATIVE_MODEL': '备选模型', 'CHATCCC_CCC_EFFORT': 'Effort'
2003
2018
  };
2004
2019
  var hintMap = {
2005
2020
  'CHATCCC_WEB_UI_OPEN_ON_START': '关闭后可继续手动访问 http://localhost:<端口>/;/restart、/update 和 Web UI 重启无论此项为何值都不会自动打开。',
@@ -2049,6 +2064,7 @@ function editSection(section) {
2049
2064
  else if (key === 'CHATCCC_CCC_BASE_URL') val = state.config.ccc.DEEPSEEK_BASE_URL || '';
2050
2065
  else if (key === 'CHATCCC_CCC_MODEL') val = state.config.ccc.model || '';
2051
2066
  else if (key === 'CHATCCC_CCC_ALTERNATIVE_MODEL') val = state.config.ccc.alternativeModel || '';
2067
+ else if (key === 'CHATCCC_CCC_EFFORT') val = state.config.ccc.effort || '';
2052
2068
  }
2053
2069
  }
2054
2070
  var isSecret = key.includes('SECRET') || key.includes('API_KEY');