Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1305 lines
51 KiB
Go
1305 lines
51 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/beads/cmd/bd/doctor"
|
|
"github.com/steveyegge/beads/internal/configfile"
|
|
"github.com/steveyegge/beads/internal/ui"
|
|
)
|
|
|
|
// Status constants for doctor checks
|
|
const (
|
|
statusOK = "ok"
|
|
statusWarning = "warning"
|
|
statusError = "error"
|
|
)
|
|
|
|
type doctorCheck struct {
|
|
Name string `json:"name"`
|
|
Status string `json:"status"` // statusOK, statusWarning, or statusError
|
|
Message string `json:"message"`
|
|
Detail string `json:"detail,omitempty"` // Additional detail like storage type
|
|
Fix string `json:"fix,omitempty"`
|
|
Category string `json:"category,omitempty"` // category for grouping in output
|
|
}
|
|
|
|
type doctorResult struct {
|
|
Path string `json:"path"`
|
|
Checks []doctorCheck `json:"checks"`
|
|
OverallOK bool `json:"overall_ok"`
|
|
CLIVersion string `json:"cli_version"`
|
|
Timestamp string `json:"timestamp,omitempty"` // ISO8601 timestamp for historical tracking
|
|
Platform map[string]string `json:"platform,omitempty"` // platform info for debugging
|
|
SuppressedCount int `json:"suppressed_count,omitempty"` // GH#1095: number of suppressed warnings
|
|
}
|
|
|
|
var (
|
|
doctorFix bool
|
|
doctorYes bool
|
|
doctorInteractive bool // per-fix confirmation mode
|
|
doctorDryRun bool // preview fixes without applying
|
|
doctorOutput string // export diagnostics to file
|
|
doctorFixChildParent bool // opt-in fix for child→parent deps
|
|
doctorVerbose bool // show detailed output during fixes
|
|
perfMode bool
|
|
checkHealthMode bool
|
|
doctorCheckFlag string // run specific check (e.g., "pollution")
|
|
doctorClean bool // for pollution check, delete detected issues
|
|
doctorDeep bool // full graph integrity validation
|
|
doctorOrchestrator bool // running in orchestrator multi-workspace mode
|
|
orchestratorDuplicatesThreshold int // duplicate tolerance threshold for orchestrator mode
|
|
doctorServer bool // run server mode health checks
|
|
doctorMigration string // migration validation mode: "pre" or "post"
|
|
doctorAgent bool // agent-facing diagnostic mode (ZFC-compliant)
|
|
)
|
|
|
|
// ConfigKeyHintsDoctor is the config key for suppressing doctor hints
|
|
const ConfigKeyHintsDoctor = "hints.doctor"
|
|
|
|
var doctorCmd = &cobra.Command{
|
|
Use: "doctor [path]",
|
|
GroupID: "maint",
|
|
Short: "Check and fix beads installation health (start here)",
|
|
Long: `Sanity check the beads installation for the current directory or specified path.
|
|
|
|
This command checks:
|
|
- If .beads/ directory exists
|
|
- Database version and migration status
|
|
- Schema compatibility (all required tables and columns present)
|
|
- Whether using hash-based vs sequential IDs
|
|
- If CLI version is current (checks GitHub releases)
|
|
- If Claude plugin is current (when running in Claude Code)
|
|
- File permissions
|
|
- Circular dependencies
|
|
- Git hooks (pre-commit, post-merge, pre-push)
|
|
- .beads/.gitignore up to date
|
|
- Metadata.json version tracking (LastBdVersion field)
|
|
|
|
Performance Mode (--perf):
|
|
Run performance diagnostics on your database:
|
|
- Times key operations (bd ready, bd list, bd show, etc.)
|
|
- Collects system info (OS, arch, SQLite version, database stats)
|
|
- Generates CPU profile for analysis
|
|
- Outputs shareable report for bug reports
|
|
|
|
Export Mode (--output):
|
|
Save diagnostics to a JSON file for historical analysis and bug reporting.
|
|
Includes timestamp and platform info for tracking intermittent issues.
|
|
|
|
Specific Check Mode (--check):
|
|
Run a specific check in detail. Available checks:
|
|
- artifacts: Detect and optionally clean beads classic artifacts
|
|
(stale JSONL, SQLite files, cruft .beads dirs). Use with --clean.
|
|
- conventions: Check for convention drift (lint warnings, stale
|
|
issues, orphaned issues). Advisory only - warns, never blocks.
|
|
- pollution: Detect and optionally clean test issues from database
|
|
- validate: Run focused data-integrity checks (duplicates, orphaned
|
|
deps, test pollution, git conflicts). Use with --fix to auto-repair.
|
|
|
|
Deep Validation Mode (--deep):
|
|
Validate full graph integrity. May be slow on large databases.
|
|
Additional checks:
|
|
- Parent consistency: All parent-child deps point to existing issues
|
|
- Dependency integrity: All deps reference valid issues
|
|
- Epic completeness: Find epics ready to close (all children closed)
|
|
- Agent bead integrity: Agent beads have valid state values
|
|
- Mail thread integrity: Thread IDs reference existing issues
|
|
- Molecule integrity: Molecules have valid parent-child structures
|
|
|
|
Server Mode (--server):
|
|
Run health checks for Dolt server mode connections (bd-dolt.2.3):
|
|
- Server reachable: Can connect to configured host:port?
|
|
- Dolt version: Is it a Dolt server (not vanilla MySQL)?
|
|
- Database exists: Does the 'beads' database exist?
|
|
- Schema compatible: Can query beads tables?
|
|
- Connection pool: Pool health metrics
|
|
|
|
Migration Validation Mode (--migration):
|
|
Run Dolt migration validation checks with machine-parseable output.
|
|
Use --migration=pre before migration to verify readiness:
|
|
- JSONL file exists and is valid (parseable, no corruption)
|
|
- All JSONL issues are present in SQLite (or explains discrepancies)
|
|
- No blocking issues prevent migration
|
|
Use --migration=post after migration to verify completion:
|
|
- Dolt database exists and is healthy
|
|
- All issues from JSONL are present in Dolt
|
|
- No data was lost during migration
|
|
- Dolt database has no locks or uncommitted changes
|
|
Combine with --json for machine-parseable output for automation.
|
|
|
|
Agent Mode (--agent):
|
|
Output diagnostics designed for AI agent consumption. Instead of terse
|
|
pass/fail messages, each issue includes:
|
|
- Observed state: what the system actually looks like
|
|
- Expected state: what it should look like
|
|
- Explanation: full prose context about the issue and why it matters
|
|
- Commands: exact remediation commands to run
|
|
- Source files: where in the codebase to investigate further
|
|
- Severity: blocking (prevents operation), degraded (partial function),
|
|
or advisory (informational only)
|
|
ZFC-compliant: Go observes and reports, the agent decides and acts.
|
|
Combine with --json for structured agent-facing output.
|
|
|
|
Suppressing Warnings:
|
|
Suppress specific warnings by setting doctor.suppress.<check-slug> config:
|
|
bd config set doctor.suppress.pending-migrations true
|
|
bd config set doctor.suppress.git-hooks true
|
|
Check names are converted to slugs: "Git Hooks" → "git-hooks".
|
|
Only warnings are suppressed; errors and passing checks always show.
|
|
To unsuppress: bd config unset doctor.suppress.<slug>
|
|
|
|
Examples:
|
|
bd doctor # Check current directory
|
|
bd doctor /path/to/repo # Check specific repository
|
|
bd doctor --json # Machine-readable output
|
|
bd doctor --agent # Agent-facing diagnostic output
|
|
bd doctor --agent --json # Structured agent diagnostics (JSON)
|
|
bd doctor --fix # Automatically fix issues (with confirmation)
|
|
bd doctor --fix --yes # Automatically fix issues (no confirmation)
|
|
bd doctor --fix -i # Confirm each fix individually
|
|
bd doctor --fix --fix-child-parent # Also fix child→parent deps (opt-in)
|
|
bd doctor --fix --force # Force repair even when database can't be opened
|
|
bd doctor --fix --source=jsonl # Rebuild database from a JSONL export
|
|
bd doctor --dry-run # Preview what --fix would do without making changes
|
|
bd doctor --perf # Performance diagnostics
|
|
bd doctor --output diagnostics.json # Export diagnostics to file
|
|
bd doctor --check=artifacts # Show classic artifacts (JSONL, SQLite, cruft dirs)
|
|
bd doctor --check=artifacts --clean # Delete safe-to-delete artifacts (with confirmation)
|
|
bd doctor --check=conventions # Convention drift check (lint, stale, orphans)
|
|
bd doctor --check=pollution # Show potential test issues
|
|
bd doctor --check=pollution --clean # Delete test issues (with confirmation)
|
|
bd doctor --check=validate # Data-integrity checks only
|
|
bd doctor --check=validate --fix # Auto-fix data-integrity issues
|
|
bd doctor --deep # Full graph integrity validation
|
|
bd doctor --server # Dolt server mode health checks
|
|
bd doctor --migration=pre # Validate readiness for Dolt migration
|
|
bd doctor --migration=post # Validate Dolt migration completed
|
|
bd doctor --migration=pre --json # Machine-parseable migration validation`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if !usesSQLServer() {
|
|
fmt.Fprintln(os.Stderr, "Note: 'bd doctor' is not yet supported in embedded mode.")
|
|
fmt.Fprintln(os.Stderr, "")
|
|
fmt.Fprintln(os.Stderr, "For embedded mode troubleshooting:")
|
|
fmt.Fprintln(os.Stderr, " • Verify database exists: ls -la .beads/embeddeddolt/")
|
|
fmt.Fprintln(os.Stderr, " • Check bd version: bd version")
|
|
fmt.Fprintln(os.Stderr, " • Reinitialize if needed: bd init --force")
|
|
fmt.Fprintln(os.Stderr, " • Switch to server mode: bd init --server")
|
|
os.Exit(0)
|
|
}
|
|
if usesProxiedServer() {
|
|
fmt.Fprintln(os.Stderr, "Note: 'bd doctor' is not yet supported in proxied-server mode.")
|
|
os.Exit(0)
|
|
}
|
|
// Use global jsonOutput set by PersistentPreRun
|
|
|
|
// Determine path to check
|
|
// Precedence: explicit arg > BEADS_DIR (parent) > CWD
|
|
var checkPath string
|
|
if len(args) > 0 {
|
|
checkPath = args[0]
|
|
} else if beadsDir := os.Getenv("BEADS_DIR"); beadsDir != "" {
|
|
// BEADS_DIR points to .beads directory, doctor needs parent
|
|
checkPath = filepath.Dir(beadsDir)
|
|
} else {
|
|
checkPath = "."
|
|
}
|
|
|
|
// Convert to absolute path
|
|
absPath, err := filepath.Abs(checkPath)
|
|
if err != nil {
|
|
FatalError("failed to resolve path: %v", err)
|
|
}
|
|
|
|
// Guardrail: never run mutating bd doctor fix from orchestrator workspace root.
|
|
// Workspace roots have additional invariants beyond single-project repos;
|
|
// repairs should go through the orchestrator's own doctor command.
|
|
if doctorFix && isOrchestratorRoot(absPath) {
|
|
FatalErrorWithHint(
|
|
"refusing to run 'bd doctor --fix' at orchestrator workspace root",
|
|
"Run the orchestrator's doctor command from workspace root, or run 'bd doctor --fix' inside a specific project clone",
|
|
)
|
|
}
|
|
|
|
// Run performance diagnostics if --perf flag is set
|
|
if perfMode {
|
|
if err := doctor.RunPerformanceDiagnostics(absPath); err != nil {
|
|
FatalError("performance diagnostics: %v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
// Run quick health check if --check-health flag is set
|
|
if checkHealthMode {
|
|
runCheckHealth(absPath)
|
|
return
|
|
}
|
|
|
|
// Run specific check if --check flag is set
|
|
if doctorCheckFlag != "" {
|
|
switch doctorCheckFlag {
|
|
case "pollution":
|
|
runPollutionCheck(absPath, doctorClean, doctorYes)
|
|
return
|
|
case "validate":
|
|
runValidateCheck(absPath)
|
|
return
|
|
case "artifacts":
|
|
runArtifactsCheck(absPath, doctorClean, doctorYes)
|
|
return
|
|
case "conventions":
|
|
runConventionsCheck(absPath)
|
|
return
|
|
default:
|
|
FatalErrorWithHint(fmt.Sprintf("unknown check %q", doctorCheckFlag), "Available checks: artifacts, conventions, pollution, validate")
|
|
}
|
|
}
|
|
|
|
// Run deep validation if --deep flag is set
|
|
if doctorDeep {
|
|
runDeepValidation(absPath)
|
|
return
|
|
}
|
|
|
|
// Run server mode health checks if --server flag is set
|
|
if doctorServer {
|
|
runServerHealth(absPath)
|
|
return
|
|
}
|
|
|
|
// Run migration validation if --migration flag is set
|
|
if doctorMigration != "" {
|
|
runMigrationValidation(absPath, doctorMigration)
|
|
return
|
|
}
|
|
|
|
// Run diagnostics
|
|
result := runDiagnostics(absPath)
|
|
|
|
// Preview fixes (dry-run) or apply fixes if requested
|
|
if doctorDryRun {
|
|
previewFixes(result)
|
|
} else if doctorFix {
|
|
applyFixes(result)
|
|
fmt.Println("\nVerifying fixes...")
|
|
result = runDiagnostics(absPath)
|
|
}
|
|
|
|
// Add timestamp and platform info for export
|
|
if doctorOutput != "" || jsonOutput {
|
|
result.Timestamp = time.Now().UTC().Format(time.RFC3339)
|
|
result.Platform = doctor.CollectPlatformInfo(absPath)
|
|
}
|
|
|
|
// Export to file if --output specified
|
|
if doctorOutput != "" {
|
|
if err := exportDiagnostics(result, doctorOutput); err != nil {
|
|
FatalError("failed to export diagnostics: %v", err)
|
|
}
|
|
fmt.Printf("✓ Diagnostics exported to %s\n", doctorOutput)
|
|
}
|
|
|
|
// Output results
|
|
if doctorAgent {
|
|
agentResult := buildAgentResult(result)
|
|
if jsonOutput {
|
|
outputJSON(agentResult)
|
|
} else {
|
|
printAgentDiagnostics(agentResult)
|
|
}
|
|
} else if jsonOutput {
|
|
outputJSON(result)
|
|
} else if doctorOutput == "" {
|
|
// Only print to console if not exporting (to avoid duplicate output)
|
|
printDiagnostics(result)
|
|
}
|
|
|
|
// Exit with error if any checks failed
|
|
if !result.OverallOK {
|
|
os.Exit(1)
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
doctorCmd.Flags().BoolVar(&doctorFix, "fix", false, "Automatically fix issues where possible")
|
|
doctorCmd.Flags().BoolVarP(&doctorYes, "yes", "y", false, "Skip confirmation prompt (for non-interactive use)")
|
|
doctorCmd.Flags().BoolVarP(&doctorInteractive, "interactive", "i", false, "Confirm each fix individually")
|
|
doctorCmd.Flags().BoolVar(&doctorDryRun, "dry-run", false, "Preview fixes without making changes")
|
|
doctorCmd.Flags().BoolVar(&doctorFixChildParent, "fix-child-parent", false, "Remove child→parent dependencies (opt-in)")
|
|
doctorCmd.Flags().BoolVarP(&doctorVerbose, "verbose", "v", false, "Show all checks (default shows only warnings/errors)")
|
|
doctorCmd.Flags().BoolVar(&doctorOrchestrator, "orchestrator", false, "Running in orchestrator multi-workspace mode (routes.jsonl is expected, higher duplicate tolerance)")
|
|
doctorCmd.Flags().IntVar(&orchestratorDuplicatesThreshold, "orchestrator-duplicates-threshold", 1000, "Duplicate tolerance threshold for orchestrator mode (wisps are ephemeral)")
|
|
doctorCmd.Flags().BoolVar(&doctorServer, "server", false, "Run Dolt server mode health checks (connectivity, version, schema)")
|
|
doctorCmd.Flags().StringVar(&doctorMigration, "migration", "", "Run Dolt migration validation: 'pre' (before migration) or 'post' (after migration)")
|
|
doctorCmd.Flags().BoolVar(&doctorAgent, "agent", false, "Agent-facing diagnostic mode: rich context for AI agents (ZFC-compliant)")
|
|
}
|
|
|
|
func shouldSkipDoctorNetworkChecks() bool {
|
|
return jsonOutput || !ui.IsTerminal()
|
|
}
|
|
|
|
func runDiagnostics(path string) doctorResult {
|
|
result := doctorResult{
|
|
Path: path,
|
|
CLIVersion: Version,
|
|
OverallOK: true,
|
|
}
|
|
|
|
// Auto-detect orchestrator mode: routes.jsonl is only created by orchestrator workspaces
|
|
if !doctorOrchestrator {
|
|
resolvedBeadsDir := doctor.ResolveBeadsDirForRepo(path)
|
|
routesFile := filepath.Join(resolvedBeadsDir, "routes.jsonl")
|
|
if _, err := os.Stat(routesFile); err == nil {
|
|
doctorOrchestrator = true
|
|
}
|
|
}
|
|
|
|
// Check 1: Installation (.beads/ directory)
|
|
installCheck := convertWithCategory(doctor.CheckInstallation(path), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, installCheck)
|
|
if installCheck.Status != statusOK {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check Git Hooks early (even if .beads/ doesn't exist yet)
|
|
hooksCheck := convertWithCategory(doctor.CheckGitHooks(Version), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, hooksCheck)
|
|
// Don't fail overall check for missing hooks, just warn
|
|
|
|
// Check for stale .legacy hook sidecars calling removed "bd hook" command (GH#2398)
|
|
legacyCheck := convertWithCategory(doctor.CheckStaleLegacyHooks(), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, legacyCheck)
|
|
|
|
// Check git hooks Dolt compatibility (hooks without Dolt check cause errors)
|
|
doltHooksCheck := convertWithCategory(doctor.CheckGitHooksDoltCompatibility(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, doltHooksCheck)
|
|
if doltHooksCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// If no .beads/, skip remaining checks
|
|
if installCheck.Status != statusOK {
|
|
return result
|
|
}
|
|
|
|
// Check 1a: Fresh clone detection
|
|
// Must come early - if this is a fresh clone, other checks may be misleading
|
|
freshCloneCheck := convertWithCategory(doctor.CheckFreshClone(path), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, freshCloneCheck)
|
|
if freshCloneCheck.Status == statusWarning || freshCloneCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 1b: Metadata config file (GH#2478)
|
|
// Must come before database checks since they depend on metadata.json.
|
|
beadsDir := doctor.ResolveBeadsDirForRepo(path)
|
|
configPath := configfile.ConfigPath(beadsDir)
|
|
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
|
metaCheck := doctorCheck{
|
|
Name: "Metadata Config",
|
|
Status: statusError,
|
|
Message: "metadata.json is missing",
|
|
Fix: "Run 'bd doctor --fix' to regenerate with defaults, or 'bd init --force'",
|
|
Category: doctor.CategoryCore,
|
|
}
|
|
result.Checks = append(result.Checks, metaCheck)
|
|
result.OverallOK = false
|
|
} else {
|
|
result.Checks = append(result.Checks, doctorCheck{
|
|
Name: "Metadata Config",
|
|
Status: statusOK,
|
|
Message: "metadata.json present",
|
|
Category: doctor.CategoryCore,
|
|
})
|
|
}
|
|
|
|
// Check 1c: Managed-city handoff port conflict (GH#3926)
|
|
managedHandoffCheck := convertDoctorCheck(doctor.CheckManagedHandoffPort(path))
|
|
result.Checks = append(result.Checks, managedHandoffCheck)
|
|
if managedHandoffCheck.Status == statusWarning || managedHandoffCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// bd-jgxi: Auto-migrate database version before checking it.
|
|
// Since doctor skips PersistentPreRun DB init (it's in noDbCommands),
|
|
// trackBdVersion() and autoMigrateOnVersionBump() haven't run yet.
|
|
//
|
|
// Scope version tracking to the doctor target. Without this, `bd doctor <path>`
|
|
// can accidentally touch the caller's current repo .beads state.
|
|
origBeadsDir, hadBeadsDir := os.LookupEnv("BEADS_DIR")
|
|
_ = os.Setenv("BEADS_DIR", beadsDir)
|
|
trackBdVersion()
|
|
if hadBeadsDir {
|
|
_ = os.Setenv("BEADS_DIR", origBeadsDir)
|
|
} else {
|
|
_ = os.Unsetenv("BEADS_DIR")
|
|
}
|
|
|
|
autoMigrateOnVersionBump(beadsDir)
|
|
|
|
// Check 1b: Dolt format compatibility (GH#2137)
|
|
// Must run before opening the database — old noms formats cause server panics.
|
|
doltFormatCheck := convertWithCategory(doctor.CheckDoltFormat(path), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, doltFormatCheck)
|
|
if doltFormatCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// GH#2636: Open a single shared store for all database checks.
|
|
// This prevents the infinite Dolt server restart loop that occurred when each
|
|
// check opened and closed its own store (each close kills the server, each
|
|
// open restarts it). The shared store stays alive for the entire doctor run.
|
|
sharedStore := doctor.NewSharedStore(path)
|
|
defer sharedStore.Close()
|
|
|
|
// Check 2: Database version
|
|
dbCheck := convertWithCategory(doctor.CheckDatabaseVersionWithStore(sharedStore, Version), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, dbCheck)
|
|
if dbCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 2a: Schema compatibility
|
|
schemaCheck := convertWithCategory(doctor.CheckSchemaCompatibilityWithStore(sharedStore), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, schemaCheck)
|
|
if schemaCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 2b: Repo fingerprint (detects wrong database or URL change)
|
|
fingerprintCheck := convertWithCategory(doctor.CheckRepoFingerprintWithStore(sharedStore, path), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, fingerprintCheck)
|
|
if fingerprintCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 2c: Database integrity
|
|
integrityCheck := convertWithCategory(doctor.CheckDatabaseIntegrityWithStore(sharedStore), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, integrityCheck)
|
|
if integrityCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 3: ID format (hash vs sequential)
|
|
idCheck := convertWithCategory(doctor.CheckIDFormatWithStore(sharedStore), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, idCheck)
|
|
if idCheck.Status == statusWarning {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Network-based update checks are skipped in machine-readable and other
|
|
// non-interactive contexts so doctor remains deterministic under wrappers.
|
|
versionCheckFn := doctor.CheckCLIVersion
|
|
pluginCheckFn := doctor.CheckClaudePlugin
|
|
if shouldSkipDoctorNetworkChecks() {
|
|
versionCheckFn = doctor.CheckCLIVersionLocalOnly
|
|
pluginCheckFn = doctor.CheckClaudePluginLocalOnly
|
|
}
|
|
|
|
// Check 4: CLI version
|
|
versionCheck := convertWithCategory(versionCheckFn(Version), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, versionCheck)
|
|
// Don't fail overall check for outdated CLI, just warn
|
|
|
|
// Check 4.5: Claude plugin version (if running in Claude Code)
|
|
pluginCheck := convertWithCategory(pluginCheckFn(), doctor.CategoryIntegration)
|
|
result.Checks = append(result.Checks, pluginCheck)
|
|
// Don't fail overall check for outdated plugin, just warn
|
|
|
|
// Check 7: Database/JSONL configuration mismatch
|
|
configCheck := convertWithCategory(doctor.CheckDatabaseConfig(path), doctor.CategoryData)
|
|
result.Checks = append(result.Checks, configCheck)
|
|
if configCheck.Status == statusWarning || configCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 7a: Configuration value validation
|
|
configValuesCheck := convertWithCategory(doctor.CheckConfigValuesWithStore(path, sharedStore), doctor.CategoryData)
|
|
result.Checks = append(result.Checks, configValuesCheck)
|
|
// Don't fail overall check for config value warnings, just warn
|
|
|
|
// Check 7a1: Project identity (GH#2372 backfill)
|
|
projectIDCheck := convertWithCategory(doctor.CheckProjectIdentityWithStore(sharedStore, path), doctor.CategoryData)
|
|
result.Checks = append(result.Checks, projectIDCheck)
|
|
if projectIDCheck.Status == statusWarning || projectIDCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 7b: Multi-repo custom types discovery (bd-9ji4z)
|
|
multiRepoTypesCheck := convertWithCategory(doctor.CheckMultiRepoTypes(path), doctor.CategoryData)
|
|
result.Checks = append(result.Checks, multiRepoTypesCheck)
|
|
// Don't fail overall check for multi-repo types, just informational
|
|
|
|
// Check 7c: Role configuration (beads.role)
|
|
roleCheck := convertDoctorCheck(doctor.CheckBeadsRoleWithStore(path, sharedStore))
|
|
result.Checks = append(result.Checks, roleCheck)
|
|
// Don't fail overall check for role config, just warn - URL heuristic fallback still works
|
|
|
|
// Check 7e: Stale lock files (bootstrap, sync, startup)
|
|
staleLockCheck := convertDoctorCheck(doctor.CheckStaleLockFiles(path))
|
|
result.Checks = append(result.Checks, staleLockCheck)
|
|
if staleLockCheck.Status == statusWarning || staleLockCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 7e1: Corrupt-manifest state (GH#3290). Detection only; the
|
|
// destructive backup+reinit repair runs solely via doctor --fix (bd-6dnrw.6).
|
|
corruptManifestCheck := convertDoctorCheck(doctor.CheckCorruptManifest(path))
|
|
result.Checks = append(result.Checks, corruptManifestCheck)
|
|
if corruptManifestCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 7e2: Stale circuit breaker files
|
|
circuitCheck := convertDoctorCheck(doctor.CheckCircuitBreaker())
|
|
result.Checks = append(result.Checks, circuitCheck)
|
|
if circuitCheck.Status == statusWarning || circuitCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 7f: Migration content skew vs the cached remote ref (#4259). Advisory.
|
|
skewCheck := convertWithCategory(doctor.CheckMigrationContentSkew(sharedStore), doctor.CategoryData)
|
|
result.Checks = append(result.Checks, skewCheck)
|
|
|
|
// Dolt health checks (connection, schema, issue count, status).
|
|
for _, dc := range doctor.RunDoltHealthChecks(path) {
|
|
result.Checks = append(result.Checks, convertDoctorCheck(dc))
|
|
}
|
|
|
|
legacyRemoteCheck := convertWithCategory(doctor.CheckLegacyCLIRemotes(path), doctor.CategoryFederation)
|
|
result.Checks = append(result.Checks, legacyRemoteCheck)
|
|
|
|
// Federation health checks (bd-wkumz.6)
|
|
// Check 8d: Federation remotesapi port accessibility
|
|
remotesAPICheck := convertWithCategory(doctor.CheckFederationRemotesAPI(path), doctor.CategoryFederation)
|
|
result.Checks = append(result.Checks, remotesAPICheck)
|
|
// Don't fail overall for federation issues - they're only relevant for Dolt users
|
|
|
|
// Check 8e: Federation peer connectivity
|
|
peerConnCheck := convertWithCategory(doctor.CheckFederationPeerConnectivity(path), doctor.CategoryFederation)
|
|
result.Checks = append(result.Checks, peerConnCheck)
|
|
|
|
// Check 8f: Federation sync staleness
|
|
syncStalenessCheck := convertWithCategory(doctor.CheckFederationSyncStaleness(path), doctor.CategoryFederation)
|
|
result.Checks = append(result.Checks, syncStalenessCheck)
|
|
|
|
// Check 8g: Federation conflict detection
|
|
fedConflictsCheck := convertWithCategory(doctor.CheckFederationConflicts(path), doctor.CategoryFederation)
|
|
result.Checks = append(result.Checks, fedConflictsCheck)
|
|
if fedConflictsCheck.Status == statusError {
|
|
result.OverallOK = false // Unresolved conflicts are a real problem
|
|
}
|
|
|
|
// Check 8h: Dolt server mode configuration check
|
|
doltModeCheck := convertWithCategory(doctor.CheckDoltServerModeMismatch(path), doctor.CategoryFederation)
|
|
result.Checks = append(result.Checks, doltModeCheck)
|
|
|
|
// Check 9: Permissions
|
|
permCheck := convertWithCategory(doctor.CheckPermissionsWithStore(path, sharedStore), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, permCheck)
|
|
if permCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 10: Dependency cycles
|
|
cycleCheck := convertWithCategory(doctor.CheckDependencyCyclesWithStore(sharedStore), doctor.CategoryMetadata)
|
|
result.Checks = append(result.Checks, cycleCheck)
|
|
if cycleCheck.Status == statusError || cycleCheck.Status == statusWarning {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 10b: Rekey-backfill leftovers — randomly-keyed or targetless
|
|
// dependency rows that survive the #4259 migration backfill (bd-6dnrw.17).
|
|
depKeyCheck := convertWithCategory(doctor.CheckDependencyKeysWithStore(sharedStore), doctor.CategoryMetadata)
|
|
result.Checks = append(result.Checks, depKeyCheck)
|
|
if depKeyCheck.Status == statusError || depKeyCheck.Status == statusWarning {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 10c: is_blocked consistency — derived flags a skipped post-pull
|
|
// recompute can leave stale (bd-6dnrw.37). `bd ready` trusts is_blocked, so
|
|
// staleness silently hides ready work; the full recompute repairs it.
|
|
// Warn-only (does not fail OverallOK): this is a new check shipping in a
|
|
// patch, and is_blocked is self-healing via 'bd doctor --fix' / the next
|
|
// pull's recompute — surface it as actionable without turning doctor red
|
|
// across the fleet if an unforeseen dependency shape trips the predicate.
|
|
blockedConsistencyCheck := convertWithCategory(doctor.CheckBlockedConsistencyWithStore(sharedStore), doctor.CategoryData)
|
|
result.Checks = append(result.Checks, blockedConsistencyCheck)
|
|
|
|
// Check 11: Claude integration
|
|
claudeCheck := convertWithCategory(doctor.CheckClaude(path), doctor.CategoryIntegration)
|
|
result.Checks = append(result.Checks, claudeCheck)
|
|
// Don't fail overall check for missing Claude integration, just warn
|
|
|
|
// Check 11a: Claude settings file health (malformed JSON detection)
|
|
claudeSettingsCheck := convertWithCategory(doctor.CheckClaudeSettingsHealth(path), doctor.CategoryIntegration)
|
|
result.Checks = append(result.Checks, claudeSettingsCheck)
|
|
if claudeSettingsCheck.Status == statusError {
|
|
result.OverallOK = false // Malformed settings is a real problem
|
|
}
|
|
|
|
// Check 11b: Claude hook completeness (both SessionStart and PreCompact)
|
|
claudeHookCheck := convertWithCategory(doctor.CheckClaudeHookCompleteness(path), doctor.CategoryIntegration)
|
|
result.Checks = append(result.Checks, claudeHookCheck)
|
|
// Don't fail overall check for incomplete hooks, just warn
|
|
|
|
// Check 11c: bd prime output verification
|
|
bdPrimeOutputCheck := convertWithCategory(doctor.VerifyPrimeOutput(path), doctor.CategoryIntegration)
|
|
result.Checks = append(result.Checks, bdPrimeOutputCheck)
|
|
// Don't fail overall check for prime output issues, just warn
|
|
|
|
// Check 11d: bd in PATH (needed for Claude hooks and other integrations)
|
|
bdPathCheck := convertWithCategory(doctor.CheckBdInPath(), doctor.CategoryIntegration)
|
|
result.Checks = append(result.Checks, bdPathCheck)
|
|
// Don't fail overall check for missing bd in PATH, just warn
|
|
|
|
// Check 11e: Documentation bd prime references match installed version
|
|
bdPrimeDocsCheck := convertWithCategory(doctor.CheckDocumentationBdPrimeReference(path), doctor.CategoryIntegration)
|
|
result.Checks = append(result.Checks, bdPrimeDocsCheck)
|
|
// Don't fail overall check for doc mismatch, just warn
|
|
|
|
// Check 12: Agent documentation presence
|
|
agentDocsCheck := convertWithCategory(doctor.CheckAgentDocumentation(path), doctor.CategoryIntegration)
|
|
result.Checks = append(result.Checks, agentDocsCheck)
|
|
// Don't fail overall check for missing docs, just warn
|
|
|
|
// Check 12a: AGENTS.md / CLAUDE.md user-authored divergence
|
|
agentDocDivergenceCheck := convertWithCategory(doctor.CheckAgentDocDivergence(path), doctor.CategoryIntegration)
|
|
result.Checks = append(result.Checks, agentDocDivergenceCheck)
|
|
// Don't fail overall check for divergence, just warn
|
|
|
|
// Check 13: Legacy beads slash commands in documentation
|
|
legacyDocsCheck := convertWithCategory(doctor.CheckLegacyBeadsSlashCommands(path), doctor.CategoryMetadata)
|
|
result.Checks = append(result.Checks, legacyDocsCheck)
|
|
// Don't fail overall check for legacy docs, just warn
|
|
|
|
// Check 13a: MCP tool references in documentation
|
|
mcpToolRefsCheck := convertWithCategory(doctor.CheckLegacyMCPToolReferences(path), doctor.CategoryIntegration)
|
|
result.Checks = append(result.Checks, mcpToolRefsCheck)
|
|
// Don't fail overall check for MCP tool refs, just warn
|
|
|
|
// Check 14: Gitignore up to date
|
|
gitignoreCheck := convertWithCategory(doctor.CheckGitignore(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, gitignoreCheck)
|
|
// Don't fail overall check for gitignore, just warn
|
|
|
|
// Check 14a: Project-root Dolt exclusion patterns (GH#2034). In stealth mode these live in
|
|
// .git/info/exclude, so check that location instead to avoid recreating .gitignore.
|
|
if isStealthRepo(path) {
|
|
result.Checks = append(result.Checks, convertWithCategory(checkProjectExcludeStealth(path), doctor.CategoryGit))
|
|
} else {
|
|
projectGitignoreCheck := convertWithCategory(doctor.CheckProjectGitignore(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, projectGitignoreCheck)
|
|
}
|
|
// Don't fail overall check for project gitignore, just warn
|
|
|
|
// Check 14b: redirect file tracking (worktree redirect files shouldn't be committed)
|
|
redirectTrackingCheck := convertWithCategory(doctor.CheckRedirectNotTracked(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, redirectTrackingCheck)
|
|
// Don't fail overall check for redirect tracking, just warn
|
|
|
|
// Check 14c: redirect target validity (target exists and has valid db)
|
|
redirectTargetCheck := convertWithCategory(doctor.CheckRedirectTargetValid(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, redirectTargetCheck)
|
|
// Don't fail overall check for redirect target, just warn
|
|
|
|
// Check 14d: redirect target sync worktree (target has beads-sync if needed)
|
|
redirectTargetSyncCheck := convertWithCategory(doctor.CheckRedirectTargetSyncWorktree(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, redirectTargetSyncCheck)
|
|
// Don't fail overall check for redirect target sync, just warn
|
|
|
|
// Check 14e: vestigial sync worktrees (unused worktrees in redirected repos)
|
|
vestigialWorktreesCheck := convertWithCategory(doctor.CheckNoVestigialSyncWorktrees(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, vestigialWorktreesCheck)
|
|
// Don't fail overall check for vestigial worktrees, just warn
|
|
|
|
// Check 14g: last-touched file tracking (runtime state shouldn't be committed)
|
|
lastTouchedTrackingCheck := convertWithCategory(doctor.CheckLastTouchedNotTracked(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, lastTouchedTrackingCheck)
|
|
// Don't fail overall check for last-touched tracking, just warn
|
|
|
|
// Check 14h: tracked runtime/sensitive files (GH#2535)
|
|
trackedRuntimeCheck := convertDoctorCheck(doctor.CheckTrackedRuntimeFiles(path))
|
|
result.Checks = append(result.Checks, trackedRuntimeCheck)
|
|
if trackedRuntimeCheck.Status == statusError {
|
|
result.OverallOK = false // Sensitive files in git is a real problem
|
|
}
|
|
|
|
// Check 15a: Git working tree cleanliness (AGENTS.md hygiene)
|
|
gitWorkingTreeCheck := convertWithCategory(doctor.CheckGitWorkingTree(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, gitWorkingTreeCheck)
|
|
// Don't fail overall check for dirty working tree, just warn
|
|
|
|
// Check 15b: Git upstream sync (ahead/behind/diverged)
|
|
gitUpstreamCheck := convertWithCategory(doctor.CheckGitUpstream(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, gitUpstreamCheck)
|
|
// Don't fail overall check for upstream drift, just warn
|
|
|
|
// Check 16: Metadata.json version tracking
|
|
metadataCheck := convertWithCategory(doctor.CheckMetadataVersionTracking(path, Version), doctor.CategoryMetadata)
|
|
result.Checks = append(result.Checks, metadataCheck)
|
|
// Don't fail overall check for metadata, just warn
|
|
|
|
// Check 17b: Orphaned issues - referenced in commits but still open
|
|
orphanedIssuesCheck := convertWithCategory(doctor.CheckOrphanedIssues(path), doctor.CategoryGit)
|
|
result.Checks = append(result.Checks, orphanedIssuesCheck)
|
|
// Don't fail overall check for orphaned issues, just warn
|
|
|
|
// Check 18: Deletions manifest (legacy)
|
|
deletionsCheck := convertWithCategory(doctor.CheckDeletionsManifest(path), doctor.CategoryMetadata)
|
|
result.Checks = append(result.Checks, deletionsCheck)
|
|
// Don't fail overall check for missing deletions manifest, just warn
|
|
|
|
// Check 20: Untracked .beads/*.jsonl files
|
|
untrackedCheck := convertWithCategory(doctor.CheckUntrackedBeadsFiles(path), doctor.CategoryData)
|
|
result.Checks = append(result.Checks, untrackedCheck)
|
|
// Don't fail overall check for untracked files, just warn
|
|
|
|
// Check 21: Orphaned dependencies (from bd repair-deps, bd validate)
|
|
orphanedDepsCheck := convertDoctorCheck(doctor.CheckOrphanedDependencies(path))
|
|
result.Checks = append(result.Checks, orphanedDepsCheck)
|
|
// Don't fail overall check for orphaned deps, just warn
|
|
|
|
// Check 22a: Child→parent dependencies (anti-pattern)
|
|
childParentDepsCheck := convertDoctorCheck(doctor.CheckChildParentDependencies(path))
|
|
result.Checks = append(result.Checks, childParentDepsCheck)
|
|
// Don't fail overall check for child→parent deps, just warn
|
|
|
|
// Check 23: Duplicate issues (from bd validate)
|
|
duplicatesCheck := convertDoctorCheck(doctor.CheckDuplicateIssues(path, doctorOrchestrator, orchestratorDuplicatesThreshold))
|
|
result.Checks = append(result.Checks, duplicatesCheck)
|
|
// Don't fail overall check for duplicates, just warn
|
|
|
|
// Check 24: Test pollution (from bd validate)
|
|
pollutionCheck := convertDoctorCheck(doctor.CheckTestPollution(path))
|
|
result.Checks = append(result.Checks, pollutionCheck)
|
|
// Don't fail overall check for test pollution, just warn
|
|
|
|
// Check 26: Stale closed issues (maintenance)
|
|
staleClosedCheck := convertDoctorCheck(doctor.CheckStaleClosedIssues(path))
|
|
result.Checks = append(result.Checks, staleClosedCheck)
|
|
// Don't fail overall check for stale issues, just warn
|
|
|
|
// Check 26a: Stale molecules (complete but unclosed)
|
|
staleMoleculesCheck := convertDoctorCheck(doctor.CheckStaleMolecules(path))
|
|
result.Checks = append(result.Checks, staleMoleculesCheck)
|
|
// Don't fail overall check for stale molecules, just warn
|
|
|
|
// Check 26b: Persistent mol- issues (should have been ephemeral)
|
|
persistentMolCheck := convertDoctorCheck(doctor.CheckPersistentMolIssues(path))
|
|
result.Checks = append(result.Checks, persistentMolCheck)
|
|
// Don't fail overall check for persistent mol issues, just warn
|
|
|
|
// Check 26c: Legacy merge queue files (orchestrator mrqueue remnants)
|
|
staleMQFilesCheck := convertDoctorCheck(doctor.CheckStaleMQFiles(path))
|
|
result.Checks = append(result.Checks, staleMQFilesCheck)
|
|
// Don't fail overall check for legacy MQ files, just warn
|
|
|
|
// Check 26d: Patrol pollution (patrol digests, session beads)
|
|
patrolPollutionCheck := convertDoctorCheck(doctor.CheckPatrolPollution(path))
|
|
result.Checks = append(result.Checks, patrolPollutionCheck)
|
|
// Don't fail overall check for patrol pollution, just warn
|
|
|
|
// Check 29: Database size (pruning suggestion)
|
|
// Note: This check has no auto-fix - pruning is destructive and user-controlled
|
|
sizeCheck := convertDoctorCheck(doctor.CheckDatabaseSizeWithStore(sharedStore))
|
|
result.Checks = append(result.Checks, sizeCheck)
|
|
// Don't fail overall check for size warning, just inform
|
|
|
|
// Check 30: Pending migrations (summarizes all available migrations)
|
|
migrationsCheck := convertDoctorCheck(doctor.CheckPendingMigrations(path))
|
|
result.Checks = append(result.Checks, migrationsCheck)
|
|
// Status is determined by the check itself based on migration priorities
|
|
if migrationsCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 31: KV store sync status
|
|
kvSyncCheck := convertDoctorCheck(doctor.CheckKVSyncStatus(path))
|
|
result.Checks = append(result.Checks, kvSyncCheck)
|
|
// Don't fail overall check for KV sync warning, just inform
|
|
|
|
// Check 32: Dolt locks (uncommitted changes)
|
|
doltLocksCheck := convertDoctorCheck(doctor.CheckDoltLocks(path))
|
|
result.Checks = append(result.Checks, doltLocksCheck)
|
|
// Don't fail overall check for Dolt locks, just warn
|
|
|
|
// Check 33: Classic artifacts (post-Dolt-migration cleanup)
|
|
classicArtifactsCheck := convertDoctorCheck(doctor.CheckClassicArtifacts(path))
|
|
result.Checks = append(result.Checks, classicArtifactsCheck)
|
|
// Don't fail overall check for classic artifacts, just warn
|
|
|
|
// Check 34: Linux btrfs NoCOW on .beads/ (GH nocow-beads-dolt-init)
|
|
// Warns when the dolt data directory sits on btrfs without FS_NOCOW_FL,
|
|
// which causes kworker thrashing on the hot append-only write path. Safe
|
|
// no-op on non-Linux and non-btrfs filesystems.
|
|
btrfsNoCowCheck := convertDoctorCheck(doctor.CheckBtrfsNoCOW(path))
|
|
result.Checks = append(result.Checks, btrfsNoCowCheck)
|
|
// Don't fail overall check for btrfs NoCOW, just warn
|
|
|
|
// GH#1095: Filter out suppressed checks (doctor.suppress.<slug> = true)
|
|
suppressed := doctor.GetSuppressedChecksWithStore(sharedStore)
|
|
if len(suppressed) > 0 {
|
|
var suppressedCount int
|
|
var filtered []doctorCheck
|
|
for _, check := range result.Checks {
|
|
slug := doctor.CheckNameToSlug(check.Name)
|
|
if suppressed[slug] && check.Status == statusWarning {
|
|
suppressedCount++
|
|
continue
|
|
}
|
|
filtered = append(filtered, check)
|
|
}
|
|
if suppressedCount > 0 {
|
|
result.Checks = filtered
|
|
// Recompute OverallOK after filtering
|
|
result.OverallOK = true
|
|
for _, check := range result.Checks {
|
|
if check.Status == statusError {
|
|
result.OverallOK = false
|
|
break
|
|
}
|
|
if check.Status == statusWarning {
|
|
// Some warnings are informational (don't fail), but
|
|
// replicate the per-check logic from above is complex.
|
|
// Conservative: don't change OverallOK for warnings here.
|
|
}
|
|
}
|
|
// Store suppressed count for display
|
|
result.SuppressedCount = suppressedCount
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
// runInitDiagnostics runs a limited subset of diagnostics appropriate for a
|
|
// freshly-initialized project. Unlike runDiagnostics (which checks everything),
|
|
// this only validates that the init itself succeeded: the .beads directory exists,
|
|
// the database is openable with correct schema, and permissions are correct.
|
|
// Checks that require git, federation remotes, or other post-setup configuration
|
|
// are skipped since they cannot be satisfied in a fresh project.
|
|
func runInitDiagnostics(path string) doctorResult {
|
|
result := doctorResult{
|
|
Path: path,
|
|
CLIVersion: Version,
|
|
OverallOK: true,
|
|
}
|
|
|
|
// Check 1: Installation (.beads/ directory)
|
|
installCheck := convertWithCategory(doctor.CheckInstallation(path), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, installCheck)
|
|
if installCheck.Status != statusOK {
|
|
result.OverallOK = false
|
|
return result
|
|
}
|
|
|
|
// Check 1b: Dolt format compatibility (GH#2137)
|
|
doltFormatCheck := convertWithCategory(doctor.CheckDoltFormat(path), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, doltFormatCheck)
|
|
if doltFormatCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 2: Database version
|
|
dbCheck := convertWithCategory(doctor.CheckDatabaseVersion(path, Version), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, dbCheck)
|
|
if dbCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 3: Schema compatibility
|
|
schemaCheck := convertWithCategory(doctor.CheckSchemaCompatibility(path), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, schemaCheck)
|
|
if schemaCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 4: Permissions
|
|
permCheck := convertWithCategory(doctor.CheckPermissions(path), doctor.CategoryCore)
|
|
result.Checks = append(result.Checks, permCheck)
|
|
if permCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 5: Dolt connection — validates init actually created a working DB
|
|
doltConnCheck := convertDoctorCheck(doctor.CheckDoltConnection(path))
|
|
result.Checks = append(result.Checks, doltConnCheck)
|
|
if doltConnCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
// Check 6: Dolt schema — validates tables were created
|
|
doltSchemaCheck := convertDoctorCheck(doctor.CheckDoltSchema(path))
|
|
result.Checks = append(result.Checks, doltSchemaCheck)
|
|
if doltSchemaCheck.Status == statusError {
|
|
result.OverallOK = false
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
// convertDoctorCheck converts doctor package check to main package check
|
|
func convertDoctorCheck(dc doctor.DoctorCheck) doctorCheck {
|
|
return doctorCheck{
|
|
Name: dc.Name,
|
|
Status: dc.Status,
|
|
Message: dc.Message,
|
|
Detail: dc.Detail,
|
|
Fix: dc.Fix,
|
|
Category: dc.Category,
|
|
}
|
|
}
|
|
|
|
// convertWithCategory converts a doctor check and sets its category
|
|
func convertWithCategory(dc doctor.DoctorCheck, category string) doctorCheck {
|
|
check := convertDoctorCheck(dc)
|
|
check.Category = category
|
|
return check
|
|
}
|
|
|
|
// exportDiagnostics writes the doctor result to a JSON file
|
|
func exportDiagnostics(result doctorResult, outputPath string) error {
|
|
// #nosec G304 - outputPath is a user-provided flag value for file generation
|
|
f, err := os.Create(outputPath)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create output file: %w", err)
|
|
}
|
|
defer f.Close()
|
|
|
|
encoder := json.NewEncoder(f)
|
|
encoder.SetIndent("", " ")
|
|
if err := encoder.Encode(result); err != nil {
|
|
return fmt.Errorf("failed to write JSON: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func printDiagnostics(result doctorResult) {
|
|
// Pre-calculate counts and collect issues grouped by category
|
|
checksByCategory := make(map[string][]doctorCheck)
|
|
issuesByCategory := make(map[string][]doctorCheck)
|
|
var passCount, warnCount, failCount int
|
|
hasIssues := false
|
|
|
|
for _, check := range result.Checks {
|
|
cat := check.Category
|
|
if cat == "" {
|
|
cat = "Other"
|
|
}
|
|
checksByCategory[cat] = append(checksByCategory[cat], check)
|
|
|
|
switch check.Status {
|
|
case statusOK:
|
|
passCount++
|
|
case statusWarning:
|
|
warnCount++
|
|
issuesByCategory[cat] = append(issuesByCategory[cat], check)
|
|
hasIssues = true
|
|
case statusError:
|
|
failCount++
|
|
issuesByCategory[cat] = append(issuesByCategory[cat], check)
|
|
hasIssues = true
|
|
}
|
|
}
|
|
|
|
// Print header with version and summary
|
|
fmt.Printf("\nbd doctor v%s", result.CLIVersion)
|
|
fmt.Printf(" %s %s %d passed %s %d warnings %s %d errors\n",
|
|
ui.RenderSeparator(),
|
|
ui.RenderPassIcon(), passCount,
|
|
ui.RenderWarnIcon(), warnCount,
|
|
ui.RenderFailIcon(), failCount,
|
|
)
|
|
|
|
if doctorVerbose {
|
|
// Verbose mode: show all checks grouped by category
|
|
fmt.Println()
|
|
printAllChecks(checksByCategory)
|
|
}
|
|
|
|
// Print warnings/errors grouped by category
|
|
if hasIssues {
|
|
fmt.Println()
|
|
|
|
// Walk categories in defined order, only showing those with issues
|
|
for _, category := range doctor.CategoryOrder {
|
|
issues, exists := issuesByCategory[category]
|
|
if !exists || len(issues) == 0 {
|
|
continue
|
|
}
|
|
|
|
// Sort within category: errors first, then warnings
|
|
slices.SortStableFunc(issues, func(a, b doctorCheck) int {
|
|
if a.Status == statusError && b.Status != statusError {
|
|
return -1
|
|
}
|
|
if a.Status != statusError && b.Status == statusError {
|
|
return 1
|
|
}
|
|
return 0
|
|
})
|
|
|
|
// Category header
|
|
catChecks := checksByCategory[category]
|
|
catPass := 0
|
|
for _, c := range catChecks {
|
|
if c.Status == statusOK {
|
|
catPass++
|
|
}
|
|
}
|
|
fmt.Printf("%s %s\n", ui.RenderCategory(category),
|
|
ui.RenderMuted(fmt.Sprintf("(%d/%d passed)", catPass, len(catChecks))))
|
|
|
|
for _, check := range issues {
|
|
line := fmt.Sprintf("%s: %s", check.Name, check.Message)
|
|
if check.Status == statusError {
|
|
fmt.Printf(" %s %s\n", ui.RenderFailIcon(), ui.RenderFail(line))
|
|
} else {
|
|
fmt.Printf(" %s %s\n", ui.RenderWarnIcon(), line)
|
|
}
|
|
if check.Detail != "" {
|
|
fmt.Printf(" %s\n", ui.RenderMuted(check.Detail))
|
|
}
|
|
if check.Fix != "" {
|
|
lines := strings.Split(check.Fix, "\n")
|
|
for j, fixLine := range lines {
|
|
if j == 0 {
|
|
fmt.Printf(" %s%s\n", ui.MutedStyle.Render(ui.TreeLast), fixLine)
|
|
} else {
|
|
fmt.Printf(" %s\n", fixLine)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
fmt.Println()
|
|
}
|
|
|
|
// Handle "Other" category
|
|
if otherIssues, exists := issuesByCategory["Other"]; exists && len(otherIssues) > 0 {
|
|
fmt.Printf("%s\n", ui.RenderCategory("Other"))
|
|
for _, check := range otherIssues {
|
|
line := fmt.Sprintf("%s: %s", check.Name, check.Message)
|
|
if check.Status == statusError {
|
|
fmt.Printf(" %s %s\n", ui.RenderFailIcon(), ui.RenderFail(line))
|
|
} else {
|
|
fmt.Printf(" %s %s\n", ui.RenderWarnIcon(), line)
|
|
}
|
|
if check.Detail != "" {
|
|
fmt.Printf(" %s\n", ui.RenderMuted(check.Detail))
|
|
}
|
|
if check.Fix != "" {
|
|
lines := strings.Split(check.Fix, "\n")
|
|
for j, fixLine := range lines {
|
|
if j == 0 {
|
|
fmt.Printf(" %s%s\n", ui.MutedStyle.Render(ui.TreeLast), fixLine)
|
|
} else {
|
|
fmt.Printf(" %s\n", fixLine)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
fmt.Println()
|
|
}
|
|
|
|
if !doctorVerbose {
|
|
fmt.Printf("%s\n", ui.RenderMuted("Run with --verbose to see all checks"))
|
|
}
|
|
} else {
|
|
fmt.Println()
|
|
fmt.Printf("%s\n", ui.RenderPass("✓ All checks passed"))
|
|
if !doctorVerbose {
|
|
fmt.Printf("%s\n", ui.RenderMuted("Run with --verbose to see all checks"))
|
|
}
|
|
}
|
|
|
|
// GH#1095: Notify user about suppressed checks
|
|
if result.SuppressedCount > 0 {
|
|
noun := "warning"
|
|
if result.SuppressedCount > 1 {
|
|
noun = "warnings"
|
|
}
|
|
fmt.Printf("%s\n", ui.RenderMuted(fmt.Sprintf("(%d %s suppressed via doctor.suppress config)", result.SuppressedCount, noun)))
|
|
}
|
|
}
|
|
|
|
// printAllChecks prints all checks grouped by category with section headers.
|
|
func printAllChecks(checksByCategory map[string][]doctorCheck) {
|
|
// Print checks in defined category order
|
|
for _, category := range doctor.CategoryOrder {
|
|
checks, exists := checksByCategory[category]
|
|
if !exists || len(checks) == 0 {
|
|
continue
|
|
}
|
|
|
|
fmt.Println(ui.RenderCategory(category))
|
|
|
|
for _, check := range checks {
|
|
var statusIcon string
|
|
switch check.Status {
|
|
case statusOK:
|
|
statusIcon = ui.RenderPassIcon()
|
|
case statusWarning:
|
|
statusIcon = ui.RenderWarnIcon()
|
|
case statusError:
|
|
statusIcon = ui.RenderFailIcon()
|
|
}
|
|
|
|
fmt.Printf(" %s %s", statusIcon, check.Name)
|
|
if check.Message != "" {
|
|
fmt.Printf("%s", ui.RenderMuted(" "+check.Message))
|
|
}
|
|
fmt.Println()
|
|
|
|
if check.Detail != "" {
|
|
fmt.Printf(" %s%s\n", ui.MutedStyle.Render(ui.TreeLast), ui.RenderMuted(check.Detail))
|
|
}
|
|
}
|
|
fmt.Println()
|
|
}
|
|
|
|
// Print any checks without a known category
|
|
if otherChecks, exists := checksByCategory["Other"]; exists && len(otherChecks) > 0 {
|
|
fmt.Println(ui.RenderCategory("Other"))
|
|
for _, check := range otherChecks {
|
|
var statusIcon string
|
|
switch check.Status {
|
|
case statusOK:
|
|
statusIcon = ui.RenderPassIcon()
|
|
case statusWarning:
|
|
statusIcon = ui.RenderWarnIcon()
|
|
case statusError:
|
|
statusIcon = ui.RenderFailIcon()
|
|
}
|
|
fmt.Printf(" %s %s", statusIcon, check.Name)
|
|
if check.Message != "" {
|
|
fmt.Printf("%s", ui.RenderMuted(" "+check.Message))
|
|
}
|
|
fmt.Println()
|
|
if check.Detail != "" {
|
|
fmt.Printf(" %s%s\n", ui.MutedStyle.Render(ui.TreeLast), ui.RenderMuted(check.Detail))
|
|
}
|
|
}
|
|
fmt.Println()
|
|
}
|
|
}
|
|
|
|
// runMigrationValidation runs Dolt migration validation checks.
|
|
// Phase can be "pre" (before migration) or "post" (after migration).
|
|
// Outputs machine-parseable JSON when --json flag is set.
|
|
func runMigrationValidation(path string, phase string) {
|
|
var check doctorCheck
|
|
var result doctor.MigrationValidationResult
|
|
|
|
switch phase {
|
|
case "pre":
|
|
dc, mr := doctor.CheckMigrationReadiness(path)
|
|
check = convertDoctorCheck(dc)
|
|
result = mr
|
|
case "post":
|
|
dc, mr := doctor.CheckMigrationCompletion(path)
|
|
check = convertDoctorCheck(dc)
|
|
result = mr
|
|
default:
|
|
FatalError("invalid migration phase %q (use 'pre' or 'post')", phase)
|
|
}
|
|
|
|
// JSON output for machine consumption
|
|
if jsonOutput {
|
|
output := struct {
|
|
Check doctorCheck `json:"check"`
|
|
Validation doctor.MigrationValidationResult `json:"validation"`
|
|
CLIVersion string `json:"cli_version"`
|
|
Timestamp string `json:"timestamp"`
|
|
}{
|
|
Check: check,
|
|
Validation: result,
|
|
CLIVersion: Version,
|
|
Timestamp: time.Now().UTC().Format(time.RFC3339),
|
|
}
|
|
outputJSON(output)
|
|
if !result.Ready {
|
|
os.Exit(1)
|
|
}
|
|
return
|
|
}
|
|
|
|
// Human-readable output
|
|
fmt.Printf("\nbd doctor --migration=%s v%s\n\n", phase, Version)
|
|
|
|
// Print main status
|
|
var statusIcon string
|
|
switch check.Status {
|
|
case statusOK:
|
|
statusIcon = ui.RenderPassIcon()
|
|
case statusWarning:
|
|
statusIcon = ui.RenderWarnIcon()
|
|
case statusError:
|
|
statusIcon = ui.RenderFailIcon()
|
|
}
|
|
|
|
fmt.Printf("%s %s: %s\n", statusIcon, check.Name, check.Message)
|
|
if check.Detail != "" {
|
|
for _, line := range strings.Split(check.Detail, "\n") {
|
|
fmt.Printf(" %s\n", ui.RenderMuted(line))
|
|
}
|
|
}
|
|
|
|
// Print validation details
|
|
fmt.Println()
|
|
fmt.Println(ui.RenderCategory("Validation Details"))
|
|
fmt.Printf(" Backend: %s\n", result.Backend)
|
|
fmt.Printf(" JSONL Count: %d\n", result.JSONLCount)
|
|
if result.SQLiteCount > 0 {
|
|
fmt.Printf(" SQLite Count: %d\n", result.SQLiteCount)
|
|
}
|
|
if result.DoltCount > 0 {
|
|
fmt.Printf(" Dolt Count: %d\n", result.DoltCount)
|
|
}
|
|
fmt.Printf(" JSONL Valid: %v\n", result.JSONLValid)
|
|
if result.JSONLMalformed > 0 {
|
|
fmt.Printf(" Malformed Lines: %d\n", result.JSONLMalformed)
|
|
}
|
|
|
|
// Print warnings
|
|
if len(result.Warnings) > 0 {
|
|
fmt.Println()
|
|
fmt.Println(ui.RenderCategory("Warnings"))
|
|
for _, warn := range result.Warnings {
|
|
fmt.Printf(" %s %s\n", ui.RenderWarnIcon(), warn)
|
|
}
|
|
}
|
|
|
|
// Print errors
|
|
if len(result.Errors) > 0 {
|
|
fmt.Println()
|
|
fmt.Println(ui.RenderCategory("Errors"))
|
|
for _, err := range result.Errors {
|
|
fmt.Printf(" %s %s\n", ui.RenderFailIcon(), err)
|
|
}
|
|
}
|
|
|
|
// Print fix suggestion
|
|
if check.Fix != "" {
|
|
fmt.Println()
|
|
fmt.Printf("%s %s\n", ui.RenderMuted("Fix:"), check.Fix)
|
|
}
|
|
|
|
fmt.Println()
|
|
if result.Ready {
|
|
fmt.Printf("%s\n", ui.RenderPass("✓ Migration validation passed"))
|
|
} else {
|
|
fmt.Printf("%s\n", ui.RenderFail("✗ Migration validation failed"))
|
|
os.Exit(1)
|
|
}
|
|
}
|