# Generation-First Audit — July 2026

**Question:** what fraction of this repo is (or could be) generated by ggen from RDF specs,
and what stands between today and "all code starts from ggen, ≤0.1% custom"?

Computed at git `013bee436`, ggen v26.7.2, tokei 14.0.0 (Rust code lines, src/ only).
Re-run anytime: `bash scripts/generation-coverage.sh` (fails if any src file is unclassified).

## Headline numbers (`coverage.json`)

| Metric | Value | Meaning |
|---|---|---|
| Total workspace src LOC | **167,380** | 17 packages (`cargo metadata`), src/ only |
| **generation_coverage** | **3.16%** | 5,184 LOC actually generated — all of it `crates/ggen-a2a-mcp/src/a2a_generated/` |
| GENERATABLE-NOW | 797 LOC | template + spec exist, wiring missing (cpmp registry.rs, generated_commands.rs, standards.rs) |
| GENERATABLE-WITH-SPEC | 52,617 LOC | boilerplate-shaped; needs TTL authored, no new algorithms |
| **potential_coverage** | **35.7%** | what generation reaches without touching the custom core |
| IRREDUCIBLY-CUSTOM | 105,623 LOC (64.3%) | dominated by ggen-core (70k) + ggen-graph + LSP analyzers — mostly **E-ledger** (engine core) candidates, see below |
| DEAD-DELETE | 3,159 LOC | free coverage: delete before generating anything |

### The three-ledger reading (target definition)

Literal 0.1% over all LOC is not the goal — the machinery itself (μ-pipeline, RDF/SPARQL
engine, crypto/receipts, LSP analyzers) is human-owned by design. The trackable goal:

- **E — Engine core** (reviewed allowlist, excluded from the ratio). The per-crate audits
  nominate E-ledger candidates totaling roughly 85–95k of the 105k custom LOC
  (ggen-core machinery, ggen-graph library, ggen-lsp analyzers/route/intel, crypto modules).
- **G — Generated** (byte-identity verified). Today: 5,184 LOC — **and none of it is
  currently reproducible**: no rule in ggen.toml regenerates `a2a_generated/` (see
  machinery-gaps.md §"the flagship is unwired twice over").
- **C — Custom glue**: everything else. **Goal: C/(G+C) ≤ 0.1%**, ratcheted 25%→50%→80%→95%.

Under that reading, the honest current state: **G ≈ 5.2k, C ≈ 60–70k glue, E ≈ 90k** —
the work is converting the ~53k GENERATABLE-WITH-SPEC into G by authoring TTL + templates.

## What the audit found (details in linked files)

1. **The flagship generation rule is broken three ways** (machinery-gaps.md): the template
   indexes `row["?cmd"]` while the engine strips `?` (`codegen/pipeline.rs:845`);
   `| default(value="")` silently masks every miss; and the output `COMMANDS_REFERENCE`
   has zero consumers. The doctrine's one live example emits 8 empty tuples.
2. **Even the real generated code is orphaned**: `a2a_generated/` (5,184 LOC, 67.6% of its
   crate, header "regenerate with: ggen sync") has no wired rule — regeneration is
   currently impossible. The G-ledger's only member fails the reproducibility bar.
3. **P0 status corrections** (verified in code, superseding MASTER_TODO): P0-01 SHACL is
   no longer an always-pass stub — real SPARQL-backed checks exist; the residual defect is
   a fail-open at `shacl.rs:137-140`. P0-02 (wrong sync pipeline: `GenerationPipeline`
   in production, `StagedPipeline` only reachable from tests) is **still fully open**.
   P0-03 (namespaces) is substantially fixed; endpoint-URL residue remains.
4. **490 of 491 templates are dark**; 5 unused whole-crate CLI templates sit in
   `.specify/templates/cli/`; `cli_generator/` (ontology→workspace, tested) has no CLI
   entry; `project_generator/` is hardcoded strings.
5. **Docs: zero generated** (docs-audit.md). 990 md files in docs/: ~62% stale-delete
   candidates (docs/archive/ alone is 48%), ~10% derivable-from-TTL, ~28% keep. The
   "RDF is truth, .md is generated" rule has no implementation — the 864 "generated"
   markers are doctoc TOC blocks.
6. **New dead code found beyond the consolidation analysis**: root package src/ is 93.5%
   orphaned cpmp residue (201 LOC, modules never declared); ggen-config carries a
   2,089-LOC `#![allow(dead_code)]` swarm-coordination cluster with zero consumers.

## Per-crate summary (full audits in crates/)

| Crate | LOC | Generated | Generatable (now+spec) | Custom | Dead | Note |
|---|---|---|---|---|---|---|
| ggen-core | 95,776 | 0 | 26.5% | 73.6% | ~1k test-in-src | IS the machinery; most custom is E-ledger |
| ggen-marketplace | 18,942 | 0 | ~40% | ~60% | — | P0-03 trust-blocker cited |
| ggen-lsp | 11,687 | 0 | 29.1% | 70.9% | 1 file | analyzers/route/intel = E-ledger |
| ggen-cli | 11,665 | 0 | 74% | 26% | — | archetypal generation target |
| ggen-graph | 7,921 | 0 | 18% | 82% | artifacts | E-ledger library; 41% is gall_* audit bins |
| ggen-a2a-mcp | 7,671 | **67.6%** | 25.9% | 6.5% | — | the existence proof; rule unwired |
| ggen-config | 6,014 | 0 | 47.8%* | 52.2%* | **2,089** | *after dead subtraction |
| star-toml | 2,174 | 0 | ~17% | ~83% | — | merges into ggen-config |
| cpmp | 1,985 | 0 | 75% | 25% | — | registry.rs is GENERATABLE-NOW (dupes its own catalog.ttl) |
| genesis-core-v2 | 1,253 | 0 | 35% | 65% | 1 file | needs yawl-patterns.ttl |
| genesis-types-v2 | 793 | 0 | ~90% | ~10% | — | first-conversion candidate |
| stpnt | 675 | — | — | — | **675** | REMOVE (re-implemented in ggen-core) |
| ggen-lsp-mcp | 310 | 0 | ~87% | ~13% | — | merges into ggen-lsp |
| root ggen | 215 | 0 | 6.5% | 0 | **201** | orphaned cpmp residue |
| genesis-schema-v2 | 205 | 0 | 100% | 0 | — | merges into genesis-types-v2 |
| genesis-core | 194 | — | — | — | **194** | REMOVE (duplicated in core-v2) |
| ggen-lsp-a2a | 115 | 0 | ~90% | ~10% | — | merges into ggen-lsp |

## Roadmap to 0.1% custom glue

**Phase 0 — credibility (S/M each).** Fix the template key bug and make missing SPARQL
bindings fail loud (kill the `default(value="")` masking); wire `COMMANDS_REFERENCE` into
the CLI; **re-wire the a2a_generated rule** so the only G-ledger member is reproducible;
add a `ggen sync --check` CI drift gate (regenerate + diff, byte-identity); fix the SHACL
fail-open (`shacl.rs:137-140`); route production sync through `StagedPipeline` (P0-02);
single-source version stamps (MANIFESTO v30.1.1 / README v26.7.1 / tag v26.7.2 disagree).

**Phase 1 — free coverage (S, parallel).** Delete the 3,159 DEAD LOC (stpnt, genesis-core,
root residue, ggen-config dead cluster) and execute the consolidation analysis (LSP trio →
ggen-lsp, star-toml → ggen-config, schema-v2 → types-v2). Every deleted/merged crate is
spec surface never written.

**Phase 2 — dogfooding, in order.** (1) genesis-types-v2 as first full-crate conversion
(~90% derive structs — establishes "a crate owned by its ontology"); (2) cpmp registry.rs
(GENERATABLE-NOW — it hand-duplicates its own catalog.ttl); (3) expand cli-commands.ttl to
all 24 command modules using the multi-file emission engine + the 5 unused crate templates,
optionally graduate `cli_generator/` into `ggen cli new` (L); (4) ggen-config schema (M);
(5) ggen-lsp protocol layer post-merge (M); (6) convert codegen emitters + project_generator
payloads from hardcoded strings to .tera+TTL (M).

**Phase 3 — inverse-sync bootstrap loop.** Build the round-trip harness once (extract via
`ggen inverse-sync` → curate TTL → regenerate → diff → receipt; a2a-mcp as the regression
fixture), then it's an S-sized per-crate procedure gating each Phase-2 flip.

**Phase 4 — docs generation (after 2.3).** TTL→md is just another emission rule: CLI
reference first (spec + query already exist), then crate API refs from inverse-sync TTL,
version-stamped headers, pack catalogs. Prune the ~62% stale docs.

**Phase 5 — the ratchet.** `ggen coverage` (or extend doctor) computes G/(G+C) from the
emission ownership map verified by byte-identity; receipt per sync; CI rule: coverage may
not decrease. Trajectory: 3.2% → ~6% (Phase 2.1-2.2) → 15–20% (2.3) → 40–50% (Phase 2
complete) → 80%+ (docs counted) → 95%+ / 0.1%-glue standing ratchet.

## Files

- `METHODOLOGY.md` — taxonomy, metric formulas, anti-gaming rules, how to re-run
- `classification.tsv` — the hand-curated manifest (source of truth), assembled from `tsv-fragments/`
- `coverage.json` — committed metric snapshot (git SHA embedded)
- `crates/*.md` — 17 per-package audits with evidence commands
- `docs-audit.md` — disposition of the 990-file docs tree
- `machinery-gaps.md` — the 5 wiring gaps + P0 status corrections, file:line
- `supersessions.md` — how this audit relates to the 3 prior audit artifacts
