mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(core): ignore directories named AGENTS.md during instruction discovery (#52576)
This commit is contained in:
@@ -60,14 +60,17 @@ export const Plugin = define({
|
||||
})
|
||||
|
||||
const globalSource = Effect.fn("ConfigInstructionPlugin.globalSource")(function* () {
|
||||
if (!discovery.global) return []
|
||||
if (!discovery.global || !(yield* fs.isFile(globalFile))) return []
|
||||
const file = yield* read(globalFile)
|
||||
return file ? [file] : []
|
||||
})
|
||||
|
||||
const projectSource = Effect.fn("ConfigInstructionPlugin.projectSource")(function* () {
|
||||
if (!project) return []
|
||||
const walked = yield* Effect.forEach(yield* fs.up({ targets: ["AGENTS.md"], start, stop }), fs.resolve)
|
||||
const walked = yield* Effect.forEach(
|
||||
yield* fs.up({ targets: ["AGENTS.md"], start, stop, type: "file" }),
|
||||
fs.resolve,
|
||||
)
|
||||
const discovered = new Set(walked.filter((file) => discovery.global || file !== globalFile))
|
||||
const files = yield* Effect.forEach(discovered, read, { concurrency: "unbounded" })
|
||||
if (files.some((file) => file === undefined)) return Instructions.unavailable
|
||||
|
||||
@@ -94,6 +94,7 @@ export const Plugin = {
|
||||
targets: [FILENAME],
|
||||
start: result.content.type === "list-page" ? resolved : dirname(resolved),
|
||||
stop: root,
|
||||
type: "file",
|
||||
})
|
||||
const candidates = (yield* Effect.forEach(discovered, fs.resolve)).filter(
|
||||
(file) => !FSUtil.contains(dirname(file), root) && file !== resolved,
|
||||
|
||||
@@ -431,7 +431,7 @@ describe("ConfigInstructionPlugin.Plugin", () => {
|
||||
|
||||
it.effect("canonicalizes boundaries and honors project opt-out", () =>
|
||||
Effect.gen(function* () {
|
||||
const observed: { values: { targets: string[]; start: string; stop?: string }[] } = { values: [] }
|
||||
const observed: { values: FSUtil.UpOptions[] } = { values: [] }
|
||||
const observingFS = Layer.effect(
|
||||
FSUtil.Service,
|
||||
FSUtil.Service.pipe(
|
||||
@@ -487,7 +487,7 @@ describe("ConfigInstructionPlugin.Plugin", () => {
|
||||
)
|
||||
|
||||
const repo = path.resolve("/repo")
|
||||
expect(observed.values).toEqual([{ targets: ["AGENTS.md"], start: repo, stop: repo }])
|
||||
expect(observed.values).toEqual([{ targets: ["AGENTS.md"], start: repo, stop: repo, type: "file" }])
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -32,6 +32,8 @@ export namespace FSUtil {
|
||||
readonly start: string
|
||||
readonly stop?: string
|
||||
readonly mode?: "all" | "first"
|
||||
/** Only match regular files or directories (following symlinks). By default any existing path matches. */
|
||||
readonly type?: "file" | "directory"
|
||||
}
|
||||
|
||||
export interface Interface extends FileSystem.FileSystem {
|
||||
@@ -165,7 +167,13 @@ export namespace FSUtil {
|
||||
while (true) {
|
||||
for (const target of options.targets) {
|
||||
const search = join(current, target)
|
||||
if (yield* fs.exists(search)) {
|
||||
const found =
|
||||
options.type === "file"
|
||||
? yield* isFile(search)
|
||||
: options.type === "directory"
|
||||
? yield* isDir(search)
|
||||
: yield* fs.exists(search)
|
||||
if (found) {
|
||||
result.push(search)
|
||||
if (options.mode === "first") return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user