format

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 12 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.

Variables

View Source
var (
	ErrMissingFrontmatterStart = errors.New("missing frontmatter start")
	ErrMissingFrontmatterEnd   = errors.New("missing frontmatter end")
)

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 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"`
	AckRequired bool     `json:"ack_required"`
	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"`     // brainstorm, review_request, review_response, question, answer, decision, status, todo
	Labels   []string       `json:"labels,omitempty"`   // free-form tags
	Context  map[string]any `json:"context,omitempty"`  // structured context (paths, symbols, etc.)
}

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