mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
cleaning up
This commit is contained in:
parent
f6e64ccb93
commit
fb613ef5c8
3 changed files with 6 additions and 64 deletions
|
|
@ -60,7 +60,6 @@ import { SYSTEM_PROMPT } from "./prompts/system"
|
|||
import { addUserInstructions } from "./prompts/system"
|
||||
import { OpenAiHandler } from "../api/providers/openai"
|
||||
import { ApiStream } from "../api/transform/stream"
|
||||
import { Logger } from "../services/logging/Logger"
|
||||
|
||||
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) ?? path.join(os.homedir(), "Desktop") // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution
|
||||
|
||||
|
|
@ -126,14 +125,10 @@ export class Cline {
|
|||
images?: string[],
|
||||
historyItem?: HistoryItem,
|
||||
) {
|
||||
Logger.log("initializing LLMAC")
|
||||
this.llmAccessController = new LLMFileAccessController(cwd)
|
||||
this.llmAccessController
|
||||
.initialize()
|
||||
.then(() => Logger.log("initialized"))
|
||||
.catch((error) => {
|
||||
console.error("Failed to initialize LLMFileAccessController:", error)
|
||||
})
|
||||
this.llmAccessController.initialize().catch((error) => {
|
||||
console.error("Failed to initialize LLMFileAccessController:", error)
|
||||
})
|
||||
this.providerRef = new WeakRef(provider)
|
||||
this.api = buildApiHandler(apiConfiguration)
|
||||
this.terminalManager = new TerminalManager()
|
||||
|
|
|
|||
|
|
@ -224,52 +224,6 @@ describe("LLMFileAccessController", () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe("File Watcher", () => {
|
||||
it("should update patterns when .clineignore is modified", async () => {
|
||||
// Initial state
|
||||
controller.validateAccess("test.log").should.be.true()
|
||||
|
||||
// Modify .clineignore
|
||||
await fs.writeFile(path.join(tempDir, ".clineignore"), "*.log")
|
||||
|
||||
// Wait for the next event loop tick to ensure file watcher processes the change
|
||||
await Promise.resolve()
|
||||
|
||||
// Check if the new pattern is applied
|
||||
controller.validateAccess("test.log").should.be.false()
|
||||
})
|
||||
|
||||
it("should reset to default patterns when .clineignore is deleted", async () => {
|
||||
// Initial state with .clineignore containing a pattern
|
||||
await fs.writeFile(path.join(tempDir, ".clineignore"), "*.log")
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
controller.validateAccess("test.log").should.be.false()
|
||||
|
||||
// Delete .clineignore
|
||||
await fs.unlink(path.join(tempDir, ".clineignore"))
|
||||
|
||||
// Wait for the next event loop tick to ensure file watcher processes the deletion
|
||||
await Promise.resolve()
|
||||
|
||||
// Should now allow previously ignored files
|
||||
controller.validateAccess("test.log").should.be.true()
|
||||
})
|
||||
|
||||
it("should handle .clineignore being recreated", async () => {
|
||||
// Delete existing .clineignore
|
||||
await fs.unlink(path.join(tempDir, ".clineignore"))
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
|
||||
// Create new .clineignore with different patterns
|
||||
await fs.writeFile(path.join(tempDir, ".clineignore"), "*.temp")
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
|
||||
// Check if new patterns are applied
|
||||
controller.validateAccess("file.temp").should.be.false()
|
||||
controller.validateAccess("test.log").should.be.true()
|
||||
})
|
||||
})
|
||||
|
||||
describe("Error Handling", () => {
|
||||
it("should handle invalid paths", async () => {
|
||||
// Test with an invalid path containing null byte
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { fileExistsAtPath } from "../../utils/fs"
|
|||
import fs from "fs/promises"
|
||||
import ignore, { Ignore } from "ignore"
|
||||
import * as vscode from "vscode"
|
||||
import { Logger } from "../logging/Logger"
|
||||
|
||||
/**
|
||||
* Controls LLM access to files by enforcing ignore patterns.
|
||||
|
|
@ -13,7 +12,7 @@ import { Logger } from "../logging/Logger"
|
|||
export class LLMFileAccessController {
|
||||
private cwd: string
|
||||
private ignoreInstance: Ignore
|
||||
private fileWatcher: vscode.FileSystemWatcher | undefined
|
||||
private fileWatcher: vscode.FileSystemWatcher | null
|
||||
private disposables: vscode.Disposable[] = []
|
||||
|
||||
/**
|
||||
|
|
@ -25,6 +24,7 @@ export class LLMFileAccessController {
|
|||
this.cwd = cwd
|
||||
this.ignoreInstance = ignore()
|
||||
this.ignoreInstance.add(LLMFileAccessController.DEFAULT_PATTERNS)
|
||||
this.fileWatcher = null
|
||||
|
||||
// Set up file watcher for .clineignore
|
||||
this.setupFileWatcher()
|
||||
|
|
@ -48,15 +48,12 @@ export class LLMFileAccessController {
|
|||
// Watch for changes and updates
|
||||
this.disposables.push(
|
||||
this.fileWatcher.onDidChange(() => {
|
||||
Logger.log("[LLMFileAccessController] .clineignore changed - loading custom patterns")
|
||||
this.loadCustomPatterns()
|
||||
}),
|
||||
this.fileWatcher.onDidCreate(() => {
|
||||
Logger.log("[LLMFileAccessController] .clineignore created - loading custom patterns")
|
||||
this.loadCustomPatterns()
|
||||
}),
|
||||
this.fileWatcher.onDidDelete(() => {
|
||||
Logger.log("[LLMFileAccessController] .clineignore deleted - resetting to default patterns")
|
||||
this.resetToDefaultPatterns()
|
||||
}),
|
||||
)
|
||||
|
|
@ -70,7 +67,6 @@ export class LLMFileAccessController {
|
|||
*/
|
||||
private async loadCustomPatterns(): Promise<void> {
|
||||
try {
|
||||
Logger.log("loading custom patterns.")
|
||||
const ignorePath = path.join(this.cwd, ".clineignore")
|
||||
if (await fileExistsAtPath(ignorePath)) {
|
||||
// Reset ignore instance to prevent duplicate patterns
|
||||
|
|
@ -81,11 +77,9 @@ export class LLMFileAccessController {
|
|||
.map((line) => line.trim())
|
||||
.filter((line) => line && !line.startsWith("#"))
|
||||
|
||||
Logger.log(`[LLMFileAccessController] Loading custom patterns: ${JSON.stringify(customPatterns)}`)
|
||||
this.ignoreInstance.add(customPatterns)
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.log(`[LLMFileAccessController] Error loading .clineignore: ${error}`)
|
||||
// Continue with default patterns
|
||||
}
|
||||
}
|
||||
|
|
@ -94,7 +88,6 @@ export class LLMFileAccessController {
|
|||
* Reset ignore patterns to defaults
|
||||
*/
|
||||
private resetToDefaultPatterns(): void {
|
||||
Logger.log("[LLMFileAccessController] Resetting to default patterns")
|
||||
this.ignoreInstance = ignore()
|
||||
this.ignoreInstance.add(LLMFileAccessController.DEFAULT_PATTERNS)
|
||||
}
|
||||
|
|
@ -149,6 +142,6 @@ export class LLMFileAccessController {
|
|||
dispose(): void {
|
||||
this.disposables.forEach((d) => d.dispose())
|
||||
this.disposables = []
|
||||
this.fileWatcher = undefined
|
||||
this.fileWatcher = null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue