Files
dsh-markmag/docs/发布与更新方案.md
T
发条 4f0915c5f0 修复包名改动的连带事故 + 补齐发布配置
改包名为 @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 发布前七项检查
- 文档记录改包名必须同步的四处(踩坑记录)
2026-11-07 23:54:04 +08:00

155 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 插件发布与更新方案
> 2026-11-07。目标:不再靠「发文件包」—— 发布一条命令、更新一条命令。
## 一、现状
| 项 | 现状 |
|---|---|
| 代码 | 本地目录 `~/Documents/Essay_AI/Essay_system/dsh-markmag`,**没有进 Git** |
| 安装 | 手工跑 `scripts/install.mjs`,把文件复制进 profile 的 node_modules |
| profile 依赖 | `"dsh-markmag": "file:/Users/essay/.../dsh-markmag"` |
| profile 包管理 | **pnpm 11.1.3**(`pnpm-lock.yaml` + `pnpm-workspace.yaml`,nodeLinker: hoisted) |
| 版本 | 0.1.0,无 tag、无 changelog |
真正的问题不是「发文件包」,而是**没有版本、没有仓库、没有升级路径**。多人之后,谁装的是哪个版本完全不可知。
## 二、已验证的条件
| 条件 | 结果 |
|---|---|
| Gitea 版本 | **28.1.0**(`brain.sidaocai.cn/git`) |
| Gitea npm registry | **已开通** —— `/api/packages/sidaocai/npm/dsh-markmag` 返回 `401 reqPackageAccess`(鉴权响应,不是 404) |
| pnpm | 11.1.3,profile 由它管 |
**结论:不需要新建任何服务**,Gitea 自带 npm 私有仓库。
## 三、目标架构
```
代码 → Gitea 仓库 sidaocai/dsh-markmag(私有)
│ npm publish
▼
包 → Gitea npm registry @sidaocai/dsh-markmag
│ pnpm install / update
▼
每人 → ~/.dsh/profiles/desktop/node_modules/dsh-markmag
```
## 四、三条命令(三种角色)
### 我发布(每次改完代码)
```bash
cd ~/Documents/Essay_AI/Essay_system/dsh-markmag
node scripts/build-client.mjs # 生成 dist/client.js
npm version patch # 0.1.0 → 0.1.1;加功能用 minor
git push origin main --follow-tags
npm publish # 推到 Gitea registry
```
### 同事首次安装(一次性)
```bash
node scripts/setup-account.mjs # 已包含装插件 + 取钥匙
```
### 更新(已装过的人)
```bash
node scripts/update.mjs # 拉最新版 + 重建 client + 装进 profile
```
重启 DSH 生效。
## 五、一次性配置
1. **建 Gitea 仓库** `sidaocai/dsh-markmag`,私有。
2. **发布用 .npmrc**(放 `~/.npmrc`,token 不进仓库):
```
@sidaocai:registry=https://brain.sidaocai.cn/git/api/packages/sidaocai/npm/
//brain.sidaocai.cn/git/api/packages/sidaocai/npm/:_authToken=<GITEA_TOKEN>
```
3. **profile 的 .npmrc**(`~/.dsh/profiles/desktop/.npmrc`)同样指向 Gitea registry。
## 六、版本与变更记录
- `CHANGELOG.md` 每次发布记:版本号 + 改了什么 + 是否需要重新登录/重启
- 面板顶部显示自身版本号
- 修 bug 用 patch,加功能用 minor,改权限或协议用 major
## 七、更新提示(避免「不知道有新版本」)
**推荐 B 方案:弹匣后端登记最新版**
| 方案 | 做法 | 代价 |
|---|---|---|
| A | 面板直接查 Gitea 的包元数据 | 要给每个人发 Gitea 读权限 token |
| **B** | 弹匣加配置项 `plugin_latest`,面板比对后提示 | 改版本只需更新一处配置 |
## 八、分两阶段
### 阶段一(现在,单人):先补最小闭环
- 代码进 Gitea 私有仓库
- 加 `CHANGELOG.md` + 版本号
- 写 `scripts/update.mjs`(本地重新构建 + 装)
- **不上 registry** —— 单人场景没必要
### 阶段二(团队铺开前):切 registry
- 配好 npm 私有仓库
- profile 依赖从 `file:` 改成 `^0.1.0`
- 同事 `pnpm install` 自动拉
- 加更新提示
## 九、待验证(阶段二前必须实测)
1. **桌面版 profile 能否被 pnpm 正常维护** —— Electron 启动时会不会覆盖 node_modules(这是最大未知数)
2. Gitea npm registry 的读权限怎么给团队成员(组织成员 / token)
3. 包体积(client.js 31KB + src,可接受)
## 十、不做什么
- 不急着上 CI/CD(10 人团队,本地 publish 一条命令够用)
- 不做插件自更新(自动拉远程代码执行风险高;要更新就明确跑一条命令)
- 不引入 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 写、命令由人跑。