engine

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 12 Imported by: 0 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 engine coordinates shared memory writes across processes. Facts stay authoritative Markdown files; private state lives in a reserved .engine directory beside each scope. Every mutation is one locked transaction.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReadRequired     = errors.New("read_required")
	ErrRevisionConflict = errors.New("revision_conflict")
	ErrBusy             = errors.New("busy")
	ErrConflict         = errors.New("conflict")
	ErrNotFound         = errors.New("fact_not_found")
	ErrReasonRequired   = errors.New("reason_required")
	ErrStaleRequest     = errors.New("stale_request")
)

Stable engine failures. Callers match them with errors.Is.

Functions

This section is empty.

Types

type AppendRequest

type AppendRequest struct {
	RequestID   string
	Name        string
	Description string
	Body        string
	Reason      string
	Scope       Scope
	// Fact carries full fact metadata (type, scene, links, path, origin) for
	// adapters that need more than the default project fact. When set, the
	// engine writes this fact after name resolution instead of building a
	// default one. Callers that omit it keep the original behavior.
	Fact *memory.Fact
}

AppendRequest adds one fact. RequestID makes the append retry-safe.

type AppendResult

type AppendResult struct {
	RequestID string   `json:"requestID"`
	Name      string   `json:"name"`
	Revision  Revision `json:"revision"`
}

AppendResult is the durable outcome of an append.

type Config

type Config struct {
	Store       *memory.Store
	ProjectDir  string
	UserDir     string
	LockTimeout time.Duration
}

Config binds an engine to one project store and one user store.

type CorrectRequest

type CorrectRequest struct {
	RequestID   string
	Name        string
	Expected    Revision
	Description string
	Body        string
	Scope       Scope
}

CorrectRequest replaces a fact body after a preceding read. For user scope, Body is the full desired user memory because user.md is one record.

type Cursor

type Cursor struct {
	HarnessID string `json:"harnessID"`
	SessionID string `json:"sessionID"`
	Position  int64  `json:"position"`
	Phase     string `json:"phase"`
}

Cursor is one session's durable position. Harness and session identity keep concurrent sessions from sharing a marker.

type DeleteRequest

type DeleteRequest struct {
	RequestID string
	Name      string
	Expected  Revision
	Scope     Scope
}

DeleteRequest removes a fact after a preceding read.

type Engine

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

Engine owns transactions and scope locks over a memory store.

func Open

func Open(cfg Config) *Engine

Open binds an engine to the configured directories. Missing values fall back to the store's own paths and a five-second lock timeout.

func (*Engine) AppendFact

func (e *Engine) AppendFact(req AppendRequest) (AppendResult, error)

AppendFact adds one fact. A retry with the same RequestID returns the recorded result without writing again.

func (*Engine) CorrectFact

func (e *Engine) CorrectFact(req CorrectRequest) (FactResult, error)

CorrectFact replaces a fact body. An absent revision returns read_required; a revision that is not current returns revision_conflict. Neither changes stored content.

func (*Engine) DeleteFact

func (e *Engine) DeleteFact(req DeleteRequest) error

DeleteFact removes a fact after a preceding read. It shares the revision preconditions of a correction.

func (*Engine) Read

func (e *Engine) Read(scope Scope, name string) (ReadResult, error)

Read recovers pending work, then reads one record and its revision under the same lock. Recovery runs before the read, so the returned bytes and revision both describe the recovered state.

func (*Engine) ReadRevision

func (e *Engine) ReadRevision(name string) (Revision, error)

ReadRevision returns the revision of the named project fact.

func (*Engine) ReadRevisionForScope

func (e *Engine) ReadRevisionForScope(scope Scope, name string) (Revision, error)

ReadRevisionForScope returns the revision of one record. User scope has one user.md record, so name is ignored. Every read recovers pending work first.

func (*Engine) Recover

func (e *Engine) Recover() error

Recover settles unfinished transactions in both scopes. User scope is locked first because operations that need both scopes keep that order.

func (*Engine) SaveCursor

func (e *Engine) SaveCursor(cursor Cursor) error

SaveCursor writes one session's cursor record. Session records are separate files, so they need no shared lock.

type FactResult

type FactResult struct {
	RequestID string   `json:"requestID"`
	Name      string   `json:"name"`
	Revision  Revision `json:"revision"`
}

FactResult is the durable outcome of a correction.

type ReadResult

type ReadResult struct {
	Name     string
	Content  string
	Revision Revision
	Fact     *memory.Fact
}

ReadResult is one record's bytes and the revision of those same bytes.

type Revision

type Revision string

Revision is an opaque token over a record's normalized path and bytes.

type Scope

type Scope string

Scope selects the shared store a request writes. The zero value means project scope.

const (
	ScopeProject Scope = "project"
	ScopeUser    Scope = "user"
)

Jump to

Keyboard shortcuts

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