Skip to main content

Module protocol

Module protocol 

Source
Expand description

agents.* JSON-RPC methods — the daemon’s full-tier AGENT CATALOG surface (issue #3449), backing the Foundry GUI’s Agents management tab.

Why: distinct from session.get_agents (crate::serve::rest::agents / crate::session::protocol_agents), which answers “who is running (or ran) inside one existing session” — this module answers “what agents could I dispatch?”, independent of any session. The GUI’s Agents tab needs to list every agent across BOTH tiers resolve_agent already recognises (embedded ∪ disk — see super::resolve_agent’s docs) and let an operator add/remove disk-tier ones; the embedded roster (32 agents incl. pm, #2958/#3437) is compiled in and therefore read-only. There is exactly ONE disk tier active at a time — <binding root>/.claude/agents when a project is bound, ~/.claude/agents (Claude-Code’s user-level convention) when projectless (see crate::binding::ProjectBinding::agents_dir) — so every disk entry this module reports carries the SAME tier label for one daemon instance, computed once at register time from how the daemon itself was started, never re-derived per request. What: register wires three methods onto a shared, immutable AgentsCatalogState (dir + tier, both fixed for the daemon’s lifetime — no Mutex needed, every operation here is a stateless filesystem call):

  • agents.list -> {"agents": [{name, tier, description?, model?}]}, the union of the embedded roster (tier: "embedded") and the resolved disk tier (tier: "project" or "user") — a disk agent overriding an embedded name WINS and suppresses the embedded copy of that name, mirroring super::resolve_agent’s disk-wins precedence exactly (so the catalog never shows the same name twice with two different tiers). An unparseable disk file surfaces as tier: "broken" (see [agents_list]’s docs) — again mirroring resolve_agent, whose disk-wins rule applies even to a malformed file, so dispatch of that name fails rather than falling back.
  • agents.create{name, content} -> writes <dir>/<name>.md from the caller-supplied Markdown+frontmatter body. Rejects (see [validate_agent_name]) a name that is empty, exceeds [MAX_AGENT_NAME_LEN], contains anything outside [a-z0-9-], or collides with an EMBEDDED name (embedded is read-only — this endpoint never lets a disk file silently shadow it) with -32001 permission_denied (403); an already-existing disk file of the same name with a -32009 already_exists conflict (409, use delete-then-create to replace).
  • agents.delete{name} -> removes <dir>/<name>.md. -32002 not_found (404) if no disk file exists under that name; -32001 permission_denied (403) if name names an EMBEDDED agent (nothing to delete on disk — the embedded roster cannot be removed).

Test: tests::*.

Structs§

AgentsCatalogState
Shared, immutable state every agents.* handler in this module closes over: the resolved disk agents directory and its tier label for this daemon instance.

Functions§

register
Register agents.list, agents.create, agents.delete onto router.