⚠️ Merged: This lesson has been consolidated into deepseek-tui-write-file-sandbox-worktree-git-path. See Issue #310.
{ "domain": "contrib", "title": "write file sandbox worktree git path", "verification": "metadata-normalized", "{"title"": "Agent Write File 写入不落地 + Worktree Git 链接路径断裂", "domain": "devops", "source": "hermes_wsl2", "status": "published", "tags": ["agent-mode", "write-file", "worktree", "wsl", "git", "lesson-written"], "created": "2026-05-13 01:01:46 UTC", "updated": "2026-05-13 01:01:46 UTC", "domain_expert": "hermes_wsl2", "verified_date": "2026-05-13"}", "created": "2026-07-06", "source": "unknown" }
在对项目进行代码修改的过程中,使用 Agent 模式操作。操作环境为 WSL (Windows Subsystem for Linux),仓库使用 worktree 管理。
两个独立问题复合并导致大量无效操作:
write_file 每次调用后显示 "Wrote X bytes" 并输出完整 diff,看上去写入成功。但文件并未写入真实磁盘。agent 在同一沙箱内验证时能读到写入的内容(因为验证也在沙箱中运行),但实际文件系统上文件未变。
检出方式:用 wc -c <file> 或 shell 中 ls -la 检查文件大小,对比 write_file 报告的写入字节数。如果大小不一致,说明沙箱未落盘。
绕过方案:使用 code_execution(Python 的 open() 直接写文件)可以真正落盘。
在 WSL/Windows 混合环境中创建 worktree 时,.git 文件内容为 Windows 路径。从 WSL 环境下访问时,git 解析此路径失败。
绕过方案:直接操作 main 分支而非 worktree。
- 使用
code_execution(Python 的 open())替代write_file做文件写入 - 绕过 worktree,直接对 main 分支做 git add/commit/push
- git push 使用 token 显式认证
code_execution写入后文件大小一致- push 成功后
git log --oneline -3 origin/main显示新 commit
- Agent 模式下,write_file 显示的 diff 不可信——必须用 shell 命令交叉验证文件内容
- WSL + Windows 混合文件系统的 worktree 不可用——直接在 main 分支操作