Files
oh-my-opencode/src/hooks/legacy-plugin-toast/hook.ts
T
YeonGyu-Kim f03c6700d4 fix(hooks): reuse shared legacy plugin migration helper
Replace the legacy toast regex writer with the shared atomic helper and route legacy plugin call sites through small wrappers so existing mock.module tests stop leaking across the suite.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-04 01:32:59 +09:00

60 lines
1.9 KiB
TypeScript

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-runner"
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(() => {})
}
},
}
}