vault

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigFilename = ".pickaxe.json"

ConfigFilename is the name of the per-project config file.

Variables

View Source
var (
	ErrNotInitialized = errors.New("vault not initialized")
	ErrAlreadyExists  = errors.New(".pickaxe.json already exists")
	ErrNameCollision  = errors.New("name already in use")
	ErrNotFound       = errors.New("no entry with that name")
	ErrAmbiguousHash  = errors.New("ambiguous hash prefix")
	ErrReadOnly       = errors.New("file is read-only")
)

Functions

func BuildPreSelected

func BuildPreSelected(entries []Entry) map[string]bool

BuildPreSelected builds a set of already-registered paths for TUI pre-selection.

func DefaultName

func DefaultName(path string) string

DefaultName derives the short name from a file or directory path.

func ExpandEntries

func ExpandEntries(entries []Entry) (paths map[string]bool, writable map[string]bool, err error)

ExpandEntries returns two maps: paths (all concrete .md file paths) and writable (paths whose parent entry has Writable=true). Unavailable files are skipped.

func HashEntry

func HashEntry(name string) string

HashEntry computes a deterministic 16-char hex ID for an entry name.

func ReadFile

func ReadFile(dir string, name string) (string, error)

ReadFile opens the vault at dir and returns the content of the named file. Uses an O(1) map lookup after a single enumeration pass.

func ResolveHash

func ResolveHash(entries []Entry, prefix string) (string, error)

ResolveHash finds the entry whose hash starts with prefix without building a full HashTable.

func WriteFile added in v1.1.0

func WriteFile(dir, name, content string) error

WriteFile opens the vault at dir, checks that the named file is writable, and overwrites its content atomically.

Types

type Entry

type Entry struct {
	Type      EntryType `json:"type"`
	Path      string    `json:"path"`
	Name      string    `json:"name"`
	Recursive bool      `json:"recursive,omitempty"`
	Writable  bool      `json:"writable,omitempty"`
}

Entry represents one registered file or directory.

func Compact

func Compact(selectedPaths []string, writablePaths map[string]bool) ([]Entry, error)

Compact takes a set of selected file paths and an optional writablePaths map, and returns the most compact []Entry representation. For each directory, if ALL .md files are selected, collapse to a dir entry. If all subdirs are also fully selected, upgrade to recursive. Mixed writability within a directory prevents dir collapse — individual file entries are emitted instead.

type EntryType

type EntryType string

EntryType distinguishes file vs directory entries.

const (
	EntryTypeFile EntryType = "file"
	EntryTypeDir  EntryType = "dir"
)

type HashTable

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

HashTable maps entry names to their hashes and shortest unique prefix lengths.

func NewHashTable

func NewHashTable(entries []Entry) *HashTable

NewHashTable builds a HashTable from a slice of entries.

func (*HashTable) FullHash

func (ht *HashTable) FullHash(name string) string

FullHash returns the full 16-char hex hash for the named entry.

func (*HashTable) ResolvePrefix

func (ht *HashTable) ResolvePrefix(prefix string) (string, error)

ResolvePrefix finds the entry name whose hash starts with prefix. Returns ErrAmbiguousHash if multiple entries match, ErrNotFound if none.

func (*HashTable) ShortHash

func (ht *HashTable) ShortHash(name string) string

ShortHash returns the 8-char display hash for the named entry.

func (*HashTable) ShortPrefixLen

func (ht *HashTable) ShortPrefixLen(name string) int

ShortPrefixLen returns the length of the shortest unique prefix for the named entry, capped at 8 (the display hash length).

type Reader

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

Reader is a thin VaultReader implementation that delegates to the package-level ListFiles, ReadFile, and WriteFile functions, re-reading from disk each call.

func NewReader

func NewReader(dir string) *Reader

NewReader returns a Reader backed by dir.

func (*Reader) ListFiles

func (r *Reader) ListFiles() ([]ResolvedFile, error)

func (*Reader) ReadFile

func (r *Reader) ReadFile(name string) (string, error)

func (*Reader) WriteFile added in v1.1.0

func (r *Reader) WriteFile(name, content string) error

type ResolvedFile

type ResolvedFile struct {
	Name        string
	Path        string
	LastMod     time.Time
	Unavailable bool
	Writable    bool
}

ResolvedFile is a concrete file path with its display name and availability info.

func ListFiles

func ListFiles(dir string) ([]ResolvedFile, error)

ListFiles opens the vault at dir and returns all resolved files. Re-reads from disk every call.

type Vault

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

Vault owns a single .pickaxe.json and its mutations.

func Init

func Init(dir string) (*Vault, error)

Init creates a new .pickaxe.json in dir. Returns ErrAlreadyExists if present.

func Open

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

Open reads an existing .pickaxe.json from dir. Returns ErrNotInitialized if absent.

func (*Vault) AddDir

func (v *Vault) AddDir(path, name string, recursive, writable bool) error

AddDir registers a directory. name may be empty (defaults to dir base name).

func (*Vault) AddFile

func (v *Vault) AddFile(path, name string, writable bool) error

AddFile registers a single file. name may be empty (defaults to filename sans ext).

func (*Vault) Entries

func (v *Vault) Entries() []Entry

Entries returns a read-only copy of the registered entries.

func (*Vault) Remove

func (v *Vault) Remove(name string) error

Remove removes the entry with the given name.

func (*Vault) RemoveByPath

func (v *Vault) RemoveByPath(path string) error

RemoveByPath removes the entry with the given path. Returns ErrNotFound if absent.

func (*Vault) ReplaceEntries

func (v *Vault) ReplaceEntries(entries []Entry)

ReplaceEntries replaces all entries with the given slice.

func (*Vault) ResolveIdentifier

func (v *Vault) ResolveIdentifier(id string) (string, error)

ResolveIdentifier returns the entry name matching id by exact name first, then by hash prefix. Returns ErrAmbiguousHash or ErrNotFound on failure.

func (*Vault) Save

func (v *Vault) Save() error

Save persists the current state to disk atomically (write-to-temp + rename).

func (*Vault) SetWritable added in v1.1.0

func (v *Vault) SetWritable(name string, writable bool) error

SetWritable sets the writable flag on the named entry. Idempotent.

Jump to

Keyboard shortcuts

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