version

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package version provides spec version tracking with git-like history.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoChanges       = fmt.Errorf("no changes since last version")
	ErrVersionNotFound = fmt.Errorf("version not found")
	ErrNoVersions      = fmt.Errorf("no versions exist")
)

Errors

Functions

func SaveHistory

func SaveHistory(projectPath string, history *History) error

SaveHistory persists the version history.

Types

type CreateOptions

type CreateOptions struct {
	Author  string
	Message string
}

CreateOptions configures version creation.

type DiffLine

type DiffLine struct {
	Type    DiffType
	Content string
	LineNum int
}

DiffLine represents a single line in a diff.

type DiffResult

type DiffResult struct {
	SpecType   types.SpecType
	OldVersion int
	NewVersion int
	Lines      []DiffLine
	Additions  int
	Deletions  int
	Unchanged  int
}

DiffResult contains the diff between two versions.

func Diff

func Diff(projectPath string, specType types.SpecType, oldVersion, newVersion int) (*DiffResult, error)

Diff compares two versions of a spec.

func DiffWithCurrent

func DiffWithCurrent(projectPath string, specType types.SpecType, versionNum int) (*DiffResult, error)

DiffWithCurrent compares a version with the current spec file.

func (*DiffResult) FormatCompact

func (d *DiffResult) FormatCompact() string

FormatCompact formats a diff in compact form (changes only).

func (*DiffResult) FormatDiff

func (d *DiffResult) FormatDiff() string

FormatDiff formats a diff result for terminal output.

type DiffType

type DiffType string

DiffType indicates whether a line was added, removed, or unchanged.

const (
	DiffTypeUnchanged DiffType = " "
	DiffTypeAdded     DiffType = "+"
	DiffTypeRemoved   DiffType = "-"
)

type History

type History struct {
	SpecType types.SpecType `json:"spec_type"`
	Versions []Version      `json:"versions"`
}

History tracks all versions of a spec.

func GetHistory

func GetHistory(projectPath string, specType types.SpecType) (*History, error)

GetHistory loads the version history for a spec.

type Version

type Version struct {
	Number    int       `json:"number"`            // Sequential version number (1, 2, 3...)
	Hash      string    `json:"hash"`              // SHA256 of content
	Timestamp time.Time `json:"timestamp"`         // When version was created
	Author    string    `json:"author,omitempty"`  // Who created this version
	Message   string    `json:"message,omitempty"` // Description of changes
	Size      int       `json:"size"`              // Content size in bytes
}

Version represents a specific version of a spec.

func CreateVersion

func CreateVersion(projectPath string, specType types.SpecType, opts CreateOptions) (*Version, error)

CreateVersion creates a new version from the current spec content.

func GetLatestVersion

func GetLatestVersion(projectPath string, specType types.SpecType) (*Version, string, error)

GetLatestVersion returns the most recent version.

func GetVersion

func GetVersion(projectPath string, specType types.SpecType, versionNum int) (*Version, string, error)

GetVersion retrieves a specific version.

func ListVersions

func ListVersions(projectPath string, specType types.SpecType) ([]Version, error)

ListVersions returns all versions for a spec.

func Revert

func Revert(projectPath string, specType types.SpecType, versionNum int, message string) (*Version, error)

Revert restores a spec to a previous version.

Jump to

Keyboard shortcuts

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