Documentation
¶
Overview ¶
Package graph implements the AgentGraph normalized node and edge models and the in-memory graph store.
Index ¶
- Variables
- func IsValidEdgeType(t EdgeType) bool
- func IsValidNodeType(t NodeType) bool
- func PrivilegeRank(level string) int
- type Edge
- type EdgeType
- type Graph
- func (g *Graph) AddEdge(e *Edge) error
- func (g *Graph) AddNode(n *Node) error
- func (g *Graph) EdgeBetween(source, target string) []*Edge
- func (g *Graph) EdgeCount() int
- func (g *Graph) Edges() []*Edge
- func (g *Graph) HasEdge(source, target string, t EdgeType) bool
- func (g *Graph) InEdges(id string) []*Edge
- func (g *Graph) Node(id string) (*Node, bool)
- func (g *Graph) NodeCount() int
- func (g *Graph) Nodes() []*Node
- func (g *Graph) NodesByType(t NodeType) []*Node
- func (g *Graph) OutEdges(id string) []*Edge
- func (g *Graph) RemoveEdge(source, target string, t EdgeType)
- func (g *Graph) UpsertNode(n *Node) error
- type Node
- type NodeType
- type Provenance
Constants ¶
This section is empty.
Variables ¶
var AllEdgeTypes = []EdgeType{ EdgeUses, EdgeCanCall, EdgeHasPermission, EdgeCanRead, EdgeCanWrite, EdgeCanExecute, EdgeCanModify, EdgeCanAssume, EdgeCanImpersonate, EdgeAuthenticatesAs, EdgeHasSecret, EdgeContainsSecret, EdgeCanAccess, EdgeCanAdmin, EdgeDeploysTo, EdgeTriggers, EdgeOwns, EdgeMemberOf, EdgeConnectedTo, EdgeTrusts, EdgeExposedTo, }
AllEdgeTypes is the canonical list of edge types.
var AllNodeTypes = []NodeType{ NodeAIAgent, NodeMCPServer, NodeTool, NodeIdentity, NodeSecret, NodeRepository, NodeCIPipeline, NodeCloudRole, NodeCloudResource, NodeDatabase, NodeHost, NodeAPI, NodeDataset, }
AllNodeTypes is the canonical ordered list of node types.
var DefaultEdgeRisk = map[EdgeType]int{ EdgeCanAdmin: 95, EdgeCanExecute: 90, EdgeCanImpersonate: 90, EdgeCanAssume: 85, EdgeContainsSecret: 80, EdgeHasSecret: 80, EdgeAuthenticatesAs: 75, EdgeCanModify: 75, EdgeCanWrite: 70, EdgeTriggers: 60, EdgeCanAccess: 55, EdgeDeploysTo: 50, EdgeCanRead: 40, EdgeHasPermission: 35, EdgeUses: 30, EdgeCanCall: 30, EdgeOwns: 30, EdgeMemberOf: 30, EdgeConnectedTo: 25, EdgeTrusts: 45, EdgeExposedTo: 50, }
DefaultEdgeRisk maps edge types to intrinsic risk (0-100) when an edge does not carry an explicit risk. Dangerous capabilities are rated according to the PRD's dangerous-capability table.
Functions ¶
func IsValidEdgeType ¶
IsValidEdgeType reports whether t is a known edge type.
func IsValidNodeType ¶
IsValidNodeType reports whether t is a known node type.
func PrivilegeRank ¶
PrivilegeRank returns an ordered rank for a privilege level string.
Types ¶
type Edge ¶
type Edge struct {
Source string `json:"source" yaml:"source"`
Target string `json:"target" yaml:"target"`
Type EdgeType `json:"type" yaml:"type"`
Confidence float64 `json:"confidence" yaml:"confidence"`
Risk int `json:"risk,omitempty" yaml:"risk,omitempty"`
Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty"`
Provenance Provenance `json:"provenance,omitempty" yaml:"provenance,omitempty"`
FirstSeen time.Time `json:"first_seen,omitempty" yaml:"first_seen,omitempty"`
LastSeen time.Time `json:"last_seen,omitempty" yaml:"last_seen,omitempty"`
LastVerified time.Time `json:"last_verified,omitempty" yaml:"last_verified,omitempty"`
}
Edge is the normalized graph edge (PRD section 36) with provenance (section 41) and freshness fields (section 42).
func (*Edge) EffectiveRisk ¶
EffectiveRisk returns the edge risk, falling back to the intrinsic default risk of its type.
type EdgeType ¶
type EdgeType string
EdgeType enumerates relationship categories between nodes.
const ( EdgeUses EdgeType = "USES" EdgeCanCall EdgeType = "CAN_CALL" EdgeHasPermission EdgeType = "HAS_PERMISSION" EdgeCanRead EdgeType = "CAN_READ" EdgeCanWrite EdgeType = "CAN_WRITE" EdgeCanExecute EdgeType = "CAN_EXECUTE" EdgeCanModify EdgeType = "CAN_MODIFY" EdgeCanAssume EdgeType = "CAN_ASSUME" EdgeCanImpersonate EdgeType = "CAN_IMPERSONATE" EdgeAuthenticatesAs EdgeType = "AUTHENTICATES_AS" EdgeHasSecret EdgeType = "HAS_SECRET" EdgeContainsSecret EdgeType = "CONTAINS_SECRET" EdgeCanAccess EdgeType = "CAN_ACCESS" EdgeCanAdmin EdgeType = "CAN_ADMIN" EdgeDeploysTo EdgeType = "DEPLOYS_TO" EdgeTriggers EdgeType = "TRIGGERS" EdgeOwns EdgeType = "OWNS" EdgeMemberOf EdgeType = "MEMBER_OF" EdgeConnectedTo EdgeType = "CONNECTED_TO" EdgeTrusts EdgeType = "TRUSTS" EdgeExposedTo EdgeType = "EXPOSED_TO" )
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is an in-memory directed multigraph with adjacency indexes. It is safe for read-only concurrent use after construction.
func (*Graph) AddEdge ¶
AddEdge validates and inserts an edge. Both endpoints must already exist. Duplicate edges (same source, target, and type) are ignored so that repeated connector runs are idempotent.
func (*Graph) AddNode ¶
AddNode inserts a node. Adding a duplicate ID returns an error to prevent silent overwrites between connectors.
func (*Graph) EdgeBetween ¶
EdgeBetween returns the edges from source to target, if any.
func (*Graph) NodesByType ¶
NodesByType returns all nodes of a given type sorted by ID.
func (*Graph) RemoveEdge ¶
RemoveEdge removes the edge from source to target with the given type.
func (*Graph) UpsertNode ¶
UpsertNode inserts a node or replaces an existing one with the same ID.
type Node ¶
type Node struct {
ID string `json:"id" yaml:"id"`
Type NodeType `json:"type" yaml:"type"`
Name string `json:"name" yaml:"name"`
Provider string `json:"provider,omitempty" yaml:"provider,omitempty"`
Criticality int `json:"criticality,omitempty" yaml:"criticality,omitempty"`
CrownJewel bool `json:"crown_jewel,omitempty" yaml:"crown_jewel,omitempty"`
Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}
Node is the normalized graph node (PRD section 35).
type NodeType ¶
type NodeType string
NodeType enumerates all node categories modeled by AgentGraph.
const ( NodeAIAgent NodeType = "AI_AGENT" NodeMCPServer NodeType = "MCP_SERVER" NodeTool NodeType = "TOOL" NodeIdentity NodeType = "IDENTITY" NodeSecret NodeType = "SECRET" NodeRepository NodeType = "REPOSITORY" NodeCIPipeline NodeType = "CI_PIPELINE" NodeCloudRole NodeType = "CLOUD_ROLE" NodeCloudResource NodeType = "CLOUD_RESOURCE" NodeDatabase NodeType = "DATABASE" NodeHost NodeType = "HOST" NodeAPI NodeType = "API" NodeDataset NodeType = "DATASET" )
type Provenance ¶
type Provenance struct {
Connector string `json:"connector,omitempty" yaml:"connector,omitempty"`
ObservedAt time.Time `json:"observed_at,omitempty" yaml:"observed_at,omitempty"`
SourceObject string `json:"source_object,omitempty" yaml:"source_object,omitempty"`
}
Provenance records where a relationship was observed.