Skip to content

Commit 0f9f0a9

Browse files
authored
fix(core): ignore directories named AGENTS.md during instruction discovery (#52576)
1 parent f9e61fd commit 0f9f0a9

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎packages/core/src/config/plugin/instruction.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@ export const Plugin = define({
6060
})
6161

6262
const globalSource = Effect.fn("ConfigInstructionPlugin.globalSource")(function* () {
63-
if (!discovery.global) return []
63+
if (!discovery.global || !(yield* fs.isFile(globalFile))) return []
6464
const file = yield* read(globalFile)
6565
return file ? [file] : []
6666
})
6767

6868
const projectSource = Effect.fn("ConfigInstructionPlugin.projectSource")(function* () {
6969
if (!project) return []
70-
const walked = yield* Effect.forEach(yield* fs.up({ targets: ["AGENTS.md"], start, stop }), fs.resolve)
70+
const walked = yield* Effect.forEach(
71+
yield* fs.up({ targets: ["AGENTS.md"], start, stop, type: "file" }),
72+
fs.resolve,
73+
)
7174
const discovered = new Set(walked.filter((file) => discovery.global || file !== globalFile))
7275
const files = yield* Effect.forEach(discovered, read, { concurrency: "unbounded" })
7376
if (files.some((file) => file === undefined)) return Instructions.unavailable

‎packages/core/src/tool/plugin/read.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const Plugin = {
9494
targets: [FILENAME],
9595
start: result.content.type === "list-page" ? resolved : dirname(resolved),
9696
stop: root,
97+
type: "file",
9798
})
9899
const candidates = (yield* Effect.forEach(discovered, fs.resolve)).filter(
99100
(file) => !FSUtil.contains(dirname(file), root) && file !== resolved,

‎packages/core/test/instruction-discovery.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ describe("ConfigInstructionPlugin.Plugin", () => {
431431

432432
it.effect("canonicalizes boundaries and honors project opt-out", () =>
433433
Effect.gen(function* () {
434-
const observed: { values: { targets: string[]; start: string; stop?: string }[] } = { values: [] }
434+
const observed: { values: FSUtil.UpOptions[] } = { values: [] }
435435
const observingFS = Layer.effect(
436436
FSUtil.Service,
437437
FSUtil.Service.pipe(
@@ -487,7 +487,7 @@ describe("ConfigInstructionPlugin.Plugin", () => {
487487
)
488488

489489
const repo = path.resolve("/repo")
490-
expect(observed.values).toEqual([{ targets: ["AGENTS.md"], start: repo, stop: repo }])
490+
expect(observed.values).toEqual([{ targets: ["AGENTS.md"], start: repo, stop: repo, type: "file" }])
491491
}),
492492
)
493493
})

‎packages/util/src/fs-util.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export namespace FSUtil {
3232
readonly start: string
3333
readonly stop?: string
3434
readonly mode?: "all" | "first"
35+
/** Only match regular files or directories (following symlinks). By default any existing path matches. */
36+
readonly type?: "file" | "directory"
3537
}
3638

3739
export interface Interface extends FileSystem.FileSystem {
@@ -165,7 +167,13 @@ export namespace FSUtil {
165167
while (true) {
166168
for (const target of options.targets) {
167169
const search = join(current, target)
168-
if (yield* fs.exists(search)) {
170+
const found =
171+
options.type === "file"
172+
? yield* isFile(search)
173+
: options.type === "directory"
174+
? yield* isDir(search)
175+
: yield* fs.exists(search)
176+
if (found) {
169177
result.push(search)
170178
if (options.mode === "first") return result
171179
}

0 commit comments

Comments
 (0)