Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .agents/types/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ export interface ProposeStrReplaceParams {
/** Array of replacements to make. */
replacements: {
/** The string to replace. This must be an *exact match* of the string you want to replace, including whitespace and punctuation. */
old: string
/** The string to replace the corresponding old string with. Can be empty to delete. */
new: string
/** Whether to allow multiple replacements of old string. */
oldString: string
/** The string to replace the corresponding oldString with. Can be empty to delete. */
newString: string
/** Whether to allow multiple replacements of oldString. */
allowMultiple?: boolean
}[]
}
Expand Down Expand Up @@ -305,10 +305,10 @@ export interface StrReplaceParams {
/** Array of replacements to make. */
replacements: {
/** The string to replace. This must be an *exact match* of the string you want to replace, including whitespace and punctuation. */
old: string
/** The string to replace the corresponding old string with. Can be empty to delete. */
new: string
/** Whether to allow multiple replacements of old string. */
oldString: string
/** The string to replace the corresponding oldString with. Can be empty to delete. */
newString: string
/** Whether to allow multiple replacements of oldString. */
allowMultiple?: boolean
}[]
}
Expand Down
8 changes: 4 additions & 4 deletions agents-graveyard/editor/reviewer-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ Write out what changes you would make using the tool call format below. Use this
"path": "path/to/file",
"replacements": [
{
"old": "exact old code",
"new": "exact new code"
"oldString": "exact old code",
"newString": "exact new code"
},
{
"old": "exact old code 2",
"new": "exact new code 2"
"oldString": "exact old code 2",
"newString": "exact new code 2"
},
]
}
Expand Down
17 changes: 9 additions & 8 deletions agents/editor/best-of-n/editor-implementor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ You can make multiple tool calls across multiple steps to complete the implement
"path": "path/to/file",
"replacements": [
{
"old": "exact old code",
"new": "exact new code"
"oldString": "exact old code",
"newString": "exact new code"
},
{
"old": "exact old code 2",
"new": "exact new code 2"
"oldString": "exact old code 2",
"newString": "exact new code 2"
},
]
}
Expand All @@ -72,9 +72,10 @@ OR for new files or major rewrites:
"content": "Complete file content"
}
</codebuff_tool_call>
${isGpt5 || isGemini
? ``
: `
${
isGpt5 || isGemini
? ``
: `
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.

You can also use <think> tags interspersed between tool calls to think about the best way to implement the changes.
Expand Down Expand Up @@ -102,7 +103,7 @@ You can also use <think> tags interspersed between tool calls to think about the
</codebuff_tool_call>

</example>`
}
}

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.

Expand Down
8 changes: 4 additions & 4 deletions agents/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ Write out what changes you would make using the tool call format below. Use this
"path": "path/to/file",
"replacements": [
{
"old": "exact old code",
"new": "exact new code"
"oldString": "exact old code",
"newString": "exact new code"
},
{
"old": "exact old code 2",
"new": "exact new code 2"
"oldString": "exact old code 2",
"newString": "exact new code 2"
},
]
}
Expand Down
16 changes: 8 additions & 8 deletions agents/types/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ export interface ProposeStrReplaceParams {
/** Array of replacements to make. */
replacements: {
/** The string to replace. This must be an *exact match* of the string you want to replace, including whitespace and punctuation. */
old: string
/** The string to replace the corresponding old string with. Can be empty to delete. */
new: string
/** Whether to allow multiple replacements of old string. */
oldString: string
/** The string to replace the corresponding oldString with. Can be empty to delete. */
newString: string
/** Whether to allow multiple replacements of oldString. */
allowMultiple?: boolean
}[]
}
Expand Down Expand Up @@ -358,10 +358,10 @@ export interface StrReplaceParams {
/** Array of replacements to make. */
replacements: {
/** The string to replace. This must be an *exact match* of the string you want to replace, including whitespace and punctuation. */
old: string
/** The string to replace the corresponding old string with. Can be empty to delete. */
new: string
/** Whether to allow multiple replacements of old string. */
oldString: string
/** The string to replace the corresponding oldString with. Can be empty to delete. */
newString: string
/** Whether to allow multiple replacements of oldString. */
allowMultiple?: boolean
}[]
}
Expand Down
56 changes: 9 additions & 47 deletions cli/src/components/tools/str-replace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,14 @@ import { TextAttributes } from '@opentui/core'
import { DiffViewer } from './diff-viewer'
import { defineToolComponent } from './types'
import { useTheme } from '../../hooks/use-theme'
import {
extractDiff,
extractFilePath,
isCreateFile,
} from '../../utils/implementor-helpers'

import type { ToolRenderConfig } from './types'

function extractValueForKey(output: string, key: string): string | null {
if (!output) return null
const lines = output.split('\n')
for (let i = 0; i < lines.length; i++) {
const line = lines[i]
const match = line.match(/^\s*([A-Za-z0-9_]+):\s*(.*)$/)
if (match && match[1] === key) {
const rest = match[2]
if (rest.trim().startsWith('|')) {
const baseIndent = lines[i + 1]?.match(/^\s*/)?.[0].length ?? 0
const acc: string[] = []
for (let j = i + 1; j < lines.length; j++) {
const l = lines[j]
const indent = l.match(/^\s*/)?.[0].length ?? 0
if (l.trim().length === 0) {
acc.push('')
continue
}
if (indent < baseIndent) break
acc.push(l.slice(baseIndent))
}
return acc.join('\n')
} else {
let val = rest.trim()
if (val.startsWith('"') && val.endsWith('"')) {
val = val.slice(1, -1)
}
return val
}
}
}
return null
}

interface EditHeaderProps {
name: string
filePath: string | null
Expand Down Expand Up @@ -73,7 +44,7 @@ const EditBody = ({ name, filePath, diffText, isCreate }: EditBodyProps) => {
return (
<box style={{ flexDirection: 'column', gap: 0, width: '100%' }}>
<EditHeader name={name} filePath={filePath} />
{!isCreate && (
{!isCreate && diffText.length > 0 && (
<box style={{ paddingLeft: 2, width: '100%' }}>
<DiffViewer diffText={diffText} />
</box>
Expand All @@ -86,18 +57,9 @@ export const StrReplaceComponent = defineToolComponent({
toolName: 'str_replace',

render(toolBlock): ToolRenderConfig {
const outputStr =
typeof toolBlock.output === 'string' ? toolBlock.output : ''
const diff =
extractValueForKey(outputStr, 'unifiedDiff') ||
extractValueForKey(outputStr, 'patch')
const filePath =
extractValueForKey(outputStr, 'file') ||
(typeof (toolBlock.input as any)?.path === 'string'
? (toolBlock.input as any).path
: null)
const message = extractValueForKey(outputStr, 'message')
const isCreate = message === 'Created new file'
const diff = extractDiff(toolBlock)
const filePath = extractFilePath(toolBlock)
const isCreate = isCreateFile(toolBlock)

return {
content: (
Expand Down
Loading
Loading