myagent-ai 1.15.56 → 1.15.58

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 CHANGED
@@ -10,7 +10,6 @@
10
10
 
11
11
  ### 🚀 执行引擎
12
12
  - **多语言执行**: Python / Shell (Bash) / PowerShell / CMD
13
- - **自动修复**: ImportError 自动安装、编码修复、缩进修复
14
13
  - **安全控制**: 危险命令拦截、超时控制、输出截断
15
14
  - **结构化结果**: 执行结果标准化,LLM 稳定理解
16
15
 
@@ -123,27 +122,18 @@ powershell -c "irm https://raw.githubusercontent.com/ctz168/myagent/main/install
123
122
  curl -fsSL https://raw.githubusercontent.com/ctz168/myagent/main/install/install.sh | bash
124
123
  ```
125
124
 
126
- ### 一键重装(跳过依赖检查)
125
+ ### 快速升级
127
126
 
128
- > 已安装过 MyAgent 的环境下,快速升级/重装,安装和启动时均不检查 pip 依赖。
127
+ > 已安装过 MyAgent 的环境下,重新安装最新版:
129
128
 
130
- **npm 方式(推荐,最简单):**
131
129
  ```bash
132
- npx myagent-ai --skip-deps
130
+ npm install -g myagent-ai@latest
131
+ myagent-ai reinstall
133
132
  ```
134
133
 
135
- > `npx` 会自动安装/升级最新版 `myagent-ai`,`--skip-deps` 跳过安装和启动时的所有依赖检查。
136
-
137
- **脚本方式:**
138
-
139
- **Windows(PowerShell):**
140
- ```powershell
141
- powershell -c "& ([scriptblock]::Create((irm https://raw.githubusercontent.com/ctz168/myagent/main/install/install.ps1))) -NoDeps"
142
- ```
143
-
144
- **macOS / Linux:**
134
+ 或使用脚本重新安装:
145
135
  ```bash
146
- curl -fsSL https://raw.githubusercontent.com/ctz168/myagent/main/install/install.sh | bash -s -- --no-deps
136
+ curl -fsSL https://raw.githubusercontent.com/ctz168/myagent/main/install/install.sh | bash
147
137
  ```
148
138
 
149
139
  ---
@@ -200,19 +190,21 @@ export MYAGENT_ANTHROPIC_API_KEY="sk-ant-..."
200
190
  ### 2. 运行
201
191
 
202
192
  ```bash
203
- # 交互式命令行
204
- myagent-ai
193
+ # Web 管理后台(推荐)
194
+ myagent-ai web
205
195
 
206
- # 系统托盘后台运行
207
- myagent-ai --tray
196
+ # CLI 交互模式
197
+ myagent-ai cli
208
198
 
209
- # 调试模式
210
- myagent-ai --debug
199
+ # 系统托盘后台运行
200
+ myagent-ai tray
211
201
 
212
- # 设置开机自启
213
- myagent-ai --autostart
202
+ # API 服务模式
203
+ myagent-ai server
214
204
  ```
215
205
 
206
+ > 首次运行会自动安装所有依赖,后续启动秒开。
207
+
216
208
  ### 3. 配置聊天平台 (可选)
217
209
 
218
210
  编辑 `~/.myagent/config.json`:
@@ -11,7 +11,6 @@ $ErrorActionPreference = "Stop"
11
11
  $PKG_NAME = "myagent-ai"
12
12
  $PKG_VERSION = ""
13
13
 
14
- # 动态获取 npm 最新版本号
15
14
  function Get-NpmVersion {
16
15
  try {
17
16
  $ver = (npm view $PKG_NAME version 2>$null)
@@ -19,12 +18,10 @@ function Get-NpmVersion {
19
18
  } catch {}
20
19
  }
21
20
 
22
- # Allow running scripts for the current process
23
21
  if ($PSVersionTable.PSVersion.Major -ge 5) {
24
22
  Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
25
23
  }
26
24
 
27
- # 尝试获取最新版本
28
25
  Get-NpmVersion
29
26
 
30
27
  $verDisplay = if ($PKG_VERSION) { " v$PKG_VERSION" } else { "" }
@@ -40,16 +37,13 @@ if ($PSVersionTable.PSVersion.Major -lt 5) {
40
37
  Write-Host "[OK] Windows detected" -ForegroundColor Green
41
38
 
42
39
  # ── Python ───────────────────────────────────────────────
43
- # 记录已找到的 Python 路径
44
40
  $Script:PythonCmd = ""
45
41
 
46
42
  function Refresh-Path {
47
- # 刷新 PATH(安装后需要刷新才能找到新安装的程序)
48
43
  $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
49
44
  }
50
45
 
51
46
  function Check-Python {
52
- # 刷新 PATH(安装后可能需要刷新)
53
47
  Refresh-Path
54
48
  try {
55
49
  $pyVer = (python --version 2>$null)
@@ -59,119 +53,44 @@ function Check-Python {
59
53
  $Script:PythonCmd = "python"
60
54
  Write-Host "[OK] Python $verNum found" -ForegroundColor Green
61
55
  return $true
62
- } else {
63
- Write-Host "[!] Python $verNum found, upgrading to 3.13+ ..." -ForegroundColor Yellow
64
- # 仍然记录当前可用的 Python(即使版本低,也总比没有好)
65
- $Script:PythonCmd = "python"
66
- return $false
67
56
  }
68
57
  }
69
- } catch {
70
- Write-Host "[!] Python not found" -ForegroundColor Yellow
71
- }
72
- # 尝试在常见安装路径查找
73
- $commonPaths = @(
58
+ } catch {}
59
+ foreach ($pyPath in @(
74
60
  "$env:LOCALAPPDATA\Programs\Python\Python314\python.exe",
75
61
  "$env:LOCALAPPDATA\Programs\Python\Python313\python.exe",
76
- "C:\Python314\python.exe",
77
- "C:\Python313\python.exe",
78
- "C:\Program Files\Python314\python.exe",
79
- "C:\Program Files\Python313\python.exe"
80
- )
81
- foreach ($pyPath in $commonPaths) {
62
+ "C:\Python314\python.exe", "C:\Python313\python.exe"
63
+ )) {
82
64
  if (Test-Path $pyPath) {
83
- $verNum = (& $pyPath --version 2>$null) -replace 'Python\s+(\S+)', '$1'
84
- if ($verNum -and [version]$verNum -ge [version]"3.13") {
85
- $Script:PythonCmd = $pyPath
86
- Write-Host "[OK] Python $verNum found at $pyPath" -ForegroundColor Green
87
- return $true
88
- }
65
+ $Script:PythonCmd = $pyPath
66
+ Write-Host "[OK] Python found at $pyPath" -ForegroundColor Green
67
+ return $true
89
68
  }
90
69
  }
91
70
  return $false
92
71
  }
93
72
 
94
73
  function Install-Python {
95
- Write-Host "[*] Installing Python 3.13 ..." -ForegroundColor Yellow
96
- $installAttempted = $false
97
-
98
- # Try winget first (try 3.14, then 3.13)
74
+ Write-Host "[*] Installing Python 3.13+ ..." -ForegroundColor Yellow
99
75
  try {
100
76
  $null = (winget --version 2>$null)
101
- Write-Host " Using winget ..." -ForegroundColor Gray
102
77
  foreach ($pyVer in @("3.14", "3.13")) {
103
- Write-Host " 尝试 Python $pyVer ..." -ForegroundColor Gray
104
78
  winget install "Python.Python.$pyVer" --accept-package-agreements --accept-source-agreements 2>$null
105
- $installAttempted = $true
106
- # 等待安装完成后刷新 PATH(重试多次)
107
79
  for ($i = 1; $i -le 5; $i++) {
108
80
  Start-Sleep -Seconds 2
109
81
  if (Check-Python) { return }
110
82
  }
111
- # winget 已完成安装,即使 Check-Python 失败也不再重复安装
112
- Refresh-Path
113
- $pyPaths = @(
114
- "$env:LOCALAPPDATA\Programs\Python\Python$pyVer\python.exe",
115
- "C:\Python$pyVer\python.exe",
116
- "C:\Program Files\Python$pyVer\python.exe"
117
- )
118
- foreach ($pyPath in $pyPaths) {
119
- if (Test-Path $pyPath) {
120
- $verNum = (& $pyPath --version 2>$null) -replace 'Python\s+(\S+)', '$1'
121
- if ($verNum) {
122
- $Script:PythonCmd = $pyPath
123
- Write-Host "[OK] Python $verNum installed via winget at $pyPath" -ForegroundColor Green
124
- Write-Host "[i] PATH will be updated after restart. Using direct path for now." -ForegroundColor Gray
125
- return
126
- }
127
- }
128
- }
129
83
  }
130
- Write-Host "[i] Python was installed via winget but PATH not yet updated." -ForegroundColor Yellow
131
- Write-Host " Please restart your terminal and run: myagent-ai" -ForegroundColor Yellow
84
+ Write-Host "[i] Python installed but PATH not updated. Restart terminal and run: myagent-ai" -ForegroundColor Yellow
132
85
  exit 0
133
- } catch {
134
- Write-Host " winget not available, downloading ..." -ForegroundColor Gray
135
- }
136
-
137
- # 仅在 winget 未尝试时才从 python.org 下载(避免双重安装)
138
- if (-not $installAttempted) {
139
- # Fallback: download from python.org (try 3.13 first)
140
- $pyVersions = @(
141
- @{ Url = "https://www.python.org/ftp/python/3.13.3/python-3.13.3-amd64.exe"; Ver = "3.13.3" },
142
- @{ Url = "https://www.python.org/ftp/python/3.14.0/python-3.14.0-amd64.exe"; Ver = "3.14.0" }
143
- )
144
- foreach ($pyInfo in $pyVersions) {
145
- $pyExe = Join-Path $env:TEMP "python-installer.exe"
146
- try {
147
- Write-Host " Downloading Python $($pyInfo.Ver) ..." -ForegroundColor Gray
148
- Invoke-WebRequest -Uri $pyInfo.Url -OutFile $pyExe -UseBasicParsing -ErrorAction Stop
149
-
150
- Write-Host " Installing (Add to PATH) ..." -ForegroundColor Gray
151
- Start-Process -FilePath $pyExe -ArgumentList "/quiet InstallAllUsers=1 PrependPath=1" -Wait
152
-
153
- # 刷新 PATH 并验证(重试多次)
154
- for ($i = 1; $i -le 5; $i++) {
155
- Start-Sleep -Seconds 2
156
- if (Check-Python) { return }
157
- }
158
- } catch {
159
- Write-Host " Python $($pyInfo.Ver) download failed, trying next..." -ForegroundColor Yellow
160
- } finally {
161
- if (Test-Path $pyExe) { Remove-Item -Force $pyExe -ErrorAction SilentlyContinue }
162
- }
163
- }
164
- }
165
-
166
- Write-Host "[x] Failed to install Python." -ForegroundColor Red
167
- Write-Host " Please install Python 3.13+ manually: https://www.python.org/downloads/" -ForegroundColor Gray
86
+ } catch {}
87
+ Write-Host "[x] Failed to install Python. Please install manually: https://www.python.org/downloads/" -ForegroundColor Red
168
88
  exit 1
169
89
  }
170
90
 
171
91
  # ── Node.js ──────────────────────────────────────────────
172
92
  function Check-Node {
173
- # 刷新 PATH
174
- $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
93
+ Refresh-Path
175
94
  try {
176
95
  $nodeVer = (node -v 2>$null)
177
96
  if ($nodeVer) {
@@ -179,204 +98,74 @@ function Check-Node {
179
98
  if ($major -ge 18) {
180
99
  Write-Host "[OK] Node.js $nodeVer found" -ForegroundColor Green
181
100
  return $true
182
- } else {
183
- Write-Host "[!] Node.js $nodeVer found, but v18+ required" -ForegroundColor Yellow
184
- return $false
185
101
  }
186
102
  }
187
- } catch {
188
- Write-Host "[!] Node.js not found" -ForegroundColor Yellow
189
- }
103
+ } catch {}
190
104
  return $false
191
105
  }
192
106
 
193
107
  function Install-Node {
194
108
  Write-Host "[*] Installing Node.js 20 LTS ..." -ForegroundColor Yellow
195
-
196
109
  try {
197
110
  $null = (winget --version 2>$null)
198
- Write-Host " Using winget ..." -ForegroundColor Gray
199
111
  winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements
200
112
  if (Check-Node) { return }
201
- } catch {
202
- Write-Host " winget not available, downloading ..." -ForegroundColor Gray
203
- }
204
-
205
- # Fallback: download Node.js LTS
206
- $nodeUrl = "https://nodejs.org/dist/v20.18.0/node-v20.18.0-x64.msi"
207
- $nodeMsi = Join-Path $env:TEMP "node-installer.msi"
208
-
209
- try {
210
- Write-Host " Downloading Node.js 20 LTS ..." -ForegroundColor Gray
211
- Invoke-WebRequest -Uri $nodeUrl -OutFile $nodeMsi -UseBasicParsing
212
-
213
- Write-Host " Installing ..." -ForegroundColor Gray
214
- Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$nodeMsi`" /quiet /norestart" -Wait
215
-
216
- if (Check-Node) { return }
217
- } finally {
218
- if (Test-Path $nodeMsi) { Remove-Item -Force $nodeMsi -ErrorAction SilentlyContinue }
219
- }
220
-
221
- Write-Host "[x] Failed to install Node.js." -ForegroundColor Red
222
- Write-Host " Please install Node.js 18+ manually: https://nodejs.org/" -ForegroundColor Gray
113
+ } catch {}
114
+ Write-Host "[x] Failed to install Node.js. Please install manually: https://nodejs.org/" -ForegroundColor Red
223
115
  exit 1
224
116
  }
225
117
 
226
- # ── Install MyAgent via npm ──────────────────────────────
227
- function Install-MyAgent {
228
- Write-Host "[*] Installing $PKG_NAME ..." -ForegroundColor Yellow
229
- npm install -g $PKG_NAME
230
- if ($LASTEXITCODE -ne 0) {
231
- Write-Host "[!] npm install failed, trying with admin..." -ForegroundColor Yellow
232
- Start-Process npm -ArgumentList "install", "-g", $PKG_NAME -Verb RunAs -Wait
233
- if ($LASTEXITCODE -ne 0) {
234
- Write-Host "[x] npm install failed" -ForegroundColor Red
235
- exit 1
236
- }
237
- }
238
- Write-Host "[OK] $PKG_NAME installed" -ForegroundColor Green
118
+ # ── Main ─────────────────────────────────────────────────
119
+ if ($DryRun) {
120
+ Write-Host "[OK] Dry run" -ForegroundColor Green
121
+ exit 0
239
122
  }
240
123
 
241
- # ── Install Python dependencies (使用独立虚拟环境) ──
242
- function Install-PythonDeps {
243
- $pyCmd = if ($Script:PythonCmd) { $Script:PythonCmd } else { "python" }
244
- $npmRoot = (npm root -g 2>$null)
245
- $pkgDir = Join-Path $npmRoot $PKG_NAME
246
- $reqFile = Join-Path $pkgDir "requirements.txt"
247
-
248
- if (-not (Test-Path $reqFile)) {
249
- if (Test-Path ".\requirements.txt") {
250
- $reqFile = ".\requirements.txt"
251
- } else {
252
- Write-Host "[!] requirements.txt not found, skipping pip install" -ForegroundColor Yellow
253
- return
254
- }
255
- }
256
-
257
- $venvDir = "$env:USERPROFILE\.myagent\venv"
258
- $venvPython = Join-Path $venvDir "Scripts\python.exe"
259
-
260
- Write-Host "[*] Creating virtual environment at $venvDir ..." -ForegroundColor Yellow
261
- New-Item -ItemType Directory -Path "$env:USERPROFILE\.myagent" -Force | Out-Null
262
-
263
- # 如果旧 venv 存在且损坏,先删除重建
264
- if ((Test-Path $venvPython)) {
265
- try {
266
- $null = (& $venvPython --version 2>$null)
267
- } catch {
268
- Write-Host "[!] 旧虚拟环境损坏,正在重建..." -ForegroundColor Yellow
269
- Remove-Item -Recurse -Force $venvDir -ErrorAction SilentlyContinue
270
- }
271
- }
272
-
273
- & $pyCmd -m venv $venvDir
274
- if (-not (Test-Path $venvPython)) {
275
- Write-Host "[x] 虚拟环境创建失败!Python: $pyCmd" -ForegroundColor Red
276
- Write-Host " 请手动安装: python -m venv $venvDir" -ForegroundColor Gray
277
- return
278
- }
279
- Write-Host "[OK] Virtual environment created" -ForegroundColor Green
280
-
281
- Write-Host "[*] Installing Python dependencies into venv ..." -ForegroundColor Yellow
282
- & $venvPython -m pip install --upgrade pip --quiet 2>$null
124
+ if (-not $NoDeps) {
125
+ if (-not (Check-Python)) { Install-Python }
126
+ if (-not (Check-Node)) { Install-Node }
127
+ }
283
128
 
284
- # 尝试使用清华镜像安装(国内用户更快)
285
- $mirrorArgs = @("-i", "https://pypi.tuna.tsinghua.edu.cn/simple", "--trusted-host", "pypi.tuna.tsinghua.edu.cn")
286
- $pipResult = & $venvPython -m pip install -r $reqFile --disable-pip-version-check @mirrorArgs 2>&1
129
+ Write-Host "[*] Installing $PKG_NAME via npm ..." -ForegroundColor Yellow
130
+ npm install -g $PKG_NAME
131
+ if ($LASTEXITCODE -ne 0) {
132
+ Write-Host "[!] npm install failed, trying with admin..." -ForegroundColor Yellow
133
+ Start-Process npm -ArgumentList "install", "-g", $PKG_NAME -Verb RunAs -Wait
287
134
  if ($LASTEXITCODE -ne 0) {
288
- Write-Host "[!] 清华镜像安装失败,尝试默认源..." -ForegroundColor Yellow
289
- $pipResult = & $venvPython -m pip install -r $reqFile --disable-pip-version-check 2>&1
135
+ Write-Host "[x] npm install failed" -ForegroundColor Red
136
+ exit 1
290
137
  }
291
- if ($LASTEXITCODE -ne 0) {
292
- Write-Host "[!] 默认源安装失败,尝试阿里云镜像..." -ForegroundColor Yellow
293
- $aliyunArgs = @("-i", "https://mirrors.aliyun.com/pypi/simple/", "--trusted-host", "mirrors.aliyun.com")
294
- $pipResult = & $venvPython -m pip install -r $reqFile --disable-pip-version-check @aliyunArgs 2>&1
295
- }
296
- if ($LASTEXITCODE -ne 0) {
297
- Write-Host "[!] 部分依赖安装失败,但核心功能可在启动时自动安装" -ForegroundColor Yellow
298
- Write-Host " 请运行 'myagent-ai reinstall' 重新安装" -ForegroundColor Gray
299
- } else {
300
- Write-Host "[OK] Dependencies installed into venv" -ForegroundColor Green
301
- }
302
- Write-Host "[i] Virtual env: $venvDir" -ForegroundColor Gray
303
- Write-Host "[i] venv will be used automatically on startup" -ForegroundColor Gray
304
138
  }
305
-
306
- # ── Post-install: 直接启动 ──────────────────────────
307
- function Show-Guide {
308
- Write-Host ""
309
- Write-Host " 安装完成!正在启动 MyAgent..." -ForegroundColor Green
310
- Write-Host ""
311
-
312
- # 刷新 PATH(刚安装的 npm 全局命令可能在新的 PATH 中)
313
- Refresh-Path
314
-
315
- # npm 全局命令实际是 .cmd 文件,必须通过 cmd /c 执行
139
+ Write-Host "[OK] $PKG_NAME installed" -ForegroundColor Green
140
+
141
+ # start.js 的 install 命令创建 venv 并安装全部 Python 依赖
142
+ Write-Host "[*] Installing Python dependencies ..." -ForegroundColor Yellow
143
+ try {
144
+ & myagent-ai install
145
+ } catch {
146
+ # myagent-ai 不在 PATH 中,尝试直接调用
316
147
  $npmBinDir = ""
317
- try {
318
- $npmBinDir = (npm bin -g 2>$null).Trim()
319
- } catch {}
320
-
148
+ try { $npmBinDir = (npm bin -g 2>$null).Trim() } catch {}
321
149
  $cmdPath = ""
322
150
  if ($npmBinDir -and (Test-Path "$npmBinDir\myagent-ai.cmd")) {
323
151
  $cmdPath = "$npmBinDir\myagent-ai.cmd"
324
152
  }
325
-
326
153
  if ($cmdPath) {
327
- Write-Host " [i] 启动路径: $cmdPath" -ForegroundColor Gray
328
- Start-Process cmd -ArgumentList "/c", "`"$cmdPath`" web" -WindowStyle Minimized
154
+ & $cmdPath install
329
155
  } else {
330
- Write-Host " [i] 回退到 PATH 搜索..." -ForegroundColor Gray
331
- Start-Process cmd -ArgumentList "/c", "myagent-ai web" -WindowStyle Minimized
332
- }
333
- Write-Host " [OK] MyAgent 已在后台启动" -ForegroundColor Green
334
-
335
- # 由安装脚本自身轮询服务并打开浏览器(比 start.js 更可靠)
336
- Write-Host " [i] 等待服务启动..." -ForegroundColor Gray
337
- $url = "http://127.0.0.1:8767"
338
- $maxWait = 120 # 最多等 120 秒
339
- $waited = 0
340
- while ($waited -lt $maxWait) {
341
- Start-Sleep -Seconds 2
342
- $waited += 2
343
- try {
344
- $null = Invoke-WebRequest -Uri "$url/api/status" -UseBasicParsing -TimeoutSec 3 -ErrorAction Stop
345
- Write-Host " [OK] 服务已就绪,正在打开浏览器..." -ForegroundColor Green
346
- Start-Process $url
347
- Write-Host " [i] 如果没有自动打开,请访问: $url" -ForegroundColor Cyan
348
- Write-Host ""
349
- return
350
- } catch {
351
- # 服务还没启动,继续等待
352
- if ($waited % 10 -eq 0) {
353
- Write-Host " [i] 等待中... ($waited 秒)" -ForegroundColor Gray
354
- }
355
- }
156
+ Write-Host "[i] Please restart terminal and run: myagent-ai install" -ForegroundColor Yellow
356
157
  }
357
- Write-Host " [!] 等待超时" -ForegroundColor Yellow
358
- Write-Host " [i] 服务可能仍在启动中,请稍等片刻后访问: $url" -ForegroundColor Cyan
359
- Write-Host ""
360
- }
361
-
362
- # ── Main ─────────────────────────────────────────────────
363
- if ($DryRun) {
364
- Write-Host "[OK] Dry run" -ForegroundColor Green
365
- exit 0
366
- }
367
-
368
- # Step 1: Dependencies
369
- if (-not $NoDeps) {
370
- if (-not (Check-Python)) { Install-Python }
371
- if (-not (Check-Node)) { Install-Node }
372
158
  }
373
159
 
374
- # Step 2: npm install
375
- Install-MyAgent
160
+ Write-Host ""
161
+ Write-Host " 安装完成!" -ForegroundColor Green
162
+ Write-Host ""
376
163
 
377
- # Step 3: Python deps
378
- if (-not $NoDeps) {
379
- Install-PythonDeps
164
+ # 启动 Web 模式
165
+ Write-Host "[i] Starting myagent-ai web ..." -ForegroundColor Gray
166
+ Refresh-Path
167
+ try {
168
+ Start-Process cmd -ArgumentList "/c", "myagent-ai web" -WindowStyle Minimized
169
+ } catch {
170
+ Write-Host " Please restart terminal and run: myagent-ai web" -ForegroundColor Cyan
380
171
  }
381
-
382
- Show-Guide