extension

package
v0.0.1-testing Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 18 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 extension manages third-party commands installed from GitHub releases (like `gh extension`).

Unlike cargo/git, binaries named reearth-* on PATH are never executed implicitly. Only extensions installed through this manager run, and their SHA-256 is pinned in a lock file and re-verified before every run.

Extensions are not sandboxed. They run with the user's own access, like any process the user starts, and inherit environment variables, including REEARTH_TOKEN. The CLI does not hand them the credentials it stores (keyring or file); an extension that needs the API calls `$REEARTH_BIN api ...`. REEARTH_EXTENSION=1 is how the CLI recognises a call from an extension. None of this stops a malicious extension, which could read the keyring itself: users are protected by installing only extensions they trust.

Index

Constants

View Source
const OfficialOwner = "reearth"

OfficialOwner is the GitHub owner whose extensions are marked official.

Variables

View Source
var ErrTampered = errors.New("extension binary does not match its recorded checksum")

ErrTampered means the binary on disk no longer matches the lock file.

Functions

func AssetName

func AssetName(name, goos, goarch string) string

AssetName is the binary asset an extension release must provide.

func Dispatch

func Dispatch(m *Manager) func(f *core.Factory, root *cobra.Command, args []string) (bool, int)

Dispatch runs `reearth <name> ...` for an installed extension when <name> is not a built-in command. Agents must use `ext exec` explicitly.

func NewCmd

func NewCmd(f *core.Factory, m *Manager) *cobra.Command

func ParseRepo

func ParseRepo(s string) (owner, repo, name string, err error)

ParseRepo validates "owner/reearth-<name>" and returns the extension name.

func Run

func Run(f *core.Factory, m *Manager, e *Entry, args []string) (int, error)

Run executes an extension with stdio attached and returns its exit code.

Types

type Entry

type Entry struct {
	Name     string `json:"name"`
	Repo     string `json:"repo"`
	Version  string `json:"version"`
	Path     string `json:"path"`
	SHA256   string `json:"sha256"`
	Official bool   `json:"official"`
	// ChecksumsVerified means the release published a checksums file that matched.
	ChecksumsVerified bool      `json:"checksums_verified"`
	InstalledAt       time.Time `json:"installed_at"`
}

type Manager

type Manager struct {
	Dir string
	GH  *ghrelease.Client
	// Reserved reports names that extensions may not take (built-in commands).
	Reserved func(name string) bool
}

func NewManager

func NewManager(userAgent string, reserved func(string) bool) *Manager

func (*Manager) Command

func (m *Manager) Command(e *Entry, args []string, reearthBin string) (*exec.Cmd, error)

Command returns an exec.Cmd for the extension after verifying its checksum.

func (*Manager) Get

func (m *Manager) Get(name string) (*Entry, bool)

func (*Manager) Install

func (m *Manager) Install(ctx context.Context, p *Plan) (*Entry, error)

Install downloads the planned binary, verifies it and records it in the lock file.

func (*Manager) List

func (m *Manager) List() ([]*Entry, error)

func (*Manager) PlanInstall

func (m *Manager) PlanInstall(ctx context.Context, repoArg, tag string) (*Plan, error)

PlanInstall resolves the release and asset for repoArg at tag (latest if empty).

func (*Manager) Remove

func (m *Manager) Remove(name string) error

type Plan

type Plan struct {
	Name     string
	Repo     string
	Tag      string
	Official bool
	Asset    *ghrelease.Asset
	// Checksum is the expected SHA-256 from the release's checksums files;
	// empty only when the release publishes none.
	Checksum string
	URL      string
}

Plan describes what an install would do, for confirmation.

Jump to

Keyboard shortcuts

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