@sparkelf/dsh-dataops-managed 0.4.1 → 0.4.2

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/lib/index.js CHANGED
@@ -887,7 +887,7 @@ const AI_TOOL_ACCESS = {
887
887
  workflow_deployment: { superAdminOnly: true },
888
888
  workflow_run_control: { superAdminOnly: true },
889
889
  dataops_collect_preview: { permission: "data:resource:manage" },
890
- dataops_collect_plan: { permission: "data:resource:manage" },
890
+ dataops_collect_validate_plan: { permission: "data:resource:manage" },
891
891
  dataops_collect_execute: { permission: "data:resource:manage" },
892
892
  dataops_collect_resources: { permission: "data:resource:read" },
893
893
  dataops_open_resource_tab: {},
@@ -1354,10 +1354,11 @@ function hasCapability(id) {
1354
1354
  /**
1355
1355
  * DataOps spreadsheet-import transport for the collection skill.
1356
1356
  *
1357
- * The host reads a workspace attachment, uploads it as multipart, asks DataOps for a
1358
- * create-table or existing-table plan, and only executes when the model calls the
1359
- * execute tool after the user's plan confirmation. Nothing here creates a table on
1360
- * preview/plan; execution is the single mutating call.
1357
+ * The host reads a workspace attachment, uploads it as multipart, and validates the
1358
+ * create-table or existing-table plan the current conversation model wrote. DataOps only
1359
+ * normalizes that plan and returns SQL/mapping summaries; it never selects or calls a shared
1360
+ * model. Execution is the single mutating call and stays behind the user's explicit
1361
+ * confirmation.
1361
1362
  *
1362
1363
  * @module collect-api
1363
1364
  */
@@ -1427,12 +1428,19 @@ var CollectApi = class {
1427
1428
  const body = unwrap$1(result, "import data sources");
1428
1429
  return Array.isArray(body.dataSources) ? body.dataSources : [];
1429
1430
  }
1430
- async plan(payload) {
1431
- const result = await this.reviewApi.request("/api/resources/spreadsheet-import/plan", {
1431
+ /**
1432
+ * Validate and normalize a plan written by the current conversation model.
1433
+ *
1434
+ * Read-only and model-free: the backend runs the same deterministic sanitizers as
1435
+ * `/plan` and `/execute`, then returns the normalized plan, CREATE TABLE SQL or mapping
1436
+ * summary. It never resolves a shared `AiModelConfig` or calls a provider.
1437
+ */
1438
+ async validatePlan(payload) {
1439
+ const result = await this.reviewApi.request("/api/resources/spreadsheet-import/validate-plan", {
1432
1440
  method: "POST",
1433
1441
  body: JSON.stringify(payload)
1434
1442
  });
1435
- return unwrap$1(result, "spreadsheet plan");
1443
+ return unwrap$1(result, "spreadsheet plan validation");
1436
1444
  }
1437
1445
  async execute(payload) {
1438
1446
  const result = await this.reviewApi.request("/api/resources/spreadsheet-import/execute", {
@@ -2036,8 +2044,8 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2036
2044
  return parsed;
2037
2045
  };
2038
2046
  /**
2039
- * Keep only the fields the DataOps execute DTO accepts. The plan tool returns
2040
- * `createSql`/`targetSchema`/`notes` beside `createTable`; if the model passes
2047
+ * Keep only the fields the DataOps execute/validate DTOs accept. The validated plan
2048
+ * carries `createSql`/`targetSchema`/`notes` beside `createTable`; if the model passes
2041
2049
  * the whole plan (or rebuilds it after a table-name edit), the backend's
2042
2050
  * `forbidNonWhitelisted` pipe rejects the call with a generic 400.
2043
2051
  */
@@ -2070,6 +2078,24 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2070
2078
  columns
2071
2079
  };
2072
2080
  };
2081
+ /**
2082
+ * Keep only `{sourceKey,targetColumn}` from a model-written mapping list.
2083
+ *
2084
+ * The validated plan carries sourceHeader/targetDataType/confidence beside the pair; the
2085
+ * backend DTO drops them, but rejecting a malformed entry here names the offending index
2086
+ * instead of letting the server answer a generic "no usable mapping".
2087
+ */
2088
+ const normalizeMappings = (tool, entries) => entries.map((entry, index) => {
2089
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) throw new Error(tool + ": mappings_json[" + index + "] must be an object");
2090
+ const mapping = entry;
2091
+ const sourceKey = typeof mapping.sourceKey === "string" ? mapping.sourceKey.trim() : "";
2092
+ const targetColumn = typeof mapping.targetColumn === "string" ? mapping.targetColumn.trim() : "";
2093
+ if (!sourceKey || !targetColumn) throw new Error(tool + ": mappings_json[" + index + "] needs sourceKey and targetColumn");
2094
+ return {
2095
+ sourceKey,
2096
+ targetColumn
2097
+ };
2098
+ });
2073
2099
  return [
2074
2100
  {
2075
2101
  name: "skill_list",
@@ -2701,17 +2727,11 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2701
2727
  definition: defineTool({
2702
2728
  name: "dataops_collect_preview",
2703
2729
  description: "Parse one spreadsheet attachment from the workspace and return DataOps's preview plus the importable database destinations. Read-only: it does not create a table and does not write rows. Use this first in the data-collection skill, then ask the user to choose the destination when more than one is returned.",
2704
- parameters: {
2705
- file_path: {
2706
- type: "string",
2707
- required: true,
2708
- description: "Absolute or workspace-relative path to one .xlsx/.xls/.csv/.tsv file."
2709
- },
2710
- model_id: {
2711
- type: "number",
2712
- description: "Optional shared AI model id for the later plan call."
2713
- }
2714
- },
2730
+ parameters: { file_path: {
2731
+ type: "string",
2732
+ required: true,
2733
+ description: "Absolute or workspace-relative path to one .xlsx/.xls/.csv/.tsv file."
2734
+ } },
2715
2735
  output: {
2716
2736
  schema: OPEN_OBJECT_SCHEMA,
2717
2737
  render: renderJson
@@ -2733,10 +2753,10 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2733
2753
  })
2734
2754
  },
2735
2755
  {
2736
- name: "dataops_collect_plan",
2756
+ name: "dataops_collect_validate_plan",
2737
2757
  definition: defineTool({
2738
- name: "dataops_collect_plan",
2739
- description: "Generate a create-table plan or an existing-table field mapping for a parsed spreadsheet session. Read-only: DataOps only plans, it does not execute DDL or write rows. Call this after the user has chosen a data source; pass root_schema + root_table only when appending to an existing table.",
2758
+ name: "dataops_collect_validate_plan",
2759
+ description: "Validate and normalize the spreadsheet import plan the current conversation model wrote: a create-table plan or an existing-table field mapping. Read-only and model-free: DataOps checks identifiers, data types, source keys and target columns, then returns the normalized plan, CREATE TABLE SQL or mapping summary. It does not call any AI model and does not create tables or write rows. Call this after generating the plan and before presenting it to the user; use the returned plan for confirmation and execution.",
2740
2760
  parameters: {
2741
2761
  session_id: {
2742
2762
  type: "string",
@@ -2745,20 +2765,23 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2745
2765
  },
2746
2766
  data_source_urn: {
2747
2767
  type: "string",
2748
- required: true,
2749
- description: "Destination URN from the preview result."
2768
+ description: "Destination URN from the preview result. Required when appending to an existing table; omit only when validating a generic create-table plan."
2750
2769
  },
2751
2770
  target_schema: {
2752
2771
  type: "string",
2753
- description: "Existing-table schema; required when root_table is set."
2772
+ description: "Existing-table schema; required together with target_table."
2754
2773
  },
2755
2774
  target_table: {
2756
2775
  type: "string",
2757
- description: "Existing table name; omit to create a new table."
2776
+ description: "Existing table name; omit to validate a new create-table plan."
2758
2777
  },
2759
- model_id: {
2760
- type: "number",
2761
- description: "Optional shared AI model id."
2778
+ create_plan_json: {
2779
+ type: "string",
2780
+ description: "JSON object for CREATE_TABLE: {tableName,tableChineseName?,tableComment?,columns:[{sourceKey,name,chineseName,dataType,nullable?,comment?}]}."
2781
+ },
2782
+ mappings_json: {
2783
+ type: "string",
2784
+ description: "JSON array for EXISTING_TABLE: [{sourceKey,targetColumn}]."
2762
2785
  }
2763
2786
  },
2764
2787
  output: {
@@ -2766,21 +2789,36 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2766
2789
  render: renderJson
2767
2790
  },
2768
2791
  execute: async (args, exec) => {
2769
- const plan = await collectApi.plan({
2792
+ const tool = "dataops_collect_validate_plan";
2793
+ const createPlan = normalizeCreatePlan(tool, parseJsonObject(tool, "create_plan_json", args.create_plan_json));
2794
+ const mappings = normalizeMappings(tool, parseJsonArray(tool, "mappings_json", args.mappings_json));
2795
+ if (args.target_table !== void 0 && args.target_table.trim() === "") throw new Error(tool + ": target_table must be a non-empty existing table name");
2796
+ if (args.target_schema !== void 0 && args.target_table === void 0) throw new Error(tool + ": target_schema requires target_table");
2797
+ if (args.target_table !== void 0) {
2798
+ if (!args.target_schema || args.target_schema.trim() === "") throw new Error(tool + ": target_schema is required when target_table is set");
2799
+ if (createPlan !== void 0) throw new Error(tool + ": do not send create_plan_json when target_table is set");
2800
+ if (mappings.length === 0) throw new Error(tool + ": mappings_json is required for EXISTING_TABLE");
2801
+ } else {
2802
+ if (createPlan === void 0) throw new Error(tool + ": create_plan_json is required for CREATE_TABLE");
2803
+ if (mappings.length > 0) throw new Error(tool + ": do not send mappings_json for CREATE_TABLE");
2804
+ }
2805
+ const result = await collectApi.validatePlan({
2770
2806
  sessionId: args.session_id,
2771
- dataSourceUrn: args.data_source_urn,
2772
- ...args.target_table ? { targetTable: {
2773
- schema: args.target_schema || "",
2807
+ ...args.data_source_urn === void 0 || args.data_source_urn.trim() === "" ? {} : { dataSourceUrn: args.data_source_urn },
2808
+ ...args.target_schema && args.target_table ? { targetTable: {
2809
+ schema: args.target_schema,
2774
2810
  table: args.target_table
2775
2811
  } } : {},
2776
- ...args.model_id === void 0 ? {} : { modelId: args.model_id }
2812
+ ...createPlan === void 0 ? {} : { createPlan },
2813
+ ...mappings.length === 0 ? {} : { mappings }
2777
2814
  });
2778
- audit("dataops_collect_plan", exec, {
2815
+ audit(tool, exec, {
2779
2816
  sessionId: args.session_id,
2780
- dataSourceUrn: args.data_source_urn,
2781
- targetTable: args.target_table ?? null
2817
+ dataSourceUrn: args.data_source_urn ?? null,
2818
+ targetTable: args.target_table ?? createPlan?.tableName ?? null,
2819
+ mode: args.target_table === void 0 ? "CREATE_TABLE" : "EXISTING_TABLE"
2782
2820
  });
2783
- return plan;
2821
+ return result;
2784
2822
  }
2785
2823
  })
2786
2824
  },
@@ -2788,7 +2826,7 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2788
2826
  name: "dataops_collect_execute",
2789
2827
  definition: defineTool({
2790
2828
  name: "dataops_collect_execute",
2791
- description: "Execute one confirmed spreadsheet import: create a table (or write to an existing table), insert rows, and register the DataOps resource. This is the ONLY collection tool that mutates data. Call it only after the user explicitly confirms the read-only plan in natural language (e.g. 确认/开始吧); never call it while the plan is still being edited.",
2829
+ description: "Execute one confirmed spreadsheet import: create a table (or write to an existing table), insert rows, and register the DataOps resource. This is the ONLY collection tool that mutates data. Call it only after dataops_collect_validate_plan has normalized the plan and the user explicitly confirmed that plan in natural language (e.g. 确认/开始吧); never call it while the plan is still being edited and never call it with an unvalidated plan.",
2792
2830
  parameters: {
2793
2831
  session_id: {
2794
2832
  type: "string",
@@ -2803,7 +2841,7 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2803
2841
  mode: {
2804
2842
  type: "string",
2805
2843
  required: true,
2806
- description: "CREATE_TABLE or EXISTING_TABLE."
2844
+ description: "CREATE_TABLE, EXISTING_TABLE or OVERWRITE_TABLE. OVERWRITE_TABLE truncates the target table first; require explicit user confirmation and confirm_overwrite=true."
2807
2845
  },
2808
2846
  target_schema: {
2809
2847
  type: "string",
@@ -2815,11 +2853,15 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2815
2853
  },
2816
2854
  create_plan_json: {
2817
2855
  type: "string",
2818
- description: "Only plan.createTable (tableName/tableChineseName/tableComment/columns). Do not send createSql/targetSchema/notes; if the user edits the table name, call dataops_collect_plan again and pass its createTable."
2856
+ description: "Only plan.createTable (tableName/tableChineseName/tableComment/columns) from the plan returned by dataops_collect_validate_plan. Do not send createSql/targetSchema/notes; if the user edits the table name, regenerate the plan and call dataops_collect_validate_plan again before executing."
2819
2857
  },
2820
2858
  mappings_json: {
2821
2859
  type: "string",
2822
- description: "JSON array of {sourceKey,targetColumn} for EXISTING_TABLE."
2860
+ description: "JSON array of {sourceKey,targetColumn} for EXISTING_TABLE/OVERWRITE_TABLE."
2861
+ },
2862
+ confirm_overwrite: {
2863
+ type: "boolean",
2864
+ description: "Required true for OVERWRITE_TABLE after the user explicitly confirms that the target table will be truncated."
2823
2865
  },
2824
2866
  resource_name: {
2825
2867
  type: "string",
@@ -2834,6 +2876,18 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2834
2876
  items: { type: "string" },
2835
2877
  description: "Optional resource tags."
2836
2878
  },
2879
+ business_domain: {
2880
+ type: "string",
2881
+ description: "Business domain inferred by the conversation model from table name/comment/columns/terms, e.g. 财务域. Omit when unknown; DataOps will place it in 未分类."
2882
+ },
2883
+ domain_inference_source: {
2884
+ type: "string",
2885
+ description: "MODEL, USER, RULE or UNKNOWN. Defaults to MODEL when business_domain is provided."
2886
+ },
2887
+ domain_inference_confidence: {
2888
+ type: "string",
2889
+ description: "HIGH, MEDIUM or LOW. LOW is placed in 未分类."
2890
+ },
2837
2891
  ai_visible: {
2838
2892
  type: "boolean",
2839
2893
  description: "Whether AI may retrieve this resource. Defaults to true."
@@ -2848,7 +2902,8 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2848
2902
  render: renderJson
2849
2903
  },
2850
2904
  execute: async (args, exec) => {
2851
- if (args.mode !== "CREATE_TABLE" && args.mode !== "EXISTING_TABLE") throw new Error("dataops_collect_execute: mode must be CREATE_TABLE or EXISTING_TABLE");
2905
+ if (args.mode !== "CREATE_TABLE" && args.mode !== "EXISTING_TABLE" && args.mode !== "OVERWRITE_TABLE") throw new Error("dataops_collect_execute: mode must be CREATE_TABLE, EXISTING_TABLE or OVERWRITE_TABLE");
2906
+ if (args.mode === "OVERWRITE_TABLE" && args.confirm_overwrite !== true) throw new Error("dataops_collect_execute: OVERWRITE_TABLE requires confirm_overwrite=true after explicit user confirmation");
2852
2907
  const createPlan = normalizeCreatePlan("dataops_collect_execute", parseJsonObject("dataops_collect_execute", "create_plan_json", args.create_plan_json));
2853
2908
  const mappings = parseJsonArray("dataops_collect_execute", "mappings_json", args.mappings_json);
2854
2909
  if (args.mode === "CREATE_TABLE" && createPlan === void 0) throw new Error("dataops_collect_execute: create_plan_json is required for CREATE_TABLE");
@@ -2863,9 +2918,13 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2863
2918
  schema: args.target_schema,
2864
2919
  table: args.target_table
2865
2920
  } } : {},
2921
+ ...args.mode === "OVERWRITE_TABLE" ? { confirmOverwrite: true } : {},
2866
2922
  ...args.resource_name === void 0 ? {} : { resourceName: args.resource_name },
2867
2923
  ...args.resource_description === void 0 ? {} : { resourceDescription: args.resource_description },
2868
2924
  ...args.resource_tags === void 0 ? {} : { resourceTags: args.resource_tags },
2925
+ ...args.business_domain === void 0 ? {} : { businessDomain: args.business_domain },
2926
+ ...args.domain_inference_source === void 0 ? {} : { domainInferenceSource: args.domain_inference_source },
2927
+ ...args.domain_inference_confidence === void 0 ? {} : { domainInferenceConfidence: args.domain_inference_confidence },
2869
2928
  ...args.ai_visible === void 0 ? {} : { aiVisible: args.ai_visible },
2870
2929
  ...args.access_level === void 0 ? {} : { accessLevel: args.access_level }
2871
2930
  };
@@ -2875,7 +2934,8 @@ function buildAiManagementTools(ctx, reviewApi, readScope, collectHub) {
2875
2934
  sessionId: args.session_id,
2876
2935
  mode: args.mode,
2877
2936
  resourceId: resource?.id ?? null,
2878
- importedRows: result.importedRows ?? null
2937
+ importedRows: result.importedRows ?? null,
2938
+ businessDomain: args.business_domain ?? null
2879
2939
  });
2880
2940
  return result;
2881
2941
  }
@@ -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
  }
@@ -172,7 +172,7 @@ export declare const AI_TOOL_ACCESS: {
172
172
  readonly dataops_collect_preview: {
173
173
  readonly permission: "data:resource:manage";
174
174
  };
175
- readonly dataops_collect_plan: {
175
+ readonly dataops_collect_validate_plan: {
176
176
  readonly permission: "data:resource:manage";
177
177
  };
178
178
  readonly dataops_collect_execute: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-dataops-managed",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
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",
@@ -1,15 +1,25 @@
1
1
  ---
2
2
  name: browser
3
- description: 浏览器自动化总入口。默认用工作区 Playwright headless 抓取网页/大屏;只有用户明确要求“本地浏览器/已登录 Chrome/companion”才使用 Browser Bridge。账号密码登录走凭据插件,不强制 Companion。
3
+ description: 浏览器自动化总入口。抓取网页/大屏/表格、登录后取数、或用用户本地 Chrome/Edge 操作内网系统时使用。默认工作区 Playwright headless;只有用户明确要求本地浏览器、已登录 Chrome 或 Companion 才走 Browser Bridge。包含 headless、Companion 桥接与旧 Chrome 安装排查三套按需参考。
4
4
  ---
5
5
 
6
6
  # Browser
7
7
 
8
+ 浏览器自动化只有一个入口。先按用户意图选模式,再按需读取对应参考;不要把两套运行方式混在一起,也不要用 curl/静态抓取冒充浏览器操作。
9
+
10
+ ## 触发条件
11
+
12
+ - 抓取网页、大屏、表格、图表数据,或把页面结果整理成 JSON / 截图;
13
+ - 用给定账号密码登录后取数;
14
+ - 在用户自己的本地 Chrome/Edge 里打开内网系统、登录、点击、填表、截图;
15
+ - 需要用户扫码、短信验证码或 MFA 接管;
16
+ - 排查 Browser Bridge / Companion / 旧 Chrome 扩展的安装与连接问题。
17
+
8
18
  ## 先选模式
9
19
 
10
20
  ```text
11
21
  默认:headless
12
- 只有用户明确要求本地浏览器 → companion
22
+ 只有用户明确要求本地浏览器或已登录 Chrome → companion
13
23
  ```
14
24
 
15
25
  | 用户意图 | 模式 |
@@ -19,52 +29,53 @@ description: 浏览器自动化总入口。默认用工作区 Playwright headles
19
29
  | “用我电脑上的浏览器” | companion |
20
30
  | “用我已经登录的 Chrome” | companion |
21
31
  | “用 companion” | companion |
32
+ | 需要扫码/短信/MFA 接管 | companion |
22
33
 
23
- Agent 不得自行切 companion;需要时先询问。
24
-
25
- ## Headless
26
-
27
- 先读 `browser-headless` 技能,然后:
34
+ Agent 不得自行切换 companion;需要时先询问用户。
28
35
 
29
- 1. 写 Playwright 脚本;
30
- 2. 用工作区 Chromium 运行;
31
- 3. 产出 `result.json` + `screenshot.png`;
32
- 4. 校验数据条数/字段/接口状态。
36
+ ## 按需加载
33
37
 
34
- ## Companion
38
+ 主文件只负责路由和硬规则。进入某个模式后,再读取对应参考:
35
39
 
36
- 只有用户明确要求本地浏览器时:
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/) 下。
37
43
 
38
- 1. 先 `browser_bridge_status`;
39
- 2. 未连接则 `browser_bridge_connect`;
40
- 3. 用 `browser_navigate` / `browser_snapshot` 等现有工具;
41
- 4. 不要用 headless 脚本冒充 companion。
44
+ ## 通用硬规则
42
45
 
43
- ## 凭据
46
+ ### 凭据
44
47
 
45
- - 账号密码存凭据插件,Agent 只拿 `secretRef`;
48
+ - 用户账号密码先存凭据插件,Agent 只拿 `secretRef`;
46
49
  - 密码不得出现在 prompt、脚本、日志、截图;
47
50
  - headless 通过环境变量/secretRef 登录;
48
- - 登录失败先询问,不自动切 companion。
51
+ - 登录失败、验证码或短信验证时停止并询问;不要自动切 companion。
49
52
 
50
- ## 安全
53
+ ### 安全
51
54
 
52
- - 只访问用户明确给出的域名;
53
- - 禁止 localhost、127.0.0.1、169.254.169.254、内网管理端口;
55
+ - headless 只访问用户明确给出的域名;禁止 localhost、127.0.0.1、169.254.169.254、内网管理端口;
56
+ - companion 只操作用户明确授权的域名,允许用户已登录的内网系统;授权边界见 [references/bridge.md](references/bridge.md);
54
57
  - 并发 1,默认超时 60s;
55
- - 不持久化 cookie;
56
- - 提交/下单/删除/发布前必须用户确认。
58
+ - 独立 context,不持久化 cookie;
59
+ - 提交、下单、删除、发布前必须用户确认;
60
+ - 不读取、不导出、不上传 Cookie、LocalStorage 或密码;不绕过验证码和风控。
61
+
62
+ ### 成功判据
63
+
64
+ - 不以“点击成功”或“页面打开了”作为成功;必须校验数据条数、字段、接口状态或页面关键文本;
65
+ - 抓取结果同时写入 `result.json` 与 `screenshot.png`(路径见对应参考);
66
+ - 页面为空或结构变化时报告事实,不猜数据、不伪造结果。
57
67
 
58
68
  ## 输出
59
69
 
60
- - `result.json`:数据、来源 URL、抓取时间;
61
- - `screenshot.png`:关键页面;
62
- - 摘要:条数、字段、异常;
63
- - 不以“点击成功”作为成功判据。
70
+ ```text
71
+ /workspace/outputs/browser/<task>/
72
+ ├── result.json # 数据、来源 URL、抓取时间
73
+ └── screenshot.png # 关键页面
74
+ ```
75
+
76
+ 回复用户:数据条数、字段、来源 URL、异常;不要把整页 HTML 贴进回答。
64
77
 
65
78
  ## 相关技能
66
79
 
67
- - `browser-headless`:默认 headless 实现;
68
- - `browser-cdp-automation`:接管真实 Chrome/CDP;
69
- - `browser-bridge-companion`:Companion 工具;
70
- - `browser-bridge-chrome-install`:Companion 安装。
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` 获得生产链路与托盘。