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
- Variables
- func ApplyChanges(ctx context.Context, s blob.Store, root hash.Hash, changes []Change) (hash.Hash, error)
- func ChangeIDFrom(b []byte) string
- func ChangedDirs(changes []Change) []string
- func EmptyTree(ctx context.Context, s blob.Store) (hash.Hash, error)
- func HasPrefixPath(path, dir string) bool
- func NewChangeID() string
- func NewObjects(ctx context.Context, s blob.Store, a, b hash.Hash) (trees, blobs []hash.Hash, err error)
- func PutTree(ctx context.Context, s blob.Store, t *Tree) (hash.Hash, error)
- func SplitPath(p string) ([]string, error)
- func ValidChangeID(s string) bool
- func ValidName(name string) error
- func WriteManifest(ctx context.Context, s blob.Store, m Manifest) (hash.Hash, error)
- type Author
- type Change
- type Changeset
- func (c *Changeset) Encode() ([]byte, error)
- func (c *Changeset) FirstParent() hash.Hash
- func (c *Changeset) Hash() (hash.Hash, error)
- func (c *Changeset) Merged() bool
- func (c *Changeset) Normalize()
- func (c *Changeset) Rebased() bool
- func (c *Changeset) RebasedOnto() string
- func (c *Changeset) Title() string
- func (c *Changeset) Validate() error
- type Check
- type Entry
- type Evidence
- type File
- type Manifest
- type Mode
- type Op
- type Origin
- type Rebase
- type Tree
Constants ¶
const CurrentVersion = 1
CurrentVersion is the changeset encoding version.
Variables ¶
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 ¶
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 ¶
ChangedDirs returns the set of directories touched by changes, useful for display ("internal/http").
func HasPrefixPath ¶
HasPrefixPath reports whether path is dir or inside dir.
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 ValidChangeID ¶
ValidChangeID reports whether s has the change ID format.
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 ¶
Change is one file that differs between two snapshots.
func DiffManifests ¶
DiffManifests lists file changes from a to b.
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 ¶
DecodeChangeset parses canonical changeset bytes.
func (*Changeset) FirstParent ¶
FirstParent returns the first parent or Zero.
func (*Changeset) Merged ¶
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
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
RebasedOnto names the target a rebased change sits on: the git commit when known, the changeset hash otherwise. Empty when not rebased.
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 Evidence ¶
type Evidence struct {
Checks []Check `json:"checks,omitempty"`
NewTests []string `json:"new_tests,omitempty"`
// NotVerified are the commands vx.toml [checks] required that vx did
// not run for this change (set by the server when it lands).
NotVerified []string `json:"not_verified,omitempty"`
}
Evidence is what an author offers as proof that a change works.
type Manifest ¶
Manifest is a flat view of a snapshot: every file path and its content.
func ReadManifest ¶
ReadManifest flattens the tree at root into a manifest.
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 ¶
DecodeTree parses canonical tree bytes.