utopia-ia/elffuss-braid public
Changesets · Branches · Tags · Compare
| Changeset | b27b4d239a54f72cc21859efc28f149d8089072a2590be07387cf027ed0d2223 |
|---|---|
| Author | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-17 13:42 +02:00 |
| Committer | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-17 13:42 +02:00 |
| Parents | 4b3dd661f2e5 |
13 files changed
modified .github/workflows/ci.yml +1 −1
| @@ -43,7 +43,7 @@ | ||
| 43 | 43 | - uses: actions/checkout@v5 |
| 44 | 44 | - uses: dtolnay/rust-toolchain@1.89 |
| 45 | 45 | - uses: Swatinem/rust-cache@v2 |
| 46 | - - run: cargo check --workspace --locked | |
| 46 | + - run: cargo check --workspace --all-targets --locked | |
| 47 | 47 | |
| 48 | 48 | wasm: |
| 49 | 49 | name: format and engine on WebAssembly |
modified AGENTS.md +115 −78
| @@ -47,78 +47,92 @@ | ||
| 47 | 47 | |
| 48 | 48 | ### Is it installed, and set up here? |
| 49 | 49 | |
| 50 | +In the project root, on its main branch: | |
| 51 | + | |
| 50 | 52 | ```bash |
| 51 | 53 | braid --version # "braid 0.0.2", or newer, once it is installed |
| 52 | -braid refs # in the project root: its branches, once it is set up | |
| 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" | |
| 53 | 55 | ``` |
| 54 | 56 | |
| 55 | 57 | - Before braid is installed, `braid --version` fails with "command not |
| 56 | 58 | found", as it does while cargo's bin directory is not on `PATH`. An older |
| 57 | 59 | braid, or one that says `agents` is not a subcommand, needs the install |
| 58 | 60 | command again. |
| 59 | -- In a project where braid is not set up, `braid refs` fails with "not | |
| 60 | - inside a braid repository". Where it lists the project's branches and | |
| 61 | - `AGENTS.md` has a braid section (a `<!-- braid:start -->` line), braid is | |
| 62 | - set up: skip to "Every agent session, from then on". It lists braid's own | |
| 63 | - refs too: `braid/git-map`, the project's tags as `tags/<name>`, and once | |
| 64 | - a sync has run, `remote/<label>/<branch>`. | |
| 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. | |
| 65 | 68 | |
| 66 | 69 | ### Set up a project |
| 67 | 70 | |
| 68 | 71 | First read the project's `AGENTS.md`, `CLAUDE.md` and the like for rules |
| 69 | 72 | about git: branches, pull requests, how to commit. Look too for what braid |
| 70 | -does not run: git hooks (in `.git/hooks`, or where | |
| 71 | -`git config core.hooksPath` says; the `*.sample` files git puts in | |
| 72 | -`.git/hooks` never run, and do not count), Git LFS (`filter=lfs` in | |
| 73 | -`.gitattributes`: braid sees the pointer files, not the content) and a main | |
| 74 | -branch that takes changes only through pull requests. Then list the | |
| 75 | -project's git remotes (`git remote -v`): what agents land reaches the | |
| 76 | -user's checkout through one, which the commands here call `origin`; if it | |
| 77 | -has another name, write that instead. Tell the user what you found, and | |
| 78 | -if any of it clashes with agents landing on the main branch, ask how to | |
| 79 | -go on before you set anything up. With no remote at all, what agents land | |
| 80 | -stays in braid: offer to make one (see "No remote?" below). And if the | |
| 81 | -project has no `CLAUDE.md`, ask whether to add one, since Claude Code | |
| 82 | -reads `CLAUDE.md` rather than `AGENTS.md`: with a yes, run | |
| 83 | -`touch CLAUDE.md` before the commands below, and `braid agents init` makes | |
| 84 | -it include `AGENTS.md`. | |
| 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`. | |
| 85 | 99 | |
| 86 | 100 | Then work in the root of the project's git checkout, on its main branch, |
| 87 | 101 | with nothing to commit (`git status` shows no staged or modified files; |
| 88 | 102 | untracked files do not matter) and nothing new to pull |
| 89 | 103 | (`git pull --ff-only`; skip it when the branch has no upstream, which is |
| 90 | 104 | when `git rev-parse --abbrev-ref '@{u}'` fails). In a shallow clone, run |
| 91 | -`git fetch --unshallow` first: braid imports the whole history. The | |
| 92 | -commands say `main`; if the project's main branch has another name, such | |
| 93 | -as `master`, write that instead. Every line is safe to run again, so after | |
| 94 | -a failure, start again from the top. | |
| 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. | |
| 95 | 109 | |
| 96 | 110 | ```bash |
| 97 | 111 | test -d .braid || braid init # .braid/: the store and the agents' workspaces |
| 112 | +mkdir -p "$(git rev-parse --git-path info)" | |
| 98 | 113 | grep -qsxF .braid "$(git rev-parse --git-path info/exclude)" || echo .braid >> "$(git rev-parse --git-path info/exclude)" |
| 99 | 114 | test -f .braid/config || printf 'name = %s\nemail = %s\n' "$(git config user.name)" "$(git config user.email)" > .braid/config |
| 100 | -grep -q '^name = .' .braid/config && grep -q '^email = .' .braid/config # fails without a name and an email | |
| 101 | -braid git import . # the project's whole history: every local branch and tag | |
| 102 | -braid agents init # the rules for agents, in AGENTS.md | |
| 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 | |
| 103 | 116 | ``` |
| 104 | 117 | |
| 105 | -- The second line makes git ignore every `.braid` in this checkout, and | |
| 106 | - only in this one: braid's directory, and the `.braid` file that marks | |
| 107 | - each workspace, so that nothing of braid's is ever committed with git. | |
| 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. | |
| 108 | 122 | - `.braid/config` names who signs the changesets agents make, here the |
| 109 | - same person as git's commits. The line after it fails, with exit status | |
| 110 | - 1 and nothing printed, while the file lacks a name or an email, as it | |
| 111 | - does when git has no `user.name` or `user.email`: every commit and | |
| 112 | - landing would then fail with "no author", and the `git commit` below | |
| 113 | - would fail too, or sign with a name and an address that git guesses | |
| 114 | - from the machine. Ask the user for the name and the e-mail address to | |
| 115 | - use. With their answer, set them for this checkout, and let the setup | |
| 116 | - write the file anew: | |
| 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: | |
| 117 | 131 | |
| 118 | 132 | ```bash |
| 119 | 133 | git config user.name "<name>" |
| 120 | 134 | git config user.email "<email>" |
| 121 | - rm .braid/config # then start again from the top | |
| 135 | + rm .braid/config # then run the setup again from its first line | |
| 122 | 136 | ``` |
| 123 | 137 | |
| 124 | 138 | - Most harnesses read `AGENTS.md`. Claude Code reads `CLAUDE.md` instead, |
| @@ -126,7 +140,9 @@ | ||
| 126 | 140 | `@AGENTS.md` to each of them that exists, so that they read the section |
| 127 | 141 | too. In Claude Code, each braid command asks for permission unless the |
| 128 | 142 | project allows it: offer to add `"Bash(braid:*)"` to `permissions.allow` |
| 129 | - in `.claude/settings.json`. | |
| 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. | |
| 130 | 146 | - `braid agents init` writes a section into `AGENTS.md`, creating the file |
| 131 | 147 | if there is none, between a `<!-- braid:start -->` line and a |
| 132 | 148 | `<!-- braid:end -->` line. The section tells every agent session to work |
| @@ -148,14 +164,23 @@ | ||
| 148 | 164 | git add AGENTS.md |
| 149 | 165 | if [ -f CLAUDE.md ]; then git add CLAUDE.md; fi |
| 150 | 166 | if [ -f GEMINI.md ]; then git add GEMINI.md; fi |
| 151 | -git diff --cached --quiet || git commit -m "Set up braid for agents" | |
| 152 | -braid git import . # braid's main takes the commit | |
| 153 | -braid log main -n 1 # and shows it | |
| 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" | |
| 154 | 170 | ``` |
| 155 | 171 | |
| 156 | -If `AGENTS.md`, `CLAUDE.md` or `GEMINI.md` is a symbolic link, | |
| 157 | -`braid agents init` writes the file it points to, and names it: `git add` | |
| 158 | -that file as well. | |
| 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. | |
| 159 | 184 | |
| 160 | 185 | ### Every agent session, from then on |
| 161 | 186 | |
| @@ -224,20 +249,21 @@ | ||
| 224 | 249 | workspace's root. Only `.gitignore` and `.braidignore` apply in a |
| 225 | 250 | workspace, not `.git/info/exclude` or a global excludes file: anything |
| 226 | 251 | else that must stay local goes in `.braidignore` too. Braid runs no git |
| 227 | - hooks, so run the project's checks yourself before you land. `land` puts | |
| 228 | - the workspace's changesets on `main`, as a fast-forward or rebased onto | |
| 229 | - whatever landed first. | |
| 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. | |
| 230 | 255 | - **Before a new task**, `braid --agent agent-1 update` brings the |
| 231 | 256 | workspace onto `main`. `status --json` says how far behind it is |
| 232 | 257 | (`behind_by`). |
| 233 | 258 | - **When the session finishes**, what it landed is on braid's `main` only. |
| 234 | 259 | The user's checkout and the git remote get it with `braid git sync`, then |
| 235 | 260 | `git pull --ff-only`, both from the project root (see "Keeping the git |
| 236 | - remote up to date"). The session tells the user so, and offers to run | |
| 237 | - them: when to sync is the user's call. Where `git remote get-url origin` | |
| 238 | - fails, the project has no remote of that name: the session asks the | |
| 239 | - user which of those `git remote` lists to sync with, or, where it lists | |
| 240 | - none, says so and offers to make one first (see "No remote?"). | |
| 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?"). | |
| 241 | 267 | - **Done**: once everything has landed, `braid workspace remove agent-1` |
| 242 | 268 | from the project root. It refuses while the workspace holds work that |
| 243 | 269 | has not landed. |
| @@ -249,8 +275,11 @@ | ||
| 249 | 275 | the `name` and `email` in `.braid/config`. With neither, `commit`, |
| 250 | 276 | `land` and `update` fail with "no author", and `braid status` lists it |
| 251 | 277 | first among what stops a commit: the session asks the user who signs, |
| 252 | - and writes the answer into `.braid/config` as `name = <name>` and | |
| 253 | - `email = <email>` lines. | |
| 278 | + and writes the answer into `.braid/config` in the project root (the one | |
| 279 | + file there that a session may edit) as `name = <name>` and | |
| 280 | + `email = <email>` lines. The merges that `braid git sync` makes are | |
| 281 | + signed otherwise: by the `--agent` that ran the sync, with the email in | |
| 282 | + `.braid/config`. | |
| 254 | 283 | - New files that look like secrets (`.env*`, `*.pem`, `id_*`) or are larger |
| 255 | 284 | than 1 MiB are held back until `braid track <path>`: `commit` refuses, |
| 256 | 285 | naming them, and `--force` leaves them out. Never `braid track` a secret: |
| @@ -284,14 +313,15 @@ | ||
| 284 | 313 | together: it fetches the remote's branch and imports it, then fast-forwards |
| 285 | 314 | braid's branch when only the remote moved, pushes braid's branch when only |
| 286 | 315 | braid moved, and when both moved, merges them and pushes the merge. The |
| 287 | -push is a fast-forward with a lease on what was just fetched, so the | |
| 288 | -remote's history is never rewritten; braid never force-pushes, and runs no | |
| 289 | -git hooks. It runs the `git` binary with your environment, so it needs the | |
| 290 | -network and the credentials `git push` uses. Run it from the project root, | |
| 291 | -when the remote should have what landed: who runs it, and when, is the | |
| 292 | -user's call. Braid pushes to the remote's address, so the shared | |
| 293 | -checkout's own record of the remote (`origin/main`) does not move: | |
| 294 | -`git pull --ff-only` brings the checkout up to date. | |
| 316 | +push is a fast-forward, with a lease on what was just fetched, so the | |
| 317 | +remote's history is never rewritten. Braid runs no git hooks. It runs the | |
| 318 | +`git` binary with your environment, so it needs the network and the | |
| 319 | +credentials `git push` uses. Run it from the project root, when the | |
| 320 | +remote should have what landed: who runs it, and when, is the user's | |
| 321 | +call. Braid pushes to the remote's address, so the shared checkout's own | |
| 322 | +record of the remote (`origin/main`) does not move: `git pull --ff-only` | |
| 323 | +brings the checkout up to date. The commands here say `main`: write the | |
| 324 | +branch that the section names. | |
| 295 | 325 | |
| 296 | 326 | ```bash |
| 297 | 327 | braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main --dry-run --json |
| @@ -320,9 +350,10 @@ | ||
| 320 | 350 | git fetch .braid/export.git main |
| 321 | 351 | git merge --ff-only FETCH_HEAD # the shared checkout takes braid's main |
| 322 | 352 | git fetch origin main |
| 323 | - git merge FETCH_HEAD # the remote's: fix the conflicts, then git commit | |
| 324 | - git push | |
| 325 | - braid git sync "$(git remote get-url origin)" --branch main | |
| 353 | + git merge --no-edit origin/main # the remote's: git stops at conflicts | |
| 354 | + # if it stopped: fix those files and git add them, then git commit --no-edit --cleanup=strip | |
| 355 | + git push origin main | |
| 356 | + braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main | |
| 326 | 357 | rm -rf .braid/export.git |
| 327 | 358 | ``` |
| 328 | 359 | |
| @@ -331,17 +362,21 @@ | ||
| 331 | 362 | braid's branch as the first parent: braid follows a branch's first |
| 332 | 363 | parents to tell what a workspace has landed, so the workspaces carry on |
| 333 | 364 | from the merge. |
| 365 | +- If `git pull --ff-only` refuses, the shared checkout has commits of its | |
| 366 | + own that the remote does not have, and what to do with them is the | |
| 367 | + user's call. `git pull --rebase` puts them on top of what braid pushed; | |
| 368 | + then `git push`, and a sync brings them into braid. | |
| 334 | 369 | |
| 335 | 370 | No remote? Any bare repository will do. With the user's yes, these lines, |
| 336 | -run in the shared checkout, make one next to the project, named after it | |
| 337 | -(`../<project>.git`, by an absolute path, which braid reads the same from | |
| 338 | -any directory), and push the main branch to it. If something has that | |
| 339 | -name already, choose another. | |
| 371 | +run in the shared checkout on its main branch, make one next to the | |
| 372 | +project, named after it (`../<project>.git`, by an absolute path, which | |
| 373 | +braid reads the same from any directory), and push the main branch to it. | |
| 374 | +If something has that name already, choose another. | |
| 340 | 375 | |
| 341 | 376 | ```bash |
| 342 | -git init --bare -b main "$PWD.git" | |
| 377 | +git init --bare -b "$(git branch --show-current)" "$PWD.git" | |
| 343 | 378 | git remote add origin "$PWD.git" |
| 344 | -git push -u origin main | |
| 379 | +git push -u origin "$(git branch --show-current)" | |
| 345 | 380 | ``` |
| 346 | 381 | |
| 347 | 382 | ### Undoing |
| @@ -350,7 +385,8 @@ | ||
| 350 | 385 | first, with the agent that made it. `braid --agent agent-1 undo` reverts |
| 351 | 386 | the newest one that is not undone yet, whoever made it, so read the log |
| 352 | 387 | first. A landing undone leaves its changeset in the workspace that made |
| 353 | - it, ready to land again. | |
| 388 | + it, ready to land again. A sync undone moves braid's refs back, but not | |
| 389 | + the git remote: what it pushed stays there. | |
| 354 | 390 | - A change that landed under other changes cannot be undone that way. |
| 355 | 391 | There is no revert command yet: land a change that puts the files back. |
| 356 | 392 | - To take braid out of a project: land what the workspaces hold, sync it |
| @@ -366,8 +402,9 @@ | ||
| 366 | 402 | ### What not to do |
| 367 | 403 | |
| 368 | 404 | - Do not edit files, `git add`, `git commit`, `git push` or `git pull` in |
| 369 | - the shared checkout while you work: only setting up, syncing and merging | |
| 370 | - a sync conflict touch it, as above. | |
| 405 | + the shared checkout while you work: only setting up, syncing, merging a | |
| 406 | + sync conflict and naming who signs in `.braid/config` touch it, as | |
| 407 | + above. | |
| 371 | 408 | - Do not run git in a workspace, or get around the `.git` file that stops |
| 372 | 409 | it there. |
| 373 | 410 | - Do not share a workspace between sessions, or work in another session's |
modified README.md +2 −1
| @@ -155,7 +155,8 @@ | ||
| 155 | 155 | braid git export /tmp/mirror.git |
| 156 | 156 | ``` |
| 157 | 157 | |
| 158 | -Every operation is in the op log, and any of them can be undone: | |
| 158 | +Every operation is in the op log, and the newest can be undone, one at a | |
| 159 | +time: | |
| 159 | 160 | |
| 160 | 161 | ```bash |
| 161 | 162 | braid op log # who did what, newest first |
modified crates/cli/src/agents.rs +18 −7
| @@ -707,7 +707,8 @@ | ||
| 707 | 707 | `printf '%s\\n' .braidignore __pycache__/ >> .braidignore` in the |
| 708 | 708 | workspace's root. Only `.gitignore` and `.braidignore` apply in a |
| 709 | 709 | workspace, not `.git/info/exclude` or a global excludes file. Braid runs |
| 710 | - no git hooks: run the project's checks yourself before you land. | |
| 710 | + no git hooks: before you land, run the project's checks yourself, as | |
| 711 | + this file or `CLAUDE.md` gives them. | |
| 711 | 712 | - **Conflicts:** `land` and `update` exit with status 2, the `outcome` in |
| 712 | 713 | their JSON is `conflicts`, and `{branch}` does not move. After `land`, run |
| 713 | 714 | `braid --agent agent-1 update`, which writes conflict markers into the |
| @@ -728,11 +729,19 @@ | ||
| 728 | 729 | git pull --ff-only |
| 729 | 730 | ``` |
| 730 | 731 | |
| 731 | - Offer to run it: when to sync is the user's call. Where | |
| 732 | - `git remote get-url origin` fails, the project has no remote of that | |
| 733 | - name: if `git remote` lists others, ask the user which to sync with, and | |
| 734 | - write its name in place of `origin`; if it lists none, say so, and offer | |
| 735 | - to make one next to the project first, from the project root: | |
| 732 | + Offer to run it: when to sync is the user's call. If the sync exits | |
| 733 | + with 2 (`conflicts`), braid and the remote changed the same lines, and | |
| 734 | + nothing moved: tell the user, since the merge is made with git, in their | |
| 735 | + checkout, as <https://braid.elffuss.com/agents.md> shows under | |
| 736 | + \"Keeping the git remote up to date\". With `remote_moved` (exit status | |
| 737 | + 1), sync again; with `rejected`, ask the user. If `git pull --ff-only` | |
| 738 | + refuses, their checkout has commits of its own, and what to do is their | |
| 739 | + call: `git pull --rebase`, `git push` and a new sync bring them into | |
| 740 | + braid. Where `git remote get-url origin` fails, the project has no | |
| 741 | + remote of that name: if `git remote` lists others, ask the user which to | |
| 742 | + sync with, and write its name in place of `origin`; if it lists none, | |
| 743 | + say so, and offer to make one next to the project first, from the | |
| 744 | + project root: | |
| 736 | 745 | |
| 737 | 746 | ```bash |
| 738 | 747 | git init --bare -b {branch} \"$PWD.git\" |
| @@ -746,7 +755,9 @@ | ||
| 746 | 755 | `name` and `email` in `.braid/config`. With neither, `commit`, `land` and |
| 747 | 756 | `update` fail with \"no author\", and `status` lists it first among what |
| 748 | 757 | stops a commit: ask the user who signs, and write the answer into |
| 749 | - `.braid/config` as `name = <name>` and `email = <email>` lines. | |
| 758 | + `.braid/config` in the project root, the one file there you may edit, as | |
| 759 | + `name = <name>` and `email = <email>` lines. The merges that `git sync` | |
| 760 | + makes are signed by its `--agent`, with that email. | |
| 750 | 761 | - New files that look like secrets (`.env*`, `*.pem`, `id_*`) or are larger |
| 751 | 762 | than 1 MiB wait for `braid track <path>`. Never track a secret: move it |
| 752 | 763 | out of the workspace. |
modified crates/cli/src/main.rs +3 −3
| @@ -310,9 +310,9 @@ | ||
| 310 | 310 | }, |
| 311 | 311 | /// Keep a braid branch and a branch of a git remote in step: fetch and |
| 312 | 312 | /// import the remote branch, then fast-forward the braid branch, or push |
| 313 | - /// it (merging first when both moved) as a fast-forward with a lease. | |
| 314 | - /// Never force-pushes. Exits with 2 on conflicts and 1 when the push is | |
| 315 | - /// refused. | |
| 313 | + /// it (merging first when both moved) as a fast-forward with a lease, so | |
| 314 | + /// the remote's history is never rewritten. Exits with 2 on conflicts and | |
| 315 | + /// 1 when the push is refused. | |
| 316 | 316 | Sync { |
| 317 | 317 | /// The git remote: a URL or a path. |
| 318 | 318 | remote: String, |
modified crates/cli/src/sync.rs +5 −0
| @@ -15,6 +15,10 @@ | ||
| 15 | 15 | /// Exit status when the sync found conflicts. |
| 16 | 16 | const CONFLICTS: u8 = 2; |
| 17 | 17 | |
| 18 | +/// What the text report says to do about conflicts: the two sides meet in | |
| 19 | +/// git, and the guide for agents gives the steps. | |
| 20 | +const MERGE_IN_GIT: &str = "Merge them in git and push the merge, then sync again: https://braid.elffuss.com/agents.md shows how, under \"Keeping the git remote up to date\"."; | |
| 21 | + | |
| 18 | 22 | pub(crate) fn git_sync( |
| 19 | 23 | cli: &Cli, |
| 20 | 24 | remote: &str, |
| @@ -212,6 +216,7 @@ | ||
| 212 | 216 | String::from_utf8_lossy(&conflict.path) |
| 213 | 217 | ); |
| 214 | 218 | } |
| 219 | + println!("{MERGE_IN_GIT}"); | |
| 215 | 220 | } |
| 216 | 221 | SyncOutcome::RemoteMoved { found } => { |
| 217 | 222 | eprintln!( |
modified crates/cli/tests/git_sync.rs +7 −0
| @@ -363,6 +363,13 @@ | ||
| 363 | 363 | let text = String::from_utf8(output.stdout).unwrap(); |
| 364 | 364 | assert!(text.contains("nothing moved"), "{text}"); |
| 365 | 365 | assert!(text.contains("CONTENT f"), "{text}"); |
| 366 | + // And what to do: the two sides meet in git. | |
| 367 | + assert!( | |
| 368 | + text.ends_with( | |
| 369 | + "Merge them in git and push the merge, then sync again: https://braid.elffuss.com/agents.md shows how, under \"Keeping the git remote up to date\".\n" | |
| 370 | + ), | |
| 371 | + "{text}" | |
| 372 | + ); | |
| 366 | 373 | world.assert_forward_only(); |
| 367 | 374 | } |
| 368 | 375 |
modified crates/cli/tests/guides.rs +394 −56
| @@ -120,29 +120,87 @@ | ||
| 120 | 120 | .unwrap_or_else(|| panic!("no block with {first:?}")) |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | +/// The text of `line` without its command substitutions, such as | |
| 124 | +/// `"$(git branch --show-current)"`, which leaves `""`. | |
| 125 | +fn without_substitutions(line: &str) -> String { | |
| 126 | + let mut kept = String::new(); | |
| 127 | + let mut rest = line; | |
| 128 | + while let Some(start) = rest.find("$(") { | |
| 129 | + kept.push_str(&rest[..start]); | |
| 130 | + // From the opening parenthesis to the one that closes it. | |
| 131 | + let mut depth = 0; | |
| 132 | + let mut end = rest.len(); | |
| 133 | + for (offset, c) in rest[start + 1..].char_indices() { | |
| 134 | + match c { | |
| 135 | + '(' => depth += 1, | |
| 136 | + ')' => { | |
| 137 | + depth -= 1; | |
| 138 | + if depth == 0 { | |
| 139 | + end = start + 1 + offset + 1; | |
| 140 | + break; | |
| 141 | + } | |
| 142 | + } | |
| 143 | + _ => {} | |
| 144 | + } | |
| 145 | + } | |
| 146 | + rest = &rest[end..]; | |
| 147 | + } | |
| 148 | + kept.push_str(rest); | |
| 149 | + kept | |
| 150 | +} | |
| 151 | + | |
| 152 | +/// The braid commands a shell line runs, without its comment and its | |
| 153 | +/// command substitutions. A line may run braid after another command, | |
| 154 | +/// `test -d .braid || braid init`, pipe it into one, | |
| 155 | +/// `braid cat-object <base>:<path> | diff`, or run it inside an `if`, | |
| 156 | +/// `if ...; then braid git import . && braid agents init; else ...; fi`. | |
| 157 | +fn braid_commands(line: &str) -> Vec<String> { | |
| 158 | + let line = without_substitutions(line.split(" #").next().unwrap()); | |
| 159 | + line.split(['|', '&', ';']) | |
| 160 | + .map(|command| { | |
| 161 | + let mut command = command.trim(); | |
| 162 | + for keyword in ["if ", "then ", "else ", "! "] { | |
| 163 | + command = command.strip_prefix(keyword).unwrap_or(command).trim(); | |
| 164 | + } | |
| 165 | + command | |
| 166 | + }) | |
| 167 | + .filter(|command| command.starts_with("braid ")) | |
| 168 | + .map(str::to_owned) | |
| 169 | + .collect() | |
| 170 | +} | |
| 171 | + | |
| 123 | 172 | /// Runs `line` in a new POSIX shell in `dir`, as a harness that keeps |
| 124 | 173 | /// nothing between commands runs it: with this build's braid first on |
| 125 | 174 | /// `PATH`, no braid variables, and git reading only `config` (no system |
| 126 | -/// configuration). | |
| 175 | +/// configuration) and no identity from the environment. | |
| 127 | 176 | fn shell(dir: &Path, config: &Path, line: &str) -> Output { |
| 128 | 177 | let bin = Path::new(env!("CARGO_BIN_EXE_braid")).parent().unwrap(); |
| 129 | 178 | let path = std::env::join_paths(std::iter::once(bin.to_path_buf()).chain( |
| 130 | 179 | std::env::split_paths(&std::env::var_os("PATH").unwrap_or_default()), |
| 131 | 180 | )) |
| 132 | 181 | .unwrap(); |
| 133 | - Command::new("sh") | |
| 182 | + let mut command = Command::new("sh"); | |
| 183 | + command | |
| 134 | 184 | .arg("-c") |
| 135 | 185 | .arg(line) |
| 136 | 186 | .current_dir(dir) |
| 137 | 187 | .env("PATH", path) |
| 138 | 188 | .env("GIT_CONFIG_GLOBAL", config) |
| 139 | 189 | .env("GIT_CONFIG_NOSYSTEM", "1") |
| 140 | - .env_remove("BRAID_AUTHOR") | |
| 141 | - .env_remove("BRAID_AGENT") | |
| 142 | 190 | // The shell sets it from the directory it starts in. |
| 143 | - .env_remove("PWD") | |
| 144 | - .output() | |
| 145 | - .unwrap() | |
| 191 | + .env_remove("PWD"); | |
| 192 | + for variable in [ | |
| 193 | + "BRAID_AUTHOR", | |
| 194 | + "BRAID_AGENT", | |
| 195 | + "EMAIL", | |
| 196 | + "GIT_AUTHOR_NAME", | |
| 197 | + "GIT_AUTHOR_EMAIL", | |
| 198 | + "GIT_COMMITTER_NAME", | |
| 199 | + "GIT_COMMITTER_EMAIL", | |
| 200 | + ] { | |
| 201 | + command.env_remove(variable); | |
| 202 | + } | |
| 203 | + command.output().unwrap() | |
| 146 | 204 | } |
| 147 | 205 | |
| 148 | 206 | /// Runs `line` as [`shell`] does, expecting success. |
| @@ -157,10 +215,15 @@ | ||
| 157 | 215 | String::from_utf8(out.stdout).unwrap() |
| 158 | 216 | } |
| 159 | 217 | |
| 160 | -/// A git project in `dir`, on `main`, with one commit of `notes.txt`, and | |
| 218 | +/// A git project in `dir`, on `branch`, with one commit of `notes.txt`, and | |
| 161 | 219 | /// a git configuration of its own that gives `identity` as git's user, or |
| 162 | 220 | /// none. |
| 163 | -fn git_project(dir: &Path, identity: Option<(&str, &str)>) -> PathBuf { | |
| 221 | +fn git_project(dir: &Path, branch: &str, identity: Option<(&str, &str)>) -> PathBuf { | |
| 222 | + git_project_from(dir, &format!("git init -q -b {branch}"), identity) | |
| 223 | +} | |
| 224 | + | |
| 225 | +/// A git project as [`git_project`] makes it, created by `init`. | |
| 226 | +fn git_project_from(dir: &Path, init: &str, identity: Option<(&str, &str)>) -> PathBuf { | |
| 164 | 227 | fs::create_dir_all(dir).unwrap(); |
| 165 | 228 | let config = dir.with_extension("gitconfig"); |
| 166 | 229 | let user = identity.map_or_else(String::new, |(name, email)| { |
| @@ -169,7 +232,7 @@ | ||
| 169 | 232 | fs::write(&config, user).unwrap(); |
| 170 | 233 | fs::write(dir.join("notes.txt"), "one\ntwo\n").unwrap(); |
| 171 | 234 | for line in [ |
| 172 | - "git init -q -b main", | |
| 235 | + init, | |
| 173 | 236 | "git add notes.txt", |
| 174 | 237 | "git -c user.name=Ada -c user.email=ada@example.org commit -q -m First", |
| 175 | 238 | ] { |
| @@ -178,6 +241,22 @@ | ||
| 178 | 241 | config |
| 179 | 242 | } |
| 180 | 243 | |
| 244 | +/// The line of the guide that says whether braid is set up in a project: | |
| 245 | +/// the guide gives it to check before anything else, and ends the setup | |
| 246 | +/// with it. | |
| 247 | +fn set_up_check(guide: &str) -> String { | |
| 248 | + let check = block_with(guide, "braid --version") | |
| 249 | + .into_iter() | |
| 250 | + .find(|line| line.starts_with("braid cat-object ")) | |
| 251 | + .expect("the guide checks whether braid is set up"); | |
| 252 | + let commit = block_with(guide, "git add AGENTS.md"); | |
| 253 | + assert_eq!(commit.last(), Some(&check), "the setup ends with the check"); | |
| 254 | + check | |
| 255 | +} | |
| 256 | + | |
| 257 | +/// What the check prints once braid is set up. | |
| 258 | +const SET_UP: &str = "braid is set up here\n"; | |
| 259 | + | |
| 181 | 260 | /// The text of the file at `path` in `dir`. |
| 182 | 261 | fn read(dir: &Path, path: &str) -> String { |
| 183 | 262 | fs::read_to_string(dir.join(path)).unwrap_or_else(|err| panic!("{path}: {err}")) |
| @@ -281,25 +360,27 @@ | ||
| 281 | 360 | lines.extend(bash_lines(&text)); |
| 282 | 361 | lines.extend(code_spans(&text)); |
| 283 | 362 | } |
| 284 | - // A line may run braid after another command, `test -d .braid || braid | |
| 285 | - // init`, or pipe it into one, `braid cat-object <base>:<path> | diff`. | |
| 286 | - let commands: Vec<String> = lines | |
| 287 | - .iter() | |
| 288 | - .flat_map(|line| line.split('|').flat_map(|part| part.split("&&"))) | |
| 289 | - .map(str::trim) | |
| 290 | - .filter(|command| command.starts_with("braid ")) | |
| 291 | - .map(str::to_owned) | |
| 292 | - .collect(); | |
| 363 | + let commands: Vec<String> = lines.iter().flat_map(|line| braid_commands(line)).collect(); | |
| 293 | 364 | assert!(commands.len() >= 40, "{commands:?}"); |
| 365 | + for (line, expected) in [ | |
| 366 | + ( | |
| 367 | + "test -d .braid || braid init # .braid/: the store", | |
| 368 | + vec!["braid init"], | |
| 369 | + ), | |
| 370 | + ( | |
| 371 | + "if grep -q x f; then braid git import . && braid agents init; else echo no >&2; false; fi", | |
| 372 | + vec!["braid git import .", "braid agents init"], | |
| 373 | + ), | |
| 374 | + ( | |
| 375 | + "braid cat-object \"$(git branch --show-current):AGENTS.md\" | grep -q x", | |
| 376 | + vec!["braid cat-object \":AGENTS.md\""], | |
| 377 | + ), | |
| 378 | + ] { | |
| 379 | + assert_eq!(braid_commands(line), expected); | |
| 380 | + } | |
| 294 | 381 | let groups = ["agents", "change", "git", "op", "ref", "workspace"]; |
| 295 | 382 | for command in &commands { |
| 296 | - let words: Vec<&str> = command | |
| 297 | - .split(" #") | |
| 298 | - .next() | |
| 299 | - .unwrap() | |
| 300 | - .split_whitespace() | |
| 301 | - .skip(1) | |
| 302 | - .collect(); | |
| 383 | + let words: Vec<&str> = command.split_whitespace().skip(1).collect(); | |
| 303 | 384 | let mut rest = words.as_slice(); |
| 304 | 385 | while let [flag, _, tail @ ..] = rest { |
| 305 | 386 | if matches!(*flag, "--agent" | "--workspace" | "--repo") { |
| @@ -339,39 +420,57 @@ | ||
| 339 | 420 | |
| 340 | 421 | #[test] |
| 341 | 422 | fn the_setup_stops_at_its_check_until_braid_has_a_name_and_an_email() { |
| 342 | - let setup = block_with(&part_one(), "test -d .braid || braid init"); | |
| 343 | - let check = setup | |
| 344 | - .iter() | |
| 345 | - .position(|line| line.starts_with("grep -q '^name = .' .braid/config")) | |
| 346 | - .expect("the setup checks the name and the email it wrote"); | |
| 423 | + let guide = part_one(); | |
| 424 | + let setup = block_with(&guide, "test -d .braid || braid init"); | |
| 425 | + let commit = block_with(&guide, "git add AGENTS.md"); | |
| 426 | + let check = set_up_check(&guide); | |
| 427 | + // The import and AGENTS.md wait on the name and the email, in the line | |
| 428 | + // that checks them, so that the setup stops there however it is run. | |
| 429 | + let gate = setup.len() - 1; | |
| 430 | + assert!( | |
| 431 | + setup[gate].starts_with("if grep -q '^name = .' .braid/config"), | |
| 432 | + "{setup:?}" | |
| 433 | + ); | |
| 347 | 434 | for identity in [Some(("Ada Lovelace", "ada@example.org")), None] { |
| 348 | 435 | let temp = tempfile::tempdir().unwrap(); |
| 349 | 436 | let dir = fs::canonicalize(temp.path()).unwrap().join("project"); |
| 350 | - let config = git_project(&dir, identity); | |
| 437 | + let config = git_project(&dir, "main", identity); | |
| 438 | + assert!(!shell(&dir, &config, &check).status.success()); | |
| 351 | 439 | // Each line in a shell of its own, as written: only the check fails |
| 352 | - // where git has no identity, and nothing says why but the guide. | |
| 440 | + // where git has no identity. | |
| 353 | 441 | let run = || -> Vec<Option<i32>> { |
| 354 | 442 | setup |
| 355 | 443 | .iter() |
| 356 | 444 | .map(|line| shell(&dir, &config, line).status.code()) |
| 357 | 445 | .collect() |
| 358 | 446 | }; |
| 359 | - let failing = |index: usize| Some(i32::from(identity.is_none() && index == check)); | |
| 447 | + let failing = |index: usize| Some(i32::from(identity.is_none() && index == gate)); | |
| 360 | 448 | assert_eq!(run(), (0..setup.len()).map(failing).collect::<Vec<_>>()); |
| 361 | - assert!(read(&dir, "AGENTS.md").contains(START)); | |
| 362 | - let commit = block_with(&part_one(), "git add AGENTS.md"); | |
| 363 | 449 | let written = read(&dir, ".braid/config"); |
| 364 | 450 | let Some((name, email)) = identity else { |
| 365 | 451 | assert_eq!(written, "name = \nemail = \n"); |
| 366 | - // Every commit and landing would fail: a session's status says | |
| 367 | - // so first. | |
| 368 | - shell_ok(&dir, &config, "braid workspace add agent-1 --track main"); | |
| 369 | - let workspace = dir.join(".braid/work/agent-1"); | |
| 370 | - assert_eq!(status(&workspace)["blocking"][0]["reason"], "author"); | |
| 371 | - // Fixed as the guide says, the setup runs again from the top | |
| 372 | - // without a failure, and git's commit is signed as braid's | |
| 373 | - // changesets are, not as git would guess. | |
| 374 | - for line in block_with(&part_one(), "git config user.name") { | |
| 452 | + // The setup says why it stopped, and has imported nothing and | |
| 453 | + // written no AGENTS.md, whether its lines run one at a time or | |
| 454 | + // as one script, as a harness may run a block. | |
| 455 | + let stopped = shell(&dir, &config, &setup[gate]); | |
| 456 | + assert_eq!(stopped.status.code(), Some(1)); | |
| 457 | + let said = String::from_utf8_lossy(&stopped.stderr); | |
| 458 | + assert!(said.contains("ask the user who signs"), "{said}"); | |
| 459 | + let script = shell(&dir, &config, &setup.join("\n")); | |
| 460 | + assert_eq!(script.status.code(), Some(1)); | |
| 461 | + assert_eq!(shell_ok(&dir, &config, "braid refs"), ""); | |
| 462 | + assert!(!dir.join("AGENTS.md").exists()); | |
| 463 | + // The commit block, run all the same, commits nothing: git | |
| 464 | + // refuses to make up who signs, and the check still fails. | |
| 465 | + fs::write(dir.join("AGENTS.md"), "# Rules\n").unwrap(); | |
| 466 | + let script = shell(&dir, &config, &commit.join("\n")); | |
| 467 | + assert_eq!(script.status.code(), Some(1)); | |
| 468 | + assert_eq!(shell_ok(&dir, &config, "git log --format=%s"), "First\n"); | |
| 469 | + shell_ok(&dir, &config, "git reset -q && rm AGENTS.md"); | |
| 470 | + // Fixed as the guide says, the setup runs again from its first | |
| 471 | + // line without a failure, and git's commit is signed as braid's | |
| 472 | + // changesets are. | |
| 473 | + for line in block_with(&guide, "git config user.name") { | |
| 375 | 474 | let line = line |
| 376 | 475 | .replace("<name>", "Grace Hopper") |
| 377 | 476 | .replace("<email>", "grace@example.org"); |
| @@ -382,7 +481,6 @@ | ||
| 382 | 481 | read(&dir, ".braid/config"), |
| 383 | 482 | "name = Grace Hopper\nemail = grace@example.org\n" |
| 384 | 483 | ); |
| 385 | - assert_eq!(status(&workspace)["blocking"], serde_json::json!([])); | |
| 386 | 484 | for line in &commit { |
| 387 | 485 | shell_ok(&dir, &config, line); |
| 388 | 486 | } |
| @@ -390,16 +488,124 @@ | ||
| 390 | 488 | shell_ok(&dir, &config, "git log -1 --format='%an <%ae>'"), |
| 391 | 489 | "Grace Hopper <grace@example.org>\n" |
| 392 | 490 | ); |
| 491 | + assert_eq!(shell_ok(&dir, &config, &check), SET_UP); | |
| 393 | 492 | continue; |
| 394 | 493 | }; |
| 395 | 494 | assert_eq!(written, format!("name = {name}\nemail = {email}\n")); |
| 396 | - for line in &commit { | |
| 397 | - shell_ok(&dir, &config, line); | |
| 398 | - } | |
| 399 | - // Running it again changes nothing. | |
| 495 | + assert!(read(&dir, "AGENTS.md").contains(START)); | |
| 496 | + // Written but not committed, the section is not on braid's branch | |
| 497 | + // yet: braid is not set up. | |
| 498 | + assert!(!shell(&dir, &config, &check).status.success()); | |
| 499 | + let said: Vec<String> = commit | |
| 500 | + .iter() | |
| 501 | + .map(|line| shell_ok(&dir, &config, line)) | |
| 502 | + .collect(); | |
| 503 | + assert_eq!(said.last().map(String::as_str), Some(SET_UP)); | |
| 504 | + // Running the setup again changes nothing. | |
| 400 | 505 | assert!(run().iter().all(|code| *code == Some(0))); |
| 401 | 506 | assert_eq!(read(&dir, ".braid/config"), written); |
| 507 | + // Without anyone to sign, braid is not set up either, and the setup | |
| 508 | + // run again puts that right. | |
| 509 | + fs::remove_file(dir.join(".braid/config")).unwrap(); | |
| 510 | + assert!(!shell(&dir, &config, &check).status.success()); | |
| 511 | + assert!(run().iter().all(|code| *code == Some(0))); | |
| 512 | + assert_eq!(shell_ok(&dir, &config, &check), SET_UP); | |
| 513 | + } | |
| 514 | +} | |
| 515 | + | |
| 516 | +#[test] | |
| 517 | +fn a_session_names_who_signs_in_the_config_of_the_project_root() { | |
| 518 | + let temp = tempfile::tempdir().unwrap(); | |
| 519 | + let dir = fs::canonicalize(temp.path()).unwrap().join("project"); | |
| 520 | + let config = git_project(&dir, "main", Some(("Ada Lovelace", "ada@example.org"))); | |
| 521 | + for line in block_with(&part_one(), "test -d .braid || braid init") { | |
| 522 | + shell_ok(&dir, &config, &line); | |
| 523 | + } | |
| 524 | + // Nobody signs: the session's status says so first. | |
| 525 | + fs::write(dir.join(".braid/config"), "name = \nemail = \n").unwrap(); | |
| 526 | + shell_ok(&dir, &config, "braid workspace add agent-1 --track main"); | |
| 527 | + let workspace = dir.join(".braid/work/agent-1"); | |
| 528 | + assert_eq!(status(&workspace)["blocking"][0]["reason"], "author"); | |
| 529 | + // In the workspace, `.braid` is a file: the config the section means | |
| 530 | + // is the project root's, where the lines it gives, added after the | |
| 531 | + // empty ones, name who signs. | |
| 532 | + assert!(workspace.join(".braid").is_file()); | |
| 533 | + let section = section().split_whitespace().collect::<Vec<_>>().join(" "); | |
| 534 | + assert!( | |
| 535 | + section.contains( | |
| 536 | + "write the answer into `.braid/config` in the project root, the one file there you may edit, as `name = <name>` and `email = <email>` lines" | |
| 537 | + ), | |
| 538 | + "{section}" | |
| 539 | + ); | |
| 540 | + let mut file = fs::OpenOptions::new() | |
| 541 | + .append(true) | |
| 542 | + .open(dir.join(".braid/config")) | |
| 543 | + .unwrap(); | |
| 544 | + std::io::Write::write_all( | |
| 545 | + &mut file, | |
| 546 | + b"name = Grace Hopper\nemail = grace@example.org\n", | |
| 547 | + ) | |
| 548 | + .unwrap(); | |
| 549 | + assert_eq!(status(&workspace)["blocking"], serde_json::json!([])); | |
| 550 | +} | |
| 551 | + | |
| 552 | +#[test] | |
| 553 | +fn the_setup_runs_as_written_where_the_branch_is_master() { | |
| 554 | + let temp = tempfile::tempdir().unwrap(); | |
| 555 | + let parent = fs::canonicalize(temp.path()).unwrap(); | |
| 556 | + let dir = parent.join("project"); | |
| 557 | + let config = git_project(&dir, "master", Some(("Ada Lovelace", "ada@example.org"))); | |
| 558 | + let guide = part_one(); | |
| 559 | + let check = set_up_check(&guide); | |
| 560 | + // The setup, its commit, and a remote made where there is none, each | |
| 561 | + // line as written. | |
| 562 | + for first in [ | |
| 563 | + "test -d .braid || braid init", | |
| 564 | + "git add AGENTS.md", | |
| 565 | + "git init --bare -b", | |
| 566 | + ] { | |
| 567 | + for line in block_with(&guide, first) { | |
| 568 | + shell_ok(&dir, &config, &line); | |
| 569 | + } | |
| 570 | + } | |
| 571 | + assert_eq!(shell_ok(&dir, &config, &check), SET_UP); | |
| 572 | + let rules = read(&dir, "AGENTS.md"); | |
| 573 | + assert!(rules.contains("--track master\n"), "{rules}"); | |
| 574 | + // The new remote's HEAD names the branch, so that a clone checks it | |
| 575 | + // out, with the setup's commit. | |
| 576 | + let bare = parent.join("project.git"); | |
| 577 | + assert_eq!( | |
| 578 | + shell_ok(&bare, &config, "git symbolic-ref HEAD"), | |
| 579 | + "refs/heads/master\n" | |
| 580 | + ); | |
| 581 | + shell_ok(&parent, &config, "git clone -q project.git clone"); | |
| 582 | + assert_eq!(read(&parent.join("clone"), "AGENTS.md"), rules); | |
| 583 | +} | |
| 584 | + | |
| 585 | +#[test] | |
| 586 | +fn the_setup_keeps_braid_out_of_git_without_an_info_directory() { | |
| 587 | + // A template that holds only hooks, as hook managers set one up, gives | |
| 588 | + // repositories with no `.git/info`. | |
| 589 | + let temp = tempfile::tempdir().unwrap(); | |
| 590 | + let root = fs::canonicalize(temp.path()).unwrap(); | |
| 591 | + let template = root.join("template"); | |
| 592 | + fs::create_dir_all(template.join("hooks")).unwrap(); | |
| 593 | + let dir = root.join("project"); | |
| 594 | + let init = format!("git init -q -b main --template='{}'", template.display()); | |
| 595 | + let config = git_project_from(&dir, &init, Some(("Ada Lovelace", "ada@example.org"))); | |
| 596 | + assert!(!dir.join(".git/info").exists()); | |
| 597 | + for line in block_with(&part_one(), "test -d .braid || braid init") { | |
| 598 | + shell_ok(&dir, &config, &line); | |
| 402 | 599 | } |
| 600 | + assert_eq!(read(&dir, ".git/info/exclude"), ".braid\n"); | |
| 601 | + assert_eq!( | |
| 602 | + shell_ok( | |
| 603 | + &dir, | |
| 604 | + &config, | |
| 605 | + "git status --porcelain --untracked-files=all" | |
| 606 | + ), | |
| 607 | + "?? AGENTS.md\n" | |
| 608 | + ); | |
| 403 | 609 | } |
| 404 | 610 | |
| 405 | 611 | /// The line the guides give to keep Python's build output out of a |
| @@ -411,18 +617,21 @@ | ||
| 411 | 617 | let temp = tempfile::tempdir().unwrap(); |
| 412 | 618 | let parent = fs::canonicalize(temp.path()).unwrap(); |
| 413 | 619 | let dir = parent.join("project"); |
| 414 | - let config = git_project(&dir, Some(("Ada Lovelace", "ada@example.org"))); | |
| 620 | + let config = git_project(&dir, "main", Some(("Ada Lovelace", "ada@example.org"))); | |
| 415 | 621 | for line in block_with(&part_one(), "test -d .braid || braid init") { |
| 416 | 622 | shell_ok(&dir, &config, &line); |
| 417 | 623 | } |
| 418 | 624 | let section = section(); |
| 419 | 625 | let sync = block_with(§ion, "braid --agent agent-1 git sync"); |
| 420 | 626 | let recipe = block_with(§ion, "git init --bare"); |
| 421 | - // The guide gives the same lines for a project with no remote. | |
| 422 | - let guide = bash_lines(&part_one()); | |
| 423 | - for line in &recipe { | |
| 424 | - assert!(guide.contains(line), "the guide has no {line:?}"); | |
| 425 | - } | |
| 627 | + // The guide gives the same lines for a project with no remote, with the | |
| 628 | + // branch the shared checkout is on, which the setup has be the main | |
| 629 | + // one, where the section names its branch. | |
| 630 | + let guide: Vec<String> = block_with(&part_one(), "git init --bare -b") | |
| 631 | + .iter() | |
| 632 | + .map(|line| line.replace("\"$(git branch --show-current)\"", "main")) | |
| 633 | + .collect(); | |
| 634 | + assert_eq!(guide, recipe); | |
| 426 | 635 | for text in [part_one(), section.clone()] { |
| 427 | 636 | assert!(code_spans(&text).iter().any(|span| span == BRAIDIGNORE)); |
| 428 | 637 | } |
| @@ -493,3 +702,132 @@ | ||
| 493 | 702 | assert!(!parent.join("clone").join(kept_out).exists(), "{kept_out}"); |
| 494 | 703 | } |
| 495 | 704 | } |
| 705 | + | |
| 706 | +/// The heading of the guide that says how to keep the git remote in step, | |
| 707 | +/// and what to do when a sync fails. | |
| 708 | +const SYNC_HEADING: &str = "Keeping the git remote up to date"; | |
| 709 | + | |
| 710 | +#[test] | |
| 711 | +fn the_section_sends_a_failed_sync_to_the_guide() { | |
| 712 | + assert!(part_one().contains(&format!("\n### {SYNC_HEADING}\n"))); | |
| 713 | + let section = section().split_whitespace().collect::<Vec<_>>().join(" "); | |
| 714 | + for said in [ | |
| 715 | + "If the sync exits with 2 (`conflicts`)", | |
| 716 | + &format!("as <https://braid.elffuss.com/agents.md> shows under \"{SYNC_HEADING}\""), | |
| 717 | + "With `remote_moved` (exit status 1), sync again; with `rejected`, ask the user.", | |
| 718 | + "If `git pull --ff-only` refuses,", | |
| 719 | + ] { | |
| 720 | + assert!(section.contains(said), "{said}: {section}"); | |
| 721 | + } | |
| 722 | +} | |
| 723 | + | |
| 724 | +#[test] | |
| 725 | +fn a_sync_conflict_is_merged_in_git_as_the_guide_says() { | |
| 726 | + let temp = tempfile::tempdir().unwrap(); | |
| 727 | + let parent = fs::canonicalize(temp.path()).unwrap(); | |
| 728 | + let dir = parent.join("project"); | |
| 729 | + let config = git_project(&dir, "main", Some(("Ada Lovelace", "ada@example.org"))); | |
| 730 | + let guide = part_one(); | |
| 731 | + // A remote, the setup and its commit, each line as written, and a sync | |
| 732 | + // that takes the commit to the remote. | |
| 733 | + for first in [ | |
| 734 | + "git init --bare -b", | |
| 735 | + "test -d .braid || braid init", | |
| 736 | + "git add AGENTS.md", | |
| 737 | + "braid --agent agent-1 git sync", | |
| 738 | + ] { | |
| 739 | + for line in block_with(&guide, first) { | |
| 740 | + shell_ok(&dir, &config, &line); | |
| 741 | + } | |
| 742 | + } | |
| 743 | + let sync = block_with(&guide, "braid --agent agent-1 git sync") | |
| 744 | + .into_iter() | |
| 745 | + .find(|line| !line.contains("--dry-run") && line.starts_with("braid ")) | |
| 746 | + .unwrap(); | |
| 747 | + | |
| 748 | + // A session lands an edit of a line that someone else edits and pushes. | |
| 749 | + shell_ok(&dir, &config, "braid workspace add agent-1 --track main"); | |
| 750 | + let workspace = dir.join(".braid/work/agent-1"); | |
| 751 | + fs::write(workspace.join("notes.txt"), "one\ntwo, the agent's\n").unwrap(); | |
| 752 | + for line in [ | |
| 753 | + "braid --agent agent-1 commit -m 'The agent edits notes'", | |
| 754 | + "braid --agent agent-1 land", | |
| 755 | + ] { | |
| 756 | + shell_ok(&workspace, &config, line); | |
| 757 | + } | |
| 758 | + shell_ok(&parent, &config, "git clone -q project.git person"); | |
| 759 | + let person = parent.join("person"); | |
| 760 | + fs::write(person.join("notes.txt"), "one\ntwo, the person's\n").unwrap(); | |
| 761 | + shell_ok( | |
| 762 | + &person, | |
| 763 | + &config, | |
| 764 | + "git commit -q -am 'The person edits notes'", | |
| 765 | + ); | |
| 766 | + shell_ok(&person, &config, "git push -q"); | |
| 767 | + | |
| 768 | + // The sync stops, and says where the steps are. | |
| 769 | + let stopped = shell(&dir, &config, &sync); | |
| 770 | + assert_eq!(stopped.status.code(), Some(2)); | |
| 771 | + let said = String::from_utf8_lossy(&stopped.stdout); | |
| 772 | + assert!(said.contains("CONTENT notes.txt"), "{said}"); | |
| 773 | + assert!( | |
| 774 | + said.contains(&format!( | |
| 775 | + "https://braid.elffuss.com/agents.md shows how, under \"{SYNC_HEADING}\"" | |
| 776 | + )), | |
| 777 | + "{said}" | |
| 778 | + ); | |
| 779 | + | |
| 780 | + // The guide's steps, with the conflict fixed where git stops. | |
| 781 | + let recipe = block_with(&guide, "git init --bare .braid/export.git"); | |
| 782 | + let merge = recipe | |
| 783 | + .iter() | |
| 784 | + .position(|line| line.starts_with("git merge --no-edit origin/main")) | |
| 785 | + .expect("the remote's branch is merged into braid's"); | |
| 786 | + assert_eq!( | |
| 787 | + recipe[merge + 1], | |
| 788 | + "# if it stopped: fix those files and git add them, then git commit --no-edit --cleanup=strip" | |
| 789 | + ); | |
| 790 | + for (index, line) in recipe.iter().enumerate() { | |
| 791 | + let out = shell(&dir, &config, line); | |
| 792 | + if index == merge { | |
| 793 | + assert_eq!(out.status.code(), Some(1), "git stops at the conflict"); | |
| 794 | + fs::write(dir.join("notes.txt"), "one\ntwo, both\n").unwrap(); | |
| 795 | + shell_ok(&dir, &config, "git add notes.txt"); | |
| 796 | + shell_ok(&dir, &config, "git commit -q --no-edit --cleanup=strip"); | |
| 797 | + continue; | |
| 798 | + } | |
| 799 | + assert!( | |
| 800 | + out.status.success(), | |
| 801 | + "{line}: {}", | |
| 802 | + String::from_utf8_lossy(&out.stderr) | |
| 803 | + ); | |
| 804 | + } | |
| 805 | + // The merge's message names the branch, not the remote's address, and | |
| 806 | + // braid's branch is its first parent; braid's main and the remote's are | |
| 807 | + // the merge. | |
| 808 | + let merged = shell_ok(&dir, &config, "git log -1 --format=%B"); | |
| 809 | + assert_eq!( | |
| 810 | + merged.trim_end(), | |
| 811 | + "Merge remote-tracking branch 'origin/main'" | |
| 812 | + ); | |
| 813 | + assert_eq!( | |
| 814 | + shell_ok(&dir, &config, "git log -1 --format=%s HEAD^1"), | |
| 815 | + "The agent edits notes\n" | |
| 816 | + ); | |
| 817 | + let head = shell_ok(&dir, &config, "git rev-parse HEAD"); | |
| 818 | + assert_eq!( | |
| 819 | + shell_ok(&parent.join("project.git"), &config, "git rev-parse main"), | |
| 820 | + head | |
| 821 | + ); | |
| 822 | + assert!( | |
| 823 | + shell_ok(&dir, &config, "braid log main -n 1") | |
| 824 | + .contains("Merge remote-tracking branch 'origin/main'") | |
| 825 | + ); | |
| 826 | + // The session carries on from the merge, and the next sync has nothing | |
| 827 | + // to do. | |
| 828 | + shell_ok(&workspace, &config, "braid --agent agent-1 update"); | |
| 829 | + assert_eq!(status(&workspace)["behind_by"], 0); | |
| 830 | + assert_eq!(read(&workspace, "notes.txt"), "one\ntwo, both\n"); | |
| 831 | + assert!(shell_ok(&dir, &config, &sync).contains("up to date")); | |
| 832 | + assert!(!dir.join(".braid/export.git").exists()); | |
| 833 | +} |
modified crates/repo/src/sync.rs +5 −5
| @@ -176,11 +176,11 @@ | ||
| 176 | 176 | /// Keeps the braid branch `branch` and a branch of the git remote |
| 177 | 177 | /// `remote` in step: fetches and imports the remote branch, then |
| 178 | 178 | /// fast-forwards the braid branch, or pushes it (merging first when both |
| 179 | - /// moved) as a fast-forward with a lease. Braid never force-pushes. | |
| 180 | - /// Operations are recorded by `agent`, who is also the committer of a | |
| 181 | - /// merge, with the `email` of the repository's [`Config`](crate::Config) | |
| 182 | - /// or `<agent>@example.org`, and whom the merge's | |
| 183 | - /// [`AGENT`] field names. | |
| 179 | + /// moved) as a fast-forward with a lease, so that the remote's history is | |
| 180 | + /// never rewritten. Operations are recorded by `agent`, who is also the | |
| 181 | + /// committer of a merge, with the `email` of the repository's | |
| 182 | + /// [`Config`](crate::Config) or `<agent>@example.org`, and whom the | |
| 183 | + /// merge's [`AGENT`] field names. | |
| 184 | 184 | /// |
| 185 | 185 | /// # The mirror |
| 186 | 186 | /// |
modified docs/assets/braid-animated.svg +2 −0
| @@ -1,3 +1,5 @@ | ||
| 1 | +<!-- SPDX-License-Identifier: Apache-2.0 | |
| 2 | + Copyright (c) 2026 UtopiaIA --> | |
| 1 | 3 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 96" width="320" height="96" role="img" aria-label="Three strands braided together"> |
| 2 | 4 | <title>elffuss-braid</title> |
| 3 | 5 | <style> |
modified docs/design.md +16 −4
| @@ -391,7 +391,19 @@ | ||
| 391 | 391 | `git pull --ff-only`. The section has a session that finishes say so to |
| 392 | 392 | the user, and offer to run them, rather than leave the user looking at |
| 393 | 393 | files that did not change; where the project has no git remote, it says |
| 394 | - so, and offers to make a bare one next to the project first. | |
| 394 | + so, and offers to make a bare one next to the project first. When the | |
| 395 | + sync stops on conflicts, the section says that the merge is made with | |
| 396 | + git, in the user's checkout, and points to the guide's steps, as the | |
| 397 | + text `git sync` prints does. | |
| 398 | +- **Nobody signs by guesswork.** The guide's setup writes `.braid/config` | |
| 399 | + from git's `user.name` and `user.email`, and stops before it imports | |
| 400 | + anything while either is missing, rather than let every commit and | |
| 401 | + landing fail later with "no author". Its own commit runs git with | |
| 402 | + `user.useConfigOnly`, so that git refuses rather than sign with a name | |
| 403 | + and an address made up from the machine's user and host, which the | |
| 404 | + first sync would publish. Its check for a finished setup asks braid's | |
| 405 | + copy of the branch for the section, so that a setup that stopped half | |
| 406 | + way is run again rather than taken for done. | |
| 395 | 407 | |
| 396 | 408 | ## Git bridge |
| 397 | 409 | |
| @@ -407,9 +419,9 @@ | ||
| 407 | 419 | `remote/<label>/<branch>` for where the branches of git remotes were last |
| 408 | 420 | seen. A git branch named like one of them is imported under its full name, |
| 409 | 421 | below `git/`. |
| 410 | -- Sync fetches and imports first, then pushes with a lease, as a fast-forward. | |
| 411 | - Braid never force-pushes. The push itself runs the `git` binary as a | |
| 412 | - subprocess, since gitoxide does not push yet. | |
| 422 | +- Sync fetches and imports first, then pushes with a lease, as a fast-forward: | |
| 423 | + the remote's history is never rewritten. The push itself runs the `git` | |
| 424 | + binary as a subprocess, since gitoxide does not push yet. | |
| 413 | 425 | |
| 414 | 426 | ### Sync |
| 415 | 427 |
modified site/agents.md +115 −78
| @@ -47,78 +47,92 @@ | ||
| 47 | 47 | |
| 48 | 48 | ## Is it installed, and set up here? |
| 49 | 49 | |
| 50 | +In the project root, on its main branch: | |
| 51 | + | |
| 50 | 52 | ```bash |
| 51 | 53 | braid --version # "braid 0.0.2", or newer, once it is installed |
| 52 | -braid refs # in the project root: its branches, once it is set up | |
| 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" | |
| 53 | 55 | ``` |
| 54 | 56 | |
| 55 | 57 | - Before braid is installed, `braid --version` fails with "command not |
| 56 | 58 | found", as it does while cargo's bin directory is not on `PATH`. An older |
| 57 | 59 | braid, or one that says `agents` is not a subcommand, needs the install |
| 58 | 60 | command again. |
| 59 | -- In a project where braid is not set up, `braid refs` fails with "not | |
| 60 | - inside a braid repository". Where it lists the project's branches and | |
| 61 | - `AGENTS.md` has a braid section (a `<!-- braid:start -->` line), braid is | |
| 62 | - set up: skip to "Every agent session, from then on". It lists braid's own | |
| 63 | - refs too: `braid/git-map`, the project's tags as `tags/<name>`, and once | |
| 64 | - a sync has run, `remote/<label>/<branch>`. | |
| 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. | |
| 65 | 68 | |
| 66 | 69 | ## Set up a project |
| 67 | 70 | |
| 68 | 71 | First read the project's `AGENTS.md`, `CLAUDE.md` and the like for rules |
| 69 | 72 | about git: branches, pull requests, how to commit. Look too for what braid |
| 70 | -does not run: git hooks (in `.git/hooks`, or where | |
| 71 | -`git config core.hooksPath` says; the `*.sample` files git puts in | |
| 72 | -`.git/hooks` never run, and do not count), Git LFS (`filter=lfs` in | |
| 73 | -`.gitattributes`: braid sees the pointer files, not the content) and a main | |
| 74 | -branch that takes changes only through pull requests. Then list the | |
| 75 | -project's git remotes (`git remote -v`): what agents land reaches the | |
| 76 | -user's checkout through one, which the commands here call `origin`; if it | |
| 77 | -has another name, write that instead. Tell the user what you found, and | |
| 78 | -if any of it clashes with agents landing on the main branch, ask how to | |
| 79 | -go on before you set anything up. With no remote at all, what agents land | |
| 80 | -stays in braid: offer to make one (see "No remote?" below). And if the | |
| 81 | -project has no `CLAUDE.md`, ask whether to add one, since Claude Code | |
| 82 | -reads `CLAUDE.md` rather than `AGENTS.md`: with a yes, run | |
| 83 | -`touch CLAUDE.md` before the commands below, and `braid agents init` makes | |
| 84 | -it include `AGENTS.md`. | |
| 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`. | |
| 85 | 99 | |
| 86 | 100 | Then work in the root of the project's git checkout, on its main branch, |
| 87 | 101 | with nothing to commit (`git status` shows no staged or modified files; |
| 88 | 102 | untracked files do not matter) and nothing new to pull |
| 89 | 103 | (`git pull --ff-only`; skip it when the branch has no upstream, which is |
| 90 | 104 | when `git rev-parse --abbrev-ref '@{u}'` fails). In a shallow clone, run |
| 91 | -`git fetch --unshallow` first: braid imports the whole history. The | |
| 92 | -commands say `main`; if the project's main branch has another name, such | |
| 93 | -as `master`, write that instead. Every line is safe to run again, so after | |
| 94 | -a failure, start again from the top. | |
| 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. | |
| 95 | 109 | |
| 96 | 110 | ```bash |
| 97 | 111 | test -d .braid || braid init # .braid/: the store and the agents' workspaces |
| 112 | +mkdir -p "$(git rev-parse --git-path info)" | |
| 98 | 113 | grep -qsxF .braid "$(git rev-parse --git-path info/exclude)" || echo .braid >> "$(git rev-parse --git-path info/exclude)" |
| 99 | 114 | test -f .braid/config || printf 'name = %s\nemail = %s\n' "$(git config user.name)" "$(git config user.email)" > .braid/config |
| 100 | -grep -q '^name = .' .braid/config && grep -q '^email = .' .braid/config # fails without a name and an email | |
| 101 | -braid git import . # the project's whole history: every local branch and tag | |
| 102 | -braid agents init # the rules for agents, in AGENTS.md | |
| 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 | |
| 103 | 116 | ``` |
| 104 | 117 | |
| 105 | -- The second line makes git ignore every `.braid` in this checkout, and | |
| 106 | - only in this one: braid's directory, and the `.braid` file that marks | |
| 107 | - each workspace, so that nothing of braid's is ever committed with git. | |
| 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. | |
| 108 | 122 | - `.braid/config` names who signs the changesets agents make, here the |
| 109 | - same person as git's commits. The line after it fails, with exit status | |
| 110 | - 1 and nothing printed, while the file lacks a name or an email, as it | |
| 111 | - does when git has no `user.name` or `user.email`: every commit and | |
| 112 | - landing would then fail with "no author", and the `git commit` below | |
| 113 | - would fail too, or sign with a name and an address that git guesses | |
| 114 | - from the machine. Ask the user for the name and the e-mail address to | |
| 115 | - use. With their answer, set them for this checkout, and let the setup | |
| 116 | - write the file anew: | |
| 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: | |
| 117 | 131 | |
| 118 | 132 | ```bash |
| 119 | 133 | git config user.name "<name>" |
| 120 | 134 | git config user.email "<email>" |
| 121 | - rm .braid/config # then start again from the top | |
| 135 | + rm .braid/config # then run the setup again from its first line | |
| 122 | 136 | ``` |
| 123 | 137 | |
| 124 | 138 | - Most harnesses read `AGENTS.md`. Claude Code reads `CLAUDE.md` instead, |
| @@ -126,7 +140,9 @@ | ||
| 126 | 140 | `@AGENTS.md` to each of them that exists, so that they read the section |
| 127 | 141 | too. In Claude Code, each braid command asks for permission unless the |
| 128 | 142 | project allows it: offer to add `"Bash(braid:*)"` to `permissions.allow` |
| 129 | - in `.claude/settings.json`. | |
| 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. | |
| 130 | 146 | - `braid agents init` writes a section into `AGENTS.md`, creating the file |
| 131 | 147 | if there is none, between a `<!-- braid:start -->` line and a |
| 132 | 148 | `<!-- braid:end -->` line. The section tells every agent session to work |
| @@ -148,14 +164,23 @@ | ||
| 148 | 164 | git add AGENTS.md |
| 149 | 165 | if [ -f CLAUDE.md ]; then git add CLAUDE.md; fi |
| 150 | 166 | if [ -f GEMINI.md ]; then git add GEMINI.md; fi |
| 151 | -git diff --cached --quiet || git commit -m "Set up braid for agents" | |
| 152 | -braid git import . # braid's main takes the commit | |
| 153 | -braid log main -n 1 # and shows it | |
| 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" | |
| 154 | 170 | ``` |
| 155 | 171 | |
| 156 | -If `AGENTS.md`, `CLAUDE.md` or `GEMINI.md` is a symbolic link, | |
| 157 | -`braid agents init` writes the file it points to, and names it: `git add` | |
| 158 | -that file as well. | |
| 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. | |
| 159 | 184 | |
| 160 | 185 | ## Every agent session, from then on |
| 161 | 186 | |
| @@ -224,20 +249,21 @@ | ||
| 224 | 249 | workspace's root. Only `.gitignore` and `.braidignore` apply in a |
| 225 | 250 | workspace, not `.git/info/exclude` or a global excludes file: anything |
| 226 | 251 | else that must stay local goes in `.braidignore` too. Braid runs no git |
| 227 | - hooks, so run the project's checks yourself before you land. `land` puts | |
| 228 | - the workspace's changesets on `main`, as a fast-forward or rebased onto | |
| 229 | - whatever landed first. | |
| 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. | |
| 230 | 255 | - **Before a new task**, `braid --agent agent-1 update` brings the |
| 231 | 256 | workspace onto `main`. `status --json` says how far behind it is |
| 232 | 257 | (`behind_by`). |
| 233 | 258 | - **When the session finishes**, what it landed is on braid's `main` only. |
| 234 | 259 | The user's checkout and the git remote get it with `braid git sync`, then |
| 235 | 260 | `git pull --ff-only`, both from the project root (see "Keeping the git |
| 236 | - remote up to date"). The session tells the user so, and offers to run | |
| 237 | - them: when to sync is the user's call. Where `git remote get-url origin` | |
| 238 | - fails, the project has no remote of that name: the session asks the | |
| 239 | - user which of those `git remote` lists to sync with, or, where it lists | |
| 240 | - none, says so and offers to make one first (see "No remote?"). | |
| 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?"). | |
| 241 | 267 | - **Done**: once everything has landed, `braid workspace remove agent-1` |
| 242 | 268 | from the project root. It refuses while the workspace holds work that |
| 243 | 269 | has not landed. |
| @@ -249,8 +275,11 @@ | ||
| 249 | 275 | the `name` and `email` in `.braid/config`. With neither, `commit`, |
| 250 | 276 | `land` and `update` fail with "no author", and `braid status` lists it |
| 251 | 277 | first among what stops a commit: the session asks the user who signs, |
| 252 | - and writes the answer into `.braid/config` as `name = <name>` and | |
| 253 | - `email = <email>` lines. | |
| 278 | + and writes the answer into `.braid/config` in the project root (the one | |
| 279 | + file there that a session may edit) as `name = <name>` and | |
| 280 | + `email = <email>` lines. The merges that `braid git sync` makes are | |
| 281 | + signed otherwise: by the `--agent` that ran the sync, with the email in | |
| 282 | + `.braid/config`. | |
| 254 | 283 | - New files that look like secrets (`.env*`, `*.pem`, `id_*`) or are larger |
| 255 | 284 | than 1 MiB are held back until `braid track <path>`: `commit` refuses, |
| 256 | 285 | naming them, and `--force` leaves them out. Never `braid track` a secret: |
| @@ -284,14 +313,15 @@ | ||
| 284 | 313 | together: it fetches the remote's branch and imports it, then fast-forwards |
| 285 | 314 | braid's branch when only the remote moved, pushes braid's branch when only |
| 286 | 315 | braid moved, and when both moved, merges them and pushes the merge. The |
| 287 | -push is a fast-forward with a lease on what was just fetched, so the | |
| 288 | -remote's history is never rewritten; braid never force-pushes, and runs no | |
| 289 | -git hooks. It runs the `git` binary with your environment, so it needs the | |
| 290 | -network and the credentials `git push` uses. Run it from the project root, | |
| 291 | -when the remote should have what landed: who runs it, and when, is the | |
| 292 | -user's call. Braid pushes to the remote's address, so the shared | |
| 293 | -checkout's own record of the remote (`origin/main`) does not move: | |
| 294 | -`git pull --ff-only` brings the checkout up to date. | |
| 316 | +push is a fast-forward, with a lease on what was just fetched, so the | |
| 317 | +remote's history is never rewritten. Braid runs no git hooks. It runs the | |
| 318 | +`git` binary with your environment, so it needs the network and the | |
| 319 | +credentials `git push` uses. Run it from the project root, when the | |
| 320 | +remote should have what landed: who runs it, and when, is the user's | |
| 321 | +call. Braid pushes to the remote's address, so the shared checkout's own | |
| 322 | +record of the remote (`origin/main`) does not move: `git pull --ff-only` | |
| 323 | +brings the checkout up to date. The commands here say `main`: write the | |
| 324 | +branch that the section names. | |
| 295 | 325 | |
| 296 | 326 | ```bash |
| 297 | 327 | braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main --dry-run --json |
| @@ -320,9 +350,10 @@ | ||
| 320 | 350 | git fetch .braid/export.git main |
| 321 | 351 | git merge --ff-only FETCH_HEAD # the shared checkout takes braid's main |
| 322 | 352 | git fetch origin main |
| 323 | - git merge FETCH_HEAD # the remote's: fix the conflicts, then git commit | |
| 324 | - git push | |
| 325 | - braid git sync "$(git remote get-url origin)" --branch main | |
| 353 | + git merge --no-edit origin/main # the remote's: git stops at conflicts | |
| 354 | + # if it stopped: fix those files and git add them, then git commit --no-edit --cleanup=strip | |
| 355 | + git push origin main | |
| 356 | + braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main | |
| 326 | 357 | rm -rf .braid/export.git |
| 327 | 358 | ``` |
| 328 | 359 | |
| @@ -331,17 +362,21 @@ | ||
| 331 | 362 | braid's branch as the first parent: braid follows a branch's first |
| 332 | 363 | parents to tell what a workspace has landed, so the workspaces carry on |
| 333 | 364 | from the merge. |
| 365 | +- If `git pull --ff-only` refuses, the shared checkout has commits of its | |
| 366 | + own that the remote does not have, and what to do with them is the | |
| 367 | + user's call. `git pull --rebase` puts them on top of what braid pushed; | |
| 368 | + then `git push`, and a sync brings them into braid. | |
| 334 | 369 | |
| 335 | 370 | No remote? Any bare repository will do. With the user's yes, these lines, |
| 336 | -run in the shared checkout, make one next to the project, named after it | |
| 337 | -(`../<project>.git`, by an absolute path, which braid reads the same from | |
| 338 | -any directory), and push the main branch to it. If something has that | |
| 339 | -name already, choose another. | |
| 371 | +run in the shared checkout on its main branch, make one next to the | |
| 372 | +project, named after it (`../<project>.git`, by an absolute path, which | |
| 373 | +braid reads the same from any directory), and push the main branch to it. | |
| 374 | +If something has that name already, choose another. | |
| 340 | 375 | |
| 341 | 376 | ```bash |
| 342 | -git init --bare -b main "$PWD.git" | |
| 377 | +git init --bare -b "$(git branch --show-current)" "$PWD.git" | |
| 343 | 378 | git remote add origin "$PWD.git" |
| 344 | -git push -u origin main | |
| 379 | +git push -u origin "$(git branch --show-current)" | |
| 345 | 380 | ``` |
| 346 | 381 | |
| 347 | 382 | ## Undoing |
| @@ -350,7 +385,8 @@ | ||
| 350 | 385 | first, with the agent that made it. `braid --agent agent-1 undo` reverts |
| 351 | 386 | the newest one that is not undone yet, whoever made it, so read the log |
| 352 | 387 | first. A landing undone leaves its changeset in the workspace that made |
| 353 | - it, ready to land again. | |
| 388 | + it, ready to land again. A sync undone moves braid's refs back, but not | |
| 389 | + the git remote: what it pushed stays there. | |
| 354 | 390 | - A change that landed under other changes cannot be undone that way. |
| 355 | 391 | There is no revert command yet: land a change that puts the files back. |
| 356 | 392 | - To take braid out of a project: land what the workspaces hold, sync it |
| @@ -366,8 +402,9 @@ | ||
| 366 | 402 | ## What not to do |
| 367 | 403 | |
| 368 | 404 | - Do not edit files, `git add`, `git commit`, `git push` or `git pull` in |
| 369 | - the shared checkout while you work: only setting up, syncing and merging | |
| 370 | - a sync conflict touch it, as above. | |
| 405 | + the shared checkout while you work: only setting up, syncing, merging a | |
| 406 | + sync conflict and naming who signs in `.braid/config` touch it, as | |
| 407 | + above. | |
| 371 | 408 | - Do not run git in a workspace, or get around the `.git` file that stops |
| 372 | 409 | it there. |
| 373 | 410 | - Do not share a workspace between sessions, or work in another session's |
modified site/index.html +4 −4
| @@ -405,7 +405,7 @@ | ||
| 405 | 405 | <h2 id="ask-title"><span data-l="en" lang="en">Ask your agent</span><span data-l="es" lang="es">Pídeselo a tu agente</span></h2> |
| 406 | 406 | </div> |
| 407 | 407 | <p data-l="en" lang="en">Braid comes with instructions written for coding agents. In a project that is a git repository, ask yours, whatever harness runs it:</p> |
| 408 | -<p data-l="es" lang="es">Braid trae instrucciones escritas para agentes de programación. En un proyecto que sea un repositorio de git, pídeselo al tuyo, use el arnés que use:</p> | |
| 408 | +<p data-l="es" lang="es">Braid trae instrucciones escritas para agentes de programación. En un proyecto que sea un repositorio de git, pídeselo al tuyo, sea cual sea la herramienta con la que lo uses:</p> | |
| 409 | 409 | <div class="code prompt" data-l="en" lang="en"> |
| 410 | 410 | <div class="code-bar"><span>prompt</span><button class="copy" type="button" aria-label="Copy the prompt" data-aria-en="Copy the prompt" data-aria-es="Copiar la petición" hidden><span class="c-idle" data-l="en" lang="en">Copy</span><span class="c-idle" data-l="es" lang="es">Copiar</span><span class="c-done" data-l="en" lang="en">Copied</span><span class="c-done" data-l="es" lang="es">Copiado</span></button></div> |
| 411 | 411 | <pre tabindex="0" role="region" aria-label="The prompt for your agent" data-aria-en="The prompt for your agent" data-aria-es="La petición para tu agente"><code>Install braid in this project and set it up for agents, following https://braid.elffuss.com/agents.md (read it whole, with curl -fsSL)</code></pre> |
| @@ -416,8 +416,8 @@ | ||
| 416 | 416 | </div> |
| 417 | 417 | <p data-l="en" lang="en">Your agent installs braid with cargo, tells you what in the project braid does not run, such as git hooks, offers to make a git remote if the project has none, imports the project's git history, and writes the rules for agents into its <code>AGENTS.md</code> with <code>braid agents init</code>. From then on, every agent session works in a braid workspace of its own, where git refuses to run, lands through braid, and tells you when what it landed is waiting for a sync to the git remote. Git stays the source of truth, and in a clone where braid is not set up, agents work with git as before.</p> |
| 418 | 418 | <p data-l="es" lang="es">Tu agente instala braid con cargo, te avisa de lo que braid no ejecuta en el proyecto, como los hooks de git, se ofrece a crearle un remoto de git si no tiene ninguno, importa su historia de git y, con <code>braid agents init</code>, escribe en su <code>AGENTS.md</code> las reglas para los agentes. A partir de ahí, cada sesión trabaja en su propio espacio de trabajo, donde git se niega a funcionar, aterriza sus cambios con braid y te avisa cuando lo que ha aterrizado está pendiente de sincronizar con el remoto de git. Git sigue siendo la fuente de verdad, y en un clon donde braid no está configurado los agentes trabajan con git, como siempre.</p> |
| 419 | -<p class="note" data-l="en" lang="en">The instructions are <a href="agents.md">agents.md</a>, part 1 of the repository's <a href="https://github.com/KikoCis/elffuss-braid/blob/main/AGENTS.md"><code>AGENTS.md</code></a>; there is an <a href="llms.txt">llms.txt</a> too. To do it by hand, follow the same steps in <a href="agents.md">agents.md</a>; the quick start below tries braid on its own repository.</p> | |
| 420 | -<p class="note" data-l="es" lang="es">Las instrucciones son <a href="agents.md">agents.md</a>, la primera parte del <a href="https://github.com/KikoCis/elffuss-braid/blob/main/AGENTS.md"><code>AGENTS.md</code></a> del repositorio, en inglés; también hay un <a href="llms.txt">llms.txt</a>. Para hacerlo a mano, sigue los mismos pasos de <a href="agents.md">agents.md</a>; los primeros pasos, justo debajo, prueban braid con su propio repositorio.</p> | |
| 419 | +<p class="note" data-l="en" lang="en">The instructions are <a href="agents.md">agents.md</a>, part 1 of the repository's <a href="https://github.com/KikoCis/elffuss-braid/blob/main/AGENTS.md"><code>AGENTS.md</code></a>; there is an <a href="llms.txt">llms.txt</a> too. To do it by hand, follow the same steps in <a href="agents.md">agents.md</a>; <a href="#start">Quick start</a>, just below, tries braid on its own repository.</p> | |
| 420 | +<p class="note" data-l="es" lang="es">Las instrucciones son <a href="agents.md">agents.md</a>, la primera parte del <a href="https://github.com/KikoCis/elffuss-braid/blob/main/AGENTS.md"><code>AGENTS.md</code></a> del repositorio, en inglés; también hay un <a href="llms.txt">llms.txt</a>. Para hacerlo a mano, sigue los mismos pasos de <a href="agents.md">agents.md</a>; <a href="#start">«Primeros pasos»</a>, justo debajo, prueba braid con su propio repositorio.</p> | |
| 421 | 421 | </div> |
| 422 | 422 | </section> |
| 423 | 423 | |
| @@ -572,7 +572,7 @@ | ||
| 572 | 572 | </div> |
| 573 | 573 | <p class="licence" data-l="en" lang="en">Braid contains no code from git (GPLv2). It reads and writes git data with gitoxide (MIT or <span class="nw">Apache-2.0</span>); <code>git sync</code> also runs the git binary as a subprocess, to set up its mirror, fetch and push.</p> |
| 574 | 574 | <p class="licence" data-l="es" lang="es">Braid no contiene código de git (GPLv2). Lee y escribe datos de git con gitoxide (MIT o <span class="nw">Apache-2.0</span>); <code>git sync</code> además ejecuta el binario de git como subproceso, para preparar su espejo, hacer fetch y hacer push.</p> |
| 575 | -<p class="next-link"><a href="#autosync"><span data-l="en" lang="en">Automatic sync with git</span><span data-l="es" lang="es">Sincronización automática con git</span></a></p> | |
| 575 | +<p class="next-link"><a href="#autosync"><span data-l="en" lang="en">Coming: automatic sync with git</span><span data-l="es" lang="es">Próximamente: sincronización automática con git</span></a></p> | |
| 576 | 576 | </div> |
| 577 | 577 | </section> |
| 578 | 578 |