Skip to content

Commit 8f582b7

Browse files
Apply PR #11581: fix: prevent duplicate AGENTS.md injection when reading instruction files
2 parents d1d7447 + 151d76d commit 8f582b7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/opencode/src/session/instruction.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export namespace InstructionPrompt {
7575
for (const file of FILES) {
7676
const matches = await Filesystem.findUp(file, Instance.directory, Instance.worktree)
7777
if (matches.length > 0) {
78-
matches.forEach((p) => paths.add(path.resolve(p)))
78+
matches.forEach((p) => {
79+
paths.add(path.resolve(p))
80+
})
7981
break
8082
}
8183
}
@@ -103,7 +105,9 @@ export namespace InstructionPrompt {
103105
}),
104106
).catch(() => [])
105107
: await resolveRelative(instruction)
106-
matches.forEach((p) => paths.add(path.resolve(p)))
108+
matches.forEach((p) => {
109+
paths.add(path.resolve(p))
110+
})
107111
}
108112
}
109113

@@ -168,11 +172,17 @@ export namespace InstructionPrompt {
168172
const already = loaded(messages)
169173
const results: { filepath: string; content: string }[] = []
170174

171-
let current = path.dirname(path.resolve(filepath))
175+
const target = path.resolve(filepath)
176+
let current = path.dirname(target)
172177
const root = path.resolve(Instance.directory)
173178

174179
while (current.startsWith(root)) {
175180
const found = await find(current)
181+
if (found === target) {
182+
if (current === root) break
183+
current = path.dirname(current)
184+
continue
185+
}
176186
if (found && !system.has(found) && !already.has(found) && !isClaimed(messageID, found)) {
177187
claim(messageID, found)
178188
const content = await Bun.file(found)

0 commit comments

Comments
 (0)