'use strict'; /** * Shared helper for the canonical shipped-agent roster. * * Several tests derive "the set of agents we ship" from the source `agents/` * directory via `fs.readdirSync(...).filter(/^msd-.*\.md$/)`. This consolidates * that hand-duplicated logic into one canonical SOURCE-roster derivation. * * NOTE: This returns the SOURCE roster (basenames without `.md`, sorted). Sites * with different semantics — installed-destination dirs, absolute-path returns, * or `.toml`-inclusive Codex rosters — must NOT use this helper. * * NOTE (#4407): `agents/*.compact.md` variant siblings are deliberately EXCLUDED. * A compact variant is not a new agent — it is an alternate rendition of an * existing roster entry, served by the `#2454` fallback in `cmdAgentSkills` * (`src/init.cts`) when `workflow.compact_content` is on. Every roster-identity * check this helper backs (frontmatter/tools invariants, "every shipped agent" * install assertions, etc.) is about the SET of distinct agents MSD ships, which * a variant does not add to. */ const fs = require('node:fs'); const path = require('node:path'); // Canonical source agents directory: /agents, relative to this // helper at tests/helpers/. Matches the path the consolidated call sites used. const AGENTS_DIR = path.join(__dirname, '..', '..', 'agents'); /** * List shipped agent basenames (without the `.md` extension), sorted. * * @param {string} [agentsDir] Override for the source agents directory. * Defaults to the canonical `/agents`. * @returns {string[]} Sorted `msd-*` basenames with `.md` stripped. */ function listAgentFiles(agentsDir = AGENTS_DIR) { return fs .readdirSync(agentsDir) .filter((f) => /^msd-.*\.md$/.test(f) && !f.endsWith('.compact.md')) .map((f) => f.replace(/\.md$/, '')) .sort(); } module.exports = { // AGENTS_DIR is exported (not yet consumed by a call site) so future tests that // need the canonical source agents path can reuse it instead of rediscovering it. AGENTS_DIR, listAgentFiles, };