foliko 2.0.2 → 2.0.3

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 (78) hide show
  1. package/README.md +6 -6
  2. package/docs/public-api.md +91 -0
  3. package/docs/system-prompt.md +219 -0
  4. package/docs/usage.md +6 -6
  5. package/package.json +1 -1
  6. package/plugins/ambient/ExplorerLoop.js +1 -0
  7. package/plugins/ambient/index.js +1 -0
  8. package/plugins/core/coordinator/index.js +10 -5
  9. package/plugins/core/default/bootstrap.js +21 -3
  10. package/plugins/core/default/config.js +12 -3
  11. package/plugins/core/python-loader/index.js +3 -3
  12. package/plugins/core/scheduler/index.js +26 -2
  13. package/plugins/core/skill-manager/index.js +198 -151
  14. package/plugins/core/sub-agent/index.js +34 -15
  15. package/plugins/core/think/index.js +1 -0
  16. package/plugins/core/workflow/index.js +5 -4
  17. package/plugins/executors/data-splitter/index.js +14 -1
  18. package/plugins/executors/extension/index.js +51 -37
  19. package/plugins/executors/python/index.js +3 -3
  20. package/plugins/executors/shell/index.js +6 -4
  21. package/plugins/io/web/index.js +2 -1
  22. package/plugins/memory/index.js +29 -74
  23. package/plugins/messaging/email/handlers.js +1 -19
  24. package/plugins/messaging/email/monitor.js +2 -17
  25. package/plugins/messaging/email/reply.js +2 -1
  26. package/plugins/messaging/email/utils.js +20 -1
  27. package/plugins/messaging/feishu/index.js +1 -1
  28. package/plugins/messaging/qq/index.js +1 -1
  29. package/plugins/messaging/telegram/index.js +1 -1
  30. package/plugins/messaging/weixin/index.js +1 -1
  31. package/plugins/plugin-manager/index.js +1 -33
  32. package/plugins/tools/index.js +14 -1
  33. package/skills/plugins/SKILL.md +316 -0
  34. package/skills/skill-guide/SKILL.md +5 -5
  35. package/skills/{subagent-guide → subagents}/SKILL.md +1 -1
  36. package/skills/{workflow-guide → workflows}/SKILL.md +3 -3
  37. package/skills/{workflow-troubleshooting → workflows/workflow-troubleshooting}/DEBUGGING.md +197 -197
  38. package/skills/{workflow-troubleshooting → workflows/workflow-troubleshooting}/SKILL.md +391 -391
  39. package/src/agent/base.js +5 -20
  40. package/src/agent/index.js +20 -8
  41. package/src/agent/main.js +100 -23
  42. package/src/agent/prompt-registry.js +296 -0
  43. package/src/agent/sub-config.js +1 -78
  44. package/src/agent/sub.js +19 -24
  45. package/src/cli/commands/plugin.js +1 -60
  46. package/src/cli/ui/chat-ui-old.js +1 -1
  47. package/src/cli/ui/chat-ui.js +1 -1
  48. package/src/cli/ui/components/agent-mention-provider.js +1 -1
  49. package/src/common/constants.js +42 -0
  50. package/src/common/id.js +13 -0
  51. package/src/common/queue.js +2 -2
  52. package/src/context/compressor.js +17 -9
  53. package/src/framework/framework.js +185 -0
  54. package/src/framework/index.js +1 -2
  55. package/src/framework/lifecycle.js +102 -1
  56. package/src/framework/loader.js +1 -55
  57. package/src/index.js +11 -2
  58. package/src/plugin/base.js +69 -55
  59. package/src/plugin/loader.js +1 -57
  60. package/src/session/entry.js +1 -11
  61. package/src/storage/manager.js +1 -12
  62. package/src/tool/executor.js +2 -1
  63. package/src/tool/router.js +5 -5
  64. package/src/utils/data-splitter.js +2 -1
  65. package/src/utils/index.js +150 -0
  66. package/src/utils/message-validator.js +21 -17
  67. package/src/utils/plugin-helpers.js +19 -5
  68. package/subagent.md +2 -2
  69. package/tests/core/plugin-prompts.test.js +219 -0
  70. package/tests/core/prompt-registry.test.js +209 -0
  71. package/src/cli/utils/plugin-config.js +0 -50
  72. package/src/config/plugin-config.js +0 -50
  73. /package/skills/{ambient-agent → ambient}/SKILL.md +0 -0
  74. /package/skills/{foliko-dev → foliko}/AGENTS.md +0 -0
  75. /package/skills/{foliko-dev → foliko}/SKILL.md +0 -0
  76. /package/skills/{mcp-usage → mcp}/SKILL.md +0 -0
  77. /package/skills/{plugin-guide → plugins-guide}/SKILL.md +0 -0
  78. /package/skills/{python-plugin-dev → python}/SKILL.md +0 -0
@@ -1,197 +1,197 @@
1
- # 工作流开发调试指南
2
-
3
- ## 快速测试工作流
4
-
5
- ### 1. 使用 execute_workflow 直接测试
6
-
7
- ```javascript
8
- execute_workflow({
9
- workflow: {
10
- name: 'test-workflow',
11
- description: '测试工作流',
12
- steps: [
13
- {
14
- id: 'step1',
15
- type: 'tool',
16
- tool: 'python-execute',
17
- args: {
18
- code: "print('Hello from Python!')",
19
- },
20
- outputVariable: 'result',
21
- },
22
- ],
23
- },
24
- });
25
- ```
26
-
27
- ### 2. JSON 格式注意事项
28
-
29
- - ✅ 使用双引号包裹字符串
30
- - ✅ 确保 JSON 语法正确
31
- - ❌ 避免在 JSON 中使用未转义的特殊字符
32
- - ❌ 不要在 code 中混用单引号和双引号
33
-
34
- ### 3. 常见错误
35
-
36
- ```
37
- Unexpected identifier 'xxx'
38
- ```
39
-
40
- - 原因:JSON 格式错误,可能是引号或逗号问题
41
- - 解决:检查 JSON 语法
42
-
43
- ```
44
- Unexpected end of JSON input
45
- ```
46
-
47
- - 原因:模板字符串 `${}` 在 JSON 中导致解析错误
48
- - 解决:不要在 JSON 中使用模板变量,改用纯 Python 代码
49
-
50
- ## 工作流重载问题
51
-
52
- ### 问题
53
-
54
- 添加新工作流后,`reloadWorkflows` 不会重新加载同名工作流。
55
-
56
- ### 解决
57
-
58
- ```bash
59
- # 方法1:使用不同的文件名
60
- news-dashboard-v3.json # 不会被 v2 覆盖
61
-
62
- # 方法2:重启插件
63
- reload_plugins() # 重载所有插件
64
- ```
65
-
66
- ## Python 执行最佳实践
67
-
68
- ### 1. 错误处理
69
-
70
- ```python
71
- try:
72
- req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
73
- with urllib.request.urlopen(req, timeout=10) as resp:
74
- data = resp.read().decode('utf-8')
75
- print('SUCCESS')
76
- except Exception as e:
77
- print(f'ERROR: {e}')
78
- # fallback 逻辑
79
- ```
80
-
81
- ### 2. 输出格式
82
-
83
- ```python
84
- # 简单输出
85
- print('Status: OK')
86
- print(f'Count: {len(items)}')
87
-
88
- # JSON 输出
89
- import json
90
- print('---JSON_START---')
91
- print(json.dumps(data, ensure_ascii=False))
92
- print('---JSON_END---')
93
- ```
94
-
95
- ### 3. 超时设置
96
-
97
- ```python
98
- with urllib.request.urlopen(req, timeout=30) as resp: # 30秒超时
99
- ...
100
- ```
101
-
102
- ## 工作流步骤类型
103
-
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 思考 | 反思/分析 |
113
-
114
- ## 工具输出变量
115
-
116
- ### 正确用法
117
-
118
- ```json
119
- {
120
- "id": "step1",
121
- "type": "tool",
122
- "tool": "get_time",
123
- "outputVariable": "current_time"
124
- }
125
- ```
126
-
127
- ### 访问输出
128
-
129
- ```javascript
130
- // 在 script 步骤中
131
- context.input.current_time
132
-
133
- // 在下一个 tool 步骤中
134
- ${step1.current_time}
135
- ```
136
-
137
- ## 调试技巧
138
-
139
- ### 1. 打印中间变量
140
-
141
- ```python
142
- print('Debug - data:', data)
143
- print('Debug - length:', len(data))
144
- ```
145
-
146
- ### 2. 保存到文件
147
-
148
- ```python
149
- with open('debug.log', 'w') as f:
150
- f.write(str(data))
151
- ```
152
-
153
- ### 3. 逐步执行
154
-
155
- ```javascript
156
- {
157
- "steps": [
158
- { "id": "step1", ... }, // 先测试 step1
159
- { "id": "step2", ... } // 确认 step1 成功后添加
160
- ]
161
- }
162
- ```
163
-
164
- ## 性能优化
165
-
166
- ### 1. 合并步骤
167
-
168
- ```javascript
169
- // ❌ 多个小步骤
170
- { "id": "step1", "tool": "python-execute", "code": "a = 1" }
171
- { "id": "step2", "tool": "python-execute", "code": "b = 2" }
172
-
173
- // ✅ 单个大步骤
174
- { "id": "step1", "tool": "python-execute", "code": "a = 1; b = 2; print(a + b)" }
175
- ```
176
-
177
- ### 2. 减少变量传递
178
-
179
- ```javascript
180
- // ❌ 多步骤传递
181
- { "outputVariable": "data1" }
182
- { "outputVariable": "data2" }
183
-
184
- // ✅ 单步骤完成
185
- { "outputVariable": "final_result" }
186
- ```
187
-
188
- ### 3. 超时设置
189
-
190
- ```json
191
- {
192
- "args": {
193
- "code": "...",
194
- "timeout": 60000 // 60秒超时
195
- }
196
- }
197
- ```
1
+ # 工作流开发调试指南
2
+
3
+ ## 快速测试工作流
4
+
5
+ ### 1. 使用 execute_workflow 直接测试
6
+
7
+ ```javascript
8
+ execute_workflow({
9
+ workflow: {
10
+ name: 'test-workflow',
11
+ description: '测试工作流',
12
+ steps: [
13
+ {
14
+ id: 'step1',
15
+ type: 'tool',
16
+ tool: 'py_execute',
17
+ args: {
18
+ code: "print('Hello from Python!')",
19
+ },
20
+ outputVariable: 'result',
21
+ },
22
+ ],
23
+ },
24
+ });
25
+ ```
26
+
27
+ ### 2. JSON 格式注意事项
28
+
29
+ - ✅ 使用双引号包裹字符串
30
+ - ✅ 确保 JSON 语法正确
31
+ - ❌ 避免在 JSON 中使用未转义的特殊字符
32
+ - ❌ 不要在 code 中混用单引号和双引号
33
+
34
+ ### 3. 常见错误
35
+
36
+ ```
37
+ Unexpected identifier 'xxx'
38
+ ```
39
+
40
+ - 原因:JSON 格式错误,可能是引号或逗号问题
41
+ - 解决:检查 JSON 语法
42
+
43
+ ```
44
+ Unexpected end of JSON input
45
+ ```
46
+
47
+ - 原因:模板字符串 `${}` 在 JSON 中导致解析错误
48
+ - 解决:不要在 JSON 中使用模板变量,改用纯 Python 代码
49
+
50
+ ## 工作流重载问题
51
+
52
+ ### 问题
53
+
54
+ 添加新工作流后,`workflow_reload` 不会重新加载同名工作流。
55
+
56
+ ### 解决
57
+
58
+ ```bash
59
+ # 方法1:使用不同的文件名
60
+ news-dashboard-v3.json # 不会被 v2 覆盖
61
+
62
+ # 方法2:重启插件
63
+ reload_plugins() # 重载所有插件
64
+ ```
65
+
66
+ ## Python 执行最佳实践
67
+
68
+ ### 1. 错误处理
69
+
70
+ ```python
71
+ try:
72
+ req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
73
+ with urllib.request.urlopen(req, timeout=10) as resp:
74
+ data = resp.read().decode('utf-8')
75
+ print('SUCCESS')
76
+ except Exception as e:
77
+ print(f'ERROR: {e}')
78
+ # fallback 逻辑
79
+ ```
80
+
81
+ ### 2. 输出格式
82
+
83
+ ```python
84
+ # 简单输出
85
+ print('Status: OK')
86
+ print(f'Count: {len(items)}')
87
+
88
+ # JSON 输出
89
+ import json
90
+ print('---JSON_START---')
91
+ print(json.dumps(data, ensure_ascii=False))
92
+ print('---JSON_END---')
93
+ ```
94
+
95
+ ### 3. 超时设置
96
+
97
+ ```python
98
+ with urllib.request.urlopen(req, timeout=30) as resp: # 30秒超时
99
+ ...
100
+ ```
101
+
102
+ ## 工作流步骤类型
103
+
104
+ | 类型 | 用途 | 示例 |
105
+ | ----------- | --------------- | ------------------------------------- |
106
+ | `tool` | 调用工具 | `py_execute`, `shell_exec`, `get_time` |
107
+ | `script` | 执行 JavaScript | 数据处理、变量操作 |
108
+ | `condition` | 条件分支 | if/else 逻辑 |
109
+ | `loop` | 循环执行 | 遍历列表 |
110
+ | `delay` | 延时等待 | 等待指定时间 |
111
+ | `message` | 消息通知 | 发送通知 |
112
+ | `think` | LLM 思考 | 反思/分析 |
113
+
114
+ ## 工具输出变量
115
+
116
+ ### 正确用法
117
+
118
+ ```json
119
+ {
120
+ "id": "step1",
121
+ "type": "tool",
122
+ "tool": "get_time",
123
+ "outputVariable": "current_time"
124
+ }
125
+ ```
126
+
127
+ ### 访问输出
128
+
129
+ ```javascript
130
+ // 在 script 步骤中
131
+ context.input.current_time
132
+
133
+ // 在下一个 tool 步骤中
134
+ ${step1.current_time}
135
+ ```
136
+
137
+ ## 调试技巧
138
+
139
+ ### 1. 打印中间变量
140
+
141
+ ```python
142
+ print('Debug - data:', data)
143
+ print('Debug - length:', len(data))
144
+ ```
145
+
146
+ ### 2. 保存到文件
147
+
148
+ ```python
149
+ with open('debug.log', 'w') as f:
150
+ f.write(str(data))
151
+ ```
152
+
153
+ ### 3. 逐步执行
154
+
155
+ ```javascript
156
+ {
157
+ "steps": [
158
+ { "id": "step1", ... }, // 先测试 step1
159
+ { "id": "step2", ... } // 确认 step1 成功后添加
160
+ ]
161
+ }
162
+ ```
163
+
164
+ ## 性能优化
165
+
166
+ ### 1. 合并步骤
167
+
168
+ ```javascript
169
+ // ❌ 多个小步骤
170
+ { "id": "step1", "tool": "py_execute", "code": "a = 1" }
171
+ { "id": "step2", "tool": "py_execute", "code": "b = 2" }
172
+
173
+ // ✅ 单个大步骤
174
+ { "id": "step1", "tool": "py_execute", "code": "a = 1; b = 2; print(a + b)" }
175
+ ```
176
+
177
+ ### 2. 减少变量传递
178
+
179
+ ```javascript
180
+ // ❌ 多步骤传递
181
+ { "outputVariable": "data1" }
182
+ { "outputVariable": "data2" }
183
+
184
+ // ✅ 单步骤完成
185
+ { "outputVariable": "final_result" }
186
+ ```
187
+
188
+ ### 3. 超时设置
189
+
190
+ ```json
191
+ {
192
+ "args": {
193
+ "code": "...",
194
+ "timeout": 60000 // 60秒超时
195
+ }
196
+ }
197
+ ```