messaging

package
v0.32.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package messaging provides inter-agent communication via pub/sub topics.

Inbox Convention

Each hive session has a conventional inbox topic:

agent.<session-id>.inbox

The "agent" prefix refers to the AI agent running in the session, not the session itself. This convention allows agents to discover each other's inboxes and send direct messages.

Future: Multi-Agent Addressing

When hive supports multiple agents per session, inbox addressing will use:

agent.<session-id>.<agent-name>.inbox

The current format will continue to work as an alias to the primary/default agent:

agent.<session-id>.inbox → agent.<session-id>.main.inbox

Examples:

agent.26kj0c.inbox            // Current format (default agent)
agent.26kj0c.claude.inbox     // Future: Named agent "claude"
agent.26kj0c.test-runner.inbox // Future: Named agent "test-runner"

Index

Constants

This section is empty.

Variables

View Source
var ErrTopicNotFound = errors.New("topic not found")

Functions

This section is empty.

Types

type Message

type Message struct {
	ID        string    `json:"id"`
	Topic     string    `json:"topic"`
	Payload   string    `json:"payload"`
	Sender    string    `json:"sender,omitempty"`
	SessionID string    `json:"session_id,omitempty"`
	CreatedAt time.Time `json:"created_at"`
}

Message represents a single message published to a topic.

type SessionDetector

type SessionDetector struct {
	// contains filtered or unexported fields
}

SessionDetector finds the current session from the working directory.

func NewSessionDetector

func NewSessionDetector(store session.Store) *SessionDetector

NewSessionDetector creates a new session detector.

func (*SessionDetector) DetectSession

func (d *SessionDetector) DetectSession(ctx context.Context) (string, error)

DetectSession returns the session ID for the current working directory. Returns empty string if not in a hive session, or an error if detection fails.

func (*SessionDetector) DetectSessionFromPath

func (d *SessionDetector) DetectSessionFromPath(ctx context.Context, path string) (string, error)

DetectSessionFromPath returns the session ID for the given path. Returns empty string if the path is not within a hive session, or an error if detection fails.

type Store

type Store interface {
	// Publish adds a message to multiple topics.
	// Wildcards are expanded before publishing.
	Publish(ctx context.Context, msg Message, topics []string) error

	// Subscribe returns all messages for a topic, optionally filtered by since timestamp.
	// Returns ErrTopicNotFound if the topic doesn't exist.
	Subscribe(ctx context.Context, topic string, since time.Time) ([]Message, error)

	// Acknowledge marks messages as read by a consumer.
	Acknowledge(ctx context.Context, consumerID string, messageIDs []string) error

	// GetUnread returns messages not yet acknowledged by consumer.
	// Supports wildcard topic patterns.
	GetUnread(ctx context.Context, consumerID string, topic string) ([]Message, error)

	// List returns all topic names.
	List(ctx context.Context) ([]string, error)

	// Prune removes messages older than the given duration across all topics.
	// Returns the number of messages removed.
	Prune(ctx context.Context, olderThan time.Duration) (int, error)
}

Store defines the interface for message persistence.

type Topic

type Topic struct {
	Name      string    `json:"name"`
	Messages  []Message `json:"messages"`
	UpdatedAt time.Time `json:"updated_at"`
}

Topic represents a named channel for messages.

Jump to

Keyboard shortcuts

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