Documentation
¶
Overview ¶
Package store reads and writes the annotation records that live in .koment.
Index ¶
- Constants
- Variables
- func EncodeAnnotation(annotation *Annotation) ([]byte, error)
- func FindRoot(start string) (string, error)
- func NewID(at time.Time) (string, error)
- func Paragraphs(text string) []string
- func ValidID(id string) bool
- func WrapProse(text string) string
- type Anchor
- type AnchorStatus
- type Annotation
- type Author
- type AuthorKind
- type GitContext
- type IdentitySource
- type Metadata
- type Policy
- type Scope
- type Spec
- type Status
- type Store
- func (s *Store) All() (_ []Annotation, returnedError error)
- func (s *Store) AnnotatedFiles() ([]string, error)
- func (s *Store) FindByID(id string) (*Annotation, error)
- func (s *Store) ForFile(file string) ([]Annotation, error)
- func (s *Store) FromRoot(path string) (string, error)
- func (s *Store) FromWorkingDirectory(path string) (string, error)
- func (s *Store) Load(id string) (_ *Annotation, returnedError error)
- func (s *Store) ReadSource(file string) (_ []byte, returnedError error)
- func (s *Store) RecordPath(id string) (string, error)
- func (s *Store) Remove(id string) (returnedError error)
- func (s *Store) Root() string
- func (s *Store) Save(annotation *Annotation) (returnedError error)
- func (s *Store) WriteSource(file string, content []byte) (returnedError error)
- type Target
- type Timestamp
- type Type
Constants ¶
const ( SoftWrap = "\n" ParagraphBreak = "\n\n" )
const APIVersion = api.Version
APIVersion is matched exactly. A record carrying anything else is refused rather than guessed at.
const (
DirName = ".koment"
)
const KindAnnotation = "Annotation"
KindAnnotation is the resource kind of an annotation record.
const LegacyRecordVersion = 1
LegacyRecordVersion is the only value the pre-v1alpha `version` field ever carried.
const ProseWidth = 76
const SchemaURL = api.SchemaBase + "annotation.schema.json"
const TitleLimit = 72
TitleLimit keeps a title short enough to render beside code without being shortened, which is the only reason it exists (ADR 0115).
Variables ¶
var AnchorStatuses = []AnchorStatus{AnchorOK, AnchorAmbiguous, AnchorDrifted, AnchorOrphaned}
var Types = []Type{TypeWhy, TypeGotcha, TypeInvariant, TypeAntiPattern}
Functions ¶
func EncodeAnnotation ¶ added in v0.3.0
func EncodeAnnotation(annotation *Annotation) ([]byte, error)
func FindRoot ¶
FindRoot walks up from start for the directory that owns the annotations, preferring an existing .koment over the enclosing git work tree.
func NewID ¶
NewID returns a ULID: a 48-bit millisecond timestamp followed by 80 random bits, rendered as 26 Crockford base32 characters that sort by creation time.
func Paragraphs ¶
Paragraphs splits body text into paragraphs, re-joining the soft wraps that WrapProse introduced so the text can be laid out again at another width.
func WrapProse ¶
WrapProse hard-wraps body text at authoring time so that editing a sentence changes one line of a diff rather than all of it. It is deliberately not done when saving: the store round-trips whatever it is given, unchanged.
A single newline is a soft wrap that a reader may re-flow; a blank line is a paragraph break that it must keep.
Types ¶
type Anchor ¶ added in v0.3.0
type Anchor struct {
Scope Scope `yaml:"scope"`
Excerpt string `yaml:"excerpt,omitempty"`
Before string `yaml:"before,omitempty"`
After string `yaml:"after,omitempty"`
}
Anchor is where an annotation aims. It carries no line, because a line is something a reader observes rather than something the author decided; that lives in Status.
func (Anchor) MarshalYAML ¶ added in v0.3.0
type AnchorStatus ¶ added in v1.1.0
type AnchorStatus string
AnchorStatus is the verdict of resolving an anchor against a file. It is computed by reading the file, never by trusting a stored value.
const ( AnchorOK AnchorStatus = "ok" AnchorAmbiguous AnchorStatus = "ambiguous" AnchorDrifted AnchorStatus = "drifted" AnchorOrphaned AnchorStatus = "orphaned" )
func ParseAnchorStatus ¶ added in v1.1.0
func ParseAnchorStatus(text string) (AnchorStatus, error)
func (AnchorStatus) IsFailure ¶ added in v1.1.0
func (s AnchorStatus) IsFailure() bool
type Annotation ¶
type Annotation struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata Metadata `yaml:"metadata"`
Spec Spec `yaml:"spec"`
Status Status `yaml:"status,omitempty"`
}
Annotation is one rationale record on disk.
func DecodeAnnotation ¶ added in v0.3.0
func DecodeAnnotation(id string, content []byte) (*Annotation, error)
DecodeAnnotation validates one record read from a non-filesystem source. A v1 record is upgraded in memory; only Store.Load writes the upgrade back.
func (Annotation) Headline ¶ added in v0.5.0
func (a Annotation) Headline() string
Headline is what a reader sees beside the code. A record written before titles existed still has to show something, so the first sentence of the body stands in, shortened at a word boundary. It is never written back: a derived title in the record would become a second copy of the body that drifts.
func (Annotation) Validate ¶
func (a Annotation) Validate() error
type Author ¶
type Author struct {
Name string `yaml:"name"`
Email string `yaml:"email,omitempty"`
Kind AuthorKind `yaml:"kind"`
Source IdentitySource `yaml:"source"`
Account string `yaml:"account,omitempty"`
Verified string `yaml:"verified,omitempty"`
}
Author is a claim, not a proof, unless Verified says otherwise. ADR 0015.
type AuthorKind ¶
type AuthorKind string
AuthorKind separates a person from an agent, because an agent weighing an annotation needs to know whether another agent wrote it.
const ( AuthorHuman AuthorKind = "human" AuthorAgent AuthorKind = "agent" AuthorUnknown AuthorKind = "unknown" )
type GitContext ¶
type GitContext struct {
Commit string `yaml:"commit"`
Path string `yaml:"path"`
Line int `yaml:"line,omitempty"`
EndLine int `yaml:"endLine,omitempty"`
}
GitContext is what was true when an annotation was written. It is written once and never rewritten: reanchor changes where an annotation aims, not what it witnessed. ADR 0014.
func (GitContext) Validate ¶
func (g GitContext) Validate() error
type IdentitySource ¶
type IdentitySource string
IdentitySource records how much an identity is worth. Git config asserts an identity; it does not prove one.
const ( FromGitConfig IdentitySource = "git-config" FromSession IdentitySource = "session" FromExplicit IdentitySource = "explicit" FromMigration IdentitySource = "migration" FromOIDCProxy IdentitySource = "oidc-proxy" FromScopedAgent IdentitySource = "bearer-credential" )
type Metadata ¶ added in v1.1.0
Metadata identifies the record. Kubernetes names this field name; a ULID is not a DNS-1123 name, so koment diverges deliberately and calls it id. Do not align it without a migration.
type Policy ¶ added in v0.3.0
func (Policy) Validate ¶ added in v0.3.0
func (p Policy) Validate(annotation Annotation) error
type Spec ¶ added in v1.1.0
type Spec struct {
Target Target `yaml:"target"`
Type Type `yaml:"type"`
Title string `yaml:"title,omitempty"`
Body string `yaml:"body"`
Anchor Anchor `yaml:"anchor"`
Author Author `yaml:"author"`
Git *GitContext `yaml:"git,omitempty"`
Policy *Policy `yaml:"policy,omitempty"`
}
Spec is the authored intent: everything a person or agent decided.
type Status ¶ added in v1.1.0
type Status struct {
LastSeenLine int `yaml:"lastSeenLine,omitempty"`
Resolution AnchorStatus `yaml:"resolution,omitempty"`
ResolvedAt Timestamp `yaml:"resolvedAt,omitempty"`
ResolvedCommit string `yaml:"resolvedCommit,omitempty"`
}
Status is what the last write observed, stamped with the commit it observed it at. Nothing reads it back as a verdict: a reader resolves the anchor against the file in front of it, and ResolvedCommit is what lets that reader see how old the recorded observation is.
func (*Status) Observe ¶ added in v1.1.0
func (s *Status) Observe(resolution AnchorStatus, commit string, at Timestamp)
Observe records a resolution, leaving ResolvedAt alone when the verdict and the commit are already the ones recorded. ResolvedAt then answers "since when has this been true" instead of "when did a command last run".
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) All ¶ added in v0.3.0
func (s *Store) All() (_ []Annotation, returnedError error)
func (*Store) AnnotatedFiles ¶
func (*Store) FromRoot ¶
FromRoot reads a path the way an API caller means it: already relative to the repository root, wherever the koment process happens to be running.
func (*Store) FromWorkingDirectory ¶
FromWorkingDirectory reads a path the way a person typing it at a shell prompt means it: relative to where they are standing.
func (*Store) ReadSource ¶ added in v0.3.0
func (*Store) Save ¶
func (s *Store) Save(annotation *Annotation) (returnedError error)
type Target ¶ added in v1.1.0
type Target struct {
File string `yaml:"file"`
}
Target is what the annotation is about. It is a mapping rather than a bare path so that a function or a member can join the file without reshaping the record again.
type Timestamp ¶ added in v1.1.0
Timestamp is an instant in UTC. A v1 record carried a calendar date; both forms are read and only the instant is written back, so a reader comparing two records never has to know which generation wrote them.
func ParseTimestamp ¶ added in v1.1.0
func (Timestamp) MarshalYAML ¶ added in v1.1.0
func (*Timestamp) UnmarshalYAML ¶ added in v1.1.0
UnmarshalYAML reads the node rather than a decoded value because an unquoted 2026-08-05 resolves to !!timestamp, which will not decode into a string at all. Reading Value sidesteps tag resolution entirely.