Mergetrain
io.github.yongjip由 GitHub 帳號 yongjip 發布v3.7.1更新於 Oct 26, 2026
Queue parallel-agent worktree branches, test together, serialize and recover Git pushes.
概覽
針對平行編碼代理的本地合併佇列:讓助理把已提交的 Git worktree 分支排入佇列、執行組合閘門,並經一次核准的原子推送落地。
- 可以做什麼
- 把代理 worktree 中已提交的工作分支加入持久化本地佇列
- 檢視佇列與列車狀態,取得下一步安全指令與作業層級證據
- 在合併結果上執行設定的閘門,驗證組裝好的列車
- 把已核准的列車以一次原子 Git 參照更新部署,並驗證推送結果
- 推送中斷或結果不確定時,以本地紀錄與遠端參照核對來復原
- 適用情境
- 當多個編碼代理在同一個本地儲存庫產出分支,且合併結果必須先通過本地測試才能落地時使用。適合以 worktree 為先的本地代理整合;以 PR 為主且已有平台原生合併佇列的團隊,或一次只落地一個分支的情況,通常不需要。
- 執行需求
- 以 Python CLI 形式在本機執行,可用 uv tool、pipx 或 Homebrew 安裝,並以固定版本的 MCP 伺服器接入用戶端。需要一個以 mergetrain init 初始化的 Git 儲存庫、在 .mergetrain.yaml 中至少設定一個閘門指令,以及用於推送的 Git 遠端。不需帳號、OAuth 應用,也未宣告環境變數。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Mergetrain,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
mergetrain
[CI] [PyPI] [Python] [License: MIT]
Safely integrate committed branches from parallel coding agents.
mergetrain is a local merge queue for parallel LLM agents. These coding agents use large language models and work in Git worktrees. mergetrain runs on your machine. A train is a group of queued task branches. A gate is a configured test or check. Each agent commits and enqueues its branch. One runner merges branches in enqueue order and runs gates on the combined result. It updates your Git refs atomically only after explicit approval.
mergetrain is designed for one operator managing local repositories.
There is no mergetrain account, hosted control plane, OAuth app, or product telemetry. Queue and runner state stay on your machine. Only your configured Git remote and trusted gate or verification commands may contact external services.
Keep building through the fix
Default batch mode: passing work lands first. Work that needs a fix returns to its agent. Passing work can land while the repair continues.
Keep building during checks. Agents start their next task while mergetrain checks earlier work. This 14-second loop keeps the same four agents in view.
Agents can keep building in both modes. In ordered mode, an unresolved earlier submission holds later landings. Compare the two modes.
Pause or replay the demo · View the still image · Reproduce the continuous workflow
How this demo was made
This illustration follows recorded CLI results. The four lanes represent agent roles; letters identify work, not queue job IDs. The capture scripts agent-authored changes and operator approvals in a disposable local repository and bare remote. It does not launch an AI service.
Two fixture gate waits make the overlaps reproducible: E and F are committed during A and B validation, then G and H drafts start during E and F validation. All three deployments retain approval and the default recheck. A fresh clone of the final remote passes six tests.
G and H then refresh onto that result without losing their edits. I and J start there too. These four drafts remain unsubmitted. Your agents or operator create, fix, refresh and resubmit work; mergetrain checks and integrates it. The 14-second animation repeats this recorded window with condensed timing.
The problem
Worktrees let several agents edit one repository without sharing a checkout. They do not decide landing order, test the combined result, prevent push races, or tell you what happened if a laptop dies mid-push.
Without a shared integration workflow, the operator chooses branch order and resolves cross-branch failures. The operator also reruns tests and controls pushes. Repeating these actions can slow parallel work.
mergetrain records this workflow in a durable local queue:
Who should use it?
Use mergetrain when:
- multiple coding agents finish branches in the same repository throughout the day;
- agents work in Git worktrees and should enqueue rather than push deploy refs;
- the combined result must pass local tests before it lands;
- you want unattended processing only for explicitly pre-approved jobs; or
- one local hub should show queues and runners across several repositories.
It is harness-agnostic: Codex, Claude Code, agy, scripts, and humans all use the same CLI and JSON contract.
Running several Claude Code or Codex sessions on one laptop? The one-laptop guide covers worktrees, unattended landing, heavy gates, sleep and quiet periods, a push guard, and outcome reports, each tested in disposable repositories.
Who should not use it?
You probably do not need mergetrain when:
- one person or agent lands one branch at a time;
- every change already goes through a PR and your forge-native merge queue;
- you need a hosted review UI, organization-wide permission system, or remote runner service; or
- you are looking for a general job queue, CI provider, or deployment platform.
For PR-first teams, use GitHub Merge Queue or GitLab Merge Trains. mergetrain is for local-agent, worktree-first integration, with or before a PR.
Batch by default; ordered when needed
Start with batch, the default. It suits independent work from parallel
agents. The runner combines the queued work available when it starts; it does
not wait for every agent to finish. Compatible work can land while an agent
repairs a failed submission.
Use ordered when each change needs its own landing and the original
submission order must survive a failure and retry.
Both modes let agents start their next task after handoff. Both keep deploy approval and the default pre-push recheck. Ordered processing can run checks more often because each submission lands separately. Queue order starts at submission, not when an agent starts work, and does not express code dependencies. Order ends at a successful Git landing. Post-push verification warnings remain visible while later work proceeds; an uncertain push still requires reconciliation.
Availability: ordered is available in 3.6.0 and newer.
Keep the default batch for ordinary parallel agent work.
See the agent work examples,
configuration, and upgrade procedure.
Enforcement boundary
Lease tokens fence concurrent and stale mergetrain runners. They do not
intercept an arbitrary git push from a task agent that has shell access and an
integration-branch credential. To make “one runner owns the push” an enforced
property rather than a protocol assumption, use this topology:
Without credential separation and remote protection, mergetrain still provides safe train assembly and recovery semantics, but it cannot prevent a participant from bypassing the queue. See the security boundary.
Run the real demo
The demo creates a disposable repository and local bare remote, then runs four
real branches through merges in enqueue order, a combined-only gate failure,
conflict attribution, and deployment of the compatible train. Use --keep to
inspect the result afterward. Add --brief --pause to read each step before
continuing. The extended workflow recording
adds repair, work committed during validation, the next batch, and three verified
local deployments.
Full CLI recording
Install and first run
For VS Code / GitHub Copilot or direct MCP setup, see the MCP installation and deployment-confirmation guide.
Initialize the repository:
Add at least one project gate to .mergetrain.yaml. A new configuration has
gates: [], so it runs no project tests. For a Python project that uses pytest:
Use test commands for your project. Gates must leave the assembled checkout
unchanged. init also creates AGENTS.mergetrain.md and
CLAUDE.mergetrain.md. Link them from your existing AGENTS.md or CLAUDE.md.
Commit and land the configuration and instructions through your normal
integration path before creating task worktrees.
After the task agent commits a clean branch in its own worktree:
The task agent stops after enqueueing. From the operator checkout, run these commands when validation and deployment are authorized:
For long-running gates, run mergetrain validate earlier; it never pushes and
leaves one exact train Ready for the later deploy confirmation.
deploy names the configured atomic Git ref update; it does not imply an App
Store, Kubernetes, or other provider release.
Agents commit and enqueue. One runner owns merge → test → push → verify.
Unattended daemons process only jobs that a human explicitly enqueued with
--auto. For manual jobs, daemon --validate-only can run merge and gates in
the background, but it pauses at the validated-train approval boundary and
never pushes.
See the quickstart for configuration, daemon, and multi-repository Hub setup.
Integrating parallel Claude Code sessions and Codex worktrees
Use a Git worktree merge queue when parallel Claude Code sessions or parallel Codex worktrees produce committed branches in the same repository. The plugin install guide connects either client to the queue. Task agents commit, enqueue, and stop. A separately authorized runner tests the combined branches and handles the push.
For Orca-managed worktrees, see the Orca setup and queue guide for tested terminal commands, shared queue behavior, validation, and repair. The Orca agent guide adds native Codex, Claude Code, and agy plugin setup and bounded task/validation prompts.
Why not just worktrees and git merge?
Worktrees solve parallel editing. mergetrain solves serialized integration.
Agents keep their separate worktrees. One mergetrain runner integrates their committed results.
Why not GitHub or GitLab merge queues?
They solve a related problem for a different operating model.
The models can coexist: push a validated train to a review branch and open one PR, or reserve individual PRs for changes that need discussion. The PR workflow guide covers direct, one-PR, split-PR, and validation-only patterns.
Recovering an interrupted Git push
A stopped or timed-out Git push does not prove whether the remote accepted the
update. mergetrain records deployment evidence. Its recovery procedure checks
remote refs before another attempt. Start with mergetrain status --json and
follow the reported recovery action and its approval requirement. See the
recovery guide.
Core safety guarantees
- Exact train identity. Approval names the task HEADs and integration base; changed branches or a moved base cannot silently reuse that approval.
- Combined gates before push. A green branch is not enough. The assembled train passes the configured gates, or nothing lands.
- One fenced mergetrain owner. SQLite claims and lease tokens prevent concurrent or stale mergetrain runners from mutating the same train; remote enforcement additionally requires the credential topology above.
- Atomic remote update. Payload refs and a permanent
refs/mergetrain/deploys/<sha>recovery ref update together. - Remote-truth recovery. Write-ahead markers and pinned commits let
reconciledetermine whether a killed push landed, without replaying a successful deploy or calling a missing one shipped. - Explicit automation. A bare run never deploys. Daemons touch only
pre-approved
--autojobs whose destination and gate/reuse/verify policy still match, and MCP deploy still requires attributable human confirmation. - One state entry point.
statusprojects internal detail into Waiting, Running, Ready, Attention, and Done, and returns the next safe command.inspectsupplies job-level evidence only when it is needed.
Queue state, locking, train assembly, and gates stay local. Your configured Git remote and post-push verification may still use external services. Gate and verify commands are trusted code; review the security boundary before enabling unattended jobs.
These guarantees are exercised on macOS and Linux across Python 3.10–3.14 and
on Windows, including real-Git fault injection around git push --atomic. A
dedicated soak repository completed 20 landed trains at a 100% land rate,
including planned conflict recovery and a real killed-push reconciliation whose
verdict matched the remote. See the
soak evidence,
then use mergetrain stats --json to inspect evidence from your own queue.
Go deeper
- Start: Quickstart · Install · CLI · Config
- Understand: Design and architecture · Machine contract · PR workflow comparison
- Operate: Efficient operation · Failure modes and recovery · Upgrades · Daemon · Multi-repo Hub
- Trust and extend: Security · Agent contract · Agent adoption benchmark · Product-name-free discovery benchmark · Local multi-agent benchmark · MCP server · Adapter pattern · Product scope
Stable interface
The normal CLI is deliberately limited to six verbs:
Version 3 is the long-lived product grammar. There is no planned v4: new capabilities must fit these verbs or stay in advanced operator surfaces, and the v3 JSON and MCP contracts evolve additively apart from the contract bumps recorded in the compatibility policy.
The latest published release is shown by the PyPI badge above. Issues and operating reports are welcome on GitHub.
License
Released under the MIT License.
來源:README.md,提交 afde6ff
工具
0版本歷史
12- v3.7.1最新Oct 26, 2026
- v3.7.0Oct 18, 2026
- v3.6.0Oct 18, 2026
- v3.5.1Oct 15, 2026
- v3.5.0Oct 11, 2026
- v3.4.1Oct 3, 2026
- v3.4.0Sep 30, 2026
- v3.3.0Sep 30, 2026
- v3.2.0Sep 29, 2026
- v3.1.1Sep 29, 2026
- v3.1.0Sep 29, 2026
- v3.0.7Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分