domain

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditEntry

type AuditEntry struct {
	Timestamp   time.Time              `json:"timestamp" yaml:"timestamp"`
	NodeID      string                 `json:"node_id" yaml:"node_id"`
	Operation   string                 `json:"operation" yaml:"operation"` // create, update, delete, set, append, unset, move, baseline
	User        string                 `json:"user" yaml:"user"`
	ContentHash string                 `json:"content_hash,omitempty" yaml:"content_hash,omitempty"`
	Before      map[string]interface{} `json:"before,omitempty" yaml:"before,omitempty"`
	After       map[string]interface{} `json:"after,omitempty" yaml:"after,omitempty"`
}

AuditEntry represents a single entry in the audit log. It tracks changes to nodes over time (who, what, when).

func (*AuditEntry) Validate

func (a *AuditEntry) Validate() error

Validate checks that all required fields are present and valid.

type Block

type Block struct {
	Type string                 `json:"type"` // table, rule, param, mechanic, list, etc.
	Data map[string]interface{} `json:"data,omitempty"`
}

Block represents a content block within a section. Block fields (except 'type') are stored in Data map and written as inline YAML fields.

func (Block) MarshalYAML

func (b Block) MarshalYAML() (interface{}, error)

MarshalYAML implements custom YAML marshaling for Block. It writes Data fields as inline block fields (not nested under 'data:'). Keys are sorted for deterministic output (important for content hashing).

func (*Block) UnmarshalYAML

func (b *Block) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements custom YAML unmarshaling for Block. It captures all fields except 'type' into the Data map, preserving inline block fields.

type Constraint

type Constraint struct {
	Expr    string `json:"expr" yaml:"expr"`       // CEL expression
	Message string `json:"message" yaml:"message"` // Error message if constraint fails
	Scope   string `json:"scope" yaml:"scope"`     // Which nodes this applies to (e.g., "all", "mechanic", "systems/*")
}

Constraint defines a validation rule that must be satisfied. Constraints use CEL (Common Expression Language) for validation.

func (*Constraint) Validate

func (c *Constraint) Validate() error

Validate checks that all required fields are present.

type Content

type Content struct {
	Sections []Section `json:"sections" yaml:"sections"`
}

Content holds the structured content sections of a node.

type Contract

type Contract struct {
	Name     string   `json:"name" yaml:"name"`
	Scenario string   `json:"scenario" yaml:"scenario"`
	Given    []string `json:"given,omitempty" yaml:"given,omitempty"`
	When     []string `json:"when,omitempty" yaml:"when,omitempty"`
	Then     []string `json:"then,omitempty" yaml:"then,omitempty"`
}

Contract represents a Gherkin-style scenario or acceptance criteria.

type DecoError

type DecoError struct {
	Code       string
	Summary    string
	Detail     string
	Location   *Location
	Context    []string
	Suggestion string
	Related    []Related
}

DecoError represents a structured error following Rust-like error patterns

func (DecoError) Error

func (e DecoError) Error() string

Error implements the error interface

type DocRef

type DocRef struct {
	Path     string   `json:"path" yaml:"path"`
	Keywords []string `json:"keywords,omitempty" yaml:"keywords,omitempty"`
	Context  string   `json:"context,omitempty" yaml:"context,omitempty"`
}

DocRef represents a reference to an external markdown file.

type ErrorCode

type ErrorCode struct {
	Code     string
	Category string
	Message  string
}

ErrorCode represents a registered error code with metadata

type ErrorCodeRegistry

type ErrorCodeRegistry struct {
	// contains filtered or unexported fields
}

ErrorCodeRegistry maintains a registry of all error codes

func NewErrorCodeRegistry

func NewErrorCodeRegistry() *ErrorCodeRegistry

NewErrorCodeRegistry creates a new error code registry with all defined codes

func (*ErrorCodeRegistry) AllCodes

func (r *ErrorCodeRegistry) AllCodes() []ErrorCode

AllCodes returns all registered error codes

func (*ErrorCodeRegistry) ByCategory

func (r *ErrorCodeRegistry) ByCategory(category string) []ErrorCode

ByCategory returns all error codes in a specific category

func (*ErrorCodeRegistry) Categories

func (r *ErrorCodeRegistry) Categories() []string

Categories returns all unique categories

func (*ErrorCodeRegistry) Lookup

func (r *ErrorCodeRegistry) Lookup(code string) (ErrorCode, bool)

Lookup retrieves an error code by its code string

type ErrorDocsGenerator

type ErrorDocsGenerator struct {
	// contains filtered or unexported fields
}

ErrorDocsGenerator generates markdown documentation for error codes

func NewErrorDocsGenerator

func NewErrorDocsGenerator(registry *ErrorCodeRegistry) *ErrorDocsGenerator

NewErrorDocsGenerator creates a new documentation generator

func (*ErrorDocsGenerator) GenerateCodeList

func (g *ErrorDocsGenerator) GenerateCodeList() string

GenerateCodeList generates a simple list of all codes

func (*ErrorDocsGenerator) GenerateDetailedMarkdown

func (g *ErrorDocsGenerator) GenerateDetailedMarkdown() string

GenerateDetailedMarkdown generates detailed markdown with examples

func (*ErrorDocsGenerator) GenerateMarkdown

func (g *ErrorDocsGenerator) GenerateMarkdown() string

GenerateMarkdown generates markdown documentation for all error codes

type ErrorFormatter

type ErrorFormatter struct {
	// contains filtered or unexported fields
}

ErrorFormatter formats DecoError objects in a Rust-like style

func NewErrorFormatter

func NewErrorFormatter() *ErrorFormatter

NewErrorFormatter creates a new error formatter with color enabled by default

func (*ErrorFormatter) Format

func (f *ErrorFormatter) Format(err DecoError) string

Format formats a single DecoError into a human-readable string

func (*ErrorFormatter) FormatMultiple

func (f *ErrorFormatter) FormatMultiple(errors []DecoError) string

FormatMultiple formats multiple errors

func (*ErrorFormatter) FormatWithSource

func (f *ErrorFormatter) FormatWithSource(err DecoError, sourceLines []string) string

FormatWithSource formats a DecoError with source code context

func (*ErrorFormatter) SetColor

func (f *ErrorFormatter) SetColor(enabled bool)

SetColor enables or disables color output

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

Graph represents a collection of nodes with efficient lookup. It provides methods for adding, retrieving, and iterating over nodes.

func NewGraph

func NewGraph() *Graph

NewGraph creates a new empty graph.

func (*Graph) Add

func (g *Graph) Add(node Node) error

Add adds a node to the graph. Returns an error if a node with the same ID already exists.

func (*Graph) All

func (g *Graph) All() []Node

All returns a slice of all nodes in the graph.

func (*Graph) Count

func (g *Graph) Count() int

Count returns the number of nodes in the graph.

func (*Graph) Get

func (g *Graph) Get(id string) (Node, bool)

Get retrieves a node by ID. Returns the node and true if found, or a zero-value node and false if not found.

func (*Graph) Remove

func (g *Graph) Remove(id string) bool

Remove removes a node from the graph by ID. Returns true if the node was removed, false if it didn't exist.

func (*Graph) Update

func (g *Graph) Update(node Node) error

Update updates an existing node in the graph. Returns an error if the node doesn't exist.

type Issue

type Issue struct {
	ID          string `json:"id" yaml:"id"`
	Description string `json:"description" yaml:"description"`
	Severity    string `json:"severity" yaml:"severity"` // low, medium, high, critical
	Location    string `json:"location" yaml:"location"` // path to field (e.g., "content.sections[0]")
	Resolved    bool   `json:"resolved" yaml:"resolved"`
}

Issue represents a tracked TBD or question within a node. Issues mark areas that need clarification or resolution.

func (*Issue) Validate

func (i *Issue) Validate() error

Validate checks that all required fields are present and valid.

type Location

type Location struct {
	File   string
	Line   int
	Column int
}

Location represents a position in a file

func (Location) String

func (l Location) String() string

String formats the location as "file:line:column", "file:line", or "file"

type Node

type Node struct {
	// Core metadata
	ID      string   `json:"id" yaml:"id"`
	Kind    string   `json:"kind" yaml:"kind"`       // mechanic, system, feature, etc.
	Version int      `json:"version" yaml:"version"` // Incremented on updates
	Status  string   `json:"status" yaml:"status"`   // draft, approved, deprecated, etc.
	Title   string   `json:"title" yaml:"title"`
	Tags    []string `json:"tags,omitempty" yaml:"tags,omitempty"`

	// Source location (set during load, not serialized)
	SourceFile string `json:"-" yaml:"-"`
	// Raw YAML content (set during load, not serialized) - used for line number tracking
	RawContent []byte `json:"-" yaml:"-"`

	// References to other nodes
	Refs Ref `json:"refs,omitempty" yaml:"refs,omitempty"`

	// Structured content sections
	Content *Content `json:"content,omitempty" yaml:"content,omitempty"`

	// Tracked TBDs and questions
	Issues []Issue `json:"issues,omitempty" yaml:"issues,omitempty"`

	// External doc references
	Docs []DocRef `json:"docs,omitempty" yaml:"docs,omitempty"`

	// Optional fields
	Summary     string                 `json:"summary,omitempty" yaml:"summary,omitempty"`
	Glossary    map[string]string      `json:"glossary,omitempty" yaml:"glossary,omitempty"`
	Contracts   []Contract             `json:"contracts,omitempty" yaml:"contracts,omitempty"`
	LLMContext  string                 `json:"llm_context,omitempty" yaml:"llm_context,omitempty"`
	Constraints []Constraint           `json:"constraints,omitempty" yaml:"constraints,omitempty"`
	Reviewers   []Reviewer             `json:"reviewers,omitempty" yaml:"reviewers,omitempty"`
	Custom      map[string]interface{} `json:"custom,omitempty" yaml:"custom,omitempty"`
}

Node represents a design node in the game design document. Nodes are the core building blocks of a GDD, containing metadata, references to other nodes, structured content, and tracked issues.

func (Node) MarshalYAML

func (n Node) MarshalYAML() (interface{}, error)

MarshalYAML implements custom YAML marshaling for Node. It ensures Glossary and Custom maps are serialized with sorted keys.

func (*Node) Validate

func (n *Node) Validate() error

Validate checks that all required fields are present and valid.

type Ref

type Ref struct {
	Uses        []RefLink `json:"uses,omitempty" yaml:"uses,omitempty"`
	Related     []RefLink `json:"related,omitempty" yaml:"related,omitempty"`
	EmitsEvents []string  `json:"emits_events,omitempty" yaml:"emits_events,omitempty"`
	Vocabulary  []string  `json:"vocabulary,omitempty" yaml:"vocabulary,omitempty"`
}

Ref holds references from one node to other nodes. It tracks dependencies, relationships, events, and shared vocabulary.

type RefLink struct {
	Target   string `json:"target" yaml:"target"`
	Context  string `json:"context,omitempty" yaml:"context,omitempty"`
	Resolved bool   `json:"resolved,omitempty" yaml:"resolved,omitempty"`
}

RefLink represents a single reference to another node with optional context.

func (*RefLink) Validate

func (r *RefLink) Validate() error

Validate checks that the RefLink has a valid target.

type Related struct {
	NodeID string
	Reason string
}

Related represents a related node in an error context

type Reviewer

type Reviewer struct {
	Name      string    `json:"name" yaml:"name"`                     // reviewer email/username
	Timestamp time.Time `json:"timestamp" yaml:"timestamp"`           // when approved
	Version   int       `json:"version" yaml:"version"`               // version that was approved
	Note      string    `json:"note,omitempty" yaml:"note,omitempty"` // optional comment
}

Reviewer represents an approval record for a node version.

type Scenario

type Scenario struct {
	Name        string // Scenario name
	Description string // Scenario description text
	Given       []Step // Preconditions
	When        []Step // Actions
	Then        []Step // Expected outcomes
}

Scenario represents a parsed contract scenario with structured steps. This is the validation-ready form of the YAML Contract type.

func ParseContract

func ParseContract(c Contract) Scenario

ParseContract converts a YAML Contract into a validation-ready Scenario.

func ParseContracts

func ParseContracts(contracts []Contract) []Scenario

ParseContracts converts multiple YAML Contracts into Scenarios.

func (*Scenario) AllNodeRefs

func (s *Scenario) AllNodeRefs() []string

AllNodeRefs returns all unique node references across all steps.

func (*Scenario) AllSteps

func (s *Scenario) AllSteps() []Step

AllSteps returns all steps in the scenario in order (Given, When, Then).

func (*Scenario) Validate

func (s *Scenario) Validate() error

Validate checks basic structural requirements of a scenario. Returns an error if the scenario is invalid.

type Section

type Section struct {
	Name   string  `json:"name" yaml:"name"`
	Blocks []Block `json:"blocks" yaml:"blocks"`
}

Section represents a logical section in the node content.

type SortedInterfaceMap

type SortedInterfaceMap map[string]interface{}

SortedInterfaceMap wraps map[string]interface{} for deterministic YAML output. Keys are sorted alphabetically when marshaling to YAML.

func (SortedInterfaceMap) MarshalYAML

func (m SortedInterfaceMap) MarshalYAML() (interface{}, error)

type SortedStringMap

type SortedStringMap map[string]string

SortedStringMap wraps map[string]string for deterministic YAML output. Keys are sorted alphabetically when marshaling to YAML.

func (SortedStringMap) MarshalYAML

func (m SortedStringMap) MarshalYAML() (interface{}, error)

type Step

type Step struct {
	Text       string   // The raw step text
	NodeRefs   []string // Node IDs referenced in this step (extracted from @node.id patterns)
	StepType   StepType // Given, When, or Then
	StepNumber int      // Position within its type (1-indexed)
}

Step represents a single Given/When/Then step in a contract scenario. Steps can reference nodes using the @node.id syntax.

func (*Step) ValidateStep

func (step *Step) ValidateStep() error

ValidateStep checks that a step is well-formed.

type StepType

type StepType string

StepType indicates which phase of a scenario a step belongs to.

const (
	StepTypeGiven StepType = "given"
	StepTypeWhen  StepType = "when"
	StepTypeThen  StepType = "then"
)

Jump to

Keyboard shortcuts

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