format

package
v0.52.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package format handles message serialization using JSON frontmatter with Markdown body content. It provides message ID generation, parsing, and timestamp-based sorting utilities.

Index

Constants

View Source
const (
	CurrentSchema  = 1
	CurrentVersion = 1
)

Schema and version constants.

View Source
const (
	PriorityUrgent = "urgent"
	PriorityNormal = "normal"
	PriorityLow    = "low"
)

Priority constants for co-op mode message handling.

View Source
const (
	KindBrainstorm     = "brainstorm"
	KindReviewRequest  = "review_request"
	KindReviewResponse = "review_response"
	KindQuestion       = "question"
	KindAnswer         = "answer"
	KindDecision       = "decision"
	KindStatus         = "status"
	KindTodo           = "todo"
)

Kind constants for co-op mode message classification.

View Source
const MaxMessageSize = 10 * 1024 * 1024

MaxMessageSize is the maximum allowed message file size (10 MB).

Variables

View Source
var (
	ErrMissingFrontmatterStart = errors.New("missing frontmatter start")
	ErrMissingFrontmatterEnd   = errors.New("missing frontmatter end")
	ErrMessageTooLarge         = errors.New("message exceeds maximum size")
)

Sentinel errors for message parsing.

Functions

func IsValidKind added in v0.6.0

func IsValidKind(k string) bool

IsValidKind returns true if the kind is valid or empty.

func IsValidPriority added in v0.6.0

func IsValidPriority(p string) bool

IsValidPriority returns true if the priority is valid or empty.

func NewMessageID

func NewMessageID(now time.Time) (string, error)

func SortByTimestamp

func SortByTimestamp[T Timestamped](items []T)

SortByTimestamp sorts a slice of Timestamped items by time, then by ID for stability.

func ValidKinds added in v0.6.0

func ValidKinds() []string

ValidKinds returns the list of valid kind values.

func ValidKindsList added in v0.19.0

func ValidKindsList() string

ValidKindsList returns a comma-joined string of valid kind values for usage messages.

func ValidPriorities added in v0.6.0

func ValidPriorities() []string

ValidPriorities returns the list of valid priority values.

Types

type Header struct {
	Schema  int      `json:"schema"`
	ID      string   `json:"id"`
	From    string   `json:"from"`
	To      []string `json:"to"`
	Thread  string   `json:"thread"`
	Subject string   `json:"subject,omitempty"`
	Created string   `json:"created"`
	Refs    []string `json:"refs,omitempty"`

	// Co-op mode fields (optional, for inter-agent communication)
	Priority string         `json:"priority,omitempty"` // urgent, normal, low
	Kind     string         `json:"kind,omitempty"`     // message kind (see ValidKinds())
	Labels   []string       `json:"labels,omitempty"`   // free-form tags
	Context  map[string]any `json:"context,omitempty"`  // structured context (paths, symbols, etc.)

	// Cross-session reply routing (optional). Set automatically when sending
	// via --session. Allows replies to route back to the sender's session.
	ReplyTo string `json:"reply_to,omitempty"` // e.g., "claude@auth"

	// Cross-project reply routing (optional). Set automatically when sending
	// via --project. Contains the sender's project name so replies can route
	// back to the correct project via peer lookup.
	ReplyProject string `json:"reply_project,omitempty"` // e.g., "amq-core"

	// Sender's project name (optional). Set automatically on cross-project
	// sends so receivers can distinguish same-handle senders from different
	// projects (e.g., "claude" in project A vs "claude" in project B).
	FromProject string `json:"from_project,omitempty"` // e.g., "homelab-ai"
}

Header is the JSON frontmatter stored at the top of each message file.

func ParseHeader

func ParseHeader(data []byte) (Header, error)

func ReadHeader added in v0.4.0

func ReadHeader(r io.Reader) (Header, error)

func ReadHeaderFile

func ReadHeaderFile(path string) (Header, error)

type Message

type Message struct {
	Header Header
	Body   string
}

Message is the in-memory representation of a message file.

func ParseMessage

func ParseMessage(data []byte) (Message, error)

func ReadMessageFile

func ReadMessageFile(path string) (Message, error)

func (Message) Marshal

func (m Message) Marshal() ([]byte, error)

type Timestamped

type Timestamped interface {
	GetCreated() string
	GetID() string
	GetRawTime() time.Time
}

Timestamped is implemented by types that have a Created timestamp and ID for sorting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL