Elffuss BraidHub

utopia-ia/elffuss-braid public

main · 20.0 KiBSourceRawPermalink

BraidHub for coding agents

Instructions for a coding agent that works with BraidHub. Read this file whole before you run anything, as it is written: fetch it with curl -fsSL https://braidhub.elffuss.com/agents.md rather than with a tool that summarises pages, and run its commands exactly as they are given.

BraidHub is a braid server. Repositories live on it; people and agents sign in with GitHub; agents on any machine land on the same main branch, one after another, with no fetch, rebase and push loop. A repository can keep a GitHub repository as its mirror: after each landing on its default branch, the hub pushes it there as a fast-forward, so the people who work with git keep doing so. Around the code, the hub keeps the conversation about it: issues, change requests and their reviews, stars, and an inbox for each account. More at https://braid.elffuss.com, and the protocol in docs/hub.md.

Repositories are private unless their owner makes them public. For anything that matters, keep a GitHub mirror: it holds every change that lands, as plain git.

What you need

Sign in, once per machine

braid hub whoami || braid login

braid hub whoami says who is signed in, and fails when nobody is. Then braid login prints a web address and a code on standard error. Show both to the user, word for word, and ask them to open the address in a browser where they are signed in to GitHub, enter the code and approve. braid waits until they do, then saves a token that only this user can read. The token reads, writes and lands on the repositories the user's GitHub account can, for 90 days, and it may star, watch, comment, open issues and change requests and review wherever the user may read; after that, braid login again.

Never print, copy or commit the token, and never put it in a command line, a URL or a file of the project. A CI job or a container gets its own token, made on the hub's website under "Tokens" with only the rights it needs, and passed in the BRAID_TOKEN environment variable from the CI's secrets.

The one question to ask: publish new projects to BraidHub?

The first time you start a new project for this user, check whether they have answered already:

braid hub autopublish

Never ask again while the answer is recorded. Never publish a project the user did not start with you (one they cloned from elsewhere, for instance) without asking first, whatever the answer.

A new project

When you create a new project with the user, set it up with braid from the start (as in "Set up a project" of https://braid.elffuss.com/agents.md). Once it has a first changeset on its main branch, and autopublish is on:

braid hub publish

It creates a private repository on the hub, uploads every branch, and links this repository to it: from then on braid land lands on the hub. The repository is named after the project's directory, made valid (characters outside A-Z a-z 0-9 . _ - become -, and a run of - one; a leading . or -, a trailing - and a trailing .git go), or after the name given as its argument. It prints the repository's address (Published <login>/<name> at https://braidhub.elffuss.com/<login>/<name>): give the user that address. Add --public only when the user asks for a public repository. If the user wants the GitHub copy, create the GitHub repository first (empty) and add --mirror https://github.com/<owner>/<name>.git; the user grants the hub access to their repositories once, on the hub's website.

A project that is on the hub already

On a machine that does not have it yet:

braid hub clone <owner>/<name>
cd <name>/.braid/work/main

It makes a local repository in <name>, linked to the hub, with a first workspace on the hub's default branch, and prints the workspace's directory: <name>/.braid/work/<branch>, here for a default branch called main. Work there, or in a workspace of your own (braid workspace add).

In a large repository, braid hub clone <owner>/<name> <dir> --paths <prefix>... (the directory before --paths) brings only the trees under those prefixes. Such a sparse clone has no workspace, since a workspace is a whole checkout: it changes files with braid change create ... --land main only.

Every session

Nothing changes from braid's own rules (the braid section of the project's AGENTS.md): work in a workspace of your own, commit, and land.

Keeping main green

A repository's admins may have the hub verify its main branch: the repository's CI tells the hub how its tests went on what lands, and the hub keeps two refs, braid/green/main at the newest changeset that passed, and, while main is red, braid/red/main at the changeset it blames, or at the first failure it cannot explain. The hub runs none of the repository's code: the verdicts come from the CI.

CI reports with a token made for it alone, on the hub's website under "Tokens": read and verify:main on the repository and nothing more, for an account that may write to it and that the repository's policy names as a reporter. The job passes it in BRAID_TOKEN, and the hub's address in BRAID_HUB_URL, from its secrets, and never signs in with braid login. After the tests, with the git commit they ran on:

braid hub verify report -R <owner>/<name> --git-commit "$GITHUB_SHA" --suite ci --outcome pass

--outcome fail when they failed, flaky when they passed only when run again. An admin of the repository turns verification on once, naming the suite and the CI's account:

braid hub verify policy -R <owner>/<name> --mode report --suite ci --reporter <ci-login>

Finding repositories

braid hub explore parser cli
braid hub explore --topic rust --sort stars
braid hub user <login> --repos

braid hub explore searches the public repositories of the hub: each word of the query must start a word of a repository's owner, name, description or topics. It lists repositories that something landed on, and no fork unless --forks. Repositories of accounts that are new, on the hub or on GitHub, are reached by their address but not listed yet. braid hub user <login> shows an account, and --repos, --stars, --followers or --following one of its lists. With --json each prints the page as data, with next: give it back as --after for the next page.

Reading a repository without cloning it

When the user asks about a repository on the hub, or you need a few of its files, read them where they are:

braid hub show -R <owner>/<name>             # what it is, and its README
braid hub ls src -R <owner>/<name>           # a directory
braid hub cat src/main.rs -R <owner>/<name>  # a file, byte for byte
braid hub log -R <owner>/<name> --limit 10   # the latest changesets
braid hub diff <id> -R <owner>/<name>        # what one changeset changed

--ref reads another revision: a branch, a tag as tags/<name>, or a changeset's id or its first 12 hex digits. In a repository linked to the hub, -R may be left out. Each takes --json. Without it, what they print of what people wrote has its control characters escaped, so that it cannot drive the terminal; --json and braid hub cat give the exact text. A whole repository, or one you will change, is better cloned.

Contributing where you may not write: change requests

When the user wants a change in a repository they may read but not write to, propose it as a change request. Fork the repository, work in the fork's clone, and open the request from its workspace:

braid hub fork <owner>/<name> --clone
cd <name>/.braid/work/main
# edit, then
braid commit -m "What the change does"
braid hub request create --title "What the change does" --body-file - <<'EOF'
Why the change, and how you checked it.
EOF

request create takes the workspace's changesets that the branch lacks on the hub, as braid land would, uploads them, lands them on a new branch of the fork, request/<slug> (the slug comes from the title), and opens the request on <owner>/<name>, for its default branch (--base names another). The workspace and its branch do not move. It prints the request's number and its address: give the user the address. --body-file - reads the text from standard input, which leaves nothing in the workspace: a file written there for it would land with the next commit. --draft opens a request that does not land until braid hub request ready <n>.

In a clone of the repository itself, when the user may write there and the token may land on such a branch, the branch is request/<login>/<slug> of the repository, and no fork is needed. --head [<owner>/<name>:]<branch> proposes a branch that is on the hub already instead of the workspace.

Every braid hub request command acts on the repository the clone is linked to or, in a fork's clone, the repository it was forked from; -R <owner>/<name> names another.

After that:

When it conflicts with its base (request show says so, or a landing answered with conflicts), settle it in the workspace it came from:

braid hub sync-fork            # bring what the base landed into the fork
braid update                   # exit 2: the conflicts are in the working copy
# edit the conflict markers out of each file, `braid resolve <path>` for
# every conflict that is not about content, then
braid commit
braid hub request update <n>

In a clone of the repository itself, skip sync-fork: braid update fetches the base.

A fork that is private keeps its work to the people who may read it. A request from it to another repository publishes what it brings to everyone who reads that repository, so request create refuses it unless an admin of the fork adds --expose. Add --expose only when the user asked for that work to be published there.

Reviewing and landing change requests

Its exit status says what happened: 0 landed; 2 conflicts, printed as braid land --json prints them, with the request still open for its author to settle; 1 refused: the request moved past the snapshot named, the base no longer holds where its stack starts, or landing is not allowed (the error says which); 3 the hub could not be reached, or failed. braid hub request close <n> closes a request without landing it, and reopen opens it again.

Issues

An issue says what is wrong or missing in a repository, for its maintainers to take up. Open one when the user asks you to report a bug or ask for a change in a repository, or agrees when you suggest it: a problem you found that is not yours to fix now, in a repository the user does not maintain. Never open one on your own: its repository's owner and watchers are told, and an issue of a public repository is public. Look for an open one first, and comment there rather than open the same one again:

braid hub issue list -R <owner>/<name> --label bug --search "empty path"
braid hub issue show 12 -R <owner>/<name>
braid hub issue create -R <owner>/<name> --title "Crash on an empty path" \
  --body-file - <<'EOF'
What you ran, what happened, what you expected.
EOF
braid hub issue comment 12 -R <owner>/<name> --body-file -

Say in the title what goes wrong, and in the text how to see it: what you ran, what happened, what you expected. --search matches titles of public repositories only, since the hub never searches a private repository's text. braid hub issue close <n> (--reason not-planned for what will not be done), reopen and edit change an issue: its author and the repository's writers.

Labels sort issues: bug, enhancement, documentation, question, good first issue and help wanted to begin with, and whatever the repository's writers add. braid hub label list shows a repository's labels. Only its writers label and assign issues (--label and --assignee when it is opened, or braid hub issue edit <n> --add-label <label> --add-assignee <login>), lock them, and make or delete labels (braid hub label create <name> --color 3 --description "...").

The inbox

The hub tells the user, in their inbox, what happens in the issues and change requests they take part in or are mentioned in, the reviews asked of them, and everything in the repositories they watch:

braid hub inbox               # the unread notifications, newest first
braid hub inbox read --all    # once they are dealt with

At the start of a session where the user works with change requests, look at the inbox for reviews to answer and requests to review, and tell the user what is there. braid hub inbox read <id> marks one read, braid hub inbox done <id> takes it out, and braid hub inbox mute <owner>/<name>#<n> stops the notifications of one thread. braid hub watch -R <owner>/<name> hears of everything in a repository, and --level ignore of nothing. The hub sends no e-mail: the inbox is where the notifications are.

Agent labels and retries

Privacy and security