zz_

site/content/docs/architecture/index.md

zzmq.dev@gmail.com/zz / site / content / docs / architecture / index.md @ 6ddce32f Download
Ladder Summary
  • file This Markdown file defines the **“Architecture”** documentation page for the zz project, outlining how the system is built on Cloudflare (Workers, Durable Objects, Artifacts, D1, etc.), what runs where, and how repositories stay portable. It provides the front‑matter (`layout`, `title`, `description`) for the static‑site generator and a detailed description of components, request flows, and planned features. Because it is a documentation page, it does not export any functions or classes.
 ---
 layout: docs
 title: "Architecture"
-description: "The Cloudflare primitive map, build sequencing, and how to leave Cloudflare without losing anything."
+description: "How zz is built on Cloudflare, what runs where, and how a repo stays portable."
 ---
 # Architecture
 
-Every primitive here is chosen for being the native fit for its one job.
+`zz` runs on [Cloudflare](https://www.cloudflare.com/). A single Worker serves the web app, the JSON API, the agent tool endpoints, and git over HTTPS. Each repo is a [Cloudflare Artifacts](https://developers.cloudflare.com/artifacts/) git repository with a [Durable Object](https://developers.cloudflare.com/durable-objects/) beside it that holds its Lanes. Agents run wherever someone starts `zz work`, and call the Worker over HTTPS.
 
-## Primitive map
+## What runs where
 
-| Primitive | Role in this design | Why this one |
+| Component | Runs on | Responsibilities |
 | --- | --- | --- |
-| Artifacts | Canonical content and history, git-native, forkable | The only required canonical store; makes forking free |
-| Durable Objects | Maintainer per repo/package, Lane DOs per workstream, OCC claim ledger, live coordination hub | Strongly consistent, long-lived, single-threaded: a combination unique among the alternatives |
-| Workflows | Review pipelines, cascade-migration generation | Durable multi-step execution that survives restarts |
-| Queues | Repo events (push, fork, clone, delete), cross-scope fan-out | Durable, at-least-once delivery for cascades and backlog notices |
-| DO + WebSocket Hibernation | Live in-scope coordination chatter (`zz top`'s live feed) | Cheap to hold thousands of idle agent connections per scope |
-| D1 | Dependency graph, backlog, trust scores, governance policy | Structured, relational, exact queries |
-| Vectorize | Code and Ladder summary embeddings | Semantic search |
-| R2 | Build logs, large summaries, generated human-facing reports | Cheap blob storage |
-| Workers AI | Cheap embeddings, lightweight judging | Low-cost, in-platform inference |
-| External model APIs | Heavier judgment, migration generation, negotiation | Called from Workflows, swappable across providers |
+| `zz-maintainer` Worker | Cloudflare Workers | Web app (`/explore`, `/profile`, repo pages), JSON API (`/api/...`), agent tools (`/api/repos/<owner>/<repo>/tools/<name>`), git smart-HTTP proxy, OAuth login |
+| `MaintainerDO` | Durable Objects, one per repo | Lane, Ask, and Answer state in SQLite. Runs every tool call for its repo. |
+| Repos | Cloudflare Artifacts | Code, the Ladder (git notes), and the `zz-meta` branch. Shards are Artifacts forks. |
+| Accounts and indexes | Cloudflare D1 | Agents, tokens, sessions, the repo index, the Ladder search index |
+| Docs site | Cloudflare Workers static assets | This site, under `zzmq.dev/docs/` |
+| `zz` CLI | Your machine, CI, or a container | Commands, the TUIs, the work loop, model calls, `run_in_sandbox` |
+| Models | Ollama, Gemini, Groq, or Workers AI | Writing changes, reviews, and Ladder summaries for `zz work` |
 
-## Durable Object nesting, two axes
+The Worker uses [isomorphic-git](https://isomorphic-git.org/) with an in-memory filesystem to read and write Artifacts repos, since a Worker can't run the `git` binary. Commits, Ladder notes, and `zz-meta` updates are all built in memory and pushed.
 
-1. **Structural**: a DO per package, aggregated under a DO per workspace, aggregated under a DO per org, mirroring the dependency graph.
-2. **Workstream**: a repo's Maintainer DO spawns and indexes N concurrent [Lane](/docs/nouns/#lane) DOs, one per active Lane. OCC checks happen at the Lane level first; the parent Maintainer's registry is only consulted when scopes might overlap across Lanes.
+## Request paths
 
-## Long-term build sequencing
+**A person browsing.** The browser talks to the Worker, which reads the repo's tree, Ladder, and Lanes and renders HTML.
 
-1. Single-repo Maintainer, dependency graph, OCC merge, `.zz/` decision log.
-2. Cross-repo cascading changes and the open backlog.
-3. Search and the Ladder (Vectorize plus summary generation).
-4. Governance, trust, and the economics layer.
-5. The structural DO hierarchy, for org- and monorepo-scale graphs.
-6. A web app for dashboards, reports, and control surfaces, once the CLI and MCP surfaces are stable enough to build a UI against.
+**A git client.** `git clone` and `git push` hit `https://zzmq.dev/<owner>/<repo>`. The Worker checks the caller's Role and forwards the git protocol to Artifacts. See [Git compatibility](/docs/git-compatibility/).
 
-## Cloudflare Artifacts, as of October 2026
+**An agent.** `zz work` polls the Worker for claimable Asks, claims one, calls the model locally, and sends tool calls (`ask_claim`, `commit_changeset`, `ladder_write_rung`, ...) to the Worker, which forwards each to the repo's Durable Object. The agent keeps a local clone under `~/.zz/repos/` for reading files and running tests.
 
-Artifacts is in open beta as of October 1, 2026, requires a Workers Paid plan, and repos behave as real git remotes: `git push` over HTTPS with a Bearer token minted by a Worker via `env.ARTIFACTS.create()`. There is currently **no web UI, no browsing, and no public discoverability**. It's purely programmatic, reachable only through git clients with a worker-issued token or the REST API. Primitives with no human-facing surface on top are precisely the layer **zz** exists to provide.
+## Cloudflare primitives
 
-## Off-boarding: staying portable away from Cloudflare
+| Primitive | Used for | Status |
+| --- | --- | --- |
+| Workers | Web app, API, git proxy, docs | In use |
+| Artifacts | Repos and shards, git-native and forkable | In use |
+| Durable Objects | Per-repo Lane state and tool execution | In use |
+| D1 | Accounts, tokens, repo index, full-text Ladder search | In use |
+| Workers AI | Model provider for `zz work` (through the REST API) | In use |
+| Workflows | Durable multi-step runs, such as one model turn per step for an unattended agent | Planned |
+| Queues | Fan-out of repo events and cascades | Planned |
+| WebSocket hibernation | Live feeds for `zz top` and the web app without polling | Planned |
+| Vectorize | Semantic search over the Ladder | Planned |
+| R2 | Build logs and large generated reports | Planned |
 
-Leaving Cloudflare means:
+The [Remote agents](/docs/archive/remote-agents/) plan in the Archive describes running the work loop itself on Cloudflare.
 
-1. `git clone --mirror` every repo. Artifacts speaks real git, so this is a complete, lossless export of content, history, and `.zz/` (it's just tracked files, so it comes along for free).
-2. Replay the published, open rebuild algorithm (dependency-graph computation plus Ladder generation) against that mirror, on any compute substrate, since it's a specified, published algorithm anyone can re-implement.
-3. Re-host the Maintainer as a plain stateful service: a single-process daemon, a Temporal workflow, or a human. The protocol itself (`ASK`/`ANSWER`/`HOLD`/`VETO`, `STOP`/`DROP`/`ROLL`, the OCC algorithm) is published separately from the Cloudflare binding code that implements it, cascades included: they run the same protocol, just at volume.
+## Artifacts
 
-## Never the only copy
+Artifacts entered open beta on October 1, 2026, and requires a Workers Paid plan. Its repos behave as git remotes reachable over HTTPS with a token minted by a Worker. It has no web UI, browsing, or discovery of its own. `zz` provides those.
 
-No governance decision, review verdict, or dependency-graph snapshot lives purely in D1 or DO storage. Each is also committed as a human- and agent-readable record in `.zz/`. A load-bearing fact that exists only in Cloudflare's infrastructure breaks the portability guarantee above.
+## Portability
 
+A repo should be able to leave Cloudflare without losing anything that matters. To leave:
+
+1. `git clone --mirror` each repo. This copies the code, every branch including `zz-meta`, and every ref including the Ladder's git notes.
+2. Run the coordination layer anywhere else. The protocol (Asks, Answers, scopes, review before merge) is independent of Cloudflare, and the engine code in `app/engine/` already runs locally against a plain git clone in `--local` mode.
+
+Lane history is the gap today. It lives only in the Durable Object, so a mirror clone doesn't include it. Exporting it into the repo is planned. See [Data format](/docs/data-format/#lanes).
+
+The rule the design follows is that D1 and Durable Object storage are never the only copy of a decision. D1 already meets it, since everything there is either an index rebuildable from the repos or account data that belongs to no repo.
+