Arcana::Directory
Registry of agent and service capabilities.
Address format:
- A routing label — any single token matching
[a-z][a-z0-9-]*, or anowner:capability-style two-token form (both halves matching the same pattern). Colons in the address are just a naming convention now, not a type marker. - Kind (agent vs service) and capability (chat/image/tts/...) are explicit fields on the listing. Legacy callers that don't set them get the old behavior: kind is derived from the address (colon = service), and capability is the substring after the colon.
- Internal ephemeral mailboxes (
_reply:<id>) are carved out by a leading underscore and are neither agents nor services. - Topics (
#news,#arcana.releases) are shared logs: seeTopicLogandBus#publish. Their names may have dot-separated parts.
Constants
Agent handles use the leading @ sigil so a process representing
a conversational identity ("@mj", "@arcana") doesn't collide with
a same-project tool service registered at the bare name ("mj",
"arcana"). Enforced at register time: kind=agent addresses MUST
start with @, and kind=service addresses MUST NOT. The bus
still routes purely on the address string — the sigil is a naming
convention that the registration path enforces so senders can
tell at a glance who's an agent.
Token body: what an address (or each half of a colon-form address) must match after any leading sigil is stripped.
Topics use the leading # sigil, and their names may have
dot-separated parts: #news, #arcana.releases.
Class methods
Migrate a pre-0.14 address to the new format. Returns nil for addresses that can't be sensibly mapped — callers should skip them with a warning rather than fabricate a bogus owner.
"memo:agent" → "memo" "chat:openai:service" → "openai:chat" (owner-first reorder) "memo:service" → nil (no owner in old form — drop) "owner:cap" / "foo" → unchanged
The owner-less ":service" form was a degenerate case from the original two-token convention. Rewriting it to "<name>:legacy" (as 0.14.0 originally did) preserved the entry but introduced a made-up owner that misleads readers; cleaner to drop and let the registrant re-register with a proper owner:capability.
TODO: remove this whole helper in 0.16 once no downstream consumers carry pre-0.14 snapshots.
Return the owner half of an owner:capability address, or nil for
any other (an agent's, a topic's, a Toolset's bare name).
Is this address a service's? (No sigil: a Toolset's bare name or
owner:capability; not an internal ephemeral.) Registration holds
every listing to its sigil, so the shape tells the kind.
Validate address format. Raises if malformed. Accepts:
foo— bare single token@foo— agent-handle single token (leading@sigil)#foo,#foo.bar— topic (leading#sigil, dot-separated parts)owner:capability— two-token colon form (@not allowed here)_reply:<hex>— internal ephemeral, exempt from validation
Instance methods
How long an agent listing lives without activity before
prune_stale_agents drops it. When set, agent listings report
expires_at (last seen + TTL). The pruner still takes its TTL as
an argument; set both to the same value.
How long an agent listing lives without activity before
prune_stale_agents drops it. When set, agent listings report
expires_at (last seen + TTL). The pruner still takes its TTL as
an argument; set both to the same value.
Listings provided by a given owner (service address prefix).
Raises HeldError unless the caller shows what address is held
under: its owner token, or the key holding it (one the caller has
proved it holds). Addresses held by neither accept anything.
Raises HeldError unless owner_token matches the owner token the
address is held under. Addresses held by neither a token nor a key
accept anything; one held by a key alone needs check_holder!.
Register listing, or refresh it when owner_token shows the
caller already holds the address. This is how an agent that
forgot it registered (or whose session hook registered for it)
tells "that's me" from "someone else has it".
- Free address: registered, under
owner_tokenif one is given. - Held under the same owner token: the listing is refreshed from
listing(fields it leaves out keep their values), marked online, and its last-seen time updated. - Held without an owner token: taken over under
owner_token. An unowned listing protects nothing, so taking it gives nothing away. - Otherwise raises:
HeldErrorwhen another owner token holds it,Error("Address already registered") when neither side has one.
With key, a public key the caller has proved it holds (see
Signing), the address is held by that key instead:
- Free, or held by neither a key nor a token: held by the key.
- Held by the same key: refreshed (
Yours). - Held under an owner token, shown here: held by the key too
(
Moved), so a project's address moves to its key once. Until owner tokens retire, the token still works for it. - Held by another key, or under a token not shown:
HeldError.
An address held by a key and no token can't be claimed by a token.
Optional event recorder. When set, material directory actions (register, unregister, busy changes, prune) emit events.
Optional event recorder. When set, material directory actions (register, unregister, busy changes, prune) emit events.
Public keys by address (for snapshot save). Listings show them too: a public key is no secret.
Load listings from a JSON file. Skips addresses already registered (so built-in services registered in code take precedence). Tolerates pre-0.14 address formats and rewrites them in-place.
Look up a listing by address. Returns nil if not found.
Owner tokens by address (for snapshot save). Never serialized in directory listings.
Remove agent listings older than ttl. Services are never pruned
(they get re-registered from code on each startup anyway).
Returns the list of pruned addresses.
The walk collects candidates under the mutex, releases it, then re-acquires briefly per-address for each delete. Each delete re-verifies staleness — a re-registration between the walk and the delete is respected. Keeps every mutex acquisition O(1), so registration/lookup can slip through even during a large prune sweep.
Register a listing. Raises if the address is malformed, already taken, or its sigil doesn't match its kind.
Replace the tags on an existing listing. No-op if unregistered. Toolset uses this at start time to union user-provided tags with the names of its registered tools.
Search listings by substring match on name, description, or tags.
Restore the key holding an address (for snapshot load).
Set the last-seen timestamp directly (used by snapshot restore).
Mark a listing online or offline. Offline means no session is
running for it; its mailbox keeps collecting mail. claim marks
it online again.
Restore an owner token (for snapshot load).
Supplies a topic's TopicStatus for its listing. Bus#directory=
sets it; without it, topic listings show only their registration.
Supplies a topic's TopicStatus for its listing. Bus#directory=
sets it; without it, topic listings show only their registration.