foliko 1.0.74 → 1.0.76

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 (238) 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 +11 -1
  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 +11 -11
  128. package/cli/src/commands/chat.js +143 -141
  129. package/cli/src/commands/list.js +93 -90
  130. package/cli/src/index.js +75 -75
  131. package/cli/src/ui/chat-ui.js +201 -199
  132. package/cli/src/utils/ansi.js +40 -40
  133. package/cli/src/utils/markdown.js +292 -296
  134. package/docker-compose.yml +1 -1
  135. package/docs/ai-sdk-optimization.md +655 -643
  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 +194 -196
  140. package/examples/basic.js +50 -45
  141. package/examples/bootstrap.js +121 -112
  142. package/examples/mcp-example.js +19 -16
  143. package/examples/skill-example.js +20 -20
  144. package/examples/test-chat.js +137 -135
  145. package/examples/test-mcp.js +85 -79
  146. package/examples/test-reload.js +59 -61
  147. package/examples/test-telegram.js +50 -50
  148. package/examples/test-tg-bot.js +45 -42
  149. package/examples/test-tg-simple.js +47 -46
  150. package/examples/test-tg.js +62 -62
  151. package/examples/test-think.js +43 -37
  152. package/examples/test-web-plugin.js +103 -98
  153. package/examples/test-weixin-feishu.js +103 -100
  154. package/examples/workflow.js +158 -158
  155. package/package.json +37 -3
  156. package/plugins/ai-plugin.js +102 -100
  157. package/plugins/ambient-agent/EventWatcher.js +113 -0
  158. package/plugins/ambient-agent/ExplorerLoop.js +640 -0
  159. package/plugins/ambient-agent/GoalManager.js +197 -0
  160. package/plugins/ambient-agent/Reflector.js +95 -0
  161. package/plugins/ambient-agent/StateStore.js +90 -0
  162. package/plugins/ambient-agent/constants.js +101 -0
  163. package/plugins/ambient-agent/index.js +579 -0
  164. package/plugins/audit-plugin.js +187 -187
  165. package/plugins/default-plugins.js +662 -649
  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 +481 -477
  174. package/plugins/file-system-plugin.js +826 -476
  175. package/plugins/install-plugin.js +199 -197
  176. package/plugins/python-executor-plugin.js +367 -365
  177. package/plugins/python-plugin-loader.js +481 -479
  178. package/plugins/rules-plugin.js +294 -292
  179. package/plugins/scheduler-plugin.js +691 -689
  180. package/plugins/session-plugin.js +369 -367
  181. package/plugins/shell-executor-plugin.js +197 -197
  182. package/plugins/storage-plugin.js +240 -238
  183. package/plugins/subagent-plugin.js +845 -785
  184. package/plugins/telegram-plugin.js +482 -475
  185. package/plugins/think-plugin.js +345 -343
  186. package/plugins/tools-plugin.js +196 -194
  187. package/plugins/web-plugin.js +606 -604
  188. package/plugins/weixin-plugin.js +545 -538
  189. package/reports/system-health-report-20260401.md +79 -0
  190. package/skills/ambient-agent/SKILL.md +49 -39
  191. package/skills/foliko-dev/AGENTS.md +64 -61
  192. package/skills/foliko-dev/SKILL.md +125 -119
  193. package/skills/mcp-usage/SKILL.md +19 -17
  194. package/skills/python-plugin-dev/SKILL.md +16 -15
  195. package/skills/skill-guide/SKILL.md +12 -12
  196. package/skills/subagent-guide/SKILL.md +237 -0
  197. package/skills/workflow-guide/SKILL.md +90 -45
  198. package/skills/workflow-troubleshooting/DEBUGGING.md +36 -21
  199. package/skills/workflow-troubleshooting/SKILL.md +156 -79
  200. package/src/capabilities/index.js +11 -11
  201. package/src/capabilities/skill-manager.js +609 -595
  202. package/src/capabilities/workflow-engine.js +1109 -1195
  203. package/src/core/agent-chat.js +882 -735
  204. package/src/core/agent.js +892 -688
  205. package/src/core/framework.js +465 -431
  206. package/src/core/index.js +19 -19
  207. package/src/core/plugin-base.js +219 -219
  208. package/src/core/plugin-manager.js +863 -767
  209. package/src/core/provider.js +114 -111
  210. package/src/core/sub-agent-config.js +264 -0
  211. package/src/core/system-prompt-builder.js +120 -0
  212. package/src/core/tool-registry.js +517 -134
  213. package/src/core/tool-router.js +297 -216
  214. package/src/executors/executor-base.js +12 -12
  215. package/src/executors/mcp-executor.js +741 -729
  216. package/src/index.js +25 -37
  217. package/src/utils/circuit-breaker.js +301 -0
  218. package/src/utils/error-boundary.js +363 -0
  219. package/src/utils/error.js +374 -0
  220. package/src/utils/event-emitter.js +97 -97
  221. package/src/utils/id.js +133 -0
  222. package/src/utils/index.js +217 -3
  223. package/src/utils/logger.js +181 -0
  224. package/src/utils/plugin-helpers.js +90 -0
  225. package/src/utils/retry.js +122 -0
  226. package/src/utils/sandbox.js +292 -0
  227. package/test/tool-registry-validation.test.js +218 -0
  228. package/test_report.md +70 -0
  229. package/website/docs/api.html +169 -107
  230. package/website/docs/configuration.html +296 -144
  231. package/website/docs/plugin-development.html +154 -85
  232. package/website/docs/project-structure.html +110 -109
  233. package/website/docs/skill-development.html +117 -61
  234. package/website/index.html +209 -205
  235. package/website/script.js +136 -133
  236. package/website/styles.css +1 -1
  237. package/plugins/ambient-agent-plugin.js +0 -1565
  238. package/plugins/email.js +0 -1142
@@ -69,11 +69,11 @@ npm install
69
69
  ### 2.2 创建聊天机器人
70
70
 
71
71
  ```javascript
72
- const { Framework } = require('./src')
72
+ const { Framework } = require('./src');
73
73
 
74
74
  async function main() {
75
75
  // 创建框架
76
- const framework = new Framework({ debug: false })
76
+ const framework = new Framework({ debug: false });
77
77
 
78
78
  // Bootstrap(加载所有配置和插件)
79
79
  await framework.bootstrap({
@@ -81,25 +81,25 @@ async function main() {
81
81
  aiConfig: {
82
82
  provider: 'deepseek',
83
83
  model: 'deepseek-chat',
84
- apiKey: process.env.DEEPSEEK_API_KEY
85
- }
86
- })
84
+ apiKey: process.env.DEEPSEEK_API_KEY,
85
+ },
86
+ });
87
87
 
88
88
  // 创建 Agent
89
89
  const agent = framework.createAgent({
90
90
  name: 'MyAgent',
91
- systemPrompt: '你是一个有帮助的助手。'
92
- })
91
+ systemPrompt: '你是一个有帮助的助手。',
92
+ });
93
93
 
94
94
  // 对话
95
95
  for await (const chunk of agent.chatStream('你好')) {
96
96
  if (chunk.type === 'text') {
97
- process.stdout.write(chunk.text)
97
+ process.stdout.write(chunk.text);
98
98
  }
99
99
  }
100
100
  }
101
101
 
102
- main().catch(console.error)
102
+ main().catch(console.error);
103
103
  ```
104
104
 
105
105
  ### 2.3 运行测试聊天
@@ -117,16 +117,16 @@ node test-chat.js
117
117
  框架是整个系统的容器,管理插件和工具注册。
118
118
 
119
119
  ```javascript
120
- const framework = new Framework({ debug: false })
120
+ const framework = new Framework({ debug: false });
121
121
 
122
122
  // 加载插件
123
- await framework.loadPlugin(myPlugin)
123
+ await framework.loadPlugin(myPlugin);
124
124
 
125
125
  // 创建 Agent
126
- const agent = framework.createAgent(config)
126
+ const agent = framework.createAgent(config);
127
127
 
128
128
  // 执行工具
129
- const result = await framework.executeTool('tool_name', { arg: 'value' })
129
+ const result = await framework.executeTool('tool_name', { arg: 'value' });
130
130
  ```
131
131
 
132
132
  ### 3.2 Agent(智能体)
@@ -135,21 +135,22 @@ Agent 负责对话和推理,拥有独立的工具集和系统提示。
135
135
 
136
136
  ```javascript
137
137
  const agent = framework.createAgent({
138
- name: 'MyAgent', // Agent 名称
139
- systemPrompt: '你是一个...', // 系统提示
138
+ name: 'MyAgent', // Agent 名称
139
+ systemPrompt: '你是一个...', // 系统提示
140
140
  sharedPrompt: '{{WORK_DIR}}', // 共享提示(支持占位符)
141
- metadata: { // 元数据
142
- projectName: 'MyProject'
141
+ metadata: {
142
+ // 元数据
143
+ projectName: 'MyProject',
143
144
  },
144
- enableToolRouting: true // 启用工具路由(默认 true)
145
- })
145
+ enableToolRouting: true, // 启用工具路由(默认 true)
146
+ });
146
147
 
147
148
  // 发送消息(非流式)
148
- const result = await agent.chat('你好')
149
+ const result = await agent.chat('你好');
149
150
 
150
151
  // 发送消息(流式)
151
152
  for await (const chunk of agent.chatStream('你好')) {
152
- if (chunk.type === 'text') process.stdout.write(chunk.text)
153
+ if (chunk.type === 'text') process.stdout.write(chunk.text);
153
154
  }
154
155
  ```
155
156
 
@@ -158,21 +159,21 @@ for await (const chunk of agent.chatStream('你好')) {
158
159
  插件是功能扩展的基本单元。
159
160
 
160
161
  ```javascript
161
- const { Plugin } = require('./src/core/plugin-base')
162
+ const { Plugin } = require('./src/core/plugin-base');
162
163
 
163
164
  class MyPlugin extends Plugin {
164
165
  constructor() {
165
- super()
166
- this.name = 'my-plugin'
167
- this.version = '1.0.0'
168
- this.description = '我的插件'
169
- this.priority = 10 // 加载优先级(数字越小越先加载)
166
+ super();
167
+ this.name = 'my-plugin';
168
+ this.version = '1.0.0';
169
+ this.description = '我的插件';
170
+ this.priority = 10; // 加载优先级(数字越小越先加载)
170
171
  }
171
172
 
172
173
  install(framework) {
173
- this._framework = framework
174
+ this._framework = framework;
174
175
  // 安装时调用
175
- return this
176
+ return this;
176
177
  }
177
178
 
178
179
  start(framework) {
@@ -180,26 +181,28 @@ class MyPlugin extends Plugin {
180
181
  framework.registerTool({
181
182
  name: 'my_tool',
182
183
  description: '我的工具',
183
- inputSchema: { /* zod schema */ },
184
+ inputSchema: {
185
+ /* zod schema */
186
+ },
184
187
  execute: async (args) => {
185
- return { result: 'done' }
186
- }
187
- })
188
- return this
188
+ return { result: 'done' };
189
+ },
190
+ });
191
+ return this;
189
192
  }
190
193
 
191
194
  reload(framework) {
192
195
  // 热重载时调用
193
- return this
196
+ return this;
194
197
  }
195
198
 
196
199
  uninstall(framework) {
197
200
  // 卸载时调用
198
- return this
201
+ return this;
199
202
  }
200
203
  }
201
204
 
202
- module.exports = MyPlugin
205
+ module.exports = MyPlugin;
203
206
  ```
204
207
 
205
208
  ### 3.4 免引入写法
@@ -208,23 +211,23 @@ module.exports = MyPlugin
208
211
 
209
212
  ```javascript
210
213
  // 直接导出函数
211
- module.exports = function(Plugin) {
214
+ module.exports = function (Plugin) {
212
215
  return class extends Plugin {
213
216
  constructor() {
214
- super()
215
- this.name = 'my-plugin'
216
- this.description = '我的插件'
217
+ super();
218
+ this.name = 'my-plugin';
219
+ this.description = '我的插件';
217
220
  }
218
221
 
219
222
  start(framework) {
220
223
  framework.registerTool({
221
224
  name: 'hello',
222
- execute: async (args) => `Hello, ${args.name}!`
223
- })
224
- return this
225
+ execute: async (args) => `Hello, ${args.name}!`,
226
+ });
227
+ return this;
225
228
  }
226
- }
227
- }
229
+ };
230
+ };
228
231
  ```
229
232
 
230
233
  ---
@@ -236,12 +239,14 @@ module.exports = function(Plugin) {
236
239
  提供 AI 对话能力。
237
240
 
238
241
  ```javascript
239
- await framework.loadPlugin(new AIPlugin({
240
- provider: 'deepseek', // AI 提供商
241
- model: 'deepseek-chat', // 模型名称
242
- apiKey: 'your-api-key', // API Key
243
- baseURL: 'https://api.deepseek.com' // 可选:自定义 API 地址
244
- }))
242
+ await framework.loadPlugin(
243
+ new AIPlugin({
244
+ provider: 'deepseek', // AI 提供商
245
+ model: 'deepseek-chat', // 模型名称
246
+ apiKey: 'your-api-key', // API Key
247
+ baseURL: 'https://api.deepseek.com', // 可选:自定义 API 地址
248
+ })
249
+ );
245
250
  ```
246
251
 
247
252
  **热重载支持:** 更新 AI 配置后执行 `reload_plugins('ai')`,所有已有 Agent 会自动使用新的 LLM 设置。
@@ -252,12 +257,12 @@ await framework.executeTool('update_plugin_config', {
252
257
  name: 'ai',
253
258
  config: {
254
259
  model: 'gpt-4o',
255
- apiKey: 'new-key'
256
- }
257
- })
260
+ apiKey: 'new-key',
261
+ },
262
+ });
258
263
 
259
264
  // 2. 热重载 AI 插件
260
- await framework.executeTool('reload_plugins', { pluginName: 'ai' })
265
+ await framework.executeTool('reload_plugins', { pluginName: 'ai' });
261
266
  ```
262
267
 
263
268
  ### 4.2 存储插件 (storage-plugin)
@@ -266,11 +271,11 @@ await framework.executeTool('reload_plugins', { pluginName: 'ai' })
266
271
 
267
272
  ```javascript
268
273
  // 注册的工具
269
- storage_set(key, value) // 存储值
270
- storage_get(key) // 获取值
271
- storage_delete(key) // 删除值
272
- storage_list() // 列出所有键
273
- storage_clear() // 清空存储
274
+ storage_set(key, value); // 存储值
275
+ storage_get(key); // 获取值
276
+ storage_delete(key); // 删除值
277
+ storage_list(); // 列出所有键
278
+ storage_clear(); // 清空存储
274
279
  ```
275
280
 
276
281
  ### 4.3 工具插件 (tools-plugin)
@@ -310,8 +315,8 @@ execute_command(cmd) // 执行命令
310
315
 
311
316
  ```javascript
312
317
  // 注册的工具
313
- shell(command) // 执行 Shell 命令
314
- powershell(command) // 执行 PowerShell(仅 Windows)
318
+ shell(command); // 执行 Shell 命令
319
+ powershell(command); // 执行 PowerShell(仅 Windows)
315
320
  ```
316
321
 
317
322
  ### 4.6 Python 执行器 (python-executor-plugin)
@@ -320,9 +325,9 @@ powershell(command) // 执行 PowerShell(仅 Windows)
320
325
 
321
326
  ```javascript
322
327
  // 注册的工具
323
- python(code) // 执行 Python 代码
324
- python_script(scriptPath) // 执行 Python 脚本
325
- pip_install(package) // 安装 Python 包
328
+ python(code); // 执行 Python 代码
329
+ python_script(scriptPath); // 执行 Python 脚本
330
+ pip_install(package); // 安装 Python 包
326
331
  ```
327
332
 
328
333
  ### 4.7 MCP 执行器 (mcp-executor)
@@ -343,8 +348,8 @@ pip_install(package) // 安装 Python 包
343
348
 
344
349
  ```javascript
345
350
  // 注册的工具
346
- mcp_call(server, tool, args) // 调用 MCP 工具
347
- mcp_list_servers() // 列出已连接的 MCP 服务器
351
+ mcp_call(server, tool, args); // 调用 MCP 工具
352
+ mcp_list_servers(); // 列出已连接的 MCP 服务器
348
353
  ```
349
354
 
350
355
  ### 4.8 会话插件 (session-plugin)
@@ -367,9 +372,9 @@ session_stats() // 获取会话统计
367
372
 
368
373
  ```javascript
369
374
  // 注册的工具
370
- audit_query(options) // 查询日志
371
- audit_stats() // 获取统计
372
- audit_export(format) // 导出日志
375
+ audit_query(options); // 查询日志
376
+ audit_stats(); // 获取统计
377
+ audit_export(format); // 导出日志
373
378
  ```
374
379
 
375
380
  ### 4.10 规则插件 (rules-plugin)
@@ -378,11 +383,11 @@ audit_export(format) // 导出日志
378
383
 
379
384
  ```javascript
380
385
  // 注册的工具
381
- rules_list() // 列出规则
382
- rules_add(rule) // 添加规则
383
- rules_remove(ruleId) // 移除规则
384
- rules_test(input) // 测试规则匹配
385
- rules_stats() // 获取统计
386
+ rules_list(); // 列出规则
387
+ rules_add(rule); // 添加规则
388
+ rules_remove(ruleId); // 移除规则
389
+ rules_test(input); // 测试规则匹配
390
+ rules_stats(); // 获取统计
386
391
  ```
387
392
 
388
393
  ### 4.11 调度插件 (scheduler-plugin)
@@ -391,11 +396,11 @@ rules_stats() // 获取统计
391
396
 
392
397
  ```javascript
393
398
  // 注册的工具
394
- schedule_cron(expression, task) // 创建 Cron 任务
395
- schedule_once(datetime, task) // 创建一次性任务
396
- schedule_list() // 列出所有任务
397
- schedule_cancel(taskId) // 取消任务
398
- schedule_now(taskId) // 立即执行任务
399
+ schedule_cron(expression, task); // 创建 Cron 任务
400
+ schedule_once(datetime, task); // 创建一次性任务
401
+ schedule_list(); // 列出所有任务
402
+ schedule_cancel(taskId); // 取消任务
403
+ schedule_now(taskId); // 立即执行任务
399
404
  ```
400
405
 
401
406
  ### 4.12 子 Agent 插件 (subagent-plugin)
@@ -405,12 +410,12 @@ schedule_now(taskId) // 立即执行任务
405
410
  **方式1:配置 `this.agents = []` 自动注册**
406
411
 
407
412
  ```javascript
408
- const { Plugin } = require('../src/core/plugin-base')
409
- const { tool } = require('ai')
410
- const { z } = require('zod')
413
+ const { Plugin } = require('../src/core/plugin-base');
414
+ const { tool } = require('ai');
415
+ const { z } = require('zod');
411
416
 
412
417
  class MyPlugin extends Plugin {
413
- name = 'my-plugin'
418
+ name = 'my-plugin';
414
419
 
415
420
  // 配置式注册子Agent,插件启动时自动创建
416
421
  agents = [
@@ -423,23 +428,23 @@ class MyPlugin extends Plugin {
423
428
  description: '编译代码',
424
429
  parameters: z.object({
425
430
  language: z.string(),
426
- code: z.string()
431
+ code: z.string(),
427
432
  }),
428
- execute: async (args) => ({ success: true })
429
- })
433
+ execute: async (args) => ({ success: true }),
434
+ }),
430
435
  },
431
- parentTools: ['read_file', 'write_file'] // 从父Agent继承的工具
432
- }
433
- ]
436
+ parentTools: ['read_file', 'write_file'], // 从父Agent继承的工具
437
+ },
438
+ ];
434
439
  }
435
440
  ```
436
441
 
437
442
  **方式2:手动调用 `this.registerSubAgent()`**
438
443
 
439
444
  ```javascript
440
- const { Plugin } = require('../src/core/plugin-base')
441
- const { tool } = require('ai')
442
- const { z } = require('zod')
445
+ const { Plugin } = require('../src/core/plugin-base');
446
+ const { tool } = require('ai');
447
+ const { z } = require('zod');
443
448
 
444
449
  class MyPlugin extends Plugin {
445
450
  start(framework) {
@@ -451,24 +456,24 @@ class MyPlugin extends Plugin {
451
456
  compile: tool({
452
457
  description: '编译代码',
453
458
  parameters: z.object({ language: z.string(), code: z.string() }),
454
- execute: async (args) => ({ success: true })
455
- })
459
+ execute: async (args) => ({ success: true }),
460
+ }),
456
461
  },
457
- parentTools: ['read_file']
458
- })
462
+ parentTools: ['read_file'],
463
+ });
459
464
  }
460
465
  }
461
466
  ```
462
467
 
463
468
  **子Agent配置说明:**
464
469
 
465
- | 字段 | 类型 | 说明 |
466
- |------|------|------|
467
- | `name` | string | 子Agent名称(唯一标识) |
468
- | `role` | string | 角色描述 |
469
- | `description` | string | 详细描述(供主Agent智能选择) |
470
- | `tools` | object | 自定义工具 `{ name: toolDef }`,只属于此子Agent |
471
- | `parentTools` | array | 从父Agent继承的工具名称列表 |
470
+ | 字段 | 类型 | 说明 |
471
+ | ------------- | ------ | ----------------------------------------------- |
472
+ | `name` | string | 子Agent名称(唯一标识) |
473
+ | `role` | string | 角色描述 |
474
+ | `description` | string | 详细描述(供主Agent智能选择) |
475
+ | `tools` | object | 自定义工具 `{ name: toolDef }`,只属于此子Agent |
476
+ | `parentTools` | array | 从父Agent继承的工具名称列表 |
472
477
 
473
478
  ### 4.13 技能管理器 (skill-manager)
474
479
 
@@ -476,7 +481,7 @@ class MyPlugin extends Plugin {
476
481
 
477
482
  ```javascript
478
483
  // 注册的工具
479
- loadSkill(skill) // 加载指定技能
484
+ loadSkill(skill); // 加载指定技能
480
485
 
481
486
  // 技能存放在 skills/ 或 .agent/skills/ 目录
482
487
  ```
@@ -487,36 +492,38 @@ loadSkill(skill) // 加载指定技能
487
492
 
488
493
  ```javascript
489
494
  // 配置
490
- await framework.loadPlugin(new EmailPlugin({
491
- smtp_host: 'smtp.gmail.com',
492
- smtp_port: 587,
493
- smtp_secure: false,
494
- smtp_user: 'your-email@gmail.com',
495
- smtp_pass: 'your-app-password',
496
- imap_host: 'imap.gmail.com',
497
- imap_port: 993,
498
- imap_user: 'your-email@gmail.com',
499
- imap_pass: 'your-app-password',
500
- from_email: 'your-email@gmail.com'
501
- }))
495
+ await framework.loadPlugin(
496
+ new EmailPlugin({
497
+ smtp_host: 'smtp.gmail.com',
498
+ smtp_port: 587,
499
+ smtp_secure: false,
500
+ smtp_user: 'your-email@gmail.com',
501
+ smtp_pass: 'your-app-password',
502
+ imap_host: 'imap.gmail.com',
503
+ imap_port: 993,
504
+ imap_user: 'your-email@gmail.com',
505
+ imap_pass: 'your-app-password',
506
+ from_email: 'your-email@gmail.com',
507
+ })
508
+ );
502
509
 
503
510
  // 或通过工具配置
504
511
  email_configure({
505
512
  smtp_host: 'smtp.gmail.com',
506
513
  smtp_user: 'your-email@gmail.com',
507
- smtp_pass: 'your-app-password'
508
- })
514
+ smtp_pass: 'your-app-password',
515
+ });
509
516
  ```
510
517
 
511
518
  **注册的工具:**
512
519
 
513
- | 工具 | 说明 |
514
- |------|------|
515
- | `email_send` | 发送电子邮件 |
516
- | `email_read` | 读取电子邮件(IMAP) |
517
- | `email_unread_count` | 获取未读邮件数量 |
518
- | `email_mark_read` | 标记邮件为已读 |
519
- | `email_configure` | 配置邮箱连接参数 |
520
+ | 工具 | 说明 |
521
+ | -------------------- | -------------------- |
522
+ | `email_send` | 发送电子邮件 |
523
+ | `email_read` | 读取电子邮件(IMAP) |
524
+ | `email_unread_count` | 获取未读邮件数量 |
525
+ | `email_mark_read` | 标记邮件为已读 |
526
+ | `email_configure` | 配置邮箱连接参数 |
520
527
 
521
528
  ```javascript
522
529
  // 发送邮件
@@ -524,22 +531,22 @@ email_send({
524
531
  to: 'recipient@example.com',
525
532
  subject: '主题',
526
533
  body: '正文内容',
527
- cc: 'cc@example.com', // 可选
528
- isHtml: false
529
- })
534
+ cc: 'cc@example.com', // 可选
535
+ isHtml: false,
536
+ });
530
537
 
531
538
  // 读取邮件
532
539
  email_read({
533
540
  box: 'INBOX',
534
541
  limit: 10,
535
- unreadOnly: false
536
- })
542
+ unreadOnly: false,
543
+ });
537
544
 
538
545
  // 获取未读数量
539
- email_unread_count({ box: 'INBOX' })
546
+ email_unread_count({ box: 'INBOX' });
540
547
 
541
548
  // 标记为已读
542
- email_mark_read({ messageId: '12345' })
549
+ email_mark_read({ messageId: '12345' });
543
550
  ```
544
551
 
545
552
  ### 4.15 Telegram 插件 (telegram-plugin)
@@ -548,13 +555,15 @@ Telegram 对话插件,绑定主 Agent 进行持续对话。
548
555
 
549
556
  ```javascript
550
557
  // 配置
551
- await framework.loadPlugin(new TelegramPlugin({
552
- botToken: 'YOUR_BOT_TOKEN', // 必需
553
- allowedChats: ['123456789'], // 可选:允许的聊天ID
554
- groupMode: false, // 可选:是否启用群组模式
555
- prefix: '/', // 可选:命令前缀
556
- systemPrompt: '你是一个有帮助的AI助手。'
557
- }))
558
+ await framework.loadPlugin(
559
+ new TelegramPlugin({
560
+ botToken: 'YOUR_BOT_TOKEN', // 必需
561
+ allowedChats: ['123456789'], // 可选:允许的聊天ID
562
+ groupMode: false, // 可选:是否启用群组模式
563
+ prefix: '/', // 可选:命令前缀
564
+ systemPrompt: '你是一个有帮助的AI助手。',
565
+ })
566
+ );
558
567
  ```
559
568
 
560
569
  **功能特性:**
@@ -567,10 +576,10 @@ await framework.loadPlugin(new TelegramPlugin({
567
576
 
568
577
  **命令:**
569
578
 
570
- | 命令 | 说明 |
571
- |------|------|
572
- | `/start` | 显示帮助信息 |
573
- | `/clear` | 清除对话历史 |
579
+ | 命令 | 说明 |
580
+ | ---------- | ------------ |
581
+ | `/start` | 显示帮助信息 |
582
+ | `/clear` | 清除对话历史 |
574
583
  | `/history` | 查看对话状态 |
575
584
 
576
585
  ### 4.16 插件管理扩展
@@ -579,10 +588,10 @@ await framework.loadPlugin(new TelegramPlugin({
579
588
 
580
589
  ```javascript
581
590
  // 启用插件
582
- await framework.enablePlugin('telegram')
591
+ await framework.enablePlugin('telegram');
583
592
 
584
593
  // 禁用插件
585
- await framework.disablePlugin('telegram')
594
+ await framework.disablePlugin('telegram');
586
595
  ```
587
596
 
588
597
  #### 插件配置更新
@@ -593,17 +602,18 @@ await framework.executeTool('update_plugin_config', {
593
602
  name: 'telegram',
594
603
  config: {
595
604
  allowedChats: ['123456789', '987654321'],
596
- groupMode: true
597
- }
598
- })
605
+ groupMode: true,
606
+ },
607
+ });
599
608
 
600
609
  // 获取插件当前配置
601
610
  await framework.executeTool('get_plugin_config', {
602
- name: 'telegram'
603
- })
611
+ name: 'telegram',
612
+ });
604
613
  ```
605
614
 
606
615
  **配置持久化:**
616
+
607
617
  - 插件的 `enabled` 状态和 `config` 会自动保存到 `.agent/data/plugins-state.json`
608
618
  - 重启后自动恢复配置
609
619
 
@@ -613,9 +623,9 @@ await framework.executeTool('get_plugin_config', {
613
623
 
614
624
  ### 5.1 插件存放位置
615
625
 
616
- | 位置 | 说明 | 加载方式 |
617
- |------|------|----------|
618
- | `plugins/` | 内置插件 | 框架初始化时加载 |
626
+ | 位置 | 说明 | 加载方式 |
627
+ | ----------------- | -------- | -------------------- |
628
+ | `plugins/` | 内置插件 | 框架初始化时加载 |
619
629
  | `.agent/plugins/` | 用户插件 | Bootstrap 时自动加载 |
620
630
 
621
631
  ### 5.2 开发步骤
@@ -628,17 +638,17 @@ await framework.executeTool('get_plugin_config', {
628
638
 
629
639
  ```javascript
630
640
  // .agent/plugins/system-info.js
631
- const { Plugin } = require('../../src/core/plugin-base')
632
- const os = require('os')
633
- const { z } = require('zod')
641
+ const { Plugin } = require('../../src/core/plugin-base');
642
+ const os = require('os');
643
+ const { z } = require('zod');
634
644
 
635
645
  class SystemInfoPlugin extends Plugin {
636
646
  constructor() {
637
- super()
638
- this.name = 'system-info'
639
- this.version = '1.0.0'
640
- this.description = '系统信息查看插件'
641
- this.priority = 5
647
+ super();
648
+ this.name = 'system-info';
649
+ this.version = '1.0.0';
650
+ this.description = '系统信息查看插件';
651
+ this.priority = 5;
642
652
  }
643
653
 
644
654
  start(framework) {
@@ -652,47 +662,47 @@ class SystemInfoPlugin extends Plugin {
652
662
  hostname: os.hostname(),
653
663
  arch: os.arch(),
654
664
  homedir: os.homedir(),
655
- cwd: process.cwd()
656
- }
657
- }
658
- })
665
+ cwd: process.cwd(),
666
+ };
667
+ },
668
+ });
659
669
 
660
670
  framework.registerTool({
661
671
  name: 'get_memory_usage',
662
672
  description: '获取内存使用情况',
663
673
  inputSchema: z.object({}),
664
674
  execute: async () => {
665
- const total = os.totalmem()
666
- const free = os.freemem()
667
- const used = total - free
675
+ const total = os.totalmem();
676
+ const free = os.freemem();
677
+ const used = total - free;
668
678
  return {
669
679
  total: `${(total / 1024 / 1024 / 1024).toFixed(2)} GB`,
670
680
  used: `${(used / 1024 / 1024 / 1024).toFixed(2)} GB`,
671
681
  free: `${(free / 1024 / 1024 / 1024).toFixed(2)} GB`,
672
- percent: `${((used / total) * 100).toFixed(1)}%`
673
- }
674
- }
675
- })
682
+ percent: `${((used / total) * 100).toFixed(1)}%`,
683
+ };
684
+ },
685
+ });
676
686
 
677
- return this
687
+ return this;
678
688
  }
679
689
  }
680
690
 
681
- module.exports = SystemInfoPlugin
691
+ module.exports = SystemInfoPlugin;
682
692
  ```
683
693
 
684
694
  ### 5.4 免引入写法
685
695
 
686
696
  ```javascript
687
697
  // .agent/plugins/my-plugin.js
688
- const { z } = require('zod')
698
+ const { z } = require('zod');
689
699
 
690
- module.exports = function(Plugin) {
700
+ module.exports = function (Plugin) {
691
701
  return class extends Plugin {
692
702
  constructor() {
693
- super()
694
- this.name = 'my-plugin'
695
- this.description = '我的插件'
703
+ super();
704
+ this.name = 'my-plugin';
705
+ this.description = '我的插件';
696
706
  }
697
707
 
698
708
  start(framework) {
@@ -700,16 +710,16 @@ module.exports = function(Plugin) {
700
710
  name: 'hello',
701
711
  description: '打招呼',
702
712
  inputSchema: z.object({
703
- name: z.string().describe('姓名')
713
+ name: z.string().describe('姓名'),
704
714
  }),
705
715
  execute: async (args) => {
706
- return `Hello, ${args.name}!`
707
- }
708
- })
709
- return this
716
+ return `Hello, ${args.name}!`;
717
+ },
718
+ });
719
+ return this;
710
720
  }
711
- }
712
- }
721
+ };
722
+ };
713
723
  ```
714
724
 
715
725
  ---
@@ -718,10 +728,10 @@ module.exports = function(Plugin) {
718
728
 
719
729
  ### 6.1 技能目录
720
730
 
721
- | 位置 | 说明 |
722
- |------|------|
723
- | `skills/` | 项目级技能 |
724
- | `.agent/skills/` | Agent 专属技能 |
731
+ | 位置 | 说明 |
732
+ | ------------------- | -------------------- |
733
+ | `skills/` | 项目级技能 |
734
+ | `.agent/skills/` | Agent 专属技能 |
725
735
  | `~/.agents/skills/` | 全局技能(未来支持) |
726
736
 
727
737
  ### 6.2 技能格式
@@ -789,12 +799,14 @@ Agent: [获取插件开发指南后,按照指南创建插件]
789
799
 
790
800
  ```javascript
791
801
  // 创建子 Agent
792
- await framework.loadPlugin(new SubAgentPlugin({
793
- name: 'code-agent',
794
- role: '代码专家',
795
- description: '负责代码开发、调试和重构',
796
- tools: ['read_file', 'write_file', 'execute_command']
797
- }))
802
+ await framework.loadPlugin(
803
+ new SubAgentPlugin({
804
+ name: 'code-agent',
805
+ role: '代码专家',
806
+ description: '负责代码开发、调试和重构',
807
+ tools: ['read_file', 'write_file', 'execute_command'],
808
+ })
809
+ );
798
810
 
799
811
  // 主 Agent 自动获得 code-agent 工具
800
812
  // 使用: "帮我写一个排序算法"
@@ -805,14 +817,18 @@ await framework.loadPlugin(new SubAgentPlugin({
805
817
 
806
818
  ```markdown
807
819
  【子 Agent 分配规则 - 必须遵守】
820
+
808
821
  1. 每个子Agent有固定的专业领域,必须委托给对应的专家:
809
- - code-agent: 代码专家
810
- - data-agent: 数据专家
822
+
823
+ - code-agent: 代码专家
824
+ - data-agent: 数据专家
825
+
811
826
  2. 你需要对任务进行拆分,传递给对应的子Agent执行。
812
827
 
813
828
  【可委托的子 Agent】
814
- - code-agent: 代码专家
815
- - data-agent: 数据专家
829
+
830
+ - code-agent: 代码专家
831
+ - data-agent: 数据专家
816
832
 
817
833
  使用相应子Agent名称的工具将任务委托给相应子代理。
818
834
  ```
@@ -824,6 +840,7 @@ await framework.loadPlugin(new SubAgentPlugin({
824
840
  ### 8.1 问题
825
841
 
826
842
  44 个工具全部传给 LLM 会:
843
+
827
844
  - 消耗大量 token
828
845
  - 降低推理速度
829
846
  - 增加成本
@@ -835,18 +852,18 @@ await framework.loadPlugin(new SubAgentPlugin({
835
852
  ```javascript
836
853
  const agent = framework.createAgent({
837
854
  name: 'MyAgent',
838
- enableToolRouting: true // 默认启用
839
- })
855
+ enableToolRouting: true, // 默认启用
856
+ });
840
857
  ```
841
858
 
842
859
  ### 8.3 意图分类
843
860
 
844
- | 意图 | 关键词 | 工具 |
845
- |------|--------|------|
846
- | file_operation | 文件、读取、写入 | read_file, write_file, ... |
847
- | code_development | 代码、开发、插件 | loadSkill, read_file, ... |
848
- | system_info | 系统、信息、内存 | get_system_info, ... |
849
- | plugin_management | 插件、重载 | reload_plugins, list_plugins |
861
+ | 意图 | 关键词 | 工具 |
862
+ | ----------------- | ---------------- | ---------------------------- |
863
+ | file_operation | 文件、读取、写入 | read_file, write_file, ... |
864
+ | code_development | 代码、开发、插件 | loadSkill, read_file, ... |
865
+ | system_info | 系统、信息、内存 | get_system_info, ... |
866
+ | plugin_management | 插件、重载 | reload_plugins, list_plugins |
850
867
 
851
868
  ### 8.4 工作原理
852
869
 
@@ -913,209 +930,209 @@ Foliko 基于 EventEmitter,提供完整的事件系统。
913
930
  ```javascript
914
931
  // 监听事件
915
932
  agent.on('eventName', (data) => {
916
- console.log('事件触发:', data)
917
- })
933
+ console.log('事件触发:', data);
934
+ });
918
935
 
919
936
  // 监听一次
920
937
  agent.once('eventName', (data) => {
921
- console.log('只触发一次')
922
- })
938
+ console.log('只触发一次');
939
+ });
923
940
 
924
941
  // 移除监听
925
- agent.off('eventName', handler)
942
+ agent.off('eventName', handler);
926
943
 
927
944
  // 触发事件
928
- agent.emit('eventName', { key: 'value' })
945
+ agent.emit('eventName', { key: 'value' });
929
946
  ```
930
947
 
931
948
  ### 10.2 Framework 事件
932
949
 
933
- | 事件名 | 参数 | 说明 |
934
- |--------|------|------|
935
- | `framework:ready` | `framework` | 框架就绪 |
936
- | `framework:destroyed` | - | 框架销毁 |
937
- | `plugin:registered` | `plugin` | 插件注册 |
938
- | `plugin:loaded` | `plugin` | 插件加载完成 |
939
- | `plugin:unloaded` | `plugin` | 插件卸载 |
940
- | `plugin:reloaded` | `plugin` | 插件重载 |
941
- | `plugin:enabled` | `plugin` | 插件启用 |
942
- | `plugin:disabled` | `plugin` | 插件禁用 |
943
- | `tool:registered` | `tool` | 工具注册 |
944
- | `agent:created` | `agent` | Agent 创建 |
950
+ | 事件名 | 参数 | 说明 |
951
+ | --------------------- | ----------- | ------------ |
952
+ | `framework:ready` | `framework` | 框架就绪 |
953
+ | `framework:destroyed` | - | 框架销毁 |
954
+ | `plugin:registered` | `plugin` | 插件注册 |
955
+ | `plugin:loaded` | `plugin` | 插件加载完成 |
956
+ | `plugin:unloaded` | `plugin` | 插件卸载 |
957
+ | `plugin:reloaded` | `plugin` | 插件重载 |
958
+ | `plugin:enabled` | `plugin` | 插件启用 |
959
+ | `plugin:disabled` | `plugin` | 插件禁用 |
960
+ | `tool:registered` | `tool` | 工具注册 |
961
+ | `agent:created` | `agent` | Agent 创建 |
945
962
 
946
963
  ```javascript
947
964
  framework.on('framework:ready', (fw) => {
948
- console.log('框架就绪')
949
- })
965
+ console.log('框架就绪');
966
+ });
950
967
 
951
968
  framework.on('plugin:loaded', (plugin) => {
952
- console.log('插件已加载:', plugin.name)
953
- })
969
+ console.log('插件已加载:', plugin.name);
970
+ });
954
971
 
955
972
  framework.on('tool:registered', (tool) => {
956
- console.log('工具已注册:', tool.name)
957
- })
973
+ console.log('工具已注册:', tool.name);
974
+ });
958
975
  ```
959
976
 
960
977
  ### 10.3 Agent 事件
961
978
 
962
- | 事件名 | 参数 | 说明 |
963
- |--------|------|------|
964
- | `status` | `{ status }` | 状态变化:`idle`/`busy`/`error` |
965
- | `message` | `msg` | 非流式消息响应 |
966
- | `chunk` | `chunk` | 流式响应片段 |
967
- | `tool-call` | `{ name, args }` | 工具调用 |
968
- | `tool-result` | `{ name, args, result }` | 工具结果 |
969
- | `error` | `{ error }` | 错误发生 |
970
- | `destroyed` | - | Agent 销毁 |
979
+ | 事件名 | 参数 | 说明 |
980
+ | ------------- | ------------------------ | ------------------------------- |
981
+ | `status` | `{ status }` | 状态变化:`idle`/`busy`/`error` |
982
+ | `message` | `msg` | 非流式消息响应 |
983
+ | `chunk` | `chunk` | 流式响应片段 |
984
+ | `tool-call` | `{ name, args }` | 工具调用 |
985
+ | `tool-result` | `{ name, args, result }` | 工具结果 |
986
+ | `error` | `{ error }` | 错误发生 |
987
+ | `destroyed` | - | Agent 销毁 |
971
988
 
972
989
  ```javascript
973
990
  // 状态监听
974
991
  agent.on('status', ({ status }) => {
975
- console.log('Agent 状态:', status)
976
- })
992
+ console.log('Agent 状态:', status);
993
+ });
977
994
 
978
995
  // 流式输出
979
996
  agent.on('chunk', (chunk) => {
980
997
  if (chunk.type === 'text') {
981
- process.stdout.write(chunk.text)
998
+ process.stdout.write(chunk.text);
982
999
  }
983
- })
1000
+ });
984
1001
 
985
1002
  // 工具调用
986
1003
  agent.on('tool-call', ({ name, args }) => {
987
- console.log('调用工具:', name, args)
988
- })
1004
+ console.log('调用工具:', name, args);
1005
+ });
989
1006
 
990
1007
  agent.on('tool-result', ({ name, result }) => {
991
- console.log('工具结果:', name, result)
992
- })
1008
+ console.log('工具结果:', name, result);
1009
+ });
993
1010
 
994
1011
  // 错误处理
995
1012
  agent.on('error', ({ error }) => {
996
- console.error('Agent 错误:', error)
997
- })
1013
+ console.error('Agent 错误:', error);
1014
+ });
998
1015
  ```
999
1016
 
1000
1017
  ### 10.4 子 Agent 事件
1001
1018
 
1002
- | 事件名 | 参数 | 说明 |
1003
- |--------|------|------|
1004
- | `subagent:chat:start` | `{ parentAgent, subAgent, subAgentName, task }` | 子 Agent 开始处理 |
1005
- | `subagent:chat:end` | `{ parentAgent, subAgent, subAgentName, result }` | 子 Agent 完成 |
1006
- | `subagent:chunk` | `{ parentAgent, subAgent, subAgentName, chunk }` | 子 Agent 流式输出 |
1007
- | `subagent:error` | `{ parentAgent, subAgent, subAgentName, error }` | 子 Agent 错误 |
1019
+ | 事件名 | 参数 | 说明 |
1020
+ | --------------------- | ------------------------------------------------- | ----------------- |
1021
+ | `subagent:chat:start` | `{ parentAgent, subAgent, subAgentName, task }` | 子 Agent 开始处理 |
1022
+ | `subagent:chat:end` | `{ parentAgent, subAgent, subAgentName, result }` | 子 Agent 完成 |
1023
+ | `subagent:chunk` | `{ parentAgent, subAgent, subAgentName, chunk }` | 子 Agent 流式输出 |
1024
+ | `subagent:error` | `{ parentAgent, subAgent, subAgentName, error }` | 子 Agent 错误 |
1008
1025
 
1009
1026
  ```javascript
1010
1027
  // 监听所有子 Agent 事件
1011
1028
  agent.on('subagent:chat:start', ({ subAgentName, task }) => {
1012
- console.log(`子 Agent ${subAgentName} 开始处理:`, task)
1013
- })
1029
+ console.log(`子 Agent ${subAgentName} 开始处理:`, task);
1030
+ });
1014
1031
 
1015
1032
  agent.on('subagent:chat:end', ({ subAgentName, result }) => {
1016
- console.log(`子 Agent ${subAgentName} 完成:`, result)
1017
- })
1033
+ console.log(`子 Agent ${subAgentName} 完成:`, result);
1034
+ });
1018
1035
 
1019
1036
  agent.on('subagent:chunk', ({ subAgentName, chunk }) => {
1020
- console.log(`子 Agent ${subAgentName} 输出:`, chunk)
1021
- })
1037
+ console.log(`子 Agent ${subAgentName} 输出:`, chunk);
1038
+ });
1022
1039
 
1023
1040
  agent.on('subagent:error', ({ subAgentName, error }) => {
1024
- console.error(`子 Agent ${subAgentName} 错误:`, error)
1025
- })
1041
+ console.error(`子 Agent ${subAgentName} 错误:`, error);
1042
+ });
1026
1043
  ```
1027
1044
 
1028
1045
  ### 10.5 工具执行事件
1029
1046
 
1030
- | 事件名 | 参数 | 说明 |
1031
- |--------|------|------|
1032
- | `tool:call` | `{ name, args }` | 工具被调用 |
1047
+ | 事件名 | 参数 | 说明 |
1048
+ | ------------- | ------------------------ | ------------ |
1049
+ | `tool:call` | `{ name, args }` | 工具被调用 |
1033
1050
  | `tool:result` | `{ name, args, result }` | 工具执行结果 |
1034
- | `tool:error` | `{ name, args, error }` | 工具执行错误 |
1051
+ | `tool:error` | `{ name, args, error }` | 工具执行错误 |
1035
1052
 
1036
1053
  ```javascript
1037
1054
  // 通过 toolRegistry 监听
1038
1055
  framework.toolRegistry.on('tool:call', ({ name, args }) => {
1039
- console.log('工具调用:', name, args)
1040
- })
1056
+ console.log('工具调用:', name, args);
1057
+ });
1041
1058
 
1042
1059
  framework.toolRegistry.on('tool:result', ({ name, result }) => {
1043
- console.log('工具结果:', name, result)
1044
- })
1060
+ console.log('工具结果:', name, result);
1061
+ });
1045
1062
 
1046
1063
  framework.toolRegistry.on('tool:error', ({ name, error }) => {
1047
- console.error('工具错误:', name, error)
1048
- })
1064
+ console.error('工具错误:', name, error);
1065
+ });
1049
1066
  ```
1050
1067
 
1051
1068
  ### 10.6 完整示例
1052
1069
 
1053
1070
  ```javascript
1054
- const { Framework } = require('./src')
1071
+ const { Framework } = require('./src');
1055
1072
 
1056
1073
  async function main() {
1057
- const framework = new Framework({ debug: false })
1058
- await framework.bootstrap({ agentDir: './.agent' })
1074
+ const framework = new Framework({ debug: false });
1075
+ await framework.bootstrap({ agentDir: './.agent' });
1059
1076
 
1060
1077
  const agent = framework.createAgent({
1061
1078
  name: 'MyAgent',
1062
- systemPrompt: '你是一个有帮助的助手。'
1063
- })
1079
+ systemPrompt: '你是一个有帮助的助手。',
1080
+ });
1064
1081
 
1065
1082
  // 监听所有事件
1066
1083
  framework.on('*', (event, ...args) => {
1067
- console.log(`[Framework Event] ${event}`)
1068
- })
1084
+ console.log(`[Framework Event] ${event}`);
1085
+ });
1069
1086
 
1070
1087
  agent.on('status', ({ status }) => {
1071
- console.log(`[Agent Status] ${status}`)
1072
- })
1088
+ console.log(`[Agent Status] ${status}`);
1089
+ });
1073
1090
 
1074
1091
  agent.on('tool-call', ({ name, args }) => {
1075
- console.log(`[Tool Call] ${name}:`, args)
1076
- })
1092
+ console.log(`[Tool Call] ${name}:`, args);
1093
+ });
1077
1094
 
1078
1095
  agent.on('subagent:*', (event, data) => {
1079
- console.log(`[SubAgent Event] ${event}:`, data)
1080
- })
1096
+ console.log(`[SubAgent Event] ${event}:`, data);
1097
+ });
1081
1098
 
1082
1099
  // 对话
1083
1100
  for await (const chunk of agent.chatStream('你好')) {
1084
1101
  if (chunk.type === 'text') {
1085
- process.stdout.write(chunk.text)
1102
+ process.stdout.write(chunk.text);
1086
1103
  }
1087
1104
  }
1088
1105
  }
1089
1106
 
1090
- main()
1107
+ main();
1091
1108
  ```
1092
1109
 
1093
1110
  ### 10.7 Chat Stream Chunk 类型
1094
1111
 
1095
1112
  `chatStream` 返回的 chunk 对象有以下类型:
1096
1113
 
1097
- | type | 字段 | 说明 |
1098
- |------|------|------|
1099
- | `text` | `text` | 文本片段 |
1100
- | `tool-call` | `toolName`, `args` | 工具调用 |
1114
+ | type | 字段 | 说明 |
1115
+ | ------------- | -------------------- | -------- |
1116
+ | `text` | `text` | 文本片段 |
1117
+ | `tool-call` | `toolName`, `args` | 工具调用 |
1101
1118
  | `tool-result` | `toolName`, `result` | 工具结果 |
1102
- | `error` | `error` | 错误信息 |
1119
+ | `error` | `error` | 错误信息 |
1103
1120
 
1104
1121
  ```javascript
1105
1122
  for await (const chunk of agent.chatStream('帮我读取文件')) {
1106
1123
  switch (chunk.type) {
1107
1124
  case 'text':
1108
- process.stdout.write(chunk.text)
1109
- break
1125
+ process.stdout.write(chunk.text);
1126
+ break;
1110
1127
  case 'tool-call':
1111
- console.log('调用:', chunk.toolName, chunk.args)
1112
- break
1128
+ console.log('调用:', chunk.toolName, chunk.args);
1129
+ break;
1113
1130
  case 'tool-result':
1114
- console.log('结果:', chunk.toolName, chunk.result)
1115
- break
1131
+ console.log('结果:', chunk.toolName, chunk.result);
1132
+ break;
1116
1133
  case 'error':
1117
- console.error('错误:', chunk.error)
1118
- break
1134
+ console.error('错误:', chunk.error);
1135
+ break;
1119
1136
  }
1120
1137
  }
1121
1138
  ```
@@ -1128,74 +1145,78 @@ for await (const chunk of agent.chatStream('帮我读取文件')) {
1128
1145
 
1129
1146
  ```javascript
1130
1147
  // 创建框架
1131
- const framework = new Framework({ debug: false })
1148
+ const framework = new Framework({ debug: false });
1132
1149
 
1133
1150
  // Bootstrap(加载所有配置和插件)
1134
1151
  await framework.bootstrap({
1135
1152
  agentDir: './.agent',
1136
- aiConfig: { provider, model, apiKey }
1137
- })
1153
+ aiConfig: { provider, model, apiKey },
1154
+ });
1138
1155
 
1139
1156
  // 创建 Agent
1140
1157
  const agent = framework.createAgent({
1141
- name, systemPrompt, sharedPrompt, metadata, enableToolRouting
1142
- })
1158
+ name,
1159
+ systemPrompt,
1160
+ sharedPrompt,
1161
+ metadata,
1162
+ enableToolRouting,
1163
+ });
1143
1164
 
1144
1165
  // 注册/加载插件
1145
- await framework.loadPlugin(plugin)
1146
- await framework.reloadPlugin(name)
1147
- await framework.reloadAllPlugins()
1166
+ await framework.loadPlugin(plugin);
1167
+ await framework.reloadPlugin(name);
1168
+ await framework.reloadAllPlugins();
1148
1169
 
1149
1170
  // 启用/禁用插件
1150
- await framework.enablePlugin(name)
1151
- await framework.disablePlugin(name)
1171
+ await framework.enablePlugin(name);
1172
+ await framework.disablePlugin(name);
1152
1173
 
1153
1174
  // 更新插件配置
1154
- framework.updatePluginConfig(name, config)
1175
+ framework.updatePluginConfig(name, config);
1155
1176
 
1156
1177
  // 执行工具
1157
- const result = await framework.executeTool(name, args)
1178
+ const result = await framework.executeTool(name, args);
1158
1179
 
1159
1180
  // 获取插件/工具
1160
- const plugin = framework.pluginManager.get(name)
1161
- const tools = framework.getTools()
1181
+ const plugin = framework.pluginManager.get(name);
1182
+ const tools = framework.getTools();
1162
1183
 
1163
1184
  // 销毁
1164
- await framework.destroy()
1185
+ await framework.destroy();
1165
1186
  ```
1166
1187
 
1167
1188
  ### 11.2 Agent
1168
1189
 
1169
1190
  ```javascript
1170
1191
  // 创建(在 framework.createAgent() 后)
1171
- const agent = framework.createAgent(config)
1192
+ const agent = framework.createAgent(config);
1172
1193
 
1173
1194
  // 发送消息
1174
- const result = await agent.chat(message)
1195
+ const result = await agent.chat(message);
1175
1196
  for await (const chunk of agent.chatStream(message)) {
1176
1197
  // chunk.type: 'text' | 'tool-call' | 'tool-result' | 'error'
1177
1198
  }
1178
1199
 
1179
1200
  // 注册工具
1180
- agent.registerTool(toolDef)
1201
+ agent.registerTool(toolDef);
1181
1202
 
1182
1203
  // 子 Agent
1183
- agent.registerSubAgent(name, agent, role, goal)
1184
- agent.getSubAgents()
1204
+ agent.registerSubAgent(name, agent, role, goal);
1205
+ agent.getSubAgents();
1185
1206
 
1186
1207
  // 元数据
1187
- agent.setMetadata(key, value)
1188
- agent.getMetadata(key)
1208
+ agent.setMetadata(key, value);
1209
+ agent.getMetadata(key);
1189
1210
 
1190
1211
  // 状态
1191
- agent.getStatus() // 'idle' | 'busy' | 'error'
1192
- agent.resetStatus() // 重置状态
1212
+ agent.getStatus(); // 'idle' | 'busy' | 'error'
1213
+ agent.resetStatus(); // 重置状态
1193
1214
 
1194
1215
  // 清空历史
1195
- agent.clearHistory()
1216
+ agent.clearHistory();
1196
1217
 
1197
1218
  // 销毁
1198
- agent.destroy()
1219
+ agent.destroy();
1199
1220
  ```
1200
1221
 
1201
1222
  ### 11.3 Plugin
@@ -1203,17 +1224,25 @@ agent.destroy()
1203
1224
  ```javascript
1204
1225
  class MyPlugin extends Plugin {
1205
1226
  constructor() {
1206
- super()
1207
- this.name = 'my-plugin'
1208
- this.version = '1.0.0'
1209
- this.description = '我的插件'
1210
- this.priority = 10
1227
+ super();
1228
+ this.name = 'my-plugin';
1229
+ this.version = '1.0.0';
1230
+ this.description = '我的插件';
1231
+ this.priority = 10;
1211
1232
  }
1212
1233
 
1213
- install(framework) { /* 安装 */ return this }
1214
- start(framework) { /* 启动 */ return this }
1215
- reload(framework) { /* 重载 */ return this }
1216
- uninstall(framework) { /* 卸载 */ return this }
1234
+ install(framework) {
1235
+ /* 安装 */ return this;
1236
+ }
1237
+ start(framework) {
1238
+ /* 启动 */ return this;
1239
+ }
1240
+ reload(framework) {
1241
+ /* 重载 */ return this;
1242
+ }
1243
+ uninstall(framework) {
1244
+ /* 卸载 */ return this;
1245
+ }
1217
1246
  }
1218
1247
  ```
1219
1248
 
@@ -1242,82 +1271,84 @@ class MyPlugin extends Plugin {
1242
1271
  ### 基础对话
1243
1272
 
1244
1273
  ```javascript
1245
- const { Framework } = require('./src')
1274
+ const { Framework } = require('./src');
1246
1275
 
1247
1276
  async function main() {
1248
- const framework = new Framework()
1249
- await framework.bootstrap({ agentDir: './.agent' })
1277
+ const framework = new Framework();
1278
+ await framework.bootstrap({ agentDir: './.agent' });
1250
1279
 
1251
1280
  const agent = framework.createAgent({
1252
- systemPrompt: '你是一个有帮助的助手。'
1253
- })
1281
+ systemPrompt: '你是一个有帮助的助手。',
1282
+ });
1254
1283
 
1255
- const result = await agent.chat('你好')
1256
- console.log(result.message)
1284
+ const result = await agent.chat('你好');
1285
+ console.log(result.message);
1257
1286
  }
1258
1287
 
1259
- main()
1288
+ main();
1260
1289
  ```
1261
1290
 
1262
1291
  ### 带工具的对话
1263
1292
 
1264
1293
  ```javascript
1265
- const { Framework } = require('./src')
1294
+ const { Framework } = require('./src');
1266
1295
 
1267
1296
  async function main() {
1268
- const framework = new Framework()
1269
- await framework.bootstrap({ agentDir: './.agent' })
1297
+ const framework = new Framework();
1298
+ await framework.bootstrap({ agentDir: './.agent' });
1270
1299
 
1271
1300
  const agent = framework.createAgent({
1272
- systemPrompt: '你是一个有帮助的助手,擅长文件操作。'
1273
- })
1301
+ systemPrompt: '你是一个有帮助的助手,擅长文件操作。',
1302
+ });
1274
1303
 
1275
1304
  for await (const chunk of agent.chatStream('帮我读取 package.json')) {
1276
- if (chunk.type === 'text') process.stdout.write(chunk.text)
1277
- if (chunk.type === 'tool-call') console.log('调用工具:', chunk.toolName)
1278
- if (chunk.type === 'tool-result') console.log('结果:', chunk.result)
1305
+ if (chunk.type === 'text') process.stdout.write(chunk.text);
1306
+ if (chunk.type === 'tool-call') console.log('调用工具:', chunk.toolName);
1307
+ if (chunk.type === 'tool-result') console.log('结果:', chunk.result);
1279
1308
  }
1280
1309
  }
1281
1310
 
1282
- main()
1311
+ main();
1283
1312
  ```
1284
1313
 
1285
1314
  ### 子 Agent 分工
1286
1315
 
1287
1316
  ```javascript
1288
- const { Framework } = require('./src')
1289
- const { SubAgentPlugin } = require('./plugins/subagent-plugin')
1317
+ const { Framework } = require('./src');
1318
+ const { SubAgentPlugin } = require('./plugins/subagent-plugin');
1290
1319
 
1291
1320
  async function main() {
1292
- const framework = new Framework()
1293
- await framework.bootstrap({ agentDir: './.agent' })
1321
+ const framework = new Framework();
1322
+ await framework.bootstrap({ agentDir: './.agent' });
1294
1323
 
1295
1324
  // 创建主 Agent
1296
1325
  const mainAgent = framework.createAgent({
1297
- systemPrompt: '你是主 Agent,负责协调子 Agent 工作。'
1298
- })
1326
+ systemPrompt: '你是主 Agent,负责协调子 Agent 工作。',
1327
+ });
1299
1328
 
1300
1329
  // 添加子 Agent
1301
- await framework.loadPlugin(new SubAgentPlugin({
1302
- name: 'code-agent',
1303
- role: '代码专家',
1304
- description: '负责代码开发',
1305
- tools: {
1306
- compile: {
1307
- description: '编译代码',
1308
- inputSchema: z.object({ language: z.string(), code: z.string() }),
1309
- execute: async (args) => ({ success: true })
1310
- }
1311
- },
1312
- parentTools: ['read_file', 'write_file']
1313
- }))
1330
+ await framework.loadPlugin(
1331
+ new SubAgentPlugin({
1332
+ name: 'code-agent',
1333
+ role: '代码专家',
1334
+ description: '负责代码开发',
1335
+ tools: {
1336
+ compile: {
1337
+ description: '编译代码',
1338
+ inputSchema: z.object({ language: z.string(), code: z.string() }),
1339
+ execute: async (args) => ({ success: true }),
1340
+ },
1341
+ },
1342
+ parentTools: ['read_file', 'write_file'],
1343
+ })
1344
+ );
1314
1345
 
1315
1346
  // 对话
1316
- const result = await mainAgent.chat('帮我创建一个 Hello World 程序')
1317
- console.log(result.message)
1347
+ const result = await mainAgent.chat('帮我创建一个 Hello World 程序');
1348
+ console.log(result.message);
1318
1349
  }
1319
1350
 
1320
- main()
1351
+ main();
1321
1352
  ```
1322
1353
 
1323
1354
  ---
@@ -1327,7 +1358,7 @@ main()
1327
1358
  ### Q: 如何调试插件?
1328
1359
 
1329
1360
  ```javascript
1330
- const framework = new Framework({ debug: true })
1361
+ const framework = new Framework({ debug: true });
1331
1362
  ```
1332
1363
 
1333
1364
  ### Q: MCP 连接失败怎么办?