rulesync icon indicating copy to clipboard operation
rulesync copied to clipboard

[Feature request] Support importing agents and commands from `opencode.json`

Open r1bilski opened this issue 9 months ago • 4 comments

Opencode allow defining commands and agents both in markdown files (.opencode/agents/<agent>.md, .opencode/commands/<command>.md) and in opencode.json.

https://opencode.ai/docs/agents/#json https://opencode.ai/docs/commands/#json

Currently, rulesync will not import these configurations from opencode.json

Feature request

Read opencode.json for agent and command configurations and import them.

r1bilski avatar Feb 10 '26 17:02 r1bilski

@r1bilski Thank you. This bothers me a little. I don't think many people will suffer from this. However, well, I think it can be supported.

dyoshikawa avatar Feb 11 '26 14:02 dyoshikawa

The projects I work in often have most things in the opencode.jsonc file directly, just because that makes it easier to share / copy.

r1bilski avatar Feb 11 '26 15:02 r1bilski

@r1bilski I am positive to your suggestion.

cm-dyoshikawa avatar Feb 13 '26 00:02 cm-dyoshikawa

Confirmed this is still a real gap (June 2026): rulesync imports OpenCode agents/commands only from Markdown files — OpenCodeCommand.fromFile reads .opencode/command/*.md and OpenCodeSubagent.fromFile reads .opencode/agent/*.md. The JSON-embedded forms documented at https://opencode.ai/docs/commands/#json (top-level command key) and https://opencode.ai/docs/agents/#json (top-level agent key) are not imported. Only MCP, permissions, and rules instructions currently read opencode.json/opencode.jsonc.

Implementation outline for whoever picks this up:

  • Read opencode.jsonc then opencode.json (mirroring OpencodeMcp.fromInstructions in src/features/mcp/opencode-mcp.ts), and synthesize a RulesyncCommand/RulesyncSubagent per entry under the command/agent keys.
  • Field mapping: command template → rulesync body; description/agent/model/subtask → frontmatter (already in OpenCodeCommandFrontmatterSchema). Agent JSON fields (mode/model/prompt/permission/...) already align with OpenCodeSubagentFrontmatterSchema.
  • Open design point worth deciding before implementation: the generic commands/subagents loadToolFiles discovers one file → one entry by globbing a directory (src/features/commands/commands-processor.ts), so importing many entries embedded in a single opencode.json needs a discovery hook (or an opencode-specific load path). Also decide how to handle a prompt: { file: ... } reference (inline vs. keep).

Leaving open for a maintainer call on the discovery-hook approach, since it touches the shared import flow rather than being a self-contained adapter.

dyoshikawa avatar Jun 23 '26 16:06 dyoshikawa