capture

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 21 Imported by: 0 modules, 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 capture is abcd's transport-agnostic issue-ledger engine: the write side of a per-repo issue ledger that replaces the free-form .work/issues.md. Every capability is a function taking a structured request and returning a structured result; nothing here writes to stdout or knows about a CLI, MCP, or prompt surface. The front doors under internal/surface/* marshal these results for their transport.

The ledger lives at <repoRoot>/.abcd/work/issues with three status directories (open/, resolved/, wontfix/) whose folder membership IS the status signal — there is no status: frontmatter field. Each issue is a YAML-frontmatter + Markdown-body file named iss-<N>-<slug>.md with an unpadded, per-repo id namespace.

This package ports scripts/abcd/_issue_lib.py + issue_workflow.py to Go.

Index

Constants

View Source
const LedgerRelPath = ".abcd/work/issues"

LedgerRelPath is the ledger root relative to the repo worktree.

Variables

View Source
var (
	// ErrUnknownIssueID means the id was absent from all three dirs.
	ErrUnknownIssueID = errors.New("unknown issue id")
	// ErrTransitionConflict means the id was found but not in open/ (already
	// resolved/wontfixed), or a concurrent move consumed it.
	ErrTransitionConflict = errors.New("transition conflict")
	// ErrDuplicateIssueID means a ForceID (or on-disk state) collided.
	ErrDuplicateIssueID = errors.New("duplicate issue id")
	// ErrAllocatorContention means the lock timed out or the O_EXCL retry
	// budget was exhausted.
	ErrAllocatorContention = errors.New("allocator contention")
	// ErrChecksumMismatch means a concurrent edit occurred during a transition.
	ErrChecksumMismatch = errors.New("checksum mismatch")
	// ErrInvariantViolation means frontmatter passed the schema but violates a
	// folder-status cross-field invariant.
	ErrInvariantViolation = errors.New("invariant violation")
	// ErrMalformedFrontmatter means frontmatter could not be parsed or failed
	// schema validation.
	ErrMalformedFrontmatter = errors.New("malformed frontmatter")
	// ErrMissingRequiredField means a schema-required field was absent.
	ErrMissingRequiredField = errors.New("missing required field")
	// ErrPathUnsafe means the ledger root or a status dir is a symlink.
	ErrPathUnsafe = errors.New("path unsafe")
)

Sentinel errors the surface maps to exit codes and messages. Core never prints them.

Functions

This section is empty.

Types

type CaptureRequest

type CaptureRequest struct {
	RepoRoot       string
	IssuesRoot     string
	Text           string // markdown body
	Severity       Severity
	Category       Category
	Source         Source
	Slug           string // caller-supplied; normalised to kebab-case
	FoundDuring    string // required, non-empty
	FoundAt        string // optional; "" omits the field
	RelatedIntents []string
	RelatedSpecs   []string
	BlockedBy      []string // iss-N dependency edges; each must match ^iss-[0-9]+$
	ForceID        string   // migrator-only; "" = auto-allocate
}

CaptureRequest is the input to Capture (append a new issue).

type CaptureResult

type CaptureResult struct {
	ID     string `json:"id"`
	Slug   string `json:"slug"`
	Path   string `json:"path"`
	Status State  `json:"status"` // always "open"
	// Redacted counts the spans the ledger redactor rewrote on write, and
	// Degraded is non-empty when it ran with a weakened pattern set. Both exist
	// so a surface can SAY the text was altered: redacting in silence would edit
	// a finding's content without telling whoever filed it (loud-staging).
	Redacted int    `json:"redacted,omitempty"`
	Degraded string `json:"redaction_degraded,omitempty"`
}

CaptureResult is the outcome of a successful Capture. The timestamp-numeric mint (adr-45) consults no refs, so the max+1 era's mint_warning degrade note no longer exists on this result.

func Capture

func Capture(req CaptureRequest) (CaptureResult, error)

Capture appends a new issue to open/ with an auto-assigned (or forced) iss-N. The write is transactional: a zero-byte placeholder is reserved, and on any failure it is swept. Returns the committed path under open/.

type Category

type Category string

Category is the loose issue taxonomy.

type Issue

type Issue struct {
	SchemaVersion  int         `json:"schema_version"`
	ID             string      `json:"id"`
	Slug           string      `json:"slug"`
	Severity       Severity    `json:"severity"`
	Category       Category    `json:"category"`
	Source         Source      `json:"source"`
	FoundDuring    string      `json:"found_during"`
	FoundAt        string      `json:"found_at,omitempty"`
	RelatedIntents []string    `json:"related_intents,omitempty"`
	RelatedSpecs   []string    `json:"related_specs,omitempty"`
	RelatedIssues  []string    `json:"related_issues,omitempty"`
	BlockedBy      []string    `json:"blocked_by,omitempty"` // iss-N dependency edges
	PromotedTo     string      `json:"promoted_to,omitempty"`
	Resolution     string      `json:"resolution,omitempty"`
	WontfixReason  string      `json:"wontfix_reason,omitempty"`
	ResolvedBy     *ResolvedBy `json:"resolved_by,omitempty"`
	Status         State       `json:"status"` // derived from folder
	Path           string      `json:"path"`   // repo-relative locator (iss-81)
	Body           string      `json:"body"`
	// BlockedByOpen is the derived subset of BlockedBy whose targets are still in
	// open/ (the priority projection populated by List/Status). Not a stored
	// field: an empty slice means the issue is unblocked.
	BlockedByOpen []string `json:"blocked_by_open,omitempty"`
}

Issue is a fully-read ledger entry (frontmatter + provenance + body).

type ListRequest

type ListRequest struct {
	RepoRoot   string
	IssuesRoot string
	State      State // "" is treated as "all"
}

ListRequest queries one state (or "all").

type ListResult

type ListResult struct {
	Issues  []Issue      `json:"issues"`
	Skipped []SkipRecord `json:"skipped"`
}

ListResult is Issues sorted ascending by numeric N plus a corrupt roster.

func List

func List(req ListRequest) (ListResult, error)

List scans one state (or all) and returns issues sorted ascending by numeric N plus a roster of unparseable files. Read-only: no preamble, no dir creation, tolerant of a virgin/absent ledger.

type PromoteRequest

type PromoteRequest struct {
	RepoRoot   string
	IssuesRoot string
	ID         string // iss-N
	LinkIntent string // itd-N; "" mints
}

PromoteRequest is the input to Promote: graduate an issue into an intent. LinkIntent, when non-empty, selects the stamp-only mode that links an EXISTING draft (itd-N) instead of minting one — the repair path after a stamp failure, and the "I already filed the intent by hand" path.

type PromoteResult

type PromoteResult struct {
	IssueID     string `json:"issue_id"`
	IssueStatus State  `json:"issue_status"`
	IssuePath   string `json:"issue_path"`
	IntentID    string `json:"intent_id"`
	IntentPath  string `json:"intent_path"`
	Linked      bool   `json:"linked"`
	MintWarning string `json:"mint_warning,omitempty"`
}

PromoteResult is the outcome of a successful Promote. Paths are repo-relative. Linked reports stamp-only mode (no draft minted this call). MintWarning is the loud-degrade note from the intent-id refs-union scan (empty when the scan completed, and always empty in link mode) — the surface MUST render it so a degrade to working-tree-only minting is never silent.

func Promote

func Promote(req PromoteRequest) (PromoteResult, error)

Promote graduates an issue into an intent without retyping (spc-24, step 2 of the record walk). Default mode mints an intent draft — slug reused from the issue, body carrying a by-id pointer to the issue rather than a copy (SSOT), promoted_from back-edge in the draft's frontmatter — then stamps the issue's promoted_to with the minted itd-N. Promotion is orthogonal to fix-status: the issue may sit in any status directory and never moves.

Ordering + residue contract: mint first, stamp second. No cross-store lock is attempted — the ledger lock alone guards the stamp, exactly as transition does — so a failure after the mint leaves an orphan draft; the returned error names the draft and the stamp-only remedy (`capture promote <iss-N> --intent <itd-N>`).

type ResolveRequest

type ResolveRequest struct {
	RepoRoot   string
	IssuesRoot string
	ID         string
	Resolution string
	// Impact is the product judgement resolved/ requires (issue_impact_valid):
	// one of the shared changelog enum's values (additive|breaking|fix|internal).
	// There is no default — an empty or invalid value is refused, never invented,
	// so a resolved record the tool mints always satisfies its own blocker.
	Impact string
	// ByIntent / BySpec / ByCommit are the optional resolved_by provenance
	// members (spc-25): the intent, spec, or commit that fixed the issue.
	// Ids must exist in their record store (any bucket); the sha is
	// shape-checked only. All optional — absent members are never defaulted.
	ByIntent string // itd-N
	BySpec   string // spc-N
	ByCommit string // 7–64 hex chars (64 covers a SHA-256 repo)
}

ResolveRequest moves an open issue to resolved/.

type ResolvedBy

type ResolvedBy struct {
	Intent string `json:"intent,omitempty"`
	Spec   string `json:"spec,omitempty"`
	Commit string `json:"commit,omitempty"`
}

ResolvedBy is an optional structured pointer to what resolved an issue.

type Severity

type Severity string

Severity is the capture-time severity guess.

const (
	SeverityNitpick  Severity = "nitpick"
	SeverityMinor    Severity = "minor"
	SeverityMajor    Severity = "major"
	SeverityCritical Severity = "critical"
)

Severity enum values.

type SkipRecord

type SkipRecord struct {
	Path  string `json:"path"`
	Error string `json:"error"`
}

SkipRecord surfaces a corrupt/invalid ledger file without failing the scan.

type Source

type Source string

Source is the surfacing channel the issue was discovered through.

type State

type State string

State is a ledger status directory (or "all" for a cross-status scan).

const (
	StateAll      State = "all"
	StateOpen     State = "open"
	StateResolved State = "resolved"
	StateWontfix  State = "wontfix"
)

State enum values.

type StatusRequest

type StatusRequest struct {
	RepoRoot   string
	IssuesRoot string
}

StatusRequest is the input to the read-only status render.

type StatusResult

type StatusResult struct {
	OpenCount     int          `json:"open_count"`
	ResolvedCount int          `json:"resolved_count"`
	WontfixCount  int          `json:"wontfix_count"`
	RecentOpen    []Issue      `json:"recent_open"` // up to 10, newest first
	Skipped       []SkipRecord `json:"skipped"`
}

StatusResult is the bare-invocation status snapshot (guaranteed no mutation).

func Status

func Status(req StatusRequest) (StatusResult, error)

Status is a pure read: counts per status dir plus up to 10 most-recent open issues (newest first). Guaranteed no mutation.

type TransitionResult

type TransitionResult struct {
	ID         string      `json:"id"`
	Path       string      `json:"path"`
	FromStatus State       `json:"from_status"`
	ToStatus   State       `json:"to_status"`
	ResolvedBy *ResolvedBy `json:"resolved_by,omitempty"`
	// Redacted / Degraded mirror CaptureResult: a resolution or wontfix note is
	// free text written to the same committed ledger, so it goes through the
	// same redactor and reports the same way.
	Redacted int    `json:"redacted,omitempty"`
	Degraded string `json:"redaction_degraded,omitempty"`
}

TransitionResult is the outcome of a Resolve or Wontfix. ResolvedBy echoes the provenance members a Resolve wrote (nil on a flagless resolve and on every Wontfix — a non-action points at nothing).

func Resolve

func Resolve(req ResolveRequest) (TransitionResult, error)

Resolve moves an open issue to resolved/, writing the resolution note and the product impact. resolved/ is gated by issue_impact_valid, so the impact is validated against the shared changelog enum up front (empty or invalid is refused, never defaulted) and stamped bare alongside the note — the tool's own resolve path can never mint a record its own blocker rejects.

The optional ByIntent/BySpec/ByCommit members land as the structured resolved_by object (spc-25) in the same atomic transition. Ids are validated for existence in their record store before anything is written; the sha is shape-checked only (its home may be the remote, and shallow or rebased states must not refuse a legitimate resolution). No members → no resolved_by key at all: provenance is optional, never defaulted.

func Wontfix

func Wontfix(req WontfixRequest) (TransitionResult, error)

Wontfix moves an open issue to wontfix/, writing the wontfix_reason note. wontfix/ carries no impact (issue_impact_valid gates resolved/ only), so no judgement is stamped.

type WontfixRequest

type WontfixRequest struct {
	RepoRoot   string
	IssuesRoot string
	ID         string
	Reason     string
}

WontfixRequest moves an open issue to wontfix/.

Jump to

Keyboard shortcuts

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