Documentation
¶
Overview ¶
Package emit renders analysis results into machine- and CI-consumable artifacts (findings.json, JUnit XML) and writes them safely under an output directory. It is infrastructure: it may import the domain and third-party libraries, but the domain never imports it (ADR 0004). All emitted bytes are deterministic (the AnalysisReport is pre-sorted) so artifacts are byte-stable.
Index ¶
- Constants
- func CategoryLabel(cat string) string
- func EscapeInlineCode(s string) string
- func EscapeMarkdownText(s string) string
- func EscapeTableCell(s string) string
- func FindingsJSON(report *analysis.AnalysisReport, okf OKFVerdict) ([]byte, error)
- func FixPrompt(report *analysis.AnalysisReport, opts FixPromptOptions) []byte
- func JUnitXML(report *analysis.AnalysisReport) ([]byte, error)
- func OKFReason(f analysis.Finding) string
- func OKFRuleLabel(k analysis.FindingKind) string
- func ReachableSet(m *graphmodel.GraphMetrics) (set map[identity.DocumentID]struct{}, indeterminate bool)
- type Counts
- type DocView
- type FSWriter
- type FixPromptOptions
- type OKFVerdict
- type View
- func (v View) Backlinks(id identity.DocumentID) []identity.DocumentID
- func (v View) Doc(id identity.DocumentID) (DocView, bool)
- func (v View) Document(id identity.DocumentID) (*corpus.Document, bool)
- func (v View) EmitExcluded(id identity.DocumentID) bool
- func (v View) EmitExcludedCount() int
- func (v View) EmitExcludedRoots() []identity.DocumentID
- func (v View) RenderedBacklinks(id identity.DocumentID) []identity.DocumentID
- func (v View) RenderedTrails() []graphmodel.Trail
- func (v View) TitleOf(id identity.DocumentID) string
- func (v View) WithEmitExclude(patterns []string) View
Constants ¶
const ( FindingsJSONName = "findings.json" JUnitXMLName = "junit.xml" )
Artifact filenames (stable; CI integrations key on these).
const FindingsSchemaVersion = 8
FindingsSchemaVersion is the findings.json schema version. Adding optional fields is backward-compatible; renaming/removing a field or a Details key is a breaking change that bumps this. v2 added per-finding "details" (structured, machine-actionable context) and a top-level "remediationGuide" mapping each finding kind to a standalone how-to, so every finding is self-contained for an agent. v3 (ADR 0012) adds the graduated structure findings "under-linked" and "dead-end" (new kind values + summary counts). v4 (ADR 0013) adds the topology-based "suggested-link" finding (a new kind value + a suggestedLink summary count). v5 (ADR 0015) adds the critical-path "articulation-point" and "bridge" findings (two new kind values + articulationPoint/bridge summary counts). v6 (ADR 0016) adds the information-scent "low-scent-anchor" finding (a new kind value + a lowScentAnchor summary count). v7 (ADR 0021) adds the hops-from-root "far-from-root" finding (a new kind value + a farFromRoot summary count). v8 (ADR 0023) adds the OKF v0.1 conformance-mode findings "okf-missing-frontmatter", "okf-missing-type", "okf-reserved-file-structure" (three new kind values + three summary counts) and the always-present top-level "okfConformance" object (checked:false when the mode is off).
const FixPromptName = "fix-prompt.md"
FixPromptName is the artifact filename for the agent-ready fix prompt.
Variables ¶
This section is empty.
Functions ¶
func CategoryLabel ¶
CategoryLabel renders a document's category (its directory) for display: the root directory ("." or "") becomes the explicit "(root)" label, everything else passes through verbatim. It is the ONE shared implementation used by every emitter that surfaces a category (index.md, graph.json, llms.txt) so the label can never silently drift between artifacts. Callers that render the label in a single-line context must still collapse newlines themselves (a directory name may legally contain one on Linux).
func EscapeInlineCode ¶
EscapeInlineCode escapes a string for inclusion inside a single-backtick code span: a literal backtick would close the span and a newline would break it, so both are neutralized (ADR 0003).
func EscapeMarkdownText ¶
EscapeMarkdownText escapes a string for safe inclusion in flowing Markdown (not a table cell): newlines collapse to spaces and Markdown-significant characters are backslash-escaped so a hostile value cannot inject formatting or HTML (ADR 0003).
func EscapeTableCell ¶
EscapeTableCell escapes a string for safe inclusion in a GFM table cell. It is EscapeMarkdownText plus the pipe `|`, which would otherwise end the cell and let a hostile value forge extra columns or break the row (ADR 0003).
func FindingsJSON ¶
func FindingsJSON(report *analysis.AnalysisReport, okf OKFVerdict) ([]byte, error)
FindingsJSON renders an AnalysisReport as the canonical findings.json bytes (pretty-printed, trailing newline). The report's findings are already sorted, so output is deterministic.
The okf verdict is rendered into the always-present top-level okfConformance object (ADR 0023). Only the NON-DERIVABLE parts of the verdict are read from the parameter — Checked and Version; the three counts AND the conformant bit are DERIVED from the report's own okf-* finding counts, so findings.json can never emit an okfConformance inconsistent with its findings list (a hand-built verdict cannot lie about the counts). Pass the zero OKFVerdict (or OKFVerdictFromResult of a non-OKF run) for the mode-off shape (checked:false).
func FixPrompt ¶
func FixPrompt(report *analysis.AnalysisReport, opts FixPromptOptions) []byte
FixPrompt renders a self-contained, agent-agnostic prompt instructing an LLM coding agent to fix the documentation findings in this report, with the findings embedded inline. It is a generator, not a gate: a clean (or fully filtered) report yields a short no-op prompt. Output is deterministic (findings keep the report's total order; Details maps render with sorted keys) and ends with a trailing newline.
The default scope is curated (ADR 0020): all errors and warnings, plus the advisory (Info) findings that survive the emitExclude rule, with suggested-link and low-scent-anchor capped. findings.json always carries everything; Options.All reproduces the complete report.
FixPrompt consumes the full AnalysisReport (not emit.View) because the View drops the per-finding Details and message text an agent needs to act.
func JUnitXML ¶
func JUnitXML(report *analysis.AnalysisReport) ([]byte, error)
JUnitXML renders an AnalysisReport as JUnit XML bytes (with header and trailing newline). Findings are already sorted, so output is deterministic.
func OKFReason ¶ added in v0.0.8
OKFReason returns a one-line, user-facing reason for an OKF conformance finding (ADR 0023): the structured reason (R2/R3) or the frontmatter state (R1), falling back to the full message. Used by the terminal + markdown reports so a NOT CONFORMANT verdict names WHY each file failed, not just that it did.
func OKFRuleLabel ¶ added in v0.0.8
func OKFRuleLabel(k analysis.FindingKind) string
OKFRuleLabel maps an OKF conformance finding kind (ADR 0023) to the short rule label used in the human reports and the verdict line ("missing-frontmatter", "missing-type", "reserved-file").
func ReachableSet ¶
func ReachableSet(m *graphmodel.GraphMetrics) (set map[identity.DocumentID]struct{}, indeterminate bool)
ReachableSet returns the set of reachable document IDs and whether reachability is INDETERMINATE (no root set was found). It is the single shared reachability helper for the machine emitters (graph.json, llms.txt) so they cannot diverge on the indeterminate case: per ADR 0007, indeterminate is NOT the same as "everything unreachable" — callers must consult the returned flag and treat every document as reachable (do not mark anything unreachable) when it is true. A nil metrics carrier is treated as indeterminate with an empty set.
Types ¶
type Counts ¶
type Counts struct {
Documents int
Headings int
References int
BrokenLink int
BrokenAnchor int
Ambiguous int
Orphan int
Unreachable int
KnowledgeGap int
UnderLinked int
DeadEnd int
SuggestedLink int
FarFromRoot int
Components int
}
Counts are the corpus-overview tallies surfaced at the top of every report.
type DocView ¶
type DocView struct {
ID identity.DocumentID
// Title is the front-matter title, falling back to the first H1/heading,
// falling back to the DocumentID.
Title string
// Description is the front-matter description, falling back to the first
// heading text (ADR: the index.md description fallback to H1).
Description string
// Category is the document's directory ("." for top level).
Category string
// ModTime is the file's last-modified time.
ModTime time.Time
// InDegree / OutDegree are the projection navigational degrees.
InDegree int
OutDegree int
// Component is the WCC ID (sorted-min member) of the document.
Component identity.DocumentID
// Intentional reports the document opted out of orphan/unreachable findings.
Intentional bool
// Bowtie is the document's bow-tie bucket
// (core/in/out/tendril/disconnected), pure structure data (ADR 0012).
Bowtie string
// Betweenness is the document's betweenness-centrality score (ADR 0015): how
// load-bearing it is as a connector. IsArticulation marks it a cut vertex.
Betweenness float64
IsArticulation bool
// PageRank is the document's PageRank score (ADR 0016): global importance via
// the random-surfer stationary distribution.
PageRank float64
// Hops is the document's shortest hop distance from the nearest root
// (ADR 0021), or -1 when it is unreachable or the root set is indeterminate.
Hops int
}
DocView is a single document's presentation metadata, derived from its parsed Document plus the graph metrics (degree / component).
type FSWriter ¶
type FSWriter struct {
// contains filtered or unexported fields
}
FSWriter implements application.ArtifactWriter by writing artifacts under an output directory. Every artifact name is sanitized and verified to stay under the directory (reverse zip-slip, ADR 0003): a name that escapes is rejected with an error, never written.
func NewFSWriter ¶
NewFSWriter returns a writer rooted at outDir.
type FixPromptOptions ¶
type FixPromptOptions struct {
// ErrorsOnly restricts the embedded findings to severity==error (broken
// links/anchors), so an agent can be pointed at just the build-breaking work.
ErrorsOnly bool
// Kinds, when non-empty, restricts the findings to exactly these kinds — ALL
// of them: the default-mode caps are lifted (the emitExclude rule still
// applies). Order is preserved in the Scope line; callers dedupe.
Kinds []analysis.FindingKind
// All emits the complete, unfiltered report: every kind, every severity, no
// emitExclude filtering, no caps.
All bool
// EmitExclude carries the `.matlatl.yml emitExclude` patterns (gitignore
// dialect, ADR 0019). In default and Kinds modes, an ADVISORY (severity Info)
// finding is dropped when it touches an excluded document — its Location or
// a named pair endpoint. Gate-capable findings (Error + Warning) always
// render: fix-prompt's contract is "make `matlatl check` pass", and check is
// unaffected by emitExclude (ADR 0019, ADR 0020).
EmitExclude []string
}
FixPromptOptions tunes the generated prompt. At most one of ErrorsOnly, Kinds, and All may be set (the CLI enforces mutual exclusivity, exit 2).
type OKFVerdict ¶ added in v0.0.8
type OKFVerdict struct {
Checked bool
Conformant bool
Version string
MissingFrontmatter int
MissingType int
ReservedFileStructure int
}
OKFVerdict carries the OKF conformance verdict from the pipeline Result to the findings.json emitter (ADR 0023). The zero value (Checked:false) is the mode-off shape. Use OKFVerdictFromResult to build one from an application.Result.
func OKFVerdictFromResult ¶ added in v0.0.8
func OKFVerdictFromResult(res application.Result) OKFVerdict
OKFVerdictFromResult projects the OKF fields of a frozen pipeline Result into an OKFVerdict for the findings emitter and the verdict Line. When OKF mode was off, the result is the zero verdict (Checked:false), which renders okfConformance.checked=false.
func (OKFVerdict) Line ¶ added in v0.0.8
func (v OKFVerdict) Line() string
Line renders the one-line OKF conformance verdict (ADR 0023). It is the single home for the verdict wording, shared by the `check` summary (cmd/matlatl via OKFVerdictFromResult) and the human reports (terminal + markdown via View.OKF), so the two are byte-identical by construction. It is only meaningful when Checked is true; callers gate on that.
type View ¶
type View struct {
// Counts are the corpus-overview tallies.
Counts Counts
// Docs is every document, sorted by DocumentID, with presentation metadata.
Docs []DocView
// BrokenLinks / BrokenAnchors / Ambiguous are findings split by kind, each
// already sorted (the AnalysisReport sorts findings).
BrokenLinks []analysis.Finding
BrokenAnchors []analysis.Finding
Ambiguous []analysis.Finding
// LowScent are the low-scent-anchor findings (ADR 0016), already sorted. Info;
// they never gate the exit code.
LowScent []analysis.Finding
// Orphans (isolated) and Unreachable are the distinct ADR-0007 classes,
// sorted by DocumentID. Intentional orphans are already suppressed upstream.
Orphans []identity.DocumentID
Unreachable []identity.DocumentID
// UnderLinked and DeadEnd are the graduated structure tiers (ADR 0012), sorted
// by DocumentID. Mutually exclusive with Orphans and each other.
UnderLinked []identity.DocumentID
DeadEnd []identity.DocumentID
// FarFromRoot are the documents reachable but at or beyond the hop-distance
// threshold from every root (ADR 0021), sorted by DocumentID. Their per-doc
// hop distance is on the DocView (Hops). Empty when reachability is
// indeterminate. Root members and intentional orphans are suppressed upstream.
FarFromRoot []identity.DocumentID
// ReachabilityIndeterminate mirrors the metrics flag (no root set found).
ReachabilityIndeterminate bool
// OKF is the OKF v0.1 conformance verdict (ADR 0023), projected once from the
// pipeline Result. OKF.Checked gates whether the verdict line + violations
// section render at all; OKF.Line() is the shared verdict wording.
OKF OKFVerdict
// OKFViolations are the okf-* conformance findings (ADR 0023), already sorted
// (the AnalysisReport sorts findings). Rendered as a dedicated section in the
// human reports so NOT CONFORMANT names the offending files, not just a count.
OKFViolations []analysis.Finding
// TopHubs / TopAuthorities are HITS rankings (descending, tie-break by ID).
TopHubs []graphmodel.RankedDocument
TopAuthorities []graphmodel.RankedDocument
// TopPageRank are the documents ranked by PageRank (ADR 0016): global
// importance via the random-surfer stationary distribution, descending,
// tie-broken by ID. Pure data, surfaced in graph.json and the human report.
TopPageRank []graphmodel.RankedDocument
// Trails are the per-weak-component suggested reading orders (ADR 0016),
// sorted by Root. Surfaced in trails.json and the llms.txt reading-order block.
Trails []graphmodel.Trail
// TopBetweenness are the load-bearing docs ranked by betweenness centrality
// (ADR 0015), descending, tie-broken by ID. ArticulationPoints (cut vertices)
// and Bridges (cut edges) are the corpus' critical structure: single points of
// failure in the link graph. All pure data, surfaced in the reports/graph.json.
TopBetweenness []graphmodel.RankedDocument
ArticulationPoints []identity.DocumentID
Bridges []graphmodel.Bridge
// Gaps are experimental knowledge-gap bridge candidates (sorted upstream).
Gaps []graphmodel.Gap
GapsTruncated bool
// SuggestedLinks are topology-based link-prediction suggestions (ADR 0013),
// ranked by Adamic/Adar upstream. An additive signal alongside Gaps.
SuggestedLinks []graphmodel.LinkSuggestion
SuggestedLinksTruncated bool
// compactness, stratum, characteristic/median path length, clustering,
// diameter. Pure data, surfaced in graph.json and the human reports.
Navigability graphmodel.Navigability
// BrokenEdges are unresolved navigational references (origin → raw target),
// for the diagram emitters' red placeholder target nodes. Sorted upstream.
BrokenEdges []application.BrokenEdge
// Metrics is the frozen graph-analysis carrier, for emitters that render the
// graph itself (mermaid, dot). Read-only.
Metrics *graphmodel.GraphMetrics
// contains filtered or unexported fields
}
View is the render-ready, emitter-agnostic snapshot every human emitter (terminal, markdown, mermaid, dot, index) renders from. It is derived ONCE from the frozen application.Result + corpus.Corpus and is itself treated as immutable: emitters read it, never mutate the domain model (ADR 0004). All slices are sorted so every emitter produces byte-stable output.
The corpus is required because the GraphMetrics/AnalysisReport do not carry per-document presentation data (title, description, mod-date); those come from the parsed Document. The corpus is read-only here.
func BuildView ¶
func BuildView(res application.Result) View
BuildView assembles the render-ready View from a frozen pipeline Result. The Result's Corpus is read-only. Panics are avoided: a nil Metrics or Corpus yields an empty-but-valid View.
func (View) Backlinks ¶
func (v View) Backlinks(id identity.DocumentID) []identity.DocumentID
Backlinks returns the documents that navigationally link TO id (ADR 0016), sorted by DocumentID (= path) and self-excluded — exactly the document projection's in-neighbours. Empty when nothing links to id or metrics are absent. This realizes Nelson's Xanadu two-way links: every page can show what points at it, not just where it points. Derived from the existing projection (no redundant graph.json array).
func (View) Doc ¶
func (v View) Doc(id identity.DocumentID) (DocView, bool)
Doc returns the DocView for id and whether it exists.
func (View) Document ¶
Document returns the frozen *corpus.Document for id and whether it exists. The returned document is READ-ONLY (ADR 0004): the machine emitters read its section tree / front matter but must not mutate it.
func (View) EmitExcluded ¶ added in v0.0.2
func (v View) EmitExcluded(id identity.DocumentID) bool
EmitExcluded reports whether id is excluded from the consumption surfaces. Always false when no emitExclude patterns were applied.
func (View) EmitExcludedCount ¶ added in v0.0.2
EmitExcludedCount is the number of corpus documents the emitExclude patterns match — the honesty figure the filtered surfaces report so the artifact says what it dropped. 0 when no patterns were applied.
func (View) EmitExcludedRoots ¶ added in v0.0.2
func (v View) EmitExcludedRoots() []identity.DocumentID
EmitExcludedRoots returns the reachability roots that emitExclude matches, sorted (the RootSet is sorted upstream). Excluding a root is ALLOWED — it simply does not render; reachability is computed over the unfiltered corpus — but the CLI surfaces a notice so it is not silent (ADR 0019). Empty when no patterns were applied, metrics are absent, or the root set is indeterminate.
func (View) RenderedBacklinks ¶ added in v0.0.2
func (v View) RenderedBacklinks(id identity.DocumentID) []identity.DocumentID
RenderedBacklinks is Backlinks with emit-excluded sources dropped: the backlink clauses the consumption surfaces render must not name documents those surfaces refuse to list (ADR 0019). Identical to Backlinks when no patterns were applied. Order-stable: Backlinks is sorted and filtering preserves order.
func (View) RenderedTrails ¶ added in v0.0.2
func (v View) RenderedTrails() []graphmodel.Trail
RenderedTrails is Trails with emit-excluded documents dropped from each trail's reading order (trails exist for onboarding readers, so they are a consumption surface, ADR 0019). A trail whose order becomes empty is dropped. A trail whose Root is excluded is re-rooted at its most important remaining member — highest PageRank, tie-broken by ID — mirroring the domain's root definition. Identical to Trails when no patterns were applied. Deterministic: each order's sequence is preserved, and the list is re-sorted by Root so the upstream sorted-by-Root invariant survives re-rooting.
func (View) TitleOf ¶
func (v View) TitleOf(id identity.DocumentID) string
TitleOf returns the best-effort display title for id (or the id itself).
func (View) WithEmitExclude ¶ added in v0.0.2
WithEmitExclude returns a copy of the View carrying a compiled emitExclude matcher. Patterns use gitignore syntax — the SAME engine and semantics as `.matlatlignore` (go-gitignore), so `.claude/agents/` excludes that subtree at any depth and `!` negation re-includes. An empty pattern list is a no-op (the returned View filters nothing). The matcher is only ever string-matched against in-corpus DocumentIDs — never a filesystem read.
Only the consumption emitters (llmstxt, index, trails) consult the matcher, through EmitExcluded / RenderedBacklinks / RenderedTrails; the diagnostic and machine emitters (terminal/markdown report, graph.json, findings.json, junit.xml, diagrams) ignore it by construction (ADR 0019).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package diagram renders the reference graph as hand-rolled Mermaid and DOT / Graphviz text.
|
Package diagram renders the reference graph as hand-rolled Mermaid and DOT / Graphviz text. |
|
Package graphjson renders graph.json — the PRIMARY machine-/LLM-queryable artifact: a compact, schemaVersion-stamped, fully parseable manifest of the analyzed corpus (nodes, edges, sections, components, HITS, and every gap/ orphan/broken-link signal).
|
Package graphjson renders graph.json — the PRIMARY machine-/LLM-queryable artifact: a compact, schemaVersion-stamped, fully parseable manifest of the analyzed corpus (nodes, edges, sections, components, HITS, and every gap/ orphan/broken-link signal). |
|
Package index renders index.md: a navigable flat index of every document by canonical DocumentID, with a one-line description (front matter → first H1 fallback), category/section, and mod-date.
|
Package index renders index.md: a navigable flat index of every document by canonical DocumentID, with a one-line description (front matter → first H1 fallback), category/section, and mod-date. |
|
Package llmstxt renders the llms.txt family — the LLM-facing navigation and context artifacts:
|
Package llmstxt renders the llms.txt family — the LLM-facing navigation and context artifacts: |
|
Package report renders the human-audience analysis reports: a colorized, TTY-aware terminal summary and a committable GitHub-flavored Markdown report.
|
Package report renders the human-audience analysis reports: a colorized, TTY-aware terminal summary and a committable GitHub-flavored Markdown report. |
|
Package trails renders trails.json — the suggested reading-order artifact (ADR 0016).
|
Package trails renders trails.json — the suggested reading-order artifact (ADR 0016). |