config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 13 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 config loads the per-pack JSON configs and the registry that lists them, and reads and writes the version a pack repo says it vendors.

The config directory is a mounted volume in production -- each pack's sync-upstream.yml bind-mounts the toolkit checkout's config/ at /app/config -- so this schema is an external interface, not an internal one. It is ported from the Pydantic models in core/config.py and must accept every file those models accept, unchanged.

Index

Constants

View Source
const DefaultVersionFile = "resources/assets/svg/config.json"

DefaultVersionFile and DefaultVersionKeys mirror the Python defaults. No shipped config overrides either, so changing them changes every pack at once.

Variables

View Source
var SinkTypes = []string{"filesystem", "git-branch"}

SinkTypes is the closed set Python declared as a Literal.

View Source
var SourceTypes = []string{"npm", "github-archive", "github-tag", "github-release", "url", "script"}

SourceTypes is the closed set Python declared as a Literal. A config naming anything else is rejected at load time, before any network call.

Functions

func DefaultConfigDir

func DefaultConfigDir() string

DefaultConfigDir resolves the directory the pack configs live in.

ICHAVA_CONFIG_DIR wins (ICHAVA_DEV_CONFIG_DIR is its older name), which is how the Docker image points at the bind-mounted /app/config. Otherwise it is `config/` beside the executable, falling back to ./config -- Python derived this from the source file's location, which has no equivalent in a compiled binary.

func DefaultVersionKeys

func DefaultVersionKeys() []string

DefaultVersionKeys is returned by value; callers must not retain the slice.

func Interpolate

func Interpolate(template string, bindings map[string]string) string

Interpolate replaces {key} placeholders with the given bindings.

This is a replacement loop, not format-string semantics: an unknown token is left in the output verbatim rather than raising. Several templates in the shipped configs rely on that, carrying tokens a later stage substitutes.

func PackFile

func PackFile(slug, configDir string) (string, error)

PackFile returns the path of a pack's config: <slug>.json, .yaml or .yml.

func PackSchema

func PackSchema() []byte

PackSchema returns the embedded schema document.

func ReadVendoredVersion

func ReadVendoredVersion(pack *PackConfig) string

ReadVendoredVersion returns the version the pack repo says it vendors.

Returns "" when the file is missing, unreadable, unparseable, or declares none of the keys -- callers then fall back to the toolkit config's current_version. Swallowing the error is deliberate and matches Python: a pack that has not been synced yet is an ordinary state, not a failure.

func ResolvedCurrentVersion

func ResolvedCurrentVersion(pack *PackConfig) string

ResolvedCurrentVersion is the version upstream is compared against.

The pack repo wins. The toolkit config's current_version is a fallback for a pack with no vendored record yet: it lives in *this* repository, so a bump written during a sync run is discarded with the runner. That asymmetry is the whole reason the sync converges (V49).

func ValidatePackDocument

func ValidatePackDocument(doc []byte) error

ValidatePackDocument checks a pack config, as JSON bytes, against the schema.

The error lists every violation, one per line, each with the JSON pointer of the offending value -- "/sinks/0/root" rather than "invalid config".

func VendoredVersionFile

func VendoredVersionFile(pack *PackConfig) string

VendoredVersionFile is the pack repo's own version record.

func WriteVendoredVersion

func WriteVendoredVersion(pack *PackConfig, version string) (string, error)

WriteVendoredVersion records version at every declared key in the pack repo.

Returns the file written, or "" when the pack ships no such file. It only rewrites a leaf that already exists and already differs -- it never creates a key. That is what keeps it from inventing `package.upstream_version` in a pack that deliberately has none (icon-sets-bundled), and from touching `package.version`, which is the pack's own release number rather than the upstream one.

The edit is surgical rather than parse-modify-reserialise. Go maps have no key order, so round-tripping the document would reorder every key in it and bury a one-line version bump in a whole-file diff on the sync PR.

Types

type PackConfig

type PackConfig struct {
	Name            string           `json:"name"`
	Pack            string           `json:"pack"`
	PackRoot        string           `json:"pack_root"`
	CurrentVersion  string           `json:"current_version,omitempty"`
	VersionFile     string           `json:"version_file,omitempty"`
	VersionKeys     []string         `json:"version_keys,omitempty"`
	VersionCheckURL string           `json:"version_check_url"`
	Source          SourceConfig     `json:"source"`
	Sinks           []SinkConfig     `json:"sinks,omitempty"`
	Transforms      []map[string]any `json:"transforms,omitempty"`

	// Recipe picks the pipeline builder; empty and "auto" dispatch by pack
	// name, then by source type, exactly as before the field existed.
	Recipe string `json:"recipe,omitempty"`

	// Settings is the pack layer of the settings precedence. It is kept as a
	// raw tree here and resolved by internal/core/settings, which owns the
	// key registry; the schema has already checked its shape.
	Settings map[string]any `json:"settings,omitempty"`

	// File is where the config was loaded from. Not part of the document.
	File string `json:"-"`
}

PackConfig is one config/<slug>.json.

Unlike the source and sink blocks this rejects unknown keys, so a typo fails loudly instead of being silently ignored. Python expressed that as `extra="forbid"`, which is also why the comment-key strip below has to happen before validation rather than after.

func LoadAll

func LoadAll(configDir string) ([]*PackConfig, error)

LoadAll loads every pack in the registry, in registry order.

func LoadPack

func LoadPack(slug, configDir string) (*PackConfig, error)

LoadPack reads and validates one pack config, in JSON or YAML.

func LoadPackFile

func LoadPackFile(path string) (*PackConfig, error)

LoadPackFile reads, schema-validates and decodes one pack config.

Validation runs against the whole document before anything is decoded, so a file with three mistakes reports all three rather than the first one the decoder trips on. The strict decode after it is a second gate, and catches a schema that has drifted from the Go types.

type PacksRegistry

type PacksRegistry struct {
	Packs []string `json:"packs"`
}

PacksRegistry is config/packs.json.

func LoadRegistry

func LoadRegistry(configDir string) (*PacksRegistry, error)

LoadRegistry reads and validates config/packs.json (or packs.yaml).

type SchemaError

type SchemaError struct {
	Problems []string
}

SchemaError carries every schema violation in a document.

func (*SchemaError) Error

func (e *SchemaError) Error() string

type SinkConfig

type SinkConfig struct {
	Type string `json:"type"`

	// filesystem
	Root         string  `json:"root,omitempty"`
	Incremental  bool    `json:"incremental,omitempty"`
	MinRetention float64 `json:"min_retention,omitempty"`

	// git-branch. Each of these is a pack-level value for the matching
	// git.* setting: it wins over the default and gives way to the global
	// config, the environment and flags.
	RepoRoot      string `json:"repo_root,omitempty"`
	Branch        string `json:"branch,omitempty"`
	CommitSubject string `json:"commit_subject,omitempty"`
	CommitBody    string `json:"commit_body,omitempty"`
	Base          string `json:"base,omitempty"`
	OpenPR        *bool  `json:"open_pr,omitempty"`

	Extra map[string]any `json:"-"`
}

SinkConfig says where refreshed assets land.

func (SinkConfig) MarshalJSON

func (s SinkConfig) MarshalJSON() ([]byte, error)

MarshalJSON writes the extras back alongside the known fields.

func (*SinkConfig) UnmarshalJSON

func (s *SinkConfig) UnmarshalJSON(data []byte) error

type SourceConfig

type SourceConfig struct {
	Type       string   `json:"type"`
	Package    string   `json:"package,omitempty"`
	Owner      string   `json:"owner,omitempty"`
	Repo       string   `json:"repo,omitempty"`
	ArchiveURL string   `json:"archive_url,omitempty"`
	SourcePath string   `json:"source_path,omitempty"`
	Path       string   `json:"path,omitempty"`
	Args       []string `json:"args,omitempty"`

	// Extra holds keys with no field above. See the type comment.
	Extra map[string]any `json:"-"`
}

SourceConfig says where to fetch upstream artefacts from.

Unknown keys are kept rather than rejected, and that is load-bearing: the checker reads `version_field` out of them for `type: "url"`, and both shipped url-typed packs (icon-sets-bundled, icon-sets-emoji) rely on it. Python expressed this as `extra="allow"`.

func (SourceConfig) MarshalJSON

func (s SourceConfig) MarshalJSON() ([]byte, error)

MarshalJSON writes the extras back alongside the known fields, so `config print` shows the source block as the file declared it.

func (*SourceConfig) UnmarshalJSON

func (s *SourceConfig) UnmarshalJSON(data []byte) error

func (SourceConfig) VersionField

func (s SourceConfig) VersionField() string

VersionField returns the dot-path into the version-check response for a url-typed source, defaulting to "version" exactly as the checker does.

Jump to

Keyboard shortcuts

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