From acb2d67d962d704d38099907f3dc17ff2c551495 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Mon, 26 May 2025 10:50:17 -0400 Subject: [PATCH] Adjust the read_file prompt based on whether partial reads are enabled --- .../__snapshots__/system.test.ts.snap | 809 +++++++++++------- .../__tests__/custom-system-prompt.test.ts | 9 + src/core/prompts/__tests__/system.test.ts | 71 ++ src/core/prompts/system.ts | 4 + src/core/prompts/tools/index.ts | 2 + src/core/prompts/tools/read-file.ts | 43 +- src/core/prompts/tools/types.ts | 1 + src/core/task/Task.ts | 8 +- src/core/webview/generateSystemPrompt.ts | 2 + 9 files changed, 615 insertions(+), 334 deletions(-) diff --git a/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap b/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap index 4885b93866..40ee385f58 100644 --- a/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap +++ b/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap @@ -36,16 +36,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -55,28 +51,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -509,16 +483,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -528,28 +498,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -982,16 +930,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -1001,28 +945,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -1455,16 +1377,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -1474,28 +1392,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -1984,16 +1880,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -2003,28 +1895,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -2525,16 +2395,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -2544,28 +2410,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -3054,16 +2898,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -3073,28 +2913,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -3615,16 +3433,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -3634,28 +3448,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -4130,16 +3922,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -4149,28 +3937,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -4680,16 +4446,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -4699,28 +4461,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -5144,16 +4884,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -5163,28 +4899,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -5525,16 +5239,12 @@ Always use the actual tool name as the XML tag name for proper parsing and execu # Tools ## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: - path: (required) The path of the file to read (relative to the current workspace directory /test/path) -- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. Usage: File path here -Starting line number (optional) -Ending line number (optional) Examples: @@ -5544,28 +5254,6 @@ Examples: frontend-config.json -2. Reading the first 1000 lines of a large log file: - -logs/application.log -1000 - - -3. Reading lines 500-1000 of a CSV file: - -data/large-dataset.csv -500 -1000 - - -4. Reading a specific function in a source file: - -src/app.ts -46 -68 - - -Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. - ## fetch_instructions Description: Request to fetch instructions to perform a task Parameters: @@ -6048,6 +5736,479 @@ Mock mode-specific rules Mock generic rules" `; +exports[`addCustomInstructions should include partial read instructions when partialReadsEnabled is true 1`] = ` +"You are Roo, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices. + +==== + +MARKDOWN RULES + +ALL responses MUST show ANY \`language construct\` OR filename reference as clickable, exactly as [\`filename OR language.declaration()\`](relative/file/path.ext:line); line is required for \`syntax\` and optional for filename links. This applies to ALL markdown responses and ALSO those in + +==== + +TOOL USE + +You have access to a set of tools that are executed upon the user's approval. You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use. + +# Tool Use Formatting + +Tool uses are formatted using XML-style tags. The tool name itself becomes the XML tag name. Each parameter is enclosed within its own set of tags. Here's the structure: + + +value1 +value2 +... + + +For example, to use the read_file tool: + + +src/main.js + + +Always use the actual tool name as the XML tag name for proper parsing and execution. + +# Tools + +## read_file +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. +Parameters: +- path: (required) The path of the file to read (relative to the current workspace directory /test/path) +- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. +- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. +Usage: + +File path here +Starting line number (optional) +Ending line number (optional) + + +Examples: + +1. Reading an entire file: + +frontend-config.json + + +2. Reading the first 1000 lines of a large log file: + +logs/application.log +1000 + + +3. Reading lines 500-1000 of a CSV file: + +data/large-dataset.csv +500 +1000 + + +4. Reading a specific function in a source file: + +src/app.ts +46 +68 + + +Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues. + +## fetch_instructions +Description: Request to fetch instructions to perform a task +Parameters: +- task: (required) The task to get instructions for. This can take the following values: + create_mcp_server + create_mode + +Example: Requesting instructions to create an MCP Server + + +create_mcp_server + + +## search_files +Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context. +Parameters: +- path: (required) The path of the directory to search in (relative to the current workspace directory /test/path). This directory will be recursively searched. +- regex: (required) The regular expression pattern to search for. Uses Rust regex syntax. +- file_pattern: (optional) Glob pattern to filter files (e.g., '*.ts' for TypeScript files). If not provided, it will search all files (*). +Usage: + +Directory path here +Your regex pattern here +file pattern here (optional) + + +Example: Requesting to search for all .ts files in the current directory + +. +.* +*.ts + + +## list_files +Description: Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not. +Parameters: +- path: (required) The path of the directory to list contents for (relative to the current workspace directory /test/path) +- recursive: (optional) Whether to list files recursively. Use true for recursive listing, false or omit for top-level only. +Usage: + +Directory path here +true or false (optional) + + +Example: Requesting to list all files in the current directory + +. +false + + +## list_code_definition_names +Description: Request to list definition names (classes, functions, methods, etc.) from source code. This tool can analyze either a single file or all files at the top level of a specified directory. It provides insights into the codebase structure and important constructs, encapsulating high-level concepts and relationships that are crucial for understanding the overall architecture. +Parameters: +- path: (required) The path of the file or directory (relative to the current working directory /test/path) to analyze. When given a directory, it lists definitions from all top-level source files. +Usage: + +Directory path here + + +Examples: + +1. List definitions from a specific file: + +src/main.ts + + +2. List definitions from all files in a directory: + +src/ + + +## write_to_file +Description: Request to write content to a file. This tool is primarily used for **creating new files** or for scenarios where a **complete rewrite of an existing file is intentionally required**. If the file exists, it will be overwritten. If it doesn't exist, it will be created. This tool will automatically create any directories needed to write the file. +Parameters: +- path: (required) The path of the file to write to (relative to the current workspace directory /test/path) +- content: (required) The content to write to the file. When performing a full rewrite of an existing file or creating a new one, ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they haven't been modified. Do NOT include the line numbers in the content though, just the actual content of the file. +- line_count: (required) The number of lines in the file. Make sure to compute this based on the actual content of the file, not the number of lines in the content you're providing. +Usage: + +File path here + +Your file content here + +total number of lines in the file, including empty lines + + +Example: Requesting to write to frontend-config.json + +frontend-config.json + +{ + "apiEndpoint": "https://api.example.com", + "theme": { + "primaryColor": "#007bff", + "secondaryColor": "#6c757d", + "fontFamily": "Arial, sans-serif" + }, + "features": { + "darkMode": true, + "notifications": true, + "analytics": false + }, + "version": "1.0.0" +} + +14 + + +## insert_content +Description: Use this tool specifically for adding new lines of content into a file without modifying existing content. Specify the line number to insert before, or use line 0 to append to the end. Ideal for adding imports, functions, configuration blocks, log entries, or any multi-line text block. + +Parameters: +- path: (required) File path relative to workspace directory /test/path +- line: (required) Line number where content will be inserted (1-based) + Use 0 to append at end of file + Use any positive number to insert before that line +- content: (required) The content to insert at the specified line + +Example for inserting imports at start of file: + +src/utils.ts +1 + +// Add imports at start of file +import { sum } from './math'; + + + +Example for appending to the end of file: + +src/utils.ts +0 + +// This is the end of the file + + + + +## search_and_replace +Description: Use this tool to find and replace specific text strings or patterns (using regex) within a file. It's suitable for targeted replacements across multiple locations within the file. Supports literal text and regex patterns, case sensitivity options, and optional line ranges. Shows a diff preview before applying changes. + +Required Parameters: +- path: The path of the file to modify (relative to the current workspace directory /test/path) +- search: The text or pattern to search for +- replace: The text to replace matches with + +Optional Parameters: +- start_line: Starting line number for restricted replacement (1-based) +- end_line: Ending line number for restricted replacement (1-based) +- use_regex: Set to "true" to treat search as a regex pattern (default: false) +- ignore_case: Set to "true" to ignore case when matching (default: false) + +Notes: +- When use_regex is true, the search parameter is treated as a regular expression pattern +- When ignore_case is true, the search is case-insensitive regardless of regex mode + +Examples: + +1. Simple text replacement: + +example.ts +oldText +newText + + +2. Case-insensitive regex pattern: + +example.ts +oldw+ +new$& +true +true + + +## execute_command +Description: Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. For command chaining, use the appropriate chaining syntax for the user's shell. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Prefer relative commands and paths that avoid location sensitivity for terminal consistency, e.g: \`touch ./testdata/example.file\`, \`dir ./examples/model1/data/yaml\`, or \`go test ./cmd/front --config ./cmd/front/config.yml\`. If directed by the user, you may open a terminal in a different directory by using the \`cwd\` parameter. +Parameters: +- command: (required) The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions. +- cwd: (optional) The working directory to execute the command in (default: /test/path) +Usage: + +Your command here +Working directory path (optional) + + +Example: Requesting to execute npm run dev + +npm run dev + + +Example: Requesting to execute ls in a specific directory if directed + +ls -la +/home/user/projects + + +## ask_followup_question +Description: Ask the user a question to gather additional information needed to complete the task. This tool should be used when you encounter ambiguities, need clarification, or require more details to proceed effectively. It allows for interactive problem-solving by enabling direct communication with the user. Use this tool judiciously to maintain a balance between gathering necessary information and avoiding excessive back-and-forth. +Parameters: +- question: (required) The question to ask the user. This should be a clear, specific question that addresses the information you need. +- follow_up: (required) A list of 2-4 suggested answers that logically follow from the question, ordered by priority or logical sequence. Each suggestion must: + 1. Be provided in its own tag + 2. Be specific, actionable, and directly related to the completed task + 3. Be a complete answer to the question - the user should not need to provide additional information or fill in any missing details. DO NOT include placeholders with brackets or parentheses. +Usage: + +Your question here + + +Your suggested answer here + + + + +Example: Requesting to ask the user for the path to the frontend-config.json file + +What is the path to the frontend-config.json file? + +./src/frontend-config.json +./config/frontend-config.json +./frontend-config.json + + + +## attempt_completion +Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. Optionally you may provide a CLI command to showcase the result of your work. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again. +IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool. +Parameters: +- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance. +- command: (optional) A CLI command to execute to show a live demo of the result to the user. For example, use \`open index.html\` to display a created html website, or \`open localhost:3000\` to display a locally running development server. But DO NOT use commands like \`echo\` or \`cat\` that merely print text. This command should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions. +Usage: + + +Your final result description here + +Command to demonstrate result (optional) + + +Example: Requesting to attempt completion with a result and command + + +I've updated the CSS + +open index.html + + +## switch_mode +Description: Request to switch to a different mode. This tool allows modes to request switching to another mode when needed, such as switching to Code mode to make code changes. The user must approve the mode switch. +Parameters: +- mode_slug: (required) The slug of the mode to switch to (e.g., "code", "ask", "architect") +- reason: (optional) The reason for switching modes +Usage: + +Mode slug here +Reason for switching here + + +Example: Requesting to switch to code mode + +code +Need to make code changes + + +## new_task +Description: This will let you create a new task instance in the chosen mode using your provided message. + +Parameters: +- mode: (required) The slug of the mode to start the new task in (e.g., "code", "debug", "architect"). +- message: (required) The initial user message or instructions for this new task. + +Usage: + +your-mode-slug-here +Your initial instructions here + + +Example: + +code +Implement a new feature for the application. + + + +# Tool Use Guidelines + +1. In tags, assess what information you already have and what information you need to proceed with the task. +2. Choose the most appropriate tool based on the task and the tool descriptions provided. Assess if you need additional information to proceed, and which of the available tools would be most effective for gathering this information. For example using the list_files tool is more effective than running a command like \`ls\` in the terminal. It's critical that you think about each available tool and use the one that best fits the current step in the task. +3. If multiple actions are needed, use one tool at a time per message to accomplish the task iteratively, with each tool use being informed by the result of the previous tool use. Do not assume the outcome of any tool use. Each step must be informed by the previous step's result. +4. Formulate your tool use using the XML format specified for each tool. +5. After each tool use, the user will respond with the result of that tool use. This result will provide you with the necessary information to continue your task or make further decisions. This response may include: + - Information about whether the tool succeeded or failed, along with any reasons for failure. + - Linter errors that may have arisen due to the changes you made, which you'll need to address. + - New terminal output in reaction to the changes, which you may need to consider or act upon. + - Any other relevant feedback or information related to the tool use. +6. ALWAYS wait for user confirmation after each tool use before proceeding. Never assume the success of a tool use without explicit confirmation of the result from the user. + +It is crucial to proceed step-by-step, waiting for the user's message after each tool use before moving forward with the task. This approach allows you to: +1. Confirm the success of each step before proceeding. +2. Address any issues or errors that arise immediately. +3. Adapt your approach based on new information or unexpected results. +4. Ensure that each action builds correctly on the previous ones. + +By waiting for and carefully considering the user's response after each tool use, you can react accordingly and make informed decisions about how to proceed with the task. This iterative process helps ensure the overall success and accuracy of your work. + + + +==== + +CAPABILITIES + +- You have access to tools that let you execute CLI commands on the user's computer, list files, view source code definitions, regex search, read and write files, and ask follow-up questions. These tools help you effectively accomplish a wide range of tasks, such as writing code, making edits or improvements to existing files, understanding the current state of a project, performing system operations, and much more. +- When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. +- You can use search_files to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring. +- You can use the list_code_definition_names tool to get an overview of source code definitions for all files at the top level of a specified directory. This can be particularly useful when you need to understand the broader context and relationships between certain parts of the code. You may need to call this tool multiple times to understand various parts of the codebase related to the task. + - For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the write_to_file tool to apply the changes. If you refactored code that could affect other parts of the codebase, you could use search_files to ensure you update other files as needed. +- You can use the execute_command tool to run commands on the user's computer whenever you feel it can help accomplish the user's task. When you need to execute a CLI command, you must provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, since they are more flexible and easier to run. Interactive and long-running commands are allowed, since the commands are run in the user's VSCode terminal. The user may keep commands running in the background and you will be kept updated on their status along the way. Each command you execute is run in a new terminal instance. + +==== + +MODES + +- Test modes section + +==== + +RULES + +- The project base directory is: /test/path +- All file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to . +- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '/test/path', so be sure to pass in the correct 'path' parameter when using tools that require a path. +- Do not use the ~ character or $HOME to refer to the home directory. +- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`. +- When using the search_files tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using write_to_file to make informed changes. +- When creating a new project (such as an app, website, or any software project), organize all new files within a dedicated project directory unless the user specifies otherwise. Use appropriate file paths when writing files, as the write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser. +- For editing files, you have access to these tools: write_to_file (for creating new files or complete file rewrites), insert_content (for adding lines to existing files), search_and_replace (for finding and replacing individual pieces of text). +- The insert_content tool adds lines of text to files at a specific line number, such as adding a new function to a JavaScript file or inserting a new route in a Python file. Use line number 0 to append at the end of the file, or any positive number to insert before that line. +- 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. +- You should always prefer using other editing tools over write_to_file when making changes to existing files since write_to_file is much slower and cannot handle large files. +- When using the write_to_file tool to modify a file, use the tool directly with the desired content. You do not need to display the content before using the tool. ALWAYS provide the COMPLETE file content in your response. This is NON-NEGOTIABLE. Partial updates or placeholders like '// rest of code unchanged' are STRICTLY FORBIDDEN. You MUST include ALL parts of the file, even if they haven't been modified. Failure to do so will result in incomplete or broken code, severely impacting the user's project. +- Some modes have restrictions on which files they can edit. If you attempt to edit a restricted file, the operation will be rejected with a FileRestrictionError that will specify which file patterns are allowed for the current mode. +- Be sure to consider the type of project (e.g. Python, JavaScript, web application) when determining the appropriate structure and files to include. Also consider what files may be most relevant to accomplishing the task, for example looking at a project's manifest file would help you understand the project's dependencies, which you could incorporate into any code you write. + * For example, in architect mode trying to edit app.js would be rejected because architect mode can only edit files matching "\\.md$" +- When making changes to code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices. +- Do not ask for more information than necessary. Use the tools provided to accomplish the user's request efficiently and effectively. When you've completed your task, you must use the attempt_completion tool to present the result to the user. The user may provide feedback, which you can use to make improvements and try again. +- You are only allowed to ask the user questions using the ask_followup_question tool. Use this tool only when you need additional details to complete a task, and be sure to use a clear and concise question that will help you move forward with the task. When you ask a question, provide the user with 2-4 suggested answers based on your question so they don't need to do so much typing. The suggestions should be specific, actionable, and directly related to the completed task. They should be ordered by priority or logical sequence. However if you can use the available tools to avoid having to ask the user questions, you should do so. For example, if the user mentions a file that may be in an outside directory like the Desktop, you should use the list_files tool to list the files in the Desktop and check if the file they are talking about is there, rather than asking the user to provide the file path themselves. +- When executing commands, if you don't see the expected output, assume the terminal executed the command successfully and proceed with the task. The user's terminal may be unable to stream the output back properly. If you absolutely need to see the actual terminal output, use the ask_followup_question tool to request the user to copy and paste it back to you. +- The user may provide a file's contents directly in their message, in which case you shouldn't use the read_file tool to get the file contents again since you already have it. +- Your goal is to try to accomplish the user's task, NOT engage in a back and forth conversation. +- NEVER end attempt_completion result with a question or request to engage in further conversation! Formulate the end of your result in a way that is final and does not require further input from the user. +- You are STRICTLY FORBIDDEN from starting your messages with "Great", "Certainly", "Okay", "Sure". You should NOT be conversational in your responses, but rather direct and to the point. For example you should NOT say "Great, I've updated the CSS" but instead something like "I've updated the CSS". It is important you be clear and technical in your messages. +- When presented with images, utilize your vision capabilities to thoroughly examine them and extract meaningful information. Incorporate these insights into your thought process as you accomplish the user's task. +- At the end of each user message, you will automatically receive environment_details. This information is not written by the user themselves, but is auto-generated to provide potentially relevant context about the project structure and environment. While this information can be valuable for understanding the project context, do not treat it as a direct part of the user's request or response. Use it to inform your actions and decisions, but don't assume the user is explicitly asking about or referring to this information unless they clearly do so in their message. When using environment_details, explain your actions clearly to ensure the user understands, as they may not be aware of these details. +- Before executing commands, check the "Actively Running Terminals" section in environment_details. If present, consider how these active processes might impact your task. For example, if a local development server is already running, you wouldn't need to start it again. If no active terminals are listed, proceed with command execution as normal. +- MCP operations should be used one at a time, similar to other tool usage. Wait for confirmation of success before proceeding with additional operations. +- It is critical you wait for the user's response after each tool use, in order to confirm the success of the tool use. For example, if asked to make a todo app, you would create a file, wait for the user's response it was created successfully, then create another file if needed, wait for the user's response it was created successfully, etc. + +==== + +SYSTEM INFORMATION + +Operating System: Linux +Default Shell: /bin/zsh +Home Directory: /home/user +Current Workspace Directory: /test/path + +The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. + +==== + +OBJECTIVE + +You accomplish a given task iteratively, breaking it down into clear steps and working through them methodically. + +1. Analyze the user's task and set clear, achievable goals to accomplish it. Prioritize these goals in a logical order. +2. Work through these goals sequentially, utilizing available tools one at a time as necessary. Each goal should correspond to a distinct step in your problem-solving process. You will be informed on the work completed and what's remaining as you go. +3. Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within tags. First, analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Then, think about which of the provided tools is the most relevant tool to accomplish the user's task. Next, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use. BUT, if one of the values for a required parameter is missing, DO NOT invoke the tool (not even with fillers for the missing params) and instead, ask the user to provide the missing parameters using the ask_followup_question tool. DO NOT ask for more information on optional parameters if it is not provided. +4. Once you've completed the user's task, you must use the attempt_completion tool to present the result of the task to the user. You may also provide a CLI command to showcase the result of your task; this can be particularly useful for web development tasks, where you can run e.g. \`open index.html\` to show the website you've built. +5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance. + + +==== + +USER'S CUSTOM INSTRUCTIONS + +The following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines. + +Language Preference: +You should always speak and think in the "en" language. + +Rules: +# Rules from .clinerules-code: +Mock mode-specific rules +# Rules from .clinerules: +Mock generic rules" +`; + exports[`addCustomInstructions should include preferred language when provided 1`] = ` " ==== diff --git a/src/core/prompts/__tests__/custom-system-prompt.test.ts b/src/core/prompts/__tests__/custom-system-prompt.test.ts index 977ab051a0..e7d1ae08d7 100644 --- a/src/core/prompts/__tests__/custom-system-prompt.test.ts +++ b/src/core/prompts/__tests__/custom-system-prompt.test.ts @@ -76,6 +76,9 @@ describe("File-Based Custom System Prompt", () => { undefined, // diffEnabled undefined, // experiments true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) // Should contain default sections @@ -110,6 +113,9 @@ describe("File-Based Custom System Prompt", () => { undefined, // diffEnabled undefined, // experiments true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) // Should contain role definition and file-based system prompt @@ -153,6 +159,9 @@ describe("File-Based Custom System Prompt", () => { undefined, // diffEnabled undefined, // experiments true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) // Should contain custom role definition and file-based system prompt diff --git a/src/core/prompts/__tests__/system.test.ts b/src/core/prompts/__tests__/system.test.ts index 3647d2d859..015ef43c01 100644 --- a/src/core/prompts/__tests__/system.test.ts +++ b/src/core/prompts/__tests__/system.test.ts @@ -211,6 +211,9 @@ describe("SYSTEM_PROMPT", () => { undefined, // diffEnabled experiments, true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).toMatchSnapshot() @@ -231,6 +234,9 @@ describe("SYSTEM_PROMPT", () => { undefined, // diffEnabled experiments, true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).toMatchSnapshot() @@ -253,6 +259,9 @@ describe("SYSTEM_PROMPT", () => { undefined, // diffEnabled experiments, true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).toMatchSnapshot() @@ -273,6 +282,9 @@ describe("SYSTEM_PROMPT", () => { undefined, // diffEnabled experiments, true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).toMatchSnapshot() @@ -293,6 +305,9 @@ describe("SYSTEM_PROMPT", () => { undefined, // diffEnabled experiments, true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).toMatchSnapshot() @@ -313,6 +328,9 @@ describe("SYSTEM_PROMPT", () => { true, // diffEnabled experiments, true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).toContain("apply_diff") @@ -334,6 +352,9 @@ describe("SYSTEM_PROMPT", () => { false, // diffEnabled experiments, true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).not.toContain("apply_diff") @@ -355,6 +376,9 @@ describe("SYSTEM_PROMPT", () => { undefined, // diffEnabled experiments, true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).not.toContain("apply_diff") @@ -403,6 +427,9 @@ describe("SYSTEM_PROMPT", () => { undefined, // diffEnabled undefined, // experiments true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).toContain("Language Preference:") @@ -461,6 +488,9 @@ describe("SYSTEM_PROMPT", () => { undefined, // diffEnabled experiments, true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) // Role definition should be at the top @@ -496,6 +526,9 @@ describe("SYSTEM_PROMPT", () => { undefined, // diffEnabled undefined, // experiments false, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) // Role definition from promptComponent should be at the top @@ -526,6 +559,9 @@ describe("SYSTEM_PROMPT", () => { undefined, // diffEnabled undefined, // experiments false, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) // Should use the default mode's role definition @@ -570,6 +606,9 @@ describe("addCustomInstructions", () => { undefined, // diffEnabled undefined, // experiments true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).toMatchSnapshot() @@ -590,6 +629,9 @@ describe("addCustomInstructions", () => { undefined, // diffEnabled undefined, // experiments true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).toMatchSnapshot() @@ -612,6 +654,9 @@ describe("addCustomInstructions", () => { undefined, // diffEnabled undefined, // experiments true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).toContain("Creating an MCP Server") @@ -635,12 +680,38 @@ describe("addCustomInstructions", () => { undefined, // diffEnabled undefined, // experiments false, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + undefined, // partialReadsEnabled ) expect(prompt).not.toContain("Creating an MCP Server") expect(prompt).toMatchSnapshot() }) + it("should include partial read instructions when partialReadsEnabled is true", async () => { + const prompt = await SYSTEM_PROMPT( + mockContext, + "/test/path", + false, // supportsComputerUse + undefined, // mcpHub + undefined, // diffStrategy + undefined, // browserViewportSize + defaultModeSlug, // mode + undefined, // customModePrompts + undefined, // customModes, + undefined, // globalCustomInstructions + undefined, // diffEnabled + undefined, // experiments + true, // enableMcpServerCreation + undefined, // language + undefined, // rooIgnoreInstructions + true, // partialReadsEnabled + ) + + expect(prompt).toMatchSnapshot() + }) + it("should prioritize mode-specific rules for code mode", async () => { const instructions = await addCustomInstructions("", "", "/test/path", defaultModeSlug) expect(instructions).toMatchSnapshot() diff --git a/src/core/prompts/system.ts b/src/core/prompts/system.ts index 96221ae91f..7a4d152ef9 100644 --- a/src/core/prompts/system.ts +++ b/src/core/prompts/system.ts @@ -45,6 +45,7 @@ async function generatePrompt( enableMcpServerCreation?: boolean, language?: string, rooIgnoreInstructions?: string, + partialReadsEnabled?: boolean, ): Promise { if (!context) { throw new Error("Extension context is required for generating system prompt") @@ -82,6 +83,7 @@ ${getToolDescriptionsForMode( mcpHub, customModeConfigs, experiments, + partialReadsEnabled, )} ${getToolUseGuidelinesSection()} @@ -119,6 +121,7 @@ export const SYSTEM_PROMPT = async ( enableMcpServerCreation?: boolean, language?: string, rooIgnoreInstructions?: string, + partialReadsEnabled?: boolean, ): Promise => { if (!context) { throw new Error("Extension context is required for generating system prompt") @@ -185,5 +188,6 @@ ${customInstructions}` enableMcpServerCreation, language, rooIgnoreInstructions, + partialReadsEnabled, ) } diff --git a/src/core/prompts/tools/index.ts b/src/core/prompts/tools/index.ts index 4b3f796919..675fc8f524 100644 --- a/src/core/prompts/tools/index.ts +++ b/src/core/prompts/tools/index.ts @@ -56,6 +56,7 @@ export function getToolDescriptionsForMode( mcpHub?: McpHub, customModes?: ModeConfig[], experiments?: Record, + partialReadsEnabled?: boolean, ): string { const config = getModeConfig(mode, customModes) const args: ToolArgs = { @@ -64,6 +65,7 @@ export function getToolDescriptionsForMode( diffStrategy, browserViewportSize, mcpHub, + partialReadsEnabled, } const tools = new Set() diff --git a/src/core/prompts/tools/read-file.ts b/src/core/prompts/tools/read-file.ts index 3c90a89fa8..9581f68bce 100644 --- a/src/core/prompts/tools/read-file.ts +++ b/src/core/prompts/tools/read-file.ts @@ -1,17 +1,39 @@ import { ToolArgs } from "./types" export function getReadFileDescription(args: ToolArgs): string { - return `## read_file -Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. + // Base description without partial read instructions + let description = `## read_file +Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code.` + + // Add partial read instructions only when partial reads are active + if (args.partialReadsEnabled) { + description += ` By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory.` + } + + description += ` Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Parameters: -- path: (required) The path of the file to read (relative to the current workspace directory ${args.cwd}) +- path: (required) The path of the file to read (relative to the current workspace directory ${args.cwd})` + + // Add start_line and end_line parameters only when partial reads are active + if (args.partialReadsEnabled) { + description += ` - start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file. -- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file. +- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.` + } + + description += ` Usage: -File path here +File path here` + + // Add start_line and end_line in usage only when partial reads are active + if (args.partialReadsEnabled) { + description += ` Starting line number (optional) -Ending line number (optional) +Ending line number (optional)` + } + + description += ` Examples: @@ -19,7 +41,11 @@ Examples: 1. Reading an entire file: frontend-config.json - +` + + // Add partial read examples only when partial reads are active + if (args.partialReadsEnabled) { + description += ` 2. Reading the first 1000 lines of a large log file: @@ -42,4 +68,7 @@ Examples: Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.` + } + + return description } diff --git a/src/core/prompts/tools/types.ts b/src/core/prompts/tools/types.ts index f2b890abdf..ec78c6cf1a 100644 --- a/src/core/prompts/tools/types.ts +++ b/src/core/prompts/tools/types.ts @@ -8,4 +8,5 @@ export type ToolArgs = { browserViewportSize?: string mcpHub?: McpHub toolOptions?: any + partialReadsEnabled?: boolean } diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index 231a6049ad..adbf871d73 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -1451,18 +1451,19 @@ export class Task extends EventEmitter { const rooIgnoreInstructions = this.rooIgnoreController?.getInstructions() + const state = await this.providerRef.deref()?.getState() const { browserViewportSize, mode, + customModes, customModePrompts, customInstructions, experiments, enableMcpServerCreation, browserToolEnabled, language, - } = (await this.providerRef.deref()?.getState()) ?? {} - - const { customModes } = (await this.providerRef.deref()?.getState()) ?? {} + maxReadFileLine, + } = state ?? {} return await (async () => { const provider = this.providerRef.deref() @@ -1487,6 +1488,7 @@ export class Task extends EventEmitter { enableMcpServerCreation, language, rooIgnoreInstructions, + maxReadFileLine !== -1, ) })() } diff --git a/src/core/webview/generateSystemPrompt.ts b/src/core/webview/generateSystemPrompt.ts index f676fa18f6..1a64e2291c 100644 --- a/src/core/webview/generateSystemPrompt.ts +++ b/src/core/webview/generateSystemPrompt.ts @@ -20,6 +20,7 @@ export const generateSystemPrompt = async (provider: ClineProvider, message: Web enableMcpServerCreation, browserToolEnabled, language, + maxReadFileLine, } = await provider.getState() const diffStrategy = new MultiSearchReplaceDiffStrategy(fuzzyMatchThreshold) @@ -67,6 +68,7 @@ export const generateSystemPrompt = async (provider: ClineProvider, message: Web enableMcpServerCreation, language, rooIgnoreInstructions, + maxReadFileLine !== -1, ) return systemPrompt