2026-03-26 19:44:55 +09:00
|
|
|
import { checkForLegacyPluginEntry } from "./legacy-plugin-warning"
|
|
|
|
|
import { log } from "./logger"
|
2026-04-04 02:10:27 +09:00
|
|
|
import { migrateLegacyPluginEntry } from "./migrate-legacy-plugin-entry"
|
|
|
|
|
import { toCanonicalEntry } from "./plugin-entry-migrator"
|
2026-03-26 19:44:55 +09:00
|
|
|
import { LEGACY_PLUGIN_NAME, PLUGIN_NAME } from "./plugin-identity"
|
|
|
|
|
|
2026-04-04 19:52:25 +09:00
|
|
|
type LogLegacyPluginStartupWarningDeps = {
|
|
|
|
|
checkForLegacyPluginEntry?: typeof checkForLegacyPluginEntry
|
|
|
|
|
log?: typeof log
|
|
|
|
|
migrateLegacyPluginEntry?: typeof migrateLegacyPluginEntry
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function logLegacyPluginStartupWarning(deps: LogLegacyPluginStartupWarningDeps = {}): void {
|
|
|
|
|
const checkForLegacyPluginEntryFn = deps.checkForLegacyPluginEntry ?? checkForLegacyPluginEntry
|
|
|
|
|
const logFn = deps.log ?? log
|
|
|
|
|
const migrateLegacyPluginEntryFn = deps.migrateLegacyPluginEntry ?? migrateLegacyPluginEntry
|
|
|
|
|
|
|
|
|
|
const result = checkForLegacyPluginEntryFn()
|
2026-05-15 16:31:13 +09:00
|
|
|
if (!result.hasLegacyEntry || !result.configPath) {
|
2026-03-26 19:44:55 +09:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 15:40:04 +09:00
|
|
|
const suggestedEntries = result.legacyEntries.map(toCanonicalEntry)
|
|
|
|
|
|
2026-04-18 02:52:10 +09:00
|
|
|
logFn("[legacy-migration] Legacy plugin entry detected in OpenCode config", {
|
2026-03-26 19:44:55 +09:00
|
|
|
legacyEntries: result.legacyEntries,
|
2026-03-27 15:40:04 +09:00
|
|
|
suggestedEntries,
|
2026-03-26 19:44:55 +09:00
|
|
|
hasCanonicalEntry: result.hasCanonicalEntry,
|
|
|
|
|
})
|
2026-03-27 15:40:04 +09:00
|
|
|
|
|
|
|
|
console.warn(
|
|
|
|
|
`[oh-my-openagent] WARNING: Your opencode.json uses the legacy package name "${LEGACY_PLUGIN_NAME}".`
|
|
|
|
|
+ ` The package has been renamed to "${PLUGIN_NAME}".`
|
|
|
|
|
+ ` Attempting auto-migration...`,
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-15 16:31:13 +09:00
|
|
|
const migrated = migrateLegacyPluginEntryFn(result.configPath)
|
2026-03-27 15:40:04 +09:00
|
|
|
if (migrated) {
|
|
|
|
|
console.warn(`[oh-my-openagent] Auto-migrated opencode.json: ${result.legacyEntries.join(", ")} -> ${suggestedEntries.join(", ")}`)
|
|
|
|
|
} else {
|
|
|
|
|
console.warn(
|
|
|
|
|
`[oh-my-openagent] Could not auto-migrate. Please manually update your opencode.json:`
|
|
|
|
|
+ ` ${result.legacyEntries.map((e, i) => `"${e}" -> "${suggestedEntries[i]}"`).join(", ")}`,
|
|
|
|
|
)
|
|
|
|
|
}
|
2026-03-26 19:44:55 +09:00
|
|
|
}
|