Add Beads library API for Go integration
Expose full Storage interface and all types through public beads.go API, enabling external Go projects (like VC) to import Beads directly instead of spawning CLI processes. Changes: - Expanded beads.go with all public types (Issue, Dependency, Comment, etc.) - Added all constants (Status, IssueType, DependencyType, EventType) - Created comprehensive integration tests (beads_integration_test.go) - Added library usage example at examples/library-usage/ - Documented library integration in README.md Test coverage: 96.4% on public API, 14 integration tests, all passing. Closes bd-58, bd-59 Amp-Thread-ID: https://ampcode.com/threads/T-f0093c79-7422-45e2-b0ed-0ddfebc9ffea Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
41
README.md
41
README.md
@@ -777,6 +777,47 @@ bd ensures only one daemon runs per repository using file locking:
|
||||
|
||||
The lock file is the single source of truth for daemon status. Commands like `bd daemon --status` check lock availability rather than PID file contents, eliminating race conditions where multiple daemons could start simultaneously.
|
||||
|
||||
## Using Beads as a Library
|
||||
|
||||
For Go projects that need deeper integration, import Beads directly instead of spawning CLI processes:
|
||||
|
||||
```go
|
||||
import "github.com/steveyegge/beads"
|
||||
|
||||
// Find and open the database
|
||||
dbPath := beads.FindDatabasePath()
|
||||
store, err := beads.NewSQLiteStorage(dbPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
// Get ready work
|
||||
ctx := context.Background()
|
||||
ready, err := store.GetReadyWork(ctx, beads.WorkFilter{
|
||||
Status: beads.StatusOpen,
|
||||
Limit: 10,
|
||||
})
|
||||
|
||||
// Create issues programmatically
|
||||
issue := &beads.Issue{
|
||||
Title: "New task",
|
||||
Status: beads.StatusOpen,
|
||||
Priority: 2,
|
||||
IssueType: beads.TypeTask,
|
||||
}
|
||||
store.CreateIssue(ctx, issue, "my-app")
|
||||
```
|
||||
|
||||
**Why use Beads as a library?**
|
||||
- ✅ **Direct API access** - No process spawn overhead
|
||||
- ✅ **Type safety** - Compile-time checking
|
||||
- ✅ **Performance** - Native Go calls
|
||||
- ✅ **Transactions** - Full control over database operations
|
||||
- ✅ **Error handling** - Proper Go error types
|
||||
|
||||
See [examples/library-usage/](examples/library-usage/) for a complete working example.
|
||||
|
||||
## Extending bd
|
||||
|
||||
Applications can extend bd's SQLite database with their own tables. See [EXTENDING.md](EXTENDING.md) for the full guide.
|
||||
|
||||
Reference in New Issue
Block a user