Skip to main content

trusty_code/agents/
md_loader.rs

1//! Markdown+frontmatter agent loader for tcode — the ONLY on-disk agent
2//! source format as of #2897 Slice D (epic #2892). It was DARK-LAUNCHED
3//! alongside the (now-retired) TOML loader in Slice B, and became the loader
4//! for tcode's own EMBEDDED default agents in Slice C.
5//!
6//! Why: trusty-agents-common's `agents::builder` compose machinery (Slice A,
7//! #2952) already resolves `extends:` inheritance chains for trusty-mpm's
8//! `.md` agent format and now carries `max_tokens`/`tools` frontmatter fields
9//! that mirror tcode's `AgentConfig` schema. Rather than fork a second `.md`
10//! parser, tcode reuses that composer and projects its output onto its
11//! existing `AgentConfig`. Slice C (#2897) additionally routes
12//! `crate::assets::DEFAULT_AGENTS`'s embedded fallback through this module:
13//! the embedded strings have no source directory to resolve an `extends:`
14//! chain against (they are compiled-in `&'static str`, not files on disk), so
15//! [`project_embedded_md`] skips `compose_agent` entirely and calls
16//! [`agent_metadata_from_str`]/[`extract_body`] directly on the raw string —
17//! both are already string-in, string/struct-out, so no file-path dependency
18//! stands in the way. The two entry points ([`load_md_agent`] for disk,
19//! [`project_embedded_md`] for embedded strings) share the exact same
20//! [`project_to_agent_config`] mapping, so there is only ever one frontmatter
21//! -> `AgentConfig` projection to maintain.
22//! What: [`load_md_agent`] reads a `.md` agent source file, calls
23//! `trusty_agents_common::agents::builder::compose_agent` to resolve its
24//! `extends:` chain into one flattened document, projects the composed
25//! frontmatter (via `agents::metadata::agent_metadata_from_str`) and prose
26//! body onto tcode's `AgentConfig`. [`project_embedded_md`] does the same
27//! projection for an in-memory `&'static str` with no `extends:` resolution.
28//! Test: `load_md_agent_base_case`, `tools_projection_*` (the
29//! `Option<Vec<String>>` direct-map), `hr1_initial_prompt_not_leaked_into_body`
30//! (the HR-1 guard), `assets::tests::*` (embedded-default field-identity vs.
31//! the retired TOML fixtures, kept as a historical regression pin).
32
33use std::path::Path;
34
35use trusty_agents_common::agents::builder::compose_agent;
36use trusty_agents_common::agents::builder_in_memory::{
37    build_in_memory_source_map, compose_agent_in_memory,
38};
39use trusty_agents_common::agents::metadata::{AgentMetadata, agent_metadata_from_str};
40
41use super::config::{AgentConfig, AgentInfo, LlmParams, SystemPrompt, ToolsConfig};
42
43/// Load a tcode [`AgentConfig`] from a `.md` agent source file.
44///
45/// Why: the primary entry point for the (now sole) agent loader — takes a
46/// file path and returns a fully-populated `AgentConfig` or a descriptive
47/// error.
48/// What: resolves `path`'s parent directory as the `extends:` source dir and
49/// its file stem as the agent name, composes the inheritance chain via
50/// `compose_agent`, then projects the result via [`project_to_agent_config`].
51/// A missing parent directory, an unreadable file stem, or any
52/// `AgentBuildError` (not found, cycle, depth exceeded, malformed
53/// frontmatter) is surfaced as a descriptive `anyhow::Error` — never a panic.
54/// #8129: a disk document declaring only Claude Code's `tools:` vocabulary
55/// additionally gets that grant translated into a tcode allowlist by
56/// `agents::claude_tools::apply_claude_tools_fallback`, which the embedded
57/// projection paths below deliberately do not call.
58/// Test: `load_md_agent_base_case`, `load_md_agent_missing_file_errors`,
59/// `load_md_agent_with_extends_resolves_chain`,
60/// `agents::claude_tools::tests::translates_the_shared_version_control_grant`.
61pub fn load_md_agent(path: &Path) -> anyhow::Result<AgentConfig> {
62    let source_dir = path
63        .parent()
64        .ok_or_else(|| anyhow::anyhow!("agent file {} has no parent directory", path.display()))?;
65    let name = path
66        .file_stem()
67        .and_then(|s| s.to_str())
68        .ok_or_else(|| anyhow::anyhow!("agent file {} has no usable file stem", path.display()))?;
69
70    let composed = compose_agent(name, source_dir).map_err(|e| {
71        anyhow::anyhow!(
72            "failed to compose agent '{name}' from {}: {e}",
73            path.display()
74        )
75    })?;
76    // #7727: a body carrying `{{TM_SKILLS}}` points at the address `read_file` serves.
77    let composed =
78        super::skill_refs::resolve_skill_refs(&composed, &super::skill_refs::user_skill_refs_dir());
79
80    let metadata = agent_metadata_from_str(&composed);
81    let body = extract_body(&composed);
82
83    let mut config = project_to_agent_config(name, metadata.clone(), body);
84    // #8129: a DISK agent authored for Claude Code declares its grant as
85    // `tools: [Read, Bash, ...]`. `project_to_agent_config` ignores that
86    // vocabulary (#7683), leaving `allowed: None` — every tool allowed, the
87    // opposite of the author's grant. Translate it when, and only when, the
88    // document declared no `tcode_tools:`. Embedded agents never take this
89    // path, so the roster's #7683 behaviour is unchanged.
90    super::claude_tools::apply_claude_tools_fallback(&mut config, &metadata);
91    // #7948: parse the file's OWN bytes — `compose_agent` does not re-emit
92    // `permissions:`, so a block is not inherited through `extends:`. A
93    // malformed block fails the load; it never degrades to "no permissions".
94    let raw = std::fs::read_to_string(path)
95        .map_err(|e| anyhow::anyhow!("failed to read agent file {}: {e}", path.display()))?;
96    config.permissions = crate::permissions::parse_permissions(&path.display().to_string(), &raw)?;
97    if config.permissions.is_none() {
98        config.permissions = deployed_roster_permissions(name, &raw)?;
99    }
100    Ok(config)
101}
102
103/// The EMBEDDED roster card's `permissions:` block, when `raw` is a deployed
104/// copy of that same card and carries none of its own (#8184).
105///
106/// Why: the roster deployer re-emits frontmatter from a fixed key list
107/// (`trusty_agents_common::agents::builder`), which does not include
108/// `permissions:`, so a materialized `<project>/.trusty-code/agents/<name>.md`
109/// silently loses the block its source declared — and an agent with no block is
110/// allowed everything. Since #8184's interactive default runs the stock `pm`
111/// SOLO, with `write_file`/`edit`/`bash` in the user's own project root, that
112/// drop would turn a card that asks into a run that never prompts. Restoring
113/// the source's block here keeps the shipped card authoritative until the
114/// shared emitter carries the key itself.
115/// What: applies ONLY to a file the deployer wrote — read as the PARSED
116/// `provenance:` key, not as a substring, so a quoting or ordering change in
117/// the emitter cannot silently turn this into a no-op — whose stem names a
118/// `Direct` embedded agent, and ONLY when the file declares no block of its
119/// own. A hand-authored card, or a deployed one a user has since given rules,
120/// is never second-guessed. A malformed block in the embedded source is an
121/// `Err`, same fail-closed contract as `parse_permissions` above.
122/// Test: `deployed_roster_copy_recovers_the_cards_permissions`,
123/// `hand_authored_file_gets_no_embedded_permissions`.
124fn deployed_roster_permissions(
125    name: &str,
126    raw: &str,
127) -> anyhow::Result<Option<crate::permissions::PermissionMap>> {
128    if agent_metadata_from_str(raw).provenance
129        != Some(trusty_agents_common::agents::provenance::Provenance::FrameworkOwned)
130    {
131        return Ok(None);
132    }
133    let Some(md) = crate::assets::DEFAULT_AGENTS.iter().find_map(|a| match a {
134        crate::assets::EmbeddedAgent::Direct { name: n, md } if *n == name => Some(*md),
135        _ => None,
136    }) else {
137        return Ok(None);
138    };
139    Ok(crate::permissions::parse_permissions(name, md)?)
140}
141
142/// Project an embedded (in-memory, no source directory) `.md` agent document
143/// onto tcode's [`AgentConfig`] — the entry point for
144/// `crate::assets::DEFAULT_AGENTS`'s embedded fallback (Slice C, #2897).
145///
146/// Why: `load_md_agent` resolves an `extends:` inheritance chain via
147/// `compose_agent`, which requires a real source directory to scan for
148/// sibling `.md` files. Embedded default agents are compiled-in
149/// `&'static str` constants with no filesystem location and no `extends:`
150/// chain, so composing would be both impossible (no directory to resolve
151/// against) and unnecessary (none of the three bundled defaults declare
152/// `extends:`). This function shares every other step of the projection —
153/// [`agent_metadata_from_str`] for the frontmatter and [`extract_body`] for
154/// the prose body — with [`load_md_agent`], so the frontmatter -> `AgentConfig`
155/// mapping in [`project_to_agent_config`] is written and tested exactly once.
156/// What: parses `raw`'s frontmatter and body directly (no `compose_agent`
157/// call), then delegates to [`project_to_agent_config`]. `default_name` is
158/// used only when `raw`'s frontmatter carries no `name:` field, mirroring
159/// `load_md_agent`'s file-stem fallback. `raw`'s own `permissions:` block is
160/// parsed exactly as [`load_md_agent`] parses a file's; a malformed block is
161/// an `Err`, never "no permissions".
162/// Test: `assets::tests::default_agents_field_identical_to_retired_toml`,
163/// `assets::tests::default_agents_parse_and_names_match`,
164/// `embedded_permissions_block_projects_onto_agent_config`,
165/// `malformed_embedded_permissions_block_fails_the_load`.
166pub(crate) fn project_embedded_md(default_name: &str, raw: &str) -> anyhow::Result<AgentConfig> {
167    let metadata = agent_metadata_from_str(raw);
168    let body = extract_body(raw);
169    let mut config = project_to_agent_config(default_name, metadata, body);
170    // #7948: a bundled agent's block is enforced like a disk agent's.
171    config.permissions =
172        crate::permissions::parse_permissions(&format!("embedded agent '{default_name}'"), raw)?;
173    Ok(config)
174}
175
176/// Project a tm-catalog agent onto tcode's [`AgentConfig`], resolving its
177/// `extends:` chain entirely in memory against the catalog
178/// `crate::assets::load_tm_agent_sources` reads from instructional content
179/// (Slice E2, #2958; content since #9011).
180///
181/// Why: [`project_embedded_md`] handles tcode's own 3 defaults, none of
182/// which declare `extends:`. The bundled tm agent catalog (5 `BASE-*`
183/// templates + 26 coding-relevant roster agents) DOES use `extends:`
184/// chains -- e.g. `rust-engineer` extends `base-engineer` extends
185/// `base-agent` -- and [`compose_agent`] can't resolve those because it
186/// requires a real `source_dir` to scan, which embedded `&'static str`
187/// constants don't have. `trusty_agents_common::agents::builder_in_memory`
188/// (Slice E1, PR #3013) supplies the disk-free counterpart: an
189/// `InMemorySources` map plus `compose_agent_in_memory`, built here from
190/// the loaded catalog and passed the requested `name`. A content error (none
191/// installed, unverifiable) is an `Err` naming `tm content install`.
192/// What: builds an `InMemorySources` map from the embedded catalog table,
193/// resolves `name`'s `extends:` chain via `compose_agent_in_memory`, then
194/// projects the composed document through the same
195/// `agent_metadata_from_str` + `extract_body` + [`project_to_agent_config`]
196/// pipeline [`load_md_agent`] uses for the disk path -- so embedded and
197/// on-disk `.md` agents share one frontmatter -> `AgentConfig` mapping. Any
198/// `AgentBuildError` (unknown name, cycle, depth exceeded, malformed
199/// frontmatter anywhere in the chain) is surfaced as a descriptive
200/// `anyhow::Error`, never a panic. Called from
201/// `crate::agents::load_embedded_default_agents` for every
202/// `crate::assets::EmbeddedAgent::Composed` entry in `DEFAULT_AGENTS` (Slice
203/// E3, #2958; 26 since #8129) -- the roster agents are dispatchable defaults as of this
204/// slice.
205/// Test: `project_embedded_md_with_extends_resolves_rust_engineer_from_base_engineer`,
206/// `project_embedded_md_with_extends_unknown_name_errors`,
207/// `assets::tests::default_agents_parse_and_names_match`.
208pub fn project_embedded_md_with_extends(name: &str) -> anyhow::Result<AgentConfig> {
209    project_embedded_md_with_extends_at(name, &super::skill_refs::user_skill_refs_dir())
210}
211
212/// [`project_embedded_md_with_extends`] with the skill-refs root supplied.
213///
214/// Why (#7727): the hermetic core, so a test resolves `{{TM_SKILLS}}` against
215/// a temp dir instead of the developer's real `~/.trusty-code`.
216/// What: composes as the wrapper does, then
217/// [`super::skill_refs::resolve_skill_refs`] against `skill_refs_root`, which
218/// never writes and never fails, so the refs root cannot drop an agent.
219/// Test: `embedded_agent_skill_pointers_open_with_read_file`,
220/// `embedded_agent_composes_when_refs_dir_is_unwritable`,
221/// `embedded_agent_composes_when_refs_dir_is_relative`.
222pub fn project_embedded_md_with_extends_at(
223    name: &str,
224    skill_refs_root: &Path,
225) -> anyhow::Result<AgentConfig> {
226    let catalog = crate::assets::load_tm_agent_sources()?;
227    project_embedded_md_with_extends_from(name, &catalog, skill_refs_root)
228}
229
230/// [`project_embedded_md_with_extends_at`] over a catalog already loaded, so
231/// a batch resolves content once (#9011).
232pub(crate) fn project_embedded_md_with_extends_from(
233    name: &str,
234    catalog: &[(String, String)],
235    skill_refs_root: &Path,
236) -> anyhow::Result<AgentConfig> {
237    let entries: Vec<(&str, &str)> = catalog
238        .iter()
239        .map(|(file, md)| (file.as_str(), md.as_str()))
240        .collect();
241    project_in_memory_catalog(name, &entries, skill_refs_root)
242}
243
244/// [`project_embedded_md_with_extends_at`] over a supplied
245/// `(filename, markdown)` catalog.
246///
247/// Why (#7948): no bundled catalog agent declares `permissions:` today, so a
248/// test needs its own catalog to prove a block is enforced and not inherited.
249/// What: composes `name` against `entries`, resolves skill refs, and projects
250/// the result. It then parses the `permissions:` block from `name`'s OWN
251/// catalog entry, never the composed document, so a block is not inherited
252/// through `extends:`. A malformed block is an `Err`.
253/// Test: `embedded_extends_permissions_block_projects_onto_agent_config`,
254/// `malformed_embedded_extends_permissions_block_fails_the_load`.
255fn project_in_memory_catalog(
256    name: &str,
257    entries: &[(&str, &str)],
258    skill_refs_root: &Path,
259) -> anyhow::Result<AgentConfig> {
260    let sources = build_in_memory_source_map(entries.iter().copied());
261
262    let composed = compose_agent_in_memory(name, &sources).map_err(|e| {
263        anyhow::anyhow!("failed to compose embedded tm-catalog agent '{name}': {e}")
264    })?;
265    let composed = super::skill_refs::resolve_skill_refs(&composed, skill_refs_root);
266
267    let metadata = agent_metadata_from_str(&composed);
268    let body = extract_body(&composed);
269
270    let mut config = project_to_agent_config(name, metadata, body);
271    // #7948: the agent's own bytes, as `load_md_agent` reads the file's own.
272    let own = own_catalog_source(name, entries).ok_or_else(|| {
273        anyhow::anyhow!("embedded tm-catalog agent '{name}' composed but has no source entry")
274    })?;
275    config.permissions =
276        crate::permissions::parse_permissions(&format!("embedded tm-catalog agent '{name}'"), own)?;
277    Ok(config)
278}
279
280/// The raw markdown `entries` holds for `name`, keyed the way
281/// `InMemorySources::insert` keys it: lowercased, one `.md` suffix stripped.
282/// The last matching entry wins, as it does on insert.
283fn own_catalog_source<'a>(name: &str, entries: &[(&'a str, &'a str)]) -> Option<&'a str> {
284    fn key(s: &str) -> String {
285        let lower = s.to_lowercase();
286        lower.strip_suffix(".md").unwrap_or(&lower).to_string()
287    }
288    let wanted = key(name);
289    entries
290        .iter()
291        .rev()
292        .find(|(file, _)| key(file) == wanted)
293        .map(|(_, md)| *md)
294}
295
296/// Strip the leading YAML frontmatter block from a composed agent document.
297///
298/// Why: `compose_agent`'s merged frontmatter block may carry an HR-1-injected
299/// `initialPrompt` (auto-derived from the agent's `role:`, keyed off
300/// trusty-mpm's role table — see
301/// `trusty_agents_common::agents::builder::merge_frontmatter`'s "HR-1 Part B"
302/// enrichment). tcode's own role vocabulary (`engineer`/`qa`) collides with
303/// that table, so an mpm-role-derived `initialPrompt` must NEVER leak into
304/// tcode's `system_prompt.content` — tcode's system prompt is the composed
305/// PROSE BODY only, exactly as the TOML loader's `system_prompt.content` is a
306/// hand-authored prompt with no injected preamble. `AgentMetadata` (the
307/// public frontmatter projection this module also uses) already omits
308/// `initial_prompt`/`resource_tier` entirely, so there is no accessor that
309/// could leak it into the projection; this function provides the second,
310/// independent guarantee on the body side by never inspecting the
311/// frontmatter block's contents at all — it locates the closing fence
312/// structurally and returns only what follows.
313/// What: `compose_agent`'s output always opens with a `---` line; this scans
314/// past it to the next `---` line and returns everything after, trimmed. A
315/// document with no opening fence (defensive fallback; `compose_agent` always
316/// emits one) returns the whole string trimmed.
317/// Test: `hr1_initial_prompt_not_leaked_into_body`,
318/// `interior_horizontal_rule_survives_in_body`,
319/// `frontmatter_only_agent_has_empty_body`.
320///
321/// `pub(crate)`: also reused by `plugins::agents::load_plugin_agent` (#3539)
322/// so a plugin agent's body is stripped identically to a disk agent's,
323/// without a second frontmatter-fence scanner.
324pub(crate) fn extract_body(composed: &str) -> String {
325    let mut lines = composed.lines();
326    match lines.next() {
327        Some(first) if first.trim() == "---" => {}
328        _ => return composed.trim().to_string(),
329    }
330
331    let mut in_frontmatter = true;
332    let mut body_lines: Vec<&str> = Vec::new();
333    for line in lines {
334        if in_frontmatter {
335            if line.trim() == "---" {
336                in_frontmatter = false;
337            }
338            continue;
339        }
340        body_lines.push(line);
341    }
342    body_lines.join("\n").trim().to_string()
343}
344
345/// Project a composed `.md` agent's metadata + body onto tcode's `AgentConfig`.
346///
347/// Why: centralises the frontmatter -> TOML-schema field mapping so
348/// `load_md_agent` stays a thin IO/compose wrapper.
349/// What:
350/// - `name` -> `agent.name` (falls back to the file-stem `default_name` when
351///   the frontmatter declares no `name:`, mirroring how a source file is
352///   identified by its filename).
353/// - `role`/`description` -> `agent.role`/`agent.description` (direct map).
354/// - `model` -> `agent.model` (the higher-precedence slot per
355///   `provider::routing::resolve_model`; `llm.model_override` is left unset —
356///   the `.md` frontmatter has exactly one model concept, matching how the
357///   TOML fixtures set `[agent].model` and leave `[llm].model_override` unset).
358/// - `max_tokens` -> `llm.max_tokens` (direct map).
359/// - `tcode_tools: Option<Vec<String>>` -> `ToolsConfig.allowed` (DIRECT map,
360///   #7683 — `tools:` is Claude Code's vocabulary and is IGNORED here; both
361///   sides share identical `None`=all-allowed / `Some([])`=deny-all /
362///   `Some(list)`=allowlist semantics, per `Frontmatter::tools`'s doc comment
363///   and `runner::in_process`'s `agent.tools.as_ref().and_then(|t|
364///   t.allowed.as_ref())` consumer, which treats an absent `[tools]` section
365///   (outer `None`) and a present-but-unset `allowed` identically — so always
366///   wrapping in `Some(ToolsConfig { allowed })` is safe and matches the
367///   instructed direct-map). #8129 narrowed the "IGNORED" half to the EMBEDDED
368///   paths only: [`load_md_agent`] now translates a disk document's `tools:`
369///   through `agents::claude_tools` when it declared no `tcode_tools:`.
370/// - composed prose body -> `system_prompt.content`.
371/// - `skills:` -> `system_prompt.append_skills` (direct map, #2074). This was
372///   deliberately DROPPED until `crate::agents::describe` gave it a consumer:
373///   an agent's declared skills are part of the effective configuration
374///   `agents.describe` reports. Nothing INJECTS them into the prompt yet, so
375///   the field is a reporting surface rather than a runtime one — a
376///   distinction the describe payload's own docs state, so no caller can read
377///   a reported skill as an enforced one.
378///
379/// `pub(crate)`: also reused by `plugins::agents::load_plugin_agent` (#3539),
380/// which calls this with the plugin's LOCAL agent name (not yet namespaced)
381/// and overrides `agent.name` with the namespaced form afterward — so the
382/// frontmatter -> `AgentConfig` mapping stays written exactly once across
383/// disk, embedded, and plugin agents.
384pub(crate) fn project_to_agent_config(
385    default_name: &str,
386    meta: AgentMetadata,
387    body: String,
388) -> AgentConfig {
389    AgentConfig {
390        agent: AgentInfo {
391            name: meta.name.unwrap_or_else(|| default_name.to_string()),
392            role: meta.role,
393            model: meta.model,
394            description: meta.description,
395        },
396        llm: LlmParams {
397            temperature: None,
398            max_tokens: meta.max_tokens,
399            model_override: None,
400        },
401        system_prompt: SystemPrompt {
402            content: body,
403            // #2074: `agents.describe` reports an agent's declared skills, so
404            // this is no longer a dead field. Nothing INJECTS them into the
405            // prompt yet — see the doc comment above.
406            append_skills: meta.skills,
407        },
408        // #7683: `tcode_tools`, never `tools`. The shared roster's `tools:`
409        // now carries CLAUDE CODE's vocabulary (`Read`, `Bash`,
410        // `mcp__trusty-search`), which intersects this runtime's registry at
411        // zero tools — `ToolRegistry::gated` matches by exact name, so
412        // honouring it here would leave every embedded roster agent unable to
413        // call anything, `finish_task` included.
414        tools: Some(ToolsConfig {
415            allowed: meta.tcode_tools,
416        }),
417        runner: None,
418        // #7948: nested YAML the flat metadata reader cannot represent; the
419        // fallible loading paths attach it from the document bytes.
420        permissions: None,
421    }
422}
423
424#[cfg(test)]
425mod tests {
426    use super::*;
427
428    /// A `.md` agent with no `extends:` composes and projects cleanly.
429    ///
430    /// Why: the base case — a self-contained agent, no inheritance chain.
431    /// What: writes a single `.md` file, loads it, asserts every projected
432    /// field.
433    /// Test: this test.
434    #[test]
435    fn load_md_agent_base_case() {
436        let tmp = tempfile::tempdir().expect("tempdir");
437        std::fs::write(
438            tmp.path().join("solo.md"),
439            "---\nname: solo\nrole: engineer\ndescription: A lone agent\nmodel: sonnet\nmax_tokens: 4096\ntcode_tools: [read_file, grep]\n---\n\nYou are a solo agent.\n",
440        )
441        .expect("write");
442
443        let cfg = load_md_agent(&tmp.path().join("solo.md")).expect("load");
444        assert_eq!(cfg.agent.name, "solo");
445        assert_eq!(cfg.agent.role.as_deref(), Some("engineer"));
446        assert_eq!(cfg.agent.description.as_deref(), Some("A lone agent"));
447        assert_eq!(cfg.agent.model.as_deref(), Some("sonnet"));
448        assert_eq!(cfg.llm.max_tokens, Some(4096));
449        assert_eq!(cfg.system_prompt.content, "You are a solo agent.");
450        assert_eq!(
451            cfg.tools.and_then(|t| t.allowed),
452            Some(vec!["read_file".to_string(), "grep".to_string()])
453        );
454    }
455
456    /// `tcode_tools:` projects with identical `Option<Vec<String>>` semantics
457    /// on both sides: absent key -> `None` (all allowed), `tcode_tools: []` ->
458    /// `Some([])` (deny-all), `tcode_tools: [a, b]` -> `Some([a, b])`.
459    ///
460    /// Why: this is the load-bearing contract from Slice A (#2952) — a naive
461    /// `is_empty()` check would collapse deny-all into "inherit"/"allow-all".
462    /// What: three fixtures, one per case.
463    /// Test: this test.
464    #[test]
465    fn tools_projection_absent_is_none() {
466        let tmp = tempfile::tempdir().expect("tempdir");
467        std::fs::write(
468            tmp.path().join("a.md"),
469            "---\nname: a\nrole: engineer\n---\n\nBody.\n",
470        )
471        .expect("write");
472        let cfg = load_md_agent(&tmp.path().join("a.md")).expect("load");
473        assert_eq!(cfg.tools.and_then(|t| t.allowed), None);
474    }
475
476    #[test]
477    fn tools_projection_empty_list_is_deny_all() {
478        let tmp = tempfile::tempdir().expect("tempdir");
479        std::fs::write(
480            tmp.path().join("a.md"),
481            "---\nname: a\nrole: engineer\ntcode_tools: []\n---\n\nBody.\n",
482        )
483        .expect("write");
484        let cfg = load_md_agent(&tmp.path().join("a.md")).expect("load");
485        assert_eq!(cfg.tools.and_then(|t| t.allowed), Some(vec![]));
486    }
487
488    #[test]
489    fn tools_projection_list_is_allowlist() {
490        let tmp = tempfile::tempdir().expect("tempdir");
491        std::fs::write(
492            tmp.path().join("a.md"),
493            "---\nname: a\nrole: engineer\ntcode_tools: [read_file, grep]\n---\n\nBody.\n",
494        )
495        .expect("write");
496        let cfg = load_md_agent(&tmp.path().join("a.md")).expect("load");
497        assert_eq!(
498            cfg.tools.and_then(|t| t.allowed),
499            Some(vec!["read_file".to_string(), "grep".to_string()])
500        );
501    }
502
503    /// HR-1 GUARD: a `.md` agent declaring `role: engineer` must NOT get an
504    /// mpm-role-derived `initialPrompt` injected into its `system_prompt.content`.
505    ///
506    /// Why: `merge_frontmatter`'s HR-1 Part B enrichment auto-injects
507    /// `initialPrompt: "Begin implementation. ..."` for `role: engineer` (and
508    /// a distinct prompt for `role: qa`) because trusty-mpm agents rely on
509    /// that injection. tcode's roles collide with that same table by name,
510    /// but tcode's system prompt is the composed PROSE BODY only — the
511    /// injected `initialPrompt` lives in the frontmatter block, which
512    /// `extract_body` never inspects, and `AgentMetadata` (the frontmatter
513    /// projection) has no `initial_prompt` field at all. This test proves
514    /// both guarantees hold end-to-end.
515    /// What: an `engineer`-role agent whose body is a short known string;
516    /// asserts `system_prompt.content` equals exactly that string with no
517    /// HR-1 preamble prepended or appended.
518    /// Test: this test.
519    #[test]
520    fn hr1_initial_prompt_not_leaked_into_body() {
521        let tmp = tempfile::tempdir().expect("tempdir");
522        std::fs::write(
523            tmp.path().join("eng.md"),
524            "---\nname: eng\nrole: engineer\n---\n\nYou write Rust code.\n",
525        )
526        .expect("write");
527
528        let cfg = load_md_agent(&tmp.path().join("eng.md")).expect("load");
529        assert_eq!(
530            cfg.system_prompt.content, "You write Rust code.",
531            "HR-1's role-derived initialPrompt must not leak into the body"
532        );
533        assert!(
534            !cfg.system_prompt.content.contains("Begin implementation"),
535            "HR-1's engineer-role initialPrompt text must not appear anywhere in the body"
536        );
537    }
538
539    /// `extends:` chains resolve through `compose_agent` exactly as
540    /// trusty-mpm's own `.md` agents do.
541    ///
542    /// Why: proves the composer is genuinely reused, not reimplemented.
543    /// What: a base + child fixture; the child's `AgentConfig` carries the
544    /// base's body concatenated before the child's, and the child's
545    /// `max_tokens` wins (scalar child-wins merge).
546    /// Test: this test.
547    #[test]
548    fn load_md_agent_with_extends_resolves_chain() {
549        let tmp = tempfile::tempdir().expect("tempdir");
550        std::fs::write(
551            tmp.path().join("base-x.md"),
552            "---\nname: base-x\nmax_tokens: 1000\n---\n\nBase instructions.\n",
553        )
554        .expect("write");
555        std::fs::write(
556            tmp.path().join("child.md"),
557            "---\nname: child\nextends: base-x\nmax_tokens: 2000\n---\n\nChild instructions.\n",
558        )
559        .expect("write");
560
561        let cfg = load_md_agent(&tmp.path().join("child.md")).expect("load");
562        assert_eq!(cfg.agent.name, "child");
563        assert_eq!(cfg.llm.max_tokens, Some(2000), "child max_tokens wins");
564        assert!(cfg.system_prompt.content.contains("Base instructions."));
565        assert!(cfg.system_prompt.content.contains("Child instructions."));
566    }
567
568    /// A missing `.md` file surfaces a descriptive error, never a panic.
569    ///
570    /// Why: `load_all_agents` needs a fallible, never-panicking contract so
571    /// it can `filter_map` a directory listing without one bad path
572    /// crashing the whole scan.
573    /// What: `load_md_agent` on a nonexistent path returns `Err`.
574    /// Test: this test.
575    #[test]
576    fn load_md_agent_missing_file_errors() {
577        let result = load_md_agent(Path::new("/nonexistent/agents/dir/ghost.md"));
578        assert!(result.is_err());
579    }
580
581    /// A full-fidelity `.md` fixture projects every field the schema exposes
582    /// in one document (name, role, model, max_tokens, tools, system-prompt
583    /// body) — the successor to Slice B's retired
584    /// `parallel_fixture_equivalence` (which additionally compared against a
585    /// hand-authored TOML twin; #2897 Slice D removed the TOML loader that
586    /// comparison depended on, so this test keeps the full-field-set
587    /// assertion on the `.md` fixture alone).
588    ///
589    /// Why: pins that every projected field — not just the ones individual
590    /// narrower tests each cover — round-trips together from one realistic
591    /// agent document.
592    /// What: one `.md` fixture setting every field; asserts `model`,
593    /// `max_tokens`, `tools.allowed`, and `system_prompt.content` all match
594    /// the authored values.
595    /// Test: this test.
596    #[test]
597    fn full_fidelity_md_fixture_projects_every_field() {
598        let tmp = tempfile::tempdir().expect("tempdir");
599
600        std::fs::write(
601            tmp.path().join("twin.md"),
602            "---\nname: twin\nrole: engineer\nmodel: sonnet\nmax_tokens: 8192\ntcode_tools: [read_file, grep]\n---\n\nYou are a twin agent.\n",
603        )
604        .expect("write md");
605
606        let cfg = load_md_agent(&tmp.path().join("twin.md")).expect("load md");
607
608        assert_eq!(cfg.agent.name, "twin");
609        assert_eq!(cfg.agent.role.as_deref(), Some("engineer"));
610        assert_eq!(cfg.agent.model.as_deref(), Some("sonnet"));
611        assert_eq!(cfg.llm.max_tokens, Some(8192));
612        assert_eq!(
613            cfg.tools.and_then(|t| t.allowed),
614            Some(vec!["read_file".to_string(), "grep".to_string()])
615        );
616        assert_eq!(cfg.system_prompt.content, "You are a twin agent.");
617    }
618
619    /// `extract_body` closes the frontmatter block on the FIRST `---` fence
620    /// only and never re-enters — a `---` line appearing later, inside the
621    /// prose body (a markdown horizontal rule between two paragraphs), must
622    /// survive verbatim in `system_prompt.content` rather than being mistaken
623    /// for a second frontmatter delimiter.
624    ///
625    /// Why: code-critic finding on PR #2954 — this is the highest-risk edge
626    /// case in the fence-scanning loop (`in_frontmatter` flips to `false` and
627    /// stays `false`), and had no regression pin.
628    /// What: a `.md` fixture whose body contains a paragraph, a bare `---`
629    /// horizontal-rule line, then a second paragraph. Loads through the real
630    /// `compose_agent` -> `load_md_agent` path (not `extract_body` in
631    /// isolation) so the assertion exercises the actual composed output.
632    /// Asserts the horizontal rule is present verbatim as its own line in the
633    /// resulting body.
634    /// Test: this test.
635    #[test]
636    fn interior_horizontal_rule_survives_in_body() {
637        let tmp = tempfile::tempdir().expect("tempdir");
638        std::fs::write(
639            tmp.path().join("hr.md"),
640            "---\nname: hr\nrole: engineer\n---\n\nFirst paragraph.\n\n---\n\nSecond paragraph.\n",
641        )
642        .expect("write");
643
644        let cfg = load_md_agent(&tmp.path().join("hr.md")).expect("load");
645        assert!(
646            cfg.system_prompt
647                .content
648                .lines()
649                .any(|line| line.trim() == "---"),
650            "interior horizontal rule must survive verbatim as its own line; got: {:?}",
651            cfg.system_prompt.content
652        );
653        assert!(cfg.system_prompt.content.contains("First paragraph."));
654        assert!(cfg.system_prompt.content.contains("Second paragraph."));
655    }
656
657    /// A `.md` agent with a valid frontmatter block and NO prose body after
658    /// the closing fence projects to an EMPTY `system_prompt.content` — no
659    /// panic, no leftover blank lines, no stray `---`.
660    ///
661    /// Why: code-critic finding on PR #2954 — the frontmatter-only/empty-body
662    /// case is the other edge of the fence-scanning loop and had no
663    /// regression pin.
664    /// What: a `.md` fixture whose closing fence is the last line of the
665    /// file. Loads through the real `compose_agent` -> `load_md_agent` path.
666    /// Asserts `system_prompt.content == ""`.
667    /// Test: this test.
668    #[test]
669    fn frontmatter_only_agent_has_empty_body() {
670        let tmp = tempfile::tempdir().expect("tempdir");
671        std::fs::write(
672            tmp.path().join("empty.md"),
673            "---\nname: empty\nrole: engineer\n---\n",
674        )
675        .expect("write");
676
677        let cfg = load_md_agent(&tmp.path().join("empty.md")).expect("load");
678        assert_eq!(
679            cfg.system_prompt.content, "",
680            "frontmatter-only agent must project to an empty body, got: {:?}",
681            cfg.system_prompt.content
682        );
683    }
684
685    /// `project_embedded_md_with_extends` resolves a real 3-level
686    /// `extends:` chain (`rust-engineer` -> `base-engineer` -> `base-agent`)
687    /// entirely against the embedded tm catalog table, with no filesystem
688    /// access.
689    ///
690    /// Why: this is the acceptance criterion for Slice E2 (#2958) -- the
691    /// embedded-extends entry point must actually compose a chain, not just
692    /// parse a single flat document. `rust-engineer.md`'s frontmatter
693    /// declares `extends: base-engineer`, which itself declares
694    /// `extends: base-agent` (see `assets/agents/rust-engineer.md` and
695    /// `assets/agents/BASE-ENGINEER.md`), so a correct compose must pull
696    /// prose from all three tiers into the final body.
697    /// What: calls `project_embedded_md_with_extends("rust-engineer")` and
698    /// asserts the name/role/model project correctly and that the composed
699    /// body contains marker text unique to each of the three tiers
700    /// (BASE-AGENT's "Foundation for all trusty-mpm agents", BASE-ENGINEER's
701    /// "Foundation for all engineer agents", and rust-engineer's own
702    /// `# Rust Engineer` heading).
703    /// Test: this test.
704    #[test]
705    fn project_embedded_md_with_extends_resolves_rust_engineer_from_base_engineer() {
706        let cfg = project_embedded_md_with_extends("rust-engineer").expect("compose rust-engineer");
707
708        assert_eq!(cfg.agent.name, "rust-engineer");
709        assert_eq!(cfg.agent.role.as_deref(), Some("engineer"));
710        assert_eq!(cfg.agent.model.as_deref(), Some("sonnet"));
711        assert!(
712            cfg.system_prompt
713                .content
714                .contains("Foundation for all trusty-mpm agents"),
715            "composed body must include BASE-AGENT tier content"
716        );
717        assert!(
718            cfg.system_prompt
719                .content
720                .contains("Foundation for all engineer agents"),
721            "composed body must include BASE-ENGINEER tier content"
722        );
723        // #8215: the leaf marker is rust-engineer's own H1, which tracks the
724        // agent's identity; a skill name pinned here goes stale whenever the
725        // asset's skill wiring changes (as `toolchains-rust-core` did in #8192).
726        assert!(
727            cfg.system_prompt.content.contains("# Rust Engineer"),
728            "composed body must include rust-engineer's own content"
729        );
730    }
731
732    /// `project_embedded_md_with_extends` surfaces an unknown agent name as
733    /// a descriptive `anyhow::Error`, never a panic.
734    ///
735    /// Why: mirrors `load_md_agent`'s error-surfacing contract for the fs
736    /// path -- a caller iterating the embedded catalog with a typo'd name
737    /// must get a message it can log, not an unwind.
738    /// What: requests a name absent from the `tm_agent_sources` catalog and
739    /// asserts the call errors.
740    /// Test: this test.
741    #[test]
742    fn project_embedded_md_with_extends_unknown_name_errors() {
743        let result = project_embedded_md_with_extends("does-not-exist");
744        assert!(result.is_err(), "unknown embedded agent name must error");
745    }
746
747    /// #7727 review HIGH 1: every pointer an embedded agent carries opens with
748    /// the real `read_file`, rooted at a bound project and at a projectless
749    /// scratch dir, although the refs root is outside both and never written.
750    #[tokio::test]
751    async fn embedded_agent_skill_pointers_open_with_read_file() {
752        use crate::agents::skill_refs::REFERENCED_SKILL_FILES;
753        use crate::tools::ReadFileTool;
754        use crate::tools::traits::ToolExecutor;
755        use trusty_agents_common::agents::skill_root::SKILLS_ROOT_PLACEHOLDER;
756
757        let refs = tempfile::tempdir().expect("tempdir");
758        let refs_root = refs.path().join("skill-refs");
759        let cfg = project_embedded_md_with_extends_at("rust-engineer", &refs_root)
760            .expect("compose rust-engineer");
761        let body = &cfg.system_prompt.content;
762        assert!(
763            !body.contains(SKILLS_ROOT_PLACEHOLDER),
764            "raw placeholder leaked"
765        );
766
767        let project = tempfile::tempdir().expect("project");
768        let scratch = tempfile::tempdir().expect("projectless scratch");
769        for root in [project.path(), scratch.path()] {
770            let tool = ReadFileTool::new(root).with_skill_refs(&refs_root);
771            for (relative, content) in REFERENCED_SKILL_FILES {
772                let pointer = refs_root.join(relative).display().to_string();
773                assert!(body.contains(&format!("Read `{pointer}`")), "{pointer}");
774                let out = tool.execute(serde_json::json!({ "path": pointer })).await;
775                assert!(!out.is_error(), "{pointer}: {}", out.content());
776                assert_eq!(out.content(), *content);
777            }
778        }
779        assert!(
780            !refs_root.exists(),
781            "compose and read must not write the refs dir"
782        );
783    }
784
785    /// #7727 review HIGH 2: a refs root that cannot be written never drops an
786    /// agent; the pointer still resolves.
787    #[cfg(unix)]
788    #[test]
789    fn embedded_agent_composes_when_refs_dir_is_unwritable() {
790        use std::os::unix::fs::PermissionsExt;
791
792        let home = tempfile::tempdir().expect("tempdir");
793        std::fs::set_permissions(home.path(), std::fs::Permissions::from_mode(0o555))
794            .expect("chmod");
795        let refs_root = home.path().join(".trusty-code").join("skill-refs");
796        let composed = project_embedded_md_with_extends_at("rust-engineer", &refs_root);
797        std::fs::set_permissions(home.path(), std::fs::Permissions::from_mode(0o755))
798            .expect("chmod back");
799        let cfg = composed.expect("an unwritable refs dir must not drop the agent");
800        assert!(cfg.system_prompt.content.contains(&format!(
801            "{}/self-improvement-loop/SKILL.md",
802            refs_root.display()
803        )));
804    }
805
806    /// #7727 review HIGH 2: the no-home relative root keeps the agent, with the
807    /// pointer left unresolved (and a warning naming the path).
808    #[test]
809    fn embedded_agent_composes_when_refs_dir_is_relative() {
810        use trusty_agents_common::agents::skill_root::SKILLS_ROOT_PLACEHOLDER;
811
812        let cfg = project_embedded_md_with_extends_at(
813            "rust-engineer",
814            Path::new(".trusty-code/skill-refs"),
815        )
816        .expect("a relative refs dir must not drop the agent");
817        assert!(cfg.system_prompt.content.contains(SKILLS_ROOT_PLACEHOLDER));
818    }
819
820    /// (#7948) A disk agent's `permissions:` block reaches `AgentConfig`.
821    ///
822    /// Why: `compose_agent` drops the key, so this proves the loader reads the
823    /// file's own bytes — the regression that would leave every map inert.
824    /// Test: this test.
825    #[test]
826    fn permissions_block_projects_onto_agent_config() {
827        let dir = tempfile::tempdir().expect("tempdir");
828        let path = dir.path().join("solo.md");
829        std::fs::write(
830            &path,
831            "---\nname: solo\nrole: engineer\npermissions:\n  read_file: allow\n  bash:\n    \"rm *\": deny\n---\n\nBody.\n",
832        )
833        .expect("write");
834
835        let cfg = load_md_agent(&path).expect("loads");
836        assert_eq!(
837            cfg.permissions
838                .expect("the block must reach the config")
839                .len(),
840            2
841        );
842    }
843
844    /// (#7948 fail-open check) A malformed `permissions:` block FAILS the load.
845    ///
846    /// Why: fails if the error arm ever becomes a default — a map silently
847    /// degraded to "no permissions" allows every tool.
848    /// Test: this test.
849    #[test]
850    fn malformed_permissions_block_fails_the_load() {
851        let dir = tempfile::tempdir().expect("tempdir");
852        let path = dir.path().join("broken.md");
853        std::fs::write(
854            &path,
855            "---\nname: broken\nrole: engineer\npermissions:\n  bash: allowed\n---\n\nBody.\n",
856        )
857        .expect("write");
858
859        let err = load_md_agent(&path).expect_err("a typo'd decision must fail the load");
860        let text = err.to_string();
861        assert!(text.contains("broken.md"), "must name the file: {text}");
862        assert!(text.contains("allowed"), "must quote the value: {text}");
863    }
864
865    /// A valid two-rule `permissions:` block on an agent named `solo`.
866    const PERMISSIONS_MD: &str = "---\nname: solo\nrole: engineer\npermissions:\n  read_file: allow\n  bash:\n    \"rm *\": deny\n---\n\nBody.\n";
867
868    /// A `permissions:` block with a typo'd decision word.
869    const MALFORMED_PERMISSIONS_MD: &str =
870        "---\nname: broken\nrole: engineer\npermissions:\n  bash: allowed\n---\n\nBody.\n";
871
872    /// A catalog whose `child` and `heir` both extend a base declaring its own
873    /// block; `child` declares one too, `heir` does not.
874    fn permissions_catalog(child_md: &'static str) -> [(&'static str, &'static str); 3] {
875        [
876            (
877                "BASE-FIXTURE.md",
878                "---\nname: base-fixture\nrole: engineer\npermissions:\n  bash: deny\n---\n\nBase.\n",
879            ),
880            ("child.md", child_md),
881            (
882                "heir.md",
883                "---\nname: heir\nextends: base-fixture\n---\n\nHeir.\n",
884            ),
885        ]
886    }
887
888    /// (#7948) A bundled `Direct` agent's `permissions:` block reaches
889    /// `AgentConfig`, the embedded twin of
890    /// `permissions_block_projects_onto_agent_config`.
891    /// Test: this test.
892    #[test]
893    fn embedded_permissions_block_projects_onto_agent_config() {
894        let cfg = project_embedded_md("solo", PERMISSIONS_MD).expect("loads");
895        assert_eq!(
896            cfg.permissions
897                .expect("the block must reach the config")
898                .len(),
899            2
900        );
901    }
902
903    /// (#7948) A catalog agent's OWN block reaches `AgentConfig`; a base
904    /// template's block is not inherited by an agent that declares none.
905    /// Test: this test.
906    #[test]
907    fn embedded_extends_permissions_block_projects_onto_agent_config() {
908        let catalog = permissions_catalog(
909            "---\nname: child\nextends: base-fixture\npermissions:\n  read_file: allow\n  bash:\n    \"rm *\": deny\n---\n\nChild.\n",
910        );
911        let refs = Path::new("unused-skill-refs");
912        let child = project_in_memory_catalog("child", &catalog, refs).expect("child loads");
913        assert_eq!(
914            child
915                .permissions
916                .expect("the block must reach the config")
917                .len(),
918            2
919        );
920        let heir = project_in_memory_catalog("heir", &catalog, refs).expect("heir loads");
921        assert!(heir.permissions.is_none(), "a base block is not inherited");
922    }
923
924    /// (#7948 fail-open check) A malformed block FAILS a `Direct` embedded load.
925    /// Test: this test.
926    #[test]
927    fn malformed_embedded_permissions_block_fails_the_load() {
928        let err = project_embedded_md("broken", MALFORMED_PERMISSIONS_MD)
929            .expect_err("a typo'd decision must fail the load");
930        let text = err.to_string();
931        assert!(text.contains("broken"), "must name the agent: {text}");
932        assert!(text.contains("allowed"), "must quote the value: {text}");
933    }
934
935    /// (#7948 fail-open check) A malformed block FAILS a composed embedded load.
936    /// Test: this test.
937    #[test]
938    fn malformed_embedded_extends_permissions_block_fails_the_load() {
939        let catalog = permissions_catalog(
940            "---\nname: child\nextends: base-fixture\npermissions:\n  bash: allowed\n---\n\nChild.\n",
941        );
942        let err = project_in_memory_catalog("child", &catalog, Path::new("unused-skill-refs"))
943            .expect_err("a typo'd decision must fail the load");
944        let text = err.to_string();
945        assert!(text.contains("child"), "must name the agent: {text}");
946        assert!(text.contains("allowed"), "must quote the value: {text}");
947    }
948
949    /// #8184: the deployer drops `permissions:` when it re-emits frontmatter,
950    /// so a materialized roster card must recover its source's block — the
951    /// difference between the stock `pm` asking before it writes and never
952    /// prompting at all. FAILS before #8184: the deployed copy loaded with no
953    /// permissions, which means everything allowed.
954    /// Test: this test.
955    #[test]
956    fn deployed_roster_copy_recovers_the_cards_permissions() {
957        let tmp = tempfile::tempdir().expect("tempdir");
958        std::fs::write(
959            tmp.path().join("pm.md"),
960            "---\nname: pm\nrole: pm\nprovenance: framework-owned\nmodel: sonnet\n\
961             tcode_tools: [read_file, write_file, bash]\n---\n\nYou are the PM.\n",
962        )
963        .expect("write");
964
965        let cfg = load_md_agent(&tmp.path().join("pm.md")).expect("loads");
966        let permissions = cfg
967            .permissions
968            .expect("a deployed roster card must carry its source's block");
969        assert!(
970            !permissions.is_empty(),
971            "the recovered block must carry the card's rules"
972        );
973    }
974
975    /// #8184: the provenance test reads the PARSED key, so a QUOTED value —
976    /// which a frontmatter emitter may legitimately produce — still recovers
977    /// the block. FAILS against the substring form this replaced, which only
978    /// matched the bare spelling and would have silently stopped recovering.
979    /// Test: this test.
980    #[test]
981    fn quoted_provenance_still_recovers_the_cards_permissions() {
982        let tmp = tempfile::tempdir().expect("tempdir");
983        std::fs::write(
984            tmp.path().join("pm.md"),
985            "---\nname: pm\nrole: pm\nprovenance: \"framework-owned\"\nmodel: sonnet\n\
986             tcode_tools: [read_file, write_file, bash]\n---\n\nYou are the PM.\n",
987        )
988        .expect("write");
989
990        let cfg = load_md_agent(&tmp.path().join("pm.md")).expect("loads");
991        assert!(
992            cfg.permissions.is_some_and(|p| !p.is_empty()),
993            "a quoted `provenance:` is the same declaration as an unquoted one"
994        );
995    }
996
997    /// The recovery is scoped to the deployer's own output: a hand-authored
998    /// file sharing a roster name keeps its author's silence.
999    /// Test: this test.
1000    #[test]
1001    fn hand_authored_file_gets_no_embedded_permissions() {
1002        let tmp = tempfile::tempdir().expect("tempdir");
1003        std::fs::write(
1004            tmp.path().join("pm.md"),
1005            "---\nname: pm\nmodel: sonnet\ntcode_tools: [read_file]\n---\n\nMy own PM.\n",
1006        )
1007        .expect("write");
1008
1009        let cfg = load_md_agent(&tmp.path().join("pm.md")).expect("loads");
1010        assert!(
1011            cfg.permissions.is_none(),
1012            "a hand-authored card must not inherit the roster's rules"
1013        );
1014    }
1015}