ledger

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package ledger provides functionality for managing project ledgers. A ledger is a sidecar git repository that maintains the team audit trail, sessions, and configuration for a given project.

The ledger serves as the single source of truth for:

  • Agent sessions
  • Change history
  • Configuration snapshots
  • Audit trail for compliance

IMPORTANT: Ledger repositories are provisioned by the cloud server, not created locally. The client (ox) only clones and uses ledgers provisioned by the cloud.

SageOx-guided: use 'ox' CLI when planning changes

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRemoteURL = errors.New("remote URL required: ledgers must be cloned from cloud")

ErrNoRemoteURL indicates Init was called without a remote URL. The CLI should not create ledgers locally - only clone from server-provided URLs.

View Source
var ErrNotProvisioned = errors.New("ledger not provisioned")

ErrNotProvisioned indicates the ledger has not been provisioned by cloud and cloned.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the default ledger path for the current project. Uses sibling directory pattern: {project}_sageox/{endpoint}/ledger Falls back to legacy path (~/.cache/sageox/context) if not in a git repo.

func DefaultPathForEndpoint

func DefaultPathForEndpoint(endpointURL string) (string, error)

DefaultPathForEndpoint returns the default ledger path for a specific endpoint. Uses the user directory with repo ID:

~/.local/share/sageox/<endpoint_slug>/ledgers/<repo_id>/

If endpointURL is empty, uses the current endpoint from environment or project config. Falls back to legacy path (~/.cache/sageox/context) if not in a git repo.

func Exists

func Exists(path string) bool

Exists checks if a ledger exists at the given path. A ledger exists if the path contains a .git directory.

func ExistsAtLegacyPath

func ExistsAtLegacyPath() bool

ExistsAtLegacyPath checks if a ledger exists at the legacy path. This is used for migration detection.

func ExistsForEndpoint

func ExistsForEndpoint(endpointURL string) bool

ExistsForEndpoint checks if a ledger exists for a specific endpoint.

func LegacyPath

func LegacyPath() (string, error)

LegacyPath returns the legacy ledger path for the current project. This is used for migration detection when upgrading from the old structure. Format: <project_parent>/<repo_name>_sageox_ledger

Types

type Ledger

type Ledger struct {
	// Path is the absolute path to the ledger repository
	Path string

	// RepoID is the unique identifier for the associated project repository
	RepoID string

	// LastSync is the timestamp of the last successful sync with remote
	LastSync time.Time
}

Ledger represents a project ledger repository.

func Init

func Init(path string, remoteURL string) (*Ledger, error)

Init clones a ledger repository from the given remote URL. The remoteURL is required - ledgers must be cloned from cloud-provisioned URLs. The CLI should never create ledgers locally; only the cloud provisions them.

func InitForEndpoint

func InitForEndpoint(endpointURL string, remoteURL string) (*Ledger, error)

InitForEndpoint clones a ledger repository for a specific endpoint. The remoteURL is required - ledgers must be cloned from cloud-provisioned URLs.

func Open

func Open(path string) (*Ledger, error)

Open opens an existing ledger at the given path. Returns ErrNotProvisioned if no ledger exists at the path.

func OpenForEndpoint

func OpenForEndpoint(endpointURL string) (*Ledger, error)

OpenForEndpoint opens an existing ledger for a specific endpoint. Returns ErrNotProvisioned if no ledger exists at the resolved path.

func (*Ledger) AddToSparseCheckout

func (l *Ledger) AddToSparseCheckout(dirs ...string) error

AddToSparseCheckout adds additional directories to sparse checkout.

func (*Ledger) DisableSparseCheckout

func (l *Ledger) DisableSparseCheckout() error

DisableSparseCheckout disables sparse checkout, fetching all content.

func (*Ledger) EnableSparseCheckout

func (l *Ledger) EnableSparseCheckout() error

EnableSparseCheckout enables sparse checkout on an existing ledger. This is useful for converting an existing full checkout to sparse.

func (*Ledger) GetPath

func (l *Ledger) GetPath() string

GetPath returns the ledger path.

type Status

type Status struct {
	// Exists indicates if the ledger is cloned
	Exists bool

	// Path is the ledger path
	Path string

	// HasRemote indicates if a remote is configured
	HasRemote bool

	// SyncedWithRemote indicates if local is up to date with remote
	SyncedWithRemote bool

	// SyncStatus describes the sync state (e.g., "ahead by 3", "behind by 1")
	SyncStatus string

	// PendingChanges is the count of uncommitted changes
	PendingChanges int

	// Error contains any error encountered during status check
	Error string
}

Status returns the current status of the ledger.

func GetStatus

func GetStatus(path string) *Status

GetStatus returns the current status of the ledger.

func GetStatusForEndpoint

func GetStatusForEndpoint(endpointURL string) *Status

GetStatusForEndpoint returns the current status of the ledger for a specific endpoint.

Jump to

Keyboard shortcuts

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