fix(beads): fix agent bead creation during rig add

Three issues were causing errors when running `gt rig add`:

1. **bd init flag**: Removed non-existent `--no-agents` flag from bd init
   command that was causing silent failures.

2. **BEADS_DIR for init**: Added explicit BEADS_DIR to bd init and migrate
   commands to prevent bd from finding parent directory databases.

3. **Agent beads location**: Agent beads now go in town beads (gt-* prefix)
   instead of rig beads. This is necessary because:
   - Agent IDs use canonical gt-* prefix (e.g., gt-tribal-witness)
   - Rig beads use rig-specific prefixes (e.g., tr-*)
   - bd strictly validates ID prefix against database prefix
   - Town beads must be initialized with `gt` prefix

4. **beads.run() BEADS_DIR**: Modified to explicitly pass BEADS_DIR in child
   process environment to ensure bd uses the correct database.

5. **Agent ID prefix**: Use WitnessBeadID/RefineryBeadID (canonical gt-*)
   instead of WithPrefix variants.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
PepijnSenders
2026-01-02 22:34:15 +01:00
parent c0d597f092
commit ca487a8fed
2 changed files with 44 additions and 22 deletions

View File

@@ -225,6 +225,21 @@ func (b *Beads) run(args ...string) ([]byte, error) {
cmd := exec.Command("bd", fullArgs...)
cmd.Dir = b.workDir
// Explicitly set BEADS_DIR for child process to ensure bd uses the correct
// database. Without this, bd may search parent directories and find a different
// .beads/ directory with a different prefix, causing "prefix mismatch" errors.
beadsDir := filepath.Join(b.workDir, ".beads")
env := os.Environ()
// Filter out any existing BEADS_DIR to avoid conflicts
filteredEnv := make([]string, 0, len(env)+1)
for _, e := range env {
if !strings.HasPrefix(e, "BEADS_DIR=") {
filteredEnv = append(filteredEnv, e)
}
}
filteredEnv = append(filteredEnv, "BEADS_DIR="+beadsDir)
cmd.Env = filteredEnv
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr