foliko 1.0.73 → 1.0.75

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 (237) hide show
  1. package/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
  2. package/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
  3. package/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
  4. package/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
  5. package/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
  6. package/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
  7. package/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
  8. package/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  9. package/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  10. package/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  11. package/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  12. package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  13. package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  14. package/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  15. package/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
  16. package/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  17. package/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  18. package/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  19. package/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  20. package/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
  21. package/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
  22. package/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  23. package/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  24. package/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
  25. package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-313.pyc +0 -0
  26. package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-313.pyc +0 -0
  27. package/.agent/.shared/ui-ux-pro-max/scripts/core.py +258 -0
  28. package/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +1067 -0
  29. package/.agent/.shared/ui-ux-pro-max/scripts/search.py +106 -0
  30. package/.agent/ARCHITECTURE.md +288 -0
  31. package/.agent/agents/ambient-agent.md +57 -0
  32. package/.agent/agents/debugger.md +55 -0
  33. package/.agent/agents/email-assistant.md +49 -0
  34. package/.agent/agents/file-manager.md +42 -0
  35. package/.agent/agents/python-developer.md +60 -0
  36. package/.agent/agents/scheduler.md +59 -0
  37. package/.agent/agents/web-developer.md +45 -0
  38. package/.agent/data/default.json +29 -0
  39. package/.agent/data/plugins-state.json +255 -0
  40. package/.agent/mcp_config.json +4 -0
  41. package/.agent/mcp_config_updated.json +12 -0
  42. package/.agent/plugins.json +5 -0
  43. package/.agent/rules/GEMINI.md +273 -0
  44. package/.agent/rules/allow-rule.md +77 -0
  45. package/.agent/rules/log-rule.md +83 -0
  46. package/.agent/rules/security-rule.md +93 -0
  47. package/.agent/scripts/auto_preview.py +148 -0
  48. package/.agent/scripts/checklist.py +217 -0
  49. package/.agent/scripts/session_manager.py +120 -0
  50. package/.agent/scripts/verify_all.py +327 -0
  51. package/.agent/skills/api-patterns/SKILL.md +81 -0
  52. package/.agent/skills/api-patterns/api-style.md +42 -0
  53. package/.agent/skills/api-patterns/auth.md +24 -0
  54. package/.agent/skills/api-patterns/documentation.md +26 -0
  55. package/.agent/skills/api-patterns/graphql.md +41 -0
  56. package/.agent/skills/api-patterns/rate-limiting.md +31 -0
  57. package/.agent/skills/api-patterns/response.md +37 -0
  58. package/.agent/skills/api-patterns/rest.md +40 -0
  59. package/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
  60. package/.agent/skills/api-patterns/security-testing.md +122 -0
  61. package/.agent/skills/api-patterns/trpc.md +41 -0
  62. package/.agent/skills/api-patterns/versioning.md +22 -0
  63. package/.agent/skills/app-builder/SKILL.md +75 -0
  64. package/.agent/skills/app-builder/agent-coordination.md +71 -0
  65. package/.agent/skills/app-builder/feature-building.md +53 -0
  66. package/.agent/skills/app-builder/project-detection.md +34 -0
  67. package/.agent/skills/app-builder/scaffolding.md +118 -0
  68. package/.agent/skills/app-builder/tech-stack.md +40 -0
  69. package/.agent/skills/app-builder/templates/SKILL.md +39 -0
  70. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
  71. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
  72. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
  73. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
  74. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
  75. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
  76. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
  77. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +122 -0
  78. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +122 -0
  79. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +169 -0
  80. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +134 -0
  81. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
  82. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +119 -0
  83. package/.agent/skills/architecture/SKILL.md +55 -0
  84. package/.agent/skills/architecture/context-discovery.md +43 -0
  85. package/.agent/skills/architecture/examples.md +94 -0
  86. package/.agent/skills/architecture/pattern-selection.md +68 -0
  87. package/.agent/skills/architecture/patterns-reference.md +50 -0
  88. package/.agent/skills/architecture/trade-off-analysis.md +77 -0
  89. package/.agent/skills/clean-code/SKILL.md +201 -0
  90. package/.agent/skills/doc.md +177 -0
  91. package/.agent/skills/frontend-design/SKILL.md +418 -0
  92. package/.agent/skills/frontend-design/animation-guide.md +331 -0
  93. package/.agent/skills/frontend-design/color-system.md +311 -0
  94. package/.agent/skills/frontend-design/decision-trees.md +418 -0
  95. package/.agent/skills/frontend-design/motion-graphics.md +306 -0
  96. package/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
  97. package/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
  98. package/.agent/skills/frontend-design/typography-system.md +345 -0
  99. package/.agent/skills/frontend-design/ux-psychology.md +1116 -0
  100. package/.agent/skills/frontend-design/visual-effects.md +383 -0
  101. package/.agent/skills/i18n-localization/SKILL.md +154 -0
  102. package/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
  103. package/.agent/skills/mcp-builder/SKILL.md +176 -0
  104. package/.agent/skills/web-design-guidelines/SKILL.md +57 -0
  105. package/.agent/workflows/brainstorm.md +113 -0
  106. package/.agent/workflows/create.md +59 -0
  107. package/.agent/workflows/debug.md +103 -0
  108. package/.agent/workflows/deploy.md +176 -0
  109. package/.agent/workflows/enhance.md +63 -0
  110. package/.agent/workflows/orchestrate.md +237 -0
  111. package/.agent/workflows/plan.md +89 -0
  112. package/.agent/workflows/preview.md +81 -0
  113. package/.agent/workflows/simple-test.md +42 -0
  114. package/.agent/workflows/status.md +86 -0
  115. package/.agent/workflows/structured-orchestrate.md +180 -0
  116. package/.agent/workflows/test.md +144 -0
  117. package/.agent/workflows/ui-ux-pro-max.md +296 -0
  118. package/.claude/settings.local.json +157 -149
  119. package/.editorconfig +56 -0
  120. package/.husky/pre-commit +4 -0
  121. package/.lintstagedrc +7 -0
  122. package/.prettierignore +29 -0
  123. package/.prettierrc +11 -0
  124. package/CLAUDE.md +2 -0
  125. package/README.md +64 -55
  126. package/SPEC.md +102 -61
  127. package/cli/bin/foliko.js +4 -4
  128. package/cli/src/commands/chat.js +53 -51
  129. package/cli/src/commands/list.js +40 -37
  130. package/cli/src/index.js +18 -18
  131. package/cli/src/ui/chat-ui.js +78 -76
  132. package/cli/src/utils/ansi.js +15 -15
  133. package/cli/src/utils/markdown.js +112 -116
  134. package/docker-compose.yml +1 -1
  135. package/docs/ai-sdk-optimization.md +655 -636
  136. package/docs/features.md +80 -80
  137. package/docs/quick-reference.md +49 -46
  138. package/docs/user-manual.md +411 -380
  139. package/examples/ambient-example.js +95 -97
  140. package/examples/basic.js +115 -110
  141. package/examples/bootstrap.js +52 -43
  142. package/examples/mcp-example.js +56 -53
  143. package/examples/skill-example.js +49 -49
  144. package/examples/test-chat.js +60 -58
  145. package/examples/test-mcp.js +49 -43
  146. package/examples/test-reload.js +38 -40
  147. package/examples/test-telegram.js +3 -3
  148. package/examples/test-tg-bot.js +7 -4
  149. package/examples/test-tg-simple.js +4 -3
  150. package/examples/test-tg.js +3 -3
  151. package/examples/test-think.js +13 -7
  152. package/examples/test-web-plugin.js +61 -56
  153. package/examples/test-weixin-feishu.js +40 -37
  154. package/examples/workflow.js +49 -49
  155. package/foliko-1.0.75.tgz +0 -0
  156. package/package.json +37 -3
  157. package/plugins/ai-plugin.js +7 -5
  158. package/plugins/ambient-agent/EventWatcher.js +113 -0
  159. package/plugins/ambient-agent/ExplorerLoop.js +640 -0
  160. package/plugins/ambient-agent/GoalManager.js +197 -0
  161. package/plugins/ambient-agent/Reflector.js +95 -0
  162. package/plugins/ambient-agent/StateStore.js +90 -0
  163. package/plugins/ambient-agent/constants.js +101 -0
  164. package/plugins/ambient-agent/index.js +579 -0
  165. package/plugins/default-plugins.js +62 -49
  166. package/plugins/email/constants.js +64 -0
  167. package/plugins/email/handlers.js +461 -0
  168. package/plugins/email/index.js +278 -0
  169. package/plugins/email/monitor.js +269 -0
  170. package/plugins/email/parser.js +138 -0
  171. package/plugins/email/reply.js +151 -0
  172. package/plugins/email/utils.js +124 -0
  173. package/plugins/feishu-plugin.js +23 -19
  174. package/plugins/file-system-plugin.js +469 -120
  175. package/plugins/install-plugin.js +6 -4
  176. package/plugins/python-executor-plugin.js +3 -1
  177. package/plugins/python-plugin-loader.js +10 -8
  178. package/plugins/rules-plugin.js +5 -3
  179. package/plugins/scheduler-plugin.js +18 -16
  180. package/plugins/session-plugin.js +3 -1
  181. package/plugins/storage-plugin.js +5 -3
  182. package/plugins/subagent-plugin.js +152 -92
  183. package/plugins/telegram-plugin.js +26 -19
  184. package/plugins/think-plugin.js +4 -2
  185. package/plugins/tools-plugin.js +3 -1
  186. package/plugins/web-plugin.js +15 -13
  187. package/plugins/weixin-plugin.js +43 -36
  188. package/reports/system-health-report-20260401.md +79 -0
  189. package/skills/ambient-agent/SKILL.md +49 -39
  190. package/skills/foliko-dev/AGENTS.md +64 -61
  191. package/skills/foliko-dev/SKILL.md +125 -119
  192. package/skills/mcp-usage/SKILL.md +19 -17
  193. package/skills/python-plugin-dev/SKILL.md +16 -15
  194. package/skills/skill-guide/SKILL.md +12 -12
  195. package/skills/subagent-guide/SKILL.md +237 -0
  196. package/skills/workflow-guide/SKILL.md +90 -45
  197. package/skills/workflow-troubleshooting/DEBUGGING.md +36 -21
  198. package/skills/workflow-troubleshooting/SKILL.md +156 -79
  199. package/src/capabilities/index.js +4 -4
  200. package/src/capabilities/skill-manager.js +211 -197
  201. package/src/capabilities/workflow-engine.js +461 -547
  202. package/src/core/agent-chat.js +426 -279
  203. package/src/core/agent.js +453 -248
  204. package/src/core/framework.js +183 -149
  205. package/src/core/index.js +8 -8
  206. package/src/core/plugin-base.js +52 -52
  207. package/src/core/plugin-manager.js +377 -281
  208. package/src/core/provider.js +35 -32
  209. package/src/core/sub-agent-config.js +264 -0
  210. package/src/core/system-prompt-builder.js +120 -0
  211. package/src/core/tool-registry.js +416 -33
  212. package/src/core/tool-router.js +149 -68
  213. package/src/executors/executor-base.js +58 -58
  214. package/src/executors/mcp-executor.js +269 -257
  215. package/src/index.js +5 -17
  216. package/src/utils/circuit-breaker.js +301 -0
  217. package/src/utils/error-boundary.js +363 -0
  218. package/src/utils/error.js +374 -0
  219. package/src/utils/event-emitter.js +20 -20
  220. package/src/utils/id.js +133 -0
  221. package/src/utils/index.js +217 -3
  222. package/src/utils/logger.js +181 -0
  223. package/src/utils/plugin-helpers.js +90 -0
  224. package/src/utils/retry.js +122 -0
  225. package/src/utils/sandbox.js +292 -0
  226. package/test/tool-registry-validation.test.js +218 -0
  227. package/test_report.md +70 -0
  228. package/website/docs/api.html +169 -107
  229. package/website/docs/configuration.html +296 -144
  230. package/website/docs/plugin-development.html +154 -85
  231. package/website/docs/project-structure.html +110 -109
  232. package/website/docs/skill-development.html +117 -61
  233. package/website/index.html +209 -205
  234. package/website/script.js +20 -17
  235. package/website/styles.css +1 -1
  236. package/plugins/ambient-agent-plugin.js +0 -1565
  237. package/plugins/email.js +0 -1142
@@ -6,6 +6,8 @@
6
6
  const fs = require('fs')
7
7
  const path = require('path')
8
8
  const { Plugin } = require('../src/core/plugin-base')
9
+ const { logger } = require('../src/utils/logger')
10
+ const log = logger.child('SubAgent')
9
11
  const { z } = require('zod')
10
12
  const { Agent } = require('../src/core/agent')
11
13
 
@@ -19,17 +21,15 @@ class SubAgentPlugin extends Plugin {
19
21
 
20
22
  this.system = true
21
23
 
24
+ this.role= config.role || config.name
25
+ this.tools = config.tools || {}
26
+ this.parentTools = config.parentTools || []
27
+ this.llmConfig = config.llmConfig || null
28
+
22
29
  // 子Agent配置
23
30
  // tools: { toolName: toolFn } 自定义工具(只属于此子Agent)
24
31
  // parentTools: ['read_file'] 从父Agent继承的工具名称列表
25
- this.config = {
26
- name: config.name, // 子Agent名称
27
- role: config.role || config.name, // 角色描述
28
- description: config.description || '', // 供主Agent智能选择
29
- tools: config.tools || {}, // 自定义工具 { name: toolDef }
30
- parentTools: config.parentTools || [], // 从父Agent继承的工具名称列表
31
- llmConfig: config.llmConfig || null // 独立LLM配置
32
- }
32
+ this.config = {}
33
33
 
34
34
  this._framework = null
35
35
  this._agent = null
@@ -60,10 +60,11 @@ class SubAgentPlugin extends Plugin {
60
60
  if (!parentAgent) {
61
61
  // 父agent还没创建,监听事件等其创建
62
62
  if (this._framework) {
63
- const framework = this._framework
64
- framework.on('agent:created', (agent) => {
65
- if (framework._mainAgent && agent === framework._mainAgent) {
66
- // agent已创建,重新尝试创建子agent
63
+ this._framework.on('agent:created', (agent) => {
64
+ if (this._framework._mainAgent && agent === this._framework._mainAgent) {
65
+ // agent已创建,更新父agent引用
66
+ this._parentAgent = agent
67
+ // 重新尝试创建子agent
67
68
  this._doCreateSubAgent(agent)
68
69
  // 注册委托工具
69
70
  this._registerDelegateTool()
@@ -90,58 +91,39 @@ class SubAgentPlugin extends Plugin {
90
91
 
91
92
  // 确定LLM配置
92
93
  const aiPlugin = this._framework.pluginManager.get('ai')
93
- const llmConfig = this.config.llmConfig || (aiPlugin ? aiPlugin.getConfig() : {})
94
+ const llmConfig = this.llmConfig || (aiPlugin ? aiPlugin.getConfig() : {})
94
95
 
95
- // 创建子Agent
96
- this._agent = new Agent(this._framework, {
97
- name: this.config.name,
98
- systemPrompt: this._buildSystemPrompt(),
96
+
97
+ // 创建子Agent,使用完整的 md 文件内容作为系统提示词
98
+ this._agent = this._framework.createSubAgent({
99
+ name: this.name,
100
+ systemPrompt: this._getFullSystemPrompt(),
99
101
  model: llmConfig.model,
100
102
  provider: llmConfig.provider,
101
103
  apiKey: llmConfig.apiKey,
102
- baseURL: llmConfig.baseURL
104
+ baseURL: llmConfig.baseURL,
105
+ tools: this.tools||{}, // 自定义工具
106
+ parentTools: parentTools
103
107
  })
104
108
 
105
109
  // 注册从父Agent继承的工具
106
- for (const tool of parentTools) {
107
- this._framework.registerTool(tool)
108
- }
109
-
110
- // 注册自定义工具(只属于此子Agent,不污染全局)
111
- // tools 格式: { toolName: toolDef }
112
- if (this.config.tools && typeof this.config.tools === 'object') {
113
- for (const [toolName, toolDef] of Object.entries(this.config.tools)) {
114
- const tool = typeof toolDef === 'function' ? toolDef() : toolDef
115
- if (typeof tool === 'object' && tool.name) {
116
- this._framework.registerTool(tool)
117
- } else {
118
- // 假设是简化的工具定义,需要补充 name
119
- this._framework.registerTool({ name: toolName, ...tool })
120
- }
121
- }
122
- }
110
+ // for (const tool of parentTools) {
111
+ // this._framework.registerTool(tool)
112
+ // }
123
113
 
124
- // 保存父Agent引用
114
+ // Register custom tools (only for this subAgent, won't pollute global)
115
+ // tools format: { toolName: toolDef }
116
+
125
117
  this._parentAgent = parentAgent
126
118
 
127
119
  // 注册子Agent到父Agent
128
- parentAgent.registerSubAgent(this.config.name, this._agent, this.config.role, this.config.description)
120
+ parentAgent.registerSubAgent(this.name, this._agent, this.role, this.description)
129
121
 
130
122
  // 监听子Agent的chunk事件并转发给父Agent
131
123
  this._agent.on('chunk', (chunk) => {
132
- chunk.fromSubAgent = this.config.name
124
+ chunk.fromSubAgent = this.name
133
125
  parentAgent.emit('chunk', chunk)
134
126
  })
135
-
136
- const parentToolNames = parentTools.map(t => t.name)
137
- const customToolNames = Object.keys(this.config.tools || {})
138
- //console.log(`[SubAgent:${this.config.name}] Created with ${parentToolNames.length} parent tools + ${customToolNames.length} custom tools`)
139
- // if (parentToolNames.length > 0) {
140
- // console.log(` Parent tools: ${parentToolNames.join(', ')}`)
141
- // }
142
- // if (customToolNames.length > 0) {
143
- // console.log(` Custom tools: ${customToolNames.join(', ')}`)
144
- // }
145
127
  }
146
128
 
147
129
  /**
@@ -154,7 +136,6 @@ class SubAgentPlugin extends Plugin {
154
136
  }
155
137
 
156
138
  // 尝试从framework获取主agent
157
- // 在foliko中,主agent通常是通过framework.createAgent创建的
158
139
  if (this._framework._mainAgent) {
159
140
  return this._framework._mainAgent
160
141
  }
@@ -176,12 +157,12 @@ class SubAgentPlugin extends Plugin {
176
157
  const toolMap = new Map(allTools.map(t => [t.name, t]))
177
158
 
178
159
  // 如果没有指定 parentTools,返回全部
179
- if (!this.config.parentTools || this.config.parentTools.length === 0) {
160
+ if (!this.parentTools || this.parentTools.length === 0) {
180
161
  return allTools
181
162
  }
182
163
  // 过滤指定工具
183
164
  const filtered = []
184
- for (const toolName of this.config.parentTools) {
165
+ for (const toolName of this.parentTools) {
185
166
  const tool = toolMap.get(toolName)
186
167
  if (tool) {
187
168
  filtered.push(tool)
@@ -198,9 +179,9 @@ class SubAgentPlugin extends Plugin {
198
179
  * 构建系统提示
199
180
  */
200
181
  _buildSystemPrompt() {
201
- return `你是 ${this.config.role}。
182
+ return `你是 ${this.role}。
202
183
 
203
- 角色描述:${this.config.description || '一个专业的子Agent'}
184
+ 角色描述:${this.description || '一个专业的子Agent'}
204
185
 
205
186
  当你被调用时,你应该:
206
187
  1. 仔细理解任务要求
@@ -217,8 +198,8 @@ class SubAgentPlugin extends Plugin {
217
198
  const framework = this._framework
218
199
  if (!framework) return
219
200
 
220
- const agentName = this.config.name
221
- const role = this.config.role
201
+ const agentName = this.name
202
+ const role = this.role
222
203
 
223
204
  const toolDef = {
224
205
  name: agentName,
@@ -245,7 +226,7 @@ class SubAgentPlugin extends Plugin {
245
226
  })
246
227
 
247
228
  try {
248
- const result = await this._agent.pushMessage(args.task)
229
+ const result = await this._agent.chat(args.task)
249
230
  // 发射子Agent完成处理事件
250
231
  parentAgent.emit('subagent:chat:end', {
251
232
  parentAgent,
@@ -276,12 +257,12 @@ class SubAgentPlugin extends Plugin {
276
257
  }
277
258
 
278
259
  // 注册到框架(供后续创建的 Agent 同步)
279
- framework.registerTool(toolDef)
260
+ // framework.registerTool(toolDef)
280
261
 
281
- // 如果主 Agent 已存在,直接注册到它
282
- if (framework._mainAgent) {
283
- framework._mainAgent.registerTool(toolDef)
284
- }
262
+ // // 如果主 Agent 已存在,直接注册到它
263
+ // if (framework._mainAgent) {
264
+ // framework._mainAgent.registerTool(toolDef)
265
+ // }
285
266
 
286
267
  //console.log(`[SubAgent:${this.config.name}] Delegate tool registered`)
287
268
  }
@@ -295,12 +276,77 @@ class SubAgentPlugin extends Plugin {
295
276
 
296
277
  /**
297
278
  * 调用子Agent处理任务
279
+ * 延迟创建 Agent,使用完整的 md 文件内容作为系统提示词
298
280
  */
299
281
  async chat(task) {
282
+ // 延迟创建 Agent(如果尚未创建)
300
283
  if (!this._agent) {
301
- throw new Error(`SubAgent ${this.config.name} not initialized`)
284
+ await this._createSubAgentForChat();
285
+ } else {
286
+ // 每次调用时更新系统提示词,确保使用最新的 md 文件内容
287
+ this._updateAgentSystemPrompt();
288
+ }
289
+ return this._agent.chat(task)
290
+ }
291
+
292
+ /**
293
+ * 创建用于聊天的高完整度 Agent
294
+ * 使用 SubAgentConfig 读取完整的 md 文件内容
295
+ */
296
+ async _createSubAgentForChat() {
297
+ const parentAgent = this._getParentAgent();
298
+ if (!parentAgent) {
299
+ throw new Error(`SubAgent ${this.name}: parent agent not found`);
300
+ }
301
+
302
+ // 使用 SubAgentConfig 获取完整的系统提示词
303
+ const systemPrompt = this._getFullSystemPrompt();
304
+ const parentTools = this._getParentTools(parentAgent)
305
+ // 获取 LLM 配置
306
+ const aiPlugin = this._framework.pluginManager.get('ai');
307
+ const llmConfig = this.llmConfig || (aiPlugin ? aiPlugin.getConfig() : {});
308
+
309
+ // 创建 Agent,使用完整的 md 内容作为系统提示词
310
+ this._agent = this._framework.createSubAgent({
311
+ name: this.name,
312
+ systemPrompt: systemPrompt,
313
+ model: llmConfig.model,
314
+ provider: llmConfig.provider,
315
+ apiKey: llmConfig.apiKey,
316
+ baseURL: llmConfig.baseURL,
317
+ tools: this.tools||{}, // 自定义工具
318
+ parentTools: parentTools
319
+ });
320
+
321
+ // 注册到父 Agent
322
+ this._parentAgent = parentAgent;
323
+ parentAgent.registerSubAgent(this.name, this._agent, this.role, this.description);
324
+ }
325
+
326
+ /**
327
+ * 获取完整的系统提示词(从 md 文件读取)
328
+ */
329
+ _getFullSystemPrompt() {
330
+ // 尝试从 SubAgentConfigManager 获取完整内容
331
+ const configManager = this._framework._subAgentConfigManager;
332
+ if (configManager) {
333
+ const config = configManager.get(this.name);
334
+ if (config) {
335
+ return config.getSystemPrompt();
336
+ }
302
337
  }
303
- return this._agent.pushMessage(task)
338
+
339
+ // 回退到默认的 _buildSystemPrompt
340
+ return this._buildSystemPrompt();
341
+ }
342
+
343
+ /**
344
+ * 更新 Agent 的系统提示词
345
+ */
346
+ _updateAgentSystemPrompt() {
347
+ if (!this._agent) return;
348
+ const systemPrompt = this._getFullSystemPrompt();
349
+ this._agent.setSystemPrompt(systemPrompt);
304
350
  }
305
351
 
306
352
  reload(framework) {
@@ -310,7 +356,7 @@ class SubAgentPlugin extends Plugin {
310
356
 
311
357
  uninstall(framework) {
312
358
  if (this._parentAgent) {
313
- this._parentAgent.unregisterSubAgent(this.config.name)
359
+ this._parentAgent.unregisterSubAgent(this.name)
314
360
  }
315
361
  if (this._agent) {
316
362
  this._agent.destroy()
@@ -330,11 +376,13 @@ class SubAgentManagerPlugin extends Plugin {
330
376
  this.name = 'subagent-manager'
331
377
  this.version = '1.0.0'
332
378
  this.description = '子Agent管理器,统一管理多个子Agent'
333
- this.priority = 10
334
379
 
380
+ this.systemPrompt= `你是一个子Agent管理器,负责管理多个子Agent。每个子Agent都有独立的工具集和角色描述。当需要处理特定任务时,你会选择合适的子Agent来执行。`
381
+
382
+ this.priority = 10
383
+ this.agents = config.agents || [] // 预定义的子Agent配置列表
335
384
  this.config = {
336
385
  agentsDir: config.agentsDir || null, // 子Agent配置目录
337
- agents: config.agents || [] // 子Agent配置列表
338
386
  }
339
387
 
340
388
  this._framework = null
@@ -353,7 +401,7 @@ class SubAgentManagerPlugin extends Plugin {
353
401
  this._loadAgentsFromDir()
354
402
 
355
403
  // 创建所有配置的子Agent
356
- for (const agentConfig of this.config.agents) {
404
+ for (const agentConfig of this.agents) {
357
405
  const plugin = new SubAgentPlugin(agentConfig)
358
406
  plugin.install(framework)
359
407
  plugin.start(framework)
@@ -391,9 +439,9 @@ class SubAgentManagerPlugin extends Plugin {
391
439
  inputSchema: z.object({}),
392
440
  execute: async () => {
393
441
  const agents = Array.from(this._subAgents.values()).map(p => ({
394
- name: p.config.name,
395
- role: p.config.role,
396
- description: p.config.description,
442
+ name: p.name,
443
+ role: p.role,
444
+ description: p.description,
397
445
  toolCount: p._agent ? p._agent.getTools().length : 0
398
446
  }))
399
447
  return { success: true, agents }
@@ -414,7 +462,7 @@ class SubAgentManagerPlugin extends Plugin {
414
462
  }
415
463
 
416
464
  try {
417
- const result = await plugin.pushMessage(args.task)
465
+ const result = await plugin.chat(args.task)
418
466
  return {
419
467
  success: true,
420
468
  agent: args.agentName,
@@ -441,7 +489,7 @@ class SubAgentManagerPlugin extends Plugin {
441
489
  }
442
490
  })
443
491
 
444
- //console.log('[SubAgentManager] Management tools registered to agent')
492
+ //log.info(' Management tools registered to agent')
445
493
  }
446
494
 
447
495
  /**
@@ -454,9 +502,9 @@ class SubAgentManagerPlugin extends Plugin {
454
502
  inputSchema: z.object({}),
455
503
  execute: async () => {
456
504
  const agents = Array.from(this._subAgents.values()).map(p => ({
457
- name: p.config.name,
458
- role: p.config.role,
459
- description: p.config.description,
505
+ name: p.name,
506
+ role: p.role,
507
+ description: p.description,
460
508
  toolCount: p._agent ? p._agent.getTools().length : 0
461
509
  }))
462
510
  return { success: true, agents }
@@ -477,7 +525,7 @@ class SubAgentManagerPlugin extends Plugin {
477
525
  }
478
526
 
479
527
  try {
480
- const result = await plugin.pushMessage(args.task)
528
+ const result = await plugin.chat(args.task)
481
529
  return {
482
530
  success: true,
483
531
  agent: args.agentName,
@@ -504,7 +552,7 @@ class SubAgentManagerPlugin extends Plugin {
504
552
  }
505
553
  })
506
554
 
507
- //console.log('[SubAgentManager] Management tools registered to framework')
555
+ //log.info(' Management tools registered to framework')
508
556
  }
509
557
 
510
558
  /**
@@ -512,14 +560,14 @@ class SubAgentManagerPlugin extends Plugin {
512
560
  */
513
561
  _loadAgentsFromDir() {
514
562
  const agentsDir = this.config.agentsDir
515
- //console.log('[SubAgentManager] _loadAgentsFromDir called, agentsDir:', agentsDir)
563
+ //log.info(' _loadAgentsFromDir called, agentsDir:', agentsDir)
516
564
  if (!agentsDir || !fs.existsSync(agentsDir)) {
517
- console.log('[SubAgentManager] agentsDir not found or does not exist')
565
+ log.info(' agentsDir not found or does not exist')
518
566
  return
519
567
  }
520
568
 
521
569
  const entries = fs.readdirSync(agentsDir, { withFileTypes: true })
522
- //console.log('[SubAgentManager] Found entries:', entries.length)
570
+ //log.info(' Found entries:', entries.length)
523
571
 
524
572
  for (const entry of entries) {
525
573
  if (entry.isFile() && (entry.name.endsWith('.js') || entry.name.endsWith('.json') || entry.name.endsWith('.md'))) {
@@ -527,7 +575,7 @@ class SubAgentManagerPlugin extends Plugin {
527
575
  const filePath = path.join(agentsDir, entry.name)
528
576
 
529
577
  // 跳过与已有配置同名的
530
- if (this.config.agents.some(a => a.name === baseName)) {
578
+ if (this.agents.some(a => a.name === baseName)) {
531
579
  continue
532
580
  }
533
581
 
@@ -539,7 +587,7 @@ class SubAgentManagerPlugin extends Plugin {
539
587
  } else if (entry.name.endsWith('.md')) {
540
588
  // 解析 markdown 文件,提取 JSON 配置
541
589
  agentConfig = this._parseMarkdownConfig(filePath, baseName)
542
- //console.log('[SubAgentManager] Parsed md:', baseName, agentConfig)
590
+ //log.info(' Parsed md:', baseName, agentConfig)
543
591
  } else {
544
592
  // 清除缓存并加载
545
593
  delete require.cache[require.resolve(filePath)]
@@ -549,13 +597,13 @@ class SubAgentManagerPlugin extends Plugin {
549
597
 
550
598
  if (agentConfig && agentConfig.name) {
551
599
  agentConfig._fromDir = true
552
- this.config.agents.push(agentConfig)
553
- //console.log('[SubAgentManager] Loaded agent:', agentConfig.name)
600
+ this.agents.push(agentConfig)
601
+ //log.info(' Loaded agent:', agentConfig.name)
554
602
  } else {
555
- console.warn('[SubAgentManager] Agent config has no name:', baseName, agentConfig)
603
+ log.warn(' Agent config has no name:', baseName, agentConfig)
556
604
  }
557
605
  } catch (err) {
558
- console.warn(`[SubAgentManager] Failed to load agent config from ${filePath}:`, err.message, err.stack)
606
+ log.warn(` Failed to load agent config from ${filePath}:`, err.message, err.stack)
559
607
  }
560
608
  }
561
609
  }
@@ -571,14 +619,14 @@ class SubAgentManagerPlugin extends Plugin {
571
619
  */
572
620
  _parseMarkdownConfig(filePath, defaultName) {
573
621
  const content = fs.readFileSync(filePath, 'utf-8')
574
- //console.log('[SubAgentManager] _parseMarkdownConfig:', filePath)
622
+ //log.info(' _parseMarkdownConfig:', filePath)
575
623
 
576
624
  // 尝试从 code block 中提取 JSON
577
625
  const jsonMatch = content.match(/```(?:json)?\s*\n([\s\S]*?)\n\s*```/)
578
626
  if (jsonMatch) {
579
627
  try {
580
628
  const config = JSON.parse(jsonMatch[1].trim())
581
- //console.log('[SubAgentManager] Found JSON in code block')
629
+ //log.info(' Found JSON in code block')
582
630
  return config
583
631
  } catch (err) {
584
632
  // JSON 解析失败,继续
@@ -588,11 +636,11 @@ class SubAgentManagerPlugin extends Plugin {
588
636
  // 尝试从 frontmatter 格式中提取
589
637
  const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/)
590
638
  if (frontmatterMatch) {
591
- //console.log('[SubAgentManager] Found frontmatter')
639
+ //log.info(' Found frontmatter')
592
640
  const frontmatterContent = frontmatterMatch[1]
593
641
  const parsed = this._parseYamlLike(frontmatterContent)
594
642
  if (parsed && parsed.name) {
595
- //console.log('[SubAgentManager] Parsed frontmatter:', parsed)
643
+ //log.info(' Parsed frontmatter:', parsed)
596
644
  return { name: parsed.name || defaultName, ...parsed }
597
645
  }
598
646
  }
@@ -608,6 +656,13 @@ class SubAgentManagerPlugin extends Plugin {
608
656
  return config
609
657
  }
610
658
 
659
+ /**
660
+ * 获取所有 subAgent 的基本信息列表
661
+ */
662
+ getAllSubAgents() {
663
+ return Array.from(this._subAgents.values());
664
+ }
665
+
611
666
  /**
612
667
  * 解析类似 YAML 的配置
613
668
  */
@@ -731,7 +786,7 @@ class SubAgentManagerPlugin extends Plugin {
731
786
  }
732
787
 
733
788
  if (hasChanges) {
734
- //console.log('[SubAgentManager] File changes detected, reloading...')
789
+ //log.info(' File changes detected, reloading...')
735
790
  this._updateFileStates()
736
791
  this.reload(this._framework)
737
792
  }
@@ -759,7 +814,12 @@ class SubAgentManagerPlugin extends Plugin {
759
814
  this._subAgents.clear()
760
815
 
761
816
  // 清空从目录加载的配置,重新加载
762
- this.config.agents = this.config.agents.filter(a => !a._fromDir)
817
+ this.agents = this.agents.filter(a => !a._fromDir)
818
+
819
+ // 刷新 SubAgentConfigManager(如果存在)
820
+ if (framework._subAgentConfigManager) {
821
+ framework._subAgentConfigManager.refresh()
822
+ }
763
823
 
764
824
  // 重新创建
765
825
  this.start(framework)
@@ -10,6 +10,8 @@
10
10
  */
11
11
 
12
12
  const { Plugin } = require('../src/core/plugin-base')
13
+ const { logger } = require('../src/utils/logger')
14
+ const log = logger.child('Telegram')
13
15
  const { z } = require('zod')
14
16
 
15
17
  // 转义 MarkdownV2 特殊字符
@@ -27,6 +29,11 @@ class TelegramPlugin extends Plugin {
27
29
  this.priority = 80
28
30
  this.enabled = false
29
31
  this.systemPrompt = `你是一个有帮助的AI助手。回复内容不要使用markdown格式文本。
32
+
33
+ **重要:** 子Agent 匹配规则必须遵守:
34
+ - 根据【子 Agent 匹配表】,将任务委托给最匹配的子Agent处理
35
+ - 使用 subagent_call 工具并指定 agentName 来委托任务
36
+ - 只有当没有匹配的子Agent时,才直接调用工具
30
37
 
31
38
  **命令执行规范:**
32
39
  - 执行 npx skills add / npx skills remove / npx skills list 命令时,必须自动添加参数:-a openclaw -y
@@ -54,7 +61,7 @@ class TelegramPlugin extends Plugin {
54
61
 
55
62
  start(framework) {
56
63
  if (!this.config.botToken) {
57
- console.warn('[Telegram] No bot token. Set TELEGRAM_BOT_TOKEN env var.')
64
+ log.warn(' No bot token. Set TELEGRAM_BOT_TOKEN env var.')
58
65
  return this
59
66
  }
60
67
 
@@ -64,7 +71,7 @@ class TelegramPlugin extends Plugin {
64
71
  if (this._sessionPlugin) {
65
72
  this._sessionDeleteHandler = (sessionId) => {
66
73
  if (sessionId.startsWith('telegram_')) {
67
- console.log(`[Telegram] Session deleted: ${sessionId}`)
74
+ log.info(` Session deleted: ${sessionId}`)
68
75
  }
69
76
  }
70
77
  this._sessionPlugin.on('session:deleted', this._sessionDeleteHandler)
@@ -79,25 +86,25 @@ class TelegramPlugin extends Plugin {
79
86
  const TelegramBot = require('node-telegram-bot-api')
80
87
  this._bot = new TelegramBot(this.config.botToken, { polling: true })
81
88
 
82
- console.log('[Telegram] Bot started successfully')
89
+ log.info(' Bot started successfully')
83
90
 
84
91
  this._bot.setMyCommands([
85
92
  { command: 'start', description: '显示帮助信息' },
86
93
  { command: 'clear', description: '清除对话历史' },
87
94
  { command: 'history', description: '查看对话状态' }
88
95
  ]).catch((err) => {
89
- console.error('[Telegram] Failed to register commands:', err.message)
96
+ log.error(' Failed to register commands:', err.message)
90
97
  })
91
98
 
92
99
  this._bot.on('message', (msg) => this._handleMessage(msg))
93
100
  this._bot.on('edit_message', (msg) => this._handleEdit(msg))
94
101
  this._bot.on('callback_query', (query) => this._handleCallback(query))
95
- this._bot.on('polling_error', (err) => console.error('[Telegram] Polling error:', err.message))
96
- this._bot.on('error', (err) => console.error('[Telegram] Bot error:', err.message))
102
+ this._bot.on('polling_error', (err) => log.error(' Polling error:', err.message))
103
+ this._bot.on('error', (err) => log.error(' Bot error:', err.message))
97
104
 
98
105
  if (this._framework) {
99
106
  this._framework.on('agent:created', (agent) => {
100
- console.log('[Telegram] New agent created:', agent.name)
107
+ log.info(' New agent created:', agent.name)
101
108
  })
102
109
 
103
110
  // 监听统一通知事件
@@ -111,7 +118,7 @@ class TelegramPlugin extends Plugin {
111
118
  })
112
119
  }
113
120
  } catch (err) {
114
- console.error('[Telegram] Failed to initialize bot:', err.message)
121
+ log.error(' Failed to initialize bot:', err.message)
115
122
  }
116
123
  }
117
124
 
@@ -122,7 +129,7 @@ class TelegramPlugin extends Plugin {
122
129
  const { title, message, source, level } = data
123
130
 
124
131
  if (!this._bot) {
125
- console.warn('[Telegram] Bot not ready, cannot send notification')
132
+ log.warn(' Bot not ready, cannot send notification')
126
133
  return
127
134
  }
128
135
 
@@ -151,7 +158,7 @@ class TelegramPlugin extends Plugin {
151
158
  }
152
159
 
153
160
  if (!chatId) {
154
- console.warn('[Telegram] No telegram session found for notification')
161
+ log.warn(' No telegram session found for notification')
155
162
  return
156
163
  }
157
164
 
@@ -167,9 +174,9 @@ class TelegramPlugin extends Plugin {
167
174
 
168
175
  try {
169
176
  await this._bot.sendMessage(chatId, notificationText)
170
- console.log(`[Telegram] Notification sent to chat ${chatId}`)
177
+ log.info(` Notification sent to chat ${chatId}`)
171
178
  } catch (err) {
172
- console.error(`[Telegram] Failed to send notification:`, err.message)
179
+ log.error(` Failed to send notification:`, err.message)
173
180
  }
174
181
  }
175
182
 
@@ -188,9 +195,9 @@ class TelegramPlugin extends Plugin {
188
195
 
189
196
  try {
190
197
  await this._bot.sendMessage(chatId, notificationText)
191
- console.log(`[Telegram] Webhook notification sent to chat ${chatId}`)
198
+ log.info(` Webhook notification sent to chat ${chatId}`)
192
199
  } catch (err) {
193
- console.error(`[Telegram] Failed to send webhook notification:`, err.message)
200
+ log.error(` Failed to send webhook notification:`, err.message)
194
201
  }
195
202
  }
196
203
 
@@ -299,7 +306,7 @@ class TelegramPlugin extends Plugin {
299
306
  reply_to_message_id: replyToMessageId
300
307
  })
301
308
  } catch (err) {
302
- console.error('[Telegram] Send thinking error:', err.message)
309
+ log.error(' Send thinking error:', err.message)
303
310
  return
304
311
  }
305
312
 
@@ -330,7 +337,7 @@ class TelegramPlugin extends Plugin {
330
337
  parse_mode: 'MarkdownV2'
331
338
  })
332
339
  } catch (err) {
333
- console.error('[Telegram] Chat error:', err)
340
+ log.error(' Chat error:', err)
334
341
  await this._bot.editMessageText(escapeMarkdown(`❌ 发生错误:${err.message}`), {
335
342
  chat_id: chatId,
336
343
  message_id: thinkingMsg.message_id
@@ -365,7 +372,7 @@ class TelegramPlugin extends Plugin {
365
372
  await this._processChat(chatId, `图片:${filePath}, ${caption}`, msg.message_id)
366
373
  }
367
374
  } catch (err) {
368
- console.error('[Telegram] Failed to save photo:', err.message)
375
+ log.error(' Failed to save photo:', err.message)
369
376
  await this._sendMessage(chatId, '图片保存失败: ' + err.message, msg.message_id)
370
377
  }
371
378
  }
@@ -388,7 +395,7 @@ class TelegramPlugin extends Plugin {
388
395
  await this._processChat(chatId, `文件:${filePath}, ${caption}`, msg.message_id)
389
396
  }
390
397
  } catch (err) {
391
- console.error('[Telegram] Failed to save document:', err.message)
398
+ log.error(' Failed to save document:', err.message)
392
399
  await this._sendMessage(chatId, '文件保存失败: ' + err.message, msg.message_id)
393
400
  }
394
401
  }
@@ -445,7 +452,7 @@ class TelegramPlugin extends Plugin {
445
452
  if (this._bot) {
446
453
  this._bot.stopPolling()
447
454
  this._bot = null
448
- console.log('[Telegram] Bot stopped')
455
+ log.info(' Bot stopped')
449
456
  }
450
457
  }
451
458
 
@@ -4,6 +4,8 @@
4
4
  */
5
5
 
6
6
  const { Plugin } = require('../src/core/plugin-base')
7
+ const { logger } = require('../src/utils/logger')
8
+ const log = logger.child('Think')
7
9
  const { z } = require('zod')
8
10
 
9
11
  class ThinkPlugin extends Plugin {
@@ -239,7 +241,7 @@ ${topic || '接下来的行动'}
239
241
  })
240
242
  }
241
243
  } catch (err) {
242
- console.error('[Think] Auto-reflect error:', err.message)
244
+ log.error(' Auto-reflect error:', err.message)
243
245
  }
244
246
  }
245
247
 
@@ -272,7 +274,7 @@ ${topic || '接下来的行动'}
272
274
  this._continuousTimer = setTimeout(runThink, interval)
273
275
  }
274
276
  } catch (err) {
275
- console.error('[Think] Continuous think error:', err.message)
277
+ log.error(' Continuous think error:', err.message)
276
278
  }
277
279
  }
278
280