spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

fix: rewrite extension-relative subdir paths in generated command bodies

Open marcelsafin opened this issue 4 months ago • 2 comments

Fixes #2101

Root cause

Extension command bodies reference bundled files relative to the extension root (agents/control/commander.md, knowledge-base/agent-scores.yaml, templates/kill-report.md). After install those files live under .specify/extensions/<id>/, but register_commands emitted the bare paths verbatim. Agents resolve them against the workspace root, where they don't exist. rewrite_project_relative_paths only knows about memory/, scripts/ and templates/, and rewrites templates/ to .specify/templates/ even when the extension bundles its own.

Fix

New static CommandRegistrar.rewrite_extension_paths(text, extension_id, extension_dir):

  • Discovers subdirectories that actually exist in the installed extension and rewrites matching subdir/... references to .specify/extensions/<id>/subdir/.... Existence-based discovery keeps it conservative: no false positives on prose, and extensions without a given subdir keep today's behavior.
  • Never rewrites commands/ (slash-command sources), specs/ (user project artifacts) or dot-directories.
  • Called once in the register_commands loop when extension_id is set, so every output format (SKILL.md, markdown, TOML, YAML) and every alias gets the fix through the shared path.

Before: Read agents/control/commander.md (unresolvable) After: Read .specify/extensions/echelon/agents/control/commander.md

Tests

  • Codex SKILL.md registration rewrites agents/, knowledge-base/ and templates/ refs; specs/ and commands/ stay untouched
  • Alias skills reuse the rewritten body
  • Markdown-format agents (amp) get the same rewrite via the shared path
  • Unit: only existing subdirs rewritten, dot-dirs skipped, missing extension dir returns text unchanged

Full suite: 3896 passed, 108 skipped. ruff check clean.

Credit

Approach follows @mbachorik's design in his fork (existence-based subdir discovery, the specs/ exclusion). He offered the takeover in #2101. This PR extracts only the path-rewrite fix; the behavior-vocabulary work in #2103 is untouched.

marcelsafin avatar Jul 10 '26 07:07 marcelsafin

Please address Copilot feedback

mnriem avatar Jul 10 '26 14:07 mnriem

Fixed the remaining composition path in 8c92ead: extension-relative paths are now rewritten when append/prepend/wrap presets compose over an extension base, covering command, skill, initial-registration, and reconciliation outputs. Full suite: 3904 passed, 108 skipped. Posted on behalf of @marcelsafin by GitHub Copilot (model: GPT-5.6 Sol). @copilot review

marcelsafin avatar Jul 11 '26 00:07 marcelsafin

Thank you!

mnriem avatar Jul 13 '26 15:07 mnriem