Skip to content
Closed
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 @@ -79,6 +79,7 @@ import { switchModeTool } from "./tools/switchModeTool"
import { attemptCompletionTool } from "./tools/attemptCompletionTool"
import { newTaskTool } from "./tools/newTaskTool"
import { appendToFileTool } from "./tools/appendToFileTool"
import { prependToFileTool } from "./tools/prependToFileTool"

// prompts
import { formatResponse } from "./prompts/responses"
Expand Down Expand Up @@ -1242,6 +1243,8 @@ export class Cline extends EventEmitter<ClineEvents> {
return `[${block.name} for '${block.params.path}']`
case "append_to_file":
return `[${block.name} for '${block.params.path}']`
case "prepend_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 @@ -1429,6 +1432,9 @@ export class Cline extends EventEmitter<ClineEvents> {
case "append_to_file":
await appendToFileTool(this, block, askApproval, handleError, pushToolResult, removeClosingTag)
break
case "prepend_to_file":
await prependToFileTool(this, block, askApproval, handleError, pushToolResult, removeClosingTag)
break
case "apply_diff":
await applyDiffTool(this, block, askApproval, handleError, pushToolResult, removeClosingTag)
break
Expand Down
577 changes: 562 additions & 15 deletions src/core/prompts/__tests__/__snapshots__/system.test.ts.snap

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/core/prompts/sections/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
availableTools.push("write_to_file (for creating new files or complete file rewrites)")
}

availableTools.push("append_to_file (for appending content to the end of files)")
availableTools.push(
"append_to_file (for appending content to the end of files)",
"prepend_to_file (for prepending content to the beginning of files)"
)

if (experiments?.["insert_content"]) {
availableTools.push("insert_content (for adding lines to existing files)")
Expand All @@ -28,6 +31,7 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
instructions.push(
`- For editing files, you have access to these tools: ${availableTools.join(", ")}.`,
"- 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.",
"- The prepend_to_file tool adds content to the beginning of files, such as adding license headers, import statements, or configuration headers. This tool will always add the content at the beginning of the file, before any existing content. Use this tool when adding content that logically belongs at the top of a file.",
)
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/prompts/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getReadFileDescription } from "./read-file"
import { getFetchInstructionsDescription } from "./fetch-instructions"
import { getWriteToFileDescription } from "./write-to-file"
import { getAppendToFileDescription } from "./append-to-file"
import { getPrependToFileDescription } from "./prepend-to-file"
import { getSearchFilesDescription } from "./search-files"
import { getListFilesDescription } from "./list-files"
import { getInsertContentDescription } from "./insert-content"
Expand All @@ -29,6 +30,7 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined>
fetch_instructions: () => getFetchInstructionsDescription(),
write_to_file: (args) => getWriteToFileDescription(args),
append_to_file: (args) => getAppendToFileDescription(args),
prepend_to_file: (args) => getPrependToFileDescription(args),
search_files: (args) => getSearchFilesDescription(args),
list_files: (args) => getListFilesDescription(args),
list_code_definition_names: (args) => getListCodeDefinitionNamesDescription(args),
Expand Down Expand Up @@ -114,6 +116,7 @@ export {
getFetchInstructionsDescription,
getWriteToFileDescription,
getAppendToFileDescription,
getPrependToFileDescription,
getSearchFilesDescription,
getListFilesDescription,
getListCodeDefinitionNamesDescription,
Expand Down
41 changes: 41 additions & 0 deletions src/core/prompts/tools/prepend-to-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ToolArgs } from "./types"

export function getPrependToFileDescription(args: ToolArgs): string {
return `## prepend_to_file
Description: Request to prepend content to a file at the specified path. If the file exists, the content will be added to the beginning 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 prepend to (relative to the current workspace directory ${args.cwd})
- content: (required) The content to prepend to the file. The content will be added at the beginning of the existing file content. Do NOT include line numbers in the content.
Usage:
<prepend_to_file>
<path>File path here</path>
<content>
Your content to prepend here
</content>
</prepend_to_file>

Example: Requesting to prepend a license header
<prepend_to_file>
<path>src/index.js</path>
<content>
/**
* Copyright (c) 2025 Roo Veterinary Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

</content>
</prepend_to_file>

Example: Requesting to prepend import statements
<prepend_to_file>
<path>src/components/Button.js</path>
<content>
import React from 'react';
import PropTypes from 'prop-types';
import './Button.css';

</content>
</prepend_to_file>`
}
Loading