Documentation
¶
Overview ¶
Package core provides shared primitives for the Krewire ecosystem, including the common error type and process exit-code mapping.
Package core — workload registry (KWF-M8K2Q, KWL-K1N2Q).
Index ¶
- Constants
- Variables
- func CheckEcosystemCompatibility(required, actual map[ModuleName]Version) error
- func FormatStack(frames []StackFrame) string
- func FormatTree(err error) string
- func HintOf(err error) string
- func IsOptIn(kind Kind, imported []string) bool
- func ParseRequirementID(s string) error
- func ValidateKrewireYamlPath(path string) error
- func WithAttrs(err error, attrs ...Attr) error
- func WithHint(err error, text string) error
- func WithStack(err error) error
- type Attr
- type DomainEvent
- type Env
- type Error
- type ExitCode
- type Kind
- type ModuleName
- type Project
- type RequirementID
- type Scope
- type SpecID
- type StackFrame
- type Status
- type Version
- type Versioned
- type Workload
Constants ¶
const DefaultEnv = EnvLocal
DefaultEnv is assumed when no environment is declared anywhere.
Variables ¶
var AllKinds = []Kind{KindApp, KindCLI, KindSite, KindBook, KindWorker, KindService, KindInfra, KindKernel}
AllKinds lists every valid Kind in canonical order.
var AllScopes = []Scope{ScopeWorkspace, ScopeModule, ScopeDomain, ScopePackage, ScopeService, ScopeFunc}
AllScopes lists every valid Scope in canonical order.
var CurrentVersion = MustParseVersion("0.1.0")
CurrentVersion is the libs module's own version. Bump per release.
var EcosystemVersions = map[ModuleName]Version{ ModuleFramework: MustParseVersion("0.1.0"), ModuleLibs: CurrentVersion, ModuleMdbind: MustParseVersion("0.1.0"), ModuleKrewire: MustParseVersion("0.1.0"), ModuleGuild: MustParseVersion("0.1.0"), ModuleInternal: MustParseVersion("0.1.0"), }
EcosystemVersions is the known-good compatibility matrix for the current release.
var Workloads = []Workload{ {Kind: KindCLI, Package: "framework/tui", Title: "CLI tools", SpecID: "KWF-5XJFC", Status: StatusShipped}, {Kind: KindApp, Package: "framework/web", Title: "Backend / API", SpecID: "KWF-M07QS", Status: StatusShipped}, {Kind: KindSite, Package: "framework/web/ssg", Title: "Static sites (SSG)", SpecID: "KWF-PT8OD", Status: StatusShipped}, {Kind: KindBook, Package: "mdbind", Title: "Documentation sites", SpecID: "KWM-FX9H2", Status: StatusShipped}, {Kind: KindApp, Package: "framework/app", Title: "Fullstack / Monolith", SpecID: "KWF-C4087", Status: StatusShipped}, {Kind: KindSite, Package: "framework/runtime", Title: "Frontend (client)", SpecID: "KWF-T4X9P", Status: StatusPlanned}, {Kind: KindWorker, Package: "framework/worker", Title: "Workers & jobs", SpecID: "KWF-L5H2F", Status: StatusPlanned}, {Kind: KindService, Package: "framework/service", Title: "Microservice", SpecID: "KWF-L5H2F", Status: StatusPlanned}, {Kind: KindInfra, Package: "framework/infra", Title: "Cloud infrastructure", SpecID: "KWF-B7N3D", Status: StatusPlanned}, }
Workloads is the canonical 9-workload matrix from internal/docs/project-vision.md.
Functions ¶
func CheckEcosystemCompatibility ¶
func CheckEcosystemCompatibility(required, actual map[ModuleName]Version) error
CheckEcosystemCompatibility verifies that actual versions satisfy required versions per IsCompatible. Pass the go.mod require versions as actual; the matrix as required.
func FormatStack ¶
func FormatStack(frames []StackFrame) string
FormatStack renders frames as an indented multi-line trace, newest first.
func FormatTree ¶ added in v0.2.0
FormatTree renders err as a human-readable diagnostic tree: the message chain top-down, each annotated with its creation point when a stack was captured, attributes inline, and the nearest hint as footer (KWL-P8W2N KWL-ERRV-010).
func HintOf ¶ added in v0.2.0
HintOf returns the nearest hint found walking the wrap chain from the outside in, or "" when none is attached (KWL-P8W2N KWL-ERRV-009).
func IsOptIn ¶
IsOptIn reports whether importing the given import paths violates opt-in for the declared kind. For example, a KindApp monolith importing framework/service should be flagged.
func ParseRequirementID ¶
ParseRequirementID validates s as a RequirementID.
func ValidateKrewireYamlPath ¶
ValidateKrewireYamlPath ensures the config path is krewire.yaml.
func WithAttrs ¶ added in v0.2.0
WithAttrs attaches structured diagnostic attributes to err. Nil-safe; wrapping repeatedly accumulates layers extractable by AttrsOf.
Types ¶
type Attr ¶ added in v0.2.0
Attr is one structured key/value pair attached to an error for diagnostics (KWL-P8W2N KWL-ERRV-008).
type DomainEvent ¶
type DomainEvent struct {
Type string `json:"type"`
Payload any `json:"payload"`
At time.Time `json:"at"`
}
DomainEvent is a cross-module domain event.
func NewDomainEvent ¶
func NewDomainEvent(typ string, payload any) DomainEvent
NewDomainEvent creates a DomainEvent with the current time.
type Env ¶
type Env string
Env is the target environment a workload runs in.
type Error ¶
type Error struct {
// Message is the human-readable error message.
Message string
// Code is the process exit code associated with the error.
Code ExitCode
}
Error pairs a human-readable message with an ExitCode.
func FailureError ¶
FailureError creates an Error with ExitCodeFailure.
func UsageError ¶
UsageError creates an Error with ExitCodeUsage.
type ExitCode ¶
type ExitCode int
ExitCode is a standard process exit code used across Krewire applications.
const ( // ExitCodeSuccess indicates successful termination. ExitCodeSuccess ExitCode = 0 // ExitCodeFailure indicates a generic runtime failure. ExitCodeFailure ExitCode = 1 // ExitCodeUsage indicates invalid usage: missing or malformed arguments, // configuration, or input. ExitCodeUsage ExitCode = 2 )
func ExitCodeFromInt ¶
ExitCodeFromInt maps a raw process exit code back to the closest known ExitCode.
type Kind ¶
type Kind string
Kind is a Krewire project kind. Eight kinds cover the unified workload spectrum.
type ModuleName ¶
type ModuleName string
ModuleName identifies a Krewire module in the ecosystem compatibility matrix.
const ( ModuleFramework ModuleName = "framework" ModuleLibs ModuleName = "libs" ModuleMdbind ModuleName = "mdbind" ModuleKrewire ModuleName = "krewire" ModuleGuild ModuleName = "guild" ModuleDocs ModuleName = "docs" ModuleLanding ModuleName = "krewire.github.io" ModuleInternal ModuleName = "internal" )
type Project ¶
type Project struct {
Name string `json:"name"`
ModulePath string `json:"modulePath"`
Kind Kind `json:"kind"`
ConfigPath string `json:"configPath"`
}
Project describes a Krewire project for validation.
type RequirementID ¶
type RequirementID string
RequirementID is a requirement identifier such as FRK-CLI-001 or KWL-CORE-001.
type Scope ¶
type Scope string
Scope is the ecosystem level a spec, test, or doc targets. Ordered: Workspace < Module < Domain < Package < Service < Func. See KWL-ARCH-J2K9Q.
Workspace is the Krewire Workspace (hub dir ~/Workspace/Dev/krewire with bin/kiw + 7 repos), which is also the Go `go.work` workspace at the hub root (see `go.work` and `AGENTS.md`). Domain is a DDD bounded context (e.g. catalog, user) — a cohesive set of Packages inside a Module (internal/<domain>/). Pre-extraction it is Package set, post-extraction it becomes its own Service (and often its own Module/Project). Service is a Krewire runtime deployable, implemented in Go as a main package (e.g. cmd/<service>/ or service/<name>/); Func is inside Package.
func ParseScope ¶
ParseScope parses s as a Scope, case-insensitive, returning UsageError on unknown. Accepted forms are the canonical names (Workspace, Module, Domain, Package, Service, Func), case-insensitive, with surrounding whitespace trimmed. "Project" is no longer a valid scope — use Module (Go module, formerly Project==Module).
type SpecID ¶
type SpecID string
SpecID is a Krewire specification identifier. Two forms are accepted:
- Short: KWF-M8K2Q (ProjectId-Code)
- Full file prefix: KWF-ARCH-M8K2Q (ProjectId-Scope-Code) — with or without slug suffix.
func ParseSpecID ¶
ParseSpecID validates s as a SpecID and returns UsageError on failure.
type StackFrame ¶
StackFrame is one rendered-ready entry of a captured stack.
func StackOf ¶
func StackOf(err error) []StackFrame
StackOf extracts the most recently attached stack from err, or nil (KWL-P8W2N KWL-ERRV-002).
type Version ¶
Version is a semantic version per https://semver.org/. Build metadata is retained but ignored for precedence.
func MustParseVersion ¶
MustParseVersion parses s or panics. Use for constants.
func ParseVersion ¶
ParseVersion parses s as a semantic version. Leading "v" is optional.
func (Version) Compare ¶
Compare returns -1 if v < other, 0 if equal, 1 if v > other per semver precedence. Build metadata is ignored.
func (Version) IsCompatible ¶
IsCompatible reports whether actual satisfies required per semver caret semantics for the Krewire ecosystem: for 0.y.z, minor must match; for >=1.0.0, major must match and actual >= required.
type Versioned ¶
type Versioned interface {
Version() Version
}
Versioned is implemented by any module that exposes its version via core.Version.
type Workload ¶
type Workload struct {
Kind Kind `json:"kind"`
Package string `json:"package"`
Title string `json:"title"`
SpecID string `json:"specId"` // e.g. KWF-5XJFC
Status Status `json:"status"`
}
Workload describes one cell of the unified workload matrix.
func WorkloadFor ¶
WorkloadFor returns the first Workload matching k and whether it was found.