app

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 14 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 app holds the orchestration both front-ends call.

It exists because the CLI and the TUI must not be two implementations. The first attempt put these helpers in internal/cli and had the TUI import them, which produced an import cycle the moment the CLI needed to launch the TUI -- a useful accident, because it forced the shared layer to be named rather than left implicit in whichever package happened to define it first.

Index

Constants

View Source
const BundledPack = "icon-sets-bundled"

BundledPack is the registry slug of the aggregator pack the audit surveys.

Variables

This section is empty.

Functions

func AnyFailed

func AnyFailed(outcomes []Outcome) bool

AnyFailed reports whether any outcome failed.

func ApplyWorkspace

func ApplyWorkspace(pack *config.PackConfig, workspace string)

ApplyWorkspace resolves a relative pack_root against the workspace setting.

Every shipped config names an absolute /work/<pack>, which is where the Docker image sees the mounted checkouts. A relative root is for running the binary on a laptop against sibling checkouts without editing four configs.

func AuditBundled added in v0.1.1

func AuditBundled(ctx context.Context, opts AuditOptions) ([]bundled.Resolution, error)

AuditBundled identifies, by measurement, which upstream each vendored set of the bundled pack came from. It is the body of `bundled audit`, so the CLI and the web UI cannot survey differently. Results are sorted.

func BuildStack added in v0.1.1

func BuildStack(in StackInput) (settings.Stack, string, error)

BuildStack resolves the settings layers that do not vary by pack: the global config file, the environment, and the flag layer.

It is the body of the CLI's resolveState, moved here so the web UI resolves precedence through exactly the same code. Errors in the environment, the assignments or the overlay are *UsageError; a missing or malformed global config is a plain error.

func CheckAll

func CheckAll(ctx context.Context, packs []*config.PackConfig) []checker.Result

CheckAll resolves upstream status for every pack, in order.

Sequential on purpose. Polling four registries concurrently would save a second or two and cost the deterministic output order that makes a CI log diffable between runs.

func IsUsage added in v0.1.1

func IsUsage(err error) bool

IsUsage reports whether err is, or wraps, a UsageError.

func LoadPacks

func LoadPacks(configDir, only string) ([]*config.PackConfig, error)

LoadPacks loads one pack, or every pack in registry order.

Shared so the two front-ends cannot disagree about what "every pack" means.

func LoadPacksIn

func LoadPacksIn(configDir, only, workspace string) ([]*config.PackConfig, error)

LoadPacksIn is LoadPacks with a relative pack_root resolved against workspace, so the checker reads the vendored version from the right tree.

func PackSettings

func PackSettings(stack settings.Stack, pack *config.PackConfig) (settings.Resolved, error)

PackSettings resolves one pack's settings over the run-wide stack.

The pack layer is the config's `settings` block. It is parsed here rather than at load time because the schema has already checked its shape, and only the settings package knows which keys are pack-scoped.

func Problems added in v0.1.1

func Problems(fs []Finding) int

Problems counts the error-level findings.

func Recipe added in v0.1.1

func Recipe(ctx context.Context, req RecipeRequest) (pipeline.Result, error)

Recipe runs one pack's recipe at a version: the body of the `recipe` command, so the web UI runs it through the same checks. A missing version is a *UsageError; a pack with no sinks outside a dry run is refused before anything is fetched.

func ResolveSets added in v0.1.1

func ResolveSets(ctx context.Context, sets []string, filesRoot, workDir string, parallel int, pkg string, fetcher bundled.Fetcher) []bundled.Resolution

ResolveSets audits sets concurrently.

Each set is independent and dominated by a network fetch, so this is worthwhile -- 72 sets fetched one at a time is minutes of waiting. Results are written into a fixed slot per set rather than appended, so the output order stays deterministic regardless of which finishes first.

func RunRecipe

func RunRecipe(ctx context.Context, pack *config.PackConfig, version string, opts recipes.Options) (pipeline.Result, error)

RunRecipe builds a pack's pipelines and runs them in order.

Aborts on the first failure and returns that result, rather than running the rest: the emoji recipe's trailing pipeline commits whatever the three asset pipelines left on disk, so continuing past a failed fetch would commit a half-refreshed pack.

ctx reaches every stage, so cancelling it stops the pipeline in flight and skips the pipelines after it.

Types

type AuditOptions added in v0.1.1

type AuditOptions struct {
	ConfigDir string
	Workspace string

	// Set restricts the audit to one set. Package verifies one named npm
	// package against it instead of guessing; it needs Set.
	Set     string
	Package string

	// WorkDir keeps the downloads. Empty means a temporary directory that is
	// removed afterwards.
	WorkDir string

	// Parallel bounds the concurrent sets. Below 1 means the CPU count.
	Parallel int

	// Fetcher fetches candidate packages. Nil means npm.
	Fetcher bundled.Fetcher

	// Starting is called once the sets are known, before any fetch. May be nil.
	Starting func(sets int, filesRoot string)

	// SetDone is called as each set is resolved, in completion order, one
	// call at a time. May be nil.
	SetDone func(bundled.Resolution)

	// Logger receives the resolver's lines. Nil means slog.Default().
	Logger *slog.Logger
}

AuditOptions configures AuditBundled.

type Checker

type Checker interface {
	CheckPack(ctx context.Context, pack *config.PackConfig) checker.Result
}

Checker is the version check a sync runs first.

type Finding added in v0.1.1

type Finding struct {
	Level Level  `json:"level"`
	Text  string `json:"text"`
}

Finding is one line of a validation report.

func ValidateConfigs added in v0.1.1

func ValidateConfigs(dir string, stack settings.Stack) []Finding

ValidateConfigs validates the registry and every pack it lists, the same checks `config validate` runs with no arguments, in the same order.

The global config is not covered: it has already been loaded, and so validated, by whoever built the stack.

func ValidatePack added in v0.1.1

func ValidatePack(dir, slug string, stack settings.Stack) []Finding

ValidatePack checks one registered pack: that it loads against the schema, that its name matches its slug, that its settings block resolves, that a recipe can run it and, for the bundled pack, that its set manifest loads. A pack with no sinks is a warning, not an error.

func ValidatePackBytes added in v0.1.1

func ValidatePackBytes(dir, slug, path string, data []byte, stack settings.Stack) []Finding

ValidatePackBytes runs ValidatePack's checks on a document that is not yet on disk -- the bytes an editor is about to save to path.

type Level added in v0.1.1

type Level string

Level is how serious one validation finding is.

const (
	LevelOK    Level = "ok"
	LevelWarn  Level = "warn"
	LevelError Level = "error"
)

The levels a finding can have. Only LevelError makes validation fail.

type Outcome

type Outcome struct {
	Pack    string
	Status  Status
	Current string
	Latest  string
	DryRun  bool
	Result  pipeline.Result
	Err     error
}

Outcome is one pack's result.

func Sync

func Sync(ctx context.Context, packs []*config.PackConfig, opts SyncOptions) []Outcome

Sync refreshes every pack that is behind upstream (or every pack, with force), and returns one outcome per pack in input order.

Two things fail loudly here that the Python let pass:

  • An upstream whose latest version cannot be resolved is a failure, not a skip. The Python printed a yellow line and exited 0, so a dead registry or a renamed package looked exactly like an up-to-date pack, every Monday, indefinitely.
  • A pack that declares no sinks is a failure unless this is a dry run: it would fetch, transform, and then write nothing, and report success.

Neither stops the other packs. One dead registry must not hold back the rest of the run; it makes the run exit non-zero once the rest are done.

func (Outcome) Failed

func (o Outcome) Failed() bool

Failed reports whether the outcome should make the run exit non-zero.

type RecipeRequest added in v0.1.1

type RecipeRequest struct {
	Stack     settings.Stack
	Pack      *config.PackConfig
	ConfigDir string

	// Version is the upstream version to fetch. Empty means the pack's
	// current_version.
	Version string

	Logger   *slog.Logger
	Observer pipeline.Observer
}

RecipeRequest is one direct recipe run, skipping the upstream check.

type RunFunc

type RunFunc func(ctx context.Context, pack *config.PackConfig, version string, opts recipes.Options) (pipeline.Result, error)

RunFunc builds and runs one pack's recipe.

type StackInput added in v0.1.1

type StackInput struct {
	// GlobalPath is an explicit global config file. Empty means discover it
	// the way GlobalConfigPath does (ICHAVA_GLOBAL_CONFIG, then XDG).
	GlobalPath string

	// Lookup reads the environment. Nil means os.LookupEnv. A server passes
	// its own so a test can run it against a controlled environment.
	Lookup func(string) (string, bool)

	// Assignments are --set key=value pairs, the start of the flag layer.
	Assignments []string

	// Overlay applies the dedicated flags (--dry-run, --concurrency, a web
	// form's toggles) on top of the assignments. It runs last, so a
	// dedicated flag beats a --set of the same key, exactly as on the
	// command line. An error it returns is a usage error. May be nil.
	Overlay func(flags settings.Values) error
}

StackInput is what BuildStack needs to assemble the run-wide settings.

type Status

type Status string

Status is how one pack's sync ended.

const (
	StatusUpToDate   Status = "up-to-date"
	StatusSynced     Status = "synced"
	StatusFailed     Status = "failed"
	StatusUnresolved Status = "unresolved"
)

The outcomes a sync can have.

type SyncOptions

type SyncOptions struct {
	// Stack is the run-wide settings; each pack's own layer is merged in.
	Stack settings.Stack

	// ConfigDir is handed to the recipes (the bundled manifest lives there).
	ConfigDir string

	// Concurrency bounds how many packs run at once. Below 1 means 1.
	Concurrency int

	Checker Checker
	Run     RunFunc

	// Logger and Observer are handed to every pack's recipe; see
	// recipes.Options. Nil means slog.Default() and no observer.
	Logger   *slog.Logger
	Observer pipeline.Observer

	// Starting and Done are called around each pack, from that pack's
	// goroutine, for progress output. Either may be nil. Calls are
	// serialised, so a reporter need not lock.
	Starting func(pack *config.PackConfig, result checker.Result, dryRun bool)
	Done     func(Outcome)
}

SyncOptions configures Sync.

type UsageError added in v0.1.1

type UsageError struct{ Err error }

UsageError marks an error the caller made in what it asked for, as opposed to one the machine or a file produced. The CLI maps it onto exit code 2; the web UI onto a 400. Keeping the distinction here means neither front-end has to guess it from a message.

func (*UsageError) Error added in v0.1.1

func (e *UsageError) Error() string

func (*UsageError) Unwrap added in v0.1.1

func (e *UsageError) Unwrap() error

Jump to

Keyboard shortcuts

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