提交历史重构工具

unsquash是一款将混乱的提交历史重写为干净、可审查序列的MCP工具,适用于代码审查和版本控制优化场景。

  • by lambdasistemi
  • Clojure
  • 本地部署
  • 更新于
在 GitHub 查看 lambdasistemi/unsquash

使用说明

unsquash

MCP工具,将混乱的提交历史重写为干净、可审查的序列。

它做什么

给定一个混乱的PR(WIP提交、修复、来回)或一个压缩的提交,unsquash会产生一个逻辑有序的提交序列,其中每个提交都是独立编译的。

两个阶段:

  1. 巩固 --智能南瓜相关的提交保持顺序(提交+修复,WIP噪声)。原始提交边界携带意图信号——永远不要先挤压一切。
  2. 展开 --通过构建大块的依赖图、将共同发生的更改收缩为原子单位以及计算有效的拓扑顺序来分解大型提交。

三层边缘发现:

  1. 预检 --机械规则(R1-R12)在没有LLM的情况下检测到明显的关系
  2. LLM确认 --验证适度置信度飞行前边缘
  3. LLM发现 --对剩余大块进行迭代细化,稳定后收敛

编译预言机验证每一步。用户从有效的顺序中选择提交叙述。

堆栈

  • 巴巴什卡 --编排、差异解析、图构建、git操作
  • LLM-CLI (可插拔)——语义边缘发现、提交分组、中间状态综合
  • 编译oracle (可插拔)--每种语言的构建验证(GHC、cargo、go、tsc等)

发展

nix develop                    # enter dev shell (babashka, git, just, stgit)
just ci                        # run full CI pipeline
just test                      # run tests
cp unsquash.example.edn unsquash.edn  # configure oracle + LLM

用法

命令行界面

# Analyze a single commit — build dependency graph
bb analyze --ref HEAD --oracle "cabal build all -O0" --llm "llm chat -m claude-sonnet"

# Analyze with patience diff algorithm for better hunk boundaries
bb analyze --ref HEAD --diff-algorithm patience

# Propose orderings — show valid topological sorts with narratives
bb propose --max 3

# Apply chosen ordering — create commits validated by oracle
bb apply --ordering 0

# Consolidate messy commit range (full two-phase)
bb consolidate --ref main..feature --llm "llm chat -m claude-sonnet"

MCP服务器(克劳德代码集成)

添加到MCP配置中:

{
  "mcpServers": {
    "unsquash": {
      "command": "nix",
      "args": ["develop", "--quiet", "--command", "bb", "mcp"],
      "cwd": "/path/to/unsquash"
    }
  }
}

可用工具: unsquash-analyze, unsquash-propose, unsquash-apply, unsquash-consolidate.

配置

复制 unsquash.example.edn 到 unsquash.edn:

{:oracle {:command "cabal build all -O0"    ;; compile oracle command
          :timeout 120}                      ;; timeout in seconds
 :llm {:command "llm chat -m claude-sonnet"} ;; LLM CLI command
 :diff {:algorithm "patience"                ;; patience | histogram | myers
        :split-at-blank-lines true}          ;; split hunks at blank lines
 :max-rounds 4                               ;; LLM refinement rounds
 :max-orderings 3}                           ;; topological sorts to compute

文档