Documentation
¶
Overview ¶
Package positioning holds a repository's canonical self-description — its title, tagline and elevator pitch, and optionally the name, descriptor and purpose that complete its lockup — 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, which checks each person's own record on their machine, 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" // EscapeJSON says a regexp surface's capture is the body of a JSON string // literal. EscapeJSON = "json" // EscapeYAML says a regexp surface's capture is the body of a YAML // double-quoted scalar. EscapeYAML = "yaml" )
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 meant the git commit-author pin (now each person's own record, kept on their machine) — 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".
var FieldNames = []string{"name", "title", "descriptor", "tagline", "purpose", "pitch", "listing"}
FieldNames is the block's vocabulary in the order the block lists it: the names a surface's requires and template may use.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
// Name is what the product is called, apart from its title ("abcd").
Name string `json:"name,omitempty"`
Title string `json:"title"`
// Descriptor is a noun phrase that completes "<name> is …": what kind of
// thing the product is and whom it is for.
Descriptor string `json:"descriptor,omitempty"`
Tagline string `json:"tagline"`
// Purpose says why the product exists, in one sentence.
Purpose string `json:"purpose,omitempty"`
// Pitch says what the product is technically, for the surfaces that list it
// beside other tools.
Pitch string `json:"pitch,omitempty"`
// Listing is the line a tool listing shows beside other tools, written
// whole: a surface carries it as written rather than assembling it from
// the descriptor and the pitch, and any surface may use it.
Listing string `json:"listing,omitempty"`
File string `json:"file"`
Line int `json:"line"`
}
Block is a repository's canonical self-description. Title and Tagline are required; every other field is optional. File and Line cite where it was parsed from so a finding can point back at the canon.
The lockup is the three lines a reader meets first: the headline (the name and its descriptor), the tagline, and the purpose. Name, Descriptor and Purpose are optional so a block written before they existed reads exactly as it did: with no Name the brand is the title's first word, and with neither a Name nor a Descriptor the headline is the title.
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; the other fields are 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".
func (Block) Brand ¶
Brand is the short handle a surface shows for the product: the declared Name, or failing that the title's first word, which is how a block without a Name has always been read.
func (Block) Field ¶
Field returns a block field by its lower-case name (the vocabulary a surface's requires/template use), reporting whether the name is one of FieldNames.
func (Block) Headline ¶
Headline is the lockup's first line: the name and its descriptor ("abcd — the open way to build your idea, one working prototype at a time"). A block with a Name and no Descriptor heads on its title after the name; a block with neither heads on its title alone, as it did before the lockup fields existed.
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 reported absent,
// never 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"`
// Escape (KindRegexp) names the quoted string the capture sits inside:
// EscapeJSON for the body of a JSON string literal, EscapeYAML for the
// body of a YAML double-quoted scalar. The capture is decoded before it is
// compared, and a proposal re-escapes the rendered text before splicing it
// back, so a block value holding a quote or a backslash neither breaks the
// file nor reads as drift that never clears. Empty means the capture is
// plain text. A KindJSONField surface is always decoded and re-escaped.
Escape string `json:"escape,omitempty"`
// Requires names the block fields this surface must carry (any of
// FieldNames). At least one is required.
Requires []string `json:"requires"`
// Template renders the proposed replacement, over the {field} placeholders FieldNames lists.
// 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"`
// Reason says why a drifted surface drifted when it is not a missing
// field: a quoted string that does not decode in its own format.
Reason string `json:"reason,omitempty"`
}
SurfaceResult is one surface's comparison against the block.