contextengine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contextengine provides stable-keyed, revisioned context assembly. Storage and user presentation are host responsibilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Digest

func Digest(snapshot Snapshot) string

Types

type Class

type Class string
const (
	ClassPolicy     Class = "policy"
	ClassRequest    Class = "request"
	ClassHistory    Class = "history"
	ClassToolResult Class = "tool_result"
	ClassMemory     Class = "memory"
	ClassRuntime    Class = "runtime"
)

type Engine

type Engine struct {
	Registry      *Registry
	MaxFrameBytes int
	Spill         SpillStore
}

func (Engine) Reconcile

func (e Engine) Reconcile(ctx context.Context, previous Snapshot, workspaceID string) (Snapshot, []Update, error)

Reconcile produces one deterministic chronological update batch. Prior admitted state is retained when an existing source is temporarily unavailable; a missing initial source fails explicitly.

type Frame

type Frame struct {
	SourceKey string `json:"source_key"`
	Revision  string `json:"revision"`
	Class     Class  `json:"class"`
	Trust     Trust  `json:"trust"`
	Content   string `json:"content"`
	SpillRef  string `json:"spill_ref,omitempty"`
}

Frame is one model-visible context contribution.

type Lifecycle

type Lifecycle struct {
	Engine Engine
	Store  SnapshotStore
}

func (Lifecycle) BeginTurn

func (l Lifecycle) BeginTurn(ctx context.Context, owner execution.Identity, id, workspaceID string) (Turn, error)

func (Lifecycle) Commit

func (l Lifecycle) Commit(ctx context.Context, turn Turn) (SnapshotRecord, error)

func (Lifecycle) Rebaseline

func (l Lifecycle) Rebaseline(ctx context.Context, owner execution.Identity, id string, expected uint64) (SnapshotRecord, error)

type MemorySnapshotStore

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

func NewMemorySnapshotStore

func NewMemorySnapshotStore() *MemorySnapshotStore

func (*MemorySnapshotStore) CompareAndSwap

func (s *MemorySnapshotStore) CompareAndSwap(ctx context.Context, owner execution.Identity, id string, expected uint64, snapshot Snapshot) (SnapshotRecord, error)

func (*MemorySnapshotStore) Create

func (*MemorySnapshotStore) Get

type OutputManager

type OutputManager struct {
	MaxBytes int
	Spill    SpillStore
}

OutputManager applies one bound and spill policy to all provider and tool output before it is admitted into context.

func (OutputManager) Bound

func (m OutputManager) Bound(ctx context.Context, sourceKey, revision string, class Class, trust Trust, content string) (Frame, error)

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Register

func (r *Registry) Register(source Source) error

type RetrievalQuery

type RetrievalQuery struct {
	Text         string   `json:"text"`
	Limit        int      `json:"limit"`
	AccessScopes []string `json:"access_scopes"`
}

RetrievalQuery is host-authored search input. Access scopes are authority, not model-provided filters, and must be enforced again by the retriever.

type RetrievalResult

type RetrievalResult struct {
	DocumentID  string    `json:"document_id"`
	ChunkID     string    `json:"chunk_id"`
	Revision    string    `json:"revision"`
	Provenance  string    `json:"provenance"`
	Content     string    `json:"content"`
	Score       float64   `json:"score"`
	FreshAt     time.Time `json:"fresh_at"`
	AccessScope string    `json:"access_scope"`
	Tombstoned  bool      `json:"tombstoned,omitempty"`
}

type RetrievalSource

type RetrievalSource struct {
	SourceKey string
	Query     RetrievalQuery
	Retriever Retriever
}

RetrievalSource adapts a retriever into the ordinary context lifecycle so search results receive the same revision, spill, and reconciliation rules.

func (RetrievalSource) Key

func (s RetrievalSource) Key() string

func (RetrievalSource) Resolve

func (s RetrievalSource) Resolve(ctx context.Context) ([]Frame, error)

func (RetrievalSource) Revision

func (s RetrievalSource) Revision(ctx context.Context) (string, error)

type Retriever

type Retriever interface {
	Revision(context.Context, RetrievalQuery) (string, error)
	Search(context.Context, RetrievalQuery) ([]RetrievalResult, error)
}

Retriever supplies a stable revision and provenance-bearing results. The host owns indexing, deletion propagation, and authorization enforcement.

type Snapshot

type Snapshot struct {
	Epoch       uint64                 `json:"epoch"`
	WorkspaceID string                 `json:"workspace_id,omitempty"`
	Sources     map[string]SourceState `json:"sources"`
}

Snapshot is the admitted context baseline for one epoch.

func Rebaseline

func Rebaseline(snapshot Snapshot) Snapshot

Rebaseline begins a new epoch after compaction or another destructive projection change while preserving the current admitted sources.

type SnapshotRecord

type SnapshotRecord struct {
	ID        string             `json:"id"`
	Identity  execution.Identity `json:"identity"`
	Snapshot  Snapshot           `json:"snapshot"`
	Digest    string             `json:"digest"`
	Revision  uint64             `json:"revision"`
	UpdatedAt time.Time          `json:"updated_at"`
}

SnapshotRecord is the durable context head for one owner/session.

type Source

type Source interface {
	Key() string
	Revision(context.Context) (string, error)
	Resolve(context.Context) ([]Frame, error)
}

Source is a stable-keyed context contributor.

type SourceState

type SourceState struct {
	Revision string  `json:"revision"`
	Frames   []Frame `json:"frames"`
}

type SpillStore

type SpillStore interface {
	Put(context.Context, string, string) (string, error)
}

SpillStore stores complete oversized frame content and returns an opaque managed reference.

type Trust

type Trust string
const (
	TrustAuthoritative Trust = "authoritative"
	TrustUntrusted     Trust = "untrusted"
)

type Turn

type Turn struct {
	Record  SnapshotRecord
	Next    Snapshot
	Updates []Update
}

Turn pins the exact context head observed before provider inference.

type Update

type Update struct {
	Kind      UpdateKind `json:"kind"`
	SourceKey string     `json:"source_key"`
	Revision  string     `json:"revision,omitempty"`
	Error     string     `json:"error,omitempty"`
}

type UpdateKind

type UpdateKind string
const (
	UpdateAdded       UpdateKind = "added"
	UpdateChanged     UpdateKind = "changed"
	UpdateRemoved     UpdateKind = "removed"
	UpdateUnavailable UpdateKind = "unavailable"
)

Jump to

Keyboard shortcuts

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