nodes

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package nodes provides concrete DAG node implementations for Trace pipelines.

Overview

This package contains production-ready nodes that wrap the core Trace packages (ast, graph, cache, lint, lsp, patterns, impact, safety). Each node implements the dag.Node interface and can be composed into execution pipelines.

Node Categories

Foundation Nodes (sequential):

  • ParseFilesNode: Wraps ast.ParserRegistry to parse source files
  • LoadCacheNode: Wraps cache.GraphCache to load/build cached graphs
  • BuildGraphNode: Wraps graph.Builder to construct code graphs

Verification Nodes (parallel):

  • LSPSpawnNode: Spawns language servers via lsp.Manager
  • LSPTypeCheckNode: Performs type checking via lsp.Operations
  • LintAnalyzeNode: Runs linters via lint.LintRunner
  • LintCheckNode: Validates lint results against policies
  • PatternScanNode: Detects design patterns via patterns.PatternDetector

Analysis Nodes:

  • BlastRadiusNode: Analyzes change impact via impact.ChangeImpactAnalyzer
  • SafetyScanNode: Performs security scanning via safety interfaces

Control Flow Nodes:

  • GateNode: Conditional execution based on previous outputs
  • TDGNode: Wraps Test-Driven Generation as a sub-DAG

Usage Example

// Create foundation nodes
parseNode := nodes.NewParseFilesNode(registry)
cacheNode := nodes.NewLoadCacheNode(graphCache)
graphNode := nodes.NewBuildGraphNode(builder)

// Create verification nodes (these run in parallel)
lspNode := nodes.NewLSPSpawnNode(lspManager)
lintNode := nodes.NewLintAnalyzeNode(lintRunner)
patternNode := nodes.NewPatternScanNode(detector)

// Build pipeline
pipeline, err := dag.NewBuilder("code-analysis").
    AddNode(parseNode).
    AddNode(cacheNode).
    AddNode(graphNode).
    AddNode(lspNode).
    AddNode(lintNode).
    AddNode(patternNode).
    Build()

Thread Safety

All nodes are safe for concurrent use. Multiple DAG executions can share the same node instances. Each Execute() call receives independent input and produces independent output.

Error Handling

Nodes follow Trace error handling conventions:

  • Return wrapped errors with context (never panic)
  • Partial results may be returned alongside errors
  • Context cancellation is always respected

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingInput is returned when a required input is not provided.
	ErrMissingInput = errors.New("missing required input")

	// ErrInvalidInputType is returned when input has wrong type.
	ErrInvalidInputType = errors.New("invalid input type")

	// ErrNoFilesToProcess is returned when no files match the criteria.
	ErrNoFilesToProcess = errors.New("no files to process")

	// ErrParserNotFound is returned when no parser exists for a file type.
	ErrParserNotFound = errors.New("parser not found for file type")

	// ErrBuildFailed is returned when graph building fails.
	ErrBuildFailed = errors.New("graph build failed")

	// ErrLSPUnavailable is returned when LSP server cannot be spawned.
	ErrLSPUnavailable = errors.New("LSP server unavailable")

	// ErrLintFailed is returned when linting fails.
	ErrLintFailed = errors.New("lint failed")

	// ErrGateBlocked is returned when a gate condition blocks execution.
	ErrGateBlocked = errors.New("gate condition not met")

	// ErrNilDependency is returned when a required dependency is nil.
	ErrNilDependency = errors.New("required dependency is nil")

	// ErrGraphNotFrozen is returned when a graph operation requires frozen graph.
	ErrGraphNotFrozen = errors.New("graph must be frozen")

	// ErrCacheNotReady is returned when cache is not initialized.
	ErrCacheNotReady = errors.New("cache not ready")
)

Sentinel errors for node operations.

Functions

This section is empty.

Types

type BlastRadiusNode

type BlastRadiusNode struct {
	dag.BaseNode
}

BlastRadiusNode analyzes the impact of changing a symbol.

Description:

Uses the impact.ChangeImpactAnalyzer to determine what would be
affected if a symbol is changed. Includes callers, test coverage,
side effects, and risk assessment.

Inputs (from map[string]any):

"graph" (*graph.Graph): The code graph. Required.
"index" (*index.SymbolIndex): Symbol index for lookups. Required.
"target_id" (string): Symbol ID to analyze. Required.
"proposed_change" (string): New signature for breaking change analysis. Optional.

Outputs:

*BlastRadiusOutput containing:
  - Impact: The change impact analysis result
  - RiskLevel: Overall risk level
  - Duration: Analysis time

Thread Safety:

Safe for concurrent use.

func NewBlastRadiusNode

func NewBlastRadiusNode(deps []string) *BlastRadiusNode

NewBlastRadiusNode creates a new blast radius node.

Inputs:

deps - Names of nodes this node depends on.

Outputs:

*BlastRadiusNode - The configured node.

func (*BlastRadiusNode) Execute

func (n *BlastRadiusNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute analyzes the blast radius of changing a symbol.

Description:

Creates a ChangeImpactAnalyzer and runs full impact analysis.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "graph", "index", "target_id", and optionally "proposed_change".

Outputs:

*BlastRadiusOutput - The analysis result.
error - Non-nil if required inputs are missing or analysis fails.

Thread Safety:

Safe for concurrent use.

type BlastRadiusOutput

type BlastRadiusOutput struct {
	// Impact contains the full change impact analysis.
	Impact *impact.ChangeImpact

	// RiskLevel is the overall risk level (low, medium, high, critical).
	RiskLevel string

	// RiskScore is the numeric risk score (0.0 - 1.0).
	RiskScore float64

	// DirectCallers is the count of direct callers.
	DirectCallers int

	// TotalImpact is the total number of affected symbols.
	TotalImpact int

	// Duration is the analysis time.
	Duration time.Duration
}

BlastRadiusOutput contains the result of blast radius analysis.

type BuildGraphNode

type BuildGraphNode struct {
	dag.BaseNode
	// contains filtered or unexported fields
}

BuildGraphNode builds a code graph from parsed AST results.

Description:

Takes parsed AST results and constructs a code graph with nodes
for symbols and edges for relationships (calls, imports, etc.).

Inputs (from map[string]any):

"parse_results" ([]*ast.ParseResult): Results from PARSE_FILES node. Required.
"project_root" (string): Absolute path to project root. Required.

Outputs:

*BuildGraphOutput containing:
  - Graph: The constructed code graph (frozen)
  - BuildResult: Detailed build statistics and errors
  - Duration: Build time

Thread Safety:

Safe for concurrent use.

func NewBuildGraphNode

func NewBuildGraphNode(builder *graph.Builder, deps []string) *BuildGraphNode

NewBuildGraphNode creates a new build graph node.

Inputs:

builder - The graph builder to use. Must not be nil.
deps - Names of nodes this node depends on.

Outputs:

*BuildGraphNode - The configured node.

func (*BuildGraphNode) Execute

func (n *BuildGraphNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute builds the code graph from parse results.

Description:

Uses the graph.Builder to construct a code graph from the provided
AST parse results. The resulting graph is frozen and ready for queries.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "parse_results" and "project_root".

Outputs:

*BuildGraphOutput - The build result.
error - Non-nil if building fails completely.

Thread Safety:

Safe for concurrent use.

type BuildGraphOutput

type BuildGraphOutput struct {
	// Graph is the constructed code graph.
	Graph *graph.Graph

	// BuildResult contains detailed build statistics.
	BuildResult *graph.BuildResult

	// Duration is the build time.
	Duration time.Duration
}

BuildGraphOutput contains the result of building a code graph.

type GateCondition

type GateCondition func(ctx context.Context, inputs map[string]any) (bool, string)

GateCondition defines a function that checks whether the gate should pass.

func AllPassedCondition

func AllPassedCondition(nodeNames ...string) GateCondition

AllPassedCondition creates a condition that checks multiple node outputs.

func LintPassedCondition

func LintPassedCondition() GateCondition

LintPassedCondition creates a condition that checks lint results.

func RiskLevelCondition

func RiskLevelCondition(maxLevel string) GateCondition

RiskLevelCondition creates a condition that checks blast radius risk level.

func SafetyPassedCondition

func SafetyPassedCondition() GateCondition

SafetyPassedCondition creates a condition that checks security scan results.

type GateNode

type GateNode struct {
	dag.BaseNode
	// contains filtered or unexported fields
}

GateNode provides conditional execution control.

Description:

Evaluates a condition and either passes through or blocks execution.
Use this to implement quality gates, feature flags, or conditional
pipeline branches.

Inputs (from map[string]any):

Depends on the configured condition function.

Outputs:

*GateOutput containing:
  - Passed: Whether the gate condition was met
  - Reason: Explanation of why the gate passed or failed
  - Duration: Check time

Thread Safety:

Safe for concurrent use.

func NewGateNode

func NewGateNode(name string, condition GateCondition, deps []string) *GateNode

NewGateNode creates a new gate node with a condition.

Inputs:

name - Unique name for this gate.
condition - Function that evaluates the gate condition.
deps - Names of nodes this node depends on.

Outputs:

*GateNode - The configured node.

func (*GateNode) Execute

func (n *GateNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute evaluates the gate condition.

Description:

Runs the configured condition function. If blockOnFail is true and
the condition returns false, returns ErrGateBlocked.

Inputs:

ctx - Context for cancellation.
inputs - Inputs passed to the condition function.

Outputs:

*GateOutput - The gate result.
error - ErrGateBlocked if condition fails and blockOnFail is true.

Thread Safety:

Safe for concurrent use.

func (*GateNode) WithBlockOnFail

func (n *GateNode) WithBlockOnFail(block bool) *GateNode

WithBlockOnFail configures whether to return an error when gate fails.

func (*GateNode) WithPassThrough

func (n *GateNode) WithPassThrough(pass bool) *GateNode

WithPassThrough configures whether to pass inputs through on success.

type GateOutput

type GateOutput struct {
	// Passed indicates whether the gate condition was met.
	Passed bool

	// Reason explains why the gate passed or failed.
	Reason string

	// PassedInputs contains inputs passed through (if passThrough is enabled).
	PassedInputs map[string]any

	// Duration is the check time.
	Duration time.Duration
}

GateOutput contains the result of gate evaluation.

type LSPSpawnError

type LSPSpawnError struct {
	Language string
	Error    string
}

LSPSpawnError represents a language server spawn failure.

type LSPSpawnNode

type LSPSpawnNode struct {
	dag.BaseNode
	// contains filtered or unexported fields
}

LSPSpawnNode spawns language servers for the requested languages.

Description:

Uses the LSP Manager to spawn language servers for the specified
languages. Servers are spawned on-demand and cached for reuse.

Inputs (from map[string]any):

"languages" ([]string): Languages to spawn servers for. Required.
    E.g., ["go", "python", "typescript"]

Outputs:

*LSPSpawnOutput containing:
  - Spawned: Languages with successfully spawned servers
  - Failed: Languages that failed to spawn
  - Manager: The LSP manager for downstream use
  - Duration: Spawn time

Thread Safety:

Safe for concurrent use.

func NewLSPSpawnNode

func NewLSPSpawnNode(manager *lsp.Manager, deps []string) *LSPSpawnNode

NewLSPSpawnNode creates a new LSP spawn node.

Inputs:

manager - The LSP manager to use. Must not be nil.
deps - Names of nodes this node depends on.

Outputs:

*LSPSpawnNode - The configured node.

func (*LSPSpawnNode) Execute

func (n *LSPSpawnNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute spawns the requested language servers.

Description:

Spawns language servers for each requested language. Failures for
individual languages are reported but don't fail the entire operation.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "languages".

Outputs:

*LSPSpawnOutput - The spawn result.
error - Non-nil only if manager is nil.

Thread Safety:

Safe for concurrent use.

func (*LSPSpawnNode) OnResume

func (n *LSPSpawnNode) OnResume(ctx context.Context, output any) error

OnResume restores LSP servers after checkpoint load.

Description:

Called when resuming from a checkpoint where LSP_SPAWN was marked complete.
Checks if the LSP servers from the checkpoint are still alive, and respawns
them if necessary. This prevents the "zombie checkpoint" problem where
downstream nodes (TYPE_CHECK) try to use dead LSP processes.

The Problem This Solves:

  1. Agent runs LSP_SPAWN, servers start
  2. DAG saves checkpoint - LSP_SPAWN = Complete
  3. System crashes
  4. System loads checkpoint
  5. Without OnResume: TYPE_CHECK calls dead LSP → PANIC
  6. With OnResume: LSP servers are respawned → TYPE_CHECK works

Inputs:

ctx - Context for cancellation.
output - The node's output (*LSPSpawnOutput) from the checkpoint.

Outputs:

error - Non-nil if respawn fails. Causes node to be re-executed.

Thread Safety:

Safe for concurrent use via LSP Manager's internal locking.

type LSPSpawnOutput

type LSPSpawnOutput struct {
	// Spawned contains languages with active servers.
	Spawned []string

	// Failed contains languages that failed to spawn.
	Failed []LSPSpawnError

	// Manager is the LSP manager for downstream use.
	Manager *lsp.Manager

	// Operations is the LSP operations wrapper.
	Operations *lsp.Operations

	// Duration is the spawn time.
	Duration time.Duration
}

LSPSpawnOutput contains the result of spawning LSP servers.

type LSPTypeCheckNode

type LSPTypeCheckNode struct {
	dag.BaseNode
}

LSPTypeCheckNode performs type checking using LSP hover.

Description:

Uses the LSP hover operation to retrieve type information for
specified symbols. This provides accurate type resolution across
the project.

Inputs (from map[string]any):

"operations" (*lsp.Operations): LSP operations from LSP_SPAWN. Required.
"symbols" ([]SymbolLocation): Symbols to type check. Required.

Outputs:

*LSPTypeCheckOutput containing:
  - Results: Type information for each symbol
  - Errors: Symbols that failed type checking
  - Duration: Check time

Thread Safety:

Safe for concurrent use.

func NewLSPTypeCheckNode

func NewLSPTypeCheckNode(deps []string) *LSPTypeCheckNode

NewLSPTypeCheckNode creates a new LSP type check node.

Inputs:

deps - Names of nodes this node depends on.

Outputs:

*LSPTypeCheckNode - The configured node.

func (*LSPTypeCheckNode) Execute

func (n *LSPTypeCheckNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute performs type checking on the specified symbols.

Description:

Uses LSP hover to retrieve type information for each symbol.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "operations" and "symbols".

Outputs:

*LSPTypeCheckOutput - The type check result.
error - Non-nil if operations is nil.

Thread Safety:

Safe for concurrent use.

type LSPTypeCheckOutput

type LSPTypeCheckOutput struct {
	// Results contains type information for checked symbols.
	Results []TypeCheckResult

	// Errors contains symbols that failed type checking.
	Errors []TypeCheckError

	// Duration is the check time.
	Duration time.Duration
}

LSPTypeCheckOutput contains the result of type checking.

type LintAnalyzeNode

type LintAnalyzeNode struct {
	dag.BaseNode
	// contains filtered or unexported fields
}

LintAnalyzeNode runs linters on source files.

Description:

Uses the lint.LintRunner to analyze source files for code quality
issues. Supports multiple languages and runs linting in parallel.

Inputs (from map[string]any):

"files" ([]string): File paths to lint. Required.
"project_root" (string): Project root for relative paths. Optional.

Outputs:

*LintAnalyzeOutput containing:
  - Results: Lint results for each file
  - TotalErrors: Count of errors across all files
  - TotalWarnings: Count of warnings across all files
  - Duration: Lint time

Thread Safety:

Safe for concurrent use.

func NewLintAnalyzeNode

func NewLintAnalyzeNode(runner *lint.LintRunner, deps []string) *LintAnalyzeNode

NewLintAnalyzeNode creates a new lint analyze node.

Inputs:

runner - The lint runner to use. Must not be nil.
deps - Names of nodes this node depends on.

Outputs:

*LintAnalyzeNode - The configured node.

func (*LintAnalyzeNode) Execute

func (n *LintAnalyzeNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute runs linting on the specified files.

Description:

Lints each file using the appropriate linter based on file extension.
Files with unsupported extensions are skipped.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "files" and optionally "project_root".

Outputs:

*LintAnalyzeOutput - The lint results.
error - Non-nil if runner is nil.

Thread Safety:

Safe for concurrent use.

type LintAnalyzeOutput

type LintAnalyzeOutput struct {
	// Results contains lint results for each file.
	Results []*lint.LintResult

	// TotalErrors is the count of errors across all files.
	TotalErrors int

	// TotalWarnings is the count of warnings across all files.
	TotalWarnings int

	// FilesLinted is the number of files that were linted.
	FilesLinted int

	// FilesSkipped is the number of files skipped (unsupported language).
	FilesSkipped int

	// Duration is the lint time.
	Duration time.Duration
}

LintAnalyzeOutput contains the result of linting files.

type LintCheckNode

type LintCheckNode struct {
	dag.BaseNode
	// contains filtered or unexported fields
}

LintCheckNode validates lint results against policies.

Description:

Checks lint results from LINT_ANALYZE against configured policies.
Can be used as a quality gate to block pipelines with too many issues.

Inputs (from map[string]any):

"lint_results" (*LintAnalyzeOutput): Results from LINT_ANALYZE. Required.
"max_errors" (int): Maximum allowed errors. Optional, default 0.
"max_warnings" (int): Maximum allowed warnings. Optional, default -1 (unlimited).

Outputs:

*LintCheckOutput containing:
  - Passed: Whether the check passed
  - ErrorCount: Number of errors found
  - WarningCount: Number of warnings found
  - Violations: Details of policy violations

Thread Safety:

Safe for concurrent use.

func NewLintCheckNode

func NewLintCheckNode(maxErrors, maxWarnings int, deps []string) *LintCheckNode

NewLintCheckNode creates a new lint check node.

Inputs:

maxErrors - Maximum allowed errors (0 = none allowed).
maxWarnings - Maximum allowed warnings (-1 = unlimited).
deps - Names of nodes this node depends on.

Outputs:

*LintCheckNode - The configured node.

func (*LintCheckNode) Execute

func (n *LintCheckNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute checks lint results against policies.

Description:

Compares lint results against configured thresholds. Fails if
error or warning counts exceed the maximum allowed.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "lint_results".

Outputs:

*LintCheckOutput - The check result.
error - Non-nil if inputs are invalid.

Thread Safety:

Safe for concurrent use.

type LintCheckOutput

type LintCheckOutput struct {
	// Passed indicates whether all policies were satisfied.
	Passed bool

	// ErrorCount is the number of lint errors.
	ErrorCount int

	// WarningCount is the number of lint warnings.
	WarningCount int

	// Violations contains details of policy violations.
	Violations []string

	// Duration is the check time.
	Duration time.Duration
}

LintCheckOutput contains the result of lint policy checking.

type LoadCacheNode

type LoadCacheNode struct {
	dag.BaseNode
	// contains filtered or unexported fields
}

LoadCacheNode loads or builds a cached code graph.

Description:

Attempts to load a cached graph for the project. If not cached or
stale, uses the provided build function to create a new graph and
caches it for future use.

Inputs (from map[string]any):

"project_root" (string): Absolute path to project root. Required.
"force_rebuild" (bool): If true, ignores cache and rebuilds. Optional.

Outputs:

*LoadCacheOutput containing:
  - Graph: The loaded or built graph
  - Manifest: The project manifest
  - FromCache: Whether the graph was loaded from cache
  - Duration: Load/build time

Thread Safety:

Safe for concurrent use.

func NewLoadCacheNode

func NewLoadCacheNode(
	graphCache *cache.GraphCache,
	buildFunc cache.BuildFunc,
	deps []string,
) *LoadCacheNode

NewLoadCacheNode creates a new load cache node.

Inputs:

graphCache - The graph cache to use. Must not be nil.
buildFunc - Function to build graph if not cached. Must not be nil.
deps - Names of nodes this node depends on.

Outputs:

*LoadCacheNode - The configured node.

func (*LoadCacheNode) Execute

func (n *LoadCacheNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute loads or builds the cached graph.

Description:

First attempts to load from cache. If not found or force_rebuild is
set, uses the build function to create a new graph. The result is
cached for future use.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "project_root" and optionally "force_rebuild".

Outputs:

*LoadCacheOutput - The load result.
error - Non-nil if loading and building both fail.

Thread Safety:

Safe for concurrent use.

type LoadCacheOutput

type LoadCacheOutput struct {
	// Graph is the loaded or built code graph.
	Graph *graph.Graph

	// Manifest is the project manifest.
	Manifest *manifest.Manifest

	// GraphID is the unique identifier for this cached graph.
	GraphID string

	// FromCache indicates whether the graph was loaded from cache.
	FromCache bool

	// WasStale indicates the cache entry was stale.
	WasStale bool

	// Duration is the load/build time.
	Duration time.Duration
}

LoadCacheOutput contains the result of loading/building a cache.

type ParseError

type ParseError struct {
	FilePath string
	Error    string
}

ParseError represents a single file parse failure.

type ParseFilesNode

type ParseFilesNode struct {
	dag.BaseNode
	// contains filtered or unexported fields
}

ParseFilesNode parses source files using the AST parser registry.

Description:

Reads source files from disk and parses them using language-specific
parsers registered in the ParserRegistry. Supports parallel parsing
for improved performance on multi-file projects.

Inputs (from map[string]any):

"project_root" (string): Absolute path to project root. Required.
"files" ([]string): List of file paths to parse. Required.
    Paths can be relative (to project_root) or absolute.

Outputs:

*ParseFilesOutput containing:
  - Results: Parsed results for each file
  - Errors: Files that failed to parse
  - Duration: Total parsing time

Thread Safety:

Safe for concurrent use.

func NewParseFilesNode

func NewParseFilesNode(registry *ast.ParserRegistry, deps []string) *ParseFilesNode

NewParseFilesNode creates a new parse files node.

Inputs:

registry - The parser registry to use. Must not be nil.
deps - Names of nodes this node depends on.

Outputs:

*ParseFilesNode - The configured node.

func (*ParseFilesNode) Execute

func (n *ParseFilesNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute parses the specified files.

Description:

Parses source files in parallel using the configured parser registry.
Files are grouped by extension and parsed using the appropriate parser.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "project_root" and "files".

Outputs:

*ParseFilesOutput - The parse results.
error - Non-nil if critical failure (individual file errors in output).

Thread Safety:

Safe for concurrent use.

func (*ParseFilesNode) WithParallelism

func (n *ParseFilesNode) WithParallelism(p int) *ParseFilesNode

WithParallelism sets the number of parallel parsing goroutines.

type ParseFilesOutput

type ParseFilesOutput struct {
	// Results contains successfully parsed files.
	Results []*ast.ParseResult

	// Errors contains files that failed to parse.
	Errors []ParseError

	// FilesProcessed is the total number of files attempted.
	FilesProcessed int

	// Duration is the total parsing time.
	Duration time.Duration
}

ParseFilesOutput contains the results of file parsing.

type PatternScanNode

type PatternScanNode struct {
	dag.BaseNode
	// contains filtered or unexported fields
}

PatternScanNode detects design patterns in code.

Description:

Uses the patterns.PatternDetector to find design patterns in the
code graph. Can detect singleton, factory, builder, and other
common patterns.

Inputs (from map[string]any):

"graph" (*graph.Graph): The code graph to scan. Required.
"index" (*index.SymbolIndex): Symbol index for lookups. Required.
"scope" (string): Package/file prefix to scan. Optional, default "" (all).
"patterns" ([]string): Specific patterns to detect. Optional.

Outputs:

*PatternScanOutput containing:
  - Patterns: Detected design patterns
  - Summary: Pattern detection summary
  - Duration: Scan time

Thread Safety:

Safe for concurrent use.

func NewPatternScanNode

func NewPatternScanNode(deps []string) *PatternScanNode

NewPatternScanNode creates a new pattern scan node.

Inputs:

deps - Names of nodes this node depends on.

Outputs:

*PatternScanNode - The configured node.

func (*PatternScanNode) Execute

func (n *PatternScanNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute scans for design patterns in the code graph.

Description:

Creates a PatternDetector and scans the graph for patterns.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "graph", "index", and optionally "scope".

Outputs:

*PatternScanOutput - The scan result.
error - Non-nil if required inputs are missing.

Thread Safety:

Safe for concurrent use.

func (*PatternScanNode) WithIdiomaticOnly

func (n *PatternScanNode) WithIdiomaticOnly(only bool) *PatternScanNode

WithIdiomaticOnly excludes non-idiomatic patterns.

func (*PatternScanNode) WithMinConfidence

func (n *PatternScanNode) WithMinConfidence(conf float64) *PatternScanNode

WithMinConfidence sets the minimum confidence threshold.

type PatternScanOutput

type PatternScanOutput struct {
	// Patterns contains detected design patterns.
	Patterns []patterns.DetectedPattern

	// Summary is a human-readable summary.
	Summary string

	// PatternCounts maps pattern types to counts.
	PatternCounts map[string]int

	// IdiomaticCount is the number of idiomatic patterns.
	IdiomaticCount int

	// Duration is the scan time.
	Duration time.Duration
}

PatternScanOutput contains the result of pattern detection.

type SafetyScanNode

type SafetyScanNode struct {
	dag.BaseNode
	// contains filtered or unexported fields
}

SafetyScanNode performs security vulnerability scanning.

Description:

Uses the security scanning interfaces to detect vulnerabilities
like SQL injection, XSS, command injection, and hardcoded secrets.

Inputs (from map[string]any):

"scanner" (safety.SecurityScanner): The security scanner. Required.
"scope" (string): Package/file scope to scan. Required.
"min_severity" (string): Minimum severity to report. Optional.
"min_confidence" (float64): Minimum confidence to report. Optional.

Outputs:

*SafetyScanOutput containing:
  - Result: The full scan result
  - IssueCount: Number of issues found
  - CriticalCount: Number of critical issues
  - Duration: Scan time

Thread Safety:

Safe for concurrent use.

func NewSafetyScanNode

func NewSafetyScanNode(scanner safety.SecurityScanner, deps []string) *SafetyScanNode

NewSafetyScanNode creates a new safety scan node.

Inputs:

scanner - The security scanner to use. Must not be nil.
deps - Names of nodes this node depends on.

Outputs:

*SafetyScanNode - The configured node.

func (*SafetyScanNode) Execute

func (n *SafetyScanNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute performs security scanning on the specified scope.

Description:

Runs the security scanner against the specified scope.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "scope" and optionally severity/confidence thresholds.

Outputs:

*SafetyScanOutput - The scan result.
error - Non-nil if scanner is nil or scope is missing.

Thread Safety:

Safe for concurrent use.

func (*SafetyScanNode) WithMinConfidence

func (n *SafetyScanNode) WithMinConfidence(conf float64) *SafetyScanNode

WithMinConfidence sets the minimum confidence to report.

func (*SafetyScanNode) WithMinSeverity

func (n *SafetyScanNode) WithMinSeverity(sev safety.Severity) *SafetyScanNode

WithMinSeverity sets the minimum severity to report.

type SafetyScanOutput

type SafetyScanOutput struct {
	// Result is the full scan result.
	Result *safety.ScanResult

	// IssueCount is the total number of issues found.
	IssueCount int

	// CriticalCount is the number of critical issues.
	CriticalCount int

	// HighCount is the number of high severity issues.
	HighCount int

	// Passed indicates no critical or high issues were found.
	Passed bool

	// Duration is the scan time.
	Duration time.Duration
}

SafetyScanOutput contains the result of security scanning.

type SymbolLocation

type SymbolLocation struct {
	FilePath string
	Line     int // 1-indexed
	Column   int // 0-indexed
}

SymbolLocation identifies a symbol for type checking.

type TDGConfig

type TDGConfig struct {
	// MaxRetries is the maximum number of generation/fix attempts.
	MaxRetries int

	// TestTimeout is the timeout for running tests.
	TestTimeout time.Duration

	// Logger is the logger to use.
	Logger *slog.Logger
}

TDGConfig contains configuration for Test-Driven Generation.

func DefaultTDGConfig

func DefaultTDGConfig() TDGConfig

DefaultTDGConfig returns sensible defaults.

type TDGExecutor

type TDGExecutor interface {
	Execute(ctx context.Context, req TDGRequest) (*TDGOutput, error)
}

TDGExecutor defines the interface for TDG execution. This allows injecting the actual TDG implementation.

type TDGNode

type TDGNode struct {
	mainDag.BaseNode
	// contains filtered or unexported fields
}

TDGNode wraps Test-Driven Generation as a DAG node.

Description:

TDG (Test-Driven Generation) is an iterative process:
1. Generate a failing test from a user query
2. Generate implementation to make test pass
3. If test fails, iterate on implementation
4. Return when test passes or max retries exceeded

This node wraps the TDG workflow as a single DAG node that
internally manages its own state machine.

Inputs (from map[string]any):

"query" (string): The user's request describing what to implement. Required.
"target_file" (string): File path where implementation should go. Required.
"test_file" (string): File path where test should go. Required.
"language" (string): Programming language (e.g., "go", "python"). Required.
"context" (string): Additional context about the codebase. Optional.

Outputs:

*TDGOutput containing:
  - TestCode: The generated test code
  - Implementation: The generated implementation code
  - Iterations: Number of iterations needed
  - Success: Whether generation succeeded
  - Duration: Total generation time

Thread Safety:

Safe for concurrent use.

func NewTDGNode

func NewTDGNode(config TDGConfig, deps []string) *TDGNode

NewTDGNode creates a new TDG node.

Inputs:

config - TDG configuration.
deps - Names of nodes this node depends on.

Outputs:

*TDGNode - The configured node.

func (*TDGNode) Execute

func (n *TDGNode) Execute(ctx context.Context, inputs map[string]any) (any, error)

Execute runs the TDG workflow.

Description:

Extracts the TDG request from inputs and runs the generation loop.
The actual LLM interaction is delegated to the configured executor
or sub-DAG.

Inputs:

ctx - Context for cancellation.
inputs - Map containing "query", "target_file", "test_file", "language".

Outputs:

*TDGOutput - The generation result.
error - Non-nil if extraction fails or TDG completely fails.

Thread Safety:

Safe for concurrent use.

func (*TDGNode) WithSubDAG

func (n *TDGNode) WithSubDAG(dag *mainDag.DAG) *TDGNode

WithSubDAG sets a custom sub-DAG for TDG execution. This allows composing TDG as a nested DAG instead of a single executor.

type TDGOutput

type TDGOutput struct {
	// TestCode is the generated test code.
	TestCode string

	// Implementation is the generated implementation code.
	Implementation string

	// Iterations is the number of generate/fix cycles.
	Iterations int

	// TestsPassed indicates all tests passed.
	TestsPassed bool

	// Success indicates the overall operation succeeded.
	Success bool

	// ErrorMessage contains error details if Success is false.
	ErrorMessage string

	// Duration is the total generation time.
	Duration time.Duration
}

TDGOutput contains the result of Test-Driven Generation.

type TDGRequest

type TDGRequest struct {
	Query      string
	TargetFile string
	TestFile   string
	Language   string
	Context    string
}

TDGRequest contains the input for TDG.

type TypeCheckError

type TypeCheckError struct {
	Symbol SymbolLocation
	Error  string
}

TypeCheckError represents a type check failure.

type TypeCheckResult

type TypeCheckResult struct {
	Symbol   SymbolLocation
	TypeInfo string
	Kind     string // "plaintext" or "markdown"
}

TypeCheckResult contains type information for a symbol.

Jump to

Keyboard shortcuts

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