7.2 KiB
Agent Note: Documentation graph index for maintainers and SDK users
Status: implemented
Problem
The repo already had several high-trust documentation surfaces, each on a different axis: module-graph.md is generated from package peerDependencies, the generated Cordis events and services catalogs are generated from Cordis Events and Context declarations, tool-catalog.md is generated by booting shipped tool plugins, and core-data-structures/ uses ts type-equiv blocks to keep pasted type definitions synchronized with source.
Those references are accurate, but they are mostly catalogs. A maintainer still has to synthesize the relationships: which packages form a capability seam, which app bundles a concrete spine, which event is durable vs live, where a hook or policy plugin can intercept work, and which model-facing tool depends on which service. An SDK user has the same problem from another angle: "Which package do I install or load for the behavior I want, and which event/service/tool do I extend?"
The hooks subsystem makes event producer/consumer topology and interception points much more important, and the filesystem seam makes capability seams, policy vetoes, tool presentation, and SDK assembly paths much more important — relationship graphs scoped to a small bash/todo/subagent surface would have gone stale immediately.
Decision
Add generated relationship graph docs, indexed at docs/graph-atlas.md, produced by focused generators and verified by pnpm run verify-doc-graphs / existing catalog freshness checks as part of doc-sync.
The index is a relationship layer above the existing catalogs. It does not replace exact references; instead, it links to them and explains how their pieces fit together.
Maintenance modes
Every graph page declares one maintenance mode:
- Generated: all nodes and edges are discovered from source;
--checkfails if the committed artifact is stale. - Hybrid generated: source discovers the inventory, a small manifest classifies irreducible policy, and a completeness guard fails if discovered items are unclassified.
- Curated: the diagram explains design intent, temporal order, or ownership; it is emitted by the generator so the graph docs remain a regenerated unit, but the content is deliberately authored.
First shipped index
The index links eleven relationship surfaces. Package topology and tool-package affordances live in the existing generated catalogs that already own those facts; the remaining focused diagrams are generated by scripts/gen-doc-graphs.ts.
| Graph | Maintenance mode | Source of truth |
|---|---|---|
| module dependency graph | generated | packages/*/*/package.json peer dependencies plus package group paths |
| tool schema catalog and package map | generated | boot-harvested tool schemas plus tool-package service/effect metadata |
| capability seams and core services | hybrid generated | Cordis service declarations plus a role manifest in gen-doc-graphs.ts |
| tui-agent app composition | hybrid generated | examples/tui-agent/cordis.yml plugin list plus curated app/bundle expansion |
| headless-agent app composition | hybrid generated | examples/headless-agent/cordis.yml plugin list plus curated app/bundle expansion |
| cordis-agent app composition | hybrid generated | examples/cordis-agent/cordis.yml plugin list plus curated app/bundle expansion |
| acp-agent app composition | hybrid generated | examples/acp-agent/cordis.yml plugin list plus curated app/bundle expansion |
| event producer/consumer matrix | hybrid generated | Cordis event declarations, AST-scanned ctx.on/emit/parallel/serial/waterfall sites, and explicit dynamic dispatch overrides |
| agent turn and step lifecycle | curated | architecture.md loop lifecycle, Cordis catalog links, and session event semantics |
| tool execution pipeline | curated | tool pipeline semantics and the tools/execute waterfall |
| ACP snapshot replay | curated | snapshot harness behavior |
Why generators own the docs
Package topology stays in gen-module-graph.ts, and tool-package affordances stay in gen-tool-catalog.ts, because those generators already own the canonical facts and freshness gates. gen-doc-graphs.ts owns the remaining relationship pages and the index. The tradeoff is that curated diagrams are edited in TypeScript string blocks rather than directly in Markdown. That is acceptable for this first cut because the user-facing artifact is still plain Markdown/Mermaid, and a future change can split the curated pages out if authorship ergonomics matter more than regeneration.
Completeness guards
The hybrid pages must fail loud when their manifests are stale:
- The module graph reads every package's
peerDependenciesand groups each package by itspackages/<group>/<pkg>path. - The tool catalog boot-harvests shipped tools and renders the package/service/effect map from the same manifest that its completeness guard already checks.
- The capability seam graph imports the Cordis service collector and asserts every discovered harness
ctx.<key>is classified inSERVICE_ROLES, and every classified key still exists. - The event producer/consumer matrix labels itself hybrid because subagent lifecycle events deliberately use
ctx.events.dispatchfor per-listener containment; those dynamic edges are explicit overrides rather than invisible omissions. verify-mermaidparses every repo-authored```mermaidfence with Mermaid's own parser, so syntax errors faildoc-synclocally and in CI instead of showing up as broken GitHub-rendered diagrams.
Alternatives considered
Committed diagrams use Mermaid because GitHub renders it in Markdown and it adds no new docs build dependency; dense many-to-many data such as event producer/consumer relationships uses Markdown tables instead. PlantUML, hosted diagram services, and generated SVGs were considered and deliberately not adopted until Mermaid becomes the limiting factor.
Consequences
- Maintainers get visual entry points for topology, seams, event flow, lifecycle, app composition, and snapshot behavior.
- SDK users get a path from use case to package composition instead of only bottom-up package references.
doc-syncnow includesverify-doc-graphsandverify-mermaid, so graph drift and Mermaid syntax errors are caught with the other doc freshness gates.- Future fs and hooks work has a concrete place to land new complexity: fs should expand the capability docs and tool catalog, while hooks should expand the event matrix and tool execution pipeline.