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
- func AnyFailed(outcomes []Outcome) bool
- func AnyNeedsReview(outcomes []Outcome) bool
- func ApplyWorkspace(pack *config.PackConfig, workspace string)
- func AuditManifestPack(ctx context.Context, opts AuditOptions) ([]manifestpack.Resolution, error)
- func AuditSets(configDir, workspace string) ([]string, error)
- func BuildStack(in StackInput) (settings.Stack, string, error)
- func BuildStackLocated(in StackInput) (settings.Stack, settings.GlobalLocation, error)
- func CheckAll(ctx context.Context, packs []*config.PackConfig) []checker.Result
- func InitRecordPath(historyDir string) string
- func IsUsage(err error) bool
- func LoadPacks(configDir, only string) ([]*config.PackConfig, error)
- func LoadPacksIn(configDir, only, workspace string) ([]*config.PackConfig, error)
- func Locate(data []byte, err error) (line, col int)
- func MissingPackagesDirs(dirs []string) []string
- func PackSettings(stack settings.Stack, pack *config.PackConfig) (settings.Resolved, error)
- func PackagesDirs() []string
- func PrivateConfigCandidates(workspace string) []string
- func Problems(fs []Finding) int
- func Recipe(ctx context.Context, req RecipeRequest) (pipeline.Result, error)
- func ResolveSets(ctx context.Context, sets []string, filesRoot, workDir string, parallel int, ...) []manifestpack.Resolution
- func RunRecipe(ctx context.Context, pack *config.PackConfig, version string, ...) (pipeline.Result, error)
- func SetPackagesDirs(dirs []string)
- func SuggestSets(name string, sets []string) []string
- func WriteInitRecord(path string, data []byte) error
- type AuditOptions
- type Checker
- type Finding
- type Fixed
- type GlobalInit
- type GlobalState
- type InitRecord
- type KindReport
- type Level
- type Outcome
- type RecipeRequest
- type RunFunc
- type StackInput
- type Status
- type SyncOptions
- type Tool
- type UnknownSetError
- type UsageError
Constants ¶
const ( KindGlobalConfig = "global" KindPackConfig = "pack" )
The config documents FixConfig knows. The web editor's kinds use the same strings.
const DefaultKindSuggestionsDir = ".cache/kind-suggestions"
DefaultKindSuggestionsDir is where `check` and `sync --suggest-kinds` write, relative to the working directory (the repository root, in practice). The repository's .gitignore already covers .cache/, and `make clean` removes it. Not build/, which holds the binaries and nothing else (checkbuild).
const KindsSVGDir = "resources/assets/svg"
KindsSVGDir is where a pack keeps config.json and its files/ tree.
const ManifestPack = "icon-sets-bundled"
ManifestPack is the registry slug of the aggregator pack the manifest-pack audit surveys.
const MaxConcurrency = 64
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. MaxConcurrency is the most packs a run syncs at once, whatever asked for more: the concurrency setting, a flag or an API request. The API refuses a larger value; this bounds the run itself, so no caller can size the worker pool past it.
const PackSchemaRef = "./schema/pack.schema.json"
PackSchemaRef is the $schema a pack config in config/ names.
const PrivateConfigSubdir = ".dev/icon-sets-sync"
PrivateConfigSubdir is where a pack keeps its private sync config.
Variables ¶
This section is empty.
Functions ¶
func AnyNeedsReview ¶ added in v0.1.3
AnyNeedsReview reports whether any outcome needs review.
func ApplyWorkspace ¶
func ApplyWorkspace(pack *config.PackConfig, workspace string)
ApplyWorkspace resolves where a pack's checkout is.
A relative pack_root is joined to the first packages_dirs entry that holds it, else to the workspace setting, as before. Every shipped config names an absolute /work/<pack>, the layout sync-pack.yml makes on a CI runner; for such a root, in order:
- each packages_dirs entry (--packages-dir, ICHAVA_PACKAGES_DIRS), when <dir>/<pack> exists;
- the workspace setting (--set workspace=, ICHAVA_WORKSPACE), when <workspace>/<pack> exists;
- /work/<pack>, when it exists (CI);
- the sibling checkout <toolkit root>/../<pack>, when it exists (a developer machine, where the packs sit beside this repository), with the toolkit root found from the working directory or, failing that, from the executable's own directory;
- the configured value, unchanged, with PackRootOrigin naming the setting that fixes it.
pack.PackRootOrigin records which of these applied.
func AuditManifestPack ¶ added in v0.1.2
func AuditManifestPack(ctx context.Context, opts AuditOptions) ([]manifestpack.Resolution, error)
AuditManifestPack identifies, by measurement, which upstream each vendored set of the manifest pack came from. It is the body of `manifest-pack audit`, so the CLI and the web UI cannot survey differently. Results are sorted.
func AuditSets ¶ added in v0.1.3
AuditSets lists the aggregator pack's sets, for a form's suggestions.
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 BuildStackLocated ¶ added in v0.1.3
func BuildStackLocated(in StackInput) (settings.Stack, settings.GlobalLocation, error)
BuildStackLocated is BuildStack, also returning where the global config was found and where it belongs, so a front-end can explain it and warn about a file at a legacy location.
func CheckAll ¶
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 InitRecordPath ¶ added in v0.1.3
InitRecordPath is $XDG_STATE_HOME/icon-sets-sync/global-init.json (else ~/.local/state/...), beside the config history.
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 Locate ¶ added in v0.1.3
Locate finds the line and column (1-based) an error is about, or 0, 0. JSON syntax and type errors carry a byte offset; an error naming a key ("unknown setting \"dry_rnu\"") is placed at that key's first occurrence, by the last segment of a dotted name.
func MissingPackagesDirs ¶ added in v0.1.3
MissingPackagesDirs lists the packages_dirs entries that are not directories, for a warning: a missing entry is skipped, not fatal.
func PackSettings ¶
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 PackagesDirs ¶ added in v0.1.3
func PackagesDirs() []string
PackagesDirs returns the packages_dirs setting.
func PrivateConfigCandidates ¶ added in v0.1.3
PrivateConfigCandidates finds pack checkouts carrying a private config directory (<pack>/.dev/icon-sets-sync/ with a packs.json): under each packages_dirs entry, under workspace, and beside this checkout. The web UI offers them when the aggregator pack's config is not loaded, so the fix is a click rather than a restart with a flag. Nothing is enabled by finding one: a private config stays opt-in.
func Recipe ¶ added in v0.1.1
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 manifestpack.Fetcher) []manifestpack.Resolution
ResolveSets audits sets concurrently.
Each set is independent and dominated by a network fetch, so this is worthwhile -- dozens of 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.
func SetPackagesDirs ¶ added in v0.1.3
func SetPackagesDirs(dirs []string)
SetPackagesDirs sets the packages_dirs setting: directories searched, in order, for a pack's checkout before the workspace setting.
func SuggestSets ¶ added in v0.1.3
SuggestSets returns the sets a mistyped name probably meant: those it is a part of ("tabler" for tabler-icons), and those one or two edits away ("mdl" for mdi). Sorted; empty when nothing is close.
func WriteInitRecord ¶ added in v0.1.3
WriteInitRecord records data as what the generator wrote.
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 manifestpack.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(manifestpack.Resolution)
// Logger receives the resolver's lines. Nil means slog.Default().
Logger *slog.Logger
}
AuditOptions configures AuditManifestPack.
type Finding ¶ added in v0.1.1
type Finding struct {
Level Level `json:"level"`
Text string `json:"text"`
// Line and Col (1-based) place the finding in the document, when known.
Line int `json:"line,omitempty"`
Col int `json:"col,omitempty"`
}
Finding is one line of a validation report.
func ValidateConfigs ¶ added in v0.1.1
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
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 a manifest-pack, that its set manifest loads. A pack with no sinks is a warning, not an error.
type Fixed ¶ added in v0.1.3
Fixed is FixConfig's result: the repaired text and what changed, in words.
func FixConfig ¶ added in v0.1.3
FixConfig applies the safe repairs to a config document: it formats JSON with two-space indentation, renames deprecated keys (packages_dir becomes packages_dirs) and adds a $schema an editor can complete against. Key order is kept. Broken JSON is an error -- a guess at what was meant is not a safe repair -- and YAML is returned unchanged, because re-encoding it would drop its comments. It never writes; the caller shows the diff and asks.
type GlobalInit ¶ added in v0.1.3
type GlobalInit struct {
Data []byte
// Notes say, in words, what was found and what was left unset.
Notes []string
}
GlobalInit is the global config a machine starts from: the $schema line and the settings that say where this machine keeps things, found rather than guessed. Everything else stays at its default, so a later default change still reaches it.
func InitialGlobal ¶ added in v0.1.3
func InitialGlobal(workspace string) GlobalInit
InitialGlobal builds the global config for this machine: packages_dirs is the directory holding this checkout, when it holds ichava packs; private_config_dir is the one pack checkout carrying a private config, when exactly one does.
type GlobalState ¶ added in v0.1.3
type GlobalState string
GlobalState is how a global config file stands against the generator.
const ( GlobalMissing GlobalState = "missing" GlobalEmpty GlobalState = "empty" // nothing but $schema (or blank) GlobalGenerated GlobalState = "generated" // byte for byte what was last generated GlobalEdited GlobalState = "edited" // anything else: a person's file )
The states. Only an edited file is left alone by a start.
func ClassifyGlobal ¶ added in v0.1.3
func ClassifyGlobal(data []byte, exists bool, rec InitRecord) GlobalState
ClassifyGlobal says how the global config stands. A file that is exactly what the generator last wrote (rec) is still the generator's; one with nothing in it but $schema has nothing to lose; anything else a person made.
type InitRecord ¶ added in v0.1.3
InitRecord remembers what the generator last wrote, so a start can tell its own file from one a person edited.
func ReadInitRecord ¶ added in v0.1.3
func ReadInitRecord(path string) InitRecord
ReadInitRecord reads the record; a missing or unreadable one is empty.
type KindReport ¶ added in v0.1.3
type KindReport struct {
Pack string
File string
Records int
Items int
Skipped []string
Issues []kinds.Issue
Err error
}
KindReport is one pack's row-7 scan.
func SuggestKinds ¶ added in v0.1.3
func SuggestKinds(packs []*config.PackConfig, mode kinds.Mode, outDir string) []KindReport
SuggestKinds scans each pack's checkout for items that look like illustrations and writes <outDir>/<pack>.json for each (contract section 3).
It reads the pack and writes only into outDir. It never touches config.json, the pack's files or any database: a suggestion becomes a kind only when a human copies its accept block into the pack's config. One pack failing does not stop the others; its report carries the error.
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
func (Outcome) LicenceChanged ¶ added in v0.1.3
LicenceChanged reports whether the outcome failed because the upstream's licence no longer matches the licence the pack declares. The outcome's own error is flattened to text, so the pipeline result's error is checked too.
func (Outcome) NeedsReview ¶ added in v0.1.3
NeedsReview reports whether a guard stopped the run for a person to decide.
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" // StatusNeedsReview is a run a guard stopped for a person to decide: a // refresh would rename or remove shipped icons. A dry run that would hit // the guard ends here too, having reported every icon, rather than failing. StatusNeedsReview Status = "needs-review" )
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 (a manifest-pack's set 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 Tool ¶ added in v0.1.3
type Tool struct {
Name string `json:"name"`
// Why says what needs it.
Why string `json:"why"`
// Optional tools only matter on a fallback path.
Optional bool `json:"optional"`
Path string `json:"path,omitempty"`
Found bool `json:"found"`
// OnPath is false for a tool found only in the usual install
// directories: it works, and PATH is missing that directory.
OnPath bool `json:"on_path"`
Detail string `json:"detail,omitempty"`
}
Tool is one external program a pipeline may run, and whether it is here.
func MissingTools ¶ added in v0.1.3
MissingTools lists the required tools that are not found.
type UnknownSetError ¶ added in v0.1.3
UnknownSetError is an audit asked for a set the pack does not have. It carries the near names, so a front-end can offer them.
func (*UnknownSetError) Error ¶ added in v0.1.3
func (e *UnknownSetError) Error() string
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