Documentation
¶
Overview ¶
Package store is the Postgres metadata store: principals, repos, branches, efforts, workspaces, changesets and the operation log. File contents and trees live in the blob store; this package holds everything else.
Index ¶
- Constants
- Variables
- func NewID() uuid.UUID
- func Slugify(name string) string
- func ValidateHandle(kind PrincipalKind, handle string) error
- func ValidateRepoName(name string) error
- type Branch
- type ChangesetRow
- type Effort
- type EffortState
- type FileChange
- type GitObject
- type Op
- type Principal
- type PrincipalKind
- type Provider
- type Q
- func (q Q) AdvanceEffort(ctx context.Context, id uuid.UUID, seenVersion int64, newHead hash.Hash) (bool, error)
- func (q Q) Authenticate(ctx context.Context, secret string) (Principal, error)
- func (q Q) Chain(ctx context.Context, repoID uuid.UUID, head, stop hash.Hash, limit int) ([]ChangesetRow, error)
- func (q Q) ChangesetByGitSHA(ctx context.Context, repoID uuid.UUID, sha string) (ChangesetRow, error)
- func (q Q) CreateEffort(ctx context.Context, e Effort) (Effort, error)
- func (q Q) CreatePrincipal(ctx context.Context, p Principal) (Principal, error)
- func (q Q) CreateRepo(ctx context.Context, r Repo) (Repo, error)
- func (q Q) CreateToken(ctx context.Context, principalID uuid.UUID, name string) (string, error)
- func (q Q) CreateWorkspace(ctx context.Context, w Workspace) (Workspace, error)
- func (q Q) EffortByID(ctx context.Context, id uuid.UUID) (Effort, error)
- func (q Q) FileChanges(ctx context.Context, repoID uuid.UUID, h hash.Hash) ([]FileChange, error)
- func (q Q) FinishWorkspace(ctx context.Context, id uuid.UUID, state WorkspaceState, landedAs hash.Hash) error
- func (q Q) GetBranch(ctx context.Context, repoID uuid.UUID, name string) (Branch, error)
- func (q Q) GetChangeset(ctx context.Context, repoID uuid.UUID, h hash.Hash) (ChangesetRow, error)
- func (q Q) GetEffort(ctx context.Context, repoID uuid.UUID, slug string) (Effort, error)
- func (q Q) GetWorkspace(ctx context.Context, id uuid.UUID) (Workspace, error)
- func (q Q) GetWorkspaceForUpdate(ctx context.Context, id uuid.UUID) (Workspace, error)
- func (q Q) GitHashesFor(ctx context.Context, repoID uuid.UUID, vxHashes []hash.Hash) (map[hash.Hash]string, error)
- func (q Q) InsertChangeset(ctx context.Context, repoID uuid.UUID, effortID *uuid.UUID, ...) (hash.Hash, error)
- func (q Q) ListAgents(ctx context.Context, owner uuid.UUID) ([]Principal, error)
- func (q Q) ListBranches(ctx context.Context, repoID uuid.UUID) ([]Branch, error)
- func (q Q) ListEfforts(ctx context.Context, repoID uuid.UUID, state EffortState) ([]Effort, error)
- func (q Q) ListOps(ctx context.Context, repoID uuid.UUID, limit int) ([]Op, error)
- func (q Q) ListRepos(ctx context.Context) ([]Repo, error)
- func (q Q) ListShipments(ctx context.Context, effortID uuid.UUID) ([]Shipment, error)
- func (q Q) ListWorkspaces(ctx context.Context, effortID uuid.UUID, state WorkspaceState) ([]Workspace, error)
- func (q Q) LogOp(ctx context.Context, repoID, actorID *uuid.UUID, op, target string, ...) error
- func (q Q) LookupGitObjects(ctx context.Context, repoID uuid.UUID, gitHashes []string) (map[string]hash.Hash, error)
- func (q Q) OnChain(ctx context.Context, repoID uuid.UUID, head, target hash.Hash, limit int) (bool, error)
- func (q Q) PrincipalByHandle(ctx context.Context, handle string) (Principal, error)
- func (q Q) PrincipalByID(ctx context.Context, id uuid.UUID) (Principal, error)
- func (q Q) RebaseEffort(ctx context.Context, id uuid.UUID, seenVersion int64, ...) (bool, error)
- func (q Q) RepoByID(ctx context.Context, id uuid.UUID) (Repo, error)
- func (q Q) RepoByName(ctx context.Context, name string) (Repo, error)
- func (q Q) ResolveChangeset(ctx context.Context, repoID uuid.UUID, ref string) (ChangesetRow, error)
- func (q Q) SaveGitObjects(ctx context.Context, repoID uuid.UUID, objs []GitObject) error
- func (q Q) SaveShipment(ctx context.Context, s Shipment) (Shipment, error)
- func (q Q) SetEffortState(ctx context.Context, id uuid.UUID, state EffortState) error
- func (q Q) SetWorkspaceBase(ctx context.Context, id uuid.UUID, base hash.Hash) error
- func (q Q) UpsertBranch(ctx context.Context, b Branch) error
- type Repo
- type Shipment
- type ShipmentChange
- type Store
- type Tx
- type Workspace
- type WorkspaceState
Constants ¶
const TokenPrefix = "vxt_"
TokenPrefix starts every vx token, so leaked tokens are easy to spot.
Variables ¶
var ErrExists = errors.New("already exists")
ErrExists is returned when a unique row already exists.
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a row does not exist.
Functions ¶
func ValidateHandle ¶
func ValidateHandle(kind PrincipalKind, handle string) error
ValidateHandle checks a handle: lowercase name, and for agents "owner/name".
func ValidateRepoName ¶
ValidateRepoName checks names like "shop-api" or "acme/shop-api".
Types ¶
type Branch ¶
type Branch struct {
RepoID uuid.UUID
Name string
Head hash.Hash // changeset
GitSHA string
SyncedAt time.Time
}
Branch is an upstream branch that vx follows.
type ChangesetRow ¶
ChangesetRow is a changeset with the metadata vx keeps beside it.
type Effort ¶
type Effort struct {
ID uuid.UUID
RepoID uuid.UUID
Slug string
Name string
Goal string
BaseBranch string
Base hash.Hash // upstream changeset the effort sits on
Head hash.Hash
Version int64
State EffortState
OwnerID uuid.UUID
CreatedAt time.Time
UpdatedAt time.Time
}
Effort is a shared line of work that agents land changes into.
type EffortState ¶
type EffortState string
EffortState is the lifecycle state of an effort.
const ( EffortOpen EffortState = "open" EffortShipping EffortState = "shipping" EffortMerged EffortState = "merged" EffortAbandoned EffortState = "abandoned" )
type FileChange ¶
FileChange is a changed path recorded with a changeset, with line counts.
type Op ¶
type Op struct {
ID int64
RepoID *uuid.UUID
ActorID *uuid.UUID
Op string
Target string
Before json.RawMessage
After json.RawMessage
At time.Time
}
Op is one entry in the operation log.
type Principal ¶
type Principal struct {
ID uuid.UUID
Kind PrincipalKind
Handle string // "alice" or "alice/claude-backend"
ParentID *uuid.UUID
DisplayName string
Email string
CreatedAt time.Time
}
Principal is a human, an agent acting for a human, or a service account.
type PrincipalKind ¶
type PrincipalKind string
PrincipalKind is the type of an identity.
const ( KindHuman PrincipalKind = "human" KindAgent PrincipalKind = "agent" KindService PrincipalKind = "service" )
type Q ¶
type Q struct {
// contains filtered or unexported fields
}
Q holds the query methods. Store and Tx both embed it, so every query can run on its own or inside a transaction.
func (Q) AdvanceEffort ¶
func (q Q) AdvanceEffort(ctx context.Context, id uuid.UUID, seenVersion int64, newHead hash.Hash) (bool, error)
AdvanceEffort moves the effort head with a compare-and-swap on version. It reports false when another writer moved the head first.
func (Q) Authenticate ¶
Authenticate resolves a token to its principal.
func (Q) Chain ¶
func (q Q) Chain(ctx context.Context, repoID uuid.UUID, head, stop hash.Hash, limit int) ([]ChangesetRow, error)
Chain returns changesets from head back along first parents, stopping before stop (exclusive) or after limit rows. Newest first.
func (Q) ChangesetByGitSHA ¶
func (q Q) ChangesetByGitSHA(ctx context.Context, repoID uuid.UUID, sha string) (ChangesetRow, error)
ChangesetByGitSHA finds the changeset imported from a git commit.
func (Q) CreateEffort ¶
CreateEffort inserts an effort with a unique slug derived from its name.
func (Q) CreatePrincipal ¶
CreatePrincipal inserts a principal.
func (Q) CreateRepo ¶
CreateRepo inserts a repo and its upstream.
func (Q) CreateToken ¶
CreateToken issues a new token for a principal and returns the secret. Only its hash is stored, so the secret cannot be shown again.
func (Q) CreateWorkspace ¶
CreateWorkspace inserts an open workspace.
func (Q) EffortByID ¶
EffortByID finds an effort by id.
func (Q) FileChanges ¶
FileChanges returns the recorded file list of a changeset.
func (Q) FinishWorkspace ¶
func (q Q) FinishWorkspace(ctx context.Context, id uuid.UUID, state WorkspaceState, landedAs hash.Hash) error
FinishWorkspace marks a workspace landed (with its changeset) or abandoned.
func (Q) GetChangeset ¶
GetChangeset loads a changeset by hash.
func (Q) GetWorkspace ¶
GetWorkspace loads a workspace.
func (Q) GetWorkspaceForUpdate ¶
GetWorkspaceForUpdate loads a workspace and locks its row until the transaction ends, so two lands of the same workspace cannot race.
func (Q) GitHashesFor ¶
func (q Q) GitHashesFor(ctx context.Context, repoID uuid.UUID, vxHashes []hash.Hash) (map[hash.Hash]string, error)
GitHashesFor returns git hashes for vx objects (the reverse mapping).
func (Q) InsertChangeset ¶
func (q Q) InsertChangeset(ctx context.Context, repoID uuid.UUID, effortID *uuid.UUID, cs *object.Changeset, files []FileChange) (hash.Hash, error)
InsertChangeset stores a changeset and its file list. Inserting the same changeset twice is a no-op, which makes imports safe to repeat.
func (Q) ListAgents ¶
ListAgents returns the agents acting for owner.
func (Q) ListBranches ¶
ListBranches returns the tracked branches of a repo.
func (Q) ListEfforts ¶
ListEfforts lists a repo's efforts, newest first. An empty state lists all.
func (Q) ListShipments ¶
ListShipments returns an effort's shipments with their changes.
func (Q) ListWorkspaces ¶
func (q Q) ListWorkspaces(ctx context.Context, effortID uuid.UUID, state WorkspaceState) ([]Workspace, error)
ListWorkspaces lists an effort's workspaces. An empty state lists all.
func (Q) LogOp ¶
func (q Q) LogOp(ctx context.Context, repoID, actorID *uuid.UUID, op, target string, before, after any) error
LogOp appends to the operation log. before and after are marshaled to JSON.
func (Q) LookupGitObjects ¶
func (q Q) LookupGitObjects(ctx context.Context, repoID uuid.UUID, gitHashes []string) (map[string]hash.Hash, error)
LookupGitObjects returns the vx hashes known for the given git hashes.
func (Q) OnChain ¶
func (q Q) OnChain(ctx context.Context, repoID uuid.UUID, head, target hash.Hash, limit int) (bool, error)
OnChain reports whether target is head or one of its first-parent ancestors, looking back at most limit steps.
func (Q) PrincipalByHandle ¶
PrincipalByHandle looks a principal up by handle.
func (Q) PrincipalByID ¶
PrincipalByID looks a principal up by id.
func (Q) RebaseEffort ¶
func (q Q) RebaseEffort(ctx context.Context, id uuid.UUID, seenVersion int64, newBase, newHead hash.Hash) (bool, error)
RebaseEffort moves the effort onto a new base and head, with the same compare-and-swap as AdvanceEffort.
func (Q) RepoByName ¶
RepoByName looks a repo up by name.
func (Q) ResolveChangeset ¶
func (q Q) ResolveChangeset(ctx context.Context, repoID uuid.UUID, ref string) (ChangesetRow, error)
ResolveChangeset finds a changeset by full hash, hex prefix (at least 6 characters) or change ID.
func (Q) SaveGitObjects ¶
SaveGitObjects records mappings; existing ones are kept.
func (Q) SaveShipment ¶
SaveShipment inserts a shipment or updates the one for the same effort and branch, replacing its change list.
func (Q) SetEffortState ¶
SetEffortState changes the lifecycle state.
func (Q) SetWorkspaceBase ¶
SetWorkspaceBase records the snapshot the workspace's files are based on.
type Repo ¶
type Repo struct {
ID uuid.UUID
Name string
Provider Provider
Remote string
DefaultBranch string
CreatedAt time.Time
}
Repo is a repository known to vx and its upstream.
type Shipment ¶
type Shipment struct {
ID uuid.UUID
EffortID uuid.UUID
Title string
Branch string
Target string
BaseGitSHA string
HeadGitSHA string
ProviderRef string
URL string
State string
CreatedBy uuid.UUID
CreatedAt time.Time
UpdatedAt time.Time
Changes []ShipmentChange
}
Shipment is an effort's changes pushed as a branch, usually with a PR.
type ShipmentChange ¶
ShipmentChange is one changeset in a shipment and the commit made for it.
type Store ¶
type Store struct {
Q
// contains filtered or unexported fields
}
Store is the connection pool plus queries.
type Tx ¶
type Tx struct {
Q
// contains filtered or unexported fields
}
Tx is a transaction plus queries.
type Workspace ¶
type Workspace struct {
ID uuid.UUID
EffortID uuid.UUID
OwnerID uuid.UUID
Intent string
ChangeID string
Base hash.Hash
State WorkspaceState
LandedAs hash.Hash
CreatedAt time.Time
UpdatedAt time.Time
}
Workspace is one task's draft inside an effort.
type WorkspaceState ¶
type WorkspaceState string
WorkspaceState is the lifecycle state of a workspace.
const ( WorkspaceOpen WorkspaceState = "open" WorkspaceLanded WorkspaceState = "landed" WorkspaceAbandoned WorkspaceState = "abandoned" )