mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 17:59:21 +08:00
python-runtime 与 dev-environment-setup 还在描述客户端 10.0.105 之前的 Hatch 布局:正常安装时没有 runtime/hatch/hatch,probe-python.sh 的 hatch_path 恒空,Agent 接着就会用系统包管理器。文档的 CLI 写法同样有问题:Hatch 1.16.5 里没有 HATCH_HOME 和 HATCH_PYTHON_MIRROR_URL,不带 --private --dir 的 python install 装到用户数据目录并改写 .zshrc、.zprofile,DesireCore 也看不到那个 Python。 - 二进制改为随包的 static/toolchains/<平台>-<架构>/hatch/hatch;runtime/hatch/hatch 只有手动下载后才存在 - 先用已在 PATH 上的内置 Python;指定版本用 runtime/hatch/local/<版本> 的绝对路径,pip 走探测到的解释器 - 安装命令带 --private --dir,环境变量改为 PYAPP_INSTALL_DIR_HATCH;换下载源用 HATCH_PYTHON_CUSTOM_SOURCE_<NAME>,并写明 URL 形态约束 - probe-python.sh 按新布局查找,新增 hatch_bootstrap,只认与二进制同版本的分发;没有解包好的分发时不执行二进制,避免 --version 触发下载;输出的路径字段做 JSON 转义 - 写明这个 bash 探测脚本在 Windows 上不查找 Hatch,降级到 L3 前先试 L2 的 Windows 路径 - 记录首启导入把本机镜像地址写进 hatch-dist.json,导致 local/ 上的 Hatch 命令报 Unknown distribution source,并给出修复办法;客户端修复见 desirecore/desirecore#5578 - desirecore-runtime.md 的源码路径改为 packages/agent-service/src;decision-tree.md 补上 standalone 的 401 - 版本 python-runtime 1.0.3 → 1.0.4、dev-environment-setup 2.0.5 → 2.0.6,sidecar 与 i18n source_hash 同步;不设客户端版本门槛 Correct the Hatch paths and install commands in python-runtime and dev-environment-setup, which still described the layout from before client 10.0.105 and told Agents to run an install that edits shell startup files and lands where DesireCore cannot see it. probe-python.sh now finds the current layout, reports the unpacked distribution, and no longer triggers a download. 验证:catalog metadata 与 i18n 校验 0 error,translate --check 通过,market-i18n-real-repo 22/22;真实 Hatch 1.16.5 在隔离 HOME 下逐条跑过文档命令;standalone 隔离 HOME + mock 模型下真实 Bash 工具按文档跑通,未调用真实模型;探测脚本覆盖多种布局及含引号、反斜杠的路径。Windows 写法只对照源码。私有敏感词扫描未执行,经用户确认后合并。
7.5 KiB
7.5 KiB
环境管理四级降级决策树
python-runtime 与 nodejs-runtime 在执行任何安装/版本切换前必须按本决策树选择路径。
总体流程
┌──────────────────┐
│ 执行 probe 脚本 │
└─────────┬────────┘
▼
┌─────────────────────────────┐
│ desirecore_api 字段非空? │
└────────┬───────────────┬─────┘
是 │ │ 否
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ L1:HTTP API 路径 │ │ hatch_path / │
└────────┬─────────┘ │ volta_path 非空? │
│ └────────┬──┬──────┘
失败/超时 是 │ │ 否
▼ ▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ L2:DesireCore CLI │ │ L3:系统包管理器 │
└────────┬─────────┘ └────────┬─────────┘
│ │
二进制损坏 / 安装失败 失败/不可用
▼ ▼
┌─────────────────────────────────────────┐
│ L4:社区方案(pyenv / nvm / fnm / conda)│
└─────────────────────────────────────────┘
L1:DesireCore HTTP API(最高优先级)
触发条件
${DESIRECORE_ROOT}/agent-service.port文件存在且可读curl -sk --max-time 0.5 https://127.0.0.1:${PORT}/api/runtime/environment返回 2xx- 当前会话能订阅 Socket.IO(DesireCore 内部 Agent 默认满足)
典型操作
PORT=$(cat ${DESIRECORE_ROOT}/agent-service.port)
BASE="https://127.0.0.1:${PORT}/api/runtime"
# 1. 拉取快照
curl -sk "${BASE}/environment"
# 2. 触发安装(异步)
curl -sk -X POST "${BASE}/python/install" \
-H "Content-Type: application/json" \
-d '{"version":"3.12"}'
# 3. 订阅 runtime:terminal / runtime:complete 事件展示日志
判定失败的信号
- HTTP 状态码 ≥ 500 或 502(远端镜像不可用,见
runtime-env-routes.ts) - HTTP 401:standalone 部署的接口要求实例令牌,Agent 没有
runtime:complete事件success: false- Socket.IO 连接断开后超过 30 秒未收到
runtime:complete
切换提示:API 失败立即降级到 L2 CLI,不要重试同一接口(可能是镜像被墙)。
L2:DesireCore 内置 CLI(绝对路径)
触发条件
- API 不可达或失败
- probe 脚本中
hatch_path/volta_path字段非空(即二进制存在)
典型操作(macOS / Linux)
PY_PROBE=$(bash skills/python-runtime/scripts/probe-python.sh)
HATCH=$(echo "$PY_PROBE" | jq -r .hatch_path)
VOLTA=$(bash skills/nodejs-runtime/scripts/probe-node.sh | jq -r .volta_path)
export PYAPP_INSTALL_DIR_HATCH=$(echo "$PY_PROBE" | jq -r .hatch_bootstrap)
export VOLTA_HOME="${VOLTA_HOME:-${DESIRECORE_ROOT}/runtime/volta-home}"
export VOLTA_FEATURE_PNPM=1
"$HATCH" python install 3.12 --private --dir="${DESIRECORE_ROOT}/runtime/hatch/local"
"$VOLTA" fetch node@22
典型操作(Windows PowerShell)
$Hatch = "<安装目录>\static\toolchains\win32-x64\hatch\hatch.exe"
$Volta = "<安装目录>\static\toolchains\win32-x64\volta\volta.exe" # ARM 为 win32-arm64
$env:PYAPP_INSTALL_DIR_HATCH = "$env:DESIRECORE_ROOT\runtime\hatch\bootstrap\<Hatch 版本>-win32-x64"
if (-not $env:VOLTA_HOME) { $env:VOLTA_HOME = "$env:DESIRECORE_ROOT\runtime\volta-home" }
$env:VOLTA_FEATURE_PNPM = "1"
& $Hatch python install 3.12 --private "--dir=$env:DESIRECORE_ROOT\runtime\hatch\local"
& $Volta fetch node@22
Hatch、Volta 二进制和 Volta Home 的位置见 desirecore-runtime.md 第一节。python install 必须带 --private --dir,否则 Hatch 装到用户数据目录并改写 shell 配置;报 Unknown distribution source 时见 python-runtime/references/hatch-desirecore.md。
判定失败的信号
- exit code ≠ 0
- stderr 包含
network、timeout、ENOTFOUND、failed to fetch - 可执行文件被反病毒软件隔离(macOS Gatekeeper / Windows Defender)
切换提示:失败后才考虑 L3,不要在 L2 内重试。
L3:系统包管理器
触发条件:DesireCore 二进制全部缺失,或用户明确要求"系统级"安装。
| 平台 | Python | Node.js |
|---|---|---|
| macOS | brew install python3 |
brew install node |
| Debian/Ubuntu | sudo apt install python3 python3-pip python3-venv |
NodeSource 仓库或 sudo apt install nodejs npm |
| Fedora/RHEL | sudo dnf install python3 python3-pip |
sudo dnf install nodejs |
| Arch | sudo pacman -S python python-pip |
sudo pacman -S nodejs npm |
| Windows | winget install Python.Python.3 |
winget install OpenJS.NodeJS.LTS |
判定失败的信号
command not found(包管理器自身缺失,如brew未装)- PEP 668 报错(Linux 新版发行版
pip install全局被拒)→ 见 python-runtime troubleshooting - 权限被拒(缺少 sudo / 非管理员)
切换提示:仅在系统包管理器都失败、并且用户明确希望安装时升级到 L4。
L4:社区方案
仅在以下情况启用:
- 用户明确指定("我要 pyenv"、"用 nvm 装")
- L1–L3 全部失败
- 项目已经使用社区方案(存在
.python-version/.nvmrc文件)
| 工具 | 用途 | 文档 |
|---|---|---|
| pyenv / pyenv-win | Python 多版本 | python-runtime/references/pyenv-fallback.md |
| nvm / nvm-windows | Node.js 多版本(shell 脚本) | nodejs-runtime/references/nvm-fallback.md |
| fnm | Rust 实现的 nvm 替代 | nodejs-runtime/references/nvm-fallback.md |
| conda / miniconda | 数据科学场景 | python-runtime/references/virtualenv.md |
何时跳过决策树
skill 直接执行用户原话——不要走决策树——的情况:
- 运行时已可用且版本够用:DesireCore 把内置 Python、Node 各一个版本追加在 PATH 末尾,
python3 --version、node --version成功就不需要安装 - 用户明示路径:"用 brew 装 python"、"在 .venv 里 pip install xxx"
- 用户在 skill 之外手工修改了环境(识别到
.python-version、.nvmrc、package.json#volta) - skill 上下文已经存在激活的虚拟环境(
$VIRTUAL_ENV非空)
每次升级版本后
无论走哪条路径,安装/移除完成后立即调用:
# L1 模式
curl -sk -X POST "${BASE}/environment/refresh"
# L2/L3/L4 模式(强制 probe 输出最新结果)
bash <skill>/scripts/probe-{python,node}.sh
避免后续判断基于陈旧缓存。