Apply PR #11581: fix: prevent duplicate AGENTS.md injection when reading instruction files

This commit is contained in:
opencode-agent[bot]
2026-02-01 14:06:39 +00:00

View File

@@ -75,7 +75,9 @@ export namespace InstructionPrompt {
for (const file of FILES) {
const matches = await Filesystem.findUp(file, Instance.directory, Instance.worktree)
if (matches.length > 0) {
matches.forEach((p) => paths.add(path.resolve(p)))
matches.forEach((p) => {
paths.add(path.resolve(p))
})
break
}
}
@@ -103,7 +105,9 @@ export namespace InstructionPrompt {
}),
).catch(() => [])
: await resolveRelative(instruction)
matches.forEach((p) => paths.add(path.resolve(p)))
matches.forEach((p) => {
paths.add(path.resolve(p))
})
}
}
@@ -168,11 +172,17 @@ export namespace InstructionPrompt {
const already = loaded(messages)
const results: { filepath: string; content: string }[] = []
let current = path.dirname(path.resolve(filepath))
const target = path.resolve(filepath)
let current = path.dirname(target)
const root = path.resolve(Instance.directory)
while (current.startsWith(root)) {
const found = await find(current)
if (found === target) {
if (current === root) break
current = path.dirname(current)
continue
}
if (found && !system.has(found) && !already.has(found) && !isClaimed(messageID, found)) {
claim(messageID, found)
const content = await Bun.file(found)