feat(mail): add interrupt vs queue delivery semantics (gt-6k8)
Add delivery modes to mail messages: - queue (default): message stored for periodic checking - interrupt: inject system-reminder directly into session New features: - --interrupt flag on gt mail send for urgent/lifecycle messages - --quiet flag on gt mail check for silent non-blocking checks - gt mail wait command to block until mail arrives (with optional timeout) Interrupt delivery injects a system-reminder via tmux send-keys, useful for stuck detection, nudges, and urgent notifications. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -71,8 +71,14 @@ func (r *Router) Send(msg *Message) error {
|
||||
return fmt.Errorf("sending message: %w", err)
|
||||
}
|
||||
|
||||
// Notify recipient if they have an active session
|
||||
r.notifyRecipient(msg)
|
||||
// Handle delivery based on mode
|
||||
if msg.Delivery == DeliveryInterrupt {
|
||||
// Interrupt: inject system-reminder directly into session
|
||||
r.interruptRecipient(msg)
|
||||
} else {
|
||||
// Queue (default): just notify in status line
|
||||
r.notifyRecipient(msg)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -102,6 +108,39 @@ func (r *Router) notifyRecipient(msg *Message) error {
|
||||
return r.tmux.DisplayMessageDefault(sessionID, notification)
|
||||
}
|
||||
|
||||
// interruptRecipient injects a system-reminder directly into the session.
|
||||
// Uses tmux send-keys to inject text that Claude will see as input.
|
||||
// This is disruptive - use for lifecycle events, URGENT messages, or stuck detection.
|
||||
func (r *Router) interruptRecipient(msg *Message) error {
|
||||
sessionID := addressToSessionID(msg.To)
|
||||
if sessionID == "" {
|
||||
return nil // Unable to determine session ID
|
||||
}
|
||||
|
||||
// Check if session exists
|
||||
hasSession, err := r.tmux.HasSession(sessionID)
|
||||
if err != nil || !hasSession {
|
||||
return nil // No active session, skip interrupt
|
||||
}
|
||||
|
||||
// Build system-reminder with message content
|
||||
priorityStr := ""
|
||||
if msg.Priority == PriorityUrgent {
|
||||
priorityStr = " [URGENT]"
|
||||
} else if msg.Priority == PriorityHigh {
|
||||
priorityStr = " [HIGH PRIORITY]"
|
||||
}
|
||||
|
||||
reminder := fmt.Sprintf("\n<system-reminder>\n📬 NEW MAIL%s from %s\nSubject: %s\n", priorityStr, msg.From, msg.Subject)
|
||||
if msg.Body != "" {
|
||||
reminder += fmt.Sprintf("\n%s\n", msg.Body)
|
||||
}
|
||||
reminder += "\nRun 'gt mail inbox' to see your messages.\n</system-reminder>\n"
|
||||
|
||||
// Inject via send-keys (don't press Enter, just paste)
|
||||
return r.tmux.SendKeysRaw(sessionID, reminder)
|
||||
}
|
||||
|
||||
// addressToSessionID converts a mail address to a tmux session ID.
|
||||
// Returns empty string if address format is not recognized.
|
||||
func addressToSessionID(address string) string {
|
||||
|
||||
@@ -41,6 +41,19 @@ const (
|
||||
TypeReply MessageType = "reply"
|
||||
)
|
||||
|
||||
// Delivery specifies how a message is delivered to the recipient.
|
||||
type Delivery string
|
||||
|
||||
const (
|
||||
// DeliveryQueue creates the message in the mailbox for periodic checking.
|
||||
// This is the default delivery mode. Agent checks with `gt mail check`.
|
||||
DeliveryQueue Delivery = "queue"
|
||||
|
||||
// DeliveryInterrupt injects a system-reminder directly into the agent's session.
|
||||
// Use for lifecycle events, URGENT priority, or stuck detection.
|
||||
DeliveryInterrupt Delivery = "interrupt"
|
||||
)
|
||||
|
||||
// Message represents a mail message between agents.
|
||||
// This is the GGT-side representation; it gets translated to/from beads messages.
|
||||
type Message struct {
|
||||
@@ -71,6 +84,10 @@ type Message struct {
|
||||
// Type indicates the message type (task, scavenge, notification, reply).
|
||||
Type MessageType `json:"type"`
|
||||
|
||||
// Delivery specifies how the message is delivered (queue or interrupt).
|
||||
// Queue: agent checks periodically. Interrupt: inject into session.
|
||||
Delivery Delivery `json:"delivery,omitempty"`
|
||||
|
||||
// ThreadID groups related messages into a conversation thread.
|
||||
ThreadID string `json:"thread_id,omitempty"`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user