@qingflow-tech/qingflow-cli 1.1.62 → 1.1.63-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.
Files changed (34) hide show
  1. package/README.md +3 -3
  2. package/package.json +2 -1
  3. package/pyproject.toml +2 -1
  4. package/skills/qingflow-cli/SKILL.md +112 -3
  5. package/skills/qingflow-cli/reference/builder/20-build-complete-system.md +1 -1
  6. package/skills/qingflow-cli/reference/builder/70-portal.md +46 -6
  7. package/skills/qingflow-cli/reference/builder/README.md +2 -2
  8. package/skills/qingflow-cli/reference/examples/portal/portal_sections_all_types.example.json +22 -5
  9. package/src/qingflow_mcp/builder_facade/app_form.py +5 -0
  10. package/src/qingflow_mcp/builder_facade/models.py +16 -0
  11. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/complete.json +59 -0
  12. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/amount.json +59 -0
  13. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/number.json +59 -0
  14. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/subtable.json +59 -0
  15. package/src/qingflow_mcp/builder_facade/schemas/portals/v1alpha1/complete.json +2 -2
  16. package/src/qingflow_mcp/builder_facade/schemas/portals/v1alpha1/components/filter.json +111 -29
  17. package/src/qingflow_mcp/builder_facade/service.py +8 -0
  18. package/src/qingflow_mcp/cli/formatters.py +11 -0
  19. package/src/qingflow_mcp/cli/main.py +90 -2
  20. package/src/qingflow_mcp/cli/permission_gate.py +59 -0
  21. package/src/qingflow_mcp/cloud_context.py +16 -1
  22. package/src/qingflow_mcp/entity_permissions.py +10 -0
  23. package/src/qingflow_mcp/permission_catalog.json +1210 -0
  24. package/src/qingflow_mcp/public_surface.py +67 -8
  25. package/src/qingflow_mcp/response_trim.py +2 -1
  26. package/src/qingflow_mcp/server.py +12 -6
  27. package/src/qingflow_mcp/server_app_builder.py +9 -5
  28. package/src/qingflow_mcp/server_app_user.py +9 -5
  29. package/src/qingflow_mcp/server_cloud.py +43 -7
  30. package/src/qingflow_mcp/tool_catalog.py +388 -0
  31. package/src/qingflow_mcp/tool_catalog_i18n.py +184 -0
  32. package/src/qingflow_mcp/tool_policy.py +191 -0
  33. package/src/qingflow_mcp/tools/base.py +1 -0
  34. package/src/qingflow_mcp/tools/record_tools.py +37 -2
@@ -1323,6 +1323,65 @@
1323
1323
  "null"
1324
1324
  ]
1325
1325
  },
1326
+ "numberFormatOptions": {
1327
+ "description": "新数字格式配置,存于字段扩展属性(question_extra_attr),与旧 numberFormat/canDecimal 相互独立;style 非空即生效,小数位缺省时按后端默认最多 10 位;传对象写入配置,null 或缺省沿用现值。",
1328
+ "oneOf": [
1329
+ {
1330
+ "type": "null"
1331
+ },
1332
+ {
1333
+ "additionalProperties": false,
1334
+ "properties": {
1335
+ "maximumFractionDigits": {
1336
+ "description": "最多小数位(0-10);0 表示仅整数。",
1337
+ "maximum": 10,
1338
+ "minimum": 0,
1339
+ "type": [
1340
+ "integer",
1341
+ "null"
1342
+ ]
1343
+ },
1344
+ "minimumFractionDigits": {
1345
+ "description": "最少小数位(0-10)。",
1346
+ "maximum": 10,
1347
+ "minimum": 0,
1348
+ "type": [
1349
+ "integer",
1350
+ "null"
1351
+ ]
1352
+ },
1353
+ "minimumIntegerDigits": {
1354
+ "description": "最少整数位(1-21)。",
1355
+ "maximum": 21,
1356
+ "minimum": 1,
1357
+ "type": [
1358
+ "integer",
1359
+ "null"
1360
+ ]
1361
+ },
1362
+ "style": {
1363
+ "description": "数字样式:decimal 普通数字,percent 百分比。",
1364
+ "enum": [
1365
+ "decimal",
1366
+ "percent"
1367
+ ],
1368
+ "type": "string"
1369
+ },
1370
+ "useGrouping": {
1371
+ "description": "是否显示千分位分隔符。",
1372
+ "type": [
1373
+ "boolean",
1374
+ "null"
1375
+ ]
1376
+ }
1377
+ },
1378
+ "required": [
1379
+ "style"
1380
+ ],
1381
+ "type": "object"
1382
+ }
1383
+ ]
1384
+ },
1326
1385
  "numberLimitStatus": {
1327
1386
  "description": "是否启用最小值和最大值限制。",
1328
1387
  "type": [
@@ -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
  }
@@ -31194,6 +31194,14 @@ def _build_view_update_payload(
31194
31194
  payload["viewgraphType"] = "calendarView"
31195
31195
  payload["beingShowTitleQue"] = True
31196
31196
  payload.pop("groupQueId", None)
31197
+ elif normalized_type == "hierarchy":
31198
+ payload["viewgraphType"] = "hierarchyView"
31199
+ payload["beingShowTitleQue"] = True
31200
+ payload.pop("groupQueId", None)
31201
+ elif normalized_type == "calendar":
31202
+ payload["viewgraphType"] = "calendarView"
31203
+ payload["beingShowTitleQue"] = True
31204
+ payload.pop("groupQueId", None)
31197
31205
  return _hydrate_view_backend_payload(
31198
31206
  payload=payload,
31199
31207
  view_type=normalized_type,
@@ -72,6 +72,16 @@ def _format_failed_result(result: dict[str, Any]) -> str:
72
72
  return "\n".join(lines) + "\n"
73
73
 
74
74
 
75
+ def _format_tool_permissions(result: dict[str, Any]) -> str:
76
+ lines = [f"策略状态:{result['mode']}"]
77
+ for key, label in (("allowed_tools", "允许工具"), ("denied_tools", "禁止工具"), ("exempt_tools", "豁免工具")):
78
+ lines.append(f"{label}:")
79
+ for row in result[key]:
80
+ commands = " / ".join("qingflow " + " ".join(item["route"]) for item in row["entrypoints"])
81
+ lines.append(f"- {row['id']}:{row['description']}({commands})")
82
+ return "\n".join(lines) + "\n"
83
+
84
+
75
85
  def _format_generic(result: dict[str, Any]) -> str:
76
86
  lines: list[str] = []
77
87
  title = _first_present(result, "status", "message")
@@ -1727,6 +1737,7 @@ def _format_login_link(result: dict[str, Any]) -> str:
1727
1737
 
1728
1738
 
1729
1739
  _FORMATTERS = {
1740
+ "tool_permissions": _format_tool_permissions,
1730
1741
  "login_link": _format_login_link,
1731
1742
  "auth_whoami": _format_whoami,
1732
1743
  "workspace_list": _format_workspace_list,
@@ -7,12 +7,26 @@ import sys
7
7
  from typing import Any, Callable, TextIO
8
8
 
9
9
  from ..errors import QingflowApiError, backend_code_value_int, message_looks_like_invalid_token
10
- from ..public_surface import cli_public_tool_spec_from_namespace
10
+ from ..public_surface import (
11
+ NON_TOOL_CLI_HANDLER_ROUTES,
12
+ PUBLIC_TOOL_BY_CLI_ROUTE,
13
+ cli_public_tool_spec_from_namespace,
14
+ cli_route_from_namespace,
15
+ cli_trim_key_from_namespace,
16
+ )
11
17
  from ..resource_uri import cli_resource_base_url
12
18
  from ..response_trim import resolve_cli_tool_name, trim_error_response, trim_public_response
13
19
  from ..tools.ai_builder_tools import _attach_builder_apply_envelope
14
20
  from ..version import get_cli_version, get_cli_version_info
21
+ from ..tool_catalog import TOOL_DESCRIPTIONS, tool_is_exempt
22
+ from ..tool_policy import (
23
+ TOOL_POLICY_INVALID,
24
+ ToolPolicySnapshot,
25
+ ToolPolicyViolation,
26
+ read_current_tool_policy,
27
+ )
15
28
  from .context import CliContext, build_cli_context
29
+ from .permission_gate import guard_cli_context
16
30
  from .formatters import emit_json_result, emit_text_result
17
31
  from .commands import register_all_commands
18
32
 
@@ -41,6 +55,10 @@ def build_parser() -> argparse.ArgumentParser:
41
55
  subparsers = parser.add_subparsers(dest="command", required=True)
42
56
  version_parser = subparsers.add_parser("version", help="输出 Qingflow CLI 版本")
43
57
  version_parser.set_defaults(handler=_handle_version, format_hint="version")
58
+ tools_parser = subparsers.add_parser("tools", help="查看当前 CLI 的工具授权")
59
+ tools_commands = tools_parser.add_subparsers(dest="tools_command", required=True)
60
+ permissions_parser = tools_commands.add_parser("permissions", help="只读查看本轮允许、禁止及豁免工具,不初始化认证")
61
+ permissions_parser.set_defaults(handler=_handle_tools_permissions)
44
62
  register_all_commands(subparsers)
45
63
  return parser
46
64
 
@@ -90,16 +108,41 @@ def run(
90
108
  if handler is None:
91
109
  parser.print_help(out)
92
110
  return 2
111
+ if cli_route_from_namespace(args) == ("tools", "permissions"):
112
+ # 工具开关自省只解析调用方参数,不初始化业务上下文。
113
+ result = _handle_tools_permissions(args, None)
114
+ if result["status"] == "failed":
115
+ return _emit_error(result, json_mode=bool(args.json), stdout=out, stderr=err)
116
+ if args.json:
117
+ emit_json_result(result, stream=out)
118
+ else:
119
+ emit_text_result(result, hint="tool_permissions", stream=out)
120
+ return 0
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)
124
+ if violation is not None:
125
+ return _emit_error(
126
+ violation.payload(),
127
+ json_mode=bool(args.json),
128
+ stdout=out,
129
+ stderr=err,
130
+ )
93
131
  try:
94
132
  if _should_force_json_output(args):
95
133
  setattr(args, "json", True)
96
- 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)
97
138
  if not bool(args.json):
98
139
  _emit_cli_effective_context_notice(args, context, stream=err)
99
140
  with cli_resource_base_url(os.getenv("QINGFLOW_BASE_URL") or ""):
100
141
  result = handler(args, context)
101
142
  except SystemExit as exc:
102
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)
103
146
  except RuntimeError as exc:
104
147
  payload = trim_error_response(_parse_error_payload(exc))
105
148
  payload = _maybe_attach_builder_apply_error_envelope_from_args(args, payload)
@@ -122,6 +165,51 @@ def run(
122
165
  return exit_code
123
166
 
124
167
 
168
+ def _cli_tool_policy_violation(args: argparse.Namespace, snapshot: ToolPolicySnapshot | None = None) -> ToolPolicyViolation | None:
169
+ stable_id = cli_trim_key_from_namespace(args)
170
+ if stable_id is None:
171
+ # 仅显式登记的非业务分发器可跳过闸门;无子命令的新增 handler 也必须默认拒绝。
172
+ if cli_route_from_namespace(args) in NON_TOOL_CLI_HANDLER_ROUTES:
173
+ return None
174
+ return ToolPolicyViolation(
175
+ TOOL_POLICY_INVALID,
176
+ "user:unregistered",
177
+ "CLI 业务命令未登记稳定工具 ID",
178
+ )
179
+ if tool_is_exempt(stable_id):
180
+ return None
181
+ return (snapshot or read_current_tool_policy()).violation_for(stable_id)
182
+
183
+
184
+ def _handle_tools_permissions(_args: argparse.Namespace, _context: CliContext | None) -> dict[str, Any]:
185
+ snapshot = read_current_tool_policy()
186
+ tools: dict[str, dict[str, Any]] = {}
187
+ # 只报告当前 CLI 实际可达的工具;未知策略 ID 不代表已安装相应能力。
188
+ for route, spec in sorted(PUBLIC_TOOL_BY_CLI_ROUTE.items()):
189
+ row = tools.setdefault(spec.trim_key, {
190
+ "id": spec.trim_key,
191
+ "description": TOOL_DESCRIPTIONS[spec.trim_key],
192
+ "entrypoints": [],
193
+ })
194
+ row["entrypoints"].append({"type": "cli", "route": list(route)})
195
+ result: dict[str, Any] = {
196
+ "status": "success",
197
+ "mode": snapshot.mode,
198
+ "allowed_tools": [],
199
+ "denied_tools": [],
200
+ "exempt_tools": [],
201
+ }
202
+ for stable_id, row in sorted(tools.items()):
203
+ if tool_is_exempt(stable_id):
204
+ group = "exempt_tools"
205
+ elif snapshot.violation_for(stable_id) is None:
206
+ group = "allowed_tools"
207
+ else:
208
+ group = "denied_tools"
209
+ result[group].append(row)
210
+ return result
211
+
212
+
125
213
  def _handle_version(_args: argparse.Namespace, _context: CliContext) -> dict[str, Any]:
126
214
  info = get_cli_version_info()
127
215
  return {
@@ -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
@@ -2,11 +2,14 @@ from __future__ import annotations
2
2
 
3
3
  from contextvars import ContextVar
4
4
  from dataclasses import dataclass, field
5
- from typing import Callable
5
+ from typing import TYPE_CHECKING, Callable
6
6
 
7
7
  from .backend_client import BackendRequestContext
8
8
  from .session_store import BackendSession, SessionProfile
9
9
 
10
+ if TYPE_CHECKING:
11
+ from .tool_policy import ToolPolicySnapshot
12
+
10
13
 
11
14
  CLOUD_PROFILE_NAME = "__cloud_mcp__"
12
15
 
@@ -73,3 +76,15 @@ current_call_platform: ContextVar[str] = ContextVar(
73
76
  "qingflow_mcp_current_call_platform",
74
77
  default="",
75
78
  )
79
+
80
+ # 远端 MCP 每个 HTTP 请求独立绑定策略原文;缺头用 None 表示,不回退进程环境变量。
81
+ current_tool_policy_header: ContextVar[str | None] = ContextVar(
82
+ "qingflow_mcp_current_tool_policy_header",
83
+ default=None,
84
+ )
85
+
86
+ # 在 HTTP 入口合成一次快照,列表与调用共用,避免将 URL 选择保存到会话或共享环境。
87
+ current_http_tool_policy: ContextVar[ToolPolicySnapshot | None] = ContextVar(
88
+ "qingflow_mcp_current_http_tool_policy",
89
+ default=None,
90
+ )
@@ -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"))