#!/usr/bin/env node /** * 修复桌面版 profile 的 bundles 列表。 * * 背景:2026-11-07 改包名后 DSH 启动失败,它自己把 bundles 从 12 个重置成 2 个 * (只剩官方 base + web-app),第三方插件全被移除。这个脚本从备份恢复。 * * 幂等:跑几次结果一样。 */ import fs from "node:fs" import { homedir } from "node:os" import { join } from "node:path" const P = join(homedir(), ".dsh/profiles/desktop") const PKG = join(P, "package.json") const BAK = join(P, "package.json.bak-20261107-plugin") const PLUGIN = "@sidaocai/dsh-markmag" const LEGACY = "dsh-markmag" const log = (k, v) => console.log(k.padEnd(14), v) const die = (m) => { console.error("✗ " + m); process.exit(1) } if (!fs.existsSync(PKG)) die("没找到 " + PKG) if (!fs.existsSync(BAK)) die("没找到备份 " + BAK + "(没有它无法恢复 bundles)") const cur = JSON.parse(fs.readFileSync(PKG, "utf8")) const bak = JSON.parse(fs.readFileSync(BAK, "utf8")) // 备份里有完整 12 项;保留当前 dependencies(含新包名) const restored = (bak.dsh?.profile?.bundles || []).filter((b) => b !== LEGACY) if (!restored.includes(PLUGIN)) restored.push(PLUGIN) log("bundles 恢复:", (cur.dsh?.profile?.bundles || []).length + " → " + restored.length) cur.dsh ??= {} cur.dsh.profile ??= {} cur.dsh.profile.bundles = restored cur.dependencies ??= {} delete cur.dependencies[LEGACY] if (!cur.dependencies[PLUGIN]) cur.dependencies[PLUGIN] = "file:" + join(homedir(), "Documents/Essay_AI/Essay_system/dsh-markmag") // 先备份当前(可能已被 DSH 重置)的版本 fs.copyFileSync(PKG, PKG + ".bak-repair-" + Date.now()) fs.writeFileSync(PKG, JSON.stringify(cur, null, 2) + "\n") const out = JSON.parse(fs.readFileSync(PKG, "utf8")) const checks = { bundleCount: out.dsh.profile.bundles.length, hasMediaDesk: out.dsh.profile.bundles.includes("dsh-media-desk"), hasContext: out.dsh.profile.bundles.includes("dsh-context"), hasOpenviking: out.dsh.profile.bundles.includes("@openviking/dsh-memory-plugin"), hasMarkmag: out.dsh.profile.bundles.includes(PLUGIN), noLegacy: !out.dsh.profile.bundles.includes(LEGACY), } log("SELF_CHECK", JSON.stringify(checks)) if (checks.bundleCount !== restored.length || !checks.hasMarkmag || !checks.hasMediaDesk) { console.log("\n✗ 自检没过") process.exit(1) } console.log("\nbundles 已恢复。重启 DSH 生效。")