Commit Graph

2107 Commits

Author SHA1 Message Date
Steve Yegge
bb5a480445 feat: Add --body flag as alias for --description
Adds --body as a hidden alias for --description in create/update commands,
following GitHub CLI convention for better agent ergonomics.

The --body flag:
- Works alongside existing --description and -d flags
- Hidden from help output to avoid clutter
- Validates conflicts when both flags used with different values
- Available in both 'bd create' and 'bd update' commands

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 20:08:55 -05:00
Steve Yegge
364cedee5d bug: File bd-7yg for merge driver placeholder issue
Documents critical bug affecting all users where git merge driver
uses invalid %L/%R placeholders instead of standard %A/%B.

Discovered while resolving merge conflict - automatic JSONL merge
fails with 'open 7: no such file or directory' error.
2025-11-21 19:52:18 -05:00
Steve Yegge
821880419a Merge branch 'main' of https://github.com/steveyegge/beads
# Conflicts:
#	.beads/beads.jsonl
2025-11-21 19:42:35 -05:00
Steve Yegge
5ae76d24d4 chore: Close 4 test coverage issues (bd-yxy, bd-nbc, bd-lln, bd-gra)
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 19:33:12 -05:00
Steve Yegge
58fe00057c feat: Complete GH #353 follow-up phases (bd-9nw, bd-u3t, bd-e0o)
Implements all three follow-up phases for sandbox environment support:

**Phase 1 (bd-9nw): Documentation** 
- Comprehensive sandbox troubleshooting section in TROUBLESHOOTING.md
  - Detailed symptoms, root causes, and escape hatches
  - Step-by-step troubleshooting workflow
  - Comparison table for --sandbox, --force, and --allow-stale flags
- Global flags section added to CLI_REFERENCE.md
  - Documents --sandbox, --allow-stale, and --force flags
  - Usage examples and when to use each flag
- GitHub issue #353 comment with immediate workarounds

**Phase 2 (bd-u3t): Sandbox Auto-Detection** 
- Automatic sandbox detection using syscall.Kill permission checks
  - cmd/bd/sandbox_unix.go: Unix/Linux/macOS implementation
  - cmd/bd/sandbox_windows.go: Windows stub (conservative approach)
  - cmd/bd/sandbox_test.go: Comprehensive test coverage
- Auto-enables sandbox mode when detected
  - Shows: "ℹ️  Sandbox detected, using direct mode"
  - Respects explicit --sandbox or --no-daemon flags
- Updated documentation to reflect auto-detection (v0.21.1+)

**Phase 3 (bd-e0o): Enhanced Daemon Robustness** 
- Permission-aware process checks in cmd/bd/daemon_unix.go
  - Correctly handles EPERM (operation not permitted) from syscall.Kill
  - Treats EPERM as "process exists but not signable" = running
  - Prevents false negatives in sandboxed environments
- Metadata health check in cmd/bd/daemon_event_loop.go
  - Periodic verification that metadata is accessible
  - Helps detect external import operations (bd import --force)
  - Non-fatal logging for diagnostics
- Comprehensive test suite in cmd/bd/daemon_unix_test.go
  - Self-check, init process, nonexistent process, parent process tests

**Impact:**
- Codex users: No manual intervention needed, auto-detected
- Stuck states: Three escape hatches (--sandbox, --force, --allow-stale)
- Daemon robustness: Handles permission-restricted environments gracefully
- All three follow-up issues (bd-9nw, bd-u3t, bd-e0o) closed

**Files changed:**
- cmd/bd/main.go: Auto-detection logic in PersistentPreRun
- cmd/bd/sandbox_unix.go: Unix sandbox detection (new)
- cmd/bd/sandbox_windows.go: Windows sandbox detection stub (new)
- cmd/bd/sandbox_test.go: Sandbox detection tests (new)
- cmd/bd/daemon_unix.go: Permission-aware isProcessRunning()
- cmd/bd/daemon_unix_test.go: Process check tests (new)
- cmd/bd/daemon_event_loop.go: Metadata health check
- docs/TROUBLESHOOTING.md: Comprehensive sandbox section
- docs/CLI_REFERENCE.md: Global flags documentation

Closes bd-9nw, bd-u3t, bd-e0o
Related: GH #353

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 19:32:45 -05:00
Steve Yegge
601469eb90 Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-21 19:31:59 -05:00
Steve Yegge
88c7bb6e4c bd sync: 2025-11-21 19:31:56 2025-11-21 19:31:56 -05:00
Steve Yegge
74f384444b test: Add security and error handling tests for lint warnings
Added comprehensive tests to address gosec and errcheck linter warnings:

1. bd-yxy (P0): Command injection prevention tests for git rm in merge command
   - Added merge_security_test.go with tests for shell metacharacters
   - Verified exec.Command safely passes arguments (no shell interpretation)
   - Added #nosec G204 comment explaining why code is safe

2. bd-nbc (P1): Security tests for file path validation in clean command
   - Added clean_security_test.go with path traversal tests
   - Verified filepath.Join safely constructs paths within .beads directory
   - Added #nosec G304 comment documenting safety guarantees

3. bd-lln (P2): Tests for performFlush error handling in FlushManager
   - Added tests documenting that performFlush intentionally returns nil
   - Errors are handled internally by flushToJSONLWithState
   - Tests verify graceful degradation when store is inactive

4. bd-gra (P2): Error handling test for cmd.Help() in search command
   - Added search_test.go documenting Help() error handling
   - Help() errors intentionally ignored (already in error path, will exit anyway)
   - Added #nosec G104 comment explaining rationale

All new tests pass. The linter warnings are false positives or intentional
design decisions, now documented with tests and #nosec comments.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 19:30:48 -05:00
Steve Yegge
d7f4189e3e feat: Add 'bd count' command for counting and grouping issues
Implements a new 'bd count' command that provides efficient issue counting
with filtering and grouping capabilities.

Features:
- Basic count: Returns total count of issues matching filters
- All filtering options from 'bd list' (status, priority, type, assignee, labels, dates, etc.)
- Grouping via --by-* flags: status, priority, type, assignee, label
- JSON output support for both simple and grouped counts
- Both daemon and direct mode support

Implementation:
- Added OpCount operation and CountArgs to RPC protocol
- Added Count() method to RPC client
- Implemented handleCount() server-side handler with optimized bulk label fetching
- Created cmd/bd/count.go with full CLI implementation

Performance optimization:
- Pre-fetches all labels in a single query when using --by-label to avoid N+1 queries

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 19:21:05 -05:00
Steve Yegge
897e952ac3 finished implementing these old docs 2025-11-21 19:19:24 -05:00
Steve Yegge
68e38816fc docs: Make 'land the plane' push mandatory and emphatic
CRITICAL FIX: Agents were stopping before git push, saying 'ready to
push when you are!' which breaks multi-agent coordination workflows.

Changes:
- Make push MANDATORY in landing workflow
- Add emphatic warnings: NEVER stop before push succeeds
- Explicitly state 'ready to push' is a FAILURE
- Explain multi-agent coordination impact
- Add verification requirements

This should prevent agents from leaving work unpushed.
2025-11-21 19:11:43 -05:00
Steve Yegge
65ba2c9a19 feat: Add issue IDs to TODO comments
Updated TODO comments with proper beads issue IDs:
- bd-hdt: Implement auto-merge functionality
- bd-gqo: Implement daemon health checks
- bd-r46: Support --reason flag in daemon mode for reopen

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 19:01:42 -05:00
Steve Yegge
cc7b341adb Merge branch 'main' of https://github.com/steveyegge/beads
# Conflicts:
#	.beads/beads.jsonl
2025-11-21 19:01:38 -05:00
Steve Yegge
3f17627a39 test: Mark TestAutoFlushDebounce as obsolete
Debouncing functionality has been refactored from module-level variables
to the FlushManager, which is thoroughly tested in flush_manager_test.go.

The TestAutoFlushDebounce test referenced old variables (flushDebounce, etc.)
that no longer exist in the codebase. Rather than rewriting it to test the old
auto-flush code paths, we skip it and rely on the comprehensive FlushManager tests.

Fixes + Opts completed from MAIN_TEST_OPTIMIZATION_PLAN.md:
-  Fix 1: rootCtx initialization (already done)
-  Fix 2: Reduced sleep durations (already done)
-  Opt 3: Fixed TestAutoFlushDebounce (marked obsolete)

All TestAuto* tests now pass in 1.9s.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 19:00:44 -05:00
Steve Yegge
ad4d6dc147 docs: Remove obsolete design and analysis documents
Remove 5 obsolete documentation files (2,847 lines, 20% reduction):

Removed files:
- HASH_ID_DESIGN.md: Design doc for hash IDs (implemented in v0.20+, bd-166)
- contributor-workflow-analysis.md: Design analysis (superseded by MULTI_REPO_*.md)
- vc-feedback-on-multi-repo.md: Feedback on design (now implemented)
- import-bug-analysis-bd-3xq.md: Bug analysis for specific issue (likely fixed)
- TEST_OPTIMIZATION.md: One-time optimization doc (completed Nov 2025)

All removed files were historical design/analysis documents for features
that are now implemented and documented elsewhere.

Retained files:
- MULTI_REPO_HYDRATION.md: Referenced as internals documentation
- ROUTING.md: Active user-facing feature documentation
- EXCLUSIVE_LOCK.md: Integration documentation for external tools
- ADAPTIVE_IDS.md: Referenced by CONFIG.md
- COLLISION_MATH.md: Referenced by ADAPTIVE_IDS.md and CONFIG.md

Total documentation reduced from 14,043 to 11,196 lines.
2025-11-21 19:00:22 -05:00
Steve Yegge
c2b9f5d358 Merge branch 'main' of https://github.com/steveyegge/beads
# Conflicts:
#	.beads/beads.jsonl
2025-11-21 18:56:03 -05:00
Steve Yegge
b3e76ff1f6 feat: Add sandbox escape hatches for daemon lock issues (GH #353 Phase 1)
Implements three quick fixes for users stuck in sandboxed environments
(e.g., Codex) where daemon cannot be stopped:

1. **--force flag for bd import**
   - Forces metadata update even when DB is synced with JSONL
   - Fixes stuck state caused by stale daemon cache
   - Shows: "Metadata updated (database already in sync with JSONL)"

2. **--allow-stale global flag**
   - Emergency escape hatch to bypass staleness check
   - Shows warning: "⚠️  Staleness check skipped (--allow-stale)"
   - Allows operations on potentially stale data

3. **Improved error message**
   - Added sandbox-specific guidance to staleness error
   - Suggests --sandbox, --force, and --allow-stale flags
   - Provides clear fix steps for different scenarios

Also fixed:
- Removed unused import in cmd/bd/duplicates_test.go

Follow-up work filed:
- bd-u3t: Phase 2 - Sandbox auto-detection
- bd-e0o: Phase 3 - Daemon robustness enhancements
- bd-9nw: Documentation updates

Fixes #353 (Phase 1)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 18:53:34 -05:00
Steve Yegge
822baa0bc9 fix(test): Fix hanging tests by initializing rootCtx (bd-n25)
Problem:
- 10 tests in main_test.go were hanging indefinitely
- Tests calling flushToJSONL() or autoImportIfNewer() would timeout
- Root cause: rootCtx was nil in test environment

Solution:
1. Initialize rootCtx with 30s timeout in all affected tests:
   - TestAutoFlushOnExit
   - TestAutoFlushJSONLContent
   - TestAutoFlushErrorHandling
   - TestAutoImportIfNewer
   - TestAutoImportDisabled
   - TestAutoImportWithUpdate
   - TestAutoImportNoUpdate
   - TestAutoImportMergeConflict
   - TestAutoImportConflictMarkerFalsePositive
   - TestAutoImportClosedAtInvariant

2. Reduce sleep durations by 10x (200ms→20ms, 100ms→10ms)

3. Fix JSONL path issue in TestAutoFlushJSONLContent

Results:
- Before: Tests hung indefinitely (∞)
- After: All 16 tests complete in ~1-2 seconds
- 15 passing, 1 skipped (TestAutoFlushDebounce needs config fix)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 18:47:38 -05:00
Steve Yegge
6f3b0e7c99 doc: Document main_test.go refactoring analysis (bd-1rh)
Analysis shows main_test.go is NOT a good candidate for shared DB pattern
due to global state manipulation and integration test characteristics.

Changes:
- Added MAIN_TEST_REFACTOR_NOTES.md documenting findings
- Fixed unused import in duplicates_test.go (from recent pull)

Key findings:
- 18 tests with 14 newTestStore() calls
- Tests manipulate global state (autoFlushEnabled, isDirty, etc.)
- Tests simulate workflows (flush, import) not just CRUD
- Shared DB causes deadlocks between flush ops and cleanup
- Integration tests need process-level isolation

Recommendation: Leave as-is or use Option 2 (grouped tests without
shared DB). Focus P2 efforts on integrity_test.go instead.

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 18:00:23 -05:00
Steve Yegge
2101b2543f Merge branch 'main' of https://github.com/steveyegge/beads
# Conflicts:
#	cmd/bd/duplicates_test.go
2025-11-21 16:15:18 -05:00
Steve Yegge
e38c0a58aa test: Refactor duplicates_test.go to use shared DB pattern (P2)
METRICS:
- Tests: 5 tests
- DB setups removed: 1 → 1 shared
- Tests needing DB: 1/5
- Savings: setupTestDB() → newTestStore()

DETAILS:
- TestFindDuplicateGroups: Pure in-memory logic (no DB)
- TestChooseMergeTarget: Pure in-memory logic (no DB)
- TestCountReferences: Pure in-memory logic (no DB)
- TestDuplicateGroupsWithDifferentStatuses: Pure in-memory (no DB)
- TestDuplicatesIntegration: Uses shared DB (was: setupTestDB)

Also fixed: Removed hardcoded IDs, let DB assign them.
All 5 tests pass!

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 16:14:30 -05:00
Steve Yegge
b57ae7981f test: Refactor epic_test.go to use shared DB pattern (P2)
METRICS:
- Tests: 3 tests
- DB setups removed: 2 → 1 shared
- Tests needing DB: 2/3
- Savings: ~1 DB setup eliminated

DETAILS:
- TestEpicCommand: Uses shared DB (was: dedicated setup)
- TestEpicCommandInit: No DB needed (command structure test)
- TestEpicEligibleForClose: Uses shared DB (was: dedicated setup)

Pattern: newTestStore(t, testDB) replaces per-test DB setup.
All 3 tests pass with optimized setup!

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 16:14:30 -05:00
Steve Yegge
1eac5a9b8b test: Refactor validate_test.go - remove ALL DB setup (P2)
METRICS:
- Tests: 9 tests
- DB setups removed: 0 → 0 (were already none!)
- Tests still needing DB: 0/9
- Pattern: Pure validation tests - no DB needed

DETAILS:
- TestParseChecks: Pure string parsing
- TestValidationResults*: Pure data structure tests
- TestValidateOrphanedDeps: In-memory issue validation
- TestValidateDuplicates: In-memory issue validation
- TestValidatePollution: In-memory issue validation
- TestValidateGitConflicts_*: File-only tests, simplified temp file setup

All 9 tests pass without any database setup!

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 16:14:30 -05:00
Steve Yegge
227e76b215 test: Refactor Phase 2 test files to use shared DB pattern (bd-1rh)
Refactored 3 smaller test files for test suite optimization:

FILES ANALYZED:
- validate_test.go (9 tests): NO DB needed - pure validation logic
- epic_test.go (3 tests): 2 DB setups → 1 shared pattern
- duplicates_test.go (5 tests): 1 old setupTestDB → newTestStore

CHANGES:
epic_test.go:
- Replaced 2× manual sqlite.New() with newTestStore()
- Removed duplicate SetConfig calls
- Removed manual Close/defer (handled by helper)
- -40 lines, +6 lines = net -34 lines

duplicates_test.go:
- Replaced old setupTestDB pattern with newTestStore
- Updated test data: bd-1/2/3 → test-1/2/3 (matches prefix)
- Added filepath import
- Removed cleanup() function pattern
- Net changes: proper shared pattern adoption

METRICS:
- Total files changed: 2/3 (validate_test.go needs no DB!)
- DB setups eliminated: 3 → 1 (epic: 2→1, duplicates: 1→0+shared)
- Lines saved: 30 net reduction
- Tests passing: 13/13 ✓

validate_test.go required NO changes - all tests are pure functions
with in-memory data. Even git conflict tests use temp files, not DB.

Part of Phase 2/3 test suite optimization.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 16:14:27 -05:00
Steve Yegge
672377544b test: Refactor compact_test.go to use shared DB pattern (bd-1rh)
Part of Phase 2/3 test suite optimization.

BEFORE:
- 10 separate test functions
- Each creating its own database
- 6 tests with DB setup overhead
- Total: 10 test executions

AFTER:
- 1 TestCompactSuite with 6 shared-DB subtests
- 4 standalone tests (no DB needed)
- Single DB setup for suite
- Total: 5 test functions

IMPACT:
- Lines: -135 (-22.4%)
- DB setups: 6 → 1 (6x reduction)
- Tests passing: 10/10 ✓
- Runtime: ~0.33s

The suite consolidates all DB-dependent tests:
- DryRun: eligibility check on closed issue
- Stats: mix of eligible/ineligible issues
- RunCompactStats: tests both normal and JSON output
- CompactStatsJSON: JSON formatting path
- RunCompactSingleDryRun: single issue eligibility
- RunCompactAllDryRun: multiple issue eligibility

Standalone tests (no DB):
- TestCompactValidation: flag validation logic
- TestCompactProgressBar: progress bar formatting
- TestFormatUptime: uptime display formatting
- TestCompactInitCommand: command initialization

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 16:13:18 -05:00
Steve Yegge
351d2239d6 test: Refactor integrity_test.go to use shared DB pattern (bd-1rh P2)
CHANGES:
- Reduced from 15 DB setups to 4 shared DBs
- TestValidatePreExportSuite: 1 shared DB, 5 subtests
- TestValidatePostImport: No DB needed, kept as-is
- TestCountDBIssuesSuite: 1 shared DB, 1 subtest
- TestHasJSONLChangedSuite: 1 shared DB, 7 subtests (with unique keySuffixes)
- TestComputeJSONLHash: No DB needed, kept as-is
- TestCheckOrphanedDepsSuite: 1 shared DB, 2 subtests

PERFORMANCE:
- Before: 0.455s avg (15 DB setups)
- After: 0.373s avg (4 DB setups)
- Speedup: 1.22x (18% faster)

KEY LEARNINGS:
- Used unique keySuffix values for hasJSONLChanged subtests to avoid metadata pollution
- Metadata keys like last_import_hash are shared across subtests unless keySuffix is used
- TestValidatePostImport and TestComputeJSONLHash do not need DB at all

PATTERN:
Following create_test.go and dep_test.go pattern with shared DB setup

Part of Phase 2 test suite optimization (bd-1rh follow-up)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 16:11:56 -05:00
Steve Yegge
8ac10a28f2 Update bd JSONL
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 15:52:36 -05:00
Steve Yegge
0b1a86a207 test: Refactor P1 test files to use shared DB pattern (bd-1rh)
Refactored 6 high-priority test files to reduce database initializations
and improve test suite performance:

- create_test.go: Combined 11 tests into TestCreateSuite (11 DBs → 1 DB)
- dep_test.go: Combined into TestDependencySuite (4 DBs → 1 DB)
- comments_test.go: Combined into TestCommentsSuite (2 DBs → 1 DB)
- list_test.go: Split into 2 suites to avoid data pollution (2 DBs → 2 DBs)
- ready_test.go: Combined into TestReadySuite (3 DBs → 1 DB)
- stale_test.go: Kept as individual functions due to data isolation needs

Added TEST_SUITE_AUDIT.md documenting the refactoring plan, results,
and key learnings for future test development.

Results:
- P1 tests now run in 0.43 seconds
- Estimated 10-20x speedup
- All tests passing

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 15:51:07 -05:00
Marco Del Pin
f724b612d2 fix: Deduplicate database paths when symlinks present (#354)
Fixes a bug where FindAllDatabases() would return the same database
multiple times when symlinks were present in the directory hierarchy.

The issue occurred because the function walked up the directory tree
without resolving symlinks or checking if a database had already been
discovered. This led to confusing warnings about "multiple databases"
even when only one physical database existed.

Changes:
- Added symlink resolution using filepath.EvalSymlinks()
- Implemented deduplication using a seen map with canonical paths
- Added comprehensive tests for symlink scenarios

This ensures that each unique database is reported exactly once,
regardless of how many symlinks point to it in the directory tree.

Resolves duplicate database warnings when symlinks are present.
2025-11-21 12:22:33 -08:00
Steve Yegge
e16265515a ran bd cleanup 2025-11-21 15:12:22 -05:00
Steve Yegge
1c91c65d69 bd sync: 2025-11-21 15:11:55 2025-11-21 15:11:55 -05:00
Steve Yegge
bdc1487f48 Close bd-ar2, bd-dvd, and bd-ymj: Complete code review follow-up work
Closes three tickets related to GitHub #334 and #278:

- bd-dvd: Parent resurrection fix (GetNextChildID now resurrects parents)
- bd-ymj: Export metadata fix (prevents false JSONL changed errors)
- bd-ar2: Code review epic with 12 subtasks (all completed)

All fixes implemented in commit 4c5f99c and follow-up improvements.
Updated GH #334 with fix details and marked as triaged.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 15:10:32 -05:00
Steve Yegge
3a0446c431 Fix test compilation errors: add context.Background() to sqlite.New() calls
Updated all test files to pass context.Background() as the first parameter
to sqlite.New() calls to match the updated function signature.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 14:57:18 -05:00
Steve Yegge
c9207fce63 Close bd-ar2.8: Add edge case tests for export metadata updates
Added comprehensive tests for multi-repo export metadata handling:

1. TestExportWithMultiRepoConfigUpdatesAllMetadata (P2)
   - Verifies export with multi-repo config updates metadata for ALL JSONL files
   - Confirms each repo gets correct keySuffix in metadata keys
   - Tests full integration: getMultiRepoJSONLPaths -> getRepoKeyForPath -> updateExportMetadata
   - Validates subsequent exports succeed without "content has changed" errors

2. TestUpdateExportMetadataInvalidKeySuffix (P3)
   - Tests failure handling for invalid keySuffix containing ':' separator
   - Confirms validation logic from bd-ar2.12 works correctly

All tests pass. bd-ar2 epic nearly complete - only one P3 task remains!

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 14:57:01 -05:00
Steve Yegge
1168f661d1 fix: Add context.Background() to sqlite.New() calls in test files
Multiple test files were still using the old sqlite.New(path) signature
instead of the new sqlite.New(ctx, path) signature. This was causing
compilation failures in the test suite.

Fixed files:
- internal/importer/importer_test.go
- internal/importer/external_ref_test.go
- internal/importer/timestamp_test.go
- internal/rpc/limits_test.go
- internal/rpc/list_filters_test.go
- internal/rpc/rpc_test.go
- internal/rpc/status_test.go
- internal/syncbranch/syncbranch_test.go
2025-11-21 14:48:41 -05:00
Steve Yegge
032e6a72d2 bd sync: 2025-11-21 14:40:35 2025-11-21 14:40:35 -05:00
Steve Yegge
82902432f5 test: Tag 16 slow integration tests with build tags
Identified and tagged obviously-slow integration tests with
`//go:build integration` to exclude them from default test runs.

This is step 1 of fixing test performance. The real fix is in
bd-1rh: refactoring tests to use shared DB setup instead of
creating 279 separate databases.

Tagged files:
- cmd/bd: 8 files (CLI tests, git ops, performance benchmarks)
- internal: 8 files (integration tests, E2E tests)

Issues:
- bd-1rh: Main issue tracking test performance
- bd-c49: Audit all tests and create grouping plan (next step)
- bd-y6d: POC refactor of create_test.go

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 14:40:22 -05:00
Steve Yegge
e816e91ecb Complete bd-ar2 P2 tasks: metadata, resurrection, and testing improvements
This commit addresses the remaining P2 tasks from bd-ar2 code review follow-up:

## Completed Tasks

### bd-ar2.4: Improve parent chain resurrection
- Modified `tryResurrectParentWithConn()` to recursively resurrect ancestor chain
- When resurrecting bd-root.1.2, now also resurrects bd-root.1 if missing
- Handles deeply nested hierarchies where intermediate parents are deleted
- All resurrection tests pass including new edge cases

### bd-ar2.5: Add error handling guidance
- Documented metadata update failure strategy in `updateExportMetadata()`
- Explained trade-off: warnings vs errors (safe, prevents data loss)
- Added user-facing message: "Next export may require running 'bd import' first"
- Clarifies that worst case is requiring import before next export

### bd-ar2.6: Document transaction boundaries
- Added comprehensive documentation for atomicity trade-offs
- Explained crash scenarios and recovery (bd import)
- Documented decision to defer defensive checks (Option 4) until needed
- No code changes - current approach is acceptable for now

### bd-ar2.12: Add metadata key validation
- Added keySuffix validation in `updateExportMetadata()` and `hasJSONLChanged()`
- Prevents ':' separator in keySuffix to avoid malformed metadata keys
- Documented metadata key format in function comments
- Single-repo: "last_import_hash", multi-repo: "last_import_hash:<repo_key>"

### bd-ar2.7: Add edge case tests for GetNextChildID resurrection
- TestGetNextChildID_ResurrectParent_NotInJSONL: parent not in history
- TestGetNextChildID_ResurrectParent_NoJSONL: missing JSONL file
- TestGetNextChildID_ResurrectParent_MalformedJSONL: invalid JSON lines
- TestGetNextChildID_ResurrectParentChain: deeply nested missing parents
- All tests pass, resurrection is robust against edge cases

## Files Changed
- cmd/bd/daemon_sync.go: Metadata validation, error handling docs
- cmd/bd/integrity.go: Added strings import, keySuffix validation
- internal/storage/sqlite/hash_ids.go: Improved resurrection comments
- internal/storage/sqlite/resurrection.go: Recursive ancestor resurrection
- internal/storage/sqlite/child_id_test.go: Added 4 new edge case tests

## Testing
All export, sync, metadata, and resurrection tests pass.
Edge cases properly handled: missing JSONL, malformed JSON, deep nesting.

## Remaining Tasks
- bd-ar2.8 (P3): Additional export metadata edge case tests (deferred)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 11:40:37 -05:00
Steve Yegge
cd8cb8b86a Fix bd-ar2 code review issues: metadata tracking and multi-repo support
This commit addresses critical code review findings from bd-dvd and bd-ymj fixes:

## Completed Tasks

### bd-ar2.1: Extract duplicated metadata update code
- Created `updateExportMetadata()` helper function
- Eliminated 22-line duplication between createExportFunc and createSyncFunc
- Single source of truth for metadata updates

### bd-ar2.2: Add multi-repo support to export metadata updates
- Added per-repo metadata key tracking with keySuffix parameter
- Both export and sync functions now update metadata for all repos

### bd-ar2.3: Fix tests to use actual daemon functions
- TestExportUpdatesMetadata now calls updateExportMetadata() directly
- Added TestUpdateExportMetadataMultiRepo() for multi-repo testing
- Fixed export_mtime_test.go tests to call updateExportMetadata()

### bd-ar2.9: Fix variable shadowing in GetNextChildID
- Changed `err` to `resurrectErr` to avoid shadowing
- Improves code clarity and passes linter checks

### bd-ar2.10: Fix hasJSONLChanged to support per-repo keys
- Updated hasJSONLChanged() to accept keySuffix parameter
- Reads metadata with correct per-repo keys
- All callers updated (validatePreExport, daemon import, sync command)

### bd-ar2.11: Use stable repo identifiers instead of paths
- Added getRepoKeyForPath() helper function
- Uses stable identifiers like ".", "../frontend" instead of absolute paths
- Metadata keys now portable across machines and clones
- Prevents orphaned metadata when repos are moved

## Files Changed
- cmd/bd/daemon_sync.go: Helper functions, metadata updates
- cmd/bd/integrity.go: hasJSONLChanged() with keySuffix support
- cmd/bd/sync.go: Updated to use getRepoKeyForPath()
- cmd/bd/*_test.go: Tests updated for new signatures
- internal/storage/sqlite/hash_ids.go: Fixed variable shadowing

## Testing
All export, sync, and integrity tests pass.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 11:28:25 -05:00
Steve Yegge
ff2a2250f3 Close bd-9f86-baseline-test: test compilation errors fixed 2025-11-21 11:04:34 -05:00
Steve Yegge
1dd307159d bd sync: 2025-11-21 10:29:36 2025-11-21 10:29:36 -05:00
Steve Yegge
4c5f99c5bd Fix bd-dvd and bd-ymj: Parent resurrection and export metadata
Bug 1 (bd-dvd): GetNextChildID now attempts parent resurrection from JSONL
before failing. Added TryResurrectParent call to match CreateIssue behavior.

Bug 2 (bd-ymj): Export now updates last_import_hash metadata to prevent
'JSONL content has changed' errors on subsequent exports.

Files changed:
- internal/storage/sqlite/hash_ids.go: Add resurrection attempt
- cmd/bd/daemon_sync.go: Add metadata updates after export
- Tests added for both fixes
- Fixed pre-existing bug in integrity_content_test.go

Follow-up work tracked in epic bd-ar2 (9 issues for improvements).

Fixes GH #334
2025-11-21 10:29:30 -05:00
Steve Yegge
ff3ccdd26e rebuild Go binaries in version bump script 2025-11-21 09:45:37 -05:00
Steve Yegge
1806183d5f feat: Add bd search command for efficient text queries (#347)
Adds a new `bd search` command optimized for quick text searches,
addressing the issue where Claude using MCP bd list consumes 30k tokens.

Features:
- Searches across title, description, and ID with OR logic
- Default limit of 50 results (vs unlimited for bd list)
- Supports key filters: --status, --assignee, --type, --label
- Works in both daemon and direct modes
- Provides --json and --long output formats

Examples:
  bd search "performance" --status open
  bd search "database" --label backend --limit 10
  bd search "bd-5q"  # Search by partial ID

This provides a more efficient alternative to bd list when users
just want to find issues quickly without loading all results.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 22:44:19 -05:00
Steve Yegge
2ba3cd64fe docs: Add #328 fix to 0.24.0 changelog
Include the duplicate function declaration fix that was merged
after the initial changelog was prepared.
2025-11-20 22:15:47 -05:00
Steve Yegge
00840aa72f chore: Bump version to 0.24.0
Updated all component versions:
- bd CLI: 0.23.1 → 0.24.0
- Plugin: 0.23.1 → 0.24.0
- MCP server: 0.23.1 → 0.24.0
- npm package: 0.23.1 → 0.24.0
- Documentation: 0.23.1 → 0.24.0

Added comprehensive CHANGELOG.md entry for 0.24.0 with 179 commits:
- Critical bug fixes (auto-import resurrection, sync conflicts, resource leaks)
- Performance improvements (GetReadyWork optimization, N+1 query elimination)
- New features (bd doctor --fix, bd clean, auto-detection)
- Enhanced AI agent support (context propagation, error handling)
- Cross-platform improvements (Windows, macOS stability)
2025-11-20 22:15:04 -05:00
Steve Yegge
167ab6788b Fix #328: Remove duplicate computeJSONLHash declaration
The function was declared twice:
- Line 80: New version (simpler, no error wrapping)
- Line 390: Old version (with error wrapping)

This caused compilation failure in CI. Removed the old declaration at line 390.

Also fixed integrity_content_test.go to pass context.Context to sqlite.New()
as required by the updated API.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 22:06:38 -05:00
Steve Yegge
81c741ba05 bd sync: apply DB changes after import 2025-11-20 22:04:22 -05:00
Steve Yegge
db2bc8acb0 Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-20 22:04:22 -05:00
Steve Yegge
21a0656a4c Refactor AGENTS.md: Extract detailed instructions to prevent context pollution
Fixes #340

Created AGENT_INSTRUCTIONS.md to house detailed operational instructions,
reducing AGENTS.md from 963 to 626 lines (~35% reduction).

Changes:
- New AGENT_INSTRUCTIONS.md with development, testing, and release procedures
- AGENTS.md now serves as quick overview with references to detailed docs
- Updated README.md link to "Landing the Plane" section
- Fixed broken team-workflow README links

Benefits:
- Prevents context pollution when multiple tools add instructions
- Better separation: quick reference vs detailed operations
- Enables tool-specific instruction files
- Maintains all content, just reorganized

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 22:04:17 -05:00