Break down monolithic beads.go and mail.go into smaller, single-purpose files: beads package: - beads_agent.go: Agent-related bead operations - beads_delegation.go: Delegation bead handling - beads_dog.go: Dog pool operations - beads_merge_slot.go: Merge slot management - beads_mr.go: Merge request operations - beads_redirect.go: Redirect bead handling - beads_rig.go: Rig bead operations - beads_role.go: Role bead management cmd package: - mail_announce.go: Announcement subcommand - mail_check.go: Mail check subcommand - mail_identity.go: Identity management - mail_inbox.go: Inbox operations - mail_queue.go: Queue subcommand - mail_search.go: Search functionality - mail_send.go: Send subcommand - mail_thread.go: Thread operations Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
93 lines
2.1 KiB
Go
93 lines
2.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/gastown/internal/mail"
|
|
"github.com/steveyegge/gastown/internal/style"
|
|
)
|
|
|
|
func runMailCheck(cmd *cobra.Command, args []string) error {
|
|
// Determine which inbox (priority: --identity flag, auto-detect)
|
|
address := ""
|
|
if mailCheckIdentity != "" {
|
|
address = mailCheckIdentity
|
|
} else {
|
|
address = detectSender()
|
|
}
|
|
|
|
// All mail uses town beads (two-level architecture)
|
|
workDir, err := findMailWorkDir()
|
|
if err != nil {
|
|
if mailCheckInject {
|
|
// Inject mode: always exit 0, silent on error
|
|
return nil
|
|
}
|
|
return fmt.Errorf("not in a Gas Town workspace: %w", err)
|
|
}
|
|
|
|
// Get mailbox
|
|
router := mail.NewRouter(workDir)
|
|
mailbox, err := router.GetMailbox(address)
|
|
if err != nil {
|
|
if mailCheckInject {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("getting mailbox: %w", err)
|
|
}
|
|
|
|
// Count unread
|
|
_, unread, err := mailbox.Count()
|
|
if err != nil {
|
|
if mailCheckInject {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("counting messages: %w", err)
|
|
}
|
|
|
|
// JSON output
|
|
if mailCheckJSON {
|
|
result := map[string]interface{}{
|
|
"address": address,
|
|
"unread": unread,
|
|
"has_new": unread > 0,
|
|
}
|
|
enc := json.NewEncoder(os.Stdout)
|
|
enc.SetIndent("", " ")
|
|
return enc.Encode(result)
|
|
}
|
|
|
|
// Inject mode: output system-reminder if mail exists
|
|
if mailCheckInject {
|
|
if unread > 0 {
|
|
// Get subjects for context
|
|
messages, _ := mailbox.ListUnread()
|
|
var subjects []string
|
|
for _, msg := range messages {
|
|
subjects = append(subjects, fmt.Sprintf("- %s from %s: %s", msg.ID, msg.From, msg.Subject))
|
|
}
|
|
|
|
fmt.Println("<system-reminder>")
|
|
fmt.Printf("You have %d unread message(s) in your inbox.\n\n", unread)
|
|
for _, s := range subjects {
|
|
fmt.Println(s)
|
|
}
|
|
fmt.Println()
|
|
fmt.Println("Run 'gt mail inbox' to see your messages, or 'gt mail read <id>' for a specific message.")
|
|
fmt.Println("</system-reminder>")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Normal mode
|
|
if unread > 0 {
|
|
fmt.Printf("%s %d unread message(s)\n", style.Bold.Render("📬"), unread)
|
|
return NewSilentExit(0)
|
|
}
|
|
fmt.Println("No new mail")
|
|
return NewSilentExit(1)
|
|
}
|