fix(orphans): honor --db flag for cross-repo orphan detection (#1200)

* fix(orphans): honor --db flag for cross-repo orphan detection

Problem:
- `bd orphans --db /path` ignored the --db flag entirely
- FindOrphanedIssues() hardcoded local .beads/ directory

Solution:
- Introduce IssueProvider interface for abstract issue lookup
- Add StorageProvider adapter wrapping Storage instances
- Update FindOrphanedIssues to accept provider instead of path
- Wire orphans command to create provider from --db flag

Closes: steveyegge/beads#1196

* test(orphans): add cross-repo and provider tests for --db flag fix

- Add TestFindOrphanedIssues_WithMockProvider (table-driven, UT-01 through UT-09)
- Add TestFindOrphanedIssues_CrossRepo (validates --db flag honored)
- Add TestFindOrphanedIssues_LocalProvider (backward compat RT-01)
- Add TestFindOrphanedIssues_ProviderError (error handling UT-07)
- Add TestFindOrphanedIssues_IntegrationCrossRepo (IT-02 full)
- Add TestLocalProvider_* unit tests

Coverage for IssueProvider interface and cross-repo orphan detection.

* docs: add bd orphans command to CLI reference

Document the orphan detection command including the cross-repo
workflow enabled by the --db flag fix in this PR.
This commit is contained in:
Peter Chanthamynavong
2026-01-21 19:52:31 -08:00
committed by GitHub
parent a0dac11e42
commit c11fa799be
7 changed files with 852 additions and 61 deletions

View File

@@ -334,6 +334,24 @@ bd admin cleanup --dry-run --json # Preview what
bd admin cleanup --older-than 90 --cascade --force --json # Delete old + dependents
```
### Orphan Detection
Find issues referenced in git commits that were never closed:
```bash
# Basic usage - scan current repo
bd orphans
# Cross-repo: scan CODE repo's commits against external BEADS database
cd ~/my-code-repo
bd orphans --db ~/my-beads-repo/.beads/beads.db
# JSON output
bd orphans --json
```
**Use case**: When your beads database lives in a separate repository from your code, run `bd orphans` from the code repo and point `--db` to the external database. This scans commits in your current directory while checking issue status from the specified database.
### Duplicate Detection & Merging
```bash