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
- Variables
- func ClaimTrust(actor Actor, c Claim) string
- func Classify(err error) error
- func GitHubHandle(login string, id int64) string
- func NormalizeGitHubLogin(v string) (string, error)
- func NormalizeUserCode(code string) string
- func PKCEChallenge(verifier string) string
- func TargetsMatch(target, want string) bool
- func TaskTrust(actor Actor, t Task) string
- func TrustOf(actor Actor, n Note) string
- func WithClientIP(ctx context.Context, ip string) context.Context
- type AccessEntry
- type Actor
- type AddTaskInput
- type AgentSummary
- type AskInput
- type BackfillStats
- type CLILogin
- type Claim
- type ClaimInput
- type Code
- type ContextWorkspace
- type ContinueInput
- type CreateEffortInput
- type CreateRepoInput
- type EffortView
- type Error
- type GitHubAPI
- type GitHubAppCredentials
- type GitHubAppInfo
- type GitHubInstallation
- type GitHubRepo
- type GitHubRoleScope
- type GitHubSettings
- type GitHubSignupRefused
- type GitHubUser
- type Inbox
- type LandInput
- type LandResult
- type ListNotesInput
- type ListTasksInput
- type LogEntry
- type Membership
- type NewPerson
- type Note
- type NoteContext
- type NoteKind
- type Object
- type Org
- type OrgDetail
- type OrgRole
- type PostNoteInput
- type RebaseView
- type RepoGrant
- type RepoRole
- type RepoView
- type RevokeInput
- type ServerInfo
- type Service
- func (s *Service) Abandon(ctx context.Context, actor Actor, id uuid.UUID) (WorkspaceView, error)
- func (s *Service) AbortRebase(ctx context.Context, actor Actor, repoName, slug string) (RebaseView, error)
- func (s *Service) AddPerson(ctx context.Context, by *store.Principal, n NewPerson) (store.Principal, string, bool, error)
- func (s *Service) AddTask(ctx context.Context, actor Actor, in AddTaskInput) (Task, error)
- func (s *Service) AnswerNote(ctx context.Context, actor Actor, questionID string, body string) (Note, Note, error)
- func (s *Service) ApplyGitHubOrgMembership(ctx context.Context, githubOrgID, githubUserID int64, role string) error
- func (s *Service) ApproveCLILogin(ctx context.Context, actor Actor, userCode string, approve bool) error
- func (s *Service) Ask(ctx context.Context, actor Actor, in AskInput) (Note, error)
- func (s *Service) Authorize(ctx context.Context, actor Actor, repo string, need RepoRole) (store.Repo, RepoRole, error)
- func (s *Service) AuthorizeID(ctx context.Context, actor Actor, repoID uuid.UUID, need RepoRole) (RepoRole, error)
- func (s *Service) BackfillObjects(ctx context.Context, log *slog.Logger) ([]BackfillStats, error)
- func (s *Service) BackfillRepoObjects(ctx context.Context, repoID uuid.UUID, force bool, log *slog.Logger) (BackfillStats, error)
- func (s *Service) BlobReader(ctx context.Context, actor Actor, repoID uuid.UUID) (func(context.Context, hash.Hash) ([]byte, error), error)
- func (s *Service) Branch(ctx context.Context, actor Actor, repo store.Repo, name string) (store.Branch, error)
- func (s *Service) CheckCLIVersion(cliVersion, baseURL string) (status, message string)
- func (s *Service) CompleteGitHubSetup(ctx context.Context, actor Actor, code, state string) error
- func (s *Service) Context(ctx context.Context, actor Actor, repo, effort string, targets []string) (NoteContext, error)
- func (s *Service) ContinueRebase(ctx context.Context, actor Actor, in ContinueInput) (RebaseView, error)
- func (s *Service) CreateAgent(ctx context.Context, actor Actor, name, displayName string) (store.Principal, string, error)
- func (s *Service) CreateEffort(ctx context.Context, actor Actor, in CreateEffortInput) (store.Effort, error)
- func (s *Service) CreateLoginCode(ctx context.Context, actor Actor) (string, time.Time, error)
- func (s *Service) CreateOrg(ctx context.Context, actor Actor, handle, displayName string) (Org, error)
- func (s *Service) CreatePerson(ctx context.Context, actor Actor, handle, displayName, email string, ...) (store.Principal, string, error)
- func (s *Service) CreateRepo(ctx context.Context, actor Actor, in CreateRepoInput) (store.Repo, error)
- func (s *Service) CreateTeam(ctx context.Context, actor Actor, org, name string) (Team, error)
- func (s *Service) CreateToken(ctx context.Context, actor Actor, agent, name string) (store.Token, store.Principal, string, error)
- func (s *Service) DeleteTeam(ctx context.Context, actor Actor, org, name string) error
- func (s *Service) DismissWelcome(ctx context.Context, actor Actor, dismissed bool) error
- func (s *Service) DropGitHubRoles(ctx context.Context, scope GitHubRoleScope) error
- func (s *Service) GetChangeset(ctx context.Context, actor Actor, repoName, ref string) (store.Repo, LogEntry, error)
- func (s *Service) GetEffort(ctx context.Context, actor Actor, repoName, slug string) (EffortView, error)
- func (s *Service) GetInbox(ctx context.Context, actor Actor) (Inbox, error)
- func (s *Service) GetNote(ctx context.Context, actor Actor, id string) (Note, error)
- func (s *Service) GetObjects(ctx context.Context, actor Actor, repo string, hashes []hash.Hash, ...) ([]Object, error)
- func (s *Service) GetOrg(ctx context.Context, actor Actor, handle string) (OrgDetail, error)
- func (s *Service) GetRebase(ctx context.Context, actor Actor, repoName, slug string) (RebaseView, bool, error)
- func (s *Service) GetRepo(ctx context.Context, actor Actor, name string) (RepoView, []store.Branch, error)
- func (s *Service) GetWorkspace(ctx context.Context, actor Actor, id uuid.UUID) (WorkspaceView, error)
- func (s *Service) GitHubApp(ctx context.Context) (GitHubAppInfo, error)
- func (s *Service) GitHubAppInstallURL(ctx context.Context) (string, error)
- func (s *Service) GitHubAppManifest() ([]byte, error)
- func (s *Service) GitHubClient(ctx context.Context) (GitHubAPI, error)
- func (s *Service) GitHubLinkFinish(ctx context.Context, actor Actor, code, verifier string) (GitHubUser, error)
- func (s *Service) GitHubLinkOf(ctx context.Context, actor Actor) (store.GitHubLink, bool, error)
- func (s *Service) GitHubManifestFormURL(org, state string) string
- func (s *Service) GitHubRepoToken(ctx context.Context, repo store.Repo) (string, error)
- func (s *Service) GitHubRole(ctx context.Context, repo store.Repo, person store.Principal) (role RepoRole, ok bool, err error)
- func (s *Service) GitHubSettingsURL(r store.Repo) string
- func (s *Service) GitHubSetupManifest(ctx context.Context, actor Actor) (manifest []byte, state string, err error)
- func (s *Service) GitHubSignInEnabled(ctx context.Context) bool
- func (s *Service) GitHubSignInFinish(ctx context.Context, code, verifier string) (p store.Principal, token string, isNew bool, err error)
- func (s *Service) GitHubSignInStart(ctx context.Context, next string) (authorizeURL, state, verifier string, err error)
- func (s *Service) GitHubWebURL() string
- func (s *Service) GrantRepo(ctx context.Context, actor Actor, repo, subject string, role RepoRole) (RepoGrant, error)
- func (s *Service) HandleGitHubWebhook(ctx context.Context, event, deliveryID, signature string, body []byte) error
- func (s *Service) Info(ctx context.Context) ServerInfo
- func (s *Service) InstallCommand(baseURL string) string
- func (s *Service) InviteGitHubLogin(ctx context.Context, by *store.Principal, login, note string, siteAdmin bool) (store.SignupInvite, error)
- func (s *Service) InviteGitHubUser(ctx context.Context, actor Actor, login, note string) error
- func (s *Service) IsSiteAdmin(ctx context.Context, actor Actor) bool
- func (s *Service) Land(ctx context.Context, actor Actor, in LandInput) (LandResult, error)
- func (s *Service) ListAgents(ctx context.Context, actor Actor) ([]AgentSummary, error)
- func (s *Service) ListClaims(ctx context.Context, actor Actor, repo, effort string, targets []string) ([]Claim, error)
- func (s *Service) ListEfforts(ctx context.Context, actor Actor, repoName string, state store.EffortState) (store.Repo, []store.Effort, error)
- func (s *Service) ListGitHubInvites(ctx context.Context, actor Actor, all bool) ([]store.SignupInvite, error)
- func (s *Service) ListNotes(ctx context.Context, actor Actor, in ListNotesInput) ([]Note, error)
- func (s *Service) ListOrgs(ctx context.Context, actor Actor, all bool) ([]Org, []OrgRole, error)
- func (s *Service) ListPeople(ctx context.Context, actor Actor) ([]store.Principal, error)
- func (s *Service) ListRepos(ctx context.Context, actor Actor) ([]RepoView, error)
- func (s *Service) ListShipments(ctx context.Context, actor Actor, repoName, slug string) ([]store.Shipment, error)
- func (s *Service) ListTasks(ctx context.Context, actor Actor, in ListTasksInput) ([]Task, error)
- func (s *Service) ListTokens(ctx context.Context, actor Actor, agent string) (store.Principal, []store.Token, error)
- func (s *Service) LoadGitHubApp(ctx context.Context) error
- func (s *Service) Log(ctx context.Context, actor Actor, repoName, slug string, limit int, ...) ([]LogEntry, error)
- func (s *Service) MakeClaim(ctx context.Context, actor Actor, in ClaimInput) (Claim, []Claim, error)
- func (s *Service) MissingObjects(ctx context.Context, actor Actor, repo string, hashes []hash.Hash) ([]hash.Hash, error)
- func (s *Service) MyGitHubInstallations(ctx context.Context, actor Actor) ([]GitHubInstallation, error)
- func (s *Service) OpenShipment(ctx context.Context, actor Actor, in ShipInput) (ShipResult, error)
- func (s *Service) OpenWorkspace(ctx context.Context, actor Actor, repoName, slug, intent string) (WorkspaceView, error)
- func (s *Service) PeekLoginCode(ctx context.Context, code string) (store.Principal, error)
- func (s *Service) PendingCLILogin(ctx context.Context, actor Actor, userCode string) (clientName string, expires time.Time, err error)
- func (s *Service) PlanShipment(ctx context.Context, actor Actor, repoName, slug, target string) (ShipPlan, error)
- func (s *Service) PollCLILogin(ctx context.Context, deviceCode string) (status, token string, p store.Principal, err error)
- func (s *Service) PostNote(ctx context.Context, actor Actor, in PostNoteInput) (Note, error)
- func (s *Service) PutObjects(ctx context.Context, actor Actor, repo string, objs []Object) ([]hash.Hash, error)
- func (s *Service) ReadBlob(ctx context.Context, actor Actor, repoID uuid.UUID, h hash.Hash) ([]byte, error)
- func (s *Service) ReadableRepoIDs(ctx context.Context, actor Actor) (ids []uuid.UUID, all bool, err error)
- func (s *Service) ReadableRepos(ctx context.Context, actor Actor, org *uuid.UUID) ([]store.Repo, []RepoRole, error)
- func (s *Service) RebaseEffort(ctx context.Context, actor Actor, repoName, slug, onto string) (RebaseView, error)
- func (s *Service) RedeemLoginCode(ctx context.Context, code string) (store.Principal, string, error)
- func (s *Service) ReleaseClaims(ctx context.Context, actor Actor, id, workspaceID string) ([]Claim, error)
- func (s *Service) RemoveMember(ctx context.Context, actor Actor, org, person string) error
- func (s *Service) RemoveTeamMember(ctx context.Context, actor Actor, org, team, person string) (Team, error)
- func (s *Service) RepoAccess(ctx context.Context, actor Actor, repo string) ([]RepoGrant, []AccessEntry, error)
- func (s *Service) RepoRoleOf(ctx context.Context, actor Actor, r store.Repo) RepoRole
- func (s *Service) ResolveActor(ctx context.Context, p store.Principal) (Actor, error)
- func (s *Service) RevokeRepo(ctx context.Context, actor Actor, repo, subject string) error
- func (s *Service) RevokeToken(ctx context.Context, actor Actor, in RevokeInput) (store.Token, store.Principal, bool, error)
- func (s *Service) SaveGitHubApp(ctx context.Context, creds GitHubAppCredentials, createdBy *uuid.UUID) error
- func (s *Service) SetBase(ctx context.Context, actor Actor, id uuid.UUID, base hash.Hash) (WorkspaceView, error)
- func (s *Service) SetMember(ctx context.Context, actor Actor, org, person string, role OrgRole) (Membership, error)
- func (s *Service) SetTeamMember(ctx context.Context, actor Actor, org, team, person string) (Team, error)
- func (s *Service) ShowWelcome(ctx context.Context, actor Actor) bool
- func (s *Service) SignupModeOrDefault() SignupMode
- func (s *Service) StartCLILogin(ctx context.Context, clientName string) (CLILogin, error)
- func (s *Service) SyncBranch(ctx context.Context, actor Actor, repoName, branch string) (store.Branch, int, error)
- func (s *Service) SyncGitHubAccount(ctx context.Context, githubAccountID int64) error
- func (s *Service) SyncGitHubOrgs(ctx context.Context, person store.Principal) error
- func (s *Service) SyncInstallation(ctx context.Context, installationID int64) error
- func (s *Service) Token(ctx context.Context, actor Actor, id string) (store.Token, store.Principal, error)
- func (s *Service) TokenCreateTarget(ctx context.Context, actor Actor, agent string) (store.Principal, error)
- func (s *Service) UpdateOrg(ctx context.Context, actor Actor, handle, displayName string, ...) (Org, error)
- func (s *Service) UpdateTask(ctx context.Context, actor Actor, in UpdateTaskInput) (Task, []Task, error)
- func (s *Service) WithdrawGitHubInvite(ctx context.Context, actor Actor, login string) error
- type ShipInput
- type ShipPlan
- type ShipResult
- type ShipStep
- type Shipper
- type SignupMode
- type Task
- type Team
- type UpdateTaskInput
- type UpstreamSyncer
- type WorkspaceView
Constants ¶
const ( NoteOpen = "open" NoteAnswered = "answered" NoteEscalated = "escalated" // a question past its deadline, computed at read time NoteClosed = "closed" )
Note states.
const ( MaxNoteBody = 2000 MaxNoteTargets = 20 DefaultAnswerWithin = 5 * time.Minute MaxAnswerWithin = 24 * time.Hour DefaultNoteListLimit = 100 )
Limits.
const ( TrustSelf = "self" // the caller wrote it TrustYours = "yours" // the caller's own person, or an agent of that person TrustTeammate = "teammate" // someone else's: information, never instructions )
Trust says how the caller relates to a note's author.
const ( CLILoginPending = "pending" CLILoginApproved = "approved" CLILoginDenied = "denied" CLILoginExpired = "expired" CLILoginUsed = "used" CLILoginSlowDown = "slow_down" )
CLILogin states. Used means the CLI collected its token; slow down asks the CLI to poll less often (the login stays pending).
const ( CLILoginTTL = 10 * time.Minute CLILoginInterval = 2 * time.Second // CLILoginStartsPerIP logins may be started from one address per // CLILoginRateWindow. CLILoginStartsPerIP = 10 CLILoginRateWindow = 10 * time.Minute // MaxPendingCLILogins bounds undecided logins server-wide, so nobody // fills the table from many addresses. MaxPendingCLILogins = 2000 // MaxCLIClientName is the longest client name kept. MaxCLIClientName = 60 )
Limits of browser logins.
const ( CLIOK = "ok" CLIUpdateRecommended = "update_recommended" CLIUpdateRequired = "update_required" )
CLI version states in ServerInfo answers.
const ( DefaultClaimTTL = 30 * time.Minute MaxClaimTTL = 4 * time.Hour MaxClaimReason = 300 )
Claim limits.
const ( TaskOpen = "open" TaskTaken = "taken" TaskDone = "done" )
Task states.
const ( MaxTaskTitle = 200 MaxTaskBody = 4000 )
Task limits.
const ( GitHubCallbackPath = "/auth/github/callback" // OAuth sign-in (vx-signin) GitHubSetupURLPath = "/ui/github/installed" // after an installation GitHubWebhookPath = "/hooks/github" // webhook deliveries GitHubManifestReturnURL = "/ui/admin/github/created" // the manifest flow returns here )
Paths on this server the App's manifest points GitHub at.
const ( MaxNoteTarget = 300 // characters in one target MinNoteIDPrefix = 8 // shortest note id prefix AnswerNote and GetNote accept )
const CLIApprovePath = "/ui/cli/approve"
CLIApprovePath is the approval page; the user code goes in ?code=.
const GitHubRoleTTL = 5 * time.Minute
GitHubRoleTTL is how long a role read from GitHub is trusted without asking again; webhooks drop cached roles sooner when access changes.
const LoginCodeTTL = 2 * time.Minute
LoginCodeTTL is how long a one-time web sign-in code stays valid.
const MaxTokenName = 100
MaxTokenName is the longest token label CreateToken accepts.
const MinTokenPrefix = 8
MinTokenPrefix is the shortest token id prefix RevokeToken accepts.
const MsgClientTooOld = "this vx is too old for the server: update vx (object requests must name a repository)"
MsgClientTooOld is the error for object requests that do not name a repository, which only clients from before v0.2 send.
Variables ¶
var ( GitHubAppPermissions = map[string]string{ "metadata": "read", "contents": "write", "pull_requests": "write", "checks": "read", "members": "read", } GitHubAppEvents = []string{"repository", "member", "membership", "organization", "team", "team_add", "push", "pull_request"} )
GitHubAppPermissions and GitHubAppEvents are what the App asks for. installation and installation_repositories are always delivered to an App, so they are not listed (GitHub refuses them in a manifest).
var ErrGitHubDeliveryApplied = &Error{Code: CodeExists, Msg: "this delivery was applied already"}
ErrGitHubDeliveryApplied is returned for a delivery applied before.
var ErrGitHubNotConfigured = errors.New("GitHub is not configured on this server: a site admin sets it up on the Admin page")
ErrGitHubNotConfigured is returned when the server has no GitHub App yet.
var ErrNothingToLand = errors.New("nothing to land")
ErrNothingToLand is returned when a snapshot has no changes.
var Features = []string{"board", "claims", "tasks", "rebase", "orgs", "github", "cli-login", "install-script"}
Features this server has, for CLIs that need to tell "your server is too old" apart from other errors.
Functions ¶
func ClaimTrust ¶ added in v0.2.0
ClaimTrust says how actor relates to a claim's owner, like TrustOf.
func Classify ¶
Classify turns store and blob errors into service errors and passes others on unchanged.
func GitHubHandle ¶ added in v0.2.0
GitHubHandle turns a GitHub login into a vx handle: lowercased, characters handles do not allow become "-", then leading and trailing separators are trimmed. A login with nothing left becomes github-<id>.
func NormalizeGitHubLogin ¶ added in v0.2.0
NormalizeGitHubLogin returns the lowercased login, or an error saying what a login looks like.
func NormalizeUserCode ¶ added in v0.2.0
NormalizeUserCode upper-cases a user code and puts the dash back, so "wdjb mjht" and "WDJBMJHT" find WDJB-MJHT. It returns "" for anything that cannot be a user code.
func PKCEChallenge ¶ added in v0.2.0
PKCEChallenge is the S256 code challenge for a verifier.
func TargetsMatch ¶ added in v0.2.0
TargetsMatch reports whether a note target matches a requested path or symbol: equal, or one is a directory prefix ("internal/http/" and "internal/http/limit.go") or symbol prefix ("auth" and "auth.Login") of the other.
func TaskTrust ¶ added in v0.2.0
TaskTrust says how actor relates to a task's creator, like TrustOf.
Types ¶
type AccessEntry ¶ added in v0.2.0
AccessEntry is one person's effective role on a repository and why.
type Actor ¶
type Actor struct {
store.Principal
Parent *store.Principal // set for agents
// TokenID is the token the request was made with; uuid.Nil when the
// caller did not authenticate with a token (tests, internal calls).
TokenID uuid.UUID
}
Actor is the authenticated caller, with the human it acts for.
func (Actor) OnBehalfOf ¶
OnBehalfOf is the parent's ref for agents, empty otherwise.
type AddTaskInput ¶ added in v0.2.0
type AddTaskInput struct {
Repo, Effort string
Title, Body string
DependsOn []string // ids or 8+ character prefixes
Owner string // optional: agent name, handle or ref
}
AddTaskInput is a new task.
type AgentSummary ¶ added in v0.2.0
type AgentSummary struct {
Agent store.Principal
ActiveTokens int
RevokedTokens int
LastUsedAt *time.Time // latest use of any of its tokens
}
AgentSummary is one of a person's agents with a summary of its tokens.
type AskInput ¶ added in v0.2.0
type AskInput struct {
Repo, Effort string
Targets []string
Body string
To string // agent name, handle or ref; empty: anyone
AnswerWithin time.Duration // 0: DefaultAnswerWithin
}
AskInput is a question.
type BackfillStats ¶ added in v0.2.0
type BackfillStats struct {
Repo string
Changesets int
Objects int // objects recorded, including ones already recorded
Skipped int // trees that could not be read (missing from the store)
Ran bool
Took time.Duration
}
BackfillStats is what one repository's backfill did.
type CLILogin ¶ added in v0.2.0
type CLILogin struct {
DeviceCode string
UserCode string
VerificationURL string
ExpiresAt time.Time
Interval time.Duration
}
CLILogin is a started browser login.
type Claim ¶ added in v0.2.0
type Claim struct {
ID uuid.UUID
RepoName string
EffortSlug string
EffortID uuid.UUID
Targets []string
Owner store.Principal
OwnerParent *store.Principal // the person an agent owner acts for
WorkspaceID *uuid.UUID
Reason string
CreatedAt time.Time
ExpiresAt time.Time
ReleasedAt *time.Time
}
Claim says a principal is changing some paths or symbols now.
type ClaimInput ¶ added in v0.2.0
type ClaimInput struct {
Repo, Effort string
Targets []string
Reason string
TTL time.Duration // 0: DefaultClaimTTL
WorkspaceID string // optional
}
ClaimInput is a new claim.
type ContextWorkspace ¶ added in v0.2.0
ContextWorkspace is an open workspace with its owner.
type ContinueInput ¶ added in v0.2.0
type ContinueInput struct {
Repo, Effort string
// StoppedAt is the conflicting change the caller resolved (its old-chain
// hash), so a resolution of an earlier stop is never applied to a later
// one.
StoppedAt hash.Hash
// Tree is the resolved tree of that change on top of the rebased chain
// so far; its objects must be uploaded.
Tree hash.Hash
}
ContinueInput resolves the change a stopped rebase conflicts on.
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
// Org owns the repo. Empty: the organization named like the repo's
// owner part when the caller may create repos there, else the
// caller's personal organization.
Org string
}
CreateRepoInput describes a new repo.
type EffortView ¶
type EffortView struct {
Repo store.Repo
Effort store.Effort
Workspaces []store.Workspace
// Rebase is the effort's rebase in progress (running or stopped), if any.
Rebase *store.Rebase
}
EffortView is an effort with its repo and open workspaces.
type GitHubAPI ¶ added in v0.2.0
type GitHubAPI interface {
// CreateAppFromManifest completes the manifest flow and returns the new
// App's credentials.
CreateAppFromManifest(ctx context.Context, code string) (GitHubAppCredentials, error)
// Installation and InstallationRepos read an installation of the App.
Installation(ctx context.Context, id int64) (GitHubInstallation, error)
InstallationRepos(ctx context.Context, id int64) ([]GitHubRepo, error)
// InstallationToken returns a short-lived token for an installation, for
// git pushes and API calls on its repositories.
InstallationToken(ctx context.Context, id int64) (token string, expires time.Time, err error)
// ExchangeOAuthCode turns a web sign-in code into a user access token.
ExchangeOAuthCode(ctx context.Context, code, redirectURI, codeVerifier string) (userToken string, err error)
// User returns the signed-in GitHub user.
User(ctx context.Context, userToken string) (GitHubUser, error)
// RepoPermission returns login's permission on owner/repo: admin,
// maintain, write, triage, read or none.
RepoPermission(ctx context.Context, installationID int64, owner, repo, login string) (string, error)
// OrgMembership returns login's role in org: admin, member or none.
OrgMembership(ctx context.Context, installationID int64, org, login string) (string, error)
}
GitHubAPI is what vx needs from GitHub. internal/github implements it over HTTP; tests use the fake in internal/github/githubtest.
type GitHubAppCredentials ¶ added in v0.2.0
type GitHubAppCredentials struct {
AppID int64
Slug string
HTMLURL string
ClientID string
ClientSecret string
PrivateKeyPEM string
WebhookSecret string
}
GitHubAppCredentials are what the manifest flow returns.
type GitHubAppInfo ¶ added in v0.2.0
type GitHubAppInfo struct {
AppID int64
Slug string
HTMLURL string // https://github.com/apps/<slug>
ClientID string
InstallURL string // where an organization installs the App
AuthorizeURL string // OAuth authorize endpoint for web sign-in
CreatedBy *uuid.UUID
CreatedAt time.Time
}
GitHubAppInfo is what may be shown about the App (no secrets).
type GitHubInstallation ¶ added in v0.2.0
type GitHubInstallation struct {
ID int64
AccountID int64
AccountLogin string
AccountType string // Organization or User
RepositorySelection string // all or selected
SuspendedAt *time.Time
}
GitHubInstallation is an installation of the App.
type GitHubRepo ¶ added in v0.2.0
GitHubRepo is a repository an installation can reach.
type GitHubRoleScope ¶ added in v0.2.0
type GitHubRoleScope struct {
RepoID *uuid.UUID
GitHubRepoID int64
GitHubOrgID int64
GitHubUserID int64
InstallationID int64
Reason string
}
GitHubRoleScope selects what DropGitHubRoles forgets. Every set field adds its own part (the fields are OR-ed, never AND-ed):
- RepoID or GitHubRepoID: everyone's role on that repository (member added, removed or edited; repository visibility, rename, transfer).
- GitHubOrgID: roles on every repository of installations on that account and memberships in it (organization membership and team changes).
- GitHubUserID: everything cached for that person (person removed, or their access changed in a way that names only them).
- InstallationID: roles on every repository of the installation and memberships in its account (installation removed, suspended, or its repositories changed).
Reason is logged.
type GitHubSettings ¶ added in v0.2.0
type GitHubSettings struct {
API GitHubAPI // nil until the App is configured
PublicURL string // e.g. https://app.vxbench.com, for redirect and webhook URLs
Signup SignupMode // empty: SignupInvite
SecretKey []byte // 32 bytes from VX_SECRET_KEY, for secrets at rest
// WebURL and APIURL are GitHub's browser and REST API bases; empty:
// github.com. GitHub Enterprise Server: https://HOST and
// https://HOST/api/v3.
WebURL, APIURL string
// Connect makes the API client for the App once its credentials are
// known (internal/github in the server, the fake in tests). With zero
// credentials it returns a client that can only complete the manifest
// flow. nil: the App cannot be set up or loaded.
Connect func(creds GitHubAppCredentials) (GitHubAPI, error)
}
GitHubSettings configure the GitHub integration of a Service.
type GitHubSignupRefused ¶ added in v0.2.0
type GitHubSignupRefused struct {
Login string
Mode SignupMode
}
GitHubSignupRefused is returned when a GitHub account has no vx person and the signup mode does not let it create one.
func (*GitHubSignupRefused) Error ¶ added in v0.2.0
func (e *GitHubSignupRefused) Error() string
type GitHubUser ¶ added in v0.2.0
type GitHubUser struct {
ID int64
Login string
Name string
Email string // primary verified email if GitHub shares it; may be empty
}
GitHubUser is a signed-in GitHub user.
type Inbox ¶ added in v0.2.0
type Inbox struct {
Questions []Note // open questions to the caller (people: also to their agents)
Answers []Note // answers to the caller's questions, newest first
Escalated []Note // people only: overdue questions in their efforts or to their agents
}
Inbox is what needs a principal's attention.
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
// Warnings are problems found in the landed tree, such as a Go function
// declared twice in one package after a clean text merge. They never
// stop a land.
Warnings []engine.Warning
// OverlappingClaims are active claims of other principals on files this
// land changed. They never stop a land.
OverlappingClaims []Claim
// KeptBoth lists paths where both sides inserted different lines at the
// same place and the merge kept both; worth a look.
KeptBoth []string
}
LandResult is the outcome of Land.
type ListNotesInput ¶ added in v0.2.0
type ListNotesInput struct {
Repo, Effort string
Targets []string
Kinds []NoteKind
Since time.Time
ThreadID uuid.UUID
Limit int // 0: DefaultNoteListLimit
}
ListNotesInput filters a board listing.
type ListTasksInput ¶ added in v0.2.0
ListTasksInput filters an effort's tasks.
type LogEntry ¶
type LogEntry struct {
store.ChangesetRow
Files []store.FileChange
}
LogEntry is a landed changeset with its file list.
type Membership ¶ added in v0.2.0
Membership is a person in an organization.
type NewPerson ¶ added in v0.2.0
type NewPerson struct {
Handle string
DisplayName string
Email string
SiteAdmin bool
// Org, when set, adds the person to this organization as a member.
Org string
// CreateOrg creates Org with the person as its owner when it does not
// exist yet (vx-server user-add on a new server).
CreateOrg bool
}
NewPerson describes a person for AddPerson.
type Note ¶ added in v0.2.0
type Note struct {
ID uuid.UUID
RepoName string
EffortSlug string
EffortID uuid.UUID
ThreadID uuid.UUID // the root note of the thread; equals ID for a root
Kind NoteKind
Targets []string
Author store.Principal
AuthorOwner *store.Principal // the person an agent author acts for
To *store.Principal // a question's addressee; nil: anyone
Body string
State string
AnswerBy *time.Time
CreatedAt time.Time
}
Note is one note on an effort's board.
type NoteContext ¶ added in v0.2.0
type NoteContext struct {
Notes []Note
Working []ContextWorkspace
RecentChanges []LogEntry // landed changes touching the targets, newest first, with files
Claims []Claim // active claims on the targets (all when no targets)
}
NoteContext is what an agent should know before touching some targets.
type NoteKind ¶ added in v0.2.0
type NoteKind string
NoteKind is the type of a board note.
const ( NotePlan NoteKind = "plan" // what I am about to change NoteDecision NoteKind = "decision" // a choice others should follow NoteInterface NoteKind = "interface" // a signature others can rely on NoteQuestion NoteKind = "question" // asked with Ask NoteAnswer NoteKind = "answer" // given with AnswerNote NoteBlocker NoteKind = "blocker" // what I am waiting on NoteHandoff NoteKind = "handoff" // work left for the next agent )
type Object ¶ added in v0.2.0
type Object struct {
Kind hash.Kind
Data []byte
Hash hash.Hash // for uploads: what the client says it is; zero skips the check
}
Object is one object in transfer.
type Org ¶ added in v0.2.0
type Org struct {
ID uuid.UUID
Handle string
DisplayName string
DefaultRepoRole RepoRole // RoleNone, RoleRead or RoleWrite
Personal bool
CreatedAt time.Time
}
Org is an organization.
type OrgDetail ¶ added in v0.2.0
type OrgDetail struct {
Org Org
MyRole OrgRole // empty when the caller is not a member
Members []Membership
Teams []Team
Repos []store.Repo
}
OrgDetail is an organization with its members, teams and the repositories the caller can read.
type PostNoteInput ¶ added in v0.2.0
type PostNoteInput struct {
Repo, Effort string
Kind NoteKind // plan, decision, interface, blocker, handoff
Targets []string
Body string
}
PostNoteInput is a non-question note.
type RebaseView ¶ added in v0.2.0
type RebaseView struct {
Repo store.Repo
Effort store.Effort
Rebase store.Rebase
// UpToDate is set when there was nothing to rebase: the effort already
// sits on the head of the branch. No rebase is recorded then.
UpToDate bool
// StoppedAt is the old-chain change whose replay conflicts, when the
// rebase is stopped. Writing the merge of BaseTree (its parent's tree),
// ChangeTree (its tree) and OntoTree (the rebased chain so far) with
// conflict markers reproduces the conflicts.
StoppedAt *store.ChangesetRow
BaseTree, ChangeTree, OntoTree hash.Hash
StartedBy, UpdatedBy string // principal refs
}
RebaseView is a rebase with what a caller needs to show or resume it.
type RepoGrant ¶ added in v0.2.0
type RepoGrant struct {
Repo string
Subject string // "user:alice" or "team:acme/backend"
Role RepoRole
}
RepoGrant is a direct grant of a role on a repository.
type RepoRole ¶ added in v0.2.0
type RepoRole string
RepoRole is what a principal may do in a repository. Roles are ordered: admin includes write, write includes read.
func RoleFromGitHub ¶ added in v0.2.0
RoleFromGitHub maps a GitHub repository permission to a vx role.
type RevokeInput ¶ added in v0.2.0
type RevokeInput struct {
// ID is a token id or a unique prefix of one (at least 8 characters)
// among the tokens the caller may manage.
ID string
// AllowCurrent allows revoking the token the request is made with, which
// signs the caller out.
AllowCurrent bool
}
RevokeInput says which token to revoke.
type ServerInfo ¶ added in v0.2.0
ServerInfo is the server's version and the oldest CLI it accepts.
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
// GitHub configures sign-in with GitHub and GitHub-backed repositories;
// its API is nil until a GitHub App is set up.
GitHub GitHubSettings
// contains filtered or unexported fields
}
Service holds the dependencies of the application logic.
func New ¶
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) AbortRebase ¶ added in v0.2.0
func (s *Service) AbortRebase(ctx context.Context, actor Actor, repoName, slug string) (RebaseView, error)
AbortRebase drops the effort's rebase in progress. The effort is left as it was; the changesets the rebase stored stay unreferenced.
func (*Service) AddPerson ¶ added in v0.2.0
func (s *Service) AddPerson(ctx context.Context, by *store.Principal, n NewPerson) (store.Principal, string, bool, error)
AddPerson creates a person, their personal organization and a first token, without checking who asks: CreatePerson checks, and vx-server user-add runs it with by nil. It reports whether it created n.Org.
func (*Service) AnswerNote ¶ added in v0.2.0
func (s *Service) AnswerNote(ctx context.Context, actor Actor, questionID string, body string) (Note, Note, error)
AnswerNote answers a question (by id or an 8+ character id prefix) and returns the answer and the updated question.
func (*Service) ApplyGitHubOrgMembership ¶ added in v0.2.0
func (s *Service) ApplyGitHubOrgMembership(ctx context.Context, githubOrgID, githubUserID int64, role string) error
ApplyGitHubOrgMembership records a membership change GitHub reported in a webhook (organization member_added, member_removed, member_invited does not count): role is admin, member or "" (not a member). It drops the person's cached answers for that organization and updates the linked vx organization. People vx does not know are ignored.
func (*Service) ApproveCLILogin ¶ added in v0.2.0
func (s *Service) ApproveCLILogin(ctx context.Context, actor Actor, userCode string, approve bool) error
ApproveCLILogin approves or denies a pending login by user code; approval lets the CLI collect a token for the person named after the client.
func (*Service) Ask ¶ added in v0.2.0
Ask posts a question, optionally to one principal, that escalates after its deadline.
func (*Service) Authorize ¶ added in v0.2.0
func (s *Service) Authorize(ctx context.Context, actor Actor, repo string, need RepoRole) (store.Repo, RepoRole, error)
Authorize returns the repository named repo if actor has at least need on it. A repository the actor cannot read is reported as not found, so its existence does not leak; one it can read but needs more on is a permission error (the repository and the actor's role come back with it). Agents are checked as the person they act for.
Every service function that takes a repository name calls this first. It runs one query, plus a cache lookup (and when that is stale, a call to GitHub) for GitHub-backed repositories.
func (*Service) AuthorizeID ¶ added in v0.2.0
func (s *Service) AuthorizeID(ctx context.Context, actor Actor, repoID uuid.UUID, need RepoRole) (RepoRole, error)
AuthorizeID is Authorize for a repository id (for objects, workspaces and other records that carry a repo id).
func (*Service) BackfillObjects ¶ added in v0.2.0
BackfillObjects queues every repository that has changesets but no recorded objects and backfills each queued repository, one at a time. Requests for a repository that is still queued backfill it on demand, so a long backfill of one repository does not hold up the others.
func (*Service) BackfillRepoObjects ¶ added in v0.2.0
func (s *Service) BackfillRepoObjects(ctx context.Context, repoID uuid.UUID, force bool, log *slog.Logger) (BackfillStats, error)
BackfillRepoObjects records the objects of every changeset tree in the repository. Unless force is set it does nothing for a repository that is not queued. Concurrent calls for one repository wait for each other.
func (*Service) BlobReader ¶ added in v0.2.0
func (s *Service) BlobReader(ctx context.Context, actor Actor, repoID uuid.UUID) (func(context.Context, hash.Hash) ([]byte, error), error)
BlobReader returns a function that reads file contents of the repository with id repoID, after checking once that actor can read it. The web UI and the MCP tools read blobs through it. Zero hashes read as empty.
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. The caller has authorized actor on repo already.
func (*Service) CheckCLIVersion ¶ added in v0.2.0
CheckCLIVersion says whether a CLI of cliVersion works with this server, and what to tell its user. Dev builds and CLIs that send no version are always ok.
func (*Service) CompleteGitHubSetup ¶ added in v0.2.0
CompleteGitHubSetup exchanges the manifest code for the App's credentials and stores them encrypted (site admins).
func (*Service) Context ¶ added in v0.2.0
func (s *Service) Context(ctx context.Context, actor Actor, repo, effort string, targets []string) (NoteContext, error)
Context returns notes on the targets, open workspaces, active claims and recent changes touching them. Without targets it returns the effort's latest notes and changes.
func (*Service) ContinueRebase ¶ added in v0.2.0
func (s *Service) ContinueRebase(ctx context.Context, actor Actor, in ContinueInput) (RebaseView, error)
ContinueRebase records the resolved tree as the stopped change's rebased version, marked as resolved by the actor, and replays the rest. It may stop again on a later change.
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 (write).
func (*Service) CreateLoginCode ¶ added in v0.2.0
CreateLoginCode returns a one-time code that signs the actor in to the web UI. It expires after LoginCodeTTL and works once.
func (*Service) CreateOrg ¶ added in v0.2.0
func (s *Service) CreateOrg(ctx context.Context, actor Actor, handle, displayName string) (Org, error)
CreateOrg creates an organization owned by the calling person.
func (*Service) CreatePerson ¶ added in v0.2.0
func (s *Service) CreatePerson(ctx context.Context, actor Actor, handle, displayName, email string, siteAdmin bool, org string) (store.Principal, string, error)
CreatePerson creates a person with a first token (site admins), optionally as a member of an organization.
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) CreateTeam ¶ added in v0.2.0
CreateTeam, DeleteTeam, SetTeamMember and RemoveTeamMember manage teams (org owners and admins).
func (*Service) CreateToken ¶ added in v0.2.0
func (s *Service) CreateToken(ctx context.Context, actor Actor, agent, name string) (store.Token, store.Principal, string, error)
CreateToken issues a new token to the caller (agent empty) or to one of the caller's agents and returns it with its secret, which is shown once.
Only people can create tokens, also for themselves. Agents can list and revoke their own tokens, but if an agent could mint tokens, a leaked agent token could create replacements that survive its revocation, so revoking it would no longer contain the leak. An agent that needs a new token asks the person it acts for.
func (*Service) DeleteTeam ¶ added in v0.2.0
func (*Service) DismissWelcome ¶ added in v0.2.0
DismissWelcome hides the welcome page from the navigation (or shows it again).
func (*Service) DropGitHubRoles ¶ added in v0.2.0
func (s *Service) DropGitHubRoles(ctx context.Context, scope GitHubRoleScope) error
DropGitHubRoles forgets cached GitHub answers in scope, so the next check asks GitHub. Webhooks call it; it never calls GitHub. An empty scope is an error, so a caller bug cannot silently keep stale roles.
func (*Service) GetChangeset ¶
func (s *Service) GetChangeset(ctx context.Context, actor Actor, repoName, ref string) (store.Repo, LogEntry, error)
GetChangeset resolves a changeset by hash, prefix or change ID (read).
func (*Service) GetEffort ¶
func (s *Service) GetEffort(ctx context.Context, actor Actor, repoName, slug string) (EffortView, error)
GetEffort loads an effort by repo name and slug (read), with its rebase in progress if there is one.
func (*Service) GetInbox ¶ added in v0.2.0
GetInbox returns what needs the caller's attention across efforts, in the repositories the caller can read.
func (*Service) GetNote ¶ added in v0.2.0
GetNote returns one note by id or an 8+ character id prefix.
func (*Service) GetObjects ¶ added in v0.2.0
func (s *Service) GetObjects(ctx context.Context, actor Actor, repo string, hashes []hash.Hash, maxBytes int) ([]Object, error)
GetObjects returns objects that are part of repo, in the order asked, stopping before maxBytes (but always returning at least one); the client asks again for the rest. An object that is not part of repo is not found, whether or not another repository has it.
func (*Service) GetOrg ¶ added in v0.2.0
GetOrg returns an organization the caller is a member of (or any, for site admins).
func (*Service) GetRebase ¶ added in v0.2.0
func (s *Service) GetRebase(ctx context.Context, actor Actor, repoName, slug string) (RebaseView, bool, error)
GetRebase returns the effort's rebase in progress, or else its latest one. Found is false when the effort was never rebased.
func (*Service) GetRepo ¶ added in v0.2.0
func (s *Service) GetRepo(ctx context.Context, actor Actor, name string) (RepoView, []store.Branch, error)
GetRepo returns a repository the caller can read, with its branches.
func (*Service) GetWorkspace ¶
func (s *Service) GetWorkspace(ctx context.Context, actor Actor, id uuid.UUID) (WorkspaceView, error)
GetWorkspace loads a workspace with its effort and repo (read).
func (*Service) GitHubApp ¶ added in v0.2.0
func (s *Service) GitHubApp(ctx context.Context) (GitHubAppInfo, error)
GitHubApp returns the server's App: ErrGitHubNotConfigured when there is none.
func (*Service) GitHubAppInstallURL ¶ added in v0.2.0
GitHubAppInstallURL is where an organization installs the App; empty without an App.
func (*Service) GitHubAppManifest ¶ added in v0.2.0
GitHubAppManifest builds the manifest of this server's App.
func (*Service) GitHubClient ¶ added in v0.2.0
GitHubClient returns the API client for the server's App: ErrGitHubNotConfigured when there is none. s.GitHub.API, when set, wins (tests).
func (*Service) GitHubLinkFinish ¶ added in v0.2.0
func (s *Service) GitHubLinkFinish(ctx context.Context, actor Actor, code, verifier string) (GitHubUser, error)
GitHubLinkFinish links the GitHub account a sign-in code is for to the signed-in person, for people created with a token before GitHub sign-in.
func (*Service) GitHubLinkOf ¶ added in v0.2.0
GitHubLinkOf returns the GitHub account linked to a person; ok is false when there is none.
func (*Service) GitHubManifestFormURL ¶ added in v0.2.0
GitHubManifestFormURL is where the manifest form posts: the person's account, or org when set. state goes along and comes back.
func (*Service) GitHubRepoToken ¶ added in v0.2.0
GitHubRepoToken returns an installation token for a repository linked to an installation of the App, for git over HTTPS (user x-access-token) and API calls; "" for other repositories, which use VX_GITHUB_TOKEN or SSH. The git bridge asks for it on every fetch, push and pull request; the client caches tokens until shortly before they expire.
func (*Service) GitHubRole ¶ added in v0.2.0
func (s *Service) GitHubRole(ctx context.Context, repo store.Repo, person store.Principal) (role RepoRole, ok bool, err error)
GitHubRole returns a person's role on a GitHub-backed repository, from the cache or GitHub. ok is false when the repository is not GitHub-backed (then vx's own roles apply). Authorize calls it. An agent is checked as its person; a service principal has no GitHub role. When GitHub cannot be reached and no answer younger than an hour is cached, err is a retryable CodeUnavailable error and role is RoleNone.
func (*Service) GitHubSettingsURL ¶ added in v0.2.0
GitHubSettingsURL is where access to a GitHub-backed repository is managed on GitHub.
func (*Service) GitHubSetupManifest ¶ added in v0.2.0
func (s *Service) GitHubSetupManifest(ctx context.Context, actor Actor) (manifest []byte, state string, err error)
GitHubSetupManifest returns the App manifest (JSON) and a state value for the manifest flow (site admins). The web page posts it to GitHub.
func (*Service) GitHubSignInEnabled ¶ added in v0.2.0
GitHubSignInEnabled reports whether people can sign in with GitHub here: the server has a GitHub App.
func (*Service) GitHubSignInFinish ¶ added in v0.2.0
func (s *Service) GitHubSignInFinish(ctx context.Context, code, verifier string) (p store.Principal, token string, isNew bool, err error)
GitHubSignInFinish completes a web sign-in: it links or creates the person (per the signup mode), syncs their organizations, and returns the person and a new web-session token. isNew is true on first sign-in.
func (*Service) GitHubSignInStart ¶ added in v0.2.0
func (s *Service) GitHubSignInStart(ctx context.Context, next string) (authorizeURL, state, verifier string, err error)
GitHubSignInStart returns the GitHub authorize URL for a web sign-in and the state and PKCE verifier the web layer keeps in a short-lived cookie. next is kept by the web layer too; it is not sent to GitHub.
func (*Service) GitHubWebURL ¶ added in v0.2.0
GitHubWebURL is GitHub's browser base URL (github.com or GHE).
func (*Service) GrantRepo ¶ added in v0.2.0
func (s *Service) GrantRepo(ctx context.Context, actor Actor, repo, subject string, role RepoRole) (RepoGrant, error)
GrantRepo gives a person or team a role on a repository (repo admins). On a GitHub-backed repository only service principals can be granted: people's roles come from GitHub.
func (*Service) HandleGitHubWebhook ¶ added in v0.2.0
func (s *Service) HandleGitHubWebhook(ctx context.Context, event, deliveryID, signature string, body []byte) error
HandleGitHubWebhook verifies and applies a webhook delivery: installations, repositories, membership and permission changes.
func (*Service) Info ¶ added in v0.2.0
func (s *Service) Info(ctx context.Context) ServerInfo
Info describes this server.
func (*Service) InstallCommand ¶ added in v0.2.0
InstallCommand is the one-liner that installs vx from the server at baseURL (PublicURL wins when set).
func (*Service) InviteGitHubLogin ¶ added in v0.2.0
func (s *Service) InviteGitHubLogin(ctx context.Context, by *store.Principal, login, note string, siteAdmin bool) (store.SignupInvite, error)
InviteGitHubLogin invites a GitHub login on behalf of by (nil: the server console, vx-server invite). siteAdmin makes the person a site admin when they sign up; only the console can ask for that.
func (*Service) InviteGitHubUser ¶ added in v0.2.0
InviteGitHubUser allows a GitHub login to sign up while sign-up is invite-only (site admins).
func (*Service) IsSiteAdmin ¶ added in v0.2.0
IsSiteAdmin reports whether actor (or, for agents, its person) is a site admin. It reads the database, so a change applies at once.
func (*Service) Land ¶
Land merges a workspace snapshot into its effort (write).
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) ListAgents ¶ added in v0.2.0
ListAgents returns the agents acting for the calling person.
func (*Service) ListClaims ¶ added in v0.2.0
func (s *Service) ListClaims(ctx context.Context, actor Actor, repo, effort string, targets []string) ([]Claim, error)
ListClaims returns the active claims of an effort, optionally only those matching targets (TargetsMatch).
func (*Service) ListEfforts ¶
func (s *Service) ListEfforts(ctx context.Context, actor Actor, repoName string, state store.EffortState) (store.Repo, []store.Effort, error)
ListEfforts lists a repo's efforts (read).
func (*Service) ListGitHubInvites ¶ added in v0.2.0
func (s *Service) ListGitHubInvites(ctx context.Context, actor Actor, all bool) ([]store.SignupInvite, error)
ListGitHubInvites lists invites (site admins): open ones, or all.
func (*Service) ListOrgs ¶ added in v0.2.0
ListOrgs lists the caller's organizations, or all of them for site admins with all set.
func (*Service) ListPeople ¶ added in v0.2.0
ListPeople lists every person on the server (site admins).
func (*Service) ListRepos ¶ added in v0.2.0
ListRepos lists the repositories the caller can read, with the caller's role on each.
func (*Service) ListShipments ¶
func (s *Service) ListShipments(ctx context.Context, actor Actor, repoName, slug string) ([]store.Shipment, error)
ListShipments returns an effort's shipments (read).
func (*Service) ListTasks ¶ added in v0.2.0
ListTasks lists an effort's tasks: not done first, then by creation.
func (*Service) ListTokens ¶ added in v0.2.0
func (s *Service) ListTokens(ctx context.Context, actor Actor, agent string) (store.Principal, []store.Token, error)
ListTokens returns the tokens of the caller (agent empty) or of one of the caller's agents, given by name ("backend") or handle ("alice/backend").
func (*Service) LoadGitHubApp ¶ added in v0.2.0
LoadGitHubApp loads the App at server start. No App is not an error; an App the server cannot open (no or another VX_SECRET_KEY) is.
func (*Service) Log ¶
func (s *Service) Log(ctx context.Context, actor Actor, repoName, slug string, limit int, withFiles bool) ([]LogEntry, error)
Log lists changes landed in an effort since its base, newest first (read).
func (*Service) MakeClaim ¶ added in v0.2.0
func (s *Service) MakeClaim(ctx context.Context, actor Actor, in ClaimInput) (Claim, []Claim, error)
MakeClaim records a claim and returns it with the active claims of others on the same targets. It never fails because of them.
func (*Service) MissingObjects ¶ added in v0.2.0
func (s *Service) MissingObjects(ctx context.Context, actor Actor, repo string, hashes []hash.Hash) ([]hash.Hash, error)
MissingObjects returns the hashes that are not part of repo yet, which the client then uploads. An object stored only for another repository is missing here: uploading it again costs little, because storage dedupes, and proves the uploader has the bytes.
func (*Service) MyGitHubInstallations ¶ added in v0.2.0
func (s *Service) MyGitHubInstallations(ctx context.Context, actor Actor) ([]GitHubInstallation, error)
MyGitHubInstallations lists the installations of the App on the actor's own GitHub account and on GitHub organizations GitHub says they are a member of. It is empty for people without a GitHub link.
func (*Service) OpenShipment ¶
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. PlanShipment checks admin on the repository.
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 (write).
func (*Service) PeekLoginCode ¶ added in v0.2.0
PeekLoginCode tells who a code would sign in, without using it up.
func (*Service) PendingCLILogin ¶ added in v0.2.0
func (s *Service) PendingCLILogin(ctx context.Context, actor Actor, userCode string) (clientName string, expires time.Time, err error)
PendingCLILogin returns the client name of a pending login by user code, for the approval page (signed-in people only).
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. Shipping needs admin on the repository.
func (*Service) PollCLILogin ¶ added in v0.2.0
func (s *Service) PollCLILogin(ctx context.Context, deviceCode string) (status, token string, p store.Principal, err error)
PollCLILogin returns the state of a login; on approval it returns the new token exactly once. Later polls return CLILoginUsed. Polling faster than the interval returns CLILoginSlowDown while the login is pending.
func (*Service) PostNote ¶ added in v0.2.0
PostNote adds a plan, decision, interface, blocker or handoff note.
func (*Service) PutObjects ¶ added in v0.2.0
func (s *Service) PutObjects(ctx context.Context, actor Actor, repo string, objs []Object) ([]hash.Hash, error)
PutObjects stores objects and records them as part of repo. The caller needs write access. The server hashes the bytes it receives, so an object only becomes part of a repository when its content was sent.
func (*Service) ReadBlob ¶ added in v0.2.0
func (s *Service) ReadBlob(ctx context.Context, actor Actor, repoID uuid.UUID, h hash.Hash) ([]byte, error)
ReadBlob reads one file's contents from a repository actor can read.
func (*Service) ReadableRepoIDs ¶ added in v0.2.0
func (s *Service) ReadableRepoIDs(ctx context.Context, actor Actor) (ids []uuid.UUID, all bool, err error)
ReadableRepoIDs returns the ids of every repository actor can read, for filtering lists. all is true when the actor can read every repository (a site admin), in which case ids is nil.
func (*Service) ReadableRepos ¶ added in v0.2.0
func (s *Service) ReadableRepos(ctx context.Context, actor Actor, org *uuid.UUID) ([]store.Repo, []RepoRole, error)
ReadableRepos lists the repositories actor can read, by name, with its role on each, in one query. org limits it to one organization's repositories; nil lists them all.
func (*Service) RebaseEffort ¶ added in v0.2.0
func (s *Service) RebaseEffort(ctx context.Context, actor Actor, repoName, slug, onto string) (RebaseView, error)
RebaseEffort replays the effort's changes, oldest first, onto the latest head of onto (default: the effort's base branch), after importing that branch's new commits. Each change is three-way merged onto the rebased chain so far with the same rules as a land, and keeps its change id, intent, author and evidence; it is marked as rebased. The effort head moves only when every change replayed, with a compare-and-swap; changes landed meanwhile are replayed too. When a change conflicts the rebase stops and waits for ContinueRebase or AbortRebase.
func (*Service) RedeemLoginCode ¶ added in v0.2.0
func (s *Service) RedeemLoginCode(ctx context.Context, code string) (store.Principal, string, error)
RedeemLoginCode uses up a code and issues a new token for its principal, to be kept in the browser's session cookie.
func (*Service) ReleaseClaims ¶ added in v0.2.0
func (s *Service) ReleaseClaims(ctx context.Context, actor Actor, id, workspaceID string) ([]Claim, error)
ReleaseClaims ends one claim (id or prefix) or all of the caller's claims for a workspace, and returns what it released.
func (*Service) RemoveMember ¶ added in v0.2.0
RemoveMember removes a person from an organization and its teams.
func (*Service) RemoveTeamMember ¶ added in v0.2.0
func (*Service) RepoAccess ¶ added in v0.2.0
func (s *Service) RepoAccess(ctx context.Context, actor Actor, repo string) ([]RepoGrant, []AccessEntry, error)
RepoAccess lists a repository's direct grants and everyone's effective role (repo admins).
func (*Service) RepoRoleOf ¶ added in v0.2.0
RepoRoleOf returns actor's role on r without checking anything, for filling my_role in responses. It is RoleNone when the actor cannot read r.
func (*Service) ResolveActor ¶
ResolveActor loads the parent of an agent principal.
func (*Service) RevokeRepo ¶ added in v0.2.0
RevokeRepo removes a direct grant (repo admins). It also works on GitHub-backed repositories, to clean up grants made before the repository was linked (they have no effect there).
func (*Service) RevokeToken ¶ added in v0.2.0
func (s *Service) RevokeToken(ctx context.Context, actor Actor, in RevokeInput) (store.Token, store.Principal, bool, error)
RevokeToken revokes one of the caller's tokens or one of their agents'. It returns the token and whether it was already revoked.
func (*Service) SaveGitHubApp ¶ added in v0.2.0
func (s *Service) SaveGitHubApp(ctx context.Context, creds GitHubAppCredentials, createdBy *uuid.UUID) error
SaveGitHubApp stores the App's credentials sealed with the server key and starts using them. CompleteGitHubSetup calls it; tests too.
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 (write).
func (*Service) SetMember ¶ added in v0.2.0
func (s *Service) SetMember(ctx context.Context, actor Actor, org, person string, role OrgRole) (Membership, error)
SetMember adds a person to an organization or changes their role. Owners and admins may; only owners make owners; the last owner stays.
func (*Service) SetTeamMember ¶ added in v0.2.0
func (*Service) ShowWelcome ¶ added in v0.2.0
ShowWelcome reports whether the welcome page is still linked from the navigation for actor's person.
func (*Service) SignupModeOrDefault ¶ added in v0.2.0
func (s *Service) SignupModeOrDefault() SignupMode
SignupModeOrDefault is the signup mode in effect: invite unless set.
func (*Service) StartCLILogin ¶ added in v0.2.0
StartCLILogin begins a browser login for a CLI (no token needed).
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 (write). For repos without an upstream it returns the branch as it is.
func (*Service) SyncGitHubAccount ¶ added in v0.2.0
SyncGitHubAccount syncs the installations on a GitHub account that have no vx organization yet: call it when the person of a GitHub user account signs in for the first time, so their personal installation comes in.
func (*Service) SyncGitHubOrgs ¶ added in v0.2.0
SyncGitHubOrgs refreshes a person's memberships in every GitHub organization with an installation of the App, and so in the linked vx organizations, and drops their cached roles. Web sign-in calls it. It asks GitHub once per organization installation.
func (*Service) SyncInstallation ¶ added in v0.2.0
SyncInstallation reads an installation's account and repositories from GitHub and creates or updates the matching vx organization and repos.
func (*Service) Token ¶ added in v0.2.0
func (s *Service) Token(ctx context.Context, actor Actor, id string) (store.Token, store.Principal, error)
Token returns a token the caller may manage, by id or unique prefix, with its owner. It changes nothing; use it to show what RevokeToken would do.
func (*Service) TokenCreateTarget ¶ added in v0.2.0
func (s *Service) TokenCreateTarget(ctx context.Context, actor Actor, agent string) (store.Principal, error)
TokenCreateTarget returns who CreateToken would create a token for, or why the caller may not. It changes nothing.
func (*Service) UpdateOrg ¶ added in v0.2.0
func (s *Service) UpdateOrg(ctx context.Context, actor Actor, handle, displayName string, defaultRole *RepoRole) (Org, error)
UpdateOrg changes an organization's display name or default repository role (owners and admins). Empty values are unchanged.
func (*Service) UpdateTask ¶ added in v0.2.0
func (s *Service) UpdateTask(ctx context.Context, actor Actor, in UpdateTaskInput) (Task, []Task, error)
UpdateTask applies an action to a task and returns it, plus the tasks a done unblocked.
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
// Warnings are problems found in the tree that would ship, checked over
// every path the effort changes on the target. They do not stop a ship.
Warnings []engine.Warning
}
ShipPlan is what shipping an effort would produce.
type ShipResult ¶
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 SignupMode ¶ added in v0.2.0
type SignupMode string
SignupMode says who may create an account by signing in with GitHub.
const ( SignupInvite SignupMode = "invite" // only invited GitHub logins (the default) SignupOpen SignupMode = "open" // anyone with a GitHub account SignupClosed SignupMode = "closed" // nobody new; existing people still sign in )
func ParseSignupMode ¶ added in v0.2.0
func ParseSignupMode(v string) (SignupMode, error)
ParseSignupMode reads a signup mode from configuration (VX_SIGNUP).
type Task ¶ added in v0.2.0
type Task struct {
ID uuid.UUID
RepoName string
EffortSlug string
EffortID uuid.UUID
Title, Body string
State string
Owner *store.Principal
DependsOn []uuid.UUID
Blocked bool // computed: some DependsOn task is not done
CreatedBy store.Principal
CreatedParent *store.Principal // the person an agent creator acts for
CreatedAt time.Time
UpdatedAt time.Time
}
Task is one item of an effort's shared plan.
type UpdateTaskInput ¶ added in v0.2.0
UpdateTaskInput changes a task: Action is take, release, done, reopen or assign (with Owner).
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.