@qingflow-tech/qingflow-cli 1.1.61-beta.9 → 1.1.62-beta.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.
package/README.md CHANGED
@@ -7,7 +7,7 @@ Qingflow CLI 是轻流面向开发者和 AI Agent 的命令行工具。它把轻
7
7
  ## 安装
8
8
 
9
9
  ```bash
10
- npm install @qingflow-tech/qingflow-cli@1.1.61-beta.9
10
+ npm install @qingflow-tech/qingflow-cli@1.1.62-beta.1
11
11
  ```
12
12
 
13
13
  推荐从官网复制这一条一键安装 Qingflow CLI:
@@ -21,7 +21,7 @@ npx qingflow-cli@latest install
21
21
  ## 运行
22
22
 
23
23
  ```bash
24
- npx -y -p @qingflow-tech/qingflow-cli@1.1.61-beta.9 qingflow
24
+ npx -y -p @qingflow-tech/qingflow-cli@1.1.62-beta.1 qingflow
25
25
  ```
26
26
 
27
27
  全局安装后可以直接运行:
@@ -62,7 +62,7 @@ qingflow-skills install --agent codex --scope user
62
62
  如果你通过一次性 `npx -p` 执行 skills 安装,建议加 `--copy`,避免 symlink 指向 npm 临时执行缓存:
63
63
 
64
64
  ```bash
65
- npx -y -p @qingflow-tech/qingflow-cli@1.1.61-beta.9 qingflow-skills install --agent codex --scope user --copy
65
+ npx -y -p @qingflow-tech/qingflow-cli@1.1.62-beta.1 qingflow-skills install --agent codex --scope user --copy
66
66
  ```
67
67
 
68
68
  `qingflow-skills install` 默认使用 symlink,且遇到同名 skill 不会覆盖;只有显式传入 `--force` 才会替换。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qingflow-tech/qingflow-cli",
3
- "version": "1.1.61-beta.9",
3
+ "version": "1.1.62-beta.1",
4
4
  "description": "Human-friendly Qingflow command line interface for auth, record operations, import, tasks, and stable builder flows.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,6 +16,7 @@
16
16
  "pyproject.toml",
17
17
  "entry_point.py",
18
18
  "src/qingflow_mcp/**/*.py",
19
+ "src/qingflow_mcp/permission_catalog.json",
19
20
  "src/qingflow_mcp/builder_facade/schemas/**/*.json",
20
21
  "src/qingflow_mcp/py.typed",
21
22
  "qingflow",
package/pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "qingflow-mcp"
7
- version = "1.1.61b9"
7
+ version = "1.1.62b1"
8
8
  description = "User-authenticated MCP server for Qingflow"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -67,6 +67,7 @@ where = ["src"]
67
67
 
68
68
  [tool.setuptools.package-data]
69
69
  qingflow_mcp = [
70
+ "permission_catalog.json",
70
71
  "py.typed",
71
72
  "builder_facade/schemas/app_form/**/*.json",
72
73
  "builder_facade/schemas/views/**/*.json",
@@ -63,7 +63,7 @@ Before `portal apply`, verify this short list:
63
63
  | Standard heights | Metric cards `rows=5`; BI charts `rows=7`; data views `rows=11`. Do not mix different heights in one row. |
64
64
  | Standard order | Business entry -> metrics -> BI charts -> data views. Do not put data views before metrics/charts in a dashboard-style portal. |
65
65
  | Default/system views | Do not use `全部数据` / `我的数据` as the main business portal views. Use concrete business views. |
66
- | Filter component | `config.rules` must contain at least one rule group (empty-rules filters are written but invisible in readback; blocked at validation). Rule keys: filterGroupName/filterGroupConfig/filterItemName/que/judge, see §3.4. |
66
+ | Filter component | `config.rules` must contain at least one rule group (empty-rules filters are written but invisible in readback; blocked at validation). Item keys are backend persistence keys: filterGroupName/filterGroupConfig/filterItemName/dftJudgeType/dftJudgeValue/filterCondition — never `que`/`judge` (silently dropped, blocked at validation), see §3.4. |
67
67
  | Readback | After apply, run `portal get` and compare section count, refs, and positions before claiming frontend visibility. |
68
68
 
69
69
  Inline QingBI chart creation uses one chart job per section and runs with an internal concurrency limit of 10. If two sections declare the same `app_key + name + chart_type` with identical config, CLI creates/updates once and reuses the chart id. If their config differs, CLI rejects the portal write as a duplicate inline chart conflict.
@@ -293,19 +293,38 @@ CLI 校验(`PortalSectionPatch`):**chart** 须 **`chart`** 或 **`chart_re
293
293
 
294
294
  ### 3.4 **`filter`**:声明式筛选条(支持,**rules 必须非空**)
295
295
 
296
- 声明形态:**`config.graphs`**(受筛选作用的图表引用)+ **`config.rules`**(筛选规则组,至少 1 组),编译为后端 `ComponentFilter`(`graphList` + `filterConfig`)。规则键集:`filterGroupName`(组名)/`filterGroupConfig`(筛选项:`filterItemName` + `que{queId}` + `judge{judgeType,judgeValues}`);代理键 `filterGroupId`/`filterItemId` 为后端自增位移键,声明里不要携带。
296
+ 声明形态:**`config.rules`**(筛选规则组,至少 1 组)编译为后端 `ComponentFilter.filterConfig`;可选 **`config.graphs`** 一般省略——后端按 `filterCondition` 聚合派生 `graphList`。规则键集为**后端持久化键受控透传**:组键 `filterGroupName`(组名)/`filterGroupConfig`(筛选项列表);**筛选项键必须是后端持久化键**:`filterItemName` + `dftJudgeType` + `dftJudgeValue` + `filterCondition[]`;代理键 `filterGroupId`/`filterItemId` 为后端自增位移键,声明里不要携带。
297
+
298
+ **不要写 `que{queId}`/`judge{judgeType,judgeValues}` 声明键**(历史文档形态):后端写链的 `FilterGroupConfig` DTO 不识别这两个键,写入即被**静默丢弃**——落库只剩 `filterItemName`,回读表现为每项 `dftJudgeType: null、filterCondition: []`,前端筛选条件渲染为**空**(实测:apply 成功、回读组件存在但绑定全丢)。该形态现已被模型层阻断(apply/validate 共同路径显式报错)。
299
+
300
+ 字段绑定写在 `filterCondition[]`:每个条目把筛选项绑定到一张目标图表(`graphType: "CHART"`)或视图(`graphType: "VIEW"`),作用于 N 张图表就写 N 条:
297
301
 
298
302
  ```json
299
303
  {
300
304
  "source_type": "filter",
301
- "position": {"pc": {"x": 0, "y": 0, "cols": 24, "rows": 3}},
305
+ "position": {"pc": {"x": 0, "y": 0, "cols": 24, "rows": 3}, "mobile": {"x": 0, "y": 0, "cols": 6, "rows": 3}},
302
306
  "config": {
303
- "graphs": [{"chart_key": "CHART_KEY_1001"}],
304
307
  "rules": [
305
308
  {
306
309
  "filterGroupName": "区域",
307
310
  "filterGroupConfig": [
308
- {"filterItemName": "城市", "que": {"queId": 123456}, "judge": {"judgeType": 3, "judgeValues": ["上海"]}}
311
+ {
312
+ "filterItemName": "城市",
313
+ "dftJudgeType": 2,
314
+ "dftJudgeValue": [],
315
+ "filterCondition": [
316
+ {
317
+ "queId": 123456,
318
+ "queType": 2,
319
+ "queTitle": "城市",
320
+ "queOriginType": 2,
321
+ "chartKey": "CHART_KEY_1001",
322
+ "biFieldId": "APP_KEY_1:123456",
323
+ "chartName": "故障类型分布",
324
+ "graphType": "CHART"
325
+ }
326
+ ]
327
+ }
309
328
  ]
310
329
  }
311
330
  ]
@@ -313,7 +332,27 @@ CLI 校验(`PortalSectionPatch`):**chart** 须 **`chart`** 或 **`chart_re
313
332
  }
314
333
  ```
315
334
 
316
- **关键边界(旧实测记录的真相)**:`rules` 为空的 filter **会被模型层直接拒绝**——后端读面按筛选组(dash_filter_group 行)反查筛选组件,空规则的组件行虽写入但读面枚举不到,表现为「apply 成功、回读缺 type:6」。历史上「filter 不落库」的实测记录(命令式 raw 直传时代、全部空规则组合)即此机制,不是后端拒绝 type:6。存量筛选组件合法无标题(提取产物不带 `title`,不要合成);round-trip 重放已验证(ws40013 基准 337 个 filter 组件一致率 100%)。专项 Schema:`qingflow --json builder portal schema --schema-kind filter`。
335
+ `filterCondition[]` 条目键(后端持久化键,实测落库形态):
336
+
337
+ | 键 | 来源 |
338
+ |----|------|
339
+ | `queId` | 目标应用字段 queId(`builder app get --app-key … fields`) |
340
+ | `queType` | 字段类型编码:text=2、long_text=3、date/datetime=4、member=5、email=6、phone=7、number/amount=8、boolean=10、single_select=11、multi_select=12、attachment=13、subtable=18、q_linker=20、address=21、department=22、relation=25、code_block=26 |
341
+ | `queTitle` | 字段显示名 |
342
+ | `queOriginType` | 一般同 `queType` |
343
+ | `chartKey` | 目标图表 key(门户回读 `chart_ref.chart_id` / QingBI 图表 id);绑定视图时为视图 `viewgraph_key` |
344
+ | `biFieldId` | `"<app_key>:<queId>"` |
345
+ | `chartName` | 目标图表显示名 |
346
+ | `graphType` | `CHART`(图表)/`VIEW`(视图) |
347
+
348
+ 要点:
349
+
350
+ - `dftJudgeType: 2` 是「包含」(文本筛选项实测可用);`dftJudgeValue` 是默认筛选值,不希望预过滤就写 `[]`。
351
+ - 同一筛选项绑定多应用图表时,按各应用真实字段分别写条件条目;字段必须真实存在于目标图表所属应用,否则绑定不生效。
352
+ - 回读校验必须核对**每项 `filterCondition` 非空、`dftJudgeType` 有值**——只核对组件存在/组名存在会漏检绑定丢失(实测教训)。
353
+ - 回读的 `graphs` 可能按 filterCondition 条数展开重复——是派生数据,不是真实重复。
354
+
355
+ **关键边界(旧实测记录的真相)**:`rules` 为空的 filter **会被模型层直接拒绝**——后端读面按筛选组(dash_filter_group 行)反查筛选组件,空规则的组件行虽写入但读面枚举不到,表现为「apply 成功、回读缺 type:6」。历史上「filter 不落库」的实测记录(命令式 raw 直传时代、全部空规则组合)即此机制,不是后端拒绝 type:6。存量筛选组件合法无标题(提取产物不带 `title`,不要合成);round-trip 重放已验证(ws40013 基准 337 个 filter 组件一致率 100%——该基准验证的是后端键回读→重放路径,从未覆盖 que/judge 首写路径,后者实测被后端静默丢弃)。专项 Schema:`qingflow --json builder portal schema --schema-kind filter`。
317
356
 
318
357
  ### 3.5 **`grid` / `text` / `link` / `view`**
319
358
 
@@ -391,6 +430,7 @@ qingflow --json builder portal delete --dash-key "<DASH_KEY>" > tmp/builder_port
391
430
  |------|------|
392
431
  | `portal apply accepts exactly one selector mode` | **`dash-key`** vs **`package-id`** 二选一。 |
393
432
  | `PORTAL_READBACK_PENDING` / **`components expected N, got M`** | **`portal get`** 数组件;`filter` 回读缺失多为 **空 rules**(模型层已阻断,检查报错)或 **异步回读**(可再 **`get`** 一次);含规则的 filter 写入正常(见 **§3.4**)。 |
433
+ | **前端筛选条件为空 / 回读筛选项只剩 `filterItemName`** | 筛选项缺 `filterCondition[]` 绑定,或误用了 `que`/`judge` 声明键(模型层已阻断)。按 **§3.4** 用后端持久化键(`filterItemName` + `dftJudgeType` + `dftJudgeValue` + `filterCondition[]`)重建,并回读核对 `filterCondition` 非空。 |
394
434
  | **`published: true` 但 `verified: false`** | 读 **§7**;用 **`get` 草稿+线上**对照。 |
395
435
  | **503** | 网关/运维;稍后重试。 |
396
436
  | 缺 **chart** | 在对应 portal section 写 **`chart`**;或换用已有报表的 **`chart: {"chart_id": "..."}`** / 兼容旧 **`chart_ref`**。 |
@@ -17,13 +17,30 @@
17
17
  }
18
18
  },
19
19
  "config": {
20
- "graphs": [
20
+ "rules": [
21
21
  {
22
- "chart_key": "REPLACE_WITH_QINGBI_CHART_ID",
23
- "chart_name": "可选_图表显示名"
22
+ "filterGroupName": "区域",
23
+ "filterGroupConfig": [
24
+ {
25
+ "filterItemName": "城市",
26
+ "dftJudgeType": 2,
27
+ "dftJudgeValue": [],
28
+ "filterCondition": [
29
+ {
30
+ "queId": 123456,
31
+ "queType": 2,
32
+ "queTitle": "城市",
33
+ "queOriginType": 2,
34
+ "chartKey": "REPLACE_WITH_QINGBI_CHART_ID",
35
+ "biFieldId": "REPLACE_WITH_APP_KEY:123456",
36
+ "chartName": "REPLACE_WITH_CHART_NAME",
37
+ "graphType": "CHART"
38
+ }
39
+ ]
40
+ }
41
+ ]
24
42
  }
25
- ],
26
- "rules": []
43
+ ]
27
44
  }
28
45
  },
29
46
  {
@@ -2736,6 +2736,22 @@ class PortalSectionPatch(StrictModel):
2736
2736
  "filter section requires config.rules with at least one rule group; "
2737
2737
  "an empty-rules filter is written but invisible in portal get readback"
2738
2738
  )
2739
+ # 筛选项的后端持久化键是 dftJudgeType/dftJudgeValue/filterCondition;历史
2740
+ # 文档的声明键 que/judge 不被后端 FilterGroupConfig DTO 识别,静默丢弃后
2741
+ # 落库只剩 filterItemName——前端筛选条件渲染为空(实测首建全空真身)。
2742
+ # 同在模型咽喉阻断,把静默丢键变成显式报错。
2743
+ for group in rule_groups:
2744
+ if not isinstance(group, dict):
2745
+ continue
2746
+ for item in group.get("filterGroupConfig") or []:
2747
+ if isinstance(item, dict) and ("que" in item or "judge" in item):
2748
+ raise ValueError(
2749
+ "filter rule items must use backend persistence keys "
2750
+ "(filterItemName/dftJudgeType/dftJudgeValue/filterCondition); "
2751
+ "the declaration keys 'que'/'judge' are silently dropped by the "
2752
+ "backend and leave the frontend filter condition empty "
2753
+ "(see 70-portal.md section 3.4)"
2754
+ )
2739
2755
  return self
2740
2756
 
2741
2757
 
@@ -944,7 +944,7 @@
944
944
  "FilterConfig": {
945
945
  "type": "object",
946
946
  "additionalProperties": false,
947
- "filterConfigShapeDescription": "筛选组件配置(受控键集)。graphs 为受影响的图表引用;rules 为筛选规则组,键集 filterGroupName/filterGroupConfig/filterItemName/que/judge 系(受控透传,dataset 实测形态定稿;代理键 filterGroupId/filterItemId 剔除)。rules 必须至少 1 组——后端读面按筛选组反查筛选组件,空规则的 filter 写入后读面不可见(模型层已阻断)。",
947
+ "filterConfigShapeDescription": "筛选组件配置(受控键集)。graphs 为受影响的图表引用(可省略,后端按 filterCondition 派生);rules 为筛选规则组,项键为后端持久化键 filterGroupName/filterGroupConfig/filterItemName/dftJudgeType/dftJudgeValue/filterCondition 系(受控透传;代理键 filterGroupId/filterItemId 剔除;声明键 que/judge 会被后端静默丢弃致筛选条件为空,模型层已阻断)。rules 必须至少 1 组——后端读面按筛选组反查筛选组件,空规则的 filter 写入后读面不可见(模型层已阻断)。",
948
948
  "properties": {
949
949
  "graphs": {
950
950
  "type": "array",
@@ -965,7 +965,7 @@
965
965
  },
966
966
  "rules": {
967
967
  "type": "array",
968
- "filterRulesDescription": "筛选规则组(至少 1 组;空规则组件读面不可见)。组键 filterGroupName(必填)/filterGroupConfig(筛选项:filterItemName/que{queId}/judge{judgeType,judgeValues})。",
968
+ "filterRulesDescription": "筛选规则组(至少 1 组;空规则组件读面不可见)。组键 filterGroupName(必填)/filterGroupConfig(筛选项后端持久化键:filterItemName/dftJudgeType/dftJudgeValue/filterCondition[],详见专项 Schema --schema-kind filter)。",
969
969
  "x-backend": "ComponentFilter.filterConfig(List<FilterConfig>)"
970
970
  }
971
971
  }
@@ -59,11 +59,11 @@
59
59
  "required": [
60
60
  "rules"
61
61
  ],
62
- "filterConfigShapeDescription": "筛选组件配置。rules 必须非空——后端读面(DashSvcImpl#getComponentFilter)按筛选组(dash_filter_group 行)反查筛选组件,空规则的 filter 组件行虽会写入但读面枚举不到,表现为「apply 成功、回读缺该组件」;规则键集为受控透传(filterGroupName/filterGroupConfig/filterItemName/que/judge 系,以 ws40013 dataset 实测形态定稿)。",
62
+ "filterConfigShapeDescription": "筛选组件配置。rules 必须非空——后端读面(DashSvcImpl#getComponentFilter)按筛选组(dash_filter_group 行)反查筛选组件,空规则的 filter 组件行虽会写入但读面枚举不到,表现为「apply 成功、回读缺该组件」。规则键集为后端持久化键受控透传(filterGroupName/filterGroupConfig/filterItemName/dftJudgeType/dftJudgeValue/filterCondition 系);声明键 que/judge 会被后端写链静默丢弃(落库只剩 filterItemName,前端筛选条件为空),模型层已阻断。",
63
63
  "properties": {
64
64
  "graphs": {
65
65
  "type": "array",
66
- "filterGraphsShapeDescription": "筛选作用的图表引用(为空表示作用于全部图表)。",
66
+ "filterGraphsShapeDescription": "受筛选作用的图表引用(可省略:后端按 filterCondition 聚合派生 graphList,回读的 graphs 可能按绑定条数展开,非真实重复)。",
67
67
  "items": {
68
68
  "$ref": "#/$defs/FilterGraphRef"
69
69
  },
@@ -72,7 +72,7 @@
72
72
  "rules": {
73
73
  "type": "array",
74
74
  "minItems": 1,
75
- "filterRulesShapeDescription": "筛选规则组(至少 1 组)。组键:filterGroupName(组名,必填)、filterGroupConfig(组内筛选项列表);项键:filterItemName、que{queId}(绑定字段)、judge{judgeType,judgeValues}(默认条件)。代理键 filterGroupId/filterItemId 为后端自增位移键,读写两侧均剔除,不要携带。",
75
+ "filterRulesShapeDescription": "筛选规则组(至少 1 组)。组键:filterGroupName(组名,必填)、filterGroupConfig(组内筛选项列表);项键为后端持久化键:filterItemName、dftJudgeType、dftJudgeValue、filterCondition[](字段绑定)。代理键 filterGroupId/filterItemId 为后端自增位移键,读写两侧均剔除,不要携带;声明键 que/judge 会被后端静默丢弃,模型层已阻断。",
76
76
  "items": {
77
77
  "$ref": "#/$defs/FilterRuleGroup"
78
78
  },
@@ -136,22 +136,97 @@
136
136
  "required": [
137
137
  "filterItemName"
138
138
  ],
139
- "filterRuleItemShapeDescription": "单个筛选项(绑定一个字段)。que/judge 为后端受控透传形态;条件表达式(关联图表/字段)键集以 dataset 实测形态为准。",
139
+ "filterRuleItemShapeDescription": "单个筛选项,必须用后端持久化键:filterItemName + dftJudgeType/dftJudgeValue(默认条件) + filterCondition[](字段绑定,每条绑定一张目标图表/视图)。历史文档的声明键 que{queId}/judge{judgeType,judgeValues} 不被后端 FilterGroupConfig DTO 识别,写入即被静默丢弃——落库只剩 filterItemName,前端筛选条件渲染为空;模型层已阻断,不要携带。",
140
140
  "properties": {
141
141
  "filterItemName": {
142
142
  "type": "string",
143
143
  "filterRuleItemNameShapeDescription": "筛选项名称。",
144
144
  "x-backend": "FilterGroupConfig.filterItemName"
145
145
  },
146
- "que": {
147
- "type": "object",
148
- "filterRuleItemQueShapeDescription": "绑定的字段引用(queId 为字段唯一键)。",
149
- "x-backend": "FilterGroupConfig.que(Question)"
146
+ "dftJudgeType": {
147
+ "type": [
148
+ "integer",
149
+ "null"
150
+ ],
151
+ "dftJudgeTypeShapeDescription": "默认判断符;2=包含(文本筛选项实测可用)。",
152
+ "x-backend": "FilterGroupConfig.dftJudgeType"
150
153
  },
151
- "judge": {
152
- "type": "object",
153
- "filterRuleItemJudgeShapeDescription": "默认筛选条件:judgeType(比较符)+judgeValues(比较值列表)。",
154
- "x-backend": "FilterGroupConfig.dftJudgeType/dftJudgeValue"
154
+ "dftJudgeValue": {
155
+ "type": "array",
156
+ "dftJudgeValueShapeDescription": "默认筛选值列表;不希望预过滤写 []。",
157
+ "x-backend": "FilterGroupConfig.dftJudgeValue"
158
+ },
159
+ "filterCondition": {
160
+ "type": "array",
161
+ "filterConditionListShapeDescription": "字段绑定列表:每个条目把筛选项绑定到一张目标图表(graphType=CHART)或视图(graphType=VIEW);作用于 N 张图表就写 N 条。",
162
+ "items": {
163
+ "$ref": "#/$defs/FilterCondition"
164
+ },
165
+ "x-backend": "FilterGroupConfig.filterCondition"
166
+ },
167
+ "filterType": {
168
+ "type": [
169
+ "string",
170
+ "integer",
171
+ "null"
172
+ ],
173
+ "filterTypeShapeDescription": "筛选展示类型(后端键,可空;缺省 null 实测可正常落库)。",
174
+ "x-backend": "FilterGroupConfig.filterType"
175
+ }
176
+ }
177
+ },
178
+ "FilterCondition": {
179
+ "type": "object",
180
+ "required": [
181
+ "queId",
182
+ "chartKey"
183
+ ],
184
+ "filterConditionShapeDescription": "筛选项与一张目标图表/视图的字段绑定(后端持久化键,实测落库形态)。",
185
+ "properties": {
186
+ "queId": {
187
+ "type": "integer",
188
+ "conditionQueIdShapeDescription": "目标应用字段 queId(builder app get fields 读取)。",
189
+ "x-backend": "FilterCondition.queId"
190
+ },
191
+ "queType": {
192
+ "type": "integer",
193
+ "conditionQueTypeShapeDescription": "字段类型编码:text=2、long_text=3、date/datetime=4、member=5、email=6、phone=7、number/amount=8、boolean=10、single_select=11、multi_select=12、attachment=13、subtable=18、q_linker=20、address=21、department=22、relation=25、code_block=26。",
194
+ "x-backend": "FilterCondition.queType"
195
+ },
196
+ "queTitle": {
197
+ "type": "string",
198
+ "conditionQueTitleShapeDescription": "字段显示名。",
199
+ "x-backend": "FilterCondition.queTitle"
200
+ },
201
+ "queOriginType": {
202
+ "type": "integer",
203
+ "conditionQueOriginTypeShapeDescription": "来源字段类型,一般同 queType。",
204
+ "x-backend": "FilterCondition.queOriginType"
205
+ },
206
+ "chartKey": {
207
+ "type": "string",
208
+ "conditionChartKeyShapeDescription": "目标图表 key(门户回读 chart_ref.chart_id / QingBI 图表 bi id);绑定视图时为视图 viewgraph_key。",
209
+ "x-backend": "FilterCondition.chartKey"
210
+ },
211
+ "biFieldId": {
212
+ "type": "string",
213
+ "conditionBiFieldIdShapeDescription": "BI 字段 ID,格式 \"<app_key>:<queId>\"。",
214
+ "x-backend": "FilterCondition.biFieldId"
215
+ },
216
+ "chartName": {
217
+ "type": "string",
218
+ "conditionChartNameShapeDescription": "目标图表显示名。",
219
+ "x-backend": "FilterCondition.chartName"
220
+ },
221
+ "graphType": {
222
+ "type": "string",
223
+ "conditionGraphTypeShapeDescription": "绑定目标类型:CHART(图表)/VIEW(视图)。",
224
+ "x-backend": "FilterCondition.graphType"
225
+ },
226
+ "dateType": {
227
+ "type": "integer",
228
+ "conditionDateTypeShapeDescription": "date/datetime 字段补充键(date=0/datetime=1)。",
229
+ "x-backend": "FilterCondition.dateType"
155
230
  }
156
231
  }
157
232
  },
@@ -216,29 +291,36 @@
216
291
  }
217
292
  },
218
293
  "config": {
219
- "graphs": [
220
- {
221
- "chart_key": "CHART_KEY_1001"
222
- },
223
- {
224
- "chart_name": "故障类型分布"
225
- }
226
- ],
227
294
  "rules": [
228
295
  {
229
296
  "filterGroupName": "区域",
230
297
  "filterGroupConfig": [
231
298
  {
232
299
  "filterItemName": "城市",
233
- "que": {
234
- "queId": 123456
235
- },
236
- "judge": {
237
- "judgeType": 3,
238
- "judgeValues": [
239
- "上海"
240
- ]
241
- }
300
+ "dftJudgeType": 2,
301
+ "dftJudgeValue": [],
302
+ "filterCondition": [
303
+ {
304
+ "queId": 123456,
305
+ "queType": 2,
306
+ "queTitle": "城市",
307
+ "queOriginType": 2,
308
+ "chartKey": "CHART_KEY_1001",
309
+ "biFieldId": "APP_KEY_1:123456",
310
+ "chartName": "故障类型分布",
311
+ "graphType": "CHART"
312
+ },
313
+ {
314
+ "queId": 123456,
315
+ "queType": 2,
316
+ "queTitle": "城市",
317
+ "queOriginType": 2,
318
+ "chartKey": "CHART_KEY_1002",
319
+ "biFieldId": "APP_KEY_1:123456",
320
+ "chartName": "区域销量分布",
321
+ "graphType": "CHART"
322
+ }
323
+ ]
242
324
  }
243
325
  ]
244
326
  }
@@ -20,12 +20,13 @@ from ..tools.ai_builder_tools import _attach_builder_apply_envelope
20
20
  from ..version import get_cli_version, get_cli_version_info
21
21
  from ..tool_catalog import TOOL_DESCRIPTIONS, tool_is_exempt
22
22
  from ..tool_policy import (
23
- TOOL_POLICY_ENV,
24
23
  TOOL_POLICY_INVALID,
24
+ ToolPolicySnapshot,
25
25
  ToolPolicyViolation,
26
- parse_tool_policy,
26
+ read_current_tool_policy,
27
27
  )
28
28
  from .context import CliContext, build_cli_context
29
+ from .permission_gate import guard_cli_context
29
30
  from .formatters import emit_json_result, emit_text_result
30
31
  from .commands import register_all_commands
31
32
 
@@ -108,7 +109,7 @@ def run(
108
109
  parser.print_help(out)
109
110
  return 2
110
111
  if cli_route_from_namespace(args) == ("tools", "permissions"):
111
- # 授权自省必须早于业务上下文初始化,非法策略下也能说明拒绝原因。
112
+ # 工具开关自省只解析调用方参数,不初始化业务上下文。
112
113
  result = _handle_tools_permissions(args, None)
113
114
  if result["status"] == "failed":
114
115
  return _emit_error(result, json_mode=bool(args.json), stdout=out, stderr=err)
@@ -117,7 +118,9 @@ def run(
117
118
  else:
118
119
  emit_text_result(result, hint="tool_permissions", stream=out)
119
120
  return 0
120
- violation = _cli_tool_policy_violation(args)
121
+ stable_id = cli_trim_key_from_namespace(args)
122
+ snapshot = ToolPolicySnapshot("unrestricted") if stable_id and tool_is_exempt(stable_id) else read_current_tool_policy()
123
+ violation = _cli_tool_policy_violation(args, snapshot)
121
124
  if violation is not None:
122
125
  return _emit_error(
123
126
  violation.payload(),
@@ -128,13 +131,18 @@ def run(
128
131
  try:
129
132
  if _should_force_json_output(args):
130
133
  setattr(args, "json", True)
131
- context = context_factory()
134
+ stable_id = cli_trim_key_from_namespace(args)
135
+ context = guard_cli_context(context_factory(),
136
+ domain=stable_id.split(":", 1)[0] if stable_id else "user",
137
+ entry_tool_id=stable_id)
132
138
  if not bool(args.json):
133
139
  _emit_cli_effective_context_notice(args, context, stream=err)
134
140
  with cli_resource_base_url(os.getenv("QINGFLOW_BASE_URL") or ""):
135
141
  result = handler(args, context)
136
142
  except SystemExit as exc:
137
143
  return int(exc.code or 0)
144
+ except ToolPolicyViolation as exc:
145
+ return _emit_error(exc.payload(), json_mode=bool(args.json), stdout=out, stderr=err)
138
146
  except RuntimeError as exc:
139
147
  payload = trim_error_response(_parse_error_payload(exc))
140
148
  payload = _maybe_attach_builder_apply_error_envelope_from_args(args, payload)
@@ -157,7 +165,7 @@ def run(
157
165
  return exit_code
158
166
 
159
167
 
160
- def _cli_tool_policy_violation(args: argparse.Namespace) -> ToolPolicyViolation | None:
168
+ def _cli_tool_policy_violation(args: argparse.Namespace, snapshot: ToolPolicySnapshot | None = None) -> ToolPolicyViolation | None:
161
169
  stable_id = cli_trim_key_from_namespace(args)
162
170
  if stable_id is None:
163
171
  # 仅显式登记的非业务分发器可跳过闸门;无子命令的新增 handler 也必须默认拒绝。
@@ -168,11 +176,13 @@ def _cli_tool_policy_violation(args: argparse.Namespace) -> ToolPolicyViolation
168
176
  "user:unregistered",
169
177
  "CLI 业务命令未登记稳定工具 ID",
170
178
  )
171
- return parse_tool_policy(os.getenv(TOOL_POLICY_ENV)).violation_for(stable_id)
179
+ if tool_is_exempt(stable_id):
180
+ return None
181
+ return (snapshot or read_current_tool_policy()).violation_for(stable_id)
172
182
 
173
183
 
174
184
  def _handle_tools_permissions(_args: argparse.Namespace, _context: CliContext | None) -> dict[str, Any]:
175
- snapshot = parse_tool_policy(os.getenv(TOOL_POLICY_ENV))
185
+ snapshot = read_current_tool_policy()
176
186
  tools: dict[str, dict[str, Any]] = {}
177
187
  # 只报告当前 CLI 实际可达的工具;未知策略 ID 不代表已安装相应能力。
178
188
  for route, spec in sorted(PUBLIC_TOOL_BY_CLI_ROUTE.items()):
@@ -197,8 +207,6 @@ def _handle_tools_permissions(_args: argparse.Namespace, _context: CliContext |
197
207
  else:
198
208
  group = "denied_tools"
199
209
  result[group].append(row)
200
- if snapshot.mode == "invalid":
201
- result.update(status="failed", error_code=TOOL_POLICY_INVALID, message=snapshot.error)
202
210
  return result
203
211
 
204
212
 
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ from functools import wraps
4
+ from typing import Any
5
+
6
+ from ..public_surface import ALL_PUBLIC_TOOL_SPECS
7
+ from ..tool_catalog import tool_is_exempt
8
+ from ..tool_policy import read_current_tool_policy
9
+
10
+ _METHOD_IDS = {
11
+ domain: {method: spec.trim_key for spec in ALL_PUBLIC_TOOL_SPECS if spec.domain == domain
12
+ for method in (*spec.method_names, spec.tool_name)}
13
+ for domain in ("user", "builder")
14
+ }
15
+ _METHOD_IDS["builder"].update({
16
+ "app_form_evaluate_formula": "builder:app_form_validate_formula",
17
+ "app_form_run_code_block": "builder:app_form_validate_code_block",
18
+ })
19
+
20
+
21
+ class _GuardedFacade:
22
+ def __init__(self, target: Any, domain: str, *, workspace_selection: bool = False) -> None:
23
+ self._target, self._domain = target, domain
24
+ self._workspace_selection = workspace_selection
25
+
26
+ def __getattr__(self, name: str) -> Any:
27
+ method = getattr(self._target, name)
28
+ stable_id = _METHOD_IDS[self._domain].get(name)
29
+ if stable_id is None or not callable(method) or tool_is_exempt(stable_id):
30
+ return method
31
+ # 切换工作区是基础恢复入口,交互选择必须先读取候选项;独立列表命令仍受闸门约束。
32
+ if self._workspace_selection and stable_id == "user:workspace_list":
33
+ return method
34
+
35
+ @wraps(method)
36
+ def guarded(*args: Any, **kwargs: Any) -> Any:
37
+ # 交互命令可能长时间驻留,二次动作必须使用最新配置,不能沿用入口快照。
38
+ violation = read_current_tool_policy().violation_for(stable_id)
39
+ if violation is not None:
40
+ raise violation
41
+ return method(*args, **kwargs)
42
+ return guarded
43
+
44
+
45
+ def guard_cli_context(context: Any, *, domain: str = "user", entry_tool_id: str | None = None) -> Any:
46
+ # 交互工作台中的二次动作仍按工具检查,不能仅凭工作台的查看许可执行写入。
47
+ for name in ("auth", "login_link", "workspace", "app", "resource", "record", "data", "code_block",
48
+ "imports", "exports", "task", "files", "builder_feedback", "builder"):
49
+ target = getattr(context, name, None)
50
+ if target is not None:
51
+ # 文件 facade 被两个域共用,按当前入口域检查;其他业务 facade 保持自身权限域。
52
+ facade_domain = domain if name == "files" else (
53
+ "builder" if name in {"builder", "builder_feedback"} else "user"
54
+ )
55
+ setattr(context, name, _GuardedFacade(
56
+ target, facade_domain,
57
+ workspace_selection=name == "workspace" and entry_tool_id == "user:workspace_select",
58
+ ))
59
+ return context
@@ -0,0 +1,10 @@
1
+ """实体档位只展示完整工具集,不承担字段级或资源差异授权。"""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+
9
+ def permission_catalog() -> dict[str, Any]:
10
+ return json.loads(Path(__file__).with_name("permission_catalog.json").read_text(encoding="utf-8"))