@sparkelf/dsh-dataops-managed 0.3.53 → 0.4.0

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.
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * DataOps spreadsheet-import transport for the collection skill.
3
3
  *
4
- * The host reads a workspace attachment, uploads it as multipart, asks DataOps for a
5
- * create-table or existing-table plan, and only executes when the model calls the
6
- * execute tool after the user's plan confirmation. Nothing here creates a table on
7
- * preview/plan; execution is the single mutating call.
4
+ * The host reads a workspace attachment, uploads it as multipart, and validates the
5
+ * create-table or existing-table plan the current conversation model wrote. DataOps only
6
+ * normalizes that plan and returns SQL/mapping summaries; it never selects or calls a shared
7
+ * model. Execution is the single mutating call and stays behind the user's explicit
8
+ * confirmation.
8
9
  *
9
10
  * @module collect-api
10
11
  */
@@ -33,10 +34,10 @@ export interface CollectPreview {
33
34
  columns?: Array<Record<string, unknown>>;
34
35
  [key: string]: unknown;
35
36
  }
36
- /** A create-table or field-mapping plan plus its session context. */
37
- export interface CollectPlanResult {
37
+ /** The deterministic validation result: the normalized plan and its session context. */
38
+ export interface CollectValidatePlanResult {
39
+ success?: boolean;
38
40
  session?: Record<string, unknown>;
39
- model?: Record<string, unknown>;
40
41
  plan?: Record<string, unknown>;
41
42
  [key: string]: unknown;
42
43
  }
@@ -85,15 +86,23 @@ export declare class CollectApi {
85
86
  constructor(reviewApi: ReviewApi);
86
87
  preview(filePath: string): Promise<CollectPreview>;
87
88
  dataSources(): Promise<CollectDataSource[]>;
88
- plan(payload: {
89
+ /**
90
+ * Validate and normalize a plan written by the current conversation model.
91
+ *
92
+ * Read-only and model-free: the backend runs the same deterministic sanitizers as
93
+ * `/plan` and `/execute`, then returns the normalized plan, CREATE TABLE SQL or mapping
94
+ * summary. It never resolves a shared `AiModelConfig` or calls a provider.
95
+ */
96
+ validatePlan(payload: {
89
97
  sessionId: string;
90
98
  dataSourceUrn?: string;
91
99
  targetTable?: {
92
100
  schema: string;
93
101
  table: string;
94
102
  };
95
- modelId?: number;
96
- }): Promise<CollectPlanResult>;
103
+ createPlan?: Record<string, unknown>;
104
+ mappings?: unknown[];
105
+ }): Promise<CollectValidatePlanResult>;
97
106
  execute(payload: Record<string, unknown>): Promise<CollectExecuteResult>;
98
107
  listResources(query?: string, limit?: number): Promise<CollectResourceRow[]>;
99
108
  }
@@ -157,7 +157,7 @@ export declare const AI_TOOL_ACCESS: {
157
157
  readonly dataops_collect_preview: {
158
158
  readonly permission: "data:resource:manage";
159
159
  };
160
- readonly dataops_collect_plan: {
160
+ readonly dataops_collect_validate_plan: {
161
161
  readonly permission: "data:resource:manage";
162
162
  };
163
163
  readonly dataops_collect_execute: {
@@ -167,6 +167,19 @@ export declare const AI_TOOL_ACCESS: {
167
167
  readonly permission: "data:resource:read";
168
168
  };
169
169
  readonly dataops_open_resource_tab: {};
170
+ readonly dataops_user_lookup: {
171
+ readonly permission: "system:user:read";
172
+ };
173
+ readonly dataops_user_create: {
174
+ readonly capability: "admin.manage";
175
+ readonly adminOnly: true;
176
+ readonly defaultEnabled: true;
177
+ };
178
+ readonly dataops_role_assign: {
179
+ readonly capability: "admin.manage";
180
+ readonly adminOnly: true;
181
+ readonly defaultEnabled: true;
182
+ };
170
183
  readonly dataops_resource_pending_list: {
171
184
  readonly capability: "resource.manage";
172
185
  readonly adminOnly: true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-dataops-managed",
3
- "version": "0.3.53",
3
+ "version": "0.4.0",
4
4
  "description": "DataOps JWT intake and credential-backed MCP tools for managed DeepSeek Harness workspaces.",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -42,10 +42,12 @@
42
42
  "skills/dataops-query/SKILL.md",
43
43
  "skills/dataops-query/i18n/zh.json",
44
44
  "skills/dataops-collect/SKILL.md",
45
+ "skills/dataops-collect/references/*.md",
45
46
  "skills/admin-workspace-rescue/SKILL.md",
46
47
  "README.md",
47
48
  "LICENSE",
48
- "skills/**/SKILL.md"
49
+ "skills/**/SKILL.md",
50
+ "skills/browser/references/**/*"
49
51
  ],
50
52
  "scripts": {
51
53
  "build": "rm -rf lib && tsc -p tsconfig.build.json && tsdown",
@@ -0,0 +1,81 @@
1
+ ---
2
+ name: browser
3
+ description: 浏览器自动化总入口。抓取网页/大屏/表格、登录后取数、或用用户本地 Chrome/Edge 操作内网系统时使用。默认工作区 Playwright headless;只有用户明确要求本地浏览器、已登录 Chrome 或 Companion 才走 Browser Bridge。包含 headless、Companion 桥接与旧 Chrome 安装排查三套按需参考。
4
+ ---
5
+
6
+ # Browser
7
+
8
+ 浏览器自动化只有一个入口。先按用户意图选模式,再按需读取对应参考;不要把两套运行方式混在一起,也不要用 curl/静态抓取冒充浏览器操作。
9
+
10
+ ## 触发条件
11
+
12
+ - 抓取网页、大屏、表格、图表数据,或把页面结果整理成 JSON / 截图;
13
+ - 用给定账号密码登录后取数;
14
+ - 在用户自己的本地 Chrome/Edge 里打开内网系统、登录、点击、填表、截图;
15
+ - 需要用户扫码、短信验证码或 MFA 接管;
16
+ - 排查 Browser Bridge / Companion / 旧 Chrome 扩展的安装与连接问题。
17
+
18
+ ## 先选模式
19
+
20
+ ```text
21
+ 默认:headless
22
+ 只有用户明确要求本地浏览器或已登录 Chrome → companion
23
+ ```
24
+
25
+ | 用户意图 | 模式 |
26
+ |---|---|
27
+ | “抓取这个大屏/网页/表格” | headless |
28
+ | 给了账号密码 | headless + 凭据插件 |
29
+ | “用我电脑上的浏览器” | companion |
30
+ | “用我已经登录的 Chrome” | companion |
31
+ | “用 companion” | companion |
32
+ | 需要扫码/短信/MFA 接管 | companion |
33
+
34
+ Agent 不得自行切换 companion;需要时先询问用户。
35
+
36
+ ## 按需加载
37
+
38
+ 主文件只负责路由和硬规则。进入某个模式后,再读取对应参考:
39
+
40
+ - **headless(默认)**:[references/headless.md](references/headless.md) — Playwright + Chromium 工作流、脚本模板、凭据登录、大屏抓取、失败处理、输出约定。
41
+ - **companion(本地浏览器)**:[references/bridge.md](references/bridge.md) — `browser_bridge_status` / `browser_bridge_connect` 探测、门户一键配对、`browser_*` 工具流程、安全边界与常见错误。
42
+ - **旧 Chrome 扩展安装/排查**:[references/chrome-install.md](references/chrome-install.md) — 已废弃的扩展安装流程,仅在排查旧环境时读取;脚本在 [references/scripts/](references/scripts/) 下。
43
+
44
+ ## 通用硬规则
45
+
46
+ ### 凭据
47
+
48
+ - 用户账号密码先存凭据插件,Agent 只拿 `secretRef`;
49
+ - 密码不得出现在 prompt、脚本、日志、截图;
50
+ - headless 通过环境变量/secretRef 登录;
51
+ - 登录失败、验证码或短信验证时停止并询问;不要自动切 companion。
52
+
53
+ ### 安全
54
+
55
+ - headless 只访问用户明确给出的域名;禁止 localhost、127.0.0.1、169.254.169.254、内网管理端口;
56
+ - companion 只操作用户明确授权的域名,允许用户已登录的内网系统;授权边界见 [references/bridge.md](references/bridge.md);
57
+ - 并发 1,默认超时 60s;
58
+ - 独立 context,不持久化 cookie;
59
+ - 提交、下单、删除、发布前必须用户确认;
60
+ - 不读取、不导出、不上传 Cookie、LocalStorage 或密码;不绕过验证码和风控。
61
+
62
+ ### 成功判据
63
+
64
+ - 不以“点击成功”或“页面打开了”作为成功;必须校验数据条数、字段、接口状态或页面关键文本;
65
+ - 抓取结果同时写入 `result.json` 与 `screenshot.png`(路径见对应参考);
66
+ - 页面为空或结构变化时报告事实,不猜数据、不伪造结果。
67
+
68
+ ## 输出
69
+
70
+ ```text
71
+ /workspace/outputs/browser/<task>/
72
+ ├── result.json # 数据、来源 URL、抓取时间
73
+ └── screenshot.png # 关键页面
74
+ ```
75
+
76
+ 回复用户:数据条数、字段、来源 URL、异常;不要把整页 HTML 贴进回答。
77
+
78
+ ## 相关技能
79
+
80
+ - `browser-cdp-automation`:接管真实 Chrome / CDP 的通用排障(本技能之外的环境问题)。
81
+ - `dataops-collect`:把抓到的表格/Excel/CSV 建成可问数的数据资源。
@@ -1,8 +1,3 @@
1
- ---
2
- name: browser-bridge-companion
3
- description: 用户要在自己的本地 Chrome/Edge 里打开内网系统、登录、点页面、填表、截图或做网页自动化时使用。先调用 browser_bridge_status 探测 Companion;未连接时调用 browser_bridge_connect 主动连接,仍失败再让用户打开门户「浏览器桥接」一键配对或启动托盘。不要向用户索取配对码、密码或 Cookie。
4
- ---
5
-
6
1
  # 浏览器桥接 Companion
7
2
 
8
3
  用户说「打开这个网页」「登录内网系统」「帮我点一下」「填这个表」「截个图」并涉及**用户本地浏览器**时,按本技能执行。
@@ -58,4 +53,4 @@ description: 用户要在自己的本地 Chrome/Edge 里打开内网系统、登
58
53
  ## 当前版本说明
59
54
 
60
55
  安装包是离线 Windows 包,内含 Chromium、Node 和 Playwright MCP;安装和启动不需要外网。
61
- 本次交付未重打安装包,已安装机器通过替换 `companion.mjs` / `tray.ps1` 获得生产链路与托盘。
56
+ 本次交付未重打安装包,已安装机器通过替换 `companion.mjs` / `tray.ps1` 获得生产链路与托盘。
@@ -0,0 +1,309 @@
1
+ > **已废弃(2026-11):** 本参考描述的是旧 Chrome 扩展安装流程。现在请优先使用 [bridge.md](bridge.md) 的离线 Companion + Playwright MCP。保留本文仅用于排查旧环境。
2
+
3
+ # Browser Bridge Chrome Install
4
+
5
+ ## Overview
6
+
7
+ Prepare a local browser for DataOps `browser` tool verification on Windows.
8
+
9
+ This skill covers the stable operator workflow for automated test-browser startup, unpacked extension refresh, backend bridge verification, and the fallback manual Google Chrome flow.
10
+
11
+ ## Preconditions
12
+
13
+ - Work from the `dataops` repo on the same Windows machine that runs Chrome/Chromium.
14
+ - The snippets read the admin password from `DATAOPS_ADMIN_PASSWORD`; never paste a real credential into this file, a script, or a log.
15
+ - `references/scripts/start_test_browser_bridge.cjs` also needs `DATAOPS_PROJECTS_ROOT` pointing at the directory that contains the `dataops` checkout, and `DATAOPS_BROWSER_BRIDGE_PASSWORD` for the login.
16
+ - Reuse the current DataOps backend/frontend when available; do not restart them unless the user asks.
17
+ - Treat browser-side install as local-machine state. It is acceptable to open browser UI, but do not mutate unrelated browser profiles.
18
+ - Prefer an isolated Playwright Chromium profile for automated testing. Only use the user's Google Chrome profile when they explicitly ask to.
19
+
20
+ ## Stable Workflow
21
+
22
+ ### 1. Confirm backend truth first
23
+
24
+ Run these checks before touching the browser:
25
+
26
+ ```powershell
27
+ Get-NetTCPConnection -State Listen -LocalPort 3000,3101 -ErrorAction SilentlyContinue |
28
+ Select-Object LocalPort,OwningProcess,State
29
+ ```
30
+
31
+ ```powershell
32
+ @'
33
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
34
+ (async() => {
35
+ const loginResponse = await fetch('https://127.0.0.1:3101/api/auth/login', {
36
+ method: 'POST',
37
+ headers: { 'content-type': 'application/json' },
38
+ body: JSON.stringify({ account: 'admin', password: process.env.DATAOPS_ADMIN_PASSWORD }),
39
+ });
40
+ const loginPayload = await loginResponse.json();
41
+ const toolsResponse = await fetch('https://127.0.0.1:3101/api/ai/tools', {
42
+ headers: { Authorization: `Bearer ${loginPayload.accessToken}` },
43
+ });
44
+ const toolsPayload = await toolsResponse.json();
45
+ const browserTool = toolsPayload.tools.find((tool) => tool.name === 'browser');
46
+ console.log(JSON.stringify({
47
+ browserBridge: browserTool?.browserBridge ?? null,
48
+ dependencyPackage: browserTool?.dependencyPackage ?? null,
49
+ }, null, 2));
50
+ })();
51
+ '@ | node -
52
+ ```
53
+
54
+ Interpretation:
55
+
56
+ - `dependencyPackage.available = true` means backend package generation works.
57
+ - `browserBridge.connected = false` means Chrome-side install/connect work is still required.
58
+ - `workspaceStatus = RUNNING` is needed later for screenshot persistence, but not for extension install.
59
+
60
+ ### 2. Download and unpack the extension package
61
+
62
+ Save the package and unpack it into a predictable local folder:
63
+
64
+ ```powershell
65
+ @'
66
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
67
+ (async() => {
68
+ const fs = require('fs');
69
+ const loginResponse = await fetch('https://127.0.0.1:3101/api/auth/login', {
70
+ method: 'POST',
71
+ headers: { 'content-type': 'application/json' },
72
+ body: JSON.stringify({ account: 'admin', password: process.env.DATAOPS_ADMIN_PASSWORD }),
73
+ });
74
+ const loginPayload = await loginResponse.json();
75
+ const response = await fetch('https://127.0.0.1:3101/api/ai/tools/browser/dependency-package', {
76
+ headers: { Authorization: `Bearer ${loginPayload.accessToken}` },
77
+ });
78
+ fs.writeFileSync('D:/project/projects/tmp-dataops-browser-bridge.zip', Buffer.from(await response.arrayBuffer()));
79
+ })();
80
+ '@ | node -
81
+ ```
82
+
83
+ ```powershell
84
+ if (Test-Path D:\project\projects\tmp-dataops-browser-bridge) {
85
+ Remove-Item -LiteralPath D:\project\projects\tmp-dataops-browser-bridge -Recurse -Force
86
+ }
87
+ Expand-Archive -LiteralPath D:\project\projects\tmp-dataops-browser-bridge.zip `
88
+ -DestinationPath D:\project\projects\tmp-dataops-browser-bridge -Force
89
+ ```
90
+
91
+ The unpacked extension root is:
92
+
93
+ - `D:\project\projects\tmp-dataops-browser-bridge\extension`
94
+
95
+ ### 3. Preferred automated path: launch the test browser
96
+
97
+ The preferred automated path is the Playwright Chromium browser that loads the latest unpacked Browser Bridge and connects it to the current backend automatically.
98
+
99
+ Run from this skill's base directory (the directory containing this `references/` folder):
100
+
101
+ ```powershell
102
+ node .\references\scripts\start_test_browser_bridge.cjs --keep-open
103
+ ```
104
+
105
+ Expected success signal:
106
+
107
+ - the script prints `backendBridge.connected = true`
108
+ - the script prints an `extensionId`, `workerUrl`, and non-empty `sessionId`
109
+ - backend `GET /api/ai/tools` shows `browser.browserBridge.connected = true`
110
+
111
+ What the script does:
112
+
113
+ - logs into backend with the current admin account
114
+ - reads `browser.dependencyPackage.version` from backend truth
115
+ - downloads and unpacks the latest Browser Bridge package when the local unpacked directory is missing or when the recorded package version no longer matches backend truth
116
+ - launches a persistent Playwright Chromium profile
117
+ - loads the unpacked extension with `--disable-extensions-except` and `--load-extension`
118
+ - opens the DataOps frontend, injects the login token into the page, opens the extension popup, fills the DataOps URL, and lets the extension auto-poll until it resolves the same-origin signed-in session and connects
119
+ - polls both popup state and backend state until the bridge is connected
120
+
121
+ Use this path for automated testing and repeatable local verification.
122
+
123
+ ### 4. Fallback manual path: isolated Google Chrome
124
+
125
+ Use a dedicated profile and CDP port so manual Google Chrome validation does not collide with the user's normal Chrome windows:
126
+
127
+ ```powershell
128
+ $chrome = 'C:\Users\Administrator\AppData\Local\Google\Chrome\Bin\chrome.exe'
129
+ $profile = 'D:\project\projects\tmp-chrome-browser-bridge-profile'
130
+ $extension = 'D:\project\projects\tmp-dataops-browser-bridge\extension'
131
+ New-Item -ItemType Directory -Force -Path $profile | Out-Null
132
+ Start-Process -FilePath $chrome -ArgumentList @(
133
+ "--user-data-dir=$profile",
134
+ '--disable-background-networking',
135
+ '--remote-debugging-port=9999',
136
+ "--disable-extensions-except=$extension",
137
+ "--load-extension=$extension",
138
+ '--no-first-run',
139
+ '--no-default-browser-check',
140
+ '--ignore-certificate-errors',
141
+ '--new-window',
142
+ 'https://127.0.0.1:3000'
143
+ )
144
+ ```
145
+
146
+ Confirm CDP is reachable:
147
+
148
+ ```powershell
149
+ curl.exe http://127.0.0.1:9999/json/version
150
+ ```
151
+
152
+ ### 5. Manual install and reload method
153
+
154
+ Use this path only when the user explicitly wants Google Chrome itself rather than the automated test browser:
155
+
156
+ 1. Open `chrome://extensions/`
157
+ 2. Turn on `Developer mode`
158
+ 3. Click `Load unpacked`
159
+ 4. Select `D:\project\projects\tmp-dataops-browser-bridge\extension`
160
+ 5. Open a logged-in DataOps tab in the same Chrome instance
161
+ 6. Open the `DataOps Browser Bridge` popup
162
+ 7. Enter the DataOps URL or paste a full DataOps page URL
163
+ 8. Leave the popup open while it auto-polls for the same-origin signed-in session and connects; `Connect bridge` is only an immediate manual retry.
164
+
165
+ For an already installed unpacked extension after code changes:
166
+
167
+ 1. Keep the unpacked folder path stable
168
+ 2. Open `chrome://extensions/`
169
+ 3. Use the existing extension card's `Reload`
170
+ 4. Reopen the popup and wait for auto-connect if backend restarted
171
+
172
+ ### 6. Current automation boundary
173
+
174
+ What automation can do reliably today:
175
+
176
+ - confirm backend Browser Bridge truth
177
+ - download and unpack the extension package
178
+ - launch Playwright Chromium with the extension and connect it automatically
179
+ - launch isolated Google Chrome with CDP
180
+ - open `chrome://extensions/`
181
+ - click `Load unpacked`
182
+ - detect the native folder-picker dialog and enumerate its controls
183
+
184
+ What remains unreliable and should be treated as a manual confirmation point:
185
+
186
+ - consumer Google Chrome on Windows does not provide a stable script-only path for registering the unpacked extension into `chrome.management`
187
+ - in project-local verification, Google Chrome logs `--disable-extensions-except is not allowed in Google Chrome, ignoring.`, so the automated path must target Playwright Chromium rather than the user's regular Google Chrome installation
188
+ - the native Windows Google Chrome folder picker for unpacked extensions does not reliably accept Win32 `WM_SETTEXT`, synthetic `SendKeys`, or repeated button invoke attempts in a way that registers the unpacked extension into `chrome.management`
189
+ - in the current verified environment, Google Chrome can still expose `chrome-extension://.../popup.html` targets that resolve to `chrome-error://chromewebdata/ ERR_FILE_NOT_FOUND`; do not treat those targets as proof the extension is installed
190
+
191
+ Therefore the stable workflow is:
192
+
193
+ - use Playwright Chromium for any automated Browser Bridge testing
194
+ - reserve Google Chrome for manual operator validation only
195
+ - if Google Chrome must be used, let the operator manually confirm the `extension/` directory in the folder picker and then continue with popup import/connect validation
196
+
197
+ ## Verification
198
+
199
+ ### Automated test-browser verification
200
+
201
+ After `start_test_browser_bridge.cjs`, verify backend state directly:
202
+
203
+ ```powershell
204
+ cd dataops
205
+ node .\references\scripts\check_browser_bridge_status.js
206
+ ```
207
+
208
+ Success condition:
209
+
210
+ - `browserBridge.connected = true`
211
+ - `activeSessionCount >= 1`
212
+
213
+ ### Manual Google Chrome verification
214
+
215
+ After manual confirmation, verify the extension is real rather than trusting stale popup targets:
216
+
217
+ ```powershell
218
+ @'
219
+ const path = require('path');
220
+ const { createRequire } = require('module');
221
+ const frontendRequire = createRequire(path.resolve('d:/project/projects/dataops/frontend/package.json'));
222
+ const { chromium } = frontendRequire('playwright');
223
+ (async () => {
224
+ const browser = await chromium.connectOverCDP('http://127.0.0.1:9999');
225
+ const context = browser.contexts()[0];
226
+ const page = await context.newPage();
227
+ await page.goto('chrome://extensions/', { waitUntil: 'domcontentloaded', timeout: 60000 });
228
+ const result = await page.evaluate(() => new Promise((resolve, reject) => {
229
+ chrome.management.getAll((items) => {
230
+ const err = chrome.runtime?.lastError?.message;
231
+ if (err) return reject(new Error(err));
232
+ resolve(items.map((item) => ({
233
+ id: item.id,
234
+ name: item.name,
235
+ enabled: item.enabled,
236
+ installType: item.installType,
237
+ type: item.type,
238
+ })));
239
+ });
240
+ }));
241
+ console.log(JSON.stringify(result, null, 2));
242
+ await browser.close();
243
+ })();
244
+ '@ | node -
245
+ ```
246
+
247
+ Success condition:
248
+
249
+ - `chrome.management.getAll()` contains `DataOps Browser Bridge`
250
+
251
+ Failure condition:
252
+
253
+ - `getAll()` stays empty or does not include the Browser Bridge entry
254
+ - any `chrome-extension://.../popup.html` target still renders `chrome-error://chromewebdata/ ERR_FILE_NOT_FOUND`
255
+
256
+ ### Backend-side verification
257
+
258
+ After popup auto-connect, backend must flip to connected:
259
+
260
+ ```powershell
261
+ @'
262
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
263
+ (async() => {
264
+ const loginResponse = await fetch('https://127.0.0.1:3101/api/auth/login', {
265
+ method: 'POST',
266
+ headers: { 'content-type': 'application/json' },
267
+ body: JSON.stringify({ account: 'admin', password: process.env.DATAOPS_ADMIN_PASSWORD }),
268
+ });
269
+ const loginPayload = await loginResponse.json();
270
+ const toolsResponse = await fetch('https://127.0.0.1:3101/api/ai/tools', {
271
+ headers: { Authorization: `Bearer ${loginPayload.accessToken}` },
272
+ });
273
+ const toolsPayload = await toolsResponse.json();
274
+ const browserTool = toolsPayload.tools.find((tool) => tool.name === 'browser');
275
+ console.log(JSON.stringify(browserTool?.browserBridge ?? null, null, 2));
276
+ })();
277
+ '@ | node -
278
+ ```
279
+
280
+ Success condition:
281
+
282
+ - `connected = true`
283
+ - `activeSessionCount >= 1`
284
+
285
+ ## Recovery Notes
286
+
287
+ - If backend still shows `Bridge required`, reopen the popup in the same browser instance and wait for auto-connect.
288
+ - If `start_test_browser_bridge.cjs` fails before backend flips to connected, rerun it with the latest unpacked package in place and read the emitted popup/backend state rather than switching immediately to the manual Chrome path.
289
+ - If `chrome.management.getAll()` does not show `DataOps Browser Bridge` in Google Chrome, do not keep retrying synthetic text-entry against the folder picker. Reopen `chrome://extensions/` and perform the final folder selection manually.
290
+ - If Chrome is already running on the default profile, prefer the isolated profile/CDP launch above instead of reusing the default profile for automation.
291
+
292
+ ## Cleanup
293
+
294
+ Only remove temporary artifacts that were created for isolated automation:
295
+
296
+ ```powershell
297
+ Get-CimInstance Win32_Process -Filter \"Name = 'chrome.exe'\" |
298
+ Where-Object { $_.CommandLine -like '*tmp-chrome-browser-bridge-profile*' } |
299
+ ForEach-Object { Stop-Process -Id $_.ProcessId -Force }
300
+ ```
301
+
302
+ ```powershell
303
+ Remove-Item D:\project\projects\tmp-dataops-browser-bridge.zip -Force -ErrorAction SilentlyContinue
304
+ Remove-Item D:\project\projects\tmp-dataops-browser-bridge -Recurse -Force -ErrorAction SilentlyContinue
305
+ Remove-Item D:\project\projects\tmp-chrome-browser-bridge-profile -Recurse -Force -ErrorAction SilentlyContinue
306
+ Remove-Item D:\project\projects\tmp-chrome-browser-bridge-profile-2 -Recurse -Force -ErrorAction SilentlyContinue
307
+ Remove-Item D:\project\projects\tmp-playwright-browser-bridge-profile -Recurse -Force -ErrorAction SilentlyContinue
308
+ Remove-Item D:\project\projects\tmp-chrome-browser-bridge-profile-log -Recurse -Force -ErrorAction SilentlyContinue
309
+ ```
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Browser Bridge Chrome Install"
3
+ short_description: "Install and verify the DataOps Browser Bridge in Chrome"
4
+ default_prompt: "Use $browser-bridge-chrome-install to prepare Chrome for a DataOps Browser Bridge update."
@@ -0,0 +1,107 @@
1
+ # Browser Headless
2
+
3
+ ## 前置
4
+
5
+ - 工作区已安装 Playwright 和 Chromium;
6
+ - 检查:
7
+
8
+ ```bash
9
+ node -e "console.log(require.resolve('playwright'))"
10
+ ```
11
+
12
+ - 不需要安装无头浏览器;缺依赖时才报告。
13
+
14
+ ## 工作流
15
+
16
+ 1. 明确目标 URL、要抓的字段/表格、是否需要登录;
17
+ 2. 在 `/workspace/outputs/browser/<task>/` 写 `scrape.mjs`;
18
+ 3. headless 启动 Chromium;
19
+ 4. 登录(仅使用凭据插件注入的环境变量);
20
+ 5. 等待页面稳定,优先抓接口返回/表格,不只看 DOM;
21
+ 6. 保存 `result.json` + `screenshot.png`;
22
+ 7. 校验条数/字段,再把摘要回复用户。
23
+
24
+ ## 脚本模板
25
+
26
+ ```js
27
+ const { chromium } = require('/usr/local/lib/node_modules/playwright');
28
+ const fs = require('node:fs');
29
+ const path = require('node:path');
30
+
31
+ const out = '/workspace/outputs/browser/task';
32
+ fs.mkdirSync(out, { recursive: true });
33
+
34
+ const browser = await chromium.launch({
35
+ headless: true,
36
+ args: ['--no-sandbox', '--disable-dev-shm-usage'],
37
+ });
38
+ const context = await browser.newContext({ viewport: { width: 1600, height: 1000 } });
39
+ const page = await context.newPage();
40
+
41
+ try {
42
+ await page.goto(process.env.TARGET_URL, { waitUntil: 'domcontentloaded', timeout: 60000 });
43
+
44
+ if (process.env.BROWSER_USERNAME) {
45
+ await page.fill('input[autocomplete="username"], input[name="username"]', process.env.BROWSER_USERNAME);
46
+ await page.fill('input[type="password"]', process.env.BROWSER_PASSWORD);
47
+ await page.click('button[type="submit"], button:has-text("登录")');
48
+ await page.waitForLoadState('networkidle', { timeout: 60000 }).catch(() => {});
49
+ }
50
+
51
+ const rows = await page.locator('table tbody tr').evaluateAll((trs) =>
52
+ trs.map((tr) => Array.from(tr.querySelectorAll('td')).map((td) => td.innerText.trim())));
53
+
54
+ fs.writeFileSync(path.join(out, 'result.json'), JSON.stringify({ url: page.url(), rows }, null, 2));
55
+ await page.screenshot({ path: path.join(out, 'screenshot.png'), fullPage: true });
56
+ console.log(JSON.stringify({ ok: true, rows: rows.length, out }));
57
+ } finally {
58
+ await browser.close();
59
+ }
60
+ ```
61
+
62
+ 按实际页面替换选择器;不要硬编码不存在的按钮。
63
+
64
+ ## 登录与凭据
65
+
66
+ - 用户账号密码先存凭据插件;
67
+ - 脚本只读环境变量:
68
+ - `BROWSER_USERNAME`
69
+ - `BROWSER_PASSWORD`
70
+ - 不把密码写入脚本、日志、截图;
71
+ - 登录失败/验证码/短信时停止并询问用户;
72
+ - 不自动切 Companion。
73
+
74
+ ## 大屏抓取
75
+
76
+ - 先看页面是否直接暴露 JSON 接口;优先 `page.waitForResponse`/接口抓取;
77
+ - 表格:抓 `tbody tr`;图表:优先接口数据,不要 OCR;
78
+ - 需要点击切换 tab 时,每次点击后校验数据变化;
79
+ - 动态加载等待 `networkidle` 或目标元素出现;
80
+ - 保存完整 HTML 仅用于调试,不作为最终数据。
81
+
82
+ ## 安全
83
+
84
+ - 只访问用户给出的域名;
85
+ - 禁止 localhost/127.0.0.1/169.254.169.254/内网管理端口;
86
+ - 并发 1,超时 60s;
87
+ - 独立 context,不持久化 cookie;
88
+ - 提交/下单/删除/发布前必须用户确认。
89
+
90
+ ## 失败处理
91
+
92
+ | 现象 | 动作 |
93
+ |---|---|
94
+ | 401/403 | 检查凭据;仍失败则询问用户 |
95
+ | 验证码/短信 | 停止,询问;用户明确要求本地浏览器才走 companion |
96
+ | 页面结构变化 | 重新快照,调整选择器;不要猜数据 |
97
+ | 数据为空 | 检查接口/筛选条件,报告空结果,不伪造 |
98
+
99
+ ## 输出
100
+
101
+ ```text
102
+ /workspace/outputs/browser/<task>/
103
+ ├── result.json
104
+ └── screenshot.png
105
+ ```
106
+
107
+ 回复用户:数据条数、字段、来源 URL、异常;不要把整页 HTML 贴进回答。
@@ -0,0 +1,33 @@
1
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
2
+
3
+ async function main() {
4
+ const backendOrigin = process.env.DATAOPS_BROWSER_BRIDGE_BACKEND_ORIGIN || 'https://127.0.0.1:3101';
5
+ const account = process.env.DATAOPS_BROWSER_BRIDGE_ACCOUNT || 'admin';
6
+ const password = process.env.DATAOPS_BROWSER_BRIDGE_PASSWORD;
7
+ if (!password) {
8
+ throw new Error('set DATAOPS_BROWSER_BRIDGE_PASSWORD before running this script');
9
+ }
10
+ const loginResponse = await fetch(`${backendOrigin}/api/auth/login`, {
11
+ method: 'POST',
12
+ headers: { 'content-type': 'application/json' },
13
+ body: JSON.stringify({ account, password }),
14
+ });
15
+ if (!loginResponse.ok) {
16
+ throw new Error(`Login failed: ${loginResponse.status}`);
17
+ }
18
+ const loginPayload = await loginResponse.json();
19
+ const toolsResponse = await fetch(`${backendOrigin}/api/ai/tools`, {
20
+ headers: { Authorization: `Bearer ${loginPayload.accessToken}` },
21
+ });
22
+ if (!toolsResponse.ok) {
23
+ throw new Error(`GET /api/ai/tools failed: ${toolsResponse.status}`);
24
+ }
25
+ const toolsPayload = await toolsResponse.json();
26
+ const browserTool = toolsPayload.tools.find((tool) => tool.name === 'browser');
27
+ console.log(JSON.stringify(browserTool ?? null, null, 2));
28
+ }
29
+
30
+ main().catch((error) => {
31
+ console.error(String(error));
32
+ process.exit(1);
33
+ });
@@ -0,0 +1,10 @@
1
+ Get-CimInstance Win32_Process -Filter "Name = 'chrome.exe'" |
2
+ Where-Object { $_.CommandLine -like '*tmp-chrome-browser-bridge-profile*' } |
3
+ ForEach-Object { Stop-Process -Id $_.ProcessId -Force }
4
+
5
+ Remove-Item D:\project\projects\tmp-dataops-browser-bridge.zip -Force -ErrorAction SilentlyContinue
6
+ Remove-Item D:\project\projects\tmp-dataops-browser-bridge -Recurse -Force -ErrorAction SilentlyContinue
7
+ Remove-Item D:\project\projects\tmp-chrome-browser-bridge-profile -Recurse -Force -ErrorAction SilentlyContinue
8
+ Remove-Item D:\project\projects\tmp-chrome-browser-bridge-profile-2 -Recurse -Force -ErrorAction SilentlyContinue
9
+ Remove-Item D:\project\projects\tmp-playwright-browser-bridge-profile -Recurse -Force -ErrorAction SilentlyContinue
10
+ Remove-Item D:\project\projects\tmp-chrome-browser-bridge-profile-log -Recurse -Force -ErrorAction SilentlyContinue