bpmax-cli 0.1.44 → 0.2.1-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 +52 -5
- package/dist/bin.js +11966 -1320
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/scripts/install-skills.mjs +98 -0
- package/skills/bpmax-ai-taskbook/SKILL.md +226 -0
- package/skills/bpmax-ai-taskbook/agents/openai.yaml +3 -0
- package/skills/bpmax-ai-taskbook/references/taskbook-template.md +68 -0
- 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-approval-matrix/SKILL.md +87 -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 +5 -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 +603 -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 +203 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/agents/openai.yaml +4 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/references/orchestration-matrix.md +63 -0
- package/skills/bpmax-e2e-flow-test-operator/SKILL.md +551 -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/ai-test-suite.md +333 -0
- package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +41 -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 +24 -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 +109 -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 +83 -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 +121 -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 +1086 -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 +174 -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 +168 -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 +106 -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 +96 -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 +1113 -0
- package/skills/bpmax-form-template-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-form-template-editor/references/form-template-api-workflow.md +203 -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 +91 -0
- package/skills/bpmax-form-template-editor/scripts/form_template_editor_common.py +1762 -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 +1292 -0
- package/skills/bpmax-list-template-editor/SKILL.md +478 -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 +165 -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 +108 -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 +147 -0
- package/skills/bpmax-list-template-editor/references/special-formats.md +411 -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-memory-protocol/SKILL.md +72 -0
- package/skills/bpmax-nav-config-editor/SKILL.md +350 -0
- package/skills/bpmax-nav-config-editor/agents/openai.yaml +4 -0
- package/skills/bpmax-nav-config-editor/references/api-workflow.md +70 -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 +51 -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-plugin-config/SKILL.md +42 -0
- package/skills/bpmax-project/SKILL.md +17 -3
- package/skills/bpmax-project-detail-template-editor/SKILL.md +355 -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 +120 -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/bpmax-user-mock-operator/SKILL.md +106 -0
- package/skills/bpmax-user-mock-operator/agents/openai.yaml +4 -0
- package/skills/bpmax-user-mock-operator/scripts/switch_user_identity.py +37 -0
- package/skills/bpmax-user-mock-operator/scripts/user_mock_operator_common.py +136 -0
- package/skills/bpmax-user-mock-operator/tests/test_user_mock_operator.py +138 -0
- package/skills/bpmax-workspace-editor/SKILL.md +78 -0
- package/skills/bpmax-workspace-editor/agents/openai.yaml +4 -0
- 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
package/skills/bpmax-project-detail-template-editor/scripts/project_detail_template_editor_common.py
ADDED
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import copy
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import ssl
|
|
8
|
+
import sys
|
|
9
|
+
import urllib.error
|
|
10
|
+
import urllib.parse
|
|
11
|
+
import urllib.request
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from datetime import datetime, timezone
|
|
14
|
+
from difflib import unified_diff
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any, Dict, Iterable, Optional
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
DEFAULT_LANGUAGE = "zhCN"
|
|
20
|
+
REPO_ROOT = Path(__file__).resolve().parents[4]
|
|
21
|
+
SHARED_SKILL_ROOT = Path(__file__).resolve().parents[2] / "bpmax-builder-shared"
|
|
22
|
+
if str(SHARED_SKILL_ROOT) not in sys.path:
|
|
23
|
+
sys.path.insert(0, str(SHARED_SKILL_ROOT))
|
|
24
|
+
|
|
25
|
+
from base_url import resolve_base_url
|
|
26
|
+
from template_script_hard_rules import scan_named_script_surfaces
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
TMP_ROOT = REPO_ROOT / ".codex" / "tmp" / "project-detail-template-editor"
|
|
30
|
+
TMP_SUBDIRS = ("raw", "work", "meta", "submit", "diffs", "result")
|
|
31
|
+
|
|
32
|
+
MODULE_ALLOW_IN = {
|
|
33
|
+
"project-info": {"main_col", "side_col"},
|
|
34
|
+
"meta-form": {"main_col"},
|
|
35
|
+
"step-form": {"main_col"},
|
|
36
|
+
"step-form-any": {"main_col"},
|
|
37
|
+
"comment-list": {"main_col", "side_col"},
|
|
38
|
+
"project-list": {"main_col", "side_col"},
|
|
39
|
+
"step-log": {"side_col"},
|
|
40
|
+
"attachment-list": {"side_col"},
|
|
41
|
+
"circulate": {"side_col"},
|
|
42
|
+
"finance": {"main_col"},
|
|
43
|
+
"customer-binding": {"main_col"},
|
|
44
|
+
"step-arrange": {"main_col"},
|
|
45
|
+
"periods": {"main_col"},
|
|
46
|
+
"auto-replay-info": {"main_col"},
|
|
47
|
+
"delay-reason": {"main_col"},
|
|
48
|
+
"generate-report": {"main_col"},
|
|
49
|
+
"project-detail-panel": {"main_col"},
|
|
50
|
+
"project-meta-info": {"main_col", "side_col"},
|
|
51
|
+
"project-reopen": {"main_col"},
|
|
52
|
+
"custom-form-list": {"side_col"},
|
|
53
|
+
}
|
|
54
|
+
KNOWN_MODULE_TYPES = set(MODULE_ALLOW_IN)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def utc_now_iso() -> str:
|
|
58
|
+
return datetime.now(timezone.utc).isoformat()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def ensure_tmp_dirs() -> None:
|
|
62
|
+
for part in TMP_SUBDIRS:
|
|
63
|
+
(TMP_ROOT / part).mkdir(parents=True, exist_ok=True)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def paths_for(stem: str) -> Dict[str, Path]:
|
|
67
|
+
ensure_tmp_dirs()
|
|
68
|
+
return {
|
|
69
|
+
"raw": TMP_ROOT / "raw" / f"{stem}.json",
|
|
70
|
+
"work": TMP_ROOT / "work" / f"{stem}.json",
|
|
71
|
+
"meta": TMP_ROOT / "meta" / f"{stem}.json",
|
|
72
|
+
"submit": TMP_ROOT / "submit" / f"{stem}.json",
|
|
73
|
+
"work_diff": TMP_ROOT / "diffs" / f"{stem}.work.diff.txt",
|
|
74
|
+
"submit_diff": TMP_ROOT / "diffs" / f"{stem}.submit.diff.txt",
|
|
75
|
+
"response": TMP_ROOT / "result" / f"{stem}.response.json",
|
|
76
|
+
"readback": TMP_ROOT / "result" / f"{stem}.readback.json",
|
|
77
|
+
"verify": TMP_ROOT / "result" / f"{stem}.verify.json",
|
|
78
|
+
"semantic_lint": TMP_ROOT / "result" / f"{stem}.semantic-lint.json",
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def dump_json(path: Path, payload: Any) -> None:
|
|
83
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
84
|
+
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def load_json(path: Path) -> Any:
|
|
88
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def file_sha256(path: Path) -> str:
|
|
92
|
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def stable_json_lines(payload: Any) -> list[str]:
|
|
96
|
+
return (json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True) + "\n").splitlines(keepends=True)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def write_diff(path: Path, before: Any, after: Any, before_label: str, after_label: str) -> None:
|
|
100
|
+
diff = unified_diff(stable_json_lines(before), stable_json_lines(after), fromfile=before_label, tofile=after_label)
|
|
101
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
102
|
+
path.write_text("".join(diff) or "# no diff\n", encoding="utf-8")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def parse_content(value: Any) -> Dict[str, Any]:
|
|
106
|
+
if isinstance(value, dict):
|
|
107
|
+
payload = copy.deepcopy(value)
|
|
108
|
+
elif isinstance(value, str):
|
|
109
|
+
text = value.strip()
|
|
110
|
+
payload = json.loads(text) if text else {}
|
|
111
|
+
elif value in (None, ""):
|
|
112
|
+
payload = {}
|
|
113
|
+
else:
|
|
114
|
+
raise SystemExit("project detail template content must be a JSON string or object")
|
|
115
|
+
if not isinstance(payload, dict):
|
|
116
|
+
raise SystemExit("project detail template content must be an object")
|
|
117
|
+
payload.setdefault("config", {})
|
|
118
|
+
payload.setdefault("main_col", [])
|
|
119
|
+
payload.setdefault("side_col", [])
|
|
120
|
+
if not isinstance(payload["config"], dict):
|
|
121
|
+
raise SystemExit("content.config must be an object")
|
|
122
|
+
if not isinstance(payload["main_col"], list):
|
|
123
|
+
raise SystemExit("content.main_col must be an array")
|
|
124
|
+
if not isinstance(payload["side_col"], list):
|
|
125
|
+
raise SystemExit("content.side_col must be an array")
|
|
126
|
+
return payload
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def serialize_content(content: Dict[str, Any]) -> str:
|
|
130
|
+
return json.dumps(parse_content(content), ensure_ascii=False, separators=(",", ":"))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def create_stem(flow_type: str, flow_key: str, sample_template_id: int) -> str:
|
|
134
|
+
return f"create-{flow_type}-{flow_key or 'default'}-{sample_template_id}"
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def build_create_raw_payload(detail: Dict[str, Any], *, sample_template_id: int) -> Dict[str, Any]:
|
|
138
|
+
content = parse_content(detail.get("content"))
|
|
139
|
+
return {
|
|
140
|
+
"id": None,
|
|
141
|
+
"name": detail.get("name", ""),
|
|
142
|
+
"desc": detail.get("desc", ""),
|
|
143
|
+
"type": 2,
|
|
144
|
+
"flow_type": detail.get("flow_type", ""),
|
|
145
|
+
"flow_key": detail.get("flow_key", ""),
|
|
146
|
+
"status": 1,
|
|
147
|
+
"content": content,
|
|
148
|
+
"sampleTemplateId": sample_template_id,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def detail_to_work_payload(detail: Dict[str, Any], *, mode: str, sample_template_id: int | None = None) -> Dict[str, Any]:
|
|
153
|
+
if mode not in ("edit", "create"):
|
|
154
|
+
raise SystemExit(f"unsupported mode: {mode}")
|
|
155
|
+
return {
|
|
156
|
+
"id": detail.get("id") if mode == "edit" else None,
|
|
157
|
+
"mode": mode,
|
|
158
|
+
"basic": {
|
|
159
|
+
"name": detail.get("name", ""),
|
|
160
|
+
"desc": detail.get("desc", ""),
|
|
161
|
+
"type": 2,
|
|
162
|
+
"flow_type": detail.get("flow_type", ""),
|
|
163
|
+
"flow_key": detail.get("flow_key", ""),
|
|
164
|
+
"status": detail.get("status", 1),
|
|
165
|
+
},
|
|
166
|
+
"content": parse_content(detail.get("content")),
|
|
167
|
+
"meta": {
|
|
168
|
+
"templateUuid": detail.get("uuid"),
|
|
169
|
+
"sourceTemplateId": detail.get("id"),
|
|
170
|
+
"sampleTemplateId": sample_template_id,
|
|
171
|
+
"moduleSources": [
|
|
172
|
+
"browser/api",
|
|
173
|
+
"ProjectDetailConfig/utils/moduleRegistry.js",
|
|
174
|
+
"components/DetailSections/README.md",
|
|
175
|
+
"doc.bpmax.cn/script/ui/project-detail.html",
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def build_submit_payload(work: Dict[str, Any]) -> Dict[str, Any]:
|
|
182
|
+
basic = copy.deepcopy(work.get("basic") or {})
|
|
183
|
+
content = parse_content(work.get("content"))
|
|
184
|
+
submit = {
|
|
185
|
+
"name": basic.get("name", ""),
|
|
186
|
+
"desc": basic.get("desc", ""),
|
|
187
|
+
"type": 2,
|
|
188
|
+
"flow_type": basic.get("flow_type", ""),
|
|
189
|
+
"flow_key": basic.get("flow_key", ""),
|
|
190
|
+
"content": serialize_content(content),
|
|
191
|
+
}
|
|
192
|
+
if work.get("mode") == "create":
|
|
193
|
+
submit["status"] = basic.get("status", 1)
|
|
194
|
+
return submit
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _scan_modules(modules: list[Any], *, area: str, report: Dict[str, Any]) -> None:
|
|
198
|
+
for idx, module in enumerate(modules):
|
|
199
|
+
path = f"content.{area}[{idx}]"
|
|
200
|
+
if not isinstance(module, dict):
|
|
201
|
+
report["errors"].append(f"{path} must be an object")
|
|
202
|
+
continue
|
|
203
|
+
module_type = module.get("type")
|
|
204
|
+
title = module.get("title")
|
|
205
|
+
config = module.get("config")
|
|
206
|
+
if not isinstance(module_type, str) or not module_type.strip():
|
|
207
|
+
report["errors"].append(f"{path}.type must be a non-empty string")
|
|
208
|
+
continue
|
|
209
|
+
if not isinstance(title, str) or not title.strip():
|
|
210
|
+
report["errors"].append(f"{path}.title must be a non-empty string")
|
|
211
|
+
if not isinstance(config, dict):
|
|
212
|
+
report["errors"].append(f"{path}.config must be an object")
|
|
213
|
+
config = {}
|
|
214
|
+
|
|
215
|
+
allowed_areas = MODULE_ALLOW_IN.get(module_type)
|
|
216
|
+
if allowed_areas is None:
|
|
217
|
+
report["warnings"].append(
|
|
218
|
+
f"{path}.type={module_type!r} is not in the known registry union; allow as advanced JSON mode candidate only"
|
|
219
|
+
)
|
|
220
|
+
elif area not in allowed_areas:
|
|
221
|
+
report["errors"].append(f"{path}.type={module_type!r} is not allowed in {area}")
|
|
222
|
+
|
|
223
|
+
if module_type == "step-form":
|
|
224
|
+
step_id = config.get("flow_step_id")
|
|
225
|
+
if step_id in (None, "", 0, "0"):
|
|
226
|
+
report["errors"].append(f"{path}.config.flow_step_id is required for step-form")
|
|
227
|
+
if module_type == "project-list":
|
|
228
|
+
if not config.get("isSubProcess") and not (config.get("flow_type") or config.get("flow_key")):
|
|
229
|
+
report["warnings"].append(
|
|
230
|
+
f"{path}.config should usually include flow_type/flow_key unless it is an isSubProcess sidebar module"
|
|
231
|
+
)
|
|
232
|
+
if area == "main_col" and config.get("isSubProcess") is True:
|
|
233
|
+
report["errors"].append(f"{path}.config.isSubProcess=true is only valid in side_col")
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def lint_project_detail_template_semantics(
|
|
237
|
+
work_payload: Dict[str, Any], *, submit_payload: Optional[Dict[str, Any]] = None
|
|
238
|
+
) -> Dict[str, Any]:
|
|
239
|
+
payload = submit_payload or build_submit_payload(work_payload)
|
|
240
|
+
content = parse_content(payload.get("content"))
|
|
241
|
+
report: Dict[str, Any] = {
|
|
242
|
+
"ok": True,
|
|
243
|
+
"errors": [],
|
|
244
|
+
"warnings": [],
|
|
245
|
+
"checks": {
|
|
246
|
+
"knownModuleTypes": sorted(KNOWN_MODULE_TYPES),
|
|
247
|
+
"mainModuleCount": len(content["main_col"]),
|
|
248
|
+
"sideModuleCount": len(content["side_col"]),
|
|
249
|
+
},
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if payload.get("type") != 2:
|
|
253
|
+
report["errors"].append("submit.type must be 2")
|
|
254
|
+
|
|
255
|
+
_scan_modules(content["main_col"], area="main_col", report=report)
|
|
256
|
+
_scan_modules(content["side_col"], area="side_col", report=report)
|
|
257
|
+
|
|
258
|
+
try:
|
|
259
|
+
json.dumps(content, ensure_ascii=False)
|
|
260
|
+
except TypeError as exc:
|
|
261
|
+
report["errors"].append(f"content is not JSON-serializable: {exc}")
|
|
262
|
+
|
|
263
|
+
hard_rule_report = scan_named_script_surfaces(
|
|
264
|
+
[
|
|
265
|
+
{"path": "content.config", "value": content.get("config")},
|
|
266
|
+
{"path": "content.main_col", "value": content.get("main_col")},
|
|
267
|
+
{"path": "content.side_col", "value": content.get("side_col")},
|
|
268
|
+
]
|
|
269
|
+
)
|
|
270
|
+
report["checks"]["scriptHardRules"] = hard_rule_report["findings"]
|
|
271
|
+
report["errors"].extend(hard_rule_report["errors"])
|
|
272
|
+
report["ok"] = not report["errors"]
|
|
273
|
+
return report
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def ensure_meta_shape(meta: Dict[str, Any], stem: str) -> Dict[str, Any]:
|
|
277
|
+
payload = dict(meta)
|
|
278
|
+
payload.setdefault("stem", stem)
|
|
279
|
+
payload.setdefault("mode", None)
|
|
280
|
+
payload.setdefault("workspace", None)
|
|
281
|
+
payload.setdefault("status", "exported")
|
|
282
|
+
payload.setdefault("templateId", None)
|
|
283
|
+
payload.setdefault("templateUuid", None)
|
|
284
|
+
payload.setdefault("sampleTemplateId", None)
|
|
285
|
+
payload.setdefault("workSha256", None)
|
|
286
|
+
payload.setdefault("submitSha256", None)
|
|
287
|
+
payload.setdefault("workConfirmedAt", None)
|
|
288
|
+
payload.setdefault("submitConfirmedAt", None)
|
|
289
|
+
payload.setdefault("submitBuiltAt", None)
|
|
290
|
+
payload.setdefault("lintPassed", False)
|
|
291
|
+
payload.setdefault("lintedAt", None)
|
|
292
|
+
payload.setdefault("lintSha256", None)
|
|
293
|
+
return payload
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def write_export_meta(
|
|
297
|
+
meta_path: Path,
|
|
298
|
+
*,
|
|
299
|
+
stem: str,
|
|
300
|
+
mode: str,
|
|
301
|
+
template_id: int | None,
|
|
302
|
+
template_uuid: str | None,
|
|
303
|
+
sample_template_id: int | None,
|
|
304
|
+
workspace: str,
|
|
305
|
+
language: str,
|
|
306
|
+
request_url: str,
|
|
307
|
+
raw_path: Path,
|
|
308
|
+
work_path: Path,
|
|
309
|
+
) -> Dict[str, Any]:
|
|
310
|
+
payload = ensure_meta_shape({}, stem)
|
|
311
|
+
payload.update(
|
|
312
|
+
{
|
|
313
|
+
"mode": mode,
|
|
314
|
+
"templateId": template_id,
|
|
315
|
+
"templateUuid": template_uuid,
|
|
316
|
+
"sampleTemplateId": sample_template_id,
|
|
317
|
+
"workspace": workspace,
|
|
318
|
+
"language": language,
|
|
319
|
+
"requestUrl": request_url,
|
|
320
|
+
"rawSha256": file_sha256(raw_path),
|
|
321
|
+
"workSha256": file_sha256(work_path),
|
|
322
|
+
"status": "exported",
|
|
323
|
+
"exportedAt": utc_now_iso(),
|
|
324
|
+
}
|
|
325
|
+
)
|
|
326
|
+
dump_json(meta_path, payload)
|
|
327
|
+
return payload
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def update_build_meta(meta_path: Path, *, stem: str, work_path: Path, submit_path: Path) -> Dict[str, Any]:
|
|
331
|
+
payload = ensure_meta_shape(load_json(meta_path) if meta_path.exists() else {}, stem)
|
|
332
|
+
payload["workSha256"] = file_sha256(work_path)
|
|
333
|
+
payload["submitSha256"] = file_sha256(submit_path)
|
|
334
|
+
payload["submitBuiltAt"] = utc_now_iso()
|
|
335
|
+
payload["lintPassed"] = False
|
|
336
|
+
payload["lintedAt"] = None
|
|
337
|
+
payload["lintSha256"] = None
|
|
338
|
+
payload["submitConfirmedAt"] = None
|
|
339
|
+
payload["status"] = "submit_built"
|
|
340
|
+
dump_json(meta_path, payload)
|
|
341
|
+
return payload
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def update_confirmation_state(meta_path: Path, *, stem: str, actor: str, stage: str, work_path: Path, submit_path: Path) -> Dict[str, Any]:
|
|
345
|
+
payload = ensure_meta_shape(load_json(meta_path) if meta_path.exists() else {}, stem)
|
|
346
|
+
payload["actor"] = actor
|
|
347
|
+
payload["workSha256"] = file_sha256(work_path)
|
|
348
|
+
now = utc_now_iso()
|
|
349
|
+
if stage == "work":
|
|
350
|
+
payload["workConfirmedAt"] = now
|
|
351
|
+
payload["submitConfirmedAt"] = None
|
|
352
|
+
payload["status"] = "work_confirmed"
|
|
353
|
+
elif stage == "submit":
|
|
354
|
+
if not submit_path.exists():
|
|
355
|
+
raise SystemExit("submit confirmation requires an existing submit file")
|
|
356
|
+
payload["submitSha256"] = file_sha256(submit_path)
|
|
357
|
+
payload["submitConfirmedAt"] = now
|
|
358
|
+
payload["status"] = "submit_confirmed"
|
|
359
|
+
else:
|
|
360
|
+
raise SystemExit(f"unsupported confirmation stage: {stage}")
|
|
361
|
+
dump_json(meta_path, payload)
|
|
362
|
+
return payload
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def update_lint_meta(meta_path: Path, *, stem: str, submit_path: Path, lint_path: Path, report: Dict[str, Any]) -> Dict[str, Any]:
|
|
366
|
+
payload = ensure_meta_shape(load_json(meta_path) if meta_path.exists() else {}, stem)
|
|
367
|
+
payload["submitSha256"] = file_sha256(submit_path)
|
|
368
|
+
payload["lintPassed"] = bool(report.get("ok"))
|
|
369
|
+
payload["lintSha256"] = file_sha256(lint_path)
|
|
370
|
+
payload["lintedAt"] = utc_now_iso()
|
|
371
|
+
payload["status"] = "lint_passed" if report.get("ok") else "lint_failed"
|
|
372
|
+
dump_json(meta_path, payload)
|
|
373
|
+
return payload
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def persist_create_submission_meta(
|
|
377
|
+
meta_path: Path,
|
|
378
|
+
*,
|
|
379
|
+
stem: str,
|
|
380
|
+
action_mode: str,
|
|
381
|
+
template_id: int,
|
|
382
|
+
readback: Dict[str, Any],
|
|
383
|
+
) -> Dict[str, Any]:
|
|
384
|
+
payload = ensure_meta_shape(load_json(meta_path) if meta_path.exists() else {}, stem)
|
|
385
|
+
if action_mode != "create":
|
|
386
|
+
raise SystemExit("persist_create_submission_meta requires action_mode=create")
|
|
387
|
+
payload["mode"] = "edit"
|
|
388
|
+
payload["templateId"] = template_id
|
|
389
|
+
if readback.get("uuid"):
|
|
390
|
+
payload["templateUuid"] = readback["uuid"]
|
|
391
|
+
payload["status"] = payload.get("status") or "submit_confirmed"
|
|
392
|
+
dump_json(meta_path, payload)
|
|
393
|
+
return payload
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
def ensure_submission_allowed(meta_path: Path, work_path: Path, submit_path: Path) -> Dict[str, Any]:
|
|
397
|
+
if not meta_path.exists():
|
|
398
|
+
raise SystemExit("missing meta confirmation file")
|
|
399
|
+
meta_raw = load_json(meta_path)
|
|
400
|
+
meta = ensure_meta_shape(meta_raw, meta_raw.get("stem", "unknown"))
|
|
401
|
+
if meta.get("status") != "submit_confirmed":
|
|
402
|
+
raise SystemExit("submission blocked: current status is not submit_confirmed")
|
|
403
|
+
if meta.get("lintPassed") is not True:
|
|
404
|
+
raise SystemExit("submission blocked: lint has not passed")
|
|
405
|
+
if meta.get("workSha256") != file_sha256(work_path):
|
|
406
|
+
raise SystemExit("submission blocked: work file changed after confirmation")
|
|
407
|
+
if meta.get("submitSha256") != file_sha256(submit_path):
|
|
408
|
+
raise SystemExit("submission blocked: submit file changed after confirmation")
|
|
409
|
+
return meta
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def summarize_verification(submit_payload: Dict[str, Any], readback: Dict[str, Any]) -> Dict[str, Any]:
|
|
413
|
+
submitted_content = parse_content(submit_payload.get("content"))
|
|
414
|
+
readback_content = parse_content(readback.get("content"))
|
|
415
|
+
mismatches = []
|
|
416
|
+
for key in ("name", "desc", "type", "flow_type", "flow_key"):
|
|
417
|
+
if submit_payload.get(key) != readback.get(key):
|
|
418
|
+
mismatches.append({"field": key, "expected": submit_payload.get(key), "actual": readback.get(key)})
|
|
419
|
+
if submitted_content != readback_content:
|
|
420
|
+
mismatches.append({"field": "content", "expected": submitted_content, "actual": readback_content})
|
|
421
|
+
return {
|
|
422
|
+
"ok": not mismatches,
|
|
423
|
+
"submittedContent": submitted_content,
|
|
424
|
+
"readbackContent": readback_content,
|
|
425
|
+
"mismatches": mismatches,
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
def extract_template_id(response_payload: Dict[str, Any]) -> int | None:
|
|
430
|
+
data = response_payload.get("data")
|
|
431
|
+
if isinstance(data, dict) and isinstance(data.get("id"), int):
|
|
432
|
+
return data["id"]
|
|
433
|
+
if isinstance(response_payload.get("id"), int):
|
|
434
|
+
return response_payload["id"]
|
|
435
|
+
return None
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
@dataclass
|
|
439
|
+
class ApiClient:
|
|
440
|
+
base_url: str
|
|
441
|
+
workspace: str
|
|
442
|
+
language: str
|
|
443
|
+
cookie_header: str
|
|
444
|
+
timeout: float
|
|
445
|
+
insecure: bool = False
|
|
446
|
+
|
|
447
|
+
def _build_url(self, path: str) -> str:
|
|
448
|
+
query = urllib.parse.urlencode({"$workspace": self.workspace, "$language": self.language})
|
|
449
|
+
return f"{self.base_url}{path}{'&' if '?' in path else '?'}{query}"
|
|
450
|
+
|
|
451
|
+
def _request(self, method: str, path: str, payload: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
452
|
+
data = None
|
|
453
|
+
headers = {
|
|
454
|
+
"Accept": "application/json, text/plain, */*",
|
|
455
|
+
"Content-Type": "application/json",
|
|
456
|
+
}
|
|
457
|
+
if self.cookie_header:
|
|
458
|
+
headers["Cookie"] = self.cookie_header
|
|
459
|
+
if payload is not None:
|
|
460
|
+
data = json.dumps(payload, ensure_ascii=False).encode("utf-8")
|
|
461
|
+
req = urllib.request.Request(self._build_url(path), data=data, headers=headers, method=method.upper())
|
|
462
|
+
context = None
|
|
463
|
+
if self.insecure:
|
|
464
|
+
context = ssl._create_unverified_context()
|
|
465
|
+
try:
|
|
466
|
+
with urllib.request.urlopen(req, timeout=self.timeout, context=context) as resp:
|
|
467
|
+
raw = resp.read().decode("utf-8")
|
|
468
|
+
except urllib.error.HTTPError as exc:
|
|
469
|
+
body = exc.read().decode("utf-8", errors="replace")
|
|
470
|
+
raise SystemExit(f"HTTP {exc.code} for {path}: {body}") from exc
|
|
471
|
+
payload = json.loads(raw)
|
|
472
|
+
if payload.get("code") not in (0, None):
|
|
473
|
+
raise SystemExit(f"API returned error for {path}: {payload}")
|
|
474
|
+
return payload
|
|
475
|
+
|
|
476
|
+
def get_flow_page_template(self, template_id: int) -> Dict[str, Any]:
|
|
477
|
+
return self._request("GET", f"/api/flow_page_template/{template_id}?type=2&create=&skip_i18n=true")
|
|
478
|
+
|
|
479
|
+
def create_flow_page_template(self, payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
480
|
+
return self._request("POST", "/api/flow_page_template", payload)
|
|
481
|
+
|
|
482
|
+
def update_flow_page_template(self, template_id: int, payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
483
|
+
return self._request("PUT", f"/api/flow_page_template/{template_id}", payload)
|
|
484
|
+
|
|
485
|
+
def activate_flow_page_template(self, template_id: int, *, flow_type: str, flow_key: str = "") -> Dict[str, Any]:
|
|
486
|
+
return self._request(
|
|
487
|
+
"PUT",
|
|
488
|
+
f"/api/flow_page_template/{template_id}",
|
|
489
|
+
{"status": 1, "flow_type": flow_type, "flow_key": flow_key},
|
|
490
|
+
)
|
|
491
|
+
|
|
492
|
+
def delete_flow_page_template(self, template_id: int) -> Dict[str, Any]:
|
|
493
|
+
return self._request("DELETE", f"/api/flow_page_template/{template_id}")
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def build_client(args: Any) -> ApiClient:
|
|
497
|
+
workspace = getattr(args, "workspace", None) or ""
|
|
498
|
+
if not workspace:
|
|
499
|
+
raise SystemExit("missing workspace: pass --workspace from the current browser page")
|
|
500
|
+
return ApiClient(
|
|
501
|
+
base_url=resolve_base_url(getattr(args, "base_url", None)),
|
|
502
|
+
workspace=workspace,
|
|
503
|
+
language=getattr(args, "language", DEFAULT_LANGUAGE),
|
|
504
|
+
cookie_header=getattr(args, "cookie_header", "") or "",
|
|
505
|
+
timeout=float(getattr(args, "timeout", 30)),
|
|
506
|
+
insecure=bool(getattr(args, "insecure", False)),
|
|
507
|
+
)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
print(
|
|
7
|
+
"Legacy config submit scripts are disabled in bpmax-cli. Use `bpmax-cli config project-detail-template submit` so capability, dry-run, confirmation, audit, and baseline checks are enforced.",
|
|
8
|
+
file=sys.stderr,
|
|
9
|
+
)
|
|
10
|
+
sys.exit(2)
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
|
|
14
|
+
from project_detail_template_editor_common import (
|
|
15
|
+
build_client,
|
|
16
|
+
dump_json,
|
|
17
|
+
ensure_submission_allowed,
|
|
18
|
+
extract_template_id,
|
|
19
|
+
load_json,
|
|
20
|
+
parse_content,
|
|
21
|
+
persist_create_submission_meta,
|
|
22
|
+
paths_for,
|
|
23
|
+
summarize_verification,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
28
|
+
p = argparse.ArgumentParser(description="Submit, activate or delete a BPMAX project-detail-template payload and verify readback.")
|
|
29
|
+
p.add_argument("--stem")
|
|
30
|
+
p.add_argument("--action", choices=("submit", "activate", "delete"), default="submit")
|
|
31
|
+
p.add_argument("--template-id", type=int)
|
|
32
|
+
p.add_argument("--flow-type")
|
|
33
|
+
p.add_argument("--flow-key", default="")
|
|
34
|
+
p.add_argument("--workspace")
|
|
35
|
+
p.add_argument("--base-url")
|
|
36
|
+
p.add_argument("--language", default="zhCN")
|
|
37
|
+
p.add_argument("--cookie-header")
|
|
38
|
+
p.add_argument("--timeout", type=float, default=30)
|
|
39
|
+
p.add_argument("--insecure", action="store_true")
|
|
40
|
+
return p
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main() -> int:
|
|
44
|
+
args = build_parser().parse_args()
|
|
45
|
+
client = build_client(args)
|
|
46
|
+
|
|
47
|
+
if args.action in ("activate", "delete"):
|
|
48
|
+
if not args.template_id:
|
|
49
|
+
raise SystemExit("--template-id is required for activate/delete")
|
|
50
|
+
if args.action == "activate":
|
|
51
|
+
if not args.flow_type:
|
|
52
|
+
raise SystemExit("--flow-type is required for activate")
|
|
53
|
+
response = client.activate_flow_page_template(args.template_id, flow_type=args.flow_type, flow_key=args.flow_key)
|
|
54
|
+
readback = client.get_flow_page_template(args.template_id).get("data") or {}
|
|
55
|
+
else:
|
|
56
|
+
response = client.delete_flow_page_template(args.template_id)
|
|
57
|
+
readback = {"id": args.template_id, "deleted": True}
|
|
58
|
+
result = {"action": args.action, "templateId": args.template_id, "response": response, "readback": readback}
|
|
59
|
+
if args.stem:
|
|
60
|
+
paths = paths_for(args.stem)
|
|
61
|
+
dump_json(paths["response"], response)
|
|
62
|
+
dump_json(paths["readback"], readback)
|
|
63
|
+
dump_json(paths["verify"], {"ok": True, **result})
|
|
64
|
+
print(paths["response"])
|
|
65
|
+
print(paths["readback"])
|
|
66
|
+
print(paths["verify"])
|
|
67
|
+
else:
|
|
68
|
+
print(result)
|
|
69
|
+
return 0
|
|
70
|
+
|
|
71
|
+
if not args.stem:
|
|
72
|
+
raise SystemExit("--stem is required for action=submit")
|
|
73
|
+
paths = paths_for(args.stem)
|
|
74
|
+
meta = ensure_submission_allowed(paths["meta"], paths["work"], paths["submit"])
|
|
75
|
+
action_mode = meta.get("mode")
|
|
76
|
+
submit_payload = load_json(paths["submit"])
|
|
77
|
+
|
|
78
|
+
if action_mode == "create":
|
|
79
|
+
response = client.create_flow_page_template(submit_payload)
|
|
80
|
+
template_id = extract_template_id(response)
|
|
81
|
+
if not template_id:
|
|
82
|
+
raise SystemExit("create response did not include a template id")
|
|
83
|
+
else:
|
|
84
|
+
template_id = meta.get("templateId")
|
|
85
|
+
if not template_id:
|
|
86
|
+
raise SystemExit("edit submission requires templateId in meta")
|
|
87
|
+
response = client.update_flow_page_template(int(template_id), submit_payload)
|
|
88
|
+
|
|
89
|
+
readback = client.get_flow_page_template(int(template_id)).get("data") or {}
|
|
90
|
+
if action_mode == "create":
|
|
91
|
+
persist_create_submission_meta(
|
|
92
|
+
paths["meta"],
|
|
93
|
+
stem=args.stem,
|
|
94
|
+
action_mode=action_mode,
|
|
95
|
+
template_id=int(template_id),
|
|
96
|
+
readback=readback,
|
|
97
|
+
)
|
|
98
|
+
verification = summarize_verification(submit_payload, readback)
|
|
99
|
+
dump_json(paths["response"], response)
|
|
100
|
+
dump_json(paths["readback"], readback)
|
|
101
|
+
dump_json(
|
|
102
|
+
paths["verify"],
|
|
103
|
+
{
|
|
104
|
+
"ok": verification["ok"],
|
|
105
|
+
"mode": action_mode,
|
|
106
|
+
"templateId": template_id,
|
|
107
|
+
"submittedContent": parse_content(submit_payload.get("content")),
|
|
108
|
+
"verification": verification,
|
|
109
|
+
},
|
|
110
|
+
)
|
|
111
|
+
print(paths["response"])
|
|
112
|
+
print(paths["readback"])
|
|
113
|
+
print(paths["verify"])
|
|
114
|
+
if not verification["ok"]:
|
|
115
|
+
raise SystemExit("readback verification failed; inspect verify.json for mismatches")
|
|
116
|
+
return 0
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if __name__ == "__main__":
|
|
120
|
+
raise SystemExit(main())
|