Skip to content

fix(opencode2): support stable 2.0.x without ctx.catalog - #24

Merged
oakimov merged 7 commits into
oakimov:mainfrom
ebysofyan:fix/oc2-stable-no-catalog-compat
Sep 18, 2026
Merged

oakimov merged 7 commits into
oakimov:mainfrom
ebysofyan:fix/oc2-stable-no-catalog-compat

Conversation

@ebysofyan

Copy link
Copy Markdown
Contributor

Summary

  • Fixes crash on OpenCode 2.0 stable (2.0.5 / 2.0.6) where ctx.catalog is absent (ctx.catalog.transform undefined).
  • Keeps the existing beta path when ctx.catalog.transform is present.
  • Stable fallback: sync discovered Cursor models into providers.cursor in $OPENCODE_CONFIG_DIR/opencode.json(c) so auth, AI SDK hooks, and the model picker work.
  • Classic OpenCode 1.x plugin entries (plugin / plugin/v2) unchanged.

Fixes #23

Test plan

  • On OpenCode stable 2.0.5+: load OC2 plugin entry → no setup crash
  • Cursor auth succeeds; models appear in picker after discovery
  • On OpenCode beta (with ctx.catalog): catalog transform path still used; no regression
  • npm test — test/config-catalog.test.ts passes
  • OC1 install path still works with "plugin": ["cursor-opencode-provider"]

Stable OpenCode 2.0 omits the unified catalog domain that the beta plugin
required, so setup crashed on ctx.catalog.transform. Detect catalog when
present (beta path unchanged) and otherwise sync discovered models into
providers.cursor in OPENCODE_CONFIG_DIR so auth, aisdk hooks, and the
model picker work on 2.0.5/2.0.6. Classic OC1 plugin entrypoints untouched.
Restore oakimov/cursor-opencode-provider repository/bugs/homepage so the
contribution PR does not retarget package metadata to the fork.

@oakimov oakimov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the clear issue + fix direction — detecting ctx.catalog and keeping the beta transform path is the right shape. Requesting changes before merge: stable support must not regress safety or thin out functionality relative to the beta catalog path.

Required for merge

  1. No config destruction / silent decline in config handling

    • On parse failure, do not fall back to {} and rewrite the file (that can wipe a user’s opencode.json(c) down to only providers.cursor).
    • Do not strip JSONC comments / reformat the whole document as a side effect of model sync.
    • Fail closed (skip write) or surgically update only the Cursor provider block with a real JSONC-preserving approach.
  2. No functionality decline vs beta catalog models

    • Stable providers.cursor entries must carry the same model metadata as applyCursorModels / applyModelEntry (at least variants, cost, limits/modalities, settings/wire id) — not a reduced picker-only subset.
    • Prefer sharing one translation helper so beta and stable cannot drift.
  3. Drop the 0.6.8 → 0.6.9 bump from this PR (release/version is maintainer-owned).

  4. README: remove “fork compat” framing; document upstream OC2 stable vs beta dual-path clearly.

Also missing / strengthen

  • Tests for: hasCatalogDomain; parse-failure does not write; idempotent sync; parity assertions that synced models match catalog-shaped fields (variants/cost).
  • Confirm default config dir / OPENCODE_CONFIG_DIR behavior matches how stable OC2 is actually run (docs mention opencode2 layouts).
  • Keep classic OC1 + beta catalog behavior byte-for-byte unchanged (no accidental optional-domain fallthrough that skips registration when catalog is present).

Happy to re-review once stable is a true fallback with equal model surface and non-destructive config updates.

Comment thread src/opencode2/config-catalog.ts Resolved
Comment thread src/opencode2/config-catalog.ts Resolved
Comment thread package.json Resolved
Comment thread README.md Resolved
Surgical jsonc-parser upsert preserves comments/unrelated keys and fails
closed on parse errors. Shared model translator keeps full Cursor metadata
parity; drop 0.6.9 bump; document stable vs beta dual-path in README.
@ebysofyan

Copy link
Copy Markdown
Contributor Author

Hey, thanks for the review — really helpful. I pushed 6cb48c5 with the follow-up fixes.

  • Config sync uses jsonc-parser and fails closed on parse errors.
  • Updates only the managed Cursor fields, preserving unrelated config, provider-level options, comments, and legacy OC1 Cursor data.
  • Stable cache seeding and model discovery now reload the provider before the model picker. Reload failures remain retryable.
  • Stable and beta still share the same model translation, including variants, cost, limits, modalities, wire IDs, and settings.
  • No version bump; the package remains at 0.6.8.
  • README wording and anchors now document the stable/beta dual path clearly.
  • Added coverage for JSONC preservation, legacy config compatibility, parity, idempotence, reload ordering, retry behavior, and stable plugin setup.

The focused PR suite is green: 77 tests passed. Build, typecheck, and diff checks also pass. The remaining five full-suite failures reproduce on the original base commit and are unrelated request-context/MCP tests.

The branch is pushed and ready for re-review. Happy to adjust anything else you find.

Document plugin directories, dedicated OPENCODE_CONFIG_DIR, and
released:0 picker sorting; include id/providerID on catalog model
info for stable/beta parity.
@oakimov

oakimov commented Sep 18, 2026

Copy link
Copy Markdown
Owner

Follow-up polish (c2f2052)

  • Docs: stable host range 2.0.5+ (incl. 2.0.8); dedicated OPENCODE_CONFIG_DIR; plugins directory layout (not bare .js); plugin key; service set env; OC2 empty-picker troubleshooting; note time.released: 0 sorts Cursor models last.
  • Catalog parity: CatalogModelInfo now carries id + providerID (stable config sync matches beta).
  • AGENTS / host-compat checklist aligned with the stable+beta dual path.

Skip foreign providers.cursor identities, resolve config via OPENCODE_CONFIG_DIR
then the host path bridge, retry after parse failures, and write configs atomically.
Lead the install docs with 2.0.5+ providers.cursor sync; keep ctx.catalog
as a dev/next host surface instead of calling the product beta.
@oakimov

oakimov commented Sep 18, 2026

Copy link
Copy Markdown
Owner

Follow-up (101ee31, fd9dda0)

Stable sync hardening

  • Skip providers.cursor when another package/integrationID already owns it (legacy provider.cursor is not treated as owner).
  • Resolve config via $OPENCODE_CONFIG_DIR, then the host path bridge, then native ~/.config/opencode. Prefer existing opencode.json over .jsonc when both exist.
  • Parse failures fail closed and stay retryable (no longer counted as a successful publish).
  • Config writes are atomic (temp file + rename).

Docs

  • OpenCode 2.0 is documented as stable (2.0.5+), not beta. ctx.catalog is a dev/next host surface only.

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 2.0 stable (2.0.5+): plugin crashes — ctx.catalog missing

2 participants