beads/cmd/bd/linear.go
matt wilkie 3e56f0b214
Document Linear external_ref pre-linking (#3517)
* Document Linear external ref prelinking (bd-ly3)
* Fix Linear sync dependency graph handling
* Fix init remote clone routing
* Fix stale gate help text
* Fix init remote cherry-pick integration
* Fix init remote flag handling
* Fix Linear prelink hydration blockers
* Fix Linear relation dependency gating
* Fix ready list parent filtering
* Deduplicate dry-run dependency previews by stored identity
2026-04-27 06:05:30 -07:00

733 lines
24 KiB
Go

package main
import (
"context"
"fmt"
"os"
"regexp"
"strconv"
"strings"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/debug"
"github.com/steveyegge/beads/internal/linear"
"github.com/steveyegge/beads/internal/tracker"
"github.com/steveyegge/beads/internal/types"
)
// linearCmd is the root command for Linear integration.
var linearCmd = &cobra.Command{
Use: "linear",
GroupID: "advanced",
Short: "Linear integration commands",
Long: `Synchronize issues between beads and Linear.
Configuration:
bd config set linear.api_key "YOUR_API_KEY"
bd config set linear.team_id "TEAM_ID"
bd config set linear.team_ids "TEAM_ID1,TEAM_ID2" # Multiple teams (comma-separated)
bd config set linear.project_id "PROJECT_ID" # Optional: sync only this project
Environment variables (alternative to config):
LINEAR_API_KEY - Linear API key
LINEAR_TEAM_ID - Linear team ID (UUID, singular)
LINEAR_TEAM_IDS - Linear team IDs (comma-separated UUIDs)
Data Mapping (optional, sensible defaults provided):
Priority mapping (Linear 0-4 to Beads 0-4):
bd config set linear.priority_map.0 4 # No priority -> Backlog
bd config set linear.priority_map.1 0 # Urgent -> Critical
bd config set linear.priority_map.2 1 # High -> High
bd config set linear.priority_map.3 2 # Medium -> Medium
bd config set linear.priority_map.4 3 # Low -> Low
State mapping (Linear state type to Beads status):
bd config set linear.state_map.backlog open
bd config set linear.state_map.unstarted open
bd config set linear.state_map.started in_progress
bd config set linear.state_map.completed closed
bd config set linear.state_map.canceled closed
bd config set linear.state_map.my_custom_state in_progress # Custom state names
Label to issue type mapping:
bd config set linear.label_type_map.bug bug
bd config set linear.label_type_map.feature feature
bd config set linear.label_type_map.epic epic
Relation type mapping (Linear relations to Beads dependencies):
bd config set linear.relation_map.blocks blocks
bd config set linear.relation_map.blockedBy blocks
bd config set linear.relation_map.duplicate duplicates
bd config set linear.relation_map.related related
ID generation (optional, hash IDs to match bd/Jira hash mode):
bd config set linear.id_mode "hash" # hash (default)
bd config set linear.hash_length "6" # hash length 3-8 (default: 6)
Examples:
bd linear sync --pull # Import issues from Linear
bd linear sync --push # Export issues to Linear
bd linear sync # Bidirectional sync (pull then push)
bd linear sync --dry-run # Preview sync without changes
bd create "Fix login" --external-ref https://linear.app/team/issue/TEAM-123
# Link a local issue to an existing Linear issue
bd linear status # Show sync status`,
}
// linearSyncCmd handles synchronization with Linear.
var linearSyncCmd = &cobra.Command{
Use: "sync",
Short: "Synchronize issues with Linear",
Long: `Synchronize issues between beads and Linear.
Modes:
--pull Import issues from Linear into beads
--push Export issues from beads to Linear
(no flags) Bidirectional sync: pull then push, with conflict resolution
Team Selection:
--team ID1,ID2 Override configured team IDs for this sync
Multiple teams can be configured via linear.team_ids (comma-separated).
Falls back to linear.team_id for backward compatibility.
Push requires explicit --team when multiple teams are configured.
Type Filtering (--push only):
--type task,feature Only sync issues of these types
--exclude-type wisp Exclude issues of these types
--include-ephemeral Include ephemeral issues (wisps, etc.); default is to exclude
--parent TICKET Only push this ticket and its descendants
--relations Import Linear relations as bd dependencies on pull
Conflict Resolution:
By default, newer timestamp wins. Override with:
--prefer-local Always prefer local beads version
--prefer-linear Always prefer Linear version
Examples:
bd linear sync --pull # Import from Linear
bd linear sync --pull --relations # Import Linear blocking relations as bd deps
bd linear sync --push --create-only # Push new issues only
bd linear sync --push --type=task,feature # Push only tasks and features
bd linear sync --push --exclude-type=wisp # Push all except wisps
bd linear sync --push --parent=bd-abc123 # Push one ticket tree
bd linear sync --dry-run # Preview without changes
bd linear sync --prefer-local # Bidirectional, local wins`,
Run: runLinearSync,
}
// linearStatusCmd shows the current sync status.
var linearStatusCmd = &cobra.Command{
Use: "status",
Short: "Show Linear sync status",
Long: `Show the current Linear sync status, including:
- Last sync timestamp
- Configuration status
- Number of issues with Linear links
- Issues pending push (no external_ref)`,
Run: runLinearStatus,
}
// linearTeamsCmd lists available teams.
var linearTeamsCmd = &cobra.Command{
Use: "teams",
Short: "List available Linear teams",
Long: `List all teams accessible with your Linear API key.
Use this to find the team ID (UUID) needed for configuration.
Example:
bd linear teams
bd config set linear.team_id "12345678-1234-1234-1234-123456789abc"`,
Run: runLinearTeams,
}
func init() {
linearSyncCmd.Flags().Bool("pull", false, "Pull issues from Linear")
linearSyncCmd.Flags().Bool("push", false, "Push issues to Linear")
linearSyncCmd.Flags().Bool("dry-run", false, "Preview sync without making changes")
linearSyncCmd.Flags().Bool("prefer-local", false, "Prefer local version on conflicts")
linearSyncCmd.Flags().Bool("prefer-linear", false, "Prefer Linear version on conflicts")
linearSyncCmd.Flags().Bool("create-only", false, "Only create new issues, don't update existing")
linearSyncCmd.Flags().Bool("update-refs", true, "Update external_ref after creating Linear issues")
linearSyncCmd.Flags().String("state", "all", "Issue state to sync: open, closed, all")
linearSyncCmd.Flags().StringSlice("type", nil, "Only sync issues of these types (can be repeated)")
linearSyncCmd.Flags().StringSlice("exclude-type", nil, "Exclude issues of these types (can be repeated)")
linearSyncCmd.Flags().Bool("include-ephemeral", false, "Include ephemeral issues (wisps, etc.) when pushing to Linear")
linearSyncCmd.Flags().String("parent", "", "Limit push to this beads ticket and its descendants")
linearSyncCmd.Flags().StringSlice("team", nil, "Team ID(s) to sync (overrides configured team_id/team_ids)")
linearSyncCmd.Flags().Bool("relations", false, "Import Linear relations as bd dependencies when pulling")
registerSelectiveSyncFlags(linearSyncCmd)
linearCmd.AddCommand(linearSyncCmd)
linearCmd.AddCommand(linearStatusCmd)
linearCmd.AddCommand(linearTeamsCmd)
rootCmd.AddCommand(linearCmd)
}
func runLinearSync(cmd *cobra.Command, args []string) {
pull, _ := cmd.Flags().GetBool("pull")
push, _ := cmd.Flags().GetBool("push")
dryRun, _ := cmd.Flags().GetBool("dry-run")
preferLocal, _ := cmd.Flags().GetBool("prefer-local")
preferLinear, _ := cmd.Flags().GetBool("prefer-linear")
createOnly, _ := cmd.Flags().GetBool("create-only")
state, _ := cmd.Flags().GetString("state")
typeFilters, _ := cmd.Flags().GetStringSlice("type")
excludeTypes, _ := cmd.Flags().GetStringSlice("exclude-type")
includeEphemeral, _ := cmd.Flags().GetBool("include-ephemeral")
cliTeams, _ := cmd.Flags().GetStringSlice("team")
relations, _ := cmd.Flags().GetBool("relations")
if !dryRun {
CheckReadonly("linear sync")
}
if preferLocal && preferLinear {
FatalError("cannot use both --prefer-local and --prefer-linear")
}
if err := ensureStoreActive(); err != nil {
FatalError("database not available: %v", err)
}
if err := validateLinearConfig(cliTeams); err != nil {
FatalError("%v", err)
}
ctx := rootCtx
teamIDs := getLinearTeamIDs(ctx, cliTeams)
willPush := push || !pull
// Require explicit --team for push when multiple teams are configured.
if willPush && len(teamIDs) > 1 && len(cliTeams) == 0 {
FatalError("push requires explicit --team flag when multiple teams are configured\n" +
"Use: bd linear sync --push --team <TEAM_ID>")
}
// Create and initialize the Linear tracker
lt := &linear.Tracker{}
lt.SetTeamIDs(teamIDs)
if err := lt.Init(ctx, store); err != nil {
FatalError("initializing Linear tracker: %v", err)
}
if willPush {
if err := lt.ValidatePushStateMappings(ctx); err != nil {
FatalError("%v", err)
}
}
// Create the sync engine
engine := tracker.NewEngine(lt, store, actor)
engine.OnMessage = func(msg string) { fmt.Println(" " + msg) }
engine.OnWarning = func(msg string) { fmt.Fprintf(os.Stderr, "Warning: %s\n", msg) }
// Set up Linear-specific pull hooks
engine.PullHooks = buildLinearPullHooks(ctx)
// Build sync options from CLI flags
opts := tracker.SyncOptions{
Pull: pull,
Push: push,
DryRun: dryRun,
CreateOnly: createOnly,
State: state,
}
opts.DependencySources = linearPullDependencySources(relations)
// Convert type filters
for _, t := range typeFilters {
opts.TypeFilter = append(opts.TypeFilter, types.IssueType(strings.ToLower(t)))
}
for _, t := range excludeTypes {
opts.ExcludeTypes = append(opts.ExcludeTypes, types.IssueType(strings.ToLower(t)))
}
if !includeEphemeral {
opts.ExcludeEphemeral = true
}
if err := applySelectiveSyncFlags(cmd, &opts, push); err != nil {
FatalError("%v", err)
}
allowProjectCreates := opts.ParentID != "" || len(opts.IssueIDs) > 0
// Set up Linear-specific push hooks
engine.PushHooks = buildLinearPushHooks(ctx, lt, allowProjectCreates)
// Map conflict resolution
if preferLocal {
opts.ConflictResolution = tracker.ConflictLocal
} else if preferLinear {
opts.ConflictResolution = tracker.ConflictExternal
} else {
opts.ConflictResolution = tracker.ConflictTimestamp
}
// Run sync
result, err := engine.Sync(ctx, opts)
if err != nil {
if jsonOutput {
outputJSON(result)
} else {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
}
os.Exit(1)
}
// Output results
if jsonOutput {
outputJSON(result)
} else if dryRun {
fmt.Println("\n✓ Dry run complete (no changes made)")
} else {
if result.Stats.Pulled > 0 {
fmt.Printf("✓ Pulled %d issues (%d created, %d updated)\n",
result.Stats.Pulled, result.Stats.Created, result.Stats.Updated)
}
if result.Stats.Pushed > 0 {
fmt.Printf("✓ Pushed %d issues\n", result.Stats.Pushed)
}
if result.Stats.Conflicts > 0 {
fmt.Printf("→ Resolved %d conflicts\n", result.Stats.Conflicts)
}
fmt.Println("\n✓ Linear sync complete")
if len(result.Warnings) > 0 {
fmt.Println("\nWarnings:")
for _, w := range result.Warnings {
fmt.Printf(" - %s\n", w)
}
}
}
}
func linearPullDependencySources(includeRelations bool) []tracker.DependencySource {
if includeRelations {
return nil
}
return []tracker.DependencySource{tracker.DependencySourceParent}
}
// buildLinearPullHooks creates PullHooks for Linear-specific pull behavior.
func buildLinearPullHooks(ctx context.Context) *tracker.PullHooks {
idMode := getLinearIDMode(ctx)
hashLength := getLinearHashLength(ctx)
hooks := &tracker.PullHooks{}
if idMode == "hash" {
// Pre-load existing IDs for collision avoidance
existingIssues, err := store.SearchIssues(ctx, "", types.IssueFilter{})
usedIDs := make(map[string]bool)
if err == nil {
for _, issue := range existingIssues {
if issue.ID != "" {
usedIDs[issue.ID] = true
}
}
}
// YAML config takes precedence — in shared-server mode the DB
// may belong to a different project (GH#2469).
prefix := config.GetString("issue-prefix")
if prefix == "" {
var err error
prefix, err = store.GetConfig(ctx, "issue_prefix")
if err != nil || prefix == "" {
prefix = "bd"
}
}
hooks.GenerateID = func(_ context.Context, issue *types.Issue) error {
ids := []*types.Issue{issue}
idOpts := linear.IDGenerationOptions{
BaseLength: hashLength,
MaxLength: 8,
UsedIDs: usedIDs,
}
if err := linear.GenerateIssueIDs(ids, prefix, "linear-import", idOpts); err != nil {
return err
}
// Track the newly generated ID for future collision avoidance
usedIDs[issue.ID] = true
return nil
}
}
return hooks
}
// buildLinearPushHooks creates PushHooks for Linear-specific push behavior.
func buildLinearPushHooks(ctx context.Context, lt *linear.Tracker, allowProjectCreates bool) *tracker.PushHooks {
config := lt.MappingConfig()
return &tracker.PushHooks{
FormatDescription: func(issue *types.Issue) string {
return linear.BuildLinearDescription(issue)
},
ContentEqual: func(local *types.Issue, remote *tracker.TrackerIssue) bool {
remoteIssue, ok := remote.Raw.(*linear.Issue)
if ok && remoteIssue != nil {
return linear.PushFieldsEqual(local, remoteIssue, config)
}
remoteConv := lt.FieldMapper().IssueToBeads(remote)
if remoteConv == nil || remoteConv.Issue == nil {
return false
}
return linear.PushFieldsEqualToBeads(local, remoteConv.Issue)
},
BuildStateCache: func(ctx context.Context) (interface{}, error) {
return linear.BuildStateCacheFromTracker(ctx, lt)
},
ResolveState: func(cache interface{}, status types.Status) (string, bool) {
sc, ok := cache.(*linear.StateCache)
if !ok || sc == nil {
return "", false
}
id := sc.FindStateForBeadsStatus(status)
return id, id != ""
},
ShouldPush: func(issue *types.Issue) bool {
if projectID, _ := store.GetConfig(ctx, "linear.project_id"); projectID != "" {
if issue.ExternalRef == nil || strings.TrimSpace(*issue.ExternalRef) == "" {
if !allowProjectCreates {
return false
}
}
}
// Apply push prefix filtering if configured
pushPrefix, _ := store.GetConfig(ctx, "linear.push_prefix")
if pushPrefix == "" {
return true
}
for _, prefix := range strings.Split(pushPrefix, ",") {
prefix = strings.TrimSpace(prefix)
prefix = strings.TrimSuffix(prefix, "-")
if prefix != "" && strings.HasPrefix(issue.ID, prefix+"-") {
return true
}
}
return false
},
}
}
func runLinearStatus(cmd *cobra.Command, args []string) {
ctx := rootCtx
if err := ensureStoreActive(); err != nil {
FatalError("%v", err)
}
apiKey, _ := getLinearConfig(ctx, "linear.api_key")
teamIDs := getLinearTeamIDs(ctx, nil)
lastSync, _ := store.GetConfig(ctx, "linear.last_sync")
configured := apiKey != "" && len(teamIDs) > 0
allIssues, err := store.SearchIssues(ctx, "", types.IssueFilter{})
if err != nil {
FatalError("%v", err)
}
withLinearRef := 0
pendingPush := 0
for _, issue := range allIssues {
if issue.ExternalRef != nil && linear.IsLinearExternalRef(*issue.ExternalRef) {
withLinearRef++
} else if issue.ExternalRef == nil {
pendingPush++
}
}
if jsonOutput {
hasAPIKey := apiKey != ""
// Backward compat: include team_id as first team, plus full list.
teamID := ""
if len(teamIDs) > 0 {
teamID = teamIDs[0]
}
outputJSON(map[string]interface{}{
"configured": configured,
"has_api_key": hasAPIKey,
"team_id": teamID,
"team_ids": teamIDs,
"last_sync": lastSync,
"total_issues": len(allIssues),
"with_linear_ref": withLinearRef,
"pending_push": pendingPush,
})
return
}
fmt.Println("Linear Sync Status")
fmt.Println("==================")
fmt.Println()
if !configured {
fmt.Println("Status: Not configured")
fmt.Println()
fmt.Println("To configure Linear integration:")
fmt.Println(" bd config set linear.api_key \"YOUR_API_KEY\"")
fmt.Println(" bd config set linear.team_id \"TEAM_ID\"")
fmt.Println(" bd config set linear.team_ids \"TEAM_ID1,TEAM_ID2\" # multiple teams")
fmt.Println()
fmt.Println("Or use environment variables:")
fmt.Println(" export LINEAR_API_KEY=\"YOUR_API_KEY\"")
fmt.Println(" export LINEAR_TEAM_ID=\"TEAM_ID\"")
return
}
if len(teamIDs) == 1 {
fmt.Printf("Team ID: %s\n", teamIDs[0])
} else {
fmt.Printf("Team IDs: %s (%d teams)\n", strings.Join(teamIDs, ", "), len(teamIDs))
}
fmt.Printf("API Key: %s\n", maskAPIKey(apiKey))
if lastSync != "" {
fmt.Printf("Last Sync: %s\n", lastSync)
} else {
fmt.Println("Last Sync: Never")
}
fmt.Println()
fmt.Printf("Total Issues: %d\n", len(allIssues))
fmt.Printf("With Linear: %d\n", withLinearRef)
fmt.Printf("Local Only: %d\n", pendingPush)
if pendingPush > 0 {
fmt.Println()
fmt.Printf("Run 'bd linear sync --push' to push %d local issue(s) to Linear\n", pendingPush)
}
}
func runLinearTeams(cmd *cobra.Command, args []string) {
ctx := rootCtx
apiKey, apiKeySource := getLinearConfig(ctx, "linear.api_key")
if apiKey == "" {
fmt.Fprintf(os.Stderr, "Error: Linear API key not configured\n")
fmt.Fprintf(os.Stderr, "Run: bd config set linear.api_key \"YOUR_API_KEY\"\n")
fmt.Fprintf(os.Stderr, "Or: export LINEAR_API_KEY=YOUR_API_KEY\n")
os.Exit(1)
}
debug.Logf("Using API key from %s", apiKeySource)
client := linear.NewClient(apiKey, "")
teams, err := client.FetchTeams(ctx)
if err != nil {
FatalError("fetching teams: %v", err)
}
if len(teams) == 0 {
fmt.Println("No teams found (check your API key permissions)")
return
}
if jsonOutput {
outputJSON(teams)
return
}
fmt.Println("Available Linear Teams")
fmt.Println("======================")
fmt.Println()
fmt.Printf("%-40s %-6s %s\n", "ID (use this for linear.team_id)", "Key", "Name")
fmt.Printf("%-40s %-6s %s\n", "----------------------------------------", "------", "----")
for _, team := range teams {
fmt.Printf("%-40s %-6s %s\n", team.ID, team.Key, team.Name)
}
fmt.Println()
fmt.Println("To configure:")
fmt.Println(" bd config set linear.team_id \"<ID>\"")
fmt.Println(" bd config set linear.team_ids \"<ID1>,<ID2>\" # multiple teams")
}
// uuidRegex matches valid UUID format (with or without hyphens).
var uuidRegex = regexp.MustCompile(`^[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12}$`)
func isValidUUID(s string) bool {
return uuidRegex.MatchString(s)
}
// validateLinearConfig checks that required Linear configuration is present.
// cliTeams is the list of team IDs from the --team flag (may be nil).
func validateLinearConfig(cliTeams []string) error {
if err := ensureStoreActive(); err != nil {
return fmt.Errorf("database not available: %w", err)
}
ctx := rootCtx
apiKey, _ := getLinearConfig(ctx, "linear.api_key")
if apiKey == "" {
return fmt.Errorf("Linear API key not configured\nRun: bd config set linear.api_key \"YOUR_API_KEY\"\nOr: export LINEAR_API_KEY=YOUR_API_KEY")
}
teamIDs := getLinearTeamIDs(ctx, cliTeams)
if len(teamIDs) == 0 {
return fmt.Errorf("no Linear team ID configured\nRun: bd config set linear.team_id \"TEAM_ID\"\nOr: bd config set linear.team_ids \"TEAM_ID1,TEAM_ID2\"\nOr: export LINEAR_TEAM_ID=TEAM_ID")
}
for _, id := range teamIDs {
if !isValidUUID(id) {
return fmt.Errorf("invalid Linear team ID (expected UUID format like '12345678-1234-1234-1234-123456789abc')\nInvalid value: %s", id)
}
}
return nil
}
// maskAPIKey returns a masked version of an API key for display.
// Shows first 4 and last 4 characters, with dots in between.
func maskAPIKey(key string) string {
if len(key) <= 8 {
return "****"
}
return key[:4] + "..." + key[len(key)-4:]
}
// getLinearConfig reads a Linear configuration value. Returns the value and its source.
// Priority: project config > environment variable.
func getLinearConfig(ctx context.Context, key string) (value string, source string) {
// Secret keys (e.g. linear.api_key) are stored in config.yaml, not the
// Dolt database, to avoid leaking secrets when pushing to remotes.
if config.IsYamlOnlyKey(key) {
if value := config.GetString(key); value != "" {
return value, "project config (config.yaml)"
}
envKey := linearConfigToEnvVar(key)
if envKey != "" {
if value := os.Getenv(envKey); value != "" {
return value, fmt.Sprintf("environment variable (%s)", envKey)
}
}
return "", ""
}
// Try to read from store (works in direct mode)
if store != nil {
value, _ = store.GetConfig(ctx, key) // Best effort: empty value is valid fallback
if value != "" {
return value, "project config (bd config)"
}
} else if dbPath != "" {
tempStore, err := openReadOnlyStoreForDBPath(ctx, dbPath)
if err == nil {
defer func() { _ = tempStore.Close() }()
value, _ = tempStore.GetConfig(ctx, key) // Best effort: empty value is valid fallback
if value != "" {
return value, "project config (bd config)"
}
}
}
// Fall back to environment variable
envKey := linearConfigToEnvVar(key)
if envKey != "" {
value = os.Getenv(envKey)
if value != "" {
return value, fmt.Sprintf("environment variable (%s)", envKey)
}
}
return "", ""
}
// linearConfigToEnvVar maps Linear config keys to their environment variable names.
func linearConfigToEnvVar(key string) string {
switch key {
case "linear.api_key":
return "LINEAR_API_KEY"
case "linear.team_id":
return "LINEAR_TEAM_ID"
case "linear.team_ids":
return "LINEAR_TEAM_IDS"
default:
return ""
}
}
// getLinearTeamIDs resolves the effective team IDs from all config sources.
// Precedence: cliTeams (--team flag) > linear.team_ids > LINEAR_TEAM_IDS > linear.team_id > LINEAR_TEAM_ID
func getLinearTeamIDs(ctx context.Context, cliTeams []string) []string {
pluralVal, _ := getLinearConfig(ctx, "linear.team_ids")
singularVal, _ := getLinearConfig(ctx, "linear.team_id")
return tracker.ResolveProjectIDs(cliTeams, pluralVal, singularVal)
}
// getLinearClient creates a configured Linear client from beads config.
// Uses the first configured team ID for operations that require a single team.
func getLinearClient(ctx context.Context) (*linear.Client, error) {
apiKey, _ := getLinearConfig(ctx, "linear.api_key")
if apiKey == "" {
return nil, fmt.Errorf("Linear API key not configured")
}
teamIDs := getLinearTeamIDs(ctx, nil)
if len(teamIDs) == 0 {
return nil, fmt.Errorf("Linear team ID not configured")
}
client := linear.NewClient(apiKey, teamIDs[0])
if store != nil {
if endpoint, _ := store.GetConfig(ctx, "linear.api_endpoint"); endpoint != "" {
client = client.WithEndpoint(endpoint)
}
// Filter to specific project if configured
if projectID, _ := store.GetConfig(ctx, "linear.project_id"); projectID != "" {
client = client.WithProjectID(projectID)
}
}
return client, nil
}
// storeConfigLoader adapts the store to the linear.ConfigLoader interface.
type storeConfigLoader struct {
ctx context.Context
}
func (l *storeConfigLoader) GetAllConfig() (map[string]string, error) {
return store.GetAllConfig(l.ctx)
}
// loadLinearMappingConfig loads mapping configuration from beads config.
func loadLinearMappingConfig(ctx context.Context) *linear.MappingConfig {
if store == nil {
return linear.DefaultMappingConfig()
}
return linear.LoadMappingConfig(&storeConfigLoader{ctx: ctx})
}
// getLinearIDMode returns the configured ID mode for Linear imports.
// Supported values: "hash" (default) or "db".
func getLinearIDMode(ctx context.Context) string {
mode, _ := getLinearConfig(ctx, "linear.id_mode")
mode = strings.ToLower(strings.TrimSpace(mode))
if mode == "" {
return "hash"
}
return mode
}
// getLinearHashLength returns the configured hash length for Linear imports.
// Values are clamped to the supported range 3-8.
func getLinearHashLength(ctx context.Context) int {
raw, _ := getLinearConfig(ctx, "linear.hash_length")
if raw == "" {
return 6
}
value, err := strconv.Atoi(strings.TrimSpace(raw))
if err != nil {
return 6
}
if value < 3 {
return 3
}
if value > 8 {
return 8
}
return value
}