Skip to content

Plan Mode:原始 git diff/show 可通过仓库配置执行外部程序 #70

Closed

Description

@tt-a1i

维护者范围决定(2026-08-24)

本 Issue 精确收窄为 Plan Mode 的 diff-driver 执行边界:查看差异时不得因为仓库配置的 diff.external 或 textconv driver 而启动外部程序。

本 Issue 不建设通用 hostile Git configuration 沙箱。core.fsmonitor、pager,以及其他允许的 Git 调研命令仍属于 Pi 已有的 Project Trust 边界。OpenPI 只对已经复现、位于常用 diff 路径、且能通过现有结构化工具低成本封堵的 seam 落实运行时保证。

问题

当前 Plan Mode 为了允许只读调查,在 Bash 白名单中开放了原始 git diff 与 git show。

但 Git 会读取仓库配置:

  • diff.external 可以让 git diff 执行外部程序;
  • textconv driver 可以在生成 diff 时执行外部程序。

因此,“命令名和参数看起来只读”并不等于 diff 生成过程不会启动外部程序。模型无法可靠观察或记住这个隐藏执行边界,安全参数应由 Runtime 确定性落实。

当前证据

基于创建 Issue 时的 main@22e77d6:

  • extensions/plan-mode/bash-policy.ts 允许原始 git diff / git show;
  • --no-ext-diff 只是可选允许参数,不会被运行时强制加入;
  • 结构化 git_diff / git_show 已在 extensions/git-read/src/args.ts 固定加入 --no-ext-diff --no-textconv --no-color。

仓库已经有安全 argv 构造能力,但 Plan Mode 的原始 Bash diff 入口可以绕过它。

期望

  1. Plan Mode 的差异查看使用结构化 git_diff / git_show;
  2. 原始 Bash 中会进入 diff machinery 的 git diff、git show、git whatchanged 和对应 git log 形式被拒绝;
  3. 不依赖模型自行补 --no-ext-diff --no-textconv;
  4. 普通模式与非 diff Git 调研继续遵循现有 Project Trust 边界。

验收标准

  • 在临时仓库配置 diff.external 后,Plan Mode 通过结构化工具查看差异不会执行该 helper;
  • textconv driver 同样不会被调用;
  • 普通 staged/worktree/revision/path diff 仍可使用;
  • 测试证明实际传给 Git 的 argv 含 --no-ext-diff --no-textconv --no-color;
  • 原始 Bash diff-producing 形式 fail-closed,并给出结构化替代入口;
  • Plan Mode 文档和 threat model 明确说明该保证只覆盖 diff-driver seam,其余 Git 调研仍位于 Project Trust 边界;
  • bun run check 与 bun run test 通过,并完成真实 Plan Mode 工具接线 smoke。

非目标

  • 隔离任意 hostile Git configuration;
  • 为 core.fsmonitor、pager 或所有 Git 子命令建立第二套安全沙箱;
  • 改变普通模式的 Git 行为;
  • 依赖提示词要求模型每次手工补安全参数。

来源说明

该问题最早来自一次基于 v0.3.0 旧分支的审计;创建 Issue 时已在当时最新 main 上重新复现。后续评审确认宽泛的 hostile-config 合同会把 OpenPI 推向通用 Git 沙箱,因此按上述边界收窄。

Activity

  1. added
    bug
    on Aug 22, 2026
  2. CuSO41108 commented on Aug 23, 2026

    @CuSO41108
    Contributor

    I’d like to work on this. I plan to add hostile diff.external/textconv regressions first, then make Plan Mode use the existing structured git_diff/git_show safety boundary while preserving normal diff workflows. I’ll keep the change scoped and run the focused tests plus bun run check and bun run test.

  3. tt-a1i commented on Aug 24, 2026

    @tt-a1i
    CollaboratorAuthor

    维护者范围决定

    经过对 #70、PR #91 和 Project Trust 边界的重新评审,本 Issue 已收窄为已经复现的 diff.external / textconv seam,不再要求 PR 抵御 core.fsmonitor 或任意 hostile Git configuration。

    原因:模型无法观察 Git 在 diff machinery 内隐式启动的 helper,这一小块应由 Runtime 通过现有结构化工具确定性兜底;继续扩展为通用 Git 配置隔离则会越过 OpenPI 的最小能力层定位。

    PR #91 的总体方向与收窄后的合同一致。此前关于 core.fsmonitor 的 changes-requested finding 按新合同不再是 blocker;接下来会继续核对工具面是否为最小必要集合、完成最新 main 本地门禁与真实 Plan Mode smoke,并在 GitHub CI 通过后更新 review。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions