bpmax-cli 0.1.44 → 0.2.1-beta.10
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 +79 -5
- package/dist/bin.js +14430 -2672
- 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 +230 -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 +90 -0
- package/skills/bpmax-auth/SKILL.md +6 -17
- package/skills/bpmax-blueprint-doc-workflow/SKILL.md +87 -0
- package/skills/bpmax-blueprint-doc-workflow/agents/openai.yaml +4 -0
- package/skills/bpmax-blueprint-doc-workflow/references/blueprint-structure.md +60 -0
- package/skills/bpmax-blueprint-doc-workflow/references/per-flow-required-structure.md +98 -0
- package/skills/bpmax-blueprint-doc-workflow/references/sample-forbidden-term.xml +12 -0
- package/skills/bpmax-blueprint-doc-workflow/references/sample-mermaid-codeblock.xml +12 -0
- package/skills/bpmax-blueprint-doc-workflow/references/sample-missing-boundary.xml +10 -0
- package/skills/bpmax-blueprint-doc-workflow/references/sample-missing-whiteboard.xml +10 -0
- package/skills/bpmax-blueprint-doc-workflow/references/sample-pass.xml +55 -0
- package/skills/bpmax-blueprint-doc-workflow/scripts/lint_blueprint_doc.py +257 -0
- 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 +606 -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 +789 -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 +227 -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 +564 -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 +355 -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 +1148 -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 +1160 -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
|
@@ -0,0 +1,1084 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import copy
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
import ssl
|
|
10
|
+
from collections import Counter
|
|
11
|
+
import urllib.error
|
|
12
|
+
import urllib.parse
|
|
13
|
+
import urllib.request
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from datetime import datetime, timezone
|
|
16
|
+
from difflib import unified_diff
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any, Dict, Iterable, Optional
|
|
19
|
+
|
|
20
|
+
|
|
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
|
+
from base_url import DEFAULT_BASE_URL, resolve_base_url
|
|
25
|
+
|
|
26
|
+
DEFAULT_LANGUAGE = "zhCN"
|
|
27
|
+
REPO_ROOT = Path(__file__).resolve().parents[4]
|
|
28
|
+
TMP_ROOT = REPO_ROOT / ".codex" / "tmp" / "flow-template-editor"
|
|
29
|
+
TMP_SUBDIRS = ("raw", "work", "meta", "submit", "diffs", "result")
|
|
30
|
+
RUNTIME_ACCEPTANCE_PENDING = "pending"
|
|
31
|
+
RUNTIME_ACCEPTANCE_NOT_REQUIRED = "not_required"
|
|
32
|
+
|
|
33
|
+
from template_script_hard_rules import scan_named_script_surfaces
|
|
34
|
+
|
|
35
|
+
ONLINE_TEMPLATE_REF_ERROR_SUFFIX = (
|
|
36
|
+
"must use the current online remote id style; do not write local uuid/directory refs into /api/flow payloads"
|
|
37
|
+
)
|
|
38
|
+
APPROVAL_SEMANTIC_KEYWORDS = (
|
|
39
|
+
"审批",
|
|
40
|
+
"审核",
|
|
41
|
+
"确认",
|
|
42
|
+
"验收",
|
|
43
|
+
"批准",
|
|
44
|
+
"复核",
|
|
45
|
+
"月审",
|
|
46
|
+
"对账",
|
|
47
|
+
"判定",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def utc_now_iso() -> str:
|
|
52
|
+
return datetime.now(timezone.utc).isoformat()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def ensure_tmp_dirs() -> None:
|
|
56
|
+
for part in TMP_SUBDIRS:
|
|
57
|
+
(TMP_ROOT / part).mkdir(parents=True, exist_ok=True)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def slugify(value: str) -> str:
|
|
61
|
+
text = (value or "").strip()
|
|
62
|
+
if not text:
|
|
63
|
+
return "default"
|
|
64
|
+
chars: list[str] = []
|
|
65
|
+
for ch in text:
|
|
66
|
+
if ch.isalnum() or ch in ("-", "_", "."):
|
|
67
|
+
chars.append(ch)
|
|
68
|
+
else:
|
|
69
|
+
chars.append("-")
|
|
70
|
+
slug = "".join(chars).strip("-")
|
|
71
|
+
return slug or "default"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def stem_for_identity(*, flow_type: str = "", key: str = "") -> str:
|
|
75
|
+
if flow_type:
|
|
76
|
+
return str(flow_type)
|
|
77
|
+
if key:
|
|
78
|
+
return f"sub-{slugify(key)}"
|
|
79
|
+
raise SystemExit("flow identity requires flow_type or key")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def paths_for(stem: str) -> Dict[str, Path]:
|
|
83
|
+
ensure_tmp_dirs()
|
|
84
|
+
return {
|
|
85
|
+
"raw": TMP_ROOT / "raw" / f"{stem}.json",
|
|
86
|
+
"work": TMP_ROOT / "work" / f"{stem}.json",
|
|
87
|
+
"meta": TMP_ROOT / "meta" / f"{stem}.json",
|
|
88
|
+
"submit": TMP_ROOT / "submit" / f"{stem}.json",
|
|
89
|
+
"work_diff": TMP_ROOT / "diffs" / f"{stem}.work.diff.txt",
|
|
90
|
+
"submit_diff": TMP_ROOT / "diffs" / f"{stem}.submit.diff.txt",
|
|
91
|
+
"response": TMP_ROOT / "result" / f"{stem}.response.json",
|
|
92
|
+
"readback": TMP_ROOT / "result" / f"{stem}.readback.json",
|
|
93
|
+
"verify": TMP_ROOT / "result" / f"{stem}.verify.json",
|
|
94
|
+
"drift": TMP_ROOT / "result" / f"{stem}.drift.json",
|
|
95
|
+
"semantic_lint": TMP_ROOT / "result" / f"{stem}.semantic-lint.json",
|
|
96
|
+
"runtime_acceptance": TMP_ROOT / "result" / f"{stem}.runtime-acceptance.json",
|
|
97
|
+
"live_response": TMP_ROOT / "result" / f"{stem}.live-response.json",
|
|
98
|
+
"live_readback": TMP_ROOT / "result" / f"{stem}.live-readback.json",
|
|
99
|
+
"live_verify": TMP_ROOT / "result" / f"{stem}.live-verify.json",
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def dump_json(path: Path, payload: Any) -> None:
|
|
104
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
105
|
+
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def load_json(path: Path) -> Any:
|
|
109
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def file_sha256(path: Path) -> str:
|
|
113
|
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def stable_json_lines(payload: Any) -> list[str]:
|
|
117
|
+
return (json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True) + "\n").splitlines(keepends=True)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def write_diff(path: Path, before: Any, after: Any, before_label: str, after_label: str) -> None:
|
|
121
|
+
diff = unified_diff(
|
|
122
|
+
stable_json_lines(before),
|
|
123
|
+
stable_json_lines(after),
|
|
124
|
+
fromfile=before_label,
|
|
125
|
+
tofile=after_label,
|
|
126
|
+
)
|
|
127
|
+
text = "".join(diff)
|
|
128
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
129
|
+
path.write_text(text or "# no diff\n", encoding="utf-8")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def load_meta(path: Path) -> Dict[str, Any]:
|
|
133
|
+
if not path.exists():
|
|
134
|
+
return {}
|
|
135
|
+
payload = load_json(path)
|
|
136
|
+
if not isinstance(payload, dict):
|
|
137
|
+
raise SystemExit(f"invalid meta file: {path}")
|
|
138
|
+
return payload
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def save_meta(path: Path, payload: Dict[str, Any]) -> None:
|
|
142
|
+
dump_json(path, payload)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def type_name(value: Any) -> str:
|
|
146
|
+
if isinstance(value, dict):
|
|
147
|
+
return "dict"
|
|
148
|
+
if isinstance(value, list):
|
|
149
|
+
return "list"
|
|
150
|
+
return type(value).__name__
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _append_report_error(report: Dict[str, Any], message: str, *, hard: bool = False) -> None:
|
|
154
|
+
report["errors"].append(message)
|
|
155
|
+
if hard:
|
|
156
|
+
report.setdefault("hardErrors", []).append(message)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _int_value(value: Any, default: int = 0) -> int:
|
|
160
|
+
if value in (None, ""):
|
|
161
|
+
return default
|
|
162
|
+
try:
|
|
163
|
+
return int(value)
|
|
164
|
+
except (TypeError, ValueError):
|
|
165
|
+
return default
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _node_has_approval_semantics(node: Dict[str, Any]) -> bool:
|
|
169
|
+
text_parts: list[str] = []
|
|
170
|
+
for key in ("name", "period"):
|
|
171
|
+
value = node.get(key)
|
|
172
|
+
if isinstance(value, str):
|
|
173
|
+
text_parts.append(value)
|
|
174
|
+
for key in ("approve_actions", "approve_fail_actions"):
|
|
175
|
+
value = node.get(key)
|
|
176
|
+
if isinstance(value, list):
|
|
177
|
+
text_parts.extend(str(item) for item in value if item not in (None, ""))
|
|
178
|
+
text = " ".join(text_parts)
|
|
179
|
+
return any(keyword in text for keyword in APPROVAL_SEMANTIC_KEYWORDS)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _extract_action_targets(actions: Any) -> list[str]:
|
|
183
|
+
targets: list[str] = []
|
|
184
|
+
if not isinstance(actions, list):
|
|
185
|
+
return targets
|
|
186
|
+
for action in actions:
|
|
187
|
+
if not isinstance(action, str):
|
|
188
|
+
continue
|
|
189
|
+
if "|" not in action:
|
|
190
|
+
continue
|
|
191
|
+
target = action.rsplit("|", 1)[-1].strip()
|
|
192
|
+
if target:
|
|
193
|
+
targets.append(target)
|
|
194
|
+
return targets
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _approval_targets(node: Dict[str, Any]) -> tuple[set[str], set[str]]:
|
|
198
|
+
approve_targets = set(_extract_action_targets(node.get("approve_actions")))
|
|
199
|
+
reject_targets = set(_extract_action_targets(node.get("approve_fail_actions")))
|
|
200
|
+
approve_to = node.get("approve_to_step")
|
|
201
|
+
approve_fail = node.get("approve_fail")
|
|
202
|
+
if approve_to not in (None, ""):
|
|
203
|
+
approve_targets.add(str(approve_to))
|
|
204
|
+
if approve_fail not in (None, ""):
|
|
205
|
+
reject_targets.add(str(approve_fail))
|
|
206
|
+
return approve_targets, reject_targets
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _is_online_remote_id(value: Any) -> bool:
|
|
210
|
+
return isinstance(value, int) and not isinstance(value, bool)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _check_online_template_ref(report: Dict[str, Any], field_path: str, value: Any) -> None:
|
|
214
|
+
if value in (None, ""):
|
|
215
|
+
return
|
|
216
|
+
report["checks"].setdefault("onlineTemplateRefs", []).append({"path": field_path, "value": value})
|
|
217
|
+
if not _is_online_remote_id(value):
|
|
218
|
+
_append_report_error(report, f"{field_path} {ONLINE_TEMPLATE_REF_ERROR_SUFFIX}", hard=True)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def extract_api_data(payload: Dict[str, Any]) -> Any:
|
|
222
|
+
if isinstance(payload, dict) and "data" in payload:
|
|
223
|
+
return payload.get("data")
|
|
224
|
+
return payload
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def get_flow_data(detail: Any) -> Dict[str, Any] | None:
|
|
228
|
+
if not isinstance(detail, dict) or not detail:
|
|
229
|
+
return None
|
|
230
|
+
data = detail.get("data")
|
|
231
|
+
if isinstance(data, dict):
|
|
232
|
+
return data
|
|
233
|
+
if any(key in detail for key in ("periods", "nodes", "meta", "group")):
|
|
234
|
+
return detail
|
|
235
|
+
return None
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def is_empty_flow_detail(detail: Any) -> bool:
|
|
239
|
+
data = get_flow_data(detail)
|
|
240
|
+
if not isinstance(data, dict):
|
|
241
|
+
return True
|
|
242
|
+
nodes = data.get("nodes")
|
|
243
|
+
periods = data.get("periods")
|
|
244
|
+
meta = data.get("meta")
|
|
245
|
+
group = data.get("group")
|
|
246
|
+
has_surface = any(
|
|
247
|
+
(
|
|
248
|
+
isinstance(nodes, list) and len(nodes) > 0,
|
|
249
|
+
isinstance(periods, list) and len(periods) > 0,
|
|
250
|
+
isinstance(meta, dict) and len(meta) > 0,
|
|
251
|
+
isinstance(group, (dict, list)) and len(group) > 0,
|
|
252
|
+
)
|
|
253
|
+
)
|
|
254
|
+
return not has_surface
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def normalize_flow_detail(
|
|
258
|
+
detail: Dict[str, Any],
|
|
259
|
+
*,
|
|
260
|
+
flow_type: str = "",
|
|
261
|
+
key: str = "",
|
|
262
|
+
name: str = "",
|
|
263
|
+
update_time: str = "",
|
|
264
|
+
) -> Dict[str, Any]:
|
|
265
|
+
data = get_flow_data(detail)
|
|
266
|
+
if not isinstance(data, dict):
|
|
267
|
+
raise SystemExit("flow detail missing data object")
|
|
268
|
+
return {
|
|
269
|
+
**detail,
|
|
270
|
+
"name": detail.get("name") or detail.get("flowTypeName") or name,
|
|
271
|
+
"update_time": detail.get("update_time") or detail.get("updateTime") or update_time,
|
|
272
|
+
"flow_type": detail.get("flow_type") or detail.get("flowTypeKey") or flow_type,
|
|
273
|
+
"key": detail.get("key") or key,
|
|
274
|
+
"data": copy.deepcopy(data),
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def resolve_export_detail(api_detail: Any, runtime_detail: Any | None = None) -> tuple[Dict[str, Any], str]:
|
|
279
|
+
if isinstance(api_detail, dict) and not is_empty_flow_detail(api_detail):
|
|
280
|
+
return api_detail, "api"
|
|
281
|
+
if isinstance(runtime_detail, dict) and not is_empty_flow_detail(runtime_detail):
|
|
282
|
+
return runtime_detail, "runtime_fallback"
|
|
283
|
+
raise SystemExit("flow detail is empty and no usable runtime fallback was provided")
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def summarize_preserve(detail: Dict[str, Any]) -> Dict[str, Any]:
|
|
287
|
+
data = get_flow_data(detail) if isinstance(detail, dict) else {}
|
|
288
|
+
if not isinstance(data, dict):
|
|
289
|
+
data = {}
|
|
290
|
+
nodes = data.get("nodes") if isinstance(data.get("nodes"), list) else []
|
|
291
|
+
meta = data.get("meta") if isinstance(data.get("meta"), dict) else {}
|
|
292
|
+
return {
|
|
293
|
+
"topLevelKeys": sorted(detail.keys()),
|
|
294
|
+
"dataKeys": sorted(data.keys()),
|
|
295
|
+
"periodCount": len(data.get("periods") or []) if isinstance(data.get("periods"), list) else 0,
|
|
296
|
+
"nodeCount": len(nodes),
|
|
297
|
+
"nodeNames": [node.get("name") for node in nodes if isinstance(node, dict) and node.get("name")],
|
|
298
|
+
"metaKeys": sorted(meta.keys()),
|
|
299
|
+
"groupType": type_name(data.get("group")),
|
|
300
|
+
"updateTime": detail.get("update_time") or detail.get("updateTime"),
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def detail_to_work_payload(
|
|
305
|
+
detail: Dict[str, Any],
|
|
306
|
+
*,
|
|
307
|
+
workspace: str,
|
|
308
|
+
flow_type: str = "",
|
|
309
|
+
key: str = "",
|
|
310
|
+
source: str = "api",
|
|
311
|
+
) -> Dict[str, Any]:
|
|
312
|
+
normalized = normalize_flow_detail(detail, flow_type=flow_type, key=key)
|
|
313
|
+
data = normalized["data"]
|
|
314
|
+
resolved_flow_type = normalized.get("flow_type") or ""
|
|
315
|
+
resolved_key = normalized.get("key") or ""
|
|
316
|
+
identity_scope = "sub" if resolved_key else "main"
|
|
317
|
+
name = normalized.get("name") or ""
|
|
318
|
+
update_time = normalized.get("update_time") or ""
|
|
319
|
+
return {
|
|
320
|
+
"mode": "edit",
|
|
321
|
+
"identity": {
|
|
322
|
+
"scope": identity_scope,
|
|
323
|
+
"workspace": workspace,
|
|
324
|
+
"flowType": resolved_flow_type,
|
|
325
|
+
"key": resolved_key,
|
|
326
|
+
"source": source,
|
|
327
|
+
},
|
|
328
|
+
"basic": {
|
|
329
|
+
"name": name,
|
|
330
|
+
"updateTime": update_time,
|
|
331
|
+
"workspace": workspace,
|
|
332
|
+
"flowType": resolved_flow_type,
|
|
333
|
+
"key": resolved_key,
|
|
334
|
+
},
|
|
335
|
+
"data": copy.deepcopy(data),
|
|
336
|
+
"preserve": summarize_preserve(normalized),
|
|
337
|
+
"notes": "",
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _ensure_target_known(target: Any, node_refs: set[str], path: str, errors: list[str]) -> None:
|
|
342
|
+
if target in (None, "", [], {}):
|
|
343
|
+
return
|
|
344
|
+
if isinstance(target, str):
|
|
345
|
+
if target in {"-1", "success_end", "fail_end"}:
|
|
346
|
+
return
|
|
347
|
+
if target not in node_refs:
|
|
348
|
+
errors.append(f"{path} references missing node: {target}")
|
|
349
|
+
return
|
|
350
|
+
if isinstance(target, list):
|
|
351
|
+
for idx, item in enumerate(target):
|
|
352
|
+
_ensure_target_known(item, node_refs, f"{path}[{idx}]", errors)
|
|
353
|
+
return
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def lint_work_payload(work: Dict[str, Any], *, raw_payload: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
357
|
+
report: Dict[str, Any] = {"ok": True, "errors": [], "warnings": [], "checks": {}}
|
|
358
|
+
basic = work.get("basic")
|
|
359
|
+
data = work.get("data")
|
|
360
|
+
if not isinstance(basic, dict):
|
|
361
|
+
report["errors"].append("work payload missing basic object")
|
|
362
|
+
report["ok"] = False
|
|
363
|
+
return report
|
|
364
|
+
if not isinstance(data, dict):
|
|
365
|
+
report["errors"].append("work payload missing data object")
|
|
366
|
+
report["ok"] = False
|
|
367
|
+
return report
|
|
368
|
+
|
|
369
|
+
name = basic.get("name")
|
|
370
|
+
periods = data.get("periods")
|
|
371
|
+
nodes = data.get("nodes")
|
|
372
|
+
meta = data.get("meta")
|
|
373
|
+
group = data.get("group")
|
|
374
|
+
|
|
375
|
+
if not isinstance(name, str) or not name.strip():
|
|
376
|
+
report["errors"].append("basic.name must be a non-empty string")
|
|
377
|
+
if not isinstance(periods, list):
|
|
378
|
+
report["errors"].append("data.periods must be an array")
|
|
379
|
+
periods = []
|
|
380
|
+
if not isinstance(nodes, list):
|
|
381
|
+
report["errors"].append("data.nodes must be an array")
|
|
382
|
+
nodes = []
|
|
383
|
+
if not isinstance(meta, dict):
|
|
384
|
+
report["errors"].append("data.meta must be an object")
|
|
385
|
+
if not isinstance(group, list):
|
|
386
|
+
report["errors"].append("data.group must be an array")
|
|
387
|
+
|
|
388
|
+
period_set = {item for item in periods if isinstance(item, str) and item}
|
|
389
|
+
node_names: set[str] = set()
|
|
390
|
+
node_ids: set[str] = set()
|
|
391
|
+
duplicate_names: list[str] = []
|
|
392
|
+
for node in nodes:
|
|
393
|
+
if not isinstance(node, dict):
|
|
394
|
+
report["errors"].append("data.nodes must contain only objects")
|
|
395
|
+
continue
|
|
396
|
+
node_name = node.get("name")
|
|
397
|
+
if not isinstance(node_name, str) or not node_name.strip():
|
|
398
|
+
report["errors"].append("every node must have a non-empty name")
|
|
399
|
+
continue
|
|
400
|
+
if node_name in node_names:
|
|
401
|
+
duplicate_names.append(node_name)
|
|
402
|
+
node_names.add(node_name)
|
|
403
|
+
node_id = node.get("id")
|
|
404
|
+
if node_id not in (None, ""):
|
|
405
|
+
node_ids.add(str(node_id))
|
|
406
|
+
|
|
407
|
+
node_refs = set(node_names) | set(node_ids)
|
|
408
|
+
|
|
409
|
+
for node in nodes:
|
|
410
|
+
if not isinstance(node, dict):
|
|
411
|
+
continue
|
|
412
|
+
node_name = node.get("name")
|
|
413
|
+
if not isinstance(node_name, str) or not node_name.strip():
|
|
414
|
+
continue
|
|
415
|
+
node_period = node.get("period")
|
|
416
|
+
if node_period not in (None, "") and node_period not in period_set:
|
|
417
|
+
report["errors"].append(f"node {node_name} references missing period: {node_period}")
|
|
418
|
+
_ensure_target_known(node.get("approve_to_step"), node_refs, f"{node_name}.approve_to_step", report["errors"])
|
|
419
|
+
_ensure_target_known(node.get("approve_fail"), node_refs, f"{node_name}.approve_fail", report["errors"])
|
|
420
|
+
conds = node.get("condational_nodes")
|
|
421
|
+
if isinstance(conds, list):
|
|
422
|
+
for idx, cond in enumerate(conds):
|
|
423
|
+
if not isinstance(cond, dict):
|
|
424
|
+
report["errors"].append(f"{node_name}.condational_nodes[{idx}] must be an object")
|
|
425
|
+
continue
|
|
426
|
+
_ensure_target_known(cond.get("result"), node_refs, f"{node_name}.condational_nodes[{idx}].result", report["errors"])
|
|
427
|
+
auto_trigger = node.get("auto_trigger_flows")
|
|
428
|
+
if auto_trigger not in (None, "") and not isinstance(auto_trigger, dict):
|
|
429
|
+
report["errors"].append(f"{node_name}.auto_trigger_flows must be an object when present")
|
|
430
|
+
|
|
431
|
+
if duplicate_names:
|
|
432
|
+
report["errors"].append("duplicate node names: " + ", ".join(sorted(set(duplicate_names))))
|
|
433
|
+
|
|
434
|
+
report["checks"]["periodCount"] = len(periods)
|
|
435
|
+
report["checks"]["nodeCount"] = len(nodes)
|
|
436
|
+
report["checks"]["metaType"] = type_name(meta)
|
|
437
|
+
report["checks"]["groupType"] = type_name(group)
|
|
438
|
+
|
|
439
|
+
if raw_payload:
|
|
440
|
+
raw_data = raw_payload.get("data") if isinstance(raw_payload, dict) else None
|
|
441
|
+
if isinstance(raw_data, dict):
|
|
442
|
+
raw_nodes = raw_data.get("nodes") if isinstance(raw_data.get("nodes"), list) else []
|
|
443
|
+
raw_meta = raw_data.get("meta") if isinstance(raw_data.get("meta"), dict) else {}
|
|
444
|
+
if raw_nodes and not nodes:
|
|
445
|
+
report["errors"].append("work.data.nodes is empty while raw payload contains nodes")
|
|
446
|
+
if len(raw_nodes) >= 6 and len(nodes) <= len(raw_nodes) // 2:
|
|
447
|
+
report["errors"].append(
|
|
448
|
+
f"work.data.nodes dropped too many nodes vs raw payload: raw={len(raw_nodes)} work={len(nodes)}"
|
|
449
|
+
)
|
|
450
|
+
if raw_meta and not meta:
|
|
451
|
+
report["errors"].append("work.data.meta is empty while raw payload contains flow-level configuration")
|
|
452
|
+
|
|
453
|
+
report["ok"] = not report["errors"]
|
|
454
|
+
return report
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def lint_flow_semantics(work_payload: Dict[str, Any], *, raw_payload: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
458
|
+
report: Dict[str, Any] = {
|
|
459
|
+
"ok": True,
|
|
460
|
+
"errors": [],
|
|
461
|
+
"hardErrors": [],
|
|
462
|
+
"warnings": [],
|
|
463
|
+
"checks": {
|
|
464
|
+
"nodeFormTemplateIds": [],
|
|
465
|
+
"metaFormTemplateId": None,
|
|
466
|
+
"beforeNextStepScripts": [],
|
|
467
|
+
"autoTriggerForms": [],
|
|
468
|
+
"groupType": None,
|
|
469
|
+
"onlineTemplateRefs": [],
|
|
470
|
+
},
|
|
471
|
+
}
|
|
472
|
+
data = work_payload.get("data")
|
|
473
|
+
if not isinstance(data, dict):
|
|
474
|
+
_append_report_error(report, "work payload missing data object for semantic lint")
|
|
475
|
+
report["ok"] = False
|
|
476
|
+
return report
|
|
477
|
+
|
|
478
|
+
nodes = data.get("nodes") if isinstance(data.get("nodes"), list) else []
|
|
479
|
+
meta = data.get("meta") if isinstance(data.get("meta"), dict) else {}
|
|
480
|
+
group = data.get("group")
|
|
481
|
+
report["checks"]["groupType"] = type_name(group)
|
|
482
|
+
if isinstance(group, list):
|
|
483
|
+
report["warnings"].append("group is array in current online runtime; preserve original shape and do not normalize")
|
|
484
|
+
else:
|
|
485
|
+
_append_report_error(
|
|
486
|
+
report,
|
|
487
|
+
"data.group must stay as an array; object-shaped group can save remotely but breaks FlowMap rendering"
|
|
488
|
+
)
|
|
489
|
+
|
|
490
|
+
meta_form_template = meta.get("form_template")
|
|
491
|
+
report["checks"]["metaFormTemplateId"] = meta_form_template
|
|
492
|
+
_check_online_template_ref(report, "meta.form_template", meta_form_template)
|
|
493
|
+
_check_online_template_ref(report, "meta.table_list_template", meta.get("table_list_template"))
|
|
494
|
+
_check_online_template_ref(report, "meta.table_filter_template", meta.get("table_filter_template"))
|
|
495
|
+
_check_online_template_ref(report, "meta.step_detail_id", meta.get("step_detail_id"))
|
|
496
|
+
|
|
497
|
+
for node in nodes:
|
|
498
|
+
if not isinstance(node, dict):
|
|
499
|
+
continue
|
|
500
|
+
node_name = node.get("name") or "<unnamed-node>"
|
|
501
|
+
form_template = node.get("form_template")
|
|
502
|
+
if form_template not in (None, ""):
|
|
503
|
+
report["checks"]["nodeFormTemplateIds"].append({"name": node_name, "value": form_template})
|
|
504
|
+
_check_online_template_ref(report, f"{node_name}.form_template", form_template)
|
|
505
|
+
_check_online_template_ref(report, f"{node_name}.step_detail_id", node.get("step_detail_id"))
|
|
506
|
+
|
|
507
|
+
approve_count = _int_value(node.get("approve_count_required"))
|
|
508
|
+
has_approval_semantics = _node_has_approval_semantics(node)
|
|
509
|
+
approve_targets, reject_targets = _approval_targets(node)
|
|
510
|
+
report["checks"].setdefault("approvalRouting", []).append(
|
|
511
|
+
{
|
|
512
|
+
"name": node_name,
|
|
513
|
+
"approveCountRequired": approve_count,
|
|
514
|
+
"hasApprovalSemantics": has_approval_semantics,
|
|
515
|
+
"approveTargets": sorted(approve_targets),
|
|
516
|
+
"rejectTargets": sorted(reject_targets),
|
|
517
|
+
}
|
|
518
|
+
)
|
|
519
|
+
if approve_count > 0 and not has_approval_semantics:
|
|
520
|
+
_append_report_error(
|
|
521
|
+
report,
|
|
522
|
+
f"{node_name}.approve_count_required is {approve_count}, but this is not an approval-semantic step; non-approval steps must use 0",
|
|
523
|
+
)
|
|
524
|
+
if approve_count > 0 and has_approval_semantics:
|
|
525
|
+
if not reject_targets:
|
|
526
|
+
_append_report_error(
|
|
527
|
+
report,
|
|
528
|
+
f"{node_name} is an approval-semantic step with approve_count_required={approve_count}, but no explicit reject target is configured; reject must not default to the approve target",
|
|
529
|
+
)
|
|
530
|
+
overlap = approve_targets & reject_targets
|
|
531
|
+
if overlap:
|
|
532
|
+
_append_report_error(
|
|
533
|
+
report,
|
|
534
|
+
f"{node_name} approval and reject routing target the same node(s): {', '.join(sorted(overlap))}",
|
|
535
|
+
)
|
|
536
|
+
|
|
537
|
+
before_script = node.get("beforeNextStepScript")
|
|
538
|
+
before_enabled = node.get("enableBeforeNextStepScript")
|
|
539
|
+
if before_script not in (None, ""):
|
|
540
|
+
report["checks"]["beforeNextStepScripts"].append({"name": node_name, "enabled": before_enabled})
|
|
541
|
+
if before_enabled is not True:
|
|
542
|
+
_append_report_error(
|
|
543
|
+
report,
|
|
544
|
+
f"{node_name}.beforeNextStepScript is present but enableBeforeNextStepScript is not true",
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
auto_trigger = node.get("auto_trigger_flows")
|
|
548
|
+
if not isinstance(auto_trigger, dict):
|
|
549
|
+
continue
|
|
550
|
+
flows = auto_trigger.get("flows")
|
|
551
|
+
if not isinstance(flows, list):
|
|
552
|
+
continue
|
|
553
|
+
for idx, flow_item in enumerate(flows):
|
|
554
|
+
if not isinstance(flow_item, dict):
|
|
555
|
+
continue
|
|
556
|
+
create_rule = flow_item.get("create_rule")
|
|
557
|
+
if not isinstance(create_rule, str) or not create_rule.strip():
|
|
558
|
+
continue
|
|
559
|
+
entry = {"name": node_name, "index": idx, "hasCreateRule": True}
|
|
560
|
+
report["checks"]["autoTriggerForms"].append(entry)
|
|
561
|
+
if "form:" in create_rule and "key_to_value" not in create_rule and "field_to_value" not in create_rule:
|
|
562
|
+
_append_report_error(
|
|
563
|
+
report,
|
|
564
|
+
f"{node_name}.auto_trigger_flows.flows[{idx}].create_rule contains bare form object; use key_to_value or field_to_value"
|
|
565
|
+
)
|
|
566
|
+
|
|
567
|
+
script_surfaces = []
|
|
568
|
+
for idx, node in enumerate(nodes):
|
|
569
|
+
if not isinstance(node, dict):
|
|
570
|
+
continue
|
|
571
|
+
node_name = node.get("name") or f"nodes[{idx}]"
|
|
572
|
+
for key in (
|
|
573
|
+
"beforeNextStepScript",
|
|
574
|
+
"message_template",
|
|
575
|
+
"cc_message_template",
|
|
576
|
+
"message_template_simple",
|
|
577
|
+
"step_notify_owner_message_template_simple",
|
|
578
|
+
"step_cc_message_template_simple",
|
|
579
|
+
):
|
|
580
|
+
value = node.get(key)
|
|
581
|
+
if isinstance(value, str) and value.strip():
|
|
582
|
+
script_surfaces.append({"path": f"data.nodes[{idx}].{key}<{node_name}>", "script": value})
|
|
583
|
+
auto_trigger = node.get("auto_trigger_flows")
|
|
584
|
+
if isinstance(auto_trigger, dict):
|
|
585
|
+
for flow_idx, flow_item in enumerate(auto_trigger.get("flows") or []):
|
|
586
|
+
if isinstance(flow_item, dict) and isinstance(flow_item.get("create_rule"), str):
|
|
587
|
+
script_surfaces.append(
|
|
588
|
+
{
|
|
589
|
+
"path": f"data.nodes[{idx}].auto_trigger_flows.flows[{flow_idx}].create_rule<{node_name}>",
|
|
590
|
+
"script": flow_item["create_rule"],
|
|
591
|
+
}
|
|
592
|
+
)
|
|
593
|
+
for key in ("project_name_template", "task_project_name_template", "message_template", "cc_message_template"):
|
|
594
|
+
value = meta.get(key)
|
|
595
|
+
if isinstance(value, str) and value.strip():
|
|
596
|
+
script_surfaces.append({"path": f"data.meta.{key}", "script": value})
|
|
597
|
+
hard_rule_report = scan_named_script_surfaces(script_surfaces)
|
|
598
|
+
report["checks"]["scriptHardRules"] = hard_rule_report["findings"]
|
|
599
|
+
report["errors"].extend(hard_rule_report["errors"])
|
|
600
|
+
|
|
601
|
+
report["ok"] = not report["errors"]
|
|
602
|
+
return report
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
def _subtract_preexisting_errors(
|
|
606
|
+
errors: list[str],
|
|
607
|
+
baseline_errors: list[str],
|
|
608
|
+
*,
|
|
609
|
+
protected_errors: Optional[set[str]] = None,
|
|
610
|
+
) -> tuple[list[str], list[str]]:
|
|
611
|
+
protected = protected_errors or set()
|
|
612
|
+
remaining = Counter(baseline_errors)
|
|
613
|
+
fresh: list[str] = []
|
|
614
|
+
ignored: list[str] = []
|
|
615
|
+
for error in errors:
|
|
616
|
+
if error in protected:
|
|
617
|
+
fresh.append(error)
|
|
618
|
+
continue
|
|
619
|
+
if remaining[error] > 0:
|
|
620
|
+
remaining[error] -= 1
|
|
621
|
+
ignored.append(error)
|
|
622
|
+
else:
|
|
623
|
+
fresh.append(error)
|
|
624
|
+
return fresh, ignored
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
def _build_raw_baseline_work_payload(work_payload: Dict[str, Any], raw_payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
628
|
+
basic = work_payload.get("basic") if isinstance(work_payload.get("basic"), dict) else {}
|
|
629
|
+
return detail_to_work_payload(
|
|
630
|
+
raw_payload,
|
|
631
|
+
workspace=basic.get("workspace") or "",
|
|
632
|
+
flow_type=basic.get("flowType") or "",
|
|
633
|
+
key=basic.get("key") or "",
|
|
634
|
+
source="raw_baseline",
|
|
635
|
+
)
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
def evaluate_lints(
|
|
639
|
+
work_payload: Dict[str, Any],
|
|
640
|
+
*,
|
|
641
|
+
raw_payload: Optional[Dict[str, Any]] = None,
|
|
642
|
+
allow_preexisting_lint_errors: bool = False,
|
|
643
|
+
) -> tuple[Dict[str, Any], Dict[str, Any]]:
|
|
644
|
+
structure_lint = lint_work_payload(work_payload, raw_payload=raw_payload)
|
|
645
|
+
semantic_lint = lint_flow_semantics(work_payload, raw_payload=raw_payload)
|
|
646
|
+
structure_lint["allErrors"] = list(structure_lint["errors"])
|
|
647
|
+
semantic_lint["allErrors"] = list(semantic_lint["errors"])
|
|
648
|
+
structure_lint["ignoredPreexistingErrors"] = []
|
|
649
|
+
semantic_lint["ignoredPreexistingErrors"] = []
|
|
650
|
+
|
|
651
|
+
if allow_preexisting_lint_errors and raw_payload:
|
|
652
|
+
baseline_work = _build_raw_baseline_work_payload(work_payload, raw_payload)
|
|
653
|
+
baseline_structure = lint_work_payload(baseline_work, raw_payload=raw_payload)
|
|
654
|
+
baseline_semantic = lint_flow_semantics(baseline_work, raw_payload=raw_payload)
|
|
655
|
+
structure_lint["errors"], structure_lint["ignoredPreexistingErrors"] = _subtract_preexisting_errors(
|
|
656
|
+
structure_lint["errors"],
|
|
657
|
+
baseline_structure["errors"],
|
|
658
|
+
)
|
|
659
|
+
semantic_lint["errors"], semantic_lint["ignoredPreexistingErrors"] = _subtract_preexisting_errors(
|
|
660
|
+
semantic_lint["errors"],
|
|
661
|
+
baseline_semantic["errors"],
|
|
662
|
+
protected_errors=set(semantic_lint.get("hardErrors") or []),
|
|
663
|
+
)
|
|
664
|
+
structure_lint["ok"] = not structure_lint["errors"]
|
|
665
|
+
semantic_lint["ok"] = not semantic_lint["errors"]
|
|
666
|
+
|
|
667
|
+
return structure_lint, semantic_lint
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
def build_submit_payload(
|
|
671
|
+
work: Dict[str, Any],
|
|
672
|
+
*,
|
|
673
|
+
raw_payload: Optional[Dict[str, Any]] = None,
|
|
674
|
+
allow_preexisting_lint_errors: bool = False,
|
|
675
|
+
) -> Dict[str, Any]:
|
|
676
|
+
lint, semantic_lint = evaluate_lints(
|
|
677
|
+
work,
|
|
678
|
+
raw_payload=raw_payload,
|
|
679
|
+
allow_preexisting_lint_errors=allow_preexisting_lint_errors,
|
|
680
|
+
)
|
|
681
|
+
if lint["errors"]:
|
|
682
|
+
raise SystemExit("invalid work payload: " + "; ".join(lint["errors"]))
|
|
683
|
+
if semantic_lint["errors"]:
|
|
684
|
+
raise SystemExit("invalid work payload semantic lint: " + "; ".join(semantic_lint["errors"]))
|
|
685
|
+
basic = work["basic"]
|
|
686
|
+
data = work["data"]
|
|
687
|
+
return {
|
|
688
|
+
"name": basic.get("name", ""),
|
|
689
|
+
"data": copy.deepcopy(data),
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
def _node_summary(node: Dict[str, Any]) -> Dict[str, Any]:
|
|
694
|
+
conds = node.get("condational_nodes")
|
|
695
|
+
cond_targets: list[Any] = []
|
|
696
|
+
if isinstance(conds, list):
|
|
697
|
+
for cond in conds:
|
|
698
|
+
if isinstance(cond, dict):
|
|
699
|
+
cond_targets.append(copy.deepcopy(cond.get("result")))
|
|
700
|
+
return {
|
|
701
|
+
"name": node.get("name"),
|
|
702
|
+
"period": node.get("period"),
|
|
703
|
+
"id": node.get("id"),
|
|
704
|
+
"approveTo": copy.deepcopy(node.get("approve_to_step")),
|
|
705
|
+
"approveFail": copy.deepcopy(node.get("approve_fail")),
|
|
706
|
+
"formTemplate": node.get("form_template"),
|
|
707
|
+
"needConfirm": node.get("need_confirm"),
|
|
708
|
+
"ownerIsCreater": node.get("owner_is_creater"),
|
|
709
|
+
"ownerRoles": copy.deepcopy(node.get("owner_roles")),
|
|
710
|
+
"beforeNextStepEnabled": node.get("enableBeforeNextStepScript"),
|
|
711
|
+
"beforeNextStepPresent": bool(node.get("beforeNextStepScript")),
|
|
712
|
+
"conditionalTargets": cond_targets,
|
|
713
|
+
"autoTriggerFlowsPresent": bool(node.get("auto_trigger_flows")),
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
def _focus_flow_state(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
718
|
+
data = payload.get("data") if isinstance(payload, dict) else {}
|
|
719
|
+
if not isinstance(data, dict):
|
|
720
|
+
data = {}
|
|
721
|
+
nodes = data.get("nodes") if isinstance(data.get("nodes"), list) else []
|
|
722
|
+
meta = data.get("meta") if isinstance(data.get("meta"), dict) else {}
|
|
723
|
+
return {
|
|
724
|
+
"name": payload.get("name"),
|
|
725
|
+
"periods": copy.deepcopy(data.get("periods") if isinstance(data.get("periods"), list) else []),
|
|
726
|
+
"nodeSummaries": [_node_summary(node) for node in nodes if isinstance(node, dict)],
|
|
727
|
+
"metaKeys": sorted(meta.keys()),
|
|
728
|
+
"groupType": type_name(data.get("group")),
|
|
729
|
+
"nodeCount": len(nodes),
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
def summarize_verification(submit_payload: Dict[str, Any], readback_detail: Dict[str, Any]) -> Dict[str, Any]:
|
|
734
|
+
actual_payload = {
|
|
735
|
+
"name": readback_detail.get("name", ""),
|
|
736
|
+
"data": copy.deepcopy(readback_detail.get("data") if isinstance(readback_detail.get("data"), dict) else {}),
|
|
737
|
+
}
|
|
738
|
+
expected_focus = _focus_flow_state(submit_payload)
|
|
739
|
+
actual_focus = _focus_flow_state(actual_payload)
|
|
740
|
+
checks = {
|
|
741
|
+
"name": {
|
|
742
|
+
"match": submit_payload.get("name") == actual_payload.get("name"),
|
|
743
|
+
"expected": submit_payload.get("name"),
|
|
744
|
+
"actual": actual_payload.get("name"),
|
|
745
|
+
},
|
|
746
|
+
"periods": {
|
|
747
|
+
"match": expected_focus["periods"] == actual_focus["periods"],
|
|
748
|
+
"expected": expected_focus["periods"],
|
|
749
|
+
"actual": actual_focus["periods"],
|
|
750
|
+
},
|
|
751
|
+
"nodeCount": {
|
|
752
|
+
"match": expected_focus["nodeCount"] == actual_focus["nodeCount"],
|
|
753
|
+
"expected": expected_focus["nodeCount"],
|
|
754
|
+
"actual": actual_focus["nodeCount"],
|
|
755
|
+
},
|
|
756
|
+
"nodeSummaries": {
|
|
757
|
+
"match": expected_focus["nodeSummaries"] == actual_focus["nodeSummaries"],
|
|
758
|
+
"expected": expected_focus["nodeSummaries"],
|
|
759
|
+
"actual": actual_focus["nodeSummaries"],
|
|
760
|
+
},
|
|
761
|
+
"metaKeys": {
|
|
762
|
+
"match": expected_focus["metaKeys"] == actual_focus["metaKeys"],
|
|
763
|
+
"expected": expected_focus["metaKeys"],
|
|
764
|
+
"actual": actual_focus["metaKeys"],
|
|
765
|
+
},
|
|
766
|
+
"groupType": {
|
|
767
|
+
"match": expected_focus["groupType"] == actual_focus["groupType"],
|
|
768
|
+
"expected": expected_focus["groupType"],
|
|
769
|
+
"actual": actual_focus["groupType"],
|
|
770
|
+
},
|
|
771
|
+
"fullDataMatch": {
|
|
772
|
+
"match": submit_payload.get("data") == actual_payload.get("data"),
|
|
773
|
+
"expected": submit_payload.get("data"),
|
|
774
|
+
"actual": actual_payload.get("data"),
|
|
775
|
+
},
|
|
776
|
+
}
|
|
777
|
+
ok = all(item["match"] for item in checks.values())
|
|
778
|
+
return {
|
|
779
|
+
"ok": ok,
|
|
780
|
+
"checks": checks,
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def _compare_drift(before: Dict[str, Any], after: Dict[str, Any], *, before_label: str, after_label: str) -> Dict[str, Any]:
|
|
785
|
+
before_focus = _focus_flow_state(before)
|
|
786
|
+
after_focus = _focus_flow_state(after)
|
|
787
|
+
changes: Dict[str, Any] = {}
|
|
788
|
+
for key, value in before_focus.items():
|
|
789
|
+
other = after_focus.get(key)
|
|
790
|
+
if value != other:
|
|
791
|
+
changes[key] = {before_label: value, after_label: other}
|
|
792
|
+
return {"ok": not changes, "changes": changes}
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
def build_drift_report(submit_payload: Dict[str, Any], draft_readback: Dict[str, Any]) -> Dict[str, Any]:
|
|
796
|
+
submit_to_draft = _compare_drift(
|
|
797
|
+
submit_payload,
|
|
798
|
+
{"name": draft_readback.get("name"), "data": get_flow_data(draft_readback)},
|
|
799
|
+
before_label="submit",
|
|
800
|
+
after_label="draft",
|
|
801
|
+
)
|
|
802
|
+
return {
|
|
803
|
+
"ok": submit_to_draft["ok"],
|
|
804
|
+
"submitToDraft": submit_to_draft,
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
def _runtime_acceptance_template() -> Dict[str, Any]:
|
|
809
|
+
return {
|
|
810
|
+
"required": False,
|
|
811
|
+
"flowType": None,
|
|
812
|
+
"acceptancePage": None,
|
|
813
|
+
"freshInstanceRequired": False,
|
|
814
|
+
"decisionSource": None,
|
|
815
|
+
"updatedAt": None,
|
|
816
|
+
"updatedBy": None,
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
def _normalize_runtime_acceptance(runtime_acceptance: Optional[Dict[str, Any]]) -> Dict[str, Any]:
|
|
821
|
+
payload = _runtime_acceptance_template()
|
|
822
|
+
if runtime_acceptance:
|
|
823
|
+
payload.update(runtime_acceptance)
|
|
824
|
+
payload["required"] = bool(payload.get("required"))
|
|
825
|
+
payload["freshInstanceRequired"] = bool(payload.get("freshInstanceRequired"))
|
|
826
|
+
return payload
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
def ensure_meta_shape(meta: Dict[str, Any], stem: str) -> Dict[str, Any]:
|
|
830
|
+
payload = dict(meta)
|
|
831
|
+
payload.setdefault("stem", stem)
|
|
832
|
+
payload.setdefault("status", "exported")
|
|
833
|
+
payload.setdefault("notes", "")
|
|
834
|
+
payload["runtimeAcceptance"] = _normalize_runtime_acceptance(payload.get("runtimeAcceptance"))
|
|
835
|
+
return payload
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
def write_export_meta(
|
|
839
|
+
path: Path,
|
|
840
|
+
*,
|
|
841
|
+
stem: str,
|
|
842
|
+
mode: str,
|
|
843
|
+
workspace: str,
|
|
844
|
+
flow_type: str,
|
|
845
|
+
key: str,
|
|
846
|
+
source: str,
|
|
847
|
+
request_url: str,
|
|
848
|
+
raw_path: Path,
|
|
849
|
+
work_path: Path,
|
|
850
|
+
update_time: str,
|
|
851
|
+
) -> Dict[str, Any]:
|
|
852
|
+
payload = ensure_meta_shape(load_meta(path), stem)
|
|
853
|
+
payload.update(
|
|
854
|
+
{
|
|
855
|
+
"mode": mode,
|
|
856
|
+
"workspace": workspace,
|
|
857
|
+
"flowType": flow_type,
|
|
858
|
+
"key": key,
|
|
859
|
+
"source": source,
|
|
860
|
+
"requestUrl": request_url,
|
|
861
|
+
"updateTime": update_time,
|
|
862
|
+
"rawSha256": file_sha256(raw_path),
|
|
863
|
+
"workSha256": file_sha256(work_path),
|
|
864
|
+
"submitSha256": None,
|
|
865
|
+
"exportedAt": utc_now_iso(),
|
|
866
|
+
"submitBuiltAt": None,
|
|
867
|
+
"workConfirmedAt": None,
|
|
868
|
+
"workConfirmedBy": None,
|
|
869
|
+
"submitConfirmedAt": None,
|
|
870
|
+
"submitConfirmedBy": None,
|
|
871
|
+
"allowPreexistingLintErrors": False,
|
|
872
|
+
"runtimeAcceptance": _runtime_acceptance_template(),
|
|
873
|
+
"status": "exported",
|
|
874
|
+
}
|
|
875
|
+
)
|
|
876
|
+
save_meta(path, payload)
|
|
877
|
+
return payload
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
def update_build_meta(
|
|
881
|
+
meta_path: Path,
|
|
882
|
+
*,
|
|
883
|
+
stem: str,
|
|
884
|
+
work_path: Path,
|
|
885
|
+
submit_path: Path,
|
|
886
|
+
allow_preexisting_lint_errors: bool = False,
|
|
887
|
+
) -> Dict[str, Any]:
|
|
888
|
+
payload = ensure_meta_shape(load_meta(meta_path), stem)
|
|
889
|
+
previous_work_sha = payload.get("workSha256")
|
|
890
|
+
current_work_sha = file_sha256(work_path)
|
|
891
|
+
if payload.get("workConfirmedAt") and previous_work_sha != current_work_sha:
|
|
892
|
+
payload["workConfirmedAt"] = None
|
|
893
|
+
payload["workConfirmedBy"] = None
|
|
894
|
+
payload["workSha256"] = current_work_sha
|
|
895
|
+
payload["submitSha256"] = file_sha256(submit_path)
|
|
896
|
+
payload["submitBuiltAt"] = utc_now_iso()
|
|
897
|
+
payload["submitConfirmedAt"] = None
|
|
898
|
+
payload["submitConfirmedBy"] = None
|
|
899
|
+
payload["allowPreexistingLintErrors"] = bool(allow_preexisting_lint_errors)
|
|
900
|
+
payload["status"] = "submit_built"
|
|
901
|
+
save_meta(meta_path, payload)
|
|
902
|
+
return payload
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
def update_confirmation_state(
|
|
906
|
+
meta_path: Path,
|
|
907
|
+
*,
|
|
908
|
+
stem: str,
|
|
909
|
+
actor: str,
|
|
910
|
+
stage: str,
|
|
911
|
+
work_path: Path,
|
|
912
|
+
submit_path: Optional[Path] = None,
|
|
913
|
+
runtime_acceptance: Optional[Dict[str, Any]] = None,
|
|
914
|
+
) -> Dict[str, Any]:
|
|
915
|
+
payload = ensure_meta_shape(load_meta(meta_path), stem)
|
|
916
|
+
payload["workSha256"] = file_sha256(work_path)
|
|
917
|
+
now = utc_now_iso()
|
|
918
|
+
if stage == "work":
|
|
919
|
+
if runtime_acceptance is not None or "runtimeAcceptance" not in payload:
|
|
920
|
+
normalized_runtime = _normalize_runtime_acceptance(runtime_acceptance)
|
|
921
|
+
normalized_runtime["updatedAt"] = now
|
|
922
|
+
normalized_runtime["updatedBy"] = actor
|
|
923
|
+
payload["runtimeAcceptance"] = normalized_runtime
|
|
924
|
+
payload["workConfirmedAt"] = now
|
|
925
|
+
payload["workConfirmedBy"] = actor
|
|
926
|
+
payload["submitConfirmedAt"] = None
|
|
927
|
+
payload["submitConfirmedBy"] = None
|
|
928
|
+
payload["status"] = "work_confirmed"
|
|
929
|
+
if submit_path and submit_path.exists():
|
|
930
|
+
payload["submitSha256"] = file_sha256(submit_path)
|
|
931
|
+
elif stage == "submit":
|
|
932
|
+
if submit_path is None or not submit_path.exists():
|
|
933
|
+
raise SystemExit("submit confirmation requires existing submit file")
|
|
934
|
+
confirmed_work_sha = payload.get("workSha256")
|
|
935
|
+
if payload.get("status") not in ("work_confirmed", "submit_built"):
|
|
936
|
+
raise SystemExit("work file is not confirmed; confirm work before submit")
|
|
937
|
+
if confirmed_work_sha != file_sha256(work_path):
|
|
938
|
+
raise SystemExit("work file changed after confirmation; reconfirm work before submit")
|
|
939
|
+
payload["submitSha256"] = file_sha256(submit_path)
|
|
940
|
+
payload["submitConfirmedAt"] = now
|
|
941
|
+
payload["submitConfirmedBy"] = actor
|
|
942
|
+
payload["status"] = "submit_confirmed"
|
|
943
|
+
else:
|
|
944
|
+
raise SystemExit(f"unsupported confirmation stage: {stage}")
|
|
945
|
+
save_meta(meta_path, payload)
|
|
946
|
+
return payload
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
def ensure_submission_allowed(meta_path: Path, work_path: Path, submit_path: Path, raw_path: Path) -> Dict[str, Any]:
|
|
950
|
+
if not meta_path.exists():
|
|
951
|
+
raise SystemExit("missing meta confirmation file")
|
|
952
|
+
raw_meta = load_meta(meta_path)
|
|
953
|
+
meta = ensure_meta_shape(raw_meta, raw_meta.get("stem", "unknown"))
|
|
954
|
+
required = (
|
|
955
|
+
"mode",
|
|
956
|
+
"workspace",
|
|
957
|
+
"workSha256",
|
|
958
|
+
"submitSha256",
|
|
959
|
+
"workConfirmedAt",
|
|
960
|
+
"submitConfirmedAt",
|
|
961
|
+
"status",
|
|
962
|
+
"updateTime",
|
|
963
|
+
)
|
|
964
|
+
missing = [key for key in required if not meta.get(key)]
|
|
965
|
+
if missing:
|
|
966
|
+
raise SystemExit(f"meta confirmation incomplete: missing {', '.join(missing)}")
|
|
967
|
+
if meta.get("status") != "submit_confirmed":
|
|
968
|
+
raise SystemExit("submission blocked: current status is not submit_confirmed")
|
|
969
|
+
current_work_sha = file_sha256(work_path)
|
|
970
|
+
current_submit_sha = file_sha256(submit_path)
|
|
971
|
+
if meta.get("workSha256") != current_work_sha:
|
|
972
|
+
raise SystemExit("submission blocked: work file changed after confirmation")
|
|
973
|
+
if meta.get("submitSha256") != current_submit_sha:
|
|
974
|
+
raise SystemExit("submission blocked: submit file changed after confirmation")
|
|
975
|
+
submit_built_at = meta.get("submitBuiltAt")
|
|
976
|
+
work_confirmed_at = meta.get("workConfirmedAt")
|
|
977
|
+
if submit_built_at and work_confirmed_at and submit_built_at < work_confirmed_at:
|
|
978
|
+
raise SystemExit("submission blocked: submit payload predates work confirmation")
|
|
979
|
+
work_payload = load_json(work_path)
|
|
980
|
+
raw_payload = load_json(raw_path)
|
|
981
|
+
lint, semantic_lint = evaluate_lints(
|
|
982
|
+
work_payload,
|
|
983
|
+
raw_payload=raw_payload,
|
|
984
|
+
allow_preexisting_lint_errors=bool(meta.get("allowPreexistingLintErrors")),
|
|
985
|
+
)
|
|
986
|
+
if lint["errors"]:
|
|
987
|
+
raise SystemExit("submission blocked by work lint: " + "; ".join(lint["errors"]))
|
|
988
|
+
if semantic_lint["errors"]:
|
|
989
|
+
raise SystemExit("submission blocked by semantic lint: " + "; ".join(semantic_lint["errors"]))
|
|
990
|
+
return meta
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
@dataclass
|
|
994
|
+
class ApiClient:
|
|
995
|
+
base_url: str
|
|
996
|
+
workspace: str
|
|
997
|
+
language: str
|
|
998
|
+
cookie_header: str
|
|
999
|
+
timeout: float
|
|
1000
|
+
insecure: bool = False
|
|
1001
|
+
|
|
1002
|
+
def _build_url(self, path: str) -> str:
|
|
1003
|
+
suffix = f"$workspace={urllib.parse.quote(self.workspace)}&$language={urllib.parse.quote(self.language)}"
|
|
1004
|
+
joiner = "&" if "?" in path else "?"
|
|
1005
|
+
return self.base_url.rstrip("/") + path + joiner + suffix
|
|
1006
|
+
|
|
1007
|
+
def request(self, method: str, path: str, body: Optional[dict] = None) -> dict:
|
|
1008
|
+
headers = {
|
|
1009
|
+
"content-type": "application/json",
|
|
1010
|
+
"cookie": self.cookie_header,
|
|
1011
|
+
"accept": "application/json, text/plain, */*",
|
|
1012
|
+
}
|
|
1013
|
+
data = None if body is None else json.dumps(body, ensure_ascii=False).encode("utf-8")
|
|
1014
|
+
req = urllib.request.Request(self._build_url(path), data=data, headers=headers, method=method)
|
|
1015
|
+
context = ssl._create_unverified_context() if self.insecure else None
|
|
1016
|
+
try:
|
|
1017
|
+
with urllib.request.urlopen(req, timeout=self.timeout, context=context) as resp:
|
|
1018
|
+
raw = resp.read().decode("utf-8", "replace")
|
|
1019
|
+
except urllib.error.HTTPError as err:
|
|
1020
|
+
raw = err.read().decode("utf-8", "replace")
|
|
1021
|
+
raise SystemExit(f"HTTP {err.code} {path}: {raw}") from err
|
|
1022
|
+
except urllib.error.URLError as err:
|
|
1023
|
+
raise SystemExit(f"Request failed {path}: {err}") from err
|
|
1024
|
+
payload = json.loads(raw)
|
|
1025
|
+
if isinstance(payload, dict) and payload.get("code") not in (None, 0):
|
|
1026
|
+
raise SystemExit(f"API error {path}: {payload}")
|
|
1027
|
+
return payload
|
|
1028
|
+
|
|
1029
|
+
def get_flow(self, *, flow_type: str = "", key: str = "", draft: bool = False) -> dict:
|
|
1030
|
+
if flow_type:
|
|
1031
|
+
path = f"/api/flow?flow_type={urllib.parse.quote(flow_type)}"
|
|
1032
|
+
elif key:
|
|
1033
|
+
path = f"/api/flow?key={urllib.parse.quote(key)}"
|
|
1034
|
+
else:
|
|
1035
|
+
raise SystemExit("get_flow requires flow_type or key")
|
|
1036
|
+
if draft:
|
|
1037
|
+
path += "&draft=1"
|
|
1038
|
+
path += "&skip_i18n=true"
|
|
1039
|
+
return self.request("GET", path)
|
|
1040
|
+
|
|
1041
|
+
def save_flow_draft(self, *, flow_type: str = "", key: str = "", update_time: str, body: Dict[str, Any]) -> dict:
|
|
1042
|
+
quoted_time = urllib.parse.quote(update_time)
|
|
1043
|
+
if flow_type:
|
|
1044
|
+
path = f"/api/flow?flow_type={urllib.parse.quote(flow_type)}&publish=2&update_time={quoted_time}"
|
|
1045
|
+
elif key:
|
|
1046
|
+
path = f"/api/flow?key={urllib.parse.quote(key)}&publish=2&update_time={quoted_time}"
|
|
1047
|
+
else:
|
|
1048
|
+
raise SystemExit("save_flow_draft requires flow_type or key")
|
|
1049
|
+
return self.request("PUT", path, body)
|
|
1050
|
+
|
|
1051
|
+
def publish_flow(self, *, flow_type: str = "", key: str = "", update_time: str, body: Dict[str, Any]) -> dict:
|
|
1052
|
+
quoted_time = urllib.parse.quote(update_time)
|
|
1053
|
+
if flow_type:
|
|
1054
|
+
path = f"/api/flow?flow_type={urllib.parse.quote(flow_type)}&publish=1&update_time={quoted_time}"
|
|
1055
|
+
elif key:
|
|
1056
|
+
path = f"/api/flow?key={urllib.parse.quote(key)}&publish=1&update_time={quoted_time}"
|
|
1057
|
+
else:
|
|
1058
|
+
raise SystemExit("publish_flow requires flow_type or key")
|
|
1059
|
+
return self.request("PUT", path, body)
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
def resolve_cookie_header(value: Optional[str]) -> str:
|
|
1063
|
+
cookie = value or os.environ.get("BPMAX_COOKIE_HEADER", "")
|
|
1064
|
+
if not cookie:
|
|
1065
|
+
raise SystemExit("missing cookie header: pass --cookie-header or set BPMAX_COOKIE_HEADER")
|
|
1066
|
+
return cookie
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
def resolve_workspace(value: Optional[str]) -> str:
|
|
1070
|
+
workspace = value or os.environ.get("BPMAX_WORKSPACE", "")
|
|
1071
|
+
if not workspace:
|
|
1072
|
+
raise SystemExit("missing workspace: pass --workspace or set BPMAX_WORKSPACE")
|
|
1073
|
+
return workspace
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
def build_client(args: Any) -> ApiClient:
|
|
1077
|
+
return ApiClient(
|
|
1078
|
+
base_url=resolve_base_url(getattr(args, "base_url", None)),
|
|
1079
|
+
workspace=resolve_workspace(getattr(args, "workspace", None)),
|
|
1080
|
+
language=getattr(args, "language", DEFAULT_LANGUAGE),
|
|
1081
|
+
cookie_header=resolve_cookie_header(getattr(args, "cookie_header", None)),
|
|
1082
|
+
timeout=float(getattr(args, "timeout", 30)),
|
|
1083
|
+
insecure=bool(getattr(args, "insecure", False)),
|
|
1084
|
+
)
|