refactor: Move agent field parsing to shared beads package

- Add AgentFields and ParseAgentFieldsFromDescription to internal/beads/fields.go
- Update daemon/lifecycle.go to use shared parsing
- Update cmd/molecule_status.go to use shared parsing
- Remove duplicate parsing code and unused isAgentRunningByBead function

This consolidates agent bead field parsing in one place, following the pattern
established for AttachmentFields and MRFields.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-28 01:43:27 -08:00
parent 4f5b7bf519
commit a1715fa91f
3 changed files with 120 additions and 118 deletions

View File

@@ -14,67 +14,7 @@ import (
"github.com/steveyegge/gastown/internal/workspace"
)
// AgentBeadFields holds parsed fields from an agent bead's description.
// Agent beads store their state as key: value lines in the description.
type AgentBeadFields struct {
RoleType string // role_type: mayor, deacon, witness, refinery, polecat
Rig string // rig: gastown (or null)
AgentState string // agent_state: idle, working, done
HookBead string // hook_bead: the bead ID on the hook (or null)
RoleBead string // role_bead: the role definition bead
}
// ParseAgentBeadFields extracts agent bead fields from a bead's description.
// Returns nil if no agent fields found.
func ParseAgentBeadFields(description string) *AgentBeadFields {
if description == "" {
return nil
}
fields := &AgentBeadFields{}
hasFields := false
for _, line := range strings.Split(description, "\n") {
line = strings.TrimSpace(line)
if line == "" {
continue
}
colonIdx := strings.Index(line, ":")
if colonIdx == -1 {
continue
}
key := strings.TrimSpace(line[:colonIdx])
value := strings.TrimSpace(line[colonIdx+1:])
if value == "" || value == "null" {
continue
}
switch strings.ToLower(key) {
case "role_type":
fields.RoleType = value
hasFields = true
case "rig":
fields.Rig = value
hasFields = true
case "agent_state":
fields.AgentState = value
hasFields = true
case "hook_bead":
fields.HookBead = value
hasFields = true
case "role_bead":
fields.RoleBead = value
hasFields = true
}
}
if !hasFields {
return nil
}
return fields
}
// Note: Agent field parsing is now in internal/beads/fields.go (AgentFields, ParseAgentFieldsFromDescription)
// buildAgentBeadID constructs the agent bead ID from an agent identity.
// Examples:
@@ -388,7 +328,7 @@ func runMoleculeStatus(cmd *cobra.Command, args []string) error {
status.AgentBeadID = agentBeadID
// Parse hook_bead from the agent bead's description
agentFields := ParseAgentBeadFields(agentBead.Description)
agentFields := beads.ParseAgentFieldsFromDescription(agentBead.Description)
if agentFields != nil && agentFields.HookBead != "" {
// Fetch the bead on the hook
hookBead, err = b.Show(agentFields.HookBead)