| 1 | # AGENTS.md |
| 2 | |
| 3 | Instructions for coding agents. Part 1 is for when someone asks you to |
| 4 | install braid in a project and set it up for agents. Part 2 is for working |
| 5 | on braid itself, in this repository. |
| 6 | |
| 7 | Braid is a version control system for repositories where many agents land |
| 8 | changes at the same time. Each agent works in a workspace of its own over |
| 9 | one shared store, and landing on the main branch is one short step that |
| 10 | agents take in turn: no fetch, rebase and push loop. Git stays at the edges: |
| 11 | braid imports a project's whole history from git, and sends what lands back |
| 12 | to the project's git remote. |
| 13 | |
| 14 | **Keep git as the source of truth:** the project's git remote holds |
| 15 | everything that matters, and nothing lives only in braid. |
| 16 | |
| 17 | ## 1. Installing braid and setting it up in a project |
| 18 | |
| 19 | Read this part whole before you run anything, and run its commands exactly |
| 20 | as they are written. |
| 21 | |
| 22 | ### Install |
| 23 | |
| 24 | Braid builds from source with cargo. It needs: |
| 25 | |
| 26 | - Rust 1.89 or newer (`rustc --version` says which; <https://rustup.rs> |
| 27 | installs it), a C compiler (`cc`), git, and a POSIX shell such as bash: |
| 28 | every command here is written for one. |
| 29 | - Linux, macOS or another Unix-like system. Windows is not tested yet: use |
| 30 | WSL there. |
| 31 | - The network, and permission to write in cargo's directory, `~/.cargo`. |
| 32 | A sandboxed harness blocks both by default: ask the user to allow them, |
| 33 | or to run the command themselves. |
| 34 | |
| 35 | ```bash |
| 36 | cargo install --locked --git https://github.com/utopia-ia/elffuss-braid --tag v0.1.4 elffuss-braid-cli |
| 37 | ``` |
| 38 | |
| 39 | It compiles braid and its dependencies from source, which takes a while: |
| 40 | give the command a long timeout, or run it in the background, since a |
| 41 | command cut short starts again from the beginning. It puts a `braid` binary |
| 42 | in cargo's bin directory, `~/.cargo/bin` unless `CARGO_HOME` says |
| 43 | otherwise. If that directory is not on `PATH`, call braid as |
| 44 | `"$HOME/.cargo/bin/braid"` wherever this file says `braid`: a harness may |
| 45 | not keep a changed `PATH` from one command to the next. Running the same |
| 46 | command again replaces an older braid with this version. |
| 47 | |
| 48 | ### Is it installed, and set up here? |
| 49 | |
| 50 | In the project root, on its main branch: |
| 51 | |
| 52 | ```bash |
| 53 | braid --version # "braid 0.1.4", or newer, once it is installed |
| 54 | braid cat-object "$(git branch --show-current):AGENTS.md" | grep -q '^<!-- braid:start -->' && grep -q '^name = .' .braid/config && grep -q '^email = .' .braid/config && echo "braid is set up here" |
| 55 | ``` |
| 56 | |
| 57 | - Before braid is installed, `braid --version` fails with "command not |
| 58 | found", as it does while cargo's bin directory is not on `PATH`. An older |
| 59 | braid, or one that says `agents` is not a subcommand, needs the install |
| 60 | command again. |
| 61 | - The second line prints "braid is set up here" once the setup below is |
| 62 | finished: braid's copy of the branch has the braid section of |
| 63 | `AGENTS.md`, committed, and `.braid/config` names who signs. Then skip to |
| 64 | "Every agent session, from then on". If it fails instead, set the |
| 65 | project up as below, whether braid says "not inside a braid repository", |
| 66 | where it was never set up, or an earlier setup stopped half way: every |
| 67 | line of the setup is safe to run again. |
| 68 | |
| 69 | ### Set up a project |
| 70 | |
| 71 | First read the project's `AGENTS.md`, `CLAUDE.md` and the like for rules |
| 72 | about git: branches, pull requests, how to commit. Look too for what braid |
| 73 | does not run, or does not check out as git does: |
| 74 | |
| 75 | - git hooks, in `.git/hooks` or where `git config core.hooksPath` says |
| 76 | (the `*.sample` files git puts in `.git/hooks` never run, and do not |
| 77 | count); |
| 78 | - submodules, which `.gitmodules` lists: each one is an empty directory in |
| 79 | every workspace; |
| 80 | - filters, `filter=` in `.gitattributes`: a workspace holds the bytes git |
| 81 | stores, so Git LFS's pointer files rather than their content, and what |
| 82 | git-crypt encrypts stays encrypted; |
| 83 | - a main branch that takes changes only through pull requests. |
| 84 | |
| 85 | Tell the user what you found, and if any of it clashes with agents landing |
| 86 | on the main branch, ask how to go on before you set anything up. Where the |
| 87 | hooks run checks, such as tests or a linter, offer to write those commands |
| 88 | into `AGENTS.md`, outside the braid section, so that every session runs |
| 89 | them before it lands. |
| 90 | |
| 91 | Then list the project's git remotes (`git remote -v`): what agents land |
| 92 | reaches the user's checkout through one, which the commands here call |
| 93 | `origin`; if it has another name, write that instead. With no remote at |
| 94 | all, what agents land stays in braid: offer to make one (see "No remote?" |
| 95 | below). And if the project has no `CLAUDE.md`, ask whether to add one, |
| 96 | since Claude Code reads `CLAUDE.md` rather than `AGENTS.md`: with a yes, |
| 97 | run `touch CLAUDE.md` before the commands below, and `braid agents init` |
| 98 | makes it include `AGENTS.md`. |
| 99 | |
| 100 | Then work in the root of the project's git checkout, on its main branch, |
| 101 | with nothing to commit (`git status` shows no staged or modified files; |
| 102 | untracked files do not matter) and nothing new to pull |
| 103 | (`git pull --ff-only`; skip it when the branch has no upstream, which is |
| 104 | when `git rev-parse --abbrev-ref '@{u}'` fails). In a shallow clone, run |
| 105 | `git fetch --unshallow` first: braid imports the whole history. Run the |
| 106 | lines of each block below one at a time, and stop at the first one that |
| 107 | fails. Every line is safe to run again, so once the cause is fixed, start |
| 108 | again from the first line of its block. |
| 109 | |
| 110 | ```bash |
| 111 | test -d .braid || braid init # .braid/: the store and the agents' workspaces |
| 112 | mkdir -p "$(git rev-parse --git-path info)" |
| 113 | grep -qsxF .braid "$(git rev-parse --git-path info/exclude)" || echo .braid >> "$(git rev-parse --git-path info/exclude)" |
| 114 | test -f .braid/config || printf 'name = %s\nemail = %s\n' "$(git config user.name)" "$(git config user.email)" > .braid/config |
| 115 | if grep -q '^name = .' .braid/config && grep -q '^email = .' .braid/config; then braid git import . && braid agents init; else echo 'braid: .braid/config has no name or no email: ask the user who signs' >&2; false; fi |
| 116 | ``` |
| 117 | |
| 118 | - The second and third lines make git ignore every `.braid` in this |
| 119 | checkout, and only in this one: braid's directory, and the `.braid` file |
| 120 | that marks each workspace, so that nothing of braid's is ever committed |
| 121 | with git. |
| 122 | - `.braid/config` names who signs the changesets agents make, here the |
| 123 | same person as git's commits. The last line imports the project's whole |
| 124 | history, every local branch and tag, and then writes the rules for |
| 125 | agents into `AGENTS.md`, but only once the file has a name and an email. |
| 126 | Until then it stops and says so, as it does when git has no `user.name` |
| 127 | or `user.email`: every commit and landing would fail with "no author", |
| 128 | and the `git commit` below would fail too. Ask the user for the name and |
| 129 | the e-mail address to use. With their answer, set them for this |
| 130 | checkout, and let the setup write the file anew: |
| 131 | |
| 132 | ```bash |
| 133 | git config user.name "<name>" |
| 134 | git config user.email "<email>" |
| 135 | rm .braid/config # then run the setup again from its first line |
| 136 | ``` |
| 137 | |
| 138 | - Most harnesses read `AGENTS.md`. Claude Code reads `CLAUDE.md` instead, |
| 139 | and Gemini CLI `GEMINI.md`: `braid agents init` adds the line |
| 140 | `@AGENTS.md` to each of them that exists, so that they read the section |
| 141 | too. In Claude Code, each braid command asks for permission unless the |
| 142 | project allows it: offer to add `"Bash(braid:*)"` to `permissions.allow` |
| 143 | in `.claude/settings.local.json`, the user's own settings for this |
| 144 | checkout, which are never committed: braid is set up in this checkout |
| 145 | only. |
| 146 | - `braid agents init` writes a section into `AGENTS.md`, creating the file |
| 147 | if there is none, between a `<!-- braid:start -->` line and a |
| 148 | `<!-- braid:end -->` line. The section tells every agent session to work |
| 149 | in a workspace of its own and to land through braid, and names the branch |
| 150 | agents land on: `main`, `master`, or the project's only branch. With |
| 151 | several, it asks for `--branch <name>`, which must name a branch the |
| 152 | project has. `--dry-run` shows what it would write. Text outside the |
| 153 | markers is never touched, and running it again rewrites the section in |
| 154 | place. |
| 155 | |
| 156 | Commit what `braid agents init` wrote, so that every workspace and every |
| 157 | clone has the rules, then import that commit too. From this commit on, |
| 158 | agents in every clone of the project read the section: tell the user so |
| 159 | before you commit. Where `braid agents init` found the files as they |
| 160 | should be already, there is nothing to commit, and the `git commit` line |
| 161 | does nothing. |
| 162 | |
| 163 | ```bash |
| 164 | git add AGENTS.md |
| 165 | if [ -f CLAUDE.md ]; then git add CLAUDE.md; fi |
| 166 | if [ -f GEMINI.md ]; then git add GEMINI.md; fi |
| 167 | git diff --cached --quiet || git -c user.useConfigOnly=true commit -m "Set up braid for agents" |
| 168 | braid git import . # braid's copy of the branch takes the commit |
| 169 | braid cat-object "$(git branch --show-current):AGENTS.md" | grep -q '^<!-- braid:start -->' && grep -q '^name = .' .braid/config && grep -q '^email = .' .braid/config && echo "braid is set up here" |
| 170 | ``` |
| 171 | |
| 172 | The last line is the check from "Is it installed, and set up here?": it |
| 173 | prints "braid is set up here" once the commit is in braid. With |
| 174 | `user.useConfigOnly`, git refuses to commit rather than make up a name and |
| 175 | an address from the machine; where it says "Author identity unknown", set |
| 176 | them as above, then run this block again. If `AGENTS.md`, `CLAUDE.md` or |
| 177 | `GEMINI.md` is a symbolic link, `braid agents init` writes the file it |
| 178 | points to, and names it: `git add` that file as well. |
| 179 | |
| 180 | The commit stays in this checkout until it is pushed: the next |
| 181 | `braid git sync` takes it to the git remote, with what agents land, and |
| 182 | other clones get the rules from there (see "Keeping the git remote up to |
| 183 | date"). Tell the user so, and offer to sync now. |
| 184 | |
| 185 | ### Every agent session, from then on |
| 186 | |
| 187 | The section in the project's `AGENTS.md` tells each session what to do, |
| 188 | with the branch it names where the commands here say `main`. In short: |
| 189 | |
| 190 | - **Only where braid is set up.** A checkout with no `.braid` directory in |
| 191 | its root (a fresh clone, CI, another machine) does not use braid: agents |
| 192 | there work with git, as the project's other rules say, and set braid up |
| 193 | only when the user asks. With `.braid` but no `braid` command, braid is |
| 194 | not on `PATH`: `"$HOME/.cargo/bin/braid"` may be there, or it needs |
| 195 | installing. |
| 196 | - **Never edit files, `git add`, `git commit` or `git push` in the project |
| 197 | root.** It is the shared checkout, where the user works. Every session |
| 198 | works in a workspace of its own, under `.braid/work/`. |
| 199 | - **Start** with a workspace named for the session: 1 to 64 ASCII letters, |
| 200 | digits, `.`, `_` or `-`, starting with a letter or a digit. |
| 201 | `braid workspace list` shows the names taken, and a name that is taken is |
| 202 | refused. Wherever it runs in the project, `braid workspace add` puts the |
| 203 | workspace in `.braid/work/<name>` of the project root, and it refuses a |
| 204 | branch the project does not have. Then edit, build and test only in that |
| 205 | directory. A workspace is a whole checkout of the branch, so builds in it |
| 206 | start from scratch. |
| 207 | |
| 208 | ```bash |
| 209 | braid workspace add agent-1 --track main |
| 210 | cd .braid/work/agent-1 # from the project root |
| 211 | ``` |
| 212 | |
| 213 | - **No git in the workspace.** A workspace holds a `.git` file that points |
| 214 | nowhere, so `git` fails there with "not a git repository" instead of |
| 215 | acting on the shared checkout around it, where `git stash`, `reset`, |
| 216 | `checkout`, `restore`, `clean`, `add` or `commit` would change the user's |
| 217 | files. Do not get around it with `git -C` or `GIT_DIR`. A build or test |
| 218 | script that finds the project with git (`git rev-parse --show-toplevel`) |
| 219 | fails in a workspace too: run its steps yourself. To see what an edit |
| 220 | changed, compare the file with the workspace's `base`, which |
| 221 | `braid status --json` gives, from the workspace's root: |
| 222 | `braid cat-object <base>:<path> | diff -u - <path>`. To undo an edit, |
| 223 | write the base's version back with |
| 224 | `braid cat-object <base>:<path> > <path>`; a file the workspace added has |
| 225 | none, so delete it. |
| 226 | - **Record and land** from the workspace. `--agent` (or `BRAID_AGENT`) |
| 227 | names the session in the op log and in every changeset it makes; pass it |
| 228 | every time, since a harness may not keep variables between commands. If |
| 229 | the shell does not keep its directory either, add `--workspace agent-1` |
| 230 | and run the commands from the project root. The hints braid prints, and |
| 231 | `next` in its JSON, repeat the `--agent` and `--workspace` given. |
| 232 | |
| 233 | ```bash |
| 234 | braid --agent agent-1 status --json |
| 235 | braid --agent agent-1 commit -m "Say what changed and why" |
| 236 | braid --agent agent-1 land --json |
| 237 | ``` |
| 238 | |
| 239 | There is no staging area: `commit` records every change in the |
| 240 | workspace, or only the paths it is given |
| 241 | (`braid --agent agent-1 commit -m "..." <path>...`), so read |
| 242 | `braid status` before each commit. `land` refuses while anything is left |
| 243 | uncommitted ("the workspace has uncommitted changes ...; commit them |
| 244 | first"). Building or running the project writes files too: those that |
| 245 | `.gitignore` does not list are new files like any other. Delete them, or |
| 246 | list them in `.braidignore`, which must then list itself too, or it is a |
| 247 | new file to commit: for Python's `__pycache__/`, run |
| 248 | `printf '%s\n' .braidignore __pycache__/ >> .braidignore` in the |
| 249 | workspace's root. Only `.gitignore` and `.braidignore` apply in a |
| 250 | workspace, not `.git/info/exclude` or a global excludes file: anything |
| 251 | else that must stay local goes in `.braidignore` too. Braid runs no git |
| 252 | hooks, so before you land, run the checks that the project's `AGENTS.md` |
| 253 | or `CLAUDE.md` gives. `land` puts the workspace's changesets on `main`, |
| 254 | as a fast-forward or rebased onto whatever landed first. |
| 255 | - **Before a new task**, `braid --agent agent-1 update` brings the |
| 256 | workspace onto `main`. `status --json` says how far behind it is |
| 257 | (`behind_by`). |
| 258 | - **When the session finishes**, what it landed is on braid's `main` only. |
| 259 | The user's checkout and the git remote get it with `braid git sync`, then |
| 260 | `git pull --ff-only`, both from the project root (see "Keeping the git |
| 261 | remote up to date", which also says what to do when either fails). The |
| 262 | session tells the user so, and offers to run them: when to sync is the |
| 263 | user's call. Where `git remote get-url origin` fails, the project has no |
| 264 | remote of that name: the session asks the user which of those |
| 265 | `git remote` lists to sync with, or, where it lists none, says so and |
| 266 | offers to make one first (see "No remote?"). |
| 267 | - **Done**: once everything has landed, `braid workspace remove agent-1` |
| 268 | from the project root. It refuses while the workspace holds work that |
| 269 | has not landed. |
| 270 | - Every command takes `--json`. Exit status 2 is a conflict, and 1 a |
| 271 | failure, which braid prints as text on standard error, with nothing on |
| 272 | standard output, even with `--json`; only `git sync`, `fsck` and |
| 273 | `verify`, once its tests have started, print their report as well when |
| 274 | they exit with 1. `verify` exits with 4 when the branch it checks is red. |
| 275 | - Changesets are signed by `BRAID_AUTHOR` (`"Name <email>"`), or else by |
| 276 | the `name` and `email` in `.braid/config`. With neither, `commit`, |
| 277 | `land` and `update` fail with "no author", and `braid status` lists it |
| 278 | first among what stops a commit: the session asks the user who signs, |
| 279 | and writes the answer into `.braid/config` in the project root (the one |
| 280 | file there that a session may edit) as `name = <name>` and |
| 281 | `email = <email>` lines. The merges that `braid git sync` makes are |
| 282 | signed otherwise: by the `--agent` that ran the sync, with the email in |
| 283 | `.braid/config`. |
| 284 | - New files that look like secrets (`.env*`, `*.pem`, `id_*`) or are larger |
| 285 | than 1 MiB are held back until `braid track <path>`: `commit` refuses, |
| 286 | naming them, and `--force` leaves them out. Never `braid track` a secret: |
| 287 | move it out of the workspace. |
| 288 | |
| 289 | ### Conflicts |
| 290 | |
| 291 | When another agent landed a change to the same lines first, `land` exits |
| 292 | with status 2 and leaves `main` where it was, and `update` exits with 2 as |
| 293 | it writes the conflicts into the files. Exit status 2 also means a command |
| 294 | line braid could not parse, which prints only an error, so read the JSON: |
| 295 | a conflict's `outcome` is `conflicts`. Each conflict names its sides: |
| 296 | `base`, `branch` (what `main` holds now) and `workspace` (the session's |
| 297 | own change), and `next` says what to run. |
| 298 | |
| 299 | ```bash |
| 300 | braid --agent agent-1 update # exit status 2: conflict markers in the files |
| 301 | # edit the files until no marker is left; `braid status` lists what still blocks |
| 302 | braid --agent agent-1 commit # keeps the change's message; -m gives another |
| 303 | braid --agent agent-1 land --json |
| 304 | ``` |
| 305 | |
| 306 | `braid resolve <path>` settles conflicts that are not about content, such |
| 307 | as a file deleted on one side and changed on the other. Never |
| 308 | `commit --force` while a rebase is in progress: it would commit the |
| 309 | conflict markers as they are. |
| 310 | |
| 311 | ### Keeping the git remote up to date |
| 312 | |
| 313 | Landings change braid's `main`, not git's. `braid git sync` brings the two |
| 314 | together: it fetches the remote's branch and imports it, then fast-forwards |
| 315 | braid's branch when only the remote moved, pushes braid's branch when only |
| 316 | braid moved, and when both moved, merges them and pushes the merge. The |
| 317 | push is a fast-forward, with a lease on what was just fetched, so the |
| 318 | remote's history is never rewritten. Braid runs no git hooks. It runs the |
| 319 | `git` binary with your environment, so it needs the network and the |
| 320 | credentials `git push` uses. Run it from the project root, when the |
| 321 | remote should have what landed: who runs it, and when, is the user's |
| 322 | call. Braid pushes to the remote's address, so the shared checkout's own |
| 323 | record of the remote (`origin/main`) does not move: `git pull --ff-only` |
| 324 | brings the checkout up to date. The commands here say `main`: write the |
| 325 | branch that the section names. |
| 326 | |
| 327 | ```bash |
| 328 | braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main --dry-run --json |
| 329 | braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main |
| 330 | git pull --ff-only # the shared checkout follows |
| 331 | ``` |
| 332 | |
| 333 | - With `--json`, `outcome` is one of `up_to_date`, `created`, |
| 334 | `fast_forwarded`, `pushed`, `merged`, `conflicts`, `remote_moved` or |
| 335 | `rejected`. `--dry-run` writes nothing. `--agent` names the session in |
| 336 | the op log, and in the merge a sync makes. |
| 337 | - Each changeset reaches git as a commit of its own, with an `agent` header |
| 338 | that names the agent that made it. |
| 339 | - Exit status 1 with `remote_moved`: someone pushed meanwhile; sync again. |
| 340 | With `rejected`, also exit status 1, the remote refused the push, as a |
| 341 | protected branch does: ask the user. They may let braid push there, or |
| 342 | have it push to a branch of its own, with `--remote-branch <name>`, to |
| 343 | open a pull request from. |
| 344 | - Exit status 2 with `conflicts`: braid and the remote changed the same |
| 345 | lines. Nothing moved and nothing was pushed. Merge them in git, in the |
| 346 | shared checkout, and sync again: |
| 347 | |
| 348 | ```bash |
| 349 | git init --bare .braid/export.git # a scratch repository, which git ignores |
| 350 | braid git export .braid/export.git --ref main |
| 351 | git fetch .braid/export.git main |
| 352 | git merge --ff-only FETCH_HEAD # the shared checkout takes braid's main |
| 353 | git fetch origin main |
| 354 | git merge --no-edit origin/main # the remote's: git stops at conflicts |
| 355 | # if it stopped: fix those files and git add them, then git commit --no-edit --cleanup=strip |
| 356 | git push origin main |
| 357 | braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main |
| 358 | rm -rf .braid/export.git |
| 359 | ``` |
| 360 | |
| 361 | Braid knows the commits it exported, so the sync after the push |
| 362 | fast-forwards braid's `main` to the merge. Merge in this order, with |
| 363 | braid's branch as the first parent: braid follows a branch's first |
| 364 | parents to tell what a workspace has landed, so the workspaces carry on |
| 365 | from the merge. |
| 366 | - If `git pull --ff-only` refuses, the shared checkout has commits of its |
| 367 | own that the remote does not have, and what to do with them is the |
| 368 | user's call. `git pull --rebase` puts them on top of what braid pushed; |
| 369 | then `git push`, and a sync brings them into braid. |
| 370 | |
| 371 | No remote? Any bare repository will do. With the user's yes, these lines, |
| 372 | run in the shared checkout on its main branch, make one next to the |
| 373 | project, named after it (`../<project>.git`, by an absolute path, which |
| 374 | braid reads the same from any directory), and push the main branch to it. |
| 375 | If something has that name already, choose another. |
| 376 | |
| 377 | ```bash |
| 378 | git init --bare -b "$(git branch --show-current)" "$PWD.git" |
| 379 | git remote add origin "$PWD.git" |
| 380 | git push -u origin "$(git branch --show-current)" |
| 381 | ``` |
| 382 | |
| 383 | ### Across machines: BraidHub |
| 384 | |
| 385 | Braid's store lives in one checkout. For agents on several machines, a |
| 386 | repository can live on [BraidHub](https://braidhub.elffuss.com), a braid |
| 387 | server where people and agents sign in with GitHub and land on the same |
| 388 | main branch, and which can keep a GitHub repository as its mirror. Its own |
| 389 | guide for agents, <https://braidhub.elffuss.com/agents.md>, says how to sign |
| 390 | in, publish a project, clone one, and when to ask the user first. |
| 391 | |
| 392 | ### Undoing |
| 393 | |
| 394 | - `braid op log` lists every operation (imports, landings, syncs), newest |
| 395 | first, with the agent that made it. `braid --agent agent-1 undo` reverts |
| 396 | the newest one that is not undone yet, whoever made it, so read the log |
| 397 | first. A landing undone leaves its changeset in the workspace that made |
| 398 | it, ready to land again. A sync undone moves braid's refs back, but not |
| 399 | the git remote: what it pushed stays there. |
| 400 | - A change that landed under other changes cannot be undone that way: |
| 401 | `braid --agent agent-1 revert <changeset> --json` lands a changeset that |
| 402 | puts its files back, rebased over what landed since. When later changes |
| 403 | touched the same lines, it exits with status 2, `land` in its JSON has |
| 404 | the conflicts, and nothing moves: undo the change by hand in a workspace. |
| 405 | - To take braid out of a project: land what the workspaces hold, sync it |
| 406 | and run `git pull --ff-only`; remove each workspace |
| 407 | (`braid workspace remove <name>`, which refuses while work has not |
| 408 | landed); delete `.braid/`, the `.braid` line of the file that |
| 409 | `git rev-parse --git-path info/exclude` names, the braid section of |
| 410 | `AGENTS.md` (its two marker lines and everything between them) and the |
| 411 | `@AGENTS.md` line it added to `CLAUDE.md` and `GEMINI.md`; and commit |
| 412 | that with git. Then `cargo uninstall elffuss-braid-cli` removes the |
| 413 | command. |
| 414 | |
| 415 | ### What not to do |
| 416 | |
| 417 | - Do not edit files, `git add`, `git commit`, `git push` or `git pull` in |
| 418 | the shared checkout while you work: only setting up, syncing, merging a |
| 419 | sync conflict and naming who signs in `.braid/config` touch it, as |
| 420 | above. |
| 421 | - Do not run git in a workspace, or get around the `.git` file that stops |
| 422 | it there. |
| 423 | - Do not share a workspace between sessions, or work in another session's |
| 424 | workspace. |
| 425 | - Do not run `braid undo` without reading `braid op log` first. |
| 426 | - Do not `braid git export` into the shared checkout or into the remote: it |
| 427 | overwrites git refs of the same names. `braid git sync` is the way to the |
| 428 | remote. |
| 429 | - Do not `commit --force` past conflict markers, and never `braid track` a |
| 430 | secret. |
| 431 | - Do not delete `.braid/` while a workspace holds work that has not landed |
| 432 | and been synced: the workspaces and their changesets live there. |
| 433 | - Do not force-push the branch braid syncs with, and do not keep anything |
| 434 | only in braid. |
| 435 | |
| 436 | ## 2. Working on braid itself |
| 437 | |
| 438 | Braid is written in Rust, edition 2024, and needs Rust 1.89 or newer. CI |
| 439 | pins the toolchain to 1.99.0. |
| 440 | |
| 441 | | Path | What it is | |
| 442 | |---|---| |
| 443 | | `crates/format` | Object ids and the hashed format (frozen; see `docs/spec/format-v1.md`). No I/O. | |
| 444 | | `crates/engine` | Change lists, merges, landing, ancestry and blame. No I/O. | |
| 445 | | `crates/store` | The store: objects in shared segments, refs in the op log. | |
| 446 | | `crates/git` | The git bridge, through gitoxide. | |
| 447 | | `crates/repo` | A repository on disk: discovery, names, git import, export and sync. | |
| 448 | | `crates/wc` | Workspaces: checkouts, status, commit, land and update. | |
| 449 | | `crates/cli` | The `braid` command; `braid agents init` is `crates/cli/src/agents.rs`. | |
| 450 | | `crates/hubproto` | The BraidHub protocol the client speaks: names, tokens, scopes, the object stream and the JSON bodies; `docs/hub.md` is its prose. | |
| 451 | | `crates/sim` | Deterministic simulation of many agents landing at once. | |
| 452 | | `docs/` | The design, the format specification and the hub's protocol (`docs/hub.md`, `docs/hub-agents.md`). | |
| 453 | | `site/` | braid.elffuss.com, in English and Spanish; `site/agents.md` is part 1 of this file. | |
| 454 | |
| 455 | ### Build and test |
| 456 | |
| 457 | ```bash |
| 458 | cargo build |
| 459 | cargo test --workspace |
| 460 | ``` |
| 461 | |
| 462 | The tests and the quick benchmark read this repository's whole history: in |
| 463 | a shallow clone, run `git fetch --unshallow` first. |
| 464 | |
| 465 | ### Before every commit |
| 466 | |
| 467 | All of these must pass: |
| 468 | |
| 469 | ```bash |
| 470 | cargo fmt --all |
| 471 | cargo +1.99.0 clippy --workspace --all-targets --locked -- -D warnings |
| 472 | cargo clippy --workspace --all-targets -- -D warnings |
| 473 | cargo test --workspace |
| 474 | RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-features --locked |
| 475 | cargo deny check |
| 476 | cargo +1.89 check --workspace --all-targets |
| 477 | cargo +1.99.0 check -p elffuss-braid-format -p elffuss-braid-engine --target wasm32-unknown-unknown --locked |
| 478 | python3 docs/spec/check_vectors.py |
| 479 | python3 bench/run.py --quick |
| 480 | scripts/privacy-check.sh |
| 481 | ``` |
| 482 | |
| 483 | CI runs all of them but the unpinned clippy, which catches the lints of |
| 484 | newer toolchains early, and it also runs each fuzz target for a minute with |
| 485 | cargo-fuzz, on nightly. The WebAssembly check needs its target |
| 486 | (`rustup +1.99.0 target add wasm32-unknown-unknown`), and the vector check |
| 487 | `b3sum` (`cargo install b3sum --locked`). |
| 488 | |
| 489 | ### Rules |
| 490 | |
| 491 | From [CONTRIBUTING.md](CONTRIBUTING.md), in short: |
| 492 | |
| 493 | - No code from git or any other GPL project: braid is Apache-2.0. The git |
| 494 | bridge uses gitoxide. Dependencies must be compatible with Apache-2.0 |
| 495 | (`deny.toml` lists the licences accepted). |
| 496 | - The hashed formats (`crates/format`, sections 1 to 5 of the spec) are |
| 497 | frozen. Changing the bytes of an id, a tree or a changeset needs a new |
| 498 | format version, with the spec and its golden vectors updated in the same |
| 499 | change. |
| 500 | - Tests come with the change, and a bug fix comes with a test that fails |
| 501 | without it. |
| 502 | - Performance claims are ratios against git on the same machine, with the |
| 503 | script that reproduces them (`bench/run.py`). Never publish absolute |
| 504 | timings or describe the hardware. |
| 505 | - Every source file starts with `SPDX-License-Identifier: Apache-2.0` and |
| 506 | `Copyright (c) 2026 UtopiaIA` in a comment. |
| 507 | - Code and documentation are in English. The site has every text in English |
| 508 | and in Spanish (see `site/README.md`). |
| 509 | - The repository is public: no absolute paths, user names, real e-mail |
| 510 | addresses (use `example.org`), hardware or timings in anything committed. |
| 511 | - Part 1 of this file and `site/agents.md` say the same thing, and a test |
| 512 | checks it: change both together. The install command names the tag of |
| 513 | the version in `Cargo.toml`, and the test checks that too: a release |
| 514 | bumps both. |