Skip to content

fix(opencode): make generated rules discoverable across direct generation and CLI #913

Closed

Description

@blafourcade

Summary: OpenCode does not natively discover .opencode/rules/. Direct generation and CLI installation can therefore report success while leaving a rule outside OpenCode's instruction context. Use one config-backed rule contract across aidd-context and the CLI; keep flat archive emission in #789.

Expected behavior

A rule generated or installed for OpenCode is present in OpenCode's instruction context without requiring the user to move files, duplicate content into AGENTS.md, or repair configuration manually.

User-owned configuration, including JSONC comments, must not be silently destroyed.

Actual behavior

  • plugins/aidd-context/skills/05-rule-generate/references/tool-paths.md labels .opencode/rules//.md as natively supported.
  • OpenCode does not auto-discover a rules directory.
  • plugins/aidd-context/skills/11-explore/references/ai-mapping.md contradicts the generator and says OpenCode rules are not supported and should be folded into AGENTS.md.
  • The CLI writes OpenCode rules under .opencode/rules/ and its bundled config references .opencode/rules//*.md**, but this config-backed dependency is not expressed as the shared capability contract.
  • The current CLI JSONC merge strips comments before serializing the whole document with JSON.stringify. It preserves parsed values, not the user's comments or original representation.

The result is a silent failure: a generated rule can exist on disk while OpenCode never loads it.

Reproduction

  1. Start in a project detected as OpenCode through .opencode/, with no opencode.json or opencode.jsonc.
  2. Run the direct rule generator for OpenCode.
  3. Observe a successful write under .opencode/rules/.
  4. Start OpenCode.
  5. Observe that the generated rule is absent from the instruction context because no instructions entry references it.

Official OpenCode contract

Verified on 2026-09-24.

Decision

Use one config-backed OpenCode rule contract:

  1. Store modular rules at .opencode/rules//.md.
  2. For direct generation, append the exact generated relative path to the active project configuration's instructions array.
  3. For CLI installation or synchronization, ensure every installed rule is covered by an idempotent instructions entry. A CLI-managed relative glob may be used when runtime-tested.
  4. Treat AGENTS.md as OpenCode's native project-memory surface, not as the default destination for generated modular rules.
  5. Describe .opencode/rules/ everywhere as config-backed, never native.
  6. Preserve existing instructions entries, duplicates, and order; append each AIDD-owned entry once.
  7. Preserve JSONC comments and unrelated formatting when safely updating instructions. If a safe edit cannot be made, stop with an actionable error before writing instead of normalizing or overwriting the file.
  8. If both opencode.json and opencode.jsonc exist, retain the CLI's explicit dual-config refusal. If neither exists, create opencode.json.

Scope

aidd-context

  • Correct the rule-generator path contract and the contradictory exploration mapping.
  • Detect OpenCode from .opencode/, opencode.json, or opencode.jsonc.
  • Generate the modular Markdown rule.
  • Wire its exact relative path into instructions.
  • Keep generation idempotent and preserve user-owned configuration.

CLI

  • Model OpenCode rules as config-backed rather than natively directory-discovered.
  • Make the OpenCode install/sync path use the same safe instructions updater as direct generation.
  • Keep the existing rule location and bundled configuration compatible.
  • Add a JSONC-aware update path; the existing stripJsonComments plus JSON.stringify rewrite is not sufficient when editing a user-owned JSONC file.
  • Ensure CLI output and documentation never imply that writing .opencode/rules/ alone makes a rule discoverable.

Shared verification

  • Prove that generated and CLI-installed rules reach OpenCode's resolved instruction context.
  • Cover JSON, JSONC, missing config, duplicate entries, dual config, re-run, invalid config, and supported platforms.
  • Keep the official source URL and verification date beside the path contract.

Acceptance criteria

  • No source, help output, or generated documentation calls .opencode/rules/ a native OpenCode surface.
  • Direct generation writes .opencode/rules//.md and appends that exact relative path to instructions.
  • CLI installation/synchronization uses the same config-backed contract.
  • Existing instructions entries, duplicates, and order survive unchanged; the AIDD-owned entry appears once.
  • Existing JSONC comments and unrelated formatting survive an instructions update.
  • Invalid or ambiguous configuration produces an actionable error and no partial write.
  • Re-running direct generation or CLI installation changes nothing.
  • Tests cover discovery through .opencode/, opencode.json, and opencode.jsonc.
  • Tests cover JSON, commented JSONC with trailing commas, no config, both config files, invalid config, and an already-wired rule.
  • A runtime-level test proves the generated rule is present in OpenCode's resolved instructions; any retained recursive glob is exercised on every supported OS.
  • The official source URL and verification date are present in the canonical path reference.

Repository evidence

  • Wrong native claim: plugins/aidd-context/skills/05-rule-generate/references/tool-paths.md
  • Contradictory exploration contract: plugins/aidd-context/skills/11-explore/references/ai-mapping.md
  • CLI OpenCode capability: cli/src/contexts/tools/domain/profiles/opencode/profile.ts
  • Bundled instruction glob: cli/assets/configs/opencode/opencode.json
  • Current parsed-value merge and JSONC normalization: cli/src/contexts/tools/domain/formats/opencode-mcp-merge.ts
  • Existing merge coverage: cli/tests/contexts/tools/domain/formats/opencode-mcp-merge.unit.test.ts

Relations and boundaries

Activity

  1. added theissue type on Sep 23, 2026
  2. moved this from Ideation to Todo in AIDD Roadmapon Sep 23, 2026
  3. changed the title [-]fix(aidd-context): wire generated OpenCode rules into supported instruction surfaces[/-] [+]fix(opencode): make generated rules discoverable across direct generation and CLI[/+] on Sep 24, 2026
  4. moved this from Todo to In Progress in AIDD Roadmapon Oct 8, 2026
  5. moved this from In review to In Progress in AIDD Roadmapon Oct 9, 2026
  6. blafourcade commented on Oct 12, 2026

    @blafourcade
    ContributorAuthor

    Closed by #1009, with #979 before it.

    Rule generation writes OpenCode rules into the root AGENTS.md, which every OpenCode version reads (https://opencode.ai/docs/rules/). The contract now says: "OpenCode: write the root AGENTS.md only, never .opencode/rules". No opencode.json is touched, so user JSONC is never at risk.

    This rests on OpenCode's documentation; no OpenCode 1.x session has been run against a generated rule.

  7. moved this from Done to In review in AIDD Roadmapon Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    None yet

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions