config

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides YAML configuration parsing and validation for the Guardian CLI tool. It handles reading, writing, and validating the various configuration files stored in the .agreements/ directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveConstitution

func SaveConstitution(path string, c *Constitution) error

SaveConstitution writes a Constitution to the given path as YAML.

func SaveException

func SaveException(path string, e *Exception) error

SaveException writes an Exception to the given path as YAML.

func SaveProposal

func SaveProposal(path string, p *Proposal) error

SaveProposal writes a Proposal to the given path as YAML.

func SaveVote

func SaveVote(path string, v *Vote) error

SaveVote writes a Vote to the given path as YAML.

func ValidateConstitution

func ValidateConstitution(c *Constitution) error

ValidateConstitution validates a Constitution for required fields and correct enum values.

func ValidateException

func ValidateException(e *Exception) error

ValidateException validates an Exception for required fields.

func ValidateProposal

func ValidateProposal(p *Proposal) error

ValidateProposal validates a Proposal for required fields and correct enum values.

func ValidateRules

func ValidateRules(r *RulesFile) error

ValidateRules validates a RulesFile for required fields and correct values.

func ValidateVote

func ValidateVote(v *Vote) error

ValidateVote validates a Vote for required fields and correct enum values.

Types

type Constitution

type Constitution struct {
	Governance Governance      `yaml:"governance"`
	Identity   Identity        `yaml:"identity"`
	Roles      map[string]Role `yaml:"roles"`
	LLM        LLMConfig       `yaml:"llm"`
}

Constitution represents the top-level constitution.yml configuration file.

func LoadConstitution

func LoadConstitution(path string) (*Constitution, error)

LoadConstitution reads and parses a constitution.yml file from the given path.

type Exception

type Exception struct {
	ID        string     `yaml:"id"`
	RuleID    string     `yaml:"rule_id"`
	Paths     []string   `yaml:"paths"`
	Reason    string     `yaml:"reason"`
	CreatedBy string     `yaml:"created_by"`
	CreatedAt time.Time  `yaml:"created_at"`
	ExpiresAt *time.Time `yaml:"expires_at,omitempty"`
}

Exception represents a temporary or permanent exemption from a rule for specific file paths.

func LoadAllExceptions

func LoadAllExceptions(dir string) ([]*Exception, error)

LoadAllExceptions reads all YAML exception files from the given directory.

func LoadException

func LoadException(path string) (*Exception, error)

LoadException reads and parses an exception YAML file from the given path.

type ExceptionPolicy

type ExceptionPolicy struct {
	RequireApproval bool `yaml:"require_approval"`
}

ExceptionPolicy configures how exceptions are handled.

type Governance

type Governance struct {
	Voters             []VoterRef              `yaml:"voters"`
	Quorum             QuorumConfig            `yaml:"quorum"`
	ForbidSelfApproval bool                    `yaml:"forbid_self_approval"`
	AllowVoteChange    bool                    `yaml:"allow_vote_change"`
	ProposalTTLDays    int                     `yaml:"proposal_ttl_days"`
	PerRuleOverrides   map[string]RuleOverride `yaml:"per_rule_overrides"`
	Exceptions         ExceptionPolicy         `yaml:"exceptions"`
}

Governance defines the voting and proposal governance rules.

type Identity

type Identity struct {
	AllowedDomains       []string `yaml:"allowed_domains"`
	RequireSignedCommits bool     `yaml:"require_signed_commits"`
}

Identity configures identity verification settings.

type LLMConfig

type LLMConfig struct {
	Provider string     `yaml:"provider"` // deepseek|openai|claude|custom
	Endpoint string     `yaml:"endpoint"`
	Model    string     `yaml:"model"`
	Prompts  LLMPrompts `yaml:"prompts"`
}

LLMConfig configures the LLM provider used by Guardian.

type LLMPrompts

type LLMPrompts struct {
	CheckSystem   string `yaml:"check_system"`
	ProposeSystem string `yaml:"propose_system"`
}

LLMPrompts allows overriding the built-in LLM system prompts.

type Proposal

type Proposal struct {
	ID           string         `yaml:"id"`
	RuleID       string         `yaml:"rule_id"`
	ProposalType string         `yaml:"proposal_type"` // modify|add|remove
	Change       ProposalChange `yaml:"change"`
	Reason       string         `yaml:"reason"`
	Impact       string         `yaml:"impact"`
	CreatedBy    string         `yaml:"created_by"`
	CreatedAt    time.Time      `yaml:"created_at"`
	Status       string         `yaml:"status"` // proposed|accepted|rejected|withdrawn|expired
}

Proposal represents a proposal to modify, add, or remove a rule.

func LoadAllProposals

func LoadAllProposals(dir string) ([]*Proposal, error)

LoadAllProposals reads all YAML proposal files from the given directory. It returns only files with .yml or .yaml extensions.

func LoadProposal

func LoadProposal(path string) (*Proposal, error)

LoadProposal reads and parses a proposal YAML file from the given path.

type ProposalChange

type ProposalChange struct {
	Description string `yaml:"description"`
	Details     string `yaml:"details"`
}

ProposalChange describes the proposed change.

type QuorumConfig

type QuorumConfig struct {
	Type      string  `yaml:"type"`      // majority|two_thirds|unanimous|custom
	Threshold float64 `yaml:"threshold"` // for custom
}

QuorumConfig defines the quorum calculation method.

type Role

type Role struct {
	Members []RoleMember `yaml:"members"`
}

Role defines a named role and its members.

type RoleMember

type RoleMember struct {
	Email string `yaml:"email"`
}

RoleMember represents a single member within a role.

type Rule

type Rule struct {
	ID          string                 `yaml:"id"`
	Description string                 `yaml:"description"`
	Type        string                 `yaml:"type"`
	Config      map[string]interface{} `yaml:"config"`
	Severity    string                 `yaml:"severity"`
}

Rule defines a single rule that Guardian checks code changes against.

type RuleOverride

type RuleOverride struct {
	Quorum QuorumConfig `yaml:"quorum"`
}

RuleOverride allows per-rule quorum overrides.

type RulesFile

type RulesFile struct {
	Rules []Rule `yaml:"rules"`
}

RulesFile represents the rules.yml configuration containing all rule definitions.

func LoadRules

func LoadRules(path string) (*RulesFile, error)

LoadRules reads and parses a rules.yml file from the given path.

type Vote

type Vote struct {
	ProposalID string    `yaml:"proposal_id"`
	VoterEmail string    `yaml:"voter_email"`
	Decision   string    `yaml:"decision"` // yes|no
	Comment    string    `yaml:"comment"`
	VotedAt    time.Time `yaml:"voted_at"`
}

Vote represents a voter's decision on a proposal.

func LoadVote

func LoadVote(path string) (*Vote, error)

LoadVote reads and parses a vote YAML file from the given path.

func LoadVotesForProposal

func LoadVotesForProposal(dir string, proposalID string) ([]*Vote, error)

LoadVotesForProposal reads all vote files from a proposal-specific subdirectory within the votes directory. It expects the layout: <dir>/<proposalID>/<voter_email>.yml

type VoterRef

type VoterRef struct {
	Role string `yaml:"role"`
}

VoterRef references a role that is eligible to vote.

Jump to

Keyboard shortcuts

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