@sparkelf/dsh-dataops-managed 0.3.54 → 0.4.1

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.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Browser-version notice.
3
+ *
4
+ * The workspace is a web app; the local browser bridge only supports current Chromium
5
+ * releases. This banner is deliberately a sibling of the workspace-image banner: it uses
6
+ * the same shell-overlay seat and the same quiet notice geometry, while keeping the
7
+ * browser floor and the installer URL owned by this plugin.
8
+ *
9
+ * @module BrowserVersionPrompt
10
+ */
11
+ import type { en } from './locales.ts';
12
+ /** Lowest Chromium major the local browser bridge supports. */
13
+ export declare const MIN_BROWSER_MAJOR = 150;
14
+ export interface BrowserVersionPromptProps {
15
+ /** Resolve one managed DataOps message key. */
16
+ readonly t: (key: keyof typeof en) => string;
17
+ }
18
+ /**
19
+ * Extract the Chromium major from the user agent.
20
+ *
21
+ * `navigator.userAgentData` is preferred in modern Chromium; the UA fallback keeps
22
+ * Firefox/Safari and older embedded WebViews from producing a false positive.
23
+ */
24
+ export declare function chromiumMajor(ua: string): number | null;
25
+ /** Render the browser-version banner while the current browser is below the floor. */
26
+ export declare function BrowserVersionPrompt(props: BrowserVersionPromptProps): import("react").JSX.Element | null;
@@ -156,6 +156,10 @@ export declare const en: {
156
156
  readonly upgradeBusy: "Upgrading workspace…";
157
157
  readonly upgradeStarted: "Upgrade started. Reload this page when the workspace reconnects.";
158
158
  readonly upgradeFailed: "The workspace upgrade could not be started. Try again.";
159
+ readonly browserVersionTitle: "Browser version is out of date";
160
+ readonly browserVersionBody: "This browser is version {version}; version {minimum} or newer is recommended for the local browser bridge. Download the fully offline bridge installer.";
161
+ readonly browserVersionAction: "Download browser package";
162
+ readonly browserVersionLater: "Later";
159
163
  readonly upgradeRetry: "Retry";
160
164
  };
161
165
  /** Stable key set shared by every managed DataOps locale. */
@@ -142,6 +142,21 @@ export declare const AI_TOOL_ACCESS: {
142
142
  readonly dataops_api_docs: {
143
143
  readonly superAdminOnly: true;
144
144
  };
145
+ readonly synonym_group_list: {
146
+ readonly superAdminOnly: true;
147
+ };
148
+ readonly synonym_group_get: {
149
+ readonly superAdminOnly: true;
150
+ };
151
+ readonly synonym_group_create: {
152
+ readonly superAdminOnly: true;
153
+ };
154
+ readonly synonym_group_update: {
155
+ readonly superAdminOnly: true;
156
+ };
157
+ readonly synonym_group_delete: {
158
+ readonly superAdminOnly: true;
159
+ };
145
160
  readonly workflow_query: {
146
161
  readonly superAdminOnly: true;
147
162
  };
@@ -167,6 +182,19 @@ export declare const AI_TOOL_ACCESS: {
167
182
  readonly permission: "data:resource:read";
168
183
  };
169
184
  readonly dataops_open_resource_tab: {};
185
+ readonly dataops_user_lookup: {
186
+ readonly permission: "system:user:read";
187
+ };
188
+ readonly dataops_user_create: {
189
+ readonly capability: "admin.manage";
190
+ readonly adminOnly: true;
191
+ readonly defaultEnabled: true;
192
+ };
193
+ readonly dataops_role_assign: {
194
+ readonly capability: "admin.manage";
195
+ readonly adminOnly: true;
196
+ readonly defaultEnabled: true;
197
+ };
170
198
  readonly dataops_resource_pending_list: {
171
199
  readonly capability: "resource.manage";
172
200
  readonly adminOnly: true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-dataops-managed",
3
- "version": "0.3.54",
3
+ "version": "0.4.1",
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,14 @@
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/**/*",
51
+ "skills/**/i18n/*.json",
52
+ "skills/**/references/**/*.md"
49
53
  ],
50
54
  "scripts": {
51
55
  "build": "rm -rf lib && tsc -p tsconfig.build.json && tsdown",
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: dataops-governance
3
+ description: 管理员/超管使用的正常数据治理技能:导入资源、写资源/列/指标/血缘、查全量平台元数据。普通用户问“我的资源/可申请资源”走 dataops-query 的 metadata-query,不用本技能。
4
+ ---
5
+
6
+ # 数据治理
7
+
8
+ ## 适用范围
9
+
10
+ 管理员/超管需要:
11
+
12
+ - 导入表格/Excel/CSV,建成可问数资源;
13
+ - 接 OpenAPI/接口文档,导入接口资源;
14
+ - 改资源、列、指标、血缘、可见性;
15
+ - 查全量平台元数据(不限当前用户授权)。
16
+
17
+ 普通用户不要用本技能;普通用户的受控元数据查询在 `dataops-query/references/metadata-query.md`。
18
+
19
+ ## 硬规则
20
+
21
+ 1. **写元数据只走 `govern_metadata`**:先 `search_resources` 查真实事实,再 `preview`,用户确认后 `apply`;禁止 shell/SQL/Prisma 直写。
22
+ 2. **指标只写 SQL 片段**:`name`、`displayName`、`description`、`sqlFragment`、`enabled`、`accessLevel`、`aiVisible`;不写 aggregation/grain/dimension/aliases/MetricColumn。
23
+ 3. **没有 `govern_metric` 就只提案**:不要用 SQL 直写 `metrics`;记录 `GAP-METRIC-WRITE`。
24
+ 4. **导入与治理分开**:文件导入读 `01-file-import`;接口导入读 `02-api-import`。
25
+ 5. **不做 Benchmark 特判**:产品技能只按正常用户流程执行。
26
+
27
+ ## 流程
28
+
29
+ 1. 判断意图:导入文件 / 导入接口 / 写元数据 / 读元数据。
30
+ 2. 读对应 reference。
31
+ 3. 写操作必须 preview + 用户确认 + apply。
32
+ 4. 完成后回读并汇报结果;失败按错误合同停止。
33
+
34
+ ## Reference 路由
35
+
36
+ | 意图 | 读哪个 |
37
+ | --- | --- |
38
+ | 表格/Excel/CSV 导入 | `references/01-file-import.md` |
39
+ | OpenAPI/接口文档导入 | `references/02-api-import.md` |
40
+ | 写资源/列/指标/血缘/可见性 | `references/03-metadata-write.md` |
41
+ | 全量平台元数据查询 | `references/04-metadata-read.md` |
@@ -0,0 +1,10 @@
1
+ {
2
+ "_meta": {
3
+ "sourceHash": "1bdca8934cf5a192a59c35e811f4f49c9b97ff40",
4
+ "model": "manual-zh",
5
+ "translatedAt": "2026-11-23T10:25:00+08:00"
6
+ },
7
+ "title": "数据治理",
8
+ "description": "管理员/超管导入资源、维护资源/列/指标/血缘与可见性、查询全量平台元数据时使用。",
9
+ "summary": "覆盖表格/Excel/CSV 导入、OpenAPI 接入、元数据写入和全量元数据读取;写操作必须先 preview,用户确认后再 apply。"
10
+ }
@@ -0,0 +1,201 @@
1
+ # 文件导入(合并自 dataops-collect)
2
+
3
+ # 数据采集(AI 建资源)
4
+
5
+ 用户把一份表格交给 AI,AI 解析、出计划、用户确认后建表写数,最后得到一个能问数的资源。第一版只做一次性导入;一个会话一份文件、一个目标资源。
6
+
7
+ ## 一、什么时候用
8
+
9
+ 用户表达下面任一意图时使用本技能:
10
+
11
+ - 把这份表格建成能问数的资源
12
+ - 这个 Excel 帮我导进来
13
+ - 上传个表能问数吗
14
+ - 把这份数据加到已有的那个资源里
15
+ - 追加到 XX 资源
16
+ - 新建一个数据资源
17
+ - 表格导入 / 导入成表 / 建成资源
18
+ - 把 CSV 变成能查的表 / 能问数的表
19
+ - 这份数据帮我入库 / 建表
20
+ - 把这个 sheet 建成资源
21
+ - 这个表以后能用来问数吗
22
+ - 把这份销售表导入
23
+ - 把这份名单建成资源
24
+ - 加到门店销售明细里
25
+ - 追加一份月度数据
26
+ - 建个新资源,用这个文件
27
+ - 导入到数据中台
28
+ - 这个文件能建成资源吗
29
+ - 把附件建成资源
30
+ - 用这个表格建一张表
31
+
32
+ 不适用:纯问数、取数、查数据(用 `dataops-query`);只讨论表结构但不导入。
33
+
34
+ ## 二、四个硬规则
35
+
36
+ 1. **一次会话一份文件、一个目标资源。** 多文件批量不做。
37
+ 2. **有引用 = 追加;无引用 = 先问,不默认新建。** 用户话里已经说清“新建”或“追加”的,跳过这一问;没说清又没引用,必须先出「新建资源 / 选择已有资源」二选一,不能直接出新建计划。
38
+ 3. **计划确认是唯一硬闸。** 用户明确回复「确认」「开始吧」「可以」等之前,绝不调用 `dataops_collect_execute`,绝不建表、绝不写数。预览和计划工具本身不建表,可以放心调用。
39
+ 4. **执行走原生工具流。** 不要自己造执行卡、进度卡;工具参数、结果、耗时、失败原因都在原生工具卡里。你只在旁边说人话。
40
+
41
+ ## 三、主流程
42
+
43
+ ### 1. 找到文件
44
+
45
+ 从当前消息的附件 / 系统上下文里取得表格在工作区的路径(通常是 `/workspace/...` 或 `temp/conversations/.../attachments/...`)。没有路径时,不要猜目录、不要扫全工作区;直接说“请把表格拖进输入框,或点输入框的 + 上传”,并给一个内联上传提示。
46
+
47
+ ### 2. 预览,不要建表
48
+
49
+ 调用:
50
+
51
+ `dataops_collect_preview({ file_path })`
52
+
53
+ 返回 `sessionId`、`preview`、`dataSources`。用大白话复述:
54
+
55
+ > 看了下,明细 sheet 共 12,000 行、18 列;表头在第 2 行。我先按明细建资源。
56
+
57
+ 文件读不出来也在这里说清楚:
58
+
59
+ > 这个 xlsx 读不出来,可能加密了。你换个文件,或者告诉我表头在第几行。
60
+
61
+ ### 3. 先定去向
62
+
63
+ - 当前会话里有 `resource-ref` 引用块 → 追加到该资源;
64
+ - 用户说“新建 / 建个新资源 / 不要加到已有的” → 新建;
65
+ - 用户说“追加 / 加到 / 并到 / 合到” → 追加;没有具体资源时先让用户选;
66
+ - 都没有 → 出「新建资源 / 选择已有资源」GenUI,等用户选。
67
+
68
+ 选择已有资源时:
69
+ 1. 调用 `dataops_collect_resources({ query, limit: 8 })`;
70
+ 2. 用 `choices` 或 `list` + 按钮列出最多 8 个候选(资源名 + 表名 + 行数);
71
+ 3. 用户选中后,把该资源作为本次目标,进入计划。
72
+
73
+ ### 3.5 判定业务域
74
+
75
+ 每次新建/导入资源前,由会话模型根据**表名、表注释、字段名/注释、术语、少量样例值**判断业务域,不依赖代码里的固定表名规则。判断结果是资源目录的一部分,必须写入导入参数:
76
+
77
+ - `business_domain`:业务域名称,例如「金融域」「软件研发域」;不确定时不要猜,留空或传「未分类」。
78
+ - `domain_inference_source`:`MODEL`(模型根据元数据判断)、`USER`(用户明确指定)、`RULE`(已有治理规则)、`UNKNOWN`。
79
+ - `domain_inference_confidence`:`HIGH` / `MEDIUM` / `LOW`。`LOW` 或无法判断时统一落 `/业务域/未分类`,不要为了好看硬塞一个域。
80
+
81
+ 判定顺序:
82
+
83
+ 1. 用户明确说了业务域 → `USER` + `HIGH`。
84
+ 2. 表名/注释/字段/术语有明确业务语义 → `MODEL` + `HIGH` 或 `MEDIUM`。
85
+ 3. 只能靠库名或样例值猜测 → `MODEL` + `LOW`,最终落未分类。
86
+ 4. 完全无信号 → `UNKNOWN` + `LOW`,落未分类。
87
+
88
+ 常见公开数据集的业务域示例(仅作判断参考,不是代码规则):
89
+
90
+ - BIRD `codebase_community` → 软件研发域
91
+ - `financial` / `debit_card_specializing` → 金融域
92
+ - `student_club` → 教育域
93
+ - `thrombosis_prediction` / `toxicology` → 医疗域
94
+ - `european_football_2` / `formula_1` → 体育域
95
+ - `card_games` / `superhero` → 娱乐域
96
+
97
+ 目录规则:资源挂在 `/业务域/<业务域>/<数据源>/<库>/<schema>`,无 schema 时省略该层;不为每张表单独建目录。系统表不属于业务域,统一在 `/系统域/<模块>`。
98
+
99
+ ### 4. 生成计划,不要执行
100
+
101
+ 调用:
102
+
103
+ `dataops_collect_plan({ session_id, data_source_urn, target_schema?, target_table? })`
104
+
105
+ - 不传 `target_table` = 新建表(CREATE_TABLE);
106
+ - 传 `target_schema` + `target_table` = 追加到已有表(EXISTING_TABLE)。
107
+
108
+ 返回后检查 `plan`:
109
+ - 新建表:`plan.mode === 'CREATE_TABLE'`,有 `plan.createTable`、`plan.createSql`;
110
+ - 追加:`plan.mode === 'EXISTING_TABLE'`,有 `plan.mappings`,并在计划里多一行映射摘要(匹配 N 个字段、新增 N 个、N 个类型不兼容)。
111
+
112
+ ### 5. 出计划 GenUI(只读预览,语言确认)
113
+
114
+ 计划是主确认点,但**只读**:卡上不放 `input` / `textarea` / 下拉 / `submit`,也不放「开始导入」「再调整」按钮。用户看完卡后,直接用自然语言回复「确认」「开始吧」才执行。
115
+
116
+ 必须包含(全部纯展示):
117
+
118
+ - 资源名(AI 起草)
119
+ - 去向(新建资源 / 追加到「已有资源名」)
120
+ - 目标表(库.表)
121
+ - 导入数据源
122
+ - 行数 / 字段数
123
+ - 业务域(含推断来源/置信度;未分类也要写明)
124
+ - **表头映射**:原表头 → 目标字段 → 类型;低置信度类型写「需确认」,并用 warning callout 再列一遍(GenUI 表格单元格不支持单独标黄)
125
+ - 默认权限
126
+
127
+ 计划 GenUI 示例(把 `<...>` 换成真实值;注意没有任何输入控件):
128
+
129
+ ```dsh-ui
130
+ {"title":"导入计划","items":[{"type":"text","size":"body","content":"看了下,明细 sheet 共 <行数> 行、<列数> 列;我先按明细建资源。"},{"type":"card","title":"<资源名>","items":[{"type":"keyvalue","pairs":[{"key":"资源名","value":"<资源名>"},{"key":"去向","value":"新建资源"},{"key":"目标表","value":"<schema.table>"},{"key":"导入数据源","value":"<数据源名>"},{"key":"行数 / 字段数","value":"<行数> 行 / <字段数> 列"},{"key":"默认权限","value":"仅自己可见"}]},{"type":"table","columns":["原表头","目标字段","类型"],"rows":[["<原表头1>","<目标字段1>","<类型1>"],["<原表头2>","<目标字段2>","⚠️ 需确认"]]},{"type":"callout","tone":"warning","content":"以下类型需要确认:<列出低置信度字段>。"},{"type":"callout","tone":"info","content":"确认无误请直接回复「确认」或「开始吧」;要改表名、类型或资源名,直接说,我会重新出计划,不会执行。"}]}]}
131
+ ```
132
+
133
+ 规则:
134
+
135
+ - 用户提出修改(「表名换成 xxx」「金额按文本存」「资源名改成 xxx」)→ 只在对话里改参数,然后重新调用 `dataops_collect_plan` / 调整计划,**重新出只读计划卡,不要执行**;
136
+ - 用户确认后,计划折叠成一行“已按此计划执行”的回执,把屏幕让给工具流;
137
+ - 确认后如果要改参数,先停,再出新计划。
138
+
139
+ ### 6. 执行
140
+
141
+ 用户明确回复「确认」「开始吧」「可以」后,使用计划卡上展示的资源名/目标表/描述调用:
142
+
143
+ `dataops_collect_execute({ session_id, data_source_urn, mode, target_schema?, target_table?, create_plan_json, mappings_json, resource_name, resource_description, resource_tags?, ai_visible?, access_level?, business_domain?, domain_inference_source?, domain_inference_confidence? })`
144
+
145
+ - `mode` 用 `plan.mode`;
146
+ - 新建表:`create_plan_json` 传 `JSON.stringify(plan.createTable)`,`mappings_json` 传 `"[]"`;
147
+ - 追加:`mappings_json` 传 `JSON.stringify(plan.mappings)`;
148
+ - `resource_name` 用计划卡上展示、用户确认过的资源名;
149
+ - `access_level` 默认 `PRIVATE`;`ai_visible` 默认 `true`。
150
+ - `business_domain` / `domain_inference_source` / `domain_inference_confidence` 按 3.5 的判定结果传入;不传时后端落 `/业务域/未分类`。
151
+
152
+ 执行期间只说阶段小结,例如:
153
+
154
+ > 表建好了。现在写数据,一万两千行,估计一两分钟。
155
+ >
156
+ > 写完了,正在生成字段说明。
157
+
158
+ 失败只说三类,并给一个动作:
159
+ - 文件问题 → 重新上传 / 告诉我表头在第几行;
160
+ - 字段问题 → 调整映射 / 改类型;
161
+ - 系统问题 → 重试。
162
+
163
+ ### 7. 结果 GenUI + 打开资源页签
164
+
165
+ 执行成功后:
166
+
167
+ 1. 调用 `dataops_open_resource_tab({ resource_id, resource_name, mode: 'focus' })`,让右侧栏自动打开 `dataops-resources` 页签并定位新资源;
168
+ 2. 出结果 GenUI,必须包含资源名、目标表、行数、字段数、业务域(含推断来源/置信度;未分类要明确写“未分类”)、 “已可问数”、当前可见范围(默认“仅自己可见”),以及三个动作:**分配权限 / 去问数 / 查看详情**,外加一条 **查看操作记录** 文字链。
169
+
170
+ 结果 GenUI 示例:
171
+
172
+ ```dsh-ui
173
+ {"title":"导入完成","items":[{"type":"callout","tone":"success","title":"已可问数","content":"资源已建成,可以开始问数。"},{"type":"keyvalue","pairs":[{"key":"资源名","value":"<资源名>"},{"key":"目标表","value":"<schema.table>"},{"key":"行数","value":"<行数>"},{"key":"字段数","value":"<字段数>"},{"key":"可见范围","value":"仅自己可见"}]},{"type":"row","items":[{"type":"button","label":"分配权限","tone":"primary","action":"dataops_open_grant"},{"type":"button","label":"去问数","action":"dataops_ask"},{"type":"button","label":"查看详情","action":"dataops_open_detail"}]},{"type":"button","label":"查看操作记录 →","tone":"ghost","small":true,"action":"dataops_open_audit"}]}
174
+ ```
175
+
176
+ 三个动作的处理:
177
+
178
+ - 分配权限 → `dataops_open_resource_tab({ resource_id, mode: 'grant' })`,侧栏资源卡定位并自动打开授权弹窗;
179
+ - 去问数 → 不要跳页,直接在对话里给 2-3 个可以问的问题示例,并说明资源已可被检索;
180
+ - 查看详情 → `dataops_open_resource_tab({ resource_id, mode: 'detail' })`;
181
+ - 查看操作记录 → `dataops_open_resource_tab({ resource_id, mode: 'audit' })`。
182
+
183
+ ## 四、引用资源(追加)
184
+
185
+ 引用可能来自输入框的资源 chip,也可能来自右侧栏资源卡的「添加到对话」。如果引用以结构化块出现,形如:
186
+
187
+ ```resource-ref
188
+ {"kind":"dataops-resource","resourceId":123,"name":"门店销售明细","table":"dwd_store_sales"}
189
+ ```
190
+
191
+ 就把它当作本次追加目标,不要再问“新建还是追加”。如果用户在上传文件之前先引用了资源,直接按追加处理。
192
+
193
+ 如果「添加到对话」降级成发送一条消息,消息里必须带这个 `resource-ref` 块;没有结构化块时,按“用户口头提到资源名”处理,先用 `dataops_collect_resources` 找到资源再确认,不要凭名字猜 id。
194
+
195
+ ## 五、边界
196
+
197
+ - 不做定时采集、增量水位、失败重试策略;
198
+ - 不做多文件批量、文件夹上传;
199
+ - 不做覆盖(只追加);
200
+ - 不在对话里做权限表单(GenUI 没有人员选择器);
201
+ - 不在 DSH 里做审计弹窗;操作记录在 DataOps 资源详情 / 系统审计。
@@ -0,0 +1,11 @@
1
+ # 接口导入
2
+
3
+ OpenAPI / Swagger / 接口说明导入接口资源,按现有 `api-connector-authoring` 技能执行;本 reference 只负责在治理技能内路由,不复制其步骤。
4
+
5
+ 要求:
6
+
7
+ - 先解析接口文档,判断一个 connector 还是多个;
8
+ - 资源命名用业务语义,不用 `api_v1`;
9
+ - 导入前用 GenUI 预览,用户确认后才导入;
10
+ - 字段返回英文缩写时给中文语义名;
11
+ - 不在本流程里写指标/血缘。
@@ -0,0 +1,32 @@
1
+ # 元数据写入
2
+
3
+ ## 通道
4
+
5
+ - 资源/列/血缘:`metadata-governance` + `govern_metadata`。
6
+ - 指标:当前无 `govern_metric`;只能提案或走 Metrics API;禁止 SQL 直写 `metrics`。
7
+
8
+ ## 资源
9
+
10
+ - `chineseName`、`alias`、`remark`、`usageManual`、`catalog`、`tags`、`accessLevel`、`aiVisible`。
11
+ - `alias` 是检索别名,不是 SQL 名。
12
+
13
+ ## 列
14
+
15
+ - `chineseName`、`description`、`dataType`、`nullable`、`isPrimaryKey`、`glossaryTermIds`、`isCommonlyUsed`、`accessLevel`、`aiVisible`。
16
+ - 只 patch 既有字段;找不到字段先报告缺失,不新造。
17
+
18
+ ## 指标
19
+
20
+ - 只写 SQL 片段:`name`、`displayName`、`description`、`sqlFragment`、`enabled`、`accessLevel`、`aiVisible`、`source`。
21
+ - `sqlFragment` 是完整表达式,如 `SUM(amount)` 或 `SUM(a)/NULLIF(SUM(b),0)`。
22
+ - 不写 `aggregation/baseGrain/grainKeyColumnIds/dimensionColumnIds/aliases/MetricColumn`。
23
+ - 指标名与同视图列名不能冲突。
24
+
25
+ ## 血缘
26
+
27
+ - `sourceResourceId` / `targetResourceId` 必须是真实 resourceId,不能相同。
28
+ - 字段映射用真实字段名;推断血缘标 confidence。
29
+
30
+ ## 写入顺序
31
+
32
+ `search_resources` 查真值 → `govern_metadata preview` → 用户确认 → `apply`(带 confirmationToken)→ 回读汇报。
@@ -0,0 +1,132 @@
1
+ # 全量平台元数据查询
2
+
3
+ # Data Warehouse Operations
4
+
5
+ ## Overview
6
+
7
+ This is a knowledge base, not a flow skill. 本技能是知识库,不是流程。Use it to answer DataOps middle-platform and warehouse metadata questions by querying platform tables through `query_table`, instead of only calling `search_resources` and returning a small resource page.
8
+
9
+ `search_resources` is useful for semantic lookup and resolving a named resource. For catalog-wide questions, counts, field inventories, lineage statistics, dictionary lookups, or "agent platform has what resources", query the metadata tables directly.
10
+
11
+ ## Permission Boundary
12
+
13
+ This skill does not grant write access.
14
+
15
+ - 管理员 / Administrators may create, update, delete, and query middle-platform tables only through approved admin APIs or governance tools.
16
+ - 运营人员 / Operators may query middle-platform tables; do not suggest direct INSERT/UPDATE/DELETE/DDL.
17
+ - 应用人员 / Application users can see only authorized rows and fields.
18
+ - Runtime enforces strong filtering: SQL is parsed/normalized and AST/WHERE conditions are completed automatically for visibility and authorization. Do not remove, bypass, weaken, or contradict injected filters.
19
+ - If a query returns no rows, treat it as "no authorized visible data" unless there is evidence of a system error.
20
+
21
+ `query_table` accepts only `SELECT` or `WITH`. Never use `DESCRIBE`, `DESC`, semicolons, write SQL, or `SELECT *` on wide tables unless the user explicitly asks for all columns.
22
+
23
+ ## Core Tables
24
+
25
+ | Need | Query these tables | Notes |
26
+ | --- | --- | --- |
27
+ | Resource list/statistics | `resources` | Uses `id`, `urn`, `resource_type`, `chinese_name`, `source_system`, `source_table`, `database`, `catalog`, `access_level`, `is_enabled`, `ai_visible`, `columns`, `tags`, `row_count`, `data_size`. Runtime adds visibility filters. |
28
+ | Field inventory | `resources.columns` JSON plus `data_source_table_column_metadata` | `columns` contains synced field metadata; table-column metadata stores datasource/table/column comments. |
29
+ | Lineage | `resource_lineages` joined to `resources` | Use `source_resource_id`, `target_resource_id`, `relation_type`, `status`, `process_name`, `field_mappings`, `ai_visible`. Runtime filters visible lineage. |
30
+ | Dictionaries | `dictionaries`, `dictionary_entries` | Use dictionary `code`, Chinese/English names, `status`, entry key/value/order. |
31
+ | Glossary/terms | `glossary_terms`, `glossary_term_rule_constraints` | Use `path`, `skill_key`, `ai_visible`, `dictionary_codes`, semantic bindings. |
32
+ | Catalog tree | `catalog_nodes` | Use `path`, `type`, `owner`, `owner_dept`, `owner_system`, `access_level`. Runtime filters public catalog scope. |
33
+ | Data sources | `data_sources`, `data_source_accounts`, `data_source_account_assignments` | Use for datasource inventory and account assignment status; never expose secrets. Runtime filters enabled datasources. |
34
+ | Semantic layer | `semantic_models`, `semantic_model_resources`, `semantic_query_templates` | Use for semantic model coverage, bound resources, reusable query templates, and visible business questions. |
35
+ | Resource authorization | `resource_access_grants` | Use only to explain grant facts visible to the caller; do not hand-build an authorization bypass. |
36
+
37
+ ## Query Patterns
38
+
39
+ Answer "中台有什么资源 / agent 中台有什么资源" with grouped metadata, not a capped resource search:
40
+
41
+ ```sql
42
+ SELECT
43
+ source_system,
44
+ resource_type,
45
+ COUNT(*) AS resource_count,
46
+ SUM(COALESCE(row_count, 0)) AS total_rows
47
+ FROM resources
48
+ GROUP BY source_system, resource_type
49
+ ORDER BY resource_count DESC
50
+ ```
51
+
52
+ Find resource fields by name:
53
+
54
+ ```sql
55
+ SELECT
56
+ id,
57
+ chinese_name,
58
+ source_system,
59
+ source_table,
60
+ columns
61
+ FROM resources
62
+ WHERE chinese_name ILIKE '%客户%' OR source_table ILIKE '%customer%'
63
+ ORDER BY updated_at DESC
64
+ LIMIT 20
65
+ ```
66
+
67
+ Summarize lineage around a resource:
68
+
69
+ ```sql
70
+ SELECT
71
+ src.chinese_name AS source_resource,
72
+ dst.chinese_name AS target_resource,
73
+ l.relation_type,
74
+ l.status,
75
+ l.process_name,
76
+ l.field_mappings
77
+ FROM resource_lineages l
78
+ JOIN resources src ON src.id = l.source_resource_id
79
+ JOIN resources dst ON dst.id = l.target_resource_id
80
+ WHERE src.chinese_name ILIKE '%客户%' OR dst.chinese_name ILIKE '%客户%'
81
+ ORDER BY l.updated_at DESC
82
+ LIMIT 50
83
+ ```
84
+
85
+ Query dictionaries and entries:
86
+
87
+ ```sql
88
+ SELECT
89
+ d.code,
90
+ d.chinese_name,
91
+ d.english_name,
92
+ e.entry_key,
93
+ e.entry_value,
94
+ e.display_order
95
+ FROM dictionaries d
96
+ LEFT JOIN dictionary_entries e ON e.dictionary_id = d.id
97
+ WHERE d.code ILIKE '%status%' OR d.chinese_name ILIKE '%状态%'
98
+ ORDER BY d.code, e.display_order
99
+ LIMIT 100
100
+ ```
101
+
102
+ Check semantic model coverage:
103
+
104
+ ```sql
105
+ SELECT
106
+ m.name AS semantic_model,
107
+ m.domain,
108
+ COUNT(smr.resource_id) AS bound_resources
109
+ FROM semantic_models m
110
+ LEFT JOIN semantic_model_resources smr ON smr.semantic_model_id = m.id
111
+ GROUP BY m.id, m.name, m.domain
112
+ ORDER BY bound_resources DESC
113
+ ```
114
+
115
+ ## Answering Rules
116
+
117
+ - Ground every catalog, field, lineage, dictionary, and statistic answer in a `query_table` result.
118
+ - Prefer aggregate queries for "how many / what kinds / coverage / distribution" questions.
119
+ - Prefer explicit columns; large JSON fields such as `columns` and `field_mappings` should be returned only when needed.
120
+ - When the user names one business resource ambiguously, use `search_resources` or a narrow `resources` query to resolve candidates, then query platform tables for details.
121
+ - Do not expose credentials or encrypted secret fields from datasource/account tables.
122
+ - If the user requests changes to metadata, switch to the approved governance capability; this skill itself is reference-only and read-only.
123
+
124
+ ## Common Mistakes
125
+
126
+ | Mistake | Correct behavior |
127
+ | --- | --- |
128
+ | Answering "中台有什么资源" by returning 50 `search_resources` hits | Query `resources` with grouping, counts, filters, and representative rows. |
129
+ | Treating fields as unavailable because `search_resources` summary is short | Query `resources.columns` or `data_source_table_column_metadata`. |
130
+ | Explaining lineage from prose only | Query `resource_lineages` and join `resources` for source/target names. |
131
+ | Manually adding weak visibility clauses | Let runtime AST/WHERE strong filtering apply; keep SQL simple and read-only. |
132
+ | Using this skill to write platform metadata | Do not write. Use admin APIs or metadata governance tools when authorized. |
@@ -0,0 +1,53 @@
1
+ ---
2
+ name: dataops-metadata-optimizer
3
+ description: 用户要求优化元数据、补标注、让 AI 自己发现数据规律、提升问数准确率或速度时使用;扫描资源/列/指标/血缘,提出有证据的标注改进,preview 后 apply,并对比前后效果。
4
+ ---
5
+
6
+ # 元数据优化
7
+
8
+ ## 适用范围
9
+
10
+ 用户说“优化一下元数据”“让 AI 自己看看这个库”“把标注补全”“提升问数准确率/速度”时使用。
11
+
12
+ 不适用:
13
+
14
+ - 只导入数据 → `dataops-governance` 的 import reference;
15
+ - 只改单个字段 → 直接走 `govern_metadata`;
16
+ - 只问数 → `dataops-query`。
17
+
18
+ ## 核心原则
19
+
20
+ 1. **少问多做**:先自己盘点、采样、发现规律,再给少量高价值提案;不要一开始就让用户逐条解释。
21
+ 2. **每个提案必须有证据**:样本值、查询、血缘、命名、数据分布;低置信度必须标记。
22
+ 3. **写入走正常治理通道**:`govern_metadata` / 指标写入;禁止 shell/SQL/Prisma 直写。
23
+ 4. **Metric 是 SQL 片段**:只保留 name、displayName、description、sqlFragment、enabled、accessLevel、aiVisible;不做 aggregation/grain/dimension/aliases/MetricColumn。
24
+ 5. **分批**:一次最多 10 个提案;高影响(删除、隐藏、批量可见性)单独确认。
25
+ 6. **优化前后可量化**:覆盖率、检索命中、问数准确率、查询延迟;能测则测,不能测说明缺口。
26
+
27
+ ## 流程
28
+
29
+ 1. **盘点**:资源/列/指标/血缘覆盖,空描述、命名冲突、重复指标、未使用列。
30
+ 2. **发现规律**:枚举、日期、金额、ID、地域、状态、join key、view/base 关系、查询高频列。
31
+ 3. **生成提案**:对象、字段、当前值、建议值、证据、置信度、影响范围。
32
+ 4. **preview**:按影响分组展示;用户确认后 apply;高影响逐项确认。
33
+ 5. **apply**:走 `govern_metadata` / 指标写入;失败按错误合同停止,不绕过。
34
+ 6. **度量**:对比优化前后的覆盖率、检索命中、问数准确率/延迟;记录本轮改动。
35
+
36
+ ## 停止条件
37
+
38
+ - 找不到真实 resourceId/字段;
39
+ - 提案没有证据,或置信度低且用户未确认;
40
+ - 写入工具不存在(如指标工具);
41
+ - 已冻结/只读;
42
+ - 用户未确认 preview。
43
+
44
+ 遇到以上情况:停止写入,输出提案清单、缺口和已完成项。
45
+
46
+ ## Reference 路由
47
+
48
+ | 需要做什么 | 读哪个 |
49
+ | --- | --- |
50
+ | 盘点与基线 | `references/01-inventory.md` |
51
+ | 发现规律 | `references/02-pattern-catalog.md` |
52
+ | 生成/展示提案 | `references/03-proposal-and-preview.md` |
53
+ | 应用与度量 | `references/04-apply-and-measure.md` |
@@ -0,0 +1,10 @@
1
+ {
2
+ "_meta": {
3
+ "sourceHash": "d20372b9d2127d6f1b4afe0142ba24b062f609c3",
4
+ "model": "manual-zh",
5
+ "translatedAt": "2026-11-23T10:25:00+08:00"
6
+ },
7
+ "title": "元数据优化",
8
+ "description": "盘点资源、列、指标和血缘,识别命名、口径、冗余与缺失问题,生成治理提案并预览影响。",
9
+ "summary": "用于数据治理前的现状盘点、模式目录、提案/预览和变更前后度量。"
10
+ }
@@ -0,0 +1,23 @@
1
+ # 盘点与基线
2
+
3
+ ## 查什么
4
+
5
+ - 资源:数量、类型、表/视图、`aiVisible`、`accessLevel`、描述为空。
6
+ - 列:数量、类型、空描述、无中文名、枚举/日期/金额列。
7
+ - 指标:数量、重复、表达式为空、同名冲突。
8
+ - 血缘:断点、视图→基表、指标依赖。
9
+ - 使用:高频查询列、从未查询的列(能取到查询日志时)。
10
+
11
+ ## 工具
12
+
13
+ - 平台元数据:`query_table` 查 `resources`、`resource_columns`、`metrics`、`resource_lineages`。
14
+ - 样本:对重点表做 `SELECT ... LIMIT 20`,只看分布,不拉全量。
15
+ - 盘点结果写 `inventory.json`,作为本轮基线。
16
+
17
+ ## 基线指标
18
+
19
+ - 列描述覆盖率
20
+ - 列中文名覆盖率
21
+ - 指标覆盖率/重复率
22
+ - 血缘完整率
23
+ - 问数准确率/延迟(如果已有 benchmark 结果)
@@ -0,0 +1,16 @@
1
+ # 规律目录
2
+
3
+ 按优先级发现:
4
+
5
+ 1. **枚举/状态**:低基数、重复值多的列 → 补枚举含义、字典绑定。
6
+ 2. **日期/时间**:`date`/`timestamp`/`month` → 补时间口径、截止日、财年。
7
+ 3. **金额/数量**:`amount`/`price`/`qty` → 补单位、币种、是否含税。
8
+ 4. **ID/主键**:`*_id` → 补业务含义、是否唯一、join 对象。
9
+ 5. **地域**:城市/区县/路段/服务区 → 补层级关系。
10
+ 6. **join key**:同名/同类型列、view 定义 → 补血缘/关系。
11
+ 7. **重复指标**:同一 sqlFragment/口径 → 合并。
12
+ 8. **命名不一致**:同一概念多种叫法 → 统一。
13
+ 9. **空描述/无中文名**:优先事实表、指标依赖列、高频过滤列。
14
+ 10. **未使用列**:长期无查询 → 标记,不急着删。
15
+
16
+ 每条规律必须带:证据(样本值/分布/查询/血缘)、置信度、影响对象。