feat: 添加 mind update 命令 + 远端版本检查(versions.json)
- mind update: 检查 dl.brainwork.club/mindos-next/versions.json - 有新版本时自动 pip install --upgrade - 修复 VENDOR_COMMIT 文件读取
This commit is contained in:
parent
3a1ecd7adc
commit
f0cc661067
@ -217,16 +217,56 @@ def record_status():
|
|||||||
click.echo("⏹️ Health Server 未运行")
|
click.echo("⏹️ Health Server 未运行")
|
||||||
|
|
||||||
|
|
||||||
def _get_vendor_commit() -> str:
|
@main.command()
|
||||||
"""读取 _vendor/HERMES_COMMIT 文件获取 vendor 版本。"""
|
def update():
|
||||||
commit_file = os.path.join(mindcli._VENDOR_DIR, "HERMES_COMMIT")
|
"""检查并升级到最新版本。"""
|
||||||
|
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:
|
try:
|
||||||
with open(commit_file) as f:
|
req = urllib.request.Request(versionsUrl)
|
||||||
return f.read().strip()
|
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:
|
except FileNotFoundError:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user