fix: prefer canonical plugin config files
This commit is contained in:
@@ -177,6 +177,13 @@ export function loadPluginConfig(
|
||||
? userDetected.path
|
||||
: path.join(configDir, "oh-my-opencode.json");
|
||||
|
||||
if (userDetected.legacyPath) {
|
||||
log("Canonical plugin config detected alongside legacy config. Remove the legacy file to avoid confusion.", {
|
||||
canonicalPath: userDetected.path,
|
||||
legacyPath: userDetected.legacyPath,
|
||||
});
|
||||
}
|
||||
|
||||
// Auto-copy legacy config file to canonical name if needed
|
||||
if (userDetected.format !== "none" && path.basename(userDetected.path).startsWith(LEGACY_CONFIG_BASENAME)) {
|
||||
migrateLegacyConfigFile(userDetected.path);
|
||||
@@ -190,6 +197,13 @@ export function loadPluginConfig(
|
||||
? projectDetected.path
|
||||
: path.join(projectBasePath, "oh-my-opencode.json");
|
||||
|
||||
if (projectDetected.legacyPath) {
|
||||
log("Canonical plugin config detected alongside legacy config. Remove the legacy file to avoid confusion.", {
|
||||
canonicalPath: projectDetected.path,
|
||||
legacyPath: projectDetected.legacyPath,
|
||||
});
|
||||
}
|
||||
|
||||
// Auto-copy legacy project config file to canonical name if needed
|
||||
if (projectDetected.format !== "none" && path.basename(projectDetected.path).startsWith(LEGACY_CONFIG_BASENAME)) {
|
||||
migrateLegacyConfigFile(projectDetected.path);
|
||||
|
||||
@@ -2,6 +2,8 @@ import { existsSync, readFileSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import { parse, ParseError, printParseErrorCode } from "jsonc-parser"
|
||||
|
||||
import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "./plugin-identity"
|
||||
|
||||
export interface JsoncParseResult<T> {
|
||||
data: T | null
|
||||
errors: Array<{ message: string; offset: number; length: number }>
|
||||
@@ -66,15 +68,24 @@ export function detectConfigFile(basePath: string): {
|
||||
return { format: "none", path: jsonPath }
|
||||
}
|
||||
|
||||
const PLUGIN_CONFIG_NAMES = ["oh-my-opencode", "oh-my-openagent"] as const
|
||||
|
||||
export function detectPluginConfigFile(dir: string): {
|
||||
format: "json" | "jsonc" | "none"
|
||||
path: string
|
||||
legacyPath?: string
|
||||
} {
|
||||
for (const name of PLUGIN_CONFIG_NAMES) {
|
||||
const result = detectConfigFile(join(dir, name))
|
||||
if (result.format !== "none") return result
|
||||
const canonicalResult = detectConfigFile(join(dir, CONFIG_BASENAME))
|
||||
const legacyResult = detectConfigFile(join(dir, LEGACY_CONFIG_BASENAME))
|
||||
|
||||
if (canonicalResult.format !== "none") {
|
||||
return {
|
||||
...canonicalResult,
|
||||
legacyPath: legacyResult.format !== "none" ? legacyResult.path : undefined,
|
||||
}
|
||||
}
|
||||
return { format: "none", path: join(dir, PLUGIN_CONFIG_NAMES[0] + ".json") }
|
||||
|
||||
if (legacyResult.format !== "none") {
|
||||
return legacyResult
|
||||
}
|
||||
|
||||
return { format: "none", path: join(dir, `${CONFIG_BASENAME}.json`) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user