From 53604c94131e9125ab68ae30d2f905f0a1378b9e Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Fri, 7 Feb 2025 10:51:22 -0800 Subject: [PATCH] Modify clineignore prompt --- src/core/Cline.ts | 8 +++++++- src/core/ignore/ClineIgnoreController.ts | 10 +++++----- src/core/prompts/system.ts | 12 +++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 5a520f1177..81d97a087f 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -1242,9 +1242,15 @@ export class Cline { } } + const clineIgnoreContent = this.clineIgnoreController.clineIgnoreContent + let clineIgnoreInstructions: string | undefined + if (clineIgnoreContent) { + clineIgnoreInstructions = `# .clineignore\n\nThe following is provided by a root-level .clineignore file where the user has specified files and directories that should not be accessed. When using list_files, you'll notice a \u{1F512} next to files that are blocked. Attempting to access the file's contents e.g. through read_file will result in an error.\n\n${clineIgnoreContent}` + } + if (settingsCustomInstructions || clineRulesFileInstructions) { // altering the system prompt mid-task will break the prompt cache, but in the grand scheme this will not change often so it's better to not pollute user messages with it the way we have to with - systemPrompt += addUserInstructions(settingsCustomInstructions, clineRulesFileInstructions) + systemPrompt += addUserInstructions(settingsCustomInstructions, clineRulesFileInstructions, clineIgnoreInstructions) } // If the previous API request's total token usage is close to the context window, truncate the conversation history to free up space for the new request diff --git a/src/core/ignore/ClineIgnoreController.ts b/src/core/ignore/ClineIgnoreController.ts index 0fb882e121..1ed8097382 100644 --- a/src/core/ignore/ClineIgnoreController.ts +++ b/src/core/ignore/ClineIgnoreController.ts @@ -13,12 +13,12 @@ export class ClineIgnoreController { private cwd: string private ignoreInstance: Ignore private disposables: vscode.Disposable[] = [] - clineIgnoreExists: boolean + clineIgnoreContent: string | undefined constructor(cwd: string) { this.cwd = cwd this.ignoreInstance = ignore() - this.clineIgnoreExists = false + this.clineIgnoreContent = undefined // Set up file watcher for .clineignore this.setupFileWatcher() } @@ -64,11 +64,11 @@ export class ClineIgnoreController { this.ignoreInstance = ignore() const ignorePath = path.join(this.cwd, ".clineignore") if (await fileExistsAtPath(ignorePath)) { - this.clineIgnoreExists = true const content = await fs.readFile(ignorePath, "utf8") + this.clineIgnoreContent = content this.ignoreInstance.add(content) } else { - this.clineIgnoreExists = false + this.clineIgnoreContent = undefined } } catch (error) { // Should never happen: reading file failed even though it exists @@ -83,7 +83,7 @@ export class ClineIgnoreController { */ validateAccess(filePath: string): boolean { // Always allow access if .clineignore does not exist - if (!this.clineIgnoreExists) { + if (!this.clineIgnoreContent) { return true } try { diff --git a/src/core/prompts/system.ts b/src/core/prompts/system.ts index d84391bed2..a9a13f1e90 100644 --- a/src/core/prompts/system.ts +++ b/src/core/prompts/system.ts @@ -957,20 +957,26 @@ You accomplish a given task iteratively, breaking it down into clear steps and w 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.` -export function addUserInstructions(settingsCustomInstructions?: string, clineRulesFileInstructions?: string) { +export function addUserInstructions( + settingsCustomInstructions?: string, + clineRulesFileInstructions?: string, + clineIgnoreInstructions?: string, +) { let customInstructions = "" if (settingsCustomInstructions) { customInstructions += settingsCustomInstructions + "\n\n" } if (clineRulesFileInstructions) { - customInstructions += clineRulesFileInstructions + customInstructions += clineRulesFileInstructions + "\n\n" + } + if (clineIgnoreInstructions) { + customInstructions += clineIgnoreInstructions } return ` ==== USER'S CUSTOM INSTRUCTIONS -The user may have a ".clineignore" file that blocks you from accessing certain directories and files. The paths blocked by this file will be indicated to you with a \u{1F512}, but you need not mention the \u{1F512}. For example, do NOT say things like 'I notice that {some_file}.ts is marked with \u{1F512} in the file list.' Instead, if you ever encounter an error about being blocked by the .clineignore, don't make a big deal about it, just move on without remarking on it. If you absolutely have to say something, just make a casual remark that you are 'blocked by the .clineignore'. Note that the .clineignore is also blocked. 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.