feat(shared): add findProjectOpencodePluginConfigFiles walker
Walks up the directory tree from a start directory looking for .opencode/oh-my-openagent.json[c] (or legacy basename) files. Returns detected paths in nearest-first order, optionally stopping at a caller-provided directory. Reuses detectPluginConfigFile so canonical/legacy basename detection, caching, and JSONC vs JSON precedence stay consistent with existing config loading. Foundation for #417 hierarchical config discovery.
This commit is contained in:
committed by
YeonGyu-Kim
parent
44216a538e
commit
01c8a2a927
@@ -2,6 +2,8 @@ import { execFileSync } from "node:child_process"
|
||||
import { existsSync, realpathSync } from "node:fs"
|
||||
import { dirname, join, resolve } from "node:path"
|
||||
|
||||
import { detectPluginConfigFile } from "./jsonc-parser"
|
||||
|
||||
const worktreePathCache = new Map<string, string | undefined>()
|
||||
|
||||
function normalizePath(path: string): string {
|
||||
@@ -114,3 +116,35 @@ export function findProjectOpencodeCommandDirs(startDirectory: string, stopDirec
|
||||
stopDirectory ?? detectWorktreePath(startDirectory),
|
||||
)
|
||||
}
|
||||
|
||||
export function findProjectOpencodePluginConfigFiles(
|
||||
startDirectory: string,
|
||||
stopDirectory?: string,
|
||||
): string[] {
|
||||
const paths: string[] = []
|
||||
const seen = new Set<string>()
|
||||
let currentDirectory = normalizePath(startDirectory)
|
||||
const resolvedStopDirectory = stopDirectory ? normalizePath(stopDirectory) : undefined
|
||||
|
||||
while (true) {
|
||||
const opencodeDirectory = join(currentDirectory, ".opencode")
|
||||
if (existsSync(opencodeDirectory)) {
|
||||
const detected = detectPluginConfigFile(opencodeDirectory)
|
||||
if (detected.format !== "none" && !seen.has(detected.path)) {
|
||||
seen.add(detected.path)
|
||||
paths.push(detected.path)
|
||||
}
|
||||
}
|
||||
|
||||
if (resolvedStopDirectory === currentDirectory) {
|
||||
return paths
|
||||
}
|
||||
|
||||
const parentDirectory = dirname(currentDirectory)
|
||||
if (parentDirectory === currentDirectory) {
|
||||
return paths
|
||||
}
|
||||
|
||||
currentDirectory = normalizePath(parentDirectory)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user