Skip to content

refactor(agents): flatten agents directory#621

Merged
tmchow merged 6 commits intomainfrom
refactor/flatten-agents-directory
Apr 21, 2026
Merged

refactor(agents): flatten agents directory#621
tmchow merged 6 commits intomainfrom
refactor/flatten-agents-directory

Conversation

@tmchow
Copy link
Copy Markdown
Collaborator

@tmchow tmchow commented Apr 21, 2026

Summary

Agent references are now plain ce-<agent-name> — one canonical form, not a category-qualified <category>:ce-<agent> namespace tied to directory layout. All 50 agents live flat under plugins/compound-engineering/agents/. Codex TOML filenames drop the category prefix too (review-ce-correctness-reviewer.tomlce-correctness-reviewer.toml).

Previously, the category segment was structural coupling: the Codex converter rebuilt it from each agent's sourcePath, and 117 references across 16 files had to stay aligned with the six subfolder names. Flattening removes the coupling — the filename is the identifier, and there is one canonical reference form.

Why these commits ship together

Commit Change
refactor(agents): flatten agents directory 50 git mv renames out of six category subfolders into flat agents/. No content change.
refactor(agents): rewrite category-prefixed refs to bare ce- form Narrow perl regex across 16 skill and agent files. 117 insertions == 117 deletions.
refactor(agents): update AGENTS.md conventions for flat layout Root AGENTS.md and plugin AGENTS.md — agent-reference convention, Directory Structure, Naming Convention, Adding Components.
feat(codex): clean up orphan sidecar dirs for retained agents New sweep in src/targets/codex.ts: for retained agents with no sidecarDirs, delete any same-basename sibling directory under agentsRoot. Gated by isSafeManagedPath. Three new tests.
refactor(tests): update fixtures for flat agents layout Seven test files moved to flat sourcePath fixtures. New test pins the nested-layout dead-code fallback. Dead -ce- split branch in cleanupLegacyAgentSkillDirs removed.

A partial landing would break things: moving files without updating references would leave the Codex converter unable to resolve source <category>:ce-<agent> refs (the new flat-layout converter no longer registers those aliases); updating references without moving files would leave 50 agents in subfolders that the convention no longer documents; and flipping the convention docs without both would hand contributors contradictory guidance.

Design decisions

  • The ce- prefix alone carries uniqueness. The category segment was redundant defense-in-depth against short-name collisions across plugins — the ce- prefix already prevents them. Dropping the category tier removes a fake hierarchy without weakening the actual guarantee.
  • getAgentCategory() stays as dead-code fallback. Compound-engineering won't exercise it, but any third-party plugin passed through the CLI that still uses subfolders continues producing <category>-ce-<agent> Codex names. A test in tests/codex-converter.test.ts pins the behavior; deletion is deferred.
  • No migration shim for installed Codex users. The existing install-manifest cleanup path (cleanupRemovedAgents in src/targets/codex.ts) sweeps the 50 stale <category>-ce-<agent>.toml files on next bun install --to codex, including same-name sibling directories. A fresh install converges on the new names without a compatibility alias.
  • Orphan sidecar cleanup generalizes past the flatten. cleanupRemovedAgents only removed sidecar dirs when the TOML itself was being removed — a same-name agent that lost its sidecar left an orphan indefinitely. The new sweep runs for every retained agent that declares zero sidecarDirs, closing that gap for future cases.

Test plan

  • bun test — 830 pass / 0 fail
  • bun run release:validate — no drift (compound-engineering currently has 50 agents, 45 skills, 0 MCP servers)
  • Real-install smoke test: bun install --to codex against a working Codex install — the 50 prior <category>-ce-<agent>.toml files were removed, the research-ce-session-historian/ orphan sidecar directory was removed, 50 bare ce-<name>.toml files were written, the install manifest lists the new names
  • Reviewer: re-run bun install --to codex on your own Codex install to verify the rename-and-cleanup path behaves the same against your manifest state
  • Reviewer: confirm bare ce-<name> references resolve correctly for you in Claude Code — there is no programmatic test that proves the runtime subagent resolver accepts bare names; the refactor depends on it

Notes for reviewers

The pre-implementation doc review surfaced seven P2 concerns that were deliberately not resolved in this PR (concrete triggering incident, ce- as a reserved prefix across the marketplace, upgrade-archetype enumeration, and so on). They live under ### From 2026-04-21 review in docs/plans/2026-04-21-001-refactor-flatten-agents-directory-plan.md — worth a glance if any are blocking for you.

Plan: docs/plans/2026-04-21-001-refactor-flatten-agents-directory-plan.md


Compound Engineering
Claude Code

tmchow and others added 5 commits April 21, 2026 01:54
Move all 50 agent files out of category subfolders (review/, research/,
workflow/, design/, document-review/, docs/) into the flat
plugins/compound-engineering/agents/ directory. Filenames and name:
frontmatter values are unchanged; only the parent directory moves.

The subfolder organization was a human-readability aid, not a harness
requirement. The Claude Code parser walks recursively, and every other
target writer (Codex, OpenCode, Gemini, Kiro, Droid, Copilot, Pi) writes
agents to a flat output regardless of input layout. Flattening removes a
coupling point between source structure and Codex agent naming.

Subsequent commits in this series rewrite the 117 category-prefixed
references in skill/agent content, update the AGENTS.md conventions, and
update the test fixtures that hardcoded nested paths.

Per docs/plans/2026-04-21-001-refactor-flatten-agents-directory-plan.md
Unit 1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Convert 117 occurrences of `<category>:ce-<agent-name>` to bare
`ce-<agent-name>` across 16 files in the compound-engineering plugin.
The ce- prefix is sufficient for uniqueness; the `<category>:` segment
was only meaningful because the Codex converter's getAgentCategory()
rebuilt it from the source path, which now returns null for every agent
after Unit 1's flatten.

Applied via a narrow perl regex matching only the six known category
names (review, research, workflow, design, document-review, docs) when
followed directly by `:ce-`. Post-sweep grep for the pattern returns
zero. Insertions and deletions balance exactly (117 each), confirming
the rewrite was surface-only.

Per docs/plans/2026-04-21-001-refactor-flatten-agents-directory-plan.md
Unit 3.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Root AGENTS.md: rewrite "Agent References in Skills" to mandate bare
ce-<agent-name>. Plugin AGENTS.md: collapse the Directory Structure
tree to a flat agents/ listing; update the Naming Convention paragraph
to state bare ce-<agent-name> as the reference form; update the "New
agent" bullet under Adding Components to drop the <category> path
segment.

Verified plugins/compound-engineering/README.md has no prose implying
agents/<category>/ — the topical agent tables describe conceptual
groupings, not directory paths.

Per docs/plans/2026-04-21-001-refactor-flatten-agents-directory-plan.md
Unit 4.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When writing Codex custom agents, delete any same-basename sibling
directory under agentsRoot if the retained agent declares zero
sidecarDirs. Previously, cleanupRemovedAgents only swept the sibling
directory when the TOML itself was being removed — a same-name agent
that lost its sidecar between plugin versions left an orphan directory
indefinitely.

The new sweep is narrowly scoped: it only runs against base names of
agents in the current install and only when the agent declares no
sidecars, so unrelated directories under agentsRoot are untouched.
Gated by isSafeManagedPath to match the existing cleanup safety
pattern.

Tests cover the three scenarios: orphan removed when agent has no
sidecars, sidecar preserved when agent declares one, unrelated
directory left alone.

Per docs/plans/2026-04-21-001-refactor-flatten-agents-directory-plan.md
Unit 4b.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Update sourcePath fixtures and expected Codex agent names across the
test suite to reflect agents now living directly under
plugins/compound-engineering/agents/ with no category subfolders:

- tests/codex-converter.test.ts: flip the namespaced-Task test to the
  flat layout with bare ce-<agent> expected names. Add a new test that
  pins the nested-layout fallback: any third-party plugin still using
  agents/<category>/<name>.md passed through convertClaudeToCodex must
  continue to produce <category>-ce-<agent> Codex agent names.
- tests/pi-writer.test.ts, tests/review-skill-contract.test.ts,
  tests/legacy-cleanup.test.ts, tests/pipeline-review-contract.test.ts,
  tests/kiro-writer.test.ts: strip the <category>/ segment from every
  hardcoded plugins/compound-engineering/agents/* path. Several of
  these (legacy-cleanup.test.ts in particular) perform live filesystem
  reads and would throw ENOENT if left pointing at the old nested
  locations.
- tests/review-skill-contract.test.ts: update the
  stack-specific-reviewers contract test to assert bare ce-<agent>
  references in SKILL.md / persona-catalog.md, matching the new
  convention.

Also simplify cleanupLegacyAgentSkillDirs: the `agent.name.includes("-ce-")`
branch relied on compound names like review-ce-foo to extract a legacy
ce-<final> variant. Every current agent now starts with ce- with no
embedded -ce-, so that branch produced nonsense entries (ce-ce-<name>)
and swept nothing. Remove the dead branch; keep the primary
legacySkillNames.add(sanitizePathName(agent.name)) which still catches
stale skill directories under ~/.codex/skills/<plugin>/<agent-name>/.

bun test passes with 830 tests green. bun run release:validate reports
no drift: compound-engineering at 50 agents, 45 skills, 0 MCP servers.

Per docs/plans/2026-04-21-001-refactor-flatten-agents-directory-plan.md
Unit 5.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tmchow tmchow changed the title refactor(agents): flatten agents directory for cross-harness simplicity refactor(agents): flatten agents directory Apr 21, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25f1c8b975

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/targets/codex.ts
In cleanupLegacyAgentSkillDirs, re-add the branch that extracts the
final segment after `-ce-` from a compound agent name and seeds
`ce-<final-segment>` as a legacy-cleanup candidate. The branch was
removed in 25f1c8b as dead code for compound-engineering itself, but
it's load-bearing for nested-layout third-party plugins passed through
the CLI: their agent names keep the `<category>-ce-<name>` shape, and
without the split a stale `~/.codex/skills/<plugin>/ce-<name>/`
directory from a prior flat-alias install is never swept. For
compound-engineering the branch remains inert (names don't contain
embedded `-ce-`), so this is purely additive coverage for other shapes.

Guard the split on `agent.name.includes("-ce-")` so no-op candidates
are not seeded for flat-only layouts. Add a comment naming the
cross-layout-migration intent so the branch isn't flagged as dead code
again. Regression test in tests/codex-writer.test.ts pins the behavior
against a nested-layout bundle.

Addresses PR #621 review feedback.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tmchow tmchow merged commit 4c57508 into main Apr 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant