Elffuss BraidHub

utopia-ia/elffuss-braid public

2dd40509e7e2 · 20.3 KiBSourceRawPermalink

AGENTS.md

Instructions for coding agents. Part 1 is for when someone asks you to install braid in a project and set it up for agents. Part 2 is for working on braid itself, in this repository.

Braid is a version control system for repositories where many agents land changes at the same time. Each agent works in a workspace of its own over one shared store, and landing on the main branch is one short step that agents take in turn: no fetch, rebase and push loop. Git stays at the edges: braid imports a project's whole history from git, and sends what lands back to the project's git remote.

Braid is pre-alpha. Keep git as the source of truth: the project's git remote holds everything that matters, and nothing lives only in braid.

1. Installing braid and setting it up in a project

Read this part whole before you run anything, and run its commands exactly as they are written.

Install

Braid builds from source with cargo. It needs:

cargo install --locked --git https://github.com/KikoCis/elffuss-braid --tag v0.0.2 elffuss-braid-cli

It compiles braid and its dependencies from source, which takes a while: give the command a long timeout, or run it in the background, since a command cut short starts again from the beginning. It puts a braid binary in cargo's bin directory, ~/.cargo/bin unless CARGO_HOME says otherwise. If that directory is not on PATH, call braid as "$HOME/.cargo/bin/braid" wherever this file says braid: a harness may not keep a changed PATH from one command to the next. Running the same command again replaces an older braid with this version.

Is it installed, and set up here?

braid --version     # "braid 0.0.2", or newer, once it is installed
braid refs          # in the project root: its branches, once it is set up

Set up a project

First read the project's AGENTS.md, CLAUDE.md and the like for rules about git: branches, pull requests, how to commit. Look too for what braid does not run: git hooks (in .git/hooks, or where git config core.hooksPath says), Git LFS (filter=lfs in .gitattributes: braid sees the pointer files, not the content) and a main branch that takes changes only through pull requests. Tell the user what you found, and if any of it clashes with agents landing on the main branch, ask how to go on before you set anything up.

Then work in the root of the project's git checkout, on its main branch, with nothing to commit (git status) and nothing new to pull (git pull --ff-only; skip it when the branch has no upstream). In a shallow clone, run git fetch --unshallow first: braid imports the whole history. The commands say main; if the project's main branch has another name, such as master, write that instead. Every line is safe to run again, so after a failure, start again from the top.

test -d .braid || braid init     # .braid/: the store and the agents' workspaces
grep -qsxF .braid "$(git rev-parse --git-path info/exclude)" || echo .braid >> "$(git rev-parse --git-path info/exclude)"
test -f .braid/config || printf 'name = %s\nemail = %s\n' "$(git config user.name)" "$(git config user.email)" > .braid/config
touch CLAUDE.md                  # for Claude Code, which reads CLAUDE.md, not AGENTS.md
braid git import .               # the project's whole history: every local branch and tag
braid agents init                # the rules for agents, in AGENTS.md

Commit what braid agents init wrote, so that every workspace and every clone has the rules, then import that commit too. From this commit on, agents in every clone of the project read the section: tell the user so before you commit. Where braid agents init found the files as they should be already, there is nothing to commit, and the git commit line does nothing.

git add AGENTS.md
if [ -f CLAUDE.md ]; then git add CLAUDE.md; fi
if [ -f GEMINI.md ]; then git add GEMINI.md; fi
git diff --cached --quiet || git commit -m "Set up braid for agents"
braid git import .               # braid's main takes the commit
braid log main -n 1              # and shows it

If AGENTS.md, CLAUDE.md or GEMINI.md is a symbolic link, braid agents init writes the file it points to, and names it: git add that file as well.

Every agent session, from then on

The section in the project's AGENTS.md tells each session what to do, with the branch it names where the commands here say main. In short:

Conflicts

When another agent landed a change to the same lines first, land exits with status 2 and leaves main where it was, and update exits with 2 as it writes the conflicts into the files. Exit status 2 also means a command line braid could not parse, which prints only an error, so read the JSON: a conflict's outcome is conflicts. Each conflict names its sides: base, branch (what main holds now) and workspace (the session's own change), and next says what to run.

braid --agent agent-1 update      # exit status 2: conflict markers in the files
# edit the files until no marker is left; `braid status` lists what still blocks
braid --agent agent-1 commit      # keeps the change's message
braid --agent agent-1 land --json

braid resolve <path> settles conflicts that are not about content, such as a file deleted on one side and changed on the other. Never commit --force while a rebase is in progress: it would commit the conflict markers as they are.

Keeping the git remote up to date

Landings change braid's main, not git's. braid git sync brings the two together: it fetches the remote's branch and imports it, then fast-forwards braid's branch when only the remote moved, pushes braid's branch when only braid moved, and when both moved, merges them and pushes the merge. The push is a fast-forward with a lease on what was just fetched, so the remote's history is never rewritten; braid never force-pushes, and runs no git hooks. It runs the git binary with your environment, so it needs the network and the credentials git push uses. Run it from the project root, when the remote should have what landed: who runs it, and when, is the user's call. Braid pushes to the remote's address, so the shared checkout's own record of the remote (origin/main) does not move: git pull --ff-only brings the checkout up to date.

braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main --dry-run --json
braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main
git pull --ff-only               # the shared checkout follows

No remote? Any bare repository will do. In the shared checkout, git init --bare ../project.git, then git remote add origin "$(cd .. && pwd)/project.git" (an absolute path, which braid reads the same from any directory) and git push -u origin main.

Undoing

What not to do

2. Working on braid itself

Braid is written in Rust, edition 2024, and needs Rust 1.89 or newer. CI pins the toolchain to 1.99.0.

PathWhat it is
crates/formatObject ids and the hashed format (frozen; see docs/spec/format-v1.md). No I/O.
crates/engineChange lists, merges, landing, ancestry and blame. No I/O.
crates/storeThe store: objects in shared segments, refs in the op log.
crates/gitThe git bridge, through gitoxide.
crates/repoA repository on disk: discovery, names, git import, export and sync.
crates/wcWorkspaces: checkouts, status, commit, land and update.
crates/cliThe braid command; braid agents init is crates/cli/src/agents.rs.
crates/simDeterministic simulation of many agents landing at once.
docs/The design and the format specification.
site/braid.elffuss.com, in English and Spanish; site/agents.md is part 1 of this file.

Build and test

cargo build
cargo test --workspace

The tests and the quick benchmark read this repository's whole history: in a shallow clone, run git fetch --unshallow first.

Before every commit

All of these must pass:

cargo fmt --all
cargo +1.99.0 clippy --workspace --all-targets --locked -- -D warnings
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
cargo deny check
cargo +1.89 check --workspace --all-targets
cargo +1.99.0 check -p elffuss-braid-format -p elffuss-braid-engine --target wasm32-unknown-unknown --locked
python3 docs/spec/check_vectors.py
python3 bench/run.py --quick
scripts/privacy-check.sh

CI runs all of them but the unpinned clippy, which catches the lints of newer toolchains early, and it also runs each fuzz target for a minute with cargo-fuzz, on nightly. The WebAssembly check needs its target (rustup +1.99.0 target add wasm32-unknown-unknown), and the vector check b3sum (cargo install b3sum --locked).

Rules

From CONTRIBUTING.md, in short: