Documentation
¶
Overview ¶
Package positioning holds a repository's canonical self-description — its title, tagline, and elevator pitch — and the deterministic check that every rendered surface still says it.
The canonical home is a markdown block in the repo's own record (markdown stays the single source of truth); the committed configuration records only where that block lives and which surfaces render from it. The check is advisory by default and never rewrites a surface: a re-render is always a proposed diff a human adopts (spc-19, itd-102).
This is repo POSITIONING, not commit-author identity: the git author gate pinned in .abcd/config/identity.json lives in internal/core/identity and shares nothing with this package but the English word.
Index ¶
Constants ¶
const ( // KindRegexp locates the text with the first Patterns entry that matches, // capturing group 1. The capture may span lines (a wrapped paragraph). KindRegexp = "regexp" // KindJSONField reads a top-level string field of a JSON manifest, so the // registry is not tied to one manifest format. KindJSONField = "json_field" )
Surface kinds — how a surface's self-description is located in its file.
const ( SeverityWarn = "warn" SeverityBlocker = "blocker" )
Severity levels a repo may set for the whole positioning family.
const ConfigRelPath = ".abcd/positioning.json"
ConfigRelPath is the committed positioning configuration, relative to the repo root. It sits beside the repo's other per-concern lint configuration (.abcd/docs-lint.json, .abcd/record-lint.json, .abcd/rules.json) rather than inside .abcd/config/, where identity.json already means the git commit-author pin — two different things must not share a filename.
Variables ¶
var ( // ErrBlockFileMissing: the configured file does not exist (or is not a // regular file). ErrBlockFileMissing = errors.New("identity block file not found") // ErrHeadingMissing: the file exists but carries no such heading. ErrHeadingMissing = errors.New("identity block heading not found") // ErrBulletMissing: the heading exists but a required bullet (title or // tagline) is absent or empty. ErrBulletMissing = errors.New("identity block is missing a required bullet") // ErrBadLocation: the configured location is not a safe repo-relative path. ErrBadLocation = errors.New("identity block location is not a repo-relative path") )
Parse failures, as sentinels so a caller can distinguish "the repo has not adopted a block" from "the block is malformed" without string matching.
var ( // ErrAlreadyAdopted: the repo has a registry already, and Init was given // answers that would change what it points at. Repointing the canon is a // deliberate edit, never a side effect of re-running onboarding. ErrAlreadyAdopted = errors.New("this repo already records an identity block") // ErrAnswersRequired: no block exists to adopt, and the required answers // (title and tagline) were not supplied. ErrAnswersRequired = errors.New("an identity block needs at least a title and a tagline") )
Init refusals, so a surface can render each one as its own message.
var DefaultBlockLocation = BlockLocation{
File: ".abcd/development/IDENTITY.md",
Heading: "Identity (canonical)",
}
DefaultBlockLocation is where a repo's identity block lands when onboarding does not name a location: one file in the durable record, under the heading the parser and every generated pointer use.
var ErrConfigInvalid = errors.New("positioning config is invalid")
ErrConfigInvalid wraps every configuration-validation failure, so a caller can distinguish a malformed registry from a real drift finding.
var ErrSurfaceUnreadable = errors.New("surface file could not be read")
ErrSurfaceUnreadable: a registered surface file is present but could not be read safely — it escapes the repository root through a symlinked component, its leaf is a symlink or a device, or it is oversize. It is never an absence: a surface that cannot be read must not read as "no drift".
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
Title string `json:"title"`
Tagline string `json:"tagline"`
Pitch string `json:"pitch,omitempty"`
File string `json:"file"`
Line int `json:"line"`
}
Block is a repository's canonical self-description. Title and Tagline are required; Pitch is optional at onboarding. File and Line cite where it was parsed from so a finding can point back at the canon.
func ParseBlock ¶
func ParseBlock(root string, loc BlockLocation) (Block, error)
ParseBlock reads the identity block at loc under root. The heading match is case-insensitive and level-agnostic; the block runs to the next heading of the same or shallower level (or end of file). A bullet's value may wrap onto indented continuation lines, which are joined with a single space.
Title and Tagline are required; Pitch is optional. Every failure mode is a sentinel-wrapped error, never a zero Block with a nil error — a caller must not read "no block" as "the block says nothing".
type BlockLocation ¶
BlockLocation is where the identity block lives: a repo-relative markdown file and the heading the block sits under. It is committed configuration, not derived, so both fields are validated before use.
type Config ¶
type Config struct {
SchemaVersion int `json:"schema_version"`
Block BlockLocation `json:"block"`
// Severity is the whole family's weight: "warn" (the default — highlight,
// never gate) or "blocker" (a repo opting into a hard gate).
Severity string `json:"severity,omitempty"`
// Surfaces is the registry. Empty means the three defaults; a non-empty
// list REPLACES them, so nothing is ever registered silently.
Surfaces []Surface `json:"surfaces,omitempty"`
}
Config is the committed positioning registry: where the identity block lives, how loudly the family reports, and which surfaces render from the block.
func DefaultConfig ¶
func DefaultConfig(loc BlockLocation) Config
DefaultConfig is the registry a repo adopts at onboarding when it has no committed one: the three default surfaces, warn-tier, pointed at loc.
func LoadConfig ¶
LoadConfig reads and validates .abcd/positioning.json under root. It returns (cfg, true, nil) when the registry is present and well formed, (Config{}, false, nil) when the repo has not adopted the check, and an ErrConfigInvalid error when the file is present but unusable — a malformed registry must never read as "no drift".
type InitRequest ¶
type InitRequest struct {
Title string
Tagline string
Pitch string
Location BlockLocation // zero value means DefaultBlockLocation
}
InitRequest is the onboarding interview's outcome. The host asks the questions (the prepare surface carries the wording); this is what it hands over. Pitch may be empty — it is skippable at onboarding.
type InitResult ¶
type InitResult struct {
Location BlockLocation `json:"location"`
Block Block `json:"block"`
// AdoptedExisting: a block was already there and was registered as the
// canon rather than re-interviewed and rewritten.
AdoptedExisting bool `json:"adoptedExisting"`
// NoOp: the repo was already fully adopted; nothing was written.
NoOp bool `json:"noOp"`
// Wrote lists the repo-relative paths written, in order.
Wrote []string `json:"wrote,omitempty"`
}
InitResult reports what onboarding did, so a surface can say it plainly.
func Init ¶
func Init(root string, req InitRequest) (InitResult, error)
Init adopts the positioning check for a repo: it registers an identity block and writes the pointer that records where it lives.
It never re-interviews a repo that already has a block — an existing block at the target location is adopted as the canon and left byte-for-byte alone, because a second set of answers is exactly how a project ends up with two canons. A repo whose registry is already committed is a no-op when no answers are given, and a refusal when they are: repointing the canon is a deliberate edit to the registry, not a side effect of re-running onboarding.
type Proposal ¶
type Proposal struct {
Report Report `json:"report"`
Diffs []SurfaceDiff `json:"diffs"`
}
Proposal is a re-render of every drifted surface from the identity block. It is a PROPOSAL: nothing here touches the working tree, and there is no flag that makes it. A deliberate identity change is an edit to the block, after which the same proposal flow chases the surfaces.
func Propose ¶
Propose runs the positioning check and, for every surface that drifted, renders what the surface would say if it were re-rendered from the block. It performs no writes whatsoever.
A surface the locator could not find yields no diff — there is no region to replace, and inventing one would propose a patch against a line that was never located. It still reports as drifted in the embedded Report.
type Report ¶
type Report struct {
Block Block `json:"block"`
Severity string `json:"severity"`
Surfaces []SurfaceResult `json:"surfaces"`
}
Report is a whole positioning check: the block it was held to, the family severity, and one result per registered surface.
type Status ¶
type Status string
Status is one surface's outcome.
const ( // StatusOK: the surface carries every block field it declares. StatusOK Status = "ok" // StatusDrifted: the surface was located but no longer says what the block // says. StatusDrifted Status = "drifted" // StatusAbsent: none of the surface's candidate files exists, so the // surface is not present in this repo. Not a finding. StatusAbsent Status = "absent" // StatusUnlocatable: the file exists but the locator found nothing. A // finding: a locator that stopped matching hides drift rather than proving // its absence. StatusUnlocatable Status = "unlocatable" )
type Surface ¶
type Surface struct {
ID string `json:"id"`
// Files are candidate locations, in order; the first that exists is the one
// checked. A surface whose candidates are all absent is skipped, never
// reported as drifted.
Files []string `json:"files"`
Kind string `json:"kind"`
// Patterns (KindRegexp) are tried in order; the first that matches wins.
// Each must compile and expose exactly one capture group.
Patterns []string `json:"patterns,omitempty"`
// Field (KindJSONField) is the top-level JSON key holding the description.
Field string `json:"field,omitempty"`
// Requires names the block fields this surface must carry (title, tagline,
// pitch). At least one is required.
Requires []string `json:"requires"`
// Template renders the proposed replacement, over {title}/{tagline}/{pitch}.
// Empty means the required fields joined by a single space.
Template string `json:"template,omitempty"`
}
Surface is one rendered surface held to the block.
func DefaultSurfaces ¶
func DefaultSurfaces() []Surface
DefaultSurfaces is the canonical three: the README strapline, the plugin/package manifest description, and the conventions file's opening paragraph. They are data, not branches — a repo overrides them wholesale in its own configuration, and the manifest entry lists candidate files so the default is not tied to one manifest format.
type SurfaceDiff ¶
type SurfaceDiff struct {
SurfaceID string `json:"surfaceId"`
File string `json:"file"`
// Proposed is the surface file as it would read once the proposal is
// adopted. It is returned, never written.
Proposed string `json:"-"`
// Unified is the human-readable patch: the exact drifted line removed, the
// canonical line added, with surrounding context.
Unified string `json:"unified"`
}
SurfaceDiff is one surface's proposed correction: the whole proposed file content and the unified diff that turns the current file into it.
type SurfaceResult ¶
type SurfaceResult struct {
ID string `json:"id"`
Status Status `json:"status"`
// File is the candidate that was checked (empty when all were absent).
File string `json:"file,omitempty"`
// Line is the 1-based line the located text starts on.
Line int `json:"line,omitempty"`
// Found is the located text, verbatim — the exact drifted content.
Found string `json:"found,omitempty"`
// Missing names the block fields the surface no longer carries.
Missing []string `json:"missing,omitempty"`
// Canonical is what the block says this surface should carry.
Canonical string `json:"canonical,omitempty"`
}
SurfaceResult is one surface's comparison against the block.