Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:

jobs:
rust:
runs-on: macos-14
runs-on: macos-15
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install 1.93.0 --profile minimal --component clippy,rustfmt --target aarch64-apple-darwin
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
.DS_Store
.pi/
.wrangler/

# svc:begin local-config sha256=0cb2591848c4e5675766aa516f16dfb9981fc52e1dcbadd8cec89b6982db927d
svc.local.json
AGENTS.local.md
# svc:end local-config
23 changes: 16 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ This repository implements Braid: GitHub Issue and pull-request state become the
durable working memory of local Coding Agents. Apply these instructions only in
this repository; do not modify user-scope Agent instructions.

<!-- svc:begin navigation sha256=48c8d7b497ed094589c4a192f3ef97450fd7f614712dc1b4b22e9a20578360cd -->
## SVC

Use the installed `svc` CLI when SVC guidance or project integration is relevant. Discover the current interface through `svc --help` and `svc <command> --help`; `svc lookup` reads the SVC Corpus, not CLI help. Treat unmarked project instructions and documentation as Consumer-owned.
<!-- svc:end navigation -->

## Knowledge Owners

- Product purpose, promises, workflows, and scope:
Expand Down Expand Up @@ -53,9 +47,13 @@ Use the installed `svc` CLI when SVC guidance or project integration is relevant

## Repository Workflow

- After fetching, use the remote default branch for mainline work. For work
based on a pending PR, verify its head and base and use a dedicated worktree.
- Use the binary built from that checkout for source verification. The
installed `braid` can be from a different release.
- The clean Rust runtime replaces the obsolete Python prototype; do not carry
old turn-mirror abstractions, schemas, or compatibility aliases into Rust.
- Runtime: Rust 1.93+ for the first implementation; commit `Cargo.lock`.
- Use the toolchain pinned by `rust-toolchain.toml` and commit `Cargo.lock`.
- Prefer readable deep modules aligned with the Product TDD owners. Do not pass
`serde_json::Value` across internal boundaries when a typed enum/struct owns
the contract.
Expand All @@ -69,3 +67,14 @@ Use the installed `svc` CLI when SVC guidance or project integration is relevant
- The Agent may make coherent verified commits in this repository without
per-commit approval. Pushes, releases, external GitHub mutations, and changes
outside this repository retain their own authority gates.

<!-- svc:begin -->
## SVC

Use `svc --help` or `svc <command> --help`.

- `svc status`: inspect project state
- `svc dev`: manage declared development targets

If `AGENTS.local.md` exists, read it after this file. It is ignored local guidance; shared rules belong here.
<!-- svc:end -->
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ braid setup owner/repository --provider pi --model deepseek-chat --api-key-envir
Follow the printed GitHub App installation link, then check the instance and start the local runtime:

```sh
braid migrate apply --instance owner
braid doctor --instance owner
braid serve --instance owner --tunnel
```
Expand Down Expand Up @@ -106,5 +107,8 @@ A repository maintainer can activate Braid by posting a visible, trusted `@braid
| [Deployment & observability](docs/40-deployment/README.md) | Configuration, migrations, diagnostics, and operations. |
| [Real end-to-end acceptance](docs/10-prd/acceptance.md) | How the complete GitHub-to-agent workflow is verified. |

For source development, Braid is a single Rust package that produces a portable `braid` executable. Build with `cargo build --locked`; the repository's product and technical contracts live in [`docs/`](docs/10-prd/README.md). See the [MIT license](LICENSE).
For source development, run `cargo build --locked` from the checkout and invoke
`target/debug/braid` to exercise that build. For the documentation map and
repository workflow, see the [documentation index](docs/index.md) and
[`AGENTS.md`](AGENTS.md). See the [MIT license](LICENSE).

6 changes: 1 addition & 5 deletions docs/10-prd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ local Coding Agent. GitHub holds the current collaboration state; provider
sessions are replaceable execution contexts built from that state.

The project vocabulary is owned by [`glossary.md`](glossary.md).
This document owns product purpose, promises, workflows, and exclusions. The
cross-unit realization is owned by [`../20-product-tdd/`](../20-product-tdd/),
and only the real campaign in [`acceptance.md`](acceptance.md) accepts them.

This directory owns product purpose, promises, workflows, and exclusions.
The cross-unit realization is owned by [`../20-product-tdd/`](../20-product-tdd/),
and only the real campaign in [`acceptance.md`](acceptance.md) accepts them.
and [`acceptance.md`](acceptance.md) defines the product acceptance campaign.

- [`glossary.md`](glossary.md) — project vocabulary.
- [`purpose.md`](purpose.md) — why Braid exists and the pressure it relieves.
Expand Down
5 changes: 0 additions & 5 deletions docs/10-prd/acceptance.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# End-to-End Acceptance

This document is the PRD acceptance oracle. It defines what "done" means for
Braid: real GitHub Work Items, the packaged Rust binary, a real public webhook
path, a real Codex app-server, and observable Agent behavior. Unit/component/
fake transport checks may diagnose code but do not satisfy this contract.

Braid is accepted only through real GitHub Work Items, the packaged Rust
binary, a real public webhook path, a real Codex app-server, and observable
Agent behavior. Unit/component/fake transport checks may diagnose code but do
Expand Down
4 changes: 2 additions & 2 deletions docs/10-prd/scope.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## Scope and Exclusions

The MVP includes Codex app-server, macOS arm64, real GitHub, SQLite, a free
The MVP includes Codex and Pi runtime adapters, macOS arm64, real GitHub, SQLite, a free
Cloudflare tunnel for acceptance, `braid gh` writes, packaged installation,
OpenTelemetry, and the Issue-to-PR workflow above. Linux x86_64 follows with
the same contract.

The MVP does not promise Pi/Claude adapters, hosted ingress, deterministic
The MVP does not promise a Claude adapter, hosted ingress, deterministic
multi-Agent merge, automatic merge, universal GitHub CLI parity, automatic
semantic readiness/acceptance, or recovery of a provider transcript that the
provider itself has lost.
41 changes: 20 additions & 21 deletions docs/40-deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ GitHub mutation authority by itself.

## Supported Shape

The first supported artifact is a signed/checksummed macOS arm64 `braid` binary.
It runs without Python, PDM, Cargo, or a source checkout. Linux x86_64 is the
next target. Runtime prerequisites remain explicit:
The packaged macOS arm64 `braid` archive has a SHA-256 checksum. The binary runs
without Python, PDM, Cargo, or a source checkout. Linux x86_64 is the next target.
Runtime prerequisites remain explicit:

- Git and `gh` for Agent workflows;
- pinned Codex executable and authenticated provider home;
- the configured Codex or Pi executable and its credentials;
- Wrangler for the free Quick Tunnel acceptance path;
- GitHub App ID/private key/webhook secret and installation;
- optional OTLP endpoint; full campaign acceptance requires one.
Expand Down Expand Up @@ -40,8 +40,9 @@ names. The main sections are:
- log format and bounded health/status settings.

`braid config check` prints the effective non-secret declaration and validates
its static invariants. `braid doctor` runs filesystem, SQLite, GitHub, Codex
schema, Git/gh, OTLP, and Wrangler precondition probes. Profiles expose
its static invariants. `braid doctor` probes filesystem, SQLite, GitHub,
Git/gh, OTLP, Wrangler, and the configured adapters and credentials. For Codex
it also checks the app-server schema. Profiles expose
their effective mapped provider settings through `braid profile inspect`.

## Filesystem Layout
Expand All @@ -52,23 +53,24 @@ Everything below is scoped by trust boundary:
```text
~/.braid/
registry.toml # instance registry (SSoT)
config.toml # optional user defaults (future)
secrets/ # user-level provider API keys
instances/<key>/
config.toml # instance config, schema version 2
github-app.pem # GitHub App private key
secrets.toml # webhook secret
source/ # repository checkout used to provision worktrees
state/
braid.sqlite3
backups/
worktrees/<repository>/<pr-number>-<assignment-generation>/
worktrees/
provider/ # adapter home (e.g. Codex provider state)
logs/ # optional sampled-log export
```

The default `runtime.root` is `<config_dir>/state`. `braid setup` writes
`instances/<key>` explicitly with the layout above. Multiple instances share
the same user root but have isolated databases, webhooks, and worktrees.
The [worktree contract](../20-product-tdd/README.md#durable-state-and-migrations)
describes generation paths and overrides.

## Database Lifecycle

Expand Down Expand Up @@ -109,18 +111,15 @@ retained span preserved all five controlled full-payload attributes.

## Startup and Supervision

Startup is ordered:

1. parse/validate config and secrets;
2. acquire process/runtime owner lease;
3. verify/apply permitted DB migrations;
4. probe installed Codex version/schema and GitHub App installation;
5. start OTLP exporters and loopback health/ingress;
6. start Codex adapter and reconcile persisted sessions/turns/outbox;
7. start canonical GitHub reconciliation;
8. optionally start Wrangler, verify a signed public ping through the returned
URL, then update the GitHub App webhook;
9. mark repository ready for assignment/turn claims.
Braid validates the configuration and database schema before acquiring the
runtime owner lease. It recovers pending writes and checks the GitHub App
installation before starting loopback ingress and health. Supervised workers
handle scheduling, GitHub writes and reconciliation, and provider session
recovery. `serve --transport-only` skips the provider workers.

With `--tunnel`, Braid verifies the signed public probe before updating the
App webhook and marking startup ready. Provider availability is reported
through health as the configured adapters connect.

The provider adapter reconnects and resumes compatible sessions where the
provider contract makes that safe. Any other supervised worker exit makes
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Braid Documentation

<!-- svc:begin navigation sha256=7f7f63d0b8989624f57bd21b82b2ac2d05e4445edfd5af4bc3742996f0754bda -->
## SVC Corpus
<!-- svc:begin navigation sha256=55c5c21e0087021bc7f81047e2ffe91f889b81829473655d86d78fbe2029d4f2 -->
## SVC CLI

Use `svc lookup` when packaged Sustainable Vibe Coding Corpus guidance is relevant, and discover its browse/search/read grammar through `svc lookup --help`. Project documentation outside this marked block remains Consumer-owned.
Use `svc --help` and the installed SVC Skills for framework guidance. Project documentation outside this marked block remains Consumer-owned.
<!-- svc:end navigation -->

Read owners progressively from the problem being changed:
Expand Down
28 changes: 17 additions & 11 deletions docs/user-manual/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ braid --version
- [`gh`](https://cli.github.com/) installed and authenticated with an account
that can create GitHub Apps for the target owner (user or organization).
- A repository where you will install the App.
- The selected runtime executable, [Pi](https://pi.dev/) or
[Codex](https://github.com/openai/codex).
- For the Pi provider: a DeepSeek API key exported as `DEEPSEEK_API_KEY` (or
the environment variable configured with `--api-key-environment`) *only at
setup time*.
setup time). An existing user-level provider secret also works.

## Bootstrap

Expand All @@ -41,22 +43,24 @@ Options:
the user-level secrets file, so the env var is only needed at setup time.
- `--user-home <DIR>` — defaults to `~/.braid` (or `BRAID_USER_HOME`).
- `--instance <KEY>` — defaults to the repository owner.
- `--runtime-executable <PATH>` — use an explicit Pi or Codex executable
instead of automatic discovery.

`braid setup` performs these steps:

1. Verifies `gh auth` and reads the acting GitHub login.
2. Resolves the Braid user home (`~/.braid` by default) and instance key
(owner by default).
3. Generates a random webhook secret.
4. Reads the provider API key from the environment variable named by
`--api-key-environment`.
5. Builds a GitHub App Manifest with the permissions Braid needs
4. Builds a GitHub App Manifest with the permissions Braid needs
(`contents:write`, `issues:write`, `pull_requests:write`, `metadata:read`).
6. Starts a temporary local HTTP callback server.
7. Opens a browser to `github.com/settings/apps/new` (or the organization
5. Starts a temporary local HTTP callback server.
6. Opens a browser to `github.com/settings/apps/new` (or the organization
variant) with the manifest pre-filled.
8. Captures the browser redirect and exchanges the code for the App's
7. Captures the browser redirect and exchanges the code for the App's
private key, slug, and ID.
8. Verifies the selected runtime and resolves provider credentials from the
existing provider secret or the configured environment variable.
9. Writes files under `~/.braid`:
- `registry.toml` — the instance registry (SSoT for `BRAID_INSTANCE`
resolution).
Expand All @@ -75,9 +79,10 @@ environment variable. `BRAID_WEBHOOK_SECRET` is no longer required.
After setup:

1. Install the App on your repository by visiting the printed install URL.
2. Run diagnostics:
2. Initialize the instance database and run diagnostics.

```shell
braid migrate apply --instance <KEY>
braid doctor --instance <KEY>
```

Expand All @@ -95,9 +100,10 @@ The tunnel receives GitHub webhooks and routes them to Braid's local ingress.
## Activating Braid on an Issue

Braid activates through a **trusted `@braid` mention**: a visible `@braid` in
an issue comment from a repository MAINTAIN/ADMIN actor wakes the Issue Agent
(after the Quiet Window). Braid acknowledges the mention with an `eyes`
reaction.
an issue comment from a repository MAINTAIN/ADMIN actor bypasses the Quiet
Window and event threshold. Braid acknowledges durable receipt with `eyes`.
See the [scheduling contract](../10-prd/scheduling.md) for provider acceptance
and terminal reactions.

Native Issue assignment is a GitHub-side *Agent App* provisioning (the same
capability that makes Copilot assignable), not a permission an ordinary
Expand Down
9 changes: 6 additions & 3 deletions docs/user-manual/tunnel.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Braid performs these steps automatically:
3. Parses the tunnel output to obtain a public HTTPS URL such as
`https://<random>.trycloudflare.com`.
4. Appends `/webhook` to form the public webhook endpoint.
5. Sends a signed `ping` probe to that endpoint to confirm GitHub can reach it.
5. Sends a signed `ping` through that endpoint to verify it reaches Braid's
ingress and passes signature verification.
6. Once reachable, updates the GitHub App's webhook URL to the public endpoint.
7. Runs the runtime normally.
8. On clean shutdown, restores the GitHub App's previous webhook URL.
Expand Down Expand Up @@ -57,7 +58,9 @@ maps instance keys to their home directories, so `--instance` (or

## Troubleshooting

- If the tunnel does not converge within 45 seconds, Braid retries up to 3
tunnel candidates and then fails with `QuickTunnel` error details in the logs.
- Braid tries at most five tunnel candidates. Each candidate has up to 45
seconds to publish its URL and register the connection. Braid then allows
time for DNS propagation before probing the public endpoint. If all
candidates fail, Braid reports the last error.
- `braid tunnel probe --instance <KEY> --url <public-url>` can verify a
specific URL manually, but normal `serve --tunnel` does this automatically.
25 changes: 13 additions & 12 deletions scripts/tests/00_clean_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ runtime="$temporary_root/runtime"
mkdir -p "$runtime/state/backups" "$runtime/provider" "$runtime/workspace"
private_key="$runtime/github-app.pem"
secrets_file="$runtime/secrets.toml"
printf '%s\n' 'diagnostic placeholder; no GitHub API call is made in Slice 0' > "$private_key"
printf '%s\n' 'diagnostic placeholder for the intentionally unready instance' > "$private_key"
touch "$secrets_file"

write_config() {
Expand Down Expand Up @@ -130,6 +130,13 @@ run_clean() {
}

run_clean "$braid" --version
run_clean "$braid" setup --help | /usr/bin/grep -q -- '--runtime-executable'
if run_clean "$braid" setup owner/repo --runtime-api-url https://example.invalid \
> "$temporary_root/setup-removed-argument.out" 2>&1; then
echo "setup accepted a removed option" >&2
exit 1
fi
/usr/bin/grep -q 'unexpected argument.*--runtime-api-url' "$temporary_root/setup-removed-argument.out"
run_clean "$braid" config check --config "$config"
run_clean "$braid" migrate plan --config "$config"
run_clean "$braid" migrate apply --config "$config"
Expand Down Expand Up @@ -178,30 +185,24 @@ test "$backup_count_after" = "$((backup_count_before + 1))"
run_clean "$braid" migrate apply --config "$v1_config"
backup_count_final=$(find "$runtime/state/backups" -type f -name '*.sqlite3' | wc -l | tr -d ' ')
test "$backup_count_final" = "$backup_count_after"
v1_schema=$(run_clean "$braid" status --config "$v1_config" --json | /usr/bin/sed -n 's/.*"config_schema": \([0-9][0-9]*\).*/\1/p')
test "$v1_schema" = "2"
test "$(/usr/bin/sqlite3 "$v1" 'SELECT MAX(version) FROM schema_migrations;')" = "2"
/usr/bin/sqlite3 "$v1" \
"SELECT 1 FROM associations WHERE issue_node_id='ISSUE_NODE' AND pr_node_id='PR_NODE' AND active=1;" \
| /usr/bin/grep -q '^1$'
/usr/bin/sqlite3 "$v1" \
"SELECT 1 FROM canonical_objects WHERE node_id='COMMENT_NODE' AND lifecycle='active';" \
| /usr/bin/grep -q '^1$'
test "$(/usr/bin/sqlite3 "$v1" "SELECT count(*) FROM issue_context_sources;")" = "0"
if /usr/bin/sqlite3 "$v1" "SELECT issue_content_digest FROM associations LIMIT 1;" \
>"$temporary_root/removed-column.out" 2>&1; then
echo "schema 11 retained the obsolete association digest column" >&2
exit 1
fi
/usr/bin/sqlite3 "$v1" 'SELECT kind, detail FROM events LIMIT 0;'

newer="$runtime/state/newer.sqlite3"
/usr/bin/sqlite3 "$newer" 'CREATE TABLE schema_migrations(version INTEGER PRIMARY KEY, name TEXT NOT NULL, checksum TEXT NOT NULL, applied_at TEXT NOT NULL); INSERT INTO schema_migrations VALUES (12,"future","0000000000000000000000000000000000000000000000000000000000000000","future");'
/usr/bin/sqlite3 "$newer" 'CREATE TABLE schema_migrations(version INTEGER PRIMARY KEY, name TEXT NOT NULL, checksum TEXT NOT NULL, applied_at TEXT NOT NULL); INSERT INTO schema_migrations VALUES (3,"future","0000000000000000000000000000000000000000000000000000000000000000","future");'
newer_config="$temporary_root/newer.toml"
write_config "$newer_config" "$newer" 1.0 43189
if run_clean "$braid" migrate plan --config "$newer_config" > "$temporary_root/newer.out" 2>&1; then
echo "schema-newer fixture was accepted unexpectedly" >&2
exit 1
fi
/usr/bin/grep -q 'schema 12 is newer' "$temporary_root/newer.out"
/usr/bin/grep -q 'schema 3 is newer' "$temporary_root/newer.out"

foreign="$runtime/state/foreign.sqlite3"
/usr/bin/sqlite3 "$foreign" 'CREATE TABLE prototype_state(id INTEGER PRIMARY KEY);'
Expand Down Expand Up @@ -239,4 +240,4 @@ else
exit 1
fi

echo "clean-install Slice 0 diagnostics passed"
echo "clean-install diagnostics passed"
Loading
Loading