mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 23:24:00 +03:00
fix(core): match absolute instruction globs across directories (#58749)
This commit is contained in:
committed by
GitHub
Unverified
parent
05bc77fbc6
commit
99845391b7
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user