fix(beads): multi-repo routing for custom types and role slots

Fixes two bugs in multi-repo routing scenarios:

1. "invalid issue type: agent" error when creating agent beads
   - Added EnsureCustomTypes() with two-level caching (in-memory + sentinel file)
   - CreateAgentBead() now resolves routing target and ensures custom types

2. "could not set role slot: issue not found" warning when setting slots
   - Added runSlotSet() and runSlotClear() helpers that run bd from correct directory
   - Slot operations now use the resolved target directory

New files:
- internal/beads/beads_types.go - routing resolution and custom types logic
- internal/beads/beads_types_test.go - unit tests

Based on PR #811 by Perttulands, rebased onto current main.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gastown/crew/dennis
2026-01-21 10:44:37 -08:00
committed by beads/crew/emma
parent b2b9cbc836
commit fa1f812ce9
4 changed files with 435 additions and 4 deletions
+25
View File
@@ -114,6 +114,11 @@ type Beads struct {
workDir string
beadsDir string // Optional BEADS_DIR override for cross-database access
isolated bool // If true, suppress inherited beads env vars (for test isolation)
// Lazy-cached town root for routing resolution.
// Populated on first call to getTownRoot() to avoid filesystem walk on every operation.
townRoot string
searchedRoot bool
}
// New creates a new Beads wrapper for the given directory.
@@ -144,6 +149,26 @@ func (b *Beads) getActor() string {
return os.Getenv("BD_ACTOR")
}
// getTownRoot returns the Gas Town root directory, using lazy caching.
// The town root is found by walking up from workDir looking for mayor/town.json.
// Returns empty string if not in a Gas Town project.
func (b *Beads) getTownRoot() string {
if !b.searchedRoot {
b.townRoot = FindTownRoot(b.workDir)
b.searchedRoot = true
}
return b.townRoot
}
// getResolvedBeadsDir returns the beads directory this wrapper is operating on.
// This follows any redirects and returns the actual beads directory path.
func (b *Beads) getResolvedBeadsDir() string {
if b.beadsDir != "" {
return b.beadsDir
}
return ResolveBeadsDir(b.workDir)
}
// Init initializes a new beads database in the working directory.
// This uses the same environment isolation as other commands.
func (b *Beads) Init(prefix string) error {