setup

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 16 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 setup is the first-run setup's service: where the user is in it and whether it is done, and the checks its steps make that no other service makes for them: whether the GitHub CLI's sign-in gives the inbox what it needs, which terminals are installed, and how many of the user's clones use the tools the Tools step offers. It also starts a reset the user asked for, which the next start carries out.

It keeps its state in the setup.* preferences, which it alone writes: setup.done and setup.step. They are the window's memory, so a backup never holds them. Adopt decides, once per database, whether the setup shows at all: an install from before it, whose inbox ever signed in, is adopted as done, and a fresh database, as a new install, a reset, or a sandbox has, shows it.

It reaches every other part of the app through the narrow interfaces it declares, which core adapts: the GitHub sign-in through Account, the clones through Clones, the runs through Runs, and the backup saved before a reset through Saver.

Index

Constants

View Source
const (
	// FixInstall installs the GitHub CLI with Homebrew.
	FixInstall = "brew install gh"

	// FixSignIn signs the GitHub CLI in to github.com.
	FixSignIn = "gh auth login"

	// FixScopes grants the scopes the inbox needs.
	FixScopes = "gh auth refresh -s repo,read:org"
)

The commands the GitHub step offers, one for each state but ready and unreachable.

View Source
const (
	// KeyDone says the setup is done: the user finished or skipped it, or Adopt adopted an
	// install from before it as done.
	KeyDone = "setup.done"

	// KeyStep is the step the user was on, where the setup opens again.
	KeyStep = "setup.step"
)

The setup.* preferences, which the setup alone writes.

View Source
const ResetWord = "reset"

ResetWord is what the user types to confirm a reset.

Variables

View Source
var (
	// ErrNotConfirmed is returned for a reset the user didn't confirm by typing ResetWord.
	ErrNotConfirmed = errors.New("the reset was not confirmed")

	// ErrRunsGoing is returned for a reset asked for while runs are going in the app.
	ErrRunsGoing = errors.New("runs are going in the app")

	// ErrNoResetRequest is returned when the Service has nowhere to write a reset request.
	ErrNoResetRequest = errors.New("the reset request's path is not set")
)
View Source
var ErrUnknownStep = errors.New("unknown setup step")

ErrUnknownStep is returned for a step the setup doesn't have.

Functions

This section is empty.

Types

type Account

type Account interface {
	SignIn(ctx context.Context) (github.SignIn, error)
}

Account reads who the GitHub CLI's token belongs to, and the scopes the token reports: core adapts the token source and the shared client (github.WithToken and FetchSignIn). Its errors are the token source's and the client's, which GitHub tells apart.

type CLI

type CLI interface {
	GHVersion(ctx context.Context) (version string, installed bool)
}

CLI reads the GitHub CLI's version, as Settings → About shows it: core adapts appinfo's ToolVersions. installed is false when gh isn't found.

type Clones

type Clones interface {
	Clones(ctx context.Context) ([]string, error)
}

Clones lists the folders of the user's clones, in every repository location, with the locations that didn't answer in time skipped: core adapts the settings' locations and the shared localrepos.Reader.

type Config

type Config struct {
	// Memory keeps the setup's state.
	Memory Memory

	// Account and CLI read the GitHub step's state.
	Account Account
	CLI     CLI

	// Terminals lists the terminals launches can open in, and whether each is installed
	// (core: the terminal registry's Installed, over /Applications and ~/Applications).
	Terminals func() []terminal.Choice

	// Clones lists the user's clones, whose markers Signals counts.
	Clones Clones

	// Runs holds a reset back while runs are going, and Saver saves the setup before one.
	Runs  Runs
	Saver Saver

	// ResetRequest is where Reset writes its request (appdata.Paths.ResetRequest).
	ResetRequest string

	// Clock stamps the reset request. Nil is the system clock.
	Clock clock.Clock

	// Events hears an event.SetupFinished when the setup ends, and an
	// event.ResetRequested once a reset is asked for.
	Events event.Sink

	// Logger hears what a check could not read. Nil discards.
	Logger *slog.Logger
}

Config holds a Service's dependencies. Memory is required; a check whose dependency is missing reads as having found nothing.

type GitHub

type GitHub struct {
	// State is where the sign-in stands.
	State GitHubState `json:"state"`

	// Login and Name are the account's login and display name, for a token GitHub took.
	Login string `json:"login"`
	Name  string `json:"name"`

	// Scopes are the scopes the token reports, in its order; empty for one that reports
	// none.
	Scopes []string `json:"scopes"`

	// Missing are the scopes the inbox needs that the token lacks, for GitHubMissingScopes.
	Missing []string `json:"missing"`

	// Unverified reports a token that reports no scopes, such as a fine-grained one, whose
	// access can't be checked: the inbox may miss some items.
	Unverified bool `json:"unverified"`

	// Projects says whether the token reads GitHub Projects.
	Projects ProjectAccess `json:"projects"`

	// CLIVersion is the GitHub CLI's version, or "" when it isn't installed or its version
	// can't be read.
	CLIVersion string `json:"cliVersion"`

	// Fix is the command that fixes the state, run in a terminal, or "" for none.
	Fix string `json:"fix"`

	// Message says what is wrong, in words the window shows, or "" when ready.
	Message string `json:"message"`
}

GitHub is the GitHub step's check of the sign-in the app borrows from the GitHub CLI. No slice it holds is nil.

type GitHubState

type GitHubState string

GitHubState is where the GitHub CLI's sign-in stands, as the GitHub step shows it.

const (
	// GitHubReady is a sign-in whose token reads everything the inbox needs, or reports no
	// scopes to check (a fine-grained token).
	GitHubReady GitHubState = "ready"

	// GitHubNoCLI is the GitHub CLI not installed, or not where the app looks.
	GitHubNoCLI GitHubState = "no_cli"

	// GitHubSignedOut is the GitHub CLI installed but not signed in to github.com.
	GitHubSignedOut GitHubState = "signed_out"

	// GitHubMissingScopes is a token without the repo or read:org scope.
	GitHubMissingScopes GitHubState = "missing_scopes"

	// GitHubRefused is a token GitHub refused: revoked or expired.
	GitHubRefused GitHubState = "refused"

	// GitHubUnreachable is GitHub not answering, or answering in a way the app can't read.
	GitHubUnreachable GitHubState = "unreachable"
)

Where the sign-in stands.

type Memory

type Memory interface {
	GetMany(ctx context.Context, keys ...string) (map[string]string, error)
	SetMany(ctx context.Context, values map[string]string) error
}

Memory is where the setup keeps its state, the setup.* preferences: a *prefs.Store.

type ProjectAccess

type ProjectAccess string

ProjectAccess says whether the token reads GitHub Projects, which the inbox shows when it can.

const (
	// ProjectsGranted is a token with read:project, or project, which includes it.
	ProjectsGranted ProjectAccess = "granted"

	// ProjectsMissing is a token that reports its scopes, neither of them among them.
	ProjectsMissing ProjectAccess = "missing"

	// ProjectsUnverified is a token that reports no scopes, or one the step didn't read.
	ProjectsUnverified ProjectAccess = "unverified"
)

What the token says of GitHub Projects.

type ResetStarted

type ResetStarted struct {
	// SavedTo is the copy of the user's setup saved first, with ~ for home, or "" when
	// there was nowhere to save it.
	SavedTo string `json:"savedTo"`
}

ResetStarted says what Reset did before it asked for the reset.

type Runs

type Runs interface {
	Active() bool
}

Runs says whether runs are going in the app, which quitting for a reset would stop: *scriptrun.Engine.

type Saver

type Saver interface {
	SaveBeforeReset(ctx context.Context) (string, error)
}

Saver saves the user's whole setup before a reset, and returns where, with ~ for home: *backup.Saver.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the setup the window binds.

func NewService

func NewService(cfg Config) *Service

NewService returns a Service over cfg.

func (*Service) Finish

func (s *Service) Finish(ctx context.Context) (State, error)

Finish marks the setup done, as the user finished or skipped it, and returns the state: the window shows the inbox from now on, and the desktop shell, which an event.SetupFinished tells, asks to allow notification banners if it hasn't. Its next run (Restart) opens on Welcome.

func (*Service) GitHub

func (s *Service) GitHub(ctx context.Context) (GitHub, error)

GitHub checks the sign-in the app borrows from the GitHub CLI, with one GraphQL point when gh lends a token: who it belongs to and whether its scopes give the inbox what it needs. A problem is a state with a command that fixes it, never an error; only a check the window gave up on is.

func (*Service) Reset

func (s *Service) Reset(ctx context.Context, confirmation string) (ResetStarted, error)

Reset asks for a fresh start, as Settings → About → Reset asks once the user typed ResetWord: it saves the user's whole setup into the backups folder first, refusing the reset when that fails, writes the request that the next start carries out, and tells the desktop shell (event.ResetRequested), which quits and opens the app again. The next start sets the database aside and starts a fresh one, bringing back the prompts, the launch defaults, and the user's own scripts. It refuses, in words the window shows, a confirmation that isn't ResetWord, and a reset while runs are going in the app, which the quit would stop.

func (*Service) Restart

func (s *Service) Restart(ctx context.Context) (State, error)

Restart opens the setup again from Welcome, as Settings → About's Run setup again asks, and returns the state. Every step shows what is set already, so it doubles as a check of the setup.

func (*Service) SetStep

func (s *Service) SetStep(ctx context.Context, step Step) (State, error)

SetStep remembers that the user is on step, so quitting part way through opens the setup there again, and returns the state with it.

func (*Service) Signals

func (s *Service) Signals(ctx context.Context) (Signals, error)

Signals counts the user's clones, in every repository location, that hold each sign the Tools step looks for. It checks a few fixed paths in each clone with lstat alone: no git, no file read, no folder listed, so it is quick and touches nothing a clone controls. A location that doesn't answer in time is skipped, as every listing skips it.

func (*Service) State

func (s *Service) State(ctx context.Context) (State, error)

State returns where the setup stands. A database whose state Adopt never stored, which only a failed write leaves, reads as done, so a passing problem never traps a user in the setup.

func (*Service) Terminals

func (s *Service) Terminals(context.Context) []TerminalChoice

Terminals returns the terminals launches can open in, in the settings' order, and whether each is installed, so the Agents step never leaves the user on one that isn't. It reads only whether each app is there; a system without terminal support has none.

type Signals

type Signals struct {
	// Clones is how many clones were looked at.
	Clones int `json:"clones"`

	// GoModules counts the clones with a go.mod at their root.
	GoModules int `json:"goModules"`

	// MageX counts the clones set up for mage-x: its env file, its .mage.yaml, or a
	// magefiles folder.
	MageX int `json:"mageX"`

	// GoPreCommit counts the clones set up for go-pre-commit: its env file, or the older
	// .github/.env.base.
	GoPreCommit int `json:"goPreCommit"`

	// Fortress counts the clones whose CI is go-fortress's: its main workflow.
	Fortress int `json:"fortress"`
}

Signals counts the user's clones that hold each sign the Tools step looks for, so it shows only when the tools it offers fit, and says why it is suggested.

type State

type State struct {
	// Done reports that the setup is done: the window shows the inbox, not the setup.
	Done bool `json:"done"`

	// Step is the step the setup opens on: the one the user was on when they left it, or
	// Welcome before any.
	Step Step `json:"step"`
}

State is where the setup stands.

func Adopt

func Adopt(ctx context.Context, memory Memory, viewer Viewer) (State, error)

Adopt decides, once per database, whether the setup shows, and returns the state. While the setup has stored nothing, as on the first start of a build that has it, it stores the setup done when the inbox ever signed in, which only an install from before the setup has (a failed refresh never clears the account), and not done otherwise, as on a new install, after a reset, or in a sandbox. Once decided it never decides again, so a user who signs in outside the app and quits on Welcome still sees the setup at the next start. Core calls it once, at startup, before anything refreshes; it is never bound.

type Step

type Step string

Step is one of the setup's steps.

const (
	StepWelcome       Step = "welcome"
	StepGitHub        Step = "github"
	StepClones        Step = "clones"
	StepAgents        Step = "agents"
	StepNotifications Step = "notifications"
	StepTools         Step = "tools"
	StepFinish        Step = "finish"
)

The steps, in their order. Tools shows only when the user's tools or clones make it fit, which the window decides.

func Steps

func Steps() []Step

Steps returns every step, in order.

func (Step) Valid

func (s Step) Valid() bool

Valid reports whether s is one of the steps.

type TerminalChoice

type TerminalChoice struct {
	// ID is the terminal, as the terminal setting stores it, and Name what it is called.
	ID   terminal.ID `json:"id"`
	Name string      `json:"name"`

	// Installed reports that the terminal is on this Mac. Terminal always is.
	Installed bool `json:"installed"`
}

TerminalChoice is a terminal launches can open in, as the Agents step offers it.

type Viewer

type Viewer interface {
	ViewerLogin(ctx context.Context) (string, error)
}

Viewer reads the account the inbox last signed in with, "" before its first refresh: *inbox.Store.

Jump to

Keyboard shortcuts

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