--- url: /sturn/tutorials/first-swarm.md --- # Your first swarm Goal: two agents editing one repo, zero checkouts, one prevented conflict. ## Setup ```sh git init demo && cd demo git commit -qm init --allow-empty sturn init sturn daemon & # or: sturn deploy service ``` ## Two workspaces ```sh sturn ws new agent-a sturn ws new agent-b ``` Both point at `HEAD`. Nothing was written to disk — no worktree, no index, no checkout. ## Claim before you edit ```sh STURN_ACTOR=agent-a sturn claim "src/**" --ws agent-a # claimed src/** (ws agent-a, ttl 3600s) STURN_ACTOR=agent-b sturn claim "src/lib.rs" --ws agent-b # conflict: agent-a claimed src/** (ws agent-a, expires …) # sturn: claim denied — --force to override ``` Agent-b learns in milliseconds that `src/` is taken and picks `tests/**` instead. In git, both would have edited the file and discovered it at merge. ## Write ops, snap, repeat ```sh echo '…' | sturn write src/lib.rs --ws agent-a echo '…' | sturn write tests/lib.rs --ws agent-b sturn snap agent-a -m "a: lib" # → real commit on main sturn snap agent-b -m "b: test" # → real commit on main ``` `git log` shows two ordinary signed-able commits. `git for-each-ref refs/sturn/*` shows the coordination layer GitHub never needed to understand. --- --- url: /sturn/how-to/hydrate.md --- # Hydrate a workspace Agents read through the ODB; compilers need POSIX files. Hydration materializes the ws *view* — tip commit **plus** uncommitted WAL ops, matching what `ws_read` sees. ```sh sturn ws hydrate agent-7 /tmp/ws-7 # whole view sturn ws hydrate agent-7 /tmp/ws-7 --path src # subset ``` Or hydrate + run + clean in one step: ```sh sturn exec --ws agent-7 -- cargo check # tmpfs, gone after sturn exec --ws agent-7 --keep -- cargo test # keep the dir ``` * Target tmpfs (`/dev/shm`/`/tmp`) — it's a projection, delete freely. * Exit status propagates: `sturn exec` fails iff the command does. * Writes inside the hydrated dir do **not** flow back — ops are the only write path. (Write-back hydration is a backlog item.) * FUSE mounts for humans land last — `git` works meanwhile. --- --- url: /sturn/how-to/mount.md --- # How-to: mount a workspace `sturn mount` exposes a workspace tree as a real filesystem — the interception layer: tools write normally, sturn records ops. ``` agent's write_file() ──► kernel ──► FUSE ──► SturnFs write() → buffer release → Op::Write → WAL ``` FUSE = *Filesystem in USErspace*: syscalls route to a user process instead of a disk driver, so `sturn-fuse` decides what "a file" means — ops, not bytes on disk. ## Use ```console $ sturn mount devin /mnt/devin # read-only view of the tree $ sturn mount --rw devin /mnt/devin # writes become WAL ops ``` Under `--rw`, plain POSIX writes — `echo`, editors, build tools, agent `write_file` — land as `Write`/`Rename`/`Delete` ops with `intent: "fuse"`. The agent can't bypass the write path: it *is* a filesystem, the thing tools already use. ## Semantics * **Buffer-then-commit**: `write()` buffers per open file; the op emits on `release` (close) or `fsync` — editors that fsync-per- save get an op at sync point, not just at close. * **Mount-time view**: the tree is the ws tip at mount time — other agents' ops don't appear live (unmount/remount to see). * **Dirs are implicit** in git trees — `mkdir`/`rmdir` are local only; a `Write` op into the dir is what persists. ```console $ fusermount -u /mnt/devin ``` --- --- url: /sturn/how-to/daemon.md --- # Run the daemon `sturn daemon` polls WAL heads and fans new events onto topics (`repo..ops|claims|review|presence`) in the embedded bus store. ```sh sturn daemon # foreground sturn deploy service # systemd user unit, Restart=always sturn service disable # stop now + skip at login (unit kept) sturn service enable # back on, now and at login sturn service status # enabled=/active= probe sturn service restart # bounce in place sturn service logs -f # journal tail; -f follows sturn destroy service # disable + remove the unit file ``` ## If the daemon is down Nothing is lost. The bus is a cache — ops still live in `refs/sturn/wal/*` and replicate via `git push`/`git fetch`. Subscribers catch up by replaying the WAL. The daemon only removes latency; it never owns truth. ## Consumers today * `sturn claims` — fold all WALs into live advisory locks * M2: SSE/unix-socket subscribers; M3: the MCP `subs` tool --- --- url: /sturn/explanation/architecture.md --- # Architecture Three layers, strictly ordered by authority: ``` ┌────────── evented layer ──────────┐ agents │ ops: write/rename/claim/intent/… │ │ virtual workspaces (ws = pointer) │ │ bus: repo..{ops,claims,…} │ └──────┬─────────────────┬───────────┘ │ append │ append (offline) refs/sturn/wal/* ── git ODB ── refs/sturn/ws/* │ normal git push/fetch → GitHub — free, signed, ordinary ``` ## Invariants 1. **The WAL is the state.** Anything derivable from `refs/sturn/wal/*` is a cache (bus cursors, materialized views). 2. **Merges stay git's.** Ops never encode merge semantics — claims prevent collisions; `snap` squashes into ordinary commits. 3. **Coordination before work.** Claims publish *before* edits. Discovering a conflict at merge is the failure mode git taught us. ## What each piece owes * `refs/sturn/wal/` — source of truth, replicates for free * daemon + bus — latency reduction only; optional * `refs/sturn/ws/` — workspace namespaces; hydration opt-in * `snap` — the bridge back to ordinary git history --- --- url: /sturn/explanation/no-crdt.md --- # Why no CRDT for code CRDTs are right for the *log*, wrong for the *tree*. **For the WAL:** when replicas append ops and diverge, a CRDT-style merge (grow-only set + causal order) converges the log with no coordination — same events, same state. That part we keep. **For the tree:** a CRDT auto-merge produces a *syntactically* merged file, not a semantically correct one. Two agents inserting different `main()` bodies converge to a file that compiles only by luck. Code needs decisions, not convergence. So sturn splits the difference: * The **log** merges deterministically (CRDT semantics; a `libgrite-git` impl is on the backlog). * The **tree** is produced by `snap` — a deterministic reduction over ops on a base. When ops collide semantically, that's a decision for a reviewer, not a merge algorithm. * **Claims** make most collisions never happen — prevention beats resolution. --- --- url: /sturn/explanation/model.md --- # The model — files, approval, agents ## Files are a projection, not the state Git materializes a working tree because POSIX tools need paths. Sturn keeps the tree *virtual*: `ws_read` serves blob contents straight from the object database — no checkout, no index, no lock. When something genuinely needs real files: * `sturn exec --ws w -- cmd` — hydrate the ws view (tip + uncommitted ops) to tmpfs, run, discard * `sturn mount w /dir --rw` — live FUSE filesystem; edits buffer per-open and become Write/Delete/Rename ops on release * `--writeback` on `exec`/`hydrate` — dir diffs flow back as ops Agents aren't filesystem-deprived — `ws_read/ws_write/ws_glob/ ws_grep` are the same file primitives harnesses already use; the backend is virtualized, not the interaction. ## Approval without the PR cliff Every op is content-addressed and streams through the WAL. A reviewer emits `review approve|reject` — itself a signed, attributed op. With `[review] require = true`, `snap` refuses unreviewed tree ops and names their ids — the gate exists, but verdicts stream *per-op before commit time* instead of one giant diff at the end. PRs become a packaging format, not the gate. ## Agents review agents A verdict is just an op — any actor appends it. Intended topology: fast writers produce ops → a senior agent or human watches `subs ops|review` and emits verdicts → gated `snap` lands only approved work. Humans spot-check the stream instead of serializing merges. --- --- url: /sturn/reference/ops.md --- # Ops The event vocabulary appended to `refs/sturn/wal/`. JSON, content-addressed (blob sha = event id), one commit per append. ## Tree ops | Op | Fields | Effect at `snap` | |---|---|---| | `write` | `path`, `blob`, `intent?` | replace/create file | | `rename` | `from`, `to` | move entry | | `delete` | `path` | remove entry | ## Multi-workspace merge `sturn snap a b …` folds several workspaces' pending ops into one commit — rename-aware, not a bare path concat: * a `write` onto a path *another* ws renamed away follows the rename to its destination (the modify-vs-rename case a 3-way merge resolves the same way), chained f→g→h and applied after the rename no matter the ws order; * genuinely ambiguous shapes stay put and warn on stderr instead of picking a silent winner: a source renamed two ways (`rename f diverged`), a `delete` meeting a rename (either side), colliding destinations, and cross-ws same-path write/delete collisions. ## Coordination ops | Op | Fields | Effect | |---|---|---| | `claim` | `glob`, `ttl_secs` | advisory lock; auto-expires | | `release` | `glob` | drop a claim | | `intent` | `text` | provenance — why the work exists | | `review` | `event`, `verdict` | approve/reject an event id | | `snapshot` | `message` | marker — ops before it are committed | | `presence` | `status` | actor joined/left | | `ask` | `subject`, `target`, `options?`, `ttl_secs` | pending *response* — open question; the event id is the ask handle | | `answer` | `ask`, `verdict` | close an ask with a verdict | | `cancel` | `ask` | withdraw an open ask | ## Claims `claim.glob` carries a resource URI — `scheme:path`. `fs:` globs (`src/**`, and a bare glob means `fs:`) or opaque resources (`dev:display0`, `sess:T-012`, `cap:role`). `net:` paths may be port ranges — `net:13000-13100` conflicts with `net:13050`; non-numeric paths fall back to prefix matching. Each live claim derives a **fencing token** at fold time — a Lamport-style epoch: `1 + max` over earlier claims on overlapping URIs, ordered by `ts` then WAL position. Never stored, and never repeats for a resource — expired and released claims still count as predecessors. `sturn claim` prints it; a holder passes it to `sturn check --fence ` to ask "has anything outranked me?" — the stale-usurper probe. It's advisory like the claim: second-granularity `ts` plus concatenation order means same-second cross-ws races resolve deterministically, not temporally. ## Asks Claims are pending *ownership*; asks are pending *answers*. An `ask` opens under its event id and stays `open` until an `answer` or `cancel` op lands — or `ttl_secs` runs out (`0` = never). The question and its answer can live on different workspaces' WALs; responders filter `target` (`actor:`, `human:`, `node:`, `claim-holder:`, `any`) to find asks meant for them. ## Envelope ```json {"id":"","ws":"agent-7","actor":"agent-7","ts":1792292994, "op":{"op":"write","path":"src/lib.rs","blob":"","intent":"…"}} ``` --- --- url: /sturn/reference/cli.md --- # CLI reference Global flags: `--repo ` (default cwd) · `--config `. | Command | What it does | |---|---| | `sturn init` | write `sturn.toml`; confirm ref namespaces; note colocated jj | | `sturn ws new [--base]` | create workspace ref — no checkout | | `sturn ws ls` | list workspaces | | `sturn ws read ` | blob contents, straight from the ODB | | `sturn ws hydrate [--path P] [--writeback]` | materialize view; --writeback diffs dir → ops | | `sturn claim --ws [--ttl N] [--force]` | advisory lock on a resource URI — `fs:` glob (`src/**`; bare glob means `fs:`) or opaque (`dev:display0`, `net:13000` or range `net:13000-13100`, `sess:T-012`, `cap:role`); prints the fencing token; exits 1 on live conflict | | `sturn release --ws ` | drop a claim | | `sturn claims` | live claims across every workspace — uri, holder, expiry, fence | | `sturn check [--fence N] [--watch]` | list live claims conflicting with a URI; exits 1 when contested. `--fence N` reports only claims outranking N — the held-claim staleness probe. `--watch` streams conflict-set changes via WAL poll | | `sturn write --ws [--file F] [--intent T]` | append a write op (stdin → blob) | | `sturn intent --ws ` | record provenance | | `sturn log [--ws ]` | replay the WAL as JSONL | | `sturn snap -m ` | fold ops → commit; multi-ws merges into one — rename-aware; conflicts → stderr | | `sturn review --ws ` | continuous review | | `sturn ask --ws [--target T] [--option O…] [--ttl N]` | open a pending ask — event id is the handle | | `sturn asks [--all] [--json]` | pending asks; --all adds resolved | | `sturn answer --ws ` | close an ask with a verdict | | `sturn cancel --ws ` | withdraw an open ask | | `sturn wait [--timeout N] [--poll MS]` | block until resolved; exit 0 answered · 2 cancelled · 3 expired · 4 timeout | | `sturn push [--remote R]` | push heads + `refs/sturn/*` | | `sturn daemon` | WAL → topic fan-out loop + `bus.sock` push | | `sturn sub ` | stream ops|claims|review|presence|asks as JSONL | | `sturn mcp [--ws W]` | MCP stdio server; --ws emits joined/left presence | | `sturn exec --ws [--keep][--writeback] -- cmd…` | hydrate → run → clean; write-back as ops | | `sturn join\|leave ` | presence; leave sweeps actor claims | | `sturn rename\|delete … --ws` | tree ops that keep intent | | `sturn verify [--ws W]` | verify event sigs vs allowed_signers | | `sturn compact [--ws W]` | drop pre-snapshot WAL history (archived) | | `sturn bridge --to ` | snapshot ops → HMAC webhook (bupha CI) | | `sturn mount [--rw]` | FUSE mount; --rw edits flow back as ops | | `sturn deploy service\|env` | systemd unit / secrets skeleton | | `sturn service enable\|disable\|status\|restart\|logs [-f]` | toggle/bounce the daemon unit (kept); logs tails the journal | | `sturn destroy service` | disable + remove the systemd user unit | --- --- url: /sturn/reference/config.md --- # Config reference `sturn.toml` — searched at `$STURN_CONFIG`, `./sturn.toml`, `~/.config/sturn/sturn.toml`. Unknown fields are rejected. Secrets never live here. ```toml [repo] dir = "." # required — the git repo being coordinated id = "9aia/sturn" # topic prefix; default: dir basename branch = "main" # snap target; default: main [wal] ref_prefix = "refs/sturn/wal" # default [bus] store = "~/.local/state/sturn/bus.redb" # default poll_ms = 100 # daemon fan-out interval # repos = ["../other-repo"] # extra repos to fan out [review] require = true # snap refuses unreviewed tree ops [signing] key = "~/.ssh/id_ed25519" # sign every event (ssh-keygen) # allowed_signers = "..." [actor] name = "agent-7" # default: $STURN_ACTOR → $USER → "anon" ``` See `examples/sturn.toml.example` in the repo. --- --- url: /sturn/reference/crate-api.md --- # Crate map Ports (traits only) and impls — new backends are new impl crates, never core changes. | Crate | Role | |---|---| | `sturn-core` | `Event`/`Op`/`Verdict`, `Config`, topic names | | `sturn-wal` → `sturn-wal-git` | append-only op log in git refs (CAS) | | `sturn-bus` → `sturn-bus-redb` | topic pub/sub cache over the WAL | | `sturn-ws` → `sturn-ws-git` | virtual workspaces over the ODB | | `sturn-vcs` → `sturn-git` | remote sync/push; `snap_commit` bridge | | `sturn-claim` | pure claim logic: fold → live locks → conflicts | | `sturn-mcp` | the agent tool contract (M3 wires the server) | | `sturn-config` → `sturn-config-toml` | config source | | `sturn-secret` → `sturn-keyring`/`sturn-dotenv` | secret resolution | | `sturn-service` → `sturn-systemd` | daemon lifecycle | | `sturn-odb` | direct loose-object I/O — the `-git` impls' fast path (plumbing fallback) | | `sturn-cli` | `sturn` binary — the composition root (`&dyn` ports) | Rustdoc: `/api/sturn_core/` etc. after `bun run docs:api`. --- --- url: /sturn/getting-started.md --- # Getting started ```sh cargo install --git https://github.com/9aia/sturn sturn cd your-repo sturn init ``` `init` writes a `sturn.toml` and confirms the ref namespaces. It also detects **colocated jj** repos (`jj git init`) — sturn works on them unchanged; non-colocated jj isn't supported. From here, workspaces are the unit of parallel work: ```sh sturn ws new agent-7 # refs/sturn/ws/agent-7 → HEAD. No checkout. sturn ws ls ``` Append ops to the workspace's log: ```sh echo 'fn helper() { 42 }' | sturn write src/lib.rs --ws agent-7 --intent "add helper" sturn claim "src/**" --ws agent-7 sturn log --ws agent-7 # JSONL replay of the WAL ``` Land the work as an ordinary commit: ```sh sturn snap agent-7 -m "add helper" # ops → real commit on main sturn push # heads + refs/sturn/* → origin ``` Run the coordination daemon so other actors see ops live: ```sh sturn daemon # WAL → repo..{ops,claims,review,presence,asks} sturn deploy service # systemd user unit ``` Next: [your first swarm](/tutorials/first-swarm). --- --- url: /sturn/public/api/static.files/SourceSerif4-LICENSE-a2cfd9d5.md --- Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. Copyright 2014 - 2023 Adobe (http://www.adobe.com/), with Reserved Font Name ‘Source’. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. This Font Software is licensed under the SIL Open Font License, Version 1.1. This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL *** ## SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 PREAMBLE The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others. The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives. DEFINITIONS "Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation. "Reserved Font Name" refers to any names specified as such after the copyright statement(s). "Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s). "Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment. "Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software. PERMISSION & CONDITIONS Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions: 1. Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself. 2. Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user. 3. No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users. 4. The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission. 5. The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software. TERMINATION This license becomes null and void if any of the above conditions are not met. DISCLAIMER THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.