beads/cmd/bd/version.go
matt wilkie 4fe05a3bec
Use getting started docs as bugs to fix (#3034)
* fix: narrow cross-version smoke CI triggers and warn on high skip rate

Remove push-to-main and PR triggers from cross-version smoke test
workflow — 30-45 min runtime is too costly for every push. Keep tag
pushes (releases/RCs) and manual dispatch.

Add a visible warning when >80% of tested versions are skipped, printed
to stderr and GitHub step summary. Prevents silent "all passed" when
nearly nothing actually ran.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* chore: add .buildflags for consistent ICU build configuration

Amp-Thread-ID: https://ampcode.com/threads/T-019d5c3f-42eb-7794-8d59-524bbf77bdf8
Co-authored-by: Amp <amp@ampcode.com>

* Add analysis of getting-started docs: necessity vs. fixable errors

Analyzes ~3,200 lines of getting-started documentation across 9 files.
Finds ~50% of the content compensates for tool-level UX gaps that should
be fixed rather than documented. Categorizes every section as genuinely
necessary, useful reference, workaround for fixable issue, or redundant.
Includes specific recommendations for both tool fixes and doc consolidation.

Requested by @csells.

https://claude.ai/code/session_01Fak22deVmDX3KRBKVptJBL

* Streamline getting-started docs: reduce noise, fix user-facing paths

QUICKSTART.md:
- Change all ./bd to bd (reflects installed binary, not local build)
- Replace go-build install section with brew/npm + link to INSTALLING.md
- Remove Notion sync, database maintenance, and migration sections
  (these are advanced topics, not quickstart material)
- Add "Database maintenance" link to Next Steps

README.md:
- Consolidate installation from ~30 lines to ~8 lines
- Remove CGO/build-from-source details (belong in INSTALLING.md)
- Add links to INSTALLING.md sections for all install methods

INSTALLING.md:
- Demote go install/source to "Contributors / Go developers" in matrix
- Move Build Dependencies section after platform installs, retitle to
  "Build Dependencies (Contributors Only)" with skip-if-prebuilt note
- Add cross-reference to TROUBLESHOOTING.md in troubleshooting section

Net effect: -91 lines, clearer separation between user and contributor
paths, less noise in the first-time experience.

https://claude.ai/code/session_01Fak22deVmDX3KRBKVptJBL

* fix: detect permission errors in bd init with platform-specific guidance

On Windows, Controlled Folder Access can block bd init from creating
.beads/ with no useful error. Now detects os.IsPermission and prints
specific guidance for Windows (CFA whitelist instructions) and Unix
(ls -la / chmod suggestions) instead of a generic failure message.

https://claude.ai/code/session_01Fak22deVmDX3KRBKVptJBL

* fix: add circuit breaker cleanup to bd doctor --fix

Stale circuit breaker files in /tmp/beads-circuit/ can block all bd
operations. Previously users had to manually rm these files. Now
bd doctor detects stale breaker files as a fixable check, and
bd doctor --fix clears them automatically via CleanStaleCircuitBreakerFiles.

https://claude.ai/code/session_01Fak22deVmDX3KRBKVptJBL

* feat: warn about multiple bd binaries in PATH

bd version now scans PATH for duplicate bd executables and warns when
more than one is found. This catches the common case where go install
and Homebrew binaries coexist, causing version confusion. Symlinks
are resolved to avoid false positives.

https://claude.ai/code/session_01Fak22deVmDX3KRBKVptJBL

* fix: show holding process PID in database lock errors

When the Dolt database is locked, the error message now tries to
identify the holding process by scanning /proc for bd/dolt processes.
On Linux, users see e.g. "Process 12345 (bd/dolt) may be holding
the lock." Gracefully degrades to the previous message on platforms
without /proc (macOS, Windows, FreeBSD).

https://claude.ai/code/session_01Fak22deVmDX3KRBKVptJBL

* fix: only flag circuit breaker files as stale after TTL expires

CheckCircuitBreaker() was counting any open/half-open breaker as stale
regardless of age. This could reset a legitimately active breaker
during a real outage. Now uses the same 5-minute staleness threshold
as CleanStaleCircuitBreakerFiles() — only breakers older than 5 minutes
(from TrippedAt or LastFailure) are flagged for cleanup.

https://claude.ai/code/session_01Fak22deVmDX3KRBKVptJBL

* fix: correct broken doc anchors in README installation links

The "go install" and "from source" links pointed to nonexistent anchors
in INSTALLING.md. Found during review checklist testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: suppress gosec G304 false positive in circuit breaker check

Path comes from filepath.Glob with a controlled pattern, matching
the same nolint pattern used in internal/storage/dolt/circuit.go.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Amp <amp@ampcode.com>
2026-04-05 16:09:58 -07:00

154 lines
3.5 KiB
Go

package main
import (
"context"
"fmt"
"os"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/beads"
)
var (
// Version is the current version of bd (overridden by ldflags at build time)
Version = "1.0.0"
// Build can be set via ldflags at compile time
Build = "dev"
// Commit and branch the git revision the binary was built from (optional ldflag)
Commit = ""
Branch = ""
)
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version information",
Run: func(cmd *cobra.Command, args []string) {
commit := resolveCommitHash()
branch := resolveBranch()
if jsonOutput {
result := map[string]interface{}{
"version": Version,
"build": Build,
}
if commit != "" {
result["commit"] = commit
}
if branch != "" {
result["branch"] = branch
}
outputJSON(result)
} else {
if commit != "" && branch != "" {
fmt.Printf("bd version %s (%s: %s@%s)\n", Version, Build, branch, shortCommit(commit))
} else if commit != "" {
fmt.Printf("bd version %s (%s: %s)\n", Version, Build, shortCommit(commit))
} else {
fmt.Printf("bd version %s (%s)\n", Version, Build)
}
}
// Check for multiple bd binaries in PATH
if dups := findDuplicateBinaries(); len(dups) > 1 {
fmt.Fprintf(os.Stderr, "\nWarning: multiple 'bd' binaries found in PATH:\n")
for _, p := range dups {
fmt.Fprintf(os.Stderr, " %s\n", p)
}
fmt.Fprintf(os.Stderr, "The first one is being used. Remove duplicates to avoid confusion.\n")
}
},
}
func init() {
rootCmd.AddCommand(versionCmd)
}
func resolveCommitHash() string {
if Commit != "" {
return Commit
}
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" && setting.Value != "" {
return setting.Value
}
}
}
return ""
}
func shortCommit(hash string) string {
if len(hash) > 12 {
return hash[:12]
}
return hash
}
func resolveBranch() string {
if Branch != "" {
return Branch
}
// Try to get branch from build info (build-time VCS detection)
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.branch" && setting.Value != "" {
return setting.Value
}
}
}
// Fallback: try to get branch from git at runtime
// Use symbolic-ref to work in fresh repos without commits
// Uses CWD repo context since this shows user's current branch
if rc, err := beads.GetRepoContext(); err == nil {
cmd := rc.GitCmdCWD(context.Background(), "symbolic-ref", "--short", "HEAD")
if output, err := cmd.Output(); err == nil {
if branch := strings.TrimSpace(string(output)); branch != "" && branch != "HEAD" {
return branch
}
}
}
return ""
}
// findDuplicateBinaries searches PATH for all "bd" executables.
// Returns their full paths. If len > 1, there are duplicates.
func findDuplicateBinaries() []string {
name := "bd"
if runtime.GOOS == "windows" {
name = "bd.exe"
}
seen := make(map[string]bool)
var paths []string
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
candidate := filepath.Join(dir, name)
// Resolve symlinks so we don't double-count
resolved, err := filepath.EvalSymlinks(candidate)
if err != nil {
// Try the raw path (might be a valid binary without symlinks)
resolved = candidate
}
info, err := os.Stat(candidate)
if err != nil {
continue
}
if info.IsDir() {
continue
}
if !seen[resolved] {
seen[resolved] = true
paths = append(paths, candidate)
}
}
return paths
}