Skip to main content

Intelligent update

This tool updates files by rewriting them from scratch based on provided instructions. It's particularly useful for applying partial code changes or fixing malformed diffs.

✓ Regenerates whole files in concurrent API calls
✓ Smaller models like Gemini Flash are sufficient
✓ Can fix malformed diff patches

When is it used?

Intelligent Update is automatically used in a few scenarios:

  1. Applying truncated chat responses: When you ask the chatbot for code changes and it responds with a partial file (using // ... to omit unchanged parts), CWC uses this tool to apply the changes. It sends the original file content along with the chatbot's partial response to the model and asks it to generate the complete, updated file.

  2. Fixing failed patches: When applying a response formatted as a diff patch, if the built-in programmatic fallback to git apply command fails, CWC will use Intelligent Update as a last resort. It sends the original file and the failed patch to the model, asking it to correctly apply the changes and generate the full new file.

  3. Manual trigger: After applying changes via "Fast replace", if the result isn't what you expected (e.g. AI generated code missed truncation comments // ...), you can click the "Looks off, use intelligent update" button in the notification. This reverts the previous change and re-applies it using the more robust Intelligent Update method.

API message structure

For each file to be updated, a separate API call is made. The prompt contains the full original content of the file, followed by instructions to rewrite it based on the changes from the chat response. The model is expected to return the complete, updated file content inside a markdown code block.

<file></file> // full original content of the file
User requested refactor of a file. Please show me the full code of the updated <file>, without explanations or any other text. I have a disability which means I can't type and need to be able to copy and paste the full code.
[CODE_CHANGES_FROM_CHAT_RESPONSE]