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
- Variables
- func WithLedgerLock(repoRoot string, fn func() error) error
- type CaptureRequest
- type CaptureResult
- type Category
- type DispositionRequest
- type DispositionResult
- type IngestReadingRequest
- type IngestReadingResult
- type Issue
- type ListRequest
- type ListResult
- type PromoteRequest
- type PromoteResult
- type ReadingItem
- type ReadingRecordRef
- type ResolveRequest
- type ResolvedBy
- type Severity
- type SkipRecord
- type Source
- type State
- type StatusRequest
- type StatusResult
- type TransitionResult
- type WontfixRequest
Constants ¶
const LedgerRelPath = ".abcd/work/issues"
LedgerRelPath is the ledger root relative to the repo worktree.
Variables ¶
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") // ErrGroundsRefused means the triage's grounds argument was absent, outside // the closed vocabulary, malformed, or below the substance floor. It is one // sentinel for every one of those because they are one thing to a caller — // the argument was not usable and nothing was written — and a surface that // distinguished them by exit code would teach a script that a misspelled // token is a different KIND of failure from a missing one // (iss-2608300930057882). ErrGroundsRefused = errors.New("grounds refused") // 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 ¶
func WithLedgerLock ¶ added in v0.7.0
WithLedgerLock runs fn while holding this ledger's exclusive allocator lock, for a caller OUTSIDE this package that mutates the ledger's files directly.
The cold-reading ingest verb is the one such caller: its orphan sweep unlinks reading records whose run never committed, and without this that delete races this package's own readers. Exporting the lock rather than the path is what keeps one file the lock: a caller that rebuilt the path would be holding a different lock the day this one moves.
It is NOT reentrant — an flock blocks a second acquisition in the same process — so a caller must not hold it across any exported verb of this package, every one of which takes it internally.
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
// LapsedAt is the RFC 3339 instant the discipline gave way. There is no
// default and none may be invented: the wall clock at write-up is exactly the
// value the lapse log exists to distinguish itself from (spc-60).
LapsedAt string
RelatedIntents []string
RelatedSpecs []string
BlockedBy []string // iss-N dependency edges; each must match ^iss-[0-9]+$
ForceID string // migrator-only; "" = auto-allocate
// ProductionMode is how the issue's text was produced (itd-178): one of the
// closed provenance vocabulary, or empty for the vocabulary's default. There
// is no free-text form. The record's `origin` has no request member at all —
// it is derived from which command ran, and a capture is researcher-authored
// by construction.
ProductionMode string
}
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 DispositionRequest ¶ added in v0.7.0
type DispositionRequest struct {
RepoRoot string
IssuesRoot string
// Item is the reading item this answers (rdi-N).
Item string
// State is one of issueschema.DispositionStates, subject to the per-position
// availability rule.
State string
// Grounds is disposition_grounds: free text, required on every state except
// held.
Grounds string
// ExitCondition is required on held and refused elsewhere.
ExitCondition string
// Supersedes names the standing disposition this one replaces (dsp-N) — the
// only exit from a hold.
Supersedes string
// Recurs cites prior item ids: the recorded form of the researcher's warm
// recognition of a persistence. Never a mechanical join, and never a state.
Recurs []string
// HoldFrameLocation / HoldMoscow are the RESERVED two-axis hold field. Both
// are refused while populated; the grammars are stated and dormant.
HoldFrameLocation string
HoldMoscow string
}
DispositionRequest writes one disposition, keyed to one reading item.
type DispositionResult ¶ added in v0.7.0
type DispositionResult struct {
ID string `json:"id"`
Item string `json:"item"`
State string `json:"state"`
Position string `json:"position"`
Path string `json:"path"`
Redacted int `json:"redacted,omitempty"`
Degraded string `json:"redaction_degraded,omitempty"`
}
DispositionResult is the outcome of a successful Disposition.
func Disposition ¶ added in v0.7.0
func Disposition(req DispositionRequest) (DispositionResult, error)
Disposition writes the researcher's answer to one reading item, into a directory keyed by the ITEM and a file keyed by the disposition's own id.
The two keys settle requirements that pull against each other. Status is the presence of the keyed directory — one probe, never a folder-membership question. And a disposition still has an id of its own, so the only exit from a held state (a superseding disposition that CITES the one it replaces) has something to cite. The superseded record stays in place: a hold that vanished when it was answered would take its own exit condition with it (adr-3 — the location is the state, and git is the history).
type IngestReadingRequest ¶ added in v0.7.0
type IngestReadingRequest struct {
RepoRoot string
IssuesRoot string
// Run is the run identifier (rdg-N) minted by the assembler.
Run string
// Manifest is the content-hash reference to the run's committed manifest,
// which is what makes the assembly re-runnable and diffable.
Manifest string
Position string
Regime string
Items []ReadingItem
}
IngestReadingRequest writes one run's items into the ledger. Position and Regime come from the reading's DEFINITION, never from operator input, and are therefore run-level rather than per-item.
type IngestReadingResult ¶ added in v0.7.0
type IngestReadingResult struct {
Run string `json:"run"`
Records []ReadingRecordRef `json:"records"`
// Redacted counts the spans the ledger redactor rewrote across every item
// written, and Degraded is non-empty when it ran with a weakened pattern set.
// Both exist so a surface can SAY the text was altered.
Redacted int `json:"redacted,omitempty"`
Degraded string `json:"redaction_degraded,omitempty"`
}
IngestReadingResult is the outcome of a successful ingest.
func IngestReading ¶ added in v0.7.0
func IngestReading(req IngestReadingRequest) (IngestReadingResult, error)
IngestReading writes one reading record per item under readings/<run-id>/rdi-<N>.md. Every id is minted (adr-45) and never derived from the item's content, so two runs returning the same tension carry different ids for free — a re-raise stays distinguishable from its first appearance, and the recurrence signal survives.
It is the ledger's record WRITER, not a payload validator: the output contract that "validated" refers to belongs to the cold-reading output contract, which calls this and adds no second validation path. What is enforced here is the RECORD schema — the envelope, the position's own body, and the reserved fields — which is this package's to refuse.
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"`
// LapsedAt is the RFC 3339 instant at which a recorded discipline gave way —
// the lapse itself, never the write-up (spc-60). Required exactly when
// Category is lapse; optional, and rarely meaningful, for every other.
LapsedAt string `json:"lapsed_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"`
// Grounds is the record's recorded conjectures, in the order they were
// written: one `<token>: <text>` value in the shared core/grounds vocabulary
// per grounds-bearing act. Appended by promote, resolve and wontfix; never by
// the create path, because an observation being filed is not yet a conjecture
// being pursued.
//
// It is a LIST because recording is append-only. A record promoted and then
// resolved carries both conjectures, and the earlier one is precisely what a
// later reader checks the outcome against (iss-2608301657354776). The values
// live in the body's `## Grounds` section, not in frontmatter: a frontmatter
// scalar is set, and setting is what destroyed the first of them.
Grounds []string `json:"grounds,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 ¶
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 is the record to graduate: an iss-N, or the rdi-N of a reading item
// that has been dispositioned.
ID string
LinkIntent string // itd-N; "" mints
// Grounds is the REQUIRED conjecture behind the promotion, in the shared
// `<token>: <text>` grammar (core/grounds). A capture routed to an intent
// draft is a conjecture being pursued, and there is nothing to stage here:
// promote mints the value in the same call, so it has no corpus to fix.
Grounds string
// ProductionMode is how the MINTED DRAFT's seed text was produced (itd-178),
// or empty for the vocabulary's default. It has no effect in stamp-only mode,
// where nothing is minted. The draft's `origin` is not a member here: promote
// is the one shipped path that derives a record from another record, so it
// derives extracted-from-record from what it did rather than from what it was
// told.
ProductionMode string
}
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 is the source record's status. For an issue that is its status
// directory; for a reading item it is the STANDING DISPOSITION's state,
// because that family's status signal is the presence of the keyed
// disposition and never folder membership.
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"`
// Redacted / Degraded mirror TransitionResult: the grounds text is free prose
// written to the same committed ledger, so it goes through the same redactor
// and reports the same way. Rewriting somebody's reasoning in silence is worse
// than not recording it.
Redacted int `json:"redacted,omitempty"`
Degraded string `json:"redaction_degraded,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>`).
Every refusal that can be established from the bytes in hand is therefore raised BEFORE the mint: the grounds text, and whether the record can take the append at all. What is left to the stamp is what only a write under the lock can discover, which is the residue the remedy above is for — never a deterministic refusal that would leak one draft per attempt.
type ReadingItem ¶ added in v0.7.0
type ReadingItem struct {
// Pattern is the pattern named — required at every position and in every
// supply regime.
Pattern string
// Body carries exactly the fields the run's position declares
// (issueschema.ReadingBodyFields). A field from another position's body is
// refused: one record type, four bodies, and an item belongs to one of them.
Body map[string]string
// OccasionedBy is RESERVED and dormant — the join key of the surprise entry,
// populated in Iteration 2. A populated value is refused until the shape is
// ruled, so the reservation is a behaviour rather than a comment.
OccasionedBy string
}
ReadingItem is one thing the instrument returned: the pattern it named (an envelope field, because a universal core condition must not live in a variant part) plus the position-typed body.
type ReadingRecordRef ¶ added in v0.7.0
ReadingRecordRef is one written reading record: its minted id and its repo-relative path.
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
// ShippedIn optionally names the release that already carried this work, as a
// tag (v0.6.2). It is a MIGRATION mechanism for the ledger-hygiene case:
// closing a record for a fix released long ago. A repository abcd manages from
// its first commit should never need it, because RS001 makes resolution ride
// the fixing commit and the cut is then right by construction. The derivation reads it and leaves such a record out
// of the current cut, so the release record cannot announce old work as new
// (iss-2608241612087533). Absent by default — the ordinary resolution is for
// work shipping in the release being prepared, and it must never be guessed.
ShippedIn 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)
// Grounds is the REQUIRED conjecture behind the resolution, in the shared
// `<token>: <text>` grammar (core/grounds). There is no default and none may
// be invented: a route recorded without its reasoning is the evaporation
// itd-179 exists to close, and resolve mints the value in the same call, so
// it has no corpus to fix and refuses from the start.
Grounds string
// ProductionMode RESTAMPS the record's production_mode (itd-178). A
// resolution note is new text with its own mode, so the key is not frozen at
// mint — but an empty value leaves the existing stamp alone rather than
// overwriting it with a default, because a transition that declares nothing
// has made no claim about how the note was produced. `origin` is never
// rewritten: where a record came from does not change when it is resolved.
ProductionMode string
}
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 SkipRecord ¶
SkipRecord surfaces a corrupt/invalid ledger file without failing the scan.
type State ¶
type State string
State is a ledger status directory (or "all" for a cross-status scan).
type StatusRequest ¶
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 and the `declined:` grounds derived from it. wontfix/ carries no impact (issue_impact_valid gates resolved/ only), so no judgement is stamped.
It needs no new required flag: transition already refuses an empty reason, so a wontfix could never be recorded without grounds — what it lacked was the TYPE. Grounds overrides the text when the conjecture is worth stating separately from the user-facing reason.
type WontfixRequest ¶
type WontfixRequest struct {
RepoRoot string
IssuesRoot string
ID string
Reason string
// Grounds optionally overrides the text stamped as `declined: <text>`. A
// wontfix can never be recorded without grounds — transition already refuses
// an empty Reason — so what it lacked was the TYPE, not the text, and the
// reason supplies the default. The override exists because the user-facing
// reason and the conjecture are not always the same sentence. The token stays
// declined: a non-action is what that value names.
Grounds string
// ProductionMode restamps production_mode on the same terms as
// ResolveRequest's: declared restamps, absent leaves the stamp alone.
ProductionMode string
}
WontfixRequest moves an open issue to wontfix/.