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:
yige authored and GitHub committed 2026-11-01 21:50:44 +08:00
1 parent e02b8ad773
commit 3ad8afde37
11 files changed
+276 -106

No files matched your search

+30 -15
View File
@@ -14,7 +14,7 @@ description: >-
version", "pip command not found", or any Python-related runtime error.
使用场景:用户需要 安装 Python、安装 pip、配置虚拟环境、管理多版本、
解决 PEP 668、import 失败、PATH 问题、SSL 证书错误等。
version: 1.0.3
version: 1.0.4
type: procedural
risk_level: low
status: enabled
@@ -31,7 +31,7 @@ tags:
- environment
metadata:
author: desirecore
updated_at: '2026-05-02'
updated_at: '2026-11-01'
i18n:
default_locale: en-US
source_locale: zh-CN
@@ -44,7 +44,7 @@ metadata:
description: >-
Use this skill when the user needs to install, upgrade, or troubleshoot Python and pip environments. Covers four-tier fallback strategy: (1) DesireCore HTTP API for in-app installation, (2) DesireCore built-in Hatch CLI for Python version management, (3) system package managers (brew/apt/dnf/winget), (4) community pyenv as last resort. Also covers virtual environments (venv/pipx/conda), PEP 668 externally-managed errors, and import / PATH troubleshooting. Triggers include: "install python", "pip not found", "python not found", "PEP 668", "externally-managed", "venv", "virtualenv", "pipx", "conda", "miniconda", "pyenv", "hatch", "python version", "pip command not found", or any Python-related runtime error. 使用场景:用户需要 安装 Python、安装 pip、配置虚拟环境、管理多版本、 解决 PEP 668、import 失败、PATH 问题、SSL 证书错误等。
body: ./SKILL.zh-CN.md
source_hash: sha256:ea796e0282dc77af
source_hash: sha256:6d530a7932ec82f6
translated_by: human
en-US:
name: Python Runtime Management
@@ -52,9 +52,9 @@ metadata:
description: >-
Use this skill when the user needs to install, upgrade, or troubleshoot Python and pip environments. Covers four-tier fallback strategy: (1) DesireCore HTTP API for in-app installation, (2) DesireCore built-in Hatch CLI for Python version management, (3) system package managers (brew/apt/dnf/winget), (4) community pyenv as last resort. Also covers virtual environments (venv/pipx/conda), PEP 668 externally-managed errors, and import / PATH troubleshooting. Triggers include: "install python", "pip not found", "python not found", "PEP 668", "externally-managed", "venv", "virtualenv", "pipx", "conda", "miniconda", "pyenv", "hatch", "python version", "pip command not found", or any Python-related runtime error. Use when the user needs to install Python, install pip, configure virtual environments, manage multiple versions, resolve PEP 668, import failures, PATH issues, SSL certificate errors, etc.
body: ./SKILL.md
source_hash: sha256:585a14843750b051
source_hash: sha256:6d530a7932ec82f6
translated_by: human
translated_at: '2026-05-03'
translated_at: '2026-11-01'
market:
icon: >-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0
@@ -88,9 +88,11 @@ between multiple Python versions / configure pip / create virtual environments
import failures, PATH anomalies, and other Python runtime issues; or when
another skill (docx / pdf / xlsx / pptx) reports "Python unavailable".
**How to do it**: Prefer DesireCore's built-in Hatch, executing through the
four-tier fallback (HTTP API → Hatch CLI → system package manager
brew/apt/dnf/winget → community solution pyenv).
**How to do it**: First check whether `python3` already works: DesireCore appends
a managed Python directory to its service PATH, so nothing usually needs
installing. To install or switch versions, prefer DesireCore's built-in Hatch,
executing through the four-tier fallback (HTTP API → Hatch CLI → system package
manager brew/apt/dnf/winget → community solution pyenv).
## L1: Overview and Use Cases
@@ -131,11 +133,17 @@ Decide using `../dev-environment-setup/references/decision-tree.md`:
| Condition | Path |
|------|------|
| `system_python.path` non-empty and its version is sufficient | Use that interpreter directly, with pip through `"<system_python.path>" -m pip`; nothing to install |
| A specific version is needed and `hatch_versions` lists it | Absolute path `${DESIRECORE_ROOT}/runtime/hatch/local/<version>/python/bin/python3` (→ `references/hatch-desirecore.md`) |
| `desirecore_api` is non-empty | **L1** HTTP API |
| `desirecore_api` empty, `hatch_path` non-empty | **L2** Hatch CLI |
| Neither of the above | **L3** system package manager (brew/apt/dnf/winget) |
| L1–L3 all fail or user explicitly requests | **L4** community solution (pyenv) |
`system_python` is whatever PATH resolves, which may be DesireCore's managed Python: one managed version is appended after the system directories, so a system `python3` wins when there is one. The Managed runtimes section of the `<env>` block lists the absolute path of every managed version.
This bash probe does not look for Hatch on Windows, so `hatch_path` stays empty there. Before falling to L3 on Windows, try the Windows path under L2.
### Step 3: Execute (only the main path is shown; see references for details)
#### L1: HTTP API (→ `references/hatch-desirecore.md`)
@@ -147,7 +155,8 @@ BASE="https://127.0.0.1:${PORT}/api/runtime"
# List installable versions
curl -sk "${BASE}/python/available"
# Trigger install (asynchronous; subscribe to runtime:terminal for progress)
# Trigger install (asynchronous; subscribe to runtime:terminal for progress).
# version is the name from the list above, such as 3.12, not 3.12.12
curl -sk -X POST "${BASE}/python/install" \
-H "Content-Type: application/json" \
-d '{"version":"3.12"}'
@@ -159,17 +168,22 @@ curl -sk -X POST "${BASE}/environment/refresh"
#### L2: Hatch CLI absolute path (→ `references/hatch-desirecore.md`)
```bash
HATCH=${DESIRECORE_ROOT}/runtime/hatch/hatch
export HATCH_HOME=${DESIRECORE_ROOT}/runtime/hatch
HATCH=$(jq -r .hatch_path /tmp/py-probe.json)
export PYAPP_INSTALL_DIR_HATCH=$(jq -r .hatch_bootstrap /tmp/py-probe.json)
LOCAL="${DESIRECORE_ROOT}/runtime/hatch/local"
"$HATCH" python install 3.12
"$HATCH" python show # List installed/installable versions
"$HATCH" python install 3.12 --private --dir="$LOCAL"
"$HATCH" python show --dir "$LOCAL" # List installed/installable versions
# Use the Hatch-installed Python directly
${DESIRECORE_ROOT}/runtime/hatch/local/3.12/python/bin/python3 -m venv .venv
"$LOCAL/3.12/python/bin/python3" -m venv .venv
```
Windows: `%USERPROFILE%\.desirecore\runtime\hatch\hatch.exe`.
Always pass `--private --dir`: without them Hatch installs into its user data directory and edits `.zshrc` and `.zprofile`, and DesireCore cannot see that Python. Set `PYAPP_INSTALL_DIR_HATCH` on every call: DesireCore sets it only for its own calls, not for Bash, and without it the first Hatch command downloads about 45 MB and unpacks it into the user directory. The binary ships at `static/toolchains/<platform>-<arch>/hatch/hatch` under the app directory; `runtime/hatch/hatch` exists only after a manual Hatch download.
`ValueError: Unknown distribution source` on these commands, or an L1 install that never completes, means the source recorded by the bundled first-start import needs repairing: see "修复首启导入留下的来源记录" in `references/hatch-desirecore.md`.
Windows: `<install dir>\static\toolchains\win32-x64\hatch\hatch.exe`, with `PYAPP_INSTALL_DIR_HATCH` at `$env:DESIRECORE_ROOT\runtime\hatch\bootstrap\<Hatch version>-win32-x64`.
#### L3: System Package Manager
@@ -209,6 +223,7 @@ When errors occur, look up `references/troubleshooting.md`:
2. **Refresh after modifying the environment**: for L1 call `POST /api/runtime/environment/refresh`; for L2/L3/L4 re-run probe.
3. **Cross-skill collaboration**: when `docx` / `pdf` / `xlsx` / `pptx` report "Python unavailable", fall into L1/L2 install; for office dependency lookup see `../dev-environment-setup/references/office-deps.md`.
4. **Do not pollute system Python**: at the project level always use venv; for global CLI use pipx.
5. **Never run `hatch python install` without `--private --dir`**: it would write to the user's shell startup files and install where DesireCore cannot see it.
## References