beads/cmd/bd/upgrade.go
Okano, Osamu ef6c6e3e48
Follow up remaining runtime .beads fallbacks after GH#3124 (#3183)
* fix(workspace): align resolved workspace messaging and config lookup

intent(workspace): pure worktrees and external BEADS_DIR setups should work without implying a local .beads directory is required
decision(config): derive config repo roots from FindBeadsDir-backed workspace resolution instead of a local-only .beads walk
constraint(workspace-detection): keep FindBeadsDir ordering and storage behavior unchanged while making bd where the primary diagnostic hint
learned(testing): shared-server env and global .beads ignore rules can distort CGO suites, so regression coverage now normalizes those test paths

* fix(bootstrap): align no-workspace JSON wording

intent(bootstrap): machine-readable no-workspace output should match the resolved-workspace guidance used elsewhere on this branch
decision(bootstrap-json): reuse the shared workspace error helpers through a dedicated payload builder so tests can lock the JSON contract
constraint(review-loop): keep the bootstrap CLI flow unchanged outside the no-workspace JSON branch while adding a focused regression test

* fix(where): allow no-workspace diagnostics without db (beads-9f74-5l1)

intent(where): no-workspace guidance should point to a command that actually runs when workspace resolution fails
decision(startup): treat top-level where as a no-db command so it reaches its own handler before database preflight
constraint(where-tests): subprocess mode can change the exact hint text, so the regression test locks the JSON contract and stable guidance fragments instead

* fix(bootstrap): restore bd where guidance for no-workspace output (beads-9f74-3c3)

intent(bootstrap): no-workspace bootstrap guidance should match the resolved-workspace diagnostics introduced on this branch
decision(no-workspace-hints): reuse the shared hint that mentions bd where instead of the bootstrap-specific fallback text
constraint(bootstrap-tests): cover both the payload helper and subprocess CLI path so wording regressions are caught before release

* fix(workspace): remove no-workspace .beads fallbacks (beads-9f74-gr1)

intent(workspace-resolution): finish the GH#3124 follow-up for runtime paths that still fabricated local .beads state
rejected(no-workspace-fallback): inventing ./ .beads paths outside an active workspace hid shared-worktree resolution and created stray files
decision(setup-recipes): keep built-in bd setup recipes usable without a workspace but require an active workspace for custom recipe state
constraint(worktree-support): completion and backup helpers still need to resolve shared main-repo workspaces from a git worktree

* fix(config): skip no-workspace store init for store-free commands

intent(config): review-fix-loop found no-workspace config commands should reach their own graceful paths instead of failing in PersistentPreRun
decision(config-preflight): detect store-free config subcommands before DB synthesis so config.yaml, git-backed, and diagnostic flows can run without an opened store
constraint(json-contract): keep bd config validate --json machine-readable on stdout once pre-run stops short-circuiting into low-level DB errors
learned(config-preflight): the parent config command not being in noDbCommands leaked store init into show, validate, drift, apply, and yaml-only config helpers

* fix(ci): restore init prefix normalization and formatting

intent(ci): clear the current PR failures instead of leaving the branch blocked behind known red checks

decision(init-prefix): normalize dotted prefixes before persisting issue_prefix so config, metadata.json, and Dolt database naming stay aligned for Julia-style repos
constraint(fmt-check): CI runs gofmt over the whole repo, so the existing spacing drift in internal/jira/tracker_test.go had to be cleaned up on this branch to get a green run
learned(ci): the latest main CI was already red on the same formatting file and the same embedded shard, so rebasing surfaced pre-existing blockers rather than introducing a new shard-only regression
2026-04-10 21:23:14 -07:00

217 lines
5.8 KiB
Go

package main
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/beads"
"github.com/steveyegge/beads/internal/configfile"
)
var upgradeCmd = &cobra.Command{
Use: "upgrade",
GroupID: "maint",
Short: "Check and manage bd version upgrades",
Long: `Commands for checking bd version upgrades and reviewing changes.
The upgrade command helps you stay aware of bd version changes:
- bd upgrade status: Check if bd version changed since last use
- bd upgrade review: Show what's new since your last version
- bd upgrade ack: Acknowledge the current version
Version tracking is automatic - bd updates metadata.json on every run.`,
}
var upgradeStatusCmd = &cobra.Command{
Use: "status",
Short: "Check if bd version has changed",
Long: `Check if bd has been upgraded since you last used it.
This command uses the version tracking that happens automatically
at startup to detect if bd was upgraded.
Examples:
bd upgrade status
bd upgrade status --json`,
Run: func(cmd *cobra.Command, args []string) {
// Use in-memory state from trackBdVersion() which runs in PersistentPreRun
if jsonOutput {
result := map[string]interface{}{
"upgraded": versionUpgradeDetected,
"current_version": Version,
}
if versionUpgradeDetected {
result["previous_version"] = previousVersion
result["changes_available"] = len(getVersionsSince(previousVersion)) > 0
}
outputJSON(result)
return
}
// Human-readable output
if versionUpgradeDetected {
fmt.Printf("✨ bd upgraded from v%s to v%s\n", previousVersion, Version)
newVersions := getVersionsSince(previousVersion)
if len(newVersions) > 0 {
fmt.Printf(" %d version%s with changes available\n",
len(newVersions),
pluralize(len(newVersions)))
fmt.Println()
fmt.Println("Run 'bd upgrade review' to see what changed")
}
} else if previousVersion == "" {
fmt.Printf("bd version: v%s (first run or version tracking just enabled)\n", Version)
} else {
fmt.Printf("bd version: v%s (no upgrade detected)\n", Version)
}
},
}
var upgradeReviewCmd = &cobra.Command{
Use: "review",
Short: "Review changes since last bd version",
Long: `Show what's new in bd since the last version you used.
Unlike 'bd info --whats-new' which shows the last 3 versions,
this command shows ALL changes since your specific last version.
If you're upgrading from an old version, you'll see the complete
changelog of everything that changed since then.
Examples:
bd upgrade review
bd upgrade review --json`,
Run: func(cmd *cobra.Command, args []string) {
// Use in-memory state from trackBdVersion() which runs in PersistentPreRun
lastVersion := previousVersion
if lastVersion == "" {
fmt.Println("No previous version recorded")
fmt.Println("Run 'bd info --whats-new' to see recent changes")
return
}
if !versionUpgradeDetected {
fmt.Printf("You're already on v%s (no upgrade detected)\n", Version)
fmt.Println("Run 'bd info --whats-new' to see recent changes")
return
}
newVersions := getVersionsSince(lastVersion)
if jsonOutput {
outputJSON(map[string]interface{}{
"current_version": Version,
"previous_version": lastVersion,
"new_versions": newVersions,
})
return
}
// Human-readable output
fmt.Printf("\n🔄 Upgraded from v%s to v%s\n", lastVersion, Version)
fmt.Println(strings.Repeat("=", 60))
fmt.Println()
if len(newVersions) == 0 {
fmt.Printf("v%s is newer than v%s but not in changelog\n", Version, lastVersion)
fmt.Println("Run 'bd info --whats-new' to see recent documented changes")
return
}
for _, vc := range newVersions {
versionMarker := ""
if vc.Version == Version {
versionMarker = " ← current"
}
fmt.Printf("## v%s (%s)%s\n\n", vc.Version, vc.Date, versionMarker)
for _, change := range vc.Changes {
fmt.Printf(" • %s\n", change)
}
fmt.Println()
}
fmt.Println("💡 Run 'bd upgrade ack' to mark this version as seen")
fmt.Println()
},
}
var upgradeAckCmd = &cobra.Command{
Use: "ack",
Short: "Acknowledge the current bd version",
Long: `Mark the current bd version as acknowledged.
This updates metadata.json to record that you've seen the current
version. Mainly useful after reviewing upgrade changes to suppress
future upgrade notifications.
Note: Version tracking happens automatically, so you don't need to
run this command unless you want to explicitly mark acknowledgement.
Examples:
bd upgrade ack
bd upgrade ack --json`,
Run: func(cmd *cobra.Command, args []string) {
beadsDir := beads.FindBeadsDir()
if beadsDir == "" {
fmt.Println("Error: " + activeWorkspaceNotFoundMessage())
fmt.Println("Hint: " + diagHint())
return
}
cfg, err := configfile.Load(beadsDir)
if err != nil {
fmt.Printf("Error loading metadata.json: %v\n", err)
return
}
if cfg == nil {
cfg = configfile.DefaultConfig()
}
lastSeenVersion := cfg.LastBdVersion
cfg.LastBdVersion = Version
if err := cfg.Save(beadsDir); err != nil {
fmt.Printf("Error saving metadata.json: %v\n", err)
return
}
// Mark as acknowledged in current session
upgradeAcknowledged = true
versionUpgradeDetected = false
if jsonOutput {
outputJSON(map[string]interface{}{
"acknowledged": true,
"current_version": Version,
"previous_version": lastSeenVersion,
})
return
}
if lastSeenVersion == Version {
fmt.Printf("✓ Already on v%s\n", Version)
} else if lastSeenVersion == "" {
fmt.Printf("✓ Acknowledged bd v%s\n", Version)
} else {
fmt.Printf("✓ Acknowledged upgrade from v%s to v%s\n", lastSeenVersion, Version)
}
},
}
func pluralize(count int) string {
if count == 1 {
return ""
}
return "s"
}
func init() {
upgradeCmd.AddCommand(upgradeStatusCmd)
upgradeCmd.AddCommand(upgradeReviewCmd)
upgradeCmd.AddCommand(upgradeAckCmd)
rootCmd.AddCommand(upgradeCmd)
}