skyloom 1.12.0 → 1.13.1

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 (137) hide show
  1. package/.github/workflows/ci.yml +36 -36
  2. package/README.md +137 -46
  3. package/config/default.yaml +43 -47
  4. package/config/models.yaml +155 -155
  5. package/config/providers.yaml +39 -39
  6. package/config/skills/api_integrator/SKILL.md +15 -15
  7. package/config/skills/arch_designer/SKILL.md +13 -13
  8. package/config/skills/ci_cd_manager/SKILL.md +14 -14
  9. package/config/skills/code_analysis/SKILL.md +13 -13
  10. package/config/skills/code_generator/SKILL.md +12 -12
  11. package/config/skills/code_reviewer/SKILL.md +13 -13
  12. package/config/skills/content_writer/SKILL.md +14 -14
  13. package/config/skills/data_transformer/SKILL.md +15 -15
  14. package/config/skills/document_analysis/SKILL.md +13 -13
  15. package/config/skills/emotional_companion/SKILL.md +15 -15
  16. package/config/skills/performance_checker/SKILL.md +14 -14
  17. package/config/skills/security_auditor/SKILL.md +14 -14
  18. package/config/skills/self_evolve/SKILL.md +13 -13
  19. package/config/skills/sys_operator/SKILL.md +15 -15
  20. package/config/skills/task_planner/SKILL.md +14 -14
  21. package/config/skills/web_research/SKILL.md +14 -14
  22. package/config/skills/workflow_designer/SKILL.md +13 -13
  23. package/dist/agents/dew.js +52 -52
  24. package/dist/agents/fair.js +84 -84
  25. package/dist/agents/fog.js +30 -30
  26. package/dist/agents/frost.js +32 -32
  27. package/dist/agents/rain.js +32 -32
  28. package/dist/agents/snow.js +68 -68
  29. package/dist/cli/main.js +127 -74
  30. package/dist/cli/main.js.map +1 -1
  31. package/dist/cli/tui.d.ts +52 -19
  32. package/dist/cli/tui.d.ts.map +1 -1
  33. package/dist/cli/tui.js +198 -265
  34. package/dist/cli/tui.js.map +1 -1
  35. package/dist/core/agent/task.d.ts +58 -0
  36. package/dist/core/agent/task.d.ts.map +1 -0
  37. package/dist/core/agent/task.js +83 -0
  38. package/dist/core/agent/task.js.map +1 -0
  39. package/dist/core/agent.d.ts +2 -45
  40. package/dist/core/agent.d.ts.map +1 -1
  41. package/dist/core/agent.js +61 -145
  42. package/dist/core/agent.js.map +1 -1
  43. package/dist/core/agent_helpers.d.ts +10 -0
  44. package/dist/core/agent_helpers.d.ts.map +1 -1
  45. package/dist/core/agent_helpers.js +39 -0
  46. package/dist/core/agent_helpers.js.map +1 -1
  47. package/dist/core/catalog.d.ts +71 -0
  48. package/dist/core/catalog.d.ts.map +1 -0
  49. package/dist/core/catalog.js +176 -0
  50. package/dist/core/catalog.js.map +1 -0
  51. package/dist/core/config.d.ts +8 -0
  52. package/dist/core/config.d.ts.map +1 -1
  53. package/dist/core/config.js +12 -4
  54. package/dist/core/config.js.map +1 -1
  55. package/dist/core/factory.js +16 -16
  56. package/dist/core/llm.d.ts +7 -0
  57. package/dist/core/llm.d.ts.map +1 -1
  58. package/dist/core/llm.js +139 -7
  59. package/dist/core/llm.js.map +1 -1
  60. package/dist/core/longdoc.js +5 -5
  61. package/dist/core/memory.d.ts.map +1 -1
  62. package/dist/core/memory.js +69 -62
  63. package/dist/core/memory.js.map +1 -1
  64. package/dist/core/theme.d.ts +46 -0
  65. package/dist/core/theme.d.ts.map +1 -0
  66. package/dist/core/theme.js +42 -0
  67. package/dist/core/theme.js.map +1 -0
  68. package/dist/web/server.js +542 -519
  69. package/dist/web/server.js.map +1 -1
  70. package/docs/AESTHETIC_DESIGN.md +144 -0
  71. package/docs/OPTIMIZATION_PLAN.md +178 -0
  72. package/package.json +60 -60
  73. package/scripts/install.js +48 -48
  74. package/scripts/link.js +10 -10
  75. package/setup.bat +79 -79
  76. package/skill-test-ty2fOA/test.md +10 -10
  77. package/src/agents/dew.ts +70 -70
  78. package/src/agents/fair.ts +102 -102
  79. package/src/agents/fog.ts +48 -48
  80. package/src/agents/frost.ts +50 -50
  81. package/src/agents/rain.ts +50 -50
  82. package/src/agents/snow.ts +239 -239
  83. package/src/cli/main.ts +417 -372
  84. package/src/cli/mode.ts +58 -58
  85. package/src/cli/tui.ts +174 -223
  86. package/src/core/agent/task.ts +100 -0
  87. package/src/core/agent.ts +1446 -1549
  88. package/src/core/agent_helpers.ts +496 -461
  89. package/src/core/arbitrate.ts +162 -162
  90. package/src/core/catalog.ts +178 -0
  91. package/src/core/checkpoint.ts +94 -94
  92. package/src/core/config.ts +20 -4
  93. package/src/core/estimate.ts +104 -104
  94. package/src/core/evolve.ts +191 -191
  95. package/src/core/factory.ts +627 -627
  96. package/src/core/filter.ts +103 -103
  97. package/src/core/graph.ts +156 -156
  98. package/src/core/icons.ts +53 -53
  99. package/src/core/index.ts +37 -37
  100. package/src/core/learn.ts +146 -146
  101. package/src/core/llm.ts +108 -5
  102. package/src/core/longdoc.ts +155 -155
  103. package/src/core/mcp_server.ts +176 -176
  104. package/src/core/memory.ts +1178 -1171
  105. package/src/core/profile.ts +255 -255
  106. package/src/core/router.ts +124 -124
  107. package/src/core/sandbox.ts +142 -142
  108. package/src/core/security.ts +243 -243
  109. package/src/core/skill.ts +342 -342
  110. package/src/core/theme.ts +65 -0
  111. package/src/core/tool_router.ts +193 -193
  112. package/src/core/vector.ts +152 -152
  113. package/src/core/workspace.ts +150 -150
  114. package/src/plugins/loader.ts +66 -66
  115. package/src/skills/loader.ts +46 -46
  116. package/src/sql.js.d.ts +29 -29
  117. package/src/tools/builtin.ts +380 -380
  118. package/src/tools/computer.ts +269 -269
  119. package/src/tools/delegate.ts +49 -49
  120. package/src/web/server.ts +660 -634
  121. package/src/web/tts.ts +93 -93
  122. package/tests/agent_helpers.test.ts +48 -0
  123. package/tests/bus.test.ts +121 -121
  124. package/tests/catalog.test.ts +86 -0
  125. package/tests/config.test.ts +41 -0
  126. package/tests/icons.test.ts +45 -45
  127. package/tests/memory.test.ts +147 -0
  128. package/tests/router.test.ts +86 -86
  129. package/tests/schemas.test.ts +51 -51
  130. package/tests/semantic.test.ts +83 -83
  131. package/tests/setup.ts +10 -10
  132. package/tests/skill.test.ts +172 -172
  133. package/tests/task.test.ts +60 -0
  134. package/tests/tool.test.ts +108 -108
  135. package/tests/tool_router.test.ts +71 -71
  136. package/tests/tui.test.ts +67 -0
  137. package/vitest.config.ts +17 -17
@@ -1,191 +1,191 @@
1
- /**
2
- * 自我进化模块 — Prompt self-optimization via failure analysis.
3
- *
4
- * When an agent repeatedly fails at similar tasks, this module analyzes
5
- * the failure patterns and suggests targeted improvements to the agent's
6
- * System Prompt. The agent can then apply these suggestions to improve
7
- * future performance.
8
- *
9
- * Architecture:
10
- * Failure log → Pattern analysis → Prompt diff → Agent.applyDiff()
11
- */
12
-
13
- import * as fs from "fs";
14
- import * as path from "path";
15
- import { USER_CONFIG_DIR } from "./config";
16
- import { getLogger } from "./logger";
17
-
18
- const log = getLogger("evolve");
19
-
20
- /* ═══════════════════════════════════════
21
- Prompt diff — a suggested change
22
- ═══════════════════════════════════════ */
23
- export interface PromptDiff {
24
- id: string;
25
- ts: string;
26
- agent: string;
27
- reason: string; // Why this change is needed
28
- before: string; // Old prompt fragment
29
- after: string; // New prompt fragment
30
- applied: boolean;
31
- improvement?: string; // Measured improvement after applying
32
- }
33
-
34
- /* ═══════════════════════════════════════
35
- Failure analysis
36
- ═══════════════════════════════════════ */
37
- export interface FailureAnalysis {
38
- agent: string;
39
- period: string;
40
- totalCalls: number;
41
- failureCount: number;
42
- topFailures: Array<{ pattern: string; count: number }>;
43
- suggestedDiffs: PromptDiff[];
44
- }
45
-
46
- const evolveDir = path.join(USER_CONFIG_DIR, "evolve");
47
- function ensureDir() { if (!fs.existsSync(evolveDir)) fs.mkdirSync(evolveDir, { recursive: true }); }
48
-
49
- /** Analyze recent failures from the learning module and suggest prompt improvements. */
50
- export function analyzeFailures(
51
- agent: string,
52
- experiences: Array<{ pattern: string; solution: string; frequency: number; lastSeen: string }>,
53
- systemPrompt: string
54
- ): FailureAnalysis {
55
- const recent = experiences.filter(e => {
56
- try { return new Date(e.lastSeen).getTime() > Date.now() - 7 * 86400000; }
57
- catch { return false; }
58
- });
59
-
60
- const topFailures = recent
61
- .sort((a, b) => b.frequency - a.frequency)
62
- .slice(0, 5)
63
- .map(e => ({ pattern: e.pattern, count: e.frequency }));
64
-
65
- const suggestedDiffs: PromptDiff[] = [];
66
-
67
- // Rule-based suggestions from failure patterns
68
- for (const f of topFailures) {
69
- const lower = f.pattern.toLowerCase();
70
-
71
- // Search storm → add search budget rule
72
- if ((lower.includes("search") || lower.includes("web_search")) && f.count >= 3) {
73
- const rule = `- 搜索不超过 5 轮。5 轮后直接基于已有信息综合回答。`;
74
- if (!systemPrompt.includes("搜索不超过")) {
75
- suggestedDiffs.push({
76
- id: Math.random().toString(36).slice(2, 8),
77
- ts: new Date().toISOString(), agent,
78
- reason: `搜索风暴 (${f.count} 次重复搜索)`,
79
- before: "", after: rule, applied: false,
80
- });
81
- }
82
- }
83
-
84
- // Empty response → add deliverable checklist
85
- if ((lower.includes("empty") || lower.includes("placeholder") || lower.includes("完成了")) && f.count >= 2) {
86
- const rule = `- 完成任务后,必须输出实际产物(代码/文件路径/数据),禁止只说"完成了"而无产出。`;
87
- if (!systemPrompt.includes("必须输出实际产物")) {
88
- suggestedDiffs.push({
89
- id: Math.random().toString(36).slice(2, 8),
90
- ts: new Date().toISOString(), agent,
91
- reason: `空响应/占位 (${f.count} 次)`,
92
- before: "", after: rule, applied: false,
93
- });
94
- }
95
- }
96
-
97
- // Tool not found → add tool discovery to prompt
98
- if (lower.includes("does not exist") || lower.includes("tool") && lower.includes("not found")) {
99
- const rule = `- 使用不熟悉的工具前先调 list_skills 查看可用工具列表。`;
100
- if (!systemPrompt.includes("list_skills")) {
101
- suggestedDiffs.push({
102
- id: Math.random().toString(36).slice(2, 8),
103
- ts: new Date().toISOString(), agent,
104
- reason: `工具不存在 (${f.count} 次)`,
105
- before: "", after: rule, applied: false,
106
- });
107
- }
108
- }
109
-
110
- // File not found → add path verification rule
111
- if (lower.includes("file not found") || lower.includes("directory not found")) {
112
- const rule = `- 文件操作前先用 list_directory 或 read_file 确认路径存在。`;
113
- if (!systemPrompt.includes("确认路径存在")) {
114
- suggestedDiffs.push({
115
- id: Math.random().toString(36).slice(2, 8),
116
- ts: new Date().toISOString(), agent,
117
- reason: `文件路径错误 (${f.count} 次)`,
118
- before: "", after: rule, applied: false,
119
- });
120
- }
121
- }
122
- }
123
-
124
- // General rule: if failure rate > 20%, suggest self-review
125
- const recentExperiences = recent.filter(e => {
126
- try { return new Date(e.lastSeen).getTime() > Date.now() - 3 * 86400000; }
127
- catch { return false; }
128
- });
129
-
130
- // Deduplicate suggestions
131
- const seen = new Set<string>();
132
- const uniqueDiffs = suggestedDiffs.filter(d => {
133
- const key = d.after.slice(0, 30);
134
- if (seen.has(key)) return false;
135
- seen.add(key); return true;
136
- });
137
-
138
- // Max 3 suggestions per analysis
139
- return {
140
- agent, period: "last 7 days",
141
- totalCalls: 0, failureCount: 0,
142
- topFailures,
143
- suggestedDiffs: uniqueDiffs.slice(0, 3),
144
- };
145
- }
146
-
147
- /* ═══════════════════════════════════════
148
- Apply prompt diff to agent
149
- ═══════════════════════════════════════ */
150
- export function applyPromptDiff(agent: any, diff: PromptDiff): boolean {
151
- try {
152
- const currentPrompt = agent.systemPrompt;
153
- if (!diff.after || currentPrompt.includes(diff.after.slice(0, 20))) return false;
154
-
155
- // Append the new rule after "## 行为守则" or "## Behavior" section
156
- const marker = currentPrompt.includes("行为守则") ? "## 行为守则" : "## Behavior";
157
- const idx = currentPrompt.indexOf(marker);
158
- if (idx < 0) { agent.systemPrompt += "\n" + diff.after; }
159
- else {
160
- const insertPoint = currentPrompt.indexOf("\n", currentPrompt.indexOf("\n-", idx) + 1);
161
- agent.systemPrompt = currentPrompt.slice(0, insertPoint) + "\n" + diff.after + "\n" + currentPrompt.slice(insertPoint);
162
- }
163
-
164
- diff.applied = true;
165
- diff.improvement = "pending evaluation";
166
-
167
- // Persist the diff
168
- ensureDir();
169
- const file = path.join(evolveDir, `${diff.agent}_diffs.jsonl`);
170
- fs.appendFileSync(file, JSON.stringify(diff) + "\n");
171
-
172
- agent.rebuildSystemPrompt();
173
- return true;
174
- } catch (e) {
175
- log.warn("apply_prompt_diff_failed", { agent: diff.agent, error: String(e) });
176
- return false;
177
- }
178
- }
179
-
180
- /** Get all applied diffs for an agent. */
181
- export function getAppliedDiffs(agent: string): PromptDiff[] {
182
- const diffs: PromptDiff[] = [];
183
- try {
184
- const file = path.join(evolveDir, `${agent}_diffs.jsonl`);
185
- if (fs.existsSync(file)) {
186
- const lines = fs.readFileSync(file, "utf-8").split("\n").filter(Boolean);
187
- for (const line of lines) { try { diffs.push(JSON.parse(line)); } catch { } }
188
- }
189
- } catch { /* ignore */ }
190
- return diffs;
191
- }
1
+ /**
2
+ * 自我进化模块 — Prompt self-optimization via failure analysis.
3
+ *
4
+ * When an agent repeatedly fails at similar tasks, this module analyzes
5
+ * the failure patterns and suggests targeted improvements to the agent's
6
+ * System Prompt. The agent can then apply these suggestions to improve
7
+ * future performance.
8
+ *
9
+ * Architecture:
10
+ * Failure log → Pattern analysis → Prompt diff → Agent.applyDiff()
11
+ */
12
+
13
+ import * as fs from "fs";
14
+ import * as path from "path";
15
+ import { USER_CONFIG_DIR } from "./config";
16
+ import { getLogger } from "./logger";
17
+
18
+ const log = getLogger("evolve");
19
+
20
+ /* ═══════════════════════════════════════
21
+ Prompt diff — a suggested change
22
+ ═══════════════════════════════════════ */
23
+ export interface PromptDiff {
24
+ id: string;
25
+ ts: string;
26
+ agent: string;
27
+ reason: string; // Why this change is needed
28
+ before: string; // Old prompt fragment
29
+ after: string; // New prompt fragment
30
+ applied: boolean;
31
+ improvement?: string; // Measured improvement after applying
32
+ }
33
+
34
+ /* ═══════════════════════════════════════
35
+ Failure analysis
36
+ ═══════════════════════════════════════ */
37
+ export interface FailureAnalysis {
38
+ agent: string;
39
+ period: string;
40
+ totalCalls: number;
41
+ failureCount: number;
42
+ topFailures: Array<{ pattern: string; count: number }>;
43
+ suggestedDiffs: PromptDiff[];
44
+ }
45
+
46
+ const evolveDir = path.join(USER_CONFIG_DIR, "evolve");
47
+ function ensureDir() { if (!fs.existsSync(evolveDir)) fs.mkdirSync(evolveDir, { recursive: true }); }
48
+
49
+ /** Analyze recent failures from the learning module and suggest prompt improvements. */
50
+ export function analyzeFailures(
51
+ agent: string,
52
+ experiences: Array<{ pattern: string; solution: string; frequency: number; lastSeen: string }>,
53
+ systemPrompt: string
54
+ ): FailureAnalysis {
55
+ const recent = experiences.filter(e => {
56
+ try { return new Date(e.lastSeen).getTime() > Date.now() - 7 * 86400000; }
57
+ catch { return false; }
58
+ });
59
+
60
+ const topFailures = recent
61
+ .sort((a, b) => b.frequency - a.frequency)
62
+ .slice(0, 5)
63
+ .map(e => ({ pattern: e.pattern, count: e.frequency }));
64
+
65
+ const suggestedDiffs: PromptDiff[] = [];
66
+
67
+ // Rule-based suggestions from failure patterns
68
+ for (const f of topFailures) {
69
+ const lower = f.pattern.toLowerCase();
70
+
71
+ // Search storm → add search budget rule
72
+ if ((lower.includes("search") || lower.includes("web_search")) && f.count >= 3) {
73
+ const rule = `- 搜索不超过 5 轮。5 轮后直接基于已有信息综合回答。`;
74
+ if (!systemPrompt.includes("搜索不超过")) {
75
+ suggestedDiffs.push({
76
+ id: Math.random().toString(36).slice(2, 8),
77
+ ts: new Date().toISOString(), agent,
78
+ reason: `搜索风暴 (${f.count} 次重复搜索)`,
79
+ before: "", after: rule, applied: false,
80
+ });
81
+ }
82
+ }
83
+
84
+ // Empty response → add deliverable checklist
85
+ if ((lower.includes("empty") || lower.includes("placeholder") || lower.includes("完成了")) && f.count >= 2) {
86
+ const rule = `- 完成任务后,必须输出实际产物(代码/文件路径/数据),禁止只说"完成了"而无产出。`;
87
+ if (!systemPrompt.includes("必须输出实际产物")) {
88
+ suggestedDiffs.push({
89
+ id: Math.random().toString(36).slice(2, 8),
90
+ ts: new Date().toISOString(), agent,
91
+ reason: `空响应/占位 (${f.count} 次)`,
92
+ before: "", after: rule, applied: false,
93
+ });
94
+ }
95
+ }
96
+
97
+ // Tool not found → add tool discovery to prompt
98
+ if (lower.includes("does not exist") || lower.includes("tool") && lower.includes("not found")) {
99
+ const rule = `- 使用不熟悉的工具前先调 list_skills 查看可用工具列表。`;
100
+ if (!systemPrompt.includes("list_skills")) {
101
+ suggestedDiffs.push({
102
+ id: Math.random().toString(36).slice(2, 8),
103
+ ts: new Date().toISOString(), agent,
104
+ reason: `工具不存在 (${f.count} 次)`,
105
+ before: "", after: rule, applied: false,
106
+ });
107
+ }
108
+ }
109
+
110
+ // File not found → add path verification rule
111
+ if (lower.includes("file not found") || lower.includes("directory not found")) {
112
+ const rule = `- 文件操作前先用 list_directory 或 read_file 确认路径存在。`;
113
+ if (!systemPrompt.includes("确认路径存在")) {
114
+ suggestedDiffs.push({
115
+ id: Math.random().toString(36).slice(2, 8),
116
+ ts: new Date().toISOString(), agent,
117
+ reason: `文件路径错误 (${f.count} 次)`,
118
+ before: "", after: rule, applied: false,
119
+ });
120
+ }
121
+ }
122
+ }
123
+
124
+ // General rule: if failure rate > 20%, suggest self-review
125
+ const recentExperiences = recent.filter(e => {
126
+ try { return new Date(e.lastSeen).getTime() > Date.now() - 3 * 86400000; }
127
+ catch { return false; }
128
+ });
129
+
130
+ // Deduplicate suggestions
131
+ const seen = new Set<string>();
132
+ const uniqueDiffs = suggestedDiffs.filter(d => {
133
+ const key = d.after.slice(0, 30);
134
+ if (seen.has(key)) return false;
135
+ seen.add(key); return true;
136
+ });
137
+
138
+ // Max 3 suggestions per analysis
139
+ return {
140
+ agent, period: "last 7 days",
141
+ totalCalls: 0, failureCount: 0,
142
+ topFailures,
143
+ suggestedDiffs: uniqueDiffs.slice(0, 3),
144
+ };
145
+ }
146
+
147
+ /* ═══════════════════════════════════════
148
+ Apply prompt diff to agent
149
+ ═══════════════════════════════════════ */
150
+ export function applyPromptDiff(agent: any, diff: PromptDiff): boolean {
151
+ try {
152
+ const currentPrompt = agent.systemPrompt;
153
+ if (!diff.after || currentPrompt.includes(diff.after.slice(0, 20))) return false;
154
+
155
+ // Append the new rule after "## 行为守则" or "## Behavior" section
156
+ const marker = currentPrompt.includes("行为守则") ? "## 行为守则" : "## Behavior";
157
+ const idx = currentPrompt.indexOf(marker);
158
+ if (idx < 0) { agent.systemPrompt += "\n" + diff.after; }
159
+ else {
160
+ const insertPoint = currentPrompt.indexOf("\n", currentPrompt.indexOf("\n-", idx) + 1);
161
+ agent.systemPrompt = currentPrompt.slice(0, insertPoint) + "\n" + diff.after + "\n" + currentPrompt.slice(insertPoint);
162
+ }
163
+
164
+ diff.applied = true;
165
+ diff.improvement = "pending evaluation";
166
+
167
+ // Persist the diff
168
+ ensureDir();
169
+ const file = path.join(evolveDir, `${diff.agent}_diffs.jsonl`);
170
+ fs.appendFileSync(file, JSON.stringify(diff) + "\n");
171
+
172
+ agent.rebuildSystemPrompt();
173
+ return true;
174
+ } catch (e) {
175
+ log.warn("apply_prompt_diff_failed", { agent: diff.agent, error: String(e) });
176
+ return false;
177
+ }
178
+ }
179
+
180
+ /** Get all applied diffs for an agent. */
181
+ export function getAppliedDiffs(agent: string): PromptDiff[] {
182
+ const diffs: PromptDiff[] = [];
183
+ try {
184
+ const file = path.join(evolveDir, `${agent}_diffs.jsonl`);
185
+ if (fs.existsSync(file)) {
186
+ const lines = fs.readFileSync(file, "utf-8").split("\n").filter(Boolean);
187
+ for (const line of lines) { try { diffs.push(JSON.parse(line)); } catch { } }
188
+ }
189
+ } catch { /* ignore */ }
190
+ return diffs;
191
+ }