Skip to content

fix: forward model variants to opencode prompt body#15

Open
AveryanAlex wants to merge 2 commits into
AlaeddineMessadi:mainfrom
AveryanAlex:fix/forward-variant-to-prompt-body
Open

fix: forward model variants to opencode prompt body#15
AveryanAlex wants to merge 2 commits into
AlaeddineMessadi:mainfrom
AveryanAlex:fix/forward-variant-to-prompt-body

Conversation

@AveryanAlex

@AveryanAlex AveryanAlex commented Jun 12, 2026

Copy link
Copy Markdown

Summary

  • Send OpenCode variant as a top-level prompt/command body field instead of nesting it under model.
  • Keep model payloads limited to { providerID, modelID } so OpenCode can apply the requested variant/effort correctly.
  • Add regression coverage for opencode_ask, opencode_reply, and opencode_message_send.

Why

OpenCode's session prompt API accepts variant next to model, not inside model. Nesting it under model causes model selection to work while the requested variant is ignored and the agent/default variant is used instead.

Verification

  • npm run build
  • npm test
  • git diff --check

Summary by CodeRabbit

  • Refactor

    • Simplified model-default logic and return shape used by tools.
    • Variant is now handled as a top-level request field (not nested), and the shell execution tool no longer exposes a variant option.
  • Tests

    • Added/updated tests to verify schema exposure and top-level variant handling for ask, reply, and message send tools.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7309b82a-3815-4914-8e3c-0bc2fb417edd

📥 Commits

Reviewing files that changed from the base of the PR and between 86bffee and 0396c46.

📒 Files selected for processing (2)
  • src/tools/message.ts
  • tests/tools.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tools/message.ts

📝 Walkthrough

Walkthrough

This PR removes variant from the applyModelDefaults signature/return and updates message/workflow tools to set body.model from the simplified helper result while applying variant directly to request bodies; tests and the tool-registration mock are updated to reflect the new shape.

Changes

Variant Parameter Refactoring

Layer / File(s) Summary
Helper function contract simplification
src/helpers.ts
applyModelDefaults signature and return type now exclude variant, returning only `{ providerID, modelID }
Message & command tools update
src/tools/message.ts
Message, async-message, command, and shell handlers call applyModelDefaults(providerID, modelID) to set body.model; variant is assigned separately when present (shell no longer accepts variant).
Workflow tools update
src/tools/workflow.ts
opencode_ask, opencode_reply, opencode_run, opencode_fire, and opencode_provider_test use the simplified helper for body.model and apply variant at the top level; provider-test conditionally sets body.model or body.providerID.
Test updates and schema capture
tests/tools.test.ts
Tool-capture mock stores schemas; new tests assert opencode_shell_execute schema lacks variant and that variant is sent as a top-level field (not nested in model) for multiple tools.

🎯 3 (Moderate) | ⏱️ ~20 minutes

"I hopped through code with a careful twitch,
Pulled variant out of the helper stitch,
Now models sit tidy, variants stand tall,
Top-level and proud — a clean payload for all. 🐇"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: moving the model variant parameter to the top level of the prompt body instead of nesting it, which is the core objective of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/tools/message.ts (1)

231-239: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

opencode_shell_execute drops variant from the request body

Line 234 accepts variant, but the body built around Line 236-Line 239 never forwards it. This causes shell requests to ignore the requested variant while other updated tools now send it correctly.

Proposed fix
         const body: Record<string, unknown> = { command, agent };
         const shellModel = applyModelDefaults(providerID, modelID);
         if (shellModel) body.model = shellModel;
+        if (variant) body.variant = variant;
         const result = await client.post(
           `/session/${sessionId}/shell`,
           body,
           { directory },
         );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tools/message.ts` around lines 231 - 239, The opencode_shell_execute
handler accepts variant but never forwards it in the request body; update the
async handler (the anonymous function receiving { sessionId, command, agent,
providerID, modelID, variant, directory }) to add variant to the constructed
body when present (e.g., body.variant = variant or include within body.model if
your API expects it), so that applyModelDefaults(providerID, modelID), the body
object, and the subsequent client.post call carry the variant through to the
backend; ensure the field name matches what the server expects and keep the
conditional (only set variant when defined).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/tools/message.ts`:
- Around line 231-239: The opencode_shell_execute handler accepts variant but
never forwards it in the request body; update the async handler (the anonymous
function receiving { sessionId, command, agent, providerID, modelID, variant,
directory }) to add variant to the constructed body when present (e.g.,
body.variant = variant or include within body.model if your API expects it), so
that applyModelDefaults(providerID, modelID), the body object, and the
subsequent client.post call carry the variant through to the backend; ensure the
field name matches what the server expects and keep the conditional (only set
variant when defined).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f832f78f-a49c-4a4a-8890-6aae44902c7b

📥 Commits

Reviewing files that changed from the base of the PR and between 4e4db4c and 86bffee.

📒 Files selected for processing (4)
  • src/helpers.ts
  • src/tools/message.ts
  • src/tools/workflow.ts
  • tests/tools.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.

1 participant