component

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package component defines the public bring-up contract for services an embedding repository composes alongside deploy. A component is a value the embedding repository already owns: Core never constructs it, never reads its configuration, and never hands it Core state. Core owns only ordering — every registered component is assembled before the agent harness is constructed, started before the harness starts, and stopped after the harness closes, in the exact reverse of the resolved order.

Index

Constants

View Source
const (
	// MaxNameBytes bounds a component name.
	MaxNameBytes = 64
	// MaxEventBytes bounds an event passed to ICapabilities.Log. Together with
	// MaxNameBytes it keeps the namespaced record "component.<name>.<event>"
	// inside the 128-byte telemetry event field.
	MaxEventBytes = 48
)

Variables

View Source
var (
	// ErrNilOption reports a nil functional option, named by its 1-based
	// position in the option list.
	ErrNilOption = errors.New("component: option is nil")
	// ErrNilDefinition reports a nil definition supplied as a requirement or
	// to Order.
	ErrNilDefinition = errors.New("component: definition is nil")
	// ErrName reports a name outside the accepted grammar or byte bound.
	ErrName = errors.New("component: name must match [a-z][a-z0-9-]* within 64 bytes")
	// ErrMissingAssemble reports a definition constructed without WithAssemble.
	ErrMissingAssemble = errors.New("component: assemble function is required")
	// ErrRequirement reports a self-referential or repeated requirement.
	ErrRequirement = errors.New("component: invalid requirement")
	// ErrDuplicateName reports two definitions sharing one name in one ordered
	// set.
	ErrDuplicateName = errors.New("component: duplicate name")
	// ErrMissingRequirement reports a requirement that is absent from the
	// ordered set, naming both components.
	ErrMissingRequirement = errors.New("component: requirement is not in the ordered set")
	// ErrDependencyCycle reports a cycle, naming the full path it traverses.
	ErrDependencyCycle = errors.New("component: dependency cycle")
)

Functions

This section is empty.

Types

type Definition

type Definition struct {
	// contains filtered or unexported fields
}

Definition is one immutable named unit of bring-up work. It holds no Core state, so a resolved order can be computed without any infrastructure.

func New

func New(name string, options ...Option) (*Definition, error)

New validates the complete option set and returns an immutable definition.

func Order

func Order(definitions ...*Definition) ([]*Definition, error)

Order resolves definitions into a deterministic initialization order using Kahn's algorithm with the ready set processed in registration order, never map iteration order. It is pure: it performs no I/O and invokes no definition function.

func (*Definition) Assemble

func (definition *Definition) Assemble(ctx context.Context, capabilities ICapabilities) error

Assemble runs the required assembly function.

func (*Definition) Name

func (definition *Definition) Name() string

Name reports the registered component name.

func (*Definition) Start

func (definition *Definition) Start(ctx context.Context) error

Start runs the optional start hook, reporting nil when none was declared.

func (*Definition) Stop

func (definition *Definition) Stop(ctx context.Context) error

Stop runs the optional stop hook, reporting nil when none was declared.

type ICapabilities

type ICapabilities interface {
	// Log writes one INFO record through Core's reporter as event
	// "component.<name>.<event>", with message redacted of Core's configured
	// secrets unless the embedding binary opted into raw diagnostics.
	Log(ctx context.Context, event string, message string) error
}

ICapabilities is the only typed Core surface a component receives.

type Option

type Option func(settings *settings) error

Option configures one Definition. New validates the complete option set before returning a definition.

func WithAssemble

func WithAssemble(assemble func(ctx context.Context, capabilities ICapabilities) error) Option

WithAssemble sets the required assembly function. It runs during bootstrap.AssembleCore, before the harness factory is invoked. The component stores what it builds in the embedding repository's own variables; Core injects nothing.

func WithRequires

func WithRequires(requirements ...*Definition) Option

WithRequires declares dependencies by pointer identity; repeatable.

func WithStart

func WithStart(start func(ctx context.Context) error) Option

WithStart sets an optional start hook, run immediately before the harness starts. Its context is Core's lifecycle context, cancelled at shutdown, so goroutines started here are children of the Core lifecycle.

func WithStop

func WithStop(stop func(ctx context.Context) error) Option

WithStop sets an optional stop hook, run in reverse resolved order after the harness closes and before Core's store closes. Stop must be idempotent-safe, must tolerate a component that never started, and must not block indefinitely.

Jump to

Keyboard shortcuts

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