summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packages/opencode/src/session/instruction.ts17
-rw-r--r--packages/opencode/test/session/instruction.test.ts20
2 files changed, 31 insertions, 6 deletions
diff --git a/packages/opencode/src/session/instruction.ts b/packages/opencode/src/session/instruction.ts
index 723439a3f..65ca1e9bb 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,12 +172,14 @@ 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)) {
+ while (current.startsWith(root) && current !== root) {
const found = await find(current)
- if (found && !system.has(found) && !already.has(found) && !isClaimed(messageID, found)) {
+
+ if (found && found !== target && !system.has(found) && !already.has(found) && !isClaimed(messageID, found)) {
claim(messageID, found)
const content = await Bun.file(found)
.text()
@@ -182,7 +188,6 @@ export namespace InstructionPrompt {
results.push({ filepath: found, content: "Instructions from: " + found + "\n" + content })
}
}
- if (current === root) break
current = path.dirname(current)
}
diff --git a/packages/opencode/test/session/instruction.test.ts b/packages/opencode/test/session/instruction.test.ts
index 67719fa33..4d57e92a2 100644
--- a/packages/opencode/test/session/instruction.test.ts
+++ b/packages/opencode/test/session/instruction.test.ts
@@ -47,4 +47,24 @@ describe("InstructionPrompt.resolve", () => {
},
})
})
+
+ test("doesn't reload AGENTS.md when reading it directly", async () => {
+ await using tmp = await tmpdir({
+ init: async (dir) => {
+ await Bun.write(path.join(dir, "subdir", "AGENTS.md"), "# Subdir Instructions")
+ await Bun.write(path.join(dir, "subdir", "nested", "file.ts"), "const x = 1")
+ },
+ })
+ await Instance.provide({
+ directory: tmp.path,
+ fn: async () => {
+ const filepath = path.join(tmp.path, "subdir", "AGENTS.md")
+ const system = await InstructionPrompt.systemPaths()
+ expect(system.has(filepath)).toBe(false)
+
+ const results = await InstructionPrompt.resolve([], filepath, "test-message-2")
+ expect(results).toEqual([])
+ },
+ })
+ })
})