compound-engineering-plugin icon indicating copy to clipboard operation
compound-engineering-plugin copied to clipboard

fix(opencode): generate slash-command stubs for each skill

Open lucabattistini opened this issue 6 months ago • 4 comments

Problem

When installing the compound-engineering plugin to OpenCode, zero slash commands were written to ~/.config/opencode/commands/. The convertClaudeToOpenCode function only consumed plugin.commands (a commands/ directory), but the CE plugin ships only skills — so users had no /ce-work, /ce-plan, etc. available in OpenCode, even though all 54 skills were correctly installed.

Solution

Added convertSkillsToCommands(skills: ClaudeSkill[]): OpenCodeCommandFile[] that generates one slash-command stub per skill. Each stub:

  • Carries the skill's description as frontmatter
  • Forwards argument-hint when present
  • Has a body that tells the model to load and execute the named skill, with $ARGUMENTS passed through

Skills with disable-model-invocation: true are excluded. Platform-filtered skills (e.g. ce_platforms: [claude]) never reach the function.

The generated stubs are merged with any convertCommands() output in convertClaudeToOpenCode, so plugins that have both a commands/ directory and skills get both.

Tests

  • Updated the existing "current compound-engineering output" test to assert commandFiles.length > 0 and ≤ skillDirs.length
  • Added a new test asserting skill-one generates a command with correct frontmatter, and that disabled-skill / claude-only-skill are absent from commandFiles
  • All 1338 tests pass

lucabattistini avatar May 05 '26 10:05 lucabattistini

Does this handle the cleanup properly when skills change (renamed or deleted)?

tmchow avatar May 05 '26 17:05 tmchow

@tmchow Yes — cleanup rides the existing managed-install-manifest plumbing.

convertSkillsToCommands produces OpenCodeCommandFile[] that get appended to bundle.commandFiles (claude-to-opencode.ts:104-110). The writer then:

  1. Builds currentCommands from bundle.commandFiles (opencode.ts:73)
  2. Calls cleanupRemovedManagedFiles(commandDir, manifest, "commands", currentCommands) before writing (opencode.ts:79) — anything in the prior manifest's commands group that's not in the new currentCommands gets fs.rm-ed
  3. Rewrites the manifest with the current set (opencode.ts:135-144)

So:

Scenario Behavior
Skill renamed Old stub path drops out of currentCommands → removed; new path written and tracked
Skill deleted Old stub path drops out → removed
Skill gains disable-model-invocation / user-invocable: false Filtered out of stubs (claude-to-opencode.ts:184-185) → removed on next install
First upgrade from a pre-776 install Prior manifest had commands: [], so cleanup is a no-op; the 54 stubs become tracked from this install onward

Test coverage for this contract already exists at tests/opencode-writer.test.ts:359 ("removes previously managed OpenCode artifacts that disappear on reinstall") — it writes old:cmd, re-installs with new:cmd only, and asserts commands/old/cmd.md is gone. Stubs ride the same path; nothing in this PR changes the writer/manifest contract, only what feeds into it.

One small caveat (pre-existing, not introduced here): cleanupRemovedManagedFiles removes files but doesn't prune empty parent dirs, so a colon-namespaced rename (foo:bar → foo:baz) could leave an empty commands/foo/. Happy to fix that in a follow-up if it's worth it, but it applies to any nested command path, not just skill stubs.

lucabattistini avatar May 05 '26 21:05 lucabattistini

@tmchow do you have any updates for me? Anything else I can do to wrap this up?

lucabattistini avatar May 11 '26 07:05 lucabattistini

Verified on macOS — the fix works correctly.

Before this PR, my install-manifest.json had "commands": []. After installing from this branch, the command stubs were generated under ~/.config/opencode/commands, each with proper description and argument-hint frontmatter.

All skills are now directly invocable via / commands in OpenCode. Thanks @lucabattistini!

MicheleMontesi avatar May 19 '26 17:05 MicheleMontesi