framework

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package framework contains the small cross-surface contracts used to compose HumanLLM and HumanAgent without hiding resource ownership.

Index

Constants

This section is empty.

Variables

View Source
var ErrContractMismatch = errors.New("framework contract mismatch")

ErrContractMismatch means a port cannot satisfy a core requirement. It is a construction-time error, never a signal to silently downgrade at runtime.

View Source
var ErrResourceReleased = errors.New("framework resource is released")

ErrResourceReleased is returned when a composition attempts to consume an owned Resource after its release callback has started. Borrowed resources are never released by Resource.

Functions

func FaultInfo

func FaultInfo(err error) (FaultCode, RetryMode, bool)

FaultInfo returns a stable classification from err.

func NewFault

func NewFault(code FaultCode, retry RetryMode, message string, cause error) error

NewFault validates and constructs a classified fault.

Types

type Contract

type Contract struct {
	ID       ContractID
	Major    uint16
	Minor    uint16
	Features map[Feature]uint16
}

Contract is a port's immutable protocol description. Atomicity and other base correctness requirements belong to the major contract itself; Features describe optional additions, never permissions.

func Negotiate

func Negotiate(provided Contract, required Requirements) (Contract, error)

Negotiate verifies the contract once during construction and returns an independent frozen copy. Major versions must match exactly; providers may have a newer minor or feature revision.

type ContractID

type ContractID string

type Fault

type Fault struct {
	Code    FaultCode
	Retry   RetryMode
	Message string
	Cause   error
}

Fault carries a stable code and retry disposition while retaining the original error for errors.Is/errors.As. Message is safe for the embedding application; adapters must not expose Cause text unless their policy allows it.

func (*Fault) Error

func (fault *Fault) Error() string

func (*Fault) Unwrap

func (fault *Fault) Unwrap() error

type FaultCode

type FaultCode string

FaultCode is a transport-neutral classification. Adapters map it to their wire protocol without parsing error text.

const (
	CodeInvalid         FaultCode = "invalid"
	CodeUnauthenticated FaultCode = "unauthenticated"
	CodeForbidden       FaultCode = "forbidden"
	CodeNotFound        FaultCode = "not_found"
	CodeConflict        FaultCode = "conflict"
	CodeStale           FaultCode = "stale"
	CodeUnavailable     FaultCode = "unavailable"
	CodeIndeterminate   FaultCode = "indeterminate"
	CodeCorrupt         FaultCode = "corrupt"
	CodeClosed          FaultCode = "closed"
)

type Feature

type Feature string

type ReleaseFunc

type ReleaseFunc func(context.Context) error

ReleaseFunc closes a resource that was explicitly transferred to a Human composition. The context bounds shutdown; implementations should make the operation idempotent because a constructor-failure cleanup and normal shutdown may race.

type Requirements

type Requirements struct {
	ID           ContractID
	Major        uint16
	MinimumMinor uint16
	Features     map[Feature]uint16
}

Requirements declares what a consumer needs from one port.

type Resource

type Resource[T any] struct {
	// contains filtered or unexported fields
}

Resource pairs a dependency with an explicit ownership decision. Borrowed dependencies remain owned by the caller. Owned dependencies are released at most once, including when Resource values are copied.

A Resource is a composition value, not a lease. Calling Release on an owned Resource permanently releases that composition's dependency; Value then returns ErrResourceReleased. The zero Resource is borrowed and contains the zero value of T, which consuming constructors normally reject.

func Borrow

func Borrow[T any](value T) Resource[T]

Borrow declares that value remains caller-owned. Release is a no-op.

func Own

func Own[T any](value T, release ReleaseFunc) (Resource[T], error)

Own transfers value and its explicit release callback to the receiving composition. Own rejects a nil callback rather than guessing ownership from whether value happens to implement io.Closer.

func (Resource[T]) Owned

func (resource Resource[T]) Owned() bool

Owned reports whether this composition must release the dependency.

func (Resource[T]) Release

func (resource Resource[T]) Release(ctx context.Context) error

Release invokes an owned dependency's callback at most once. Concurrent callers observe the same result. It never closes a borrowed dependency.

func (Resource[T]) Value

func (resource Resource[T]) Value() (T, error)

Value returns the dependency while it has not begun release. Borrowed values are always returned. Consumers should call Value during construction and retain the returned dependency only while they own the Resource lifecycle.

type RetryMode

type RetryMode string

RetryMode tells an adapter which class of retry is safe. It never grants authorization and does not override a domain-specific idempotency contract.

const (
	RetryNever      RetryMode = "never"
	RetryExactInput RetryMode = "exact_input"
	RetryBackoff    RetryMode = "backoff"
	RetryReconcile  RetryMode = "reconcile"
)

type Runtime

type Runtime interface {
	// Done closes after shutdown has stopped background work and released every
	// explicitly owned resource.
	Done() <-chan struct{}
	// Err returns the terminal runtime error after Done closes. A clean explicit
	// shutdown returns nil.
	Err() error
	// Shutdown stops admission, drains accepted work where the concrete runtime
	// contract requires it, and releases owned dependencies in reverse order.
	// It must be safe for concurrent and repeated calls.
	Shutdown(context.Context) error
}

Runtime is the common lifecycle exposed by active Human compositions. Constructor contexts only bound initialization and recovery; after a successful constructor returns, Shutdown owns the runtime lifetime.

Jump to

Keyboard shortcuts

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