Refactor modes

This commit is contained in:
Matt Rubens
2025-01-17 01:12:06 -05:00
parent b35206bc9d
commit 72fe12d096
39 changed files with 909 additions and 4310 deletions

View File

@@ -28,7 +28,7 @@ describe('main', () => {
describe('getToolDescription', () => {
it('should return tool description with correct cwd', () => {
const cwd = '/test/path'
const description = strategy.getToolDescription(cwd)
const description = strategy.getToolDescription({ cwd })
expect(description).toContain('apply_diff')
expect(description).toContain(cwd)

View File

@@ -1521,12 +1521,12 @@ function two() {
it('should include the current working directory', async () => {
const cwd = '/test/dir'
const description = await strategy.getToolDescription(cwd)
const description = await strategy.getToolDescription({ cwd })
expect(description).toContain(`relative to the current working directory ${cwd}`)
})
it('should include required format elements', async () => {
const description = await strategy.getToolDescription('/test')
const description = await strategy.getToolDescription({ cwd: '/test' })
expect(description).toContain('<<<<<<< SEARCH')
expect(description).toContain('=======')
expect(description).toContain('>>>>>>> REPLACE')
@@ -1535,7 +1535,7 @@ function two() {
})
it('should document start_line and end_line parameters', async () => {
const description = await strategy.getToolDescription('/test')
const description = await strategy.getToolDescription({ cwd: '/test' })
expect(description).toContain('start_line: (required) The line number where the search block starts.')
expect(description).toContain('end_line: (required) The line number where the search block ends.')
})

View File

@@ -10,7 +10,7 @@ describe('UnifiedDiffStrategy', () => {
describe('getToolDescription', () => {
it('should return tool description with correct cwd', () => {
const cwd = '/test/path'
const description = strategy.getToolDescription(cwd)
const description = strategy.getToolDescription({ cwd })
expect(description).toContain('apply_diff')
expect(description).toContain(cwd)

View File

@@ -107,7 +107,7 @@ export class NewUnifiedDiffStrategy implements DiffStrategy {
return { hunks }
}
getToolDescription(cwd: string): string {
getToolDescription(args: { cwd: string; toolOptions?: { [key: string]: string } }): string {
return `# apply_diff Tool Rules:
Generate a unified diff similar to what "diff -U0" would produce.
@@ -173,7 +173,7 @@ Format Requirements:
Be precise, consistent, and follow these rules carefully to generate correct diffs!
Parameters:
- path: (required) The path of the file to apply the diff to (relative to the current working directory ${cwd})
- path: (required) The path of the file to apply the diff to (relative to the current working directory ${args.cwd})
- diff: (required) The diff content in unified format to apply to the file.
Usage:

View File

@@ -65,7 +65,7 @@ export class SearchReplaceDiffStrategy implements DiffStrategy {
this.bufferLines = bufferLines ?? BUFFER_LINES;
}
getToolDescription(cwd: string): string {
getToolDescription(args: { cwd: string; toolOptions?: { [key: string]: string } }): string {
return `## apply_diff
Description: Request to replace existing code using a search and replace block.
This tool allows for precise, surgical replaces to files by specifying exactly what content to search for and what to replace it with.
@@ -76,7 +76,7 @@ If you're not confident in the exact content to search for, use the read_file to
When applying the diffs, be extra careful to remember to change any closing brackets or other syntax that may be affected by the diff farther down in the file.
Parameters:
- path: (required) The path of the file to modify (relative to the current working directory ${cwd})
- path: (required) The path of the file to modify (relative to the current working directory ${args.cwd})
- diff: (required) The search/replace block defining the changes.
- start_line: (required) The line number where the search block starts.
- end_line: (required) The line number where the search block ends.

View File

@@ -2,12 +2,12 @@ import { applyPatch } from "diff"
import { DiffStrategy, DiffResult } from "../types"
export class UnifiedDiffStrategy implements DiffStrategy {
getToolDescription(cwd: string): string {
getToolDescription(args: { cwd: string; toolOptions?: { [key: string]: string } }): string {
return `## apply_diff
Description: Apply a unified diff to a file at the specified path. This tool is useful when you need to make specific modifications to a file based on a set of changes provided in unified diff format (diff -U3).
Parameters:
- path: (required) The path of the file to apply the diff to (relative to the current working directory ${cwd})
- path: (required) The path of the file to apply the diff to (relative to the current working directory ${args.cwd})
- diff: (required) The diff content in unified format to apply to the file.
Format Requirements:

View File

@@ -15,10 +15,10 @@ export type DiffResult =
export interface DiffStrategy {
/**
* Get the tool description for this diff strategy
* @param cwd The current working directory
* @param args The tool arguments including cwd and toolOptions
* @returns The complete tool description including format requirements and examples
*/
getToolDescription(cwd: string): string
getToolDescription(args: { cwd: string; toolOptions?: { [key: string]: string } }): string
/**
* Apply a diff to the original content