Go to file
caoqianming 23ff996d38 Stage C Step 3d: fs 工具进容器 + DESIGN §7.5 #6 重写(物理边界替代代码护栏)
Ubuntu dogfood 暴露 host 工具漏底:base_dir=Path.cwd() 无 user_root 校验,
模型 glob "*" 列出 host /home/lighthouse/zcbot/.git/.venv/... zcbot 源码自身。
DESIGN §7.5 #6 原写"host 工具走 paths.py::resolve_user_path 校验"是假命题
(代码里没那函数),绝对路径完全不挡。

修法:fs 工具(read/write/edit/glob/grep)也走 docker exec,物理边界替代
代码护栏(Phase B path validator 那条不做 ── 脆弱)。

- core/sandbox/tool_runner.py 新增:容器内 helper,stdin 接 JSON args,
  调 tools/fs.py 的 Tool 子类;base_dir=cwd,user_root=/workspace
- DockerExecutor 加 FS_TOOLS 信任域 + _exec_fs_tool:docker exec -i ...
  python /sandbox/tool_runner.py <name>,stdin 喂 JSON args(CJK / 引号
  透明传不被 shell metachar 切)
- _run_subprocess 加 stdin 参数 + is_fs_tool 分支返 stdout 直透(原 Tool
  返回串语义保持),exit≠0 stderr 当 ToolResult content
- SandboxPool 加 repo_root 字段 + <repo>/skills:/sandbox/skills:ro mount
  让容器内 read SKILL references 能解析
- Dockerfile COPY tools/ /sandbox/tools/ + tool_runner.py(build-time COPY
  而非 mount ── 容器内代码不应跟随 host repo 改动)
- web/app.py 透传 ROOT 给 init_pool
- 留 host 的工具:load_skill(SkillRegistry 内存查找)/ web_search /
  web_fetch / seedream / seedance(持 Bocha/ARK key 不入容器)
- DESIGN §7.5 #6 重写:"几乎所有工具进容器,host 只留持 key + 跨 user 的",
  原假命题溯源标注 2026-05-26 修正

代价:每 fs tool call +~200ms docker exec overhead,对话级 N≤15 总 1-3s,
LLM 推理 5-30s 下噪声。升级触发(§7.9 升级表)docker exec → unix socket RPC
仍按原信号(overhead/total > 30% 持续 / 长驻服务工作流)。

测试:test_executor_docker 加 4 fs 路径测试(argv 形态 / CJK stdin JSON /
exit≠0 stderr 透传 / timeout);改原 read 直通测试 → load_skill 直通
(read 现在进容器)。unittest discover 35/35 PASS。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 21:56:41 +08:00
config Add web_search and web_fetch tools via Bocha AI search API 2026-05-25 11:37:33 +08:00
core Stage C Step 3d: fs 工具进容器 + DESIGN §7.5 #6 重写(物理边界替代代码护栏) 2026-05-26 21:56:41 +08:00
db/migrations feat(media): 接入豆包 Seedream 5.0 图像生成 tool + 0007 cost_usd→cost_cny 全表统一币种 2026-05-20 15:20:34 +08:00
deploy/sandbox Stage C Step 3d: fs 工具进容器 + DESIGN §7.5 #6 重写(物理边界替代代码护栏) 2026-05-26 21:56:41 +08:00
prompts/system feat(paths): 对外路径统一全形式 <wd_name>/<rel> + UI 一次性兼容历史简写 2026-05-22 12:45:54 +08:00
scripts feat(seedance): 加 seedance_2_pro variant + smoke 支持 --variant 参数 2026-05-22 10:11:31 +08:00
skills Stage C Step 3 hotfix: exec_user 跟随 build_arg + 镜像装 mermaid-cli 2026-05-26 21:47:33 +08:00
tests Stage C Step 3d: fs 工具进容器 + DESIGN §7.5 #6 重写(物理边界替代代码护栏) 2026-05-26 21:56:41 +08:00
tools Add web_search and web_fetch tools via Bocha AI search API 2026-05-25 11:37:33 +08:00
web Stage C Step 3d: fs 工具进容器 + DESIGN §7.5 #6 重写(物理边界替代代码护栏) 2026-05-26 21:56:41 +08:00
.gitattributes Add .gitattributes: force LF for shell + Dockerfile 2026-05-26 10:45:17 +08:00
.gitignore skills+core(命名约定): task 级宪法文件 <date>-<short_id>-<name>.spec.md + spec_lock → spec 简化 2026-05-20 14:03:21 +08:00
CLAUDE.md ui(media): tool 结果与 assistant 正文同路径 chip/inline 图去重 — Set O(n) + CLAUDE.md 加 "实施前先对方案" 段 2026-05-20 16:33:47 +08:00
DESIGN.md Stage C Step 3d: fs 工具进容器 + DESIGN §7.5 #6 重写(物理边界替代代码护栏) 2026-05-26 21:56:41 +08:00
DOCUMENT_SEARCH_API.md feat(skill): documents skill 接内部材料学科知识库(document_search API) 2026-05-21 15:31:21 +08:00
EMBED.md feat(web): embed 模式接受 ?task_id=<uuid> URL 参数自动定位 task 2026-05-22 15:27:19 +08:00
PROGRESS.md Stage C Step 3d: fs 工具进容器 + DESIGN §7.5 #6 重写(物理边界替代代码护栏) 2026-05-26 21:56:41 +08:00
RUN.md Stage C Step 3 hotfix: exec_user 跟随 build_arg + 镜像装 mermaid-cli 2026-05-26 21:47:33 +08:00
alembic.ini core(§7 B Step 1): Storage 基建 — SQLAlchemy ORM + alembic + db CLI 2026-05-14 10:41:44 +08:00
main.py Stage C Step 5: main.py sandbox check + lifespan fs quota WARN 2026-05-26 16:41:16 +08:00
requirements.txt Add web_search and web_fetch tools via Bocha AI search API 2026-05-25 11:37:33 +08:00