ledger

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT 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.

README

Native ledger binding

cengine/ledger binds lib/ledger through cengine/library. Bind accepts an explicitly loaded library; BindInterface accepts an explicit ABI driver. CreatePrivateVolume, InspectPrivateVolume and RemovePrivateVolume use the ledger's native private-directory operations; there is no Go filesystem fallback. Library.OpenStore opens a C store, NewGraph opens its recorder, and NativeStore.OpenWatch provides typed change observation.

cengine/ledger/supervisor.OpenNative binds the C supervisor. Shared records, errors and interfaces come from engine/ledger; observation wire records come from engine/ledger/observation. Consumers own host selection. ObserveRequirements collects through C; an explicit shell search path is passed to C without mutating process PATH.

CTX and execution-graph publication use this binding. It never silently falls back to the Go store. Existing native users of engine/ledger must update their import to cengine/ledger; memory storage is opened through Library.OpenStore(ctx, "memory", "", options).

Driver coverage is explicit:

Driver Ledger support
purego Bind loads the native shared library.
cgo cgoengine/ledger.Bind, built with ext_ledger_cgo and the fetched C headers and library.
c2go c2goengine/ledger.Bind, generated from the C portable profile with ext_ledger_c2go; memory/file stores, watches, recorder projections and fingerprints on 64-bit Linux/macOS.
go Removed; use a C driver. Shared record types live in engine/ledger.

BindInterface accepts a described ABI supplied by a driver; it does not create a missing driver or substitute another implementation. Platform collector and supervisor support is determined by the loaded C library.

The translated profile returns unsupported for native collection, machine environments and process supervision. Windows translation is unavailable; Bind returns driver.ErrUnavailable on targets without that driver. Use the native purego or cgo library for those platform operations. Run bash scripts/ledger-c2go.sh from the repository to regenerate and validate the profile; generated translations are not committed.

See the consumer-shaped example for a standalone Go consumer of the ledger binding.

Documentation

Overview

Package ledger binds the canonical C ledger through its described library interface. Store and recorder operations execute in C; Go retains wire types.

Shared contracts are defined in engine/ledger; aliases preserve type identity.

Shared contracts are defined in engine/ledger; aliases preserve type identity.

Index

Constants

View Source
const DefaultMaxChangeBytes = shared.DefaultMaxChangeBytes
View Source
const DefaultMaxChanges = shared.DefaultMaxChanges
View Source
const DefaultMaxRecordBytes = shared.DefaultMaxRecordBytes
View Source
const DefaultMaxResults = shared.DefaultMaxResults
View Source
const DefaultMaxSnapshotRecords = shared.DefaultMaxSnapshotRecords
View Source
const DefaultMaxTransactionRecords = shared.DefaultMaxTransactionRecords
View Source
const MaxStringBytes = shared.MaxStringBytes
View Source
const Namespace = shared.Namespace

Variables

View Source
var (
	ErrUnsafeVolumePath = errors.New("unsafe private volume path")
	ErrStaleVolume      = errors.New("private volume identity changed")
	ErrVolumeLimit      = errors.New("private volume limit exceeded")
	ErrInvalidVolume    = errors.New("invalid private volume")
)
View Source
var Code = shared.Code
View Source
var ErrBusy = shared.ErrBusy
View Source
var ErrClosed = shared.ErrClosed
View Source
var ErrConflict = shared.ErrConflict
View Source
var ErrCursorExpired = shared.ErrCursorExpired
View Source
var ErrDanglingEdge = shared.ErrDanglingEdge
View Source
var ErrIdempotency = shared.ErrIdempotency
View Source
var ErrIncidentEdges = shared.ErrIncidentEdges
View Source
var ErrInvalid = shared.ErrInvalid
View Source
var ErrInvalidName = shared.ErrInvalidName
View Source
var ErrLimitRequired = shared.ErrLimitRequired
View Source
var ErrNotFound = shared.ErrNotFound
View Source
var ErrNotRegistered = shared.ErrNotRegistered
View Source
var ErrSchemaMismatch = shared.ErrSchemaMismatch
View Source
var ErrSchemaViolation = shared.ErrSchemaViolation
View Source
var ErrSecretValue = shared.ErrSecretValue
View Source
var ErrTooLarge = shared.ErrTooLarge
View Source
var ErrUnsupported = shared.ErrUnsupported
View Source
var SafeOrigin = shared.SafeOrigin

Functions

This section is empty.

Types

type AdapterObservation

type AdapterObservation = shared.AdapterObservation

type AliasObservation

type AliasObservation = shared.AliasObservation

type Change

type Change = shared.Change

type Commit

type Commit = shared.Commit

type ContextCandidate

type ContextCandidate = shared.ContextCandidate

type ContextObservation

type ContextObservation = shared.ContextObservation

type ContextProgram

type ContextProgram = shared.ContextProgram

type Edge

type Edge = shared.Edge

type EdgeQuery

type EdgeQuery = shared.EdgeQuery

type EdgeRef

type EdgeRef = shared.EdgeRef

type FilesystemRequirement

type FilesystemRequirement = shared.FilesystemRequirement

type Graph

type Graph struct {
	Store *NativeStore
	// contains filtered or unexported fields
}

func NewGraph

func NewGraph(ctx context.Context, s *NativeStore) (*Graph, error)

NewGraph opens a C recorder on a C store. The graph owns the store on success.

func (*Graph) CheckHostAccess

func (g *Graph) CheckHostAccess(ctx context.Context, path, what string) error

func (*Graph) Close

func (g *Graph) Close() error

func (*Graph) Collect

func (g *Graph) Collect(ctx context.Context, what string, options map[string]any, out any) error

func (*Graph) FilesystemAt

func (g *Graph) FilesystemAt(ctx context.Context, path string) (wire.FilesystemInfo, error)

func (*Graph) InspectProcess

func (g *Graph) InspectProcess(ctx context.Context, pid int, opts wire.ProcessOptions) (out wire.ProcessSnapshot, err error)

func (*Graph) ObserveHost

func (g *Graph) ObserveHost(ctx context.Context, in HostInventory) error

func (*Graph) ObserveInventory

func (g *Graph) ObserveInventory(ctx context.Context, adapters []AdapterObservation, aliases []AliasObservation, installers ...InstallerObservation) error

func (*Graph) ObserveProcesses

func (g *Graph) ObserveProcesses(ctx context.Context, in wire.ProcessSnapshot) error

func (*Graph) ObserveRequirements

func (g *Graph) ObserveRequirements(ctx context.Context, r OperationRequirements) (HostSnapshot, error)

ObserveRequirements refreshes requested observations through C; consumers select and validate resources.

func (*Graph) ObserveShell

func (g *Graph) ObserveShell(ctx context.Context, cwd, profile string, selections map[string]string) error

func (*Graph) ObserveWeb

func (g *Graph) ObserveWeb(ctx context.Context, provider, profile, scheme, host string) error

func (*Graph) ReadHost

func (g *Graph) ReadHost(ctx context.Context) (out HostSnapshot, err error)

func (*Graph) Record

func (g *Graph) Record(ctx context.Context, op string, input, out any) error

func (*Graph) ResolveInventory

func (g *Graph) ResolveInventory(ctx context.Context, runtime string) (out Inventory, err error)

func (*Graph) ScanHost

func (g *Graph) ScanHost(ctx context.Context) (out HostInventory, err error)

func (*Graph) ScanProcesses

func (g *Graph) ScanProcesses(ctx context.Context, opts wire.ProcessOptions) (out wire.ProcessSnapshot, err error)

type HostCandidates

type HostCandidates = shared.HostCandidates

type HostInventory

type HostInventory = shared.HostInventory

type HostRequirementError

type HostRequirementError = shared.HostRequirementError

type HostSnapshot

type HostSnapshot = shared.HostSnapshot

type InstallerObservation

type InstallerObservation = shared.InstallerObservation

type Inventory

type Inventory = shared.Inventory

type Library

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

func Bind

func Bind(native *library.Library) (*Library, error)

Bind binds an explicitly supplied native library. Loading and installation policy belong to the application; the binding never falls back to a Go engine.

func BindInterface

func BindInterface(api *library.Interface) (*Library, error)

BindInterface accepts the canonical described ABI from any explicit driver.

func (*Library) CanonicalTransaction

func (l *Library) CanonicalTransaction(ctx context.Context, tx Transaction) (json.RawMessage, string, error)

CanonicalTransaction asks C for the canonical JSON and its idempotency fingerprint.

func (*Library) CheckHostAccess

func (l *Library) CheckHostAccess(ctx context.Context, path, what string) error

CheckHostAccess checks execute or directory-write access without a probe file.

func (*Library) Collect

func (l *Library) Collect(ctx context.Context, what string, options map[string]any, out any) error

func (*Library) CreatePrivateVolume

func (l *Library) CreatePrivateVolume(ctx context.Context, path string, limits PrivateVolumeLimits) (PrivateVolume, error)

CreatePrivateVolume creates and inspects a caller-selected private directory. Ledger never chooses the path or authorizes its removal.

func (*Library) FilesystemAt

func (l *Library) FilesystemAt(ctx context.Context, path string) (wire.FilesystemInfo, error)

FilesystemAt asks the C ledger for the mount containing one existing path.

func (*Library) InspectPrivateVolume

func (l *Library) InspectPrivateVolume(ctx context.Context, path string, limits PrivateVolumeLimits) (PrivateVolume, error)

InspectPrivateVolume validates a private directory and measures its contents.

func (*Library) InspectProgram

func (l *Library) InspectProgram(ctx context.Context, name, path string) (Program, error)

InspectProgram checks one caller-declared executable path without running it.

func (*Library) InspectService

func (l *Library) InspectService(ctx context.Context, definition ServiceDefinition, directory string) (ServiceInspection, error)

InspectService checks the installed definition against the expected content.

func (*Library) Objects

func (l *Library) Objects() *library.Described

Objects exposes the complete described C API, including watches and supervisors, without requiring a separate hand-maintained wrapper per method.

func (*Library) OpenStore

func (l *Library) OpenStore(ctx context.Context, backend, path string, options Options) (*NativeStore, error)

func (*Library) ProcessStart

func (l *Library) ProcessStart(ctx context.Context, pid int) (string, error)

ProcessStart reads the OS birth token for a PID so an action can reject a process generation different from the one it observed.

func (*Library) PublishService

func (l *Library) PublishService(ctx context.Context, definition ServiceDefinition, directory string) (ServiceInspection, error)

PublishService writes the definition without replacing an existing file.

func (*Library) RemovePrivateVolume

func (l *Library) RemovePrivateVolume(ctx context.Context, volume PrivateVolume, limits PrivateVolumeLimits) error

RemovePrivateVolume reopens and remeasures the exact inspected directory before removing it. The caller remains responsible for authorization.

func (*Library) RemoveService

func (l *Library) RemoveService(ctx context.Context, definition ServiceDefinition, directory string) (ServiceInspection, error)

RemoveService removes the definition only while its content still matches.

func (*Library) RenderService

func (l *Library) RenderService(ctx context.Context, platform string, spec ServiceSpec) (ServiceDefinition, error)

RenderService produces a platform definition without invoking a manager.

func (*Library) ScanPrograms

func (l *Library) ScanPrograms(ctx context.Context, names []string, searchPath string) ([]Program, error)

ScanPrograms asks the C ledger to discover named executables on searchPath.

func (*Library) ValidateAttributes

func (l *Library) ValidateAttributes(ctx context.Context, attributes map[string]any) error

ValidateAttributes applies the C ledger's graph metadata rules without writing a record.

type NativeStore

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

func (*NativeStore) Apply

func (s *NativeStore) Apply(ctx context.Context, tx Transaction) (out Commit, err error)

func (*NativeStore) Changes

func (s *NativeStore) Changes(ctx context.Context, ns string, after uint64, limit int) (out []Change, err error)

func (*NativeStore) Close

func (s *NativeStore) Close() error

func (*NativeStore) GetEdge

func (s *NativeStore) GetEdge(ctx context.Context, ns, id string) (out Edge, err error)

func (*NativeStore) GetVertex

func (s *NativeStore) GetVertex(ctx context.Context, ns, id string) (out Vertex, err error)

func (*NativeStore) OpenChild

func (s *NativeStore) OpenChild(ctx context.Context, kind string, config map[string]any) (*library.Object, error)

OpenChild opens a described object owned by this store. Close the child before closing the store; C enforces that lifetime even for concurrent callers.

func (*NativeStore) OpenWatch

func (s *NativeStore) OpenWatch(ctx context.Context, namespace string, after uint64, buffer int) (*NativeWatch, error)

func (*NativeStore) Peers

func (s *NativeStore) Peers(ctx context.Context) (out []Vertex, err error)

Peers returns the live provider registrations in the shared ledger.

func (*NativeStore) PublishPeer

func (s *NativeStore) PublishPeer(ctx context.Context, id string, registration any, lease time.Duration) error

PublishPeer creates or renews an immutable registration for a session.

func (*NativeStore) QueryEdges

func (s *NativeStore) QueryEdges(ctx context.Context, q EdgeQuery) (out []Edge, err error)

func (*NativeStore) QueryVertices

func (s *NativeStore) QueryVertices(ctx context.Context, q VertexQuery) (out []Vertex, err error)

func (*NativeStore) Reconcile

func (s *NativeStore) Reconcile(ctx context.Context, desired Snapshot) (out Commit, err error)

Reconcile replaces the complete desired namespace at its observed revision.

func (*NativeStore) Register

func (s *NativeStore) Register(ctx context.Context, schema Schema) error

func (*NativeStore) Snapshot

func (s *NativeStore) Snapshot(ctx context.Context, ns string) (out Snapshot, err error)

func (*NativeStore) Traverse

func (s *NativeStore) Traverse(ctx context.Context, namespace, start string, maxDepth, maxVertices int) (out []Path, err error)

func (*NativeStore) Watch

func (s *NativeStore) Watch(ctx context.Context, namespace string, after uint64, buffer int) (<-chan Change, error)

Watch preserves the compatibility channel API. OpenWatch exposes terminal error details; Store.Close terminates these compatibility channels.

func (*NativeStore) WithdrawPeer

func (s *NativeStore) WithdrawPeer(ctx context.Context, id string) error

WithdrawPeer removes a provider's registration for this session.

type NativeWatch

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

NativeWatch retains terminal errors explicitly, unlike the compatibility channel API. Next and Close are safe to call concurrently.

func (*NativeWatch) Close

func (w *NativeWatch) Close() error

func (*NativeWatch) Next

func (w *NativeWatch) Next(ctx context.Context) (Change, error)

type OperationRequirements

type OperationRequirements = shared.OperationRequirements

type Options

type Options = shared.Options

type Path

type Path = shared.Path

type PreparedHost

type PreparedHost = shared.PreparedHost

type PrivateVolume

type PrivateVolume struct {
	Path     string `json:"path"`
	Identity string `json:"identity"`
	Created  bool   `json:"created"`
	Entries  int    `json:"entries"`
	Bytes    int64  `json:"bytes"`
	// contains filtered or unexported fields
}

PrivateVolume is the result of a ledger inspection. Only a value returned by CreatePrivateVolume or InspectPrivateVolume can be removed through Go.

type PrivateVolumeLimits

type PrivateVolumeLimits struct {
	MaxEntries int   `json:"max_entries"`
	MaxBytes   int64 `json:"max_bytes"`
	MaxDepth   int   `json:"max_depth"`
}

PrivateVolumeLimits bounds native inspection and removal. Zero selects the ledger's default (10,000 entries, 1 GiB and 32 path components).

type Program

type Program struct {
	Name     string `json:"name"`
	Path     string `json:"path"`
	RealPath string `json:"realpath"`
	Source   string `json:"source"`
	OnPath   bool   `json:"on_path"`
}

Program is a named executable observed on a caller-supplied PATH. The ledger checks and resolves it without running it; selection remains with the caller.

type Provenance

type Provenance = shared.Provenance

type RelationObservation

type RelationObservation = shared.RelationObservation

type Relationship

type Relationship = shared.Relationship

type ResourceObservation

type ResourceObservation = shared.ResourceObservation

type Schema

type Schema = shared.Schema

type ServiceDefinition

type ServiceDefinition struct {
	Platform string `json:"platform"`
	Identity string `json:"identity"`
	FileName string `json:"file_name"`
	Content  string `json:"content"`
	Digest   string `json:"digest"`
}

type ServiceInspection

type ServiceInspection struct {
	Path      string `json:"path"`
	Installed bool   `json:"installed"`
	Matches   bool   `json:"matches"`
	Created   bool   `json:"created"`
	Existing  bool   `json:"existing"`
	Digest    string `json:"digest,omitempty"`
}

ServiceInspection reports the state of a rendered definition in one caller-selected directory. Created and Existing describe a publish attempt.

type ServiceSpec

type ServiceSpec struct {
	Name             string            `json:"name"`
	Description      string            `json:"description,omitempty"`
	Executable       string            `json:"executable"`
	Arguments        []string          `json:"arguments,omitempty"`
	Environment      map[string]string `json:"environment,omitempty"`
	WorkingDirectory string            `json:"working_directory,omitempty"`
	Restart          string            `json:"restart,omitempty"`
	RestartSeconds   int               `json:"restart_seconds,omitempty"`
	UserID           string            `json:"user_id,omitempty"`
}

ServiceSpec describes a caller-selected per-user OS service. The C ledger validates and renders it; a platform adapter registers the definition with its native manager.

type ShellRequirement

type ShellRequirement = shared.ShellRequirement

type Snapshot

type Snapshot = shared.Snapshot

type Store

type Store = shared.Store

type Transaction

type Transaction = shared.Transaction

type Vertex

type Vertex = shared.Vertex

type VertexQuery

type VertexQuery = shared.VertexQuery

type VertexRef

type VertexRef = shared.VertexRef

type WebviewRequirement

type WebviewRequirement = shared.WebviewRequirement

type WebviewValidator

type WebviewValidator = shared.WebviewValidator

Directories

Path Synopsis
Shared contracts are defined in core; aliases preserve type identity.
Shared contracts are defined in core; aliases preserve type identity.

Jump to

Keyboard shortcuts

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