Skip to content

fix: strengthen default Apply prompt for local models#10486

Merged
RomneyDa merged 1 commit intocontinuedev:mainfrom
shanevcantwell:fix/apply-prompt-local-models
Mar 20, 2026
Merged

fix: strengthen default Apply prompt for local models#10486
RomneyDa merged 1 commit intocontinuedev:mainfrom
shanevcantwell:fix/apply-prompt-local-models

Conversation

@shanevcantwell
Copy link
Contributor

@shanevcantwell shanevcantwell commented Feb 13, 2026

Summary

  • Local/open-weight models respond to the default Apply prompt with prose summaries of changes instead of actual code, because defaultApplyPrompt returns a single-sentence plain string with no code-only constraint
  • Change defaultApplyPrompt to return ChatMessage[] with labeled ORIGINAL CODE / SUGGESTED EDIT sections, explicit "Output ONLY code" instructions, and an assistant prefill opening a code block
  • This routes through streamChat (instead of streamComplete), and the assistant prefill forces the model to continue with code rather than prose
  • The existing filterCodeBlockLines filter strips the closing fence from the output

Context

defaultApplyPrompt is the fallback Apply prompt used when no model-specific promptTemplates.apply is configured. It applies when a model calls edit_existing_file and the Apply step merges the suggested code into the original file.

The previous prompt was:

{original_code}\n\nThe following code was suggested as an edit:\n```\n{new_code}\n```\nPlease apply it to the previous code.

Local models (tested with gpt-oss-20b via LM Studio) interpreted this as a request to describe changes rather than output code. The new prompt with explicit rules and assistant prefill produces clean code diffs.

What this doesn't change

  • Claude Sonnet lazy-apply path (separate code path in core/edit/lazy/)
  • GPT/Claude edit prompts (gptEditPrompt, not defaultApplyPrompt)
  • Users with custom promptTemplates.apply in config (custom overrides defaultApplyPrompt)

Test plan

  • cd core && npm run vitest — 1654 tests pass, 0 failures
  • Tested with gpt-oss-20b (local model via LM Studio) — Apply produces code diffs instead of prose summaries
  • Verify cloud model Apply still works (they typically use model-specific prompts, not defaultApplyPrompt)

🤖 Generated with Claude Code


Summary by cubic

Make the default Apply prompt produce code (not prose) for local/open‑weight models by switching to a chat-based prompt with code-only instructions and an assistant prefill. Apply now routes through streamChat and returns the full modified file.

  • Bug Fixes
    • defaultApplyPrompt now returns ChatMessage[] with ORIGINAL CODE / SUGGESTED EDIT blocks and “output ONLY code” instructions.
    • Assistant prefill opens a code block to force code continuation; existing filter removes the closing fence.
    • No changes to model-specific prompts, lazy-apply path, or user overrides.

Written for commit 25026d7. Summary will update on new commits.

Local models respond to the existing single-sentence Apply prompt with
prose summaries instead of code. Return ChatMessage[] with explicit
code-only instructions and assistant prefill to force code output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shanevcantwell shanevcantwell requested a review from a team as a code owner February 13, 2026 05:23
@shanevcantwell shanevcantwell requested review from RomneyDa and removed request for a team February 13, 2026 05:23
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 13, 2026
Copy link
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 1 file

Copy link
Collaborator

@RomneyDa RomneyDa left a comment

Choose a reason for hiding this comment

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

@shanevcantwell just to double check any reason the new apply prompt is now messages instead of the raw text?

@shanevcantwell
Copy link
Contributor Author

The messages format lets us include an assistant prefill: the role: "assistant" message that opens with a code fence. Without it, local models (Ollama, LM Studio, etc.) tend to respond to the raw text prompt with prose like "Sure! Here's the modified code:" before the actual code, which breaks the diff parser.

The assistant prefill locks the model into continuing inside a code fence, so the output is code-only. This pattern already exists in the lazy apply prompt (core/edit/lazy/prompts.ts) for the same reason.

The fallback path in renderPromptTemplate handles providers that don't support prefill. It compiles the messages down to a completion prompt instead (canPutWordsInModelsMouth check in core/llm/index.ts).

@RomneyDa RomneyDa closed this Mar 19, 2026
@github-project-automation github-project-automation bot moved this from Todo to Done in Issues and PRs Mar 19, 2026
@RomneyDa RomneyDa reopened this Mar 19, 2026
@github-project-automation github-project-automation bot moved this from Done to In Progress in Issues and PRs Mar 19, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Mar 19, 2026
Copy link
Collaborator

@RomneyDa RomneyDa left a comment

Choose a reason for hiding this comment

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

@shanevcantwell appreciate the explanation! Looks good to me.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 20, 2026
@RomneyDa RomneyDa merged commit f1a2fbf into continuedev:main Mar 20, 2026
96 of 103 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants