integrations

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: 43 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 integrations finds the tools the app drives, mage-x's magex and go-pre-commit, says what the settings show about each, and checks once a day for a newer release.

Each tool is a Definition. Detection looks for it on the user's login shell's PATH (shellenv), then in the well-known tool folders and go install's, runs each copy's --version with the environment every run of the tool gets (Definition.RunEnv: the shell's, quiet, and with git's prompts off), and works out where each came from. It runs after the window's first paint, never on the cold start, and its result is kept in tools.<id>.seen, which List serves at once, marked as checking, until this run's detection finishes. The latest releases come from one GitHub query a day, kept in tools.<id>.latest. This package writes the tools.* preferences, and only reads the integrations.* ones, which the settings write.

Index

Constants

View Source
const (
	ActionInstall   = "install"
	ActionUpdate    = "update"
	ActionReinstall = "reinstall"
)

The install plan's actions.

View Source
const StepUpdating = "updating"

StepUpdating is an install's step while the tool's own updater runs.

Variables

View Source
var (
	// ErrSignedOut is returned by Releases when no one is signed in to GitHub. Core's
	// adapter returns it for the GitHub CLI's own signed-out errors.
	ErrSignedOut = errors.New("not signed in to GitHub")

	// ErrInstallRefused is returned for an install the plan doesn't allow, with the plan's
	// reason as its message.
	ErrInstallRefused = errors.New("the install was refused")

	// ErrNotACopy is returned by Trash and Reveal for a path that isn't a copy of the tool
	// the app found.
	ErrNotACopy = errors.New("not a copy of the tool the app found")
)
View Source
var ErrAutomationDenied = errors.New("not allowed to control Finder")

ErrAutomationDenied is returned by Trash when the user hasn't let the app control Finder; the window offers Reveal in Finder instead.

View Source
var ErrNoVersion = errors.New("no version in the output")

ErrNoVersion is returned when a tool's output holds no version this package can read.

Functions

func Effective

func Effective(sw integrationprefs.Switch, usable bool) bool

Effective reports whether an integration is on: on and off are what the user chose, and automatic is on while the tool can be used.

func ScriptsOn

func ScriptsOn(sw integrationprefs.Switch, mageXOn, goPreCommitOn bool) bool

ScriptsOn reports whether the scripts are on: as the user chose, or, while automatic, while either tool is on.

Types

type Asset

type Asset struct {
	Name   string `json:"name"`
	URL    string `json:"url"`
	Size   int64  `json:"size"`
	Digest string `json:"digest"`
}

Asset is one file of a release.

type Config

type Config struct {
	// Prefs reads the integrations' settings and keeps the tools' state.
	Prefs *prefs.Store

	// Env is the user's login shell's environment.
	Env ShellEnv

	// Releases looks up the latest releases. Without it, no update is ever checked.
	Releases Releases

	// Home is the user's home folder, for the well-known tool folders and ~ in paths.
	Home string

	// Clock stamps detections and checks. It defaults to the system clock.
	Clock clock.Clock

	// Events hears an event.ToolsUpdated whenever what List returns changed.
	Events event.Sink

	// Logger gets one record per detection and per failed check.
	Logger *slog.Logger

	// Definitions are the tools. They default to Definitions().
	Definitions []Definition

	// Runner returns what runs a tool with env, the whole environment it gets. It
	// defaults to execpath.Exec, with stdin from /dev/null; tests hand in one that runs
	// nothing.
	Runner func(env []string) execpath.Runner

	// DB holds tool_installs, the record of what the app installed. Without it no copy
	// reads as installed by the app, and nothing is recorded.
	DB *sql.DB

	// Installer installs releases. Without it, nothing is installed.
	Installer *toolinstall.Installer

	// Runs runs a tool's own updater, for a copy that can update itself, as a run the
	// window follows. Without it, no tool updates itself: the Installer does every update.
	Runs Runs

	// Locks is the app's one set of clone locks, which the runs hold too: the Installer
	// holds the folder it places a program in, so it never meets a tool's own update there.
	// Without it, the service keeps a set of its own.
	Locks *clonelock.Set

	// Commands runs Finder's scripts and open, for the Trash and Reveal in Finder.
	Commands execpath.Runner

	// InUse reports whether a run is using a tool, which an install then waits for.
	// Without it, none is.
	InUse func(id integrationprefs.ID) bool

	// GOOS and GOARCH pick a release's archive. They default to this build's.
	GOOS, GOARCH string
}

Config holds a Service's dependencies. Prefs and Env are required.

type Copy

type Copy struct {
	// Path is where it was found, and DisplayPath the same with ~ for the home folder.
	Path        string `json:"path"`
	DisplayPath string `json:"displayPath"`

	// Link reports a symbolic link, and Target where it points, with ~; the installer
	// never replaces a link.
	Link   bool   `json:"link"`
	Target string `json:"target"`

	// Runs reports that it ran and printed its version; Error is its first error line
	// when it didn't.
	Runs    bool    `json:"runs"`
	Version Version `json:"version"`
	Error   string  `json:"error"`

	// Source is where it came from.
	Source Source `json:"source"`

	// OnPath reports that the user's shell finds it on its PATH.
	OnPath bool `json:"onPath"`

	// InstalledAt and Archive say, for a copy the app installed, when it did and from which
	// release archive.
	InstalledAt string `json:"installedAt"`
	Archive     string `json:"archive"`

	// Shadowing reports the copy the user's terminal runs when it isn't the one in use.
	Shadowing bool `json:"shadowing"`
}

Copy is one copy of a tool on this machine.

type CopyFacts

type CopyFacts struct {
	// Path is the copy in use, absolute, or "" when there is none; Version is its version
	// as printed, without a leading v.
	Path    string
	Version string

	// State is what the settings say of it, and Off reports the user turned the tool off:
	// only their switch says so, since automatic is on whenever the copy can be used, and a
	// copy too old to use is too old, not off.
	State State
	Off   bool

	// Features are the upstream changes this copy has, sorted (Definition.FeaturesOf).
	Features []Feature
}

CopyFacts is what a page that runs a tool knows of the copy in use: where it is, its version, what the settings say of it, and what it can do. Release, Hooks, and Repo scripts each embed it in their own ToolFacts, beside what only that page needs.

func CopyFactsOf

func CopyFactsOf(def Definition, tool Tool) CopyFacts

CopyFactsOf reads the facts of the copy in use from what the settings show of tool, as def, its definition, describes it. Features is never nil.

func (CopyFacts) Has

func (c CopyFacts) Has(f Feature) bool

Has reports whether the copy in use has feature f; one that can't be used has none.

func (CopyFacts) Key

func (c CopyFacts) Key() string

Key names the copy in use, for what a page keeps of what it read with it: its path and its version.

func (CopyFacts) Usable

func (c CopyFacts) Usable() bool

Usable reports a copy a page can run: on, found, and new enough.

type Definition

type Definition struct {
	// ID is the tool's integration, which keys its preferences.
	ID integrationprefs.ID

	// Name is what the settings call it, Binary its program's name, and Repo where its
	// releases live.
	Name   string
	Binary string
	Repo   repo.Name

	// Purpose is the settings card's one line on what it does for the user.
	Purpose string

	// VersionArgs make it print its version, which ParseVersion reads.
	VersionArgs  []string
	ParseVersion func([]byte) (Version, error)

	// Asset names a release's archive for an OS and architecture, and Checksums the
	// release's checksums file. Both take the version without a leading v.
	Asset     func(version, goos, goarch string) string
	Checksums func(version string) string

	// QuietEnv is set on every run of it: no update banners, no color.
	QuietEnv map[string]string

	// UpdateArgs make it update itself, in place, from its latest release, once the copy
	// has FeatureSelfUpdate.
	UpdateArgs []string

	// MinVersion is the oldest version the app drives.
	MinVersion string

	// Features maps each upstream change to the first release that has it.
	Features map[Feature]string
}

Definition describes one tool the app can find, install, and drive. Adding a tool is one more Definition and, if it gets a page, one more page.

func Definitions

func Definitions() []Definition

Definitions returns every tool the app knows, in the order the settings list them.

func GoPreCommit

func GoPreCommit() Definition

GoPreCommit is go-pre-commit, which installs and runs the pre-commit checks.

func MageX

func MageX() Definition

MageX is mage-x, whose magex tags and pushes the user's releases.

func (Definition) FeaturesOf

func (d Definition) FeaturesOf(v Version) []Feature

FeaturesOf lists, sorted, every feature a copy at version v has (Has); the list is never nil.

func (Definition) Has

func (d Definition) Has(f Feature, v Version) bool

Has reports whether a copy at version v has feature f: the feature is released and v is that release or newer. A development build has none, since its version can't say.

func (Definition) RunEnv

func (d Definition) RunEnv(base []string, runsIn integrationprefs.RunsIn) []string

RunEnv is the environment a run of the tool gets (§5.5). In the app it is base, the login shell's, with the tool's quiet settings and git's terminal prompts off, since no one can answer one there, each in place of base's own. In the terminal it is only the quiet settings the script exports, colors kept: the terminal's own shell sets the rest up.

type Feature

type Feature string

Feature is an upstream change a tool gained in some release, which the app uses once the copy it finds has it.

const (
	// FeaturePushFails is magex failing version:bump when the push it was asked for
	// didn't happen.
	FeaturePushFails Feature = "pushFails"

	// FeatureExpect is magex's expect=, which refuses to tag any version but the one
	// named.
	FeatureExpect Feature = "expect"

	// FeatureBumpJSON is magex's json=true, which reports version:bump's outcome as one
	// JSON line.
	FeatureBumpJSON Feature = "bumpJson"

	// FeatureFastForwardPull is magex's ff-only, which updates the branch by fast-forward
	// only and refuses to tag otherwise.
	FeatureFastForwardPull Feature = "fastForwardPull"

	// FeatureVerifiedTools is go-pre-commit installing its own tools from checksum-verified
	// releases, with an opt-out.
	FeatureVerifiedTools Feature = "verifiedTools"

	// FeatureInstallExitCode is go-pre-commit's install exiting non-zero when it skips a
	// hook.
	FeatureInstallExitCode Feature = "installExitCode"

	// FeatureStatusJSON is go-pre-commit's status --json.
	FeatureStatusJSON Feature = "statusJson"

	// FeatureRunJSON is go-pre-commit's run --json.
	FeatureRunJSON Feature = "runJson"

	// FeatureSelfUpdate is a tool's own updater, which the app runs to update a copy that
	// can update itself: it downloads the latest release, checks it against the release's
	// SHA-256 checksums, and swaps it in for the copy it runs as, with a rename. Older
	// updaters put the new copy elsewhere, or ran go install.
	FeatureSelfUpdate Feature = "selfUpdate"
)

The features the app looks for.

type InstallPlan

type InstallPlan struct {
	// Action is install, update, or reinstall.
	Action string `json:"action"`

	// Version and Archive are the latest release's version and its archive for this Mac,
	// "" until the release is known.
	Version string `json:"version"`
	Archive string `json:"archive"`

	// TargetDir and Target are where the program would go, with ~.
	TargetDir string `json:"targetDir"`
	Target    string `json:"target"`

	// Replaces is the version of the copy it would replace, and ReplacesPath where, or
	// "" when it replaces none. Foreign reports a copy the app didn't install, which the
	// user confirms replacing first.
	Replaces     string `json:"replaces"`
	ReplacesPath string `json:"replacesPath"`
	Foreign      bool   `json:"foreign"`

	// Blocked says why it can't be done, as a sentence, or "" when it can; BrewCommand is
	// the command that updates a Homebrew copy.
	Blocked     string `json:"blocked"`
	BrewCommand string `json:"brewCommand"`

	// Updater, for an update of a copy that updates itself, is the tool's own update
	// command, as the window shows it ("~/.local/bin/magex update:install"), which the
	// update runs in place of the app's download. It is "" when the app installs the
	// release itself.
	Updater string `json:"updater"`
}

InstallPlan says what installing the tool would do, for the card's button and the install dialog, or why it can't.

type InstallProgress

type InstallProgress struct {
	// Step is downloading, verifying, trying, or installing, updating while the tool's own
	// updater runs, or "" when none runs.
	Step  string `json:"step"`
	Done  int64  `json:"done"`
	Total int64  `json:"total"`
}

InstallProgress is how far an install of the tool has got.

type InstallResult

type InstallResult struct {
	// Message says what was done, as in "Installed go-pre-commit 1.13.1 in ~/.local/bin";
	// it is "" for an update the tool runs itself, whose run says so as it ends.
	Message string `json:"message"`

	// Run is the run of the tool's own updater an update started, which the window shows,
	// or 0 when the app installed the release itself.
	Run int64 `json:"run"`

	Tools Tools `json:"tools"`
}

InstallResult is what an install did, and the tools as they are after it.

type Latest

type Latest struct {
	// Version is its version, without a leading v, or "" when the tool has no release.
	Version string `json:"version"`
	URL     string `json:"url"`

	// CheckedAt is when it was checked.
	CheckedAt string `json:"checkedAt"`
}

Latest is a tool's latest release, as the daily check last found it.

type Release

type Release struct {
	Tag         string
	URL         string
	PublishedAt time.Time
	Assets      []Asset
}

Release is a repository's latest release.

type Releases

type Releases interface {
	LatestReleases(ctx context.Context, repos []repo.Name) (map[string]Release, error)
}

Releases looks up repositories' latest releases on GitHub, keyed by each repository's Key. A repository with no release is left out. Core adapts the GitHub client to it.

type Runs

type Runs interface {
	Start(ctx context.Context, spec scriptrun.Spec) (int64, error)

	// Updating returns the ID of the tool's own update going now, however it started, one
	// from before the app restarted included, or 0.
	Updating(tool string) int64
}

Runs starts the runs of the tools' own updaters and follows them to their end. *scriptrun.Engine implements it.

type SelfUpdate

type SelfUpdate struct {
	// Run is the run's ID, or 0 when the tool hasn't updated itself since the app started,
	// and Running reports that it goes now.
	Run     int64 `json:"run"`
	Running bool  `json:"running"`

	// Updated reports that it ended with the copy at a newer version, Failed that it ended
	// any way but updated or already up to date, and Message says what it did, as "Updated
	// magex to 1.30.0" or "magex is already up to date (1.30.0)", or why it failed, once the
	// run ended and the tool was looked for again; until then all three are unset.
	Updated bool   `json:"updated"`
	Failed  bool   `json:"failed"`
	Message string `json:"message"`
}

SelfUpdate is the last run of a tool's own updater since the app started, or one the runner follows from before it restarted, as the settings card follows it.

type Service

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

Service says what the settings show about each tool, and looks again when asked.

func NewService

func NewService(cfg Config) *Service

NewService returns a Service over cfg.

func (*Service) CheckAgain

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

CheckAgain reads the user's shell's environment again and looks for every tool again, and meanwhile checks for newer releases unless that was done in the last ten minutes, then returns what the settings show.

func (*Service) Install

func (s *Service) Install(ctx context.Context, id integrationprefs.ID) (InstallResult, error)

Install installs the latest release of a tool that has no copy, or whose copy it replaces, as its plan says, and returns what it did.

func (*Service) List

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

List returns what the settings show about every tool. It never waits for a detection: until this run's first one ends, it serves the last one kept, and while one is asked for or runs, the last one found; either way each tool is marked as checking, and an event.ToolsUpdated follows when the detection ends. A detection more than ten minutes old asks for a new one.

func (*Service) Reinstall

func (s *Service) Reinstall(ctx context.Context, id integrationprefs.ID) (InstallResult, error)

Reinstall installs the latest release again, as over a copy that won't run.

func (*Service) Reveal

func (s *Service) Reveal(ctx context.Context, id integrationprefs.ID, path string) error

Reveal shows a copy of a tool in Finder: one detection found, never anything else.

func (*Service) Trash

func (s *Service) Trash(ctx context.Context, id integrationprefs.ID, path string) (Tools, error)

Trash moves a copy of a tool to the Trash through Finder, so Finder's Put Back works: one the app installed, or another copy detection found, never anything else. The path is passed to the script as an argument, never written into it. When the user hasn't let the app control Finder, it returns ErrAutomationDenied.

func (*Service) Update

Update updates the tool's copy to its latest release, as its plan says: a copy that updates itself runs its own updater, as a run whose ID the result holds, and any other gets the latest release installed over it.

type ShellEnv

type ShellEnv interface {
	// Env returns the environment, and whether it was read; until it was, the app's own,
	// with the well-known tool folders on PATH.
	Env() ([]string, bool)

	// Ready is closed once the first read has ended.
	Ready() <-chan struct{}

	// Read reads it again.
	Read(ctx context.Context) error
}

ShellEnv is the user's login shell's environment. *shellenv.Reader implements it.

type Source

type Source string

Source says where a copy of a tool came from.

const (
	// SourceApp is a copy the app installed: the newest install recorded at its path has
	// its SHA-256.
	SourceApp Source = "app"

	// SourceHomebrew is a copy inside a Homebrew Cellar.
	SourceHomebrew Source = "homebrew"

	// SourceGoInstall is a copy in $GOBIN or $GOPATH/bin, where go install puts one.
	SourceGoInstall Source = "goInstall"

	// SourceDevelopment is a copy built from a working copy: its version is dev, a
	// pseudo-version, or dirty.
	SourceDevelopment Source = "development"

	// SourceRelease is any other copy, which a GitHub release put there.
	SourceRelease Source = "release"
)

The sources.

type State

type State string

State is what the settings card says about a tool.

const (
	// StateFound is a copy that runs and is new enough.
	StateFound State = "found"

	// StateUpdate is a copy that runs, is new enough, and has a newer release.
	StateUpdate State = "update"

	// StateTooOld is a copy older than the oldest version the app drives.
	StateTooOld State = "tooOld"

	// StateWontRun is a copy that is there but didn't run or print its version.
	StateWontRun State = "wontRun"

	// StateMissing is no copy at all.
	StateMissing State = "missing"
)

The states.

func (State) Usable

func (s State) Usable() bool

Usable reports a state in which the tool can be used.

type Tool

type Tool struct {
	ID          integrationprefs.ID `json:"id"`
	Name        string              `json:"name"`
	Binary      string              `json:"binary"`
	Purpose     string              `json:"purpose"`
	Repo        string              `json:"repo"`
	ReleasesURL string              `json:"releasesUrl"`
	MinVersion  string              `json:"minVersion"`

	// Switch is how the user set it, and On whether it is on: what the user chose, or,
	// while automatic, whether it can be used (see Effective).
	Switch integrationprefs.Switch `json:"switch"`
	On     bool                    `json:"on"`

	// State is what the card says, and Checking reports a state from the last run while
	// the tool is looked for again.
	State    State `json:"state"`
	Checking bool  `json:"checking"`

	// Copy is the copy in use, zero when it is missing, and Others every other copy found.
	Copy   Copy   `json:"copy"`
	Others []Copy `json:"others"`

	// Chosen is the copy the user chose, with ~, or "" for the one their shell finds;
	// ChosenMissing reports one that is no longer there.
	Chosen        string `json:"chosen"`
	ChosenMissing bool   `json:"chosenMissing"`

	// Latest is the tool's latest release, zero until it was checked.
	Latest Latest `json:"latest"`

	// Install says what installing it would do, or why it can't; Progress is how far a
	// running install has got, with an empty step when none runs.
	Install  InstallPlan     `json:"install"`
	Progress InstallProgress `json:"progress"`

	// SelfUpdate is the last run of the tool's own updater since the app started.
	SelfUpdate SelfUpdate `json:"selfUpdate"`

	// CheckedAt is when the tool was last looked for, or "" when it never was.
	CheckedAt string `json:"checkedAt"`
}

Tool is what the settings show about one tool.

type Tools

type Tools struct {
	Tools []Tool `json:"tools"`

	// ShellChecked reports that a read of the user's login shell's environment has ended,
	// and ShellRead that one succeeded; when it failed, the tools are looked for with a
	// basic PATH, and the settings say so.
	ShellChecked bool `json:"shellChecked"`
	ShellRead    bool `json:"shellRead"`
}

Tools is what the settings show about every tool.

type Verifier

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

Verifier settles a tool's own update from before the app restarted as one that just ended: once the shell's environment is read, it looks for the tools again, reads the copy's version from that look, and keeps a copy the app installed recorded as the app's. Core registers it with the runner for scriptrun.KindUpdate.

func NewVerifier

func NewVerifier(s *Service) Verifier

NewVerifier returns the Verifier of s's tools' own updates.

func (Verifier) Verify

Verify gives a tool's own update from before the app restarted its output reader and its Finish. A record whose intent can't be read, or names no tool the app knows, gets none: the runner's own outcome stands.

type Version

type Version struct {
	// Raw is the version as printed, without a leading v: "1.29.5", "dev", or a Go
	// pseudo-version such as "1.29.6-0.20261105041738-9a61f25f00aa+dirty".
	Raw string `json:"raw"`

	// Commit is the commit it was built from, as printed, or "".
	Commit string `json:"commit"`

	// Built is when it was built, as printed, or "".
	Built string `json:"built"`
}

Version is a tool's version as it reported it.

func ParseGoPreCommitVersion

func ParseGoPreCommitVersion(out []byte) (Version, error)

ParseGoPreCommitVersion reads `go-pre-commit --version`: "go-pre-commit version 1.13.1 (commit: <sha>, built: <date>)". A go install build prints v1.13.1 and "built: go-install".

func ParseMagexVersion

func ParseMagexVersion(out []byte) (Version, error)

ParseMagexVersion reads `magex --version`: a banner, then a "Version Information" block whose lines are " Version: 1.29.5", " Commit: 9a61f25", and " Build Date: 2026-11-05T04:17:38Z".

func (Version) AtLeast

func (v Version) AtLeast(minimum string) bool

AtLeast reports whether v is min or newer. A development build, or a version that isn't one, is never at least anything.

func (Version) Development

func (v Version) Development() bool

Development reports a build from a working copy rather than a release: "dev", a Go pseudo-version, or a version marked dirty. Nothing compares it with a release.

func (Version) OlderThan

func (v Version) OlderThan(other string) bool

OlderThan reports whether v is older than other. A development build, or a version that isn't one, is never older.

type Worker

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

Worker looks for the tools after the window's first paint, again when woken, and checks for newer releases once a day. The desktop shell runs it as deferred work; it is not bound.

func NewWorker

func NewWorker(s *Service) *Worker

NewWorker returns the worker that keeps s current.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context)

Run waits for the first read of the user's shell's environment, looks for the tools, checks for updates when a day has passed, and then looks again whenever woken, until ctx ends.

func (*Worker) Wake

func (w *Worker) Wake()

Wake asks the worker to look for the tools again, as when the user flips a switch or chooses a copy.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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