export

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package export writes a code graph out in interchange formats.

Why this package exists

The web explorer's /api/graph payload is view-shaped: it carries the LOD level, budgets and cluster assignments a drawing needs. That is the right shape for a viewer and the wrong shape for anything else. A reader who wants the graph in Gephi, in Graphviz, in a notebook or in a diff wants the graph, not a rendering of it.

The one rule every exporter here obeys

Direction is read from Edge.From and Edge.To, never from the order two node keys happen to appear in. Writing a canonicalised pair into a directional format silently reverses every relationship whose source sorts after its target, and nothing downstream can detect it. Confidence is likewise carried into every format that can hold it, and an exporter that cannot hold it declares itself Lossy rather than dropping it quietly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildASCIITree

func BuildASCIITree(paths []string) string

BuildASCIITree constructs an ASCII file hierarchy from a sorted list of relative paths.

Types

type Exporter

type Exporter interface {
	// Format is the name this exporter is registered under.
	Format() Format
	// Lossy reports what this format cannot represent, or "" when it is
	// faithful. Callers surface it so a reader is never surprised by an export
	// that quietly dropped half the model.
	Lossy() string
	// Write encodes g into w.
	Write(ctx context.Context, w io.Writer, g metrics.Graph) error
	// Counts reports how many nodes and edges the artifact Write produces
	// will actually contain, which is not always what g holds.
	//
	// It exists because a caller reporting "wrote N nodes" had nothing to go
	// on but g.Order(), and for an edge-list format that number is a claim
	// about the graph contradicting the same command's own lossy note about
	// the file. A format that carries everything answers with g's own totals;
	// one that cannot says what it can. Keeping the answer beside the encoder
	// is what stops the two from drifting apart.
	Counts(g metrics.Graph) (nodes, edges int)
}

Exporter writes a graph in one format.

The interface is deliberately three methods: an exporter that needs more than this is doing something other than encoding.

func ForFormat

func ForFormat(f Format) (Exporter, error)

ForFormat resolves a format name to its exporter.

type Format

type Format string

Format names one output encoding.

const (
	FormatDOT     Format = "dot"
	FormatGraphML Format = "graphml"
	FormatJSON    Format = "json"
	FormatCSV     Format = "csv"
	FormatSVG     Format = "svg"
)

func Formats

func Formats() []Format

Formats lists every supported format, ascending.

type JSONEdge

type JSONEdge struct {
	Source     string `json:"source"`
	Target     string `json:"target"`
	Kind       string `json:"kind"`
	Confidence string `json:"confidence"`
	Weight     int    `json:"weight"`
}

JSONEdge is one directed edge on the wire.

Weight rides alongside Kind and Confidence for the same reason it rides in DOT and GraphML: a user exporting the same graph three ways should not get three different fidelities, and JSON has no competing semantic (the way DOT's `weight` attribute doubles as a layout hint) that would make carrying it a tradeoff instead of a straight win.

type JSONGraph

type JSONGraph struct {
	Directed bool       `json:"directed"`
	Nodes    []JSONNode `json:"nodes"`
	Edges    []JSONEdge `json:"edges"`
}

JSONGraph is the node-link document.

Directed is stated rather than implied. A consumer that has to guess will guess wrong on exactly the graphs where it matters.

type JSONNode

type JSONNode struct {
	ID   string `json:"id"`
	Kind string `json:"kind"`
}

JSONNode is one node on the wire.

type LayoutOptions

type LayoutOptions struct {
	Width      int
	Height     int
	Iterations int
	// Seed pins the initial placement. Without it the same graph draws
	// differently on every export and two pictures cannot be compared.
	Seed int64
}

LayoutOptions controls the seeded force-directed layout.

func DefaultLayoutOptions

func DefaultLayoutOptions() LayoutOptions

DefaultLayoutOptions returns a seeded layout sized for a page.

type PackFormat

type PackFormat string
const (
	PackFormatXML      PackFormat = "xml"
	PackFormatMarkdown PackFormat = "markdown"
	PackFormatJSON     PackFormat = "json"
)

type PackOptions

type PackOptions struct {
	Format       PackFormat
	IncludeTree  bool
	MaxFileBytes int64
	PathPrefix   string
	Redact       bool
}

type PackResult

type PackResult struct {
	Content         string `json:"content,omitempty"`
	FileCount       int    `json:"file_count"`
	TotalBytes      int64  `json:"total_bytes"`
	EstimatedTokens int    `json:"estimated_tokens"`
	Tree            string `json:"tree,omitempty"`
	RedactedCount   int    `json:"redacted_count"`
}

func GeneratePack

func GeneratePack(ctx context.Context, reg *regpkg.Registry, runID int64, opts PackOptions) (*PackResult, error)

GeneratePack bundles codebase files into an AI-ready XML, Markdown, or JSON prompt pack.

func StreamPack

func StreamPack(ctx context.Context, reg *regpkg.Registry, runID int64, opts PackOptions, w io.Writer) (*PackResult, error)

StreamPack bundles codebase files and writes the output directly to w, avoiding buffering the entire codebase representation in heap memory.

Jump to

Keyboard shortcuts

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