Elffuss BraidHub

utopia-ia/elffuss-braid public

main · 33.7 KiBSourceRawPermalink

Design

Braid is a version control system for repositories where many agents create and land changes at the same time. This document explains the architecture and the reasons behind it. The byte-level format is in spec/format-v1.md.

Goals

Non-goals

Data model

Store

A store is a directory of files that several processes share. Its correctness rests only on guarantees every local file system gives: exclusive create, appends protected by checksums, advisory locks that the kernel releases when a process dies, atomic rename, and ordered syncs.

Derived data

Everything that is not in a changeset is derived data: computed from changesets, stored, and always recomputable. A derived value is what a named function, at some version, gives for some inputs, and its key is BLAKE3-derive-key("elffuss-braid 2026 derived v1", function ‖ version ‖ input ids ‖ argument). The encodings are in section 8 of the format spec.

Landing on a branch

land takes a changeset C built on base B and moves a branch to include it. Bases are always ids, never branch names, so nothing is resolved late.

  1. If the request for (branch, C) already landed, return that result. A lost acknowledgement is retried safely.
  2. B must be on the branch's first-parent chain.
  3. If B is the head, fast-forward.
  4. Otherwise rebase C onto the head, path by path: unchanged since B takes C's value; changed on both sides goes through a three-way merge. The cost follows the size of C.
  5. Write the new objects, append the landing record, sync, then publish the new head.

Locally this step runs under the op log lock; on a server, one task per branch runs it in order, grouping several landings into one sync.

Conflicts are reported as data, not as markers in a file: the path, the kind, what the base, the head (ours) and the change (theirs) have there, and the hunks, with line numbers counted from 0 and the end excluded. The command line names the sides from the caller's point of view: base, branch and workspace. Braid is stricter than git about structural conflicts: a file against a directory, two names that differ only in case or Unicode normalisation, a directory removed under a new file, and the same file renamed two ways.

A revert is a landing like any other. The revert R of a changeset C has C as its only parent, the change list from C's tree back to its first parent's, and a reverts extra field naming C. Landed on a head that moved past C, it is rebased path by path with C as the base, the head as ours and C's parent as theirs: later work on other lines stays, and later work on the same lines is a conflict. braid verify lands the reverts it makes the same way, with the agent braid-verify. Its limits are read from the branch, so that a fresh clone keeps them: it refuses to revert a changeset that has a reverts field and that agent, and counts the reverts of the last hour by each one's own committer time, among the last 10,000 changesets of the branch. Dates are not in order along a branch, since a fast-forward keeps the date a changeset was made with and a git commit can carry any date, so an old one stops nothing: only the depth bounds the walk. Anyone can write that field and that label: the label is only ever a reason to refuse. The field also tells bisecting where a culprit was reverted later in the range, but verify only acts on that by testing the changeset that carries it, and bisects on after it only if the tests pass there: a false field can make verify run one more test, or end with no_culprit instead of reverting the culprit, but it never blames a changeset that passes, or one whose parent fails. A local record in .braid/verify/ is a second source for both limits. Its green ref, braid/green/<branch>, lives in braid's own namespace: it is local to the repository and never exported or sent to a hub.

Invariants. A branch only moves forward. A branch never contains a conflict. No value is overwritten except by a change whose base already contained it. An acknowledged landing is durable. Readers only see durable heads.

History

Three derived functions answer history queries without walking all of history every time. The engine's History reads them through the derived index, computes what is missing, and remembers what it read.

Blame differs from git's on purpose in two ways, and the differential tests check that it differs in no other:

Workspaces

Instructions for agents

Coding agents learn a project's rules from its AGENTS.md, or, for Claude Code and Gemini CLI, from a CLAUDE.md or a GEMINI.md that can include it. braid agents init writes there what an agent needs to work through braid, so that a project set up once tells every later session, whatever harness runs it. The guide that sets a project up is part 1 of the repository's AGENTS.md, which the site also serves as agents.md. It installs braid from the tag of the version it describes, since the site serves it apart from the code.

Git bridge

Sync

braid git sync <remote> [--branch main] [--remote-branch <name>] keeps a braid branch and a branch of a git remote (GitHub, Gitea, a path) in step, so that the git host stays the public face of a repository while agents land in braid.

Server and caches

Testing

Performance targets

Stated as complexity and as ratios against git on the same machine. Braid's published benchmarks will only ever be ratios with the script that reproduces them.