Skip to content

fix(opencode): use plural commands/ directory to match OpenCode convention#760

Open
fsilvaortiz wants to merge 2 commits intoFission-AI:mainfrom
fsilvaortiz:fix/748-opencode-commands-directory
Open

fix(opencode): use plural commands/ directory to match OpenCode convention#760
fsilvaortiz wants to merge 2 commits intoFission-AI:mainfrom
fsilvaortiz:fix/748-opencode-commands-directory

Conversation

@fsilvaortiz
Copy link

@fsilvaortiz fsilvaortiz commented Feb 25, 2026

Summary

  • OpenCode adapter path corrected from .opencode/command/ (singular) to .opencode/commands/ (plural) to match OpenCode's official directory convention
  • Legacy cleanup detects both opsx-*.md and openspec-*.md in old singular path (via string | string[] pattern support)
  • Auto-cleanup legacy artifacts in non-interactive mode (CI) instead of aborting with exit 1
  • Documentation, specs, and tests updated accordingly

Fixes #748.

Test plan

  • All 82 adapter tests pass (pnpm vitest run test/core/command-generation/adapters.test.ts)
  • All 88 legacy-cleanup tests pass (pnpm vitest run test/core/legacy-cleanup.test.ts)
  • All 42 init tests pass (pnpm vitest run test/core/init.test.ts)
  • Build succeeds (pnpm build)
  • Verify openspec init --tools opencode generates files at .opencode/commands/
  • Verify legacy cleanup detects old .opencode/command/opsx-*.md artifacts
  • Verify legacy cleanup detects old .opencode/command/openspec-*.md artifacts
  • Verify both patterns map to opencode tool ID (deduplicated)
  • Verify non-interactive init auto-cleans legacy artifacts without --force

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Corrected OpenCode adapter to store commands in the proper directory structure, aligning with official conventions and improving consistency.
    • Implemented automatic detection and cleanup of legacy command artifacts during initialization with full backward compatibility support.
  • Documentation

    • Updated supported tools reference documentation to reflect the corrected OpenCode command path structure.

…vention

The OpenCode adapter was using `.opencode/command/` (singular) but OpenCode's
official documentation specifies `.opencode/commands/` (plural). This aligns
with every other adapter in the codebase. Legacy cleanup updated to detect
old singular-path artifacts. Fixes Fission-AI#748.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fsilvaortiz fsilvaortiz requested a review from TabishB as a code owner February 25, 2026 19:04
@greptile-apps
Copy link

greptile-apps bot commented Feb 25, 2026

Greptile Summary

This PR corrects the OpenCode adapter to use the plural .opencode/commands/ directory path instead of the singular .opencode/command/, aligning with OpenCode's official convention and matching the pattern used by all other adapters in the codebase.

Key changes:

  • Adapter path corrected in src/core/command-generation/adapters/opencode.ts (line 20)
  • Legacy cleanup updated to detect old singular-path artifacts at .opencode/command/opsx-*.md
  • Documentation and tests updated to reflect the new path
  • Comprehensive spec-driven change documentation included

Quality notes:

  • The legacy cleanup pattern correctly uses opsx-*.md (not openspec-*.md) since OpenCode adapter always used the opsx- prefix from its introduction
  • All 82 adapter tests pass according to the PR description
  • Change follows established patterns across the codebase (all other adapters use plural directory names)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Simple path correction with comprehensive test coverage and documentation. The change is a straightforward string replacement that aligns with established conventions. Legacy cleanup properly handles backward compatibility.
  • No files require special attention

Important Files Changed

Filename Overview
src/core/command-generation/adapters/opencode.ts Changed path from .opencode/command/ to .opencode/commands/ (plural) to match OpenCode convention
src/core/legacy-cleanup.ts Updated legacy pattern to detect old singular-path artifacts with opsx-*.md prefix
test/core/command-generation/adapters.test.ts Updated test assertion to match new plural commands/ directory path
docs/supported-tools.md Updated documentation table to reflect corrected .opencode/commands/ path

Last reviewed commit: c58d3c8


#### Scenario: Detect old singular-path OpenCode command files

- **WHEN** running legacy artifact detection on a project with files matching `.opencode/command/openspec-*.md` or `.opencode/command/opsx-*.md`
Copy link
Contributor

Choose a reason for hiding this comment

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

This scenario says we detect both openspec-* and opsx-* in .opencode/command/, but the implementation currently only has opsx-*. Can we align code and spec here so behavior is clear?

Copy link
Author

Choose a reason for hiding this comment

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

Aligned — LegacySlashCommandPattern.pattern now accepts string | string[], and the opencode entry uses both patterns: ['.opencode/command/opsx-*.md', '.opencode/command/openspec-*.md']. Added 6 tests covering detection and tool ID mapping for both prefixes.

'auggie': { type: 'files', pattern: '.augment/commands/openspec-*.md' },
'factory': { type: 'files', pattern: '.factory/commands/openspec-*.md' },
'opencode': { type: 'files', pattern: '.opencode/command/openspec-*.md' },
'opencode': { type: 'files', pattern: '.opencode/command/opsx-*.md' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice fix on the directory rename. One compatibility gap: this only matches .opencode/command/opsx-*.md. Some older installs may still have .opencode/command/openspec-*.md. Can we detect both so those users are migrated too?

Copy link
Author

Choose a reason for hiding this comment

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

Done — same change as above. The opencode entry now detects both opsx-*.md and openspec-*.md in .opencode/command/. Both patterns map to the opencode tool ID, so legacy cleanup and tool re-detection work for either prefix. Verified with detectLegacyArtifacts and getToolsFromLegacyArtifacts.


#### Scenario: Clean up old OpenCode command files on init

- **WHEN** a user runs `openspec init` in a project with old `.opencode/command/` artifacts
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also account for non-interactive openspec init here? Right now legacy artifacts cause init to exit unless --force is set. That could surprise existing /command users in CI. Either auto-handle this rename migration or call out the one-time --force requirement in release notes.

Copy link
Author

Choose a reason for hiding this comment

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

Good call — handleLegacyCleanup now auto-cleans in non-interactive mode instead of aborting with exit 1. Legacy slash commands are 100% OpenSpec-managed, and config file cleanup only removes markers (never deletes files), so auto-cleanup is safe without --force.

Added a test verifying that openspec init --tools opencode in non-interactive mode cleans up .opencode/command/ legacy files and generates new ones at .opencode/commands/. Spec updated with the new scenario.

… in CI

- Extend LegacySlashCommandPattern.pattern to accept string | string[]
- OpenCode legacy entry now detects both opsx-*.md and openspec-*.md
- Auto-cleanup legacy artifacts in non-interactive mode instead of
  aborting with exit 1 (safe: slash commands are OpenSpec-managed,
  config cleanup only removes markers)
- Add 7 tests (6 legacy detection + 1 non-interactive init)
- Update spec with array pattern support and auto-cleanup scenario

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 2026

📝 Walkthrough

Walkthrough

Updates the OpenCode adapter to use the directory path .opencode/commands/ (plural) instead of .opencode/command/ (singular) to align with OpenCode's official convention. Implements backward compatibility through legacy cleanup logic that recognizes the old singular path, updated tests, documentation, and supporting specification documentation.

Changes

Cohort / File(s) Summary
Changeset & Documentation
.changeset/fix-opencode-commands-directory.md, docs/supported-tools.md
Adds changeset entry for patch release and updates documentation to reflect the plural commands directory path .opencode/commands/opsx-<id>.md.
OpenCode Adapter
src/core/command-generation/adapters/opencode.ts
Changes getFilePath to return paths under .opencode/commands/ instead of .opencode/command/.
Legacy Cleanup & Initialization
src/core/legacy-cleanup.ts, src/core/init.ts
Extends LegacySlashCommandPattern to support multiple patterns (string | string[]), updates LEGACY_SLASH_COMMAND_PATHS for OpenCode, and enables automatic cleanup in non-interactive mode without requiring --force flag.
Adapter Tests
test/core/command-generation/adapters.test.ts
Updates test assertion to verify getFilePath returns the new plural path .opencode/commands/opsx-explore.md.
Legacy Cleanup & Init Tests
test/core/init.test.ts, test/core/legacy-cleanup.test.ts
Adds comprehensive tests for legacy artifact detection and cleanup of both opsx-* and openspec-* files in the old singular .opencode/command/ directory, including deduplication scenarios.
OpenSpec Specifications
openspec/changes/fix-opencode-commands-directory/*
Adds change documentation including design, proposal, specification, and task documentation detailing the path migration, backward-compatibility approach, and implementation details.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • TabishB

Poem

🐰 From command to commands, we hop along,
Where directories now plural, where standards belong,
Old paths fade gently into the past,
While new .opencode/commands/ arrive at last,
A backward-compatible leap, forward at last! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: switching OpenCode adapter from singular 'command/' to plural 'commands/' directory to match OpenCode convention.
Linked Issues check ✅ Passed All code requirements from issue #748 are met: adapter path changed from .opencode/command/ to .opencode/commands/, legacy cleanup detects old singular artifacts, documentation updated, tests adjusted, ensuring alignment with OpenCode standard.
Out of Scope Changes check ✅ Passed All changes are directly related to the issue #748 objective. The PR updates adapter paths, legacy cleanup detection, documentation, and tests—all scoped to the OpenCode directory naming convention fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
openspec/changes/fix-opencode-commands-directory/tasks.md (1)

7-7: Minor discrepancy: Task description doesn't fully reflect the implementation.

The task description says to change the pattern from openspec-*.md to opsx-*.md, but the actual implementation in src/core/legacy-cleanup.ts supports both patterns as an array: ['.opencode/command/opsx-*.md', '.opencode/command/openspec-*.md'].

Consider updating this task description to accurately reflect that both legacy prefixes are now supported:

-- [x] 2.1 Update `src/core/legacy-cleanup.ts`: change the `'opencode'` entry in `LEGACY_SLASH_COMMAND_PATHS` from `'.opencode/command/openspec-*.md'` to `'.opencode/command/opsx-*.md'` to detect old singular-path artifacts with the current `opsx-*` prefix
++ [x] 2.1 Update `src/core/legacy-cleanup.ts`: update the `'opencode'` entry in `LEGACY_SLASH_COMMAND_PATHS` to detect both `opsx-*.md` and `openspec-*.md` patterns at `.opencode/command/` for backward compatibility
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openspec/changes/fix-opencode-commands-directory/tasks.md` at line 7, Update
the task description in tasks.md to match the implementation: state that
LEGACY_SLASH_COMMAND_PATHS in src/core/legacy-cleanup.ts now supports both
legacy patterns (the opsx-* prefix and the openspec-* prefix) rather than only
replacing openspec-*.md with opsx-*.md, so reword the checklist item to
explicitly mention both opsx-* and openspec-* patterns are supported.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@openspec/changes/fix-opencode-commands-directory/tasks.md`:
- Line 7: Update the task description in tasks.md to match the implementation:
state that LEGACY_SLASH_COMMAND_PATHS in src/core/legacy-cleanup.ts now supports
both legacy patterns (the opsx-* prefix and the openspec-* prefix) rather than
only replacing openspec-*.md with opsx-*.md, so reword the checklist item to
explicitly mention both opsx-* and openspec-* patterns are supported.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7d1860 and f2ece90.

📒 Files selected for processing (13)
  • .changeset/fix-opencode-commands-directory.md
  • docs/supported-tools.md
  • openspec/changes/fix-opencode-commands-directory/.openspec.yaml
  • openspec/changes/fix-opencode-commands-directory/design.md
  • openspec/changes/fix-opencode-commands-directory/proposal.md
  • openspec/changes/fix-opencode-commands-directory/specs/command-generation/spec.md
  • openspec/changes/fix-opencode-commands-directory/tasks.md
  • src/core/command-generation/adapters/opencode.ts
  • src/core/init.ts
  • src/core/legacy-cleanup.ts
  • test/core/command-generation/adapters.test.ts
  • test/core/init.test.ts
  • test/core/legacy-cleanup.test.ts

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.

OpenCode command directory: command/ vs commands/

2 participants