loam

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommitTypeFeat     = "feat"
	CommitTypeFix      = "fix"
	CommitTypeDocs     = "docs"
	CommitTypeStyle    = "style"
	CommitTypeRefactor = "refactor"
	CommitTypePerf     = "perf"
	CommitTypeTest     = "test"
	CommitTypeChore    = "chore"
)

CommitType constants for semantic commits

Variables

This section is empty.

Functions

func AppendFooter added in v0.4.0

func AppendFooter(msg string) string

AppendFooter appends the Loam footer to an arbitrary message if not present. Used for free-form -m "msg" commits.

func FormatCommitMessage added in v0.4.0

func FormatCommitMessage(ctype, scope, subject, body string) string

FormatCommitMessage builds a Conventional Commit message. logic:

<type>(<scope>): <subject>

<body>

Powered-by: Loam

func IsDevRun added in v0.3.0

func IsDevRun() bool

IsDevRun checks if the current process is running via `go run` or `go test`. It relies on the fact that these commands build binaries in temporary directories.

func ResolveVaultPath added in v0.3.0

func ResolveVaultPath(userPath string, forceTemp bool) string

ResolveVaultPath determines the actual path for the vault based on safety rules. If isDev is true (or forced), it re-roots the path into a temporary directory to avoid polluting the user's workspace/host repo.

Types

type Metadata

type Metadata map[string]interface{}

Metadata aliases the flexible YAML frontmatter map.

type Note

type Note struct {
	ID       string   // Typically the filename without extension
	Metadata Metadata // Parsed YAML frontmatter
	Content  string   // The markdown body
}

Note represents a Markdown file with optional YAML frontmatter.

func Parse

func Parse(r io.Reader) (*Note, error)

Parse reads a stream and decodes it into a Note. It detects if the stream starts with a frontmatter block (delimeted by ---).

func (*Note) String

func (n *Note) String() (string, error)

String serializes the note back to Markdown with Frontmatter.

type Option added in v0.3.0

type Option func(*Vault) error

Option is a functional option for configuring a Vault.

func WithAutoInit added in v0.3.0

func WithAutoInit(auto bool) Option

WithAutoInit enables automatic initialization of the vault directory and git repository if they do not exist.

func WithGitless added in v0.3.0

func WithGitless(gitless bool) Option

WithGitless forces the vault to operate without Git interactions. If false, it tries to auto-detect if git is available.

func WithMustExist added in v0.3.0

func WithMustExist() Option

WithMustExist enforces that the vault directory must already exist. It overrides AutoInit behavior.

func WithTempDir added in v0.3.0

func WithTempDir() Option

WithTempDir forces the vault to use a temporary directory for safety. This is useful for tests and examples.

type Transaction added in v0.2.0

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

Transaction represents a multi-step operation that holds the lock.

func (*Transaction) Apply added in v0.2.0

func (tx *Transaction) Apply(msg string) error

Apply persists the transaction changes: git add + git commit + unlock.

func (*Transaction) Rollback added in v0.2.0

func (tx *Transaction) Rollback() error

Rollback undoes changes made during the transaction and releases the lock.

func (*Transaction) Write added in v0.2.0

func (tx *Transaction) Write(n *Note) error

Write saves a note to disk within the transaction. It does NOT stage the file in Git.

type Vault

type Vault struct {
	Path string
	Git  *git.Client

	Logger *slog.Logger
	// contains filtered or unexported fields
}

Vault represents a directory containing notes backed by Git.

func NewVault

func NewVault(path string, logger *slog.Logger, opts ...Option) (*Vault, error)

NewVault creates a Vault instance rooted at the given path. It accepts options to configure behavior (AutoInit, Gitless, Safety).

func (*Vault) Begin added in v0.2.0

func (v *Vault) Begin() (*Transaction, error)

Begin starts a new transaction. It acquires the global lock.

func (*Vault) Delete

func (v *Vault) Delete(id string) error

Delete removes a note from the vault and stages the deletion in Git.

func (*Vault) IsGitless added in v0.3.0

func (v *Vault) IsGitless() bool

IsGitless returns true if the vault is operating in gitless mode.

func (*Vault) List

func (v *Vault) List() ([]Note, error)

List returns a list of all notes in the vault. It scans the directory recursively for .md files and parses them.

func (*Vault) Read

func (v *Vault) Read(id string) (*Note, error)

Read loads a note by its ID (filename without extension). It looks for {ID}.md in the vault root.

func (*Vault) Save added in v0.2.0

func (v *Vault) Save(n *Note, msg string) error

Save is an atomic wrapper for Write+Commit.

func (*Vault) Sync

func (v *Vault) Sync() error

Sync synchronizes the vault with the remote repository. It effectively performs a git pull --rebase and git push.

Jump to

Keyboard shortcuts

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