Files
oh-my-opencode/src/hooks/legacy-plugin-toast/hook.ts
T
YeonGyu-Kim 33ac57ba7a refactor: update remaining modules to use plugin-identity constants
Update various modules to use centralized constants from plugin-identity:
- get-local-version/formatter: Use PUBLISHED_PACKAGE_NAME
- run/session-resolver: Use PUBLISHED_PACKAGE_NAME
- background-agent/task-poller: Use PUBLISHED_PACKAGE_NAME
- mcp-oauth/provider: Use PUBLISHED_PACKAGE_NAME
- auto-update-checker/constants: Use ACCEPTED_PACKAGE_NAMES
- comment-checker/downloader: Use PUBLISHED_PACKAGE_NAME
- legacy-plugin-toast/hook: Use PLUGIN_NAME
- shared/data-path: Use CACHE_DIR_NAME
- shared/external-plugin-detector: Use ACCEPTED_PACKAGE_NAMES
- shared/logger: Use LOG_FILENAME
- tools/ast-grep/downloader: Use PUBLISHED_PACKAGE_NAME
- tools/call-omo-agent/tools: Use PUBLISHED_PACKAGE_NAME
- tools/delegate-task/category-resolver: Use PUBLISHED_PACKAGE_NAME
- tools/grep/constants: Use PUBLISHED_PACKAGE_NAME
- tools/grep/downloader: Use PUBLISHED_PACKAGE_NAME
- tools/lsp/lsp-client-wrapper: Use PUBLISHED_PACKAGE_NAME

🤖 Generated with assistance of OhMyOpenCode
2026-04-10 11:16:16 +09:00

69 lines
2.4 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, PUBLISHED_PACKAGE_NAME } from "../../shared/plugin-identity"
import { autoMigrateLegacyPluginEntry } from "./auto-migrate-runner"
type LegacyPluginToastDeps = {
checkForLegacyPluginEntry?: typeof checkForLegacyPluginEntry
log?: typeof log
autoMigrateLegacyPluginEntry?: typeof autoMigrateLegacyPluginEntry
}
export function createLegacyPluginToastHook(ctx: PluginInput, deps: LegacyPluginToastDeps = {}) {
let fired = false
const checkForLegacyPluginEntryFn = deps.checkForLegacyPluginEntry ?? checkForLegacyPluginEntry
const logFn = deps.log ?? log
const autoMigrateLegacyPluginEntryFn = deps.autoMigrateLegacyPluginEntry ?? autoMigrateLegacyPluginEntry
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 = checkForLegacyPluginEntryFn()
if (!result.hasLegacyEntry) return
const migration = autoMigrateLegacyPluginEntryFn()
if (migration.migrated) {
logFn("[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 {
logFn("[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 ${PUBLISHED_PACKAGE_NAME} install`,
variant: "warning" as const,
duration: 10000,
},
})
.catch(() => {})
}
},
}
}