Documentation
¶
Overview ¶
Package mail implements inter-AI messaging.
Architecture:
- internal/mail — Core domain logic (this package)
- internal/toolcall/mail — LLM tool registration & argument parsing
The mail system enables explicit communication between AI maintainers. Each AI is identified by a name_id (from ai_names table). Senders are determined from the current session via ainame.GetNameID(). Recipients are looked up by case-insensitive name_en or email.
Data Model:
mail — id, sender_name_id, recipient_name_id, subject, body, is_read, created_at mail_fts — FTS5 external content table over mail(subject, body)
Handlers:
HandleSendMail — Send a mail to another maintainer by name/email HandleReadMail — Read a single mail by ID for the current maintainer HandleListMail — List recent mails with subject only (no body) HandleMailSearch — FTS5 search across mails HandleReplyMail — Reply to an existing mail HandleDeleteMail — Delete a mail (recipient only) HandleContacts — List all known contacts from ai_names
Package mail implements an inter-AI messaging system backed by SQLite.
Architecture:
The mail system is split into two layers:
- internal/mail — Core domain logic (this package)
- internal/toolcall/mail — LLM tool registration & argument parsing
Mail enables explicit communication between AI maintainers. Each AI is identified by a name_id (from ai_names). Senders are determined from the current session via ainame.GetNameID(). Recipients are looked up by case-insensitive name or email.
Schema:
mail — id, sender_name_id, recipient_name_id, subject, body, is_read, created_at mail_fts — FTS5 external content table over mail(subject, body)
FTS sync is managed explicitly in Go (not via SQL triggers), so that Chinese content is tokenized with gse before insertion — ensuring the same tokenization on both index and query sides.
Handlers:
HandleSendMail — Send a mail to another maintainer by name HandleReadMail — Read mails for the current maintainer HandleMailSearch — FTS5 search across mails HandleContacts — List contacts with assigned projects
Index ¶
- func FormatUnreadMailLine(summaries []UnreadMailSummary) string
- func FormatUnreadMailNotification(summaries []UnreadMailSummary) string
- func HandleContacts(ctx context.Context) (result, warning string, err error)
- func HandleDeleteMail(ctx context.Context, mailID int64) (result, warning string, err error)
- func HandleListMail(ctx context.Context, unreadOnly bool, limit int) (result, warning string, err error)
- func HandleMailSearch(ctx context.Context, query string, limit int) (result, warning string, err error)
- func HandleReadMail(ctx context.Context, mailID int64) (result, warning string, err error)
- func HandleReplyMail(ctx context.Context, replyToID int64, subject, body string) (result, warning string, err error)
- func HandleSendMail(ctx context.Context, recipient, subject, body string) (result, warning string, err error)
- func UnreadMailCount(ctx context.Context) int
- type MailRow
- type MaintainerRow
- type UnreadMailSummary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatUnreadMailLine ¶ added in v0.8.5
func FormatUnreadMailLine(summaries []UnreadMailSummary) string
FormatUnreadMailLine returns a one-line mail notification string. Returns empty string when there are no summaries — caller should skip injection. Use this instead of FormatUnreadMailNotification for concise in-message injection (e.g. prepended to user or tool content).
func FormatUnreadMailNotification ¶
func FormatUnreadMailNotification(summaries []UnreadMailSummary) string
FormatUnreadMailNotification formats unread mail summaries into a user-message notification. Returns empty string when there are no summaries — caller should skip injection in that case.
func HandleContacts ¶
HandleContacts lists contacts that have been assigned to at least one project, along with their project assignments.
func HandleDeleteMail ¶
HandleDeleteMail deletes a mail by ID. Only the recipient (current user) can delete their own mails.
func HandleListMail ¶
func HandleListMail(ctx context.Context, unreadOnly bool, limit int) (result, warning string, err error)
HandleListMail lists recent mails for the current maintainer, showing subject only (no body). Optional unreadOnly filter.
func HandleMailSearch ¶
func HandleMailSearch(ctx context.Context, query string, limit int) (result, warning string, err error)
HandleMailSearch searches mails using FTS5.
func HandleReadMail ¶
HandleReadMail reads a single mail by ID for the current maintainer. Also marks the mail as read.
func HandleReplyMail ¶
func HandleReplyMail(ctx context.Context, replyToID int64, subject, body string) (result, warning string, err error)
HandleReplyMail replies to an existing mail. The recipient is automatically set to the original mail's sender. If subject is empty, "Re: <original subject>" is used.
func HandleSendMail ¶
func HandleSendMail(ctx context.Context, recipient, subject, body string) (result, warning string, err error)
HandleSendMail sends a mail to a recipient identified by name or email.
func UnreadMailCount ¶
UnreadMailCount returns the number of unread mails for the current maintainer. Returns 0 on any error (missing session, DB error, etc.) — errors are silently swallowed because this is a prompt hint; it must never block or error out.
Types ¶
type MailRow ¶
type MailRow struct {
ID int64 `json:"id"`
SenderName string `json:"sender_name"`
SenderEmail string `json:"sender_email"`
RecipientName string `json:"recipient_name"`
RecipientEmail string `json:"recipient_email"`
Subject string `json:"subject"`
Body string `json:"body"`
IsRead bool `json:"is_read"`
CreatedAt string `json:"created_at"`
}
MailRow represents a single mail message.
type MaintainerRow ¶
type MaintainerRow struct {
ID int64 `json:"id"`
NameCN string `json:"name_cn"`
NameEN string `json:"name_en"`
BirdFrog string `json:"bird_frog"`
Email string `json:"email"`
}
MaintainerRow represents a maintainer from ai_names.
type UnreadMailSummary ¶
UnreadMailSummary is a lightweight view of an unread mail for notification.
func UnreadMailList ¶
func UnreadMailList(ctx context.Context) []UnreadMailSummary
UnreadMailList returns unread mail summaries for the current maintainer. Returns nil on any error — errors are silently swallowed because this is a prompt hint; it must never block or error out.