foliko 1.0.0

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 (54) hide show
  1. package/.claude/settings.local.json +30 -0
  2. package/22.txt +10 -0
  3. package/README.md +218 -0
  4. package/SPEC.md +452 -0
  5. package/cli/bin/foliko.js +12 -0
  6. package/cli/src/commands/chat.js +75 -0
  7. package/cli/src/index.js +64 -0
  8. package/cli/src/ui/chat-ui.js +272 -0
  9. package/cli/src/utils/ansi.js +40 -0
  10. package/cli/src/utils/markdown.js +296 -0
  11. package/docs/quick-reference.md +131 -0
  12. package/docs/user-manual.md +1205 -0
  13. package/examples/basic.js +110 -0
  14. package/examples/bootstrap.js +93 -0
  15. package/examples/mcp-example.js +53 -0
  16. package/examples/skill-example.js +49 -0
  17. package/examples/workflow.js +158 -0
  18. package/package.json +36 -0
  19. package/plugins/ai-plugin.js +89 -0
  20. package/plugins/audit-plugin.js +187 -0
  21. package/plugins/default-plugins.js +412 -0
  22. package/plugins/file-system-plugin.js +344 -0
  23. package/plugins/install-plugin.js +93 -0
  24. package/plugins/python-executor-plugin.js +331 -0
  25. package/plugins/rules-plugin.js +292 -0
  26. package/plugins/scheduler-plugin.js +426 -0
  27. package/plugins/session-plugin.js +343 -0
  28. package/plugins/shell-executor-plugin.js +196 -0
  29. package/plugins/storage-plugin.js +237 -0
  30. package/plugins/subagent-plugin.js +395 -0
  31. package/plugins/think-plugin.js +329 -0
  32. package/plugins/tools-plugin.js +114 -0
  33. package/skills/mcp-usage/SKILL.md +198 -0
  34. package/skills/vb-agent-dev/AGENTS.md +162 -0
  35. package/skills/vb-agent-dev/SKILL.md +370 -0
  36. package/src/capabilities/index.js +11 -0
  37. package/src/capabilities/skill-manager.js +319 -0
  38. package/src/capabilities/workflow-engine.js +401 -0
  39. package/src/core/agent-chat.js +311 -0
  40. package/src/core/agent.js +573 -0
  41. package/src/core/framework.js +255 -0
  42. package/src/core/index.js +19 -0
  43. package/src/core/plugin-base.js +205 -0
  44. package/src/core/plugin-manager.js +392 -0
  45. package/src/core/provider.js +108 -0
  46. package/src/core/tool-registry.js +134 -0
  47. package/src/core/tool-router.js +216 -0
  48. package/src/executors/executor-base.js +58 -0
  49. package/src/executors/mcp-executor.js +728 -0
  50. package/src/index.js +37 -0
  51. package/src/utils/event-emitter.js +97 -0
  52. package/test-chat.js +129 -0
  53. package/test-mcp.js +79 -0
  54. package/test-reload.js +61 -0
@@ -0,0 +1,162 @@
1
+ # AGENTS.md
2
+
3
+ This file provides guidance to AI coding agents on how to create plugins for the VB-Agent Framework system.
4
+
5
+ ## Plugin File Location
6
+
7
+ ### User Plugins: `.agent/plugins/` (auto-loaded)
8
+
9
+ User plugins go in `.agent/plugins/` and are **automatically loaded** on bootstrap.
10
+
11
+ ```
12
+ 项目目录/
13
+ └── .agent/
14
+ └── plugins/
15
+ ├── my-plugin.js ✅ correct
16
+ └── another-plugin.js ✅ correct
17
+ ```
18
+
19
+ ### Built-in Plugins: `plugins/` (internal)
20
+
21
+ Built-in framework plugins are in `plugins/` directory.
22
+
23
+ ## Plugin Export Formats
24
+
25
+ ###免引入写法 for `.agent/plugins/` ✅
26
+
27
+ User plugins **must** use this format:
28
+
29
+ ```javascript
30
+ // .agent/plugins/my-plugin.js
31
+ module.exports = function(Plugin) {
32
+ return class MyPlugin extends Plugin {
33
+ constructor(config = {}) {
34
+ super()
35
+ this.name = 'my-plugin'
36
+ this.version = '1.0.0'
37
+ this.description = '我的插件'
38
+ this.priority = 10
39
+ }
40
+
41
+ install(framework) {
42
+ const { z } = require('zod')
43
+ framework.registerTool({
44
+ name: 'my_tool',
45
+ description: '工具描述',
46
+ inputSchema: z.object({
47
+ param: z.string().describe('参数描述')
48
+ }),
49
+ execute: async (args, framework) => {
50
+ return { success: true, result: args.param }
51
+ }
52
+ })
53
+ return this
54
+ }
55
+
56
+ uninstall(framework) {
57
+ // cleanup
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ **Key points:**
64
+ - `Plugin` base class passed automatically by system (no require needed)
65
+ - Factory function returns plugin class
66
+ - Use `require('zod')` inside methods
67
+
68
+ ### Traditional format for `plugins/` (built-in)
69
+
70
+ ```javascript
71
+ // plugins/my-plugin.js
72
+ const { Plugin } = require('../src/core/plugin-base')
73
+ const { z } = require('zod')
74
+
75
+ class MyPlugin extends Plugin {
76
+ constructor(config = {}) {
77
+ super()
78
+ this.name = 'my-plugin'
79
+ this.version = '1.0.0'
80
+ this.description = '我的插件'
81
+ this.priority = 10
82
+ }
83
+
84
+ install(framework) {
85
+ framework.registerTool({
86
+ name: 'my_tool',
87
+ description: '工具描述',
88
+ inputSchema: z.object({
89
+ param: z.string().describe('参数描述')
90
+ }),
91
+ execute: async (args, framework) => {
92
+ return { success: true, result: args.param }
93
+ }
94
+ })
95
+ return this
96
+ }
97
+
98
+ uninstall(framework) { }
99
+ }
100
+
101
+ module.exports = { MyPlugin }
102
+ ```
103
+
104
+ ## Plugin Properties
105
+
106
+ | Property | Type | Required | Description |
107
+ |----------|------|----------|-------------|
108
+ | `name` | string | ✅ | Unique name |
109
+ | `version` | string | ❌ | Version, default '1.0.0' |
110
+ | `description` | string | ❌ | Description |
111
+ | `priority` | number | ❌ | Load priority, default 10 |
112
+
113
+ ## Lifecycle Methods
114
+
115
+ | Method | Called When | Required |
116
+ |--------|-------------|----------|
117
+ | `install(framework)` | Plugin installed | ✅ |
118
+ | `start(framework)` | Plugin started | Recommended |
119
+ | `reload(framework)` | Hot reload | Optional |
120
+ | `uninstall(framework)` | Plugin uninstalled | Recommended |
121
+
122
+ ## Tool Registration
123
+
124
+ In `install()` method, register tools using `framework.registerTool()`:
125
+
126
+ ```javascript
127
+ install(framework) {
128
+ const { z } = require('zod')
129
+ framework.registerTool({
130
+ name: 'my_tool',
131
+ description: '工具描述',
132
+ inputSchema: z.object({
133
+ param: z.string().describe('参数描述')
134
+ }),
135
+ execute: async (args, framework) => {
136
+ return { success: true, result: args.param }
137
+ }
138
+ })
139
+ return this
140
+ }
141
+ ```
142
+
143
+ ## Framework Object
144
+
145
+ The framework object provides:
146
+
147
+ | Method | Description |
148
+ |--------|-------------|
149
+ | `framework.registerTool(tool)` | Register tool |
150
+ | `framework.getTools()` | Get all tools |
151
+ | `framework.executeTool(name, args)` | Execute tool |
152
+ | `framework.createAgent(config)` | Create Agent |
153
+ | `framework.reloadPlugin(name)` | Reload single plugin |
154
+ | `framework.reloadAllPlugins()` | Reload all plugins |
155
+
156
+ ## Common Mistakes
157
+
158
+ 1. ❌ Creating directory `plugins/my-plugin/index.js` - must be single file
159
+ 2. ❌ Forgetting `install()` - tools won't be registered
160
+ 3. ❌ Forgetting `return this` - chain calls will fail
161
+ 4. ❌ Using `parameters` instead of `inputSchema`
162
+ 5. ❌ Registering tools outside `install()`
@@ -0,0 +1,370 @@
1
+ ---
2
+ name: vb-agent-dev
3
+ description: VB-Agent Framework 插件开发指南。当用户说"创建插件"、"开发插件"时立即调用此 skill。
4
+ allowed-tools: Read, Write, Edit, Glob, Grep, Bash
5
+ ---
6
+
7
+ # VB-Agent Plugin Development Guide
8
+
9
+ ## 概述
10
+
11
+ VB-Agent 是一个基于插件的 Agent 框架,核心简单,通过插件扩展功能。
12
+
13
+ ---
14
+
15
+ ## 插件存放位置
16
+
17
+ ### `.agent/plugins/` 目录(用户插件,自动加载)
18
+
19
+ 用户自定义插件放在项目根目录的 `.agent/plugins/` 下,**自动加载**,无需手动注册。
20
+
21
+ ```
22
+ 项目目录/
23
+ └── .agent/
24
+ └── plugins/
25
+ ├── my-plugin.js ✅ 正确
26
+ └── another-plugin.js ✅ 正确
27
+ ```
28
+
29
+ ### `plugins/` 目录(内置插件)
30
+
31
+ 框架内置插件位于 `plugins/` 目录。
32
+
33
+ ---
34
+
35
+ ## 用户插件写法(`.agent/plugins/`)
36
+
37
+ **必须使用免引入写法**:
38
+
39
+ ```javascript
40
+ // .agent/plugins/my-plugin.js
41
+ module.exports = function(Plugin) {
42
+ return class MyPlugin extends Plugin {
43
+ constructor(config = {}) {
44
+ super()
45
+ this.name = 'my-plugin'
46
+ this.version = '1.0.0'
47
+ this.description = '我的工具插件'
48
+ this.priority = 10
49
+ }
50
+
51
+ install(framework) {
52
+ const { z } = require('zod')
53
+ framework.registerTool({
54
+ name: 'my_tool',
55
+ description: '我的工具',
56
+ inputSchema: z.object({
57
+ param: z.string().describe('参数描述')
58
+ }),
59
+ execute: async (args, framework) => {
60
+ return { success: true, result: args.param }
61
+ }
62
+ })
63
+ return this
64
+ }
65
+
66
+ uninstall(framework) {
67
+ // 清理资源
68
+ }
69
+ }
70
+ }
71
+ ```
72
+ **插件开发流程:**
73
+ 1. **创建插件文件**(暂不加载)
74
+ 2. **安装依赖**:`install { package: "包名" }`
75
+ 3. **热重载**:`reload_plugins`
76
+ 4. **检查加载状态**
77
+
78
+
79
+ **关键点:**
80
+ - `Plugin` 基类由系统自动传入(无需 require)
81
+ - 函数直接返回插件类
82
+ - 在 `install(framework)` 中通过 `framework` 注册工具
83
+
84
+ ---
85
+
86
+ ## 依赖管理
87
+
88
+ 当插件需要使用第三方 npm 包(如 `zod`、`axios` 等)时,必须自动安装到 `.agent/node_modules`:
89
+
90
+ ### 自动安装工具
91
+
92
+ 框架提供了 `install` 工具,可以自动安装 npm 包:
93
+
94
+ ```javascript
95
+ // 在 execute 中调用 install 工具
96
+ execute: async (args, framework) => {
97
+ // 安装缺失的包
98
+ const installResult = await framework.callTool('install', {
99
+ package: 'zod' // 或 'zod@4.3.6' 指定版本
100
+ })
101
+
102
+ if (!installResult.success) {
103
+ return { success: false, error: installResult.error }
104
+ }
105
+
106
+ // 安装成功后可以正常 require
107
+ const { z } = require('zod')
108
+ // ... 继续执行
109
+ }
110
+ ```
111
+
112
+ ### 安装步骤
113
+
114
+ 当 LLM 检测到 `Cannot find module 'xxx'` 错误时,必须:
115
+
116
+ 1. **立即调用 `install` 工具** 安装缺失的包
117
+ 2. **安装完成后** 重新加载插件
118
+ 3. **返回状态** 给用户
119
+
120
+ 示例流程:
121
+ ```
122
+ 错误: Cannot find module 'axios'
123
+
124
+ 自动安装: install { package: "axios" }
125
+
126
+ 重新加载插件
127
+
128
+ 成功
129
+ ```
130
+
131
+ ### 重要提醒
132
+
133
+ - **不要尝试手动 require 全局安装的包** - 必须在 `.agent/node_modules` 中安装
134
+ - **使用 `install` 工具自动处理** - 让 LLM 知道如何处理缺失依赖
135
+ - **插件加载失败时检查依赖** - 优先安装缺失的包再重试
136
+
137
+ ---
138
+
139
+ ## 内置插件写法(`plugins/` 目录)
140
+
141
+ 内置插件使用传统写法,需要 `require` Plugin 基类:
142
+
143
+ ```javascript
144
+ // plugins/my-plugin.js
145
+ const { Plugin } = require('../src/core/plugin-base')
146
+ const { z } = require('zod')
147
+
148
+ class MyPlugin extends Plugin {
149
+ constructor(config = {}) {
150
+ super()
151
+ this.name = 'my-plugin'
152
+ this.version = '1.0.0'
153
+ this.description = '我的工具插件'
154
+ this.priority = 10
155
+ }
156
+
157
+ install(framework) {
158
+ framework.registerTool({
159
+ name: 'my_tool',
160
+ description: '我的工具',
161
+ inputSchema: z.object({
162
+ param: z.string().describe('参数描述')
163
+ }),
164
+ execute: async (args, framework) => {
165
+ return { success: true, result: args.param }
166
+ }
167
+ })
168
+ return this
169
+ }
170
+
171
+ uninstall(framework) { }
172
+ }
173
+
174
+ module.exports = { MyPlugin }
175
+ ```
176
+
177
+ ---
178
+
179
+ ## 插件属性
180
+
181
+ | 属性 | 类型 | 必须 | 说明 |
182
+ |------|------|------|------|
183
+ | `name` | string | ✅ | 唯一名称 |
184
+ | `version` | string | ❌ | 版本号,默认 '1.0.0' |
185
+ | `description` | string | ❌ | 插件描述 |
186
+ | `priority` | number | ❌ | 加载优先级,默认 10 |
187
+
188
+ ---
189
+
190
+ ## 生命周期
191
+
192
+ | 方法 | 调用时机 | 必须实现 |
193
+ |------|----------|---------|
194
+ | `install(framework)` | 插件安装时 | ✅ |
195
+ | `start(framework)` | 插件启动时 | 推荐 |
196
+ | `reload(framework)` | 热重载时 | 可选 |
197
+ | `uninstall(framework)` | 卸载时 | 推荐 |
198
+
199
+ ---
200
+
201
+ ## 注册工具
202
+
203
+ ```javascript
204
+ install(framework) {
205
+ const { z } = require('zod')
206
+ framework.registerTool({
207
+ name: 'my_tool',
208
+ description: '工具描述',
209
+ inputSchema: z.object({
210
+ param: z.string().describe('参数描述')
211
+ }),
212
+ execute: async (args, framework) => {
213
+ return { success: true, result: args.param }
214
+ }
215
+ })
216
+ return this
217
+ }
218
+ ```
219
+
220
+ ---
221
+
222
+ ## 核心规则
223
+
224
+ | 规则 | 说明 |
225
+ |------|------|
226
+ | **禁止创建目录!** | **必须是单个 `.js` 文件!** |
227
+ | **必须用 inputSchema** | `inputSchema: z.object({})`(不是 parameters!) |
228
+ | **必须用 zod 定义参数** | `param: z.string().describe('描述')` |
229
+ | **install 必须返回 this** | 确保链式调用 |
230
+
231
+ ## 开发完成后注意事项
232
+
233
+ ### 引入第三方库时
234
+
235
+ **必须先安装依赖,再热重载!**
236
+
237
+ 如果插件需要使用第三方 npm 包(如 `zod`、`axios`),按以下顺序操作:
238
+
239
+ 1. **创建插件文件**(暂不加载)
240
+ 2. **安装依赖**:`install { package: "包名" }`
241
+ 3. **热重载**:`reload_plugins`
242
+ 4. **检查加载状态**
243
+
244
+ 示例:
245
+ ```
246
+ 创建插件 my-plugin.js(需要 zod)
247
+
248
+ install { package: "zod" }
249
+
250
+ reload_plugins
251
+
252
+ 成功加载
253
+ ```
254
+
255
+ ### 其他注意事项
256
+ --**开发完成重载成功后检测有没有加载新的插件,不需要进行过多测试步骤,直接告知用户状态即可**
257
+
258
+ ---
259
+
260
+ ## 内置占位符
261
+
262
+ Agent 支持 `sharedPrompt` 中的占位符替换:
263
+
264
+ | 占位符 | 说明 |
265
+ |--------|------|
266
+ | `{{WORK_DIR}}` | 工作目录 |
267
+ | `{{HOME_DIR}}` | 主目录 |
268
+ | `{{HOST_NAME}}` | 主机名 |
269
+ | `{{PLATFORM}}` | 平台 |
270
+ | `{{TIME}}` | 当前时间 |
271
+ | `{{DATE}}` | 当前日期 |
272
+
273
+ ---
274
+
275
+ ## 创建 Agent
276
+
277
+ ```javascript
278
+ const agent = framework.createAgent({
279
+ name: 'MyAgent',
280
+ systemPrompt: '你是一个助手',
281
+ sharedPrompt: '工作目录: {{WORK_DIR}}\n项目: {{projectName}}',
282
+ metadata: {
283
+ projectName: 'MyProject',
284
+ version: '1.0.0'
285
+ }
286
+ })
287
+ ```
288
+
289
+ ---
290
+
291
+ ## 热重载
292
+
293
+ ```javascript
294
+ // 重载单个插件
295
+ await framework.reloadPlugin('my-plugin')
296
+
297
+ // 重载所有插件
298
+ await framework.reloadAllPlugins()
299
+ ```
300
+
301
+ ---
302
+
303
+ ## 子 Agent 注册
304
+
305
+ 插件可以通过 `this.agents = []` 配置或 `this.registerSubAgent()` 方法注册子Agent。
306
+
307
+ ### 方式1:配置 `agents` 数组
308
+
309
+ ```javascript
310
+ // plugins/my-plugin.js
311
+ const { Plugin } = require('../src/core/plugin-base')
312
+ const { tool } = require('ai')
313
+ const { z } = require('zod')
314
+
315
+ class MyPlugin extends Plugin {
316
+ constructor(config = {}) {
317
+ super()
318
+ this.name = 'my-plugin'
319
+ }
320
+
321
+ // 配置式注册子Agent,插件启动时自动创建
322
+ agents = [
323
+ {
324
+ name: 'code-agent',
325
+ role: '代码专家',
326
+ description: '处理代码开发任务',
327
+ tools: {
328
+ compile: tool({
329
+ description: '编译代码',
330
+ parameters: z.object({
331
+ language: z.string(),
332
+ code: z.string()
333
+ }),
334
+ execute: async (args) => ({ success: true })
335
+ })
336
+ },
337
+ parentTools: ['read_file', 'write_file']
338
+ }
339
+ ]
340
+ }
341
+ ```
342
+
343
+ ### 方式2:手动调用 `registerSubAgent()`
344
+
345
+ ```javascript
346
+ start(framework) {
347
+ this.registerSubAgent({
348
+ name: 'code-agent',
349
+ role: '代码专家',
350
+ tools: {
351
+ compile: tool({
352
+ description: '编译代码',
353
+ parameters: z.object({ language: z.string(), code: z.string() }),
354
+ execute: async (args) => ({ success: true })
355
+ })
356
+ },
357
+ parentTools: ['read_file', 'write_file']
358
+ })
359
+ }
360
+ ```
361
+
362
+ ### 子Agent配置说明
363
+
364
+ | 字段 | 类型 | 说明 |
365
+ |------|------|------|
366
+ | `name` | string | 子Agent名称(唯一标识) |
367
+ | `role` | string | 角色描述 |
368
+ | `description` | string | 详细描述 |
369
+ | `tools` | object | 自定义工具 `{ name: toolDef }`,只属于此子Agent |
370
+ | `parentTools` | array | 从父Agent继承的工具名称列表 |
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Capabilities 能力模块导出
3
+ */
4
+
5
+ const { SkillManagerPlugin } = require('./skill-manager')
6
+ const { WorkflowPlugin } = require('./workflow-engine')
7
+
8
+ module.exports = {
9
+ SkillManagerPlugin,
10
+ WorkflowPlugin
11
+ }