specs

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package specs reads a project's specification as the project-spec agent (/spec) writes it, .agents/specs/NNN-<name>.md with README.md as the index, and checks it without a model (spec_057_spec_driven SDD-01..05): the title, the status, what each spec depends on, the requirements' IDs, "Done when" and the open questions.

Index

Constants

View Source
const (
	Traced       = "traced"
	Untraced     = "untraced"
	Implemented  = "implemented"
	Partial      = "partial"
	Missing      = "missing"
	Contradicted = "contradicted"
)

The states a requirement's trace can be in: the check without a model says traced (its ID is in the work) or untraced; the model's judgement says implemented, partial, missing or contradicted.

View Source
const Dir = ".agents/specs"

Dir is where a workspace's specs live.

View Source
const Index = "README.md"

Index is the specs' index file.

View Source
const LedgerDir = ".agents/.ledger"

LedgerDir holds what the specification's work is traced to (spec_057_spec_driven SDD-10): specs/<name>.json, a spec's approval and each requirement's trace; baselines/<file>, the text approved; diffs/, a diff for each change to an approved spec.

View Source
const MaxEvidence = 8

MaxEvidence is the most evidence kept for one requirement.

Variables

View Source
var Statuses = []string{"draft", "approved", "in progress", "implemented", "changed", "retired"}

Statuses are a spec's states, in the order a spec goes through them.

Functions

func BaselinePath

func BaselinePath(file string) string

BaselinePath is where the approved text of file is kept.

func DiffPath

func DiffPath(file string, at time.Time) string

DiffPath is where a change to file approved at at is kept.

func Done

func Done(s Spec, l Ledger) bool

Done reports that s is done: approved, unchanged since, and every requirement found in the work (traced, or judged implemented).

func DoneWhen

func DoneWhen(text string) string

DoneWhen is s's "Done when" text (its section's lines), for a plan.

func Drift

func Drift(change, was, now string, judged bool) string

Drift is why an approved requirement no longer holds, if it doesn't: "changed" (since approval), "lost" (no longer found in the work: it was before), or "judged" (the model said missing or contradicted).

func EvidenceKind

func EvidenceKind(p string) string

EvidenceKind says what a file is to a requirement: a test, a document, or code (anything else: scripts, configuration, notebooks).

func Fingerprint

func Fingerprint(text string) string

Fingerprint is a requirement's text, normalized (case, spacing and emphasis don't count), hashed: what tells that it changed.

func Hash

func Hash(text string) string

Hash is a whole text's hash.

func LedgerPath

func LedgerPath(file string) string

Paths in the ledger, for a spec file (002-orders.md).

func SetStatus

func SetStatus(text, status string) string

SetStatus is text with its Status: line saying status (added after the title when there's none).

func Sort

func Sort(all []Spec)

Sort puts specs in their order: the index first, then by number, then the unnumbered by name.

func StateOf

func StateOf(ev []Evidence) string

StateOf is what the evidence says without a model: traced when code, a test or a commit names the requirement, untraced otherwise (documents that only mention it don't implement it).

func Touched

func Touched(l Ledger, changed map[string]bool) []string

Touched are the approved requirements whose evidence is in one of the changed files (relative, slash-separated): what a turn's changes may have broken (SDD-31).

func UnifiedDiff

func UnifiedDiff(name, a, b string) string

UnifiedDiff is a diff of a and b, every changed line with three lines around it, under name's headers.

func Unlisted

func Unlisted(indexText string, all []Spec) []string

Unlisted are the numbered specs the index (its text) doesn't name.

Types

type Approval

type Approval struct {
	At   time.Time `json:"at"`
	By   string    `json:"by,omitempty"`
	Hash string    `json:"hash"`
}

Approval is when a spec was approved, by whom, and its text's hash.

type Change

type Change struct {
	ID string
	// Kind is "added", "changed" or "removed".
	Kind string
}

Change is a requirement that differs from what was approved.

type Evidence

type Evidence struct {
	Path string `json:"path"`
	Line int    `json:"line,omitempty"`
	Kind string `json:"kind"`
	Text string `json:"text,omitempty"`
}

Evidence is where a requirement was found: a file's line (code, test or doc) or a commit (Path is its hash).

func Uses

func Uses(p, text, name string, decl int) []Evidence

Uses are the lines of p (its text) that use name as a whole word, but its declaration (decl, 0 for none): the text search an impact scan falls back on without a language server.

type Finder

type Finder struct {

	// Found is the evidence by ID, in the order it was found.
	Found map[string][]Evidence
	// contains filtered or unexported fields
}

Finder finds requirements' IDs in the work (SDD-12's pass without a model): a file's lines and commit messages that name one.

func NewFinder

func NewFinder(ids []string) *Finder

NewFinder looks for ids (nil when there are none).

func (*Finder) Commit

func (f *Finder) Commit(hash, subject, message string)

Commit looks for the IDs in a commit's message (its hash and subject shown).

func (*Finder) File

func (f *Finder) File(p, text string)

File looks for the IDs in a file's text (p, relative to the workspace).

type Finding

type Finding struct {
	// Line is where (1-based; 0 for the whole spec).
	Line int
	// ID is the requirement it's about, if one.
	ID string
	// Severity is "error" (the spec can't be traced or ordered as written),
	// "warning" (it can, but it's weaker for it) or "info".
	Severity string
	// Code names the check (no-title, duplicate-id, vague, …).
	Code    string
	Message string
}

Finding is something a check found in a spec.

func Lint

func Lint(s Spec, all []Spec) []Finding

Lint checks spec s against the rest of the set (all, s among them), without a model.

type Item

type Item struct {
	ID   string
	Text string
	Line int
}

Item is one requirement with its ID (AUTH-01).

func Pending

func Pending(s Spec, l Ledger) []Item

Pending are s's requirements not yet implemented, by l's last verification, in order.

type Ledger

type Ledger struct {
	Spec     string            `json:"spec"`
	Approved *Approval         `json:"approved,omitempty"`
	Items    map[string]*Trace `json:"items"`
}

Ledger is one spec's entry: its approval and its requirements' traces.

func ReadLedger

func ReadLedger(file string, data []byte) (Ledger, error)

ReadLedger reads a ledger entry; empty data is an empty one for file.

func (*Ledger) Approve

func (l *Ledger) Approve(s Spec, text string, at time.Time, by string)

Approve records s (text) as approved at at by by: each requirement's text and fingerprint. A requirement whose fingerprint is unchanged keeps its verification; a changed one starts over; one gone is dropped.

func (Ledger) Bytes

func (l Ledger) Bytes() []byte

Bytes is the entry as it's written: indented, so its diffs read.

func (Ledger) Changes

func (l Ledger) Changes(s Spec) []Change

Changes are s's requirements against its approval: added, changed and removed, in the spec's order (the removed last). Nothing when it was never approved.

type Order

type Order struct {
	Next    int
	Blocked map[int][]int
}

Order is where each numbered spec stands (SDD-32): Next is the first in order that isn't done and whose dependencies are; Blocked are, by number, the dependencies not done that each other spec waits for.

func Progress

func Progress(all []Spec, done map[int]bool) Order

Progress is the specification's order, from which specs are done.

type Spec

type Spec struct {
	// File is its name in Dir (001-overview.md).
	File string
	// Number is its place in the order (0 for the index or an unnumbered file).
	Number int
	// Title is its heading's text, without the number ("Overview").
	Title string
	// TitleLine is the heading's line (1-based; 0 when there's none).
	TitleLine int
	// Status is its Status: line, lowercase ("" when there's none).
	Status     string
	StatusLine int
	// DependsOn are the numbers its Depends on: line names.
	DependsOn     []int
	DependsOnLine int
	// Kind is 001-overview's Kind: line (software, research, …).
	Kind []string
	// Items are its numbered requirements (or objectives, content).
	Items []Item
	// DoneWhen reports whether it says how to tell it's finished.
	DoneWhen bool
	// OpenQuestions are the lines under its Open questions heading.
	OpenQuestions []string
}

Spec is one spec file, as read.

func Parse

func Parse(file string, text string) Spec

Parse reads the spec file named file.

type Symbol

type Symbol struct {
	Name string
	Path string
	// Line and Column are the name's (1-based; the column in characters).
	Line   int
	Column int
}

Symbol is a declaration a requirement's evidence sits in: the function, method, type or class whose uses an impact scan follows (SDD-20).

func Declaration

func Declaration(p, text string, line int) (Symbol, bool)

Declaration is the symbol line (1-based) of p (its text) belongs to: the declaration the comment it's in documents (a few lines below), else the nearest one above it. ok is false for a language it can't read, or none.

type Trace

type Trace struct {
	Text                string     `json:"text"`
	Fingerprint         string     `json:"fingerprint"`
	VerifiedAt          *time.Time `json:"verified_at,omitempty"`
	VerifiedFingerprint string     `json:"verified_fingerprint,omitempty"`
	State               string     `json:"state,omitempty"`
	Judged              bool       `json:"judged,omitempty"`
	Reason              string     `json:"reason,omitempty"`
	Evidence            []Evidence `json:"evidence,omitempty"`
}

Trace is one requirement: its text and fingerprint as approved, and its last verification (the fingerprint it was verified at, its state, why, and the evidence).

Jump to

Keyboard shortcuts

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