foliko 1.0.0 → 1.0.1
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.
- package/README.md +132 -172
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,217 +1,177 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Foliko
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
简约的插件化 Agent 框架
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 特性
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
7
|
+
- **插件化架构** - 核心简单,通过插件扩展功能
|
|
8
|
+
- **流式输出** - 支持实时流式输出
|
|
9
|
+
- **多 AI 支持** - 支持 Anthropic、DeepSeek、MiniMax 等
|
|
10
|
+
- **内置工具** - Shell、Python、MCP、文件系统等
|
|
11
|
+
- **技能系统** - 可扩展的 Skill 管理
|
|
12
|
+
- **会话管理** - 支持多会话切换
|
|
13
|
+
- **规则引擎** - 可配置的行为规则
|
|
10
14
|
|
|
11
|
-
##
|
|
15
|
+
## 快速开始
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- 边界情况测试
|
|
17
|
-
- 异常测试
|
|
18
|
-
|
|
19
|
-
### 2. 异步测试
|
|
20
|
-
- Promise 测试
|
|
21
|
-
- async/await 测试
|
|
22
|
-
- 超时处理
|
|
23
|
-
|
|
24
|
-
### 3. 集成测试
|
|
25
|
-
- 多个类的组合测试
|
|
26
|
-
- 完整流程测试
|
|
27
|
-
|
|
28
|
-
### 4. Mock 和 Spy
|
|
29
|
-
- 模拟函数
|
|
30
|
-
- 模拟 API 调用
|
|
31
|
-
- 验证函数调用
|
|
32
|
-
|
|
33
|
-
### 5. 参数化测试
|
|
34
|
-
- 使用 `test.each` 测试多组数据
|
|
35
|
-
|
|
36
|
-
### 6. 快照测试
|
|
37
|
-
- 对象结构验证
|
|
38
|
-
|
|
39
|
-
## 最佳实践展示
|
|
17
|
+
```bash
|
|
18
|
+
# 安装
|
|
19
|
+
npm install
|
|
40
20
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
test('应该正确计算两个数的和', () => {
|
|
44
|
-
// Arrange: 准备测试数据
|
|
45
|
-
const a = 5;
|
|
46
|
-
const b = 3;
|
|
47
|
-
const expected = 8;
|
|
48
|
-
|
|
49
|
-
// Act: 执行被测试的方法
|
|
50
|
-
const result = calculator.add(a, b);
|
|
51
|
-
|
|
52
|
-
// Assert: 验证结果
|
|
53
|
-
expect(result).toBe(expected);
|
|
54
|
-
});
|
|
21
|
+
# 启动聊天
|
|
22
|
+
npm run chat
|
|
55
23
|
```
|
|
56
24
|
|
|
57
|
-
|
|
58
|
-
- 使用 "should" 描述预期行为
|
|
59
|
-
- 包含测试条件
|
|
60
|
-
- 清晰表达测试目的
|
|
61
|
-
|
|
62
|
-
### 3. 测试隔离
|
|
63
|
-
- 每个测试独立运行
|
|
64
|
-
- 使用 `beforeEach` 重置状态
|
|
65
|
-
- 避免测试间的依赖
|
|
25
|
+
## 项目结构
|
|
66
26
|
|
|
67
|
-
|
|
68
|
-
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
## 安装和运行
|
|
79
|
-
|
|
80
|
-
### 1. 安装依赖
|
|
81
|
-
```bash
|
|
82
|
-
npm install
|
|
27
|
+
```
|
|
28
|
+
vb-agent/
|
|
29
|
+
├── cli/ # 命令行入口
|
|
30
|
+
│ └── bin/foliko.js # CLI 入口
|
|
31
|
+
├── src/ # 核心框架
|
|
32
|
+
│ ├── core/ # 核心组件
|
|
33
|
+
│ ├── capabilities/ # 能力插件
|
|
34
|
+
│ └── executors/ # 执行器
|
|
35
|
+
├── plugins/ # 内置插件
|
|
36
|
+
├── skills/ # 技能目录
|
|
37
|
+
└── examples/ # 示例
|
|
83
38
|
```
|
|
84
39
|
|
|
85
|
-
|
|
86
|
-
```bash
|
|
87
|
-
# 运行所有测试
|
|
88
|
-
npm test
|
|
40
|
+
## 配置
|
|
89
41
|
|
|
90
|
-
|
|
91
|
-
npm run test:watch
|
|
42
|
+
在项目根目录创建 `.agent` 目录:
|
|
92
43
|
|
|
93
|
-
|
|
94
|
-
|
|
44
|
+
```
|
|
45
|
+
.agent/
|
|
46
|
+
├── config # 配置文件
|
|
47
|
+
├── ai.json # AI 配置
|
|
48
|
+
├── mcp_config.json # MCP 服务器配置
|
|
49
|
+
├── plugins/ # 用户插件目录
|
|
50
|
+
├── skills/ # 用户技能目录
|
|
51
|
+
└── data/ # 数据目录
|
|
52
|
+
```
|
|
95
53
|
|
|
96
|
-
|
|
97
|
-
npm run test:verbose
|
|
54
|
+
### config 文件格式
|
|
98
55
|
|
|
99
|
-
|
|
100
|
-
|
|
56
|
+
```
|
|
57
|
+
ai_key: your-api-key
|
|
58
|
+
ai_model: MiniMax-M2.7
|
|
59
|
+
ai_provider: minimax
|
|
101
60
|
```
|
|
102
61
|
|
|
103
|
-
###
|
|
104
|
-
运行 `npm run test:coverage` 后,打开 `coverage/index.html` 查看详细的覆盖率报告。
|
|
62
|
+
### ai.json 格式
|
|
105
63
|
|
|
106
|
-
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"provider": "minimax",
|
|
67
|
+
"model": "MiniMax-M2.7",
|
|
68
|
+
"apiKey": "your-api-key",
|
|
69
|
+
"baseURL": "https://api.minimaxi.com/v1"
|
|
70
|
+
}
|
|
71
|
+
```
|
|
107
72
|
|
|
108
|
-
|
|
73
|
+
### mcp_config.json 格式
|
|
109
74
|
|
|
110
75
|
```json
|
|
111
76
|
{
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"coverageReporters": ["text", "lcov", "html"], // 报告格式
|
|
118
|
-
"coverageThreshold": { // 覆盖率阈值
|
|
119
|
-
"global": {
|
|
120
|
-
"branches": 80,
|
|
121
|
-
"functions": 80,
|
|
122
|
-
"lines": 80,
|
|
123
|
-
"statements": 80
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
"testMatch": [ // 测试文件匹配模式
|
|
127
|
-
"**/__tests__/**/*.js",
|
|
128
|
-
"**/?(*.)+(spec|test).js"
|
|
129
|
-
],
|
|
130
|
-
"testTimeout": 10000, // 测试超时时间
|
|
131
|
-
"clearMocks": true, // 自动清理 mock
|
|
132
|
-
"resetMocks": true, // 重置 mock
|
|
133
|
-
"restoreMocks": true // 恢复原始实现
|
|
77
|
+
"mcpServers": {
|
|
78
|
+
"fetch": {
|
|
79
|
+
"command": "npx",
|
|
80
|
+
"args": ["-y", "@modelcontextprotocol/server-fetch"]
|
|
81
|
+
}
|
|
134
82
|
}
|
|
135
83
|
}
|
|
136
84
|
```
|
|
137
85
|
|
|
138
|
-
##
|
|
86
|
+
## 开发插件
|
|
87
|
+
|
|
88
|
+
### 用户插件(.agent/plugins/)
|
|
139
89
|
|
|
140
|
-
### 1. 测试异步代码
|
|
141
90
|
```javascript
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
91
|
+
// .agent/plugins/my-plugin.js
|
|
92
|
+
module.exports = function(Plugin) {
|
|
93
|
+
return class MyPlugin extends Plugin {
|
|
94
|
+
constructor(config = {}) {
|
|
95
|
+
super()
|
|
96
|
+
this.name = 'my-plugin'
|
|
97
|
+
this.version = '1.0.0'
|
|
98
|
+
this.description = '我的工具插件'
|
|
99
|
+
this.priority = 10
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
install(framework) {
|
|
103
|
+
const { z } = require('zod')
|
|
104
|
+
framework.registerTool({
|
|
105
|
+
name: 'my_tool',
|
|
106
|
+
description: '我的工具',
|
|
107
|
+
inputSchema: z.object({
|
|
108
|
+
param: z.string().describe('参数描述')
|
|
109
|
+
}),
|
|
110
|
+
execute: async (args, framework) => {
|
|
111
|
+
return { success: true, result: args.param }
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
return this
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
152
118
|
```
|
|
153
119
|
|
|
154
|
-
|
|
155
|
-
```javascript
|
|
156
|
-
// 创建 mock 函数
|
|
157
|
-
const mockFn = jest.fn();
|
|
120
|
+
**注意**:如果插件需要第三方库(如 `zod`),需要先安装:
|
|
158
121
|
|
|
159
|
-
|
|
160
|
-
|
|
122
|
+
1. 创建插件文件
|
|
123
|
+
2. 调用 `install` 工具安装依赖
|
|
124
|
+
3. 热重载插件
|
|
161
125
|
|
|
162
|
-
|
|
163
|
-
expect(mockFn).toHaveBeenCalledTimes(1);
|
|
164
|
-
expect(mockFn).toHaveBeenCalledWith('参数');
|
|
165
|
-
```
|
|
126
|
+
### 技能开发
|
|
166
127
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
[2, 1, 3],
|
|
173
|
-
])('add(%i, %i) should equal %i', (a, b, expected) => {
|
|
174
|
-
expect(a + b).toBe(expected);
|
|
175
|
-
});
|
|
128
|
+
在 `.agent/skills/` 下创建技能:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
.agent/skills/my-skill/
|
|
132
|
+
└── SKILL.md
|
|
176
133
|
```
|
|
177
134
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
date: expect.any(Date) // 忽略具体日期值
|
|
189
|
-
});
|
|
190
|
-
});
|
|
135
|
+
SKILL.md 格式:
|
|
136
|
+
|
|
137
|
+
```markdown
|
|
138
|
+
---
|
|
139
|
+
name: my-skill
|
|
140
|
+
description: 技能描述
|
|
141
|
+
allowed-tools: tool1,tool2
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
技能内容...
|
|
191
145
|
```
|
|
192
146
|
|
|
193
|
-
##
|
|
147
|
+
## CLI 命令
|
|
194
148
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
149
|
+
```bash
|
|
150
|
+
# 聊天模式
|
|
151
|
+
foliko chat
|
|
152
|
+
|
|
153
|
+
# 指定模型
|
|
154
|
+
foliko chat --model gpt-4
|
|
155
|
+
|
|
156
|
+
# 指定 API
|
|
157
|
+
foliko chat --api-key xxx
|
|
158
|
+
```
|
|
199
159
|
|
|
200
|
-
|
|
201
|
-
- 确保测试独立
|
|
202
|
-
- 避免依赖外部状态
|
|
203
|
-
- 使用固定的测试数据
|
|
160
|
+
## 内置工具
|
|
204
161
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
162
|
+
| 工具 | 说明 |
|
|
163
|
+
|------|------|
|
|
164
|
+
| `loadSkill` | 加载技能 |
|
|
165
|
+
| `mcp_execute` | 执行 MCP 工具 |
|
|
166
|
+
| `shell_execute` | 执行 Shell 命令 |
|
|
167
|
+
| `python_execute` | 执行 Python 代码 |
|
|
168
|
+
| `install` | 安装 npm 包 |
|
|
169
|
+
| `mcp_reload` | 重载 MCP 服务器 |
|
|
170
|
+
| `audit_query` | 查询审计日志 |
|
|
209
171
|
|
|
210
|
-
##
|
|
172
|
+
## 工作目录
|
|
211
173
|
|
|
212
|
-
|
|
213
|
-
- [测试金字塔原则](https://martinfowler.com/bliki/TestPyramid.html)
|
|
214
|
-
- [AAA 测试模式](https://medium.com/@pjbgf/title-testing-code-ocd-and-the-aaa-pattern-df453975ab80)
|
|
174
|
+
CLI 工作目录默认使用执行命令的目录。
|
|
215
175
|
|
|
216
176
|
## 许可证
|
|
217
177
|
|