From 151d76db0f6d3e39faf7e89bdb2e4121779c045a Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 1 Feb 2026 17:29:15 +0900 Subject: [PATCH] fix: prevent duplicate AGENTS.md injection when reading instruction files When reading an AGENTS.md file directly, InstructionPrompt.resolve() would re-inject the same file as a system-reminder, causing duplicate 'Read/Loaded' log entries. Skip instruction files that match the file being read to prevent this duplication. --- packages/opencode/src/session/instruction.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/opencode/src/session/instruction.ts b/packages/opencode/src/session/instruction.ts index 723439a3fd..27a06612f0 100644 --- a/packages/opencode/src/session/instruction.ts +++ b/packages/opencode/src/session/instruction.ts @@ -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)