generate

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package generate builds a seed Contexo knowledge base from a codebase by running the external Graphify CLI, parsing its graph.json, and mapping the code graph into migrate Candidates the agent then distills into pages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCandidates

func BuildCandidates(g *Graph, projectRoot, graphifyOutDir, cacheDir string, caps Caps) ([]migrate.Candidate, error)

BuildCandidates maps a parsed graph into migrate Candidates, materializing a markdown slice file per community/god-node under <cacheDir>/slices/. Order: overview, then communities (largest first), then god nodes. If g is nil it degrades to just the GRAPH_REPORT.md overview candidate.

func CacheDir

func CacheDir(contexoDir string) string

CacheDir is where generate keeps Graphify artifacts + slices (a dot-dir, so migrate's Store.Walk exclusion keeps it out of pushes).

func DefaultRunner

func DefaultRunner(projectRoot, cacheDir, backend string) (string, error)

DefaultRunner shells out to the user-installed `graphify` CLI (keyless code extraction), then relocates <projectRoot>/graphify-out into the cache so the repo root is left clean.

func Discover

func Discover(projectRoot, contexoDir, backend string, runner Runner) ([]migrate.Candidate, string, error)

Discover runs Graphify (via runner) and maps its output into candidates. A missing/unparseable graph.json degrades to the report-only candidate.

func GraphifyInstalled

func GraphifyInstalled() bool

GraphifyInstalled reports whether the `graphify` CLI is on PATH.

func InstallGraphify

func InstallGraphify() (method string, err error)

InstallGraphify installs the `graphifyy` package with the first available installer (uv → pipx → pip → …) and returns which one it used. The package name is fixed and passed as an arg slice (no shell, no injection). It returns an error listing the manual commands when no installer is on PATH.

Types

type Caps

type Caps struct{ Communities, GodNodes int }

Caps bound how many communities / god nodes become candidates, so a large codebase doesn't explode into hundreds of pages.

func DefaultCaps

func DefaultCaps() Caps

type Graph

type Graph struct {
	Nodes []Node `json:"nodes"`
	Links []Link `json:"links"`
}

Graph is Graphify's networkx node-link output (only the parts we use).

func ParseGraph

func ParseGraph(data []byte) (*Graph, error)

ParseGraph decodes a graph.json. Errors on malformed JSON or an empty node set (callers degrade to the report-only path on error).

func (*Graph) Communities

func (g *Graph) Communities() map[int][]Node

Communities groups nodes by their community id.

func (*Graph) GodNodes

func (g *Graph) GodNodes(topM int) []Node

GodNodes returns the topM most-connected SYMBOL nodes (files excluded), by degree descending, id ascending as a deterministic tiebreak.

func (*Graph) NeighborsOf

func (g *Graph) NeighborsOf(id string) []Link

NeighborsOf returns every link touching id (as source or target).

type Link struct {
	Source     string  `json:"source"`
	Target     string  `json:"target"`
	Relation   string  `json:"relation"`
	Confidence string  `json:"confidence"`
	SourceFile string  `json:"source_file"`
	SourceLoc  string  `json:"source_location"`
	Weight     float64 `json:"weight"`
}

Link is one graph.json edge.

type Node

type Node struct {
	ID            string `json:"id"`
	Label         string `json:"label"`
	Community     int    `json:"community"`
	CommunityName string `json:"community_name"`
	SourceFile    string `json:"source_file"`
	SourceLoc     string `json:"source_location"`
	FileType      string `json:"file_type"`
	NormLabel     string `json:"norm_label"`
}

Node is one graph.json node (a file or a code symbol).

type Runner

type Runner func(projectRoot, cacheDir, backend string) (graphifyOutDir string, err error)

Runner runs Graphify for projectRoot and returns the directory containing the produced graph.json / GRAPH_REPORT.md. Seam for testing.

Jump to

Keyboard shortcuts

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