From f0cc661067ebb2ac585afad4eb7136b36d2f9ee4 Mon Sep 17 00:00:00 2001 From: lidf Date: Wed, 29 Apr 2026 08:50:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20mind=20update=20?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=20+=20=E8=BF=9C=E7=AB=AF=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=EF=BC=88versions.json=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - mind update: 检查 dl.brainwork.club/mindos-next/versions.json - 有新版本时自动 pip install --upgrade - 修复 VENDOR_COMMIT 文件读取 --- mindcli/cli.py | 52 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/mindcli/cli.py b/mindcli/cli.py index e11cbc7..9be3065 100644 --- a/mindcli/cli.py +++ b/mindcli/cli.py @@ -217,16 +217,56 @@ def record_status(): click.echo("⏹️ Health Server 未运行") -def _get_vendor_commit() -> str: - """读取 _vendor/HERMES_COMMIT 文件获取 vendor 版本。""" - commit_file = os.path.join(mindcli._VENDOR_DIR, "HERMES_COMMIT") +@main.command() +def update(): + """检查并升级到最新版本。""" + import subprocess + + click.echo(f"当前版本: v{mindcli.__version__}") + click.echo("正在检查最新版本...") + + remoteVersion = _check_remote_version() + if remoteVersion and remoteVersion != mindcli.__version__: + click.echo(f"⬆️ 发现新版本 v{remoteVersion}") + click.echo("正在升级...") + installCmd = "pip install --upgrade git+https://git.brainwork.club/lidf/MindOS_CLI.git" + result = subprocess.run(installCmd.split(), capture_output=True, text=True) + if result.returncode == 0: + click.echo(f"✅ 已升级到 v{remoteVersion}") + click.echo(" 请重启 Mind CLI(mind start)以生效") + else: + click.echo(f"❌ 升级失败: {result.stderr[:200]}") + elif remoteVersion: + click.echo(f"✅ 已是最新版本 v{mindcli.__version__}") + else: + click.echo("⚠️ 无法检查远端版本(网络问题?)") + + +def _check_remote_version(): + """从 versions.json 获取远端 CLI 最新版本号。""" + import urllib.request + versionsUrl = "https://dl.brainwork.club/mindos-next/versions.json" try: - with open(commit_file) as f: - return f.read().strip() + req = urllib.request.Request(versionsUrl) + with urllib.request.urlopen(req, timeout=5) as resp: + data = json.loads(resp.read()) + return data.get("cli", {}).get("version") + except Exception: + return None + + +def _get_vendor_commit() -> str: + """读取 _vendor/VENDOR_COMMIT 文件获取 vendor 版本。""" + commitFile = os.path.join(mindcli._VENDOR_DIR, "VENDOR_COMMIT") + try: + with open(commitFile) as f: + for line in f: + if line.startswith("commit:"): + return line.split(":", 1)[1].strip() + return "unknown" except FileNotFoundError: return "unknown" if __name__ == "__main__": main() -