configgen

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package configgen is the SINGLE SOURCE OF TRUTH for the operator settings.yaml surface (issue #140). It builds ONE model of the permconfig YAML schema — the settings subtrees (permissions, guardrails, posture, learning, models, and peers) — and renders BOTH of the operator-facing artifacts from it:

  • the commented settings.yaml SKELETON that `mecated config init` writes, and
  • the Markdown REFERENCE table (docs/configuration-reference.md).

Because both surfaces walk the SAME model, they cannot drift from each other; and because the model is built by reflecting over the permconfig.*Section structs (the authoritative strict-decode key list), neither can drift from the code.

The go/ast boundary

The doc-comment HARVEST (parsing schema.go's field comments via go/ast) happens in the build-time generator program ONLY (internal/configgen/cmd/configref). That generator emits two COMMITTED artifacts: settings.skeleton.yaml (embedded here and served by `config init`) and docs/configuration-reference.md. The shipped mecated binary never imports go/ast — it //go:embed's the committed skeleton. The artifacts are regenerated by `task docs:configref` and a CI step fails the build if they drift.

LAYERING: this is an adapter-side helper. It imports internal/adapter/permconfig (the schema it reflects over). It is imported by the generator cmd and by cmd/mecated (for the embedded skeleton). It is never imported by the engine, the domain, or the port layers.

Index

Constants

View Source
const SettingsRelPath = permconfig.UserSettingsRelPath

SettingsRelPath is the user-global settings.yaml location relative to the XDG config base, re-exported from permconfig so the WRITE path (config init) and the READ path (the resolver's loadUserRules) provably resolve the same file. There is no second hardcoded "mecatl/settings.yaml" copy.

Variables

This section is empty.

Functions

func RenderReference

func RenderReference(m *Model) string

RenderReference renders the Markdown reference page: a table per subtree plus the hand-written flag-driven-features pointer block. Deterministic.

func RenderSkeleton

func RenderSkeleton(m *Model) string

RenderSkeleton renders the commented settings.yaml skeleton from the model. The output is deterministic (the model's slices are already in a fixed order), so the CI diff-guard never flakes.

func Skeleton

func Skeleton() string

Skeleton returns the committed commented settings.yaml skeleton that `mecated config init` writes (or prints with --print). It is the embedded artifact, NOT a fresh render — the shipped binary stays go/ast-free.

Types

type Docs

type Docs map[string]string

Docs maps "StructName.FieldName" to a field's doc-comment text. The generator harvests it via go/ast (the ONLY go/ast user); BuildModel attaches it to the reflected fields. Tests can pass an empty Docs (the structure is still exercised).

type Field

type Field struct {
	// Key is the YAML key (e.g. "classifier-slot").
	Key string
	// Type is the rendered Go-ish type (e.g. "string", "map[string]string",
	// "[]string", "[]category", "bool", "int").
	Type string
	// Default is the rendered zero/default value.
	Default string
	// Doc is the field's one-or-more-line description, harvested from its doc-comment.
	Doc string
	// EnableNote mirrors Subtree.EnableNote at the field grain (e.g. guardrails.model
	// "setting this ENABLES guardrails").
	EnableNote string
	// Nested, when non-nil, describes a structured sub-mapping (e.g. each router
	// category, or the subagent permissions block) so the skeleton can show its shape.
	Nested []*Field
	// SkeletonCollapse renders this field as its type-shaped placeholder in the
	// skeleton even when Nested is populated for the exhaustive reference. It is
	// used for closed unions whose mutually exclusive variants cannot all appear
	// in one uncomment-and-run structural example; Subtree.Example shows valid arms.
	SkeletonCollapse bool
	// ExampleValue is a short inline example used in the skeleton's commented binding
	// (e.g. `default: sonnet`). Empty renders a type-shaped placeholder.
	ExampleValue string
	// ExampleMapKey is the illustrative map key a map-of-struct skeleton entry renders
	// under (e.g. the openrouter.models per-model entry's model id). Empty renders the
	// generic `"<key>"` placeholder. Documentation only — the operator replaces it.
	ExampleMapKey string
}

Field is one key within a subtree (or a scalar subtree's single value).

type Model

type Model struct {
	Subtrees []*Subtree
}

Model is the whole settings.yaml surface: the ordered top-level subtrees.

func BuildModel

func BuildModel(docs Docs) *Model

BuildModel constructs the settings.yaml Model by REFLECTING over the permconfig *Section structs (yaml tags + types, in declaration order) and attaching the harvested doc-comments, the hand-pinned tier map, and the enable notes / examples. It uses reflect ONLY (no go/ast), so it is safe to compile anywhere and is the ONE place the surface's shape, semantics, and provenance come together — both the generator and the configgen tests call it, so neither can build a different model.

type Subtree

type Subtree struct {
	// Key is the top-level YAML key (e.g. "models").
	Key string
	// Tier is which tier(s) honour the subtree.
	Tier Tier
	// Doc is the subtree-level description (from the struct or Config field comment).
	Doc string
	// EnableNote, when non-empty, is the headline enable-semantics line surfaced in
	// the skeleton AND the reference (e.g. the router taxonomy-presence note). It is
	// the one thing operators most need to know about an opt-in subtree.
	EnableNote string
	// CommentedOut marks an opt-in subtree the skeleton emits fully commented (the
	// operator uncomments to enable). Always-present subtrees (permissions) are live.
	CommentedOut bool
	// Scalar marks a subtree that is a bare scalar (posture) rather than a mapping; its
	// Fields holds a single pseudo-field describing the scalar.
	Scalar bool
	// ListBody marks a subtree whose body is a YAML SEQUENCE of the Fields (each field
	// is one ELEMENT key), not a mapping. The skeleton renders one `- ` list element
	// showing the fields; the reference renders the keys as `subtree[].field`.
	ListBody bool
	// Fields are the keys within the subtree, in declaration order.
	Fields []*Field
	// Example is an optional commented example value block (raw YAML lines, no leading
	// comment markers) the skeleton renders under the subtree to show real shape.
	Example []string
}

Subtree is one top-level YAML key (permissions / guardrails / posture / models).

type Tier

type Tier string

Tier classifies which configuration tier honours a subtree. It is HAND-PINNED per subtree (the tier is a security decision — whether a project file may set it — not a struct-tag derivable by reflection), and is NOT machine-validated against the schema. A regression test (TestSubtreeTiersAreAsPinned) pins the expected Tier per subtree so a future mislabel is caught.

const (
	// TierOperator subtrees are honoured ONLY from the user-global settings.yaml + CLI
	// (a project-tier file's copy is ignored with a WARN — honouring it would be a
	// security downgrade).
	TierOperator Tier = "operator"
	// TierProject subtrees may ALSO be set in a project .mecatl/settings.yaml (within
	// the operator's cap / trust gate where one applies).
	TierProject Tier = "operator + project"
)

Directories

Path Synopsis
cmd
configref command
Command configref is the BUILD-TIME generator (issue #140) that emits the two committed configuration artifacts from the permconfig YAML schema:
Command configref is the BUILD-TIME generator (issue #140) that emits the two committed configuration artifacts from the permconfig YAML schema:

Jump to

Keyboard shortcuts

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