Documentation
¶
Overview ¶
Package provenance implements Provenance Records functionality for LineSpec. Provenance Records are structured YAML artifacts that capture organizational intent, constraints, and reasoning behind system changes.
Index ¶
- Variables
- func CurrentDate() string
- func CurrentYear() int
- func GlobToRegex(glob string) string
- func IsValidID(id string) bool
- func MatchPattern(filePath, pattern string) (bool, error)
- func NextID(year int, existingIDs []string) string
- func ParseID(id string) (year int, seq int, err error)
- type CheckOptions
- type Commands
- func (c *Commands) Check(opts CheckOptions) error
- func (c *Commands) Complete(opts CompleteOptions) error
- func (c *Commands) Create(opts CreateOptions) error
- func (c *Commands) Deprecate(opts DeprecateOptions) error
- func (c *Commands) Graph(opts GraphOptions) error
- func (c *Commands) InstallHooks() error
- func (c *Commands) Lint(opts LintOptions) error
- func (c *Commands) LockScope(opts LockScopeOptions) error
- func (c *Commands) Status(opts StatusOptions) error
- type CommitChecker
- func (c *CommitChecker) AutoPopulateScope(record *Record) error
- func (c *CommitChecker) CheckCommit(commit string) ([]Violation, error)
- func (c *CommitChecker) CheckRange(from, to string) ([]Violation, error)
- func (c *CommitChecker) CheckStaged(messageFile string, commitTagRequired bool) ([]Violation, error)
- type CompleteOptions
- type CreateOptions
- type DeprecateOptions
- type Formatter
- func (f *Formatter) FormatCheckResult(violations []Violation, commit string)
- func (f *Formatter) FormatCompleteSuccess(record *Record)
- func (f *Formatter) FormatCreateSuccess(record *Record, superseded string)
- func (f *Formatter) FormatError(message string)
- func (f *Formatter) FormatGraph(loader *Loader, filter string)
- func (f *Formatter) FormatJSON(data interface{}) error
- func (f *Formatter) FormatLint(result *LintResult)
- func (f *Formatter) FormatLockScopeSuccess(record *Record, lockedPaths []string)
- func (f *Formatter) FormatStatus(loader *Loader, enforcement string, filter string)
- func (f *Formatter) FormatStatusDetailed(record *Record, loader *Loader)
- type Git
- func (g *Git) ExtractProvenanceIDs(message string) []string
- func (g *Git) GetCommitMessage(commit string) (string, error)
- func (g *Git) GetCommitsForRecord(recordID string) ([]string, error)
- func (g *Git) GetCommitsInRange(from, to string) ([]string, error)
- func (g *Git) GetFilesChangedInCommits(commits []string) ([]string, error)
- func (g *Git) GetGitEmail() (string, error)
- func (g *Git) GetModifiedFiles(commit string) ([]string, error)
- func (g *Git) GetStagedFiles() ([]string, error)
- func (g *Git) ReadCommitMessageFile(path string) (string, error)
- type GraphOptions
- type Issue
- type JSONGraphNode
- type JSONIssue
- type JSONLintResult
- type LintOptions
- type LintResult
- type Linter
- type Loader
- func (l *Loader) BuildGraph() error
- func (l *Loader) FilterByStatus(status Status) []*Record
- func (l *Loader) FilterByTag(tag string) []*Record
- func (l *Loader) GetAllIDs() []string
- func (l *Loader) GetRecord(id string) (*Record, bool)
- func (l *Loader) GetSupersededChain(id string) []string
- func (l *Loader) LoadAll() error
- func (l *Loader) LoadFile(path string) (*Record, error)
- func (l *Loader) LoadFromDir(dir string) error
- func (l *Loader) SaveRecord(record *Record) error
- func (l *Loader) UpdateSupersededBy()
- type LockScopeOptions
- type ProvenanceConfig
- type Record
- type Severity
- type Status
- type StatusOptions
- type Violation
Constants ¶
This section is empty.
Variables ¶
var IDPattern = regexp.MustCompile(`^prov-(\d{4})-(\d{3})(?:-[a-z0-9-]+)?$`)
IDPattern is the regex for valid provenance record IDs: prov-YYYY-NNN or prov-YYYY-NNN-service-name
var ValidStatuses = []Status{StatusOpen, StatusImplemented, StatusSuperseded, StatusDeprecated}
ValidStatuses contains all valid status values
Functions ¶
func CurrentDate ¶
func CurrentDate() string
CurrentDate returns the current date in ISO 8601 format (YYYY-MM-DD)
func GlobToRegex ¶
GlobToRegex converts a glob pattern to a regex pattern
func IsValidID ¶
IsValidID returns true if the ID matches the prov-YYYY-NNN format (with optional service suffix)
func MatchPattern ¶
MatchPattern checks if a file path matches a pattern (exact, glob, or regex)
Types ¶
type CheckOptions ¶
type CheckOptions struct {
Commit string // Single commit to check (default: HEAD)
Range string // Range to check (e.g., SHA..SHA)
Record string // Check only against a specific record
Staged bool // Check staged files instead of committed
MessageFile string // Path to commit message file (for staged mode)
ConfigFile string // Path to custom .linespec.yml file
}
CheckOptions holds options for the check command
type Commands ¶
type Commands struct {
Loader *Loader
Linter *Linter
Git *Git
Checker *CommitChecker
Formatter *Formatter
Config *ProvenanceConfig
RepoRoot string
}
Commands provides all provenance CLI commands
func NewCommands ¶
func NewCommands(config *ProvenanceConfig, repoRoot string, output *os.File, color bool) (*Commands, error)
NewCommands creates a new commands instance
func (*Commands) Check ¶
func (c *Commands) Check(opts CheckOptions) error
Check checks commits for violations
func (*Commands) Complete ¶
func (c *Commands) Complete(opts CompleteOptions) error
Complete marks a record as implemented
func (*Commands) Create ¶
func (c *Commands) Create(opts CreateOptions) error
Create creates a new provenance record
func (*Commands) Deprecate ¶
func (c *Commands) Deprecate(opts DeprecateOptions) error
Deprecate marks a record as deprecated
func (*Commands) Graph ¶
func (c *Commands) Graph(opts GraphOptions) error
Graph shows the provenance graph
func (*Commands) InstallHooks ¶
InstallHooks installs git hooks
func (*Commands) LockScope ¶
func (c *Commands) LockScope(opts LockScopeOptions) error
LockScope locks the scope of a record
func (*Commands) Status ¶
func (c *Commands) Status(opts StatusOptions) error
Status shows record status
type CommitChecker ¶
CommitChecker checks commits for provenance violations
func NewCommitChecker ¶
func NewCommitChecker(git *Git, loader *Loader) *CommitChecker
NewCommitChecker creates a new commit checker
func (*CommitChecker) AutoPopulateScope ¶
func (c *CommitChecker) AutoPopulateScope(record *Record) error
AutoPopulateScope populates affected_scope from git commits for a record
func (*CommitChecker) CheckCommit ¶
func (c *CommitChecker) CheckCommit(commit string) ([]Violation, error)
CheckCommit checks a single commit for violations
func (*CommitChecker) CheckRange ¶
func (c *CommitChecker) CheckRange(from, to string) ([]Violation, error)
CheckRange checks a range of commits for violations
func (*CommitChecker) CheckStaged ¶ added in v1.0.1
func (c *CommitChecker) CheckStaged(messageFile string, commitTagRequired bool) ([]Violation, error)
CheckStaged checks staged files against provenance records referenced in a commit message
type CompleteOptions ¶
type CompleteOptions struct {
RecordID string
Force bool
ConfigFile string // Path to custom .linespec.yml file
}
CompleteOptions holds options for the complete command
type CreateOptions ¶
type CreateOptions struct {
Title string
Supersedes string
Tags []string
NoEdit bool
IDSuffix string // Service suffix for ID (e.g., "user-service" creates prov-YYYY-NNN-user-service)
ConfigFile string // Path to custom .linespec.yml file
}
CreateOptions holds options for the create command
type DeprecateOptions ¶
type DeprecateOptions struct {
RecordID string
Reason string
ConfigFile string // Path to custom .linespec.yml file
}
DeprecateOptions holds options for the deprecate command
type Formatter ¶
Formatter handles output formatting for provenance commands
func NewFormatter ¶
NewFormatter creates a new formatter
func (*Formatter) FormatCheckResult ¶
FormatCheckResult formats the check command output
func (*Formatter) FormatCompleteSuccess ¶
FormatCompleteSuccess formats the complete command success output
func (*Formatter) FormatCreateSuccess ¶
FormatCreateSuccess formats the create command success output
func (*Formatter) FormatError ¶
FormatError formats an error message
func (*Formatter) FormatGraph ¶
FormatGraph formats the provenance graph
func (*Formatter) FormatJSON ¶
FormatJSON outputs data as JSON
func (*Formatter) FormatLint ¶
func (f *Formatter) FormatLint(result *LintResult)
FormatLint formats lint results
func (*Formatter) FormatLockScopeSuccess ¶
FormatLockScopeSuccess formats the lock-scope command success output
func (*Formatter) FormatStatus ¶
FormatStatus formats the status output
func (*Formatter) FormatStatusDetailed ¶
FormatStatusDetailed formats detailed status for a single record
type Git ¶
type Git struct {
RepoRoot string
}
Git provides git operations for provenance integration
func (*Git) ExtractProvenanceIDs ¶
ExtractProvenanceIDs extracts provenance record IDs from a commit message Format: [prov-YYYY-NNN] or [prov-YYYY-NNN-service-name]
func (*Git) GetCommitMessage ¶
GetCommitMessage returns the commit message for a given commit
func (*Git) GetCommitsForRecord ¶
GetCommitsForRecord returns all commits that reference a given record ID
func (*Git) GetCommitsInRange ¶
GetCommitsInRange returns all commits between two references
func (*Git) GetFilesChangedInCommits ¶
GetFilesChangedInCommits returns all files changed across a set of commits
func (*Git) GetGitEmail ¶
func (*Git) GetModifiedFiles ¶
GetModifiedFiles returns files modified in a commit or commit range
func (*Git) GetStagedFiles ¶ added in v1.0.1
GetStagedFiles returns files staged for commit
type GraphOptions ¶
type GraphOptions struct {
Root string // Start from specific record
Filter string // open | implemented | superseded | deprecated
Format string // human | json | dot
ConfigFile string // Path to custom .linespec.yml file
}
GraphOptions holds options for the graph command
type JSONGraphNode ¶
type JSONGraphNode struct {
ID string `json:"id"`
Title string `json:"title"`
Status string `json:"status"`
Supersedes string `json:"supersedes,omitempty"`
SupersededBy string `json:"superseded_by,omitempty"`
Children []JSONGraphNode `json:"children,omitempty"`
}
JSONGraphNode represents a node in the graph for JSON output
func BuildJSONGraph ¶
func BuildJSONGraph(loader *Loader) []JSONGraphNode
BuildJSONGraph builds the graph for JSON output
type JSONIssue ¶
type JSONIssue struct {
RecordID string `json:"record_id"`
Field string `json:"field"`
Message string `json:"message"`
Severity string `json:"severity"`
}
JSONIssue represents a single issue for JSON output
type JSONLintResult ¶
type JSONLintResult struct {
Enforcement string `json:"enforcement"`
Total int `json:"total"`
Passed int `json:"passed"`
Warnings int `json:"warnings"`
Errors int `json:"errors"`
Issues []JSONIssue `json:"issues"`
}
JSONLintResult represents lint results for JSON output
type LintOptions ¶
type LintOptions struct {
RecordID string
Enforcement string
Format string // human | json
ConfigFile string // Path to custom .linespec.yml file
}
LintOptions holds options for the lint command
type LintResult ¶
type LintResult struct {
Issues []Issue
PassedCount int
WarningCount int
ErrorCount int
HintCount int
Enforcement string
}
LintResult contains the results of linting a record or set of records
func (*LintResult) HasErrors ¶
func (r *LintResult) HasErrors() bool
HasErrors returns true if there are any error-level issues
func (*LintResult) ToJSON ¶
func (r *LintResult) ToJSON() *JSONLintResult
ToJSON converts LintResult to JSONLintResult
type Linter ¶
type Linter struct {
Loader *Loader
Enforcement string // none | warn | strict
CommitTagRequired bool
}
Linter validates Provenance Records according to the schema and enforcement rules
func (*Linter) LintAll ¶
func (l *Linter) LintAll() *LintResult
LintAll validates all loaded records
func (*Linter) LintRecord ¶
func (l *Linter) LintRecord(recordID string) *LintResult
LintRecord validates a single record
type Loader ¶
Loader handles loading and managing Provenance Records
func (*Loader) BuildGraph ¶
BuildGraph builds the ID index and validates relationships
func (*Loader) FilterByStatus ¶
FilterByStatus returns records filtered by status
func (*Loader) FilterByTag ¶
FilterByTag returns records filtered by tag
func (*Loader) GetSupersededChain ¶
GetSupersededChain returns the chain of records that supersede the given one
func (*Loader) LoadFromDir ¶
LoadFromDir loads all .yml files from the given directory
func (*Loader) SaveRecord ¶
SaveRecord saves a record to its file path
func (*Loader) UpdateSupersededBy ¶
func (l *Loader) UpdateSupersededBy()
UpdateSupersededBy updates the superseded_by field and status for all records that are superseded by other records
type LockScopeOptions ¶
type LockScopeOptions struct {
RecordID string
DryRun bool
ConfigFile string // Path to custom .linespec.yml file
}
LockScopeOptions holds options for the lock-scope command
type ProvenanceConfig ¶
type ProvenanceConfig struct {
Enforcement string
Dir string
CommitTagRequired bool
AutoAffectedScope bool
}
ProvenanceConfig holds provenance-related configuration
type Record ¶
type Record struct {
// Required fields
ID string `yaml:"id"`
Title string `yaml:"title"`
Status Status `yaml:"status"`
CreatedAt string `yaml:"created_at"`
Author string `yaml:"author"`
// Intent and reasoning
Intent string `yaml:"intent"`
Constraints []string `yaml:"constraints"`
// Scope
AffectedScope []string `yaml:"affected_scope"`
ForbiddenScope []string `yaml:"forbidden_scope"`
// Graph relationships
Supersedes string `yaml:"supersedes"`
SupersededBy string `yaml:"superseded_by"`
Related []string `yaml:"related"`
// Proof of completion
AssociatedLineSpecs []string `yaml:"associated_linespecs"`
AssociatedTraces []string `yaml:"associated_traces"`
Monitors []string `yaml:"monitors"`
// Tags
Tags []string `yaml:"tags"`
// File path (not stored in YAML, set during loading)
FilePath string `yaml:"-"`
}
Record represents a single Provenance Record See PROVENANCE_RECORD_SCHEMA.md for full documentation
func (*Record) IsMutableAfterImplemented ¶
IsMutableAfterImplemented returns true if the field can be modified after status is 'implemented'
type StatusOptions ¶
type StatusOptions struct {
RecordID string
Filter string // open | implemented | superseded | deprecated | tag:xxx
Format string // human | json
SaveScope bool // persist auto-populated scope to file
ConfigFile string // Path to custom .linespec.yml file
}
StatusOptions holds options for the status command