Documentation
¶
Overview ¶
Package render contains graph presentation helpers: ASCII tree, DOT, and Mermaid formatters. These were moved out of the public magus package so the public surface stays free of formatting details.
Index ¶
- func EncodeFragmentRaw(raw []byte) (string, error)
- func ExplainText(out types.KnowledgeExplainOutput) string
- func FormatDuration(d time.Duration) string
- func MissText(query string, ans types.KnowledgeAnswer) string
- func PathText(out types.KnowledgePathOutput) string
- func WriteGraphDOT(w io.Writer, out types.GraphOutput) error
- func WriteGraphMermaid(w io.Writer, out types.GraphOutput) error
- func WriteKnowledgeDOT(w io.Writer, out types.KnowledgeGraphOutput) error
- func WriteKnowledgeGraphML(w io.Writer, out types.KnowledgeGraphOutput) error
- func WriteKnowledgeMermaid(w io.Writer, out types.KnowledgeGraphOutput) error
- func WriteTargetGraphDOT(w io.Writer, out types.TargetGraphOutput) error
- func WriteTargetGraphMarkdown(w io.Writer, out types.TargetGraphOutput, routing *types.KnowledgeRouting, ...) error
- func WriteTargetGraphMermaid(w io.Writer, out types.TargetGraphOutput) error
- func WriteTree(w io.Writer, g *types.Graph, opts ...RenderOption) error
- type RenderOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeFragmentRaw ¶ added in v0.2.0
EncodeFragmentRaw gzip-compresses (BestCompression) raw and returns a base64url-encoded string (no padding) suitable for use as a #data= URL fragment. The browser reverses it with DecompressionStream('gzip'). gzip header fields are left at their zero values to guarantee byte-stable output across calls. Callers marshal their payload to JSON first; this is the canonical encoder shared by the render package and cmd/magus (graph open --targets and the knowledge-graph #data= path), both of which feed the same browser decode contract, so byte-for-byte wire-format parity is required.
func ExplainText ¶ added in v0.2.0
func ExplainText(out types.KnowledgeExplainOutput) string
ExplainText renders one node's context card: its identity and attrs, then its relationships grouped by natural-language verb, each group listing the full IDs.
func FormatDuration ¶
FormatDuration formats a duration as a human-readable string.
func MissText ¶ added in v0.4.0
func MissText(query string, ans types.KnowledgeAnswer) string
MissText renders explain's miss for an unknown verdict: what magus could not see, and the command that would let it. It exists so an agent reading a text-channel tool gets the same coverage statement a JSON consumer gets from the answer field, rather than an error string it would have to pattern-match.
Unknown only. An absent verdict is a fact explain reports as an error, so rendering one here would print "verdict: absent, not absent".
func PathText ¶ added in v0.2.0
func PathText(out types.KnowledgePathOutput) string
PathText renders a shortest path as the chain of natural-language steps from the source to the target, one labeled step per hop (direction folded into the verb).
func WriteGraphDOT ¶
func WriteGraphDOT(w io.Writer, out types.GraphOutput) error
WriteGraphDOT emits a deterministic Graphviz DOT digraph to w (rankdir=LR, paths quoted).
func WriteGraphMermaid ¶
func WriteGraphMermaid(w io.Writer, out types.GraphOutput) error
WriteGraphMermaid emits a Mermaid flowchart with spell subgraphs, BR/duration labels, cross-spell edge labels, exclusive hexagons, and click-to-dir handlers.
func WriteKnowledgeDOT ¶ added in v0.2.0
func WriteKnowledgeDOT(w io.Writer, out types.KnowledgeGraphOutput) error
WriteKnowledgeDOT emits a knowledge-graph export as a Graphviz DOT digraph. Node identity is the raw node ID; the format is structural (edges only), so relations and Attrs are dropped - GraphML carries the full detail. Meant for a selected neighborhood, not the whole graph (an unfiltered dump is unreadable).
func WriteKnowledgeGraphML ¶ added in v0.2.0
func WriteKnowledgeGraphML(w io.Writer, out types.KnowledgeGraphOutput) error
WriteKnowledgeGraphML emits the merged knowledge graph as GraphML, the XML graph format external viewers (Gephi, yEd) open directly - the second export format next to node-link JSON. Every node/edge field becomes a declared <key>; kind-specific node Attrs are declared as attr_<name> keys collected across the whole graph, so the schema is self-describing. Output is deterministic: nodes/edges are written in input order (the export is already sorted) and attr keys are sorted.
func WriteKnowledgeMermaid ¶ added in v0.2.0
func WriteKnowledgeMermaid(w io.Writer, out types.KnowledgeGraphOutput) error
WriteKnowledgeMermaid emits a knowledge-graph export as a Mermaid flowchart: nodes colored by kind, edges labeled with their relation. Meant for a selected neighborhood - Mermaid chokes on thousands of nodes, so the CLI gates it behind --select.
func WriteTargetGraphDOT ¶
func WriteTargetGraphDOT(w io.Writer, out types.TargetGraphOutput) error
WriteTargetGraphDOT emits the target graph as Graphviz DOT, nodes qualified by project path so cross-project name clashes stay distinct.
func WriteTargetGraphMarkdown ¶
func WriteTargetGraphMarkdown(w io.Writer, out types.TargetGraphOutput, routing *types.KnowledgeRouting, explorerURL string, defaultCharms []string) error
WriteTargetGraphMarkdown renders a workspace's MAGUS.md: a routing index, not a catalog. It leads with the knowledge-graph "query first" section, then lists every project's targets with a one-line summary each, and points the reader at the two commands that expand any entry - `magus describe target <name>` for a target's fully-evaluated dispatch plan, `magus describe mcp-tools` for the agent tool list. The per-target dispatch plan and the Mermaid graphs deliberately do not live here: their bulk made the file useless as in-context routing, and both are one command (or the Graph Explorer link) away. It is engine- and repo-agnostic - `magus describe graph -o markdown` produces it for any magus workspace, which is how a project's MAGUS.md is generated and drift-checked. Output is deterministic (no timestamps) so it can back a drift gate.
func WriteTargetGraphMermaid ¶
func WriteTargetGraphMermaid(w io.Writer, out types.TargetGraphOutput) error
WriteTargetGraphMermaid emits a target dependency graph as a Mermaid flowchart. It is the one Mermaid emitter for the target graph: `magus describe graph -o mermaid` routes through it. See targetGraphIR for the stage-boxing and role-styling rules.
Types ¶
type RenderOption ¶
type RenderOption func(*renderConfig)
RenderOption configures a WriteTree call.
func WithDirection ¶
func WithDirection(d types.Direction) RenderOption
WithDirection sets the traversal direction (Downstream or Upstream).
func WithMaxDepth ¶
func WithMaxDepth(depth int) RenderOption
WithMaxDepth caps the depth of the rendered tree. 0 means unlimited.
func WithRoots ¶
func WithRoots(paths ...string) RenderOption
WithRoots restricts the tree to subtrees rooted at the named projects.
func WithSpell ¶
func WithSpell(name string) RenderOption
WithSpell filters the tree to projects of the given spell name ("go", "rust", "typescript"). Projects of other spells are skipped from display, and their subtrees are not traversed.