bpmax-cli 0.2.1-beta.91 → 0.2.1-beta.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +7106 -980
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/scripts/install-skills.mjs +9 -1
- package/skills/bpmax-local-dev/SKILL.md +68 -0
- package/skills/bpmax-plugin-browser-install/SKILL.md +247 -0
- package/skills/bpmax-plugin-browser-install/scripts/bpmax-browser.mjs +245 -0
- package/skills/bpmax-plugin-config/SKILL.md +6 -14
- package/skills/bpmax-plugin-development/SKILL.md +89 -0
- package/skills/bpmax-plugin-development/references/business-context-guidance.md +61 -0
- package/skills/bpmax-plugin-development/references/develop-guide.md +148 -0
- package/skills/bpmax-plugin-development/references/discovery-guide.md +168 -0
- package/skills/bpmax-plugin-development/references/enterprise-readiness.md +159 -0
- package/skills/bpmax-plugin-development/references/frontend-data-access.md +208 -0
- package/skills/bpmax-plugin-development/references/git-guide.md +128 -0
- package/skills/bpmax-plugin-development/references/install-remote.md +154 -0
- package/skills/bpmax-plugin-development/references/personalized-pages.md +207 -0
- package/skills/bpmax-plugin-development/references/planning-guide.md +146 -0
- package/skills/bpmax-plugin-development/references/plugin-backend-api.md +215 -0
- package/skills/bpmax-plugin-development/references/plugin-data-access.md +100 -0
- package/skills/bpmax-plugin-development/references/plugin-flow-integration.md +128 -0
- package/skills/bpmax-plugin-development/references/plugin-interop.md +68 -0
- package/skills/bpmax-plugin-development/references/plugin-page-styling.md +315 -0
- package/skills/bpmax-plugin-development/references/plugin-permissions.md +223 -0
- package/skills/bpmax-plugin-development/references/plugin-spec.md +166 -0
- package/skills/bpmax-plugin-development/references/remote-debug.md +85 -0
- package/skills/bpmax-plugin-development/references/remote-logs.md +97 -0
- package/skills/bpmax-plugin-development/references/scaffold-guide.md +230 -0
- package/skills/bpmax-plugin-development/references/test-guide.md +136 -0
- package/skills/bpmax-plugin-development/references/troubleshooting.md +115 -0
package/package.json
CHANGED
|
@@ -68,11 +68,19 @@ async function exists(targetPath) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
const SKILL_COPY_SKIP = new Set(['__pycache__', '.DS_Store']);
|
|
72
|
+
|
|
71
73
|
async function installSkillDir(skillName, sourceDir, root) {
|
|
72
74
|
await mkdir(root, { recursive: true });
|
|
73
75
|
const destination = path.join(root, skillName);
|
|
74
76
|
await rm(destination, { recursive: true, force: true });
|
|
75
|
-
await cp(sourceDir, destination, {
|
|
77
|
+
await cp(sourceDir, destination, {
|
|
78
|
+
recursive: true,
|
|
79
|
+
filter: (src) => {
|
|
80
|
+
const base = path.basename(src);
|
|
81
|
+
return !SKILL_COPY_SKIP.has(base) && !base.endsWith('.pyc');
|
|
82
|
+
},
|
|
83
|
+
});
|
|
76
84
|
return destination;
|
|
77
85
|
}
|
|
78
86
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bpmax-local-dev
|
|
3
|
+
description: Use when the user asks to start, check, or troubleshoot the local BPMAX development environment, including hpt-frontend, huanpingtong-server, bpmax-server, local ports 10018/10010/8033, plugin loading through PLUGIN_NAME, and Node 16 startup commands.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# BPMAX Local Dev
|
|
7
|
+
|
|
8
|
+
> **本页是专题参考,入口在 `bpmax-plugin-development`。** 本页只处理本地服务启动与排查。
|
|
9
|
+
|
|
10
|
+
用于启动或排查 BPMAX 本地开发环境。涉及 `hpt-frontend`、`huanpingtong-server`、`bpmax-server` 本地服务时使用本 skill。
|
|
11
|
+
|
|
12
|
+
## Repos
|
|
13
|
+
|
|
14
|
+
- Frontend: `/Users/yanghanwen/Development/Cicada/bpmax-core/hpt-frontend`
|
|
15
|
+
- Huanpingtong server: `/Users/yanghanwen/Development/Cicada/bpmax-core/huanpingtong-server`
|
|
16
|
+
- BPMAX server: `/Users/yanghanwen/Development/Cicada/bpmax-core/bpmax-server`
|
|
17
|
+
|
|
18
|
+
## Startup Checklist
|
|
19
|
+
|
|
20
|
+
1. 检查端口 `10018`、`10010`、`8033` 未被占用。
|
|
21
|
+
- 推荐命令:`lsof -nP -iTCP:10018 -iTCP:10010 -iTCP:8033 -sTCP:LISTEN`
|
|
22
|
+
- 如果端口被占用,先向用户说明占用进程,再决定是否终止;不要擅自 kill。
|
|
23
|
+
2. 如需加载插件,在启动服务前设置环境变量:
|
|
24
|
+
- `export PLUGIN_NAME=pluginA,pluginB`
|
|
25
|
+
- `PLUGIN_NAME` 的值是插件名逗号分隔列表。
|
|
26
|
+
- `hpt-frontend` 和 `huanpingtong-server` 启动前设置该变量后,会自动编译安装插件并支持热更新。
|
|
27
|
+
3. 使用 Node 16 启动三个服务。
|
|
28
|
+
4. 前端访问地址以 `huanpingtong-server/env-local.sh` 中的 `DOMAIN` 为准。
|
|
29
|
+
- 如果 `DOMAIN` 是 IP,访问地址要加前端端口:`http://<DOMAIN>:10018/`。
|
|
30
|
+
- 如果 `DOMAIN` 是域名,访问地址不加端口:`http://<DOMAIN>/` 或 `https://<DOMAIN>/`,协议按 `DOMAIN` 配置和本地环境实际情况判断。
|
|
31
|
+
- 不要直接使用 Nuxt 输出里的 `localhost:10018`。本地登录态、回调域名、Cookie 和跨端口代理都要按 `DOMAIN` 对齐;例如 `DOMAIN=127.0.0.1` 时,前端访问地址必须使用 `http://127.0.0.1:10018/`。
|
|
32
|
+
|
|
33
|
+
## Commands
|
|
34
|
+
|
|
35
|
+
在三个独立终端或后台 session 中启动:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
cd /Users/yanghanwen/Development/Cicada/bpmax-core/hpt-frontend
|
|
39
|
+
nvm use 16
|
|
40
|
+
export PLUGIN_NAME=pluginA,pluginB
|
|
41
|
+
yarn dev:local
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
cd /Users/yanghanwen/Development/Cicada/bpmax-core/huanpingtong-server
|
|
46
|
+
nvm use 16
|
|
47
|
+
export PLUGIN_NAME=pluginA,pluginB
|
|
48
|
+
yarn start:local
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
cd /Users/yanghanwen/Development/Cicada/bpmax-core/bpmax-server
|
|
53
|
+
nvm use 16
|
|
54
|
+
yarn start:local
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
If no plugins are needed, omit `export PLUGIN_NAME=...`.
|
|
58
|
+
|
|
59
|
+
## Agent Behavior
|
|
60
|
+
|
|
61
|
+
- 浏览器验证与页面数量约束见 `bpmax-plugin-development` 的「硬门禁」与全局浏览器规则;本页只管本地服务启动、端口与域名推导。
|
|
62
|
+
- 启动前先检查端口和 repo 是否存在。
|
|
63
|
+
- 如果用户给了插件名,按原样写入 `PLUGIN_NAME`;不要猜插件名。
|
|
64
|
+
- 如果用户没有给插件名,默认不设置 `PLUGIN_NAME`。
|
|
65
|
+
- 启动服务时优先使用 long-running shell sessions,并把每个服务的 session/端口状态反馈给用户。
|
|
66
|
+
- 启动完成后,读取 `/Users/yanghanwen/Development/Cicada/bpmax-core/huanpingtong-server/env-local.sh` 的 `DOMAIN`,按 IP 加 `:10018`、域名不加端口的规则告诉用户前端访问地址。
|
|
67
|
+
- 浏览器验证必须打开上一步推导出的 `DOMAIN` 地址,不要因为终端显示 `Listening: http://localhost:10018/` 就改用 `localhost`。
|
|
68
|
+
- 不要把服务启动在 `bpmax-cli` 仓库中。
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bpmax-plugin-browser-install
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: Install or upgrade a BPMAX plugin through the plugin management page in a real browser (upload local zip → restart → verify), environment-agnostic. Use when a plugin has no typed CLI install channel or when the user asks to install a plugin in the browser.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# BPMAX 插件浏览器安装
|
|
8
|
+
|
|
9
|
+
> **本页是专题参考,入口在 `bpmax-plugin-development`。** 本页是 `plugin install` 不可用时的浏览器兜底流程。
|
|
10
|
+
|
|
11
|
+
CLI 发布 `bpmax-cli plugin install` 后,优先用 typed 命令(见 `install-remote.md`)。本页是 CLI 不可用、或用户明确要求观察页面实际下发产物时的浏览器兜底流程:**上传本地安装包 → 马上重启 → 回读验证**。
|
|
12
|
+
|
|
13
|
+
本页不绑定具体环境:把环境名、工作区名、插件名当参数传进来即可。
|
|
14
|
+
|
|
15
|
+
> **浏览器操作约束:** 本 skill 的浏览器场景一律优先使用 Tabbit(`"$HOME/.local/bin/tabbit-cli"`,connect → open → observe and act → verify → finish)。禁止 Chrome DevTools MCP 和 AppleScript。只有 Tabbit 启动器不可用且用户明确同意时,才可使用下面的直连 CDP 脚本作为只读降级通道;任务结束用 `finish --task "<任务名>"` 释放所有权。
|
|
16
|
+
|
|
17
|
+
## 何时使用
|
|
18
|
+
- 用户说「在浏览器安装插件」「上传插件包」「升级插件版本」。
|
|
19
|
+
- 插件包(`dist.zip`)已构建好,需要装到某个 BPMAX 环境。
|
|
20
|
+
- 需要确认线上实际下发的前端产物是不是最新包。
|
|
21
|
+
|
|
22
|
+
## 前置:安装包
|
|
23
|
+
|
|
24
|
+
安装包由 `develop-guide.md` 的构建流程产出;上传前确认 `dist/dist.zip` 晚于全部源码:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
cd <plugin_dir>
|
|
28
|
+
shasum -a 256 dist/dist.zip
|
|
29
|
+
find frontend/src server/src -newer dist/dist.zip -type f | head
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`find -newer` 有输出就说明源码改过但没重新打包,先回去重新 build。**把 zip 复制到当前项目目录下**,后续所有操作引用这个副本;SHA256 与构建细节见 `develop-guide.md`。
|
|
33
|
+
|
|
34
|
+
## 浏览器驱动方式:优先 Tabbit
|
|
35
|
+
|
|
36
|
+
默认通过 Tabbit 的 `nodejs` 执行页面动作。先 `create` 拿标签页清单(不会新开或占用标签页):
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
"$HOME/.local/bin/tabbit-cli" create --task "Install plugin"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- 已有插件管理页:用 `nodejs --task "Install plugin" --tab <ID> --request-id <id>` 接管该标签页,复用它的登录态。
|
|
43
|
+
- 没有:直接用 `nodejs`(不带 `--tab`)打开 `page.goto("https://<env>/w:<workspace>/plugins/")`。
|
|
44
|
+
- 每个新程序换一个 `--request-id`;程序里可直接用 `page`、`expect`、`locator` 等 Playwright API。
|
|
45
|
+
- 上传、点击、reload、回读、截图都在同一个任务标签页里完成;结束时 `finish --task "Install plugin"` 释放所有权。
|
|
46
|
+
|
|
47
|
+
只有 Tabbit 启动器不可用且用户明确同意时,才用同目录的直连 CDP 脚本,且只允许只读子命令(`pages`/`eval`/`shot`):
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
B=/Users/yanghanwen/.claude/skills/bpmax-plugin-browser-install/scripts/bpmax-browser.mjs
|
|
51
|
+
CDP_URL=${CDP_URL:-http://127.0.0.1:9444} # 已打开的 Chrome 调试端口
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
只读降级可用的命令:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
node "$B" pages
|
|
58
|
+
node "$B" eval --url "/plugins/" --expr 'location.href'
|
|
59
|
+
node "$B" shot --url "/plugins/" --out .codex/tmp/plugin-install/fallback.png
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`upload`/`click` 会写页面状态,**不属于降级通道**;Tabbit 不可用时停下来等它恢复,不要用 CDP 完成安装。
|
|
63
|
+
|
|
64
|
+
**为什么不用 chrome-devtools-mcp:** `upload_file` / `take_screenshot` 受 workspace root 校验,路径易被拒;每次调用都会新起 MCP server,`take_snapshot` 的 uid 下次调用即失效;隐藏的 `<input type=file>` 即使路径通过也未必有反应。直连 CDP 没有这些问题,但只保留为只读降级。
|
|
65
|
+
|
|
66
|
+
## 安装流程
|
|
67
|
+
|
|
68
|
+
### 1. 打开插件管理页
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
"$HOME/.local/bin/tabbit-cli" nodejs --task "Install plugin" --request-id open-plugins <<'JS'
|
|
72
|
+
if (!/\/plugins\//.test(page.url())) {
|
|
73
|
+
await page.goto("https://<env>/w:<workspace>/plugins/", {waitUntil: "domcontentloaded"});
|
|
74
|
+
}
|
|
75
|
+
return {url: page.url()};
|
|
76
|
+
JS
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
已有 `/plugins/` 标签页时,先 `create` 找到它的 `tabId`,再在 `nodejs` 上加 `--tab <ID>` 接管;不要另开重复页面。
|
|
80
|
+
|
|
81
|
+
页面上三个按钮:**上传本地安装包**、**按工作区批量激活**、**远程插件库**。
|
|
82
|
+
|
|
83
|
+
### 2. 上传安装包
|
|
84
|
+
|
|
85
|
+
按钮会打开文件选择器,先挂 waiter 再点击,最后 `setFiles` 指向 zip 绝对路径:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
"$HOME/.local/bin/tabbit-cli" nodejs --task "Install plugin" --request-id upload-plugin --timeout-ms 120000 <<'JS'
|
|
89
|
+
const stop = new AbortController();
|
|
90
|
+
let chooser;
|
|
91
|
+
try {
|
|
92
|
+
[chooser] = await Promise.all([
|
|
93
|
+
page.waitForEvent("filechooser", {timeout: 10000, signal: stop.signal}),
|
|
94
|
+
page.getByRole("button", {name: "上传本地安装包", exact: true}).click(),
|
|
95
|
+
]);
|
|
96
|
+
await chooser.setFiles("/absolute/path/to/.codex/tmp/plugin-install/dist.zip");
|
|
97
|
+
} finally { stop.abort(); }
|
|
98
|
+
await expect(page.locator("body")).toContainText("需要重启生效", {timeout: 30000});
|
|
99
|
+
return {uploaded: true};
|
|
100
|
+
JS
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
页面若直接暴露 `<input type="file">` 而没有 chooser 事件,改用
|
|
104
|
+
`await page.locator('input[type="file"]').setInputFiles("<zip 绝对路径>")`。
|
|
105
|
+
|
|
106
|
+
预期页面顶部出现 `⚠ 需要重启生效 [马上重启]`。**这一步背后是两次请求**:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
POST /api/upload (先传文件拿地址)
|
|
110
|
+
POST /api/plugin/upload?$workspace=<ws>&... (再登记插件,约 3~5s)
|
|
111
|
+
GET /api/plugin?page=1&page_size=10&... (列表刷新)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 3. 马上重启
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
"$HOME/.local/bin/tabbit-cli" nodejs --task "Install plugin" --request-id restart-plugin --timeout-ms 120000 <<'JS'
|
|
118
|
+
await page.getByRole("button", {name: "马上重启", exact: true}).click();
|
|
119
|
+
await page.getByRole("button", {name: "确认", exact: true}).first().click();
|
|
120
|
+
await page.waitForTimeout(15000);
|
|
121
|
+
await page.reload({waitUntil: "domcontentloaded"});
|
|
122
|
+
return {tip: /需要重启生效/.test(await page.locator("body").innerText())};
|
|
123
|
+
JS
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**第二步「确认」不能漏。** 只点「马上重启」、不点确认框里的「确认」,不会产生任何
|
|
127
|
+
`/api/plugin/restart` 请求。点击后提示条不会立刻消失,它是页面加载时算出来的状态,必须
|
|
128
|
+
reload 才能看到结果;而 `tip:false` 也不等于后端已重启(见下)。
|
|
129
|
+
|
|
130
|
+
#### `tip:false` 不等于后端已重启(重要)
|
|
131
|
+
|
|
132
|
+
提示条是按「上传时间 vs 记录里的重启时间」算出来的页面状态。**漏掉二次确认时,
|
|
133
|
+
reload 后同样会得到 `tip:false`**,但后端 worker 仍是旧代码——这是最危险的"假重启":
|
|
134
|
+
安装流程一路绿灯,实际跑的是旧逻辑,只有功能行为不对时才暴露。
|
|
135
|
+
|
|
136
|
+
判断后端是否真的换了代码,要用**只有新版本才有的行为做探针**,三选一:
|
|
137
|
+
|
|
138
|
+
1. **模型复述系统提示**(改的是提示词/agent 逻辑时最直接):直接问模型
|
|
139
|
+
「你的系统提示里有没有 X 这一节」,让它原样复述。旧代码会回答「没有」。
|
|
140
|
+
2. **新行为可观测**:调一次只有新版本才有的功能,看后端审计/日志里有没有对应记录。
|
|
141
|
+
3. **服务端产物指纹**:能拿到机器时比对 `app/service/<plugin>.js` 的 sha256。
|
|
142
|
+
|
|
143
|
+
任何一项对不上,就回去重做「点二次确认 → reload」。
|
|
144
|
+
|
|
145
|
+
## 验证(浏览器兜底)
|
|
146
|
+
|
|
147
|
+
CLI 安装的权威回读标准见 `install-remote.md`;本节三项是浏览器兜底时的补充证据。
|
|
148
|
+
|
|
149
|
+
### A. 插件记录回读
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
"$HOME/.local/bin/tabbit-cli" nodejs --task "Install plugin" --request-id verify-plugin --timeout-ms 120000 <<'JS'
|
|
153
|
+
return await page.evaluate(async () => {
|
|
154
|
+
const r = await fetch("/api/plugin?page=1&page_size=50&count=50¤tPage=1", { credentials: "include" });
|
|
155
|
+
const p = (await r.json()).data.data.find(x => x.en_name === "<plugin_en_name>");
|
|
156
|
+
const fp = JSON.parse(p.config).file_paths;
|
|
157
|
+
return {
|
|
158
|
+
id: p.id, version: p.version, update_time: p.update_time,
|
|
159
|
+
files: fp.length,
|
|
160
|
+
fe: fp.filter(f => /hpt-frontend/.test(f)).length,
|
|
161
|
+
menu: p.guide_menu_entries,
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
JS
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
判断标准:
|
|
168
|
+
- `update_time` 变成刚才的时间(安装前记一次,对比)。
|
|
169
|
+
- `file_paths` 里后端(`huanpingtong-server`)和前端(`hpt-frontend`)都有条目;
|
|
170
|
+
前端至少 `vite-plugin.umd.js` / `.mjs` / `style.css` / 两个 `.map`。
|
|
171
|
+
- `guide_menu_entries` 是插件自己的菜单登记,`enabled:true` 才会出现在导航里。
|
|
172
|
+
|
|
173
|
+
### B. 线上实际下发的产物
|
|
174
|
+
|
|
175
|
+
插件前端**不在本站 `/plugins/...` 下发**(那里返回 22 字节 `/* script not found */`),
|
|
176
|
+
而是在 **TOS CDN**,且 `<script src>` 里的插件名带 `plugin_` 前缀:
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
https://bpmax.tos-cn-shanghai.volces.com/<tenant>/plugins/<plugin_en_name>/vite-plugin.umd.js?timestamp=<ms>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
`<tenant>` 形如 `lanjiantest_yitaiyitai_com`(环境域名把 `.` 换成 `_`)。从页面读,别猜:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
"$HOME/.local/bin/tabbit-cli" nodejs --task "Install plugin" --request-id verify-cdn <<'JS'
|
|
186
|
+
return await page.evaluate(() => Array.from(document.querySelectorAll("script[src]"))
|
|
187
|
+
.map(s => s.src).filter(s => /<plugin_keyword>/.test(s)));
|
|
188
|
+
JS
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
拿到 URL 后直接拉下来断言内容:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
curl -s -o /tmp/live-umd.js -w '%{http_code} %{size_download}\n' '<script src>'
|
|
195
|
+
shasum -a 256 /tmp/live-umd.js
|
|
196
|
+
grep -c '<本地包里有、但旧包没有的标识符>' /tmp/live-umd.js
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**时间戳会变**:重启后 `?timestamp=` 会被刷新成新的 ms 值,这是包确实换了的直接证据。
|
|
200
|
+
拿旧 timestamp 复拉的可能是缓存,务必从页面重新读一次。
|
|
201
|
+
|
|
202
|
+
### C. 页面渲染验收(防白屏)
|
|
203
|
+
|
|
204
|
+
插件控件有问题时最典型的表现是**白屏**,编辑器里什么都不渲染。至少打开一个用了该插件控件的页面:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
"$HOME/.local/bin/tabbit-cli" nodejs --task "Install plugin" --request-id verify-render --timeout-ms 120000 <<'JS'
|
|
208
|
+
await page.goto("https://<env>/w:<workspace>/form_template/<id>", {waitUntil: "domcontentloaded"});
|
|
209
|
+
await page.waitForTimeout(12000);
|
|
210
|
+
const result = await page.evaluate(() => ({
|
|
211
|
+
pluginNodes: document.querySelectorAll("[class*=\"<插件类名前缀>\"]").length,
|
|
212
|
+
errs: Array.from(document.querySelectorAll(".el-message--error")).map(e => e.textContent.trim()),
|
|
213
|
+
}));
|
|
214
|
+
return {...result, shot: await page.screenshot({fullPage: false})};
|
|
215
|
+
JS
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`pluginNodes > 0` 且 `errs` 为空才算通过。截图会以 artifact 回执返回路径,**用主机看图**:
|
|
219
|
+
节点数不为 0 但布局塌掉也算失败。
|
|
220
|
+
|
|
221
|
+
## 常见失败与判据
|
|
222
|
+
|
|
223
|
+
| 现象 | 判据 | 处理 |
|
|
224
|
+
| --- | --- | --- |
|
|
225
|
+
| 上传后无任何反应 | `performance` 里没有 `/api/plugin/upload` | 按钮没点中,换 `--tag button` 精确定位 |
|
|
226
|
+
| 上传报错 | `.el-message--error` 有文案 | 包体结构不对;确认 zip 里是 `dist/` 而非源码 |
|
|
227
|
+
| 点击后 tip 一直在 | reload 后仍是 `tip:true` | 重启没走通;重试一次,仍失败则看后端日志 |
|
|
228
|
+
| **tip 变 false 但功能还是旧的** | 探针(模型复述系统提示 / 新行为审计)对不上 | **假重启**:二次确认没点。回去点「确认」再 reload;不要用 `tip:false` 当后端生效的判据 |
|
|
229
|
+
| 编辑器白屏 | `pluginNodes === 0` | 大概率是控件 `setup()` 抛错;看 Console,回本地复现 |
|
|
230
|
+
| 有节点但样式错 | 节点数正常、截图塌陷 | `style.css` 没下发或类名冲突 |
|
|
231
|
+
| CDN 还是旧包 | `?timestamp=` 未变 | 重启未真正刷新;不要拿旧 URL 判断 |
|
|
232
|
+
|
|
233
|
+
## 环境无关性
|
|
234
|
+
|
|
235
|
+
换环境只改三样,其余流程完全一致:
|
|
236
|
+
|
|
237
|
+
1. 入口 URL 里的环境域名:Tabbit 直接打开 `https://<env>/w:<workspace>/plugins/`,不需要配 CDP 端口。
|
|
238
|
+
2. 工作区 key(`/w:<workspace>/`)。
|
|
239
|
+
3. `en_name` 与 `tenant` —— 从页面 `script[src]` 和 `/api/plugin` 回读,不写死。
|
|
240
|
+
|
|
241
|
+
(仅当 Tabbit 不可用、走只读降级时才额外设置 `CDP_URL`;降级只能回读和截图,不能上传或重启。)
|
|
242
|
+
|
|
243
|
+
## 硬约束
|
|
244
|
+
- 不得把手机号、验证码、Cookie、token、API Key 写进任何脚本、日志、截图说明或汇报文件。
|
|
245
|
+
- 不得读取或复用浏览器凭据/存储/手工请求头;本 skill 只用页面自身的登录态。
|
|
246
|
+
- 不得用 `bpmax-cli api`、curl 或页面 fetch **写**插件配置;安装动作只能在插件管理页做。
|
|
247
|
+
- 上传前必须校验 `dist.zip` 比源码新,避免装旧包。
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// BPMAX 浏览器操作助手:直连已打开的 Chrome(CDP),不依赖 chrome-devtools-mcp。
|
|
3
|
+
//
|
|
4
|
+
// 为什么不走 MCP:
|
|
5
|
+
// 1. MCP 的 upload_file / take_screenshot 会对路径做 workspace root 校验,
|
|
6
|
+
// 仓库不在它配置的 root 下时直接 Access denied;
|
|
7
|
+
// 2. 每次 `npx chrome-devtools-mcp` 起的是新进程,take_snapshot 生成的 uid
|
|
8
|
+
// 在下一次调用里失效(No snapshot found for page N)。
|
|
9
|
+
// 直连 CDP 两个问题都没有:DOM.setFileInputFiles 是浏览器原生命令,
|
|
10
|
+
// 元素定位在同一个连接里现取现用。
|
|
11
|
+
//
|
|
12
|
+
// 用法(--cdp 默认 http://127.0.0.1:9444):
|
|
13
|
+
// node bpmax-browser.mjs pages
|
|
14
|
+
// node bpmax-browser.mjs eval --url <子串> --expr '<js>' [--await]
|
|
15
|
+
// node bpmax-browser.mjs click --url <子串> --text '<可见文字>' [--tag button]
|
|
16
|
+
// node bpmax-browser.mjs upload --url <子串> --text '<按钮文字>' --file <绝对路径>
|
|
17
|
+
// node bpmax-browser.mjs shot --url <子串> --out <png 路径> [--full]
|
|
18
|
+
//
|
|
19
|
+
// 所有子命令都输出一行 JSON,退出码 0 成功、非 0 失败。
|
|
20
|
+
|
|
21
|
+
const argv = process.argv.slice(2);
|
|
22
|
+
const command = argv[0];
|
|
23
|
+
const opts = {};
|
|
24
|
+
for (let i = 1; i < argv.length; i += 1) {
|
|
25
|
+
const a = argv[i];
|
|
26
|
+
if (a.startsWith('--')) {
|
|
27
|
+
const key = a.slice(2);
|
|
28
|
+
const next = argv[i + 1];
|
|
29
|
+
if (next === undefined || next.startsWith('--')) {
|
|
30
|
+
opts[key] = true;
|
|
31
|
+
} else {
|
|
32
|
+
opts[key] = next;
|
|
33
|
+
i += 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const CDP = opts.cdp || process.env.CDP_URL || 'http://127.0.0.1:9444';
|
|
39
|
+
|
|
40
|
+
function fail(message, extra = {}) {
|
|
41
|
+
console.log(JSON.stringify({ ok: false, error: message, ...extra }));
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function connect(urlPart) {
|
|
46
|
+
const list = await (await fetch(`${CDP}/json/list`)).json();
|
|
47
|
+
const pages = list.filter((t) => t.type === 'page');
|
|
48
|
+
const page = urlPart
|
|
49
|
+
? pages.find((t) => t.url.includes(urlPart))
|
|
50
|
+
: pages.find((t) => !t.url.startsWith('devtools://'));
|
|
51
|
+
if (!page) {
|
|
52
|
+
fail(`no page matching "${urlPart}"`, { pages: pages.map((p) => p.url) });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const ws = new WebSocket(page.webSocketDebuggerUrl);
|
|
56
|
+
const pending = new Map();
|
|
57
|
+
const listeners = [];
|
|
58
|
+
let seq = 0;
|
|
59
|
+
|
|
60
|
+
// 浏览器端的 WebSocket 是事件目标,不是 Node 的 EventEmitter:必须用 addEventListener
|
|
61
|
+
ws.addEventListener('message', (ev) => {
|
|
62
|
+
const msg = JSON.parse(String(ev.data));
|
|
63
|
+
if (msg.id && pending.has(msg.id)) {
|
|
64
|
+
pending.get(msg.id)(msg);
|
|
65
|
+
pending.delete(msg.id);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (msg.method) listeners.forEach((fn) => fn(msg));
|
|
69
|
+
});
|
|
70
|
+
await new Promise((resolve, reject) => {
|
|
71
|
+
ws.addEventListener('open', resolve, { once: true });
|
|
72
|
+
ws.addEventListener('error', () => reject(new Error('cdp connect failed')), { once: true });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const send = (method, params = {}) =>
|
|
76
|
+
new Promise((resolve) => {
|
|
77
|
+
const id = (seq += 1);
|
|
78
|
+
pending.set(id, resolve);
|
|
79
|
+
ws.send(JSON.stringify({ id, method, params }));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const waitFor = (method, timeoutMs) =>
|
|
83
|
+
new Promise((resolve) => {
|
|
84
|
+
const timer = setTimeout(() => resolve(null), timeoutMs);
|
|
85
|
+
listeners.push((msg) => {
|
|
86
|
+
if (msg.method === method) {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
resolve(msg.params);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return { ws, send, waitFor, page };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function unwrap(res, label) {
|
|
97
|
+
if (res.error) fail(`${label}: ${JSON.stringify(res.error)}`);
|
|
98
|
+
if (res.result?.exceptionDetails) {
|
|
99
|
+
fail(`${label}: ${res.result.exceptionDetails.text}`, {
|
|
100
|
+
detail: String(res.result.exceptionDetails.exception?.description || '').slice(0, 800),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return res.result?.result?.value;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 按可见文字定位:取可见、文字完全匹配的最小元素,避免命中容器
|
|
107
|
+
const locateExpr = (text, tag) => `(() => {
|
|
108
|
+
const want = ${JSON.stringify(text)};
|
|
109
|
+
const norm = (s) => (s || '').replace(/\\s+/g, '');
|
|
110
|
+
const sel = ${JSON.stringify(tag || '*')};
|
|
111
|
+
const hits = Array.from(document.querySelectorAll(sel))
|
|
112
|
+
.filter((e) => e.offsetParent !== null && norm(e.textContent) === norm(want))
|
|
113
|
+
.map((e) => {
|
|
114
|
+
const r = e.getBoundingClientRect();
|
|
115
|
+
return { e, r, area: r.width * r.height };
|
|
116
|
+
})
|
|
117
|
+
.filter((x) => x.area > 0)
|
|
118
|
+
.sort((a, b) => a.area - b.area);
|
|
119
|
+
if (!hits.length) return null;
|
|
120
|
+
const { e, r } = hits[0];
|
|
121
|
+
return {
|
|
122
|
+
x: r.x + r.width / 2,
|
|
123
|
+
y: r.y + r.height / 2,
|
|
124
|
+
width: Math.round(r.width),
|
|
125
|
+
height: Math.round(r.height),
|
|
126
|
+
tag: e.tagName,
|
|
127
|
+
cls: typeof e.className === 'string' ? e.className : '',
|
|
128
|
+
};
|
|
129
|
+
})()`;
|
|
130
|
+
|
|
131
|
+
async function clickAt(send, box) {
|
|
132
|
+
for (const type of ['mousePressed', 'mouseReleased']) {
|
|
133
|
+
await send('Input.dispatchMouseEvent', {
|
|
134
|
+
type,
|
|
135
|
+
x: box.x,
|
|
136
|
+
y: box.y,
|
|
137
|
+
button: 'left',
|
|
138
|
+
clickCount: 1,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function main() {
|
|
144
|
+
if (!command || command === 'help') {
|
|
145
|
+
fail('usage: pages | eval | click | upload | shot');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (command === 'pages') {
|
|
149
|
+
const list = await (await fetch(`${CDP}/json/list`)).json();
|
|
150
|
+
console.log(JSON.stringify({
|
|
151
|
+
ok: true,
|
|
152
|
+
pages: list.filter((t) => t.type === 'page').map((t) => ({ url: t.url, title: t.title })),
|
|
153
|
+
}));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const conn = await connect(opts.url);
|
|
158
|
+
const { ws, send, waitFor, page } = conn;
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
if (command === 'eval') {
|
|
162
|
+
if (!opts.expr) fail('--expr required');
|
|
163
|
+
await send('Runtime.enable');
|
|
164
|
+
const res = await send('Runtime.evaluate', {
|
|
165
|
+
expression: opts.expr,
|
|
166
|
+
returnByValue: true,
|
|
167
|
+
awaitPromise: opts.await === true,
|
|
168
|
+
userGesture: true,
|
|
169
|
+
});
|
|
170
|
+
console.log(JSON.stringify({ ok: true, url: page.url, value: unwrap(res, 'eval') }));
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (command === 'shot') {
|
|
175
|
+
if (!opts.out) fail('--out required');
|
|
176
|
+
const res = await send('Page.captureScreenshot', {
|
|
177
|
+
format: 'png',
|
|
178
|
+
captureBeyondViewport: opts.full === true,
|
|
179
|
+
});
|
|
180
|
+
if (res.error) fail(`screenshot: ${JSON.stringify(res.error)}`);
|
|
181
|
+
const { writeFileSync } = await import('node:fs');
|
|
182
|
+
writeFileSync(opts.out, Buffer.from(res.result.data, 'base64'));
|
|
183
|
+
console.log(JSON.stringify({ ok: true, url: page.url, out: opts.out }));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (command === 'click') {
|
|
188
|
+
if (!opts.text) fail('--text required');
|
|
189
|
+
const res = await send('Runtime.evaluate', {
|
|
190
|
+
expression: locateExpr(opts.text, opts.tag),
|
|
191
|
+
returnByValue: true,
|
|
192
|
+
});
|
|
193
|
+
const box = unwrap(res, 'locate');
|
|
194
|
+
if (!box) fail(`text not found: ${opts.text}`);
|
|
195
|
+
await clickAt(send, box);
|
|
196
|
+
console.log(JSON.stringify({ ok: true, url: page.url, text: opts.text, box }));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (command === 'upload') {
|
|
201
|
+
if (!opts.text || !opts.file) fail('--text and --file required');
|
|
202
|
+
await send('Page.enable');
|
|
203
|
+
await send('DOM.enable');
|
|
204
|
+
// 拦截原生文件选择器:点按钮 -> fileChooserOpened 给出 backendNodeId -> 塞文件。
|
|
205
|
+
// 不依赖 <input type=file> 是否 display:none,也不怕 Vue 重渲染换节点。
|
|
206
|
+
await send('Page.setInterceptFileChooserDialog', { enabled: true });
|
|
207
|
+
|
|
208
|
+
const res = await send('Runtime.evaluate', {
|
|
209
|
+
expression: locateExpr(opts.text, opts.tag),
|
|
210
|
+
returnByValue: true,
|
|
211
|
+
});
|
|
212
|
+
const box = unwrap(res, 'locate');
|
|
213
|
+
if (!box) fail(`button not found: ${opts.text}`);
|
|
214
|
+
|
|
215
|
+
const chooserPromise = waitFor('Page.fileChooserOpened', 8000);
|
|
216
|
+
await clickAt(send, box);
|
|
217
|
+
const chooser = await chooserPromise;
|
|
218
|
+
if (!chooser) {
|
|
219
|
+
await send('Page.setInterceptFileChooserDialog', { enabled: false });
|
|
220
|
+
fail('file chooser did not open', { button: opts.text });
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const set = await send('DOM.setFileInputFiles', {
|
|
224
|
+
backendNodeId: chooser.backendNodeId,
|
|
225
|
+
files: [opts.file],
|
|
226
|
+
});
|
|
227
|
+
await send('Page.setInterceptFileChooserDialog', { enabled: false });
|
|
228
|
+
if (set.error) fail(`setFileInputFiles: ${JSON.stringify(set.error)}`);
|
|
229
|
+
console.log(JSON.stringify({
|
|
230
|
+
ok: true,
|
|
231
|
+
url: page.url,
|
|
232
|
+
button: opts.text,
|
|
233
|
+
mode: chooser.mode,
|
|
234
|
+
file: opts.file,
|
|
235
|
+
}));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
fail(`unknown command: ${command}`);
|
|
240
|
+
} finally {
|
|
241
|
+
ws.close();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
main().catch((err) => fail(err.message));
|
|
@@ -6,6 +6,8 @@ description: Manage BPMAX plugin activation, plugin-scoped Agent skills, and plu
|
|
|
6
6
|
|
|
7
7
|
# BPMAX Plugin Config
|
|
8
8
|
|
|
9
|
+
> **本页是专题参考,入口在 `bpmax-plugin-development`。** 本页只处理插件激活与插件自有配置。
|
|
10
|
+
|
|
9
11
|
Use this skill when a BPMAX task involves installing or activating a plugin, discovering its Agent Skill, or changing plugin-owned configuration.
|
|
10
12
|
|
|
11
13
|
## Distinguish the four plugin states
|
|
@@ -44,22 +46,12 @@ bpmax-cli plugin activation defaults set --plugin <plugin_name> --profile <profi
|
|
|
44
46
|
- A locally modified or unowned Skill directory is `conflicted` and is never overwritten by automatic update. Both the Agent-visible copy and the profile-scoped lint/config adapter copy are hash-checked. An explicit `plugin skills update` may adopt a legacy unowned copy after the operator chooses to replace it.
|
|
45
47
|
- The install directory records `.bpmax-plugin-skill.json` with the source profile, origin, plugin, version, and hash. A running Agent may need a new task before it reloads updated instructions; CLI lint/adapters are effective immediately.
|
|
46
48
|
|
|
47
|
-
##
|
|
48
|
-
|
|
49
|
-
1. Confirm the target profile and origin from the user's context or existing `bpmax-cli` profile. Plugin Skill discovery is site-wide and is not bound to a BPMAX business workspace.
|
|
50
|
-
2. Check available and outdated plugin skills:
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
bpmax-cli plugin skills check --profile <profile> --agent codex --format json
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
3. If the needed plugin skill is not installed locally, install it explicitly:
|
|
49
|
+
## Plugin Skill 发现与安装
|
|
57
50
|
|
|
58
|
-
|
|
59
|
-
bpmax-cli plugin skills ensure <plugin_name> --profile <profile> --agent codex --format json
|
|
60
|
-
```
|
|
51
|
+
插件生命周期的总流程见 `bpmax-plugin-development`;本页不再重复「检查 → 安装 → 读取」的完整流程,只保留与激活、插件自有配置相关的规则。`plugin skills check` / `ensure` 等命令仍在下方 `## Useful Commands` 中。
|
|
61
52
|
|
|
62
|
-
|
|
53
|
+
- 先确认目标 profile 与 origin。Plugin Skill 发现是站点级的,不绑定 BPMAX 业务工作区。
|
|
54
|
+
- 编辑或测试某个插件的配置前,先读该插件安装后的 `SKILL.md`。
|
|
63
55
|
|
|
64
56
|
## Safety Rules
|
|
65
57
|
|