Elffuss BraidHub

utopia-ia/elffuss-braid public

2dd40509e7e2 · 31.0 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.

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.