Merge pull request #39 from cvsloane/fix/polecat-dispatcher-notification

feat: notify dispatcher when polecat work completes
This commit is contained in:
Steve Yegge
2026-01-04 23:09:23 -08:00
committed by GitHub
3 changed files with 106 additions and 0 deletions

View File

@@ -330,6 +330,23 @@ func runDone(cmd *cobra.Command, args []string) error {
fmt.Printf("%s Witness notified of %s\n", style.Bold.Render("✓"), exitType)
}
// Notify dispatcher if work was dispatched by another agent
if issueID != "" {
if dispatcher := getDispatcherFromBead(cwd, issueID); dispatcher != "" && dispatcher != sender {
dispatcherNotification := &mail.Message{
To: dispatcher,
From: sender,
Subject: fmt.Sprintf("WORK_DONE: %s", issueID),
Body: strings.Join(bodyLines, "\n"),
}
if err := townRouter.Send(dispatcherNotification); err != nil {
style.PrintWarning("could not notify dispatcher %s: %v", dispatcher, err)
} else {
fmt.Printf("%s Dispatcher %s notified of %s\n", style.Bold.Render("✓"), dispatcher, exitType)
}
}
}
// Log done event (townlog and activity feed)
_ = LogDone(townRoot, sender, issueID)
_ = events.LogFeed(events.TypeDone, sender, events.DonePayload(issueID, branch))
@@ -421,6 +438,27 @@ func updateAgentStateOnDone(cwd, townRoot, exitType, _ string) { // issueID unus
}
}
// getDispatcherFromBead retrieves the dispatcher agent ID from the bead's attachment fields.
// Returns empty string if no dispatcher is recorded.
func getDispatcherFromBead(cwd, issueID string) string {
if issueID == "" {
return ""
}
bd := beads.New(cwd)
issue, err := bd.Show(issueID)
if err != nil {
return ""
}
fields := beads.ParseAttachmentFields(issue)
if fields == nil {
return ""
}
return fields.DispatchedBy
}
// computeCleanupStatus checks git state and returns the cleanup status.
// Returns the most critical issue: has_unpushed > has_stash > has_uncommitted > clean
func computeCleanupStatus(cwd string) string {