foliko 1.0.1 → 1.0.2
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 +3 -1
- package/cli/src/ui/chat-ui.js +27 -2
- package/install.ps1 +179 -0
- package/package.json +2 -2
- package/plugins/default-plugins.js +9 -0
- package/plugins/python-executor-plugin.js +3 -3
- package/plugins/python-plugin-loader.js +478 -0
- package/skills/python-plugin-dev/SKILL.md +265 -0
- package/website/docs/api.html +159 -0
- package/website/docs/configuration.html +119 -0
- package/website/docs/plugin-development.html +155 -0
- package/website/docs/project-structure.html +142 -0
- package/website/docs/skill-development.html +85 -0
- package/website/index.html +197 -0
- package/website/script.js +77 -0
- package/website/styles.css +306 -0
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"Bash(cd D:/Code/vb-agent && node test-stream-emoji.js 2>&1)",
|
|
25
25
|
"Read(//d/Date/20260321/app/**)",
|
|
26
26
|
"Bash(node -e \":*)",
|
|
27
|
-
"Bash(node -e \"\nconst { loadAgentConfig } = require\\('./plugins/default-plugins'\\);\nconst config = loadAgentConfig\\('D:/Date/20260321/app/.agent'\\);\nconsole.log\\('skillsDirs:', config.skillsDirs\\);\n\")"
|
|
27
|
+
"Bash(node -e \"\nconst { loadAgentConfig } = require\\('./plugins/default-plugins'\\);\nconst config = loadAgentConfig\\('D:/Date/20260321/app/.agent'\\);\nconsole.log\\('skillsDirs:', config.skillsDirs\\);\n\")",
|
|
28
|
+
"Bash(cd D:/Code/vb-agent && pnpm install --shamefully-hoist 2>&1 | head -20)",
|
|
29
|
+
"Bash(cd D:/Code/vb-agent && rm -rf node_modules && pnpm install)"
|
|
28
30
|
]
|
|
29
31
|
}
|
|
30
32
|
}
|
package/cli/src/ui/chat-ui.js
CHANGED
|
@@ -208,6 +208,20 @@ class ChatUI extends EventEmitter {
|
|
|
208
208
|
console.log(colored('Agent:', GREEN))
|
|
209
209
|
console.log()
|
|
210
210
|
|
|
211
|
+
// 用于打断的标志
|
|
212
|
+
let interrupted = false
|
|
213
|
+
|
|
214
|
+
// 设置打断处理
|
|
215
|
+
const interruptHandler = () => {
|
|
216
|
+
if (!interrupted) {
|
|
217
|
+
interrupted = true
|
|
218
|
+
console.log(`\n${colored('[中断]', RED)} 输出已中断`)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// 监听 Ctrl+C
|
|
223
|
+
process.on('SIGINT', interruptHandler)
|
|
224
|
+
|
|
211
225
|
try {
|
|
212
226
|
let lineBuffer = ''
|
|
213
227
|
// 渲染状态追踪
|
|
@@ -233,6 +247,9 @@ class ChatUI extends EventEmitter {
|
|
|
233
247
|
}
|
|
234
248
|
|
|
235
249
|
for await (const chunk of this.agent.chatStream(message)) {
|
|
250
|
+
// 检查是否被打断
|
|
251
|
+
if (interrupted) break
|
|
252
|
+
|
|
236
253
|
if (chunk.type === 'text') {
|
|
237
254
|
lineBuffer += chunk.text
|
|
238
255
|
|
|
@@ -243,6 +260,9 @@ class ChatUI extends EventEmitter {
|
|
|
243
260
|
|
|
244
261
|
// 当有一行完整内容时,渲染并输出
|
|
245
262
|
while (lineBuffer.includes('\n')) {
|
|
263
|
+
// 检查是否被打断
|
|
264
|
+
if (interrupted) break
|
|
265
|
+
|
|
246
266
|
const nlIndex = lineBuffer.indexOf('\n')
|
|
247
267
|
const line = lineBuffer.substring(0, nlIndex)
|
|
248
268
|
lineBuffer = lineBuffer.substring(nlIndex + 1)
|
|
@@ -258,11 +278,16 @@ class ChatUI extends EventEmitter {
|
|
|
258
278
|
}
|
|
259
279
|
|
|
260
280
|
// 输出剩余内容
|
|
261
|
-
if (lineBuffer.trim()) {
|
|
281
|
+
if (lineBuffer.trim() && !interrupted) {
|
|
262
282
|
console.log(renderLine(lineBuffer, renderState))
|
|
263
283
|
}
|
|
264
284
|
} catch (err) {
|
|
265
|
-
|
|
285
|
+
if (!interrupted) {
|
|
286
|
+
console.error(`\n${colored('[错误]', RED)} ${err.message}\n`)
|
|
287
|
+
}
|
|
288
|
+
} finally {
|
|
289
|
+
// 移除监听器
|
|
290
|
+
process.removeListener('SIGINT', interruptHandler)
|
|
266
291
|
}
|
|
267
292
|
|
|
268
293
|
this.prompt()
|
package/install.ps1
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# Foliko 安装脚本
|
|
2
|
+
# 使用方式: irm https://raw.githubusercontent.com/user/vb-agent/main/install.ps1 | iex
|
|
3
|
+
|
|
4
|
+
$ErrorActionPreference = "Stop"
|
|
5
|
+
|
|
6
|
+
$Repo = "your-username/vb-agent"
|
|
7
|
+
$InstallDir = "$env:LOCALAPPDATA\Foliko"
|
|
8
|
+
|
|
9
|
+
Write-Host "Foliko 安装器" -ForegroundColor Cyan
|
|
10
|
+
Write-Host "=================" -ForegroundColor Cyan
|
|
11
|
+
Write-Host ""
|
|
12
|
+
|
|
13
|
+
# 检查并安装 Node.js
|
|
14
|
+
function Install-NodeJS {
|
|
15
|
+
Write-Host "正在检查 Node.js..." -ForegroundColor Cyan
|
|
16
|
+
|
|
17
|
+
if (Get-Command node -ErrorAction SilentlyContinue) {
|
|
18
|
+
Write-Host "Node.js 已安装: $(node --version)" -ForegroundColor Green
|
|
19
|
+
return $true
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Write-Host "Node.js 未安装,正在安装..." -ForegroundColor Yellow
|
|
23
|
+
|
|
24
|
+
# 下载 Node.js LTS 安装包
|
|
25
|
+
$nodeUrl = "https://nodejs.org/dist/v20.11.0/node-v20.11.0-x64.msi"
|
|
26
|
+
$nodeInstaller = "$env:TEMP\node-installer.msi"
|
|
27
|
+
|
|
28
|
+
Write-Host "下载 Node.js..." -ForegroundColor Cyan
|
|
29
|
+
Invoke-WebRequest -Uri $nodeUrl -OutFile $nodeInstaller
|
|
30
|
+
|
|
31
|
+
Write-Host "安装 Node.js (需要管理员权限)..." -ForegroundColor Yellow
|
|
32
|
+
Start-Process msiexec.exe -ArgumentList "/i", $nodeInstaller, "/quiet", "/norestart" -Wait
|
|
33
|
+
|
|
34
|
+
# 刷新环境变量
|
|
35
|
+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
|
36
|
+
|
|
37
|
+
# 验证安装
|
|
38
|
+
Start-Sleep -Seconds 2
|
|
39
|
+
if (Get-Command node -ErrorAction SilentlyContinue) {
|
|
40
|
+
Write-Host "Node.js 安装成功: $(node --version)" -ForegroundColor Green
|
|
41
|
+
Remove-Item $nodeInstaller -Force -ErrorAction SilentlyContinue
|
|
42
|
+
return $true
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Write-Host "Node.js 安装失败,请手动安装" -ForegroundColor Red
|
|
46
|
+
Write-Host "下载地址: https://nodejs.org/" -ForegroundColor Yellow
|
|
47
|
+
return $false
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
# 检查并安装 Python
|
|
51
|
+
function Install-Python {
|
|
52
|
+
Write-Host "正在检查 Python..." -ForegroundColor Cyan
|
|
53
|
+
|
|
54
|
+
if (Get-Command python -ErrorAction SilentlyContinue) {
|
|
55
|
+
Write-Host "Python 已安装: $(python --version)" -ForegroundColor Green
|
|
56
|
+
return $true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Write-Host "Python 未安装,正在安装..." -ForegroundColor Yellow
|
|
60
|
+
|
|
61
|
+
# 下载 Python 安装包
|
|
62
|
+
$pythonUrl = "https://www.python.org/ftp/python/3.12.1/python-3.12.1-amd64.exe"
|
|
63
|
+
$pythonInstaller = "$env:TEMP\python-installer.exe"
|
|
64
|
+
|
|
65
|
+
Write-Host "下载 Python..." -ForegroundColor Cyan
|
|
66
|
+
Invoke-WebRequest -Uri $pythonUrl -OutFile $pythonInstaller
|
|
67
|
+
|
|
68
|
+
Write-Host "安装 Python (需要管理员权限)..." -ForegroundColor Yellow
|
|
69
|
+
# 使用静默安装参数,添加 PATH 和 pip
|
|
70
|
+
Start-Process $pythonInstaller -ArgumentList "/quiet", "InstallAllUsers=1", "PrependPath=1", "Include_pip=1" -Wait
|
|
71
|
+
|
|
72
|
+
# 刷新环境变量
|
|
73
|
+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
|
74
|
+
|
|
75
|
+
# 验证安装
|
|
76
|
+
Start-Sleep -Seconds 2
|
|
77
|
+
if (Get-Command python -ErrorAction SilentlyContinue) {
|
|
78
|
+
Write-Host "Python 安装成功: $(python --version)" -ForegroundColor Green
|
|
79
|
+
Remove-Item $pythonInstaller -Force -ErrorAction SilentlyContinue
|
|
80
|
+
return $true
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
Write-Host "Python 安装失败,请手动安装" -ForegroundColor Red
|
|
84
|
+
Write-Host "下载地址: https://www.python.org/downloads/" -ForegroundColor Yellow
|
|
85
|
+
return $false
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
# 创建 Python 虚拟环境
|
|
89
|
+
function Install-PythonVenv {
|
|
90
|
+
param([string]$venvDir)
|
|
91
|
+
|
|
92
|
+
Write-Host "正在检查 Python venv..." -ForegroundColor Cyan
|
|
93
|
+
|
|
94
|
+
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
|
|
95
|
+
Write-Host "Python 未安装,跳过 venv" -ForegroundColor Yellow
|
|
96
|
+
return $false
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (Test-Path $venvDir) {
|
|
100
|
+
Write-Host "虚拟环境已存在: $venvDir" -ForegroundColor Green
|
|
101
|
+
return $true
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
Write-Host "创建虚拟环境: $venvDir" -ForegroundColor Cyan
|
|
105
|
+
python -m venv $venvDir
|
|
106
|
+
|
|
107
|
+
if (Test-Path "$venvDir\Scripts\python.exe") {
|
|
108
|
+
Write-Host "虚拟环境创建成功" -ForegroundColor Green
|
|
109
|
+
|
|
110
|
+
# 激活并安装基础包
|
|
111
|
+
Write-Host "安装基础依赖..." -ForegroundColor Cyan
|
|
112
|
+
& "$venvDir\Scripts\pip.exe" install pip --upgrade
|
|
113
|
+
return $true
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Write-Host "虚拟环境创建失败" -ForegroundColor Red
|
|
117
|
+
return $false
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
# 主安装流程
|
|
121
|
+
Write-Host "环境检查" -ForegroundColor Cyan
|
|
122
|
+
Write-Host "-----------" -ForegroundColor Cyan
|
|
123
|
+
Write-Host ""
|
|
124
|
+
|
|
125
|
+
# 检查并安装依赖
|
|
126
|
+
$nodeOk = Install-NodeJS
|
|
127
|
+
Write-Host ""
|
|
128
|
+
$pythonOk = Install-Python
|
|
129
|
+
Write-Host ""
|
|
130
|
+
|
|
131
|
+
if (-not $nodeOk) {
|
|
132
|
+
Write-Host "警告: Node.js 未正确安装,部分功能可能不可用" -ForegroundColor Yellow
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (-not $pythonOk) {
|
|
136
|
+
Write-Host "警告: Python 未正确安装,部分功能可能不可用" -ForegroundColor Yellow
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
# 创建 Python 虚拟环境
|
|
140
|
+
$venvDir = "$InstallDir\venv"
|
|
141
|
+
if ($pythonOk) {
|
|
142
|
+
Write-Host ""
|
|
143
|
+
$venvOk = Install-PythonVenv -venvDir $venvDir
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
# 创建安装目录
|
|
147
|
+
if (-not (Test-Path $InstallDir)) {
|
|
148
|
+
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
Write-Host "安装到: $InstallDir" -ForegroundColor Cyan
|
|
152
|
+
Write-Host ""
|
|
153
|
+
|
|
154
|
+
Push-Location $InstallDir
|
|
155
|
+
|
|
156
|
+
if (Test-Path ".git") {
|
|
157
|
+
Write-Host "更新现有安装..." -ForegroundColor Cyan
|
|
158
|
+
git pull
|
|
159
|
+
} else {
|
|
160
|
+
Write-Host "下载 Foliko..." -ForegroundColor Cyan
|
|
161
|
+
git clone https://github.com/$Repo.git .
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
# 安装依赖
|
|
165
|
+
Write-Host "安装 npm 依赖..." -ForegroundColor Cyan
|
|
166
|
+
npm install
|
|
167
|
+
|
|
168
|
+
# 全局链接 CLI
|
|
169
|
+
Write-Host "安装 CLI..." -ForegroundColor Cyan
|
|
170
|
+
npm link
|
|
171
|
+
|
|
172
|
+
Pop-Location
|
|
173
|
+
|
|
174
|
+
Write-Host ""
|
|
175
|
+
Write-Host "安装完成!" -ForegroundColor Green
|
|
176
|
+
Write-Host ""
|
|
177
|
+
Write-Host "使用方法:" -ForegroundColor Yellow
|
|
178
|
+
Write-Host " foliko chat" -ForegroundColor White
|
|
179
|
+
Write-Host ""
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foliko",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "简约的插件化 Agent 框架",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"marked": "^11.2.0",
|
|
32
32
|
"marked-terminal": "6",
|
|
33
33
|
"node-cron": "^4.2.1",
|
|
34
|
-
"zod": "^
|
|
34
|
+
"zod": "^3.24.0"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -342,6 +342,15 @@ async function bootstrapDefaults(framework, config = {}) {
|
|
|
342
342
|
console.log('[Bootstrap] Think Plugin already loaded, skipping')
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
+
// 12.5 Python 插件加载器
|
|
346
|
+
if (!framework.pluginManager.has('python-plugin-loader')) {
|
|
347
|
+
const { PythonPluginLoader } = require('./python-plugin-loader')
|
|
348
|
+
await framework.loadPlugin(new PythonPluginLoader({ agentDir: agentConfig.agentDir }))
|
|
349
|
+
console.log('[Bootstrap] Python Plugin Loader loaded')
|
|
350
|
+
} else {
|
|
351
|
+
console.log('[Bootstrap] Python Plugin Loader already loaded, skipping')
|
|
352
|
+
}
|
|
353
|
+
|
|
345
354
|
// 13. 加载自定义插件
|
|
346
355
|
await loadCustomPlugins(framework, agentConfig)
|
|
347
356
|
|
|
@@ -42,10 +42,10 @@ class PythonExecutorPlugin extends Plugin {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
start(framework) {
|
|
45
|
-
// 注册 python 工具
|
|
45
|
+
// 注册 python-execute 工具
|
|
46
46
|
framework.registerTool({
|
|
47
|
-
name: 'python',
|
|
48
|
-
description: '执行 Python
|
|
47
|
+
name: 'python-execute',
|
|
48
|
+
description: '执行 Python 代码,禁止传入无用的emoji',
|
|
49
49
|
inputSchema: z.object({
|
|
50
50
|
code: z.string().describe('Python 代码'),
|
|
51
51
|
timeout: z.number().optional().describe('超时时间(毫秒),默认 120000')
|