Help us shape the future of Go! Take the 2026 Go Developer Survey

extract

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EvidenceTypeOpenAPI = "openapi"
	EvidenceTypeProto   = "proto"
)

Evidence type tags specific to the contract layer.

View Source
const (
	MetaLayer                  = "layer"
	MetaEvidenceType           = "evidence_type"
	MetaEvidenceConfidence     = "evidence_confidence"
	MetaEvidenceSourceArtifact = "evidence_source_artifact"
)

Metadata keys stamped onto extracted nodes and edges so that downstream layers (graph insertion, chunking, retrieval, evidence attribution) have a uniform, layer-aware contract independent of which extractor produced them.

Canonical identity is still assigned by ExtractAll (project prefixing, file node IDs); extractors only produce layer-local metadata here — they must not invent graph-level identity.

View Source
const (
	EvidenceTypeAST        = "ast"
	EvidenceTypeDocLLM     = "doc-llm"
	EvidenceTypePDFLLM     = "pdf-llm"
	EvidenceTypeFilesystem = "filesystem"
	EvidenceTypeProject    = "project"
)

Evidence type tags used when stamping extraction output. These correspond to the Evidence.Type field in pkg/types and let the orchestrator attribute retrieval hits back to the extractor that produced them.

Variables

This section is empty.

Functions

func ChunkText

func ChunkText(text string, maxTokens int) []string

ChunkText splits text into chunks of at most maxTokens (estimated via charsPerToken). Each chunk overlaps with the previous by chunkOverlapRatio of the previous chunk's length to preserve context at boundaries. If the entire text fits within maxTokens, a single-element slice is returned.

func CreateProjectNode

func CreateProjectNode(src *types.Source) types.Node

CreateProjectNode creates the root node for a codebase extraction. All file/function nodes link to this via "belongs_to" edges.

func DetectProject

func DetectProject(dir string) *types.Source

DetectProject extracts project metadata from a directory. Priority:

  1. Git remote URL → extract repo name (e.g., "github.com/Syfra3/vela" → "vela")
  2. Fall back to directory basename

Returns a Source with Type=codebase, Name, Path, and Remote (if git).

func ExtractAll

func ExtractAll(
	root string,
	files []string,
	provider types.LLMProvider,
	src *types.Source,
	maxChunkTokens ...int,
) ([]types.Node, []types.Edge, error)

ExtractAll dispatches each file to the appropriate extractor and returns the merged set of nodes and edges.

src describes which project this extraction belongs to. If nil, DetectProject is called using root. All returned nodes carry src in Node.Source and have their IDs prefixed with "<project>:". A project root node and one file node per extracted file are also created and linked via "contains" edges.

provider may be nil; if so, doc files are skipped. maxChunkTokens controls chunking for local LLMs (0 = default 8000).

func ExtractAncora

func ExtractAncora(
	dbPath string,
	provider types.LLMProvider,
	maxTokens int,
	progress func(done, total int, current string),
) ([]types.Node, []types.Edge, error)

ExtractAncora reads all observations from the ancora SQLite database and returns nodes + edges for the knowledge graph.

Graph structure:

Hierarchy nodes:  Workspace → Visibility → Organization (when present)
Observation nodes: one per observation, linked into the hierarchy
Reference edges:  explicit references stored in observations.references
LLM edges:        semantic relations inferred by the LLM provider (optional)

provider may be nil — in that case only structural edges are produced.

func ExtractContract added in v1.4.0

func ExtractContract(root string, files []string, src *types.Source) ([]types.Node, []types.Edge, error)

ExtractContract parses the supplied set of files, keeping only those recognised as contract artifacts, and returns contract-layer nodes + edges stamped with declared evidence.

src is the repo/workspace context the artifacts were discovered in — the extractor emits a workspace-consumable binding edge (`declared_in`) from each service to the project node so workspace routing can pick up declared services without re-reading the artifact. If src is nil no binding edges are emitted (the contract graph is still produced).

func ExtractDoc

func ExtractDoc(path string, relFile string, provider types.LLMProvider, maxChunkTokens int) ([]types.Node, []types.Edge, error)

ExtractDoc reads a markdown or text file, chunks it if necessary, and sends each chunk to the LLM provider for NER + RE extraction.

func ExtractGoEdges

func ExtractGoEdges(parsed *parsedGoFile, _ []byte, relFile string) []types.Edge

ExtractGoEdges extracts function call edges from a parsed Go AST.

func ExtractGoNodes

func ExtractGoNodes(parsed *parsedGoFile, _ []byte, relFile string) []types.Node

ExtractGoNodes extracts named function declarations, struct type declarations, and interface type declarations from a parsed Go file.

func ExtractPDF

func ExtractPDF(path string, relFile string, provider types.LLMProvider, maxChunkTokens int) ([]types.Node, []types.Edge, error)

ExtractPDF reads a PDF file, converts it to plain text, chunks it, and sends each chunk to the LLM provider for NER + RE extraction.

func ExtractPythonEdges

func ExtractPythonEdges(root *sitter.Node, src []byte, relFile string) []types.Edge

ExtractPythonEdges extracts call edges from Python function bodies.

func ExtractPythonNodes

func ExtractPythonNodes(root *sitter.Node, src []byte, relFile string) []types.Node

ExtractPythonNodes extracts function_definition → function nodes and class_definition → struct nodes from a Python AST.

func ExtractTSEdges

func ExtractTSEdges(root *sitter.Node, src []byte, relFile string) []types.Edge

ExtractTSEdges extracts call edges from TypeScript/JavaScript files.

func ExtractTSNodes

func ExtractTSNodes(root *sitter.Node, src []byte, relFile string) []types.Node

ExtractTSNodes extracts functions, arrow functions, classes and interfaces.

func IsContractFile added in v1.4.0

func IsContractFile(path string) bool

IsContractFile returns true when a path looks like a declared contract artifact supported by this extractor.

func ParseGoFile

func ParseGoFile(path string) (*parsedGoFile, []byte, error)

ParseGoFile parses a .go source file using go/ast (pure Go, no CGO).

func ParsePythonFile

func ParsePythonFile(path string) (*sitter.Node, []byte, error)

ParsePythonFile parses a .py source file and returns the root AST node.

func ParseReferences

func ParseReferences(title, content string) []types.ObsReference

ParseReferences extracts explicit references from observation text. It is intentionally conservative — false positives create noise in the graph.

func ParseTSFile

func ParseTSFile(path string) (*sitter.Node, []byte, error)

ParseTSFile parses a TypeScript or JavaScript file using tree-sitter. Pass the appropriate language based on the file extension.

func PrefixedNodeID

func PrefixedNodeID(project, fileRelPath, symbol string) string

PrefixedNodeID returns a node ID prefixed with the project name. Format: "<project>:<file>:<symbol>" or "<project>:<file>" for file nodes.

func ProjectNodeID

func ProjectNodeID(name string) string

ProjectNodeID returns the canonical node ID for a project root node. Format: "project:<name>"

func RelPath

func RelPath(root, path string) string

RelPath returns path relative to root, or path if it cannot be made relative.

Types

type LLMExtractor

type LLMExtractor struct {
	// contains filtered or unexported fields
}

LLMExtractor uses an LLM to find implicit references in an observation's content that are not captured by the explicit reference parser. It runs as a worker pool consuming from the Patcher's LLM queue.

func NewLLMExtractor

func NewLLMExtractor(cfg *types.LLMConfig, workerCount int, onRefsFound func(int64, []types.ObsReference)) (*LLMExtractor, error)

NewLLMExtractor creates an extractor using the provided LLM client. workerCount controls how many parallel extraction goroutines are run.

func (*LLMExtractor) Start

func (e *LLMExtractor) Start(ctx context.Context, queue <-chan types.ObservationNode)

Start launches worker goroutines that consume from queue. It returns when ctx is cancelled or queue is closed.

Jump to

Keyboard shortcuts

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