Skip to content

Commit 4d77f49

Browse files
authored
Instructions (#173)
1 parent da5860a commit 4d77f49

File tree

13 files changed

+70
-64
lines changed

13 files changed

+70
-64
lines changed

backend/src/__tests__/__snapshots__/tools.test.ts.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Assistant: Sure thing! Let's update that file!
4141
4242
<write_file>
4343
<path>path/to/example/file.ts</path>
44+
<instructions>Update the console logs</instructions>
4445
<content>console.log('Hello from Buffy!');</content>
4546
</write_file>
4647
@@ -391,6 +392,7 @@ Assistant: Sure thing! Let's update that file!
391392
392393
<write_file>
393394
<path>path/to/example/file.ts</path>
395+
<instructions>Update the console logs</instructions>
394396
<content>console.log('Hello from Buffy!');</content>
395397
</write_file>
396398
@@ -484,6 +486,7 @@ Create or edit a file with the given content.
484486
485487
Params:
486488
- \`path\`: (required) Path to the file relative to the **project root**
489+
- \`instructions\`: (required) What the change is intended to do in only one sentence.
487490
- \`content\`: (required) Edit snippet to apply to the file.
488491
489492
#### **IMPORTANT** Edit Snippet
@@ -539,18 +542,21 @@ Notes for editing a file:
539542
Examples:
540543
<write_file>
541544
<path>path/to/file</path>
545+
<instructions>How the file is being updated</instructions>
542546
<content>Your file content here</content>
543547
</write_file>
544548
545549
Example 1 - Simple file creation:
546550
<write_file>
547551
<path>new-file.ts</path>
552+
<instructions>Prints Hello, world</instructions>
548553
<content>console.log("Hello, world!");</content>
549554
</write_file>
550555
551556
Example 2 - Editing with placeholder comments:
552557
<write_file>
553558
<path>foo.ts</path>
559+
<instructions>Update foo and remove console.log</instructions>
554560
<content>// ... existing code ...
555561
556562
function foo() {
@@ -945,6 +951,7 @@ Assistant: Sure thing! Let's update that file!
945951
946952
<write_file>
947953
<path>path/to/example/file.ts</path>
954+
<instructions>Update the console logs</instructions>
948955
<content>console.log('Hello from Buffy!');</content>
949956
</write_file>
950957
@@ -1038,6 +1045,7 @@ Create or edit a file with the given content.
10381045
10391046
Params:
10401047
- \`path\`: (required) Path to the file relative to the **project root**
1048+
- \`instructions\`: (required) What the change is intended to do in only one sentence.
10411049
- \`content\`: (required) Edit snippet to apply to the file.
10421050
10431051
#### **IMPORTANT** Edit Snippet
@@ -1093,18 +1101,21 @@ Notes for editing a file:
10931101
Examples:
10941102
<write_file>
10951103
<path>path/to/file</path>
1104+
<instructions>How the file is being updated</instructions>
10961105
<content>Your file content here</content>
10971106
</write_file>
10981107
10991108
Example 1 - Simple file creation:
11001109
<write_file>
11011110
<path>new-file.ts</path>
1111+
<instructions>Prints Hello, world</instructions>
11021112
<content>console.log("Hello, world!");</content>
11031113
</write_file>
11041114
11051115
Example 2 - Editing with placeholder comments:
11061116
<write_file>
11071117
<path>foo.ts</path>
1118+
<instructions>Update foo and remove console.log</instructions>
11081119
<content>// ... existing code ...
11091120
11101121
function foo() {
@@ -1499,6 +1510,7 @@ Assistant: Sure thing! Let's update that file!
14991510
15001511
<write_file>
15011512
<path>path/to/example/file.ts</path>
1513+
<instructions>Update the console logs</instructions>
15021514
<content>console.log('Hello from Buffy!');</content>
15031515
</write_file>
15041516
@@ -1592,6 +1604,7 @@ Create or edit a file with the given content.
15921604
15931605
Params:
15941606
- \`path\`: (required) Path to the file relative to the **project root**
1607+
- \`instructions\`: (required) What the change is intended to do in only one sentence.
15951608
- \`content\`: (required) Edit snippet to apply to the file.
15961609
15971610
#### **IMPORTANT** Edit Snippet
@@ -1647,18 +1660,21 @@ Notes for editing a file:
16471660
Examples:
16481661
<write_file>
16491662
<path>path/to/file</path>
1663+
<instructions>How the file is being updated</instructions>
16501664
<content>Your file content here</content>
16511665
</write_file>
16521666
16531667
Example 1 - Simple file creation:
16541668
<write_file>
16551669
<path>new-file.ts</path>
1670+
<instructions>Prints Hello, world</instructions>
16561671
<content>console.log("Hello, world!");</content>
16571672
</write_file>
16581673
16591674
Example 2 - Editing with placeholder comments:
16601675
<write_file>
16611676
<path>foo.ts</path>
1677+
<instructions>Update foo and remove console.log</instructions>
16621678
<content>// ... existing code ...
16631679
16641680
function foo() {
@@ -2053,6 +2069,7 @@ Assistant: Sure thing! Let's update that file!
20532069
20542070
<write_file>
20552071
<path>path/to/example/file.ts</path>
2072+
<instructions>Update the console logs</instructions>
20562073
<content>console.log('Hello from Buffy!');</content>
20572074
</write_file>
20582075
@@ -2146,6 +2163,7 @@ Create or edit a file with the given content.
21462163
21472164
Params:
21482165
- \`path\`: (required) Path to the file relative to the **project root**
2166+
- \`instructions\`: (required) What the change is intended to do in only one sentence.
21492167
- \`content\`: (required) Edit snippet to apply to the file.
21502168
21512169
#### **IMPORTANT** Edit Snippet
@@ -2201,18 +2219,21 @@ Notes for editing a file:
22012219
Examples:
22022220
<write_file>
22032221
<path>path/to/file</path>
2222+
<instructions>How the file is being updated</instructions>
22042223
<content>Your file content here</content>
22052224
</write_file>
22062225
22072226
Example 1 - Simple file creation:
22082227
<write_file>
22092228
<path>new-file.ts</path>
2229+
<instructions>Prints Hello, world</instructions>
22102230
<content>console.log("Hello, world!");</content>
22112231
</write_file>
22122232
22132233
Example 2 - Editing with placeholder comments:
22142234
<write_file>
22152235
<path>foo.ts</path>
2236+
<instructions>Update foo and remove console.log</instructions>
22162237
<content>// ... existing code ...
22172238
22182239
function foo() {

backend/src/__tests__/main-prompt.test.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import * as analytics from 'common/analytics'
1212
import { TEST_USER_ID } from 'common/constants'
1313
import { getInitialAgentState } from 'common/types/agent-state'
14-
import { createWriteFileBlock } from 'common/util/file'
1514
import { WebSocket } from 'ws'
1615

1716
// Mock imports
@@ -55,10 +54,11 @@ describe('mainPrompt', () => {
5554

5655
// Mock processFileBlock
5756
spyOn(processFileBlockModule, 'processFileBlock').mockImplementation(
58-
async (path, contentPromise, newContent) => {
57+
async (path, instructions, contentPromise, newContent) => {
5958
return {
6059
tool: 'write_file' as const,
6160
path,
61+
instructions,
6262
content: newContent,
6363
patch: undefined,
6464
}
@@ -303,8 +303,24 @@ describe('mainPrompt', () => {
303303
})
304304

305305
it('should handle write_file tool call', async () => {
306+
const createWriteFileBlock = (
307+
filePath: string,
308+
instructions: string,
309+
content: string
310+
) => {
311+
const tagName = 'write_file'
312+
return `<${tagName}>
313+
<path>${filePath}</path>
314+
<instructions>${instructions}</instructions>
315+
<content>${content}</content>
316+
</${tagName}>`
317+
}
306318
// Mock LLM to return a write_file tool call
307-
const writeFileBlock = createWriteFileBlock('new-file.txt', 'Hello World')
319+
const writeFileBlock = createWriteFileBlock(
320+
'new-file.txt',
321+
'Added Hello World',
322+
'Hello, world!'
323+
)
308324
mockAgentStream(writeFileBlock)
309325

310326
const agentState = getInitialAgentState(mockFileContext)
@@ -334,7 +350,7 @@ describe('mainPrompt', () => {
334350
}
335351
expect(params.type).toBe('file')
336352
expect(params.path).toBe('new-file.txt')
337-
expect(params.content).toBe('Hello World')
353+
expect(params.content).toBe('Hello, world!')
338354
})
339355

340356
it('should force end of response after MAX_CONSECUTIVE_ASSISTANT_MESSAGES', async () => {

backend/src/__tests__/process-file-block.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe('processFileBlock', () => {
6666

6767
const result = await processFileBlock(
6868
'test.ts',
69+
undefined,
6970
Promise.resolve(null),
7071
newContent,
7172
[],
@@ -102,6 +103,7 @@ describe('processFileBlock', () => {
102103

103104
const result = await processFileBlock(
104105
'test.ts',
106+
undefined,
105107
Promise.resolve(oldContent),
106108
newContent,
107109
[],
@@ -134,6 +136,7 @@ describe('processFileBlock', () => {
134136

135137
const result = await processFileBlock(
136138
'test.ts',
139+
undefined,
137140
Promise.resolve(oldContent),
138141
newContent,
139142
[],
@@ -203,6 +206,7 @@ function divide(a: number, b: number) {
203206

204207
const result = await processFileBlock(
205208
'test.ts',
209+
undefined,
206210
Promise.resolve(oldContent),
207211
newContent,
208212
[],
@@ -240,6 +244,7 @@ function divide(a: number, b: number) {
240244

241245
const result = await processFileBlock(
242246
'test.ts',
247+
undefined,
243248
Promise.resolve(oldContent),
244249
newContent,
245250
[],
@@ -281,6 +286,7 @@ function divide(a: number, b: number) {
281286

282287
const result = await processFileBlock(
283288
'test.ts',
289+
undefined,
284290
Promise.resolve(null),
285291
newContent,
286292
[],

backend/src/__tests__/tools.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,21 @@ describe('getFilteredToolsInstructions', () => {
1010

1111
it('should match snapshot for lite mode', () => {
1212
const result = getFilteredToolsInstructions('lite')
13-
1413
expect(result).toMatchSnapshot()
1514
})
1615

1716
it('should match snapshot for normal mode', () => {
1817
const result = getFilteredToolsInstructions('normal')
19-
2018
expect(result).toMatchSnapshot()
2119
})
2220

2321
it('should match snapshot for max mode', () => {
2422
const result = getFilteredToolsInstructions('max')
25-
2623
expect(result).toMatchSnapshot()
2724
})
2825

2926
it('should match snapshot for experimental mode', () => {
3027
const result = getFilteredToolsInstructions('experimental')
31-
3228
expect(result).toMatchSnapshot()
3329
})
3430
})

backend/src/fast-rewrite.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function fastRewrite(
1212
initialContent: string,
1313
editSnippet: string,
1414
filePath: string,
15+
instructions: string | undefined,
1516
clientSessionId: string,
1617
fingerprintId: string,
1718
userInputId: string,
@@ -20,7 +21,7 @@ export async function fastRewrite(
2021
) {
2122
const relaceStartTime = Date.now()
2223
const messageId = generateCompactId('cb-')
23-
let response = await promptRelaceAI(initialContent, editSnippet, {
24+
let response = await promptRelaceAI(initialContent, editSnippet, instructions, {
2425
clientSessionId,
2526
fingerprintId,
2627
userInputId,

backend/src/llm-apis/relace-api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const timeoutPromise = (ms: number) =>
1818
export async function promptRelaceAI(
1919
initialCode: string,
2020
editSnippet: string,
21+
instructions: string | undefined,
2122
options: {
2223
clientSessionId: string
2324
fingerprintId: string
@@ -48,6 +49,7 @@ export async function promptRelaceAI(
4849
body: JSON.stringify({
4950
initialCode,
5051
editSnippet,
52+
...(instructions ? { instructions } : {}),
5153
stream: false,
5254
'relace-metadata': {
5355
'codebuff-id': messageId,

backend/src/main-prompt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ export const mainPrompt = async (
764764
fileProcessingPromisesByPath[path].push(Promise.resolve(change))
765765
}),
766766
write_file: toolCallback('write_file', (toolCall) => {
767-
const { path, content } = toolCall.parameters
767+
const { path, instructions, content } = toolCall.parameters
768768
if (!content) return
769769

770770
// Initialize state for this file path if needed
@@ -790,6 +790,7 @@ export const mainPrompt = async (
790790

791791
const newPromise = processFileBlock(
792792
path,
793+
instructions,
793794
latestContentPromise,
794795
fileContentWithoutStartNewline,
795796
messagesWithUserMessage,

backend/src/process-file-block.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { countTokens } from './util/token-counter'
1515

1616
export async function processFileBlock(
1717
path: string,
18+
instructions: string | undefined,
1819
initialContentPromise: Promise<string | null>,
1920
newContent: string,
2021
messages: CoreMessage[],
@@ -116,6 +117,7 @@ export async function processFileBlock(
116117
normalizedInitialContent,
117118
normalizedEditSnippet,
118119
path,
120+
instructions,
119121
clientSessionId,
120122
fingerprintId,
121123
userInputId,
@@ -141,6 +143,7 @@ export async function processFileBlock(
141143
normalizedInitialContent,
142144
updatedEditSnippet,
143145
path,
146+
instructions,
144147
clientSessionId,
145148
fingerprintId,
146149
userInputId,

0 commit comments

Comments
 (0)