diff --git a/src/plugin-config.ts b/src/plugin-config.ts index 78350cfda..b7e8ff72a 100644 --- a/src/plugin-config.ts +++ b/src/plugin-config.ts @@ -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); diff --git a/src/shared/jsonc-parser.ts b/src/shared/jsonc-parser.ts index 7431ad9a2..66c886310 100644 --- a/src/shared/jsonc-parser.ts +++ b/src/shared/jsonc-parser.ts @@ -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 { 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`) } }