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.
- package/.claude/settings.local.json +30 -0
- package/22.txt +10 -0
- package/README.md +218 -0
- package/SPEC.md +452 -0
- package/cli/bin/foliko.js +12 -0
- package/cli/src/commands/chat.js +75 -0
- package/cli/src/index.js +64 -0
- package/cli/src/ui/chat-ui.js +272 -0
- package/cli/src/utils/ansi.js +40 -0
- package/cli/src/utils/markdown.js +296 -0
- package/docs/quick-reference.md +131 -0
- package/docs/user-manual.md +1205 -0
- package/examples/basic.js +110 -0
- package/examples/bootstrap.js +93 -0
- package/examples/mcp-example.js +53 -0
- package/examples/skill-example.js +49 -0
- package/examples/workflow.js +158 -0
- package/package.json +36 -0
- package/plugins/ai-plugin.js +89 -0
- package/plugins/audit-plugin.js +187 -0
- package/plugins/default-plugins.js +412 -0
- package/plugins/file-system-plugin.js +344 -0
- package/plugins/install-plugin.js +93 -0
- package/plugins/python-executor-plugin.js +331 -0
- package/plugins/rules-plugin.js +292 -0
- package/plugins/scheduler-plugin.js +426 -0
- package/plugins/session-plugin.js +343 -0
- package/plugins/shell-executor-plugin.js +196 -0
- package/plugins/storage-plugin.js +237 -0
- package/plugins/subagent-plugin.js +395 -0
- package/plugins/think-plugin.js +329 -0
- package/plugins/tools-plugin.js +114 -0
- package/skills/mcp-usage/SKILL.md +198 -0
- package/skills/vb-agent-dev/AGENTS.md +162 -0
- package/skills/vb-agent-dev/SKILL.md +370 -0
- package/src/capabilities/index.js +11 -0
- package/src/capabilities/skill-manager.js +319 -0
- package/src/capabilities/workflow-engine.js +401 -0
- package/src/core/agent-chat.js +311 -0
- package/src/core/agent.js +573 -0
- package/src/core/framework.js +255 -0
- package/src/core/index.js +19 -0
- package/src/core/plugin-base.js +205 -0
- package/src/core/plugin-manager.js +392 -0
- package/src/core/provider.js +108 -0
- package/src/core/tool-registry.js +134 -0
- package/src/core/tool-router.js +216 -0
- package/src/executors/executor-base.js +58 -0
- package/src/executors/mcp-executor.js +728 -0
- package/src/index.js +37 -0
- package/src/utils/event-emitter.js +97 -0
- package/test-chat.js +129 -0
- package/test-mcp.js +79 -0
- package/test-reload.js +61 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VB-Agent Framework
|
|
3
|
+
* 简约的插件化 Agent 框架
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
Framework,
|
|
8
|
+
Agent,
|
|
9
|
+
Plugin,
|
|
10
|
+
PluginManager,
|
|
11
|
+
ToolRegistry,
|
|
12
|
+
EventEmitter
|
|
13
|
+
} = require('./core')
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
SkillManagerPlugin,
|
|
17
|
+
WorkflowPlugin
|
|
18
|
+
} = require('./capabilities')
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
MCPExecutorPlugin
|
|
22
|
+
} = require('./executors/mcp-executor')
|
|
23
|
+
|
|
24
|
+
module.exports = {
|
|
25
|
+
// 核心
|
|
26
|
+
Framework,
|
|
27
|
+
Agent,
|
|
28
|
+
Plugin,
|
|
29
|
+
PluginManager,
|
|
30
|
+
ToolRegistry,
|
|
31
|
+
EventEmitter,
|
|
32
|
+
|
|
33
|
+
// 能力插件
|
|
34
|
+
SkillManagerPlugin,
|
|
35
|
+
WorkflowPlugin,
|
|
36
|
+
MCPExecutorPlugin
|
|
37
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventEmitter 事件发射器
|
|
3
|
+
* 简单的事件总线实现
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
class EventEmitter {
|
|
7
|
+
constructor() {
|
|
8
|
+
this._events = new Map()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 监听事件
|
|
13
|
+
* @param {string} event - 事件名
|
|
14
|
+
* @param {Function} handler - 处理函数
|
|
15
|
+
* @returns {this}
|
|
16
|
+
*/
|
|
17
|
+
on(event, handler) {
|
|
18
|
+
if (!this._events.has(event)) {
|
|
19
|
+
this._events.set(event, new Set())
|
|
20
|
+
}
|
|
21
|
+
this._events.get(event).add(handler)
|
|
22
|
+
return this
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 监听一次性事件
|
|
27
|
+
* @param {string} event - 事件名
|
|
28
|
+
* @param {Function} handler - 处理函数
|
|
29
|
+
* @returns {this}
|
|
30
|
+
*/
|
|
31
|
+
once(event, handler) {
|
|
32
|
+
const wrapper = (...args) => {
|
|
33
|
+
handler(...args)
|
|
34
|
+
this.off(event, wrapper)
|
|
35
|
+
}
|
|
36
|
+
return this.on(event, wrapper)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 取消监听
|
|
41
|
+
* @param {string} event - 事件名
|
|
42
|
+
* @param {Function} handler - 处理函数
|
|
43
|
+
* @returns {this}
|
|
44
|
+
*/
|
|
45
|
+
off(event, handler) {
|
|
46
|
+
const handlers = this._events.get(event)
|
|
47
|
+
if (handlers) {
|
|
48
|
+
handlers.delete(handler)
|
|
49
|
+
}
|
|
50
|
+
return this
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 触发事件
|
|
55
|
+
* @param {string} event - 事件名
|
|
56
|
+
* @param {...any} args - 参数
|
|
57
|
+
* @returns {this}
|
|
58
|
+
*/
|
|
59
|
+
emit(event, ...args) {
|
|
60
|
+
const handlers = this._events.get(event)
|
|
61
|
+
if (handlers) {
|
|
62
|
+
for (const handler of handlers) {
|
|
63
|
+
try {
|
|
64
|
+
handler(...args)
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.error(`[EventEmitter] Error in handler for '${event}':`, err)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return this
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 移除所有监听器
|
|
75
|
+
* @param {string} [event] - 可选,指定事件名
|
|
76
|
+
* @returns {this}
|
|
77
|
+
*/
|
|
78
|
+
removeAllListeners(event) {
|
|
79
|
+
if (event) {
|
|
80
|
+
this._events.delete(event)
|
|
81
|
+
} else {
|
|
82
|
+
this._events.clear()
|
|
83
|
+
}
|
|
84
|
+
return this
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 获取监听器数量
|
|
89
|
+
* @param {string} event - 事件名
|
|
90
|
+
* @returns {number}
|
|
91
|
+
*/
|
|
92
|
+
listenerCount(event) {
|
|
93
|
+
return this._events.get(event)?.size || 0
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
module.exports = { EventEmitter }
|
package/test-chat.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 持续聊天测试
|
|
3
|
+
* 运行后可以在终端输入消息与 Agent 对话
|
|
4
|
+
* 支持多行输入:连续按两次回车结束输入
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { Framework } = require('./src')
|
|
8
|
+
const readline = require('readline')
|
|
9
|
+
require('dotenv').config()
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
console.log('=== VB-Agent 持续聊天测试 ===\n')
|
|
13
|
+
console.log('输入消息与 Agent 对话,输入 exit 或 quit 退出')
|
|
14
|
+
console.log('多行输入:按两次回车结束,或输入 !! 立即结束\n')
|
|
15
|
+
|
|
16
|
+
// 创建框架
|
|
17
|
+
const framework = new Framework({ debug: false })
|
|
18
|
+
|
|
19
|
+
// Bootstrap
|
|
20
|
+
await framework.bootstrap({
|
|
21
|
+
agentDir: './.agent',
|
|
22
|
+
aiConfig: {
|
|
23
|
+
provider: 'minimax',
|
|
24
|
+
model: 'MiniMax-M2.7',
|
|
25
|
+
baseURL:'https://api.minimaxi.com/v1',
|
|
26
|
+
apiKey: process.env.MINIMAX_API_KEY
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
console.log('框架已就绪\n')
|
|
31
|
+
|
|
32
|
+
// 创建 Agent
|
|
33
|
+
const agent = framework.createAgent({
|
|
34
|
+
name: 'TestAgent',
|
|
35
|
+
systemPrompt: '你是一个有帮助的助手,擅长回答问题和执行任务。',
|
|
36
|
+
sharedPrompt: '工作目录: {{WORK_DIR}}',
|
|
37
|
+
metadata: {
|
|
38
|
+
projectName: 'VB-Agent',
|
|
39
|
+
version: '1.0.0'
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// 创建命令行界面
|
|
44
|
+
const rl = readline.createInterface({
|
|
45
|
+
input: process.stdin,
|
|
46
|
+
output: process.stdout
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// 多行输入函数
|
|
50
|
+
const readMultiline = () => {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
const lines = []
|
|
53
|
+
|
|
54
|
+
const question = () => {
|
|
55
|
+
rl.question(lines.length === 0 ? 'You: ' : '> ', (input) => {
|
|
56
|
+
// 输入 !! 立即结束
|
|
57
|
+
if (input.trim() === '!!') {
|
|
58
|
+
const result = lines.join('\n').trim()
|
|
59
|
+
resolve(result)
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
// 空行结束输入
|
|
63
|
+
if (input.trim() === '') {
|
|
64
|
+
const result = lines.join('\n').trim()
|
|
65
|
+
resolve(result)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
lines.push(input)
|
|
69
|
+
question()
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
question()
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 提问函数
|
|
77
|
+
const ask = async (question) => {
|
|
78
|
+
try {
|
|
79
|
+
console.log('\n[Agent 思考中...]\n')
|
|
80
|
+
|
|
81
|
+
// 使用流式响应
|
|
82
|
+
let fullResponse = ''
|
|
83
|
+
for await (const chunk of agent.chatStream(question)) {
|
|
84
|
+
if (chunk.type === 'text') {
|
|
85
|
+
process.stdout.write(chunk.text)
|
|
86
|
+
fullResponse += chunk.text
|
|
87
|
+
} else if (chunk.type === 'tool-call') {
|
|
88
|
+
console.log('\n\n[工具调用]', chunk.toolName)
|
|
89
|
+
} else if (chunk.type === 'tool-result') {
|
|
90
|
+
console.log('\n[工具结果]', JSON.stringify(chunk.result).substring(0, 100))
|
|
91
|
+
} else if (chunk.type === 'error') {
|
|
92
|
+
console.error('\n[错误]', chunk.error)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
console.log('\n')
|
|
97
|
+
return fullResponse
|
|
98
|
+
} catch (err) {
|
|
99
|
+
console.error('\n[错误]', err.message)
|
|
100
|
+
return ''
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 欢迎消息
|
|
105
|
+
console.log('Agent: 你好!有什么可以帮助你的吗?\n')
|
|
106
|
+
|
|
107
|
+
// 主循环
|
|
108
|
+
const promptUser = async () => {
|
|
109
|
+
const input = await readMultiline()
|
|
110
|
+
const trimmed = input.trim()
|
|
111
|
+
|
|
112
|
+
if (trimmed.toLowerCase() === 'exit' || trimmed.toLowerCase() === 'quit') {
|
|
113
|
+
console.log('\n再见!')
|
|
114
|
+
await framework.destroy()
|
|
115
|
+
rl.close()
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (trimmed) {
|
|
120
|
+
await ask(trimmed)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
promptUser()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
promptUser()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
main().catch(console.error)
|
package/test-mcp.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP 插件测试脚本
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { Framework } = require('./src')
|
|
6
|
+
const { MCPExecutorPlugin } = require('./src/executors/mcp-executor')
|
|
7
|
+
|
|
8
|
+
async function test() {
|
|
9
|
+
console.log('=== MCP Plugin Test ===\n')
|
|
10
|
+
|
|
11
|
+
console.log('1. Creating framework...')
|
|
12
|
+
const framework = new Framework({ debug: true })
|
|
13
|
+
|
|
14
|
+
console.log('2. Creating MCP plugin with fetch server...')
|
|
15
|
+
const mcpPlugin = new MCPExecutorPlugin({
|
|
16
|
+
servers: [
|
|
17
|
+
{
|
|
18
|
+
name: 'fetch',
|
|
19
|
+
command: 'uvx',
|
|
20
|
+
args: ['mcp-server-fetch']
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
console.log('3. Loading MCP plugin...')
|
|
26
|
+
await framework.loadPlugin(mcpPlugin)
|
|
27
|
+
|
|
28
|
+
console.log('4. Starting framework...')
|
|
29
|
+
await framework.pluginManager.startAll()
|
|
30
|
+
|
|
31
|
+
// 等待 MCP 服务器连接
|
|
32
|
+
console.log('\n5. Waiting for MCP connection...')
|
|
33
|
+
await new Promise(resolve => setTimeout(resolve, 2000))
|
|
34
|
+
|
|
35
|
+
console.log('\n6. Listing MCP servers...')
|
|
36
|
+
const servers = mcpPlugin.getServers()
|
|
37
|
+
console.log('Servers:', JSON.stringify(servers, null, 2))
|
|
38
|
+
|
|
39
|
+
console.log('\n7. Listing MCP tools...')
|
|
40
|
+
const mcpTools = framework.getTools().filter(t => t.name.startsWith('mcp_'))
|
|
41
|
+
console.log('MCP Tools:', mcpTools.map(t => t.name))
|
|
42
|
+
|
|
43
|
+
if (mcpTools.length > 0) {
|
|
44
|
+
console.log('\n8. Testing mcp_list_servers...')
|
|
45
|
+
const listResult = await framework.executeTool('mcp_list_servers', {})
|
|
46
|
+
console.log('List Servers Result:', JSON.stringify(listResult, null, 2))
|
|
47
|
+
|
|
48
|
+
console.log('\n9. Testing mcp_tool_schema...')
|
|
49
|
+
const schemaResult = await framework.executeTool('mcp_tool_schema', {
|
|
50
|
+
server: 'fetch',
|
|
51
|
+
tool: 'fetch'
|
|
52
|
+
})
|
|
53
|
+
console.log('Tool Schema:', JSON.stringify(schemaResult, null, 2))
|
|
54
|
+
|
|
55
|
+
console.log('\n10. Testing mcp_call (fetch a webpage)...')
|
|
56
|
+
const callResult = await framework.executeTool('mcp_call', {
|
|
57
|
+
server: 'fetch',
|
|
58
|
+
tool: 'fetch',
|
|
59
|
+
args_json: JSON.stringify({ url: 'https://httpbin.org/get' })
|
|
60
|
+
})
|
|
61
|
+
console.log('Fetch Result (truncated):', JSON.stringify(callResult, null, 2).substring(0, 500) + '...')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log('\n11. Destroying framework...')
|
|
65
|
+
await framework.destroy()
|
|
66
|
+
|
|
67
|
+
console.log('\n=== Test Complete ===')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
test()
|
|
71
|
+
.then(() => {
|
|
72
|
+
console.log('\n✓ Test completed successfully')
|
|
73
|
+
process.exit(0)
|
|
74
|
+
})
|
|
75
|
+
.catch(err => {
|
|
76
|
+
console.error('\n✗ Test failed:', err.message)
|
|
77
|
+
console.error(err.stack)
|
|
78
|
+
process.exit(1)
|
|
79
|
+
})
|
package/test-reload.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP mcp_reload 功能测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { Framework } = require('./src')
|
|
6
|
+
const { MCPExecutorPlugin } = require('./src/executors/mcp-executor')
|
|
7
|
+
const fs = require('fs')
|
|
8
|
+
const path = require('path')
|
|
9
|
+
|
|
10
|
+
async function test() {
|
|
11
|
+
console.log('=== Testing mcp_reload ===\n')
|
|
12
|
+
|
|
13
|
+
// 创建框架
|
|
14
|
+
const framework = new Framework({ debug: true })
|
|
15
|
+
|
|
16
|
+
// 创建 MCP 插件
|
|
17
|
+
const mcpPlugin = new MCPExecutorPlugin({
|
|
18
|
+
servers: [
|
|
19
|
+
{ name: 'fetch', command: 'uvx', args: ['mcp-server-fetch'] }
|
|
20
|
+
]
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
// 加载并启动
|
|
24
|
+
await framework.loadPlugin(mcpPlugin)
|
|
25
|
+
await framework.pluginManager.startAll()
|
|
26
|
+
|
|
27
|
+
// 等待连接
|
|
28
|
+
await new Promise(r => setTimeout(r, 2000))
|
|
29
|
+
|
|
30
|
+
console.log('\n1. 初始服务器列表:')
|
|
31
|
+
const initialServers = mcpPlugin.getServers()
|
|
32
|
+
console.log(JSON.stringify(initialServers, null, 2))
|
|
33
|
+
|
|
34
|
+
// 测试 mcp_reload
|
|
35
|
+
console.log('\n2. 调用 mcp_reload...')
|
|
36
|
+
const result = await framework.executeTool('mcp_reload', {})
|
|
37
|
+
console.log('mcp_reload 结果:')
|
|
38
|
+
console.log(JSON.stringify(result, null, 2))
|
|
39
|
+
|
|
40
|
+
// 检查配置
|
|
41
|
+
console.log('\n3. 当前配置文件:')
|
|
42
|
+
const configPath = path.resolve('.agent/mcp_config.json')
|
|
43
|
+
if (fs.existsSync(configPath)) {
|
|
44
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'))
|
|
45
|
+
console.log(JSON.stringify(config, null, 2))
|
|
46
|
+
} else {
|
|
47
|
+
console.log('配置文件不存在: ' + configPath)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 清理
|
|
51
|
+
await framework.destroy()
|
|
52
|
+
|
|
53
|
+
console.log('\n=== 测试完成 ===')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
test()
|
|
57
|
+
.then(() => process.exit(0))
|
|
58
|
+
.catch(err => {
|
|
59
|
+
console.error('测试失败:', err)
|
|
60
|
+
process.exit(1)
|
|
61
|
+
})
|