Commit Graph

642 Commits

Author SHA1 Message Date
Steve Yegge
bf74160f05 Fix GH#366: Encourage descriptions when creating issues
Addresses GitHub Discussion #366 where users reported Claude Code
creating issues with titles but no descriptions.

Two-pronged solution:

1. Documentation improvements (bd-na8r):
   - Updated AGENTS.md with prominent guidance section
   - Added good/bad examples showing why/what/how to include
   - Updated all bd create examples to include --description
   - Enhanced MCP tool docstring with importance note
   - Updated .github/copilot-instructions.md

2. Code validation (bd-bcrt):
   - Added friendly yellow warning when description is empty
   - Warning skips test issues (title contains "test")
   - Works in both CLI and daemon modes
   - Non-blocking to preserve quick workflows

Evidence from our own projects showed significant empty description
rates:
- ~/src/beads: 110/630 (17.5%)
- ~/wyvern: 8/119 (6.7%)
- ~/src/vc: 3/170 (1.8%)

Fixes bd-0tr0, bd-na8r, bd-bcrt

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 14:14:40 -08:00
Steve Yegge
e75b228576 Add tests and documentation for --shared hooks feature
- Fix existing tests to work with new installHooks signature
- Add TestInstallHooksShared to verify shared hooks functionality
- Update git-hooks README with comprehensive --shared documentation
- Document benefits, use cases, and workflow for shared hooks
2025-11-23 12:39:11 -08:00
Steve Yegge
1845b7d984 Add --shared flag to bd hooks install for versioned hooks
Implements support for installing git hooks to a versioned directory
(.beads-hooks/) that can be committed to the repository and shared with
team members. This solves the team collaboration issue where hooks need
to be installed in pre-built containers.

Changes:
- Add --shared flag to 'bd hooks install' command
- Install hooks to .beads-hooks/ when --shared is used
- Automatically configure git config core.hooksPath
- Update help text to explain shared mode

Fixes #229
2025-11-23 12:36:38 -08:00
Steve Yegge
012bed1068 Fix GH#367: bd import defaulting to stdin is confusing
Changes:
1. Add TTY detection to bd import - prevents silent hang when run
   interactively without arguments. Shows helpful usage message instead.
2. Fix misleading error messages - change "Run 'bd import'" to
   "Run 'bd sync --import-only'" or explicit file path throughout.

Technical details:
- Added golang.org/x/term dependency for IsTerminal()
- When stdin is a TTY and no -i flag: show usage and exit
- When stdin is piped: works as before (supports script pipelines)
- Preserved all legitimate stdin uses:
  * python gh2jsonl.py --repo owner/repo | bd import
  * python md2jsonl.py feature.md | bd import
  * git show HEAD:.beads/beads.jsonl | bd import -i /dev/stdin

Updated error messages in:
- cmd/bd/staleness.go - main "out of sync" error
- cmd/bd/sync.go - merge completion suggestions
- internal/rpc/server_export_import_auto.go - daemon warnings

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 11:15:34 -08:00
Steve Yegge
0dc8452c56 feat: Respect BEADS_SYNC_BRANCH environment variable
Fixes daemon and bd sync to honor BEADS_SYNC_BRANCH environment variable
as documented in PROTECTED_BRANCHES.md for CI/CD temporary overrides.

Changes:
- Updated internal/syncbranch.Get() to prioritize env var over DB config
- Both daemon sync and bd sync CLI now use syncbranch.Get()
- Added comprehensive tests for env var override behavior
- Validates branch names using git-style rules

This enables CI/CD workflows to override sync branch per-job without
mutating database config.

Based on PR #364 by Charles P. Cross <cpdata@users.noreply.github.com>
Co-authored-by: Charles P. Cross <cpdata@users.noreply.github.com>
2025-11-22 18:17:19 -08:00
Charles P. Cross
ea7b39e40b Fix: Use dynamic JSONL path in daemon sync branch operations (#361)
Fixes #359

The daemon's sync branch logic was hardcoding the JSONL path to .beads/beads.jsonl, ignoring the dynamic discovery logic used elsewhere. This caused sync failures in repositories where the JSONL file has a different name (e.g., beads.base.jsonl, issues.jsonl).

Changes:
- Updated cmd/bd/daemon_sync_branch.go to use findJSONLPath() instead of hardcoded path
- Implemented relative path calculation for correct worktree placement
- Applied fix to both push (sync to worktree) and pull (sync from worktree) operations

This works together with PR #360 to fix team/protected branch sync issues.

Co-authored-by: Charles P. Cross <cpdata@users.noreply.github.com>
2025-11-22 16:57:39 -08:00
Charles P. Cross
9a2345f706 Fix: Daemon respects auto-commit/auto-push DB config (#360)
Fixes #358

The daemon was ignoring daemon.auto_commit and daemon.auto_push configuration values stored in the database unless the corresponding CLI flags were explicitly provided. This prevented bd init --team configuration from working as expected.

Changes:
- Modified cmd/bd/daemon.go to check database config when flags are not explicitly set
- Uses beads.FindDatabasePath() to locate the database and sqlite.New() to read config
- Only applies when starting daemon (skips for --stop, --status, --health, etc.)

Co-authored-by: Charles P. Cross <cpdata@users.noreply.github.com>
2025-11-22 16:57:23 -08:00
cerebustech-dev
3aeca3413a fix: skip /etc/passwd check on Windows in security test (#363)
Fixes #362

The test TestCleanupMergeArtifacts_CommandInjectionPrevention was failing on Windows because it checks for /etc/passwd, which is a Unix-specific file that doesn't exist on Windows.

Added runtime.GOOS check to skip the /etc/passwd verification on Windows while maintaining the security check on Unix systems.
2025-11-22 16:49:29 -08:00
Steve Yegge
599c40c703 Fix Windows and Nix test failures
Windows test fixes (bd-web8):
- Add sanitizeMetadataKey() to replace colons with underscores
- Windows absolute paths (e.g., C:\...) contain colons that conflict with
  metadata key separator ':'
- Update tests to use sanitized keys when checking metadata
- Tests now pass on Windows by auto-sanitizing path-based keys

Nix flake fixes (bd-8y1a):
- Update vendorHash in default.nix to match current Go module dependencies
- Hash mismatch was causing Nix build failures in CI

Test improvements:
- Rename TestUpdateExportMetadataInvalidKeySuffix to reflect new behavior
- Test now verifies sanitization instead of rejection
- All tests pass locally

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 10:59:40 -08:00
Steve Yegge
b409870ce5 Fix linter issues and test failures
- Fix spelling: cancelled → canceled, cancelling → canceling
- Remove unused error return from performFlush() function
- Check cmd.Help() error return in search.go
- Fix file permissions in gitignore.go (0644 → 0600)
- Update tests to match performFlush signature change
- Remove unused os import from flush_manager.go
2025-11-22 00:11:45 -08:00
Steve Yegge
7009acb169 chore: Bump version to 0.24.2
Updated all component versions:
- bd CLI: 0.24.1 → 0.24.2
- Plugin: 0.24.1 → 0.24.2
- MCP server: 0.24.1 → 0.24.2
- npm package: 0.24.1 → 0.24.2
- Documentation: 0.24.1 → 0.24.2

Generated by scripts/bump-version.sh
2025-11-22 00:06:13 -08:00
Steve Yegge
87ee3a674e Improve bd doctor JSONL checks to focus on real problems
Previously bd doctor warned about using beads.jsonl vs issues.jsonl, but
users should be free to configure any name they want. The real problems are:
1. Having multiple JSONL files (sync/merge conflicts)
2. Configuration not matching reality

Changes:
- Rewrote CheckLegacyJSONLFilename to scan for ALL .jsonl files
- Now filters out merge artifacts (backup, .orig, .bak, etc.)
- Warns only when multiple real JSONL files exist
- Added CheckDatabaseConfig to detect when configured paths do not match
  what actually exists on disk
- Updated tests to verify backup files are ignored
- Added test cases for custom JSONL filenames

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 23:44:26 -08:00
Steve Yegge
c4c5c8063a Fix: Change default JSONL filename from beads.jsonl to issues.jsonl
The canonical beads database name is issues.jsonl. Tens of thousands of users
have issues.jsonl, and beads.jsonl was only used by the Beads project itself
due to git history pollution.

Changes:
- Updated bd doctor to warn about beads.jsonl instead of issues.jsonl
- Changed default config from beads.jsonl to issues.jsonl
- Reversed precedence in checkGitForIssues to prefer issues.jsonl
- Updated git merge driver config to use issues.jsonl
- Updated all tests to expect issues.jsonl as the default

issues.jsonl is now the canonical default; beads.jsonl is legacy

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 23:34:22 -08:00
Steve Yegge
a517ec98aa Fix: TestGetAssignedStatus - Missing rootCtx initialization
Failure Type: Real
Root Cause: Test was not initializing the global rootCtx variable that getAssignedStatus depends on, causing it to return nil
Fix Applied: Added rootCtx initialization with proper cleanup using defer, matching the pattern used in other tests
Verification: All tests now pass (go test ./...)

Fixes bd-9f86-baseline-test

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 23:22:12 -08:00
Steve Yegge
b8db5ab6fc fix(test): Complete rootCtx initialization fix for all hanging tests (issue #355)
Problem:
- TestFallbackToDirectModeEnablesFlush hung with database deadlock
- TestIdempotentImportNoTimestampChurn and TestImportMultipleUnchangedIssues also hung
- All three tests call flushToJSONL() or autoImportIfNewer() which require rootCtx

Solution:
Applied the same rootCtx initialization pattern from v0.24.1 (commit 822baa0)
to the remaining hanging tests:
- TestFallbackToDirectModeEnablesFlush in direct_mode_test.go
- TestIdempotentImportNoTimestampChurn in import_idempotent_test.go
- TestImportMultipleUnchangedIssues in import_idempotent_test.go

Results:
- Before: Tests hung for 5+ minutes with database deadlock
- After: All tests pass in ~0.1s each

Fixes #355

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 23:09:47 -08:00
Steve Yegge
7dc8c15acb chore: Bump version to 0.24.1 2025-11-21 22:06:07 -08:00
Steve Yegge
787fb4e56f feat: Add date and priority filters to bd search (bd-au0.5)
Adds missing date range and priority filtering to bd search for feature
parity with bd list. Part of command standardization epic (bd-au0).

Changes:
- Add date range flags: --created-after/before, --updated-after/before,
  --closed-after/before
- Add priority range flags: --priority-min, --priority-max
- Support multiple date formats (RFC3339, YYYY-MM-DD, etc.)
- Apply filters in both direct mode and daemon RPC mode
- Add comprehensive tests for new filters

Examples:
  bd search "security" --priority-min 0 --priority-max 2
  bd search "bug" --created-after 2025-01-01
  bd search "refactor" --updated-after 2025-01-01 --priority-min 1

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 22:46:12 -05:00
Steve Yegge
3065db261e feat: Add label operations to bd update command
Implements bd-au0.2, completing all P0 tasks in the command standardization epic.

Changes:
- Add --add-label, --remove-label, --set-labels flags to bd update
- Support multiple labels via repeatable flags
- Implement in both daemon and direct modes
- Add comprehensive tests for all label operations

The bd update command now supports:
  bd update <id> --add-label <label>       # Add one or more labels
  bd update <id> --remove-label <label>    # Remove one or more labels
  bd update <id> --set-labels <labels>     # Replace all labels

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 22:17:26 -05:00
Steve Yegge
99e3d21f35 Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-21 21:57:26 -05:00
Steve Yegge
2e2b8d7c2c feat: Accept both integer and P-format for priority flags in bd list
Implements bd-au0.4: Standardize priority flag parsing across all commands.

Changes:
- Use registerPriorityFlag() for main priority flag (was IntP)
- Change priority-min/max from Int to String flags
- Add validation import and use ValidatePriority() for all priority parsing
- Update both direct mode and daemon RPC code paths

Now supports both formats consistently:
- Numeric: --priority 0, --priority-min 1, --priority-max 2
- P-format: --priority P0, --priority-min P1, --priority-max P2

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 21:57:23 -05:00
Steve Yegge
fa727c7d73 refactor: Delete 7 redundant tests from main_test.go (3x speedup)
Problem: main_test.go was testing deprecated legacy path after FlushManager
refactoring (bd-52), duplicating coverage from flush_manager_test.go.

Solution: Delete redundant tests, keep only unique integration tests.

Changes:
- Deleted 7 tests (407 lines) covered by flush_manager_test.go:
  * TestAutoFlushDirtyMarking → TestFlushManagerMarkDirtyTriggersFlush
  * TestAutoFlushDisabled → TestFlushManagerDisabledDoesNotFlush
  * TestAutoFlushDebounce (already skipped, obsolete)
  * TestAutoFlushClearState (tested implicitly in export/sync)
  * TestAutoFlushConcurrency → TestFlushManagerConcurrentMarkDirty
  * TestAutoFlushStoreInactive → TestPerformFlushStoreInactive
  * TestAutoFlushErrorHandling → TestPerformFlushErrorHandling

- Kept 2 unique integration tests:
  * TestAutoFlushOnExit (tests PersistentPostRun)
  * TestAutoFlushJSONLContent (tests actual JSONL output)

- Updated clearAutoFlushState() to no-op when FlushManager exists

Results:
- Before: 18 tests, 1079 lines, ~15-20s
- After: 11 tests, 672 lines, ~5-7s
- Speedup: ~3x faster
- All tests passing 

Files:
- cmd/bd/main_test.go: Deleted 7 tests, removed unused imports
- cmd/bd/autoflush.go: Updated clearAutoFlushState()
- docs/MAIN_TEST_REFACTOR_NOTES.md: Documented solution
- docs/MAIN_TEST_CLEANUP_PLAN.md: Created detailed plan

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 21:29:43 -05:00
Steve Yegge
605fff151e feat: Add GitHub Copilot support with .github/copilot-instructions.md
Addresses GH #298 - GitHub Copilot inconsistently interpreting AGENTS.md

Changes:
- Create .github/copilot-instructions.md (132 lines, Copilot-optimized)
- Update AGENTS.md with prominent Copilot callout
- Enhance bd onboard command to generate copilot-instructions.md

Architecture: Two-file approach for different AI agents
- AGENTS.md (626 lines): Comprehensive guide for all AI agents
- .github/copilot-instructions.md (132 lines): Concise, auto-loaded for Copilot

Note: Untested with GitHub Copilot yet. Feedback from Copilot users welcome!

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-21 20:52:18 -05:00
Steve Yegge
6e702d3ecd Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-21 20:40:23 -05:00
Steve Yegge
ddd209e26a fix: Correct git merge driver placeholders from %L/%R to %A/%B
Git merge drivers only support three placeholders:
- %O (ancestor/base)
- %A (current version)
- %B (other branch's version)

The code was incorrectly using %L and %R, which don't exist in git,
causing them to be passed through literally and breaking JSONL merges.

Changes:
- Fixed merge driver config in init.go, merge.go, README.md, docs
- Added detection in bd doctor with clear error messages
- Added auto-fix in bd doctor --fix
- Added proactive warning in bd sync before git pull
- Added reactive error detection after merge failures
- Updated all tests to use correct placeholders

Now users get helpful guidance at every step:
1. bd doctor detects the issue
2. bd doctor --fix auto-corrects it
3. bd sync warns before pulling if misconfigured
4. Error messages suggest bd doctor --fix when merge fails

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 20:40:18 -05:00
Steve Yegge
8efab3df87 chore: Move design/audit docs from cmd/bd to docs/
Relocate documentation files to centralize all .md files in docs/ directory
(except those with historical precedent in specific locations like commands/,
examples/, integrations/, etc.).

Files moved:
- cmd/bd/doctor/claude.md -> docs/CLAUDE_INTEGRATION.md
- cmd/bd/MAIN_TEST_REFACTOR_NOTES.md -> docs/MAIN_TEST_REFACTOR_NOTES.md
- cmd/bd/TEST_SUITE_AUDIT.md -> docs/TEST_SUITE_AUDIT.md

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 20:31:47 -05:00
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
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
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
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
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
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
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
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
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
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