Documentation
¶
Overview ¶
Package utils provides utility functions for issue ID parsing and resolution.
Package utils provides utility functions for issue ID parsing and path handling.
Index ¶
- func CanonicalizePath(path string) string
- func ComputeDistance(s1, s2 string) int
- func ExtractIssueNumber(issueID string) int
- func ExtractIssuePrefix(issueID string) string
- func FindJSONLInDir(dbDir string) string
- func FindMoleculesJSONLInDir(dbDir string) string
- func FuzzyMatch(source, target string) bool
- func NormalizePathForComparison(path string) string
- func ParseIssueID(input string, prefix string) string
- func PathsEqual(path1, path2 string) bool
- func ResolveForWrite(path string) (string, error)
- func ResolvePartialID(ctx context.Context, store storage.Storage, input string) (string, error)
- func ResolvePartialIDs(ctx context.Context, store storage.Storage, inputs []string) ([]string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanonicalizePath ¶
CanonicalizePath converts a path to its canonical form by: 1. Converting to absolute path 2. Resolving symlinks 3. On macOS/Windows, resolving the true filesystem case (GH#880)
If any step fails, it falls back to the best available form: - If case resolution fails, returns symlink-resolved path - If symlink resolution fails, returns absolute path - If absolute path conversion fails, returns original path
This function is used to ensure consistent path handling across the codebase, particularly for BEADS_DIR environment variable processing and git worktree paths which require exact case matching.
func ComputeDistance ¶
ComputeDistance computes the Levenshtein distance between two strings. It is case-insensitive.
func ExtractIssueNumber ¶
ExtractIssueNumber extracts the number from an issue ID like "bd-123" -> 123
func ExtractIssuePrefix ¶
ExtractIssuePrefix extracts the prefix from an issue ID like "bd-123" -> "bd" Uses the last hyphen before a numeric or hash-like suffix:
- "beads-vscode-1" -> "beads-vscode" (numeric suffix)
- "web-app-a3f8e9" -> "web-app" (hash suffix with digits)
- "my-cool-app-123" -> "my-cool-app" (numeric suffix)
- "bd-a3f" -> "bd" (3-char hash)
Falls back to first hyphen when suffix looks like an English word (4+ chars, no digits):
- "vc-baseline-test" -> "vc" (word-like suffix: "test" is not a hash)
- "bd-multi-part-id" -> "bd" (word-like suffix: "id" is too short but "part-id" path)
This distinguishes hash IDs (which may contain letters but have digits or are 3 chars) from multi-part IDs where the suffix after the first hyphen is the entire ID.
func FindJSONLInDir ¶
FindJSONLInDir finds the JSONL file in the given .beads directory. It prefers issues.jsonl over other .jsonl files to prevent accidentally reading/writing to deletions.jsonl or merge artifacts (bd-tqo fix). Always returns a path (defaults to issues.jsonl if nothing suitable found).
Search order: 1. issues.jsonl (canonical name) 2. beads.jsonl (legacy support) 3. Any other .jsonl file except deletions/merge artifacts 4. Default to issues.jsonl
func FindMoleculesJSONLInDir ¶
FindMoleculesJSONLInDir finds the molecules.jsonl file in the given .beads directory. Returns the path to molecules.jsonl if it exists, empty string otherwise. Molecules are template issues used for instantiation (beads-1ra).
func FuzzyMatch ¶
FuzzyMatch checks if source is a fuzzy match of target. Characters in source must appear in target in the same order. Case-insensitive.
func NormalizePathForComparison ¶
NormalizePathForComparison returns a normalized path suitable for comparison. It resolves symlinks and handles case-insensitive filesystems (macOS, Windows).
On case-insensitive filesystems (darwin, windows), the path is lowercased to ensure that /Users/foo/Desktop and /Users/foo/desktop compare as equal.
This function should be used whenever comparing workspace paths, not for storing or displaying paths (preserve original case for those purposes).
func ParseIssueID ¶
ParseIssueID ensures an issue ID has the configured prefix. If the input already has the prefix (e.g., "bd-a3f8e9"), returns it as-is. If the input lacks the prefix (e.g., "a3f8e9"), adds the configured prefix. Works with hierarchical IDs too: "a3f8e9.1.2" → "bd-a3f8e9.1.2"
func PathsEqual ¶
PathsEqual compares two paths for equality, handling case-insensitive filesystems and symlinks. This is the preferred way to compare workspace paths in the daemon registry and discovery code.
func ResolveForWrite ¶
ResolveForWrite returns the path to write to, resolving symlinks. If path is a symlink, returns the resolved target path. If path doesn't exist, returns path unchanged (new file).
func ResolvePartialID ¶
ResolvePartialID resolves a potentially partial issue ID to a full ID. Supports: - Full IDs: "bd-a3f8e9" or "a3f8e9" → "bd-a3f8e9" - Without hyphen: "bda3f8e9" or "wya3f8e9" → "bd-a3f8e9" - Partial IDs: "a3f8" → "bd-a3f8e9" (if unique match) - Hierarchical: "a3f8e9.1" → "bd-a3f8e9.1"
Returns an error if: - No issue found matching the ID - Multiple issues match (ambiguous prefix)
Types ¶
This section is empty.