solutions: Solutions Guide engine (catalog, rules, wizard state, native config, knowledge index, CLI)

New nested module yetano.dev/yetano/core/solutions: loads the catalog
in assets/solutions on top of the Big Picture, evaluates questions and
conditions, resolves packages/modules/capabilities, generates native
configuration from typed fragments with per-value origins, and builds
architecture graph, plan, lock file and handbook. Knowledge index with
yetano: references, search and lint (incl. manual sections). CLI with
yet's conventions (solution, task, knowledge, open), standalone as
yetano-solutions. No execution, no network.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-12-01 08:42:58 +01:00
1 parent 586e76889c
commit 2481a0dd27
48 files changed
+10304

No files matched your search

+155
View File
@@ -0,0 +1,155 @@
// Package ref parses and formats yetano: references (ADR-0004):
//
// yetano:<kind>/<path>[#<section>][@<version>]
//
// It only knows the syntax; resolving a reference against a catalog and
// rendering it for a client lives in package knowledge.
package ref
import (
"errors"
"fmt"
"regexp"
"strings"
)
// Kinds of references.
const (
Package = "package"
Module = "module"
Manual = "manual"
Microsite = "microsite"
Solution = "solution"
Task = "task"
Profile = "profile"
Capability = "capability"
Example = "example"
BigPicture = "bigpicture"
)
// Kinds lists the valid kinds and how many path segments each takes.
var Kinds = map[string]int{
Package: 1, Module: 2, Manual: -2, Microsite: 1, Solution: 1, Task: 1,
Profile: 2, Capability: 1, Example: 2, BigPicture: 1,
}
// Ref is a parsed reference.
type Ref struct {
Kind string `json:"kind"`
Path []string `json:"path"`
Section string `json:"section,omitempty"`
Version string `json:"version,omitempty"`
}
// ErrSyntax is returned for malformed references.
var ErrSyntax = errors.New("invalid yetano reference")
var segRE = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]*$`)
// MaxLen bounds a reference (SEC-03).
const MaxLen = 512
// Parse parses s.
func Parse(s string) (Ref, error) {
if len(s) > MaxLen {
return Ref{}, fmt.Errorf("%w: longer than %d bytes", ErrSyntax, MaxLen)
}
rest, ok := strings.CutPrefix(s, "yetano:")
if !ok {
return Ref{}, fmt.Errorf("%w %q: must start with yetano:", ErrSyntax, s)
}
var r Ref
if i := strings.LastIndex(rest, "@"); i >= 0 {
r.Version, rest = rest[i+1:], rest[:i]
if r.Version == "" {
return Ref{}, fmt.Errorf("%w %q: empty version", ErrSyntax, s)
}
}
if i := strings.Index(rest, "#"); i >= 0 {
r.Section, rest = rest[i+1:], rest[:i]
if !segRE.MatchString(r.Section) {
return Ref{}, fmt.Errorf("%w %q: bad section", ErrSyntax, s)
}
}
parts := strings.Split(rest, "/")
r.Kind = parts[0]
r.Path = parts[1:]
want, ok := Kinds[r.Kind]
if !ok {
return Ref{}, fmt.Errorf("%w %q: unknown kind %q", ErrSyntax, s, r.Kind)
}
switch {
case want > 0 && len(r.Path) != want:
return Ref{}, fmt.Errorf("%w %q: %s takes %d path segment(s)", ErrSyntax, s, r.Kind, want)
case want < 0 && (len(r.Path) < 2):
return Ref{}, fmt.Errorf("%w %q: %s takes <package>/<topic>", ErrSyntax, s, r.Kind)
}
for _, p := range r.Path {
if !segRE.MatchString(p) {
return Ref{}, fmt.Errorf("%w %q: bad path segment %q", ErrSyntax, s, p)
}
}
return r, nil
}
// MustParse is Parse for constants in tests.
func MustParse(s string) Ref {
r, err := Parse(s)
if err != nil {
panic(err)
}
return r
}
// String formats r.
func (r Ref) String() string {
var b strings.Builder
b.WriteString("yetano:")
b.WriteString(r.Kind)
for _, p := range r.Path {
b.WriteByte('/')
b.WriteString(p)
}
if r.Section != "" {
b.WriteByte('#')
b.WriteString(r.Section)
}
if r.Version != "" {
b.WriteByte('@')
b.WriteString(r.Version)
}
return b.String()
}
// Target is the reference without section and version (what Backlinks index).
func (r Ref) Target() string {
r.Section, r.Version = "", ""
return r.String()
}
// For builds a reference.
func For(kind string, path ...string) string {
return Ref{Kind: kind, Path: path}.String()
}
var translit = strings.NewReplacer("ä", "ae", "ö", "oe", "ü", "ue", "ß", "ss", "é", "e", "è", "e", "à", "a", "ç", "c")
// Slug turns a heading into a section ID: lower case ASCII letters and
// digits; every run of anything else becomes one "-", trimmed.
func Slug(heading string) string {
var b strings.Builder
dash := false
heading = translit.Replace(strings.ToLower(heading))
for _, r := range heading {
if (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') {
b.WriteRune(r)
dash = false
continue
}
if !dash && b.Len() > 0 {
b.WriteByte('-')
dash = true
}
}
return strings.TrimRight(b.String(), "-")
}
+38
View File
@@ -0,0 +1,38 @@
package ref
import "testing"
func TestParse(t *testing.T) {
for _, s := range []string{
"yetano:package/yamase", "yetano:module/yamase/smtpd", "yetano:manual/yamase/mail-domain#dkim",
"yetano:manual/yamase-ctl/backup", "yetano:solution/mail-server@1.0.0", "yetano:task/mail.add-domain",
"yetano:capability/mail.smtp.inbound", "yetano:bigpicture/story.mail-groupware", "yetano:example/mail-server/personal",
} {
r, err := Parse(s)
if err != nil {
t.Errorf("%s: %v", s, err)
continue
}
if r.String() != s {
t.Errorf("round trip %s -> %s", s, r.String())
}
}
for _, bad := range []string{"package/yamase", "yetano:", "yetano:nope/x", "yetano:package", "yetano:package/a/b",
"yetano:module/x", "yetano:package/../x", "yetano:manual/x", "yetano:package/x#", "yetano:package/x@"} {
if _, err := Parse(bad); err == nil {
t.Errorf("%q accepted", bad)
}
}
}
func TestSlug(t *testing.T) {
for in, want := range map[string]string{
"Schritt 2: Schlüssel erzeugen": "schritt-2-schluessel-erzeugen",
"4. Trusted relays, SRS bounces and ereject": "4-trusted-relays-srs-bounces-and-ereject",
" Hello World! ": "hello-world",
} {
if got := Slug(in); got != want {
t.Errorf("%q: %q, want %q", in, got, want)
}
}
}