bpmax-cli 0.1.43 → 0.1.44-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 +3 -3
- package/dist/bin.js +3397 -433
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-api-platform-editor/SKILL.md +321 -0
- package/skills/bpmax-api-platform-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-api-platform-editor/references/api-doc-debug-workflow.md +34 -0
- package/skills/bpmax-api-platform-editor/references/api-proxy-shape.md +41 -0
- package/skills/bpmax-api-platform-editor/references/instance-config-shape.md +41 -0
- package/skills/bpmax-api-platform-editor/references/platform-api-map.md +52 -0
- package/skills/bpmax-api-platform-editor/references/runtime-workflow.md +32 -0
- package/skills/bpmax-api-platform-editor/scripts/api_platform_editor_common.py +1276 -0
- package/skills/bpmax-api-platform-editor/scripts/build_submit_payload.py +64 -0
- package/skills/bpmax-api-platform-editor/scripts/capture_write_contract.py +40 -0
- package/skills/bpmax-api-platform-editor/scripts/export_layer_bundle.py +212 -0
- package/skills/bpmax-api-platform-editor/scripts/record_doc_debug_acceptance.py +62 -0
- package/skills/bpmax-api-platform-editor/scripts/submit_and_verify_layer.py +75 -0
- package/skills/bpmax-api-platform-editor/tests/test_api_platform_editor.py +287 -0
- package/skills/bpmax-auth/SKILL.md +6 -17
- package/skills/bpmax-builder-shared/SKILL.md +44 -0
- package/skills/bpmax-builder-shared/base_url.py +81 -0
- package/skills/bpmax-builder-shared/runtime-script-site-matrix.json +71 -0
- package/skills/bpmax-builder-shared/runtime-script-site-matrix.md +34 -0
- package/skills/bpmax-builder-shared/runtime-script-template-catalog.md +123 -0
- package/skills/bpmax-builder-shared/runtime_script_rules.py +272 -0
- package/skills/bpmax-builder-shared/skill_audit.py +374 -0
- package/skills/bpmax-builder-shared/template_script_hard_rules.py +280 -0
- package/skills/bpmax-builder-shared/tests/test_base_url.py +80 -0
- package/skills/bpmax-builder-shared/tests/test_runtime_script_rules.py +115 -0
- package/skills/bpmax-builder-shared/tests/test_skill_audit.py +231 -0
- package/skills/bpmax-builder-shared/tests/test_template_script_hard_rules.py +281 -0
- package/skills/bpmax-cli/SKILL.md +2 -0
- package/skills/bpmax-config-latest/SKILL.md +71 -0
- package/skills/bpmax-console-template-editor/SKILL.md +536 -0
- package/skills/bpmax-console-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-console-template-editor/references/filter-integration.md +60 -0
- package/skills/bpmax-console-template-editor/references/lessons-from-resume-dashboard.md +114 -0
- package/skills/bpmax-console-template-editor/references/local-temp-workflow.md +69 -0
- package/skills/bpmax-console-template-editor/references/module-catalog.md +100 -0
- package/skills/bpmax-console-template-editor/references/runtime-page-shape.md +91 -0
- package/skills/bpmax-console-template-editor/references/template-shape.md +149 -0
- package/skills/bpmax-console-template-editor/scripts/build_submit_payload.py +38 -0
- package/skills/bpmax-console-template-editor/scripts/confirm_console_template.py +33 -0
- package/skills/bpmax-console-template-editor/scripts/console_template_editor_common.py +964 -0
- package/skills/bpmax-console-template-editor/scripts/export_console_template.py +99 -0
- package/skills/bpmax-console-template-editor/scripts/lint_console_template.py +46 -0
- package/skills/bpmax-console-template-editor/scripts/submit_console_template.py +99 -0
- package/skills/bpmax-console-template-editor/tests/test_console_template_editor.py +383 -0
- package/skills/bpmax-dataset-field-template-editor/SKILL.md +600 -0
- package/skills/bpmax-dataset-field-template-editor/references/create-request-gotchas.md +25 -0
- package/skills/bpmax-dataset-field-template-editor/references/field-classify-mapping.md +35 -0
- package/skills/bpmax-dataset-field-template-editor/references/nested-field-patterns.md +24 -0
- package/skills/bpmax-dataset-field-template-editor/references/runtime-verified-field-page-shape.md +61 -0
- package/skills/bpmax-dataset-field-template-editor/references/virtual-field-patterns.md +27 -0
- package/skills/bpmax-dataset-field-template-editor/references/work-file-to-submit-mapping.md +127 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/build_submit_payload.py +67 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/confirm_dataset_field.py +37 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/dataset_field_editor_common.py +784 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/export_dataset_field.py +62 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/init_create_dataset_field.py +104 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/inspect_dataset_field_runtime.py +83 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/lint_dataset_field_semantics.py +35 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/submit_dataset_field.py +95 -0
- package/skills/bpmax-dataset-field-template-editor/tests/test_dataset_field_editor.py +709 -0
- package/skills/bpmax-dataset-field-template-editor/tests/test_init_create_dataset_field.py +59 -0
- package/skills/bpmax-dataset-template-editor/SKILL.md +779 -0
- package/skills/bpmax-dataset-template-editor/references/custom-key-usage-patterns.md +18 -0
- package/skills/bpmax-dataset-template-editor/references/dataset-script-runtime-matrix.md +73 -0
- package/skills/bpmax-dataset-template-editor/references/pre-process-script-authoring-guide.md +186 -0
- package/skills/bpmax-dataset-template-editor/references/pre-process-script-example-catalog.md +106 -0
- package/skills/bpmax-dataset-template-editor/references/runtime-gotchas.md +28 -0
- package/skills/bpmax-dataset-template-editor/references/runtime-verified-dataset-page-shape.md +47 -0
- package/skills/bpmax-dataset-template-editor/references/ui-to-backend-field-map.md +23 -0
- package/skills/bpmax-dataset-template-editor/references/work-file-to-submit-mapping.md +97 -0
- package/skills/bpmax-dataset-template-editor/scripts/basic_table_audit.py +65 -0
- package/skills/bpmax-dataset-template-editor/scripts/build_submit_payload.py +38 -0
- package/skills/bpmax-dataset-template-editor/scripts/dataset_editor_common.py +650 -0
- package/skills/bpmax-dataset-template-editor/scripts/export_dataset.py +155 -0
- package/skills/bpmax-dataset-template-editor/scripts/lint_dataset_template.py +42 -0
- package/skills/bpmax-dataset-template-editor/scripts/resolve_dataset.py +43 -0
- package/skills/bpmax-dataset-template-editor/scripts/scan_custom_key_references.py +27 -0
- package/skills/bpmax-dataset-template-editor/scripts/submit_dataset.py +115 -0
- package/skills/bpmax-dataset-template-editor/scripts/verify_dataset_list.py +52 -0
- package/skills/bpmax-dataset-template-editor/scripts/verify_publish_health.py +39 -0
- package/skills/bpmax-dataset-template-editor/tests/test_dataset_editor.py +373 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/SKILL.md +151 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/agents/openai.yaml +4 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/references/orchestration-matrix.md +60 -0
- package/skills/bpmax-e2e-flow-test-operator/SKILL.md +371 -0
- package/skills/bpmax-e2e-flow-test-operator/agents/openai.yaml +5 -0
- package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale.json +97 -0
- package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_final_v2.json +105 -0
- package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_main.json +36 -0
- package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_region.json +40 -0
- package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +33 -0
- package/skills/bpmax-e2e-flow-test-operator/references/failure-update-loop.md +17 -0
- package/skills/bpmax-e2e-flow-test-operator/references/filter-field-discovery.md +40 -0
- package/skills/bpmax-e2e-flow-test-operator/references/minimal-test-loop.md +19 -0
- package/skills/bpmax-e2e-flow-test-operator/references/negative-sale-api-matrix.md +75 -0
- package/skills/bpmax-e2e-flow-test-operator/references/profile-schema.md +107 -0
- package/skills/bpmax-e2e-flow-test-operator/references/skill-experience-coverage-matrix.md +29 -0
- package/skills/bpmax-e2e-flow-test-operator/references/stale-runtime-and-clean-sample-rules.md +54 -0
- package/skills/bpmax-e2e-flow-test-operator/references/state-schema.md +58 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/bpmax_session.py +287 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/dealer_sample_on_shelf_plan.json +59 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/dealer_sample_on_shelf_runner.py +687 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_doc.py +95 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_state.py +288 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_api_matrix.py +161 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_filter_fields.py +138 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_form_runtime.py +396 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_runner.py +341 -0
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_test_profile.py +185 -0
- package/skills/bpmax-e2e-flow-test-operator/tests/test_negative_sale_api_tools.py +138 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/SKILL.md +69 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-checklist.md +42 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-recipes.md +38 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-shape.md +86 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/gate-lint.md +68 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/hoocoo-patterns.md +39 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/runtime-behavior.md +41 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/references/script-authoring.md +110 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/scripts/lint_feishu_chat_plugin.py +278 -0
- package/skills/bpmax-feishu-chat-flow-plugin-editor/tests/test_lint_feishu_chat_plugin.py +203 -0
- package/skills/bpmax-filter-template-editor/SKILL.md +564 -0
- package/skills/bpmax-filter-template-editor/references/experience-coverage-matrix.md +38 -0
- package/skills/bpmax-filter-template-editor/references/filter-and-flow-binding.md +57 -0
- package/skills/bpmax-filter-template-editor/references/filter-content-schema.md +141 -0
- package/skills/bpmax-filter-template-editor/references/filter-request-shape.md +287 -0
- package/skills/bpmax-filter-template-editor/references/filter-runtime-patterns.md +115 -0
- package/skills/bpmax-filter-template-editor/references/runtime-verified-filter-page-shape.md +94 -0
- package/skills/bpmax-filter-template-editor/scripts/build_submit_payload.py +25 -0
- package/skills/bpmax-filter-template-editor/scripts/confirm_filter_template.py +22 -0
- package/skills/bpmax-filter-template-editor/scripts/export_filter_template.py +57 -0
- package/skills/bpmax-filter-template-editor/scripts/filter_template_editor_common.py +348 -0
- package/skills/bpmax-filter-template-editor/scripts/init_create_filter_template.py +8 -0
- package/skills/bpmax-filter-template-editor/scripts/lint_filter_template_semantics.py +26 -0
- package/skills/bpmax-filter-template-editor/scripts/submit_filter_template.py +62 -0
- package/skills/bpmax-filter-template-editor/tests/test_filter_template_editor.py +231 -0
- package/skills/bpmax-flow-template-editor/SKILL.md +1043 -0
- package/skills/bpmax-flow-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-flow-template-editor/references/before-next-step-script-runtime-gotchas.md +62 -0
- package/skills/bpmax-flow-template-editor/references/config-surfaces-and-placeholders.md +270 -0
- package/skills/bpmax-flow-template-editor/references/diff-strategy.md +67 -0
- package/skills/bpmax-flow-template-editor/references/editor-runtime-vs-draft.md +25 -0
- package/skills/bpmax-flow-template-editor/references/flow-template-api-workflow.md +159 -0
- package/skills/bpmax-flow-template-editor/references/intent-model.md +117 -0
- package/skills/bpmax-flow-template-editor/references/lessons-from-price-plan-flow.md +147 -0
- package/skills/bpmax-flow-template-editor/references/local-temp-workflow.md +97 -0
- package/skills/bpmax-flow-template-editor/references/matrix-flow-form-nav-collaboration.md +163 -0
- package/skills/bpmax-flow-template-editor/references/payload-checklist.md +133 -0
- package/skills/bpmax-flow-template-editor/references/project-create-runtime-gotchas.md +54 -0
- package/skills/bpmax-flow-template-editor/references/requirement-to-node-mapping.md +149 -0
- package/skills/bpmax-flow-template-editor/references/runtime-verified-flow-detail-shape.md +41 -0
- package/skills/bpmax-flow-template-editor/references/runtime-verified-meta-fields.md +155 -0
- package/skills/bpmax-flow-template-editor/references/runtime-verified-node-fields.md +179 -0
- package/skills/bpmax-flow-template-editor/references/save-draft-request-shape.md +91 -0
- package/skills/bpmax-flow-template-editor/references/script-review-hard-rules.md +93 -0
- package/skills/bpmax-flow-template-editor/references/work-file-to-submit-mapping.md +57 -0
- package/skills/bpmax-flow-template-editor/scripts/build_submit_payload.py +69 -0
- package/skills/bpmax-flow-template-editor/scripts/confirm_flow_template.py +52 -0
- package/skills/bpmax-flow-template-editor/scripts/export_flow_template.py +114 -0
- package/skills/bpmax-flow-template-editor/scripts/flow_template_editor_common.py +1084 -0
- package/skills/bpmax-flow-template-editor/scripts/submit_flow_template.py +159 -0
- package/skills/bpmax-flow-template-editor/tests/test_flow_template_editor.py +636 -0
- package/skills/bpmax-form-template-editor/SKILL.md +1074 -0
- package/skills/bpmax-form-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-form-template-editor/references/form-template-api-workflow.md +193 -0
- package/skills/bpmax-form-template-editor/references/local-temp-workflow.md +125 -0
- package/skills/bpmax-form-template-editor/references/payload-checklist.md +77 -0
- package/skills/bpmax-form-template-editor/references/sub-form-patterns.md +49 -0
- package/skills/bpmax-form-template-editor/scripts/build_submit_payload.py +37 -0
- package/skills/bpmax-form-template-editor/scripts/check_form_template_consistency.py +145 -0
- package/skills/bpmax-form-template-editor/scripts/confirm_form_template.py +67 -0
- package/skills/bpmax-form-template-editor/scripts/export_form_template.py +89 -0
- package/skills/bpmax-form-template-editor/scripts/form_template_editor_common.py +1745 -0
- package/skills/bpmax-form-template-editor/scripts/lint_form_template_semantics.py +30 -0
- package/skills/bpmax-form-template-editor/scripts/record_runtime_acceptance.py +67 -0
- package/skills/bpmax-form-template-editor/scripts/submit_form_template.py +163 -0
- package/skills/bpmax-form-template-editor/tests/test_form_template_editor.py +1303 -0
- package/skills/bpmax-list-template-editor/SKILL.md +468 -0
- package/skills/bpmax-list-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-list-template-editor/references/browser-page-contract.md +81 -0
- package/skills/bpmax-list-template-editor/references/content-config-shape.md +148 -0
- package/skills/bpmax-list-template-editor/references/dataset-field-mapping.md +60 -0
- package/skills/bpmax-list-template-editor/references/list-template-api-workflow.md +103 -0
- package/skills/bpmax-list-template-editor/references/local-temp-workflow.md +102 -0
- package/skills/bpmax-list-template-editor/references/payload-checklist.md +47 -0
- package/skills/bpmax-list-template-editor/references/runtime-verified-workflow.md +140 -0
- package/skills/bpmax-list-template-editor/references/special-formats.md +394 -0
- package/skills/bpmax-list-template-editor/scripts/build_submit_payload.py +37 -0
- package/skills/bpmax-list-template-editor/scripts/confirm_list_template.py +33 -0
- package/skills/bpmax-list-template-editor/scripts/export_list_template.py +89 -0
- package/skills/bpmax-list-template-editor/scripts/fetch_data_set.py +34 -0
- package/skills/bpmax-list-template-editor/scripts/lint_list_template_semantics.py +54 -0
- package/skills/bpmax-list-template-editor/scripts/list_template_editor_common.py +955 -0
- package/skills/bpmax-list-template-editor/scripts/record_acceptance.py +55 -0
- package/skills/bpmax-list-template-editor/scripts/submit_list_template.py +117 -0
- package/skills/bpmax-list-template-editor/tests/test_list_template_editor_common.py +441 -0
- package/skills/bpmax-nav-config-editor/SKILL.md +347 -0
- package/skills/bpmax-nav-config-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-nav-config-editor/references/api-workflow.md +68 -0
- package/skills/bpmax-nav-config-editor/references/config-shape.md +78 -0
- package/skills/bpmax-nav-config-editor/references/icon-selection.md +83 -0
- package/skills/bpmax-nav-config-editor/references/path-mapping-rules.md +46 -0
- package/skills/bpmax-nav-config-editor/references/payload-checklist.md +41 -0
- package/skills/bpmax-nav-config-editor/references/runtime-probing.md +47 -0
- package/skills/bpmax-nav-config-editor/scripts/build_submit_payload.py +34 -0
- package/skills/bpmax-nav-config-editor/scripts/confirm_nav_config.py +32 -0
- package/skills/bpmax-nav-config-editor/scripts/export_nav_config.py +56 -0
- package/skills/bpmax-nav-config-editor/scripts/lint_nav_config_semantics.py +33 -0
- package/skills/bpmax-nav-config-editor/scripts/nav_config_editor_common.py +812 -0
- package/skills/bpmax-nav-config-editor/scripts/submit_nav_config.py +44 -0
- package/skills/bpmax-nav-config-editor/scripts/verify_nav_config.py +33 -0
- package/skills/bpmax-nav-config-editor/tests/test_nav_config_editor.py +358 -0
- package/skills/bpmax-nav-config-editor/tests/test_nav_config_editor_common.py +138 -0
- package/skills/bpmax-nav-config-editor/tests/test_nav_config_lint.py +58 -0
- package/skills/bpmax-nav-config-editor/tests/test_nav_config_submit_verify.py +51 -0
- package/skills/bpmax-project/SKILL.md +1 -1
- package/skills/bpmax-project-detail-template-editor/SKILL.md +329 -0
- package/skills/bpmax-project-detail-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-project-detail-template-editor/references/local-temp-workflow.md +59 -0
- package/skills/bpmax-project-detail-template-editor/references/module-catalog-and-config-notes.md +47 -0
- package/skills/bpmax-project-detail-template-editor/references/payload-checklist.md +33 -0
- package/skills/bpmax-project-detail-template-editor/references/project-detail-template-api-workflow.md +44 -0
- package/skills/bpmax-project-detail-template-editor/scripts/build_submit_payload.py +30 -0
- package/skills/bpmax-project-detail-template-editor/scripts/confirm_project_detail_template.py +33 -0
- package/skills/bpmax-project-detail-template-editor/scripts/export_project_detail_template.py +87 -0
- package/skills/bpmax-project-detail-template-editor/scripts/lint_project_detail_template_semantics.py +37 -0
- package/skills/bpmax-project-detail-template-editor/scripts/project_detail_template_editor_common.py +507 -0
- package/skills/bpmax-project-detail-template-editor/scripts/submit_project_detail_template.py +120 -0
- package/skills/bpmax-project-detail-template-editor/tests/test_project_detail_template_editor.py +369 -0
- package/skills/bpmax-role-editor/SKILL.md +251 -0
- package/skills/bpmax-role-editor/references/api-workflow.md +30 -0
- package/skills/bpmax-role-editor/references/runtime-page-shape.md +18 -0
- package/skills/bpmax-role-editor/references/work-file-mapping.md +32 -0
- package/skills/bpmax-role-editor/scripts/build_submit_payload.py +38 -0
- package/skills/bpmax-role-editor/scripts/confirm_role.py +33 -0
- package/skills/bpmax-role-editor/scripts/export_role.py +163 -0
- package/skills/bpmax-role-editor/scripts/lint_role_semantics.py +38 -0
- package/skills/bpmax-role-editor/scripts/role_editor_common.py +1231 -0
- package/skills/bpmax-role-editor/scripts/submit_role.py +144 -0
- package/skills/bpmax-role-editor/tests/test_role_editor.py +343 -0
- package/skills/bpmax-shared/SKILL.md +1 -1
- package/skills/form-control-library/SKILL.md +82 -0
- package/skills/form-control-library/agents/openai.yaml +4 -0
- package/skills/form-control-library/references/form-controls.md +199 -0
- package/skills/form-control-library/references/form-template-submit-schema.md +180 -0
- package/skills/form-control-library/references/group-select-runtime.md +191 -0
- package/skills/form-control-library/scripts/rebuild_form_control_library.py +55 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Iterable
|
|
9
|
+
|
|
10
|
+
from runtime_script_rules import SCRIPT_SITE_MATRIX, lint_runtime_script
|
|
11
|
+
from template_script_hard_rules import contains_user_scope_project_list_query
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
HARD_CODED_ORIGIN_PATTERN = re.compile(
|
|
15
|
+
r"https?://(?!(?:bpmax|sysconfigdiff|git)\.example\.com\b)(?:[A-Za-z0-9-]+\.)+(?:local|test|dev|prod|com|cn)(?:/api)?"
|
|
16
|
+
)
|
|
17
|
+
UNIMPLEMENTED_DOC_PATTERNS = (
|
|
18
|
+
re.compile(r"scripts/\s*未落地"),
|
|
19
|
+
re.compile(r"脚本未落地"),
|
|
20
|
+
re.compile(r"当前仓库里这些脚本还不存在"),
|
|
21
|
+
re.compile(r"还没有\s+`?scripts/?`?\s+目录"),
|
|
22
|
+
re.compile(r"后续必须先把对应脚本落地"),
|
|
23
|
+
)
|
|
24
|
+
SCRIPT_REFERENCE_PATTERN = re.compile(r"`((?:[\w./-]+/)?[\w.-]+\.py)`")
|
|
25
|
+
FORBIDDEN_PROMISE_THEN_PATTERN = re.compile(r"\.then\s*\(")
|
|
26
|
+
GOVERNANCE_REFERENCE_PATTERNS = (
|
|
27
|
+
re.compile(r"runtime-script-site-matrix(?:\.md|\.json)?"),
|
|
28
|
+
re.compile(r"runtime-script-template-catalog(?:\.md)?"),
|
|
29
|
+
)
|
|
30
|
+
SCRIPT_GOVERNANCE_SITE_PATTERN = re.compile(
|
|
31
|
+
r"\blambda\b|customeValidate|pre_process_script|beforeNextStepScript|project_create_validator"
|
|
32
|
+
)
|
|
33
|
+
SCRIPT_GOVERNANCE_CONTEXT_PATTERN = re.compile(r"脚本|ctx\.|抽取|回写|单行化|writeback|patch|生成")
|
|
34
|
+
SECTION_HEADING_PATTERN = re.compile(r"^##\s+`?([A-Za-z_][A-Za-z0-9_-]*)`?\s*$")
|
|
35
|
+
TEXT_SUFFIXES = {".md", ".py", ".json", ".yaml", ".yml", ".txt"}
|
|
36
|
+
PROJECT_LIST_VERIFICATION_CONTEXT_PATTERN = re.compile(
|
|
37
|
+
r"验收|验证|回读|真实请求体|真实触发|请求级验证|结果级验证|自动发起|空态|列表页行为|观察"
|
|
38
|
+
)
|
|
39
|
+
PROJECT_LIST_GUIDANCE_CONTEXT_PATTERN = re.compile(
|
|
40
|
+
r"默认|优先|统一|建议|联动|初始化|回填|校验|查库存|查商品|查项目|ctx\.(?:\$axios|axios)|ESProjectList|esProjectList"
|
|
41
|
+
)
|
|
42
|
+
PROJECT_LIST_PROHIBITION_CONTEXT_PATTERN = re.compile(r"禁止|不得|不准|不能|must not|forbid", re.IGNORECASE)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _finding(code: str, file_path: Path, line_no: int, message: str, snippet: str) -> dict[str, Any]:
|
|
46
|
+
return {
|
|
47
|
+
"code": code,
|
|
48
|
+
"file": file_path.as_posix(),
|
|
49
|
+
"line": line_no,
|
|
50
|
+
"message": message,
|
|
51
|
+
"snippet": snippet[:240],
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _iter_text_files(skill_root: Path) -> Iterable[Path]:
|
|
56
|
+
for path in sorted(skill_root.rglob("*")):
|
|
57
|
+
if not path.is_file() or path.suffix.lower() not in TEXT_SUFFIXES:
|
|
58
|
+
continue
|
|
59
|
+
if "tests" in path.relative_to(skill_root).parts:
|
|
60
|
+
continue
|
|
61
|
+
if path.suffix.lower() == ".py" and "scripts" not in path.relative_to(skill_root).parts:
|
|
62
|
+
continue
|
|
63
|
+
yield path
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _script_index(skill_root: Path) -> tuple[set[str], set[str]]:
|
|
67
|
+
script_names: set[str] = set()
|
|
68
|
+
relative_paths: set[str] = set()
|
|
69
|
+
for path in skill_root.rglob("*.py"):
|
|
70
|
+
script_names.add(path.name)
|
|
71
|
+
relative_paths.add(path.relative_to(skill_root).as_posix())
|
|
72
|
+
return script_names, relative_paths
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _scan_hardcoded_origins(path: Path, text: str) -> list[dict[str, Any]]:
|
|
76
|
+
findings: list[dict[str, Any]] = []
|
|
77
|
+
for line_no, line in enumerate(text.splitlines(), start=1):
|
|
78
|
+
if HARD_CODED_ORIGIN_PATTERN.search(line):
|
|
79
|
+
findings.append(
|
|
80
|
+
_finding(
|
|
81
|
+
"hardcoded_domain",
|
|
82
|
+
path,
|
|
83
|
+
line_no,
|
|
84
|
+
"Hardcoded BPMAX environment origin should be removed from skill-local docs or scripts.",
|
|
85
|
+
line.strip(),
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
return findings
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _scan_unimplemented_claims(path: Path, text: str, *, has_scripts: bool) -> list[dict[str, Any]]:
|
|
92
|
+
if not has_scripts or path.suffix.lower() != ".md":
|
|
93
|
+
return []
|
|
94
|
+
findings: list[dict[str, Any]] = []
|
|
95
|
+
for line_no, line in enumerate(text.splitlines(), start=1):
|
|
96
|
+
if any(pattern.search(line) for pattern in UNIMPLEMENTED_DOC_PATTERNS):
|
|
97
|
+
findings.append(
|
|
98
|
+
_finding(
|
|
99
|
+
"doc_claims_scripts_unimplemented",
|
|
100
|
+
path,
|
|
101
|
+
line_no,
|
|
102
|
+
"Documentation says scripts are not landed even though the skill already ships scripts.",
|
|
103
|
+
line.strip(),
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
return findings
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _scan_missing_script_references(
|
|
110
|
+
path: Path,
|
|
111
|
+
text: str,
|
|
112
|
+
*,
|
|
113
|
+
script_names: set[str],
|
|
114
|
+
relative_paths: set[str],
|
|
115
|
+
skill_root: Path,
|
|
116
|
+
) -> list[dict[str, Any]]:
|
|
117
|
+
if path.suffix.lower() != ".md":
|
|
118
|
+
return []
|
|
119
|
+
findings: list[dict[str, Any]] = []
|
|
120
|
+
for line_no, line in enumerate(text.splitlines(), start=1):
|
|
121
|
+
for ref in SCRIPT_REFERENCE_PATTERN.findall(line):
|
|
122
|
+
normalized = ref.lstrip("./")
|
|
123
|
+
candidates = {
|
|
124
|
+
normalized,
|
|
125
|
+
f"scripts/{Path(normalized).name}",
|
|
126
|
+
}
|
|
127
|
+
if any(candidate in relative_paths for candidate in candidates):
|
|
128
|
+
continue
|
|
129
|
+
if Path(normalized).name in script_names:
|
|
130
|
+
continue
|
|
131
|
+
if (skill_root / normalized).exists():
|
|
132
|
+
continue
|
|
133
|
+
findings.append(
|
|
134
|
+
_finding(
|
|
135
|
+
"doc_references_missing_script",
|
|
136
|
+
path,
|
|
137
|
+
line_no,
|
|
138
|
+
f"Documentation references missing script `{ref}`.",
|
|
139
|
+
line.strip(),
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
return findings
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _scan_missing_runtime_script_governance_reference(skill_root: Path, markdown_files: list[tuple[Path, str]]) -> list[dict[str, Any]]:
|
|
146
|
+
if not markdown_files:
|
|
147
|
+
return []
|
|
148
|
+
requires_governance = False
|
|
149
|
+
for _, text in markdown_files:
|
|
150
|
+
for line in text.splitlines():
|
|
151
|
+
if SCRIPT_GOVERNANCE_SITE_PATTERN.search(line) and SCRIPT_GOVERNANCE_CONTEXT_PATTERN.search(line):
|
|
152
|
+
requires_governance = True
|
|
153
|
+
break
|
|
154
|
+
if requires_governance:
|
|
155
|
+
break
|
|
156
|
+
if not requires_governance:
|
|
157
|
+
return []
|
|
158
|
+
has_reference = any(
|
|
159
|
+
any(pattern.search(text) for pattern in GOVERNANCE_REFERENCE_PATTERNS)
|
|
160
|
+
for _, text in markdown_files
|
|
161
|
+
)
|
|
162
|
+
if has_reference:
|
|
163
|
+
return []
|
|
164
|
+
target_path = next((path for path, _ in markdown_files if path.name == "SKILL.md"), markdown_files[0][0])
|
|
165
|
+
return [
|
|
166
|
+
_finding(
|
|
167
|
+
"missing_runtime_script_governance_reference",
|
|
168
|
+
target_path,
|
|
169
|
+
1,
|
|
170
|
+
"Runtime-script-heavy skills must reference the bpmax-builder-shared script site matrix or template catalog.",
|
|
171
|
+
"missing bpmax-builder-shared runtime script governance reference",
|
|
172
|
+
)
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _extract_markdown_code_fences(text: str) -> list[dict[str, Any]]:
|
|
177
|
+
fences: list[dict[str, Any]] = []
|
|
178
|
+
current_site: str | None = None
|
|
179
|
+
in_code = False
|
|
180
|
+
code_language = ""
|
|
181
|
+
code_start = 0
|
|
182
|
+
code_lines: list[str] = []
|
|
183
|
+
|
|
184
|
+
def flush_code() -> None:
|
|
185
|
+
nonlocal code_lines
|
|
186
|
+
fences.append(
|
|
187
|
+
{
|
|
188
|
+
"site": current_site,
|
|
189
|
+
"language": code_language,
|
|
190
|
+
"start_line": code_start,
|
|
191
|
+
"code": "\n".join(code_lines),
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
code_lines = []
|
|
195
|
+
|
|
196
|
+
for line_no, line in enumerate(text.splitlines(), start=1):
|
|
197
|
+
heading = SECTION_HEADING_PATTERN.match(line)
|
|
198
|
+
if not in_code and heading:
|
|
199
|
+
current_site = heading.group(1)
|
|
200
|
+
continue
|
|
201
|
+
|
|
202
|
+
if line.startswith("```"):
|
|
203
|
+
if not in_code:
|
|
204
|
+
in_code = True
|
|
205
|
+
code_language = line[3:].strip().lower()
|
|
206
|
+
code_start = line_no + 1
|
|
207
|
+
code_lines = []
|
|
208
|
+
else:
|
|
209
|
+
flush_code()
|
|
210
|
+
in_code = False
|
|
211
|
+
code_language = ""
|
|
212
|
+
continue
|
|
213
|
+
|
|
214
|
+
if in_code:
|
|
215
|
+
code_lines.append(line)
|
|
216
|
+
|
|
217
|
+
if in_code:
|
|
218
|
+
flush_code()
|
|
219
|
+
return fences
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _scan_forbidden_promise_then(path: Path, text: str) -> list[dict[str, Any]]:
|
|
223
|
+
findings: list[dict[str, Any]] = []
|
|
224
|
+
for fence in _extract_markdown_code_fences(text):
|
|
225
|
+
if fence["language"] not in ("js", "javascript"):
|
|
226
|
+
continue
|
|
227
|
+
code = str(fence["code"])
|
|
228
|
+
if "allow-then" in code:
|
|
229
|
+
continue
|
|
230
|
+
if FORBIDDEN_PROMISE_THEN_PATTERN.search(code):
|
|
231
|
+
findings.append(
|
|
232
|
+
_finding(
|
|
233
|
+
"forbidden_promise_then",
|
|
234
|
+
path,
|
|
235
|
+
int(fence["start_line"]),
|
|
236
|
+
"Runtime script examples should default to async/await, not Promise.then chains.",
|
|
237
|
+
code.strip(),
|
|
238
|
+
)
|
|
239
|
+
)
|
|
240
|
+
return findings
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _scan_runtime_script_code_fences(path: Path, text: str) -> list[dict[str, Any]]:
|
|
244
|
+
findings: list[dict[str, Any]] = []
|
|
245
|
+
for fence in _extract_markdown_code_fences(text):
|
|
246
|
+
site_name = fence["site"]
|
|
247
|
+
if site_name is None or site_name not in SCRIPT_SITE_MATRIX:
|
|
248
|
+
continue
|
|
249
|
+
if fence["language"] not in ("js", "javascript"):
|
|
250
|
+
continue
|
|
251
|
+
report = lint_runtime_script(str(site_name), str(fence["code"]))
|
|
252
|
+
for item in report["findings"]:
|
|
253
|
+
findings.append(
|
|
254
|
+
_finding(
|
|
255
|
+
item["code"],
|
|
256
|
+
path,
|
|
257
|
+
int(fence["start_line"]),
|
|
258
|
+
item["message"],
|
|
259
|
+
item["snippet"],
|
|
260
|
+
)
|
|
261
|
+
)
|
|
262
|
+
return findings
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def _scan_project_list_guidance(path: Path, text: str) -> list[dict[str, Any]]:
|
|
266
|
+
if path.suffix.lower() != ".md":
|
|
267
|
+
return []
|
|
268
|
+
findings: list[dict[str, Any]] = []
|
|
269
|
+
in_code = False
|
|
270
|
+
for line_no, line in enumerate(text.splitlines(), start=1):
|
|
271
|
+
if line.startswith("```"):
|
|
272
|
+
in_code = not in_code
|
|
273
|
+
continue
|
|
274
|
+
if in_code:
|
|
275
|
+
continue
|
|
276
|
+
if not contains_user_scope_project_list_query(line):
|
|
277
|
+
continue
|
|
278
|
+
if PROJECT_LIST_PROHIBITION_CONTEXT_PATTERN.search(line):
|
|
279
|
+
continue
|
|
280
|
+
if PROJECT_LIST_VERIFICATION_CONTEXT_PATTERN.search(line):
|
|
281
|
+
continue
|
|
282
|
+
if not PROJECT_LIST_GUIDANCE_CONTEXT_PATTERN.search(line):
|
|
283
|
+
continue
|
|
284
|
+
findings.append(
|
|
285
|
+
_finding(
|
|
286
|
+
"project_list_guidance_forbidden",
|
|
287
|
+
path,
|
|
288
|
+
line_no,
|
|
289
|
+
"Documentation must not recommend `/bpmax/project/list` or user-scope ESProjectList in runtime scripts.",
|
|
290
|
+
line.strip(),
|
|
291
|
+
)
|
|
292
|
+
)
|
|
293
|
+
return findings
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def _scan_project_list_code_fences(path: Path, text: str) -> list[dict[str, Any]]:
|
|
297
|
+
if path.suffix.lower() != ".md":
|
|
298
|
+
return []
|
|
299
|
+
findings: list[dict[str, Any]] = []
|
|
300
|
+
for fence in _extract_markdown_code_fences(text):
|
|
301
|
+
if fence["language"] not in ("js", "javascript"):
|
|
302
|
+
continue
|
|
303
|
+
code = str(fence["code"])
|
|
304
|
+
if not contains_user_scope_project_list_query(code):
|
|
305
|
+
continue
|
|
306
|
+
findings.append(
|
|
307
|
+
_finding(
|
|
308
|
+
"project_list_code_fence_forbidden",
|
|
309
|
+
path,
|
|
310
|
+
int(fence["start_line"]),
|
|
311
|
+
"Runtime script examples must not use `/bpmax/project/list` or user-scope ESProjectList.",
|
|
312
|
+
code.strip(),
|
|
313
|
+
)
|
|
314
|
+
)
|
|
315
|
+
return findings
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def audit_skill_root(skill_root: str | Path) -> dict[str, Any]:
|
|
319
|
+
root = Path(skill_root).resolve()
|
|
320
|
+
script_names, relative_paths = _script_index(root)
|
|
321
|
+
findings: list[dict[str, Any]] = []
|
|
322
|
+
markdown_files: list[tuple[Path, str]] = []
|
|
323
|
+
for path in _iter_text_files(root):
|
|
324
|
+
text = path.read_text(encoding="utf-8")
|
|
325
|
+
if path.suffix.lower() == ".md":
|
|
326
|
+
markdown_files.append((path, text))
|
|
327
|
+
findings.extend(_scan_hardcoded_origins(path, text))
|
|
328
|
+
findings.extend(_scan_unimplemented_claims(path, text, has_scripts=bool(script_names)))
|
|
329
|
+
findings.extend(
|
|
330
|
+
_scan_missing_script_references(
|
|
331
|
+
path,
|
|
332
|
+
text,
|
|
333
|
+
script_names=script_names,
|
|
334
|
+
relative_paths=relative_paths,
|
|
335
|
+
skill_root=root,
|
|
336
|
+
)
|
|
337
|
+
)
|
|
338
|
+
findings.extend(_scan_forbidden_promise_then(path, text))
|
|
339
|
+
findings.extend(_scan_project_list_guidance(path, text))
|
|
340
|
+
findings.extend(_scan_project_list_code_fences(path, text))
|
|
341
|
+
findings.extend(_scan_runtime_script_code_fences(path, text))
|
|
342
|
+
findings.extend(_scan_missing_runtime_script_governance_reference(root, markdown_files))
|
|
343
|
+
findings.sort(key=lambda item: (item["file"], item["line"], item["code"]))
|
|
344
|
+
return {
|
|
345
|
+
"ok": not findings,
|
|
346
|
+
"root": root.as_posix(),
|
|
347
|
+
"errors": [f"{item['file']}:{item['line']} {item['message']}" for item in findings],
|
|
348
|
+
"findings": findings,
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def audit_skill_roots(skill_roots: Iterable[str | Path]) -> dict[str, Any]:
|
|
353
|
+
reports = [audit_skill_root(root) for root in skill_roots]
|
|
354
|
+
findings = [finding for report in reports for finding in report["findings"]]
|
|
355
|
+
return {
|
|
356
|
+
"ok": not findings,
|
|
357
|
+
"roots": [report["root"] for report in reports],
|
|
358
|
+
"errors": [error for report in reports for error in report["errors"]],
|
|
359
|
+
"findings": findings,
|
|
360
|
+
"reports": reports,
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def main(argv: list[str] | None = None) -> int:
|
|
365
|
+
parser = argparse.ArgumentParser(description="Audit BPMAX skill docs and scripts for stale contracts.")
|
|
366
|
+
parser.add_argument("skill_roots", nargs="+", help="Skill root directories to audit.")
|
|
367
|
+
args = parser.parse_args(argv)
|
|
368
|
+
report = audit_skill_roots(args.skill_roots)
|
|
369
|
+
print(json.dumps(report, ensure_ascii=False, indent=2))
|
|
370
|
+
return 0 if report["ok"] else 1
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
if __name__ == "__main__":
|
|
374
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any, Dict, Iterable
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
BLOCK_MESSAGE = "ES dataset related query must not use data_set_id as the query entry"
|
|
10
|
+
PROJECT_LIST_BLOCK_MESSAGE = (
|
|
11
|
+
"Runtime scripts must not use `/bpmax/project/list` or user-scope "
|
|
12
|
+
"ESProjectList; use raw-es-search with data_set_key, backend ctx.$esQuery, "
|
|
13
|
+
"or another non-project-list helper. If the script intentionally needs the "
|
|
14
|
+
"current user's visible project list, add `bpmax-allow-user-scope-project-list: <reason>`"
|
|
15
|
+
)
|
|
16
|
+
PROJECT_LIST_COUNT_BLOCK_MESSAGE = (
|
|
17
|
+
"Runtime scripts must not use `/bpmax/project/list` count/total as an accurate total; "
|
|
18
|
+
"project/list can be capped at 10000. Use raw-es-search with track_total_hits=true"
|
|
19
|
+
)
|
|
20
|
+
QUERY_N_PLUS_ONE_BLOCK_MESSAGE = (
|
|
21
|
+
"Runtime scripts must not call raw-es-search/ctx.$esQuery/project-list inside per-row loops; "
|
|
22
|
+
"batch terms, aggregate, or precompute the lookup instead"
|
|
23
|
+
)
|
|
24
|
+
SERIAL_ORG_LOOKUP_BLOCK_MESSAGE = (
|
|
25
|
+
"Runtime scripts must not serially await /api/group, /api/form, or /api/project lookups inside loops; "
|
|
26
|
+
"batch/cache organization mappings or push stable identity keys into the fact source"
|
|
27
|
+
)
|
|
28
|
+
SQL_JOIN_BLOCK_MESSAGE = (
|
|
29
|
+
"Runtime scripts must not use complex SQL join queries for BPMAX dataset lookup; "
|
|
30
|
+
"query the needed ES dataset directly with raw-es-search + data_set_key or a verified backend helper"
|
|
31
|
+
)
|
|
32
|
+
BULK_ES_MATCH_BLOCK_MESSAGE = (
|
|
33
|
+
"Runtime scripts must not pull a large ES dataset and match rows in script; "
|
|
34
|
+
"push the match condition into raw-es-search/ctx.$esQuery and request only the needed rows"
|
|
35
|
+
)
|
|
36
|
+
FRONTEND_COUNTING_BLOCK_MESSAGE = (
|
|
37
|
+
"Runtime scripts must not pull inventory/statistical detail rows and count them in frontend loops; "
|
|
38
|
+
"use ES size:0 aggregations for inventory/counting reports"
|
|
39
|
+
)
|
|
40
|
+
WILDCARD_NON_EMPTY_BLOCK_MESSAGE = (
|
|
41
|
+
"Runtime scripts must not use wildcard '*' or '**' to test non-empty fields; "
|
|
42
|
+
"explicitly exclude empty strings or use a verified exists/term combination"
|
|
43
|
+
)
|
|
44
|
+
INVENTORY_AGG_BLOCK_MESSAGE = (
|
|
45
|
+
"dealer_inv_opt inventory reports must use raw-es-search size:0 aggregations; "
|
|
46
|
+
"do not fetch dealer_inv_opt detail rows for frontend inventory counting"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
SQL_JOIN_PATTERN = re.compile(r"\bselect\b[\s\S]{0,800}\bjoin\b", re.IGNORECASE)
|
|
50
|
+
ES_QUERY_PATTERN = re.compile(r"raw-es-search|ctx\.\$esQuery", re.IGNORECASE)
|
|
51
|
+
PROJECT_LIST_PATTERN = re.compile(r"/bpmax/project/list|ESProjectList|esProjectList")
|
|
52
|
+
USER_SCOPE_PROJECT_LIST_ALLOW_PATTERN = re.compile(r"bpmax-allow-user-scope-project-list\s*:")
|
|
53
|
+
ES_SIZE_PATTERN = re.compile(r"\bsize\s*:\s*(\d{3,})\b")
|
|
54
|
+
SCRIPT_MATCH_PATTERN = re.compile(r"\.(?:find|filter|some)\s*\(|\.includes\s*\(")
|
|
55
|
+
FRONTEND_COUNTING_PATTERN = re.compile(r"\b(?:inventoryQty|currentInventory|currentStock|total_count|count)\s*(?:\+\+|\+=\s*1)")
|
|
56
|
+
PROJECT_LIST_COUNT_PATTERN = re.compile(
|
|
57
|
+
r"/bpmax/project/list[\s\S]{0,800}\b(?:count|total)\b|\b(?:count|total)\b[\s\S]{0,800}/bpmax/project/list",
|
|
58
|
+
re.IGNORECASE,
|
|
59
|
+
)
|
|
60
|
+
LOOP_QUERY_PATTERN = re.compile(
|
|
61
|
+
r"\b(?:for\s*\(|for\s+await\s*\(|forEach\s*\(|map\s*\()[\s\S]{0,1600}"
|
|
62
|
+
r"(?:raw-es-search|ctx\.\$esQuery|/bpmax/project/list|ESProjectList|esProjectList)",
|
|
63
|
+
re.IGNORECASE,
|
|
64
|
+
)
|
|
65
|
+
SERIAL_ORG_LOOKUP_PATTERN = re.compile(
|
|
66
|
+
r"\b(?:for\s*\(|for\s+await\s*\(|forEach\s*\(|map\s*\()[\s\S]{0,1600}"
|
|
67
|
+
r"await[\s\S]{0,400}(?:/api/group|/api/form|/api/project)",
|
|
68
|
+
re.IGNORECASE,
|
|
69
|
+
)
|
|
70
|
+
WILDCARD_STAR_PATTERN = re.compile(
|
|
71
|
+
r"wildcard[\s\S]{0,160}value\s*:\s*['\"]\*{1,2}['\"](?!\s*\+)",
|
|
72
|
+
re.IGNORECASE,
|
|
73
|
+
)
|
|
74
|
+
DEALER_INV_OPT_PATTERN = re.compile(r"data_set_key\s*:\s*['\"]dealer_inv_opt['\"]|['\"]data_set_key['\"]\s*:\s*['\"]dealer_inv_opt['\"]")
|
|
75
|
+
SIZE_ZERO_PATTERN = re.compile(r"\bsize\s*:\s*0\b|['\"]size['\"]\s*:\s*0")
|
|
76
|
+
AGGS_PATTERN = re.compile(r"\baggs\s*:|['\"]aggs['\"]\s*:|\baggregations\b")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _compact(value: Any) -> str:
|
|
80
|
+
if isinstance(value, str):
|
|
81
|
+
return value
|
|
82
|
+
return json.dumps(value, ensure_ascii=False, sort_keys=True)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _walk(value: Any, *, prefix: str) -> Iterable[tuple[str, Any]]:
|
|
86
|
+
if isinstance(value, dict):
|
|
87
|
+
for key, child in value.items():
|
|
88
|
+
child_prefix = f"{prefix}.{key}" if prefix else str(key)
|
|
89
|
+
yield child_prefix, child
|
|
90
|
+
yield from _walk(child, prefix=child_prefix)
|
|
91
|
+
elif isinstance(value, list):
|
|
92
|
+
for idx, child in enumerate(value):
|
|
93
|
+
child_prefix = f"{prefix}[{idx}]"
|
|
94
|
+
yield child_prefix, child
|
|
95
|
+
yield from _walk(child, prefix=child_prefix)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def contains_user_scope_project_list_query(text: str) -> bool:
|
|
99
|
+
if USER_SCOPE_PROJECT_LIST_ALLOW_PATTERN.search(text):
|
|
100
|
+
return False
|
|
101
|
+
return bool(PROJECT_LIST_PATTERN.search(text))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def contains_root_user_project_list_helper(text: str) -> bool:
|
|
105
|
+
if "ESProjectList" not in text and "esProjectList" not in text:
|
|
106
|
+
return False
|
|
107
|
+
return any(token in text for token in ("rootUser", "root_user"))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def contains_large_es_pull_then_script_matching(text: str) -> bool:
|
|
111
|
+
if not ES_QUERY_PATTERN.search(text) or not SCRIPT_MATCH_PATTERN.search(text):
|
|
112
|
+
return False
|
|
113
|
+
return any(int(match.group(1)) >= 500 for match in ES_SIZE_PATTERN.finditer(text))
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def contains_frontend_detail_counting(text: str) -> bool:
|
|
117
|
+
if not FRONTEND_COUNTING_PATTERN.search(text):
|
|
118
|
+
return False
|
|
119
|
+
if DEALER_INV_OPT_PATTERN.search(text):
|
|
120
|
+
return True
|
|
121
|
+
return any(int(match.group(1)) >= 500 for match in ES_SIZE_PATTERN.finditer(text))
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def contains_dealer_inventory_detail_query(text: str) -> bool:
|
|
125
|
+
if not DEALER_INV_OPT_PATTERN.search(text):
|
|
126
|
+
return False
|
|
127
|
+
if not ("flow956693507" in text or "dealer_inv_opt" in text):
|
|
128
|
+
return False
|
|
129
|
+
return not (SIZE_ZERO_PATTERN.search(text) and AGGS_PATTERN.search(text))
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def contains_project_list_count_total(text: str) -> bool:
|
|
133
|
+
return bool(PROJECT_LIST_COUNT_PATTERN.search(text))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def contains_loop_query(text: str) -> bool:
|
|
137
|
+
return bool(LOOP_QUERY_PATTERN.search(text))
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def contains_serial_org_lookup(text: str) -> bool:
|
|
141
|
+
return bool(SERIAL_ORG_LOOKUP_PATTERN.search(text))
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _finding(path: str, rule: str, snippet: str, *, message: str = BLOCK_MESSAGE) -> Dict[str, str]:
|
|
145
|
+
return {
|
|
146
|
+
"path": path,
|
|
147
|
+
"rule": rule,
|
|
148
|
+
"message": message,
|
|
149
|
+
"snippet": snippet[:240],
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _scan_text(text: str, path: str) -> list[Dict[str, str]]:
|
|
154
|
+
findings: list[Dict[str, str]] = []
|
|
155
|
+
if contains_user_scope_project_list_query(text):
|
|
156
|
+
findings.append(
|
|
157
|
+
_finding(
|
|
158
|
+
path,
|
|
159
|
+
"project_list_forbidden",
|
|
160
|
+
text,
|
|
161
|
+
message=PROJECT_LIST_BLOCK_MESSAGE,
|
|
162
|
+
)
|
|
163
|
+
)
|
|
164
|
+
if contains_project_list_count_total(text):
|
|
165
|
+
findings.append(
|
|
166
|
+
_finding(
|
|
167
|
+
path,
|
|
168
|
+
"project_list_count_total_capped",
|
|
169
|
+
text,
|
|
170
|
+
message=PROJECT_LIST_COUNT_BLOCK_MESSAGE,
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
if contains_loop_query(text):
|
|
174
|
+
findings.append(
|
|
175
|
+
_finding(
|
|
176
|
+
path,
|
|
177
|
+
"query_inside_loop",
|
|
178
|
+
text,
|
|
179
|
+
message=QUERY_N_PLUS_ONE_BLOCK_MESSAGE,
|
|
180
|
+
)
|
|
181
|
+
)
|
|
182
|
+
if contains_serial_org_lookup(text):
|
|
183
|
+
findings.append(
|
|
184
|
+
_finding(
|
|
185
|
+
path,
|
|
186
|
+
"serial_org_lookup_inside_loop",
|
|
187
|
+
text,
|
|
188
|
+
message=SERIAL_ORG_LOOKUP_BLOCK_MESSAGE,
|
|
189
|
+
)
|
|
190
|
+
)
|
|
191
|
+
if SQL_JOIN_PATTERN.search(text):
|
|
192
|
+
findings.append(
|
|
193
|
+
_finding(
|
|
194
|
+
path,
|
|
195
|
+
"sql_join_forbidden",
|
|
196
|
+
text,
|
|
197
|
+
message=SQL_JOIN_BLOCK_MESSAGE,
|
|
198
|
+
)
|
|
199
|
+
)
|
|
200
|
+
if contains_large_es_pull_then_script_matching(text):
|
|
201
|
+
findings.append(
|
|
202
|
+
_finding(
|
|
203
|
+
path,
|
|
204
|
+
"bulk_es_script_matching",
|
|
205
|
+
text,
|
|
206
|
+
message=BULK_ES_MATCH_BLOCK_MESSAGE,
|
|
207
|
+
)
|
|
208
|
+
)
|
|
209
|
+
if contains_frontend_detail_counting(text):
|
|
210
|
+
findings.append(
|
|
211
|
+
_finding(
|
|
212
|
+
path,
|
|
213
|
+
"frontend_detail_counting",
|
|
214
|
+
text,
|
|
215
|
+
message=FRONTEND_COUNTING_BLOCK_MESSAGE,
|
|
216
|
+
)
|
|
217
|
+
)
|
|
218
|
+
if WILDCARD_STAR_PATTERN.search(text):
|
|
219
|
+
findings.append(
|
|
220
|
+
_finding(
|
|
221
|
+
path,
|
|
222
|
+
"wildcard_star_non_empty",
|
|
223
|
+
text,
|
|
224
|
+
message=WILDCARD_NON_EMPTY_BLOCK_MESSAGE,
|
|
225
|
+
)
|
|
226
|
+
)
|
|
227
|
+
if contains_dealer_inventory_detail_query(text):
|
|
228
|
+
findings.append(
|
|
229
|
+
_finding(
|
|
230
|
+
path,
|
|
231
|
+
"dealer_inv_opt_without_aggregation",
|
|
232
|
+
text,
|
|
233
|
+
message=INVENTORY_AGG_BLOCK_MESSAGE,
|
|
234
|
+
)
|
|
235
|
+
)
|
|
236
|
+
if "data_set_id" not in text:
|
|
237
|
+
return findings
|
|
238
|
+
if "/bpmax/project/list" in text:
|
|
239
|
+
findings.append(_finding(path, "project_list_data_set_id", text))
|
|
240
|
+
elif "/bpmax/project/raw-es-search" in text or "raw-es-search" in text:
|
|
241
|
+
findings.append(_finding(path, "raw_es_search_data_set_id", text))
|
|
242
|
+
elif "ctx.$esQuery" in text:
|
|
243
|
+
findings.append(_finding(path, "es_query_data_set_id", text))
|
|
244
|
+
elif "ESProjectList" in text or "esProjectList" in text:
|
|
245
|
+
findings.append(_finding(path, "es_project_list_data_set_id", text))
|
|
246
|
+
elif any(token in path for token in ("content.beforeSearch", "content.customQuery", "content.tabFilters", "content.config")):
|
|
247
|
+
findings.append(_finding(path, "structured_query_data_set_id", text))
|
|
248
|
+
return findings
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def scan_named_script_surfaces(surfaces: Iterable[Dict[str, Any]]) -> Dict[str, Any]:
|
|
252
|
+
findings: list[Dict[str, str]] = []
|
|
253
|
+
for surface in surfaces:
|
|
254
|
+
path = str(surface.get("path") or "").strip()
|
|
255
|
+
if not path:
|
|
256
|
+
continue
|
|
257
|
+
script = surface.get("script")
|
|
258
|
+
if isinstance(script, str):
|
|
259
|
+
findings.extend(_scan_text(script, path))
|
|
260
|
+
if "value" not in surface:
|
|
261
|
+
continue
|
|
262
|
+
for child_path, child in _walk(surface.get("value"), prefix=path):
|
|
263
|
+
if isinstance(child, str):
|
|
264
|
+
findings.extend(_scan_text(child, child_path))
|
|
265
|
+
elif isinstance(child, dict) and "data_set_id" in child:
|
|
266
|
+
findings.append(_finding(child_path, "structured_query_data_set_id", _compact(child)))
|
|
267
|
+
|
|
268
|
+
deduped: list[Dict[str, str]] = []
|
|
269
|
+
seen: set[tuple[str, str, str]] = set()
|
|
270
|
+
for finding in findings:
|
|
271
|
+
key = (finding["path"], finding["rule"], finding["snippet"])
|
|
272
|
+
if key in seen:
|
|
273
|
+
continue
|
|
274
|
+
seen.add(key)
|
|
275
|
+
deduped.append(finding)
|
|
276
|
+
return {
|
|
277
|
+
"ok": not deduped,
|
|
278
|
+
"errors": [f"{item['path']}: {item['message']}" for item in deduped],
|
|
279
|
+
"findings": deduped,
|
|
280
|
+
}
|