service

package
v0.1.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: 13 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 service is vx's application logic: creating repos and efforts, opening workspaces and landing changes. It is independent of the API transport; internal/api adapts it to connect-go.

Index

Constants

This section is empty.

Variables

View Source
var ErrNothingToLand = errors.New("nothing to land")

ErrNothingToLand is returned when a snapshot has no changes.

Functions

func Classify

func Classify(err error) error

Classify turns store and blob errors into service errors and passes others on unchanged.

Types

type Actor

type Actor struct {
	store.Principal
	Parent *store.Principal // set for agents
}

Actor is the authenticated caller, with the human it acts for.

func (Actor) Human

func (a Actor) Human() store.Principal

Human returns the human behind the actor: the actor itself or its parent.

func (Actor) OnBehalfOf

func (a Actor) OnBehalfOf() string

OnBehalfOf is the parent's ref for agents, empty otherwise.

type Code

type Code int

Code classifies service errors so the API layer can map them.

const (
	CodeInvalid Code = iota + 1
	CodeNotFound
	CodeExists
	CodePermission
	CodeFailedPrecondition
	CodeUnavailable
)

type CreateEffortInput

type CreateEffortInput struct {
	Repo       string
	Name       string
	Goal       string
	BaseBranch string // empty: the repo's default branch
}

CreateEffortInput describes a new effort.

type CreateRepoInput

type CreateRepoInput struct {
	Name          string
	Provider      store.Provider
	Remote        string
	DefaultBranch string
}

CreateRepoInput describes a new repo.

type EffortView

type EffortView struct {
	Repo       store.Repo
	Effort     store.Effort
	Workspaces []store.Workspace
}

EffortView is an effort with its repo and open workspaces.

type Error

type Error struct {
	Code Code
	Msg  string
	Err  error
}

Error is a service error with a code and a message meant for the caller.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type LandInput

type LandInput struct {
	WorkspaceID uuid.UUID
	Base        hash.Hash // changeset the snapshot was made on
	Tree        hash.Hash // snapshot root tree; objects must be uploaded
	Intent      string    // empty: the workspace intent
	Evidence    *object.Evidence
	DependsOn   []string
	Model       string
	Session     string
	// RequireUpToDate refuses to merge onto newer work.
	RequireUpToDate bool
}

LandInput is a snapshot to land into a workspace's effort.

type LandResult

type LandResult struct {
	Landed     bool
	Changeset  store.ChangesetRow
	Files      []store.FileChange
	Rebased    bool              // the effort moved, the snapshot was merged onto it
	AutoMerged []string          // paths changed on both sides that merged cleanly
	Conflicts  []engine.Conflict // set when Landed is false
	EffortHead hash.Hash
	// EffortMoved is set when RequireUpToDate refused the land.
	EffortMoved bool
}

LandResult is the outcome of Land.

type LogEntry

type LogEntry struct {
	store.ChangesetRow
	Files []store.FileChange
}

LogEntry is a landed changeset with its file list.

type Service

type Service struct {
	Store    *store.Store
	Blobs    blob.Store
	Upstream UpstreamSyncer // nil: repos without an upstream only
	Shipper  Shipper        // nil: shipping disabled
	Now      func() time.Time
	// MaxLandAttempts bounds compare-and-swap retries when several agents
	// land into the same effort at once.
	MaxLandAttempts int
}

Service holds the dependencies of the application logic.

func New

func New(st *store.Store, blobs blob.Store, upstream UpstreamSyncer) *Service

New returns a Service with defaults filled in. When upstream can also ship (the git bridge can), it is used for that too.

func (*Service) Abandon

func (s *Service) Abandon(ctx context.Context, actor Actor, id uuid.UUID) (WorkspaceView, error)

Abandon closes a workspace without landing it.

func (*Service) Branch

func (s *Service) Branch(ctx context.Context, actor Actor, repo store.Repo, name string) (store.Branch, error)

Branch returns a tracked branch, importing it first if vx does not follow it yet. This is how efforts can start from any branch on the fly.

func (*Service) CreateAgent

func (s *Service) CreateAgent(ctx context.Context, actor Actor, name, displayName string) (store.Principal, string, error)

CreateAgent creates an agent that acts for the calling human and returns it with a fresh token. Agents cannot create agents.

func (*Service) CreateEffort

func (s *Service) CreateEffort(ctx context.Context, actor Actor, in CreateEffortInput) (store.Effort, error)

CreateEffort starts an effort on the current head of its base branch.

func (*Service) CreateRepo

func (s *Service) CreateRepo(ctx context.Context, actor Actor, in CreateRepoInput) (store.Repo, error)

CreateRepo registers a repo. A repo with an upstream imports its default branch right away; a repo without one starts from an empty snapshot.

func (*Service) GetChangeset

func (s *Service) GetChangeset(ctx context.Context, repoName, ref string) (store.Repo, LogEntry, error)

GetChangeset resolves a changeset by hash, prefix or change ID.

func (*Service) GetEffort

func (s *Service) GetEffort(ctx context.Context, repoName, slug string) (EffortView, error)

GetEffort loads an effort by repo name and slug.

func (*Service) GetWorkspace

func (s *Service) GetWorkspace(ctx context.Context, id uuid.UUID) (WorkspaceView, error)

GetWorkspace loads a workspace with its effort and repo.

func (*Service) Land

func (s *Service) Land(ctx context.Context, actor Actor, in LandInput) (LandResult, error)

Land merges a workspace snapshot into its effort.

When the effort has not moved since the snapshot's base, the snapshot becomes the new head. When it has, the snapshot is merged onto the current head with a three-way merge, and only real conflicts are sent back. The head moves with a compare-and-swap, so concurrent lands never lose work: the loser merges again on the new head and retries.

func (*Service) ListEfforts

func (s *Service) ListEfforts(ctx context.Context, repoName string, state store.EffortState) (store.Repo, []store.Effort, error)

ListEfforts lists a repo's efforts.

func (*Service) ListShipments

func (s *Service) ListShipments(ctx context.Context, repoName, slug string) ([]store.Shipment, error)

ListShipments returns an effort's shipments.

func (*Service) Log

func (s *Service) Log(ctx context.Context, repoName, slug string, limit int, withFiles bool) ([]LogEntry, error)

Log lists changes landed in an effort since its base, newest first.

func (*Service) OpenShipment

func (s *Service) OpenShipment(ctx context.Context, actor Actor, in ShipInput) (ShipResult, error)

OpenShipment pushes the planned commits to vx/<effort> and opens or updates the pull request. Shipping again replaces the branch and updates the same PR. vx never merges: that stays a decision on the git host.

func (*Service) OpenWorkspace

func (s *Service) OpenWorkspace(ctx context.Context, actor Actor, repoName, slug, intent string) (WorkspaceView, error)

OpenWorkspace starts a task in an effort, based on the effort's head.

func (*Service) PlanShipment

func (s *Service) PlanShipment(ctx context.Context, actor Actor, repoName, slug, target string) (ShipPlan, error)

PlanShipment replays the effort's changes, oldest first, onto the latest head of the target branch. Each change becomes one commit. A change whose parent is not the current tree is merged onto it, so an effort started on an older commit, or on another branch, still ships cleanly.

func (*Service) ResolveActor

func (s *Service) ResolveActor(ctx context.Context, p store.Principal) (Actor, error)

ResolveActor loads the parent of an agent principal.

func (*Service) SetBase

func (s *Service) SetBase(ctx context.Context, actor Actor, id uuid.UUID, base hash.Hash) (WorkspaceView, error)

SetBase records that the workspace's files now sit on base, which must be on the effort's chain.

func (*Service) SyncBranch

func (s *Service) SyncBranch(ctx context.Context, actor Actor, repoName, branch string) (store.Branch, int, error)

SyncBranch imports the latest commits of an upstream branch. For repos without an upstream it returns the branch as it is.

type ShipInput

type ShipInput struct {
	Repo, Effort, Target string
	Title, Body          string // empty: generated
	Draft                bool
}

ShipInput controls OpenShipment.

type ShipPlan

type ShipPlan struct {
	Repo         store.Repo
	Effort       store.Effort
	Target       string
	TargetHead   store.ChangesetRow
	Branch       string
	Title        string
	Body         string
	Steps        []ShipStep
	Conflicts    []engine.Conflict
	ConflictedAt *store.ChangesetRow
}

ShipPlan is what shipping an effort would produce.

func (ShipPlan) Commits

func (p ShipPlan) Commits() []ShipStep

Commits returns the steps that produce a commit.

type ShipResult

type ShipResult struct {
	Plan     ShipPlan
	Shipment store.Shipment
	PR       provider.OpenedPR
}

ShipResult is a pushed branch and, where the provider has them, its PR.

type ShipStep

type ShipStep struct {
	Changeset store.ChangesetRow
	Tree      hash.Hash // tree after this step, on top of the target
	Files     int       // files this step changes on the target
	Skipped   bool      // the target already has this change
}

ShipStep is one landed change replayed onto the target.

type Shipper

type Shipper interface {
	ExportBranch(ctx context.Context, repo store.Repo, baseSHA, branch string, commits []provider.Commit) ([]string, error)
	OpenPullRequest(ctx context.Context, repo store.Repo, pr provider.PullRequest) (provider.OpenedPR, error)
}

Shipper pushes branches and opens pull requests on the git host.

type UpstreamSyncer

type UpstreamSyncer interface {
	// DefaultBranch asks the provider for the repo's default branch.
	DefaultBranch(ctx context.Context, repo store.Repo) (string, error)
	// SyncBranch imports new commits on branch and records its head.
	SyncBranch(ctx context.Context, repo store.Repo, branch string) (store.Branch, int, error)
}

UpstreamSyncer imports branches from a repo's git provider.

type WorkspaceView

type WorkspaceView struct {
	Repo      store.Repo
	Effort    store.Effort
	Workspace store.Workspace
}

WorkspaceView is a workspace with its effort and repo.

Jump to

Keyboard shortcuts

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