fix: Create and lookup rig agent beads with correct prefix

Per docs/architecture.md, Witness and Refinery are rig-level agents that
should use the rig's configured prefix (e.g., pi- for pixelforge) instead
of hardcoded "gt-".

This extends PR #183's creation fix to also fix all lookup paths:
- internal/rig/manager.go: Create agent beads in rig beads with rig prefix
- internal/daemon/daemon.go: Use rig prefix when looking up agent state
- internal/daemon/lifecycle.go: Use rig prefix for identity-to-bead mapping
- internal/cmd/sling.go: Pass townRoot for prefix lookup
- internal/cmd/unsling.go: Pass townRoot for prefix lookup
- internal/cmd/molecule_status.go: Use rig prefix for agent bead lookups
- internal/cmd/molecule_attach.go: Use rig prefix for agent bead lookups
- internal/config/loader.go: Add GetRigPrefix helper

Without this fix, the daemon would:
- Create pi-gastown-witness but look for gt-gastown-witness
- Report agents as missing/dead when they are running
- Fail to manage agent lifecycle correctly

Based on work by Johann Taberlet in PR #183.

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

Co-Authored-By: Johann Taberlet <johann.taberlet@gmail.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gastown/crew/jack
2026-01-05 19:39:42 -08:00
committed by Steve Yegge
parent fc0b506253
commit e8d27e7212
8 changed files with 100 additions and 55 deletions

View File

@@ -417,7 +417,8 @@ func (d *Daemon) ensureWitnessesRunning() {
// ensureWitnessRunning ensures the witness for a specific rig is running.
func (d *Daemon) ensureWitnessRunning(rigName string) {
agentID := beads.WitnessBeadID(rigName)
prefix := config.GetRigPrefix(d.config.TownRoot, rigName)
agentID := beads.WitnessBeadIDWithPrefix(prefix, rigName)
sessionName := "gt-" + rigName + "-witness"
// Check agent bead state (ZFC: trust what agent reports)
@@ -503,7 +504,8 @@ func (d *Daemon) ensureRefineriesRunning() {
// ensureRefineryRunning ensures the refinery for a specific rig is running.
func (d *Daemon) ensureRefineryRunning(rigName string) {
agentID := beads.RefineryBeadID(rigName)
prefix := config.GetRigPrefix(d.config.TownRoot, rigName)
agentID := beads.RefineryBeadIDWithPrefix(prefix, rigName)
sessionName := "gt-" + rigName + "-refinery"
// Check agent bead state (ZFC: trust what agent reports)

View File

@@ -626,13 +626,17 @@ func (d *Daemon) identityToAgentBeadID(identity string) string {
case "mayor":
return beads.MayorBeadIDTown()
case "witness":
return beads.WitnessBeadID(parsed.RigName)
prefix := config.GetRigPrefix(d.config.TownRoot, parsed.RigName)
return beads.WitnessBeadIDWithPrefix(prefix, parsed.RigName)
case "refinery":
return beads.RefineryBeadID(parsed.RigName)
prefix := config.GetRigPrefix(d.config.TownRoot, parsed.RigName)
return beads.RefineryBeadIDWithPrefix(prefix, parsed.RigName)
case "crew":
return beads.CrewBeadID(parsed.RigName, parsed.AgentName)
prefix := config.GetRigPrefix(d.config.TownRoot, parsed.RigName)
return beads.CrewBeadIDWithPrefix(prefix, parsed.RigName, parsed.AgentName)
case "polecat":
return beads.PolecatBeadID(parsed.RigName, parsed.AgentName)
prefix := config.GetRigPrefix(d.config.TownRoot, parsed.RigName)
return beads.PolecatBeadIDWithPrefix(prefix, parsed.RigName, parsed.AgentName)
default:
return ""
}
@@ -660,9 +664,14 @@ func (d *Daemon) checkStaleAgents() {
d.logger.Printf("Warning: could not load rigs config: %v", err)
} else {
// Add rig-specific agents (witness, refinery) for each discovered rig
for rigName := range rigsConfig.Rigs {
agentBeadIDs = append(agentBeadIDs, beads.WitnessBeadID(rigName))
agentBeadIDs = append(agentBeadIDs, beads.RefineryBeadID(rigName))
for rigName, rigEntry := range rigsConfig.Rigs {
// Get rig prefix from config (defaults to "gt" if not set)
prefix := "gt"
if rigEntry.BeadsConfig != nil && rigEntry.BeadsConfig.Prefix != "" {
prefix = strings.TrimSuffix(rigEntry.BeadsConfig.Prefix, "-")
}
agentBeadIDs = append(agentBeadIDs, beads.WitnessBeadIDWithPrefix(prefix, rigName))
agentBeadIDs = append(agentBeadIDs, beads.RefineryBeadIDWithPrefix(prefix, rigName))
}
}