OpenSpec icon indicating copy to clipboard operation
OpenSpec copied to clipboard

fix: use skill references in SKILL.md for skills-only delivery

Open mc856 opened this issue 5 months ago • 4 comments

Fixes #881, closes #879.

When delivery: 'skills' is configured, generated SKILL.md files contained hardcoded /opsx:* command references pointing to commands that were never generated. This implements the fix outlined in #881: adds transformToSkillReferences() with the explicit 11-entry command-to-skill mapping and wires it at every generateSkillContent call site — init.ts, both sites in update.ts (including upgradeLegacyTools), and both sites in workspace/skills.ts.

Deviations from the issue snapshot

  • Kept the existing pi branch in the transformer condition. The issue snippet only checks opencode, but main already routes pi through transformToHyphenCommands; copying the snippet verbatim would regress pi.
  • workspace/skills.ts wired in addition to the files listed in the issue. It generates SKILL.md from the same globalConfig.delivery and is itself a skills-only surface, so the bug persisted there. Regression test included (verified to fail against the unwired code).
  • Note: WORKFLOW_TO_SKILL_DIR exists in both init.ts (local copy) and profile-sync-drift.ts (exported); the two are identical and COMMAND_TO_SKILL_REFERENCE matches both.

Open question for maintainers

In skills-only mode, opencode/pi still take the transformToHyphenCommands branch, so their SKILL.md files contain /opsx-* references to commands that were also never generated — same class of bug. I didn't expand scope because it's unclear whether /openspec-<skill> slash references resolve in those tools. Happy to file a follow-up issue. The legacy-upgrade path also lacks a skills-only content assertion; same offer.

Testing

  • npx eslint src/ clean
  • transformToSkillReferences unit tests: per-mapping assertions for all 11 commands, multi-reference, backtick, unknown-command, and bulk-archive/archive boundary cases
  • Integration: init + update skills-only cases assert generated SKILL.md contains no /opsx: and does contain /openspec- (explore template verified to contain /opsx: references, so the assertion is discriminative); new workspace test mutation-verified
  • Full vitest suite passing

Generated with Claude (Cowork) using claude-fable-5.

Summary by CodeRabbit

  • Bug Fixes
    • Skill setup and update flows now generate the correct skill command references when using skills-only delivery.
    • Generated skill files no longer include unsupported command markers and instead link to the expected skill references.
    • Command references are now selected consistently based on delivery mode, improving output across supported tools.

mc856 avatar Jun 10 '26 03:06 mc856

Review Change Stack

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] ▶️ Resume reviews
  • [ ] 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds delivery-aware reference transformation for skills-only delivery, wires it into init and update SKILL.md generation, re-exports the helpers, and expands unit and integration coverage.

Changes

Skills-Only Delivery Reference Transformation

Layer / File(s) Summary
Skill reference transformer utility
src/utils/command-references.ts, src/utils/index.ts, .changeset/skills-only-references.md
Maps /opsx:<command> tokens to /openspec-* references, selects transformers by tool and delivery, re-exports the utilities, and documents the patch.
Core module transformer wiring
src/core/init.ts, src/core/update.ts
Init and update pass delivery-aware transformers into SKILL.md generation in main and legacy setup paths.
Transformer and SKILL.md tests
test/utils/command-references.test.ts, test/core/init.test.ts, test/core/update.test.ts
Tests reference conversion, transformer selection, and generated skills-only SKILL.md content.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant InitCommand
  participant UpdateCommand
  participant getTransformerForTool
  participant generateSkillContent
  InitCommand->>getTransformerForTool: resolve transformer(tool.value, delivery)
  getTransformerForTool-->>InitCommand: return delivery-appropriate transformer
  InitCommand->>generateSkillContent: generate transformed SKILL.md
  UpdateCommand->>getTransformerForTool: resolve transformer(tool.value, delivery)
  getTransformerForTool-->>UpdateCommand: return delivery-appropriate transformer
  UpdateCommand->>generateSkillContent: generate transformed SKILL.md

Possibly related PRs

Suggested reviewers: tabishb

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: using skill references in SKILL.md for skills-only delivery.
Linked Issues check ✅ Passed The PR implements the required skill-reference mapping, wires it into init/update flows, and adds tests for skills-only delivery.
Out of Scope Changes check ✅ Passed The extra changes are limited to tests, docs, and a changeset note, which are all directly supportive of the fix.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Jun 10 '26 03:06 coderabbitai[bot]

Pushed 4ef4c48 addressing the CodeRabbit review: extracted the duplicated transformer selection into getTransformerForTool() in command-references.ts (with JSDoc and unit tests locking the selection matrix), replacing all five call sites.

On consolidating the WORKFLOW_TO_SKILL_DIR copies: agreed in principle, but deriving the map in src/utils from src/core/profile-sync-drift.ts would invert the utils ← core layering, and moving the canonical map into utils touches profile-sync-drift.ts typing and init.ts beyond this bugfix's scope. Happy to do it as a follow-up PR if maintainers agree.

mc856 avatar Jun 10 '26 03:06 mc856

Done in 8c66688 — delivery === 'skills' now wins for every tool: getTransformerForTool checks skills-only delivery first and only falls back to the hyphen transform for opencode/pi when commands are actually generated. Added unit coverage for the opencode/pi selection matrix and an opencode skills-only init integration test asserting the generated SKILL.md contains no /opsx: or /opsx- references. This also closes out the open question from the PR description — thanks for the call.

mc856 avatar Jun 12 '26 02:06 mc856

@alfred-openspec I rebased this onto the latest upstream main and resolved the merge conflict; GitHub now reports it as mergeable and CodeRabbit is green again. The previous approval was marked stale after the force-push, so could you please re-confirm when you have a chance?

mc856 avatar Jun 25 '26 04:06 mc856

I rebased this onto the latest upstream main and resolved the merge conflicts from the v1.6.0 changes — the transformer selection now also covers the newly added oh-my-pi tool, with matching test coverage. GitHub reports the PR as mergeable again. I also added docstrings to the touched entry points to clear the docstring coverage warning. @alfred-openspec the rebase marked your approval as stale — could you re-confirm when you get a chance?

mc856 avatar Jul 12 '26 19:07 mc856

Nice fix, and the opencode/pi precedence is now handled correctly. One gap before this is complete:

The new COMMAND_TO_SKILL_REFERENCE map is missing the update command. It has 11 entries, but the canonical WORKFLOW_TO_SKILL_DIR (which the map's own comment says to stay in sync with) has 12 — it also includes update.

Why it matters: update is a core workflow, so openspec-update-change/SKILL.md is generated by default, and that template references /opsx:update (src/core/templates/workflows/update-change.ts:104). In skills-only mode the transformer leaves unknown commands untouched, so that skill still ships a broken /opsx:update reference — the exact bug this PR fixes, just for one more command.

The current tests miss it because they only assert against the explore skill, which has no /opsx:update.

Suggested fix:

  • Add 'update': '/openspec-update-change', to COMMAND_TO_SKILL_REFERENCE.
  • Add an assertion against the openspec-update-change skill (or any skill containing an update reference) so not.toContain('/opsx:') would catch a future omission.

Everything else looks good to go.

clay-good avatar Jul 18 '26 18:07 clay-good

Good catch — added the update entry in bb81a67, so the map now mirrors all 12 entries of WORKFLOW_TO_SKILL_DIR. One note: the skill variant of update-change drops the /opsx:update self-reference (only the command template at update-change.ts:104 carries it), so no generated skill currently ships the raw reference — the gap was latent. Covered it anyway: a unit test asserting the /opsx:update mapping, plus not.toContain('/opsx:') assertions on the generated openspec-update-change skill in both the init and update suites, so a future template that does reference update can't ship untransformed.

mc856 avatar Jul 18 '26 19:07 mc856