Skip to content

Commit 37bc26b

Browse files
authored
Update str_replace argument names (#596)
1 parent 71b65a1 commit 37bc26b

21 files changed

Lines changed: 1063 additions & 434 deletions

File tree

.agents/types/tools.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ export interface ProposeStrReplaceParams {
181181
/** Array of replacements to make. */
182182
replacements: {
183183
/** The string to replace. This must be an *exact match* of the string you want to replace, including whitespace and punctuation. */
184-
old: string
185-
/** The string to replace the corresponding old string with. Can be empty to delete. */
186-
new: string
187-
/** Whether to allow multiple replacements of old string. */
184+
oldString: string
185+
/** The string to replace the corresponding oldString with. Can be empty to delete. */
186+
newString: string
187+
/** Whether to allow multiple replacements of oldString. */
188188
allowMultiple?: boolean
189189
}[]
190190
}
@@ -305,10 +305,10 @@ export interface StrReplaceParams {
305305
/** Array of replacements to make. */
306306
replacements: {
307307
/** The string to replace. This must be an *exact match* of the string you want to replace, including whitespace and punctuation. */
308-
old: string
309-
/** The string to replace the corresponding old string with. Can be empty to delete. */
310-
new: string
311-
/** Whether to allow multiple replacements of old string. */
308+
oldString: string
309+
/** The string to replace the corresponding oldString with. Can be empty to delete. */
310+
newString: string
311+
/** Whether to allow multiple replacements of oldString. */
312312
allowMultiple?: boolean
313313
}[]
314314
}

agents-graveyard/editor/reviewer-editor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ Write out what changes you would make using the tool call format below. Use this
3636
"path": "path/to/file",
3737
"replacements": [
3838
{
39-
"old": "exact old code",
40-
"new": "exact new code"
39+
"oldString": "exact old code",
40+
"newString": "exact new code"
4141
},
4242
{
43-
"old": "exact old code 2",
44-
"new": "exact new code 2"
43+
"oldString": "exact old code 2",
44+
"newString": "exact new code 2"
4545
},
4646
]
4747
}

agents/editor/best-of-n/editor-implementor.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ You can make multiple tool calls across multiple steps to complete the implement
5151
"path": "path/to/file",
5252
"replacements": [
5353
{
54-
"old": "exact old code",
55-
"new": "exact new code"
54+
"oldString": "exact old code",
55+
"newString": "exact new code"
5656
},
5757
{
58-
"old": "exact old code 2",
59-
"new": "exact new code 2"
58+
"oldString": "exact old code 2",
59+
"newString": "exact new code 2"
6060
},
6161
]
6262
}
@@ -72,9 +72,10 @@ OR for new files or major rewrites:
7272
"content": "Complete file content"
7373
}
7474
</codebuff_tool_call>
75-
${isGpt5 || isGemini
76-
? ``
77-
: `
75+
${
76+
isGpt5 || isGemini
77+
? ``
78+
: `
7879
IMPORTANT: Before you start writing your implementation, you should use <think> tags to think about the best way to implement the changes. You should think really really hard to make sure you implement the changes in the best way possible. Take as much time as you to think through all the cases to produce the best changes.
7980
8081
You can also use <think> tags interspersed between tool calls to think about the best way to implement the changes.
@@ -102,7 +103,7 @@ You can also use <think> tags interspersed between tool calls to think about the
102103
</codebuff_tool_call>
103104
104105
</example>`
105-
}
106+
}
106107
107108
After the edit tool calls, you can optionally mention any follow-up steps to take, like deleting a file, or a specific way to validate the changes. There's no need to use the set_output tool as your entire response will be included in the output.
108109

agents/editor/editor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ Write out what changes you would make using the tool call format below. Use this
6161
"path": "path/to/file",
6262
"replacements": [
6363
{
64-
"old": "exact old code",
65-
"new": "exact new code"
64+
"oldString": "exact old code",
65+
"newString": "exact new code"
6666
},
6767
{
68-
"old": "exact old code 2",
69-
"new": "exact new code 2"
68+
"oldString": "exact old code 2",
69+
"newString": "exact new code 2"
7070
},
7171
]
7272
}

agents/types/tools.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ export interface ProposeStrReplaceParams {
226226
/** Array of replacements to make. */
227227
replacements: {
228228
/** The string to replace. This must be an *exact match* of the string you want to replace, including whitespace and punctuation. */
229-
old: string
230-
/** The string to replace the corresponding old string with. Can be empty to delete. */
231-
new: string
232-
/** Whether to allow multiple replacements of old string. */
229+
oldString: string
230+
/** The string to replace the corresponding oldString with. Can be empty to delete. */
231+
newString: string
232+
/** Whether to allow multiple replacements of oldString. */
233233
allowMultiple?: boolean
234234
}[]
235235
}
@@ -358,10 +358,10 @@ export interface StrReplaceParams {
358358
/** Array of replacements to make. */
359359
replacements: {
360360
/** The string to replace. This must be an *exact match* of the string you want to replace, including whitespace and punctuation. */
361-
old: string
362-
/** The string to replace the corresponding old string with. Can be empty to delete. */
363-
new: string
364-
/** Whether to allow multiple replacements of old string. */
361+
oldString: string
362+
/** The string to replace the corresponding oldString with. Can be empty to delete. */
363+
newString: string
364+
/** Whether to allow multiple replacements of oldString. */
365365
allowMultiple?: boolean
366366
}[]
367367
}

cli/src/components/tools/str-replace.tsx

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,14 @@ import { TextAttributes } from '@opentui/core'
33
import { DiffViewer } from './diff-viewer'
44
import { defineToolComponent } from './types'
55
import { useTheme } from '../../hooks/use-theme'
6+
import {
7+
extractDiff,
8+
extractFilePath,
9+
isCreateFile,
10+
} from '../../utils/implementor-helpers'
611

712
import type { ToolRenderConfig } from './types'
813

9-
function extractValueForKey(output: string, key: string): string | null {
10-
if (!output) return null
11-
const lines = output.split('\n')
12-
for (let i = 0; i < lines.length; i++) {
13-
const line = lines[i]
14-
const match = line.match(/^\s*([A-Za-z0-9_]+):\s*(.*)$/)
15-
if (match && match[1] === key) {
16-
const rest = match[2]
17-
if (rest.trim().startsWith('|')) {
18-
const baseIndent = lines[i + 1]?.match(/^\s*/)?.[0].length ?? 0
19-
const acc: string[] = []
20-
for (let j = i + 1; j < lines.length; j++) {
21-
const l = lines[j]
22-
const indent = l.match(/^\s*/)?.[0].length ?? 0
23-
if (l.trim().length === 0) {
24-
acc.push('')
25-
continue
26-
}
27-
if (indent < baseIndent) break
28-
acc.push(l.slice(baseIndent))
29-
}
30-
return acc.join('\n')
31-
} else {
32-
let val = rest.trim()
33-
if (val.startsWith('"') && val.endsWith('"')) {
34-
val = val.slice(1, -1)
35-
}
36-
return val
37-
}
38-
}
39-
}
40-
return null
41-
}
42-
4314
interface EditHeaderProps {
4415
name: string
4516
filePath: string | null
@@ -73,7 +44,7 @@ const EditBody = ({ name, filePath, diffText, isCreate }: EditBodyProps) => {
7344
return (
7445
<box style={{ flexDirection: 'column', gap: 0, width: '100%' }}>
7546
<EditHeader name={name} filePath={filePath} />
76-
{!isCreate && (
47+
{!isCreate && diffText.length > 0 && (
7748
<box style={{ paddingLeft: 2, width: '100%' }}>
7849
<DiffViewer diffText={diffText} />
7950
</box>
@@ -86,18 +57,9 @@ export const StrReplaceComponent = defineToolComponent({
8657
toolName: 'str_replace',
8758

8859
render(toolBlock): ToolRenderConfig {
89-
const outputStr =
90-
typeof toolBlock.output === 'string' ? toolBlock.output : ''
91-
const diff =
92-
extractValueForKey(outputStr, 'unifiedDiff') ||
93-
extractValueForKey(outputStr, 'patch')
94-
const filePath =
95-
extractValueForKey(outputStr, 'file') ||
96-
(typeof (toolBlock.input as any)?.path === 'string'
97-
? (toolBlock.input as any).path
98-
: null)
99-
const message = extractValueForKey(outputStr, 'message')
100-
const isCreate = message === 'Created new file'
60+
const diff = extractDiff(toolBlock)
61+
const filePath = extractFilePath(toolBlock)
62+
const isCreate = isCreateFile(toolBlock)
10163

10264
return {
10365
content: (

0 commit comments

Comments
 (0)