Link MR bead to agent bead for traceability (gt-84ery)

Add bidirectional cross-references between MR beads and agent beads:

1. MRFields.AgentBead - tracks which agent created the MR
2. AgentFields.ActiveMR - tracks agent's current MR

In gt done:
- Include agent_bead in MR description when creating
- Update agent bead with active_mr pointing to the new MR

In refinery merge handling:
- Clear agent bead's active_mr after successful merge

Benefits:
- Given MR, find which polecat created it
- Given polecat, find their active MR
- Orphan detection: MR without agent = stale

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gastown/polecats/dementus
2025-12-30 22:28:33 -08:00
committed by Steve Yegge
parent b241a353f3
commit 4a22e621a9
5 changed files with 77 additions and 0 deletions

View File

@@ -706,6 +706,7 @@ type AgentFields struct {
HookBead string // Currently pinned work bead ID
RoleBead string // Role definition bead ID (canonical location; may not exist yet)
CleanupStatus string // ZFC: polecat self-reports git state (clean, has_uncommitted, has_stash, has_unpushed)
ActiveMR string // Currently active merge request bead ID (for traceability)
}
// FormatAgentDescription creates a description string from agent fields.
@@ -745,6 +746,12 @@ func FormatAgentDescription(title string, fields *AgentFields) string {
lines = append(lines, "cleanup_status: null")
}
if fields.ActiveMR != "" {
lines = append(lines, fmt.Sprintf("active_mr: %s", fields.ActiveMR))
} else {
lines = append(lines, "active_mr: null")
}
return strings.Join(lines, "\n")
}
@@ -782,6 +789,8 @@ func ParseAgentFields(description string) *AgentFields {
fields.RoleBead = value
case "cleanup_status":
fields.CleanupStatus = value
case "active_mr":
fields.ActiveMR = value
}
}
@@ -896,6 +905,26 @@ func (b *Beads) UpdateAgentCleanupStatus(id string, cleanupStatus string) error
return b.Update(id, UpdateOptions{Description: &description})
}
// UpdateAgentActiveMR updates the active_mr field in an agent bead.
// This links the agent to their current merge request for traceability.
// Pass empty string to clear the field (e.g., after merge completes).
func (b *Beads) UpdateAgentActiveMR(id string, activeMR string) error {
// First get current issue to preserve other fields
issue, err := b.Show(id)
if err != nil {
return err
}
// Parse existing fields
fields := ParseAgentFields(issue.Description)
fields.ActiveMR = activeMR
// Format new description
description := FormatAgentDescription(issue.Title, fields)
return b.Update(id, UpdateOptions{Description: &description})
}
// DeleteAgentBead permanently deletes an agent bead.
// Uses --hard --force for immediate permanent deletion (no tombstone).
func (b *Beads) DeleteAgentBead(id string) error {