If you've used cursor chat or agent you've probably seen that it's very precise with changes in some files. Have you wondered how does the LLM figure out the exact file and line to change, and how does the IDE very well integrated with it?
I was pleasantly surprised by the simplicity of this approach. While working on a hiring task a few days back, which asked me to make an extension which behaves like Cursor chat, I found this part to be quite difficult. I tried asking it to output diffs, JSON, etc - but nothing worked reliably.
Classic Occam's Razor moment!
The trick here is in the system prompt. I tried to extract the prompt to figure out how they do it, and here's what I found.
Majorly, it's these 3 things -
Markdown responses
Specifying language ids in code blocks
Providing absolute paths to files, along with line numbers
Tool calls for the model to utilise tools like searching files
Examples:
Use the exact format ```startLine:endLine:filepath``` for code citations.
This is the ONLY acceptable format for code citations. The format is ```startLine:endLine:filepath``` where startLine and endLine are line numbers.
I specify language IDs in code blocks:
```python
code here
```
For existing files, I specify file paths and restate methods/classes:
```language:path/to/file
function example() {
// code here
}
```
Have you tried out prompt injection? Let me know in the comments. If you liked this please love <3
Join Siddhartha on Peerlist!
Join amazing folks like Siddhartha and thousands of other people in tech.
Create ProfileJoin with Siddhartha’s personal invite link.
0
6
0