Skip to content

Commit aa62654

Browse files
@Directory not respecting .rooIgnore Fix (#4075)
* Issue fixed. * Update src/core/mentions/index.ts Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * Update index.ts --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
1 parent 70e753e commit aa62654

File tree

3 files changed

+77
-25
lines changed

3 files changed

+77
-25
lines changed

src/core/mentions/index.ts

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { UrlContentFetcher } from "../../services/browser/UrlContentFetcher"
1717

1818
import { FileContextTracker } from "../context-tracking/FileContextTracker"
1919

20+
import { RooIgnoreController } from "../ignore/RooIgnoreController"
21+
2022
export async function openMention(mention?: string): Promise<void> {
2123
if (!mention) {
2224
return
@@ -50,6 +52,8 @@ export async function parseMentions(
5052
cwd: string,
5153
urlContentFetcher: UrlContentFetcher,
5254
fileContextTracker?: FileContextTracker,
55+
rooIgnoreController?: RooIgnoreController,
56+
showRooIgnoredFiles: boolean = true,
5357
): Promise<string> {
5458
const mentions: Set<string> = new Set()
5559
let parsedText = text.replace(mentionRegexGlobal, (match, mention) => {
@@ -102,12 +106,11 @@ export async function parseMentions(
102106
} else if (mention.startsWith("/")) {
103107
const mentionPath = mention.slice(1)
104108
try {
105-
const content = await getFileOrFolderContent(mentionPath, cwd)
109+
const content = await getFileOrFolderContent(mentionPath, cwd, rooIgnoreController, showRooIgnoredFiles)
106110
if (mention.endsWith("/")) {
107111
parsedText += `\n\n<folder_content path="${mentionPath}">\n${content}\n</folder_content>`
108112
} else {
109113
parsedText += `\n\n<file_content path="${mentionPath}">\n${content}\n</file_content>`
110-
// Track that this file was mentioned and its content was included
111114
if (fileContextTracker) {
112115
await fileContextTracker.trackFileContext(mentionPath, "file_mentioned")
113116
}
@@ -161,15 +164,22 @@ export async function parseMentions(
161164
return parsedText
162165
}
163166

164-
async function getFileOrFolderContent(mentionPath: string, cwd: string): Promise<string> {
165-
// Unescape spaces in the path before resolving it
167+
async function getFileOrFolderContent(
168+
mentionPath: string,
169+
cwd: string,
170+
rooIgnoreController?: any,
171+
showRooIgnoredFiles: boolean = true,
172+
): Promise<string> {
166173
const unescapedPath = unescapeSpaces(mentionPath)
167174
const absPath = path.resolve(cwd, unescapedPath)
168175

169176
try {
170177
const stats = await fs.stat(absPath)
171178

172179
if (stats.isFile()) {
180+
if (rooIgnoreController && !rooIgnoreController.validateAccess(absPath)) {
181+
return `(File ${mentionPath} is ignored by .rooignore)`
182+
}
173183
try {
174184
const content = await extractTextFromFile(absPath)
175185
return content
@@ -180,33 +190,51 @@ async function getFileOrFolderContent(mentionPath: string, cwd: string): Promise
180190
const entries = await fs.readdir(absPath, { withFileTypes: true })
181191
let folderContent = ""
182192
const fileContentPromises: Promise<string | undefined>[] = []
183-
entries.forEach((entry, index) => {
193+
const LOCK_SYMBOL = "🔒"
194+
195+
for (let index = 0; index < entries.length; index++) {
196+
const entry = entries[index]
184197
const isLast = index === entries.length - 1
185198
const linePrefix = isLast ? "└── " : "├── "
199+
const entryPath = path.join(absPath, entry.name)
200+
201+
let isIgnored = false
202+
if (rooIgnoreController) {
203+
isIgnored = !rooIgnoreController.validateAccess(entryPath)
204+
}
205+
206+
if (isIgnored && !showRooIgnoredFiles) {
207+
continue
208+
}
209+
210+
const displayName = isIgnored ? `${LOCK_SYMBOL} ${entry.name}` : entry.name
211+
186212
if (entry.isFile()) {
187-
folderContent += `${linePrefix}${entry.name}\n`
188-
const filePath = path.join(mentionPath, entry.name)
189-
const absoluteFilePath = path.resolve(absPath, entry.name)
190-
fileContentPromises.push(
191-
(async () => {
192-
try {
193-
const isBinary = await isBinaryFile(absoluteFilePath).catch(() => false)
194-
if (isBinary) {
213+
folderContent += `${linePrefix}${displayName}\n`
214+
if (!isIgnored) {
215+
const filePath = path.join(mentionPath, entry.name)
216+
const absoluteFilePath = path.resolve(absPath, entry.name)
217+
fileContentPromises.push(
218+
(async () => {
219+
try {
220+
const isBinary = await isBinaryFile(absoluteFilePath).catch(() => false)
221+
if (isBinary) {
222+
return undefined
223+
}
224+
const content = await extractTextFromFile(absoluteFilePath)
225+
return `<file_content path="${filePath.toPosix()}">\n${content}\n</file_content>`
226+
} catch (error) {
195227
return undefined
196228
}
197-
const content = await extractTextFromFile(absoluteFilePath)
198-
return `<file_content path="${filePath.toPosix()}">\n${content}\n</file_content>`
199-
} catch (error) {
200-
return undefined
201-
}
202-
})(),
203-
)
229+
})(),
230+
)
231+
}
204232
} else if (entry.isDirectory()) {
205-
folderContent += `${linePrefix}${entry.name}/\n`
233+
folderContent += `${linePrefix}${displayName}/\n`
206234
} else {
207-
folderContent += `${linePrefix}${entry.name}\n`
235+
folderContent += `${linePrefix}${displayName}\n`
208236
}
209-
})
237+
}
210238
const fileContents = (await Promise.all(fileContentPromises)).filter((content) => content)
211239
return `${folderContent}\n${fileContents.join("\n\n")}`.trim()
212240
} else {

src/core/mentions/processUserContentMentions.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ export async function processUserContentMentions({
1111
cwd,
1212
urlContentFetcher,
1313
fileContextTracker,
14+
rooIgnoreController,
15+
showRooIgnoredFiles = true,
1416
}: {
1517
userContent: Anthropic.Messages.ContentBlockParam[]
1618
cwd: string
1719
urlContentFetcher: UrlContentFetcher
1820
fileContextTracker: FileContextTracker
21+
rooIgnoreController?: any
22+
showRooIgnoredFiles?: boolean
1923
}) {
2024
// Process userContent array, which contains various block types:
2125
// TextBlockParam, ImageBlockParam, ToolUseBlockParam, and ToolResultBlockParam.
@@ -35,7 +39,14 @@ export async function processUserContentMentions({
3539
if (shouldProcessMentions(block.text)) {
3640
return {
3741
...block,
38-
text: await parseMentions(block.text, cwd, urlContentFetcher, fileContextTracker),
42+
text: await parseMentions(
43+
block.text,
44+
cwd,
45+
urlContentFetcher,
46+
fileContextTracker,
47+
rooIgnoreController,
48+
showRooIgnoredFiles,
49+
),
3950
}
4051
}
4152

@@ -45,7 +56,14 @@ export async function processUserContentMentions({
4556
if (shouldProcessMentions(block.content)) {
4657
return {
4758
...block,
48-
content: await parseMentions(block.content, cwd, urlContentFetcher, fileContextTracker),
59+
content: await parseMentions(
60+
block.content,
61+
cwd,
62+
urlContentFetcher,
63+
fileContextTracker,
64+
rooIgnoreController,
65+
showRooIgnoredFiles,
66+
),
4967
}
5068
}
5169

@@ -61,6 +79,8 @@ export async function processUserContentMentions({
6179
cwd,
6280
urlContentFetcher,
6381
fileContextTracker,
82+
rooIgnoreController,
83+
showRooIgnoredFiles,
6484
),
6585
}
6686
}

src/core/task/Task.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,11 +1107,15 @@ export class Task extends EventEmitter<ClineEvents> {
11071107
}),
11081108
)
11091109

1110+
const { showRooIgnoredFiles = true } = (await this.providerRef.deref()?.getState()) ?? {}
1111+
11101112
const parsedUserContent = await processUserContentMentions({
11111113
userContent,
11121114
cwd: this.cwd,
11131115
urlContentFetcher: this.urlContentFetcher,
11141116
fileContextTracker: this.fileContextTracker,
1117+
rooIgnoreController: this.rooIgnoreController,
1118+
showRooIgnoredFiles,
11151119
})
11161120

11171121
const environmentDetails = await getEnvironmentDetails(this, includeFileDetails)

0 commit comments

Comments
 (0)