Skip to content

Commit 4fa4943

Browse files
authored
Revert "[clinerules] search clinerule in parent folders which make it easier to share within a github repo" (#1959)
Revert "[clinerules] search clinerule in parent folders which make it easier …" This reverts commit 2953bae.
1 parent fbc31c3 commit 4fa4943

File tree

4 files changed

+9
-83
lines changed

4 files changed

+9
-83
lines changed

src/core/prompts/sections/__tests__/custom-instructions.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,7 @@ describe("addCustomInstructions", () => {
106106
})
107107

108108
it("should combine all instruction types when provided", async () => {
109-
// Mock implementation to return different values based on the file path
110-
mockedFs.readFile.mockImplementation(((filePath: any) => {
111-
// For .clinerules-test-mode, return mode-specific rules
112-
if (filePath.toString().includes(".clinerules-test-mode")) {
113-
return Promise.resolve("mode specific rules")
114-
}
115-
// For any other read operation, return empty
116-
return Promise.reject({ code: "ENOENT" })
117-
}) as any)
109+
mockedFs.readFile.mockResolvedValue("mode specific rules")
118110

119111
const result = await addCustomInstructions(
120112
"mode instructions",

src/core/prompts/sections/custom-instructions.ts

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,12 @@ async function safeReadFile(filePath: string): Promise<string> {
1616
}
1717
}
1818

19-
async function findRuleInDirectory(dir: string, ruleFile: string): Promise<string> {
20-
const filePath = path.join(dir, ruleFile)
21-
const content = await safeReadFile(filePath)
22-
23-
if (content) {
24-
return content
25-
}
26-
27-
// Check if we've reached the root directory
28-
const parentDir = path.dirname(dir)
29-
if (parentDir === dir) {
30-
return ""
31-
}
32-
33-
// Recursively check parent directory
34-
return findRuleInDirectory(parentDir, ruleFile)
35-
}
36-
3719
export async function loadRuleFiles(cwd: string): Promise<string> {
3820
const ruleFiles = [".clinerules", ".cursorrules", ".windsurfrules"]
3921
let combinedRules = ""
4022

4123
for (const file of ruleFiles) {
42-
const content = await findRuleInDirectory(cwd, file)
24+
const content = await safeReadFile(path.join(cwd, file))
4325
if (content) {
4426
combinedRules += `\n# Rules from ${file}:\n${content}\n`
4527
}
@@ -48,17 +30,6 @@ export async function loadRuleFiles(cwd: string): Promise<string> {
4830
return combinedRules
4931
}
5032

51-
async function findCustomInstructionsFile(dir: string, filePattern: string): Promise<string> {
52-
// First try to find as a direct file
53-
const content = await findRuleInDirectory(dir, filePattern)
54-
if (content) {
55-
return content
56-
}
57-
58-
// If not found as a file, check if it's raw content
59-
return filePattern.trim()
60-
}
61-
6233
export async function addCustomInstructions(
6334
modeCustomInstructions: string,
6435
globalCustomInstructions: string,
@@ -83,16 +54,14 @@ export async function addCustomInstructions(
8354
)
8455
}
8556

86-
// Add global instructions first - try to find as file or use raw content
87-
const globalContent = await findCustomInstructionsFile(cwd, globalCustomInstructions)
88-
if (globalContent) {
89-
sections.push(`Global Instructions:\n${globalContent}`)
57+
// Add global instructions first
58+
if (typeof globalCustomInstructions === "string" && globalCustomInstructions.trim()) {
59+
sections.push(`Global Instructions:\n${globalCustomInstructions.trim()}`)
9060
}
9161

92-
// Add mode-specific instructions - try to find as file or use raw content
93-
const modeContent = await findCustomInstructionsFile(cwd, modeCustomInstructions)
94-
if (modeContent) {
95-
sections.push(`Mode-specific Instructions:\n${modeContent}`)
62+
// Add mode-specific instructions after
63+
if (typeof modeCustomInstructions === "string" && modeCustomInstructions.trim()) {
64+
sections.push(`Mode-specific Instructions:\n${modeCustomInstructions.trim()}`)
9665
}
9766

9867
// Add rules - include both mode-specific and generic rules if they exist

src/integrations/misc/open-file.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,6 @@ export async function openImage(dataUri: string) {
2323
interface OpenFileOptions {
2424
create?: boolean
2525
content?: string
26-
searchParents?: boolean
27-
startFromWorkspace?: boolean
28-
}
29-
30-
async function findFileInParentDirs(searchPath: string, fileName: string): Promise<string | null> {
31-
try {
32-
const fullPath = path.join(searchPath, fileName)
33-
await vscode.workspace.fs.stat(vscode.Uri.file(fullPath))
34-
return fullPath
35-
} catch {
36-
const parentDir = path.dirname(searchPath)
37-
if (parentDir === searchPath) {
38-
// Hit root
39-
return null
40-
}
41-
return findFileInParentDirs(parentDir, fileName)
42-
}
4326
}
4427

4528
export async function openFile(filePath: string, options: OpenFileOptions = {}) {
@@ -51,17 +34,7 @@ export async function openFile(filePath: string, options: OpenFileOptions = {})
5134
}
5235

5336
// If path starts with ./, resolve it relative to workspace root
54-
let fullPath = filePath.startsWith("./") ? path.join(workspaceRoot, filePath.slice(2)) : filePath
55-
56-
// Handle recursive search
57-
if (options.searchParents) {
58-
const startDir = options.startFromWorkspace ? workspaceRoot : path.dirname(fullPath)
59-
const fileName = path.basename(filePath)
60-
const foundPath = await findFileInParentDirs(startDir, fileName)
61-
if (foundPath) {
62-
fullPath = foundPath
63-
}
64-
}
37+
const fullPath = filePath.startsWith("./") ? path.join(workspaceRoot, filePath.slice(2)) : filePath
6538

6639
const uri = vscode.Uri.file(fullPath)
6740

webview-ui/src/components/prompts/PromptsView.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
462462
values: {
463463
create: true,
464464
content: JSON.stringify({ customModes: [] }, null, 2),
465-
searchParents: true,
466-
startFromWorkspace: true,
467465
},
468466
})
469467
setShowConfigMenu(false)
@@ -810,8 +808,6 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
810808
values: {
811809
create: true,
812810
content: "",
813-
searchParents: true,
814-
startFromWorkspace: true,
815811
},
816812
})
817813
}}
@@ -919,8 +915,6 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
919915
values: {
920916
create: true,
921917
content: "",
922-
searchParents: true,
923-
startFromWorkspace: true,
924918
},
925919
})
926920
}}
@@ -976,8 +970,6 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
976970
values: {
977971
create: true,
978972
content: "",
979-
searchParents: true,
980-
startFromWorkspace: true,
981973
},
982974
})
983975
}

0 commit comments

Comments
 (0)