> For the complete documentation index, see [llms.txt](https://stemma.sh/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stemma.sh/docs/examples.md). Agents can also search and read this documentation through its [MCP server](https://stemma.sh/docs/~gitbook/mcp).

# Examples

Runnable, compile-gated code for the common flows. Every example is a single file in a public workspace crate's `examples/` directory, uses only supported public surfaces, and is compiled with warnings denied as part of the merge gate, so none of them can silently rot. Each file's header comment explains, step by step, what it demonstrates.

## Learn the loop

In reading order: each teaches one idea from the guide chapters, end to end, through the public facade.

### `quickstart`

The full durable loop in one file: parse DOCX bytes, read the projection, author one tracked edit as a typed transaction, serialize, re-parse, and assert the edit landed.

```bash
cargo run -p stemma --example quickstart
```

### `walk_the_document`

Walk the blocks and see that one file is three documents: the redline, the accept-all reading, and the reject-all reading, each projected without mutating the stored document.

```bash
cargo run -p stemma --example walk_the_document
```

### `my_first_edit`

One tracked replacement, end to end: apply through the v4 wire path, read the receipt (which block changed, which revision id was created), and prove the output is validator-clean.

```bash
cargo run -p stemma --example my_first_edit
```

### `resolve_a_redline`

Resolve a two-author redline selectively, then verify by CONTENT: accept and reject both remove the marker, so only the resulting text proves which happened.

```bash
cargo run -p stemma --example resolve_a_redline
```

### `review_before_save`

The review-before-save discipline: one `review()` call reports the tracked census, any untracked delta, an untouched-scope proof, and the validator verdict on the would-be bytes.

```bash
cargo run -p stemma --example review_before_save
```

## Measure and prepare

Operational tools that happen to live in the same directory; not part of the learning path.

### `bench`

Latency benchmark for the facade: p50/p95 for cold parse, one tracked apply, and serialize at each validator level. Needs a release build.

```bash
cargo run -p stemma --release --example bench
```

### `revision_roundtrip`

Corpus preparation: parse and reserialize every document in a manifest so revision inventories can be compared externally. Takes arguments; see the file header.

```bash
cargo run -p stemma --release --example revision_roundtrip
```

## Compare documents

Use the opinionated comparison subsystem on two independently authored documents.

### `redline_from_two_files`

Parse a base and target document, infer their differences, emit one native tracked-change redline, and write it without folding comparison logic into the engine.

```bash
cargo run -p stemma-diff --example redline_from_two_files -- base.docx target.docx redline.docx
```

## Related

* [Create your first redline](https://stemma.sh/docs/getting-started.md): the CLI-first walkthrough.
* [Embed the engine](https://stemma.sh/docs/reference/embedding.md): the facade these examples exercise.
* [Concepts](https://stemma.sh/docs/understand-the-model/concepts.md), [Revisions](https://stemma.sh/docs/understand-the-model/revisions.md), [Editing](https://stemma.sh/docs/understand-the-model/editing.md): the chapters the learning examples teach.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://stemma.sh/docs/examples.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
