import { lstat, mkdir, readFile, unlink, writeFile } from "node:fs/promises"; import { homedir } from "node:os"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const EXTENSION_ID = "omp-dashscope"; const EXTENSIONS_DIR = join(homedir(), ".omp", "agent", "extensions"); const EXTENSION_DIR = join(EXTENSIONS_DIR, EXTENSION_ID); const PACKAGE_ROOT = dirname(fileURLToPath(import.meta.url)); const SOURCE_EXTENSION_FILE = join(PACKAGE_ROOT, "index.ts"); const TARGET_EXTENSION_FILE = join(EXTENSION_DIR, "index.ts"); async function ensureExtensionFiles(): Promise { await mkdir(EXTENSIONS_DIR, { recursive: true }); try { const stat = await lstat(EXTENSION_DIR); if (stat.isSymbolicLink()) { await unlink(EXTENSION_DIR); } } catch { // Extension directory does not exist yet. } await mkdir(EXTENSION_DIR, { recursive: true }); const source = await readFile(SOURCE_EXTENSION_FILE, "utf8"); let current = ""; try { current = await readFile(TARGET_EXTENSION_FILE, "utf8"); } catch { // File not present yet. } if (current !== source) { await writeFile(TARGET_EXTENSION_FILE, source, "utf8"); } } export default async function () { try { await ensureExtensionFiles(); } catch { // Ignore bootstrap errors: plugin should not block startup. } return []; }