context

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeSnapshot

func DecodeSnapshot(data []byte) (map[string]string, error)

DecodeSnapshot deserializes a snapshot from JSON.

Types

type Change

type Change struct {
	Key     string
	Type    ChangeType
	Content string
}

Change describes a context source that changed between reconciliations.

type ChangeType

type ChangeType int

ChangeType describes the kind of change.

const (
	ChangeAdded ChangeType = iota
	ChangeUpdated
	ChangeRemoved
)

type ContextSource

type ContextSource interface {
	// Key returns a stable identifier for this source (e.g., "core/instructions").
	Key() string

	// Load fetches the current value of this source.
	Load(ctx context.Context) (string, error)

	// Render formats the value for inclusion in the system prompt.
	Render(value string) string

	// RenderUpdate formats a change notification when the value changes.
	RenderUpdate(oldValue, newValue string) string

	// RenderRemoval formats a notification when the source becomes unavailable.
	RenderRemoval(value string) string
}

ContextSource provides a named piece of context that can change over time. Sources are evaluated before each LLM call and changes are emitted as mid-conversation system messages.

type DateTimeSource

type DateTimeSource struct{}

DateTimeSource provides the current date and time.

func (DateTimeSource) Key

func (DateTimeSource) Key() string

func (DateTimeSource) Load

func (DateTimeSource) Render

func (DateTimeSource) Render(value string) string

func (DateTimeSource) RenderRemoval

func (DateTimeSource) RenderRemoval(_ string) string

func (DateTimeSource) RenderUpdate

func (DateTimeSource) RenderUpdate(_, newVal string) string

type EnvironmentSource

type EnvironmentSource struct {
	WorkDir string
}

EnvironmentSource provides working directory, platform, and shell info.

func (EnvironmentSource) Key

func (EnvironmentSource) Key() string

func (EnvironmentSource) Load

func (EnvironmentSource) Render

func (EnvironmentSource) Render(value string) string

func (EnvironmentSource) RenderRemoval

func (EnvironmentSource) RenderRemoval(_ string) string

func (EnvironmentSource) RenderUpdate

func (EnvironmentSource) RenderUpdate(_, newVal string) string

type GitSource

type GitSource struct {
	WorkDir string
}

GitSource provides the current branch and last commit.

func (GitSource) Key

func (GitSource) Key() string

func (GitSource) Load

func (g GitSource) Load(_ context.Context) (string, error)

func (GitSource) Render

func (GitSource) Render(value string) string

func (GitSource) RenderRemoval

func (GitSource) RenderRemoval(_ string) string

func (GitSource) RenderUpdate

func (GitSource) RenderUpdate(_, newVal string) string

type InstructionsSource

type InstructionsSource struct {
	ProjectRoot string
	WorkDir     string
}

InstructionsSource discovers and renders AGENTS.md files.

func (InstructionsSource) Key

func (InstructionsSource) Key() string

func (InstructionsSource) Load

func (InstructionsSource) Render

func (InstructionsSource) Render(value string) string

func (InstructionsSource) RenderRemoval

func (InstructionsSource) RenderRemoval(_ string) string

func (InstructionsSource) RenderUpdate

func (InstructionsSource) RenderUpdate(_, newVal string) string

type Registry

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

Registry manages an ordered set of ContextSources and detects changes between reconciliation calls.

func NewRegistry

func NewRegistry(sources ...ContextSource) *Registry

NewRegistry creates a Registry with the given sources.

func (*Registry) Add

func (r *Registry) Add(source ContextSource)

Add registers a new context source.

func (*Registry) LoadAll

func (r *Registry) LoadAll(ctx context.Context) map[string]string

LoadAll loads all sources concurrently and returns a snapshot map.

func (*Registry) Reconcile

func (r *Registry) Reconcile(ctx context.Context, previous map[string]string) []Change

Reconcile compares the current snapshot against a previous one and returns the list of changes. Sources are evaluated in key-sorted order for deterministic output.

type Snapshot

type Snapshot struct {
	State map[string]string `json:"state"`
}

Snapshot holds a JSON-encoded state map for change detection.

func NewSnapshot

func NewSnapshot(state map[string]string) *Snapshot

NewSnapshot creates a Snapshot from a state map.

func (*Snapshot) Encode

func (s *Snapshot) Encode() ([]byte, error)

Encode serializes the snapshot to JSON.

Jump to

Keyboard shortcuts

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