l7report

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package l7report narrates layout7's decision trace (docs/dev/layout-gen/layout-debug.md): the engine emits structured TraceEvents through its one seam (layout7.Trace); this package collects them and renders the human-readable views — Text for the terminal (`layout-debug --why`) and Explain for the narrated pipeline-ordered report (`layout-explain`). The engine itself contains no narration.

Index

Constants

View Source
const RecordingVersion = 1

RecordingVersion is bumped whenever the event vocabulary or graph shape changes in a way that would make an older recording narrate wrong. The version guards against narrating a stale recording with newer templates.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExplainOpts

type ExplainOpts struct {
	Heading    string // section heading (the source doc's heading)
	SourceRef  string // "file.md:123" or "" — the reference line
	Ipmt       string // the original ipmt, embedded as a fenced block
	SVGRelPath string // relative link to a rendered companion, "" = none
	Candidates bool   // include the per-candidate route story in a <details>
	Verbose    bool   // append the full raw trace in a <details>
	Color      bool   // wrap node names / kinds / arrows in as-token markers

	// PrinciplesHref / DebugDocHref are the CLICKABLE urls for the two
	// linked docs, relative to where the report is written (compute with
	// pkg/markdown.RelPath). Empty falls back to the repo-relative display
	// path, which only resolves from the repo root.
	PrinciplesHref string
	DebugDocHref   string
}

ExplainOpts configure one narrated report.

type Recording

type Recording struct {
	Version int                  `json:"version"`
	Source  Source               `json:"source,omitempty"`
	Events  []layout7.TraceEvent `json:"events"`
	Graph   *layout.Graph        `json:"graph"`
}

Recording is a captured run: the decision trace plus the resulting graph. Deterministic (no timestamps) — event kinds and payload keys ARE the grep/diff contract, so two recordings diff clean and a recording diff doubles as a behaviour diff between engine versions.

func NewRecording

func NewRecording(r *Report, src Source) *Recording

NewRecording snapshots a report for serialization.

func (*Recording) JSON

func (rec *Recording) JSON() ([]byte, error)

JSON marshals the recording deterministically (indented; json.Marshal sorts map keys, so payloads are stable line-for-line).

type Report

type Report struct {
	Events []layout7.TraceEvent
	Graph  *layout.Graph
}

Report is a collected trace plus the generated graph.

func DecodeRecording

func DecodeRecording(data []byte) (*Report, error)

DecodeRecording parses a .debug.json back into a Report. Event payloads round-trip through JSON as map[string]any with []interface{} slices; normalizeDecoded restores the []string / [][]string shapes the renderers type-assert on. A version mismatch is a hard error — narrating a stale recording with the current templates is worse than refusing.

func Run

func Run(doc *model.IpmGraph) (*Report, error)

Run generates the layout with tracing and returns the report.

func (*Report) Emit

func (r *Report) Emit(e layout7.TraceEvent)

Emit implements layout7.Trace.

func (*Report) Explain

func (r *Report) Explain(o ExplainOpts) string

Explain renders the full narrated report for one graph.

func (*Report) Text

func (r *Report) Text(opts TextOpts) string

Text renders the decisions the way `layout-gen --why` prints them.

type Source

type Source struct {
	File string `json:"file,omitempty"`
	Line int    `json:"line,omitempty"`
}

Source locates the block a recording was made from.

type TextOpts

type TextOpts struct {
	Sel        []string
	Candidates bool // include the per-candidate route story
	Verbose    bool // append the FULL raw trace (every event, one line each)
}

TextOpts filter the terminal view. Sel limits every section to events mentioning the named nodes (context budget: a 20-line filtered answer beats a 2000-line dump — docs/dev/layout-gen/layout-debug.md, output contract).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL