修复包名改动的连带事故 + 补齐发布配置

改包名为 @sidaocai/dsh-markmag 时漏了 dist/client.js 的 factory id,
导致 DSH 判定重复注册、插件加载失败,进而把 profile 的 bundles 从 13 个重置成 2 个。

修复:
- client bundle 的 id 与包名对齐
- 新增 scripts/repair-profile.mjs 从备份恢复 bundles
- package.json 补 publishConfig(锁定私有 registry)/ prepack / prepublishOnly
- 新增 scripts/preflight.mjs 发布前七项检查
- 文档记录改包名必须同步的四处(踩坑记录)
This commit is contained in:
发条 committed 2026-11-07 23:54:04 +08:00
1 parent ff8017bbbb
commit 4f0915c5f0
5 files changed
+105 -4

No files matched your search

+3
View File
@@ -12,3 +12,6 @@
- 工具面(MCP):查汇总 / 查任务 / 查项目 / 建任务 / 完成 / 改期 / whoami - 工具面(MCP):查汇总 / 查任务 / 查项目 / 建任务 / 完成 / 改期 / whoami
- 面板:侧边栏入口,个人看板 + 角色可见范围 + 行内完成/改期 + 快速建任务 - 面板:侧边栏入口,个人看板 + 角色可见范围 + 行内完成/改期 + 快速建任务
- 离职吊销:成员停用即吊销名下全部 TDB key(弹匣侧实现) - 离职吊销:成员停用即吊销名下全部 TDB key(弹匣侧实现)
- 发布配置:scope 包名、私有 registry 锁定、prepack 自动构建、prepublishOnly 检查
- 修复记录:包名改动曾致插件加载失败并触发 DSH 重置 bundles,已加 `scripts/repair-profile.mjs`
(踩坑详情见 `docs/发布与更新方案.md` 第十一节)
+2 -2
View File
@@ -11,7 +11,7 @@
* 产物由 scripts/build-client.mjs 从 panel.css + panel.template.js 合成。 * 产物由 scripts/build-client.mjs 从 panel.css + panel.template.js 合成。
*/ */
window.__ModuleLoader__.load({ window.__ModuleLoader__.load({
id: "dsh-markmag", id: "@sidaocai/dsh-markmag",
factory: function (require) { factory: function (require) {
const module = { exports: {} } const module = { exports: {} }
const exports = module.exports const exports = module.exports
@@ -431,4 +431,4 @@ window.__ModuleLoader__.load({
module.exports = { inject: ["slots"], apply: apply } module.exports = { inject: ["slots"], apply: apply }
return module.exports return module.exports
}, },
}) })
+38
View File
@@ -114,3 +114,41 @@ node scripts/update.mjs # 拉最新版 + 重建 client + 装进 prof
- 不急着上 CI/CD(10 人团队,本地 publish 一条命令够用) - 不急着上 CI/CD(10 人团队,本地 publish 一条命令够用)
- 不做插件自更新(自动拉远程代码执行风险高;要更新就明确跑一条命令) - 不做插件自更新(自动拉远程代码执行风险高;要更新就明确跑一条命令)
- 不引入 Verdaccio 等独立 registry(Gitea 已有) - 不引入 Verdaccio 等独立 registry(Gitea 已有)
## 十一、踩坑记录
### 坑 1 · 改包名导致全站插件被清空(2026-11-07)
**现象**:把包名从 `dsh-markmag` 改成 `@sidaocai/dsh-markmag` 后,DSH 启动报
`web boot: 1 entry did not activate` 与 `client-modules: duplicate factory registration`,
然后 **bundles 从 13 个被重置成 2 个**(只剩官方 base + web-app),自媒体工作台、context、
记忆插件、子 agent 全部消失。
**根因**:改包名时漏了 `dist/client.js` 里的 `factory id`。它还是 `dsh-markmag`,
与包名 `@sidaocai/dsh-markmag` 对不上,DSH 判断为重复注册 → 插件加载失败。
**放大机制**:DSH 启动失败时会把 profile 的 bundles 重置成官方基础包。
**一次小错 → 全站第三方插件被禁用。**
**改包名必须同步的四处**(缺一不可):
| # | 位置 | 值 |
|---|---|---|
| 1 | `package.json` → `name` | `@sidaocai/dsh-markmag` |
| 2 | `cordis.patch.yml` → insert 的 `name` | 同上 |
| 3 | **`dist/client.js` → `__ModuleLoader__.load({ id })`** | 同上(最容易漏) |
| 4 | profile 的 `node_modules` 路径 + `bundles` 列表 | 同上 |
**恢复办法**:`scripts/repair-profile.mjs` 从 `package.json.bak-20261107-plugin` 还原 bundles。
这个备份是改名前留下的,务必保留。
**预防**:
- 改包名后先跑 `node scripts/build-client.mjs` 再 grep 一次 id 是否与包名一致
- 改完先重启验证,再动别的
- profile 的 `package.json.bak-*` 不许删(这是唯一能恢复 bundles 的东西)
### 坑 2 · 为什么 agent 改不了 `~/.dsh`
DSH 自己的文件沙箱对 agent 只开放工作区,`~/.dsh` 写入一律 EPERM。
这是保护机制(防 agent 误改用户配置),**不是 bug**,所以凡涉及 `~/.dsh` 的操作:
代码由 agent 写、命令由人跑。
+60
View File
@@ -0,0 +1,60 @@
#!/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 生效。")
+2 -2
View File
@@ -11,7 +11,7 @@
* 产物由 scripts/build-client.mjs 从 panel.css + panel.template.js 合成。 * 产物由 scripts/build-client.mjs 从 panel.css + panel.template.js 合成。
*/ */
window.__ModuleLoader__.load({ window.__ModuleLoader__.load({
id: "dsh-markmag", id: "@sidaocai/dsh-markmag",
factory: function (require) { factory: function (require) {
const module = { exports: {} } const module = { exports: {} }
const exports = module.exports const exports = module.exports
@@ -431,4 +431,4 @@ window.__ModuleLoader__.load({
module.exports = { inject: ["slots"], apply: apply } module.exports = { inject: ["slots"], apply: apply }
return module.exports return module.exports
}, },
}) })