feat(deps): detect/prevent child→parent dependency anti-pattern (bd-nim5)

This prevents a common mistake where users add dependencies from child
issues to their parent epics. This creates a deadlock:
- Child can't start (blocked by open parent)
- Parent can't close (children not done)

Changes:
- dep.go: Reject child→parent deps at creation time with clear error
- server_labels_deps_comments.go: Same check for daemon RPC
- doctor/validation.go: New check detects existing bad deps
- doctor/fix/validation.go: Auto-fix removes bad deps
- doctor.go: Wire up check and fix handler

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-24 13:03:13 -08:00
parent 566e4f5225
commit ce2b05356a
7 changed files with 379 additions and 0 deletions

View File

@@ -308,6 +308,79 @@ func CheckTestPollution(path string) DoctorCheck {
}
}
// CheckChildParentDependencies detects the child→parent dependency anti-pattern.
// This creates a deadlock: child can't start (parent open), parent can't close (children not done).
func CheckChildParentDependencies(path string) DoctorCheck {
beadsDir := filepath.Join(path, ".beads")
dbPath := filepath.Join(beadsDir, beads.CanonicalDatabaseName)
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
return DoctorCheck{
Name: "Child-Parent Dependencies",
Status: "ok",
Message: "N/A (no database)",
}
}
db, err := openDBReadOnly(dbPath)
if err != nil {
return DoctorCheck{
Name: "Child-Parent Dependencies",
Status: "ok",
Message: "N/A (unable to open database)",
}
}
defer db.Close()
// Query for child→parent dependencies where issue_id starts with depends_on_id + "."
// This uses SQLite's LIKE pattern matching
query := `
SELECT d.issue_id, d.depends_on_id
FROM dependencies d
WHERE d.issue_id LIKE d.depends_on_id || '.%'
`
rows, err := db.Query(query)
if err != nil {
return DoctorCheck{
Name: "Child-Parent Dependencies",
Status: "ok",
Message: "N/A (query failed)",
}
}
defer rows.Close()
var badDeps []string
for rows.Next() {
var issueID, dependsOnID string
if err := rows.Scan(&issueID, &dependsOnID); err == nil {
badDeps = append(badDeps, fmt.Sprintf("%s→%s", issueID, dependsOnID))
}
}
if len(badDeps) == 0 {
return DoctorCheck{
Name: "Child-Parent Dependencies",
Status: "ok",
Message: "No child→parent dependencies",
Category: CategoryMetadata,
}
}
detail := strings.Join(badDeps, ", ")
if len(detail) > 200 {
detail = detail[:200] + "..."
}
return DoctorCheck{
Name: "Child-Parent Dependencies",
Status: "warning",
Message: fmt.Sprintf("%d child→parent dependency anti-pattern(s) detected", len(badDeps)),
Detail: detail,
Fix: "Run 'bd doctor --fix' to remove child→parent dependencies",
Category: CategoryMetadata,
}
}
// CheckGitConflicts detects git conflict markers in JSONL file.
func CheckGitConflicts(path string) DoctorCheck {
beadsDir := filepath.Join(path, ".beads")