paths

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 3 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 paths implements attack-path enumeration and shortest-path search over the AgentGraph graph model.

Index

Constants

View Source
const DefaultMaxDepth = 10

DefaultMaxDepth is the default maximum attack-path depth (PRD section 38).

View Source
const DefaultMaxPaths = 1000

DefaultMaxPaths caps enumerated paths to protect against graph explosion.

Variables

This section is empty.

Functions

func Describe

func Describe(p *Path) string

Describe renders a path in the arrow notation used throughout the PRD, e.g. "finance-agent -USES-> github-mcp -CAN_WRITE-> payments-repository".

func IsTerminal

func IsTerminal(n *graph.Node) bool

IsTerminal reports whether a node is a valid attack-path target.

Types

type Options

type Options struct {
	// MaxDepth is the maximum number of edges in a path.
	MaxDepth int
	// MinConfidence excludes edges below this confidence (0-1).
	MinConfidence float64
	// MaxPaths caps the number of returned paths (0 = DefaultMaxPaths).
	MaxPaths int
	// TargetID restricts results to paths ending at this node ID.
	TargetID string
	// TargetSubstring matches target node ID or name (case-insensitive).
	TargetSubstring string
	// CrownJewelsOnly restricts results to paths ending at crown jewels.
	CrownJewelsOnly bool
	// EdgeTypes is an optional allowlist of edge types.
	EdgeTypes map[graph.EdgeType]bool
}

Options controls path enumeration constraints.

type Path

type Path struct {
	ID     string
	Source *graph.Node
	Target *graph.Node
	Steps  []Step // target is Steps[len-1].Node
	// Confidence is the product of all edge confidences.
	Confidence float64
}

Path is a single attack path from a source node to a target node.

func Enumerate

func Enumerate(g *graph.Graph, source string, opts Options) ([]*Path, error)

Enumerate finds all attack paths from source subject to the options. Paths are simple (no repeated nodes), which prevents meaningless loops such as Agent -> Tool -> Agent -> Tool. Results are deterministically ordered and assigned IDs of the form PATH-0001.

func EnumerateAll

func EnumerateAll(g *graph.Graph, opts Options) ([]*Path, error)

EnumerateAll enumerates paths from every AI agent in the graph. IDs are assigned across the combined, deterministically sorted result. When any single agent's enumeration hits the MaxPaths cap, its partial results are kept and enumeration continues with the remaining agents; the returned error is a *TruncatedError in that case.

func Shortest

func Shortest(g *graph.Graph, source, targetSpec string) *Path

Shortest returns the shortest path (fewest hops) from source to a target matching the spec, using breadth-first search. Target resolution: if targetSpec exactly matches a node ID, that node is used; otherwise the spec is matched case-insensitively as a substring of node ID or name. Returns nil if no target matches or no path exists.

func ShortestToPredicate

func ShortestToPredicate(g *graph.Graph, source string, match func(*graph.Node) bool) *Path

ShortestToPredicate returns the shortest path from source to any node for which match returns true.

func (*Path) Edges

func (p *Path) Edges() []*graph.Edge

Edges returns the edge sequence.

func (*Path) Length

func (p *Path) Length() int

Length returns the number of edges (hops) in the path.

func (*Path) Nodes

func (p *Path) Nodes() []*graph.Node

Nodes returns the full node sequence, source first.

type Step

type Step struct {
	Edge *graph.Edge
	Node *graph.Node
}

Step is one hop in a path: the edge taken and the node reached.

type TruncatedError

type TruncatedError struct{ Found int }

TruncatedError is returned when enumeration hits the MaxPaths cap. Partial results are returned alongside it.

func (*TruncatedError) Error

func (e *TruncatedError) Error() string

Jump to

Keyboard shortcuts

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