store

package
v0.1.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: 9 Imported by: 0

Documentation

Overview

Package store resolves where dibs keeps its files and provides small, safe filesystem primitives (atomic writes, an advisory lock, JSON helpers).

dibs state lives in two places, on purpose:

  • State: <git-common-dir>/dibs — coordination state (leases, presence, notes, journal). Every git worktree of a repository shares the same common dir, so leases taken in one worktree are visible in all others instantly, without commits, daemons, or databases. It never shows up in `git status`.

  • Shared: <repo-root>/.dibs — durable knowledge (lessons). These are plain files meant to be committed, reviewed in PRs, and shared with your team and CI through git itself.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotRepo = errors.New("not inside a git repository (dibs coordinates agents through the repo's .git dir)")

ErrNotRepo is returned when the current directory is not inside a git repo.

Functions

func AppendLine

func AppendLine(path string, line []byte) error

AppendLine appends one line to path (creating it if needed).

func ListJSON

func ListJSON[T any](dir string) ([]T, error)

ListJSON decodes every *.json file in dir into T, skipping files that fail to parse (a crashed writer must never brick coordination).

func ReadJSON

func ReadJSON(path string, v any) error

ReadJSON decodes the JSON file at path into v.

func WriteAtomic

func WriteAtomic(path string, data []byte) error

WriteAtomic writes data to path via a temp file in the same directory, so readers never observe a partial file.

func WriteJSON

func WriteJSON(path string, v any) error

WriteJSON writes v as indented JSON atomically (temp file + rename).

Types

type Store

type Store struct {
	State    string // <git-common-dir>/dibs — machine-local coordination state
	Shared   string // <repo-root>/.dibs — committed knowledge (lessons)
	Repo     string // repo root of the current worktree
	Worktree string // same as Repo; named for clarity at call sites
}

Store locates the dibs directories for one repository.

func At

func At(state, repo string) *Store

At builds a store from explicit paths. Tests use this.

func Open

func Open(dir string) (*Store, error)

Open resolves the store for the repository containing dir (usually "."). DIBS_STATE_DIR overrides the coordination dir, mainly for tests and unusual setups.

func (*Store) Branch

func (s *Store) Branch() string

Branch reports the current branch of the worktree ("HEAD" when detached, "" outside git).

func (*Store) EnsureState

func (s *Store) EnsureState() error

EnsureState creates the coordination directories.

func (*Store) WithLock

func (s *Store) WithLock(fn func() error) error

WithLock runs fn while holding an exclusive lock on the store. The lock is a kernel file lock (flock on Unix, LockFileEx on Windows), so it is released automatically when the holding process exits or crashes — there are no stale lockfiles to detect and no stealing heuristics to get wrong. Critical sections in dibs are a few milliseconds, so contention is short-lived.

Jump to

Keyboard shortcuts

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