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
- func MsgIDFromRecord(sr protocol.SignedRecord) [32]byte
- type Config
- type Daemon
- func (d *Daemon) APIAddr() string
- func (d *Daemon) RegisterEnvelopeConsumer(kind string, fn EnvelopeConsumer)
- func (d *Daemon) RegisterPending(key string, n func(a2al.Address) int)
- func (d *Daemon) Run(ctx context.Context, mcpStdio bool) error
- func (d *Daemon) SendEnvelope(ctx context.Context, local, remote a2al.Address, kind string, body []byte, ...) (EnvelopeResult, error)
- func (d *Daemon) SyncGroupWith(ctx context.Context, groupID [32]byte, localAID, peerAID a2al.Address) (int, error)
- type EnvelopeConsumer
- type EnvelopeResult
- type Event
- type EventBus
- type EventLog
- type Filter
- type GroupManager
- func (gm *GroupManager) Create(aid a2al.Address, priv []byte, title string) (*group.Store, error)
- func (gm *GroupManager) Drop(aid a2al.Address, groupID [32]byte) error
- func (gm *GroupManager) Join(aid a2al.Address, groupID [32]byte, creatorAID a2al.Address, title string) (*group.Store, error)
- func (gm *GroupManager) List(aid a2al.Address) ([]group.Meta, error)
- func (gm *GroupManager) Open(aid a2al.Address, groupID [32]byte) (*group.Store, error)
- type LoggedEvent
- type MailboxStoreEntry
Constants ¶
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 ¶
New loads config, generates or loads the node key, and initialises the host. Call Run to start serving.
func (*Daemon) APIAddr ¶
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
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 ¶
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
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
NewEventBus returns an initialised EventBus.
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 (*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
LastSeq is the newest seq still buffered for aid, or 0 if the log is empty.
func (*EventLog) Since ¶ added in v0.3.3
Since returns events for aid with seq > afterSeq. Returns (events, oldestSeq, truncated).
func (*EventLog) Watch ¶ added in v0.3.3
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
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
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.
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.
Source Files
¶
- acl.go
- acl_ipgate.go
- address_book.go
- admit.go
- aid_dialer.go
- autopublish.go
- beacon.go
- bootstrap.go
- cas.go
- cas_get.go
- cas_http.go
- cas_local.go
- chat.go
- chat_deliver.go
- chat_http.go
- chat_mcp.go
- connpool.go
- daemon.go
- demo.go
- envelope.go
- event_bus.go
- event_log.go
- fetch.go
- gateway.go
- group_align.go
- group_center.go
- group_http.go
- group_inspect.go
- group_join_probe.go
- group_mailbox.go
- group_mcp.go
- group_sched.go
- group_store.go
- group_sync.go
- hooks.go
- ice_listener.go
- lock_unix.go
- logfilter.go
- mailbox_pending.go
- mailbox_push.go
- mailbox_quic.go
- mailbox_store.go
- mailbox_sub.go
- mcp.go
- netchange.go
- path_settle.go
- profile.go
- remote_admin.go
- routes.go
- service.go
- signal_listen.go
- tunnel.go
- tunnel_tls.go
- wake.go
- wake_acp.go
- wake_exec.go
- wake_http.go
- wake_mcp.go
- wake_spawn_unix.go
- wake_store.go
- webui_embed.go