core

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package core provides error constructors, output formatters, sanitizers, fix logic, and types for the drift command. Subcommand cmd/run.go imports core for all drift analysis and reporting logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixMissingFile

func FixMissingFile(filename string) error

FixMissingFile creates a missing required context file from the template.

Parameters:

  • filename: Name of the file to create (e.g., "CONSTITUTION.md")

Returns:

  • error: Non-nil if the template is not found or file write fails

func FixStaleness

func FixStaleness(cmd *cobra.Command, ctx *entity.Context) error

FixStaleness archives completed tasks from TASKS.md.

Moves completed tasks to .context/archive/tasks-YYYY-MM-DD.md and removes them from the Completed section in TASKS.md.

Parameters:

  • cmd: Cobra command for output messages
  • ctx: Loaded context containing the files

Returns:

  • error: Non-nil if file operations fail

func FormatCheckName

func FormatCheckName(name drift.CheckName) string

FormatCheckName converts internal check identifiers to human-readable names.

Parameters:

  • name: Internal check identifier (e.g., "path_references", "staleness_check")

Returns:

  • string: Human-readable description of the check, or the original name if unknown

func OutputDriftJSON

func OutputDriftJSON(cmd *cobra.Command, report *drift.Report) error

OutputDriftJSON writes the drift report as pretty-printed JSON.

Parameters:

  • cmd: Cobra command for output stream
  • report: Drift detection report to serialize

Returns:

  • error: Non-nil if JSON encoding fails

func OutputDriftText

func OutputDriftText(cmd *cobra.Command, report *drift.Report) error

OutputDriftText writes the drift report as formatted text with icons.

Output is grouped into violations, warnings (by type), and passed checks. Includes a summary status line at the end.

Parameters:

  • cmd: Cobra command for output stream
  • report: Drift detection report to display

Returns:

  • error: Non-nil if violations were detected

Types

type FixResult

type FixResult struct {
	Fixed   int
	Skipped int
	Errors  []string
}

FixResult tracks fixes applied during drift fix.

Fields:

  • Fixed: Number of issues successfully fixed
  • Skipped: Number of issues skipped (not auto-fixable)
  • Errors: Error messages from failed fix attempts

func ApplyFixes

func ApplyFixes(
	cmd *cobra.Command, ctx *entity.Context, report *drift.Report,
) *FixResult

ApplyFixes attempts to auto-fix issues in the drift report.

Currently, supports fixing:

  • staleness: Archives completed tasks from TASKS.md
  • missing_file: Creates missing required files from templates

Parameters:

  • cmd: Cobra command for output messages
  • ctx: Loaded context
  • report: Drift report containing issues to fix

Returns:

  • *FixResult: Summary of fixes applied

type JSONOutput

type JSONOutput struct {
	Timestamp  string            `json:"timestamp"`
	Status     drift.StatusType  `json:"status"`
	Warnings   []drift.Issue     `json:"warnings"`
	Violations []drift.Issue     `json:"violations"`
	Passed     []drift.CheckName `json:"passed"`
}

JSONOutput represents the JSON structure for machine-readable drift output.

Fields:

  • Timestamp: RFC3339-formatted UTC time when the report was generated
  • Status: Overall drift status ("ok", "warning", or "violation")
  • Warnings: Issues that should be addressed but don't block
  • Violations: Constitution violations that must be fixed
  • Passed: Names of checks that passed successfully

Jump to

Keyboard shortcuts

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