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

extract

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 19 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 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 DetectProjectInWorkspace added in v1.7.1

func DetectProjectInWorkspace(workspaceRoot, dir string) *types.Source

DetectProjectInWorkspace derives a stable repo identity for dir relative to a selected workspace root when a git remote is unavailable.

func DiscoverChildGitRepos added in v1.7.1

func DiscoverChildGitRepos(root string) ([]string, error)

DiscoverChildGitRepos finds nested git repositories below root.

func ExtractAll

func ExtractAll(
	root string,
	files []string,
	_ types.LLMProvider,
	src *types.Source,
	_ ...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 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 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 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 IsGitRepoRoot added in v1.7.1

func IsGitRepoRoot(dir string) bool

IsGitRepoRoot reports whether dir itself is a git repository root.

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.

func SourceDisplayName added in v1.7.1

func SourceDisplayName(src *types.Source) string

func SourceIdentity added in v1.7.1

func SourceIdentity(src *types.Source) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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