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
6 changes: 6 additions & 0 deletions src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import { askFollowupQuestionTool } from "./tools/askFollowupQuestionTool"
import { switchModeTool } from "./tools/switchModeTool"
import { attemptCompletionTool } from "./tools/attemptCompletionTool"
import { newTaskTool } from "./tools/newTaskTool"
import { appendToFileTool } from "./tools/appendToFileTool"

export type ToolResponse = string | Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam>
type UserContent = Array<Anthropic.Messages.ContentBlockParam>
Expand Down Expand Up @@ -1390,6 +1391,8 @@ export class Cline extends EventEmitter<ClineEvents> {
return `[${block.name} for '${block.params.task}']`
case "write_to_file":
return `[${block.name} for '${block.params.path}']`
case "append_to_file":
return `[${block.name} for '${block.params.path}']`
case "apply_diff":
return `[${block.name} for '${block.params.path}']`
case "search_files":
Expand Down Expand Up @@ -1573,6 +1576,9 @@ export class Cline extends EventEmitter<ClineEvents> {
case "write_to_file":
await writeToFileTool(this, block, askApproval, handleError, pushToolResult, removeClosingTag)
break
case "append_to_file":
await appendToFileTool(this, block, askApproval, handleError, pushToolResult, removeClosingTag)
break
case "apply_diff":
await applyDiffTool(this, block, askApproval, handleError, pushToolResult, removeClosingTag)
break
Expand Down
6 changes: 6 additions & 0 deletions src/core/assistant-message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const toolUseNames = [
"execute_command",
"read_file",
"write_to_file",
"append_to_file",
"apply_diff",
"insert_content",
"search_and_replace",
Expand Down Expand Up @@ -94,6 +95,11 @@ export interface WriteToFileToolUse extends ToolUse {
params: Partial<Pick<Record<ToolParamName, string>, "path" | "content" | "line_count">>
}

export interface AppendToFileToolUse extends ToolUse {
name: "append_to_file"
params: Partial<Pick<Record<ToolParamName, string>, "path" | "content">>
}

export interface InsertCodeBlockToolUse extends ToolUse {
name: "insert_content"
params: Partial<Pick<Record<ToolParamName, string>, "path" | "operations">>
Expand Down
308 changes: 308 additions & 0 deletions src/core/prompts/__tests__/__snapshots__/system.test.ts.snap

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/core/prompts/sections/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
if (experiments?.["insert_content"]) {
availableTools.push("insert_content (for adding lines to existing files)")
}
if (experiments?.["append_to_file"]) {
availableTools.push("append_to_file (for appending content to the end of files)")
}
if (experiments?.["search_and_replace"]) {
availableTools.push("search_and_replace (for finding and replacing individual pieces of text)")
}
Expand All @@ -32,6 +35,12 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
)
}

if (experiments?.["append_to_file"]) {
instructions.push(
"- The append_to_file tool adds content to the end of files, such as appending new log entries or adding new data records. This tool will always add the content at the end of the file.",
)
}

if (experiments?.["search_and_replace"]) {
instructions.push(
"- The search_and_replace tool finds and replaces text or regex in files. This tool allows you to search for a specific regex pattern or text and replace it with another value. Be cautious when using this tool to ensure you are replacing the correct text. It can support multiple operations at once.",
Expand Down
25 changes: 25 additions & 0 deletions src/core/prompts/tools/append-to-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ToolArgs } from "./types"

export function getAppendToFileDescription(args: ToolArgs): string {
return `## append_to_file
Description: Request to append content to a file at the specified path. If the file exists, the content will be appended to the end of the file. If the file doesn't exist, it will be created with the provided content. This tool will automatically create any directories needed to write the file.
Parameters:
- path: (required) The path of the file to append to (relative to the current workspace directory ${args.cwd})
- content: (required) The content to append to the file. The content will be added at the end of the existing file content. Do NOT include line numbers in the content.
Usage:
<append_to_file>
<path>File path here</path>
<content>
Your content to append here
</content>
</append_to_file>

Example: Requesting to append to a log file
<append_to_file>
<path>logs/app.log</path>
<content>
[2024-04-17 15:20:30] New log entry
[2024-04-17 15:20:31] Another log entry
</content>
</append_to_file>`
}
3 changes: 3 additions & 0 deletions src/core/prompts/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getExecuteCommandDescription } from "./execute-command"
import { getReadFileDescription } from "./read-file"
import { getFetchInstructionsDescription } from "./fetch-instructions"
import { getWriteToFileDescription } from "./write-to-file"
import { getAppendToFileDescription } from "./append-to-file"
import { getSearchFilesDescription } from "./search-files"
import { getListFilesDescription } from "./list-files"
import { getInsertContentDescription } from "./insert-content"
Expand All @@ -26,6 +27,7 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined>
read_file: (args) => getReadFileDescription(args),
fetch_instructions: () => getFetchInstructionsDescription(),
write_to_file: (args) => getWriteToFileDescription(args),
append_to_file: (args) => getAppendToFileDescription(args),
search_files: (args) => getSearchFilesDescription(args),
list_files: (args) => getListFilesDescription(args),
list_code_definition_names: (args) => getListCodeDefinitionNamesDescription(args),
Expand Down Expand Up @@ -101,6 +103,7 @@ export {
getReadFileDescription,
getFetchInstructionsDescription,
getWriteToFileDescription,
getAppendToFileDescription,
getSearchFilesDescription,
getListFilesDescription,
getListCodeDefinitionNamesDescription,
Expand Down
Loading