completion

package
v0.1.0-rc.1 Latest Latest
Warning

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

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

Documentation

Overview

Package completion defines the completion-gate extension contract (design §6, R8). Gates observe a bounded buffered canonical event slice for one attempt and return a typed outcome; core enforces buffer limits and fail-open behavior on errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LastEventKind

func LastEventKind(events []lipapi.Event) lipapi.EventKind

LastEventKind returns the Kind of the last event, or empty string if none.

Types

type BufferLimits

type BufferLimits struct {
	// MaxEvents is the maximum number of canonical stream events retained; exceeding fails open to live passthrough.
	MaxEvents int
}

BufferLimits bounds memory retained while completion gating buffers before first output (R8). Zero value applies DefaultBufferLimits.

func DefaultBufferLimits

func DefaultBufferLimits() BufferLimits

DefaultBufferLimits returns conservative defaults for production composition roots.

func (BufferLimits) OverCapacity

func (l BufferLimits) OverCapacity(events int) bool

OverCapacity reports whether len(events) exceeds MaxEvents after normalization.

type Buffered

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

Buffered is an immutable view of canonical events passed to a gate (defensive copy).

func NewBuffered

func NewBuffered(events []lipapi.Event) Buffered

NewBuffered returns a view backed by a copy of events.

func (Buffered) Event

func (b Buffered) Event(i int) (lipapi.Event, bool)

Event returns event i and ok false when out of range.

func (Buffered) Events

func (b Buffered) Events() []lipapi.Event

Events returns a defensive copy for handlers that need a mutable slice.

func (Buffered) Len

func (b Buffered) Len() int

Len returns the number of events.

type Gate

type Gate interface {
	ID() string
	Order() int
	FailureMode() sdkhooks.FailureMode
	Handle(ctx context.Context, meta Meta, buf Buffered, svc Services) (Outcome, error)
}

Gate performs whole-completion control after bounded buffering (R8, design §6).

func MaterializeSorted

func MaterializeSorted(gates []Gate) []Gate

MaterializeSorted returns a copy of gates sorted for stable execution (design §17).

type Meta

type Meta struct {
	TraceID    string
	ALegID     string
	BLegID     string
	AttemptSeq int

	Scope     scope.PrincipalScopeView
	Session   session.SessionView
	Workspace workspace.WorkspaceView
}

Meta carries attempt-scoped identifiers and safe decision context for completion gates (no transport types). Scope is the authoritative principal/scope attribution; Session and Workspace provide the lifecycle context needed for completion-gate decision evidence (requirement 2.1, 2.6). Existing identifiers are preserved; a zero Scope preserves local/anonymous identity semantics.

type Outcome

type Outcome struct {
	Kind OutcomeKind
	// Events is the replacement stream when Kind == OutcomeReplace.
	Events []lipapi.Event
	// Err is required when Kind == OutcomeReject.
	Err error
}

Outcome is the result of one gate invocation.

func PassOriginalOutcome

func PassOriginalOutcome() Outcome

PassOriginalOutcome returns OutcomePassOriginal.

func RejectOutcome

func RejectOutcome(err error) Outcome

RejectOutcome builds an OutcomeReject.

func ReplaceOutcome

func ReplaceOutcome(events []lipapi.Event) Outcome

ReplaceOutcome builds an OutcomeReplace. Events must be non-empty; callers should end with EventResponseFinished.

func ReplayOriginalOutcome

func ReplayOriginalOutcome() Outcome

ReplayOriginalOutcome returns OutcomeReplayOriginal.

func (Outcome) Validate

func (o Outcome) Validate() error

Validate checks invariants for the outcome kind.

type OutcomeKind

type OutcomeKind int

OutcomeKind is the typed gate decision (design §6).

const (
	// OutcomePassOriginal leaves the current buffered completion unchanged for downstream gates / emit.
	OutcomePassOriginal OutcomeKind = iota
	// OutcomeReplace substitutes the completion with Events (must end with EventResponseFinished when stream completed).
	OutcomeReplace
	// OutcomeReplayOriginal resets the working buffer to the original completion snapshot (design §17 incomplete replay).
	OutcomeReplayOriginal
	// OutcomeReject fails the response path with Err (surfaced like hook rejection).
	OutcomeReject
)

type Services

type Services struct {
	State state.Store
	Aux   auxiliary.Client
}

Services exposes narrow capabilities for completion gates (design §2, §6).

Jump to

Keyboard shortcuts

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