fix(#2823): auto-migrate legacy plugin name and warn users at startup
- logLegacyPluginStartupWarning now emits console.warn (visible to user, not just log file) when oh-my-opencode is detected in opencode.json - Auto-migrates opencode.json plugin entry from oh-my-opencode to oh-my-openagent (with backup) - plugin-config.ts: add console.warn when loading legacy config filename - test: 10 tests covering migration, console output, edge cases
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
|
||||
import { checkForLegacyPluginEntry } from "../../shared/legacy-plugin-warning"
|
||||
import { log } from "../../shared/logger"
|
||||
import { LEGACY_PLUGIN_NAME, PLUGIN_NAME } from "../../shared/plugin-identity"
|
||||
import { autoMigrateLegacyPluginEntry } from "./auto-migrate"
|
||||
|
||||
export function createLegacyPluginToastHook(ctx: PluginInput) {
|
||||
let fired = false
|
||||
|
||||
return {
|
||||
event: async ({ event }: { event: { type: string; properties?: unknown } }) => {
|
||||
if (event.type !== "session.created" || fired) return
|
||||
|
||||
const props = event.properties as { info?: { parentID?: string } } | undefined
|
||||
if (props?.info?.parentID) return
|
||||
|
||||
fired = true
|
||||
|
||||
const result = checkForLegacyPluginEntry()
|
||||
if (!result.hasLegacyEntry) return
|
||||
|
||||
const migration = autoMigrateLegacyPluginEntry()
|
||||
|
||||
if (migration.migrated) {
|
||||
log("[legacy-plugin-toast] Auto-migrated opencode.json plugin entry", {
|
||||
from: migration.from,
|
||||
to: migration.to,
|
||||
})
|
||||
|
||||
await ctx.client.tui
|
||||
.showToast({
|
||||
body: {
|
||||
title: "Plugin Entry Migrated",
|
||||
message: `"${migration.from}" has been renamed to "${migration.to}" in your opencode.json.\nNo action needed.`,
|
||||
variant: "success" as const,
|
||||
duration: 8000,
|
||||
},
|
||||
})
|
||||
.catch(() => {})
|
||||
} else {
|
||||
log("[legacy-plugin-toast] Legacy entry detected but migration failed", {
|
||||
legacyEntries: result.legacyEntries,
|
||||
})
|
||||
|
||||
await ctx.client.tui
|
||||
.showToast({
|
||||
body: {
|
||||
title: "Legacy Plugin Name Detected",
|
||||
message: `Update your opencode.json: "${LEGACY_PLUGIN_NAME}" has been renamed to "${PLUGIN_NAME}".\nRun: bunx ${PLUGIN_NAME} install`,
|
||||
variant: "warning" as const,
|
||||
duration: 10000,
|
||||
},
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user