changes + potentially fix error finding SEARCH block

This commit is contained in:
Andrew Pareles 2025-03-17 23:47:33 -07:00
parent 6bb0966eea
commit 5b3471a7d7
2 changed files with 52 additions and 17 deletions

View file

@ -25,7 +25,7 @@ import * as dom from '../../../../base/browser/dom.js';
import { Widget } from '../../../../base/browser/ui/widget.js';
import { URI } from '../../../../base/common/uri.js';
import { IConsistentEditorItemService, IConsistentItemService } from './helperServices/consistentItemService.js';
import { voidPrefixAndSuffix, ctrlKStream_userMessage, ctrlKStream_systemMessage, defaultQuickEditFimTags, rewriteCode_systemMessage, rewriteCode_userMessage, searchReplace_systemMessage, searchReplace_userMessage, } from '../common/prompt/prompts.js';
import { voidPrefixAndSuffix, ctrlKStream_userMessage, ctrlKStream_systemMessage, defaultQuickEditFimTags, rewriteCode_systemMessage, rewriteCode_userMessage, searchReplace_systemMessage, searchReplace_userMessage, FINAL, ORIGINAL, DIVIDER, tripleTick, } from '../common/prompt/prompts.js';
import { mountCtrlK } from './react/out/quick-edit-tsx/index.js'
import { mountVoidCommandBar } from './react/out/void-command-bar-tsx/index.js'
@ -1629,13 +1629,24 @@ class EditCodeService extends Disposable implements IEditCodeService {
}
const errHelper = (erroneousOriginal: string) => `All previous SEARCH/REPLACE blocks (if any) have been applied except the latest erroneous one. Please continue outputting SEARCH/REPLACE blocks. The ORIGINAL code with an error was: ${JSON.stringify(erroneousOriginal)}`
const errMsgOfInvalidStr = (str: string & ReturnType<typeof findTextInCode>, blockOrig: string) => {
return str === `Not found` ?
`The ORIGINAL code provided could not be found in the file. You should make sure the text in ORIGINAL matches lines of code EXACTLY. ${errHelper(blockOrig)}`
const errMsgOfInvalidStr = (str: string & ReturnType<typeof findTextInCode>, blockOrig: string, blockNum: number, blocks: ExtractedSearchReplaceBlock[]) => {
const descStr = str === `Not found` ?
`The most recent ORIGINAL code could not be found in the file, so you were interrupted. You should make sure the text in ORIGINAL matches lines of code EXACTLY. Erroneous ORIGINAL code:\n${JSON.stringify(blockOrig)}`
: str === `Not unique` ?
`The ORIGINAL code provided shows up multiple times in the file. We recommend making the ORIGINAL portion bigger so we can find a unique match. ${errHelper(blockOrig)}`
`The most recent ORIGINAL code shows up multiple times in the file, so you were interrupted. Please make the ORIGINAL excerpt bigger so it's unique. Erroneous ORIGINAL code:\n${JSON.stringify(blockOrig)}`
: ``
// string of <<<<< ORIGINAL >>>>> REPLACE blocks so far so LLM can understand what it currently has
const blocksSoFarStr = blocks.slice(0, blockNum).map(block => `${ORIGINAL}\n${block.orig}\n${DIVIDER}\n${block.final}\n${FINAL}`).join('\n')
const soFarStr = blocksSoFarStr ? `These are the Search/Replace blocks that have been applied so far:${tripleTick[0]}\n${blocksSoFarStr}\n${tripleTick[1]}` : ''
const continueMsg = soFarStr ? `${soFarStr}Please continue outputting SEARCH/REPLACE blocks starting where this leaves off.` : ''
const errMsg = `${descStr}${continueMsg ? `\n${continueMsg}` : ''}`
console.log('ERr msg:', errMsg)
return errMsg
}
@ -1729,7 +1740,7 @@ class EditCodeService extends Disposable implements IEditCodeService {
shouldUpdateOrigStreamStyle = true
// if this is the first time we're seeing this block, add it as a diffarea so we can start streaming
// if this is the first time we're seeing this block, add it as a diffarea so we can start streaming in it
if (!(blockNum in addedTrackingZoneOfBlockNum)) {
const originalBounds = findTextInCode(block.orig, originalFileCode)
// if error
@ -1738,7 +1749,7 @@ class EditCodeService extends Disposable implements IEditCodeService {
console.log('fullText', { fullText })
console.log('error:', originalBounds)
console.log('block.orig:', block.orig)
const content = errMsgOfInvalidStr(originalBounds, block.orig)
const content = errMsgOfInvalidStr(originalBounds, block.orig, blockNum, blocks)
messages.push(
{ role: 'assistant', content: fullText, anthropicReasoning: null }, // latest output
{ role: 'user', content: content } // user explanation of what's wrong
@ -1746,11 +1757,30 @@ class EditCodeService extends Disposable implements IEditCodeService {
// REVERT THIS ONE BLOCK
// TODO!!! test this
latestStreamLocationMutable = null
shouldUpdateOrigStreamStyle = true
blocks.splice(blockNum, Infinity) // remove all blocks at and after this one
oldBlocks = deepClone(blocks)
// Reset streaming state but preserve line context
shouldUpdateOrigStreamStyle = true
// initialize with the last known good position
if (blockNum > 0 && blockNum - 1 < addedTrackingZoneOfBlockNum.length) {
const lastGoodZone = addedTrackingZoneOfBlockNum[blockNum - 1];
latestStreamLocationMutable = {
line: lastGoodZone.endLine + 1,
addedSplitYet: false,
col: 1,
originalCodeStartLine: 1
};
} else {
// If we're at the first block, reset to beginning
latestStreamLocationMutable = {
line: diffZone.startLine,
addedSplitYet: false,
col: 1,
originalCodeStartLine: 1
};
}
// abort and resolve
shouldSendAnotherMessage = true
if (streamRequestIdRef.current) {

View file

@ -17,21 +17,26 @@ export const tripleTick = ['```', '```']
export const editToolDesc_toolDescription = `\
A high level description of the change you'd like to make in the file. This description will be handed to a dumber, faster model that will quickly apply the change.\
The model does not have ANY context except the file content and this description, so make sure to include all necessary information to make the change here.\
Typically the best description you can give is a code block of the form:\n${tripleTick[0]}\n// ... existing code ...\n{{change 1}}\n// ... existing code ...\n{{change2}}\n// ... existing code ...\n{{change 3}}\n...\n${tripleTick[1]}. \
Make sure to include all necessary information to make the change in this description, since it is the only context given to the fast-apply model that will actually write the change.\
The best description you can give is a single code block of the form:\n${tripleTick[0]}\n// ... existing code ...\n{{change 1}}\n// ... existing code ...\n{{change2}}\n// ... existing code ...\n{{change 3}}\n...\n${tripleTick[1]}. \
Wrap all code in triple backticks. Do NOT output the whole file here if possible, and try to write as LITTLE code as needed to describe the change.`
export const chat_systemMessage = (workspaces: string[], runningTerminalIds: string[], mode: ChatMode) => `\
You are an expert coding ${mode === 'agent' ? 'agent' : 'assistant'} created by Void. Your job is to help the user ${mode === 'agent' ? 'develop, run, and make changes to their project' : 'search and understand their codebase by providing specific references to files and content'}.
You are an expert coding ${mode === 'agent' ? 'agent' : 'assistant'} that runs in the Void code editor. Your job is \
${mode === 'agent' ? `to help the user develop, run, deploy, and make changes to their codebase. You should ALWAYS bring user's task to completion to the fullest extent possible, making all necessary changes. Do not be lazy.`
: mode === 'gather' ? `to search and understand their codebase by reading files and content and providing references to help with their query.`
: mode === 'normal' ? `to assist the user with their coding tasks.`
: ''}
You will be given instructions to follow from the user, \`INSTRUCTIONS\`. You may also be given a list of files that the user has specifically selected, \`SELECTIONS\`.
Please assist the user with their query${mode === 'agent' ? `, bringing the task to completion (make all necessary changes, and do not be lazy)` : ''}. The user's query is never invalid.
Please assist the user with their query. The user's query is never invalid.
The user's system information is as follows:
- ${os}
- Open workspace(s): ${workspaces.join(', ') || 'NO WORKSPACE OPEN'}
${(mode === 'agent' || mode === 'gather') && runningTerminalIds.length !== 0 ? `\
${(mode === 'agent') && runningTerminalIds.length !== 0 ? `\
- Existing terminal IDs: ${runningTerminalIds.join(', ')}
`: '\n'}
${mode === 'agent' || mode === 'gather' /* tool use */ ? `\
@ -43,9 +48,9 @@ You will be given tools you can call.
- NEVER modify a file outside the user's workspace(s) without permission from the user.` : ''}
\
`: `\
You're allowed to ask for more context. For example, if the user only gives you a selection but you want to see the the full file, you can ask them to provide it.\
You're allowed to ask for more context. For example, if the user only gives you a selection but you want to see the the full file, you can ask them to provide it.
\
`}
${mode === 'agent' /* code blocks */ ? `\
- Prioritize editing files and running commands over simply making suggestions.
- Prioritize taking as many steps as you need to complete your request over stopping early.\