基于实体的、感知语言的合并算法:Weave
Weave – A language aware merge algorithm based on entities

原始链接: https://github.com/Ataraxy-Labs/weave

## Weave:更智能的 Git 合并,具备语义理解 Weave 是一款旨在解决 Git 合并冲突的工具,这些冲突源于误报——即使更改位于文件的独立部分(在并发开发中很常见,尤其是在使用 AI 代理时),Git 也会因基于行的差异而标记冲突的情况。 Weave 不比较行,而是利用 tree-sitter 将代码解析为语义实体,如函数和类。然后,它基于这些实体进行合并:独立更改会自动解决,对*相同*实体的修改会触发集中的冲突解决,删除/修改会被清晰标记。 在主要开源仓库(Git、Flask、CPython、Go、TypeScript)中的测试表明,Weave 显著减少了手动冲突解决——解决了 Git 无法解决的 6-64% 的冲突,*且*没有引入错误。当冲突*确实*发生时,Weave 会提供清晰的上下文,识别特定的冲突实体。 Weave 通过自定义合并驱动程序与 Git 无缝集成,并支持 TypeScript、Python、Go 等语言,对于不支持的类型则回退到基于行的合并。它作为一个 CLI 工具提供,并具有预览功能,可以在提交之前查看合并结果。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Weave – 一种基于实体的、感知语言的合并算法 (github.com/ataraxy-labs) 12 分,rs545837 1小时前 | 隐藏 | 过去 | 收藏 | 3 评论 帮助 kelseydh 1分钟前 | 下一个 [–] 很酷,希望看到 Ruby 支持的加入。回复 sea-gold 1小时前 | 上一个 | 下一个 [–] 网站:https://ataraxy-labs.github.io/weave/ 我还没试过,但听起来对我来说很有价值。回复 esafak 18分钟前 | 上一个 | 下一个 [–] 代理是否能很好地使用它?回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

weave

Resolves merge conflicts that Git can't by understanding code structure via tree-sitter.

Release Homebrew Rust Tests Version License Languages

Git merges by comparing lines. When two branches both add code to the same file — even to completely different functions — Git sees overlapping line ranges and declares a conflict:

<<<<<<< HEAD
export function validateToken(token: string): boolean {
    return token.length > 0 && token.startsWith("sk-");
}
=======
export function formatDate(date: Date): string {
    return date.toISOString().split('T')[0];
}
>>>>>>> feature-branch

These are completely independent changes. There's no real conflict. But someone has to manually resolve it anyway.

This happens constantly when multiple AI agents work on the same codebase. Agent A adds a function, Agent B adds a different function to the same file, and Git halts everything for a human to intervene.

Weave replaces Git's line-based merge with entity-level merge. Instead of diffing lines, it:

  1. Parses all three versions (base, ours, theirs) into semantic entities — functions, classes, JSON keys, etc. — using tree-sitter
  2. Matches entities across versions by identity (name + type + scope)
  3. Merges at the entity level:
    • Different entities changed → auto-resolved, no conflict
    • Same entity changed by both → attempts intra-entity merge, conflicts only if truly incompatible
    • One side modifies, other deletes → flags a meaningful conflict

The same scenario above? Weave merges it cleanly with zero conflicts — both functions end up in the output.

Scenario Git (line-based) Weave (entity-level)
Two agents add different functions to same file CONFLICT Auto-resolved
Agent A modifies foo(), Agent B adds bar() CONFLICT (adjacent lines) Auto-resolved
Both agents modify the same function differently CONFLICT CONFLICT (with entity-level context)
One agent modifies, other deletes same function CONFLICT (cryptic diff) CONFLICT: function 'validateToken' (modified in ours, deleted in theirs)
Both agents add identical function CONFLICT Auto-resolved (identical content detected)
Different JSON keys modified CONFLICT Auto-resolved

The key difference: Git produces false conflicts on independent changes because they happen to be in the same file. Weave only conflicts on actual semantic collisions when two branches change the same entity incompatibly.

Tested on real merge commits from major open-source repositories. For each merge commit, we replay the merge with both Git and Weave, then compare against the human-authored result.

  • Wins: Merge commits where Git conflicted but Weave resolved cleanly
  • Regressions: Cases where Weave introduced errors (0 across all repos)
  • Human Match: How often Weave's output exactly matches what the human wrote
  • Resolution Rate: Percentage of all merge commits Weave resolved vs total attempted
Repository Language Merge Commits Wins Regressions Human Match Resolution
git/git C 1319 39 0 64% 13%
Flask Python 56 14 0 57% 54%
CPython C/Python 256 7 0 29% 13%
Go Go 1247 19 0 58% 28%
TypeScript TypeScript 2000 65 0 6% 23%

Zero regressions across all repositories. Every "win" is a place where a developer had to manually resolve a false conflict that Weave handles automatically.

When a real conflict occurs, weave gives you context that Git doesn't:

<<<<<<< ours — function `process` (both modified)
export function process(data: any) {
    return JSON.stringify(data);
}
=======
export function process(data: any) {
    return data.toUpperCase();
}
>>>>>>> theirs — function `process` (both modified)

You immediately know: what entity conflicted, what type it is, and why it conflicted.

TypeScript, JavaScript, Python, Go, Rust, JSON, YAML, TOML, Markdown. Falls back to standard line-level merge for unsupported file types.

# Build
cargo build --release

# In your repo:
./target/release/weave-cli setup

# Or manually:
git config merge.weave.name "Entity-level semantic merge"
git config merge.weave.driver "/path/to/weave-driver %O %A %B %L %P"
echo "*.ts *.tsx *.js *.py *.go *.rs *.json *.yaml *.toml *.md merge=weave" >> .gitattributes

Then use Git normally. git merge will use weave automatically for configured file types.

Dry-run a merge to see what weave would do:

weave-cli preview feature-branch
  src/utils.ts — auto-resolved
    unchanged: 2, added-ours: 1, added-theirs: 1
  src/api.ts — 1 conflict(s)
    ✗ function `process`: both modified

✓ Merge would be clean (1 file(s) auto-resolved by weave)
weave-core       # Library: entity extraction, 3-way merge algorithm, reconstruction
weave-driver     # Git merge driver binary (called by git via %O %A %B %L %P)
weave-cli        # CLI: `weave setup` and `weave preview`

Uses sem-core for entity extraction via tree-sitter grammars.

         base
        /    \
     ours    theirs
        \    /
       weave merge
  1. Parse all three versions into semantic entities via tree-sitter
  2. Extract regions — alternating entity and interstitial (imports, whitespace) segments
  3. Match entities across versions by ID (file:type:name:parent)
  4. Resolve each entity: one-side-only changes win, both-changed attempts intra-entity 3-way merge
  5. Reconstruct file from merged regions, preserving ours-side ordering
  6. Fallback to line-level merge for files >1MB, binary files, or unsupported types
联系我们 contact @ memedata.com