Documentation
¶
Overview ¶
Package loader provides issue loading and file discovery utilities. This file handles automatic .gitignore management for the .bv directory.
Index ¶
- Constants
- Variables
- func EnsureBVInGitignore(projectDir string) error
- func FindJSONLPath(beadsDir string) (string, error)
- func FindJSONLPathWithWarnings(beadsDir string, warnFunc func(msg string)) (string, error)
- func GetBeadsDir(repoPath string) (string, error)
- func GetIssue() *model.Issue
- func IssuePoolStats() (hits uint64, misses uint64)
- func LoadIssues(repoPath string) ([]model.Issue, error)
- func LoadIssuesFromFile(path string) ([]model.Issue, error)
- func LoadIssuesFromFileWithOptions(path string, opts ParseOptions) ([]model.Issue, error)
- func LoadSprints(repoPath string) ([]model.Sprint, error)
- func LoadSprintsFromFile(path string) ([]model.Sprint, error)
- func ParseIssues(r io.Reader) ([]model.Issue, error)
- func ParseIssuesWithOptions(r io.Reader, opts ParseOptions) ([]model.Issue, error)
- func ParseSprints(r io.Reader) ([]model.Sprint, error)
- func PutIssue(issue *model.Issue)
- func ReturnIssuePtrsToPool(issues []*model.Issue)
- func SaveSprints(repoPath string, sprints []model.Sprint) error
- func SaveSprintsToFile(path string, sprints []model.Sprint) error
- type CacheStats
- type GitLoader
- func (g *GitLoader) CacheStats() CacheStats
- func (g *GitLoader) ClearCache()
- func (g *GitLoader) GetCommitsBetween(fromRev, toRev string) ([]RevisionInfo, error)
- func (g *GitLoader) HasBeadsAtRevision(revision string) (bool, error)
- func (g *GitLoader) ListRevisions(limit int) ([]RevisionInfo, error)
- func (g *GitLoader) LoadAt(revision string) ([]model.Issue, error)
- func (g *GitLoader) LoadAtDate(t time.Time) ([]model.Issue, error)
- func (g *GitLoader) ResolveRevision(revision string) (string, error)
- type ParseOptions
- type PooledIssues
- type RevisionInfo
Constants ¶
const BeadsDirEnvVar = "BEADS_DIR"
BeadsDirEnvVar is the name of the environment variable for custom beads directory
const DefaultMaxBufferSize = 1024 * 1024 * 10
DefaultMaxBufferSize is the default buffer size for the scanner (10MB).
const SprintsFileName = "sprints.jsonl"
SprintsFileName is the canonical filename for sprint storage.
Variables ¶
var IssuePool = sync.Pool{ New: func() any { issuePoolNews.Add(1) return &model.Issue{ Dependencies: make([]*model.Dependency, 0, defaultDepsCap), Comments: make([]*model.Comment, 0, defaultCommentsCap), Labels: make([]string, 0, defaultLabelsCap), } }, }
IssuePool manages reusable Issue structs. Only return issues when they are no longer referenced by any snapshot.
var PreferredJSONLNames = []string{"issues.jsonl", "beads.jsonl", "beads.base.jsonl"}
PreferredJSONLNames defines the priority order for looking up beads data files.
Functions ¶
func EnsureBVInGitignore ¶ added in v0.10.3
EnsureBVInGitignore ensures that .bv/ is listed in the project's .gitignore file. This prevents bv-specific files (semantic search index, baselines, drift config, etc.) from polluting the git repository.
The function is idempotent and safe to call multiple times. It will:
- Create .gitignore if it doesn't exist
- Add ".bv/" if it's not already present (checks for .bv, .bv/, .bv/*, etc.)
- Preserve existing file content and formatting
Returns nil on success, or an error if the file cannot be read/written.
func FindJSONLPath ¶
FindJSONLPath locates the beads JSONL file in the given directory. Prefers issues.jsonl (canonical per beads upstream) over beads.jsonl (backward compat). Skips backup files and merge artifacts.
func FindJSONLPathWithWarnings ¶ added in v0.10.3
FindJSONLPathWithWarnings is like FindJSONLPath but optionally reports warnings about detected merge artifacts via the provided callback.
func GetBeadsDir ¶ added in v0.10.3
GetBeadsDir returns the beads directory path, respecting BEADS_DIR env var. If BEADS_DIR is set, it is used directly. Otherwise, falls back to .beads in the given repoPath (or cwd if empty).
func IssuePoolStats ¶ added in v0.13.0
IssuePoolStats returns the total pool hits and misses since process start.
func LoadIssues ¶
LoadIssues reads issues from the beads directory. Respects BEADS_DIR environment variable, otherwise uses .beads in repoPath. Automatically finds the correct JSONL file (issues.jsonl preferred, beads.jsonl fallback).
func LoadIssuesFromFile ¶
LoadIssuesFromFile reads issues directly from a specific JSONL file path.
func LoadIssuesFromFileWithOptions ¶ added in v0.10.3
func LoadIssuesFromFileWithOptions(path string, opts ParseOptions) ([]model.Issue, error)
LoadIssuesFromFileWithOptions reads issues from a file with custom options.
func LoadSprints ¶ added in v0.10.3
LoadSprints reads sprints from .beads/sprints.jsonl under repoPath. Missing file is treated as "no sprints" (empty slice, nil error).
func LoadSprintsFromFile ¶ added in v0.10.3
LoadSprintsFromFile reads sprints directly from a specific JSONL file path. Missing file is treated as "no sprints" (empty slice, nil error).
func ParseIssues ¶ added in v0.10.3
ParseIssues parses JSONL content from a reader into issues. Handles UTF-8 BOM stripping, large lines, and validation.
func ParseIssuesWithOptions ¶ added in v0.10.3
ParseIssuesWithOptions parses JSONL content with custom options.
func ParseSprints ¶ added in v0.10.3
ParseSprints parses JSONL content from a reader into sprints. Malformed or invalid sprints are skipped with warnings written to stderr, consistent with ParseIssues behavior (suppressed in robot mode).
func PutIssue ¶ added in v0.13.0
PutIssue returns an Issue to the pool for reuse. After this call, the issue must not be used.
func ReturnIssuePtrsToPool ¶ added in v0.13.0
ReturnIssuePtrsToPool returns a slice of pooled issue pointers to the pool. Use this when a snapshot is replaced and no longer referenced.
func SaveSprints ¶ added in v0.10.3
SaveSprints writes sprints to .beads/sprints.jsonl under repoPath.
Types ¶
type CacheStats ¶
type CacheStats struct {
TotalEntries int `json:"total_entries"`
ValidEntries int `json:"valid_entries"`
MaxAge time.Duration `json:"max_age"`
}
CacheStats holds cache statistics
type GitLoader ¶
type GitLoader struct {
// contains filtered or unexported fields
}
GitLoader loads beads from git history
func NewGitLoader ¶
NewGitLoader creates a new git history loader for the given repo
func NewGitLoaderWithCacheTTL ¶
NewGitLoaderWithCacheTTL creates a loader with custom cache TTL
func (*GitLoader) CacheStats ¶
func (g *GitLoader) CacheStats() CacheStats
CacheStats returns cache statistics
func (*GitLoader) ClearCache ¶
func (g *GitLoader) ClearCache()
ClearCache removes all cached entries
func (*GitLoader) GetCommitsBetween ¶
func (g *GitLoader) GetCommitsBetween(fromRev, toRev string) ([]RevisionInfo, error)
GetCommitsBetween returns commits between two revisions
func (*GitLoader) HasBeadsAtRevision ¶
HasBeadsAtRevision checks if beads files exist at a given revision
func (*GitLoader) ListRevisions ¶
func (g *GitLoader) ListRevisions(limit int) ([]RevisionInfo, error)
ListRevisions returns commits that modified beads files
func (*GitLoader) LoadAt ¶
LoadAt loads issues from a specific git revision revision can be: SHA, branch name, tag name, HEAD~N, or date expression
func (*GitLoader) LoadAtDate ¶
LoadAtDate loads issues from the state at a specific date/time Uses git rev-list to find the commit at or before the given time
type ParseOptions ¶ added in v0.10.3
type ParseOptions struct {
// WarningHandler is called with warning messages (e.g., malformed JSON).
// If nil, warnings are printed to os.Stderr.
WarningHandler func(string)
// BufferSize sets the maximum line size (in bytes) to read at once.
// Lines longer than this are skipped with a warning.
// If 0, uses DefaultMaxBufferSize (10MB).
BufferSize int
// IssueFilter optionally filters parsed issues. Return true to include.
// When nil, all valid issues are included.
IssueFilter func(*model.Issue) bool
}
ParseOptions configures the behavior of ParseIssues.
type PooledIssues ¶ added in v0.13.0
PooledIssues bundles parsed issues with their pooled backing objects. The pooled references must be returned via ReturnIssuePtrsToPool when the snapshot is no longer used.
func LoadIssuesFromFilePooled ¶ added in v0.13.0
func LoadIssuesFromFilePooled(path string) (PooledIssues, error)
LoadIssuesFromFilePooled reads issues directly from a JSONL file path with pooling enabled.
func LoadIssuesFromFileWithOptionsPooled ¶ added in v0.13.0
func LoadIssuesFromFileWithOptionsPooled(path string, opts ParseOptions) (PooledIssues, error)
LoadIssuesFromFileWithOptionsPooled reads issues from a file with pooling enabled. The caller must return pooled issues via ReturnIssuePtrsToPool when no longer needed.
func ParseIssuesWithOptionsPooled ¶ added in v0.13.0
func ParseIssuesWithOptionsPooled(r io.Reader, opts ParseOptions) (PooledIssues, error)
ParseIssuesWithOptionsPooled parses JSONL content with pooling enabled. The caller must return pooled issues via ReturnIssuePtrsToPool when no longer needed.