daemon

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MPL-2.0 Imports: 65 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package daemon implements the a2ald runtime: DHT/QUIC host, REST API, TCP gateway, and MCP server. It is shared by the CLI binary (cmd/a2ald) and the mobile binding (mobile/).

Index

Constants

View Source
const EnvelopePersisted uint8 = 0

EnvelopePersisted is the SendEnvelope API result when the envelope was stored via mailbox. It is never written on the a2en wire.

Variables

This section is empty.

Functions

func MsgIDFromRecord added in v0.2.4

func MsgIDFromRecord(sr protocol.SignedRecord) [32]byte

MsgIDFromRecord computes a stable deduplication key: SHA-256(SignedRecord.Payload). When Payload is empty (legacy entry), it falls back to SHA-256(Address + Seq CBOR).

Types

type Config

type Config struct {
	// DataDir is the directory for keys, agents.json, peers.cache, and
	// config.toml. Required.
	DataDir string
	// CfgPath overrides the default config file path (DataDir/config.toml).
	CfgPath string
	// Override is called after the config is loaded, allowing the caller to
	// apply additional overrides (e.g., CLI flags).
	Override func(*config.Config)
	// Log is the structured logger to use. Defaults to text output on Stdout.
	Log *slog.Logger
	// MCPStdio runs the MCP server on stdin/stdout instead of HTTP.
	MCPStdio bool
}

Config is the startup configuration for New.

type Daemon

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

Daemon is the a2ald runtime.

func New

func New(cfg Config) (*Daemon, error)

New loads config, generates or loads the node key, and initialises the host. Call Run to start serving.

func (*Daemon) APIAddr

func (d *Daemon) APIAddr() string

APIAddr returns the REST API / Web UI listen address from the loaded config.

func (*Daemon) RegisterEnvelopeConsumer added in v0.3.3

func (d *Daemon) RegisterEnvelopeConsumer(kind string, fn EnvelopeConsumer)

RegisterEnvelopeConsumer installs fn for kind. fn=nil removes the entry.

func (*Daemon) RegisterPending added in v0.3.3

func (d *Daemon) RegisterPending(key string, n func(a2al.Address) int)

RegisterPending adds an application count source under key. n is called with each visible AID at hitch time; n<=0 omits the key. n=nil removes the source. "mailbox" is reserved for mailbox_store.

func (*Daemon) Run

func (d *Daemon) Run(ctx context.Context, mcpStdio bool) error

Run starts the daemon and blocks until ctx is cancelled. It saves the peers cache and config on return.

func (*Daemon) SendEnvelope added in v0.3.3

func (d *Daemon) SendEnvelope(ctx context.Context, local, remote a2al.Address, kind string, body []byte, persist bool) (EnvelopeResult, error)

SendEnvelope delivers kind+body on a live a2en stream when one exists. persist stores MailboxMsgEnvelope via execMailboxSend only when no coarse result was read. persist never reports EnvelopeOK.

func (*Daemon) SyncGroupWith added in v0.3.3

func (d *Daemon) SyncGroupWith(ctx context.Context, groupID [32]byte, localAID, peerAID a2al.Address) (int, error)

SyncGroupWith opens an outbound QUIC stream to peerAID and runs one round of Group sync for groupID. localAID must be registered with this daemon.

Returns the number of new entries received from the peer.

type EnvelopeConsumer added in v0.3.3

type EnvelopeConsumer func(local, remote a2al.Address, kind string, body []byte) (consumed bool, result EnvelopeResult)

EnvelopeConsumer handles one kind. consumed=true means this is not an ordinary mailbox note (no mailbox.received, not pending.mailbox).

type EnvelopeResult added in v0.3.3

type EnvelopeResult struct {
	Code  uint8
	Extra []byte
}

EnvelopeResult is the coarse outcome of SendEnvelope or a consumer.

type Event added in v0.2.4

type Event struct {
	Type string
	AID  a2al.Address // zero = global / not agent-specific
	Data any
	At   time.Time
}

Event is a single daemon-internal event. Type follows the naming convention "<domain>.<verb>" (e.g. "mailbox.received").

type EventBus added in v0.2.4

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

EventBus is a simple in-process publish/subscribe bus. All methods are safe for concurrent use.

func NewEventBus added in v0.2.4

func NewEventBus(log *slog.Logger) *EventBus

NewEventBus returns an initialised EventBus.

func (*EventBus) Publish added in v0.2.4

func (b *EventBus) Publish(evt Event)

Publish delivers evt to all matching subscribers. Slow consumers are handled without blocking: if a subscriber's channel is full, the oldest event is discarded and the new one is enqueued.

func (*EventBus) Subscribe added in v0.2.4

func (b *EventBus) Subscribe(filter Filter) (<-chan Event, func())

Subscribe registers a subscriber with the given filter. Returns a receive-only channel and a cancel function. The caller must call cancel when done to release resources.

type EventLog added in v0.3.3

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

EventLog holds per-AID ring-buffer event logs.

It also drives SSE live streams: after each Append the log notifies all registered watchers for that AID via a buffered channel (capacity 1). Watchers call Since to pull the new events. This design eliminates the EventBus→SSE race that existed when both subscribed to the bus independently.

func NewEventLog added in v0.3.3

func NewEventLog() *EventLog

NewEventLog creates a new EventLog.

func (*EventLog) Append added in v0.3.3

func (el *EventLog) Append(aid a2al.Address, evt LoggedEvent) uint64

Append records an event for the given AID and notifies any active watchers. Returns the assigned monotonic sequence number.

func (*EventLog) LastSeq added in v0.3.4

func (el *EventLog) LastSeq(aid a2al.Address) uint64

LastSeq is the newest seq still buffered for aid, or 0 if the log is empty.

func (*EventLog) Since added in v0.3.3

func (el *EventLog) Since(aid a2al.Address, afterSeq uint64) ([]LoggedEvent, uint64, bool)

Since returns events for aid with seq > afterSeq. Returns (events, oldestSeq, truncated).

func (*EventLog) Watch added in v0.3.3

func (el *EventLog) Watch(aid a2al.Address) (<-chan struct{}, func())

Watch registers a watcher for the given AID. The returned channel receives a struct{} whenever new events are appended; the channel has capacity 1 so multiple rapid appends coalesce into a single notification. The caller must call the returned cancel function when done to release the channel.

type Filter added in v0.2.4

type Filter struct {
	AID   a2al.Address // zero = any AID
	Types []string     // empty = all types
}

Filter restricts which events a subscriber receives. Empty/zero values match everything in that dimension.

type GroupManager added in v0.3.3

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

GroupManager manages the lifecycle of per-AID local Group replicas.

Storage layout: {baseDir}/{aid_hex}/groups/{group_id_hex}/ where baseDir = dataDir/agents.

Each local AID maintains its own replica; deleting an AID's directory automatically removes all its group stores without affecting other members.

All methods are safe for concurrent use.

func (*GroupManager) Create added in v0.3.3

func (gm *GroupManager) Create(aid a2al.Address, priv []byte, title string) (*group.Store, error)

Create creates a new Group for aid and returns the opened Store.

func (*GroupManager) Drop added in v0.3.4

func (gm *GroupManager) Drop(aid a2al.Address, groupID [32]byte) error

Drop closes the local replica and deletes it from disk.

func (*GroupManager) Join added in v0.3.3

func (gm *GroupManager) Join(aid a2al.Address, groupID [32]byte, creatorAID a2al.Address, title string) (*group.Store, error)

Join initialises or opens the local Group store for a joining member.

func (*GroupManager) List added in v0.3.3

func (gm *GroupManager) List(aid a2al.Address) ([]group.Meta, error)

List returns the metadata of all locally stored Groups for aid.

func (*GroupManager) Open added in v0.3.3

func (gm *GroupManager) Open(aid a2al.Address, groupID [32]byte) (*group.Store, error)

Open returns the Store for (aid, groupID), opening from disk if not cached.

type LoggedEvent added in v0.3.3

type LoggedEvent struct {
	Seq  uint64 // monotonically increasing, per-AID, no gaps within a log's lifetime
	Type string
	Data any
	Ts   int64 // Unix milliseconds UTC — machine-sortable, consistent with entry.ts
}

LoggedEvent is a single entry in the per-AID event log.

type MailboxStoreEntry added in v0.2.4

type MailboxStoreEntry struct {
	RecipientAID a2al.Address          `cbor:"1,keyasint"`
	Record       protocol.SignedRecord `cbor:"2,keyasint"` // encrypted; zero-value when sourced from old-style poll
	ReceivedAt   int64                 `cbor:"3,keyasint"`
	TTLExpires   int64                 `cbor:"4,keyasint"`
	ConsumedAt   int64                 `cbor:"5,keyasint,omitempty"` // 0 = unconsumed
}

MailboxStoreEntry is one persisted mailbox record.

Directories

Path Synopsis
Package aidproxy implements the AID Resource Addressing Gateway.
Package aidproxy implements the AID Resource Addressing Gateway.

Jump to

Keyboard shortcuts

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