myagent-ai 1.15.75 → 1.15.77

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 (2) hide show
  1. package/package.json +1 -1
  2. package/start.js +33 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myagent-ai",
3
- "version": "1.15.75",
3
+ "version": "1.15.77",
4
4
  "description": "本地桌面端执行型AI助手 - Open Interpreter 风格 | Local Desktop Execution-Oriented AI Assistant",
5
5
  "main": "main.py",
6
6
  "bin": {
package/start.js CHANGED
@@ -385,36 +385,58 @@ function cmdReinstall(pkgDir) {
385
385
  }
386
386
 
387
387
  function cmdUpdate(pkgDir) {
388
+ // 读取当前版本
389
+ let curVer = "";
390
+ try { curVer = JSON.parse(fs.readFileSync(path.join(pkgDir, "package.json"), "utf8")).version || ""; } catch (_) {}
391
+
388
392
  console.log("");
389
- console.log(" \x1b[36mMyAgent 更新到最新版\x1b[0m");
393
+ console.log(` MyAgent 更新${curVer ? " v" + curVer : "到最新版"}`);
390
394
  console.log("");
391
395
 
392
- // 1. npm 升级全局包
396
+ // 1. npm 升级全局包(--force 确保跳过缓存)
393
397
  console.log(" 正在通过 npm 更新 myagent-ai ...");
394
398
  try {
395
- execFileSync("npm", ["install", "-g", PKG_NAME, "--prefer-online"], {
399
+ execFileSync("npm", ["install", "-g", PKG_NAME, "--prefer-online", "--force"], {
396
400
  encoding: "utf8", stdio: "inherit", timeout: 120000,
397
401
  });
398
402
  } catch (e) {
399
- console.error("\x1b[31mnpm 更新失败,请尝试手动运行: npm install -g myagent-ai@latest\x1b[0m");
403
+ console.error("npm 更新失败,请尝试手动运行: npm install -g myagent-ai@latest --force");
400
404
  process.exit(1);
401
405
  }
402
- console.log(" \x1b[32m✓\x1b[0m npm 包已更新");
403
406
 
404
407
  // 2. 重新定位 pkgDir(npm 更新后路径可能变化)
405
408
  const newPkgDir = resolvePackageDir();
406
409
  if (!fs.existsSync(path.join(newPkgDir, "main.py"))) {
407
- console.error("\x1b[31m更新后找不到 main.py,请重新安装: npm install -g myagent-ai@latest\x1b[0m");
410
+ console.error("更新后找不到 main.py,请重新安装: npm install -g myagent-ai@latest");
408
411
  process.exit(1);
409
412
  }
410
413
 
411
- let ver = "";
412
- try { ver = JSON.parse(fs.readFileSync(path.join(newPkgDir, "package.json"), "utf8")).version || ""; } catch (_) {}
413
- markDepsInstalled(ver);
414
+ let newVer = "";
415
+ try { newVer = JSON.parse(fs.readFileSync(path.join(newPkgDir, "package.json"), "utf8")).version || ""; } catch (_) {}
416
+
417
+ // 3. 如果版本变了,用新的 start.js 重新执行自身,确保运行最新代码
418
+ if (curVer && newVer && curVer !== newVer) {
419
+ const newStartJs = path.join(newPkgDir, "start.js");
420
+ if (fs.existsSync(newStartJs)) {
421
+ console.log(` 已下载 v${newVer},正在切换到新版本...`);
422
+ console.log("");
423
+ const { execSync } = require("child_process");
424
+ execSync(process.execPath + ' "' + newStartJs + '" update', {
425
+ stdio: "inherit", windowsHide: true, timeout: 30000,
426
+ });
427
+ return;
428
+ }
429
+ }
430
+
431
+ markDepsInstalled(newVer);
414
432
 
415
433
  console.log("");
416
- console.log(` \x1b[32m✓ 更新完成${ver ? " → v" + ver : ""}\x1b[0m`);
417
- console.log(" 运行 \x1b[36mmyagent-ai web\x1b[0m 启动");
434
+ if (newVer) {
435
+ console.log(` ✓ 已是最新版 v${newVer}`);
436
+ } else {
437
+ console.log(` ✓ 更新完成`);
438
+ }
439
+ console.log(` 运行 myagent-ai web 启动`);
418
440
  console.log("");
419
441
  }
420
442