MiMo-Code icon indicating copy to clipboard operation
MiMo-Code copied to clipboard

feat(config): add an option to disable the isolated git guard(建议为隔离子会话 git 防护增加配置开关)

Open jiaxuan1101 opened this issue 2 months ago • 0 comments

## 中文

背景

isolated-git-guard(packages/opencode/src/tool/isolated-git-guard.ts)对隔离子会话拦截 merge / ebase / ranch -f / push --force 等跨分支 git 操作,防止子会话意外移动共享 ref store——这个默认保护本身很有价值,注释里对威胁模型的分析也很到位。

问题

调用点(packages/opencode/src/tool/bash.ts 中的 if (IsolatedGit.isIsolatedWorktree(own)))是硬编码的,packages/opencode/src/config/config.ts 的 schema 里没有对应的开关键。当用户明确把分支集成工作委派给子会话时(例如让子代理解决自己仓库的 PR 冲突、执行 rebase),防护没有任何逃生通道:

  • 子代理无法执行 git merge / git rebase / git branch -D 等操作,即使操作对象是用户自己的、与主工作区完全无关的独立仓库
  • 只能用 cherry-pick 等迂回方式模拟合并(在目标基线上新建分支 → cherry-pick → force-with-lease 推送),流程受限且对多提交场景很不自然

实测场景

让子代理解决一个真实 PR 的上游冲突:需要把功能分支变基到上游最新 main。由于防护拦截,最终只能改为"从上游 main 建新分支 + cherry-pick 原提交 + 解决冲突 + force-with-lease 推送"的方式完成。功能上达成了,但如果冲突更复杂(跨多个提交、需要 merge 而非 rebase 语义),这个绕法就不够用了。

建议

在配置中新增 git_guard 键,默认 rue 保持现状:

jsonc { // 关闭隔离子会话的跨分支 git 防护(默认 true) "git_guard": false }

实现上只需让 bash.ts 的调用点读取该配置:

s if (cfg.git_guard !== false && IsolatedGit.isIsolatedWorktree(own)) { IsolatedGit.assertIsolatedGitAllowed({ ... }) }

可选增强:支持按子命令的白名单粒度(如只放行 merge/ ebase),但布尔开关已覆盖绝大多数需求。


English

Background

isolated-git-guard (packages/opencode/src/tool/isolated-git-guard.ts) blocks cross-branch git operations (merge / ebase / ranch -f / push --force, ...) from isolated child sessions to protect the shared ref store. The default protection is valuable, and the threat-model analysis in the comments is excellent.

Problem

The call site (if (IsolatedGit.isIsolatedWorktree(own)) in packages/opencode/src/tool/bash.ts) is hardcoded — the config schema (packages/opencode/src/config/config.ts) has no switch for it. When the user explicitly delegates branch integration to a child session (e.g. resolving a PR conflict, running a rebase on their own repository), there is no escape hatch:

  • The child cannot run git merge / git rebase / git branch -D, even when the target is the user's own repository entirely unrelated to the parent checkout
  • The only workaround is emulating a merge via cherry-pick (new branch from the target base → cherry-pick → resolve → force-with-lease push), which is unnatural for multi-commit or merge-semantics cases

Suggestion

Add a git_guard config key, defaulting to rue to preserve current behavior:

jsonc { // Disable the cross-branch git guard for isolated child sessions (default true) "git_guard": false }

Implementation is a one-liner at the call site:

s if (cfg.git_guard !== false && IsolatedGit.isIsolatedWorktree(own)) { IsolatedGit.assertIsolatedGitAllowed({ ... }) }

Optional enhancement: per-subcommand allowlist granularity, but a boolean switch already covers most needs.

jiaxuan1101 avatar Sep 07 '26 09:09 jiaxuan1101