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
@@ -0,0 +1,237 @@
1
+ ---
2
+ name: subagent-guide
3
+ description: Guide to creating and using subagents in Foliko. Use when creating new subagents or delegating tasks to subagents.
4
+ ---
5
+
6
+ # SubAgent 子代理指南
7
+
8
+ 本文档介绍如何在 Foliko 框架中创建和使用子代理(SubAgent)。
9
+
10
+ ---
11
+
12
+ ## 什么是子代理?
13
+
14
+ 子代理是具有独立工具集和系统提示词的专用 AI Agent,用于分工处理不同领域的任务。
15
+
16
+ 主代理(MainAgent)负责任务分发,将专业任务委托给最匹配的子代理处理。
17
+
18
+ ---
19
+
20
+ ## 子代理文件位置
21
+
22
+ 所有子代理配置位于 `.agent/agents/` 目录下:
23
+
24
+ ```
25
+ .agent/agents/
26
+ ├── backend-specialist.md # 后端开发专家
27
+ ├── frontend-specialist.md # 前端开发专家
28
+ ├── database-architect.md # 数据库架构师
29
+ ├── debugger.md # 调试专家
30
+ ├── explorer-agent.md # 代码探索专家
31
+ ├── orchestrator.md # 任务编排专家
32
+ └── ... # 更多子代理
33
+ ```
34
+
35
+ ---
36
+
37
+ ## 创建新的子代理
38
+
39
+ ### 步骤 1:创建 md 文件
40
+
41
+ 在 `.agent/agents/` 目录下创建一个新的 `.md` 文件,文件名即为子代理名称。
42
+
43
+ **示例**:`my-agent.md`
44
+
45
+ ### 步骤 2:编写 frontmatter
46
+
47
+ 文件开头使用 YAML frontmatter 定义元数据:
48
+
49
+ ```yaml
50
+ ---
51
+ name: my-agent
52
+ description: 简短的能力描述,用于主代理智能选择。说明何时触发此代理。
53
+ tools: Read, Grep, Glob, Bash
54
+ skills: clean-code, architecture
55
+ model: inherit
56
+ ---
57
+
58
+ # My Agent Title
59
+
60
+ 你的详细系统提示词内容...
61
+ ```
62
+
63
+ ### frontmatter 字段说明
64
+
65
+ | 字段 | 必填 | 说明 |
66
+ |------|------|------|
67
+ | `name` | 是 | 子代理名称,必须与文件名匹配 |
68
+ | `description` | 是 | 简短描述,用于主代理的任务匹配表 |
69
+ | `tools` | 否 | 子代理可使用的工具列表 |
70
+ | `skills` | 否 | 子代理加载的技能列表 |
71
+ | `model` | 否 | 模型配置,`inherit` 表示继承父代理配置 |
72
+
73
+ ---
74
+
75
+ ## frontmatter 示例
76
+
77
+ ### 后端开发专家
78
+
79
+ ```yaml
80
+ ---
81
+ name: backend-specialist
82
+ description: Expert backend architect for Node.js, Python, and modern serverless/edge systems. Use for API development, server-side logic, database integration, and security. Triggers on backend, server, api, endpoint, database, auth.
83
+ tools: Read, Grep, Glob, Bash, Edit, Write
84
+ skills: clean-code, nodejs-best-practices, python-patterns, api-patterns, database-design
85
+ model: inherit
86
+ ---
87
+
88
+ # Backend Development Architect
89
+
90
+ You are a Backend Development Architect who designs and builds server-side systems with security, scalability, and maintainability as top priorities.
91
+ ...
92
+ ```
93
+
94
+ ### 代码调试专家
95
+
96
+ ```yaml
97
+ ---
98
+ name: debugger
99
+ description: Expert in systematic debugging, root cause analysis, and crash investigation. Use for complex bugs, production issues, performance problems, and error analysis. Triggers on bug, error, crash, not working, broken, investigate, fix.
100
+ tools: Read, Grep, Glob, Bash
101
+ skills: clean-code, systematic-debugging
102
+ model: inherit
103
+ ---
104
+
105
+ # Debugging Expert
106
+
107
+ You are an expert at finding and fixing bugs through systematic investigation.
108
+ ...
109
+ ```
110
+
111
+ ---
112
+
113
+ ## 正文内容格式
114
+
115
+ 正文内容会被完整读取作为子代理的系统提示词。支持 Markdown 格式:
116
+
117
+ ```markdown
118
+ # Agent Title
119
+
120
+ ## Section 1
121
+
122
+ 内容...
123
+
124
+ ## Section 2
125
+
126
+ 内容...
127
+ ```
128
+
129
+ ---
130
+
131
+ ## 使用子代理
132
+
133
+ ### 自动匹配
134
+
135
+ 主代理会根据任务描述自动选择最匹配的子代理处理。
136
+
137
+ ### 手动调用
138
+
139
+ 使用 `subagent_call` 工具手动调用子代理:
140
+
141
+ ```javascript
142
+ {
143
+ "agentName": "backend-specialist",
144
+ "task": "帮我创建一个用户认证的 API"
145
+ }
146
+ ```
147
+
148
+ ---
149
+
150
+ ## 子代理系统提示词组合
151
+
152
+ 当调用子代理时,系统提示词按以下顺序组合:
153
+
154
+ 1. **frontmatter description** - 简短能力描述
155
+ 2. **正文内容** - 完整的 markdown 内容
156
+
157
+ 类似于 Skill 的工作方式,子代理的完整 md 文件内容会被读取并作为系统提示词。
158
+
159
+ ---
160
+
161
+ ## 重载子代理配置
162
+
163
+ 修改 `.agent/agents/` 下的文件后,使用 `subagent_reload` 工具重载:
164
+
165
+ ```javascript
166
+ {
167
+ // 空参数
168
+ }
169
+ ```
170
+
171
+ ---
172
+
173
+ ## 技能与子代理的区别
174
+
175
+ | 特性 | Skill | SubAgent |
176
+ |------|-------|----------|
177
+ | 系统提示词 | 指令和最佳实践 | 完整角色定义 |
178
+ | 工具 | 继承父代理工具 | 可自定义工具集 |
179
+ | 调用方式 | `loadSkill` 工具 | `subagent_call` 工具 |
180
+ | 适用场景 | 专业领域指导 | 独立处理复杂任务 |
181
+ | LLM | 共享父代理 | 可独立配置 |
182
+
183
+ ---
184
+
185
+ ## 最佳实践
186
+
187
+ 1. **清晰的 description**:帮助主代理正确匹配任务
188
+ 2. **合适的工具集**:只授予必要的工具权限
189
+ 3. **技能组合**:通过 `skills` 字段引用已有技能
190
+ 4. **简洁的正文**:包含核心指令和决策逻辑
191
+
192
+ ---
193
+
194
+ ## 示例:创建一个 API 开发专家
195
+
196
+ **文件**:`.agent/agents/api-expert.md`
197
+
198
+ ```yaml
199
+ ---
200
+ name: api-expert
201
+ description: API design and development expert. Use for RESTful API, GraphQL, gRPC design and implementation. Triggers on api, endpoint, REST, GraphQL, webhook.
202
+ tools: Read, Grep, Glob, Bash, Write, Edit
203
+ skills: clean-code, api-patterns
204
+ model: inherit
205
+ ---
206
+
207
+ # API Development Expert
208
+
209
+ You are an expert at designing and building APIs.
210
+
211
+ ## Design Principles
212
+
213
+ 1. **RESTful**: Follow REST conventions for resource naming
214
+ 2. **Consistency**: Use consistent response formats
215
+ 3. **Error Handling**: Always provide meaningful error messages
216
+ 4. **Documentation**: Generate OpenAPI/Swagger specs
217
+
218
+ ## Response Format
219
+
220
+ ```json
221
+ {
222
+ "success": true,
223
+ "data": { ... },
224
+ "error": null
225
+ }
226
+ ```
227
+ ```
228
+
229
+ ---
230
+
231
+ ## 总结
232
+
233
+ - 子代理文件位于 `.agent/agents/*.md`
234
+ - 使用 YAML frontmatter 定义元数据
235
+ - 正文内容作为完整系统提示词
236
+ - 通过 `subagent_call` 调用
237
+ - 修改后用 `subagent_reload` 重载
@@ -23,6 +23,7 @@ allowed-tools: execute_workflow,reloadWorkflows
23
23
  ## 自动加载与注册
24
24
 
25
25
  将工作流文件放入 `.agent/workflows/` 目录后,系统会自动:
26
+
26
27
  1. 加载所有 `.json` 和 `.js` 文件
27
28
  2. 将工作流注册为 `workflow_<文件名>` 工具
28
29
 
@@ -42,17 +43,19 @@ allowed-tools: execute_workflow,reloadWorkflows
42
43
  ## 使用方式
43
44
 
44
45
  ### 方式一:直接执行(任意工作流)
46
+
45
47
  ```json
46
48
  {
47
49
  "tool": "execute_workflow",
48
50
  "args": {
49
- "workflow": "my-workflow", // 工作流名称(自动从 .agent/workflows/ 加载)
51
+ "workflow": "my-workflow", // 工作流名称(自动从 .agent/workflows/ 加载)
50
52
  "input": { "变量名": "值" }
51
53
  }
52
54
  }
53
55
  ```
54
56
 
55
57
  ### 方式二:执行已注册的工作流工具
58
+
56
59
  ```json
57
60
  {
58
61
  "tool": "workflow_my_workflow",
@@ -72,20 +75,20 @@ allowed-tools: execute_workflow,reloadWorkflows
72
75
 
73
76
  ### 支持的步骤类型
74
77
 
75
- | 类型 | 说明 | 自动推断 |
76
- |------|------|---------|
77
- | `tool` | 工具调用 | 有 `tool` 字段 |
78
- | `script` | JavaScript 脚本 | 有 `code` 或 `script` 字段 |
79
- | `condition` | 条件分支 | 有 `branches` 字段 |
80
- | `switch` | 开关分支 | 有 `value` + `branches` |
81
- | `try` | 异常捕获 | 有 `try` 或 `catch` 字段 |
82
- | `parallel` | 并行执行 | `"parallel": true` 或 `"mode": "parallel"` |
83
- | `sequential` | 顺序执行 | 有 `steps` 字段 |
84
- | `loop` | 循环执行 | 有 `steps` + `loopVariable`/`maxIterations` |
85
- | `delay` | 延时等待 | 有 `delayMs` 字段 |
86
- | `workflow` | 嵌套工作流 | 有 `workflow` 字段 |
87
- | `message` | 发送消息 | 有 `message` 字段 |
88
- | `think` | 主动思考 | 有 `topic` 字段 |
78
+ | 类型 | 说明 | 自动推断 |
79
+ | ------------ | --------------- | ------------------------------------------- |
80
+ | `tool` | 工具调用 | 有 `tool` 字段 |
81
+ | `script` | JavaScript 脚本 | 有 `code` 或 `script` 字段 |
82
+ | `condition` | 条件分支 | 有 `branches` 字段 |
83
+ | `switch` | 开关分支 | 有 `value` + `branches` |
84
+ | `try` | 异常捕获 | 有 `try` 或 `catch` 字段 |
85
+ | `parallel` | 并行执行 | `"parallel": true` 或 `"mode": "parallel"` |
86
+ | `sequential` | 顺序执行 | 有 `steps` 字段 |
87
+ | `loop` | 循环执行 | 有 `steps` + `loopVariable`/`maxIterations` |
88
+ | `delay` | 延时等待 | 有 `delayMs` 字段 |
89
+ | `workflow` | 嵌套工作流 | 有 `workflow` 字段 |
90
+ | `message` | 发送消息 | 有 `message` 字段 |
91
+ | `think` | 主动思考 | 有 `topic` 字段 |
89
92
 
90
93
  ### 1. script - 脚本步骤
91
94
 
@@ -101,11 +104,13 @@ allowed-tools: execute_workflow,reloadWorkflows
101
104
  ```
102
105
 
103
106
  **正确写法**:
107
+
104
108
  ```json
105
109
  { "script": "return context.variables.value + 1;" }
106
110
  ```
107
111
 
108
112
  **错误写法**(缺少 return):
113
+
109
114
  ```json
110
115
  { "script": "context.variables.value + 1;" }
111
116
  ```
@@ -133,11 +138,11 @@ allowed-tools: execute_workflow,reloadWorkflows
133
138
 
134
139
  **参数说明**:
135
140
 
136
- | 字段 | 类型 | 必填 | 说明 |
137
- |------|------|------|------|
138
- | `tool` | string | 是 | 工具名称 |
139
- | `args` | object | 否 | 工具参数 |
140
- | `outputVariable` | string | 否 | 结果保存到的变量名 |
141
+ | 字段 | 类型 | 必填 | 说明 |
142
+ | ---------------- | ------ | ---- | ------------------ |
143
+ | `tool` | string | 是 | 工具名称 |
144
+ | `args` | object | 否 | 工具参数 |
145
+ | `outputVariable` | string | 否 | 结果保存到的变量名 |
141
146
 
142
147
  **args 中支持变量引用**:
143
148
 
@@ -181,16 +186,16 @@ allowed-tools: execute_workflow,reloadWorkflows
181
186
 
182
187
  支持的引用格式:
183
188
 
184
- | 格式 | 说明 |
185
- |------|------|
186
- | `{{result}}` | 上一步完整结果 |
187
- | `{{result.body}}` | 提取 body 字段 |
188
- | `{{result.body.ip}}` | 从 body 提取嵌套字段 |
189
- | `{{result.body.data[0].name}}` | 支持数组索引 |
190
- | `{{lastResult}}` | result 的别名 |
191
- | `{{lastResult.error}}` | 从错误对象提取信息 |
192
- | `{{variables.xxx}}` | 显式引用 context.variables |
193
- | `{{input.xxx}}` | 引用工作流输入参数 |
189
+ | 格式 | 说明 |
190
+ | ------------------------------ | -------------------------- |
191
+ | `{{result}}` | 上一步完整结果 |
192
+ | `{{result.body}}` | 提取 body 字段 |
193
+ | `{{result.body.ip}}` | 从 body 提取嵌套字段 |
194
+ | `{{result.body.data[0].name}}` | 支持数组索引 |
195
+ | `{{lastResult}}` | result 的别名 |
196
+ | `{{lastResult.error}}` | 从错误对象提取信息 |
197
+ | `{{variables.xxx}}` | 显式引用 context.variables |
198
+ | `{{input.xxx}}` | 引用工作流输入参数 |
194
199
 
195
200
  **自动 JSON 解析**:如果字段值是 JSON 字符串,会自动解析为对象后再提取嵌套字段。
196
201
 
@@ -204,9 +209,7 @@ allowed-tools: execute_workflow,reloadWorkflows
204
209
  "name": "循环3次",
205
210
  "maxIterations": 3,
206
211
  "loopVariable": "i",
207
- "steps": [
208
- { "type": "script", "name": "执行内容", "script": "..." }
209
- ]
212
+ "steps": [{ "type": "script", "name": "执行内容", "script": "..." }]
210
213
  }
211
214
  ```
212
215
 
@@ -290,9 +293,9 @@ allowed-tools: execute_workflow,reloadWorkflows
290
293
  "type": "parallel",
291
294
  "name": "并行获取数据",
292
295
  "steps": [
293
- { "type": "tool", "tool": "fetch", "args": {"url": "https://api1.com"}, "output": "data1" },
294
- { "type": "tool", "tool": "fetch", "args": {"url": "https://api2.com"}, "output": "data2" },
295
- { "type": "tool", "tool": "fetch", "args": {"url": "https://api3.com"}, "output": "data3" }
296
+ { "type": "tool", "tool": "fetch", "args": { "url": "https://api1.com" }, "output": "data1" },
297
+ { "type": "tool", "tool": "fetch", "args": { "url": "https://api2.com" }, "output": "data2" },
298
+ { "type": "tool", "tool": "fetch", "args": { "url": "https://api3.com" }, "output": "data3" }
296
299
  ]
297
300
  }
298
301
  ```
@@ -355,6 +358,7 @@ allowed-tools: execute_workflow,reloadWorkflows
355
358
  ### 示例:获取IP并发送通知
356
359
 
357
360
  **推荐写法**(使用 `{{result}}` 直接引用上一步结果):
361
+
358
362
  ```json
359
363
  {
360
364
  "name": "get-ip-notify",
@@ -383,6 +387,7 @@ allowed-tools: execute_workflow,reloadWorkflows
383
387
  ```
384
388
 
385
389
  **旧写法**(仍支持,但不推荐):
390
+
386
391
  ```json
387
392
  {
388
393
  "name": "get-ip-notify-old",
@@ -449,9 +454,24 @@ allowed-tools: execute_workflow,reloadWorkflows
449
454
  "type": "parallel",
450
455
  "name": "并行获取数据",
451
456
  "steps": [
452
- { "type": "tool", "tool": "fetch", "args": {"url": "https://api.baidu.com"}, "output": "baiduData" },
453
- { "type": "tool", "tool": "fetch", "args": {"url": "https://api.bbc.com"}, "output": "bbcData" },
454
- { "type": "tool", "tool": "fetch", "args": {"url": "https://api.reddit.com"}, "output": "redditData" }
457
+ {
458
+ "type": "tool",
459
+ "tool": "fetch",
460
+ "args": { "url": "https://api.baidu.com" },
461
+ "output": "baiduData"
462
+ },
463
+ {
464
+ "type": "tool",
465
+ "tool": "fetch",
466
+ "args": { "url": "https://api.bbc.com" },
467
+ "output": "bbcData"
468
+ },
469
+ {
470
+ "type": "tool",
471
+ "tool": "fetch",
472
+ "args": { "url": "https://api.reddit.com" },
473
+ "output": "redditData"
474
+ }
455
475
  ]
456
476
  },
457
477
  {
@@ -477,12 +497,16 @@ allowed-tools: execute_workflow,reloadWorkflows
477
497
  "name": "尝试执行",
478
498
  "try": {
479
499
  "steps": [
480
- { "type": "tool", "tool": "fetch", "args": {"url": "https://可能失败的api.com"} }
500
+ { "type": "tool", "tool": "fetch", "args": { "url": "https://可能失败的api.com" } }
481
501
  ]
482
502
  },
483
503
  "catch": {
484
504
  "steps": [
485
- { "type": "script", "outputVariable": "errorMsg", "script": "return 'API 调用失败,使用备用数据';" }
505
+ {
506
+ "type": "script",
507
+ "outputVariable": "errorMsg",
508
+ "script": "return 'API 调用失败,使用备用数据';"
509
+ }
486
510
  ]
487
511
  }
488
512
  },
@@ -513,11 +537,30 @@ allowed-tools: execute_workflow,reloadWorkflows
513
537
  "type": "switch",
514
538
  "value": "{{status}}",
515
539
  "branches": [
516
- { "case": "success", "steps": [{ "type": "tool", "tool": "notification_send", "args": {"message": "操作成功"} }] },
517
- { "case": "error", "steps": [{ "type": "tool", "tool": "notification_send", "args": {"message": "操作失败"} }] },
518
- { "case": "pending", "steps": [{ "type": "tool", "tool": "notification_send", "args": {"message": "操作进行中"} }] }
540
+ {
541
+ "case": "success",
542
+ "steps": [
543
+ { "type": "tool", "tool": "notification_send", "args": { "message": "操作成功" } }
544
+ ]
545
+ },
546
+ {
547
+ "case": "error",
548
+ "steps": [
549
+ { "type": "tool", "tool": "notification_send", "args": { "message": "操作失败" } }
550
+ ]
551
+ },
552
+ {
553
+ "case": "pending",
554
+ "steps": [
555
+ { "type": "tool", "tool": "notification_send", "args": { "message": "操作进行中" } }
556
+ ]
557
+ }
519
558
  ],
520
- "default": { "steps": [{ "type": "tool", "tool": "notification_send", "args": {"message": "未知状态"} }] }
559
+ "default": {
560
+ "steps": [
561
+ { "type": "tool", "tool": "notification_send", "args": { "message": "未知状态" } }
562
+ ]
563
+ }
521
564
  }
522
565
  ]
523
566
  }
@@ -553,6 +596,7 @@ allowed-tools: execute_workflow,reloadWorkflows
553
596
  10. **嵌套工作流**:将复杂工作流拆分为子工作流,提高复用性和可维护性
554
597
 
555
598
  **错误示例**:
599
+
556
600
  ```json
557
601
  // ❌ 错误 - script 没有 return
558
602
  { "type": "script", "script": "context.variables.count + 1;" }
@@ -582,6 +626,7 @@ allowed-tools: execute_workflow,reloadWorkflows
582
626
  ```
583
627
 
584
628
  **正确示例**:
629
+
585
630
  ```json
586
631
  // ✅ 正确
587
632
  { "type": "script", "outputVariable": "count", "script": "return (context.variables.count||0) + 1;" }
@@ -7,21 +7,21 @@
7
7
  ```javascript
8
8
  execute_workflow({
9
9
  workflow: {
10
- name: "test-workflow",
11
- description: "测试工作流",
10
+ name: 'test-workflow',
11
+ description: '测试工作流',
12
12
  steps: [
13
13
  {
14
- id: "step1",
15
- type: "tool",
16
- tool: "python-execute",
14
+ id: 'step1',
15
+ type: 'tool',
16
+ tool: 'python-execute',
17
17
  args: {
18
- code: "print('Hello from Python!')"
18
+ code: "print('Hello from Python!')",
19
19
  },
20
- outputVariable: "result"
21
- }
22
- ]
23
- }
24
- })
20
+ outputVariable: 'result',
21
+ },
22
+ ],
23
+ },
24
+ });
25
25
  ```
26
26
 
27
27
  ### 2. JSON 格式注意事项
@@ -36,21 +36,25 @@ execute_workflow({
36
36
  ```
37
37
  Unexpected identifier 'xxx'
38
38
  ```
39
+
39
40
  - 原因:JSON 格式错误,可能是引号或逗号问题
40
41
  - 解决:检查 JSON 语法
41
42
 
42
43
  ```
43
44
  Unexpected end of JSON input
44
45
  ```
46
+
45
47
  - 原因:模板字符串 `${}` 在 JSON 中导致解析错误
46
48
  - 解决:不要在 JSON 中使用模板变量,改用纯 Python 代码
47
49
 
48
50
  ## 工作流重载问题
49
51
 
50
52
  ### 问题
53
+
51
54
  添加新工作流后,`reloadWorkflows` 不会重新加载同名工作流。
52
55
 
53
56
  ### 解决
57
+
54
58
  ```bash
55
59
  # 方法1:使用不同的文件名
56
60
  news-dashboard-v3.json # 不会被 v2 覆盖
@@ -62,6 +66,7 @@ reload_plugins() # 重载所有插件
62
66
  ## Python 执行最佳实践
63
67
 
64
68
  ### 1. 错误处理
69
+
65
70
  ```python
66
71
  try:
67
72
  req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
@@ -74,6 +79,7 @@ except Exception as e:
74
79
  ```
75
80
 
76
81
  ### 2. 输出格式
82
+
77
83
  ```python
78
84
  # 简单输出
79
85
  print('Status: OK')
@@ -87,6 +93,7 @@ print('---JSON_END---')
87
93
  ```
88
94
 
89
95
  ### 3. 超时设置
96
+
90
97
  ```python
91
98
  with urllib.request.urlopen(req, timeout=30) as resp: # 30秒超时
92
99
  ...
@@ -94,19 +101,20 @@ with urllib.request.urlopen(req, timeout=30) as resp: # 30秒超时
94
101
 
95
102
  ## 工作流步骤类型
96
103
 
97
- | 类型 | 用途 | 示例 |
98
- |------|------|------|
99
- | `tool` | 调用工具 | `python-execute`, `shell`, `get_time` |
100
- | `script` | 执行 JavaScript | 数据处理、变量操作 |
101
- | `condition` | 条件分支 | if/else 逻辑 |
102
- | `loop` | 循环执行 | 遍历列表 |
103
- | `delay` | 延时等待 | 等待指定时间 |
104
- | `message` | 消息通知 | 发送通知 |
105
- | `think` | LLM 思考 | 反思/分析 |
104
+ | 类型 | 用途 | 示例 |
105
+ | ----------- | --------------- | ------------------------------------- |
106
+ | `tool` | 调用工具 | `python-execute`, `shell`, `get_time` |
107
+ | `script` | 执行 JavaScript | 数据处理、变量操作 |
108
+ | `condition` | 条件分支 | if/else 逻辑 |
109
+ | `loop` | 循环执行 | 遍历列表 |
110
+ | `delay` | 延时等待 | 等待指定时间 |
111
+ | `message` | 消息通知 | 发送通知 |
112
+ | `think` | LLM 思考 | 反思/分析 |
106
113
 
107
114
  ## 工具输出变量
108
115
 
109
116
  ### 正确用法
117
+
110
118
  ```json
111
119
  {
112
120
  "id": "step1",
@@ -117,6 +125,7 @@ with urllib.request.urlopen(req, timeout=30) as resp: # 30秒超时
117
125
  ```
118
126
 
119
127
  ### 访问输出
128
+
120
129
  ```javascript
121
130
  // 在 script 步骤中
122
131
  context.input.current_time
@@ -128,18 +137,21 @@ ${step1.current_time}
128
137
  ## 调试技巧
129
138
 
130
139
  ### 1. 打印中间变量
140
+
131
141
  ```python
132
142
  print('Debug - data:', data)
133
143
  print('Debug - length:', len(data))
134
144
  ```
135
145
 
136
146
  ### 2. 保存到文件
147
+
137
148
  ```python
138
149
  with open('debug.log', 'w') as f:
139
150
  f.write(str(data))
140
151
  ```
141
152
 
142
153
  ### 3. 逐步执行
154
+
143
155
  ```javascript
144
156
  {
145
157
  "steps": [
@@ -152,6 +164,7 @@ with open('debug.log', 'w') as f:
152
164
  ## 性能优化
153
165
 
154
166
  ### 1. 合并步骤
167
+
155
168
  ```javascript
156
169
  // ❌ 多个小步骤
157
170
  { "id": "step1", "tool": "python-execute", "code": "a = 1" }
@@ -162,6 +175,7 @@ with open('debug.log', 'w') as f:
162
175
  ```
163
176
 
164
177
  ### 2. 减少变量传递
178
+
165
179
  ```javascript
166
180
  // ❌ 多步骤传递
167
181
  { "outputVariable": "data1" }
@@ -172,11 +186,12 @@ with open('debug.log', 'w') as f:
172
186
  ```
173
187
 
174
188
  ### 3. 超时设置
189
+
175
190
  ```json
176
191
  {
177
192
  "args": {
178
193
  "code": "...",
179
- "timeout": 60000 // 60秒超时
194
+ "timeout": 60000 // 60秒超时
180
195
  }
181
196
  }
182
197
  ```