Commit Graph

5499 Commits

Author SHA1 Message Date
Travis Cline
8780ec6097 examples: Add complete Go extension example with documentation (#15)
* examples: Add complete Go extension example with documentation

Adds a comprehensive Go extension example demonstrating bd's extension
patterns and Go API usage:

**New bd-example-extension-go package:**
- Complete working example in 116 lines total
- main.go (93 lines): Full workflow with embedded schema
- schema.sql (23 lines): Extension tables with foreign keys
- Comprehensive README.md (241 lines): Documentation and usage guide
- Go module with proper dependencies

**Key patterns demonstrated:**
- Schema extension with namespaced tables (example_executions, example_checkpoints)
- Foreign key integration with bd's issues table
- Dual-layer access using bd's Go API + direct SQL queries
- Complex joined queries across bd and extension tables
- Execution tracking with agent assignment and checkpointing

**Features:**
- Auto-discovery of bd database path
- Proper SQLite configuration (WAL mode, busy timeout)
- Real-world orchestration patterns
- Installation and usage instructions
- Integration examples with bd's ready work queue

This provides a complete reference implementation for developers
building bd extensions, complementing the Go API added in recent commits.

* Update go.mod after merge with main, add .gitignore

- Fix Go version to 1.21 (matches main module)
- Reorganize dependencies properly
- Keep replace directive for local development
- Add .gitignore for built binary

---------

Co-authored-by: Steve Yegge <steve.yegge@gmail.com>
2025-10-14 01:08:00 -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
e3c8554fa2 Release v0.9.1
- Incremental JSONL export for performance
- Auto-migration for seamless upgrades
- Critical bug fixes (race conditions, malformed ID detection)
- ID space partitioning for parallel workers
- Code quality improvements

See CHANGELOG.md for full details.
2025-10-14 00:44:50 -07:00
Steve Yegge
81ab3c3d1b Refactor dependency dirty marking to use shared helper (bd-56)
Replace duplicated dirty-marking logic in AddDependency and
RemoveDependency with a new markIssuesDirtyTx helper function.
This improves code maintainability and ensures consistent behavior.

The Problem:
- AddDependency and RemoveDependency had ~20 lines of duplicated code
- Each manually prepared statements and marked issues dirty
- Violation of DRY principle
- Pattern was fragile if preparation failed

The Fix:
- Created markIssuesDirtyTx() helper in dirty.go
- Takes existing transaction and issue IDs
- Both functions now use: markIssuesDirtyTx(ctx, tx, []string{id1, id2})
- Reduced from 20 lines to 3 lines per function

Benefits:
- Eliminates code duplication (DRY)
- Single source of truth for transaction-based dirty marking
- More readable and maintainable
- Easier to modify behavior in future
- Consistent error messages

Changes:
- internal/storage/sqlite/dirty.go:129-154
  * Add markIssuesDirtyTx() helper function
- internal/storage/sqlite/dependencies.go:115-117, 147-149
  * Replace duplicated code with helper call in both functions

Testing:
- All existing tests pass ✓
- Verified both issues marked dirty with same timestamp ✓
- Dependency add/remove works correctly ✓

Impact:
- Cleaner, more maintainable codebase
- No functional changes, pure refactor
- Foundation for future improvements

Closes bd-56

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 00:35:43 -07:00
Steve Yegge
3aeeeb752c Fix malformed ID detection to actually work (bd-54)
SQLite's CAST to INTEGER never returns NULL - it returns 0 for
invalid strings. This meant the malformed ID detection query was
completely broken and never found any malformed IDs.

The Problem:
- Query used: CAST(suffix AS INTEGER) IS NULL
- SQLite behavior: CAST('abc' AS INTEGER) = 0 (not NULL!)
- Result: Malformed IDs were never detected

The Fix:
- Check if CAST returns 0 AND suffix doesn't start with '0'
- This catches non-numeric suffixes like 'abc', 'foo123'
- Avoids false positives on legitimate IDs like 'test-0', 'test-007'

Changes:
- internal/storage/sqlite/sqlite.go:126-131
  * Updated malformed ID query logic
  * Check: CAST = 0 AND first char != '0'
  * Added third parameter for prefix (used 3 times now)

Testing:
- Created test DB with test-abc, test-1, test-foo123
- Warning correctly shows: [test-abc test-foo123] ✓
- Added test-0, test-007 (zero-prefixed IDs)
- No false positives ✓
- All existing tests pass ✓

Impact:
- Malformed IDs are now properly detected and warned about
- Helps maintain data quality
- Prevents confusion when auto-incrementing IDs

Closes bd-54

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 00:32:42 -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
f3a61a6458 Add auto-migration for dirty_issues table
Implement automatic database migration to add the dirty_issues table
for existing databases that were created before the incremental export
feature (bd-39) was implemented.

Changes:
- Add migrateDirtyIssuesTable() function in sqlite.go
- Check for dirty_issues table existence on database initialization
- Create table and index if missing (silent migration)
- Call migration after schema initialization in New()

The migration:
- Queries sqlite_master to check if dirty_issues table exists
- If missing, creates the table with proper schema and index
- Happens automatically on first database access after upgrade
- No user intervention required
- Fails safely if table already exists (no-op)

Testing:
- Created test database without dirty_issues table
- Verified table was auto-created on first command
- Verified issue was properly marked dirty
- All existing tests pass

This makes the incremental export feature (bd-39) work seamlessly
with existing databases without requiring manual migration steps.

Closes bd-51

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 00:19:10 -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
25644d9717 Cache compiled regexes in ID replacement for 1.9x performance boost
Implements bd-27: Cache compiled regexes in replaceIDReferences for performance

Problem:
replaceIDReferences() was compiling regex patterns on every call. With 100
issues and 10 ID mappings, that resulted in 4,000 regex compilations (100
issues × 4 text fields × 10 ID mappings).

Solution:
- Added buildReplacementCache() to pre-compile all regexes once
- Added replaceIDReferencesWithCache() to reuse compiled regexes
- Updated updateReferences() to build cache once and reuse for all issues
- Kept replaceIDReferences() for backward compatibility (calls cached version)

Performance Results (from benchmarks):
Single text:
- 1.33x faster (26,162 ns → 19,641 ns)
- 68% less memory (25,769 B → 8,241 B)
- 80% fewer allocations (278 → 55)

Real-world (400 texts, 10 mappings):
- 1.89x faster (5.1ms → 2.7ms)
- 90% less memory (7.7 MB → 0.8 MB)
- 86% fewer allocations (104,112 → 14,801)

Tests:
- All existing tests pass
- Added 3 benchmark tests demonstrating improvements

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 23:50:48 -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
252cf9a192 Update issue tracker - close bd-25 as won't-fix
Downgraded bd-25 to P4 and closed as won't-fix for 1.0:
- Transaction support is premature optimization
- SQLite already provides ACID guarantees per-operation
- Collision resolution works reliably without multi-operation transactions
- Would add significant complexity for theoretical benefit

Will revisit if actual issues arise in production use.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 22:59:24 -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
matt wilkie
b7e9fafa3c asked Claude Sonnet 4.5 to assess Supernova and Grok code's work 2025-10-13 22:44:28 -07:00
Steve Yegge
026940c8ae Track code review findings as issues (bd-36 through bd-42)
Added issues tracking code quality findings from the recent auto-flush implementation:
- bd-36: Handle missing JSONL directory in findJSONLPath
- bd-37: Refactor duplicate flush logic in PersistentPostRun
- bd-38: Add visibility for auto-flush failures
- bd-39: Optimize auto-flush to use incremental updates
- bd-40: Make auto-flush debounce duration configurable
- bd-41: Add godoc comments for auto-flush functions
- bd-42: Add test coverage for auto-flush feature

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 22:37:52 -07:00
Steve Yegge
37f3a8da87 Track code review findings as issues (bd-36 through bd-42) 2025-10-13 22:35:29 -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
matt wilkie
0626eae0f9 result of "test all command on windows"
Using KiloCode in Orchestrator mode with
Initially started by 'Code Supernova 1 million' but it kept failing on the tool calls. After switching to Grok Fast 1 the rest went smoothly.
2025-10-13 22:21:36 -07:00
matt wilkie
36f1d44e5c Windows build instructions (tested) 2025-10-13 20:30:59 -07:00
Steve Yegge
00b0292514 README updates 2025-10-13 01:05:57 -07:00
Steve Yegge
31f8367382 wording tweaks 2025-10-12 23:03:30 -07:00
Steve Yegge
4192dd27f5 more pre-launch README tweaks 2025-10-12 23:00:25 -07:00
Steve Yegge
378d98ff92 some more pre-launch tweaks to README.md 2025-10-12 22:24:25 -07:00
Steve Yegge
57e2f0593c more pre-launch README tweaks 2025-10-12 22:18:48 -07:00
Steve Yegge
3e00a32f6f edited the README.md intro 2025-10-12 22:10:44 -07:00
Steve Yegge
aaeff4d9bc Close bd-1: Export/import commands fully implemented
Feature is complete with JSONL format, collision detection, and auto-resolution.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 21:58:43 -07:00
Steve Yegge
fc0b323d57 Clarify multi-project isolation in README
- Updated Features: Multi-project isolation instead of Project-aware
- Expanded FAQ to clearly explain multi-project scenarios
- Added concrete example showing multiple agents on different projects
- Documented limitation: cross-project issue linking not supported
- Emphasized that each project database is completely isolated (no conflicts)

Makes it clear that running bd on multiple projects simultaneously is safe and expected.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 19:14:43 -07:00
Steve Yegge
896a950301 Add collaborative workflow diagram and clarify PostgreSQL status
- Added new diagram showing humans + AI agents + git workflow
- Clarified that PostgreSQL is planned but not yet implemented
- Updated system architecture diagram to distinguish implemented (SQLite) vs planned (PostgreSQL) backends
- Added workflow steps and benefits explanation for collaborative work

The architecture diagrams now accurately reflect current implementation status.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 18:48:53 -07:00
Steve Yegge
5fc61ba285 Add comprehensive Mermaid architecture diagrams to DESIGN.md
Added 5 visual diagrams to document the system architecture:
- System Architecture (layers and components)
- Entity Relationship Diagram (data model)
- Dependency Flow & Ready Work Calculation
- CLI Command Structure
- Data Flow Sequence (create issue workflow)

These diagrams provide a visual overview before diving into the detailed documentation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 17:35:38 -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
42e3bb315d Implement reference scoring algorithm (bd-13)
Add reference scoring to prioritize which colliding issues should be
renumbered during collision resolution. Issues with fewer references
are renumbered first to minimize total update work.

Changes to collision.go:
- Add ReferenceScore field to CollisionDetail
- scoreCollisions() calculates scores and sorts collisions ascending
- countReferences() counts text mentions + dependency references
- Uses word-boundary regex (\b) to match exact IDs (bd-10 not bd-100)

New tests in collision_test.go:
- TestCountReferences: validates reference counting logic
- TestScoreCollisions: verifies scoring and sorting behavior
- TestCountReferencesWordBoundary: ensures exact ID matching

Reference score = text mentions (desc/design/notes/criteria) + deps
Sort order: fewest references first (minimizes renumbering impact)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 16:27:05 -07:00
Steve Yegge
b065b32a51 Implement collision detection for import (bd-12)
Add collision detection infrastructure to identify conflicts during
JSONL import when branches diverge and create issues with the same ID.

New files:
- internal/storage/sqlite/collision.go: Core collision detection logic
  - detectCollisions() categorizes issues as exact matches, collisions, or new
  - compareIssues() identifies which fields differ between issues
  - CollisionDetail provides detailed collision reporting

- internal/storage/sqlite/collision_test.go: Comprehensive test suite
  - Tests exact matches, new issues, and various collision scenarios
  - Tests multi-field conflicts and edge cases
  - All tests passing

This lays the foundation for bd-13 through bd-17 (reference scoring,
ID remapping, CLI flags, and documentation).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 16:22:44 -07:00
Steve Yegge
ee14c811c4 Add bd-24: Support ID space partitioning for parallel worker agents
Enable external orchestrators to control issue ID assignment via --id flag
on bd create and optional next_id config. Keeps beads simple while allowing
orchestrators to implement ID partitioning strategies to minimize merge
conflicts. Complementary to bd-9 collision resolution work.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 16:20:21 -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
f048602d9f Add code review issues (bd-19 to bd-23) 2025-10-12 15:13:37 -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
216f640ab4 Fix getNextID bug and design collision resolution (bd-9)
Critical bug fix: getNextID() was using alphabetical MAX instead of
numerical MAX, causing "bd-9" to be treated as max when "bd-10" existed.
This blocked all new issue creation after bd-10.

Fixed by using SQL CAST to extract and compare numeric portions of IDs.
This ensures bd-10 > bd-9 numerically, not alphabetically.

Also completed comprehensive design for bd-9 (collision resolution):
- Algorithm design with 7 phases (detection, scoring, remapping, etc.)
- Created 7 child issues (bd-10, bd-12-17) breaking down implementation
- Added design documents to .beads/ for future reference
- Updated issues JSONL with new issues and dependencies

Issues created:
- bd-10: Export dependencies in JSONL
- bd-12: Collision detection
- bd-13: Reference scoring algorithm
- bd-14: ID remapping with updates
- bd-15: CLI flags and reporting
- bd-16: Comprehensive tests
- bd-17: Documentation updates
- bd-18: Add design/notes fields to update command

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 14:41:58 -07:00
Steve Yegge
19cd7d1887 Prepare for public launch: comprehensive examples, docs, and tooling
This commit adds everything needed for a successful public launch:

**New Documentation**
- SECURITY.md: Security policy and best practices
- CLAUDE.md: Complete agent instructions for contributing to beads
- Enhanced README with pain points, FAQ, troubleshooting sections
- Added Taskwarrior to comparison table with detailed explanation

**Installation**
- install.sh: One-liner installation script with platform detection
- Auto-detects OS/arch, tries go install, falls back to building from source
- Updated README with prominent installation instructions

**Examples** (2,268+ lines of working code)
- examples/python-agent/: Full Python implementation of agent workflow
- examples/bash-agent/: Shell script agent with colorized output
- examples/git-hooks/: Pre-commit, post-merge, post-checkout hooks with installer
- examples/claude-desktop-mcp/: Documentation for future MCP server integration
- examples/README.md: Overview of all examples

**Dogfooding**
- Initialized bd in beads project itself (.beads/beads.db)
- Created issues for roadmap (MCP server, migrations, demos, 1.0 milestone)
- Exported to .beads/issues.jsonl for git versioning

**Visual Assets**
- Added screenshot showing agent using beads to README intro
- Placed in .github/images/ following GitHub conventions

This addresses all launch readiness items:
 Security policy
 Working agent examples (Python, Bash)
 Git hooks for automation
 FAQ addressing skeptics
 Troubleshooting common issues
 Easy installation
 Dogfooding our own tool
 Pain points that create urgency

Ready to ship! 🚀

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 11:25:29 -07:00
Steve Yegge
a2957f5ee3 Highlight distributed database architecture in README
Added new section "The Magic: Distributed Database via Git" explaining
the key insight: bd provides the illusion of a centralized database
while actually distributing via git.

Key points:
- Feels like centralized DB (query, update from any machine)
- Actually distributed via git (JSONL source of truth)
- Local SQLite cache for fast queries (<100ms)
- No server, daemon, or configuration needed
- AI-assisted conflict resolution for the rare conflicts

Updated Features section:
- 📦 Git-versioned - JSONL records stored in git
- 🌍 Distributed by design - Multiple machines share one logical DB

Updated comparison table to emphasize no-server advantage:
- "Distributed via git" vs "Git-native storage"
- "No server required" vs "Self-hosted"

This clarifies what makes bd unique: you get database-like behavior
(queries, transactions, dependencies) without database-like operations
(server setup, hosting, network config). Just install bd, clone repo.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 10:31:56 -07:00
Steve Yegge
22124d2039 Update README to emphasize agent-first design
Split Quick Start into "For Humans" and "For AI Agents" sections:
- Humans: Just init and add line to CLAUDE.md, then supervise
- Agents: Run quickstart, use --json flags for programmatic workflows

Rewrite "Why bd?" section to clarify the core insight:
- Traditional issue trackers built for humans (web UIs, cards, manual updates)
- bd built for AI agents (JSON APIs, memory, autonomous execution)
- Issues aren't planning artifacts, they're agent memory
- Prevents agents from losing focus during long coding sessions
- Humans supervise rather than micromanage

This reflects the actual design intent: Beads is FOR agents, not just "agent-friendly".

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 10:17:15 -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
Steve Yegge
9105059843 Fix .gitignore to exclude binary but not cmd/beads directory
Changed 'beads' to '/beads' to only ignore the binary in the root,
not the source code directory.

🤖 Generated with Claude Code
2025-10-11 20:07:52 -07:00
Steve Yegge
704515125d Initial commit: Beads issue tracker with security fixes
Core features:
- Dependency-aware issue tracking with SQLite backend
- Ready work detection (issues with no open blockers)
- Dependency tree visualization
- Cycle detection and prevention
- Full audit trail
- CLI with colored output

Security and correctness fixes applied:
- Fixed SQL injection vulnerability in UpdateIssue (whitelisted fields)
- Fixed race condition in ID generation (added mutex)
- Fixed cycle detection to return full paths (not just issue IDs)
- Added cycle prevention in AddDependency (validates before commit)
- Added comprehensive input validation (priority, status, types, etc.)
- Fixed N+1 query in GetBlockedIssues (using GROUP_CONCAT)
- Improved query building in GetReadyWork (proper string joining)
- Fixed P0 priority filter bug (using Changed() instead of value check)

All critical and major issues from code review have been addressed.

🤖 Generated with Claude Code
2025-10-11 20:07:36 -07:00