feat(stage5): label-strip retry for package overview diagrams#60
Merged
Conversation
…d — closes #59 Stage 5 emits a per-package overview diagram by merging each package's per-class classDiagrams. On the agent-brain dogfood, one package (`config`) ended up diagram-less because a single relationship label contained `;` and `()`, which mermaid's parser rejected. When validate() rejects the first merge, retry once with every arrow label stripped (everything after `:` on relationship lines). If the stripped form passes mmdc, write it. If it also fails, fall back to the existing fail-soft path (leave the README untouched). The retry result is "boxes + bare arrows" — less informative than a labelled diagram, but it ships rather than getting dropped. mmdc's label grammar has enough fragile edge cases (semicolons, parens, quoting) that aggressive stripping is the right universal escape hatch. Unit coverage: * _strip_arrow_labels helper: strips arrow labels, leaves unlabelled arrows alone, preserves class-body `:` (e.g. `+bar: str`). * _emit_package_diagrams: retries with stripped labels when first validate fails; stays fail-soft when retry also fails. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When Stage 5's merged per-package overview diagram fails
mmdcvalidation, retry once with every arrow label stripped. If the stripped diagram passes, write it; otherwise stay fail-soft.Why
PR #58 brought per-package overview diagrams to package READMEs. The agent-brain dogfood reached 22/24 packages — the
configpackage missed out because one of its arrow labels contained;and(), which mermaid's parser rejects:Mermaid's relationship-label grammar is fiddlier than its node grammar —
;is rejected,()is sometimes rejected, and quoting rules are undocumented. The per-class diagrams passmmdcindividually because each has only a few simple arrows; merging 11 of them stacks enough exotic labels that one breaks the whole parse.Aggressive label stripping is the universal escape hatch: the retry's "boxes + bare arrows" output is less informative than a labelled diagram, but it ships rather than getting dropped, and on the agent-brain run this turns 22/24 into 24/24.
Closes #59.
Changes
src/designdoc/stages/s5_mermaid.py_strip_arrow_labels(diagram_text)helper: drops everything after:on lines containing a mermaid classDiagram arrow op (and not starting withclass). Class-body:is preserved._emit_package_diagrams: aftervalidate(merged)fails, retry once with stripped labels. Write the stripped form if it passes; otherwise unchanged fail-softcontinue.tests/unit/test_stage5_package_diagrams.pymonkeypatchso the retry control flow is pinned independently ofmmdcversion quirks.Invariants
mmdcstill gates every write; the retry just givesmmdca second, weaker candidate to validate before falling back to fail-softVerification
task cigreen locally (107 passed in 53.95s — lint + unit + integration includingtest_stage5_appends_package_overview_diagram_to_readme)ImportError: _strip_arrow_labels→ implementation → GREEN)Related