feat(context): centralize RepoContext API for git operations (#1102)

Centralizes repository context resolution via RepoContext API, fixing bugs where git commands run in the wrong repo when BEADS_DIR points elsewhere or in worktree scenarios.
This commit is contained in:
Peter Chanthamynavong
2026-01-15 07:55:08 -08:00
committed by GitHub
parent 159114563b
commit 0a48519561
33 changed files with 3211 additions and 327 deletions

View File

@@ -361,6 +361,16 @@ func AllSettings() map[string]interface{} {
return v.AllSettings()
}
// ConfigFileUsed returns the path to the config file that was loaded.
// Returns empty string if no config file was found or viper is not initialized.
// This is useful for resolving relative paths from the config file's directory.
func ConfigFileUsed() string {
if v == nil {
return ""
}
return v.ConfigFileUsed()
}
// GetStringSlice retrieves a string slice configuration value
func GetStringSlice(key string) []string {
if v == nil {
@@ -452,13 +462,23 @@ func ResolveExternalProjectPath(projectName string) string {
return ""
}
// Expand relative paths from config file location or cwd
// Resolve relative paths from repo root (parent of .beads/), NOT CWD.
// This ensures paths like "../beads" in config resolve correctly
// when running from different directories or in daemon context.
if !filepath.IsAbs(path) {
cwd, err := os.Getwd()
if err != nil {
return ""
// Config is at .beads/config.yaml, so go up twice to get repo root
configFile := ConfigFileUsed()
if configFile != "" {
repoRoot := filepath.Dir(filepath.Dir(configFile)) // .beads/config.yaml -> repo/
path = filepath.Join(repoRoot, path)
} else {
// Fallback: resolve from CWD (legacy behavior)
cwd, err := os.Getwd()
if err != nil {
return ""
}
path = filepath.Join(cwd, path)
}
path = filepath.Join(cwd, path)
}
// Verify path exists