mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 01:34:22 +01:00
tweak(config): make markdown agent files in subfolder discoverable .opencode/agent/some-folder/*.md (#1999)
This commit is contained in:
committed by
GitHub
parent
daea79c0d4
commit
1e204c23b9
@@ -44,16 +44,31 @@ export namespace Config {
|
|||||||
|
|
||||||
result.agent = result.agent || {}
|
result.agent = result.agent || {}
|
||||||
const markdownAgents = [
|
const markdownAgents = [
|
||||||
...(await Filesystem.globUp("agent/*.md", Global.Path.config, Global.Path.config)),
|
...(await Filesystem.globUp("agent/**/*.md", Global.Path.config, Global.Path.config)),
|
||||||
...(await Filesystem.globUp(".opencode/agent/*.md", app.path.cwd, app.path.root)),
|
...(await Filesystem.globUp(".opencode/agent/**/*.md", app.path.cwd, app.path.root)),
|
||||||
]
|
]
|
||||||
for (const item of markdownAgents) {
|
for (const item of markdownAgents) {
|
||||||
const content = await Bun.file(item).text()
|
const content = await Bun.file(item).text()
|
||||||
const md = matter(content)
|
const md = matter(content)
|
||||||
if (!md.data) continue
|
if (!md.data) continue
|
||||||
|
|
||||||
|
// Extract relative path from agent folder for nested agents
|
||||||
|
let agentName = path.basename(item, ".md")
|
||||||
|
const agentFolderPath = item.includes("/.opencode/agent/")
|
||||||
|
? item.split("/.opencode/agent/")[1]
|
||||||
|
: item.includes("/agent/")
|
||||||
|
? item.split("/agent/")[1]
|
||||||
|
: agentName + ".md"
|
||||||
|
|
||||||
|
// If agent is in a subfolder, include folder path in name
|
||||||
|
if (agentFolderPath.includes("/")) {
|
||||||
|
const relativePath = agentFolderPath.replace(".md", "")
|
||||||
|
const pathParts = relativePath.split("/")
|
||||||
|
agentName = pathParts.slice(0, -1).join("/").toUpperCase() + "/" + pathParts[pathParts.length - 1].toUpperCase()
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
name: path.basename(item, ".md"),
|
name: agentName,
|
||||||
...md.data,
|
...md.data,
|
||||||
prompt: md.content.trim(),
|
prompt: md.content.trim(),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user