{"modulePath":"github.com/agentshield-dev/agentshield","version":"v0.0.1-rc.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package graph\n\nPackage graph defines AgentShield's provider-neutral graph model and the pure compiler that turns plugin assertions into a canonical snapshot.\n\n### Pipeline position {#hdr-Pipeline_position}\n\nDiscovery plugins and the telemetry rollup emit an [Input](#Input): resource, facet, relationship, and bounded telemetry assertions. Package state persists those assertions per contribution and calls [Compiler](#Compiler) twice: once to validate a candidate contribution ([Compiler.CompileContribution](#Compiler.CompileContribution)) and once to materialize the union of all active contributions ([Compiler.Compile](#Compiler.Compile)). The resulting [Snapshot](#Snapshot) feeds current-state projections, the graph API, and reasoning. This package performs no I/O and holds no contribution or generation state; ownership and replacement live in package state.\n\n### Identity {#hdr-Identity}\n\nEvery graph node is named by an [IdentityClaim](#IdentityClaim): a scheme (group, version, kind), an authority ID, and an immutable key. A [Registry](#Registry) maps each [IdentityScheme](#IdentityScheme) to a normalizer, and the compiler derives a UUIDv5 resource ID from the normalized tuple. Claims must be authority-qualified (a cluster UID or cloud account, not a plugin ID) and provider-immutable (an object UID or immutable resource name, not a display name, label, or IP address), so independent plugins converge on the same node and a recreated object gets a new one. Mutable values belong in attributes. NetworkDestination and NetworkPeerClass are built-in provider-neutral schemes preloaded by [NewRegistry](#NewRegistry); plugins register only the authority-specific schemes they introduce.\n\n### Assertions and provenance {#hdr-Assertions_and_provenance}\n\nEvery assertion carries PluginID, SourceID, RuleID, and EvidenceIDs. The compiler rejects assertions without a plugin, source, or rule, sorts and deduplicates evidence IDs, groups equal claims onto one record while keeping every contributing assertion, deduplicates identical assertions, and sorts all output. Two inputs containing the same assertion set therefore compile to byte-identical [Snapshot.CanonicalJSON](#Snapshot.CanonicalJSON), regardless of slice order or duplication.\n\nRelationships use only predicates registered in this package (see [IsRegisteredPredicate](#IsRegisteredPredicate)); adding a predicate is a central change that must also update persistence constraints. A relationship or facet whose endpoint resource is not present is kept with [ResolutionUnresolved](#ResolutionUnresolved) so contributions can reference identities owned by other plugins without publication ordering. Conflicting kinds for one identity become an [AssertionConflict](#AssertionConflict) rather than an error.\n\n### Security semantics {#hdr-Security_semantics}\n\n[SecuritySemantics](#SecuritySemantics) is a closed, versioned, provider-neutral envelope stored in a facet attribute or relationship property under [SecuritySemanticsAttribute](#SecuritySemanticsAttribute). The compiler validates every envelope present and requires canonical encoding; it does not enforce that one is present.\n\nSee [https://agent-shield.dev/docs/concepts/data-model/](https://agent-shield.dev/docs/concepts/data-model/) for the full model.\n\n## Constants\n\n```go\nconst (\n\tResourceAuthoringContextAttribute   = \"agentshield/resource-authoring-context\"\n\tResourceAuthoringContextMaxBytes    = 40 \u003c\u003c 10\n\tResourceAuthoringAttributesMaxItems = 128\n)\n```\n\n```go\nconst (\n\tNetworkRoleControlPlaneAPI = \"control-plane-api\"\n\tNetworkRoleService         = \"service\"\n\tNetworkRoleWorkload        = \"workload\"\n)\n```\nValues of the provider-neutral network/role resource attribute.\n\n```go\nconst (\n\t// SecuritySemanticsAttribute is the facet attribute or relationship\n\t// property key that carries the canonical SecuritySemantics JSON.\n\tSecuritySemanticsAttribute = \"agentshield.io/security-semantics\"\n\t// SecuritySemanticsV1 is the only supported envelope version.\n\tSecuritySemanticsV1 = \"v1\"\n)\n```\n\n```go\nconst ProcessClassShell = \"shell\"\n```\nProcessClassShell is an interactive shell process.\n\n## Functions\n\n```go\nfunc EncodeSecuritySemantics(semantics SecuritySemantics) (string, error)\n```\nEncodeSecuritySemantics validates semantics and returns its canonical JSON: protocols are trimmed, uppercased, sorted, and deduplicated, and ports are sorted and deduplicated. Producers must bound native input first; oversized protocol or port lists are rejected rather than truncated.\n\n```go\nfunc IsNetworkDestinationClaim(claim IdentityClaim) bool\n```\nIsNetworkDestinationClaim reports whether claim uses the NetworkDestination scheme.\n\n```go\nfunc IsNetworkPeerClassClaim(claim IdentityClaim) bool\n```\nIsNetworkPeerClassClaim reports whether claim uses the NetworkPeerClass scheme.\n\n```go\nfunc IsProcessClassClaim(claim IdentityClaim) bool\n```\nIsProcessClassClaim reports whether claim uses the ProcessClass scheme.\n\n```go\nfunc IsRegisteredPredicate(predicate Predicate) bool\n```\nIsRegisteredPredicate reports whether predicate is in the central vocabulary.\n\n```go\nfunc ResourceNetworkRoles(snapshot Snapshot) map[string]string\n```\nResourceNetworkRoles maps resource IDs to network/role, including network destinations whose address appears in another resource's network/addresses.\n\n```go\nfunc WithSecuritySemantics(attributes map[string]string, semantics SecuritySemantics) (map[string]string, error)\n```\nWithSecuritySemantics returns a copy of attributes with the canonical encoding of semantics added under SecuritySemanticsAttribute. The input map is not modified.\n\n## Types\n\n```go\ntype AssertionConflict struct {\n\tResourceID string              `json:\"resourceId\"`\n\tKinds      []string            `json:\"kinds\"`\n\tAssertions []ResourceAssertion `json:\"assertions\"`\n}\n```\nAssertionConflict records an identity asserted with more than one kind. The identity is withheld from Snapshot.Resources so traversal never picks a kind arbitrarily; edges to it remain unresolved.\n\n```go\ntype Compiler struct {\n\t// contains filtered or unexported fields\n}\n```\nCompiler is the pure, deterministic graph materializer. It holds no state besides its registry and is safe for concurrent use once registration is complete.\n\n```go\nfunc NewCompiler(registry *Registry) *Compiler\n```\nNewCompiler returns a compiler that resolves identities through registry.\n\n```go\nfunc (c *Compiler) Compile(input Input) (Snapshot, error)\n```\nCompile materializes the complete active graph. Telemetry whose subject or object resource is absent is dropped, because telemetry rollups only attach to materialized inventory; unresolved facets and relationships are kept.\n\n```go\nfunc (c *Compiler) CompileContribution(input Input) (Snapshot, error)\n```\nCompileContribution validates and resolves assertions before persistence; endpoint presence is enforced later when all active contributions are composed.\n\n```go\nfunc (c *Compiler) NormalizeIdentityClaim(claim IdentityClaim) (IdentityClaim, error)\n```\n\n```go\ntype Facet struct {\n\tID               string           `json:\"id\"`\n\tResourceID       string           `json:\"resourceId\"`\n\tKind             string           `json:\"kind\"`\n\tKey              string           `json:\"key\"`\n\tResolutionStatus ResolutionStatus `json:\"resolutionStatus,omitempty\"`\n\tAssertions       []FacetAssertion `json:\"assertions\"`\n}\n```\nFacet is a compiled facet. ID is derived from resource ID, kind, and key.\n\n```go\ntype FacetAssertion struct {\n\tResource    IdentityClaim     `json:\"resource\"`\n\tKind        string            `json:\"kind\"`\n\tKey         string            `json:\"key\"`\n\tAttributes  map[string]string `json:\"attributes,omitempty\"`\n\tPluginID    string            `json:\"pluginId\"`\n\tSourceID    string            `json:\"sourceId\"`\n\tRuleID      string            `json:\"ruleId\"`\n\tEvidenceIDs []string          `json:\"evidenceIds\"`\n}\n```\nFacetAssertion attaches one independently computed aspect, identified by Kind and Key, to the resource named by Resource. Facets let several plugins enrich the same node without sharing ownership of it.\n\n```go\ntype IdentityClaim struct {\n\tScheme       IdentityScheme `json:\"scheme\"`\n\tAuthorityID  string         `json:\"authorityId\"`\n\tImmutableKey string         `json:\"immutableKey\"`\n}\n```\nIdentityClaim names a resource within an authority-owned scheme. The compiler normalizes this tuple and derives the stable resource ID shared by assertions.\n\n```go\nfunc NetworkDestinationClaim(authorityID, immutableKey string) (IdentityClaim, error)\n```\nNetworkDestinationClaim builds a claim through the scheme's normalizer, so it matches what the compiler stores; it fails for an empty authority or key.\n\n```go\nfunc NetworkPeerClassClaim(authorityID, immutableKey string) (IdentityClaim, error)\n```\nNetworkPeerClassClaim builds a claim through the scheme's normalizer; it fails for a key outside the closed peer-class vocabulary.\n\n```go\nfunc ProcessClassClaim(authorityID, immutableKey string) (IdentityClaim, error)\n```\nProcessClassClaim returns a normalized ProcessClass claim, or an error for a class outside the core vocabulary.\n\n```go\ntype IdentityScheme struct {\n\tGroup   string `json:\"group\"`\n\tVersion string `json:\"version\"`\n\tKind    string `json:\"kind\"`\n}\n```\nIdentityScheme names an identity authority contract in Kubernetes-style group/version/kind form. The group identifies the semantic authority, not the plugin that emits claims under it.\n\n```go\ntype Input struct {\n\tResources     []ResourceAssertion\n\tFacets        []FacetAssertion\n\tRelationships []RelationshipAssertion\n\tTelemetry     []TelemetryAssertion\n}\n```\nInput is an assertion set submitted to the compiler. Contribution ownership and replacement are handled by the publication layer around this pure model.\n\n```go\nfunc Reverse(input Input) Input\n```\nReverse returns a copy of input with every assertion slice reversed. Tests use it to prove that compiled output does not depend on input order.\n\n```go\ntype NetworkRoleDescription struct {\n\tRole        string\n\tDescription string\n}\n```\nNetworkRoleDescription pairs a network/role value with its meaning.\n\n```go\nfunc NetworkRoles() []NetworkRoleDescription\n```\nNetworkRoles lists the values providers may publish in the network/role attribute.\n\n```go\ntype Predicate string\n```\nPredicate is a directed relationship type. Only predicates in the central registry are accepted by the compiler; see IsRegisteredPredicate.\n\n```go\nconst (\n\tPredicateContains     Predicate = \"contains\"\n\tPredicateInstantiates Predicate = \"instantiates\"\n\tPredicateMemberOf     Predicate = \"member-of\"\n\tPredicateUsesIdentity Predicate = \"uses-identity\"\n\tPredicateExposes      Predicate = \"exposes\"\n\tPredicateGovernedBy   Predicate = \"governed-by\"\n\tPredicateCommunicates Predicate = \"communicates-with\"\n\tPredicateRunsOn       Predicate = \"runs-on\"\n\tPredicateBackedBy     Predicate = \"backed-by\"\n\tPredicateExecutes     Predicate = \"executes\"\n)\n```\nRegistered predicates. Adding one is a central change that also needs a new state migration widening the relationship predicate CHECK constraints.\n\n```go\ntype PredicateDescription struct {\n\tPredicate   Predicate\n\tDescription string\n}\n```\nPredicateDescription pairs a registered predicate with a human-readable meaning. It feeds generated detector-rule documentation.\n\n```go\nfunc RegisteredPredicateDescriptions() []PredicateDescription\n```\nRegisteredPredicateDescriptions returns every registered predicate sorted by name. Predicates without a description have an empty Description.\n\n```go\ntype ProcessClassDescription struct {\n\tClass       string\n\tDescription string\n}\n```\nProcessClassDescription pairs a core process class with its meaning. It feeds generated detector-rule documentation.\n\n```go\nfunc ProcessClasses() []ProcessClassDescription\n```\nProcessClasses lists the core process-class vocabulary.\n\n```go\ntype Registry struct {\n\t// contains filtered or unexported fields\n}\n```\nRegistry maps identity schemes to their normalizers. It is populated at startup before the Compiler is built and is not safe for concurrent registration.\n\n```go\nfunc NewRegistry() *Registry\n```\nNewRegistry returns a registry preloaded with the built-in NetworkDestination and NetworkPeerClass schemes.\n\n```go\nfunc (r *Registry) Register(definition SchemeDefinition) error\n```\nRegister adds a scheme definition. Registering the same scheme twice is an error, so two plugins cannot both claim authority over one scheme.\n\n```go\ntype Relationship struct {\n\tID               string                  `json:\"id\"`\n\tSubjectID        string                  `json:\"subjectId\"`\n\tPredicate        Predicate               `json:\"predicate\"`\n\tObjectID         string                  `json:\"objectId\"`\n\tQualifier        string                  `json:\"qualifier,omitempty\"`\n\tResolutionStatus ResolutionStatus        `json:\"resolutionStatus,omitempty\"`\n\tAssertions       []RelationshipAssertion `json:\"assertions\"`\n}\n```\nRelationship is a compiled edge. ID is derived from subject, predicate, object, and qualifier, so equal edges from different plugins share one record and keep separate assertions.\n\n```go\ntype RelationshipAssertion struct {\n\tSubject     IdentityClaim     `json:\"subject\"`\n\tPredicate   Predicate         `json:\"predicate\"`\n\tObject      IdentityClaim     `json:\"object\"`\n\tQualifier   string            `json:\"qualifier,omitempty\"`\n\tProperties  map[string]string `json:\"properties,omitempty\"`\n\tPluginID    string            `json:\"pluginId\"`\n\tSourceID    string            `json:\"sourceId\"`\n\tRuleID      string            `json:\"ruleId\"`\n\tEvidenceIDs []string          `json:\"evidenceIds\"`\n}\n```\nRelationshipAssertion claims a directed edge (Subject, Predicate, Object, Qualifier). Either endpoint may be owned by another contribution; the edge is kept as unresolved until both resources are present.\n\n```go\ntype ResolutionStatus string\n```\nResolutionStatus records whether a facet or relationship's endpoint resources are present in the compiled snapshot.\n\n```go\nconst (\n\tResolutionResolved   ResolutionStatus = \"\"\n\tResolutionUnresolved ResolutionStatus = \"unresolved\"\n)\n```\nResolution statuses. Resolved is the zero value so it is omitted from JSON.\n\n```go\ntype Resource struct {\n\tID         string              `json:\"id\"`\n\tKind       string              `json:\"kind\"`\n\tIdentity   IdentityClaim       `json:\"identity\"`\n\tAssertions []ResourceAssertion `json:\"assertions\"`\n}\n```\nResource is a compiled graph node with every assertion that claimed it, in canonical order.\n\n```go\ntype ResourceAssertion struct {\n\tClaim       IdentityClaim     `json:\"claim\"`\n\tKind        string            `json:\"kind\"`\n\tDisplayName string            `json:\"displayName,omitempty\"`\n\tAttributes  map[string]string `json:\"attributes,omitempty\"`\n\tPluginID    string            `json:\"pluginId\"`\n\tSourceID    string            `json:\"sourceId\"`\n\tRuleID      string            `json:\"ruleId\"`\n\tEvidenceIDs []string          `json:\"evidenceIds\"`\n}\n```\nResourceAssertion claims that a resource with Kind exists under Claim. More than one plugin may assert the same identity; differing kinds produce an AssertionConflict instead of a Resource.\n\n```go\ntype ResourceAuthoringContext struct {\n\tSchemaVersion        string            `json:\"schemaVersion\"`\n\tSourceRevisionSHA256 string            `json:\"sourceRevisionSha256,omitempty\"`\n\tContext              json.RawMessage   `json:\"context\"`\n\tAttributes           map[string]string `json:\"attributes,omitempty\"`\n}\n```\n\n```go\nfunc DecodeResourceAuthoringContext(encoded string) (ResourceAuthoringContext, error)\n```\n\n```go\nfunc NewResourceAuthoringContext(context any, attributes map[string]string) (ResourceAuthoringContext, error)\n```\n\n```go\nfunc (authoringContext ResourceAuthoringContext) SHA256() (string, error)\n```\n\n```go\nfunc (authoringContext ResourceAuthoringContext) Validate() error\n```\n\n```go\ntype SchemeDefinition struct {\n\tScheme    IdentityScheme\n\tNormalize func(IdentityClaim) (IdentityClaim, error)\n}\n```\nSchemeDefinition binds an authority contract to its identity normalizer. Plugins register only schemes whose identity authority they introduce.\n\n```go\nfunc NetworkDestinationSchemeDefinition() SchemeDefinition\n```\nNetworkDestinationSchemeDefinition defines the built-in agentshield.io/v1 NetworkDestination scheme. Its authority is a network realm and its key is dns/\\\u003chost\u003e or ip/\\\u003caddress\u003e, lowercased so configuration and telemetry converge on one node.\n\n```go\nfunc NetworkPeerClassSchemeDefinition() SchemeDefinition\n```\nNetworkPeerClassSchemeDefinition defines the built-in agentshield.io/v1 NetworkPeerClass scheme. Its key must be one value of a closed vocabulary, so unresolved telemetry peers collapse into a bounded set of nodes instead of one node per raw address.\n\n```go\nfunc ProcessClassSchemeDefinition() SchemeDefinition\n```\nProcessClassSchemeDefinition normalizes ProcessClass claims and accepts only the core process-class vocabulary.\n\n```go\nfunc TrimmedIdentityScheme(name IdentityScheme) SchemeDefinition\n```\nTrimmedIdentityScheme returns a definition whose normalizer trims whitespace and requires a non-empty authority and key. It preserves key case; use a custom normalizer when the provider key is case-insensitive.\n\n```go\ntype SecurityClass string\n```\nSecurityClass separates what is reachable (exposure) from what constrains it (governance).\n\n```go\nconst (\n\tSecurityClassExposure   SecurityClass = \"exposure\"\n\tSecurityClassGovernance SecurityClass = \"governance\"\n)\n```\nSecurity classes.\n\n```go\ntype SecurityDomain string\n```\nSecurityDomain names the security mechanism a SecuritySemantics describes.\n\n```go\nconst (\n\tSecurityDomainNetworkAccess           SecurityDomain = \"network-access\"\n\tSecurityDomainAuthorization           SecurityDomain = \"authorization\"\n\tSecurityDomainTransportAuthentication SecurityDomain = \"transport-authentication\"\n)\n```\nSecurity domains.\n\n```go\ntype SecurityPort struct {\n\tProtocol string `json:\"protocol\"`\n\tPort     uint16 `json:\"port\"`\n}\n```\nSecurityPort is one protocol and port pair in a SecuritySemantics summary.\n\n```go\ntype SecuritySemantics struct {\n\tVersion             string         `json:\"version\"`\n\tClass               SecurityClass  `json:\"class\"`\n\tDomain              SecurityDomain `json:\"domain\"`\n\tState               SecurityState  `json:\"state\"`\n\tEffect              string         `json:\"effect\"`\n\tScope               string         `json:\"scope\"`\n\tDirection           string         `json:\"direction\"`\n\tCoverage            string         `json:\"coverage\"`\n\tProtocols           []string       `json:\"protocols,omitempty\"`\n\tPorts               []SecurityPort `json:\"ports,omitempty\"`\n\tConfigurationDigest string         `json:\"configurationDigest,omitempty\"`\n}\n```\nSecuritySemantics is the provider-neutral security meaning attached to a facet or relationship. Provider-native resources and attributes remain the provenance and drill-down surface.\n\n```go\nfunc DecodeSecuritySemantics(attributes map[string]string) (*SecuritySemantics, error)\n```\nDecodeSecuritySemantics returns the envelope stored in attributes, or nil when none is present. It rejects unknown fields, trailing data, invalid vocabulary, and any payload that differs from its canonical encoding, so the stored bytes, and therefore assertion content addresses, are unambiguous.\n\n```go\ntype SecurityState string\n```\nSecurityState records whether a security fact is declared or supported by provider/runtime observations. Declared configuration alone does not prove enforcement.\n\n```go\nconst (\n\tSecurityStateDeclared SecurityState = \"declared\"\n\tSecurityStateObserved SecurityState = \"observed\"\n\tSecurityStateUnknown  SecurityState = \"unknown\"\n)\n```\nSecurity states.\n\n```go\ntype Snapshot struct {\n\tResources     []Resource          `json:\"resources\"`\n\tFacets        []Facet             `json:\"facets\"`\n\tRelationships []Relationship      `json:\"relationships\"`\n\tTelemetry     []TelemetryEvent    `json:\"telemetry\"`\n\tConflicts     []AssertionConflict `json:\"conflicts,omitempty\"`\n}\n```\nSnapshot is the canonical graph compiled by grouping assertions around their normalized identities while retaining each assertion's provenance.\n\n```go\nfunc (s Snapshot) CanonicalJSON() ([]byte, error)\n```\nCanonicalJSON encodes the snapshot. Because the compiler sorts every slice and encoding/json sorts map keys, equal snapshots encode to equal bytes.\n\n```go\nfunc (s Snapshot) MarshalIndent() ([]byte, error)\n```\nMarshalIndent encodes the snapshot for human inspection.\n\n```go\ntype TelemetryAssertion struct {\n\tEventID     string            `json:\"eventId\"`\n\tKind        string            `json:\"kind\"`\n\tSubject     IdentityClaim     `json:\"subject\"`\n\tObject      IdentityClaim     `json:\"object\"`\n\tOperation   string            `json:\"operation,omitempty\"`\n\tOutcome     string            `json:\"outcome,omitempty\"`\n\tCoverage    string            `json:\"coverage,omitempty\"`\n\tCount       uint64            `json:\"count\"`\n\tProperties  map[string]string `json:\"properties,omitempty\"`\n\tPluginID    string            `json:\"pluginId\"`\n\tSourceID    string            `json:\"sourceId\"`\n\tRuleID      string            `json:\"ruleId\"`\n\tEvidenceIDs []string          `json:\"evidenceIds\"`\n}\n```\nTelemetryAssertion is a bounded rollup of observed activity from Subject to Object. EventID must be stable for the rollup series; reusing it within one plugin and source with different content is a compile error. Raw events stay in the telemetry sink.\n\n```go\ntype TelemetryEvent struct {\n\tID          string            `json:\"id\"`\n\tEventID     string            `json:\"eventId\"`\n\tKind        string            `json:\"kind\"`\n\tSubjectID   string            `json:\"subjectId\"`\n\tObjectID    string            `json:\"objectId\"`\n\tOperation   string            `json:\"operation,omitempty\"`\n\tOutcome     string            `json:\"outcome,omitempty\"`\n\tCoverage    string            `json:\"coverage,omitempty\"`\n\tCount       uint64            `json:\"count\"`\n\tProperties  map[string]string `json:\"properties,omitempty\"`\n\tPluginID    string            `json:\"pluginId\"`\n\tSourceID    string            `json:\"sourceId\"`\n\tRuleID      string            `json:\"ruleId\"`\n\tEvidenceIDs []string          `json:\"evidenceIds\"`\n}\n```\nTelemetryEvent is a compiled telemetry rollup with endpoints resolved to resource IDs. ID is derived from plugin, source, and EventID.\n\n","path":"github.com/agentshield-dev/agentshield/pkg/graph","name":"graph","synopsis":"Package graph defines AgentShield's provider-neutral graph model and the pure compiler that turns plugin assertions into a canonical snapshot.","isRedistributable":true}
