Documentation
¶
Overview ¶
Package discovery hosts discovery plugins and connects them to observation collections and durable graph publication.
Pipeline position ¶
A source plugin watches a provider and publishes Change values to observation collections. Semantic plugins subscribe to those collections, run pure projectors over their current caches, and publish complete ContributionOutput values. RuntimeService records each change as a native event, fans it out through the in-memory Hub, and hands contributions to package state for atomic publication. The first output of each plugin run is an authoritative replacement; later outputs use explicit assertion deltas with periodic complete checkpoints. Everything after publication (outbox, reasoning, findings) is outside this package.
Shared collections and replay-then-live delivery ¶
A collection is keyed by (source ID, collection name) and is owned by exactly one publishing plugin per source; NewManager rejects duplicate publishers and consumers with no same-source publisher. Several consumers share one collection instead of opening duplicate provider watches. A new subscriber first receives the current items in key order, each marked Initial, then the last OperationSync marker if one was published, and then every later change in publish order on the same channel. Consumers can therefore treat the sync marker as "my cache now equals the source's coherent view".
A slow subscriber never blocks the publisher and is not disconnected. Once its buffer is full, the hub coalesces its pending changes to the latest per key plus the newest sync marker, the same information a fresh replay would carry, and delivers them as it catches up.
Source scoping ¶
Manager gives each plugin instance a runtime scoped to its plugin ID and configured source ID. Publish, MarkReady, ReplaceContribution, and ContributionGeneration reject any other provenance, and Subscribe only sees collections of the same source, so two instances of one plugin cannot overwrite or consume each other's observations.
Supervision ¶
Manager.Run restarts a failed plugin instance with exponential backoff and leaves the others running. Before a restart it republishes the instance's last healthy contributions with degraded health, and after it the runtime removes collection items the new instance did not republish (see RuntimeService.MarkReady).
Readiness, publication, and health ¶
Collection readiness (Runtime.MarkReady) means a source's cache is coherent. Contribution publication (Runtime.ReplaceContribution) is a durable graph write with its own Ready flag and SourceHealth. Plugins submit complete desired contribution state; the runtime may persist only the assertion delta from the last accepted output. These are separate states: a collection can be ready while its consumer has not yet published, and a contribution can stay published with degraded or stale health after its source fails.
Generations ¶
A contribution generation must increase across publications and process restarts. Plugins call Runtime.ContributionGeneration once at startup to recover the highest durable generation for their (plugin, source) and publish from the next value. Package state rejects older generations and treats a same-generation, same-input retry as idempotent.
See https://agent-shield.dev/docs/plugins/contract/ for authoring guidance and https://agent-shield.dev/docs/architecture/publication-and-storage/ for what publication does.
Index ¶
- func RegisterIdentitySchemes(registry *graph.Registry, descriptors ...Descriptor) error
- func RegisterPluginFlags(flags *pflag.FlagSet, pluginID string, register func(*PluginFlags)) error
- func ResolveIdentityReference(reference string, resolvers ...IdentityReferenceResolver) (graph.IdentityClaim, bool, error)
- type Change
- type ContributionOutput
- type Descriptor
- type Hub
- type IdentityReferenceResolver
- type Manager
- type Operation
- type Plugin
- type PluginFlags
- type PluginInstance
- type RemediationProvider
- type Runtime
- type RuntimeConfig
- type RuntimeService
- func (r *RuntimeService) ContributionGeneration(ctx context.Context, pluginID, sourceID string) (uint64, error)
- func (r *RuntimeService) MarkReady(ctx context.Context, pluginID, sourceID, collection string, generation uint64) error
- func (r *RuntimeService) Publish(ctx context.Context, change Change) error
- func (r *RuntimeService) ReplaceContribution(ctx context.Context, pluginID, sourceID string, output ContributionOutput) error
- func (r *RuntimeService) RollupTarget() telemetry.RollupTarget
- func (r *RuntimeService) Subscribe(ctx context.Context, collection string) (<-chan Change, error)
- type TelemetryMappingProvider
- type TelemetryReceiver
- type TelemetryReceiverProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterIdentitySchemes ¶
func RegisterIdentitySchemes(registry *graph.Registry, descriptors ...Descriptor) error
RegisterIdentitySchemes registers every descriptor's identity schemes. It must run before the graph compiler is constructed; a scheme declared by two plugins fails startup instead of silently sharing authority.
func RegisterPluginFlags ¶
func RegisterPluginFlags(flags *pflag.FlagSet, pluginID string, register func(*PluginFlags)) error
RegisterPluginFlags runs register with a namespace-bound flag registrar. It rejects invalid plugin IDs and any collision with a flag already present.
func ResolveIdentityReference ¶
func ResolveIdentityReference(reference string, resolvers ...IdentityReferenceResolver) (graph.IdentityClaim, bool, error)
ResolveIdentityReference asks every resolver. Matches that agree are accepted; two resolvers returning different claims is an error rather than a first-wins choice.
Types ¶
type Change ¶
type Change struct {
EventID string `json:"eventId"`
PluginID string `json:"pluginId"`
SourceID string `json:"sourceId"`
Collection string `json:"collection"`
Key string `json:"key"`
Revision string `json:"revision,omitempty"`
Generation uint64 `json:"generation"`
Operation Operation `json:"operation"`
ObservedAt time.Time `json:"observedAt"`
Initial bool `json:"initial,omitempty"`
Payload json.RawMessage `json:"payload,omitempty"`
}
Change is one replayable item in a plugin-owned observation collection; OperationSync marks the boundary after its current-state replay is coherent.
type ContributionOutput ¶
type ContributionOutput struct {
Name string
Generation uint64
Input graph.Input
SourceObservedAt time.Time
Ready bool
SourceHealth string
}
ContributionOutput is one complete current plugin-owned graph contribution. The runtime publishes an authoritative replacement after startup and at checkpoints, and explicit assertion deltas between them. Its readiness and health are independent of collection readiness.
type Descriptor ¶
type Descriptor struct {
ID string
// Version is the plugin's release version, required and otherwise
// informational. It is not persisted and is not part of contribution
// identity, input digests, or assertions, so changing it republishes
// nothing. In-tree plugins start at 0.1.0 while the project is pre-1.0;
// bump it when the plugin's collections, identity schemes, or emitted
// assertions change in a way its consumers should notice.
Version string
Description string
Consumes []string
Publishes []string
// IdentitySchemes lists authority-specific schemes this plugin introduces.
// Leave it empty when the plugin only emits claims under existing schemes.
// Follow-up: this could become an optional IdentitySchemeProvider
// capability, like TelemetryMappingProvider, so the descriptor stays
// limited to collection contracts.
IdentitySchemes []graph.SchemeDefinition
}
Descriptor declares a plugin's collection contracts and any identity schemes whose authority it owns; it does not describe graph output ownership.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub is the in-memory fan-out for observation collections. It keeps only current state, not history, and is safe for concurrent use. One mutex serializes Publish and the replay half of Subscribe, which is what makes replay-then-live ordering gap-free.
func NewHub ¶
func NewHub() *Hub
NewHub returns a hub with no collections. Each subscriber gets subscriberBuffer slots of live headroom, and the hub logs to slog.Default.
func (*Hub) Publish ¶
Publish applies change to the collection's current state and delivers it to every live subscriber without blocking. A subscriber whose buffer is full receives the change later through its coalesced backlog; see Hub.Subscribe.
func (*Hub) Subscribe ¶
Subscribe returns a channel that first replays the collection's current items in key order and its last sync marker, all marked Initial, and then carries live changes. Subscribing before the publisher starts is allowed; the replay is simply empty. The channel closes only when ctx ends.
A subscriber that falls more than the live buffer behind is not disconnected. Its pending changes are coalesced to the latest change per key and the newest sync marker, and delivered as it catches up. It may skip intermediate versions of a key and older sync markers, as a fresh replay would, but every sync marker it receives is preceded by exactly the state the collection had when that marker was published, and its cache converges to the collection's current state, including deletes.
type IdentityReferenceResolver ¶
type IdentityReferenceResolver interface {
ResolveIdentityReference(string) (graph.IdentityClaim, bool, error)
}
IdentityReferenceResolver is an optional capability that maps a provider reference found in another plugin's data, such as a Kubernetes Node spec.providerID, to an identity claim in a scheme the plugin owns. This lets plugins join on authoritative IDs instead of names or tags.
func IdentityReferenceResolvers ¶
func IdentityReferenceResolvers(plugins ...Plugin) []IdentityReferenceResolver
IdentityReferenceResolvers returns the plugins that implement IdentityReferenceResolver, in input order.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager validates and runs a fixed set of plugin instances. It owns the collection topology check and the remediation provider registry.
func NewManager ¶
func NewManager(runtime *RuntimeService, plugins ...Plugin) (*Manager, error)
NewManager validates the plugin set: every plugin needs an ID, version, and stable source ID; each (plugin, source) appears once; each (source, collection) has one publisher; and every consumed collection has a publisher on the same source. Plugins are sorted so startup order is deterministic. Remediation capabilities are registered separately from discovery.
func (*Manager) Remediations ¶
func (m *Manager) Remediations() *remediation.Registry
Remediations returns the providers extracted from plugins that implement RemediationProvider.
func (*Manager) Run ¶
Run starts every plugin instance concurrently and blocks until ctx ends.
Each instance is supervised on its own: when its Run returns an error or panics while ctx is live, the manager logs the failure, republishes the instance's last stored healthy contributions with degraded source health (their assertions stay active rather than being retracted), and restarts it after an exponential backoff. Other instances keep running. A restarted instance rebuilds its caches; see RuntimeService.MarkReady for how items it no longer publishes are removed. An instance whose Run returns nil while ctx is live has finished and is not restarted; if every instance finishes, Run reports an error, because discovery is expected to run for the life of the process. Cancellation of ctx returns nil unless it carries a non-cancellation cause.
type Plugin ¶
type Plugin interface {
Descriptor() Descriptor
Run(context.Context, Runtime) error
}
Plugin is a discovery plugin. Run blocks until ctx ends or the plugin fails. Manager restarts a failed instance with backoff and leaves the plugins managed alongside it running; see Manager.Run.
type PluginFlags ¶
type PluginFlags struct {
// contains filtered or unexported fields
}
PluginFlags registers flags in a plugin-owned namespace. Plugins receive only this wrapper, so every registered name must be prefixed with the plugin's ID.
func (*PluginFlags) BoolVar ¶
func (flags *PluginFlags) BoolVar(target *bool, name string, value bool, usage string)
BoolVar adds a boolean flag below the plugin namespace.
func (*PluginFlags) StringVar ¶
func (flags *PluginFlags) StringVar(target *string, name, value, usage string)
StringVar adds a string flag below the plugin namespace.
type PluginInstance ¶
type PluginInstance interface {
SourceID() string
}
PluginInstance exposes the stable source identity configured by the host. Manager requires it and scopes all runtime access to this identity.
type RemediationProvider ¶
type RemediationProvider interface {
remediation.Provider
}
RemediationProvider is an optional capability extracted independently from a plugin's discovery lifecycle and publication contracts.
type Runtime ¶
type Runtime interface {
// Publish records a change as a native event and delivers it to the
// source's collection subscribers.
Publish(context.Context, Change) error
// MarkReady publishes the sync marker for (plugin, source, collection) at
// the given generation, signalling that the collection is coherent.
MarkReady(context.Context, string, string, string, uint64) error
// Subscribe replays the current collection and then streams live changes.
// The channel closes when ctx ends. A subscriber that falls behind
// receives coalesced changes instead of every intermediate one.
Subscribe(context.Context, string) (<-chan Change, error)
// ReplaceContribution publishes one complete current contribution for
// (plugin, source). The runtime chooses a delta or authoritative checkpoint.
ReplaceContribution(context.Context, string, string, ContributionOutput) error
// ContributionGeneration returns the highest durable generation across
// all contributions of (plugin, source), or zero if none exist.
ContributionGeneration(context.Context, string, string) (uint64, error)
}
Runtime keeps observation collection delivery separate from durable graph contribution replacement, even when one plugin participates in both.
type RuntimeConfig ¶
RuntimeConfig controls authoritative contribution checkpoint frequency.
type RuntimeService ¶
type RuntimeService struct {
// contains filtered or unexported fields
}
RuntimeService is the unscoped host runtime shared by all plugins. Plugins never see it directly; Manager wraps it in a per-instance scoped runtime.
func NewRuntime ¶
func NewRuntime(store *state.Store, config RuntimeConfig) (*RuntimeService, error)
NewRuntime returns a runtime backed by store with a fresh in-memory hub.
func (*RuntimeService) ContributionGeneration ¶
func (r *RuntimeService) ContributionGeneration(ctx context.Context, pluginID, sourceID string) (uint64, error)
ContributionGeneration returns the highest durable generation for (plugin, source) so a restarted plugin resumes above it.
func (*RuntimeService) MarkReady ¶
func (r *RuntimeService) MarkReady(ctx context.Context, pluginID, sourceID, collection string, generation uint64) error
MarkReady publishes an in-memory sync marker. It is not persisted: after a restart the source must rebuild its cache and mark the collection ready again.
After the manager restarts a plugin instance, the first MarkReady of each of its collections first deletes the items the new instance did not republish, so objects removed while it was down do not linger in consumers' caches. The delete's event ID is the item's last event ID with its ":upsert" suffix replaced by ":delete", which is the ID the Kubernetes and AWS plugins give their own delete of that revision; an ID without that suffix falls back to <plugin>:<collection>:<key>:<revision>:delete.
func (*RuntimeService) Publish ¶
func (r *RuntimeService) Publish(ctx context.Context, change Change) error
Publish records a durable receipt before delivering change. A change that fails to persist is never delivered, so every observation a projector cites as evidence has durable provenance metadata and a content digest. Provider payloads remain in the in-memory collection path.
func (*RuntimeService) ReplaceContribution ¶
func (r *RuntimeService) ReplaceContribution(ctx context.Context, pluginID, sourceID string, output ContributionOutput) error
ReplaceContribution publishes output as the complete current contribution for (plugin, source, output.Name). A failure is logged here because some plugins only degrade their health after one instead of stopping.
func (*RuntimeService) RollupTarget ¶
func (r *RuntimeService) RollupTarget() telemetry.RollupTarget
RollupTarget returns the telemetry.RollupTarget that publishes each telemetry rollup as a ready, healthy contribution and then marks the rollup collection ready at the same generation.
type TelemetryMappingProvider ¶
TelemetryMappingProvider is an optional plugin capability for translating source-specific OTLP log records into normalized telemetry events.
type TelemetryReceiver ¶
TelemetryReceiver is an HTTP route owned by a plugin. The host mounts the route, while the plugin owns its authentication, validation, and mapping.
type TelemetryReceiverProvider ¶
type TelemetryReceiverProvider interface {
TelemetryReceivers(telemetry.EventIngestor) ([]TelemetryReceiver, error)
}
TelemetryReceiverProvider lets a plugin register native telemetry transports with the host's shared telemetry pipeline.