Skip to content

Feat: Decouple Model Definitions using Host config Hook#4

Open
dragon-Elec wants to merge 2 commits into
cortexkit:mainfrom
dragon-Elec:main
Open

Feat: Decouple Model Definitions using Host config Hook#4
dragon-Elec wants to merge 2 commits into
cortexkit:mainfrom
dragon-Elec:main

Conversation

@dragon-Elec

@dragon-Elec dragon-Elec commented Jun 20, 2026

Copy link
Copy Markdown

Feat: Decouple Model Definitions using Host config Hook

This PR implements a solution to decouple model definitions from the user's primary opencode.json configuration file, reducing configuration bloat and resolving maintenance issues discussed in #134.

The Hook Mechanism

By targeting OpenCode's runtime config lifecycle hook, which executes prior to provider validation and client instantiation, the plugin dynamically injects model catalogs directly into OpenCode's configuration memory.

This enables:

  1. Zero-configuration setups: model updates are registered automatically on plugin updates.
  2. Separation of concerns: user-level overrides or custom configurations are kept out of opencode.json.

What's Changed

  • Multi-Source Model Resolution: Added support for reading custom model declarations from:
    • ~/.config/opencode/antigravity-models.json(c)
    • .opencode/antigravity-models.json(c)
    • The models mapping block in antigravity.json.
  • Precedence-Aware Merging (Backwards Compatible): We enforce a priority order:
    Built-in defaults -> Decoupled JSON/JSONC overrides -> Main opencode.json overrides
    This ensures any existing model declarations inside opencode.json continue to override all other definitions, ensuring zero disruption for existing users.
  • Dynamic Whitelisting: The plugin no longer relies on a hardcoded array of whitelisted model IDs, instead compiling the whitelist dynamically from the keys of the final merged model dictionary.

Why Backwards Compatibility Matters (Fail-Safe Architecture)

Because OpenCode's config lifecycle hook is currently undocumented, there is a risk that a future upstream OpenCode release could deprecate or alter it.

To mitigate this, we maintain full backwards compatibility with static definitions in opencode.json:

  1. Fallback Path: If the hook is deprecated or disabled, users can fall back to pasting the model definitions into opencode.json (or using the opencode auth login model setup flow). OpenCode will parse them natively.
  2. Override Priority: By merging opencode.json definitions last, we guarantee that any static config file settings override the dynamic injection, leaving the user in complete control.

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Decouples model definitions from the main OpenCode config by injecting them during the host config hook. This reduces opencode.json bloat and enables zero‑config model updates.

  • New Features
    • Load decoupled model files from ~/.config/opencode/antigravity-models.json(c) and ./.opencode/antigravity-models.json(c) (JSON/JSONC supported).
    • Merge precedence: built‑ins → decoupled models → opencode.json overrides (backward compatible).
    • Inject merged models into the provider config and set whitelist to all merged model IDs.
    • Add optional models in the plugin config schema to carry injected definitions.

Written for commit fe739e8. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 3 files

Re-trigger cubic

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.

1 participant