Documentation
¶
Overview ¶
Package themegen is the AI theme generator module's domain layer: the brief, theme, and validation value types, the generation/store ports, and the envelope parser that validates the model's JSON output. Provider adapters (the OpenAI-compatible client) live in infrastructure; the filesystem store lives in store; neither is imported by the domain.
Index ¶
- Constants
- Variables
- func ValidateBrief(brief Brief) error
- func ValidateThemeFiles(files map[string]string) error
- func ValidateThemeName(name string) error
- type ActiveThemeState
- type Brief
- type Edition
- type Finding
- type InstalledTheme
- type Service
- func (s *Service) Delete(ctx context.Context, name string) error
- func (s *Service) Generate(ctx context.Context, brief Brief, edition Edition) (Theme, ValidationReport, error)
- func (s *Service) Get(ctx context.Context, name string) (Theme, error)
- func (s *Service) List(ctx context.Context) ([]InstalledTheme, error)
- func (s *Service) Validate(ctx context.Context, theme Theme) ValidationReport
- func (s *Service) Zip(ctx context.Context, name string) ([]byte, error)
- type Theme
- type ThemeGenerationService
- type ThemeManifest
- type ThemeSources
- type ThemeStore
- type ThemeValidator
- type ValidationReport
Constants ¶
const ( // FindingSeverityError blocks install and activation. FindingSeverityError = "error" // FindingSeverityWarning surfaces in the UI without blocking. FindingSeverityWarning = "warning" )
Variables ¶
var ( // ErrInvalidBrief reports an empty or over-long generation brief. ErrInvalidBrief = errors.New("invalid brief") // ErrInvalidThemeName reports a theme name outside the slug grammar. ErrInvalidThemeName = errors.New("invalid theme name") // ErrPathNotAllowed reports a theme file path outside the allowlist. ErrPathNotAllowed = errors.New("path not allowed") // ErrSizeLimitExceeded reports a theme file or total exceeding the caps. ErrSizeLimitExceeded = errors.New("size limit exceeded") // ErrGenerationFailed reports an AI generation or repair failure. ErrGenerationFailed = errors.New("generation failed") // ErrThemeExists reports an install colliding with an existing theme dir. ErrThemeExists = errors.New("theme exists") // ErrThemeNotFound reports a lookup for a missing theme. ErrThemeNotFound = errors.New("theme not found") // ErrThemeActive reports a delete while the theme is active. ErrThemeActive = errors.New("theme active") // ErrActivationFailed reports a validation or config-write activation failure. ErrActivationFailed = errors.New("activation failed") ErrGenerationUnavailable = errors.New("generation unavailable") )
Functions ¶
func ValidateBrief ¶
ValidateBrief enforces the generation brief contract: non-empty and capped at 5,000 runes; style is a free-form preset hint.
func ValidateThemeFiles ¶
ValidateThemeFiles enforces the v1 theme contract: at least one of static/base.css or static/style.css, allowlisted paths only, per-file 512 KiB and 2 MiB total caps.
func ValidateThemeName ¶
ValidateThemeName reports whether name is an installable theme slug: lowercase alphanumerics and dashes, 2–50 runes, not reserved.
Types ¶
type ActiveThemeState ¶
ActiveThemeState resolves the currently active installed theme: the [theme] active value the edition composes over the embedded default.
type Finding ¶
Finding is one validation result: a rule hit with severity and detail. Errors block install and activation; warnings surface in the UI only.
func NewFinding ¶
NewFinding assembles a validation finding.
func ScanGeneratedThemeFiles ¶
ScanGeneratedThemeFiles flags executable content a generated theme must not ship: script elements, inline event handlers, and javascript: URLs in renderable markup, plus any root/ file (served from the site origin). It runs only on the generation path — manual operator themes are trusted and pass through boot, reload, and activation with structural validation alone — so every finding means the model added something the repair loop must remove. Paths iterate sorted so findings (and repair prompts) are deterministic.
type InstalledTheme ¶
type InstalledTheme struct {
Name string
Edition Edition
CreatedAt time.Time
Active bool
Source string
}
InstalledTheme is the manifest projection the list endpoint serves: identity, edition, creation time, active marker, and provenance.
func NewInstalledTheme ¶
func NewInstalledTheme( name string, edition Edition, createdAt time.Time, active bool, source string, ) InstalledTheme
NewInstalledTheme assembles an installed-theme projection.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service orchestrates theme generation: brief validation, AI generation, validation gate with a bounded repair loop, and auto-install as inactive.
func NewService ¶
func NewService( generation ThemeGenerationService, validator ThemeValidator, store ThemeStore, sources func(ctx context.Context, edition Edition) ThemeSources, edition Edition, ) *Service
NewService builds the orchestration service. A nil store disables persistence (generation still validates); a nil sources func generates from the distilled contract alone.
func (*Service) Generate ¶
func (s *Service) Generate( ctx context.Context, brief Brief, edition Edition, ) (Theme, ValidationReport, error)
Generate validates the brief, asks the model, validates the result, and installs it as inactive. A failing result is sent back to the model up to maxRepairAttempts times with its findings; a still-failing theme is refused. The final report is returned alongside the theme even on success so the UI can surface warnings.
func (*Service) List ¶
func (s *Service) List(ctx context.Context) ([]InstalledTheme, error)
List returns the installed-theme projections.
type Theme ¶
Theme is a validated generated theme: an installable slug plus the relative-path → content file map the store persists.
func ParseThemeEnvelope ¶
ParseThemeEnvelope validates the model's JSON envelope and splits it into a Theme. The name and files run the slug and allowlist validators; markdown fences and surrounding commentary are rejected.
type ThemeGenerationService ¶
type ThemeGenerationService interface {
GenerateTheme(ctx context.Context, brief Brief, edition Edition, sources ThemeSources) (Theme, error)
RepairTheme(ctx context.Context, brief Brief, sources ThemeSources, theme Theme, problems []string) (Theme, error)
}
ThemeGenerationService generates theme files from a brief. The edition selects the source theme; sources carries the readable base material (stylesheets and, for template overrides, page templates) the prompts ground on. RepairTheme feeds validation problems back to the model and receives the same brief and sources so the contract stays identical.
type ThemeManifest ¶
type ThemeManifest struct {
Name string `json:"name"`
Edition string `json:"edition"`
Generator string `json:"generator"`
CreatedAt time.Time `json:"createdAt"`
Source string `json:"source"`
}
ThemeManifest is the on-disk theme.json metadata: identity and provenance. Active state lives in config, never in the manifest.
func NewThemeManifest ¶
func NewThemeManifest( name, edition, generator string, createdAt time.Time, source string, ) ThemeManifest
NewThemeManifest assembles a manifest for an installed theme.
type ThemeSources ¶
ThemeSources is the edition's readable prompt grounding: the stylesheet sources always, plus the template page sources when the brief asks for template overrides.
func NewThemeSources ¶
func NewThemeSources(css, templates string) ThemeSources
NewThemeSources assembles the edition's readable prompt grounding.
type ThemeStore ¶
type ThemeStore interface {
Install(ctx context.Context, theme Theme) error
List(ctx context.Context) ([]InstalledTheme, error)
Get(ctx context.Context, name string) (Theme, error)
Delete(ctx context.Context, name string) error
Zip(ctx context.Context, name string) ([]byte, error)
}
ThemeStore persists installed themes on disk and builds download zips.
type ThemeValidator ¶
type ThemeValidator interface {
Validate(ctx context.Context, theme Theme) ValidationReport
}
ThemeValidator checks a generated theme before install and again before activation: size caps, CSS parse, and url() policy.
func NewValidator ¶
func NewValidator() ThemeValidator
NewValidator builds the default theme validator.
type ValidationReport ¶
ValidationReport is the outcome of validating a theme before install or activation. Valid is false when any error-severity finding exists.
func NewFindingsReport ¶
func NewFindingsReport(findings []Finding) ValidationReport
NewFindingsReport assembles a report whose Valid is derived from the findings: false when any error-severity finding exists. Decorators and whole-pipeline validators use it so severity handling stays in one place.
func NewValidationReport ¶
func NewValidationReport(valid bool, findings []Finding) ValidationReport
NewValidationReport assembles a validation report.