2026-03-12 18:16:22 +09:00
|
|
|
import { basename, dirname, join } from "node:path"
|
2026-05-09 00:26:23 +08:00
|
|
|
import { getOpenCodeConfigDirs } from "./opencode-config-dir"
|
2026-03-12 18:16:22 +09:00
|
|
|
import type { OpenCodeConfigDirOptions } from "./opencode-config-dir-types"
|
|
|
|
|
|
|
|
|
|
function getParentOpencodeConfigDir(configDir: string): string | null {
|
|
|
|
|
const parentDir = dirname(configDir)
|
|
|
|
|
if (basename(parentDir) !== "profiles") {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dirname(parentDir)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getOpenCodeCommandDirs(options: OpenCodeConfigDirOptions): string[] {
|
2026-05-09 00:26:23 +08:00
|
|
|
const configDirs = getOpenCodeConfigDirs(options)
|
2026-03-12 18:16:22 +09:00
|
|
|
return Array.from(
|
|
|
|
|
new Set([
|
2026-05-09 00:26:23 +08:00
|
|
|
...configDirs.flatMap((configDir) => {
|
|
|
|
|
const parentConfigDir = getParentOpencodeConfigDir(configDir)
|
|
|
|
|
return [
|
|
|
|
|
join(configDir, "commands"),
|
|
|
|
|
join(configDir, "command"),
|
|
|
|
|
...(parentConfigDir ? [join(parentConfigDir, "commands"), join(parentConfigDir, "command")] : []),
|
|
|
|
|
]
|
|
|
|
|
}),
|
2026-03-12 18:16:22 +09:00
|
|
|
])
|
|
|
|
|
)
|
|
|
|
|
}
|
2026-03-12 19:53:30 +09:00
|
|
|
|
|
|
|
|
export function getOpenCodeSkillDirs(options: OpenCodeConfigDirOptions): string[] {
|
2026-05-09 00:26:23 +08:00
|
|
|
const configDirs = getOpenCodeConfigDirs(options)
|
2026-03-12 19:53:30 +09:00
|
|
|
return Array.from(
|
|
|
|
|
new Set([
|
2026-05-09 00:26:23 +08:00
|
|
|
...configDirs.flatMap((configDir) => {
|
|
|
|
|
const parentConfigDir = getParentOpencodeConfigDir(configDir)
|
|
|
|
|
return [
|
|
|
|
|
join(configDir, "skills"),
|
|
|
|
|
join(configDir, "skill"),
|
|
|
|
|
...(parentConfigDir ? [join(parentConfigDir, "skills"), join(parentConfigDir, "skill")] : []),
|
|
|
|
|
]
|
|
|
|
|
}),
|
2026-03-12 19:53:30 +09:00
|
|
|
])
|
|
|
|
|
)
|
|
|
|
|
}
|