Skip to content

Commit 4885782

Browse files
committed
Issue fixed.
1 parent 39d0f68 commit 4885782

File tree

3 files changed

+75
-25
lines changed

3 files changed

+75
-25
lines changed

src/core/mentions/index.ts

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export async function parseMentions(
5050
cwd: string,
5151
urlContentFetcher: UrlContentFetcher,
5252
fileContextTracker?: FileContextTracker,
53+
rooIgnoreController?: any,
54+
showRooIgnoredFiles: boolean = true,
5355
): Promise<string> {
5456
const mentions: Set<string> = new Set()
5557
let parsedText = text.replace(mentionRegexGlobal, (match, mention) => {
@@ -102,12 +104,11 @@ export async function parseMentions(
102104
} else if (mention.startsWith("/")) {
103105
const mentionPath = mention.slice(1)
104106
try {
105-
const content = await getFileOrFolderContent(mentionPath, cwd)
107+
const content = await getFileOrFolderContent(mentionPath, cwd, rooIgnoreController, showRooIgnoredFiles)
106108
if (mention.endsWith("/")) {
107109
parsedText += `\n\n<folder_content path="${mentionPath}">\n${content}\n</folder_content>`
108110
} else {
109111
parsedText += `\n\n<file_content path="${mentionPath}">\n${content}\n</file_content>`
110-
// Track that this file was mentioned and its content was included
111112
if (fileContextTracker) {
112113
await fileContextTracker.trackFileContext(mentionPath, "file_mentioned")
113114
}
@@ -161,15 +162,22 @@ export async function parseMentions(
161162
return parsedText
162163
}
163164

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

169174
try {
170175
const stats = await fs.stat(absPath)
171176

172177
if (stats.isFile()) {
178+
if (rooIgnoreController && !rooIgnoreController.validateAccess(absPath)) {
179+
return `(File ${mentionPath} is ignored by .rooignore)`
180+
}
173181
try {
174182
const content = await extractTextFromFile(absPath)
175183
return content
@@ -180,33 +188,51 @@ async function getFileOrFolderContent(mentionPath: string, cwd: string): Promise
180188
const entries = await fs.readdir(absPath, { withFileTypes: true })
181189
let folderContent = ""
182190
const fileContentPromises: Promise<string | undefined>[] = []
183-
entries.forEach((entry, index) => {
191+
const LOCK_SYMBOL = "🔒"
192+
193+
for (let index = 0; index < entries.length; index++) {
194+
const entry = entries[index]
184195
const isLast = index === entries.length - 1
185196
const linePrefix = isLast ? "└── " : "├── "
197+
const entryPath = path.join(absPath, entry.name)
198+
199+
let isIgnored = false
200+
if (rooIgnoreController) {
201+
isIgnored = !rooIgnoreController.validateAccess(entryPath)
202+
}
203+
204+
if (isIgnored && !showRooIgnoredFiles) {
205+
continue
206+
}
207+
208+
const displayName = isIgnored ? `${LOCK_SYMBOL} ${entry.name}` : entry.name
209+
186210
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) {
211+
folderContent += `${linePrefix}${displayName}\n`
212+
if (!isIgnored) {
213+
const filePath = path.join(mentionPath, entry.name)
214+
const absoluteFilePath = path.resolve(absPath, entry.name)
215+
fileContentPromises.push(
216+
(async () => {
217+
try {
218+
const isBinary = await isBinaryFile(absoluteFilePath).catch(() => false)
219+
if (isBinary) {
220+
return undefined
221+
}
222+
const content = await extractTextFromFile(absoluteFilePath)
223+
return `<file_content path="${filePath.toPosix()}">\n${content}\n</file_content>`
224+
} catch (error) {
195225
return undefined
196226
}
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-
)
227+
})(),
228+
)
229+
}
204230
} else if (entry.isDirectory()) {
205-
folderContent += `${linePrefix}${entry.name}/\n`
231+
folderContent += `${linePrefix}${displayName}/\n`
206232
} else {
207-
folderContent += `${linePrefix}${entry.name}\n`
233+
folderContent += `${linePrefix}${displayName}\n`
208234
}
209-
})
235+
}
210236
const fileContents = (await Promise.all(fileContentPromises)).filter((content) => content)
211237
return `${folderContent}\n${fileContents.join("\n\n")}`.trim()
212238
} 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
@@ -1096,11 +1096,15 @@ export class Task extends EventEmitter<ClineEvents> {
10961096
}),
10971097
)
10981098

1099+
const { showRooIgnoredFiles = true } = (await this.providerRef.deref()?.getState()) ?? {}
1100+
10991101
const parsedUserContent = await processUserContentMentions({
11001102
userContent,
11011103
cwd: this.cwd,
11021104
urlContentFetcher: this.urlContentFetcher,
11031105
fileContextTracker: this.fileContextTracker,
1106+
rooIgnoreController: this.rooIgnoreController,
1107+
showRooIgnoredFiles,
11041108
})
11051109

11061110
const environmentDetails = await getEnvironmentDetails(this, includeFileDetails)

0 commit comments

Comments
 (0)