chatccc 0.2.243 → 0.2.245

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 (65) hide show
  1. package/README.md +6 -6
  2. package/bin/cccagent.mjs +17 -17
  3. package/deepccc-agent/README.md +14 -8
  4. package/deepccc-agent/bin/deepccc.mjs +26 -26
  5. package/deepccc-agent/os-prompts/darwin.md +8 -0
  6. package/deepccc-agent/os-prompts/linux.md +8 -0
  7. package/deepccc-agent/os-prompts/win32.md +9 -0
  8. package/deepccc-agent/package-lock.json +2 -2
  9. package/deepccc-agent/package.json +63 -62
  10. package/deepccc-agent/src/__tests__/chat-session.test.ts +682 -578
  11. package/deepccc-agent/src/__tests__/cli-json.test.ts +49 -49
  12. package/deepccc-agent/src/__tests__/config.test.ts +26 -26
  13. package/deepccc-agent/src/__tests__/context.test.ts +319 -319
  14. package/deepccc-agent/src/__tests__/file-tools.test.ts +240 -240
  15. package/deepccc-agent/src/__tests__/permissions.test.ts +195 -195
  16. package/deepccc-agent/src/__tests__/privacy.test.ts +8 -5
  17. package/deepccc-agent/src/__tests__/progress-reducer.test.ts +121 -121
  18. package/deepccc-agent/src/__tests__/session-search.test.ts +262 -262
  19. package/deepccc-agent/src/__tests__/session-select.test.ts +116 -116
  20. package/deepccc-agent/src/__tests__/sigint.test.ts +56 -56
  21. package/deepccc-agent/src/__tests__/skills.test.ts +284 -284
  22. package/deepccc-agent/src/__tests__/terminal-renderer.test.ts +247 -247
  23. package/deepccc-agent/src/__tests__/web-tools.test.ts +220 -220
  24. package/deepccc-agent/src/cli.ts +7 -6
  25. package/deepccc-agent/src/config.ts +88 -84
  26. package/deepccc-agent/src/context.ts +465 -465
  27. package/deepccc-agent/src/file-log.ts +38 -38
  28. package/deepccc-agent/src/index.ts +103 -36
  29. package/deepccc-agent/src/proc-tree-kill.ts +61 -61
  30. package/deepccc-agent/src/progress/cards-helpers.ts +76 -76
  31. package/deepccc-agent/src/progress/reducer.ts +113 -113
  32. package/deepccc-agent/src/progress/terminal-renderer.ts +294 -294
  33. package/deepccc-agent/src/progress/view.ts +77 -77
  34. package/deepccc-agent/src/raw-stream-log.ts +124 -124
  35. package/deepccc-agent/src/session-search.ts +370 -370
  36. package/deepccc-agent/src/session-select.ts +48 -48
  37. package/deepccc-agent/src/sigint.ts +50 -50
  38. package/deepccc-agent/src/skills.ts +205 -205
  39. package/deepccc-agent/src/web-tools.ts +313 -313
  40. package/deepccc-agent/tsconfig.build.json +13 -13
  41. package/deepccc-agent/tsconfig.json +13 -13
  42. package/deepccc-agent/vitest.config.ts +7 -7
  43. package/package.json +1 -1
  44. package/src/__tests__/builtin-chat-session.test.ts +522 -522
  45. package/src/__tests__/builtin-config.test.ts +26 -26
  46. package/src/__tests__/builtin-context.test.ts +319 -319
  47. package/src/__tests__/builtin-file-tools.test.ts +240 -240
  48. package/src/__tests__/builtin-permissions.test.ts +211 -211
  49. package/src/__tests__/builtin-session-search.test.ts +262 -262
  50. package/src/__tests__/builtin-session-select.test.ts +116 -116
  51. package/src/__tests__/builtin-sigint.test.ts +56 -56
  52. package/src/__tests__/builtin-skills.test.ts +284 -284
  53. package/src/__tests__/builtin-web-tools.test.ts +220 -220
  54. package/src/__tests__/ccc-adapter.test.ts +15 -0
  55. package/src/__tests__/config.test.ts +17 -17
  56. package/src/__tests__/progress-reducer.test.ts +121 -121
  57. package/src/__tests__/session-ccc-config.test.ts +45 -45
  58. package/src/__tests__/session.test.ts +369 -306
  59. package/src/adapters/adapter-interface.ts +8 -2
  60. package/src/adapters/ccc-adapter.ts +149 -145
  61. package/src/config-utils.ts +13 -13
  62. package/src/config.ts +13 -13
  63. package/src/progress/reducer.ts +113 -113
  64. package/src/session-chat-binding.ts +83 -83
  65. package/src/session.ts +323 -320
@@ -1,113 +1,113 @@
1
- /**
2
- * progress/reducer.ts — ChatEvent 事件流 → ProgressView 的增量合并
3
- *
4
- * 这是飞书与终端共享的唯一一份"事件 → 过程视图"公共逻辑:
5
- * 终端 REPL 直接消费 ChatSession.chat() 的事件流,逐条 reduce;
6
- * 飞书侧 display loop 若未来接入事件流,同样使用本 reducer,保证两端
7
- * 看到的过程状态(正文累积、工具调用、终态判定)完全一致。
8
- */
9
-
10
- import type { ChatEvent } from "../index.js";
11
- import {
12
- withProgressView,
13
- type ProgressToolCall,
14
- type ProgressView,
15
- } from "./view.js";
16
-
17
- /** 工具调用 input 单行摘要(终端折叠行展示用) */
18
- export function summarizeToolInput(input: unknown, maxChars = 120): string {
19
- let raw: string;
20
- if (typeof input === "string") {
21
- raw = input;
22
- } else {
23
- try {
24
- raw = JSON.stringify(input);
25
- } catch {
26
- raw = String(input);
27
- }
28
- }
29
- const oneLine = raw.replace(/\s+/g, " ").trim();
30
- return oneLine.length > maxChars ? oneLine.slice(0, maxChars) + "…" : oneLine;
31
- }
32
-
33
- /** 工具结果单行摘要(成功/失败各取首行) */
34
- export function summarizeToolResult(content: unknown, maxChars = 120): string {
35
- let raw: string;
36
- if (typeof content === "string") {
37
- raw = content;
38
- } else if (content instanceof Error) {
39
- raw = content.message;
40
- } else {
41
- try {
42
- raw = JSON.stringify(content);
43
- } catch {
44
- raw = String(content);
45
- }
46
- }
47
- const firstLine = raw.split("\n")[0] ?? "";
48
- return firstLine.length > maxChars ? firstLine.slice(0, maxChars) + "…" : firstLine;
49
- }
50
-
51
- /**
52
- * 把一条 ChatEvent 合并进 ProgressView,返回新视图(不可变更新)。
53
- * 未识别的/不影响展示的事件(如 compact)返回原视图。
54
- */
55
- export function reduceProgress(prev: ProgressView, event: ChatEvent): ProgressView {
56
- switch (event.type) {
57
- case "status":
58
- return withProgressView(prev, {
59
- headerTitle: event.phase === "compacting" ? "压缩上下文中..." : "生成回复中...",
60
- });
61
-
62
- case "text":
63
- // accumulated 是全文累积,直接全量替换,天然幂等
64
- return withProgressView(prev, { text: event.accumulated });
65
-
66
- case "tool_use": {
67
- const tool: ProgressToolCall = {
68
- id: event.id ?? `tool-${prev.tools.length + 1}`,
69
- name: event.name,
70
- status: "running",
71
- detail: summarizeToolInput(event.input),
72
- };
73
- return withProgressView(prev, { tools: [...prev.tools, tool] });
74
- }
75
-
76
- case "tool_result": {
77
- const nextStatus = event.is_error ? ("error" as const) : ("ok" as const);
78
- const summary = summarizeToolResult(event.content);
79
- let matched = false;
80
- const tools = prev.tools.map((t) => {
81
- if (matched || t.id !== event.tool_use_id) return t;
82
- matched = true;
83
- return { ...t, status: nextStatus, summary };
84
- });
85
- if (!matched) {
86
- // id 缺失或失配:兜底更新最后一个 running 工具,避免状态悬挂
87
- const lastRunning = [...prev.tools].reverse().findIndex((t) => t.status === "running");
88
- if (lastRunning >= 0) {
89
- const idx = prev.tools.length - 1 - lastRunning;
90
- const updated = prev.tools.map((t, i) =>
91
- i === idx ? { ...t, status: nextStatus, summary } : t,
92
- );
93
- return withProgressView(prev, { tools: updated });
94
- }
95
- }
96
- return withProgressView(prev, { tools });
97
- }
98
-
99
- case "done":
100
- return withProgressView(prev, {
101
- status: "done",
102
- showStop: false,
103
- text: event.text,
104
- });
105
-
106
- case "error":
107
- return withProgressView(prev, { status: "error", showStop: false });
108
-
109
- case "compact":
110
- // 旧上下文压缩不影响当前过程展示
111
- return prev;
112
- }
113
- }
1
+ /**
2
+ * progress/reducer.ts — ChatEvent 事件流 → ProgressView 的增量合并
3
+ *
4
+ * 这是飞书与终端共享的唯一一份"事件 → 过程视图"公共逻辑:
5
+ * 终端 REPL 直接消费 ChatSession.chat() 的事件流,逐条 reduce;
6
+ * 飞书侧 display loop 若未来接入事件流,同样使用本 reducer,保证两端
7
+ * 看到的过程状态(正文累积、工具调用、终态判定)完全一致。
8
+ */
9
+
10
+ import type { ChatEvent } from "../index.js";
11
+ import {
12
+ withProgressView,
13
+ type ProgressToolCall,
14
+ type ProgressView,
15
+ } from "./view.js";
16
+
17
+ /** 工具调用 input 单行摘要(终端折叠行展示用) */
18
+ export function summarizeToolInput(input: unknown, maxChars = 120): string {
19
+ let raw: string;
20
+ if (typeof input === "string") {
21
+ raw = input;
22
+ } else {
23
+ try {
24
+ raw = JSON.stringify(input);
25
+ } catch {
26
+ raw = String(input);
27
+ }
28
+ }
29
+ const oneLine = raw.replace(/\s+/g, " ").trim();
30
+ return oneLine.length > maxChars ? oneLine.slice(0, maxChars) + "…" : oneLine;
31
+ }
32
+
33
+ /** 工具结果单行摘要(成功/失败各取首行) */
34
+ export function summarizeToolResult(content: unknown, maxChars = 120): string {
35
+ let raw: string;
36
+ if (typeof content === "string") {
37
+ raw = content;
38
+ } else if (content instanceof Error) {
39
+ raw = content.message;
40
+ } else {
41
+ try {
42
+ raw = JSON.stringify(content);
43
+ } catch {
44
+ raw = String(content);
45
+ }
46
+ }
47
+ const firstLine = raw.split("\n")[0] ?? "";
48
+ return firstLine.length > maxChars ? firstLine.slice(0, maxChars) + "…" : firstLine;
49
+ }
50
+
51
+ /**
52
+ * 把一条 ChatEvent 合并进 ProgressView,返回新视图(不可变更新)。
53
+ * 未识别的/不影响展示的事件(如 compact)返回原视图。
54
+ */
55
+ export function reduceProgress(prev: ProgressView, event: ChatEvent): ProgressView {
56
+ switch (event.type) {
57
+ case "status":
58
+ return withProgressView(prev, {
59
+ headerTitle: event.phase === "compacting" ? "压缩上下文中..." : "生成回复中...",
60
+ });
61
+
62
+ case "text":
63
+ // accumulated 是全文累积,直接全量替换,天然幂等
64
+ return withProgressView(prev, { text: event.accumulated });
65
+
66
+ case "tool_use": {
67
+ const tool: ProgressToolCall = {
68
+ id: event.id ?? `tool-${prev.tools.length + 1}`,
69
+ name: event.name,
70
+ status: "running",
71
+ detail: summarizeToolInput(event.input),
72
+ };
73
+ return withProgressView(prev, { tools: [...prev.tools, tool] });
74
+ }
75
+
76
+ case "tool_result": {
77
+ const nextStatus = event.is_error ? ("error" as const) : ("ok" as const);
78
+ const summary = summarizeToolResult(event.content);
79
+ let matched = false;
80
+ const tools = prev.tools.map((t) => {
81
+ if (matched || t.id !== event.tool_use_id) return t;
82
+ matched = true;
83
+ return { ...t, status: nextStatus, summary };
84
+ });
85
+ if (!matched) {
86
+ // id 缺失或失配:兜底更新最后一个 running 工具,避免状态悬挂
87
+ const lastRunning = [...prev.tools].reverse().findIndex((t) => t.status === "running");
88
+ if (lastRunning >= 0) {
89
+ const idx = prev.tools.length - 1 - lastRunning;
90
+ const updated = prev.tools.map((t, i) =>
91
+ i === idx ? { ...t, status: nextStatus, summary } : t,
92
+ );
93
+ return withProgressView(prev, { tools: updated });
94
+ }
95
+ }
96
+ return withProgressView(prev, { tools });
97
+ }
98
+
99
+ case "done":
100
+ return withProgressView(prev, {
101
+ status: "done",
102
+ showStop: false,
103
+ text: event.text,
104
+ });
105
+
106
+ case "error":
107
+ return withProgressView(prev, { status: "error", showStop: false });
108
+
109
+ case "compact":
110
+ // 旧上下文压缩不影响当前过程展示
111
+ return prev;
112
+ }
113
+ }