pub fn agent_config_exists(dir: &Path, name: &str) -> boolExpand description
Convenience: discover whether an agent config exists for name under
dir, on disk, in the embedded default roster (#3046), OR as a plugin
agent (issue #3539/#3547).
Why: Callers (e.g. tools::delegate::DelegateToAgentTool::execute’s
pre-flight gate) sometimes need to pre-check an agent name without
constructing a runner; exposing the same disk-then-embedded(-then-plugin)
rule crate::agents::resolve_agent uses keeps the two in lockstep — a
pre-flight check that only saw disk would reject a real embedded roster
name (e.g. rust-engineer) — or, as of #3539, a real plugin agent —
before the runner ever got a chance to resolve it. Before this fix, a
namespaced <plugin>:<name> always failed here (neither join matched),
so delegate_to_agent’s pre-flight gate rejected every plugin agent as
“unknown” even though resolve_agent could resolve it — plugin agents
were listed but never actually dispatchable (code-critic PR #3547
review, HIGH 4).
What: a namespaced name (containing :) is routed to
plugins::agents::find_plugin_agent_config — gated first by
plugins::is_valid_namespaced_name (the traversal guard; also
redundantly enforced inside find_plugin_agent_config itself, issue
#3547 HIGH 3) and by recovering a project root from dir via
plugins::project_root_two_levels_up. true iff that resolves to
Some(Ok(_)) — a plugin agent must actually load cleanly, NOT merely be
found-but-broken, to pass this gate. This is DELIBERATELY stricter than
the plain-name path below (a bare existence check, not a parseability
one): find_plugin_agent_config can return Some(Err(_)) for a
SECURITY rejection (a symlinked .md file escaping agents_dir —
issue #3547 CRITICAL 5, CWE-59), and that must fail this pre-flight gate
outright rather than let delegate_to_agent proceed to invoke the
runner on a name that can never actually resolve (code-critic PR #3547
re-review — Some(Err(_)) counting as “exists” let a symlink-rejected
name slip past the pre-flight gate; the real InProcessAgentRunner
would still refuse it one layer later via resolve_agent, so content
never reached an LLM prompt either way, but the gate’s whole purpose is
to fail fast with a clear “unknown agent” error before ever attempting
dispatch). Otherwise, unchanged: true iff <dir>/<name>.md exists
(#2897 Slice D — .toml is no longer a loadable source) OR name
matches an entry in crate::assets::DEFAULT_AGENTS.
Test: runner::tests::agent_config_exists_detects_present_and_absent,
runner::tests::agent_config_exists_detects_embedded_default,
runner::tests::agent_config_exists_detects_plugin_agent,
runner::tests::agent_config_exists_rejects_plugin_traversal_name,
runner::tests::agent_config_exists_rejects_symlinked_plugin_agent.