bd sync: 2025-11-26 20:33:12

This commit is contained in:
Steve Yegge
2025-11-26 20:33:12 -08:00
parent 6a024fb4d9
commit 8ad0144142
3 changed files with 160 additions and 1 deletions

View File

@@ -212,6 +212,8 @@ func applyFixes(result doctorResult) {
err = fix.DatabaseConfig(result.Path)
case "Deletions Manifest":
err = fix.HydrateDeletionsManifest(result.Path)
case "Untracked Files":
err = fix.UntrackedJSONL(result.Path)
default:
fmt.Printf(" ⚠ No automatic fix available for %s\n", check.Name)
fmt.Printf(" Manual fix: %s\n", check.Fix)
@@ -567,6 +569,11 @@ func runDiagnostics(path string) doctorResult {
result.Checks = append(result.Checks, deletionsCheck)
// Don't fail overall check for missing deletions manifest, just warn
// Check 19: Untracked .beads/*.jsonl files (bd-pbj)
untrackedCheck := checkUntrackedBeadsFiles(path)
result.Checks = append(result.Checks, untrackedCheck)
// Don't fail overall check for untracked files, just warn
return result
}
@@ -2123,6 +2130,77 @@ func checkDeletionsManifest(path string) doctorCheck {
}
}
// checkUntrackedBeadsFiles checks for untracked .beads/*.jsonl files that should be committed.
// This catches deletions.jsonl created by bd cleanup -f that hasn't been committed yet. (bd-pbj)
func checkUntrackedBeadsFiles(path string) doctorCheck {
beadsDir := filepath.Join(path, ".beads")
// Skip if .beads doesn't exist
if _, err := os.Stat(beadsDir); os.IsNotExist(err) {
return doctorCheck{
Name: "Untracked Files",
Status: statusOK,
Message: "N/A (no .beads directory)",
}
}
// Check if we're in a git repository
gitDir := filepath.Join(path, ".git")
if _, err := os.Stat(gitDir); os.IsNotExist(err) {
return doctorCheck{
Name: "Untracked Files",
Status: statusOK,
Message: "N/A (not a git repository)",
}
}
// Run git status --porcelain to find untracked files in .beads/
cmd := exec.Command("git", "status", "--porcelain", ".beads/")
cmd.Dir = path
output, err := cmd.Output()
if err != nil {
return doctorCheck{
Name: "Untracked Files",
Status: statusWarning,
Message: "Unable to check git status",
Detail: err.Error(),
}
}
// Parse output for untracked JSONL files (lines starting with "??")
var untrackedJSONL []string
for _, line := range strings.Split(string(output), "\n") {
line = strings.TrimSpace(line)
if line == "" {
continue
}
// Untracked files start with "?? "
if strings.HasPrefix(line, "?? ") {
file := strings.TrimPrefix(line, "?? ")
// Only care about .jsonl files
if strings.HasSuffix(file, ".jsonl") {
untrackedJSONL = append(untrackedJSONL, filepath.Base(file))
}
}
}
if len(untrackedJSONL) == 0 {
return doctorCheck{
Name: "Untracked Files",
Status: statusOK,
Message: "All .beads/*.jsonl files are tracked",
}
}
return doctorCheck{
Name: "Untracked Files",
Status: statusWarning,
Message: fmt.Sprintf("Untracked JSONL files: %s", strings.Join(untrackedJSONL, ", ")),
Detail: "These files should be committed to propagate changes to other clones",
Fix: "Run 'bd doctor --fix' to stage and commit untracked files, or manually: git add .beads/*.jsonl && git commit",
}
}
func init() {
rootCmd.AddCommand(doctorCmd)
doctorCmd.Flags().BoolVar(&perfMode, "perf", false, "Run performance diagnostics and generate CPU profile")

View File

@@ -0,0 +1,81 @@
package fix
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)
// UntrackedJSONL stages and commits untracked .beads/*.jsonl files.
// This fixes the issue where bd cleanup -f creates deletions.jsonl but
// leaves it untracked. (bd-pbj)
func UntrackedJSONL(path string) error {
if err := validateBeadsWorkspace(path); err != nil {
return err
}
beadsDir := filepath.Join(path, ".beads")
// Find untracked JSONL files
cmd := exec.Command("git", "status", "--porcelain", ".beads/")
cmd.Dir = path
output, err := cmd.Output()
if err != nil {
return fmt.Errorf("failed to check git status: %w", err)
}
// Parse output for untracked JSONL files
var untrackedFiles []string
for _, line := range strings.Split(string(output), "\n") {
line = strings.TrimSpace(line)
if line == "" {
continue
}
// Untracked files start with "?? "
if strings.HasPrefix(line, "?? ") {
file := strings.TrimPrefix(line, "?? ")
if strings.HasSuffix(file, ".jsonl") {
untrackedFiles = append(untrackedFiles, file)
}
}
}
if len(untrackedFiles) == 0 {
fmt.Println(" No untracked JSONL files found")
return nil
}
// Stage the untracked files
for _, file := range untrackedFiles {
fullPath := filepath.Join(path, file)
// Verify file exists in .beads directory (security check)
if !strings.HasPrefix(fullPath, beadsDir) {
continue
}
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
continue
}
addCmd := exec.Command("git", "add", file)
addCmd.Dir = path
if err := addCmd.Run(); err != nil {
return fmt.Errorf("failed to stage %s: %w", file, err)
}
fmt.Printf(" Staged %s\n", filepath.Base(file))
}
// Commit the staged files
commitMsg := "chore(beads): commit untracked JSONL files\n\nAuto-committed by bd doctor --fix (bd-pbj)"
commitCmd := exec.Command("git", "commit", "-m", commitMsg)
commitCmd.Dir = path
commitCmd.Stdout = os.Stdout
commitCmd.Stderr = os.Stderr
if err := commitCmd.Run(); err != nil {
return fmt.Errorf("failed to commit: %w", err)
}
return nil
}