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