utils

package
v0.62.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalizeIfRelative

func CanonicalizeIfRelative(path string) string

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

func CanonicalizePath(path string) string

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

func ExtractIssueNumber(issueID string) int

ExtractIssueNumber extracts the number from an issue ID like "bd-123" -> 123

func ExtractIssuePrefix

func ExtractIssuePrefix(issueID string) string

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

func ExtractIssuePrefixKnown(issueID string, knownPrefixes []string) string

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

func NormalizeIssueType(t string) string

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

func NormalizeLabels(ss []string) []string

NormalizeLabels trims whitespace, removes empty strings, and deduplicates labels while preserving order.

func NormalizePathForComparison

func NormalizePathForComparison(path string) string

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

func PathsEqual(path1, path2 string) bool

PathsEqual compares two paths for equality, handling case-insensitive filesystems and symlinks.

func ResolveForWrite

func ResolveForWrite(path string) (string, error)

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

func ResolvePartialID(ctx context.Context, store storage.Storage, input string) (string, error)

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)

func ResolvePartialIDs

func ResolvePartialIDs(ctx context.Context, store storage.Storage, inputs []string) ([]string, error)

ResolvePartialIDs resolves multiple potentially partial issue IDs. Returns the resolved IDs and any errors encountered.

Types

This section is empty.

Jump to

Keyboard shortcuts

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