ledger

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSourceTextBytes = 64 * 1024

MaxSourceTextBytes bounds one immutable observation before it can poison every later overlap window. It is an operational byte limit, not a semantic confidence or importance score.

View Source
const MaxStableRefBytes = 384

MaxStableRefBytes is the shared PostgreSQL/MySQL acceptance boundary for every persisted identity and idempotency reference. It is a storage interoperability limit, not a semantic weight.

Variables

View Source
var (
	ErrInvalidMemoryDelivery  = errors.New("invalid memory delivery")
	ErrMemoryDeliveryConflict = errors.New("memory delivery key already identifies a different request")
	ErrInvalidOutcomeReport   = errors.New("invalid outcome report")
	ErrOutcomeReportConflict  = errors.New("outcome key already identifies a different request")
)
View Source
var (
	ErrInvalidSourceEvent    = errors.New("invalid source event")
	ErrInvalidEpisodeBinding = errors.New("invalid episode binding")
	ErrSourceEventConflict   = errors.New("source event ref already identifies different immutable input")
	ErrIdempotencyConflict   = errors.New("idempotency key already identifies different request")
	ErrEpisodeSealed         = errors.New("materialized episode only accepts existing links or new outcomes")
)

Functions

func EpisodeRef

func EpisodeRef(scope Scope, runRef, sourceGroupRef string) string

EpisodeRef derives the stable identity of one exact scope/run/source group.

func ValidStableRef

func ValidStableRef(ref string) bool

ValidStableRef reports whether a required reference is safe and identical across every relational adapter.

func Validate

func Validate(event SourceEvent, binding EpisodeBinding) error

Validate deterministically validates one causal intake command without reading or mutating storage.

func ValidateMemoryDelivery

func ValidateMemoryDelivery(delivery MemoryDelivery) error

func ValidateOutcomeReport

func ValidateOutcomeReport(report OutcomeReport) error

Types

type ActorKind

type ActorKind string

ActorKind is trusted provenance supplied after transport authentication.

const (
	ActorKindAgent    ActorKind = "agent"
	ActorKindUser     ActorKind = "user"
	ActorKindSystem   ActorKind = "system"
	ActorKindTool     ActorKind = "tool"
	ActorKindExternal ActorKind = "external"
)

type Constitution

type Constitution struct {
	MemoryRef string
	Text      string
}

Constitution is an immutable external normative snapshot, never writable Memory. The zero value represents an unknown baseline.

type Episode

type Episode struct {
	Ref            string
	Scope          Scope
	RunRef         string
	SourceGroupRef string
	Links          []SourceLink
}

Episode is the deterministic envelope for one stable run/source group. Links are returned in role then source-ref order.

type EpisodeBinding

type EpisodeBinding struct {
	RunRef         string
	SourceGroupRef string
	Role           SourceRole
}

EpisodeBinding requests one typed provenance link in a stable run/source group. An incomplete binding admits the SourceEvent without guessing a boundary and can be retried later with all fields present.

type Ledger

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

Ledger runs after transport request-idempotency. It admits immutable SourceEvents and materializes Episodes once distinct sources provide a situation and an actual agent act. It deliberately contains no semantic or time-based boundary inference.

func New

func New() *Ledger

func (*Ledger) Observe

func (l *Ledger) Observe(event SourceEvent, binding EpisodeBinding) (Episode, bool, error)

Observe admits event, then appends binding when it is complete. Reusing one immutable source with a different binding is a separate relation command, not a retry of the transport request. Complete invalid bindings fail before either the source or relation is mutated.

type MemoryDelivery

type MemoryDelivery struct {
	IdempotencyKey      string
	Scope               Scope
	RunRef              string
	MemoryContextRef    string
	DeliveredMemoryRefs []string
}

MemoryDelivery states only which stable memories a Harness can prove were exposed. It does not claim that the model used them.

type MemoryDeliveryReceipt

type MemoryDeliveryReceipt struct {
	Ref string
}

type ObserveReceipt

type ObserveReceipt struct {
	SourceEventRef string
	EpisodeRef     string
}

ObserveReceipt is the immutable result frozen by one transport idempotency key. EpisodeRef is empty until that request materializes or appends to an already materialized Episode.

type OutcomeReceipt

type OutcomeReceipt struct {
	OutcomeEventRef string
	EpisodeRef      string
}

type OutcomeReport

type OutcomeReport struct {
	IdempotencyKey         string
	Event                  SourceEvent
	RunRef                 string
	SourceGroupRef         string
	DeliveryReceiptRefs    []string
	RelatedSourceEventRefs []string
}

OutcomeReport is an observed source-bound result, never a reinforcement instruction. Delivery attribution remains optional.

type Scope

type Scope struct {
	Kind            ScopeKind
	TenantRef       string
	AgentRef        string
	RelationshipRef string
	SessionRef      string
}

type ScopeKind

type ScopeKind string

Scope is the exact authorization boundary shared by an Episode and all of its SourceEvents. SessionRef may be empty, but when present is part of the exact boundary and Episode identity.

const (
	ScopeKindAgent        ScopeKind = "agent"
	ScopeKindRelationship ScopeKind = "relationship"
)

type SourceEvent

type SourceEvent struct {
	Ref          string
	Scope        Scope
	ActorKind    ActorKind
	ActorRef     string
	Text         string
	Constitution Constitution
}

SourceEvent is an immutable input value within its exact Scope. Episode membership and role are separate relations, not properties of the source.

type SourceLink struct {
	SourceEventRef string
	Role           SourceRole
}

SourceLink is a typed provenance edge from an Episode to a SourceEvent.

type SourceRole

type SourceRole string

SourceRole states how a SourceEvent is linked to an Episode.

const (
	RoleSituation SourceRole = "situation"
	RoleAgentAct  SourceRole = "agent_act"
	RoleOutcome   SourceRole = "outcome"
)

Jump to

Keyboard shortcuts

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