Skip to content

feat(git): typed 本地 Git 写工作流与变更审阅 - #80

Merged
Qiyuanqiii merged 2 commits into
mainfrom
codex/issue-44-git-write-workflow
Aug 16, 2026
Merged

Qiyuanqiii merged 2 commits into
mainfrom
codex/issue-44-git-write-workflow

Conversation

@Qiyuanqiii

Copy link
Copy Markdown
Member

背景

Issue #44(Parent #34):Repository 读取已存在,但没有 Go 拥有的 Git mutation service;模型不能拼接任意 git 命令,写操作必须在执行前后都能被审阅。

本次改动

  • 封闭 typed 操作集(internal/repository/mutation.go,repository_mutation.v1):stage/unstage/commit/create_branch/switch_branch。协议层面不可表达 reset --hard、clean -fdx、force checkout、rebase、历史重写;未知操作直接拒绝;路径仅接受规范化相对路径(拒绝 ..、前导 -、反斜杠、绝对路径),分支名独立校验。
  • 硬化执行边界:真实 git 二进制 + 全替换环境——GIT_CONFIG_NOSYSTEM=1、GIT_CONFIG_GLOBAL=devnull、core.hooksPath 指向空目录、pager=cat、editor=false、diff.external 与 credential.helper 置空、fsmonitor=false、GIT_LFS_SKIP_SMUDGE=1、core.autocrlf=false、--no-optional-locks、--literal-pathspecs;绝不继承 Agent 环境;argv 由固定模板生成(模型不能拼接任意 git 命令)。
  • 绑定审阅与回读:绑定指纹 = HEAD + branch + index 字节哈希 + 排序 porcelain status + 未跟踪文件内容哈希;执行前校验未漂移,漂移即拒绝并要求重新审阅。commit 用 pathspec 限定已审阅路径(新增变化不混入);执行后回读 HEAD/status/冲突,非零退出码即失败。
  • 台账与事件:schema v106 git_mutation_operations(operation key 幂等、request_fingerprint 绑定 Run/Workspace/绑定状态、receipt 收据);Complete 时追加 metadata-only run 事件 git.mutation_completed。
  • CLI:cyberagent git-op 五操作——先打印审阅(文件清单/diff stat/target branch/commit message),--confirm 后执行并打印收据。

测试覆盖

  • repository 层:stage/unstage/commit 生命周期、陈旧审阅拒绝(含未跟踪文件内容漂移)、切分支冲突、恶意 pre-commit hook 不执行、路径逃逸/危险操作/非法分支名、Unicode+空格路径、create/switch branch。
  • application 层(真实 store + 真实 repo):commit 端到端、operation key 幂等重放、git.mutation_completed 事件落库、陈旧审阅端到端拒绝。

验证结果

  • go build ./...、go vet ./... 通过;全量 go test -timeout 30m ./... 进行中。

安全边界与非目标

  • 仓库内 .gitconfig/hooks/attributes/filters/文件内容都是不可信输入,不成为执行权来源;无 push/pull/fetch/PR、无历史重写。
  • 后续 PR(ADR 0108 已记录):Desktop 右侧审阅面板(unified diff、行级增删、二进制说明)与 HTTP/OpenAPI。

Closes #44

repository_mutation.v1:stage/unstage/commit/create_branch/switch_branch 五个封闭操作,无任意 git argv。

执行边界:真实 git 二进制 + 硬化环境(GIT_CONFIG_NOSYSTEM/GLOBAL 忽略、hooksPath 指向空目录、pager/editor/external diff/credential helper/filter 全禁用、core.autocrlf=false、--no-optional-locks/--literal-pathspecs),绝不继承 Agent 环境。

审阅绑定:HEAD + branch + index 字节哈希 + 排序 porcelain status + 未跟踪文件内容哈希合成指纹;执行前校验绑定未漂移,漂移即拒绝并要求重新审阅(陈旧审阅无法执行)。commit 用 pathspec 限定已审阅路径,新增变化不会混入;执行后回读 HEAD/status/冲突,非零退出码即失败。

测试:stage/unstage/commit 生命周期、陈旧审阅拒绝、切分支冲突拒绝、恶意 pre-commit hook 不执行、路径逃逸/危险操作/非法分支名拒绝、Unicode+空格路径、create/switch branch。
schema v106 git_mutation_operations:operation key 幂等、request_fingerprint 绑定 Run/Workspace/绑定状态、receipt(post_head/commit_id/branch/conflicted/clean/bounded stderr)。CompleteGitMutationOperation 追加 metadata-only run 事件 git.mutation_completed。

GitMutationService:Review(解析 Workspace root → 绑定状态 + 文件清单 + 有界 diff stat)→ Execute(重校验绑定 → typed 执行 → 台账 + 事件)。CLI cyberagent git-op 五操作,先打印审阅、--confirm 后执行、打印收据。端到端测试:真实 store + 真实 repo(commit、幂等重放、事件落库、陈旧审阅端到端拒绝)。ADR 0108 与 usage 文档。
@Qiyuanqiii
Qiyuanqiii force-pushed the codex/issue-44-git-write-workflow branch from 89e2f38 to aa9b10d Compare August 16, 2026 07:23
@Qiyuanqiii
Qiyuanqiii merged commit 791c117 into main Aug 16, 2026
5 checks passed
@Qiyuanqiii
Qiyuanqiii deleted the codex/issue-44-git-write-workflow branch August 16, 2026 08:09
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.

feat(git): 本地 Git 写工作流与变更审阅

1 participant