# CapDAG > The CapDAG specification. ## For agents - [Agent onboarding: set up CapDAG](https://machinefabric.com/capdag/agents.md): How an AI coding agent installs the capdag command on macOS or Linux, and uses it to find capabilities, run them on files, and plan and run machines of them. ## Start - [Overview](https://machinefabric.com/capdag/docs/01-overview/): What the CapDAG specification covers, how its documents fit together, the terminology they share, and what an implementation must do to conform. ## Foundations - [Formal foundations](https://machinefabric.com/capdag/docs/02-formal-foundations/): The mathematical foundation of CapDAG: the tagged URN domain, its base relation and derived predicates, cap URNs as a product, and the dispatch relation. - [Tagged URN domain](https://machinefabric.com/capdag/docs/03-tagged-urn-domain/): The tagged URN domain: syntax, normalization, what a tag constrains and how it is written, and the base relation every comparison is built on. - [Predicates](https://machinefabric.com/capdag/docs/04-predicates/): The predicates that compare tagged URNs, what each one guarantees or merely allows, and which one to use where. - [Specificity](https://machinefabric.com/capdag/docs/05-specificity/): How CapDAG scores how constrained a tagged URN or cap URN is, and how that score is used to rank candidates. ## Dispatch and routing - [Cap URN structure](https://machinefabric.com/capdag/docs/06-cap-urn-structure/): The structure of a cap URN: its input, output, cap-tag and effect dimensions, its canonical string form, and the five cap kinds. - [Dispatch](https://machinefabric.com/capdag/docs/07-dispatch/): The dispatch predicate that decides whether a registered capability can serve a request, and the mistakes it guards against. - [Ranking](https://machinefabric.com/capdag/docs/08-ranking/): How CapDAG chooses among the candidates that are valid for a request: specificity distance, preference order, and tie-breaking. ## Machine notation and data types - [Machine notation](https://machinefabric.com/capdag/docs/09-machine-notation/): Machine notation, the textual encoding of capability strands wired into data-flow graphs, and how it is parsed and made canonical. - [Validation rules](https://machinefabric.com/capdag/docs/10-validation-rules/): Every validation rule CapDAG implementations enforce on cap URNs, cap definitions, media definitions, and across definitions. - [Media URNs](https://machinefabric.com/capdag/docs/11-media-urns/): Media URNs: how CapDAG names data types, the top and unit types, the ext/fmt/enc axes, and how media types are matched. ## Protocol - [Architecture](https://machinefabric.com/capdag/docs/12.1-architecture/): How CapDAG's components connect, what role each plays, and how frames flow from the engine through relays to cartridges. - [Frame protocol](https://machinefabric.com/capdag/docs/12.2-frame-protocol/): The Bifaci wire format: length-prefixed CBOR frames, their keys, and the semantics of every frame type. - [Handshake](https://machinefabric.com/capdag/docs/12.3-handshake/): Connection setup between host and cartridge: the HELLO exchange, limit negotiation, manifest exchange, and identity verification. - [Streaming](https://machinefabric.com/capdag/docs/12.4-streaming/): How a request carries multiple named streams, how data is chunked and sequenced, and how out-of-order frames are reordered. - [Flow control](https://machinefabric.com/capdag/docs/12.5-flow-control/): Credit-based per-stream flow control: the laws it obeys, the frames that carry it, teardown, overruns, and protocol statistics. ## Cartridge runtime - [Cartridge runtime](https://machinefabric.com/capdag/docs/13.1-cartridge-runtime/): The cartridge-side runtime: manifest construction, handler registration, mode detection, and the main frame-processing loop. - [Input and output](https://machinefabric.com/capdag/docs/13.2-input-output/): How cartridge handlers receive input and emit output through typed, flow-controlled streams. - [Peer invocation](https://machinefabric.com/capdag/docs/13.3-peer-invocation/): How a cartridge calls a capability provided by another cartridge while it is handling a request. - [Progress and logging](https://machinefabric.com/capdag/docs/13.4-progress-and-logging/): How cartridges emit progress, log messages and keepalives, and how they travel through the execution chain. ## Host and relay - [Host runtime](https://machinefabric.com/capdag/docs/14.1-host-runtime/): The host-side runtime that spawns cartridge processes, routes frames to and from them, and monitors their health. - [Relay switch](https://machinefabric.com/capdag/docs/14.2-relay-switch/): The relay switch, the cap-aware multiplexer that routes requests from the engine to the relay master able to serve them. - [Relay topology](https://machinefabric.com/capdag/docs/14.3-relay-topology/): Relay slaves and relay masters, and how relay chains bridge cartridge hosts to the relay switch. ## Execution - [Orchestrator](https://machinefabric.com/capdag/docs/15.1-orchestrator/): How the orchestrator turns machine notation or a machine plan into a validated graph of resolved caps, ready for execution. - [Execution](https://machinefabric.com/capdag/docs/15.2-execution/): How a plan is run: scopes and units, scheduling, maps, absent values, step policy, streaming, and stopping a run. - [Progress mapping](https://machinefabric.com/capdag/docs/15.3-progress-mapping/): How progress values are deterministically subdivided and mapped through nested execution layers. - [Planner](https://machinefabric.com/capdag/docs/15.4-planner/): How the planner finds a path of caps from a source media type to a target, builds a plan, and executes it. ## Cartridge development - [Cartridge anatomy](https://machinefabric.com/capdag/docs/16.1-cartridge-anatomy/): The structure of a cartridge: entry point, manifest, cap definitions, handler registration, and lifecycle. - [Handler patterns](https://machinefabric.com/capdag/docs/16.2-handler-patterns/): Patterns for writing cartridge request handlers: the Op trait, argument extraction, output emission, progress, and errors. - [Model cartridges](https://machinefabric.com/capdag/docs/16.3-model-cartridges/): How machine-learning cartridges download models through peer calls, load them with keepalive, and stream inference progress. - [Content cartridges](https://machinefabric.com/capdag/docs/16.4-content-cartridges/): How document-processing cartridges for PDF and text are structured, and the standard cap patterns they use. - [Rust vs Swift](https://machinefabric.com/capdag/docs/16.5-rust-vs-swift/): How the Rust and Swift/Objective-C implementations of CapDAG differ, and how to write a cartridge in each. ## Runtime errors - [Error handling](https://machinefabric.com/capdag/docs/17.2-error-handling/): How CapDAG carries the attribution and location of a diagnostic structurally, on the wire and through execution. ## The capdag command - [Installing the CapDAG CLI](https://machinefabric.com/capdag/docs/18.0-installing/): Every way to install the capdag command: Homebrew, apt, dnf, or a direct download. - [CapDAG CLI reference](https://machinefabric.com/capdag/docs/18.1-cli-reference/): Reference for the capdag command: running caps and machines, inspecting the fabric, and developing cartridges. - [Build and run a cartridge](https://machinefabric.com/capdag/docs/18.2-getting-started-cartridge-development/): A tutorial that takes a cartridge through the local development loop: scaffold, build, install, run, change, and reinstall. - [The terminal interface](https://machinefabric.com/capdag/docs/18.3-terminal-interface/): What capdag shows in a terminal: the live view of a run, the pickers, and the full-screen graph of a machine to look at or edit — and the keys that drive each. - [Your first run with the capdag CLI](https://machinefabric.com/capdag/docs/18.4-first-run/): A lesson: find a capability, run it on a file, plan a machine of several steps, run it, and stop a run. - [When a capdag command fails](https://machinefabric.com/capdag/docs/18.5-when-a-command-fails/): How to read what a failed capdag command says, and what to do for each kind of failure. - [Work on the terminal interface with worlds and journeys](https://machinefabric.com/capdag/docs/18.6-terminal-interface-worlds/): How to run any capdag command on a world of test data, play and check journeys, add journeys and worlds, script a run, and take a new fabric snapshot. - [Terminal interface reference: crates, Host, worlds and journeys](https://machinefabric.com/capdag/docs/18.7-terminal-interface-reference/): The crates the capdag command is built from, the Host interface its terminal interface runs against, the capdag-tuikit binary, and the formats of worlds, run scripts and journeys. ## Project - [Contributing](https://machinefabric.com/capdag/docs/99-contributing/): How to propose a new capability or media definition for the CapDAG registry, and what makes a submission acceptable.