Expand description
Claude Code plugin ingestion, Phase 1: local-directory agents + skills only (issue #3539).
Why: a plugin packages agents/skills for drop-in use the same way a
project’s own .claude/agents/.claude/skills do; this module scans
.claude/plugins/<plugin>/ and layers the result additively, namespaced
<plugin>:<name>, onto agents::protocol::agents_list,
skills::protocol::skills_list, agents::resolve_agent, and
skills::FsSkillResolver — never overriding an unnamespaced
project/embedded/bundled entry.
What: discover_plugin_roots, agents::discover_plugin_agents/
agents::find_plugin_agent_config,
skills::discover_plugin_skills/skills::resolve_plugin_skill_body.
Test: plugins::tests::*, plugins::agents::tests::*,
plugins::skills::tests::*.
Claude Code plugin ingestion, Phase 1: local-directory agents + skills
only (issue #3539).
Why: Claude Code plugins package reusable agents/skills (and, in later
phases, commands/hooks/MCP servers) for drop-in use by a harness. tcode
already parses the exact on-disk formats a plugin ships agents
(.md+frontmatter, see agents::md_loader) and skills (SKILL.md,
progressive disclosure, see crate::skills) in — so Phase 1 is a
discovery + namespacing layer over those existing parsers, not a new
format. Phase 1 is deliberately narrow (#3539’s locked scope): a plugin
is a LOCAL directory under <project_root>/.claude/plugins/<plugin>/
(no marketplace/git fetch), and only agents/ + skills/ are ingested
(no commands/hooks/MCP — later phases). Plugin entries are ADDITIVE
ONLY: they are namespaced <plugin>:<name> in every surface that lists
or resolves them, so they can never collide with — and therefore never
override — an unnamespaced project or embedded/bundled name.
What: PluginRoot is one discovered plugin (resolved name + its
agents/skills directories, honoring .claude-plugin/plugin.json’s
name/agents/skills overrides when present). discover_plugin_roots
scans <project_root>/.claude/plugins/ for plugin subdirectories.
project_root_two_levels_up is the shared seam every integration point
(agents::protocol::agents_list, agents::resolve_agent,
skills::protocol::skills_list, skills::FsSkillResolver) uses to
recover a project root from the .claude/agents or .claude/skills
directory it already holds, without threading a new parameter through
every call site. Submodules agents and skills do the actual
agent/skill discovery, namespacing, and resolution.
Test: tests::* here cover manifest parsing (present/absent/malformed,
name/agents/skills overrides, later-phase key detection) and
discover_plugin_roots scanning; agents::tests/skills::tests cover
the per-domain ingestion contracts.
§Security: plugin content is HOSTILE input (issue #3547)
Everything under .claude/plugins/ — plugin.json, agent/skill
directory names, and frontmatter content — is THIRD-PARTY, not authored
by the project owner the way .claude/agents|skills/ is. Two path-join
sites are therefore treated as adversarial and validated BEFORE any
filesystem join, exactly like agents::protocol::validate_agent_name
already treats a caller-supplied catalog name:
load_plugin_root validates a plugin.json agents/skills
override (a PathBuf::join of an absolute or ..-bearing override
escapes plugin_dir outright — code-critic PR #3547 review, CRITICAL 1)
and is_valid_namespaced_name validates every caller-supplied
<plugin>:<local> dispatch name (a raw local segment containing / or
.. escapes the plugin’s agents_dir/skills_dir — CRITICAL 2 / HIGH
3) before agents::find_plugin_agent_config/
skills::resolve_plugin_skill_body ever join it onto a directory.
A third, independent hole (re-review, CRITICAL 5, CWE-59): the
DIRECTORY-path and NAME guards above say nothing about the LEAF FILE a
validated name resolves to — std::fs::read_to_string,
Path::is_dir/is_file all FOLLOW symlinks, so a plugin can ship
agents/leak.md (or a skills/<name>/SKILL.md, or even skills/<name>
itself) as a symlink to an arbitrary host file/directory (e.g.
~/.ssh/id_rsa); discovery would read the TARGET’s content as that
agent’s system prompt or skill body, which then reaches an LLM prompt
verbatim once dispatched. path_is_contained closes this: every
point a discovered .md/SKILL.md file’s content is actually read
(agents::load_plugin_agent, skills::discover_one_plugin_skills,
skills::resolve_plugin_skill_body) canonicalizes the full leaf path
and requires it stay contained within the already-validated
agents_dir/skills_dir — since canonicalize resolves every symlink
in the path, not just the final component, one check catches a
symlinked leaf file, a symlinked intermediate directory, or both.
Modules§
- agents
- Phase-1 plugin AGENT ingestion: discovery, namespacing, and resolution (issue #3539).
- skills
- Phase-1 plugin SKILL ingestion: discovery, namespacing, and body resolution (issue #3539).
Structs§
- Plugin
Root - One discovered plugin: its resolved name and the directories its agents and skills live under.
Functions§
- discover_
plugin_ roots - Discover every plugin under the project’s resolved
plugins/directory. - is_
valid_ namespaced_ name - Whether
nameis a well-formed<plugin>:<local>namespaced dispatch name — the ONE shape every plugin-aware caller (agents::resolve_agent,plugins::agents::find_plugin_agent_config,plugins::skills::resolve_plugin_skill_body,skills::FsSkillResolver::resolve,tools::delegate::DelegateToAgentTool, the CLI’srun-taskvalidation,runner::agent_config_exists) accepts (code-critic PR #3547 review, CRITICAL 2 / HIGH 3 / HIGH 4).