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 Annotation
- type Author
- type AuthorKind
- type Date
- type GitContext
- type IdentitySource
- type Kind
- type Policy
- type Scope
- 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)
Constants ¶
const ( SoftWrap = "\n" ParagraphBreak = "\n\n" )
const (
DirName = ".koment"
)
const ProseWidth = 76
const RecordVersion = 1
const SchemaURL = "https://raw.githubusercontent.com/janpuc/koment/main/schema/annotation.schema.json"
Variables ¶
var Kinds = []Kind{KindWhy, KindGotcha, KindInvariant, KindAntiPattern}
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"`
LastSeenLine int `yaml:"last_seen_line,omitempty"`
}
func (Anchor) MarshalYAML ¶ added in v0.3.0
type Annotation ¶
type Annotation struct {
Version int `yaml:"version"`
ID string `yaml:"id"`
File string `yaml:"file"`
Kind Kind `yaml:"kind"`
Body string `yaml:"body"`
Created Date `yaml:"created"`
Anchor Anchor `yaml:"anchor"`
Git *GitContext `yaml:"git,omitempty"`
Author Author `yaml:"author"`
Policy *Policy `yaml:"policy,omitempty"`
}
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.
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 Date ¶
Date is a calendar date with no time or zone, written as YYYY-MM-DD.
func (Date) MarshalYAML ¶
type GitContext ¶
type GitContext struct {
Commit string `yaml:"commit"`
Path string `yaml:"path"`
Line int `yaml:"line,omitempty"`
EndLine int `yaml:"end_line,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 Policy ¶ added in v0.3.0
func (Policy) Validate ¶ added in v0.3.0
func (p Policy) Validate(annotation Annotation) error
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)