core

package
v0.5.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: 91 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 core assembles the app: it prepares the data directory, opens and migrates the database (starting over first when the user asked to), syncs the discovered agent profiles, brings back the prompt library, the launch defaults, and the user's own scripts the database lost, adds the starter prompts, decides once whether the first-run setup shows, and builds every service the window binds to.

Core is plain Go with no desktop dependency, so the whole startup path is tested on any OS. The desktop shell only adds the window, binds Services, hears the services' events, and runs the scheduler and the sweeper.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoDataDir is returned when Options.Paths has no root directory.
	ErrNoDataDir = errors.New("the data directory is not set")

	// ErrNoHomeDir is returned when Options.Home is empty.
	ErrNoHomeDir = errors.New("the home directory is not set")
)
View Source
var ErrNotACommentReply = errors.New("a GitHub step comments only a comment's reply")

ErrNotACommentReply is a GitHub step's reply that isn't a comment's: one written for an approval or a request for changes, which a GitHub step never posts.

Functions

func BareUpdate added in v0.5.0

func BareUpdate(opts Options) *update.Bare

BareUpdate builds the update the startup dialog runs when a newer build saved the data this one can't open (update.Bare), before anything opens the database and without it: the feed and the key opts' flavor trusts, as newUpdates hands the engine, a GitHub client of its own for the release downloads alone (no token, no budget), the update cache in the data folder, and the bundle it replaces.

Types

type Core

type Core struct {
	// DB is the open, migrated database's connection pool, which every service shares.
	// It is not bound; code that seeds the database, such as the launch measurement,
	// writes through it.
	DB *sql.DB

	// The services bound to the frontend.
	Settings       *settings.Service
	Profiles       *profiles.Service
	Prompts        *prompts.Service
	LaunchDefaults *launchdefaults.Service
	Inbox          *inbox.Service
	Launcher       *launcher.Service
	Worktrees      *worktrees.Service
	Notifications  *notify.Service
	AppInfo        *appinfo.Service
	Budget         *budget.Service
	Sessions       *sessions.Service
	Review         *review.Service
	Issues         *issues.Service
	Avatars        *avatars.Service
	Integrations   *integrations.Service
	ScriptRuns     *scriptrun.Service
	Release        *release.Service
	Hooks          *hooks.Service
	Scripts        *scripts.Service
	GHThreads      *ghthreads.Service
	Backup         *backup.Service
	ServiceStatus  *svcstatus.Service
	Setup          *setup.Service
	Updates        *update.Service
	Autopilot      *autopilot.Service

	// AutopilotEngine runs the routines: it records what each matched, and starts what may
	// start, in the copy of the app that holds the lock in the data folder. The desktop
	// shell runs it as deferred work. It is not bound; the window's actions reach it
	// through Autopilot.
	AutopilotEngine *autopilot.Engine

	// ShellAutopilot is Autopilot as the desktop shell reads it, for the menu bar's
	// Autopilot group and the window's close, and Pause Autopilot, which the menu's
	// checkbox row writes through the settings. It is not bound.
	ShellAutopilot ShellAutopilot

	// ShellSettings are the settings the desktop shell reads when the app launches. They
	// are not bound.
	ShellSettings ShellSettings

	// ProfileStore holds the stored agent profiles that Profiles lists. It is not bound;
	// code that seeds the database, such as the launch measurement, writes through it.
	ProfileStore *profiles.Store

	// Scheduler refreshes the inbox on start and every five minutes once Run is called,
	// and Sweeper does the same for the automatic worktree cleanup. Each runs until its
	// context is canceled; the desktop shell runs both while the app is open.
	Scheduler *inbox.Scheduler
	Sweeper   worktrees.Sweeper

	// WatchPasses stores what the routines' searches watch, which each refresh reads after
	// the inbox's own lists, once the refresh has stored the inbox; the desktop shell runs
	// it with the scheduler, before it. Without it running no refresh reads the searches.
	// It is not bound.
	WatchPasses *inbox.WatchPasses

	// InboxRoutines is the inbox's face for Autopilot's own reads, which the refresh
	// measurement also waits on the watch passes through. It is not bound.
	InboxRoutines *inbox.Routines

	// ChecksFollower reads again, as often as Settings → Refreshing says (45 seconds by
	// default, or never), the pull requests whose checks were still running, in one
	// request, and nothing while none runs; the desktop shell runs it with the scheduler.
	ChecksFollower *inbox.ChecksFollower

	// MergeFollower reads again, a few seconds after each merge the inbox learns of, the
	// repository's other open pull requests on the branch merged into, whose merge state
	// the merge changed, and again while GitHub is still working one out; the desktop
	// shell runs it with the other work. It is not bound.
	MergeFollower *inbox.MergeFollower

	// Rereads reads again, one at a time, the item of each agent session that stops
	// working, as the Watcher asks, and each pull request a push on this Mac moved, as the
	// PushWatcher asks (one GraphQL point each), so a pull request the agent reviewed leaves
	// Review requested at once; the desktop shell runs it with the other work. It is not
	// bound.
	Rereads *inbox.Rereads

	// PushWatcher follows, while Settings → Refreshing's switch is on, the branches of the
	// inbox's pull requests in the user's clones, and hands Rereads a pull request whose
	// branch a push or a fetch moved to a commit GitHub hadn't reported for it; the desktop
	// shell runs it with the deferred work. It is not bound.
	PushWatcher *pushwatch.Watcher

	// GHThreadsSyncer reads the user's GitHub notifications into GHThreads' mirror on
	// start, then as often as the notifications' refresh setting says, never sooner than
	// GitHub asks; the desktop shell runs it after the scheduler. It is not bound.
	GHThreadsSyncer *ghthreads.Syncer

	// Watcher follows the agent sessions launches start, once Run is called; the desktop
	// shell runs it with the other work. ShellSessions are the sessions the menu bar
	// lists, and the terminals a click on one brings forward. Neither is bound.
	Watcher       *sessions.Watcher
	ShellSessions ShellSessions

	// BudgetSaver keeps the API budget across runs: it saves it soon after each change
	// once Run is called, and once more as Run's context ends. The desktop shell runs it
	// with the other work, which it stops before it closes the database.
	BudgetSaver *budget.Saver

	// Timing records the first paint.
	Timing *timing.Recorder

	// ShellEnv holds the user's login shell's environment once Deferred has read it: the
	// PATH the tools the app finds and runs come from. It is not bound.
	ShellEnv *shellenv.Reader

	// Deferred is the work kept off the cold start, which the desktop shell runs once
	// after the window's first paint (desktop.Config.Deferred). It is not bound.
	Deferred *Deferred

	// ToolFinder looks for the tools the integrations drive once the shell's environment is
	// read, again when woken, and checks for their updates once a day. The desktop shell
	// runs it as deferred work too. It is not bound.
	ToolFinder *integrations.Worker

	// Runs starts the runs (releases, hooks actions, checks, and scripts) and follows
	// them; ScriptRuns is its bound face. The desktop shell runs it as deferred work, which
	// picks up the runs left from before a restart and stops the app's own at quit, and
	// asks it before quitting whether runs are going (desktop.QuitGuard). It is not bound.
	Runs *scriptrun.Engine

	// ReleaseRefresher reads the Release page's list again behind the page when, after a
	// restart, the page was shown the list kept from the last start. The desktop shell runs
	// it as a worker. It is not bound.
	ReleaseRefresher *release.Refresher

	// ReleaseChecksFollower reads again, as often as Settings → Refreshing says (45
	// seconds by default, or never), the Release page's repositories whose newest commit's
	// checks were still running, and patches their rows into the list, quietly; nothing
	// while none runs, nor until the page has read the list from GitHub in this run. The
	// desktop shell runs it as a worker. It is not bound.
	ReleaseChecksFollower *release.ChecksFollower

	// ReleaseFollower follows each release that reached GitHub until its workflow
	// publishes it, fails, or the follow reaches its limits, and resumes the follows a quit
	// cut off. The desktop shell runs it as deferred work, beside Runs: a release Runs
	// verifies as on GitHub after a restart is handed to it once recorded. It is not bound.
	ReleaseFollower *release.Follower

	// ServiceStatusChecker checks the status pages of the services the user watches
	// (GitHub's, Claude's, OpenAI's) as often as Settings → Service status says (every 30
	// minutes by default, or never), so the window can say when a part watched has an
	// incident; ServiceStatus is its bound face. The desktop shell runs it as deferred
	// work. It is not bound.
	ServiceStatusChecker *svcstatus.Checker

	// UpdateEngine checks for, downloads, and installs the app's updates; Updates is its
	// bound face. The desktop shell attaches the Installer it restarts with (Attach) once
	// the desktop runtime is created. It is not bound.
	UpdateEngine *update.Engine

	// UpdateWorker reads how the last restart to update went, cleans up after it, and
	// runs the timed checks (a minute in, then every six hours by the wall clock). The
	// desktop shell runs it as deferred work. It is not bound.
	UpdateWorker *update.Worker

	// HooksScans holds the Hooks page's scans, which run apart from the window's calls, to
	// the app's lifetime: the app's quit ends them, and the desktop shell, which runs it as
	// a worker, waits for them before it closes the database. It is not bound.
	HooksScans hooks.Scans
	// contains filtered or unexported fields
}

Core is the assembled app: the database and every service.

func Bootstrap

func Bootstrap(ctx context.Context, opts Options) (*Core, error)

Bootstrap prepares the data directory, opens the database (backing it up and applying any pending migrations, setting it aside for a fresh one when it cannot be used, or when the user asked to start over), syncs the agent profiles found under the home directory, brings back the prompt library and the launch defaults when the database holds a new library (from the database set aside, or else from the copies kept beside it), the Autopilot routines, switched off, when it holds none (from the same places), and the user's own scripts from a database set aside, adds any starter prompt not added before, decides once whether the first-run setup shows, and builds every service. It contacts no network; the scheduler does that once started.

func (*Core) Close

func (c *Core) Close() error

Close forgets the GitHub token held in memory, drops the banners of failed runs still gathered (their notifications are kept), and closes the database.

func (*Core) Services

func (c *Core) Services() []any

Services returns the services the frontend binds to, in a stable order.

type Deferred added in v0.2.0

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

Deferred is the work kept off the app's cold start: steps run once, in order, after the window's first paint. Reading the login shell's environment comes first, since what follows runs tools on the PATH it finds.

func (*Deferred) Run added in v0.2.0

func (d *Deferred) Run(ctx context.Context)

Run runs each step in order and returns when they are done, or when ctx ends between steps. Each step logs its own outcome.

type Options

type Options struct {
	// Paths is where the database, launch files, and logs live.
	Paths appdata.Paths

	// Home is the user's home directory: profiles are discovered there, and a ~ clone
	// root expands to it.
	Home string

	// Version is the build's version; it is reported to the frontend and to GitHub as
	// part of the user agent.
	Version string

	// Release is the release version and Build the build number; both are reported to
	// the frontend.
	Release string
	Build   string

	// Clock stamps refreshes, launches, and worktree listings. It defaults to the system
	// clock.
	Clock clock.Clock

	// Events hears every service's events: the inbox, the worktree sweep, and the
	// notification log changed; the theme or the menu bar setting was stored; the window
	// painted its first frame. Without it they are dropped.
	Events event.Sink

	// Banners shows native notifications; without it the notification log is still kept.
	Banners notify.Poster

	// Runner runs external programs: the GitHub token source, the clone scan, the
	// confirmed clone of a missing repository, the terminal drivers, and the worktree
	// service all run theirs through it. It defaults to an execpath.Exec whose search
	// covers the well-known directories under Home.
	Runner execpath.Runner

	// Logger receives every service's log records. Without it they are not logged.
	Logger *slog.Logger

	// ShellStarter runs the user's login shell to read its environment, after the first
	// paint. Nil runs the real shell; tests hand in a fake, so no test runs the
	// developer's own shell.
	ShellStarter shellenv.Starter

	// Sandbox marks a run on a data directory named with --data-dir, such as the fresh one
	// magex app:fresh opens, in place of the user's own; the window says it shows test
	// data.
	Sandbox bool

	// Flavor is the kind of build (main.flavor): a release or a rehearsal updates itself,
	// and any other build never does. Release is the version it compares a newer one with.
	Flavor update.Flavor

	// UpdateFeed is the folder a rehearsal reads its releases from, and UpdateKey the raw
	// public key it trusts; a release ignores both and trusts update.ReleaseKey alone.
	UpdateFeed string
	UpdateKey  string

	// Bundle is the running app's bundle, as the desktop bootstrap finds it, or "" outside
	// one: an update is staged beside it, and the start cleans up what one leaves there.
	Bundle string
}

Options configure Bootstrap. Paths and Home are required; the rest are optional.

type ShellAutopilot added in v0.4.0

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

ShellAutopilot is Autopilot as the desktop shell reads it and asks of it (desktop.Autopilot): Autopilot's glance, for the menu bar's group and the window's close, and Pause Autopilot, which it writes through the settings' own setter, the one writer of Autopilot's settings.

func (ShellAutopilot) SetPaused added in v0.4.0

func (a ShellAutopilot) SetPaused(ctx context.Context, paused bool) error

SetPaused turns Pause Autopilot on or off, as Settings does.

func (ShellAutopilot) State added in v0.4.0

State reads Autopilot at a glance.

type ShellSessions added in v0.2.0

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

ShellSessions are the agent sessions as the desktop shell's menu bar reads them: the sessions waiting for the user, and the terminal a click on one brings forward. It implements desktop.Sessions.

func (ShellSessions) Focus added in v0.2.0

func (s ShellSessions) Focus(ctx context.Context, id string) error

Focus brings forward the terminal tab a running session is in.

func (ShellSessions) Waiting added in v0.2.0

func (s ShellSessions) Waiting(ctx context.Context) ([]sessions.Session, error)

Waiting returns the running sessions waiting for the user, oldest first.

type ShellSettings added in v0.2.0

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

ShellSettings are the settings the desktop shell reads when the app launches: the theme, whether the menu bar icon shows, the window size, the text size, and whether the first-run setup shows. It is not bound to the window, so the size, which only the shell reads on its own, stays out of the frontend's API.

func (ShellSettings) MenuBar added in v0.2.0

func (s ShellSettings) MenuBar(ctx context.Context) (bool, error)

MenuBar returns whether the menu bar icon shows.

func (ShellSettings) SetupPending added in v0.3.0

func (s ShellSettings) SetupPending(ctx context.Context) (bool, error)

SetupPending reports whether the first-run setup shows when the window opens: the window then opens on it, and the shell holds the question to allow banners until it ends.

func (ShellSettings) TextSize added in v0.2.0

func (s ShellSettings) TextSize(ctx context.Context) (settings.TextSize, error)

TextSize returns the text size the window opens at.

func (ShellSettings) Theme added in v0.2.0

func (s ShellSettings) Theme(ctx context.Context) (settings.Theme, error)

Theme returns the stored theme, or the default.

func (ShellSettings) WindowSize added in v0.2.0

func (s ShellSettings) WindowSize(ctx context.Context) (settings.WindowSize, error)

WindowSize returns the size the window opens at.

Jump to

Keyboard shortcuts

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