store

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 16 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 (
	DirName = ".koment"
)
View Source
const ProseWidth = 76
View Source
const RecordVersion = 1
View Source
const SchemaURL = "https://raw.githubusercontent.com/janpuc/koment/main/schema/annotation.schema.json"

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"`
	LastSeenLine int    `yaml:"last_seen_line,omitempty"`
}

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

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 Date

type Date struct{ time.Time }

Date is a calendar date with no time or zone, written as YYYY-MM-DD.

func Today

func Today() Date

func (Date) MarshalYAML

func (d Date) MarshalYAML() (any, error)

func (*Date) UnmarshalYAML

func (d *Date) UnmarshalYAML(unmarshal func(any) error) error

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 Kind

type Kind string
const (
	KindWhy         Kind = "why"
	KindGotcha      Kind = "gotcha"
	KindInvariant   Kind = "invariant"
	KindAntiPattern Kind = "anti-pattern"
)

func ParseKind

func ParseKind(text string) (Kind, 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 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.

Jump to

Keyboard shortcuts

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