chatccc 0.2.243 → 0.2.244

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 (59) hide show
  1. package/README.md +5 -5
  2. package/bin/cccagent.mjs +17 -17
  3. package/deepccc-agent/bin/deepccc.mjs +26 -26
  4. package/deepccc-agent/os-prompts/darwin.md +8 -0
  5. package/deepccc-agent/os-prompts/linux.md +8 -0
  6. package/deepccc-agent/os-prompts/win32.md +9 -0
  7. package/deepccc-agent/package.json +2 -1
  8. package/deepccc-agent/src/__tests__/chat-session.test.ts +39 -0
  9. package/deepccc-agent/src/__tests__/cli-json.test.ts +49 -49
  10. package/deepccc-agent/src/__tests__/config.test.ts +26 -26
  11. package/deepccc-agent/src/__tests__/context.test.ts +319 -319
  12. package/deepccc-agent/src/__tests__/file-tools.test.ts +240 -240
  13. package/deepccc-agent/src/__tests__/permissions.test.ts +195 -195
  14. package/deepccc-agent/src/__tests__/progress-reducer.test.ts +121 -121
  15. package/deepccc-agent/src/__tests__/session-search.test.ts +262 -262
  16. package/deepccc-agent/src/__tests__/session-select.test.ts +116 -116
  17. package/deepccc-agent/src/__tests__/sigint.test.ts +56 -56
  18. package/deepccc-agent/src/__tests__/skills.test.ts +284 -284
  19. package/deepccc-agent/src/__tests__/terminal-renderer.test.ts +247 -247
  20. package/deepccc-agent/src/__tests__/web-tools.test.ts +220 -220
  21. package/deepccc-agent/src/config.ts +84 -84
  22. package/deepccc-agent/src/context.ts +465 -465
  23. package/deepccc-agent/src/file-log.ts +38 -38
  24. package/deepccc-agent/src/index.ts +46 -16
  25. package/deepccc-agent/src/proc-tree-kill.ts +61 -61
  26. package/deepccc-agent/src/progress/cards-helpers.ts +76 -76
  27. package/deepccc-agent/src/progress/reducer.ts +113 -113
  28. package/deepccc-agent/src/progress/terminal-renderer.ts +294 -294
  29. package/deepccc-agent/src/progress/view.ts +77 -77
  30. package/deepccc-agent/src/raw-stream-log.ts +124 -124
  31. package/deepccc-agent/src/session-search.ts +370 -370
  32. package/deepccc-agent/src/session-select.ts +48 -48
  33. package/deepccc-agent/src/sigint.ts +50 -50
  34. package/deepccc-agent/src/skills.ts +205 -205
  35. package/deepccc-agent/src/web-tools.ts +313 -313
  36. package/deepccc-agent/tsconfig.build.json +13 -13
  37. package/deepccc-agent/tsconfig.json +13 -13
  38. package/deepccc-agent/vitest.config.ts +7 -7
  39. package/package.json +73 -73
  40. package/src/__tests__/builtin-chat-session.test.ts +522 -522
  41. package/src/__tests__/builtin-config.test.ts +26 -26
  42. package/src/__tests__/builtin-context.test.ts +319 -319
  43. package/src/__tests__/builtin-file-tools.test.ts +240 -240
  44. package/src/__tests__/builtin-permissions.test.ts +211 -211
  45. package/src/__tests__/builtin-session-search.test.ts +262 -262
  46. package/src/__tests__/builtin-session-select.test.ts +116 -116
  47. package/src/__tests__/builtin-sigint.test.ts +56 -56
  48. package/src/__tests__/builtin-skills.test.ts +284 -284
  49. package/src/__tests__/builtin-web-tools.test.ts +220 -220
  50. package/src/__tests__/config.test.ts +17 -17
  51. package/src/__tests__/progress-reducer.test.ts +121 -121
  52. package/src/__tests__/session-ccc-config.test.ts +45 -45
  53. package/src/__tests__/session.test.ts +298 -298
  54. package/src/adapters/ccc-adapter.ts +145 -145
  55. package/src/config-utils.ts +13 -13
  56. package/src/config.ts +13 -13
  57. package/src/progress/reducer.ts +113 -113
  58. package/src/session-chat-binding.ts +83 -83
  59. package/src/session.ts +311 -311
@@ -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
+ }