store

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store reads and writes the annotation records that live in .koment.

Index

Constants

View Source
const (
	SoftWrap       = "\n"
	ParagraphBreak = "\n\n"
)
View Source
const APIVersion = api.Version

APIVersion is matched exactly. A record carrying anything else is refused rather than guessed at.

View Source
const (
	DirName = ".koment"
)
View Source
const KindAnnotation = "Annotation"

KindAnnotation is the resource kind of an annotation record.

View Source
const LegacyRecordVersion = 1

LegacyRecordVersion is the only value the pre-v1alpha `version` field ever carried.

View Source
const ProseWidth = 76
View Source
const SchemaURL = api.SchemaBase + "annotation.schema.json"
View Source
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

Functions

func EncodeAnnotation added in v0.3.0

func EncodeAnnotation(annotation *Annotation) ([]byte, error)

func FindRoot

func FindRoot(start string) (string, error)

FindRoot walks up from start for the directory that owns the annotations, preferring an existing .koment over the enclosing git work tree.

func NewID

func NewID(at time.Time) (string, error)

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

func Paragraphs(text string) []string

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 ValidID added in v0.3.0

func ValidID(id string) bool

func WrapProse

func WrapProse(text string) string

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

func (a Anchor) MarshalYAML() (any, error)

func (Anchor) Validate added in v0.3.0

func (a Anchor) Validate(id string) error

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.

func (Author) IsProven

func (a Author) IsProven() bool

IsProven reports whether the identity was verified by some mechanism. An unverified identity must not be rendered as though it were checked.

func (Author) Validate

func (a Author) Validate() error

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

type Metadata struct {
	ID      string    `yaml:"id"`
	Created Timestamp `yaml:"created"`
}

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.

func (Metadata) Validate added in v1.1.0

func (m Metadata) Validate() error

type Policy added in v0.3.0

type Policy struct {
	Exception    string `yaml:"exception"`
	Acknowledged bool   `yaml:"acknowledged"`
}

func (Policy) Validate added in v0.3.0

func (p Policy) Validate(annotation Annotation) error

type Scope

type Scope string
const (
	ScopeFile    Scope = "file"
	ScopeExcerpt Scope = "excerpt"
)

func ParseScope

func ParseScope(text string) (Scope, 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.

func (Spec) Validate added in v1.1.0

func (s Spec) Validate(id string) error

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".

func (Status) Validate added in v1.1.0

func (s Status) Validate(id string, scope Scope) error

type Store

type Store struct {
	// contains filtered or unexported fields
}

func Open

func Open(root string) *Store

func (*Store) All added in v0.3.0

func (s *Store) All() (_ []Annotation, returnedError error)

func (*Store) AnnotatedFiles

func (s *Store) AnnotatedFiles() ([]string, error)

func (*Store) FindByID

func (s *Store) FindByID(id string) (*Annotation, error)

func (*Store) ForFile added in v0.3.0

func (s *Store) ForFile(file string) ([]Annotation, error)

func (*Store) FromRoot

func (s *Store) FromRoot(path string) (string, error)

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

func (s *Store) FromWorkingDirectory(path string) (string, error)

FromWorkingDirectory reads a path the way a person typing it at a shell prompt means it: relative to where they are standing.

func (*Store) Load

func (s *Store) Load(id string) (_ *Annotation, returnedError error)

func (*Store) ReadSource added in v0.3.0

func (s *Store) ReadSource(file string) (_ []byte, returnedError error)

func (*Store) RecordPath

func (s *Store) RecordPath(id string) (string, error)

func (*Store) Remove

func (s *Store) Remove(id string) (returnedError error)

func (*Store) Root

func (s *Store) Root() string

func (*Store) Save

func (s *Store) Save(annotation *Annotation) (returnedError error)

func (*Store) WriteSource added in v0.3.0

func (s *Store) WriteSource(file string, content []byte) (returnedError error)

WriteSource atomically replaces a repository file without crossing its root.

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

type Timestamp struct{ time.Time }

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 Now added in v1.1.0

func Now() Timestamp

func ParseTimestamp added in v1.1.0

func ParseTimestamp(text string) (Timestamp, error)

func (Timestamp) MarshalYAML added in v1.1.0

func (t Timestamp) MarshalYAML() (any, error)

func (*Timestamp) UnmarshalYAML added in v1.1.0

func (t *Timestamp) UnmarshalYAML(node *yaml.Node) error

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.

type Type added in v1.1.0

type Type string

Type is the category of rationale a record carries.

const (
	TypeWhy         Type = "why"
	TypeGotcha      Type = "gotcha"
	TypeInvariant   Type = "invariant"
	TypeAntiPattern Type = "anti-pattern"
)

func ParseType added in v1.1.0

func ParseType(text string) (Type, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL