Skip to content

修复: Windows host 模式下路径兼容#570

Open
paroquet wants to merge 1 commit into
riba2534:mainfrom
paroquet:fix/windows-host-compat
Open

修复: Windows host 模式下路径兼容#570
paroquet wants to merge 1 commit into
riba2534:mainfrom
paroquet:fix/windows-host-compat

Conversation

@paroquet

Copy link
Copy Markdown

问题描述

agent-runner 最初为 Linux 容器编写,在 Windows host 模式下暴露多处 POSIX 假设,导致 host 模式无法启动 agent。

修复方案

container/agent-runner/src/index.ts

  • PROMPTS_DIR 盘符翻倍:new URL(import.meta.url).pathname 在 Windows 上返回 /E:/.../index.js(带前导斜杠 + 盘符),path.join 后丢盘符变成 \E:\...,再被 Node 按当前盘根解析成 E:\E:\... 导致 ENOENT。改用 fileURLToPath,Linux 容器与 Windows host 下都返回正确本地路径。
  • claude.exe 解析:which claude 在 Windows 上多半找不到,fallback 全是 Linux 路径,导致 pathToClaudeCodeExecutable 为空、SDK 自找漏 .exe 报 "native binary not found"。win32 下直接解析 SDK 自带的 @anthropic-ai/claude-agent-sdk-win32-x64/claude.exe(与 agent-capabilities.ts 主进程侧解析逻辑一致);Linux 容器里这些 optionalDependencies 是空包,仍走原 which 分支。

src/container-runner.ts

  • PATH 分隔符:hostEnv['PATH'] 拼接硬编码 :,Windows 上会把盘符(E:)也当分隔符拼烂 PATH。改用 path.delimiter(Windows ; / POSIX :)。
  • **~ 展开 fallback**:mount allowlist 的 ~ 展开 fallback 到 macOS 风格 /Users/user。改用 os.homedir()

验证

  • make typecheck 全量通过
  • 改动均为平台分支隔离,Linux 容器路径行为不变

🤖 Generated with Claude Code

agent-runner 本为 Linux 容器编写,在 Windows host 模式下暴露多处 POSIX 假设:

- index.ts: PROMPTS_DIR 用 new URL(import.meta.url).pathname 在 Windows 返回 /E:/... 带前导斜杠+盘符,path.join 后丢盘符变 \E:\... 被按当前盘根解析成 E:\E:\... ENOENT。改用 fileURLToPath。

- index.ts: which claude 在 Windows 找不到、fallback 全是 Linux 路径,导致 pathToClaudeCodeExecutable 为空、SDK 自找漏 .exe 报 native binary not found。win32 下直接解析 SDK 自带 claude-agent-sdk-win32-x64\claude.exe(Linux 容器仍走 which,那里平台包是空包)。

- container-runner.ts: hostEnv PATH 拼接硬编码 : 分隔符,Windows 上把盘符 E: 也当分隔符拼烂 PATH。改用 path.delimiter。

- container-runner.ts: mount allowlist ~ 展开 fallback 到 macOS 风格 /Users/user。改用 os.homedir()。
@paroquet paroquet changed the title 修复: Windows host 模式兼容(prompts 路径盘符翻倍 / claude.exe 解析 / PATH 分隔符 / ~ 展开) 修复: Windows host 模式下路径兼容 Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant