mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Added recursive AGENTS.md loading from child dirs
Co-authored-by: thdxr <thdxr@users.noreply.github.com>
This commit is contained in:
parent
736396fc70
commit
f261046361
2 changed files with 28 additions and 2 deletions
|
|
@ -55,8 +55,13 @@ export namespace SystemPrompt {
|
|||
const config = await Config.get()
|
||||
const found = []
|
||||
for (const item of CUSTOM_FILES) {
|
||||
const matches = await Filesystem.findUp(item, cwd, root)
|
||||
found.push(...matches.map((x) => Bun.file(x).text()))
|
||||
// Search upward from current directory
|
||||
const upMatches = await Filesystem.findUp(item, cwd, root)
|
||||
found.push(...upMatches.map((x) => Bun.file(x).text()))
|
||||
|
||||
// Search downward from current directory (limited depth to avoid performance issues)
|
||||
const downMatches = await Filesystem.findDown(item, cwd, 3)
|
||||
found.push(...downMatches.map((x) => Bun.file(x).text()))
|
||||
}
|
||||
found.push(
|
||||
Bun.file(path.join(Global.Path.config, "AGENTS.md"))
|
||||
|
|
|
|||
|
|
@ -64,4 +64,25 @@ export namespace Filesystem {
|
|||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export async function findDown(target: string, start: string, maxDepth: number = 3) {
|
||||
const result = []
|
||||
const glob = new Bun.Glob(`**/${target}`)
|
||||
try {
|
||||
for await (const match of glob.scan({
|
||||
cwd: start,
|
||||
onlyFiles: true,
|
||||
dot: true,
|
||||
})) {
|
||||
const fullPath = join(start, match)
|
||||
const depth = match.split('/').length - 1
|
||||
if (depth <= maxDepth) {
|
||||
result.push(fullPath)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Skip if glob fails
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue