Commit Graph

41 Commits

Author SHA1 Message Date
Steve Yegge
8dd92dfe7f Merge PR #31: Refactor export file writing to avoid Windows Defender false positives 2025-10-15 11:53:49 -07:00
Matt Wilkie
e2703d3d9b Merge branch 'main' into win-defender-mitigation
# Conflicts:
#	.beads/issues.jsonl
#	README.md
2025-10-15 06:32:44 -07:00
Steve Yegge
953858b853 fix: Resolve race condition in parallel issue creation (bd-89)
Fixed UNIQUE constraint errors when creating multiple issues in parallel.

Root cause: The previous two-step approach used INSERT OR IGNORE to
pre-initialize counters, followed by an UPSERT to increment. Multiple
concurrent transactions could all execute the INSERT OR IGNORE with the
same initial value, causing them to generate duplicate IDs.

Solution: Replaced with a single atomic UPSERT that:
1. Initializes counter from MAX(existing IDs) if needed
2. Updates counter to MAX(current, max existing) + 1 on conflict
3. Returns the final incremented value

This ensures counters are correctly initialized from existing issues
(fixing lazy init tests) while preventing race conditions through the
BEGIN IMMEDIATE transaction serialization.

Tested with 10 parallel processes - all succeeded with unique IDs.

Also added comprehensive profiling test suite for import performance
investigation (bd-199).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-15 02:57:10 -07:00
Steve Yegge
2b03805651 chore: Bump version to 0.9.6
Updated all component versions:
- bd CLI: 0.9.5 → 0.9.6
- Plugin: 0.9.5 → 0.9.6
- MCP server: 0.9.5 → 0.9.6
- Documentation: 0.9.5 → 0.9.6

Generated by scripts/bump-version.sh
2025-10-15 02:32:15 -07:00
Steve Yegge
6b88d60d6e fix: Add collision detection to auto-import (bd-228)
CRITICAL FIX: Auto-import was silently overwriting local changes without any
collision detection or warning. This caused data loss in multi-developer workflows.

Changes:
- Auto-import now uses sqlite.DetectCollisions() before importing
- Colliding issues are skipped (preserves local changes)
- Warning printed with list of skipped issues and resolution instructions
- Added autoImportWithoutCollisionDetection() fallback for non-SQLite backends
- All tests pass

Impact:
- Local changes are now preserved during git pull
- Users are informed when collisions occur
- Can manually resolve with 'bd import --resolve-collisions'
- No more silent data corruption

Also:
- Removed critical warning banner from README
- Created bd-229 for data recovery investigation
- Closed bd-228 as fixed

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-15 02:11:42 -07:00
Steve Yegge
a26dc8a849 feat: Add version mismatch detection for outdated binaries
Prevent user confusion when running outdated bd binaries by detecting
version mismatches between the binary and database.

Features:
- Store bd version in metadata table on init
- Check version on every command (PersistentPreRun)
- Warn if binary is outdated with rebuild instructions
- Auto-upgrade database if binary is newer
- Silent operation when versions match

Fixes confusion from bd-182 (auto-export not working with old binary)
Implements bd-197

Files changed:
- cmd/bd/init.go: Store version on init
- cmd/bd/main.go: checkVersionMismatch() + integration

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-15 00:43:59 -07:00
Steve Yegge
2cc17a9acf chore: Bump version to 0.9.5
Updated all component versions:
- bd CLI: 0.9.4 → 0.9.5
- Plugin: 0.9.4 → 0.9.5
- MCP server: 0.9.4 → 0.9.5
- Documentation: 0.9.4 → 0.9.5

Generated by scripts/bump-version.sh
2025-10-14 19:22:53 -07:00
Steve Yegge
b4e37f9fb5 chore: Bump version to 0.9.4
Updated all component versions:
- bd CLI: 0.9.3 → 0.9.4
- Plugin: 0.9.3 → 0.9.4
- MCP server: 0.9.3 → 0.9.4
- Documentation: 0.9.3 → 0.9.4

Generated by scripts/bump-version.sh
2025-10-14 17:12:30 -07:00
Steve Yegge
f16ba3f30f chore: Bump version to 0.9.3
Release highlights:
- Removed CGO dependency for better portability
- Fixed critical MCP server bugs (path resolution, init tool)
- Improved Claude Code plugin documentation
- Enhanced MCP server configuration robustness
- All 91 tests passing

Major changes since 0.9.2:
1. CGO removal - Pure Go SQLite driver for easier installation
2. MCP init fix - Tool now correctly creates .beads in current directory
3. MCP path resolution - Auto-detects bd executable via PATH
4. Plugin docs - Better quickstart for Claude Code users
5. Config validation - Command names resolved via shutil.which()

Breaking changes: None
Migration: No action needed

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 16:52:45 -07:00
Steve Yegge
50c85635c8 feat: Normalize prefix by stripping trailing hyphens in bd init
Ensures exactly one hyphen between prefix and issue number regardless of
whether user provides trailing hyphen.

Before:
  bd init --prefix wy-  → Issues: wy--1, wy--2 (double hyphen)
  bd init --prefix wy   → Issues: wy-1, wy-2 (single hyphen)

After:
  bd init --prefix wy-  → Issues: wy-1, wy-2 (single hyphen)
  bd init --prefix wy   → Issues: wy-1, wy-2 (single hyphen)

The hyphen is added automatically during ID generation in CreateIssue(),
so the stored prefix should never include trailing hyphens.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 16:15:14 -07:00
Matt Wilkie
6e3498115f feat: refactor export file writing to avoid Windows Defender false positives
- Replace direct file creation with atomic temp file + rename pattern
- Add path validation to prevent writing to sensitive system directories
- Set proper file permissions (0644) on exported files
- Maintain backward compatibility and JSONL export functionality
- Reduce ransomware heuristic triggers through safer file operations
2025-10-14 13:51:34 -07:00
Steve Yegge
92885bb7a3 feat: Add markdown file support to bd create command
Implement `bd create -f file.md` to parse markdown files and create
multiple issues in one command. This enables drafting features in
markdown and converting them to tracked issues.

Features:
- Parse markdown H2 headers (##) as issue titles
- Support all issue fields via H3 sections (### Priority, ### Type, etc.)
- Handle multiple issues per file
- Comprehensive validation and error handling
- Full test coverage with 5 test cases

Closes bd-91 (GH-9)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 13:21:08 -07:00
Steve Yegge
ccdacf087b fix: Auto-export to JSONL now works correctly [fixes #23]
Fixed bug where PersistentPostRun was clearing isDirty flag before
calling flushToJSONL(), causing the flush to abort immediately.

The fix ensures flushToJSONL() handles the isDirty flag itself,
allowing the JSONL export to complete successfully.

Also added Arch Linux AUR installation instructions to README.

Changes:
- cmd/bd/main.go: Fixed PersistentPostRun flush logic
- README.md: Added Arch Linux (AUR) installation section
- .beads/bd.jsonl: Auto-exported issue bd-169 (init -q flag bug)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 12:35:48 -07:00
Travis Cline
69cff96d9d Add BD_ACTOR environment variable for actor override (#21)
Allow BD_ACTOR environment variable to set the default actor name,
providing a cleaner alternative to the --actor flag for automated
workflows.

Priority order for actor determination:
1. --actor flag (highest)
2. BD_ACTOR environment variable
3. USER environment variable
4. "unknown" (fallback)

Updated --actor flag help text to reflect the new environment variable.
2025-10-14 11:10:47 -07:00
Steve Yegge
561e025fc2 chore: Bump version to 0.9.2
Release notes:
- --deps flag for one-command issue creation (#18)
- External reference tracking for linking to external trackers
- Critical bug fixes (dep tree, auto-import, parallel creation)
- Windows build support and Go extension examples
- Community PRs merged (#8, #10, #12, #14, #15, #17)

See CHANGELOG.md for full details.
2025-10-14 03:32:56 -07:00
Steve Yegge
0bff6ef5fd polish: Trim whitespace in --deps flag parsing
Handle edge cases in dependency spec parsing:
- Skip empty dependency specs (e.g., from trailing commas)
- Trim whitespace around type and ID (e.g., 'discovered-from: bd-20')

This makes the flag more forgiving of user input errors.
2025-10-14 03:29:41 -07:00
Steve Yegge
114a78a49b feat: Add --deps flag to bd create for one-command issue creation
Implements GH-18: Allow creating issues with dependencies in a single command.

Changes:
- Add --deps flag to bd create command
- Support format: 'type:id' or just 'id' (defaults to 'blocks')
- Multiple dependencies supported via comma-separated values
- Example: bd create "Fix bug" --deps discovered-from:bd-20,blocks:bd-15
- Updated README.md and CLAUDE.md with examples

This improves the UX for AI agents by reducing two commands (create + dep add)
to a single command, making discovered-from workflows much smoother.

Fixes #18

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 03:26:33 -07:00
Steve Yegge
ea5157e204 fix: Replace mtime-based auto-import with hash-based comparison (bd-84)
The auto-import mechanism previously relied on file modification time
comparison between JSONL and DB. This broke in git workflows because
git doesn't preserve original mtimes - pulled files get fresh timestamps.

Changes:
- Added metadata table for internal state storage (separate from config)
- Replaced mtime comparison with SHA256 hash comparison in autoImportIfNewer()
- Store JSONL hash in metadata after both import and export operations
- Added crypto/sha256 and encoding/hex imports

Benefits:
- Git-proof: Works regardless of file timestamps after git pull
- Universal: Works with git, Dropbox, rsync, manual edits
- Efficient: SHA256 is fast (~20ms for 1MB files)
- Accurate: Only imports when content actually changed
- No user action required: Fully automatic and invisible

Testing:
- All existing tests pass
- Manual testing confirms hash-based import triggers on content changes
- Linter warnings are baseline only (documented in LINTING.md)

This fixes issues where parallel agents in git workflows couldn't
find their assigned issues after git pull because auto-import
silently failed due to stale mtimes.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 02:54:57 -07:00
Steve Yegge
e6be7dd3e8 feat: Add external_ref field for linking to external issue trackers
Add nullable external_ref TEXT field to link bd issues with external
systems like GitHub Issues, Jira, etc. Includes automatic schema
migration for backward compatibility.

Changes:
- Added external_ref column to issues table with feature-based migration
- Updated Issue struct with ExternalRef *string field
- Added --external-ref flag to bd create and bd update commands
- Updated all SQL queries across the codebase to include external_ref:
  - GetIssue, CreateIssue, UpdateIssue, SearchIssues
  - GetDependencies, GetDependents, GetDependencyTree
  - GetReadyWork, GetBlockedIssues, GetIssuesByLabel
- Added external_ref handling in import/export logic
- Follows existing patterns for nullable fields (sql.NullString)

This enables tracking relationships between bd issues and external
systems without requiring changes to existing databases or JSONL files.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 02:43:10 -07:00
Steve Yegge
5c2cff4837 fix: Post-PR #8 critical improvements (bd-64, bd-65, bd-66, bd-67)
This commit addresses all critical follow-up issues identified in the
code review of PR #8 (atomic counter implementation).

## bd-64: Fix SyncAllCounters performance bottleneck (P0)
- Replace SyncAllCounters() on every CreateIssue with lazy initialization
- Add ensureCounterInitialized() that only scans prefix-specific issues on first use
- Performance improvement: O(n) full table scan → O(1) for subsequent creates
- Add comprehensive tests in lazy_init_test.go

## bd-65: Add migration for issue_counters table (P1)
- Add migrateIssueCountersTable() similar to migrateDirtyIssuesTable()
- Checks if table is empty and syncs from existing issues on first open
- Handles both fresh databases and migrations from old databases
- Add comprehensive tests in migration_test.go (3 scenarios)

## bd-66: Make import counter sync failure fatal (P1)
- Change SyncAllCounters() failure from warning to fatal error in import
- Prevents ID collisions when counter sync fails
- Data integrity > convenience

## bd-67: Update test comments (P2)
- Update TestMultiProcessIDGeneration comments to reflect fix is in place
- Change "With the bug, we expect errors" → "After the fix, all should succeed"

All tests pass. Atomic counter implementation is now production-ready.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 01:57:43 -07:00
v4rgas
367259168d fix: renumber phases in import.go (Phase 4.5 → Phase 5, Phase 5 → Phase 6) 2025-10-14 01:19:11 -07:00
v4rgas
73f5acadfa fix: sync ID counters after import to prevent collisions
When importing issues with explicit high IDs (e.g., bd-100), the
issue_counters table wasn't being updated. This caused the next
auto-generated issue to collide with existing IDs (bd-4 instead of bd-101).

Changes:
- Add SyncAllCounters() to scan all issues and update counters atomically
- Add SyncCounterForPrefix() for granular counter synchronization
- Call SyncAllCounters() in import command after creating issues
- Add comprehensive tests for counter sync functionality
- Update TestImportCounterSyncAfterHighID to verify fix

The fix uses a single efficient SQL query to prevent ID collisions
with subsequently auto-generated issues.
2025-10-14 01:19:03 -07:00
v4rgas
187d291647 test: add failing test for ID counter sync after import
TestImportCounterSyncAfterHighID demonstrates that importing an issue
with a high explicit ID (bd-100) doesn't sync the auto-increment counter,
causing the next auto-generated ID to be bd-4 instead of bd-101.

This test currently fails and documents the expected behavior.
2025-10-14 01:18:50 -07:00
Eli
f3a3d31dc2 Fix quickstart EXTENDING.md reference to use full URL (#12)
The quickstart command referenced EXTENDING.md as if it were a local file,
which was confusing for users running bd in their own projects. Now it
clearly points to the upstream documentation with a full GitHub URL.

- Changed from "See EXTENDING.md" to "See database extension docs"
- Added full URL to the original repo's EXTENDING.md
- Preserved the original "integration patterns" context

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

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-14 01:10:18 -07:00
Travis Cline
3b2c60d294 Better enable go extensions (#14)
* deps: run go mod tidy

* beads: Add public Go API for bd extensions

Implements a minimal public API to enable Go-based extensions without
exposing internal packages:

**New beads.go package:**
- Exports essential types: Issue, Status, IssueType, WorkFilter
- Provides status and issue type constants
- Exposes NewSQLiteStorage() as main entry point for extensions
- Includes comprehensive package documentation

**Updated EXTENDING.md:**
- Replaced internal package imports with public beads package
- Updated function calls to use new public API
- Changed sqlite.New() to beads.NewSQLiteStorage()
- Updated GetReady() to GetReadyWork() with WorkFilter

This enables clean Go-based orchestration extensions while maintaining
API stability and hiding internal implementation details.

* beads: Refine Go extensions API and documentation

Updates to the public Go API implementation following initial commit:

- Enhanced beads.go with refined extension interface
- Updated EXTENDING.md with clearer documentation
- Modified cmd/bd/main.go to support extension loading

Continues work on enabling Go-based bd extensions.

* Fix EXTENDING.md to use beads.WorkFilter instead of types.WorkFilter

The public API exports WorkFilter as beads.WorkFilter, not types.WorkFilter.
This fixes the code example to match the imports shown.

---------

Co-authored-by: Steve Yegge <steve.yegge@gmail.com>
2025-10-14 01:06:35 -07:00
Travis Cline
9f28d07a8a beads: Show issue type in bd list output (#17)
Updated the list command to display issue type alongside priority and status.

Before:
  beads-48 [P1] open

After:
  beads-48 [P1] [epic] open

This makes it easier to distinguish between bugs, features, tasks, epics, and
chores at a glance without using --json or bd show.
2025-10-14 01:03:53 -07:00
Steve Yegge
92759710de Fix race condition in dirty issue tracking (bd-52, bd-53)
Fix critical TOCTOU bug where concurrent operations could lose dirty
issue tracking, causing data loss in incremental exports. Also fixes
bug where export with filters would incorrectly clear all dirty issues.

The Problem:
1. GetDirtyIssues() returns [bd-1, bd-2]
2. Concurrent CRUD marks bd-3 dirty
3. Export writes bd-1, bd-2
4. ClearDirtyIssues() deletes ALL (including bd-3)
5. Result: bd-3 never gets exported!

The Fix:
- Add ClearDirtyIssuesByID() that only clears specific issue IDs
- Track which issues were actually exported
- Clear only those specific IDs, not all dirty issues
- Fixes both race condition and filter export bug

Changes:
- internal/storage/sqlite/dirty.go:
  * Add ClearDirtyIssuesByID() method
  * Add warning to ClearDirtyIssues() about race condition
- internal/storage/storage.go:
  * Add ClearDirtyIssuesByID to interface
- cmd/bd/main.go:
  * Update auto-flush to use ClearDirtyIssuesByID()
- cmd/bd/export.go:
  * Track exported issue IDs
  * Use ClearDirtyIssuesByID() instead of ClearDirtyIssues()

Testing:
- Created test-1, test-2, test-3 (all dirty)
- Updated test-2 to in_progress
- Exported with --status open filter (exports only test-1, test-3)
- Verified only test-2 remains dirty ✓
- All existing tests pass ✓

Impact:
- Race condition eliminated - concurrent operations are safe
- Export with filters now works correctly
- No data loss from competing writes

Closes bd-52, bd-53

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 00:29:23 -07:00
Steve Yegge
bafb2801c5 Implement incremental JSONL export with dirty issue tracking
Optimize auto-flush by tracking which issues have changed instead of
exporting the entire database on every flush. For large projects with
1000+ issues, this provides significant performance improvements.

Changes:
- Add dirty_issues table to schema with issue_id and marked_at columns
- Implement dirty tracking functions in new dirty.go file:
  * MarkIssueDirty() - Mark single issue as needing export
  * MarkIssuesDirty() - Batch mark multiple issues efficiently
  * GetDirtyIssues() - Query which issues need export
  * ClearDirtyIssues() - Clear tracking after successful export
  * GetDirtyIssueCount() - Monitor dirty issue count
- Update all CRUD operations to mark affected issues as dirty:
  * CreateIssue, UpdateIssue, DeleteIssue
  * AddDependency, RemoveDependency (marks both issues)
  * AddLabel, RemoveLabel, AddEvent
- Modify export to support incremental mode:
  * Add --incremental flag to export only dirty issues
  * Used by auto-flush for performance
  * Full export still available without flag
- Add Storage interface methods for dirty tracking

Performance impact: With incremental export, large databases only write
changed issues instead of regenerating entire JSONL file on every
auto-flush.

Closes bd-39

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 00:17:23 -07:00
Steve Yegge
33412871eb Add comprehensive test coverage for auto-flush feature
Implements bd-42: Add test coverage for auto-flush feature

Created cmd/bd/main_test.go with 11 comprehensive test functions:
- TestAutoFlushDirtyMarking: Verifies markDirtyAndScheduleFlush() marks DB as dirty
- TestAutoFlushDisabled: Tests --no-auto-flush flag disables feature
- TestAutoFlushDebounce: Tests rapid operations result in single flush
- TestAutoFlushClearState: Tests clearAutoFlushState() resets state
- TestAutoFlushOnExit: Tests flush happens on program exit
- TestAutoFlushConcurrency: Tests concurrent operations don't cause races
- TestAutoFlushStoreInactive: Tests flush skips when store is inactive
- TestAutoFlushJSONLContent: Tests flushed JSONL has correct content
- TestAutoFlushErrorHandling: Tests error scenarios (permissions, etc.)
- TestAutoImportIfNewer: Tests auto-import when JSONL is newer than DB
- TestAutoImportDisabled: Tests --no-auto-import flag disables auto-import

Coverage results:
- markDirtyAndScheduleFlush: 100%
- clearAutoFlushState: 100%
- flushToJSONL: 67.6%
- autoImportIfNewer: 66.1% (up from 0%)

All tests pass. Auto-flush feature is now thoroughly tested.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 23:38:24 -07:00
Steve Yegge
a8a90e074e Add ID space partitioning and improve auto-flush reliability
Three improvements to beads:

1. ID space partitioning (closes bd-24)
   - Add --id flag to 'bd create' for explicit ID assignment
   - Validates format: prefix-number (e.g., worker1-100)
   - Enables parallel agents to partition ID space and avoid conflicts
   - Storage layer already supported this, just wired up CLI

2. Auto-flush failure tracking (closes bd-38)
   - Track consecutive flush failures with counter and last error
   - Show prominent red warning after 3+ consecutive failures
   - Reset counter on successful flush
   - Users get clear guidance to run manual export if needed

3. Manual export cancels auto-flush timer
   - Add clearAutoFlushState() helper function
   - bd export now cancels pending auto-flush and clears dirty flag
   - Prevents redundant exports when user manually exports
   - Also resets failure counter on successful manual export

Documentation updated in README.md and CLAUDE.md with --id flag examples.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 23:31:51 -07:00
Steve Yegge
12a4c384af Fix: Ensure JSONL directory exists in findJSONLPath
Added os.MkdirAll(dbDir, 0755) to ensure the .beads directory exists
before attempting to glob for JSONL files. This fixes a bug where
findJSONLPath() would fail silently if the directory doesn't exist yet,
which can happen during new database initialization.

The fix:
- Creates the directory with 0755 permissions if it doesn't exist
- Handles errors gracefully by returning the default path
- Subsequent write operations will still fail with clear errors if
  directory creation fails

Closes bd-36

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 22:51:04 -07:00
Steve Yegge
584cd1ebfc Implement auto-import to complete automatic git sync workflow
Adds auto-import feature to complement bd-35's auto-export, completing
the automatic sync workflow for git collaboration.

**Implementation:**
- Auto-import checks if JSONL is newer than DB on command startup
- Silently imports JSONL when modification time is newer
- Skips import command itself to avoid recursion
- Can be disabled with --no-auto-import flag

**Documentation updates:**
- Updated README.md git workflow section
- Updated CLAUDE.md workflow and pro tips
- Updated bd quickstart with auto-sync section
- Updated git hooks README to clarify they're now optional

**Testing:**
- Tested auto-import by touching JSONL and running commands
- Tested auto-export with create/close operations
- Complete workflow verified working

Closes bd-33

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 22:48:30 -07:00
Steve Yegge
97d78d264f Fix critical race conditions in auto-flush feature
Fixed three critical issues identified in code review:

1. Race condition with store access: Added storeMutex and storeActive
   flag to prevent background flush goroutine from accessing closed
   store. Background timer now safely checks if store is active before
   attempting flush operations.

2. Missing auto-flush in import: Added markDirtyAndScheduleFlush()
   call after import completes, ensuring imported issues sync to JSONL.

3. Timer cleanup: Explicitly set flushTimer to nil after Stop() to
   prevent resource leaks.

Testing confirmed all fixes working:
- Debounced flush triggers after 5 seconds of inactivity
- Immediate flush on process exit works correctly
- Import operations now trigger auto-flush
- No race conditions detected

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 22:34:12 -07:00
Steve Yegge
54f76543ad Pre-release fixes and polish for open source launch
Fixed critical issues identified in code review:
- Fixed invalid Go version (1.25.2 → 1.21) in go.mod
- Fixed unchecked error in import.go JSON unmarshaling
- Fixed unchecked error returns in test cleanup (export_import_test.go, import_collision_test.go)
- Removed duplicate test code in dependencies_test.go via helper function

Added release infrastructure:
- Added 'bd version' command with JSON output support
- Created comprehensive CHANGELOG.md following Keep a Changelog format
- Updated README.md with clear alpha status warnings

All tests passing. Ready for public repository opening.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 17:28:48 -07:00
Steve Yegge
183ded4096 Add collision resolution with automatic ID remapping
Implements --resolve-collisions flag for import command to safely handle ID
collisions during branch merges. When enabled, colliding issues are remapped
to new IDs and all text references and dependencies are automatically updated.

Also adds comprehensive tests, branch-merge example, and documentation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 17:13:09 -07:00
Steve Yegge
3440899850 Fix code review issues bd-19 through bd-23
- bd-19: Fix import zero-value field handling using JSON presence detection
- bd-20: Add --strict flag for dependency import failures
- bd-21: Simplify getNextID SQL query (reduce params from 4 to 2)
- bd-22: Add validation/warning for malformed issue IDs
- bd-23: Optimize export dependency queries (fix N+1 problem)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 15:30:11 -07:00
Steve Yegge
8d3bbbcc52 Implement bd-10: Export/import dependencies in JSONL
Added dependency support to export/import workflow:

Changes:
- Added GetDependencyRecords() to Storage interface to get raw dependency records
- Extended Issue struct with Dependencies field (omitempty for backward compat)
- Modified export.go to populate dependencies for each issue
- Modified import.go to process dependencies in second pass after all issues exist
- All tests pass

Benefits:
- JSONL is now self-contained with full dependency information
- Enables proper collision resolution in future (bd-12+)
- Idempotent imports: existing dependencies are not duplicated
- Forward references handled: dependencies created after all issues exist

Example output:
{
  "id": "bd-10",
  "title": "...",
  "dependencies": [{
    "issue_id": "bd-10",
    "depends_on_id": "bd-9",
    "type": "parent-child",
    "created_at": "...",
    "created_by": "stevey"
  }]
}

Closes bd-10

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 15:08:05 -07:00
Steve Yegge
2c7708eaa7 Address remaining golangci-lint findings
- Add package comment to cmd/bd/dep.go
- Change directory permissions from 0755 to 0750 in init.go
- Simplify getNextID signature (remove unused error return)
- Configure golangci-lint exclusions for false positives
- Document linting policy in LINTING.md

The remaining ~100 lint warnings are documented false positives:
- 73 errcheck: deferred cleanup (idiomatic Go)
- 17 revive: Cobra interface requirements and naming choices
- 7 gosec: false positives on validated SQL and user file paths
- 2 dupl: acceptable test code duplication
- 1 goconst: test constant repetition

See LINTING.md for full rationale. Contributors should focus on
avoiding NEW issues rather than the documented baseline.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 09:48:22 -07:00
Steve Yegge
87ed7c8793 Polish for open-source release
Major improvements to code quality, documentation, and CI:

Code Quality:
- Add golangci-lint configuration with 13 linters
- Fix unchecked error returns in export/import/init
- Refactor duplicate scanIssues code
- Add package comments for all packages
- Add const block comments for exported constants
- Configure errcheck to allow idiomatic defer patterns

Documentation:
- Add comprehensive CONTRIBUTING.md with setup, testing, and workflow
- Fix QUICKSTART.md binary name references (beads → bd)
- Correct default database path documentation

CI/CD:
- Add GitHub Actions workflow for tests and linting
- Enable race detection and coverage reporting
- Automated quality checks on all PRs

All tests passing. Lint issues reduced from 117 to 103 (remaining are
idiomatic patterns and test code). Ready for open-source release.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 09:41:29 -07:00
Steve Yegge
9a768ba4a3 Add comprehensive test coverage for types and export/import
## Test Coverage Improvements

**Before:**
- cmd/bd: 0%
- internal/types: 0%
- internal/storage/sqlite: 57.8%

**After:**
- cmd/bd: 8.5%
- internal/types: 100%
- internal/storage/sqlite: 57.8%

## New Tests

### types_test.go (100% coverage)
- TestIssueValidation: All validation rules (title, priority, status, etc.)
- TestStatusIsValid: All status values
- TestIssueTypeIsValid: All issue types
- TestDependencyTypeIsValid: All dependency types
- TestIssueStructFields: Time field handling
- TestBlockedIssueEmbedding: Embedded struct access
- TestTreeNodeEmbedding: Tree node structure

### export_import_test.go (integration tests)
- TestExportImport: Full export/import workflow
  - Export with sorting verification
  - JSONL format validation
  - Import creates new issues
  - Import updates existing issues
  - Export with status filtering
- TestExportEmpty: Empty database handling
- TestImportInvalidJSON: Error handling for malformed JSON
- TestRoundTrip: Data integrity verification (all fields preserved)

## Test Quality
- Uses table-driven tests for comprehensive coverage
- Tests both happy paths and error cases
- Validates JSONL format correctness
- Ensures data integrity through round-trip testing
- Covers edge cases (empty DB, invalid JSON, pointer fields)

All tests passing 

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 01:24:21 -07:00
Steve Yegge
15afb5ad17 Implement JSONL export/import and shift to text-first architecture
This is a fundamental architectural shift from binary SQLite to JSONL as
the source of truth for git workflows.

## New Features

- `bd export --format=jsonl` - Export issues to JSON Lines format
- `bd import` - Import issues from JSONL (create new, update existing)
- `--skip-existing` flag for import to only create new issues

## Architecture Change

**Before:** Binary SQLite database committed to git
**After:** JSONL text files as source of truth, SQLite as ephemeral cache

Benefits:
- Git-friendly text format with clean diffs
- AI-resolvable merge conflicts (append-only is 95% conflict-free)
- Human-readable issue tracking in git
- No binary merge conflicts

## Documentation

- Updated README with JSONL-first workflow and git hooks
- Added TEXT_FORMATS.md analyzing JSONL vs CSV vs binary
- Updated GIT_WORKFLOW.md with historical context
- .gitignore now excludes *.db, includes .beads/*.jsonl

## Implementation Details

- Export sorts issues by ID for consistent diffs
- Import handles both creates and updates atomically
- Proper handling of pointer fields (EstimatedMinutes)
- All tests passing

## Breaking Changes

- Database files (*.db) should now be gitignored
- Use export/import workflow for git collaboration
- Git hooks recommended for automation

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 01:17:50 -07:00