Expand description
§sealmap-corpus
Three jobs: the generated 1:1 Mermaid corpus (below); seal, the
lockfile and checks that keep hand-written diagram topics true to the
code they cite (sealmap verify); and pack, bounded review packs of
topics with the code they cite (sealmap pack).
Projects a Codebase into a contract-enforced, 1:1 corpus of dense
Mermaid diagrams plus machine-readable metadata, designed to be read by
LLM agents and merged by an orchestrating agent.
§The 1:1 contract
For every source file S in the codebase the corpus contains exactly one
document S.md, and nothing else in the corpus claims to describe S.
Each document records the BLAKE3 hash of the source it was generated from,
so drift is detectable without re-parsing. verify checks the contract
against a directory and reports, per file:
| Status | Meaning |
|---|---|
Drift::Missing | source exists, document does not |
Drift::Orphaned | document exists, source does not |
Drift::Stale | source changed since the document was generated |
Drift::Modified | source unchanged but document differs (hand edit, or generator/options changed) |
write() brings a directory into compliance (and only ever deletes files
that carry the sealmap header); sealmap generate --check runs verify
and writes nothing. The corpus is a regenerable view, not a gate.
§What a document contains
src/net/client.rs.md:
- YAML front matter: source path, module id, source hash, counts, and the list of fragment ids in the document.
- Structure: one
classDiagramof everything defined in the file (types with fields/variants/methods, a<<module>>box for free functions, constants and submodules) and their relations (implements, extends, owns, uses), with stubs for types defined elsewhere. - Sequences: one
sequenceDiagramper function or method that makes at leastCorpusOptions::min_callscalls, rendering its ordered call flow withalt/opt/loop/parfragments.
§Corpus-level files
Reserved names start with _ and never collide with sources:
_index.json: every document and fragment with its participants and the calls it makes, each call linked to the fragment that expands it. This is the merge map for an orchestrator: to inlineA’s call intoB, look up the call’sexpandsfragment._model.json: the fullCodebase(symbols, spans, signatures, docs, relations with confidence)._overview.md: cross-cutting views: crate/repository dependency graph, per-crate module graphs, data models (erDiagram) and trait maps._README.md: how to read all of the above, for agents.
§Stable ids
Every symbol is cited by its sym: id (sym:cargo shop . db/Db#insert().,
see sealmap_model::sym) in headings, front matter and the JSON files.
Every node, class, entity and participant id is derived from that id by
an injective encoding (shop__db___tDb___finsert, see
sealmap_mermaid::Ident::from_symbol), so the same symbol has the same
id in every diagram of every document, no two symbols share one, and
diagrams can be concatenated, merged or diffed by id. generate asserts
that uniqueness over the whole codebase.
§Example
use sealmap_corpus::{CorpusOptions, generate};
use sealmap_model::SourceSet;
use sealmap_rust::{RustOptions, extract};
let mut src = SourceSet::new();
src.insert("src/lib.rs", "pub struct A; impl A { pub fn go(&self) { helper(); } }\nfn helper() {}").unwrap();
let model = extract(&src, &RustOptions { name: "demo".into(), ..Default::default() }).codebase;
let corpus = generate(&model, &CorpusOptions::default());
let doc = corpus.document("src/lib.rs.md").unwrap();
assert!(doc.contains("sequenceDiagram"));
assert!(doc.contains("demo___tA->>demo: helper()"));
assert!(corpus.document("_index.json").is_some());Modules§
- pack
- Review packs: one deterministic, bounded text holding chosen topics, the dense slice of the code each one cites and a window of that code’s source. An outside reviewer, a seal review or a debugging session reads the pack instead of the repository.
- review
- Evidence-backed dispositions adjacent to an immutable review export.
- route
- Portable model-route declarations and fail-closed family checks.
- seal
- Seals: the record that a hand-written topic was reviewed against exact versions of the code it cites, and the checks that keep that record true.
- tiers
- Portable per-corpus, per-activity route records.
Structs§
- CallRef
- One call made by a sequence fragment.
- Corpus
- A generated corpus: relative output path → file contents, plus the index.
- Corpus
Options - Options controlling projection. Every option is part of the output’s
identity: changing one changes the documents, which
verifyreports asDrift::Modified. - Document
Entry - One document (one per source file).
- Drift
Entry - One deviation.
- Fragment
Entry - One diagram inside a document.
- Index
- The corpus index.
- Report
- Result of
verify/write().
Enums§
- Drift
- How a corpus file deviates from the contract.
- External
Lanes - How external callees appear as sequence-diagram participants.
- Fragment
Kind - Kind of diagram fragment.
Constants§
- CORPUS_
SCHEMA_ VERSION - Version of the corpus layout, front-matter and
_index.jsonschema. - DOC_
SUFFIX - Suffix appended to a source path to name its document.
Functions§
- corpus_
hash - Hash of a whole corpus (all paths and contents), for cheap equality checks across machines.
- document_
path - Map a source path to its document path (
src/a.rs→src/a.rs.md). - generate
- Generate the full corpus in memory. Pure and deterministic: equal inputs give byte-identical output.
- is_
reserved truefor corpus-level files (_index.json, …).- read_
dir_ corpus - Read every file under
dir(UTF-8 only) keyed by relative path. A missing directory reads as empty. - verify
- Verify the corpus in
diragainstexpected. - verify_
against - Compare
expected(freshly generated) withactual(file path → text as found on disk or elsewhere). - write
- Bring
dirinto compliance withexpected: write missing, stale and modified files, delete orphaned generated documents and a sealmap_model.jsonthatexpectedleaves out (and nothing else). Unchanged files are not touched, so mtimes stay stable. Returns what was changed.