diff --git a/packages/core/src/config/plugin/instruction.ts b/packages/core/src/config/plugin/instruction.ts index 133bf18ea60..406eaed10e6 100644 --- a/packages/core/src/config/plugin/instruction.ts +++ b/packages/core/src/config/plugin/instruction.ts @@ -98,10 +98,18 @@ export const Plugin = define({ const match = Effect.fn("ConfigInstructionPlugin.match")(function* (source: string) { const expanded = source.startsWith("~/") ? path.join(global.home, source.slice(2)) : source const options = { absolute: true, include: "file", dot: true } as const - if (path.isAbsolute(expanded)) + if (path.isAbsolute(expanded)) { + // Keep literal directories working as before. When no literal parent exists, treat + // the whole source as a glob (`~/notes/**/*.md`) with `/` separators. + const directory = path.dirname(expanded) + const hasLiteralParent = yield* fs.isDir(directory) return yield* fs - .scan(path.basename(expanded), { ...options, cwd: path.dirname(expanded) }) + .scan(hasLiteralParent ? path.basename(expanded) : expanded.replaceAll(path.sep, "/"), { + ...options, + ...(hasLiteralParent ? { cwd: directory } : {}), + }) .pipe(Effect.orElseSucceed(() => [] as string[])) + } if (project) return yield* fs.globUp(expanded, start, root) if (!discovery.global) return [] return yield* fs diff --git a/packages/core/test/instruction-discovery.test.ts b/packages/core/test/instruction-discovery.test.ts index f4908ba0088..289b0a5fee9 100644 --- a/packages/core/test/instruction-discovery.test.ts +++ b/packages/core/test/instruction-discovery.test.ts @@ -302,18 +302,23 @@ describe("ConfigInstructionPlugin.Plugin", () => { const second = path.join(project, "rules", "b.md") const absolute = path.join(tmp.path, "absolute.md") const homeFile = path.join(tmp.path, "home.md") + const noteTop = path.join(tmp.path, "notes", "guide.md") + const noteNested = path.join(tmp.path, "notes", "projects", "memory.md") const remote = "https://example.test/instructions.md" const requests: string[] = [] return Effect.gen(function* () { yield* Effect.promise(async () => { await fs.mkdir(path.dirname(first), { recursive: true }) await fs.mkdir(directory, { recursive: true }) + await fs.mkdir(path.dirname(noteNested), { recursive: true }) await Promise.all([ fs.writeFile(agents, "agents"), fs.writeFile(first, "first"), fs.writeFile(second, "second"), fs.writeFile(absolute, "absolute"), fs.writeFile(homeFile, "home"), + fs.writeFile(noteTop, "note top"), + fs.writeFile(noteNested, "note nested"), ]) }) @@ -327,6 +332,8 @@ describe("ConfigInstructionPlugin.Plugin", () => { `Instructions from: ${second}\nsecond`, `Instructions from: ${absolute}\nabsolute`, `Instructions from: ${homeFile}\nhome`, + `Instructions from: ${noteTop}\nnote top`, + `Instructions from: ${noteNested}\nnote nested`, `Instructions from: ${remote}\nremote`, ].join("\n\n"), ) @@ -347,6 +354,7 @@ describe("ConfigInstructionPlugin.Plugin", () => { "rules/*.md", absolute, "~/home.md", + "~/notes/**/*.md", remote, "missing.md", "https://example.test/missing.md",