Skip to main content

trusty_code/assets/
mod.rs

1//! Embedded default agents & skills for trusty-code (#2895).
2//!
3//! Why: A fresh project has no `.claude/agents/` or `.claude/skills/` yet, so
4//! `tcode` would otherwise start with zero agents and zero skills — a cold,
5//! unusable default. Bundling a working default set at compile time (mirroring
6//! the embed pattern `trusty-mpm` uses in `crates/trusty-mpm/src/core/bundle.rs`,
7//! but without trusty-mpm's disk-materialize install step — these are parsed
8//! in-memory only) gives every project a usable harness out of the box while
9//! disk-based `.claude/agents/` and `.claude/skills/` always take precedence
10//! when present (see `agents::load_all_agents` and
11//! `skills::discover_skill_metadata`'s embedded-fallback branches).
12//! What: [`EmbeddedAgent`]/[`DEFAULT_AGENTS`] — the 34-agent dispatchable
13//! roster (Slice E3, #2958, plus `pm` added for #3437, `ticketing` for
14//! #4027, and the four delivery-workflow agents for #8129): tcode's own 8
15//! `Direct` defaults (`engineer`, `qa-agent`, `code-reviewer`, `pm`,
16//! `ticketing`, `version-control`, `local-ops`, `documentation` — no
17//! `extends:` chain, projected via
18//! `agents::md_loader::project_embedded_md`) plus the 26 tm agents (`extends:`-chained
19//! through the 5 `BASE-*` templates — projected via
20//! `agents::md_loader::project_embedded_md_with_extends`, which resolves
21//! against [`tm_agent_sources`]). Authored as Markdown+frontmatter
22//! (`.md`) as of #2897 Slice C (previously native TOML; Slice D subsequently
23//! retired the TOML loader for USER `.claude/agents/*.toml` configs entirely
24//! — see `agents::mod`'s docs). Both projection paths share one
25//! frontmatter->`AgentConfig` mapping with the disk `.md` loader
26//! (`agents::md_loader::load_md_agent`) — see that module's docs.
27//! [`EmbeddedSkill`]/[`DEFAULT_SKILLS`] — trusty-mpm's universal skill set
28//! (format-identical `SKILL.md` files), reused verbatim per Bob's reuse
29//! directive; the `tm-*` orchestration skills are excluded because they drive
30//! trusty-mpm MCP tools tcode does not have.
31//!
32//! ## Tools-restriction deviation (Slice E3, #2958, Bob's 2026-07-18 ruling)
33//!
34//! Four of the 26 roster agents — `qa`, `code-critic`, `code-analyzer`,
35//! `web-qa` — carry an explicit restrictive `tools:` override in their tcode
36//! FORK (`assets/agents/{qa,code-critic,code-analyzer,web-qa}.md`) that is NOT
37//! present in the shared agent they were derived from (`content/agents`,
38//! read at runtime since #9011). These four are the only agent `.md` files
39//! trusty-code still embeds a second copy of: every other roster agent is read
40//! from instructional content through [`tm_agent_sources`], so it cannot
41//! drift. (#8129's four
42//! delivery-workflow agents also live in `assets/agents/`, but they are
43//! tcode-AUTHORED, not copies — see the "Delivery-workflow agents" section
44//! below.) This is a
45//! deliberate, Bob-approved deviation, not drift: those four are
46//! reviewer-intent agents and get
47//! the same read-only tool allowlist tcode's own `code-reviewer` default uses
48//! (no `write_file`/`edit`/`bash`). `research` stays byte-identical and
49//! unrestricted per Bob's explicit ruling — it builds research reports, not
50//! verdicts. `documentation` was covered by that same ruling until #8129,
51//! which replaced the shared body with a tcode-native one carrying its own
52//! `tcode_tools:` grant; see the "Delivery-workflow agents" section below for
53//! its real status — that grant is strictly WIDER than the reviewer-intent
54//! four get, so it is not a reversal of the ruling. NOTE for the file itself: the
55//! shared frontmatter parser
56//! (`trusty_agents_common::agents::builder::split_frontmatter`) does NOT
57//! tolerate `#`-comment lines inside a frontmatter block (verified
58//! empirically — a bare `#`-prefixed line there is a hard `FrontmatterParse`
59//! error, not a tolerated comment), so no inline marker could be added to
60//! those four files without breaking the compose step; this doc comment is
61//! the marker of record. The deferred E4 CI staleness guard (diffing tcode's
62//! copies against trusty-mpm's source) MUST whitelist the `tools:` line in
63//! exactly these four files rather than flagging them as drift.
64//!
65//! ## Prose deviation follow-up (Slice E3 review round, #3041)
66//!
67//! Adding the `tools:` override alone left three of the four files
68//! internally contradictory: their prose still instructed write/bash actions
69//! the new allowlist denies (`web-qa.md`'s "Technical Testing Protocol" told
70//! the agent to create test scripts, run `CI=true npm test`, and shell out to
71//! `ps aux`; `qa.md`'s methodology told it to "Implement"/"Execute" test
72//! suites directly; `code-analyzer.md`'s "Large-Volume Analysis" told it to
73//! generate-and-run a Python script). A code-critic review of PR #3041 (WARN,
74//! two HIGH + one MEDIUM findings) caught this. `web-qa.md`, `qa.md`, and
75//! `code-analyzer.md` were reworded in the SAME PR to a genuinely read-only
76//! frame: findings plus concrete, ready-to-run recommendations (drafted
77//! scenarios, specified test cases, recommended commands) handed off to an
78//! engineer/ops/CI to execute, never executed by the agent itself.
79//! `code-critic.md` needed no prose change at the time — its review-only body
80//! had no execute-oriented instructions. This is an ADDITIONAL deviation from
81//! trusty-mpm byte-parity beyond the `tools:` line alone; the deferred E4
82//! staleness guard must whitelist the reworded prose sections in these three
83//! files too, not just the `tools:` line.
84//!
85//! `code-critic.md` gained its own reworded section later (owner ruling
86//! 2026-08-12, PR #5596): trusty-mpm's upstream copy started instructing the
87//! agent to post its verdict via `gh pr review --comment` directly. tcode's
88//! copy has no `bash`/`gh` tool, so the "Posting the Verdict" section was
89//! reworded to the same read-only frame as the three files above — it
90//! specifies the exact command for the caller to run, never runs it itself.
91//! `code-critic.md` now joins `web-qa.md`/`qa.md`/`code-analyzer.md` as a
92//! four-of-four reworded-prose deviation, not three-of-four; the E4 staleness
93//! guard whitelists it the same way (pinned-hash reconciliation, not
94//! byte-parity).
95//!
96//! ## Non-coding cross-product roster addition (#4027, epic #4021)
97//!
98//! `ticketing` joined this roster (same treatment `research` got) so
99//! trusty-agents' widened `dispatch_task` bridge (#4026) can reach ONE roster
100//! instead of growing a second dispatch leg into trusty-mpm — the owner's OQ-4
101//! ruling. It was embedded directly from the shared crate until #8129, which
102//! replaced the body with a tcode-native one declaring its own `tcode_tools:`;
103//! the dispatch NAME the bridge resolves is unchanged, which is all #4026
104//! depends on. Its non-coding property is enforced where the
105//! owner's OQ-7 ruling put enforcement — the BRIDGE's fail-closed
106//! `NON_CODING_TARGETS` floor in
107//! `crates/trusty-agents/src/tools/cross_product.rs` — not by an asset-level
108//! allowlist that a direct `tcode run-task` invocation would bypass anyway.
109//!
110//! ## Delivery-workflow agents (#8129, epic #8127)
111//!
112//! `ticketing`, `version-control`, `local-ops` and `documentation` are the
113//! four roles trusty-mpm's PM delegates the issue -> branch -> build -> PR
114//! -> changelog steps to. tcode's PM could not reach any of them: three
115//! (`ticketing`, `local-ops`, `documentation`) were `Composed` entries
116//! sourced byte-identically from the shared crate, and `version-control` was
117//! absent from the roster entirely. The shared bodies are written for
118//! trusty-mpm's harness (`Skill(...)`, `tm` CLI verbs, MCP servers tcode does
119//! not host) and their `tools:` frontmatter names Claude Code's vocabulary,
120//! which this runtime ignores (#7683) — so each one projected to
121//! `tools.allowed == None`, i.e. EVERY tool allowed, the opposite of the
122//! grant its author wrote.
123//!
124//! All four are therefore tcode-NATIVE [`EmbeddedAgent::Direct`] agents in
125//! `assets/agents/`, authored the way `pm.md`/`engineer.md` are: a short body
126//! scoped to tcode's actual tool surface, with an explicit `tcode_tools:`
127//! allowlist that carries `bash` (for `git`/`gh`/`cargo`) and `finish_task`.
128//! They are NOT forks of the same-named shared assets and are NOT pinned
129//! deviations — there is no upstream content to reconcile against, only an
130//! upstream ROLE. `scripts/check_agent_assets.sh` therefore lists them in
131//! `$TCODE_ONLY`, never in `$DEVIATED_FILES`. The three shared sources they
132//! replace are absent from [`SHARED_TM_AGENT_FILES`], so no caller can compose
133//! the trusty-mpm body under the same dispatch name.
134//!
135//! ## E4 guard (issue #2958, `scripts/check_agent_assets.sh`)
136//!
137//! The byte-parity half of this gate is gone because what it compared is gone:
138//! 30 duplicated `.md` files became one shared copy each (`content/agents`
139//! since #9011), and a file cannot drift from itself. What the gate still checks is what the compiler cannot
140//! see — it pins the 4 deviated files' SHARED source hash
141//! (`scripts/agent-asset-pins.tsv`) so an edit behind one of them fails for
142//! deliberate reconciliation, and it rejects any `.md` appearing in this
143//! directory that is neither a pinned deviation nor a declared tcode-only
144//! default, which is how a deleted duplicate stays deleted. See that script's
145//! header and `.github/workflows/agent-assets.yml`.
146//!
147//! Test: `assets::tests::*` — every embedded agent `.md` parses and projects
148//! to a field-identical `AgentConfig` vs. the retired TOML fixtures (the
149//! original 3), every roster name resolves through the extends composer with
150//! no BASE template dispatchable and no name collision, the four restricted
151//! agents' composed `AgentConfig` carries the read-only tool list, and
152//! `documentation`/`research` remain unrestricted. Every skill name is unique
153//! and every skill's frontmatter `name:` matches its table key.
154//!
155//! [`EmbeddedAgent`]: crate::assets::EmbeddedAgent
156//! [`EmbeddedAgent::Direct`]: crate::assets::EmbeddedAgent::Direct
157//! [`DEFAULT_AGENTS`]: crate::assets::DEFAULT_AGENTS
158//! [`tm_agent_sources`]: crate::assets::tm_agent_sources
159//! [`SHARED_TM_AGENT_FILES`]: crate::assets::SHARED_TM_AGENT_FILES
160//! [`EmbeddedSkill`]: crate::assets::EmbeddedSkill
161//! [`DEFAULT_SKILLS`]: crate::assets::DEFAULT_SKILLS
162
163/// One embedded default agent: either self-contained (tcode's own 3
164/// defaults, no `extends:` chain) or a roster agent whose `extends:` chain is
165/// resolved at load time against [`tm_agent_sources`] (Slice E3,
166/// #2958).
167///
168/// Why: `agents::mod`'s embedded-fallback needs a single ordered table
169/// ([`DEFAULT_AGENTS`]) covering both projection strategies tcode's embedded
170/// agents need: tcode's own 3 defaults are flat `.md` strings with no
171/// inheritance (projected via `agents::md_loader::project_embedded_md`); the
172/// 28 tm roster agents inherit from `BASE-*` templates and must be composed
173/// in-memory (`agents::md_loader::project_embedded_md_with_extends`) before
174/// projection. One enum keeps both variants in the same ordered slice rather
175/// than two parallel tables that could silently drift out of sync in count
176/// or ordering.
177/// What: [`EmbeddedAgent::Direct`] carries the dispatch name and the raw
178/// `.md` source (frontmatter fence + prose body) verbatim. [`EmbeddedAgent::Composed`]
179/// carries only the dispatch name — its content is resolved from
180/// [`tm_agent_sources`] at load time, since the whole point of the
181/// in-memory composer is that no second copy of the raw bytes is needed here.
182/// [`EmbeddedAgent::name`] reads the name back out of either variant.
183/// Test: `assets::tests::default_agents_parse_and_names_match`.
184#[derive(Debug, Clone, Copy)]
185pub enum EmbeddedAgent {
186    /// A self-contained agent: raw `.md` source, no `extends:` chain.
187    Direct {
188        /// Dispatch key, matching the frontmatter `name:` inside `md`.
189        name: &'static str,
190        /// Raw `.md` source (frontmatter fence + prose body), projectable
191        /// via `agents::md_loader::project_embedded_md`.
192        md: &'static str,
193    },
194    /// A roster agent resolved via `agents::md_loader::project_embedded_md_with_extends`
195    /// against [`tm_agent_sources`] at load time.
196    Composed {
197        /// Dispatch key, and the lookup key into `tm_agent_sources`
198        /// (after that table's own case-folding).
199        name: &'static str,
200    },
201}
202
203impl EmbeddedAgent {
204    /// The dispatch key, regardless of variant.
205    ///
206    /// Why: callers (the embedded-fallback loader, tests) usually only need
207    /// the name and would otherwise have to `match` on the variant just to
208    /// read one shared field.
209    /// What: returns `name` from either `Direct` or `Composed`.
210    /// Test: `assets::tests::default_agents_parse_and_names_match`.
211    pub fn name(&self) -> &'static str {
212        match self {
213            EmbeddedAgent::Direct { name, .. } => name,
214            EmbeddedAgent::Composed { name } => name,
215        }
216    }
217}
218
219/// One embedded default skill: its catalog name and raw `SKILL.md` source.
220///
221/// Why: `skills::mod`'s embedded-fallback needs both the name (for the
222/// `SkillMetadata` catalog) and the raw Markdown (frontmatter + body, parsed
223/// the same way a disk-based `SKILL.md` is).
224/// What: `name` matches the frontmatter `name:` inside `skill_md`; `skill_md`
225/// is the verbatim embedded file contents (frontmatter fence + body).
226/// Test: `assets::tests::default_skills_names_are_unique`.
227#[derive(Debug, Clone, Copy)]
228pub struct EmbeddedSkill {
229    /// Catalog name, matching the frontmatter `name:` inside `skill_md`.
230    pub name: &'static str,
231    /// Raw `SKILL.md` source (frontmatter fence + Markdown body).
232    pub skill_md: &'static str,
233}
234
235const ENGINEER_MD: &str = include_str!("agents/engineer.md");
236const QA_AGENT_MD: &str = include_str!("agents/qa-agent.md");
237const CODE_REVIEWER_MD: &str = include_str!("agents/code-reviewer.md");
238const PM_MD: &str = include_str!("agents/pm.md");
239// #8129: the four delivery-workflow agents. tcode-NATIVE, not forks of the
240// shared roster's same-named files — see this module's "Delivery-workflow
241// agents" doc section.
242/// Opening marker of `pm.md`'s contiguous agent-routing block (#8287).
243///
244/// Why: DOC-75 §4b row 3 ([#8293](https://github.com/bobmatnyc/trusty-tools/issues/8293))
245/// will lift the routing table out of this crate into one shared source neither
246/// product crate owns, behind a drift check. A marked, contiguous block is what
247/// makes that a move rather than a rewrite, and it is also the span the routing
248/// tests parse — so the lift boundary and the test boundary can never disagree.
249/// What: the exact Markdown-comment line opening the block. Matched literally,
250/// with no trailing prose on the marker line, so [`pm_routing_block`] needs no
251/// line-scanning heuristic.
252/// Test: `assets::tests::pm_routing_block_names_only_delegable_roster_agents`.
253pub const PM_ROUTING_BLOCK_BEGIN: &str = "<!-- pm-routing-table:begin -->";
254
255/// Closing marker of `pm.md`'s routing block.
256///
257/// Why/What/Test: as [`PM_ROUTING_BLOCK_BEGIN`].
258pub const PM_ROUTING_BLOCK_END: &str = "<!-- pm-routing-table:end -->";
259
260/// The delegation targets a delegate-mode coding task passes through, in order
261/// (#8287).
262///
263/// Why: DOC-75 §1's delegate run is "research, then engineer, then qa" — the
264/// ORDER is the behaviour, not just the membership, so it is declared here
265/// rather than re-read from the card's prose by each test. `qa-agent` and not
266/// `qa` because DOC-75 §6 requires real test output in the transcript and
267/// tcode's `qa` fork carries no `bash` (see this module's "Tools-restriction
268/// deviation" section) — it recommends commands it cannot run.
269/// What: three roster names, each an [`EmbeddedAgent`] entry in
270/// [`DEFAULT_AGENTS`], in the order the card's routing block must name them.
271/// Test: `assets::tests::pm_routing_block_names_only_delegable_roster_agents`.
272pub const PM_ROUTING_ORDER: &[&str] = &["research", "engineer", "qa-agent"];
273
274/// `pm.md`'s size before #8287 added the routing block, in bytes.
275///
276/// Why: DOC-75 §4b caps tcode's resident PM prompt at 2x its 2026-09-19 size —
277/// token budget is a first-class axis for tcode. A hardcoded baseline is what
278/// lets a test enforce that cap; deriving it from `PM_MD.len()` would make the
279/// assertion vacuous.
280/// What: `wc -c` of `crates/trusty-code/src/assets/agents/pm.md` at commit
281/// `3473119`, the tip of `main` when #8287 landed.
282/// Test: `assets::tests::pm_card_stays_within_the_doc_75_size_cap`.
283pub const PM_CARD_BASELINE_BYTES: usize = 2863;
284
285/// The routing block's inner text, or `None` when the markers are absent.
286///
287/// Why: two callers need the same span — the routing tests, and
288/// [#8293](https://github.com/bobmatnyc/trusty-tools/issues/8293)'s shared-source
289/// lift, which has to read the block out of whichever card it is migrating.
290/// Returning `None` rather than the whole prompt is deliberate: a card that
291/// lost its markers must fail the routing test, not silently pass by matching
292/// agent names elsewhere in the body.
293/// What: the text between [`PM_ROUTING_BLOCK_BEGIN`] and
294/// [`PM_ROUTING_BLOCK_END`], exclusive of both markers, trimmed. `None` when
295/// either marker is missing or they appear out of order.
296/// Test: `assets::tests::pm_routing_block_names_only_delegable_roster_agents`,
297/// `prompt::tests::delegate_mode_prompt_carries_the_routing_table`.
298pub fn pm_routing_block(card: &str) -> Option<&str> {
299    let after_begin = card.split_once(PM_ROUTING_BLOCK_BEGIN)?.1;
300    Some(after_begin.split_once(PM_ROUTING_BLOCK_END)?.0.trim())
301}
302
303const TICKETING_MD: &str = include_str!("agents/ticketing.md");
304const VERSION_CONTROL_MD: &str = include_str!("agents/version-control.md");
305const LOCAL_OPS_MD: &str = include_str!("agents/local-ops.md");
306const DOCUMENTATION_MD: &str = include_str!("agents/documentation.md");
307
308/// The 34-agent dispatchable default roster, embedded at compile time
309/// (Slice E3, #2958, plus `pm` added for #3437, `ticketing` for #4027, and
310/// the four #8129 delivery-workflow agents):
311/// tcode's 8 own `Direct` defaults plus the 26 tm roster agents. The 5
312/// `BASE-*` extends templates in [`tm_agent_sources`] are
313/// deliberately NOT entries here — they are extends-sources only, never
314/// dispatchable — and trusty-mpm's own `engineer` agent is excluded from the
315/// roster upstream (#2958's roster decision) precisely because it would
316/// collide with tcode's `engineer` below;
317/// `assets::tests::no_name_collisions_across_the_33_agent_roster` pins that
318/// no collision exists in the final table.
319///
320/// Why: gives `agents::load_all_agents`'s embedded-fallback branch a fixed,
321/// ordered table to parse when the disk `.claude/agents/` directory is empty
322/// or absent. `pm` specifically fixes #3437: `task::protocol::task_run`
323/// defaults an omitted `agent_name` to the literal `"pm"`
324/// (`task/protocol.rs`), which resolved against NEITHER a disk
325/// `~/.claude/agents/pm.md` NOR this table before #3437 — so every
326/// daemon-default (including every GUI-initiated, agent-name-omitting) run
327/// failed agent resolution before a single turn executed.
328/// What: `engineer` (general implementation, full read/write tool set),
329/// `qa-agent` (verification — read/inspect/run only, no `write_file`/`edit`,
330/// hands bugs back to the engineer rather than fixing them), `code-reviewer`
331/// (adversarial, read-only review, no `bash`), `pm` (orchestrator/default —
332/// delegates when `delegate_to_agent` is available, executes directly
333/// otherwise; see `assets/agents/pm.md`), plus the four #8129
334/// delivery-workflow agents `ticketing` (issues via `gh`), `version-control`
335/// (branch/commit/push/PR via `git`+`gh`), `local-ops` (build, test, version
336/// bump, changelog) and `documentation` (prose) — all eight
337/// [`EmbeddedAgent::Direct`], interleaved alphabetically from
338/// `documentation` onward. Then the 26 [`EmbeddedAgent::Composed`] roster
339/// agents, alphabetical, matching [`tm_agent_sources`]'s roster
340/// ordering. Four of them (`qa`, `code-critic`, `code-analyzer`, `web-qa`)
341/// carry a tcode-only restrictive `tcode_tools:` override in their `.md`
342/// source — see this module's "Tools-restriction deviation" doc section above.
343/// Test: `assets::tests::default_agents_parse_and_names_match`,
344/// `assets::tests::base_templates_are_never_dispatchable`,
345/// `assets::tests::no_name_collisions_across_the_34_agent_roster`,
346/// `assets::tests::ticketing_is_dispatchable_for_cross_product_delegation`,
347/// `assets::tests::restricted_reviewer_agents_carry_read_only_tools`,
348/// `assets::tests::delivery_workflow_agents_are_dispatchable_with_bash`,
349/// `assets::tests::research_remains_unrestricted`,
350/// `assets::tests::default_task_run_agent_resolves_against_default_agents`,
351/// `assets::tests::every_embedded_agent_model_normalizes_to_a_valid_slug`.
352pub const DEFAULT_AGENTS: &[EmbeddedAgent] = &[
353    EmbeddedAgent::Direct {
354        name: "engineer",
355        md: ENGINEER_MD,
356    },
357    EmbeddedAgent::Direct {
358        name: "qa-agent",
359        md: QA_AGENT_MD,
360    },
361    EmbeddedAgent::Direct {
362        name: "code-reviewer",
363        md: CODE_REVIEWER_MD,
364    },
365    // #8184: `pm` is the default agent of an INTERACTIVE session, which runs
366    // SOLO since #8184 — it edits and runs commands itself, in the user's real
367    // project root, instead of delegating. Its card is therefore the only
368    // bundled one carrying a `permissions:` block: every mutating tool asks
369    // first (#3422), reads stay unprompted. A headless run has nobody to ask,
370    // so an `ask` there denies (#8100) unless TCODE_PERMISSION_MODE=allow-asks.
371    // #8287: in DELEGATE mode the same card is the only routing text the PM has,
372    // so its contiguous routing block (see [`PM_ROUTING_BLOCK_BEGIN`]) is what
373    // decides whether `research`/`engineer`/`qa-agent` get dispatched at all.
374    EmbeddedAgent::Direct {
375        name: "pm",
376        md: PM_MD,
377    },
378    EmbeddedAgent::Composed { name: "api-qa" },
379    EmbeddedAgent::Composed {
380        name: "code-analyzer",
381    },
382    EmbeddedAgent::Composed {
383        name: "code-critic",
384    },
385    EmbeddedAgent::Composed {
386        name: "dart-engineer",
387    },
388    EmbeddedAgent::Composed {
389        name: "data-engineer",
390    },
391    // #8129: tcode-native, not the shared roster's `documentation.md`.
392    EmbeddedAgent::Direct {
393        name: "documentation",
394        md: DOCUMENTATION_MD,
395    },
396    EmbeddedAgent::Composed {
397        name: "golang-engineer",
398    },
399    EmbeddedAgent::Composed {
400        name: "java-engineer",
401    },
402    EmbeddedAgent::Composed {
403        name: "javascript-engineer",
404    },
405    // #8129: tcode-native build/test/version-bump/changelog agent.
406    EmbeddedAgent::Direct {
407        name: "local-ops",
408        md: LOCAL_OPS_MD,
409    },
410    EmbeddedAgent::Composed {
411        name: "nextjs-engineer",
412    },
413    EmbeddedAgent::Composed {
414        name: "elixir-engineer",
415    },
416    EmbeddedAgent::Composed {
417        name: "phoenix-engineer",
418    },
419    EmbeddedAgent::Composed {
420        name: "php-engineer",
421    },
422    EmbeddedAgent::Composed {
423        name: "prompt-engineer",
424    },
425    EmbeddedAgent::Composed {
426        name: "python-engineer",
427    },
428    EmbeddedAgent::Composed { name: "qa" },
429    EmbeddedAgent::Composed {
430        name: "react-engineer",
431    },
432    EmbeddedAgent::Composed {
433        name: "refactoring-engineer",
434    },
435    EmbeddedAgent::Composed { name: "research" },
436    EmbeddedAgent::Composed {
437        name: "ruby-engineer",
438    },
439    EmbeddedAgent::Composed {
440        name: "rust-engineer",
441    },
442    EmbeddedAgent::Composed { name: "security" },
443    EmbeddedAgent::Composed {
444        name: "svelte-engineer",
445    },
446    EmbeddedAgent::Composed {
447        name: "tauri-engineer",
448    },
449    // #4027: non-coding ticketing specialist, reachable from trusty-agents'
450    // widened cross-product bridge (#4026). See this module's "Non-coding
451    // cross-product roster addition" doc section. #8129 replaced the shared
452    // copy with a tcode-native one carrying a `tcode_tools:` allowlist.
453    EmbeddedAgent::Direct {
454        name: "ticketing",
455        md: TICKETING_MD,
456    },
457    EmbeddedAgent::Composed {
458        name: "typescript-engineer",
459    },
460    // #8129: the branch/commit/push/PR half of the delivery workflow.
461    EmbeddedAgent::Direct {
462        name: "version-control",
463        md: VERSION_CONTROL_MD,
464    },
465    EmbeddedAgent::Composed { name: "web-qa" },
466    EmbeddedAgent::Composed {
467        name: "web-ui-engineer",
468    },
469];
470
471// -- Slice E2 (#2958): embedded tm agent catalog, for `md_loader`'s in-memory
472// extends-composer. Slice E3 wires the 26 roster names above into
473// `DEFAULT_AGENTS` as `EmbeddedAgent::Composed` entries; this table remains
474// their content source, resolved at load time via
475// `agents::md_loader::project_embedded_md_with_extends`. --
476
477/// The 5 `BASE-*` extends-template names — composition bases only, never
478/// meant to be dispatched directly (issue #3465 follow-up: the Agents
479/// catalog listing was surfacing these to end users).
480///
481/// Why: single source of truth for "is this name a composition base"
482/// (issue #3449's `agents.list`) instead of a scattered `starts_with`
483/// check re-implemented per call site — `assets::tests::
484/// base_templates_are_never_dispatchable` (this table never leaks into
485/// [`DEFAULT_AGENTS`]) and `agents::protocol::is_base_agent` (the disk-tier
486/// catalog listing never surfaces one of these names even when a project's
487/// `.claude/agents/` dir has real `BASE-*.md` files on disk, as trusty-mpm's
488/// own bundle installs them — see `crates/trusty-mpm/src/core/bundle_all.rs`)
489/// both key off this list rather than duplicating it. Matched
490/// case-insensitively against a lowercased candidate — the on-disk filename
491/// convention is `BASE-QA.md` while frontmatter `name:`/`extends:` values
492/// are lowercase `base-qa`.
493/// Test: `assets::tests::base_templates_are_never_dispatchable`,
494/// `agents::protocol::tests::list_excludes_base_agents_but_resolve_agent_still_finds_them`.
495pub const BASE_AGENT_NAMES: &[&str] = &[
496    "base-agent",
497    "base-engineer",
498    "base-ops",
499    "base-qa",
500    "base-research",
501];
502
503const CODE_ANALYZER_MD: &str = include_str!("agents/code-analyzer.md");
504const CODE_CRITIC_MD: &str = include_str!("agents/code-critic.md");
505const QA_MD: &str = include_str!("agents/qa.md");
506const WEB_QA_MD: &str = include_str!("agents/web-qa.md");
507
508/// The 27 shared agent files tcode composes from: the 5 `BASE-*` extends
509/// templates plus 22 roster agents (#9011).
510///
511/// Why: these texts are instructional content (ADR-0064), read at runtime
512/// from the same source trusty-mpm reads — a trusty-tools checkout, else the
513/// bundle `tm content install` pinned — instead of being compiled in.
514/// Keyed by each file's name in `agents/` (`"BASE-QA.md"`,
515/// `"rust-engineer.md"`), which
516/// `trusty_agents_common::agents::builder_in_memory::InMemorySources::insert`
517/// lowercases and strips, so `extends: base-qa` resolves with no extra work.
518/// What: file names only; [`tm_agent_sources`] reads them from a roster.
519/// Test: `assets::tests::embedded_tm_agent_sources_has_31_entries_and_unique_keys`.
520pub const SHARED_TM_AGENT_FILES: &[&str] = &[
521    "BASE-AGENT.md",
522    "BASE-ENGINEER.md",
523    "BASE-OPS.md",
524    "BASE-QA.md",
525    "BASE-RESEARCH.md",
526    "api-qa.md",
527    "dart-engineer.md",
528    "data-engineer.md",
529    "golang-engineer.md",
530    "java-engineer.md",
531    "javascript-engineer.md",
532    "nextjs-engineer.md",
533    "elixir-engineer.md",
534    "phoenix-engineer.md",
535    "php-engineer.md",
536    "prompt-engineer.md",
537    "python-engineer.md",
538    "react-engineer.md",
539    "refactoring-engineer.md",
540    "research.md",
541    "ruby-engineer.md",
542    "rust-engineer.md",
543    "security.md",
544    "svelte-engineer.md",
545    "tauri-engineer.md",
546    "typescript-engineer.md",
547    "web-ui-engineer.md",
548];
549
550/// tcode's 4 read-only forks of shared roster agents, still embedded until
551/// PHASE_4 (#8390) — see this module's "Tools-restriction deviation" section.
552pub const LOCAL_TM_AGENT_FORKS: &[(&str, &str)] = &[
553    ("code-analyzer.md", CODE_ANALYZER_MD),
554    ("code-critic.md", CODE_CRITIC_MD),
555    ("qa.md", QA_MD),
556    ("web-qa.md", WEB_QA_MD),
557];
558
559/// The 31-entry tm agent catalog the extends-composer resolves against: every
560/// [`SHARED_TM_AGENT_FILES`] entry read from `roster`, then
561/// [`LOCAL_TM_AGENT_FORKS`].
562///
563/// Why: `agents::md_loader` and the roster deploy need one batch source of
564/// `(file name, markdown)` pairs, as the compiled-in table used to be.
565/// What: `Err(AgentContentError::Missing)` when `roster` lacks a shared file,
566/// so a partial catalog never composes.
567/// Test: `assets::tests::embedded_tm_agent_sources_has_31_entries_and_unique_keys`.
568pub fn tm_agent_sources(
569    roster: &trusty_agents_common::agent_content::AgentRoster,
570) -> Result<Vec<(String, String)>, trusty_agents_common::agent_content::AgentContentError> {
571    let mut out = Vec::with_capacity(SHARED_TM_AGENT_FILES.len() + LOCAL_TM_AGENT_FORKS.len());
572    for file in SHARED_TM_AGENT_FILES {
573        out.push(((*file).to_string(), roster.require(file)?.to_string()));
574    }
575    for (file, md) in LOCAL_TM_AGENT_FORKS {
576        out.push(((*file).to_string(), (*md).to_string()));
577    }
578    Ok(out)
579}
580
581/// [`tm_agent_sources`] over the roster resolved for this process: the
582/// trusty-tools checkout above the cwd, else the installed content bundle.
583/// Every failure names `tm content install` or `tm content update`.
584pub fn load_tm_agent_sources()
585-> Result<Vec<(String, String)>, trusty_agents_common::agent_content::AgentContentError> {
586    use trusty_agents_common::agent_content::{AgentRoster, DevOverride, resolve_content};
587    let dev = std::env::current_dir().map_or(DevOverride::Off, DevOverride::DetectFrom);
588    tm_agent_sources(&AgentRoster::load(&resolve_content(dev)?)?)
589}
590
591const API_DESIGN_PATTERNS_SKILL: &str = include_str!("skills/api-design-patterns/SKILL.md");
592const API_DOCUMENTATION_SKILL: &str = include_str!("skills/api-documentation/SKILL.md");
593const ARTIFACTS_BUILDER_SKILL: &str = include_str!("skills/artifacts-builder/SKILL.md");
594const BRAINSTORMING_SKILL: &str = include_str!("skills/brainstorming/SKILL.md");
595const CODE_PRODUCTION_PROCESS_SKILL: &str = include_str!("skills/code-production-process/SKILL.md");
596const CODE_REVIEW_STANDARDS_SKILL: &str = include_str!("skills/code-review-standards/SKILL.md");
597const CONDITION_BASED_WAITING_SKILL: &str = include_str!("skills/condition-based-waiting/SKILL.md");
598const CONTRACT_DRIVEN_TESTING_SKILL: &str = include_str!("skills/contract-driven-testing/SKILL.md");
599const DATABASE_MIGRATION_SKILL: &str = include_str!("skills/database-migration/SKILL.md");
600const DOCUMENTATION_STYLE_SKILL: &str = include_str!("skills/documentation-style/SKILL.md");
601const ENV_MANAGER_SKILL: &str = include_str!("skills/env-manager/SKILL.md");
602const GIT_WORKFLOW_SKILL: &str = include_str!("skills/git-workflow/SKILL.md");
603const INTERNAL_COMMS_SKILL: &str = include_str!("skills/internal-comms/SKILL.md");
604const JSON_DATA_HANDLING_SKILL: &str = include_str!("skills/json-data-handling/SKILL.md");
605const MODEL_CONTEXT_BUILDER_SKILL: &str = include_str!("skills/model-context-builder/SKILL.md");
606const REQUESTING_CODE_REVIEW_SKILL: &str = include_str!("skills/requesting-code-review/SKILL.md");
607const ROOT_CAUSE_TRACING_SKILL: &str = include_str!("skills/root-cause-tracing/SKILL.md");
608const SECURITY_SCANNING_SKILL: &str = include_str!("skills/security-scanning/SKILL.md");
609const SOFTWARE_PATTERNS_SKILL: &str = include_str!("skills/software-patterns/SKILL.md");
610const SYSTEMATIC_DEBUGGING_SKILL: &str = include_str!("skills/systematic-debugging/SKILL.md");
611const TEST_DRIVEN_DEVELOPMENT_SKILL: &str = include_str!("skills/test-driven-development/SKILL.md");
612const TEST_QUALITY_INSPECTOR_SKILL: &str = include_str!("skills/test-quality-inspector/SKILL.md");
613const TESTING_ANTI_PATTERNS_SKILL: &str = include_str!("skills/testing-anti-patterns/SKILL.md");
614const VERIFICATION_BEFORE_COMPLETION_SKILL: &str =
615    include_str!("skills/verification-before-completion/SKILL.md");
616const WEB_PERFORMANCE_OPTIMIZATION_SKILL: &str =
617    include_str!("skills/web-performance-optimization/SKILL.md");
618const WEBAPP_TESTING_SKILL: &str = include_str!("skills/webapp-testing/SKILL.md");
619const WRITING_PLANS_SKILL: &str = include_str!("skills/writing-plans/SKILL.md");
620const XLSX_SKILL: &str = include_str!("skills/xlsx/SKILL.md");
621
622/// trusty-mpm's universal skill set, embedded at compile time (`tm-*`
623/// orchestration skills excluded — see module docs).
624///
625/// Why: gives `skills::discover_skill_metadata`'s embedded-fallback branch a
626/// fixed, ordered table to build a `SkillMetadata` catalog from when the disk
627/// `.claude/skills/` directory is empty or absent.
628/// What: 28 skills, sorted by name, each an `EmbeddedSkill { name, skill_md }`.
629/// Test: `assets::tests::default_skills_names_are_unique`.
630pub const DEFAULT_SKILLS: &[EmbeddedSkill] = &[
631    EmbeddedSkill {
632        name: "api-design-patterns",
633        skill_md: API_DESIGN_PATTERNS_SKILL,
634    },
635    EmbeddedSkill {
636        name: "api-documentation",
637        skill_md: API_DOCUMENTATION_SKILL,
638    },
639    EmbeddedSkill {
640        name: "artifacts-builder",
641        skill_md: ARTIFACTS_BUILDER_SKILL,
642    },
643    EmbeddedSkill {
644        name: "brainstorming",
645        skill_md: BRAINSTORMING_SKILL,
646    },
647    EmbeddedSkill {
648        name: "code-production-process",
649        skill_md: CODE_PRODUCTION_PROCESS_SKILL,
650    },
651    EmbeddedSkill {
652        name: "code-review-standards",
653        skill_md: CODE_REVIEW_STANDARDS_SKILL,
654    },
655    EmbeddedSkill {
656        name: "condition-based-waiting",
657        skill_md: CONDITION_BASED_WAITING_SKILL,
658    },
659    EmbeddedSkill {
660        name: "contract-driven-testing",
661        skill_md: CONTRACT_DRIVEN_TESTING_SKILL,
662    },
663    EmbeddedSkill {
664        name: "database-migration",
665        skill_md: DATABASE_MIGRATION_SKILL,
666    },
667    EmbeddedSkill {
668        name: "documentation-style",
669        skill_md: DOCUMENTATION_STYLE_SKILL,
670    },
671    EmbeddedSkill {
672        name: "env-manager",
673        skill_md: ENV_MANAGER_SKILL,
674    },
675    EmbeddedSkill {
676        name: "git-workflow",
677        skill_md: GIT_WORKFLOW_SKILL,
678    },
679    EmbeddedSkill {
680        name: "internal-comms",
681        skill_md: INTERNAL_COMMS_SKILL,
682    },
683    EmbeddedSkill {
684        name: "json-data-handling",
685        skill_md: JSON_DATA_HANDLING_SKILL,
686    },
687    EmbeddedSkill {
688        name: "model-context-builder",
689        skill_md: MODEL_CONTEXT_BUILDER_SKILL,
690    },
691    EmbeddedSkill {
692        name: "requesting-code-review",
693        skill_md: REQUESTING_CODE_REVIEW_SKILL,
694    },
695    EmbeddedSkill {
696        name: "root-cause-tracing",
697        skill_md: ROOT_CAUSE_TRACING_SKILL,
698    },
699    EmbeddedSkill {
700        name: "security-scanning",
701        skill_md: SECURITY_SCANNING_SKILL,
702    },
703    EmbeddedSkill {
704        name: "software-patterns",
705        skill_md: SOFTWARE_PATTERNS_SKILL,
706    },
707    EmbeddedSkill {
708        name: "systematic-debugging",
709        skill_md: SYSTEMATIC_DEBUGGING_SKILL,
710    },
711    EmbeddedSkill {
712        name: "test-driven-development",
713        skill_md: TEST_DRIVEN_DEVELOPMENT_SKILL,
714    },
715    EmbeddedSkill {
716        name: "test-quality-inspector",
717        skill_md: TEST_QUALITY_INSPECTOR_SKILL,
718    },
719    EmbeddedSkill {
720        name: "testing-anti-patterns",
721        skill_md: TESTING_ANTI_PATTERNS_SKILL,
722    },
723    EmbeddedSkill {
724        name: "verification-before-completion",
725        skill_md: VERIFICATION_BEFORE_COMPLETION_SKILL,
726    },
727    EmbeddedSkill {
728        name: "web-performance-optimization",
729        skill_md: WEB_PERFORMANCE_OPTIMIZATION_SKILL,
730    },
731    EmbeddedSkill {
732        name: "webapp-testing",
733        skill_md: WEBAPP_TESTING_SKILL,
734    },
735    EmbeddedSkill {
736        name: "writing-plans",
737        skill_md: WRITING_PLANS_SKILL,
738    },
739    EmbeddedSkill {
740        name: "xlsx",
741        skill_md: XLSX_SKILL,
742    },
743];
744
745// -- Tests --------------------------------------------------------------------
746// Split into `tests.rs` (not inlined) to keep this include-table file thin;
747// see `tests.rs` module docs.
748
749#[cfg(test)]
750mod tests;