Files
37duAutomation/docs/插件/发版规范.md
T
puddy 1d66167156 chore(center): 下线第一代中心机并清除旧公网信息
- 删除 desktop/controlplane(FastAPI 旧中心机)全部代码,历史见 git

- 移除依赖旧中心机模块的两个失效测试

- AGENTS/README/docs 表述改为「已移除/只有内网一套」,去掉旧公网地址与宝塔部署信息

- agent_cli 去掉旧库拦截逻辑,--base 帮助指向内网生产;electron-shell .env.example 默认地址改内网
2026-11-06 15:40:37 +08:00

159 lines
10 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.
# 插件发版与自动更新规范
> 本文档定义 37duAutomation 各交付物的**发版流程**与执行机**自动更新机制**。
> 发版统一走 agent CLI(中心机控制面),执行机端插件按账号权限自下载、壳子由用户点击升级。
> 打包产物位置、打包脚本见 [插件开发规范.md](./插件开发规范.md) 第 4 节。
> 最后更新:2026-10-31(壳子/中心机部分已按现役 electron-shell + controlplane-next 校准)。
## 1. 总览
版本源(插件包 + 壳子安装包 + 环境包 + 文件登记)全部在**中心机控制面**(内网 `http://172.30.30.243:8800`)。
> ⚠️ **发版必须指向内网库**(2026-10-15 踩坑):控制面有两套——
> 内网生产库 `http://172.30.30.243:8800`(执行机实际连接源,端口分工:8800 控制面 / 8802 文件服务器下载 /
> 8899 文件服务器管理台)。控制面只有这一套,执行机只连它。
> 控制面只有内网一套;`--base` 指错地址的症状:执行机永远"已是最新版本"/插件不更新。
> 发版命令一律**显式** `--base http://172.30.30.243:8800`;
> 验证:`curl -H "X-API-Token: <token>" http://172.30.30.243:8800/api/shell/version`。
| 交付物 | 更新机制 | 入口 |
|--------|----------|------|
| 插件 | 执行机登录后按账号权限自动同步(`electron/plugin-sync.js`);测试版仅管理员可见 | agent CLI `publish`(默认测试通道)/ `plugin-status ... --status published`(转正)/ `grant` / `revoke` |
| 壳子(安装包) | 执行机自动下载 + 用户点击升级重启(`electron/shell-updater.js`,NSIS 静默) | agent CLI `file push --category shell` |
| 环境包(便携 Python) | 客户端自动检查下载并切换版本,保留上一版回滚(`electron/env-sync.js`) | agent CLI `file push --category python-env` |
| 中心机控制面 | 源码部署,不打包 | systemd 重启(见 [服务端部署 SOP](../部署/服务端前后端部署SOP.md)) |
## 2. 发版工具与鉴权
统一用仓库根 `tools/agent_cli.py`(任意 cwd 均可,已迁出废弃的 `desktop/controlplane`):
```powershell
d:\work\code\37duAutomation\.venv\Scripts\python.exe tools\agent_cli.py
```
鉴权两种方式:
1. **密码登录(推荐,任意机器可用)**:
`--admin <管理员> --password <密码>`(或环境变量 `AGENT_ADMIN_PASSWORD` / `AGENT_ADMIN_ACCOUNT`),
并**一律显式加** `--base http://172.30.30.243:8800`(内网生产库,见第 1 节说明)
2. **本机密钥自签(仅中心机本机)**:读新中心机 `controlplane-next/server/.env` 的
`CONTROLPLANE_ADMIN_SECRET`,或 `%USERPROFILE%\.cool-admin\37du-center\.admin_secret`
配置只认新服务端:`desktop/controlplane-next/server/.env`(控制面 token)+ `desktop/fileserver/.env`(文件服务器地址/token)。
实际账号:管理员 `puddy`,密码 `123456`,中心机控制面 `http://172.30.30.243:8800`。
本开发机直接示例:
```powershell
d:\work\code\37duAutomation\.venv\Scripts\python.exe tools\agent_cli.py `
--admin puddy --password 123456 --base http://172.30.30.243:8800 `
publish <插件.zip> --id <id> --version <v>
```
## 3. 插件发版流程(测试通道 → 人工验证 → 转正)
> 2026-10-31 起:**`publish` 默认进测试通道,不再直发正式**。
> 测试期 `plugins.status=testing`、`plugins.test_version=<新版本>`,**只有管理员账号**(`accounts.is_admin=1`)
> 能同步到在测版本,其他账号继续用 `latest_version`(业务不中断)。
> 人工验证通过后把状态改为 `published` 转正:服务端把 `test_version` 提升为 `latest_version` 并清空在测版本,
> **复用同一版本号、不重新打包**(保证"测过的就是发出去的"),全量已授权账号下次同步生效。
> ⚠️ **agent 不得自行转正**:转正 = 人工确认动作,必须在管理员机实测通过后由人执行。
1. **打包**:在插件目录(`plugins/XQ0001-0100/XQ00xx <中文名>/`)下执行 `_pack.py`,产物输出到仓库根 `dist-plugin/<id>_v<版本>.zip`
(zip 根必须含 `plugin.json`;带 UI 插件需先 `npm run build` 出 `ui/index.html`)。
2. **发布测试版**:任意 cwd 执行:
```powershell
.venv\Scripts\python.exe tools\agent_cli.py `
--admin puddy --password 123456 --base http://172.30.30.243:8800 `
publish dist-plugin\<id>_v<版本>.zip --id <id> --version <版本>
```
版本号需与 `plugin.json.version` / `ScenePlugin.version` 一致,且**必须高于当前正式版**
(执行机 `plugin-sync.js` 只升不降,低于正式版的测试版转正后不会生效,服务端会直接拒绝)。
3. **管理员机验证**:用管理员账号登录执行机 → 同步插件 → 跑真实场景,确认功能/字段/耗时/日志无异常。
列表中「在测版本」即当前测试版;控制台插件页可见「测试中」状态。
4. **转正(人工)**:
```powershell
.venv\Scripts\python.exe tools\agent_cli.py --base http://172.30.30.243:8800 `
plugin-status <id> --status published
```
控制台「插件管理」页对应插件点「转正」等效。转正后全量已授权账号下次同步即升级。
未通过验证:留在 `testing` 继续改(发更高版本号),或 `--status disabled` 暂停下发。
5. **授权 / 收回**(按账号管控可执行性):
```powershell
.venv\Scripts\python.exe tools\agent_cli.py --base http://172.30.30.243:8800 grant <账号> <id>
.venv\Scripts\python.exe tools\agent_cli.py --base http://172.30.30.243:8800 revoke <账号> <id>
```
6. **紧急直发正式**(仅热修且经人确认):`publish ... --prod` 跳过测试通道,立即全量生效。
7. **执行机端**:登录后按账号权限自动同步——`plugin-sync.js` 拉版本清单 → 下载票据 → 下载 → sha256 校验 →
解压到 `plugins/<id>/`(打包态为 `%LOCALAPPDATA%\37duAutomation\plugins`)原子替换 → 旧版备份到 `plugin_rollback/`;下次执行即用新版本。
被 revoke/下架/禁用的插件按管控清单停用或移除;在测版本仅管理员账号可下载(票据接口同步校验)。
## 4. 壳子 / 环境包发版流程
> 完整步骤(版本号、构建、打包、验证、升级链路)见 [桌面端发版SOP](../桌面端/桌面端发版SOP.md),本节为摘要。
1. 改 `desktop/electron-shell/package.json` 的 `version`(唯一真源;打包时 `scripts/after-pack.js` 写入 exe 同级 `shell.version`)
2. 前端有改动时执行 `npm run copy-renderer`(`frontend/` → `renderer/dist`)
3. `npm run pack` → `dist-app/setup-37du-shell-<version>.exe`(electron-builder NSIS)
4. 上传 + 登记:
```powershell
# 壳子
.venv\Scripts\python.exe tools\agent_cli.py `
--admin puddy --password 123456 --base http://172.30.30.243:8800 `
file push <安装包> --category shell --version <新版本> [--notes "说明"]
# 环境包(有变更时)
.venv\Scripts\python.exe tools\agent_cli.py `
--admin puddy --password 123456 --base http://172.30.30.243:8800 `
file push <python-env-<ver>.zip> --category python-env --version <ver> [--notes "说明"]
```
> 安装包/环境包上传到内网文件服务器(`FILESERVER_BASE_URL=http://172.30.30.243:8802`),并登记到**内网中心机**
> `file_sources(category)`,执行机从该直链下载。**不要用旧的 `shell-release` 子命令**。
> 登记(`--base`)必须指内网库 `http://172.30.30.243:8800`,指错地址执行机检测不到(见第 1 节说明)。
5. **执行机端**:自动下载安装包(sha256 校验)→ 前端提示 → 用户点击升级重启;环境包自动下载切换,无需用户操作。
## 5. 中心机发版流程
控制面为源码部署(Node/Midway,systemd `37du-controlplane-next.service`,不打包 exe):
- 改后端代码:`server` 下 `npm run build` → 上传 `/opt/37du/controlplane-next/server` → `systemctl restart 37du-controlplane-next.service`
- 改前端代码:`frontend` 下 `pnpm build` → 上传 `dist/` 到 `/opt/37du/controlplane-web` → 按需 `nginx -s reload`
- 数据库变更:手工执行 `migrations/*.sql` 后重启后端
- 详细步骤与排错见 [服务端部署 SOP](../部署/服务端前后端部署SOP.md)
## 6. 发布后检查
- 插件发布后:测试版只到管理员机;确认 `plugins` 表 `status=testing`、`test_version=<新版本>`,普通账号的 `/api/plugins` 仍返回旧正式版。
- 转正后:`latest_version` 等于原 `test_version`、`test_version` 被清空、`status=published`,审计表有 `plugin-promote` 记录。
- 执行机下次启动/同步自动检测下载;插件按账号权限自动更新。
- 壳子发布后:执行机自动下载,前端提示后点击升级;升级后 `.env`、插件目录、环境包不被覆盖。
- 版本冲突 / 更新失败:查执行机 `logs/shell.log` 与 `plugin-sync.js` / `shell-updater.js` / `env-sync.js` 日志;核对中心机版本清单与授权。
## 7. Agent 技能(skills,`.trae/skills/`,本地不入库)
发版/上传/账号管理已封装为 Trae agent 技能,agent 按需加载执行:
| 技能 | 用途 |
|------|------|
| `37du-Agent-CLI` | CLI 用法与鉴权总纲(先读) |
| `37du-Plugin-Release` | 插件发版 / 授权 / 状态管理 |
| `37du-File-Release` | 壳子/环境包/大文件上传发版(file push) |
| `37du-Account-Permission` | 账号与权限管理 |
| `37du-Center-Deploy` | 中心机部署(SSH、编译、重启、验证) |
| `37du-Desktop-Auto` | 桌面自动化库 `libs/desktopauto` 用法与坑位 |
| `37du-AITable-CLI` | 钉钉 AI 表格库 `libs/aitable` 用法 |
| `37du-Yingdao-To-Plugin` | 影刀脚本转插件 |
| `37du-Monthly-Review` | 月度复盘 |
> 实际账号统一 `puddy / 123456`;`agent_cli` 已默认 `--admin puddy`,支持 `--json` 机器输出与 `ping` 预检。