markdown

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package markdown provides parsing and mutation for SPEC.md files. It operates on line-level patterns, not a full AST — sufficient for the structured SPEC.md format.

Index

Constants

View Source
const (
	StepStatusPending    = "pending"
	StepStatusInProgress = "in-progress"
	StepStatusComplete   = "complete"
	StepStatusBlocked    = "blocked"
)

Step status constants.

View Source
const (
	ReviewStatusPending          = "pending"
	ReviewStatusApproved         = "approved"
	ReviewStatusChangesRequested = "changes_requested"
)

Review status constants.

Variables

This section is empty.

Functions

func AppendDecision

func AppendDecision(path, question, user string) (int, error)

AppendDecision adds a new question to the decision log in a file. Returns the assigned decision number.

func Body

func Body(content string) string

Body returns the content after the frontmatter.

func FormatDecisionTable

func FormatDecisionTable(entries []DecisionEntry) string

FormatDecisionTable renders decision entries as a markdown table.

func IsSectionNonEmpty

func IsSectionNonEmpty(sections []Section, slug string) bool

IsSectionNonEmpty checks if a section has meaningful content (not just whitespace).

func IsValidSectionSlug

func IsValidSectionSlug(slug string) bool

IsValidSectionSlug checks if the slug is a known section.

func NextSpecID

func NextSpecID(existingFiles []string) string

NextSpecID scans existing spec filenames and returns the next sequential ID. Files should be like SPEC-001.md, SPEC-002.md, etc.

func NextTriageID

func NextTriageID(existingFiles []string) string

NextTriageID scans existing triage filenames and returns the next sequential ID.

func ReplaceSection

func ReplaceSection(path, slug, newContent string) error

ReplaceSection replaces the content of a section in a file.

func ReplaceSectionContent

func ReplaceSectionContent(content, slug, newContent string) (string, error)

ReplaceSectionContent replaces a section's content in the markdown string.

func ResolveDecision

func ResolveDecision(path string, number int, decision, rationale, user string) error

ResolveDecision updates an existing decision log entry.

func ScaffoldSpec

func ScaffoldSpec(id, title, author, cycle, source string) string

ScaffoldSpec generates a new SPEC.md from the template.

func ScaffoldTriage

func ScaffoldTriage(id, title, priority, source, sourceRef, reportedBy string) string

ScaffoldTriage generates a new TRIAGE.md from the template.

func UpdateFrontmatter

func UpdateFrontmatter(content string, meta *SpecMeta) (string, error)

UpdateFrontmatter returns content with updated frontmatter, preserving the body. It also updates the 'updated' field to today's date.

func ValidSectionSlugs

func ValidSectionSlugs() []string

ValidSectionSlugs returns all valid section slugs from the spec template.

func WriteMeta

func WriteMeta(path string, meta *SpecMeta) error

WriteMeta updates the frontmatter in a file, preserving the body content.

Types

type BuildStep

type BuildStep struct {
	// Repo is the repository this step targets.
	Repo string `yaml:"repo"`

	// Description is a brief summary of what this step accomplishes.
	Description string `yaml:"description"`

	// Branch is the git branch name for this step (auto-generated if empty).
	Branch string `yaml:"branch,omitempty"`

	// PR is the pull request number once created.
	PR int `yaml:"pr,omitempty"`

	// Status tracks the step's progress: pending, in-progress, complete, blocked.
	Status string `yaml:"status"`

	// BlockedReason explains why this step is blocked (when Status == "blocked").
	BlockedReason string `yaml:"blocked_reason,omitempty"`
}

BuildStep represents a single step in the build plan. Steps are a checklist of work items, not git-level PR stacking.

type DecisionEntry

type DecisionEntry struct {
	Number    int
	Question  string
	Options   string
	Decision  string
	Rationale string
	DecidedBy string
	Date      string
}

DecisionEntry represents a row in the decision log table.

func ParseDecisionLog

func ParseDecisionLog(content string) ([]DecisionEntry, error)

ParseDecisionLog extracts decision entries from markdown content.

func ParseDecisionLogFromFile

func ParseDecisionLogFromFile(path string) ([]DecisionEntry, error)

ParseDecisionLogFromFile reads a spec file and extracts the decision log.

type ReviewApproval

type ReviewApproval struct {
	Reviewer   string `yaml:"reviewer"`
	ApprovedAt string `yaml:"approved_at"`
}

ReviewApproval records a single reviewer's approval.

type ReviewState

type ReviewState struct {
	// RequestedAt is when the review was requested.
	RequestedAt string `yaml:"requested_at,omitempty"`

	// Reviewers is the list of users/roles who should review.
	Reviewers []string `yaml:"reviewers,omitempty"`

	// Approvals records who has approved and when.
	Approvals []ReviewApproval `yaml:"approvals,omitempty"`

	// Status is the overall review state: pending, approved, changes_requested.
	Status string `yaml:"status"`

	// Feedback contains reviewer feedback when changes are requested.
	Feedback string `yaml:"feedback,omitempty"`
}

ReviewState tracks plan review status for async approval workflow.

type Section

type Section struct {
	Slug      string // e.g., "problem_statement"
	Heading   string // e.g., "## 1. Problem Statement"
	Level     int    // heading level (2 = ##, 3 = ###)
	Owner     string // from <!-- owner: role --> marker, or "auto"
	Content   string // raw markdown content (excluding heading line)
	StartLine int    // line number in the source file (1-indexed)
	EndLine   int    // line number (exclusive)
}

Section represents a parsed markdown section with ownership.

func ExtractSections

func ExtractSections(content string) []Section

ExtractSections parses markdown content into sections.

func ExtractSectionsFromFile

func ExtractSectionsFromFile(path string) ([]Section, error)

ExtractSectionsFromFile reads a file and extracts sections.

func FindSection

func FindSection(sections []Section, slug string) *Section

FindSection returns the section with the given slug, or nil.

func SectionsOwnedBy

func SectionsOwnedBy(sections []Section, role string) []Section

SectionsOwnedBy returns sections owned by the given role.

type SpecMeta

type SpecMeta struct {
	ID          string   `yaml:"id"`
	Title       string   `yaml:"title"`
	Status      string   `yaml:"status"`
	Version     string   `yaml:"version"`
	Author      string   `yaml:"author"`
	Cycle       string   `yaml:"cycle"`
	EpicKey     string   `yaml:"epic_key,omitempty"`
	Repos       []string `yaml:"repos,omitempty"`
	RevertCount int      `yaml:"revert_count"`
	Source      string   `yaml:"source,omitempty"`
	Created     string   `yaml:"created"`
	Updated     string   `yaml:"updated"`

	// Steps is the structured build plan.
	// Replaces unstructured §7.3 prose with authoritative step tracking.
	Steps []BuildStep `yaml:"steps,omitempty"`

	// Review tracks plan review state for the engineering stage.
	Review *ReviewState `yaml:"review,omitempty"`

	// FastTrack marks this as a fast-track bug fix (skips ceremony stages).
	FastTrack bool `yaml:"fast_track,omitempty"`
}

SpecMeta represents the YAML frontmatter of a SPEC.md file.

func ParseMeta

func ParseMeta(content string) (*SpecMeta, error)

ParseMeta parses YAML frontmatter from markdown content.

func ReadMeta

func ReadMeta(path string) (*SpecMeta, error)

ReadMeta reads and parses the YAML frontmatter from a markdown file.

func (*SpecMeta) AllStepsComplete

func (m *SpecMeta) AllStepsComplete() bool

AllStepsComplete returns true if all steps have status "complete".

func (*SpecMeta) CurrentStep

func (m *SpecMeta) CurrentStep() int

CurrentStep returns the index (0-based) of the first non-complete step, or -1 if all steps are complete or there are no steps.

func (*SpecMeta) IsReviewApproved

func (m *SpecMeta) IsReviewApproved() bool

IsReviewApproved returns true if the review status is "approved".

func (*SpecMeta) IsReviewChangesRequested

func (m *SpecMeta) IsReviewChangesRequested() bool

IsReviewChangesRequested returns true if reviewer requested changes.

func (*SpecMeta) IsReviewPending

func (m *SpecMeta) IsReviewPending() bool

IsReviewPending returns true if review was requested but not yet completed.

func (*SpecMeta) StepsExist

func (m *SpecMeta) StepsExist() bool

StepsExist returns true if at least one step is defined.

type TriageMeta

type TriageMeta struct {
	ID         string `yaml:"id"`
	Title      string `yaml:"title"`
	Status     string `yaml:"status"`
	Priority   string `yaml:"priority"`
	Source     string `yaml:"source,omitempty"`
	SourceRef  string `yaml:"source_ref,omitempty"`
	ReportedBy string `yaml:"reported_by,omitempty"`
	Created    string `yaml:"created"`
}

TriageMeta represents the YAML frontmatter of a TRIAGE.md file.

func ParseTriageMeta

func ParseTriageMeta(content string) (*TriageMeta, error)

ParseTriageMeta parses triage YAML frontmatter.

func ReadTriageMeta

func ReadTriageMeta(path string) (*TriageMeta, error)

ReadTriageMeta reads and parses triage frontmatter.

Jump to

Keyboard shortcuts

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