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 CanonicalizeIfRelative(path string) string
- func CanonicalizePath(path string) string
- func ExtractIssueNumber(issueID string) int
- func ExtractIssuePrefix(issueID string) string
- func ExtractIssuePrefixKnown(issueID string, knownPrefixes []string) string
- func NormalizeIssueType(t string) string
- func NormalizeLabels(ss []string) []string
- func NormalizePathForComparison(path 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 CanonicalizeIfRelative ¶
CanonicalizeIfRelative ensures a path is absolute for filepath.Rel() compatibility. If the path is non-empty and relative, it is canonicalized using CanonicalizePath. Absolute paths and empty strings are returned unchanged.
This guards against code paths that might set paths to relative values, which would cause filepath.Rel() to fail or produce incorrect results.
See GH#959 for root cause analysis of the original autoflush bug.
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 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 ExtractIssuePrefixKnown ¶
ExtractIssuePrefixKnown extracts the prefix from an issue ID using a list of known-valid prefixes before falling back to the heuristic ExtractIssuePrefix.
When the valid prefixes are known from config (issue_prefix + allowed_prefixes), this gives deterministic results for multi-hyphen prefixes that the heuristic might misclassify (e.g., "me-py-toolkit-abcd" where "abcd" looks word-like).
Prefixes are checked longest-first so overlapping entries (e.g., "hq" and "hq-cv") resolve to the most specific match.
func NormalizeIssueType ¶
NormalizeIssueType expands type aliases to their canonical forms. For example: "mr" -> "merge-request", "feat" -> "feature", "mol" -> "molecule" Returns the input unchanged if it's not an alias.
func NormalizeLabels ¶
NormalizeLabels trims whitespace, removes empty strings, and deduplicates labels while preserving order.
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 PathsEqual ¶
PathsEqual compares two paths for equality, handling case-insensitive filesystems and symlinks.
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.