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
@@ -0,0 +1,316 @@
1
+ ---
2
+ name: plugin-dev
3
+ description: JavaScript 插件开发指南。当用户说"创建插件"、"写插件"、"开发插件"时立即调用此 skill。
4
+ allowed-tools: Read, Write, Edit, Glob, Grep, Bash
5
+ ---
6
+
7
+ # JavaScript 插件开发
8
+
9
+ ## 概述
10
+
11
+ Foliko 支持两种插件开发方式:
12
+
13
+ | 类型 | 格式 | 存放位置 |
14
+ |------|------|----------|
15
+ | **function(foliko)** | `module.exports = function(foliko) {}` | `.foliko/plugins/*.js` |
16
+ | **类式插件** | `class MyPlugin extends Plugin {}` | `.foliko/plugins/*/index.js` |
17
+
18
+ 推荐使用 **function(foliko)** 方式,更简洁直观。
19
+
20
+ ---
21
+
22
+ ## 快速开始
23
+
24
+ 创建 `.foliko/plugins/my-plugin.js`:
25
+
26
+ ```javascript
27
+ /**
28
+ * 我的插件
29
+ */
30
+ module.exports = function (foliko) {
31
+ console.log('[my-plugin] 加载中...');
32
+
33
+ // 注册工具
34
+ foliko.tools.tool({
35
+ name: 'hello',
36
+ description: '打招呼',
37
+ inputSchema: foliko.z.object({
38
+ name: foliko.z.string().describe('姓名')
39
+ }),
40
+ execute: (args) => ({ message: `Hello, ${args.name}!` })
41
+ });
42
+
43
+ console.log('[my-plugin] 加载完成');
44
+ };
45
+ ```
46
+
47
+ ---
48
+
49
+ ## foliko API 速查
50
+
51
+ ### 工具注册
52
+
53
+ ```javascript
54
+ // 注册普通工具(推荐)
55
+ foliko.tools.tool({
56
+ name: 'my-tool',
57
+ description: '工具描述',
58
+ inputSchema: foliko.z.object({
59
+ arg1: foliko.z.string().describe('参数1'),
60
+ arg2: foliko.z.number().optional()
61
+ }),
62
+ execute: (args) => {
63
+ // 返回结果
64
+ return { success: true, result: '...' };
65
+ }
66
+ });
67
+
68
+ // 同上
69
+ foliko.tools.register({ name: 'my-tool', ... });
70
+
71
+ // 注册扩展工具(可被 LLM 通过 ext_call 调用)
72
+ foliko.extension.tool('my-ext', {
73
+ greet: {
74
+ description: '打招呼',
75
+ inputSchema: foliko.z.object({
76
+ name: foliko.z.string()
77
+ }),
78
+ execute: (args) => ({ message: `Hi, ${args.name}!` })
79
+ }
80
+ });
81
+ ```
82
+
83
+ ### 工具执行
84
+
85
+ ```javascript
86
+ // 执行普通工具
87
+ const result = await foliko.tools.execute('my-tool', { arg1: 'value' });
88
+
89
+ // 执行扩展工具
90
+ const result = await foliko.extension.execute('my-ext', 'greet', { name: 'Alice' });
91
+ ```
92
+
93
+ ### 工具查询
94
+
95
+ ```javascript
96
+ // 列出所有普通工具
97
+ foliko.tools.list();
98
+
99
+ // 检查工具是否存在
100
+ foliko.tools.has('my-tool');
101
+
102
+ // 获取工具定义
103
+ foliko.tools.get('my-tool');
104
+ ```
105
+
106
+ ### 扩展工具查询
107
+
108
+ ```javascript
109
+ // 列出所有扩展插件
110
+ foliko.extension.list();
111
+
112
+ // 列出扩展插件名称
113
+ foliko.extension.listPlugins();
114
+
115
+ // 列出指定插件的工具
116
+ foliko.extension.listTools('my-ext');
117
+
118
+ // 获取指定工具详情
119
+ foliko.extension.getTool('my-ext', 'greet');
120
+ ```
121
+
122
+ ### 插件管理
123
+
124
+ ```javascript
125
+ // 获取插件实例
126
+ foliko.plugin('ai');
127
+ foliko.plugins.get('skill-manager');
128
+
129
+ // 列出所有插件名
130
+ foliko.plugins.list();
131
+
132
+ // 检查插件是否存在
133
+ foliko.plugins.has('ai');
134
+ ```
135
+
136
+ ### 事件
137
+
138
+ ```javascript
139
+ // 监听事件
140
+ foliko.on('framework:ready', (data) => {
141
+ console.log('框架就绪');
142
+ });
143
+
144
+ // 发送事件
145
+ foliko.emit('my-event', { data: 'value' });
146
+
147
+ // 移除监听
148
+ foliko.off('my-event', handler);
149
+ ```
150
+
151
+ ### 日志
152
+
153
+ ```javascript
154
+ foliko.logger.info('信息日志');
155
+ foliko.logger.warn('警告日志');
156
+ foliko.logger.error('错误日志');
157
+ foliko.logger.debug('调试日志');
158
+ ```
159
+
160
+ ---
161
+
162
+ ## 完整示例
163
+
164
+ ```javascript
165
+ /**
166
+ * 我的插件 - 完整示例
167
+ */
168
+ module.exports = function (foliko) {
169
+ console.log('[my-plugin] 加载中...');
170
+
171
+ // ========== 注册普通工具 ==========
172
+
173
+ foliko.tools.tool({
174
+ name: 'hello',
175
+ description: '打招呼',
176
+ inputSchema: foliko.z.object({
177
+ name: foliko.z.string().describe('姓名')
178
+ }),
179
+ execute: (args) => ({ message: `Hello, ${args.name}!` })
180
+ });
181
+
182
+ foliko.tools.register({
183
+ name: 'calc',
184
+ description: '计算器',
185
+ inputSchema: foliko.z.object({
186
+ a: foliko.z.number(),
187
+ b: foliko.z.number(),
188
+ op: foliko.z.enum(['add', 'sub', 'mul', 'div']).optional()
189
+ }),
190
+ execute: (args) => {
191
+ const { a, b, op = 'add' } = args;
192
+ let result;
193
+ switch (op) {
194
+ case 'add': result = a + b; break;
195
+ case 'sub': result = a - b; break;
196
+ case 'mul': result = a * b; break;
197
+ case 'div': result = b !== 0 ? a / b : null; break;
198
+ }
199
+ return { success: true, result };
200
+ }
201
+ });
202
+
203
+ // ========== 注册扩展工具 ==========
204
+
205
+ foliko.extension.tool('weather', {
206
+ get: {
207
+ description: '获取天气',
208
+ inputSchema: foliko.z.object({
209
+ city: foliko.z.string().describe('城市名')
210
+ }),
211
+ execute: (args) => ({
212
+ weather: '晴天',
213
+ city: args.city,
214
+ temp: 25
215
+ })
216
+ }
217
+ });
218
+
219
+ // ========== 监听事件 ==========
220
+
221
+ foliko.on('framework:ready', () => {
222
+ console.log('[my-plugin] 框架就绪');
223
+ });
224
+
225
+ // ========== 获取其他插件 ==========
226
+
227
+ const aiPlugin = foliko.plugin('ai');
228
+ if (aiPlugin) {
229
+ console.log('[my-plugin] AI 插件已加载');
230
+ }
231
+
232
+ console.log('[my-plugin] 加载完成');
233
+ };
234
+ ```
235
+
236
+ ---
237
+
238
+ ## LLM 调用扩展工具
239
+
240
+ 扩展工具通过 `ext_call` 调用:
241
+
242
+ ```javascript
243
+ // 调用扩展工具
244
+ ext_call({
245
+ plugin: 'weather', // 插件名
246
+ tool: 'get', // 工具名
247
+ args: { city: '北京' }
248
+ });
249
+ ```
250
+
251
+ 系统提示词中会自动显示:
252
+
253
+ ```markdown
254
+ ## 【Extensions】扩展插件
255
+
256
+ **使用流程(必须按顺序执行):**
257
+ 1. 调用 `ext_skill({ plugin: "<plugin_name>" })` 获取技能命令的详细参数
258
+ 2. 根据返回的参数定义,使用 `ext_call({ plugin: "<plugin_name>", tool: "<tool_name>", args: {...} })` 调用
259
+
260
+ ### weather
261
+ **工具:** `get`
262
+ ```
263
+
264
+ ---
265
+
266
+ ## Zod Schema 用法
267
+
268
+ ```javascript
269
+ // 基础类型
270
+ foliko.z.string()
271
+ foliko.z.number()
272
+ foliko.z.boolean()
273
+ foliko.z.array(foliko.z.string())
274
+
275
+ // 可选
276
+ foliko.z.string().optional()
277
+
278
+ // 带默认值
279
+ foliko.z.string().default('World')
280
+
281
+ // 枚举
282
+ foliko.z.enum(['add', 'sub', 'mul'])
283
+
284
+ // 描述
285
+ foliko.z.string().describe('参数描述')
286
+
287
+ // 复杂对象
288
+ foliko.z.object({
289
+ name: foliko.z.string(),
290
+ age: foliko.z.number().optional(),
291
+ tags: foliko.z.array(foliko.z.string()).optional(),
292
+ address: foliko.z.object({
293
+ city: foliko.z.string(),
294
+ zip: foliko.z.string()
295
+ }).optional()
296
+ })
297
+ ```
298
+
299
+ ---
300
+
301
+ ## 注意事项
302
+
303
+ 1. **插件位置** - 放在 `.foliko/plugins/` 目录下
304
+ 2. **热重载** - 修改后运行 `foliko reload` 重载插件
305
+ 3. **工具名唯一** - 避免与现有工具名冲突
306
+ 4. **错误处理** - execute 函数应捕获错误并返回 `{ success: false, error: '...' }`
307
+ 5. **异步操作** - execute 支持 async/await
308
+
309
+ ---
310
+
311
+ ## 开发流程
312
+
313
+ 1. **创建插件文件** - `.foliko/plugins/my-plugin.js`
314
+ 2. **编写代码** - 使用 `function(foliko)` 方式
315
+ 3. **测试** - `foliko reload` 重载插件
316
+ 4. **调试** - 查看控制台日志输出
@@ -86,7 +86,7 @@ frontmatter 之后是技能的正文内容,支持 Markdown 格式,包含:
86
86
  3. 在正文中详细描述技能的功能和使用方法
87
87
  4. **如有命令**,在 SKILL.md 正文中添加 `## 命令` 章节,详细说明每个命令的用法
88
88
  5. 创建 `index.js` 文件导出命令(可选)
89
- 6. 调用 `reloadSkills` 工具重载所有技能
89
+ 6. 调用 `skill_reload` 工具重载所有技能
90
90
 
91
91
  ### SKILL.md 命令章节示例
92
92
 
@@ -266,17 +266,17 @@ module.exports = [
266
266
 
267
267
  技能命令会在以下时机自动注册:
268
268
  - 框架启动时加载技能
269
- - 调用 `reloadSkills` 工具重载后
269
+ - 调用 `skill_reload` 工具重载后
270
270
 
271
271
  注册后即可在所有渠道使用 `/技能名:命令名` 格式调用。
272
272
 
273
273
  ## 技能重载
274
274
 
275
- 创建或修改技能后,需要调用 `reloadSkills` 工具重载:
275
+ 创建或修改技能后,需要调用 `skill_reload` 工具重载:
276
276
 
277
277
  ```json
278
278
  {
279
- "tool": "reloadSkills",
279
+ "tool": "skill_reload",
280
280
  "args": {}
281
281
  }
282
282
  ```
@@ -452,6 +452,6 @@ module.exports = [
452
452
 
453
453
  技能命令会在以下时机自动注册:
454
454
  - 框架启动时加载技能
455
- - 调用 `reloadSkills` 工具重载后
455
+ - 调用 `skill_reload` 工具重载后
456
456
 
457
457
  注册后即可在所有渠道使用 `/技能名:命令名` 格式调用。
@@ -176,7 +176,7 @@ You are an expert at finding and fixing bugs through systematic investigation.
176
176
  |------|-------|----------|
177
177
  | 系统提示词 | 指令和最佳实践 | 完整角色定义 |
178
178
  | 工具 | 继承父代理工具 | 可自定义工具集 |
179
- | 调用方式 | `loadSkill` 工具 | `subagent_call` 工具 |
179
+ | 调用方式 | `skill_load` 工具 | `subagent_call` 工具 |
180
180
  | 适用场景 | 专业领域指导 | 独立处理复杂任务 |
181
181
  | LLM | 共享父代理 | 可独立配置 |
182
182
 
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: workflow-guide
3
3
  description: 工作流与多步任务指南。当用户说"创建工作流"、"多步任务"、"自动化流程"时立即调用。
4
- allowed-tools: execute_workflow,reloadWorkflows
4
+ allowed-tools: execute_workflow,workflow_reload
5
5
  ---
6
6
 
7
7
  # 工作流(Workflow)开发指南
@@ -31,11 +31,11 @@ allowed-tools: execute_workflow,reloadWorkflows
31
31
 
32
32
  ## 重载工作流
33
33
 
34
- 创建或修改工作流后,调用 `reloadWorkflows` 重载:
34
+ 创建或修改工作流后,调用 `workflow_reload` 重载:
35
35
 
36
36
  ```json
37
37
  {
38
- "tool": "reloadWorkflows",
38
+ "tool": "workflow_reload",
39
39
  "args": {}
40
40
  }
41
41
  ```