mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 18:19:29 +08:00
fix(python-runtime): 修正过时的 Hatch 路径与安装写法(1.0.4)/ correct stale Hatch paths and install commands (#242)
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 写法只对照源码。私有敏感词扫描未执行,经用户确认后合并。
This commit is contained in:
11 files changed
+276
-106
No files matched your search
@@ -13,7 +13,7 @@ description: >-
|
||||
cross-cutting environment question. 使用场景:用户提到 环境配置、PATH、
|
||||
容器、Docker、Podman、WSL、WSL2、办公依赖、系统工具,或不确定属于 Python /
|
||||
Node.js 时的入口指引。
|
||||
version: 2.0.5
|
||||
version: 2.0.6
|
||||
type: procedural
|
||||
risk_level: low
|
||||
status: enabled
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
},
|
||||
"release": {
|
||||
"state": "known",
|
||||
"version": "2.0.5",
|
||||
"version": "2.0.6",
|
||||
"versionScheme": "semver"
|
||||
},
|
||||
"timestamps": {
|
||||
|
||||
@@ -58,7 +58,8 @@ curl -sk -X POST "${BASE}/python/install" \
|
||||
|
||||
**判定失败的信号**
|
||||
|
||||
- HTTP 状态码 ≥ 500 或 502(远端镜像不可用,详见 runtime-env-routes.ts 130/162 行)
|
||||
- HTTP 状态码 ≥ 500 或 502(远端镜像不可用,见 `runtime-env-routes.ts`)
|
||||
- HTTP 401:standalone 部署的接口要求实例令牌,Agent 没有
|
||||
- `runtime:complete` 事件 `success: false`
|
||||
- Socket.IO 连接断开后超过 30 秒未收到 `runtime:complete`
|
||||
|
||||
@@ -74,32 +75,33 @@ curl -sk -X POST "${BASE}/python/install" \
|
||||
**典型操作(macOS / Linux)**
|
||||
|
||||
```bash
|
||||
HATCH=${DESIRECORE_ROOT}/runtime/hatch/hatch
|
||||
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 HATCH_HOME=${DESIRECORE_ROOT}/runtime/hatch
|
||||
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
|
||||
"$HATCH" python install 3.12 --private --dir="${DESIRECORE_ROOT}/runtime/hatch/local"
|
||||
"$VOLTA" fetch node@22
|
||||
```
|
||||
|
||||
**典型操作(Windows PowerShell)**
|
||||
|
||||
```powershell
|
||||
$Hatch = "$env:USERPROFILE\.desirecore\runtime\hatch\hatch.exe"
|
||||
$Hatch = "<安装目录>\static\toolchains\win32-x64\hatch\hatch.exe"
|
||||
$Volta = "<安装目录>\static\toolchains\win32-x64\volta\volta.exe" # ARM 为 win32-arm64
|
||||
|
||||
$env:HATCH_HOME = "$env:USERPROFILE\.desirecore\runtime\hatch"
|
||||
$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
|
||||
& $Hatch python install 3.12 --private "--dir=$env:DESIRECORE_ROOT\runtime\hatch\local"
|
||||
& $Volta fetch node@22
|
||||
```
|
||||
|
||||
Volta 二进制与 Volta Home 的位置见 `desirecore-runtime.md` 第一节。
|
||||
Hatch、Volta 二进制和 Volta Home 的位置见 `desirecore-runtime.md` 第一节。`python install` 必须带 `--private --dir`,否则 Hatch 装到用户数据目录并改写 shell 配置;报 `Unknown distribution source` 时见 `python-runtime/references/hatch-desirecore.md`。
|
||||
|
||||
**判定失败的信号**
|
||||
|
||||
|
||||
@@ -6,12 +6,18 @@ DesireCore 内置了完整的开发环境管理基础设施。`python-runtime`
|
||||
|
||||
### Hatch(Python 项目与版本管理器,v1.16.5)
|
||||
|
||||
| 平台 | 运行时绝对路径(用户安装版,优先) | 静态打包兜底 |
|
||||
|------|----------------------------------|--------------|
|
||||
| macOS / Linux | `${DESIRECORE_ROOT}/runtime/hatch/hatch` | 应用包内 `static/hatch/hatch` |
|
||||
| Windows | `%USERPROFILE%\.desirecore\runtime\hatch\hatch.exe` | 应用包内 `static/hatch/hatch.exe` |
|
||||
| 平台 | 手动下载(存在时优先) | 随包(默认) |
|
||||
|------|------------------------|--------------|
|
||||
| macOS / Linux | `${DESIRECORE_ROOT}/runtime/hatch/hatch` | 应用目录下 `static/toolchains/<平台>-<架构>/hatch/hatch` |
|
||||
| Windows | `$env:DESIRECORE_ROOT\runtime\hatch\hatch.exe` | 应用目录下 `static\toolchains\win32-x64\hatch\hatch.exe` |
|
||||
|
||||
**Python 版本安装目录**:`${DESIRECORE_ROOT}/runtime/hatch/local/<版本>/python/bin/python3`(macOS/Linux),Windows 为 `python.exe`。
|
||||
应用目录在 macOS 是 `<App>.app/Contents`,其他平台是安装目录。`runtime/hatch/` 下只有手动下载 Hatch 后才有二进制。Windows ARM64 随包的 `hatch-universal.exe` 是安装器,不能当 CLI 调用。
|
||||
|
||||
**Hatch 分发**:`${DESIRECORE_ROOT}/runtime/hatch/bootstrap/<Hatch 版本>-<平台>-<架构>/`(客户端 10.0.183 起),客户端启动后从随包归档解包。随包的 `hatch` 只是 PyApp 引导程序,直接调用时用 `PYAPP_INSTALL_DIR_HATCH` 指向这里,否则任何命令(包括 `--version`)第一次运行都要联网下载约 45MB,并解压到用户目录。
|
||||
|
||||
**Python 版本安装目录**:`${DESIRECORE_ROOT}/runtime/hatch/local/<版本>/python/bin/python3`(macOS/Linux),Windows 为 `python\python.exe`,pip 在旁边的 `Scripts\`。安装时必须带 `--private --dir=<这个 local 目录>`,否则 Hatch 装到用户数据目录并改写 `.zshrc`、`.zprofile`。
|
||||
|
||||
**内置 Python 已在 PATH 上**:服务把一个版本的可执行文件目录追加到进程 PATH 末尾,Bash 等工具都会继承,所以通常直接用 `python3`、`pip3`。系统已有 Python 时系统版本优先,要用内置版本就写绝对路径。
|
||||
|
||||
### Volta(Node.js 工具链管理器,v2.0.2)
|
||||
|
||||
@@ -32,19 +38,21 @@ DesireCore 内置了完整的开发环境管理基础设施。`python-runtime`
|
||||
|
||||
### 优先级规则
|
||||
|
||||
`runtime/` 目录优先于 `static/`。当用户更新过 Hatch/Volta 时,新版本写入 `runtime/`,DesireCore 优先调用之。
|
||||
`runtime/` 下的二进制优先于 `static/`。随包二进制可用时不会下载,只有它不可用时,`POST /hatch/install`、`POST /volta/install` 才写入 `runtime/`。
|
||||
|
||||
## 二、关键环境变量
|
||||
|
||||
| 变量 | 作用 | 默认/示例 |
|
||||
|------|------|----------|
|
||||
| `HATCH_HOME` | Hatch 工作目录 | `${DESIRECORE_ROOT}/runtime/hatch` |
|
||||
| `HATCH_PYTHON_MIRROR_URL` | Python 下载镜像 | 加速节点(中国大陆) |
|
||||
| `PYAPP_INSTALL_DIR_HATCH` | Hatch 分发目录 | `${DESIRECORE_ROOT}/runtime/hatch/bootstrap/<Hatch 版本>-<平台>-<架构>` |
|
||||
| `HATCH_PYTHON_CUSTOM_SOURCE_<NAME>` | 覆盖某个 Python 版本的下载地址(完整归档 URL,加号写成 `%2B`,路径里必须有 `/python-build-standalone/releases/download/`) | `<NAME>` 是大写的版本名,点换成下划线,如 `3_12` |
|
||||
| `VOLTA_HOME` | Volta 工作目录 | `${DESIRECORE_ROOT}/runtime/volta-home` |
|
||||
| `VOLTA_FEATURE_PNPM` | 启用 pnpm 管理 | `1` |
|
||||
|
||||
DesireCore 只在自己调用 Hatch / Volta 时设置这些变量,不会传给 Bash 等工具;直接调用绝对路径 CLI 时需手动 export。
|
||||
|
||||
客户端还会设置 `HATCH_HOME`,但 Hatch 1.16.5 不读这个变量,也没有 `HATCH_PYTHON_MIRROR_URL`,这两个都不用设。Python 的安装目录靠 `--dir` 指定。
|
||||
|
||||
## 三、HTTP API 速查表
|
||||
|
||||
DesireCore agent-service 启动后将端口写入 `${DESIRECORE_ROOT}/agent-service.port`。全部接口走 **HTTPS + 自签名证书**(curl 需要 `-k`)。
|
||||
@@ -65,8 +73,8 @@ BASE="https://127.0.0.1:${PORT}/api/runtime"
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| GET | `/hatch/status` | 检查 Hatch 是否就绪(runtime/static 任一存在即可) |
|
||||
| POST | `/hatch/install` | 下载并安装 Hatch 到 `runtime/hatch/`(同步返回成功/失败) |
|
||||
| GET | `/hatch/status` | 实际执行一次 `hatch --version`,Hatch 分发还没解包完时会先等它;返回 `{ installed, version }` |
|
||||
| POST | `/hatch/install` | 随包 Hatch 可用时直接返回成功,否则下载并安装到 `runtime/hatch/`(同步返回成功/失败) |
|
||||
| GET | `/volta/status` | 检查 Volta 是否就绪 |
|
||||
| POST | `/volta/install` | 随包 Volta 可用时直接返回成功,否则下载并安装到 `runtime/volta/` |
|
||||
|
||||
@@ -75,8 +83,8 @@ BASE="https://127.0.0.1:${PORT}/api/runtime"
|
||||
| 方法 | 路径 | 请求体 / 返回 |
|
||||
|------|------|--------------|
|
||||
| GET | `/python/installed` | 返回已安装版本列表(`["3.11", "3.12"]`) |
|
||||
| GET | `/python/available` | 返回可安装版本(依赖 Hatch 元数据) |
|
||||
| POST | `/python/install` | `{ "version": "3.12" }` → `{ "taskId": "uuid" }`,订阅 `runtime:terminal` 流 |
|
||||
| GET | `/python/available` | 返回可安装版本 `{ source, versions: [{ name, version }] }`(Hatch 内置清单,不联网;Hatch 不可用时回落到兜底清单) |
|
||||
| POST | `/python/install` | `{ "version": "3.12" }`(填上面的 `name`)→ `{ "taskId": "uuid" }`,订阅 `runtime:terminal` 流;首启导入进行中返回 409 |
|
||||
| POST | `/python/remove` | `{ "version": "3.11" }` → `{ "taskId": "uuid" }` |
|
||||
|
||||
### Node.js 版本管理
|
||||
@@ -126,11 +134,13 @@ fi
|
||||
|
||||
## 六、EnvironmentSnapshot 数据结构
|
||||
|
||||
`GET /api/runtime/environment` 返回结构(详见 `lib/agent-service/environment-detection.ts`):
|
||||
`GET /api/runtime/environment` 返回结构(详见主仓库 `packages/agent-service/src/context/environment-detection.ts`):
|
||||
|
||||
```ts
|
||||
type ToolDetection = {
|
||||
available: boolean
|
||||
status?: 'available' | 'not_found' | 'detection_failed' // detection_failed 只表示本次没有结论,不能据此建议安装
|
||||
failureCode?: string
|
||||
command?: string // 实际命令名(python3 / python)
|
||||
version?: string // 提取后的版本号
|
||||
path?: string // which/where 解析的绝对路径
|
||||
@@ -147,7 +157,11 @@ type EnvironmentSnapshot = {
|
||||
docker: ToolDetection
|
||||
podman: ToolDetection
|
||||
git: ToolDetection
|
||||
brew: ToolDetection
|
||||
gh: ToolDetection
|
||||
cuaDriver: ToolDetection
|
||||
}
|
||||
toolkits?: unknown[] // 命令行工具套件(如 FFmpeg)的检测结果
|
||||
wsl?: {
|
||||
installed: boolean
|
||||
version?: string
|
||||
@@ -187,9 +201,10 @@ type EnvDiff = {
|
||||
|
||||
## 八、参考源代码
|
||||
|
||||
| 模块 | 文件 | 行数(仓库 ~/Project/desirecore) |
|
||||
|------|------|----------------------------------|
|
||||
| 工具检测 | `lib/agent-service/environment-detection.ts` | 1–310 |
|
||||
| 工具链管理(Hatch/Volta + 版本安装) | `lib/agent-service/runtime-manager.ts` | 1–1165 |
|
||||
| HTTP 路由 | `lib/agent-service/routes/runtime-env-routes.ts` | 1–186 |
|
||||
| 端口文件 | `${DESIRECORE_ROOT}/agent-service.port` | DesireCore 启动时写入 |
|
||||
| 模块 | 文件(主仓库) |
|
||||
|------|----------------|
|
||||
| 工具检测 | `packages/agent-service/src/context/environment-detection.ts` |
|
||||
| 工具链管理(Hatch/Volta + 版本安装) | `packages/agent-service/src/session/runtime-manager.ts` |
|
||||
| 内置运行时进 PATH | `packages/agent-service/src/session/managed-runtime-path.ts` |
|
||||
| HTTP 路由 | `packages/agent-service/src/routes/runtime-env-routes.ts` |
|
||||
| 端口文件 | `${DESIRECORE_ROOT}/agent-service.port`,DesireCore 启动时写入 |
|
||||
@@ -45,9 +45,10 @@ Windows 上 `wsl` 字段值类似 `{ "installed": true, "version": "2", "default
|
||||
"desirecore_api": "https://127.0.0.1:38291",
|
||||
"system_python": { "path": "/opt/homebrew/bin/python3", "version": "3.12.4" },
|
||||
"system_pip": { "path": "/opt/homebrew/bin/pip3", "version": "24.0" },
|
||||
"hatch_path": "/Users/example/.desirecore/runtime/hatch/hatch",
|
||||
"hatch_path": "/Applications/DesireCore.app/Contents/static/toolchains/darwin-arm64/hatch/hatch",
|
||||
"hatch_version": "1.16.5",
|
||||
"hatch_versions": ["3.11", "3.12"],
|
||||
"hatch_bootstrap": "/Users/example/.desirecore/runtime/hatch/bootstrap/1.16.5-darwin-arm64",
|
||||
"hatch_versions": ["3.13"],
|
||||
"active_venv": "/Users/example/proj/.venv",
|
||||
"pep668": false,
|
||||
"pyenv_path": "",
|
||||
@@ -56,7 +57,10 @@ Windows 上 `wsl` 字段值类似 `{ "installed": true, "version": "2", "default
|
||||
```
|
||||
|
||||
字段语义:
|
||||
- `hatch_path` 空字符串表示二进制不存在
|
||||
- `system_python` / `system_pip` 是 PATH 解析到的结果,可能是 DesireCore 追加到 PATH 的内置 Python
|
||||
- `hatch_path` 空字符串表示没找到二进制,查找顺序见 `python-runtime/references/hatch-desirecore.md`;这个脚本在 Windows 上不查找 Hatch,恒为空
|
||||
- `hatch_bootstrap` 是客户端解包好的 Hatch 分发目录,直接调用 Hatch 时经 `PYAPP_INSTALL_DIR_HATCH` 传入,版本与二进制一致;空字符串表示解包还没完成或客户端早于 10.0.183
|
||||
- `hatch_version` 在 `hatch_bootstrap` 为空时读二进制旁边的 `asset.json`,读不到就是空字符串,不执行二进制(否则会触发下载)
|
||||
- `hatch_versions` 是 `${DESIRECORE_ROOT}/runtime/hatch/local/` 下的目录列表(即已通过 Hatch 安装的 Python 版本)
|
||||
- `active_venv` 取自 `$VIRTUAL_ENV` 环境变量
|
||||
- `pep668` 检测 `/usr/lib/python*/EXTERNALLY-MANAGED` 是否存在(Debian 12+/Ubuntu 23.04+ 启用)
|
||||
|
||||
Reference in new issue
Block a user