adr

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package adr manages Architectural Decision Records — markdown files with YAML frontmatter that capture significant design choices, their context, and their consequences.

Index

Constants

View Source
const (
	StatusProposed   = "Proposed"
	StatusAccepted   = "Accepted"
	StatusDeprecated = "Deprecated"
	StatusSuperseded = "Superseded"
	StatusRejected   = "Rejected"
)

Status values an ADR can carry. Free-form strings are also tolerated when reading, but writes funnel through these constants.

View Source
const Dir = ".cloop/adr"

Dir is the relative path inside a project where ADR files live.

Variables

This section is empty.

Functions

func EnsureDir

func EnsureDir(workdir string) (string, error)

EnsureDir creates the ADR directory if needed.

func Filename

func Filename(id int, title string) string

Filename for a given ID and title (e.g. "0007-use-sqlite-for-state.md").

func LinkSupersedes

func LinkSupersedes(workdir string, newID, oldID int) error

LinkSupersedes wires this ADR to mark `oldID` as superseded by `a.ID`, updating both files. If the old ADR cannot be loaded, returns an error.

func NextID

func NextID(workdir string) (int, error)

NextID returns the smallest unused 1-indexed ID in the ADR directory.

func ParseStatus

func ParseStatus(s string) (string, error)

ParseStatus resolves a user-supplied status to its canonical spelling, case-insensitively.

Reads tolerate a free-form status so that a hand-written file still loads, but writes must not invent a sixth value: a typo persisted as "Acepted" is invisible to every status filter and silently drops the record out of the listings an operator relies on. Refusing it here is the only place that can tell the difference between a typo and a deliberate choice.

func Slug

func Slug(title string) string

Slug turns a title into a filesystem-safe slug.

func Statuses

func Statuses() []string

Statuses returns the valid statuses in lifecycle order.

func Template

func Template(title string) string

Template returns the default body for a newly created ADR.

Types

type ADR

type ADR struct {
	ID           int       // sequential, 1-indexed
	Title        string    // human title
	Status       string    // Proposed/Accepted/Deprecated/Superseded/Rejected
	Date         time.Time // creation date
	Deciders     []string
	Tags         []string
	Supersedes   []int  // ADR IDs this one replaces
	SupersededBy []int  // ADR IDs that replace this one
	Path         string // absolute file path
	Body         string // markdown body (after frontmatter)
}

ADR is one decision record.

func Create

func Create(workdir, title, body string) (*ADR, error)

Create writes a brand-new ADR with the given title and optional body. If body is empty, the default template is used. Returns the saved ADR.

func FindByID

func FindByID(workdir string, id int) (*ADR, error)

FindByID resolves an ADR by its numeric ID.

func List

func List(workdir string) ([]*ADR, error)

List loads all ADRs sorted by ID ascending. Returns an empty slice (not error) if the directory does not exist.

func Load

func Load(path string) (*ADR, error)

Load parses an ADR markdown file with YAML frontmatter.

func (*ADR) Save

func (a *ADR) Save() error

Save writes the ADR back to its file. If Path is empty, the caller must set it before calling.

The write is atomic: data is staged in a sibling .tmp file, fsynced, chmod'd, then renamed into place. Without this, a crash mid-write — or two writers racing on a Status update (e.g. one process accepting, another deprecating) — would leave the markdown frontmatter half-written and unparseable, which would silently drop the ADR from listings on the next read.

func (*ADR) SetStatus

func (a *ADR) SetStatus(s string) error

SetStatus updates the status field and persists the file.

Jump to

Keyboard shortcuts

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