Support loading by directory in .clinerules/ (#2156)

* Support loading by directory in .clinerules/

* Update src/utils/fs.ts

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* Update docs/prompting/README.md

* Add changeset

* Add tests of isDirectory

* Use relative path in instructions

* Remove log

---------

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-03-09 20:08:12 -07:00
1 parent 3a3943623b
commit 8909ee77fc
5 files changed
+88 -8

No files matched your search

+21 -1
View File
@@ -3,7 +3,7 @@ import { after, describe, it } from "mocha"
import * as os from "os"
import * as path from "path"
import "should"
import { createDirectoriesForFile, fileExistsAtPath } from "./fs"
import { createDirectoriesForFile, fileExistsAtPath, isDirectory } from "./fs"
describe("Filesystem Utilities", () => {
const tmpDir = path.join(os.tmpdir(), "cline-test-" + Math.random().toString(36).slice(2))
@@ -68,4 +68,24 @@ describe("Filesystem Utilities", () => {
exists.should.be.true()
})
})
describe("isDirectory", () => {
it("should return true for directories", async () => {
await fs.mkdir(tmpDir, { recursive: true })
const isDir = await isDirectory(tmpDir)
isDir.should.be.true()
})
it("should return false for files", async () => {
const testFile = path.join(tmpDir, "test.txt")
await fs.writeFile(testFile, "test")
const isDir = await isDirectory(testFile)
isDir.should.be.false()
})
it("should return false for non-existent paths", async () => {
const nonExistentPath = path.join(tmpDir, "does-not-exist")
const isDir = await isDirectory(nonExistentPath)
isDir.should.be.false()
})
})
})
+14
View File
@@ -45,3 +45,17 @@ export async function fileExistsAtPath(filePath: string): Promise<boolean> {
return false
}
}
/**
* Checks if the path is a directory
* @param filePath - The path to check.
* @returns A promise that resolves to true if the path is a directory, false otherwise.
*/
export async function isDirectory(filePath: string): Promise<boolean> {
try {
const stats = await fs.stat(filePath)
return stats.isDirectory()
} catch {
return false
}
}