bpmax-cli 0.1.44-beta.8 → 0.1.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/README.md +5 -3
  2. package/dist/bin.js +466 -4578
  3. package/dist/bin.js.map +1 -1
  4. package/package.json +1 -1
  5. package/scripts/install-skills.mjs +0 -98
  6. package/skills/bpmax-auth/SKILL.md +17 -6
  7. package/skills/bpmax-cli/SKILL.md +0 -2
  8. package/skills/bpmax-project/SKILL.md +2 -1
  9. package/skills/bpmax-shared/SKILL.md +1 -1
  10. package/skills/bpmax-api-platform-editor/SKILL.md +0 -321
  11. package/skills/bpmax-api-platform-editor/agents/openai.yaml +0 -4
  12. package/skills/bpmax-api-platform-editor/references/api-doc-debug-workflow.md +0 -34
  13. package/skills/bpmax-api-platform-editor/references/api-proxy-shape.md +0 -41
  14. package/skills/bpmax-api-platform-editor/references/instance-config-shape.md +0 -41
  15. package/skills/bpmax-api-platform-editor/references/platform-api-map.md +0 -52
  16. package/skills/bpmax-api-platform-editor/references/runtime-workflow.md +0 -32
  17. package/skills/bpmax-api-platform-editor/scripts/api_platform_editor_common.py +0 -1276
  18. package/skills/bpmax-api-platform-editor/scripts/build_submit_payload.py +0 -64
  19. package/skills/bpmax-api-platform-editor/scripts/capture_write_contract.py +0 -40
  20. package/skills/bpmax-api-platform-editor/scripts/export_layer_bundle.py +0 -212
  21. package/skills/bpmax-api-platform-editor/scripts/record_doc_debug_acceptance.py +0 -62
  22. package/skills/bpmax-api-platform-editor/scripts/submit_and_verify_layer.py +0 -75
  23. package/skills/bpmax-api-platform-editor/tests/test_api_platform_editor.py +0 -287
  24. package/skills/bpmax-builder-shared/SKILL.md +0 -44
  25. package/skills/bpmax-builder-shared/base_url.py +0 -81
  26. package/skills/bpmax-builder-shared/runtime-script-site-matrix.json +0 -71
  27. package/skills/bpmax-builder-shared/runtime-script-site-matrix.md +0 -34
  28. package/skills/bpmax-builder-shared/runtime-script-template-catalog.md +0 -123
  29. package/skills/bpmax-builder-shared/runtime_script_rules.py +0 -272
  30. package/skills/bpmax-builder-shared/skill_audit.py +0 -374
  31. package/skills/bpmax-builder-shared/template_script_hard_rules.py +0 -280
  32. package/skills/bpmax-builder-shared/tests/test_base_url.py +0 -80
  33. package/skills/bpmax-builder-shared/tests/test_runtime_script_rules.py +0 -115
  34. package/skills/bpmax-builder-shared/tests/test_skill_audit.py +0 -231
  35. package/skills/bpmax-builder-shared/tests/test_template_script_hard_rules.py +0 -281
  36. package/skills/bpmax-config-latest/SKILL.md +0 -71
  37. package/skills/bpmax-console-template-editor/SKILL.md +0 -536
  38. package/skills/bpmax-console-template-editor/agents/openai.yaml +0 -4
  39. package/skills/bpmax-console-template-editor/references/filter-integration.md +0 -60
  40. package/skills/bpmax-console-template-editor/references/lessons-from-resume-dashboard.md +0 -114
  41. package/skills/bpmax-console-template-editor/references/local-temp-workflow.md +0 -69
  42. package/skills/bpmax-console-template-editor/references/module-catalog.md +0 -100
  43. package/skills/bpmax-console-template-editor/references/runtime-page-shape.md +0 -91
  44. package/skills/bpmax-console-template-editor/references/template-shape.md +0 -149
  45. package/skills/bpmax-console-template-editor/scripts/build_submit_payload.py +0 -38
  46. package/skills/bpmax-console-template-editor/scripts/confirm_console_template.py +0 -33
  47. package/skills/bpmax-console-template-editor/scripts/console_template_editor_common.py +0 -964
  48. package/skills/bpmax-console-template-editor/scripts/export_console_template.py +0 -99
  49. package/skills/bpmax-console-template-editor/scripts/lint_console_template.py +0 -46
  50. package/skills/bpmax-console-template-editor/scripts/submit_console_template.py +0 -99
  51. package/skills/bpmax-console-template-editor/tests/test_console_template_editor.py +0 -383
  52. package/skills/bpmax-dataset-field-template-editor/SKILL.md +0 -600
  53. package/skills/bpmax-dataset-field-template-editor/references/create-request-gotchas.md +0 -25
  54. package/skills/bpmax-dataset-field-template-editor/references/field-classify-mapping.md +0 -35
  55. package/skills/bpmax-dataset-field-template-editor/references/nested-field-patterns.md +0 -24
  56. package/skills/bpmax-dataset-field-template-editor/references/runtime-verified-field-page-shape.md +0 -61
  57. package/skills/bpmax-dataset-field-template-editor/references/virtual-field-patterns.md +0 -27
  58. package/skills/bpmax-dataset-field-template-editor/references/work-file-to-submit-mapping.md +0 -127
  59. package/skills/bpmax-dataset-field-template-editor/scripts/build_submit_payload.py +0 -67
  60. package/skills/bpmax-dataset-field-template-editor/scripts/confirm_dataset_field.py +0 -37
  61. package/skills/bpmax-dataset-field-template-editor/scripts/dataset_field_editor_common.py +0 -784
  62. package/skills/bpmax-dataset-field-template-editor/scripts/export_dataset_field.py +0 -62
  63. package/skills/bpmax-dataset-field-template-editor/scripts/init_create_dataset_field.py +0 -104
  64. package/skills/bpmax-dataset-field-template-editor/scripts/inspect_dataset_field_runtime.py +0 -83
  65. package/skills/bpmax-dataset-field-template-editor/scripts/lint_dataset_field_semantics.py +0 -35
  66. package/skills/bpmax-dataset-field-template-editor/scripts/submit_dataset_field.py +0 -95
  67. package/skills/bpmax-dataset-field-template-editor/tests/test_dataset_field_editor.py +0 -709
  68. package/skills/bpmax-dataset-field-template-editor/tests/test_init_create_dataset_field.py +0 -59
  69. package/skills/bpmax-dataset-template-editor/SKILL.md +0 -779
  70. package/skills/bpmax-dataset-template-editor/references/custom-key-usage-patterns.md +0 -18
  71. package/skills/bpmax-dataset-template-editor/references/dataset-script-runtime-matrix.md +0 -73
  72. package/skills/bpmax-dataset-template-editor/references/pre-process-script-authoring-guide.md +0 -186
  73. package/skills/bpmax-dataset-template-editor/references/pre-process-script-example-catalog.md +0 -106
  74. package/skills/bpmax-dataset-template-editor/references/runtime-gotchas.md +0 -28
  75. package/skills/bpmax-dataset-template-editor/references/runtime-verified-dataset-page-shape.md +0 -47
  76. package/skills/bpmax-dataset-template-editor/references/ui-to-backend-field-map.md +0 -23
  77. package/skills/bpmax-dataset-template-editor/references/work-file-to-submit-mapping.md +0 -97
  78. package/skills/bpmax-dataset-template-editor/scripts/basic_table_audit.py +0 -65
  79. package/skills/bpmax-dataset-template-editor/scripts/build_submit_payload.py +0 -38
  80. package/skills/bpmax-dataset-template-editor/scripts/dataset_editor_common.py +0 -650
  81. package/skills/bpmax-dataset-template-editor/scripts/export_dataset.py +0 -155
  82. package/skills/bpmax-dataset-template-editor/scripts/lint_dataset_template.py +0 -42
  83. package/skills/bpmax-dataset-template-editor/scripts/resolve_dataset.py +0 -43
  84. package/skills/bpmax-dataset-template-editor/scripts/scan_custom_key_references.py +0 -27
  85. package/skills/bpmax-dataset-template-editor/scripts/submit_dataset.py +0 -115
  86. package/skills/bpmax-dataset-template-editor/scripts/verify_dataset_list.py +0 -52
  87. package/skills/bpmax-dataset-template-editor/scripts/verify_publish_health.py +0 -39
  88. package/skills/bpmax-dataset-template-editor/tests/test_dataset_editor.py +0 -373
  89. package/skills/bpmax-e2e-flow-config-orchestrator/SKILL.md +0 -177
  90. package/skills/bpmax-e2e-flow-config-orchestrator/agents/openai.yaml +0 -4
  91. package/skills/bpmax-e2e-flow-config-orchestrator/references/orchestration-matrix.md +0 -60
  92. package/skills/bpmax-e2e-flow-test-operator/SKILL.md +0 -394
  93. package/skills/bpmax-e2e-flow-test-operator/agents/openai.yaml +0 -5
  94. package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale.json +0 -97
  95. package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_final_v2.json +0 -105
  96. package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_main.json +0 -36
  97. package/skills/bpmax-e2e-flow-test-operator/profiles/negative_sale_region.json +0 -40
  98. package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +0 -41
  99. package/skills/bpmax-e2e-flow-test-operator/references/failure-update-loop.md +0 -17
  100. package/skills/bpmax-e2e-flow-test-operator/references/filter-field-discovery.md +0 -40
  101. package/skills/bpmax-e2e-flow-test-operator/references/minimal-test-loop.md +0 -24
  102. package/skills/bpmax-e2e-flow-test-operator/references/negative-sale-api-matrix.md +0 -75
  103. package/skills/bpmax-e2e-flow-test-operator/references/profile-schema.md +0 -107
  104. package/skills/bpmax-e2e-flow-test-operator/references/skill-experience-coverage-matrix.md +0 -29
  105. package/skills/bpmax-e2e-flow-test-operator/references/stale-runtime-and-clean-sample-rules.md +0 -54
  106. package/skills/bpmax-e2e-flow-test-operator/references/state-schema.md +0 -83
  107. package/skills/bpmax-e2e-flow-test-operator/scripts/bpmax_session.py +0 -287
  108. package/skills/bpmax-e2e-flow-test-operator/scripts/dealer_sample_on_shelf_plan.json +0 -59
  109. package/skills/bpmax-e2e-flow-test-operator/scripts/dealer_sample_on_shelf_runner.py +0 -687
  110. package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_doc.py +0 -121
  111. package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_state.py +0 -288
  112. package/skills/bpmax-e2e-flow-test-operator/scripts/flow_api_matrix.py +0 -161
  113. package/skills/bpmax-e2e-flow-test-operator/scripts/flow_filter_fields.py +0 -138
  114. package/skills/bpmax-e2e-flow-test-operator/scripts/flow_form_runtime.py +0 -396
  115. package/skills/bpmax-e2e-flow-test-operator/scripts/flow_runner.py +0 -341
  116. package/skills/bpmax-e2e-flow-test-operator/scripts/flow_test_profile.py +0 -185
  117. package/skills/bpmax-e2e-flow-test-operator/tests/test_negative_sale_api_tools.py +0 -138
  118. package/skills/bpmax-feishu-chat-flow-plugin-editor/SKILL.md +0 -69
  119. package/skills/bpmax-feishu-chat-flow-plugin-editor/agents/openai.yaml +0 -4
  120. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-checklist.md +0 -42
  121. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-recipes.md +0 -38
  122. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/config-shape.md +0 -86
  123. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/gate-lint.md +0 -68
  124. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/hoocoo-patterns.md +0 -39
  125. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/runtime-behavior.md +0 -41
  126. package/skills/bpmax-feishu-chat-flow-plugin-editor/references/script-authoring.md +0 -110
  127. package/skills/bpmax-feishu-chat-flow-plugin-editor/scripts/lint_feishu_chat_plugin.py +0 -278
  128. package/skills/bpmax-feishu-chat-flow-plugin-editor/tests/test_lint_feishu_chat_plugin.py +0 -203
  129. package/skills/bpmax-filter-template-editor/SKILL.md +0 -564
  130. package/skills/bpmax-filter-template-editor/references/experience-coverage-matrix.md +0 -38
  131. package/skills/bpmax-filter-template-editor/references/filter-and-flow-binding.md +0 -57
  132. package/skills/bpmax-filter-template-editor/references/filter-content-schema.md +0 -141
  133. package/skills/bpmax-filter-template-editor/references/filter-request-shape.md +0 -287
  134. package/skills/bpmax-filter-template-editor/references/filter-runtime-patterns.md +0 -115
  135. package/skills/bpmax-filter-template-editor/references/runtime-verified-filter-page-shape.md +0 -94
  136. package/skills/bpmax-filter-template-editor/scripts/build_submit_payload.py +0 -25
  137. package/skills/bpmax-filter-template-editor/scripts/confirm_filter_template.py +0 -22
  138. package/skills/bpmax-filter-template-editor/scripts/export_filter_template.py +0 -57
  139. package/skills/bpmax-filter-template-editor/scripts/filter_template_editor_common.py +0 -348
  140. package/skills/bpmax-filter-template-editor/scripts/init_create_filter_template.py +0 -8
  141. package/skills/bpmax-filter-template-editor/scripts/lint_filter_template_semantics.py +0 -26
  142. package/skills/bpmax-filter-template-editor/scripts/submit_filter_template.py +0 -62
  143. package/skills/bpmax-filter-template-editor/tests/test_filter_template_editor.py +0 -231
  144. package/skills/bpmax-flow-template-editor/SKILL.md +0 -1058
  145. package/skills/bpmax-flow-template-editor/agents/openai.yaml +0 -4
  146. package/skills/bpmax-flow-template-editor/references/before-next-step-script-runtime-gotchas.md +0 -62
  147. package/skills/bpmax-flow-template-editor/references/config-surfaces-and-placeholders.md +0 -270
  148. package/skills/bpmax-flow-template-editor/references/diff-strategy.md +0 -67
  149. package/skills/bpmax-flow-template-editor/references/editor-runtime-vs-draft.md +0 -25
  150. package/skills/bpmax-flow-template-editor/references/flow-template-api-workflow.md +0 -174
  151. package/skills/bpmax-flow-template-editor/references/intent-model.md +0 -117
  152. package/skills/bpmax-flow-template-editor/references/lessons-from-price-plan-flow.md +0 -147
  153. package/skills/bpmax-flow-template-editor/references/local-temp-workflow.md +0 -97
  154. package/skills/bpmax-flow-template-editor/references/matrix-flow-form-nav-collaboration.md +0 -165
  155. package/skills/bpmax-flow-template-editor/references/payload-checklist.md +0 -133
  156. package/skills/bpmax-flow-template-editor/references/project-create-runtime-gotchas.md +0 -54
  157. package/skills/bpmax-flow-template-editor/references/requirement-to-node-mapping.md +0 -149
  158. package/skills/bpmax-flow-template-editor/references/runtime-verified-flow-detail-shape.md +0 -41
  159. package/skills/bpmax-flow-template-editor/references/runtime-verified-meta-fields.md +0 -155
  160. package/skills/bpmax-flow-template-editor/references/runtime-verified-node-fields.md +0 -179
  161. package/skills/bpmax-flow-template-editor/references/save-draft-request-shape.md +0 -91
  162. package/skills/bpmax-flow-template-editor/references/script-review-hard-rules.md +0 -93
  163. package/skills/bpmax-flow-template-editor/references/work-file-to-submit-mapping.md +0 -57
  164. package/skills/bpmax-flow-template-editor/scripts/build_submit_payload.py +0 -69
  165. package/skills/bpmax-flow-template-editor/scripts/confirm_flow_template.py +0 -52
  166. package/skills/bpmax-flow-template-editor/scripts/export_flow_template.py +0 -114
  167. package/skills/bpmax-flow-template-editor/scripts/flow_template_editor_common.py +0 -1084
  168. package/skills/bpmax-flow-template-editor/scripts/submit_flow_template.py +0 -159
  169. package/skills/bpmax-flow-template-editor/tests/test_flow_template_editor.py +0 -636
  170. package/skills/bpmax-form-template-editor/SKILL.md +0 -1099
  171. package/skills/bpmax-form-template-editor/agents/openai.yaml +0 -4
  172. package/skills/bpmax-form-template-editor/references/form-template-api-workflow.md +0 -203
  173. package/skills/bpmax-form-template-editor/references/local-temp-workflow.md +0 -125
  174. package/skills/bpmax-form-template-editor/references/payload-checklist.md +0 -77
  175. package/skills/bpmax-form-template-editor/references/sub-form-patterns.md +0 -49
  176. package/skills/bpmax-form-template-editor/scripts/build_submit_payload.py +0 -37
  177. package/skills/bpmax-form-template-editor/scripts/check_form_template_consistency.py +0 -145
  178. package/skills/bpmax-form-template-editor/scripts/confirm_form_template.py +0 -67
  179. package/skills/bpmax-form-template-editor/scripts/export_form_template.py +0 -91
  180. package/skills/bpmax-form-template-editor/scripts/form_template_editor_common.py +0 -1762
  181. package/skills/bpmax-form-template-editor/scripts/lint_form_template_semantics.py +0 -30
  182. package/skills/bpmax-form-template-editor/scripts/record_runtime_acceptance.py +0 -67
  183. package/skills/bpmax-form-template-editor/scripts/submit_form_template.py +0 -163
  184. package/skills/bpmax-form-template-editor/tests/test_form_template_editor.py +0 -1292
  185. package/skills/bpmax-list-template-editor/SKILL.md +0 -468
  186. package/skills/bpmax-list-template-editor/agents/openai.yaml +0 -4
  187. package/skills/bpmax-list-template-editor/references/browser-page-contract.md +0 -81
  188. package/skills/bpmax-list-template-editor/references/content-config-shape.md +0 -148
  189. package/skills/bpmax-list-template-editor/references/dataset-field-mapping.md +0 -60
  190. package/skills/bpmax-list-template-editor/references/list-template-api-workflow.md +0 -103
  191. package/skills/bpmax-list-template-editor/references/local-temp-workflow.md +0 -102
  192. package/skills/bpmax-list-template-editor/references/payload-checklist.md +0 -47
  193. package/skills/bpmax-list-template-editor/references/runtime-verified-workflow.md +0 -140
  194. package/skills/bpmax-list-template-editor/references/special-formats.md +0 -394
  195. package/skills/bpmax-list-template-editor/scripts/build_submit_payload.py +0 -37
  196. package/skills/bpmax-list-template-editor/scripts/confirm_list_template.py +0 -33
  197. package/skills/bpmax-list-template-editor/scripts/export_list_template.py +0 -89
  198. package/skills/bpmax-list-template-editor/scripts/fetch_data_set.py +0 -34
  199. package/skills/bpmax-list-template-editor/scripts/lint_list_template_semantics.py +0 -54
  200. package/skills/bpmax-list-template-editor/scripts/list_template_editor_common.py +0 -955
  201. package/skills/bpmax-list-template-editor/scripts/record_acceptance.py +0 -55
  202. package/skills/bpmax-list-template-editor/scripts/submit_list_template.py +0 -117
  203. package/skills/bpmax-list-template-editor/tests/test_list_template_editor_common.py +0 -441
  204. package/skills/bpmax-memory-protocol/SKILL.md +0 -72
  205. package/skills/bpmax-nav-config-editor/SKILL.md +0 -347
  206. package/skills/bpmax-nav-config-editor/agents/openai.yaml +0 -4
  207. package/skills/bpmax-nav-config-editor/references/api-workflow.md +0 -68
  208. package/skills/bpmax-nav-config-editor/references/config-shape.md +0 -78
  209. package/skills/bpmax-nav-config-editor/references/icon-selection.md +0 -83
  210. package/skills/bpmax-nav-config-editor/references/path-mapping-rules.md +0 -46
  211. package/skills/bpmax-nav-config-editor/references/payload-checklist.md +0 -41
  212. package/skills/bpmax-nav-config-editor/references/runtime-probing.md +0 -47
  213. package/skills/bpmax-nav-config-editor/scripts/build_submit_payload.py +0 -34
  214. package/skills/bpmax-nav-config-editor/scripts/confirm_nav_config.py +0 -32
  215. package/skills/bpmax-nav-config-editor/scripts/export_nav_config.py +0 -56
  216. package/skills/bpmax-nav-config-editor/scripts/lint_nav_config_semantics.py +0 -33
  217. package/skills/bpmax-nav-config-editor/scripts/nav_config_editor_common.py +0 -812
  218. package/skills/bpmax-nav-config-editor/scripts/submit_nav_config.py +0 -44
  219. package/skills/bpmax-nav-config-editor/scripts/verify_nav_config.py +0 -33
  220. package/skills/bpmax-nav-config-editor/tests/test_nav_config_editor.py +0 -358
  221. package/skills/bpmax-nav-config-editor/tests/test_nav_config_editor_common.py +0 -138
  222. package/skills/bpmax-nav-config-editor/tests/test_nav_config_lint.py +0 -58
  223. package/skills/bpmax-nav-config-editor/tests/test_nav_config_submit_verify.py +0 -51
  224. package/skills/bpmax-project-detail-template-editor/SKILL.md +0 -329
  225. package/skills/bpmax-project-detail-template-editor/agents/openai.yaml +0 -4
  226. package/skills/bpmax-project-detail-template-editor/references/local-temp-workflow.md +0 -59
  227. package/skills/bpmax-project-detail-template-editor/references/module-catalog-and-config-notes.md +0 -47
  228. package/skills/bpmax-project-detail-template-editor/references/payload-checklist.md +0 -33
  229. package/skills/bpmax-project-detail-template-editor/references/project-detail-template-api-workflow.md +0 -44
  230. package/skills/bpmax-project-detail-template-editor/scripts/build_submit_payload.py +0 -30
  231. package/skills/bpmax-project-detail-template-editor/scripts/confirm_project_detail_template.py +0 -33
  232. package/skills/bpmax-project-detail-template-editor/scripts/export_project_detail_template.py +0 -87
  233. package/skills/bpmax-project-detail-template-editor/scripts/lint_project_detail_template_semantics.py +0 -37
  234. package/skills/bpmax-project-detail-template-editor/scripts/project_detail_template_editor_common.py +0 -507
  235. package/skills/bpmax-project-detail-template-editor/scripts/submit_project_detail_template.py +0 -120
  236. package/skills/bpmax-project-detail-template-editor/tests/test_project_detail_template_editor.py +0 -369
  237. package/skills/bpmax-role-editor/SKILL.md +0 -251
  238. package/skills/bpmax-role-editor/references/api-workflow.md +0 -30
  239. package/skills/bpmax-role-editor/references/runtime-page-shape.md +0 -18
  240. package/skills/bpmax-role-editor/references/work-file-mapping.md +0 -32
  241. package/skills/bpmax-role-editor/scripts/build_submit_payload.py +0 -38
  242. package/skills/bpmax-role-editor/scripts/confirm_role.py +0 -33
  243. package/skills/bpmax-role-editor/scripts/export_role.py +0 -163
  244. package/skills/bpmax-role-editor/scripts/lint_role_semantics.py +0 -38
  245. package/skills/bpmax-role-editor/scripts/role_editor_common.py +0 -1231
  246. package/skills/bpmax-role-editor/scripts/submit_role.py +0 -144
  247. package/skills/bpmax-role-editor/tests/test_role_editor.py +0 -343
  248. package/skills/bpmax-user-mock-operator/SKILL.md +0 -106
  249. package/skills/bpmax-user-mock-operator/agents/openai.yaml +0 -4
  250. package/skills/bpmax-user-mock-operator/scripts/switch_user_identity.py +0 -37
  251. package/skills/bpmax-user-mock-operator/scripts/user_mock_operator_common.py +0 -136
  252. package/skills/bpmax-user-mock-operator/tests/test_user_mock_operator.py +0 -138
  253. package/skills/form-control-library/SKILL.md +0 -82
  254. package/skills/form-control-library/agents/openai.yaml +0 -4
  255. package/skills/form-control-library/references/form-controls.md +0 -199
  256. package/skills/form-control-library/references/form-template-submit-schema.md +0 -180
  257. package/skills/form-control-library/references/group-select-runtime.md +0 -191
  258. package/skills/form-control-library/scripts/rebuild_form_control_library.py +0 -55
@@ -1,1762 +0,0 @@
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 re
9
- import sys
10
- import ssl
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" / "form-template-editor"
29
- TMP_SUBDIRS = ("raw", "work", "meta", "submit", "diffs", "result")
30
- RULE_ID_KEYS = ("form_rule_id", "form_template_id", "id")
31
- VALUE_ID_KEYS = ("template_id", "id")
32
- MODELING_GATE_REQUIRED_KEYS = ("minimalFormMode", "detailEntryMode", "longTermControl", "layoutReviewed")
33
- RUNTIME_ACCEPTANCE_PENDING = "pending"
34
- RUNTIME_ACCEPTANCE_ACCEPTED = "accepted"
35
- RUNTIME_ACCEPTANCE_FAILED = "failed"
36
- RUNTIME_ACCEPTANCE_NOT_REQUIRED = "not_required"
37
-
38
- from template_script_hard_rules import scan_named_script_surfaces
39
-
40
-
41
- def utc_now_iso() -> str:
42
- return datetime.now(timezone.utc).isoformat()
43
-
44
-
45
- def ensure_tmp_dirs() -> None:
46
- for part in TMP_SUBDIRS:
47
- (TMP_ROOT / part).mkdir(parents=True, exist_ok=True)
48
-
49
-
50
- def paths_for(stem: str) -> Dict[str, Path]:
51
- ensure_tmp_dirs()
52
- return {
53
- "raw": TMP_ROOT / "raw" / f"{stem}.json",
54
- "work": TMP_ROOT / "work" / f"{stem}.json",
55
- "meta": TMP_ROOT / "meta" / f"{stem}.json",
56
- "submit": TMP_ROOT / "submit" / f"{stem}.json",
57
- "work_diff": TMP_ROOT / "diffs" / f"{stem}.work.diff.txt",
58
- "submit_diff": TMP_ROOT / "diffs" / f"{stem}.submit.diff.txt",
59
- "response": TMP_ROOT / "result" / f"{stem}.response.json",
60
- "draft_readback": TMP_ROOT / "result" / f"{stem}.draft.readback.json",
61
- "published_readback": TMP_ROOT / "result" / f"{stem}.published.readback.json",
62
- "verify": TMP_ROOT / "result" / f"{stem}.verify.json",
63
- "semantic_lint": TMP_ROOT / "result" / f"{stem}.semantic-lint.json",
64
- "drift": TMP_ROOT / "result" / f"{stem}.drift.json",
65
- "runtime_acceptance": TMP_ROOT / "result" / f"{stem}.runtime-acceptance.json",
66
- }
67
-
68
-
69
- def dump_json(path: Path, payload: Any) -> None:
70
- path.parent.mkdir(parents=True, exist_ok=True)
71
- path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
72
-
73
-
74
- def load_json(path: Path) -> Any:
75
- return json.loads(path.read_text(encoding="utf-8"))
76
-
77
-
78
- def file_sha256(path: Path) -> str:
79
- return hashlib.sha256(path.read_bytes()).hexdigest()
80
-
81
-
82
- def load_meta(path: Path) -> Dict[str, Any]:
83
- if not path.exists():
84
- return {}
85
- payload = load_json(path)
86
- if not isinstance(payload, dict):
87
- raise SystemExit(f"invalid meta file, expected object: {path}")
88
- return payload
89
-
90
-
91
- def save_meta(path: Path, payload: Dict[str, Any]) -> None:
92
- dump_json(path, payload)
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(
101
- stable_json_lines(before),
102
- stable_json_lines(after),
103
- fromfile=before_label,
104
- tofile=after_label,
105
- )
106
- path.parent.mkdir(parents=True, exist_ok=True)
107
- text = "".join(diff)
108
- path.write_text(text or "# no diff\n", encoding="utf-8")
109
-
110
-
111
- def create_stem(workspace: str, sample_template_id: Any | None = None, flow_type: str | None = None) -> str:
112
- if sample_template_id not in (None, ""):
113
- return f"create-{workspace}-{sample_template_id}"
114
- if flow_type:
115
- return f"create-{workspace}-{flow_type}"
116
- raise SystemExit("create stem requires sample template id or flow type")
117
-
118
-
119
- def strip_known_ids(payload: Dict[str, Any], keys: Iterable[str]) -> Dict[str, Any]:
120
- cloned = copy.deepcopy(payload)
121
- for key in keys:
122
- cloned.pop(key, None)
123
- return cloned
124
-
125
-
126
- def keep_id_keys(payload: Dict[str, Any], keys: Iterable[str]) -> list[str]:
127
- return [key for key in keys if key in payload]
128
-
129
-
130
- def extract_api_data(payload: Dict[str, Any]) -> Any:
131
- if isinstance(payload, dict) and "data" in payload:
132
- return payload.get("data")
133
- return payload
134
-
135
-
136
- def normalize_numeric_id(value: Any) -> int | None:
137
- if isinstance(value, int):
138
- return value
139
- if isinstance(value, str) and value.isdigit():
140
- return int(value)
141
- return None
142
-
143
-
144
- def assert_form_template_draft_id(template_id: Any, detail: Dict[str, Any], action: str) -> None:
145
- origin_template_id = normalize_numeric_id(detail.get("origin_template_id"))
146
- if origin_template_id and origin_template_id > 0:
147
- raise SystemExit(
148
- f"refusing to {action} published form-template id {template_id}; "
149
- f"use draft id {origin_template_id}. Published ids are readback-only."
150
- )
151
-
152
-
153
- def _extract_field_pairs(rule_rows: Any, value_items: Any) -> tuple[Dict[str, Dict[str, Any]], list[str]]:
154
- value_by_field: Dict[str, Dict[str, Any]] = {}
155
- if isinstance(value_items, list):
156
- for item in value_items:
157
- if isinstance(item, dict) and item.get("field"):
158
- value_by_field[item["field"]] = item
159
-
160
- pairs: Dict[str, Dict[str, Any]] = {}
161
- order: list[str] = []
162
- if not isinstance(rule_rows, list):
163
- return pairs, order
164
- for row in rule_rows:
165
- if not isinstance(row, list):
166
- continue
167
- for cell in row:
168
- if not isinstance(cell, dict):
169
- continue
170
- field = cell.get("field")
171
- if not field:
172
- continue
173
- pairs[field] = {
174
- "rule": cell,
175
- "value": value_by_field.get(field, {}),
176
- }
177
- order.append(field)
178
- return pairs, order
179
-
180
-
181
- def _field_identity(summary: Dict[str, Any]) -> str:
182
- key = summary.get("key")
183
- field = summary.get("field")
184
- if key not in (None, ""):
185
- return f"key:{key}"
186
- return f"field:{field}"
187
-
188
-
189
- def _modeling_gate_template() -> Dict[str, Any]:
190
- return {
191
- "minimalFormMode": None,
192
- "detailEntryMode": None,
193
- "longTermControl": None,
194
- "layoutReviewed": False,
195
- "checkedAt": None,
196
- "checkedBy": None,
197
- }
198
-
199
-
200
- def _normalize_modeling_gate(modeling_gate: Optional[Dict[str, Any]]) -> Dict[str, Any]:
201
- payload = _modeling_gate_template()
202
- if modeling_gate:
203
- payload.update(modeling_gate)
204
- payload["layoutReviewed"] = bool(payload.get("layoutReviewed"))
205
- return payload
206
-
207
-
208
- def _runtime_acceptance_template() -> Dict[str, Any]:
209
- return {
210
- "required": False,
211
- "flowType": None,
212
- "acceptancePage": None,
213
- "freshInstanceRequired": False,
214
- "decisionSource": None,
215
- "updatedAt": None,
216
- "updatedBy": None,
217
- }
218
-
219
-
220
- def _normalize_runtime_acceptance(runtime_acceptance: Optional[Dict[str, Any]]) -> Dict[str, Any]:
221
- payload = _runtime_acceptance_template()
222
- if runtime_acceptance:
223
- payload.update(runtime_acceptance)
224
- payload["required"] = bool(payload.get("required"))
225
- payload["freshInstanceRequired"] = bool(payload.get("freshInstanceRequired"))
226
- return payload
227
-
228
-
229
- def _normalize_string_list(values: Any) -> list[str]:
230
- if not isinstance(values, list):
231
- return []
232
- normalized: list[str] = []
233
- seen: set[str] = set()
234
- for value in values:
235
- text = str(value).strip()
236
- if not text or text in seen:
237
- continue
238
- seen.add(text)
239
- normalized.append(text)
240
- return normalized
241
-
242
-
243
- def _normalize_lint_hints(lint_hints: Optional[Dict[str, Any]]) -> Dict[str, Any]:
244
- payload = dict(lint_hints or {})
245
- payload["autoReadonlyKeys"] = _normalize_string_list(payload.get("autoReadonlyKeys"))
246
- return payload
247
-
248
-
249
- def modeling_gate_missing_keys(modeling_gate: Dict[str, Any]) -> list[str]:
250
- missing: list[str] = []
251
- for key in MODELING_GATE_REQUIRED_KEYS:
252
- value = modeling_gate.get(key)
253
- if key == "layoutReviewed":
254
- if value is not True:
255
- missing.append(key)
256
- elif value in (None, ""):
257
- missing.append(key)
258
- return missing
259
-
260
-
261
- def _safe_json(value: Any) -> str:
262
- return json.dumps(value, ensure_ascii=False, sort_keys=True)
263
-
264
-
265
- def _build_field_bundles(detail: Dict[str, Any], *, mode: str) -> tuple[list[list[str]], Dict[str, Dict[str, Any]]]:
266
- rows = detail.get("rule") or []
267
- values = detail.get("value") or []
268
- if not isinstance(rows, list):
269
- raise SystemExit("template detail rule is not an array")
270
- if not isinstance(values, list):
271
- raise SystemExit("template detail value is not an array")
272
-
273
- value_by_field: Dict[str, Dict[str, Any]] = {}
274
- for item in values:
275
- if not isinstance(item, dict):
276
- raise SystemExit("template detail value contains non-object item")
277
- field = item.get("field")
278
- if not field:
279
- raise SystemExit("template detail value item missing field")
280
- value_by_field[field] = item
281
-
282
- layout: list[list[str]] = []
283
- fields: Dict[str, Dict[str, Any]] = {}
284
-
285
- for row_idx, row in enumerate(rows):
286
- if not isinstance(row, list):
287
- raise SystemExit(f"template detail rule row {row_idx} is not an array")
288
- layout_row: list[str] = []
289
- for col_idx, cell in enumerate(row):
290
- if not isinstance(cell, dict):
291
- raise SystemExit(f"template detail rule[{row_idx}][{col_idx}] is not an object")
292
- field = cell.get("field")
293
- if not field:
294
- raise SystemExit(f"template detail rule[{row_idx}][{col_idx}] missing field")
295
- if field in fields:
296
- raise SystemExit(f"duplicate field in rule layout: {field}")
297
- if field not in value_by_field:
298
- raise SystemExit(f"rule field missing matching value skeleton: {field}")
299
- rule_payload = copy.deepcopy(cell)
300
- value_payload = copy.deepcopy(value_by_field[field])
301
- keep_ids = {
302
- "rule": keep_id_keys(rule_payload, RULE_ID_KEYS),
303
- "value": keep_id_keys(value_payload, VALUE_ID_KEYS),
304
- }
305
- if mode == "create":
306
- rule_payload = strip_known_ids(rule_payload, RULE_ID_KEYS)
307
- value_payload = strip_known_ids(value_payload, VALUE_ID_KEYS)
308
- fields[field] = {
309
- "rule": rule_payload,
310
- "value": value_payload,
311
- "keepIds": keep_ids,
312
- }
313
- layout_row.append(field)
314
- layout.append(layout_row)
315
-
316
- for field, value_payload in value_by_field.items():
317
- if field in fields:
318
- continue
319
- cloned_value = copy.deepcopy(value_payload)
320
- keep_ids = {
321
- "rule": [],
322
- "value": keep_id_keys(cloned_value, VALUE_ID_KEYS),
323
- }
324
- if mode == "create":
325
- cloned_value = strip_known_ids(cloned_value, VALUE_ID_KEYS)
326
- fields[field] = {
327
- "rule": None,
328
- "value": cloned_value,
329
- "keepIds": keep_ids,
330
- }
331
-
332
- return layout, fields
333
-
334
-
335
- def detail_to_work_payload(
336
- detail: Dict[str, Any],
337
- *,
338
- mode: str,
339
- sample_template_id: Any | None = None,
340
- ) -> Dict[str, Any]:
341
- if mode not in ("edit", "create"):
342
- raise SystemExit(f"unsupported work payload mode: {mode}")
343
- layout, fields = _build_field_bundles(detail, mode=mode)
344
- return {
345
- "id": detail.get("id") if mode == "edit" else None,
346
- "mode": mode,
347
- "sampleTemplateId": sample_template_id,
348
- "basic": {
349
- "name": detail.get("name", ""),
350
- "desc": detail.get("desc", ""),
351
- "category": detail.get("category", ""),
352
- "option": copy.deepcopy(detail.get("option") or {}),
353
- },
354
- "layout": layout,
355
- "fields": fields,
356
- "removedFields": [],
357
- }
358
-
359
-
360
- def build_create_raw_payload(sample_detail: Dict[str, Any], *, sample_template_id: Any) -> Dict[str, Any]:
361
- return {
362
- "mode": "create-skeleton-export",
363
- "sampleTemplateId": sample_template_id,
364
- "sampleDetail": sample_detail,
365
- }
366
-
367
-
368
- def _normalize_removed_fields(value: Any) -> set[str]:
369
- if value in (None, ""):
370
- return set()
371
- if not isinstance(value, list):
372
- raise SystemExit("removedFields must be an array")
373
- result = set()
374
- for item in value:
375
- if not isinstance(item, str) or not item:
376
- raise SystemExit("removedFields must contain non-empty strings")
377
- result.add(item)
378
- return result
379
-
380
-
381
- def _validate_field_bundle(field: str, bundle: Any) -> tuple[Dict[str, Any], Dict[str, Any]]:
382
- if not isinstance(bundle, dict):
383
- raise SystemExit(f"field bundle must be object: {field}")
384
- rule_payload = bundle.get("rule")
385
- value_payload = bundle.get("value")
386
- if not isinstance(rule_payload, dict):
387
- raise SystemExit(f"field bundle missing rule object: {field}")
388
- if not isinstance(value_payload, dict):
389
- raise SystemExit(f"field bundle missing value object: {field}")
390
- if rule_payload.get("field") != field:
391
- raise SystemExit(f"rule field mismatch for {field}")
392
- if value_payload.get("field") != field:
393
- raise SystemExit(f"value field mismatch for {field}")
394
- if value_payload.get("field_type") != rule_payload.get("type"):
395
- raise SystemExit(f"value field_type mismatch for {field}")
396
- if rule_payload.get("lambda") and rule_payload.get("quickValue") is not True:
397
- raise SystemExit(f"field {field} has lambda but quickValue is not true")
398
- return rule_payload, value_payload
399
-
400
-
401
- def build_submit_payload(work: Dict[str, Any]) -> Dict[str, Any]:
402
- mode = work.get("mode")
403
- if mode not in ("edit", "create"):
404
- raise SystemExit("work payload missing valid mode")
405
- basic = work.get("basic")
406
- if not isinstance(basic, dict):
407
- raise SystemExit("work payload missing basic section")
408
- layout = work.get("layout")
409
- if not isinstance(layout, list):
410
- raise SystemExit("work payload missing layout array")
411
- fields = work.get("fields")
412
- if not isinstance(fields, dict):
413
- raise SystemExit("work payload missing fields object")
414
- removed_fields = _normalize_removed_fields(work.get("removedFields"))
415
-
416
- rule_rows: list[list[Dict[str, Any]]] = []
417
- value_items: list[Dict[str, Any]] = []
418
- seen_fields: set[str] = set()
419
-
420
- for row_idx, row in enumerate(layout):
421
- if not isinstance(row, list):
422
- raise SystemExit(f"layout row {row_idx} is not an array")
423
- submit_row: list[Dict[str, Any]] = []
424
- for ref in row:
425
- if not isinstance(ref, str) or not ref:
426
- raise SystemExit(f"layout row {row_idx} contains invalid field ref")
427
- if ref in removed_fields:
428
- raise SystemExit(f"layout references removed field: {ref}")
429
- if ref not in fields:
430
- raise SystemExit(f"layout references unknown field: {ref}")
431
- if ref in seen_fields:
432
- raise SystemExit(f"duplicate field in layout: {ref}")
433
- rule_payload, value_payload = _validate_field_bundle(ref, fields[ref])
434
- submit_row.append(copy.deepcopy(rule_payload))
435
- value_items.append(copy.deepcopy(value_payload))
436
- seen_fields.add(ref)
437
- if submit_row:
438
- rule_rows.append(submit_row)
439
-
440
- orphan_fields = sorted(set(fields.keys()) - seen_fields - removed_fields)
441
- if orphan_fields:
442
- raise SystemExit(f"fields exist in work payload but are missing from layout/removedFields: {', '.join(orphan_fields)}")
443
-
444
- if mode == "create":
445
- rule_rows = [[strip_known_ids(item, RULE_ID_KEYS) for item in row] for row in rule_rows]
446
- value_items = [strip_known_ids(item, VALUE_ID_KEYS) for item in value_items]
447
-
448
- return {
449
- "name": basic.get("name", ""),
450
- "desc": basic.get("desc", ""),
451
- "category": basic.get("category", ""),
452
- "option": copy.deepcopy(basic.get("option") or {}),
453
- "rule": rule_rows,
454
- "value": value_items,
455
- }
456
-
457
-
458
- def _row_shapes(rows: Any) -> list[int]:
459
- if not isinstance(rows, list):
460
- return []
461
- shapes: list[int] = []
462
- for row in rows:
463
- shapes.append(len(row) if isinstance(row, list) else -1)
464
- return shapes
465
-
466
-
467
- def _field_order(rows: Any) -> list[str]:
468
- order: list[str] = []
469
- if not isinstance(rows, list):
470
- return order
471
- for row in rows:
472
- if not isinstance(row, list):
473
- continue
474
- for item in row:
475
- if isinstance(item, dict) and item.get("field"):
476
- order.append(item["field"])
477
- return order
478
-
479
-
480
- def _field_summary(rule_payload: Dict[str, Any], value_payload: Dict[str, Any]) -> Dict[str, Any]:
481
- props = rule_payload.get("props") or {}
482
- sub_form_template = props.get("form_template") or {}
483
- return {
484
- "field": rule_payload.get("field"),
485
- "type": rule_payload.get("type"),
486
- "key": value_payload.get("key"),
487
- "lambdaPresent": bool(rule_payload.get("lambda")),
488
- "customeValidatePresent": bool(rule_payload.get("customeValidate")),
489
- "lambdaFields": copy.deepcopy(rule_payload.get("lambdaFields", [])),
490
- "quickValue": rule_payload.get("quickValue"),
491
- "hidden": rule_payload.get("hidden"),
492
- "display": rule_payload.get("display"),
493
- "disabled": props.get("disabled"),
494
- "visibilityCondition": copy.deepcopy(rule_payload.get("visibilityCondition")),
495
- "lambdaDisableOnPreview": rule_payload.get("lambdaDisableOnPreview"),
496
- "subFormTemplateId": sub_form_template.get("id"),
497
- "subFormMode": props.get("mode"),
498
- }
499
-
500
-
501
- _AUTOFILL_DATA_FIELD_TYPES = {
502
- "raw",
503
- }
504
-
505
- _VISIBLE_AUTOFILL_MANUAL_OVERRIDE_TYPES = {
506
- "plugin_scan_input",
507
- "sub_form",
508
- }
509
-
510
- _INTERACTIVE_TRIGGER_TYPES = {
511
- "group_select",
512
- "i_input",
513
- "plugin_scan_input",
514
- "es_project_selector",
515
- }
516
-
517
-
518
- def _extract_balanced_brace_content(text: str, start_idx: int) -> tuple[Optional[str], int]:
519
- if start_idx >= len(text) or text[start_idx] != "{":
520
- return None, start_idx
521
- depth = 0
522
- in_string: Optional[str] = None
523
- escaped = False
524
- for idx in range(start_idx, len(text)):
525
- ch = text[idx]
526
- if in_string:
527
- if escaped:
528
- escaped = False
529
- elif ch == "\\":
530
- escaped = True
531
- elif ch == in_string:
532
- in_string = None
533
- continue
534
- if ch in ("'", '"', "`"):
535
- in_string = ch
536
- continue
537
- if ch == "{":
538
- depth += 1
539
- continue
540
- if ch == "}":
541
- depth -= 1
542
- if depth == 0:
543
- return text[start_idx + 1 : idx], idx
544
- return None, len(text)
545
-
546
-
547
- def _extract_top_level_object_keys(content: str) -> list[str]:
548
- keys: list[str] = []
549
- idx = 0
550
- length = len(content)
551
- while idx < length:
552
- while idx < length and content[idx] in " \t\r\n,":
553
- idx += 1
554
- if idx >= length:
555
- break
556
- key: Optional[str] = None
557
- if content[idx] in ("'", '"'):
558
- quote = content[idx]
559
- idx += 1
560
- start = idx
561
- escaped = False
562
- buffer: list[str] = []
563
- while idx < length:
564
- ch = content[idx]
565
- if escaped:
566
- buffer.append(ch)
567
- escaped = False
568
- elif ch == "\\":
569
- escaped = True
570
- elif ch == quote:
571
- break
572
- else:
573
- buffer.append(ch)
574
- idx += 1
575
- key = "".join(buffer)
576
- idx += 1
577
- else:
578
- match = re.match(r"[A-Za-z_$][A-Za-z0-9_$]*", content[idx:])
579
- if match:
580
- key = match.group(0)
581
- idx += len(key)
582
- while idx < length and content[idx].isspace():
583
- idx += 1
584
- if not key or idx >= length or content[idx] != ":":
585
- while idx < length and content[idx] != ",":
586
- idx += 1
587
- continue
588
- keys.append(key)
589
- idx += 1
590
- depth_brace = depth_bracket = depth_paren = 0
591
- in_string: Optional[str] = None
592
- escaped = False
593
- while idx < length:
594
- ch = content[idx]
595
- if in_string:
596
- if escaped:
597
- escaped = False
598
- elif ch == "\\":
599
- escaped = True
600
- elif ch == in_string:
601
- in_string = None
602
- idx += 1
603
- continue
604
- if ch in ("'", '"', "`"):
605
- in_string = ch
606
- elif ch == "{":
607
- depth_brace += 1
608
- elif ch == "}":
609
- if depth_brace > 0:
610
- depth_brace -= 1
611
- elif ch == "[":
612
- depth_bracket += 1
613
- elif ch == "]":
614
- if depth_bracket > 0:
615
- depth_bracket -= 1
616
- elif ch == "(":
617
- depth_paren += 1
618
- elif ch == ")":
619
- if depth_paren > 0:
620
- depth_paren -= 1
621
- elif ch == "," and depth_brace == 0 and depth_bracket == 0 and depth_paren == 0:
622
- idx += 1
623
- break
624
- idx += 1
625
- deduped: list[str] = []
626
- seen: set[str] = set()
627
- for key in keys:
628
- if key in seen:
629
- continue
630
- seen.add(key)
631
- deduped.append(key)
632
- return deduped
633
-
634
-
635
- def _extract_identifier_token(text: str, start_idx: int) -> tuple[Optional[str], int]:
636
- match = re.match(r"[A-Za-z_$][A-Za-z0-9_$]*", text[start_idx:])
637
- if not match:
638
- return None, start_idx
639
- identifier = match.group(0)
640
- return identifier, start_idx + len(identifier)
641
-
642
-
643
- def _extract_spread_identifiers(content: str) -> list[str]:
644
- identifiers: list[str] = []
645
- idx = 0
646
- length = len(content)
647
- in_string: Optional[str] = None
648
- escaped = False
649
- depth_brace = depth_bracket = depth_paren = 0
650
- while idx < length:
651
- ch = content[idx]
652
- if in_string:
653
- if escaped:
654
- escaped = False
655
- elif ch == "\\":
656
- escaped = True
657
- elif ch == in_string:
658
- in_string = None
659
- idx += 1
660
- continue
661
- if ch in ("'", '"', "`"):
662
- in_string = ch
663
- idx += 1
664
- continue
665
- if ch == "{":
666
- depth_brace += 1
667
- idx += 1
668
- continue
669
- if ch == "}":
670
- if depth_brace > 0:
671
- depth_brace -= 1
672
- idx += 1
673
- continue
674
- if ch == "[":
675
- depth_bracket += 1
676
- idx += 1
677
- continue
678
- if ch == "]":
679
- if depth_bracket > 0:
680
- depth_bracket -= 1
681
- idx += 1
682
- continue
683
- if ch == "(":
684
- depth_paren += 1
685
- idx += 1
686
- continue
687
- if ch == ")":
688
- if depth_paren > 0:
689
- depth_paren -= 1
690
- idx += 1
691
- continue
692
- if ch == "." and content[idx : idx + 3] == "..." and depth_brace == 0 and depth_bracket == 0 and depth_paren == 0:
693
- ident, end_idx = _extract_identifier_token(content, idx + 3)
694
- if ident:
695
- identifiers.append(ident)
696
- idx = end_idx
697
- continue
698
- idx += 1
699
- deduped: list[str] = []
700
- seen: set[str] = set()
701
- for identifier in identifiers:
702
- if identifier in seen:
703
- continue
704
- seen.add(identifier)
705
- deduped.append(identifier)
706
- return deduped
707
-
708
-
709
- def _extract_object_literal_bindings(script: str) -> Dict[str, list[str]]:
710
- bindings: Dict[str, list[str]] = {}
711
- pattern = re.compile(r"(?:const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*")
712
- for match in pattern.finditer(script):
713
- binding_name = match.group(1)
714
- idx = match.end()
715
- while idx < len(script) and script[idx].isspace():
716
- idx += 1
717
- content, _ = _extract_balanced_brace_content(script, idx)
718
- if content is None:
719
- continue
720
- keys = _extract_top_level_object_keys(content)
721
- for spread_name in _extract_spread_identifiers(content):
722
- keys.extend(bindings.get(spread_name, []))
723
- deduped: list[str] = []
724
- seen: set[str] = set()
725
- for key in keys:
726
- if key in seen:
727
- continue
728
- seen.add(key)
729
- deduped.append(key)
730
- bindings[binding_name] = deduped
731
- return bindings
732
-
733
-
734
- def _extract_autofill_helper_aliases(script: str) -> list[str]:
735
- aliases = []
736
- patterns = [
737
- r"(?:const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*\([^)]*\)\s*=>\s*ctx\.\$setValueByKeyToValue\s*\(",
738
- r"(?:const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*\([^)]*\)\s*=>\s*\{[\s\S]*?ctx\.\$setValueByKeyToValue\s*\(",
739
- r"function\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\([^)]*\)\s*\{\s*return\s+ctx\.\$setValueByKeyToValue\s*\(",
740
- r"function\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\([^)]*\)\s*\{[\s\S]*?ctx\.\$setValueByKeyToValue\s*\(",
741
- ]
742
- for pattern in patterns:
743
- for match in re.finditer(pattern, script):
744
- aliases.append(match.group(1))
745
- deduped: list[str] = []
746
- seen: set[str] = set()
747
- for alias in aliases:
748
- if alias in seen:
749
- continue
750
- seen.add(alias)
751
- deduped.append(alias)
752
- return deduped
753
-
754
-
755
- def _extract_autofill_target_field_ids(script: str) -> list[str]:
756
- field_ids = []
757
- for match in re.finditer(r"\$API\.setValue\(\s*['\"]([^'\"]+)['\"]", script):
758
- field_ids.append(match.group(1))
759
- deduped: list[str] = []
760
- seen: set[str] = set()
761
- for field_id in field_ids:
762
- if field_id in seen:
763
- continue
764
- seen.add(field_id)
765
- deduped.append(field_id)
766
- return deduped
767
-
768
-
769
- def _extract_autofill_target_keys(script: str, known_keys: Optional[Iterable[str]] = None) -> list[str]:
770
- marker = "ctx.$setValueByKeyToValue"
771
- keys: list[str] = []
772
- object_bindings = _extract_object_literal_bindings(script)
773
- normalized_known_keys = {
774
- str(item).strip() for item in (known_keys or []) if str(item).strip()
775
- }
776
- search_from = 0
777
- while True:
778
- marker_idx = script.find(marker, search_from)
779
- if marker_idx < 0:
780
- break
781
- paren_idx = script.find("(", marker_idx + len(marker))
782
- if paren_idx < 0:
783
- break
784
- idx = paren_idx + 1
785
- while idx < len(script) and script[idx].isspace():
786
- idx += 1
787
- content, end_idx = _extract_balanced_brace_content(script, idx)
788
- if content is not None:
789
- keys.extend(_extract_top_level_object_keys(content))
790
- for spread_name in _extract_spread_identifiers(content):
791
- keys.extend(object_bindings.get(spread_name, []))
792
- search_from = end_idx + 1
793
- continue
794
- ident, end_idx = _extract_identifier_token(script, idx)
795
- if ident:
796
- keys.extend(object_bindings.get(ident, []))
797
- search_from = end_idx + 1
798
- else:
799
- search_from = idx + 1
800
- for alias in _extract_autofill_helper_aliases(script):
801
- search_from = 0
802
- alias_marker = f"{alias}("
803
- while True:
804
- marker_idx = script.find(alias_marker, search_from)
805
- if marker_idx < 0:
806
- break
807
- paren_idx = script.find("(", marker_idx + len(alias))
808
- if paren_idx < 0:
809
- break
810
- idx = paren_idx + 1
811
- while idx < len(script) and script[idx].isspace():
812
- idx += 1
813
- content, end_idx = _extract_balanced_brace_content(script, idx)
814
- if content is not None:
815
- keys.extend(_extract_top_level_object_keys(content))
816
- for spread_name in _extract_spread_identifiers(content):
817
- keys.extend(object_bindings.get(spread_name, []))
818
- search_from = end_idx + 1
819
- continue
820
- ident, end_idx = _extract_identifier_token(script, idx)
821
- if ident:
822
- keys.extend(object_bindings.get(ident, []))
823
- search_from = end_idx + 1
824
- else:
825
- search_from = idx + 1
826
- deduped: list[str] = []
827
- seen: set[str] = set()
828
- for key in keys:
829
- key_text = str(key or "").strip()
830
- if not key_text:
831
- continue
832
- if normalized_known_keys and key_text not in normalized_known_keys:
833
- continue
834
- if key_text in seen:
835
- continue
836
- seen.add(key_text)
837
- deduped.append(key_text)
838
- return deduped
839
-
840
-
841
- def _autofill_target_requires_readonly(
842
- rule_payload: Dict[str, Any],
843
- *,
844
- hinted_external_autofill: bool = False,
845
- ) -> bool:
846
- if hinted_external_autofill:
847
- return True
848
- target_type = rule_payload.get("type")
849
- if target_type in _AUTOFILL_DATA_FIELD_TYPES:
850
- return False
851
- if target_type in _VISIBLE_AUTOFILL_MANUAL_OVERRIDE_TYPES:
852
- return not bool(str(rule_payload.get("lambda") or "").strip())
853
- return True
854
-
855
-
856
- def summarize_verification(submit_payload: Dict[str, Any], readback_detail: Dict[str, Any]) -> Dict[str, Any]:
857
- checks: Dict[str, Dict[str, Any]] = {}
858
- ok = True
859
-
860
- top_level_keys = ("name", "desc", "category", "option")
861
- for key in top_level_keys:
862
- expected = submit_payload.get(key)
863
- actual = readback_detail.get(key)
864
- match = expected == actual
865
- checks[key] = {"match": match, "expected": expected, "actual": actual}
866
- ok = ok and match
867
-
868
- expected_rows = submit_payload.get("rule") or []
869
- actual_rows = readback_detail.get("rule") or []
870
- row_count_match = len(expected_rows) == len(actual_rows)
871
- checks["ruleRowCount"] = {"match": row_count_match, "expected": len(expected_rows), "actual": len(actual_rows)}
872
- ok = ok and row_count_match
873
-
874
- expected_shapes = _row_shapes(expected_rows)
875
- actual_shapes = _row_shapes(actual_rows)
876
- shape_match = expected_shapes == actual_shapes
877
- checks["rowShapes"] = {"match": shape_match, "expected": expected_shapes, "actual": actual_shapes}
878
- ok = ok and shape_match
879
-
880
- expected_values = submit_payload.get("value") or []
881
- actual_values = readback_detail.get("value") or []
882
- value_count_match = len(expected_values) == len(actual_values)
883
- checks["valueCount"] = {"match": value_count_match, "expected": len(expected_values), "actual": len(actual_values)}
884
- ok = ok and value_count_match
885
-
886
- expected_order = _field_order(expected_rows)
887
- actual_order = _field_order(actual_rows)
888
- field_order_match = expected_order == actual_order
889
- checks["fieldOrder"] = {"match": field_order_match, "expected": expected_order, "actual": actual_order}
890
- ok = ok and field_order_match
891
-
892
- expected_value_by_field = {
893
- item.get("field"): item for item in expected_values if isinstance(item, dict) and item.get("field")
894
- }
895
- actual_value_by_field = {
896
- item.get("field"): item for item in actual_values if isinstance(item, dict) and item.get("field")
897
- }
898
-
899
- per_field: Dict[str, Dict[str, Any]] = {}
900
- for row in expected_rows:
901
- for rule_payload in row:
902
- field = rule_payload.get("field")
903
- if not field:
904
- continue
905
- actual_rule = None
906
- for actual_row in actual_rows:
907
- if not isinstance(actual_row, list):
908
- continue
909
- for cell in actual_row:
910
- if isinstance(cell, dict) and cell.get("field") == field:
911
- actual_rule = cell
912
- break
913
- if actual_rule:
914
- break
915
- actual_value = actual_value_by_field.get(field)
916
- expected_value = expected_value_by_field.get(field)
917
- if not actual_rule or not actual_value or not expected_value:
918
- per_field[field] = {
919
- "match": False,
920
- "expected": _field_summary(rule_payload, expected_value or {}),
921
- "actual": _field_summary(actual_rule or {"field": field}, actual_value or {"field": field}),
922
- }
923
- ok = False
924
- continue
925
- expected_summary = _field_summary(rule_payload, expected_value)
926
- actual_summary = _field_summary(actual_rule, actual_value)
927
- match = expected_summary == actual_summary
928
- per_field[field] = {
929
- "match": match,
930
- "expected": expected_summary,
931
- "actual": actual_summary,
932
- }
933
- ok = ok and match
934
-
935
- return {
936
- "ok": ok,
937
- "checks": checks,
938
- "fields": per_field,
939
- "submittedFields": expected_order,
940
- "readbackOnlyFields": sorted(set(actual_value_by_field) - set(expected_value_by_field)),
941
- }
942
-
943
-
944
- def _find_template_dirs(template_uuid: str) -> tuple[Optional[Path], Optional[Path]]:
945
- base = REPO_ROOT / "think_form_template"
946
- draft = base / f"uuid'{template_uuid}___is_del'0___origin_template_id'0"
947
- published = base / f"uuid'{template_uuid}___is_del'0___origin_template_id'!0"
948
- return (draft if draft.exists() else None, published if published.exists() else None)
949
-
950
-
951
- def _load_field_rules(template_dir: Path) -> Dict[str, dict]:
952
- base = template_dir / "think_form_rule"
953
- result: Dict[str, dict] = {}
954
- for rule_file in sorted(base.glob("*/form_rule.rule")):
955
- data = load_json(rule_file)
956
- field = data.get("field") or f"__anon__:{rule_file.parent.name}"
957
- result[field] = data
958
- return result
959
-
960
-
961
- def _summarize_repo_rule(rule: dict) -> dict:
962
- return {
963
- "field": rule.get("field"),
964
- "type": rule.get("type"),
965
- "key": rule.get("key"),
966
- "lambdaPresent": bool(rule.get("lambda")),
967
- "customeValidatePresent": bool(rule.get("customeValidate")),
968
- "lambdaFields": copy.deepcopy(rule.get("lambdaFields", [])),
969
- "quickValue": rule.get("quickValue"),
970
- }
971
-
972
-
973
- def build_publish_safety_report(submit_payload: Dict[str, Any], template_uuid: Optional[str]) -> Dict[str, Any]:
974
- report = {
975
- "ok": True,
976
- "skipped": False,
977
- "errors": [],
978
- "warnings": [],
979
- "templateUuid": template_uuid,
980
- }
981
- if not template_uuid:
982
- report["skipped"] = True
983
- report["warnings"].append("template uuid unavailable; skipped published consistency gate")
984
- return report
985
-
986
- _, published_dir = _find_template_dirs(template_uuid)
987
- if not published_dir:
988
- report["skipped"] = True
989
- report["warnings"].append(f"published mirror not found for template uuid {template_uuid}")
990
- return report
991
-
992
- published_rules = _load_field_rules(published_dir)
993
- published_summaries = {
994
- _field_identity(_summarize_repo_rule(rule)): _summarize_repo_rule(rule) for rule in published_rules.values()
995
- }
996
- submit_pairs, _ = _extract_field_pairs(submit_payload.get("rule"), submit_payload.get("value"))
997
- submit_summaries = {
998
- _field_identity(_field_summary(pair["rule"], pair["value"])): _field_summary(pair["rule"], pair["value"])
999
- for pair in submit_pairs.values()
1000
- }
1001
-
1002
- missing_in_submit = sorted(set(published_summaries) - set(submit_summaries))
1003
- if missing_in_submit:
1004
- report["errors"].append(f"submit payload is missing published fields: {', '.join(missing_in_submit)}")
1005
-
1006
- for identity in sorted(set(published_summaries) & set(submit_summaries)):
1007
- published = published_summaries[identity]
1008
- submit = submit_summaries[identity]
1009
- if published.get("type") != submit.get("type"):
1010
- report["errors"].append(
1011
- f"{identity} type mismatch vs published: submit={submit.get('type')} published={published.get('type')}"
1012
- )
1013
- if published.get("key") != submit.get("key"):
1014
- report["errors"].append(
1015
- f"{identity} key mismatch vs published: submit={submit.get('key')} published={published.get('key')}"
1016
- )
1017
- if published.get("lambdaPresent") and not submit.get("lambdaPresent"):
1018
- report["errors"].append(f"{identity} drops published lambda")
1019
- if published.get("customeValidatePresent") and not submit.get("customeValidatePresent"):
1020
- report["errors"].append(f"{identity} drops published customeValidate")
1021
- if published.get("lambdaFields") and not submit.get("lambdaFields"):
1022
- report["errors"].append(f"{identity} drops published lambdaFields")
1023
- if published.get("quickValue") is True and submit.get("quickValue") is not True:
1024
- report["errors"].append(f"{identity} regresses published quickValue=true")
1025
-
1026
- report["ok"] = not report["errors"]
1027
- return report
1028
-
1029
-
1030
- def lint_form_template_semantics(
1031
- work_payload: Dict[str, Any],
1032
- *,
1033
- meta: Optional[Dict[str, Any]] = None,
1034
- submit_payload: Optional[Dict[str, Any]] = None,
1035
- ) -> Dict[str, Any]:
1036
- report: Dict[str, Any] = {
1037
- "ok": True,
1038
- "errors": [],
1039
- "warnings": [],
1040
- "checks": {},
1041
- }
1042
- normalized_meta = ensure_meta_shape(meta or {}, str((meta or {}).get("stem", work_payload.get("id", "unknown"))))
1043
- modeling_gate = _normalize_modeling_gate(normalized_meta.get("modelingGate"))
1044
- lint_hints = _normalize_lint_hints(normalized_meta.get("lintHints"))
1045
- missing_gate = modeling_gate_missing_keys(modeling_gate)
1046
- report["checks"]["modelingGate"] = {
1047
- "passed": not missing_gate,
1048
- "value": modeling_gate,
1049
- "missing": missing_gate,
1050
- }
1051
- report["checks"]["lintHints"] = lint_hints
1052
- if missing_gate:
1053
- report["errors"].append(
1054
- "modeling gate incomplete: " + ", ".join(missing_gate)
1055
- )
1056
-
1057
- payload = submit_payload or build_submit_payload(work_payload)
1058
- pairs, _ = _extract_field_pairs(payload.get("rule"), payload.get("value"))
1059
- field_reports: Dict[str, Dict[str, Any]] = {}
1060
- has_sub_form = False
1061
- for field, pair in pairs.items():
1062
- rule_payload = pair.get("rule") or {}
1063
- value_payload = pair.get("value") or {}
1064
- field_errors: list[str] = []
1065
- field_warnings: list[str] = []
1066
- field_type = rule_payload.get("type")
1067
- lambda_script = rule_payload.get("lambda") or ""
1068
- custom_validate = rule_payload.get("customeValidate") or {}
1069
- if lambda_script and rule_payload.get("quickValue") is not True:
1070
- field_errors.append("lambda exists but quickValue is not true")
1071
- if (
1072
- lambda_script
1073
- and "ctx.$esQuery" in lambda_script
1074
- and field_type != "es_project_selector"
1075
- ):
1076
- field_errors.append("ordinary field lambda must not call ctx.$esQuery")
1077
- field_key = str(value_payload.get("key") or "").strip()
1078
- hidden = rule_payload.get("hidden") is True
1079
- disabled = ((rule_payload.get("props") or {}).get("disabled")) is True
1080
- if (
1081
- not hidden
1082
- and field_type == "raw"
1083
- and rule_payload.get("lambdaInit") is True
1084
- and bool(str(lambda_script).strip())
1085
- and not disabled
1086
- ):
1087
- field_errors.append("visible auto-filled raw/data field must be disabled or converted to hidden data field")
1088
- custom_content = ""
1089
- custom_trigger = None
1090
- if isinstance(custom_validate, dict):
1091
- custom_content = str(custom_validate.get("content") or "").strip()
1092
- custom_trigger = custom_validate.get("trigger")
1093
- elif custom_validate:
1094
- custom_content = str(custom_validate).strip()
1095
- if custom_content:
1096
- if rule_payload.get("shouldValidate") is not True:
1097
- field_errors.append("customeValidate requires shouldValidate=true")
1098
- if not custom_trigger:
1099
- field_errors.append("customeValidate requires trigger")
1100
- if (
1101
- field_type in _INTERACTIVE_TRIGGER_TYPES
1102
- and hidden is not True
1103
- and rule_payload.get("display") is not False
1104
- and disabled
1105
- and (lambda_script or custom_content)
1106
- ):
1107
- field_warnings.append(
1108
- "interactive trigger field is statically disabled; verify users can still start scan/selection flow"
1109
- )
1110
- if field_type == "raw":
1111
- hidden_value = rule_payload.get("hidden")
1112
- disabled_value = ((rule_payload.get("props") or {}).get("disabled"))
1113
- visibility_condition = rule_payload.get("visibilityCondition")
1114
- if hidden_value is not True and disabled_value is True and not visibility_condition:
1115
- field_warnings.append("raw field uses always-visible disabled shape; verify hidden + visibilityCondition")
1116
- if field_type == "sub_form":
1117
- has_sub_form = True
1118
- props = rule_payload.get("props") or {}
1119
- form_template = props.get("form_template") or {}
1120
- template_id = form_template.get("id")
1121
- if not template_id:
1122
- field_errors.append("sub_form requires published child template id")
1123
- if form_template.get("origin_template_id") == 0:
1124
- field_errors.append("sub_form must not bind draft child template id")
1125
- if form_template.get("status") not in (None, 1):
1126
- field_errors.append("sub_form child template should be published (status=1)")
1127
- if field_type == "es_project_selector":
1128
- template_text = str(((rule_payload.get("props") or {}).get("template")) or "").strip()
1129
- if (work_payload.get("mode") == "create") and template_text not in ("", "{}"):
1130
- field_warnings.append(
1131
- "create mode es_project_selector should default to minimal template unless custom sample is verified"
1132
- )
1133
- if field_errors:
1134
- report["errors"].extend([f"{field}: {message}" for message in field_errors])
1135
- if field_warnings:
1136
- report["warnings"].extend([f"{field}: {message}" for message in field_warnings])
1137
- field_reports[field] = {
1138
- "errors": field_errors,
1139
- "warnings": field_warnings,
1140
- "summary": _field_summary(rule_payload, value_payload),
1141
- }
1142
-
1143
- script_surfaces = []
1144
- for field, pair in pairs.items():
1145
- rule_payload = pair.get("rule") or {}
1146
- custom_validate = rule_payload.get("customeValidate") or {}
1147
- if isinstance(rule_payload.get("lambda"), str) and rule_payload.get("lambda").strip():
1148
- script_surfaces.append({"path": f"fields.{field}.lambda", "script": rule_payload.get("lambda")})
1149
- if isinstance(custom_validate, dict) and isinstance(custom_validate.get("content"), str) and custom_validate.get("content").strip():
1150
- script_surfaces.append({"path": f"fields.{field}.customeValidate.content", "script": custom_validate.get("content")})
1151
- props = rule_payload.get("props") or {}
1152
- if isinstance(props.get("template"), str) and props.get("template").strip():
1153
- script_surfaces.append({"path": f"fields.{field}.props.template", "script": props.get("template")})
1154
- hard_rule_report = scan_named_script_surfaces(script_surfaces)
1155
- report["checks"]["scriptHardRules"] = hard_rule_report["findings"]
1156
- report["errors"].extend(hard_rule_report["errors"])
1157
-
1158
- autofill_target_sources: Dict[str, list[str]] = {}
1159
- autofill_target_field_sources: Dict[str, list[str]] = {}
1160
- known_keys = [
1161
- key
1162
- for key in (
1163
- (pair.get("value") or {}).get("key")
1164
- for pair in pairs.values()
1165
- )
1166
- if key not in (None, "")
1167
- ]
1168
- for field, pair in pairs.items():
1169
- rule_payload = pair.get("rule") or {}
1170
- custom_validate = rule_payload.get("customeValidate") or {}
1171
- script_inputs = []
1172
- if isinstance(rule_payload.get("lambda"), str) and rule_payload.get("lambda").strip():
1173
- script_inputs.append((f"fields.{field}.lambda", rule_payload.get("lambda")))
1174
- if isinstance(custom_validate, dict) and isinstance(custom_validate.get("content"), str) and custom_validate.get("content").strip():
1175
- script_inputs.append((f"fields.{field}.customeValidate.content", custom_validate.get("content")))
1176
- for path, script in script_inputs:
1177
- for target_key in _extract_autofill_target_keys(script, known_keys):
1178
- autofill_target_sources.setdefault(target_key, []).append(path)
1179
- for target_field in _extract_autofill_target_field_ids(script):
1180
- autofill_target_field_sources.setdefault(target_field, []).append(path)
1181
- for target_key in lint_hints.get("autoReadonlyKeys", []):
1182
- autofill_target_sources.setdefault(target_key, []).append("meta.lintHints.autoReadonlyKeys")
1183
- for field, pair in pairs.items():
1184
- rule_payload = pair.get("rule") or {}
1185
- value_payload = pair.get("value") or {}
1186
- target_key = str(value_payload.get("key") or "").strip()
1187
- if not target_key:
1188
- continue
1189
- lambda_script = rule_payload.get("lambda")
1190
- if not isinstance(lambda_script, str) or not lambda_script.strip():
1191
- continue
1192
- hidden = rule_payload.get("hidden") is True or rule_payload.get("display") is False
1193
- if rule_payload.get("type") in _INTERACTIVE_TRIGGER_TYPES and not hidden:
1194
- continue
1195
- if not rule_payload.get("quickValue"):
1196
- continue
1197
- autofill_target_sources.setdefault(target_key, []).append(f"fields.{field}.lambda:self")
1198
-
1199
- autofill_checks: Dict[str, Dict[str, Any]] = {}
1200
- field_by_key = {
1201
- (pair.get("value") or {}).get("key"): field
1202
- for field, pair in pairs.items()
1203
- if (pair.get("value") or {}).get("key")
1204
- }
1205
- for target_key, sources in autofill_target_sources.items():
1206
- hinted_external_autofill = "meta.lintHints.autoReadonlyKeys" in sources
1207
- target_field = field_by_key.get(target_key)
1208
- if not target_field:
1209
- autofill_checks[target_key] = {
1210
- "sources": sources,
1211
- "field": None,
1212
- "ok": False,
1213
- "reason": "target key not found in submit payload",
1214
- "hintedExternalAutofill": hinted_external_autofill,
1215
- }
1216
- message = (
1217
- f"auto-filled key {target_key} from {', '.join(sources)} not found in submit payload; "
1218
- "verify hidden/data field mapping"
1219
- )
1220
- if hinted_external_autofill:
1221
- report["errors"].append(message)
1222
- else:
1223
- report["warnings"].append(message)
1224
- continue
1225
- target_rule = (pairs[target_field].get("rule") or {})
1226
- target_props = target_rule.get("props") or {}
1227
- hidden = target_rule.get("hidden") is True or target_rule.get("display") is False
1228
- disabled = target_props.get("disabled") is True
1229
- source_fields = [
1230
- path.split(".")[1]
1231
- for path in sources
1232
- if isinstance(path, str) and path.startswith("fields.") and len(path.split(".")) > 2
1233
- ]
1234
- self_managed_interactive_field = (
1235
- target_field in source_fields and target_rule.get("type") in _INTERACTIVE_TRIGGER_TYPES
1236
- and not hidden
1237
- )
1238
- requires_readonly = _autofill_target_requires_readonly(
1239
- target_rule,
1240
- hinted_external_autofill=hinted_external_autofill,
1241
- )
1242
- if self_managed_interactive_field:
1243
- requires_readonly = False
1244
- data_field_semantics = target_rule.get("type") in _AUTOFILL_DATA_FIELD_TYPES
1245
- ok = disabled or data_field_semantics or not requires_readonly
1246
- autofill_checks[target_key] = {
1247
- "sources": sources,
1248
- "field": target_field,
1249
- "title": target_rule.get("title"),
1250
- "type": target_rule.get("type"),
1251
- "hidden": target_rule.get("hidden"),
1252
- "display": target_rule.get("display"),
1253
- "disabled": target_props.get("disabled"),
1254
- "hintedExternalAutofill": hinted_external_autofill,
1255
- "selfManagedInteractiveField": self_managed_interactive_field,
1256
- "ok": ok,
1257
- }
1258
- if not ok:
1259
- report["errors"].append(
1260
- f"{target_field}: auto-filled field key={target_key} must be non-editable (props.disabled=true or data-field semantics such as raw); hidden editable inputs are not sufficient"
1261
- )
1262
- for target_field, sources in autofill_target_field_sources.items():
1263
- target_pair = pairs.get(target_field)
1264
- if not target_pair:
1265
- autofill_checks[target_field] = {
1266
- "sources": sources,
1267
- "field": target_field,
1268
- "ok": False,
1269
- "reason": "target field id not found in submit payload",
1270
- }
1271
- report["warnings"].append(
1272
- f"auto-filled field id {target_field} from {', '.join(sources)} not found in submit payload; verify hidden/data field mapping"
1273
- )
1274
- continue
1275
- target_rule = (target_pair.get("rule") or {})
1276
- target_props = target_rule.get("props") or {}
1277
- hidden = target_rule.get("hidden") is True or target_rule.get("display") is False
1278
- disabled = target_props.get("disabled") is True
1279
- requires_readonly = _autofill_target_requires_readonly(target_rule)
1280
- data_field_semantics = target_rule.get("type") in _AUTOFILL_DATA_FIELD_TYPES
1281
- ok = disabled or data_field_semantics or not requires_readonly
1282
- autofill_checks[target_field] = {
1283
- "sources": sources,
1284
- "field": target_field,
1285
- "title": target_rule.get("title"),
1286
- "type": target_rule.get("type"),
1287
- "hidden": target_rule.get("hidden"),
1288
- "display": target_rule.get("display"),
1289
- "disabled": target_props.get("disabled"),
1290
- "ok": ok,
1291
- }
1292
- if not ok:
1293
- report["errors"].append(
1294
- f"{target_field}: auto-filled field must be non-editable (props.disabled=true or data-field semantics such as raw); hidden editable inputs are not sufficient"
1295
- )
1296
- report["checks"]["autoFilledFields"] = autofill_checks
1297
- readonly_raw_targets = {
1298
- check.get("field")
1299
- for check in autofill_checks.values()
1300
- if isinstance(check, dict)
1301
- and check.get("field")
1302
- and check.get("type") == "raw"
1303
- and check.get("disabled") is True
1304
- and check.get("ok") is True
1305
- }
1306
- if readonly_raw_targets:
1307
- report["warnings"] = [
1308
- message
1309
- for message in report["warnings"]
1310
- if not (
1311
- ": raw field uses always-visible disabled shape; verify hidden + visibilityCondition" in message
1312
- and message.split(":", 1)[0] in readonly_raw_targets
1313
- )
1314
- ]
1315
- for field, field_report in field_reports.items():
1316
- if field not in readonly_raw_targets:
1317
- continue
1318
- field_report["warnings"] = [
1319
- message
1320
- for message in field_report.get("warnings", [])
1321
- if message != "raw field uses always-visible disabled shape; verify hidden + visibilityCondition"
1322
- ]
1323
-
1324
- detail_entry_mode = modeling_gate.get("detailEntryMode")
1325
- if detail_entry_mode == "sub_form_required" and not has_sub_form:
1326
- report["errors"].append("modeling gate requires sub_form, but submit payload has no sub_form field")
1327
-
1328
- report["checks"]["fields"] = field_reports
1329
- report["ok"] = not report["errors"]
1330
- return report
1331
-
1332
-
1333
- def _drift_focus(detail: Dict[str, Any]) -> Dict[str, Any]:
1334
- pairs, _ = _extract_field_pairs(detail.get("rule"), detail.get("value"))
1335
- fields: Dict[str, Dict[str, Any]] = {}
1336
- for field, pair in pairs.items():
1337
- rule_payload = pair.get("rule") or {}
1338
- value_payload = pair.get("value") or {}
1339
- props = rule_payload.get("props") or {}
1340
- sub_form = props.get("form_template") or {}
1341
- fields[field] = {
1342
- "type": rule_payload.get("type"),
1343
- "key": value_payload.get("key"),
1344
- "hidden": rule_payload.get("hidden"),
1345
- "visibilityCondition": copy.deepcopy(rule_payload.get("visibilityCondition")),
1346
- "quickValue": rule_payload.get("quickValue"),
1347
- "lambdaDisableOnPreview": rule_payload.get("lambdaDisableOnPreview"),
1348
- "subFormTemplateId": sub_form.get("id"),
1349
- "subFormMode": props.get("mode"),
1350
- }
1351
- return {
1352
- "topLevel": {
1353
- "name": detail.get("name"),
1354
- "desc": detail.get("desc"),
1355
- "category": detail.get("category"),
1356
- },
1357
- "fields": fields,
1358
- }
1359
-
1360
-
1361
- def _compare_drift(before: Dict[str, Any], after: Dict[str, Any], *, before_label: str, after_label: str) -> Dict[str, Any]:
1362
- before_state = _drift_focus(before)
1363
- after_state = _drift_focus(after)
1364
- changed_top: Dict[str, Dict[str, Any]] = {}
1365
- for key, value in before_state["topLevel"].items():
1366
- after_value = after_state["topLevel"].get(key)
1367
- if value != after_value:
1368
- changed_top[key] = {before_label: value, after_label: after_value}
1369
-
1370
- before_fields = before_state["fields"]
1371
- after_fields = after_state["fields"]
1372
- changed_fields: Dict[str, Dict[str, Dict[str, Any]]] = {}
1373
- for field in sorted(set(before_fields) | set(after_fields)):
1374
- if field not in before_fields:
1375
- changed_fields[field] = {"added": after_fields[field]}
1376
- continue
1377
- if field not in after_fields:
1378
- changed_fields[field] = {"removed": before_fields[field]}
1379
- continue
1380
- field_changes: Dict[str, Dict[str, Any]] = {}
1381
- for key, value in before_fields[field].items():
1382
- after_value = after_fields[field].get(key)
1383
- if value != after_value:
1384
- field_changes[key] = {before_label: value, after_label: after_value}
1385
- if field_changes:
1386
- changed_fields[field] = field_changes
1387
-
1388
- return {
1389
- "changedTopLevel": changed_top,
1390
- "changedFields": changed_fields,
1391
- "ok": not changed_top and not changed_fields,
1392
- }
1393
-
1394
-
1395
- def build_drift_report(
1396
- submit_payload: Dict[str, Any],
1397
- draft_readback: Dict[str, Any],
1398
- published_readback: Dict[str, Any],
1399
- ) -> Dict[str, Any]:
1400
- submit_to_draft = _compare_drift(submit_payload, draft_readback, before_label="submit", after_label="draft")
1401
- draft_to_published = _compare_drift(draft_readback, published_readback, before_label="draft", after_label="published")
1402
- return {
1403
- "ok": submit_to_draft["ok"] and draft_to_published["ok"],
1404
- "submitToDraft": submit_to_draft,
1405
- "draftToPublished": draft_to_published,
1406
- }
1407
-
1408
-
1409
- def build_runtime_acceptance_payload(
1410
- *,
1411
- required: bool,
1412
- flow_type: Optional[str],
1413
- expected_draft_id: Optional[int],
1414
- expected_published_id: Optional[int],
1415
- flow_meta_form_template_id: Optional[int] = None,
1416
- flow_live_form_template_id: Optional[int] = None,
1417
- flow_draft_form_template_id: Optional[int] = None,
1418
- actual_runtime_form_template_id: Optional[int] = None,
1419
- acceptance_page: Optional[str] = None,
1420
- used_fresh_instance: Optional[bool] = None,
1421
- fresh_instance_required: bool = False,
1422
- acceptance_level: str = "template_only",
1423
- runtime_reference_source: Optional[str] = None,
1424
- notes: Optional[str] = None,
1425
- ) -> Dict[str, Any]:
1426
- live_form_template_id = flow_live_form_template_id if flow_live_form_template_id is not None else flow_meta_form_template_id
1427
- flow_ref_match = (
1428
- live_form_template_id == expected_published_id
1429
- if live_form_template_id is not None and expected_published_id is not None
1430
- else None
1431
- )
1432
- runtime_load_match = (
1433
- actual_runtime_form_template_id == expected_published_id
1434
- if actual_runtime_form_template_id is not None and expected_published_id is not None
1435
- else None
1436
- )
1437
- fresh_instance_ok = (
1438
- bool(used_fresh_instance)
1439
- if fresh_instance_required and used_fresh_instance is not None
1440
- else (True if not fresh_instance_required else None)
1441
- )
1442
-
1443
- if acceptance_level not in ("template_only", "runtime_live", "runtime_diagnosis"):
1444
- raise SystemExit(f"unsupported acceptance level: {acceptance_level}")
1445
-
1446
- if not required or acceptance_level == "template_only":
1447
- status = RUNTIME_ACCEPTANCE_NOT_REQUIRED
1448
- ok = True
1449
- used_fresh_instance = None if used_fresh_instance is None else used_fresh_instance
1450
- else:
1451
- if acceptance_level == "runtime_diagnosis":
1452
- diagnostic_checks = (flow_ref_match, runtime_load_match)
1453
- if any(check is False for check in diagnostic_checks if check is not None):
1454
- status = RUNTIME_ACCEPTANCE_FAILED
1455
- ok = False
1456
- else:
1457
- status = RUNTIME_ACCEPTANCE_PENDING
1458
- ok = False
1459
- else:
1460
- if runtime_reference_source == "browser_runtime":
1461
- checks = (runtime_load_match, fresh_instance_ok)
1462
- else:
1463
- checks = (flow_ref_match, runtime_load_match, fresh_instance_ok)
1464
- if all(check is True for check in checks):
1465
- status = RUNTIME_ACCEPTANCE_ACCEPTED
1466
- ok = True
1467
- elif any(check is False for check in checks if check is not None):
1468
- status = RUNTIME_ACCEPTANCE_FAILED
1469
- ok = False
1470
- else:
1471
- status = RUNTIME_ACCEPTANCE_PENDING
1472
- ok = False
1473
-
1474
- return {
1475
- "flowType": flow_type,
1476
- "expectedDraftId": expected_draft_id,
1477
- "expectedPublishedId": expected_published_id,
1478
- "flowMetaFormTemplateId": live_form_template_id,
1479
- "flowLiveFormTemplateId": live_form_template_id,
1480
- "flowDraftFormTemplateId": flow_draft_form_template_id,
1481
- "actualRuntimeFormTemplateId": actual_runtime_form_template_id,
1482
- "acceptancePage": acceptance_page,
1483
- "usedFreshInstance": used_fresh_instance,
1484
- "required": required,
1485
- "freshInstanceRequired": fresh_instance_required,
1486
- "acceptanceLevel": acceptance_level,
1487
- "runtimeReferenceSource": runtime_reference_source,
1488
- "status": status,
1489
- "ok": ok,
1490
- "checks": {
1491
- "flowReferenceMatchesPublished": flow_ref_match,
1492
- "runtimeLoadMatchesPublished": runtime_load_match,
1493
- "freshInstanceSatisfied": fresh_instance_ok,
1494
- },
1495
- "notes": notes or "",
1496
- }
1497
-
1498
-
1499
- def ensure_meta_shape(meta: Dict[str, Any], stem: str) -> Dict[str, Any]:
1500
- payload = dict(meta)
1501
- payload.setdefault("stem", stem)
1502
- payload.setdefault("status", "exported")
1503
- payload["modelingGate"] = _normalize_modeling_gate(payload.get("modelingGate"))
1504
- payload["runtimeAcceptance"] = _normalize_runtime_acceptance(payload.get("runtimeAcceptance"))
1505
- payload["lintHints"] = _normalize_lint_hints(payload.get("lintHints"))
1506
- payload.setdefault("modelingGatePassed", False)
1507
- return payload
1508
-
1509
-
1510
- def write_export_meta(
1511
- path: Path,
1512
- *,
1513
- stem: str,
1514
- mode: str,
1515
- template_id: Any,
1516
- template_uuid: Any,
1517
- sample_template_id: Any,
1518
- workspace: str,
1519
- language: str,
1520
- request_url: str,
1521
- raw_path: Path,
1522
- work_path: Path,
1523
- ) -> Dict[str, Any]:
1524
- payload = ensure_meta_shape(load_meta(path), stem)
1525
- payload.update(
1526
- {
1527
- "mode": mode,
1528
- "templateId": template_id,
1529
- "templateUuid": template_uuid,
1530
- "sampleTemplateId": sample_template_id,
1531
- "workspace": workspace,
1532
- "language": language,
1533
- "requestUrl": request_url,
1534
- "rawSha256": file_sha256(raw_path),
1535
- "workSha256": file_sha256(work_path),
1536
- "submitSha256": None,
1537
- "exportedAt": utc_now_iso(),
1538
- "submitBuiltAt": None,
1539
- "workConfirmedAt": None,
1540
- "workConfirmedBy": None,
1541
- "submitConfirmedAt": None,
1542
- "submitConfirmedBy": None,
1543
- "modelingGate": _modeling_gate_template(),
1544
- "modelingGatePassed": False,
1545
- "runtimeAcceptance": _runtime_acceptance_template(),
1546
- "status": "exported",
1547
- }
1548
- )
1549
- save_meta(path, payload)
1550
- return payload
1551
-
1552
-
1553
- def update_build_meta(meta_path: Path, *, stem: str, work_path: Path, submit_path: Path) -> Dict[str, Any]:
1554
- payload = ensure_meta_shape(load_meta(meta_path), stem)
1555
- previous_work_sha = payload.get("workSha256")
1556
- current_work_sha = file_sha256(work_path)
1557
- if payload.get("workConfirmedAt") and previous_work_sha != current_work_sha:
1558
- payload["workConfirmedAt"] = None
1559
- payload["workConfirmedBy"] = None
1560
- payload["modelingGatePassed"] = False
1561
- payload["workSha256"] = current_work_sha
1562
- payload["submitSha256"] = file_sha256(submit_path)
1563
- payload["submitBuiltAt"] = utc_now_iso()
1564
- payload["submitConfirmedAt"] = None
1565
- payload["submitConfirmedBy"] = None
1566
- payload["status"] = "submit_built"
1567
- save_meta(meta_path, payload)
1568
- return payload
1569
-
1570
-
1571
- def update_confirmation_state(
1572
- meta_path: Path,
1573
- *,
1574
- stem: str,
1575
- actor: str,
1576
- stage: str,
1577
- work_path: Path,
1578
- submit_path: Optional[Path] = None,
1579
- modeling_gate: Optional[Dict[str, Any]] = None,
1580
- runtime_acceptance: Optional[Dict[str, Any]] = None,
1581
- ) -> Dict[str, Any]:
1582
- payload = ensure_meta_shape(load_meta(meta_path), stem)
1583
- payload["workSha256"] = file_sha256(work_path)
1584
- now = utc_now_iso()
1585
- if stage == "work":
1586
- normalized_gate = _normalize_modeling_gate(modeling_gate)
1587
- normalized_gate["checkedAt"] = now
1588
- normalized_gate["checkedBy"] = actor
1589
- missing = modeling_gate_missing_keys(normalized_gate)
1590
- if missing:
1591
- raise SystemExit("work confirmation requires modeling gate decisions: " + ", ".join(missing))
1592
- payload["modelingGate"] = normalized_gate
1593
- payload["modelingGatePassed"] = True
1594
- if runtime_acceptance is not None or "runtimeAcceptance" not in payload:
1595
- normalized_runtime = _normalize_runtime_acceptance(runtime_acceptance)
1596
- normalized_runtime["updatedAt"] = now
1597
- normalized_runtime["updatedBy"] = actor
1598
- payload["runtimeAcceptance"] = normalized_runtime
1599
- payload["workConfirmedAt"] = now
1600
- payload["workConfirmedBy"] = actor
1601
- payload["submitConfirmedAt"] = None
1602
- payload["submitConfirmedBy"] = None
1603
- payload["submitSha256"] = file_sha256(submit_path) if submit_path and submit_path.exists() else payload.get("submitSha256")
1604
- payload["status"] = "work_confirmed"
1605
- elif stage == "submit":
1606
- if submit_path is None or not submit_path.exists():
1607
- raise SystemExit("submit confirmation requires an existing submit file")
1608
- confirmed_work_sha = payload.get("workSha256")
1609
- current_work_sha = file_sha256(work_path)
1610
- if payload.get("status") not in ("work_confirmed", "submit_built") or confirmed_work_sha != current_work_sha:
1611
- raise SystemExit("work file is not confirmed or has changed; reconfirm work before submit")
1612
- payload["submitSha256"] = file_sha256(submit_path)
1613
- payload["submitConfirmedAt"] = now
1614
- payload["submitConfirmedBy"] = actor
1615
- payload["status"] = "submit_confirmed"
1616
- else:
1617
- raise SystemExit(f"unsupported confirmation stage: {stage}")
1618
- save_meta(meta_path, payload)
1619
- return payload
1620
-
1621
-
1622
- def ensure_submission_allowed(
1623
- meta_path: Path,
1624
- work_path: Path,
1625
- submit_path: Path,
1626
- *,
1627
- allow_semantic_lint_errors: bool = False,
1628
- ) -> Dict[str, Any]:
1629
- if not meta_path.exists():
1630
- raise SystemExit("missing meta confirmation file")
1631
- raw_meta = load_meta(meta_path)
1632
- meta = ensure_meta_shape(raw_meta, raw_meta.get("stem", "unknown"))
1633
- required = (
1634
- "mode",
1635
- "workspace",
1636
- "workSha256",
1637
- "submitSha256",
1638
- "workConfirmedAt",
1639
- "submitConfirmedAt",
1640
- "status",
1641
- "modelingGatePassed",
1642
- )
1643
- missing = [key for key in required if not meta.get(key)]
1644
- if missing:
1645
- raise SystemExit(f"meta confirmation incomplete: missing {', '.join(missing)}")
1646
- if meta.get("status") != "submit_confirmed":
1647
- raise SystemExit("submission blocked: current status is not submit_confirmed")
1648
- current_work_sha = file_sha256(work_path)
1649
- current_submit_sha = file_sha256(submit_path)
1650
- if meta.get("workSha256") != current_work_sha:
1651
- raise SystemExit("submission blocked: work file changed after confirmation")
1652
- if meta.get("submitSha256") != current_submit_sha:
1653
- raise SystemExit("submission blocked: submit file changed after confirmation")
1654
- submit_built_at = meta.get("submitBuiltAt")
1655
- work_confirmed_at = meta.get("workConfirmedAt")
1656
- if submit_built_at and work_confirmed_at and submit_built_at < work_confirmed_at:
1657
- raise SystemExit("submission blocked: submit payload predates work confirmation")
1658
- work_payload = load_json(work_path)
1659
- submit_payload = load_json(submit_path)
1660
- semantic_lint = lint_form_template_semantics(work_payload, meta=meta, submit_payload=submit_payload)
1661
- if semantic_lint["errors"] and not allow_semantic_lint_errors:
1662
- raise SystemExit("submission blocked by semantic lint: " + "; ".join(semantic_lint["errors"]))
1663
- if meta.get("mode") == "edit":
1664
- publish_guard = build_publish_safety_report(submit_payload, meta.get("templateUuid"))
1665
- if publish_guard["errors"]:
1666
- raise SystemExit("submission blocked by published consistency gate: " + "; ".join(publish_guard["errors"]))
1667
- return meta
1668
-
1669
-
1670
- def extract_template_id(payload: Any) -> int | None:
1671
- if payload is None:
1672
- return None
1673
- if isinstance(payload, bool):
1674
- return None
1675
- if isinstance(payload, int):
1676
- return payload
1677
- if isinstance(payload, str) and payload.isdigit():
1678
- return int(payload)
1679
- if isinstance(payload, dict):
1680
- for key in ("id", "template_id", "draftId", "publishedId"):
1681
- value = payload.get(key)
1682
- if isinstance(value, int):
1683
- return value
1684
- if isinstance(value, str) and value.isdigit():
1685
- return int(value)
1686
- if "data" in payload:
1687
- return extract_template_id(payload.get("data"))
1688
- return None
1689
-
1690
-
1691
- @dataclass
1692
- class ApiClient:
1693
- base_url: str
1694
- workspace: str
1695
- language: str
1696
- cookie_header: str
1697
- timeout: float
1698
- insecure: bool = False
1699
-
1700
- def _build_url(self, path: str) -> str:
1701
- suffix = f"$workspace={urllib.parse.quote(self.workspace)}&$language={urllib.parse.quote(self.language)}"
1702
- joiner = "&" if "?" in path else "?"
1703
- return self.base_url.rstrip("/") + path + joiner + suffix
1704
-
1705
- def request(self, method: str, path: str, body: Optional[dict] = None) -> dict:
1706
- headers = {
1707
- "content-type": "application/json",
1708
- "cookie": self.cookie_header,
1709
- "accept": "application/json, text/plain, */*",
1710
- }
1711
- data = None if body is None else json.dumps(body, ensure_ascii=False).encode("utf-8")
1712
- req = urllib.request.Request(self._build_url(path), data=data, headers=headers, method=method)
1713
- context = ssl._create_unverified_context() if self.insecure else None
1714
- try:
1715
- with urllib.request.urlopen(req, timeout=self.timeout, context=context) as resp:
1716
- raw = resp.read().decode("utf-8", "replace")
1717
- except urllib.error.HTTPError as err:
1718
- raw = err.read().decode("utf-8", "replace")
1719
- raise SystemExit(f"HTTP {err.code} {path}: {raw}") from err
1720
- except urllib.error.URLError as err:
1721
- raise SystemExit(f"Request failed {path}: {err}") from err
1722
- payload = json.loads(raw)
1723
- if payload.get("code") != 0:
1724
- raise SystemExit(f"API error {path}: {payload}")
1725
- return payload
1726
-
1727
- def get_form_template(self, template_id: Any) -> dict:
1728
- return self.request("GET", f"/api/form_template/{template_id}")
1729
-
1730
- def create_form_template(self, body: Dict[str, Any]) -> dict:
1731
- return self.request("POST", "/api/form_template", body)
1732
-
1733
- def update_form_template(self, template_id: Any, body: Dict[str, Any]) -> dict:
1734
- return self.request("PUT", f"/api/form_template/{template_id}", body)
1735
-
1736
- def publish_form_template(self, template_id: Any) -> dict:
1737
- return self.request("POST", "/api/form_template/publish", {"id": template_id})
1738
-
1739
-
1740
- def resolve_cookie_header(value: Optional[str]) -> str:
1741
- cookie = value or os.environ.get("BPMAX_COOKIE_HEADER", "")
1742
- if not cookie:
1743
- raise SystemExit("missing cookie header: pass --cookie-header or set BPMAX_COOKIE_HEADER")
1744
- return cookie
1745
-
1746
-
1747
- def resolve_workspace(value: Optional[str]) -> str:
1748
- workspace = value or os.environ.get("BPMAX_WORKSPACE", "")
1749
- if not workspace:
1750
- raise SystemExit("missing workspace: pass --workspace or set BPMAX_WORKSPACE")
1751
- return workspace
1752
-
1753
-
1754
- def build_client(args: Any) -> ApiClient:
1755
- return ApiClient(
1756
- base_url=resolve_base_url(getattr(args, "base_url", None)),
1757
- workspace=resolve_workspace(getattr(args, "workspace", None)),
1758
- language=getattr(args, "language", DEFAULT_LANGUAGE),
1759
- cookie_header=resolve_cookie_header(getattr(args, "cookie_header", None)),
1760
- timeout=float(getattr(args, "timeout", 30)),
1761
- insecure=bool(getattr(args, "insecure", False)),
1762
- )