object

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 11 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 object defines the vx object model: trees, manifests and changesets.

A tree is one directory: a sorted list of named entries, each pointing to a blob (file content) or another tree. Trees are stored in the blob store, so identical directories are stored once and two snapshots can be compared by skipping every subtree whose hash did not change.

Index

Constants

View Source
const CurrentVersion = 1

CurrentVersion is the changeset encoding version.

Variables

View Source
var ErrBadPath = errors.New("invalid path")

ErrBadPath is returned for paths or names vx cannot store.

Functions

func ApplyChanges

func ApplyChanges(ctx context.Context, s blob.Store, root hash.Hash, changes []Change) (hash.Hash, error)

ApplyChanges returns the tree that results from applying changes to root. Only the directories on the changed paths are read and rewritten, so the cost depends on the size of the change, not of the repository. Directories left empty are removed. Adds and modifies set the file; deletes remove it.

func ChangeIDFrom

func ChangeIDFrom(b []byte) string

ChangeIDFrom derives a change ID from bytes, such as a git commit hash, so importing the same commit twice gives the same change ID.

func ChangedDirs

func ChangedDirs(changes []Change) []string

ChangedDirs returns the set of directories touched by changes, useful for display ("internal/http").

func EmptyTree

func EmptyTree(ctx context.Context, s blob.Store) (hash.Hash, error)

EmptyTree returns the hash of the empty tree, storing it if needed.

func HasPrefixPath

func HasPrefixPath(path, dir string) bool

HasPrefixPath reports whether path is dir or inside dir.

func NewChangeID

func NewChangeID() string

NewChangeID returns a fresh random change ID.

func NewObjects

func NewObjects(ctx context.Context, s blob.Store, a, b hash.Hash) (trees, blobs []hash.Hash, err error)

NewObjects lists the trees and blobs reachable from tree b that are not reachable through the same path in tree a. These are the objects a client must upload when the server already has a. Subtrees with equal hashes are skipped, so the cost depends on the size of the change.

func PutTree

func PutTree(ctx context.Context, s blob.Store, t *Tree) (hash.Hash, error)

PutTree stores a tree and returns its hash.

func SplitPath

func SplitPath(p string) ([]string, error)

SplitPath validates a slash-separated relative path and splits it.

func ValidChangeID

func ValidChangeID(s string) bool

ValidChangeID reports whether s has the change ID format.

func ValidName

func ValidName(name string) error

ValidName reports whether name can be a single tree entry name.

func WriteManifest

func WriteManifest(ctx context.Context, s blob.Store, m Manifest) (hash.Hash, error)

WriteManifest stores the trees for m and returns the root tree hash. File contents must already be in the store; WriteManifest only writes trees.

Types

type Author

type Author struct {
	Principal  string `json:"principal,omitempty"`    // e.g. "agent:alice/claude-backend"
	Name       string `json:"name,omitempty"`         // display name for git
	Email      string `json:"email,omitempty"`        // email for git
	OnBehalfOf string `json:"on_behalf_of,omitempty"` // e.g. "user:alice"
	Model      string `json:"model,omitempty"`
	Session    string `json:"session,omitempty"`
}

Author records who made a change and, for agents, on whose behalf.

type Change

type Change struct {
	Path string
	Op   Op
	Old  File // zero for OpAdd
	New  File // zero for OpDelete
}

Change is one file that differs between two snapshots.

func DiffManifests

func DiffManifests(a, b Manifest) []Change

DiffManifests lists file changes from a to b.

func DiffTrees

func DiffTrees(ctx context.Context, s blob.Store, a, b hash.Hash) ([]Change, error)

DiffTrees lists file changes from tree a to tree b. Subtrees with equal hashes are skipped without being read, so the cost is proportional to the size of the change, not the size of the repository.

type Changeset

type Changeset struct {
	Version   int         `json:"v"`
	ChangeID  string      `json:"change_id"`
	Parents   []hash.Hash `json:"parents,omitempty"`
	Tree      hash.Hash   `json:"tree"`
	Origin    Origin      `json:"origin"`
	GitSHA    string      `json:"git_sha,omitempty"`
	Author    Author      `json:"author"`
	Intent    string      `json:"intent"`
	DependsOn []string    `json:"depends_on,omitempty"`
	Evidence  *Evidence   `json:"evidence,omitempty"`
	CreatedAt time.Time   `json:"created_at"`
	// SnapshotTree is the tree the author actually had, set when the server
	// merged it onto newer work so Tree differs. Evidence describes this
	// tree, not Tree.
	SnapshotTree hash.Hash `json:"snapshot_tree,omitempty"`
	// Rebase is set on a change that a rebase of its effort replayed onto a
	// newer base. Tree is the replayed tree; the evidence still describes
	// the tree of the change it was replayed from.
	Rebase *Rebase `json:"rebase,omitempty"`
}

Changeset is one change: a snapshot (tree) on top of its parents, with the intent and provenance that git has no place for. Its hash covers every field, so provenance cannot be altered after the fact.

func DecodeChangeset

func DecodeChangeset(data []byte) (*Changeset, error)

DecodeChangeset parses canonical changeset bytes.

func (*Changeset) Encode

func (c *Changeset) Encode() ([]byte, error)

Encode returns the canonical bytes that the hash covers.

func (*Changeset) FirstParent

func (c *Changeset) FirstParent() hash.Hash

FirstParent returns the first parent or Zero.

func (*Changeset) Hash

func (c *Changeset) Hash() (hash.Hash, error)

Hash returns the changeset's hash.

func (*Changeset) Merged

func (c *Changeset) Merged() bool

Merged reports whether the server merged the author's snapshot onto newer work, so the evidence was gathered on a different tree than the one landed.

func (*Changeset) Normalize

func (c *Changeset) Normalize()

Normalize applies the same normalization as Encode, so a changeset read back from the database hashes to the same value.

func (*Changeset) Rebased added in v0.2.0

func (c *Changeset) Rebased() bool

Rebased reports whether a rebase replayed this change onto a newer base, so its evidence was gathered before the rebase.

func (*Changeset) RebasedOnto added in v0.2.0

func (c *Changeset) RebasedOnto() string

RebasedOnto names the target a rebased change sits on: the git commit when known, the changeset hash otherwise. Empty when not rebased.

func (*Changeset) Title

func (c *Changeset) Title() string

Title returns the first line of the intent.

func (*Changeset) Validate

func (c *Changeset) Validate() error

Validate checks the changeset is well formed.

type Check

type Check struct {
	Name   string `json:"name"`
	Result string `json:"result"` // "pass" or "fail"
	Passed int    `json:"passed,omitempty"`
	Failed int    `json:"failed,omitempty"`
	// RanByVX is true when vx ran the command itself (vx land --run),
	// false when the author reported the result (vx land --check).
	RanByVX    bool  `json:"ran_by_vx,omitempty"`
	DurationMs int64 `json:"duration_ms,omitempty"`
	// Notes qualify the result, e.g. how many Go test packages came from
	// the test cache instead of running.
	Notes string `json:"notes,omitempty"`
}

Check is one piece of evidence: a command that was run and its result.

type Entry

type Entry struct {
	Name string
	Mode Mode
	Hash hash.Hash
}

Entry is one item in a tree.

func Lookup

func Lookup(ctx context.Context, s blob.Store, root hash.Hash, path string) (Entry, bool, error)

Lookup walks root to the entry at path ("a/b/c.go").

type Evidence

type Evidence struct {
	Checks   []Check  `json:"checks,omitempty"`
	NewTests []string `json:"new_tests,omitempty"`
}

Evidence is what an author offers as proof that a change works.

func (Evidence) IsEmpty

func (e Evidence) IsEmpty() bool

IsEmpty reports whether there is no evidence.

type File

type File struct {
	Hash hash.Hash
	Mode Mode // ModeFile, ModeExec or ModeSymlink
}

File is a file's content hash and mode.

type Manifest

type Manifest map[string]File

Manifest is a flat view of a snapshot: every file path and its content.

func ReadManifest

func ReadManifest(ctx context.Context, s blob.Store, root hash.Hash) (Manifest, error)

ReadManifest flattens the tree at root into a manifest.

func (Manifest) Apply

func (m Manifest) Apply(changes []Change) Manifest

Apply returns m with changes applied.

func (Manifest) Clone

func (m Manifest) Clone() Manifest

Clone returns a copy of the manifest.

func (Manifest) Paths

func (m Manifest) Paths() []string

Paths returns the manifest's paths in sorted order.

type Mode

type Mode byte

Mode is the type of a tree entry.

const (
	ModeFile    Mode = 'f' // regular file
	ModeExec    Mode = 'x' // executable file
	ModeSymlink Mode = 'l' // symbolic link, content is the target
	ModeDir     Mode = 'd' // subdirectory, hash is a tree
)

func ParseMode

func ParseMode(s string) (Mode, error)

ParseMode is the inverse of Mode.String.

func (Mode) String

func (m Mode) String() string

String returns a readable name for the mode.

type Op

type Op string

Op is the kind of a file change.

const (
	OpAdd    Op = "add"
	OpModify Op = "modify"
	OpDelete Op = "delete"
)

type Origin

type Origin string

Origin says where a changeset came from.

const (
	OriginVX       Origin = "vx"       // landed by an agent or person in vx
	OriginUpstream Origin = "upstream" // imported from the git provider
)

type Rebase added in v0.2.0

type Rebase struct {
	Onto       hash.Hash `json:"onto"`                   // target changeset the effort was rebased onto
	OntoGitSHA string    `json:"onto_git_sha,omitempty"` // its git commit, when it came from upstream
	Branch     string    `json:"branch,omitempty"`       // the target branch, e.g. "main"
	From       hash.Hash `json:"from"`                   // the changeset this one replays
	By         string    `json:"by,omitempty"`           // principal that ran the rebase
	ResolvedBy string    `json:"resolved_by,omitempty"`  // principal that resolved a conflict on this change during the rebase
	At         time.Time `json:"at"`
}

Rebase records how a change got onto a new base: which target commit the effort was rebased onto, which changeset this one replays, who ran the rebase and, when the replay conflicted, who resolved it.

type Tree

type Tree struct {
	Entries []Entry // sorted by Name
}

Tree is one directory.

func DecodeTree

func DecodeTree(data []byte) (*Tree, error)

DecodeTree parses canonical tree bytes.

func GetTree

func GetTree(ctx context.Context, s blob.Store, h hash.Hash) (*Tree, error)

GetTree loads a tree. The zero hash is the empty tree.

func (*Tree) Encode

func (t *Tree) Encode() ([]byte, error)

Encode returns the canonical bytes of the tree. Entries must be sorted and unique; Encode checks this so a malformed tree is never stored.

func (*Tree) Find

func (t *Tree) Find(name string) (Entry, bool)

Find returns the entry with name, if present.

Jump to

Keyboard shortcuts

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