bpmax-cli 0.1.44-beta.1 → 0.1.44-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.
Files changed (39) hide show
  1. package/dist/bin.js +1584 -69
  2. package/dist/bin.js.map +1 -1
  3. package/package.json +1 -1
  4. package/scripts/install-skills.mjs +98 -0
  5. package/skills/bpmax-api-platform-editor/SKILL.md +1 -1
  6. package/skills/bpmax-console-template-editor/SKILL.md +1 -1
  7. package/skills/bpmax-dataset-field-template-editor/SKILL.md +3 -3
  8. package/skills/bpmax-dataset-template-editor/SKILL.md +3 -3
  9. package/skills/bpmax-e2e-flow-config-orchestrator/SKILL.md +28 -2
  10. package/skills/bpmax-e2e-flow-test-operator/SKILL.md +26 -3
  11. package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +8 -0
  12. package/skills/bpmax-e2e-flow-test-operator/references/minimal-test-loop.md +9 -4
  13. package/skills/bpmax-e2e-flow-test-operator/references/state-schema.md +25 -0
  14. package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_doc.py +26 -0
  15. package/skills/bpmax-filter-template-editor/SKILL.md +1 -1
  16. package/skills/bpmax-flow-template-editor/SKILL.md +25 -10
  17. package/skills/bpmax-flow-template-editor/references/flow-template-api-workflow.md +17 -2
  18. package/skills/bpmax-flow-template-editor/references/matrix-flow-form-nav-collaboration.md +2 -0
  19. package/skills/bpmax-form-template-editor/SKILL.md +31 -6
  20. package/skills/bpmax-form-template-editor/references/form-template-api-workflow.md +15 -5
  21. package/skills/bpmax-form-template-editor/references/local-temp-workflow.md +1 -1
  22. package/skills/bpmax-form-template-editor/scripts/export_form_template.py +2 -0
  23. package/skills/bpmax-form-template-editor/scripts/form_template_editor_common.py +17 -0
  24. package/skills/bpmax-form-template-editor/tests/test_form_template_editor.py +6 -17
  25. package/skills/bpmax-list-template-editor/SKILL.md +5 -1
  26. package/skills/bpmax-list-template-editor/references/content-config-shape.md +17 -0
  27. package/skills/bpmax-list-template-editor/references/list-template-api-workflow.md +9 -4
  28. package/skills/bpmax-list-template-editor/references/runtime-verified-workflow.md +17 -10
  29. package/skills/bpmax-list-template-editor/references/special-formats.md +17 -0
  30. package/skills/bpmax-memory-protocol/SKILL.md +72 -0
  31. package/skills/bpmax-nav-config-editor/SKILL.md +1 -1
  32. package/skills/bpmax-project-detail-template-editor/SKILL.md +1 -1
  33. package/skills/bpmax-role-editor/SKILL.md +2 -2
  34. package/skills/bpmax-user-mock-operator/SKILL.md +106 -0
  35. package/skills/bpmax-user-mock-operator/agents/openai.yaml +4 -0
  36. package/skills/bpmax-user-mock-operator/scripts/switch_user_identity.py +37 -0
  37. package/skills/bpmax-user-mock-operator/scripts/user_mock_operator_common.py +136 -0
  38. package/skills/bpmax-user-mock-operator/tests/test_user_mock_operator.py +138 -0
  39. package/skills/form-control-library/SKILL.md +1 -1
package/dist/bin.js CHANGED
@@ -206,7 +206,10 @@ var CLI_GOVERNANCE_PATHS = [
206
206
  "/api/cli/audit/start",
207
207
  "/api/cli/audit/finish",
208
208
  "/api/cli/bbs_invocations/start",
209
- "/api/cli/bbs_invocations/finish"
209
+ "/api/cli/bbs_invocations/finish",
210
+ "/api/cli/memory/status",
211
+ "/api/cli/memory/search",
212
+ "/api/cli/memory"
210
213
  ];
211
214
  var CLI_GOVERNANCE_UNSUPPORTED_MESSAGE = "\u5F53\u524D BPMAX \u5E73\u53F0\u7248\u672C\u4E0D\u652F\u6301 CLI \u6CBB\u7406\u80FD\u529B\uFF0C\u8BF7\u5347\u7EA7 huanpingtong-server \u540E\u518D\u4F7F\u7528 bpmax-cli 0.1.42+ \u7684\u8FDC\u7AEF\u4E1A\u52A1\u547D\u4EE4\u3002";
212
215
  function toCliGovernanceUnsupportedError(error, fallbackPath) {
@@ -262,18 +265,73 @@ function getValue(value, path9) {
262
265
  function capabilityForRequest(method, path9) {
263
266
  const normalizedMethod = method.toUpperCase();
264
267
  const normalizedPath = normalizePath2(path9);
268
+ const pageTemplatePrefix = flowPageTemplateCapabilityPrefix(path9);
265
269
  if (normalizedPath === "/cli/capabilities") {
266
270
  return void 0;
267
271
  }
268
272
  if (normalizedPath.startsWith("/cli/bbs_invocations/")) {
269
273
  return void 0;
270
274
  }
275
+ if (normalizedMethod === "GET" && normalizedPath === "/cli/memory/status") return "memory.status";
276
+ if (normalizedMethod === "POST" && normalizedPath === "/cli/memory/search") return "memory.search";
277
+ if (normalizedMethod === "GET" && normalizedPath === "/cli/memory") return "memory.list";
278
+ if (normalizedMethod === "POST" && normalizedPath === "/cli/memory") return "memory.add";
279
+ if (normalizedMethod === "GET" && /^\/cli\/memory\/[^/]+$/.test(normalizedPath)) return "memory.get";
280
+ if (normalizedMethod === "PUT" && /^\/cli\/memory\/[^/]+$/.test(normalizedPath)) return "memory.update";
281
+ if (normalizedMethod === "DELETE" && /^\/cli\/memory\/[^/]+$/.test(normalizedPath)) return "memory.delete";
271
282
  if (normalizedMethod === "GET" && normalizedPath === "/user/current") return "user.current";
272
- if (normalizedMethod === "GET" && normalizedPath === "/workspace/by_key") return "flow.list";
283
+ if (normalizedMethod === "GET" && normalizedPath === "/workspace/by_key") return "config.workspace_flow.export";
273
284
  if (normalizedMethod === "GET" && normalizedPath === "/flow/flow_type") return "flow.list";
285
+ if (normalizedMethod === "POST" && normalizedPath === "/flow/flow_type") return "config.flow_template.create";
274
286
  if (normalizedMethod === "GET" && normalizedPath === "/flow/options") return "flow.options";
287
+ if (normalizedMethod === "GET" && normalizedPath === "/flow") return "config.flow_template.export";
288
+ if (normalizedMethod === "PUT" && normalizedPath === "/flow") return "config.flow_template.submit";
289
+ if (normalizedMethod === "DELETE" && normalizedPath === "/flow") return "config.flow_template.delete";
275
290
  if (normalizedMethod === "POST" && normalizedPath === "/flow/batch_get") return "flow.get";
276
- if (normalizedMethod === "GET" && normalizedPath.startsWith("/form_template/")) return "project.create";
291
+ if (normalizedMethod === "GET" && normalizedPath.startsWith("/form_template/")) return "config.form_template.export";
292
+ if (normalizedMethod === "POST" && normalizedPath === "/form_template") return "config.form_template.create";
293
+ if (normalizedMethod === "PUT" && /^\/form_template\/[^/]+$/.test(normalizedPath)) return "config.form_template.submit";
294
+ if (normalizedMethod === "DELETE" && /^\/form_template\/[^/]+$/.test(normalizedPath)) return "config.form_template.delete";
295
+ if (normalizedMethod === "POST" && normalizedPath === "/form_template/publish") return "config.form_template.submit";
296
+ if (normalizedMethod === "POST" && normalizedPath === "/flow_page_template") return `${pageTemplatePrefix}.create`;
297
+ if (normalizedMethod === "GET" && /^\/flow_page_template\/[^/]+$/.test(normalizedPath)) return `${pageTemplatePrefix}.export`;
298
+ if (normalizedMethod === "PUT" && /^\/flow_page_template\/[^/]+$/.test(normalizedPath)) return `${pageTemplatePrefix}.submit`;
299
+ if (normalizedMethod === "DELETE" && /^\/flow_page_template\/[^/]+$/.test(normalizedPath)) return `${pageTemplatePrefix}.delete`;
300
+ if (normalizedMethod === "POST" && normalizedPath === "/data_set") return "config.dataset.create";
301
+ if (normalizedMethod === "GET" && /^\/data_set\/[^/]+$/.test(normalizedPath)) return "config.dataset.export";
302
+ if (normalizedMethod === "POST" && /^\/data_set\/relationFields\/[^/]+$/.test(normalizedPath)) return "config.dataset.submit";
303
+ if (normalizedMethod === "POST" && /^\/data_set\/publish\/[^/]+$/.test(normalizedPath)) return "config.dataset.publish";
304
+ if (normalizedMethod === "POST" && /^\/data_set\/pause\/[^/]+$/.test(normalizedPath)) return "config.dataset.pause";
305
+ if (normalizedMethod === "POST" && /^\/data_set\/cancel-refresh\/[^/]+$/.test(normalizedPath)) return "config.dataset.cancel_refresh";
306
+ if (normalizedMethod === "DELETE" && /^\/data_set\/[^/]+$/.test(normalizedPath)) return "config.dataset.delete";
307
+ if (normalizedMethod === "POST" && normalizedPath === "/data_set_field") return "config.dataset_field.create";
308
+ if (normalizedMethod === "GET" && /^\/data_set_field\/[^/]+$/.test(normalizedPath)) return "config.dataset_field.export";
309
+ if (normalizedMethod === "PUT" && /^\/data_set_field\/[^/]+$/.test(normalizedPath)) return "config.dataset_field.submit";
310
+ if (normalizedMethod === "DELETE" && /^\/data_set_field\/[^/]+$/.test(normalizedPath)) return "config.dataset_field.delete";
311
+ if (normalizedMethod === "POST" && normalizedPath === "/api_platform") return "config.api_platform.create";
312
+ if (normalizedMethod === "POST" && normalizedPath === "/api_platform_instance") return "config.api_platform.create";
313
+ if (normalizedMethod === "POST" && normalizedPath === "/api_proxy") return "config.api_platform.create";
314
+ if (normalizedMethod === "POST" && normalizedPath === "/api_proxy_entity_binding") return "config.api_platform.create";
315
+ if (normalizedMethod === "PUT" && /^\/api_platform\/[^/]+$/.test(normalizedPath)) return "config.api_platform.submit";
316
+ if (normalizedMethod === "PUT" && /^\/api_platform_instance\/[^/]+$/.test(normalizedPath)) return "config.api_platform.submit";
317
+ if (normalizedMethod === "PUT" && /^\/api_proxy\/[^/]+$/.test(normalizedPath)) return "config.api_platform.submit";
318
+ if (normalizedMethod === "PUT" && /^\/api_proxy_entity_binding\/[^/]+$/.test(normalizedPath)) return "config.api_platform.submit";
319
+ if (normalizedMethod === "DELETE" && /^\/api_platform\/[^/]+$/.test(normalizedPath)) return "config.api_platform.delete";
320
+ if (normalizedMethod === "DELETE" && /^\/api_platform_instance\/[^/]+$/.test(normalizedPath)) return "config.api_platform.delete";
321
+ if (normalizedMethod === "DELETE" && /^\/api_proxy\/[^/]+$/.test(normalizedPath)) return "config.api_platform.delete";
322
+ if (normalizedMethod === "DELETE" && /^\/api_proxy_entity_binding\/[^/]+$/.test(normalizedPath)) return "config.api_platform.delete";
323
+ if (normalizedMethod === "POST" && normalizedPath === "/role") return "config.role.create";
324
+ if (normalizedMethod === "POST" && normalizedPath === "/point") return "config.role.create";
325
+ if (normalizedMethod === "POST" && normalizedPath === "/user_role") return "config.role.create";
326
+ if (normalizedMethod === "PUT" && /^\/role\/[^/]+$/.test(normalizedPath)) return "config.role.submit";
327
+ if (normalizedMethod === "PUT" && /^\/point\/[^/]+$/.test(normalizedPath)) return "config.role.submit";
328
+ if (normalizedMethod === "DELETE" && /^\/role\/[^/]+$/.test(normalizedPath)) return "config.role.delete";
329
+ if (normalizedMethod === "DELETE" && /^\/point\/[^/]+$/.test(normalizedPath)) return "config.role.delete";
330
+ if (normalizedMethod === "DELETE" && /^\/user_role\/[^/]+$/.test(normalizedPath)) return "config.role.delete";
331
+ if (normalizedMethod === "POST" && normalizedPath === "/configuration") return "config.nav_config.create";
332
+ if (normalizedMethod === "PUT" && /^\/configuration\/[^/]+$/.test(normalizedPath)) return "config.nav_config.submit";
333
+ if (normalizedMethod === "DELETE" && /^\/configuration\/[^/]+$/.test(normalizedPath)) return "config.nav_config.delete";
334
+ if (normalizedMethod === "PUT" && normalizedPath === "/workspace/workspace_flow") return "config.workspace_flow.submit";
277
335
  if (normalizedMethod === "POST" && normalizedPath === "/project_staging/prefill") return "project.create";
278
336
  if (normalizedMethod === "POST" && normalizedPath === "/project/search") return "project.search";
279
337
  if (normalizedMethod === "POST" && normalizedPath === "/project/list") return "project.list";
@@ -354,6 +412,20 @@ async function updateProfileCapabilities(profileName, cache) {
354
412
  };
355
413
  await saveConfig(config);
356
414
  }
415
+ function flowPageTemplateCapabilityPrefix(path9) {
416
+ const query = path9.includes("?") ? path9.slice(path9.indexOf("?") + 1) : "";
417
+ const type = new URLSearchParams(query).get("type");
418
+ if (type === "2") {
419
+ return "config.project_detail_template";
420
+ }
421
+ if (type === "3") {
422
+ return "config.filter_template";
423
+ }
424
+ if (type === "4") {
425
+ return "config.console_template";
426
+ }
427
+ return "config.list_template";
428
+ }
357
429
  function normalizePath2(path9) {
358
430
  let normalized = path9.split("?")[0] || "/";
359
431
  if (!normalized.startsWith("/")) {
@@ -372,7 +444,7 @@ function normalizePath2(path9) {
372
444
  // package.json
373
445
  var package_default = {
374
446
  name: "bpmax-cli",
375
- version: "0.1.44-beta.1",
447
+ version: "0.1.44-beta.10",
376
448
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
377
449
  type: "module",
378
450
  bin: {
@@ -2574,11 +2646,15 @@ var CONFIG_DOMAINS = {
2574
2646
  exportStatus: "supported",
2575
2647
  buildStatus: "supported",
2576
2648
  submitStatus: "supported",
2649
+ createPath: "/form_template",
2650
+ createMethod: "POST",
2651
+ deletePath: (id) => `/form_template/${id}`,
2652
+ deleteMethod: "DELETE",
2577
2653
  submitPath: (id) => `/form_template/${id}`,
2578
2654
  submitMethod: "PUT",
2579
2655
  readEndpoints: ["GET /api/form_template/:id"],
2580
- writeEndpoints: ["PUT /api/form_template/:id", "POST /api/form_template/publish"],
2581
- notes: ["Edit submit updates the draft/current template and publishes after update; create mode remains blocked until the typed adapter supports create and flow rebind semantics."]
2656
+ writeEndpoints: ["POST /api/form_template", "PUT /api/form_template/:id", "DELETE /api/form_template/:id", "POST /api/form_template/publish"],
2657
+ notes: ["Supports edit and create modes. Edit updates the draft/current template and publishes after update; create posts a new draft and publishes it through the typed adapter."]
2582
2658
  },
2583
2659
  "flow-template": {
2584
2660
  capability: "config.flow_template",
@@ -2586,11 +2662,27 @@ var CONFIG_DOMAINS = {
2586
2662
  exportStatus: "supported",
2587
2663
  buildStatus: "supported",
2588
2664
  submitStatus: "supported",
2665
+ deletePath: (id) => `/flow?${flowIdentityQuery(parseFlowIdentity(id))}`,
2666
+ deleteMethod: "DELETE",
2589
2667
  submitPath: (id) => `/flow?${flowIdentityQuery(parseFlowIdentity(id), { publish: 2 })}`,
2590
2668
  submitMethod: "PUT",
2591
2669
  readEndpoints: ["GET /api/flow?flow_type=:flow_type&draft=1", "GET /api/flow?key=:key&draft=1", "POST /api/flow/batch_get"],
2592
- writeEndpoints: ["PUT /api/flow?flow_type=:flow_type&publish=2", "PUT /api/flow?key=:key&publish=2", "PUT /api/flow?flow_type=:flow_type&publish=1", "PUT /api/flow?key=:key&publish=1"],
2593
- notes: ["Flow config is keyed by flow_type for main flows or key for subflows. Export id format: flow_type, flow_type:<type>, or key:<subflowKey>. Submit writes draft by default and only publishes when payload.publish_live=true."]
2670
+ writeEndpoints: ["POST /api/flow/flow_type", "PUT /api/flow?flow_type=:flow_type&publish=2", "PUT /api/flow?key=:key&publish=2", "PUT /api/flow?flow_type=:flow_type&publish=1", "PUT /api/flow?key=:key&publish=1", "DELETE /api/flow?flow_type=:flow_type&key=:key"],
2671
+ notes: ["Flow config is keyed by flow_type for main flows or key for subflows. Export id format: flow_type, flow_type:<type>, or key:<subflowKey>. Submit writes draft by default and only publishes when payload.publish_live=true. Create first asks the platform for a flow<number> and never accepts a hand-authored main flow_type."]
2672
+ },
2673
+ "workspace-flow": {
2674
+ capability: "config.workspace_flow",
2675
+ exportPath: (id) => `/workspace/by_key?key=${encodeURIComponent(normalizeWorkspaceKey(id))}`,
2676
+ exportStatus: "supported",
2677
+ buildStatus: "supported",
2678
+ submitStatus: "supported",
2679
+ createPath: "/workspace/workspace_flow",
2680
+ createMethod: "PUT",
2681
+ submitPath: () => "/workspace/workspace_flow",
2682
+ submitMethod: "PUT",
2683
+ readEndpoints: ["GET /api/workspace/by_key?key=:workspace"],
2684
+ writeEndpoints: ["PUT /api/workspace/workspace_flow"],
2685
+ notes: ["Workspace flow create/submit replaces the workspace_flow relation list for one workspace, then verifies by /workspace/by_key. Create is a capability alias for adding a new binding through the typed submit adapter."]
2594
2686
  },
2595
2687
  "list-template": {
2596
2688
  capability: "config.list_template",
@@ -2598,12 +2690,16 @@ var CONFIG_DOMAINS = {
2598
2690
  exportStatus: "supported",
2599
2691
  buildStatus: "supported",
2600
2692
  submitStatus: "supported",
2693
+ createPath: "/flow_page_template",
2694
+ createMethod: "POST",
2695
+ deletePath: (id) => `/flow_page_template/${id}`,
2696
+ deleteMethod: "DELETE",
2601
2697
  submitPath: (id) => `/flow_page_template/${id}`,
2602
2698
  submitMethod: "PUT",
2603
2699
  expectedType: 1,
2604
2700
  readEndpoints: ["GET /api/flow_page_template/:id?skip_i18n=true"],
2605
- writeEndpoints: ["PUT /api/flow_page_template/:id"],
2606
- notes: ["type=1 list template."]
2701
+ writeEndpoints: ["POST /api/flow_page_template", "PUT /api/flow_page_template/:id", "DELETE /api/flow_page_template/:id"],
2702
+ notes: ["type=1 list template. Create and edit both use the typed flow_page_template adapter."]
2607
2703
  },
2608
2704
  "filter-template": {
2609
2705
  capability: "config.filter_template",
@@ -2611,12 +2707,16 @@ var CONFIG_DOMAINS = {
2611
2707
  exportStatus: "supported",
2612
2708
  buildStatus: "supported",
2613
2709
  submitStatus: "supported",
2710
+ createPath: "/flow_page_template",
2711
+ createMethod: "POST",
2712
+ deletePath: (id) => `/flow_page_template/${id}`,
2713
+ deleteMethod: "DELETE",
2614
2714
  submitPath: (id) => `/flow_page_template/${id}`,
2615
2715
  submitMethod: "PUT",
2616
2716
  expectedType: 3,
2617
2717
  readEndpoints: ["GET /api/flow_page_template/:id?skip_i18n=true"],
2618
- writeEndpoints: ["PUT /api/flow_page_template/:id"],
2619
- notes: ["type=3 filter template."]
2718
+ writeEndpoints: ["POST /api/flow_page_template", "PUT /api/flow_page_template/:id", "DELETE /api/flow_page_template/:id"],
2719
+ notes: ["type=3 filter template. Create and edit both use the typed flow_page_template adapter."]
2620
2720
  },
2621
2721
  "project-detail-template": {
2622
2722
  capability: "config.project_detail_template",
@@ -2624,12 +2724,16 @@ var CONFIG_DOMAINS = {
2624
2724
  exportStatus: "supported",
2625
2725
  buildStatus: "supported",
2626
2726
  submitStatus: "supported",
2727
+ createPath: "/flow_page_template",
2728
+ createMethod: "POST",
2729
+ deletePath: (id) => `/flow_page_template/${id}`,
2730
+ deleteMethod: "DELETE",
2627
2731
  submitPath: (id) => `/flow_page_template/${id}`,
2628
2732
  submitMethod: "PUT",
2629
2733
  expectedType: 2,
2630
2734
  readEndpoints: ["GET /api/flow_page_template/:id?type=2&create=&skip_i18n=true"],
2631
- writeEndpoints: ["PUT /api/flow_page_template/:id"],
2632
- notes: ["type=2 project detail template; activate/delete remain domain-specific operations."]
2735
+ writeEndpoints: ["POST /api/flow_page_template", "PUT /api/flow_page_template/:id", "DELETE /api/flow_page_template/:id"],
2736
+ notes: ["type=2 project detail template. Create and edit both use the typed flow_page_template adapter; activate/delete remain domain-specific operations."]
2633
2737
  },
2634
2738
  "console-template": {
2635
2739
  capability: "config.console_template",
@@ -2637,12 +2741,16 @@ var CONFIG_DOMAINS = {
2637
2741
  exportStatus: "supported",
2638
2742
  buildStatus: "supported",
2639
2743
  submitStatus: "supported",
2744
+ createPath: "/flow_page_template",
2745
+ createMethod: "POST",
2746
+ deletePath: (id) => `/flow_page_template/${id}`,
2747
+ deleteMethod: "DELETE",
2640
2748
  submitPath: (id) => `/flow_page_template/${id}`,
2641
2749
  submitMethod: "PUT",
2642
2750
  expectedType: 4,
2643
2751
  readEndpoints: ["GET /api/flow_page_template/:id?skip_i18n=true"],
2644
- writeEndpoints: ["PUT /api/flow_page_template/:id"],
2645
- notes: ["type=4 console template; this is not /api/configuration."]
2752
+ writeEndpoints: ["POST /api/flow_page_template", "PUT /api/flow_page_template/:id", "DELETE /api/flow_page_template/:id"],
2753
+ notes: ["type=4 console template; this is not /api/configuration. Create and edit both use the typed flow_page_template adapter."]
2646
2754
  },
2647
2755
  dataset: {
2648
2756
  capability: "config.dataset",
@@ -2650,11 +2758,23 @@ var CONFIG_DOMAINS = {
2650
2758
  exportStatus: "supported",
2651
2759
  buildStatus: "supported",
2652
2760
  submitStatus: "supported",
2761
+ createPath: "/data_set",
2762
+ createMethod: "POST",
2763
+ deletePath: (id) => `/data_set/${id}`,
2764
+ deleteMethod: "DELETE",
2653
2765
  submitPath: (id) => `/data_set/relationFields/${id}`,
2654
2766
  submitMethod: "POST",
2655
2767
  readEndpoints: ["GET /api/data_set/:id", "POST /api/data_set/list"],
2656
- writeEndpoints: ["POST /api/data_set/relationFields/:id"],
2657
- notes: ["Edit submit updates dataset basics and selected field relations through the huanpingtong API-Key proxy. Create, publish, pause, cancel-refresh, and index refresh remain blocked until those workflows have dedicated adapters."]
2768
+ writeEndpoints: [
2769
+ "POST /api/data_set",
2770
+ "POST /api/data_set/relationFields/:id",
2771
+ "DELETE /api/data_set/:id",
2772
+ "POST /api/data_set/publish/:id",
2773
+ "POST /api/data_set/pause/:id",
2774
+ "POST /api/data_set/cancel-refresh/:id",
2775
+ "POST /api/data_set/pause/:id + POST /api/data_set/publish/:id (refresh/reindex)"
2776
+ ],
2777
+ notes: ["Create posts a new dataset through the huanpingtong API-Key proxy. Edit submit updates dataset basics and selected field relations. Publish, pause, cancel-refresh, and refresh/reindex are explicit lifecycle commands."]
2658
2778
  },
2659
2779
  "dataset-field": {
2660
2780
  capability: "config.dataset_field",
@@ -2662,28 +2782,35 @@ var CONFIG_DOMAINS = {
2662
2782
  exportStatus: "supported",
2663
2783
  buildStatus: "supported",
2664
2784
  submitStatus: "supported",
2785
+ createPath: "/data_set_field",
2786
+ createMethod: "POST",
2787
+ deletePath: (id) => `/data_set_field/${id}`,
2788
+ deleteMethod: "DELETE",
2665
2789
  submitPath: (id) => `/data_set_field/${id}`,
2666
2790
  submitMethod: "PUT",
2667
2791
  readEndpoints: ["GET /api/data_set_field/:id", "GET /api/data_set_field/getBatchByFlow"],
2668
- writeEndpoints: ["PUT /api/data_set_field/:id"],
2669
- notes: ["Edit submit updates one dataset field through the huanpingtong API-Key proxy. Create/delete remain blocked until those workflows have dedicated adapters and list checks."]
2792
+ writeEndpoints: ["POST /api/data_set_field", "PUT /api/data_set_field/:id", "DELETE /api/data_set_field/:id"],
2793
+ notes: ["Create, edit, and delete one dataset field through the huanpingtong API-Key proxy."]
2670
2794
  },
2671
2795
  "api-platform": {
2672
2796
  capability: "config.api_platform",
2673
2797
  exportStatus: "supported",
2674
2798
  buildStatus: "supported",
2675
2799
  submitStatus: "supported",
2800
+ deleteMethod: "DELETE",
2676
2801
  readEndpoints: ["GET /api/api_platform/by_key/:key", "GET /api/api_platform_instance/:id", "GET /api/api_platform_instance?api_platform_guid=:guid", "GET /api/api_proxy/:id", "GET /api/api_proxy?api_platform_guid=:guid", "GET /api/api_proxy_entity_binding?q_proxy_guid=:guid&q_direction=response"],
2677
- writeEndpoints: ["PUT /api/api_platform/:id", "PUT /api/api_platform_instance/:id", "PUT /api/api_proxy/:id", "PUT /api/api_proxy_entity_binding/:id", "POST /api/api_platform", "POST /api/api_platform_instance", "POST /api/api_proxy", "POST /api/api_proxy_entity_binding"],
2678
- notes: ["API platform config is layered. Export id format: platform:<platform_key>, instance:<id>, or api:<id>. Submit supports create/edit operation plans for platform, instance, API, and optional response binding."]
2802
+ writeEndpoints: ["PUT /api/api_platform/:id", "PUT /api/api_platform_instance/:id", "PUT /api/api_proxy/:id", "PUT /api/api_proxy_entity_binding/:id", "POST /api/api_platform", "POST /api/api_platform_instance", "POST /api/api_proxy", "POST /api/api_proxy_entity_binding", "DELETE /api/api_platform/:id", "DELETE /api/api_platform_instance/:id", "DELETE /api/api_proxy/:id", "DELETE /api/api_proxy_entity_binding/:id"],
2803
+ notes: ["API platform config is layered. Export id format: platform:<platform_key>, instance:<id>, api:<id>, or binding:<id>. Submit supports create/edit operation plans for platform, instance, API, and optional response binding."]
2679
2804
  },
2680
2805
  role: {
2681
2806
  capability: "config.role",
2682
2807
  exportStatus: "supported",
2683
2808
  buildStatus: "supported",
2684
2809
  submitStatus: "supported",
2810
+ deletePath: (id) => `/role/${id}`,
2811
+ deleteMethod: "DELETE",
2685
2812
  readEndpoints: ["GET /api/role?page=1&page_size=1000&sort=-id", "GET /api/point/point_list", "GET /api/user_role?role_id=:id", "GET /api/workspace?page_size=10000", "POST /api/flow/list/lightweight?page_size=1000"],
2686
- writeEndpoints: ["POST /api/role", "PUT /api/role/:id", "POST/PUT/DELETE /api/point", "POST/DELETE /api/user_role"],
2813
+ writeEndpoints: ["POST /api/role", "PUT /api/role/:id", "DELETE /api/role/:id", "POST/PUT/DELETE /api/point", "POST/DELETE /api/user_role"],
2687
2814
  notes: ["Role submit executes point operations, role create/update, then member operations with role_id injection."]
2688
2815
  },
2689
2816
  "nav-config": {
@@ -2692,22 +2819,30 @@ var CONFIG_DOMAINS = {
2692
2819
  buildStatus: "supported",
2693
2820
  submitStatus: "supported",
2694
2821
  readEndpoints: ["GET /api/configuration?q_type=:type&is_default_action=1&page=1&page_size=10000", "GET /api/point/point_list", "GET /api/group/sub_groups"],
2695
- writeEndpoints: ["PUT /api/configuration/:id?is_default_action=1", "POST /api/configuration?is_default_action=1"],
2822
+ writeEndpoints: ["PUT /api/configuration/:id?is_default_action=1", "POST /api/configuration?is_default_action=1", "DELETE /api/configuration/:id?is_default_action=1"],
2696
2823
  notes: ["Nav config is four configuration records (navmenu/shortcut/navmenu_mobile/shortcut_mobile). Export id is the workspace key. Submit writes all four records as an operation plan."]
2697
2824
  }
2698
2825
  };
2699
2826
  var CONFIG_SUBMIT_UNSUPPORTED_MESSAGE = "Typed config build/submit adapters are not implemented for this domain yet. Stop before remote writes and use the matching editor Skill verified scripts until bpmax-cli adds a domain-specific adapter.";
2700
2827
  function configAdapterMatrix() {
2701
- return Object.entries(CONFIG_DOMAINS).map(([domain, definition]) => ({
2702
- domain,
2703
- capability_prefix: definition.capability,
2704
- export_status: definition.exportStatus,
2705
- build_status: definition.buildStatus,
2706
- submit_status: definition.submitStatus,
2707
- read_endpoints: definition.readEndpoints,
2708
- write_endpoints: definition.writeEndpoints,
2709
- notes: definition.notes
2710
- }));
2828
+ return Object.entries(CONFIG_DOMAINS).map(([domain, definition]) => {
2829
+ const supportsCreate = Boolean(definition.createPath) || ["flow-template", "api-platform", "role", "nav-config"].includes(domain);
2830
+ const supportsDelete = Boolean(definition.deletePath) || ["workspace-flow", "api-platform", "nav-config"].includes(domain);
2831
+ return {
2832
+ domain,
2833
+ capability_prefix: definition.capability,
2834
+ export_status: definition.exportStatus,
2835
+ create_status: supportsCreate ? "supported" : "blocked",
2836
+ build_status: definition.buildStatus,
2837
+ submit_status: definition.submitStatus,
2838
+ delete_status: supportsDelete ? "supported" : "blocked",
2839
+ create_capability: supportsCreate ? `${definition.capability}.create` : null,
2840
+ delete_capability: supportsDelete ? `${definition.capability}.delete` : null,
2841
+ read_endpoints: definition.readEndpoints,
2842
+ write_endpoints: definition.writeEndpoints,
2843
+ notes: definition.notes
2844
+ };
2845
+ });
2711
2846
  }
2712
2847
  function hashJson(value) {
2713
2848
  return createHash3("sha256").update(JSON.stringify(value)).digest("hex");
@@ -2727,6 +2862,34 @@ function pickDefined(source, keys) {
2727
2862
  }
2728
2863
  return result;
2729
2864
  }
2865
+ function normalizeWorkspaceKey(workspace) {
2866
+ const nextWorkspace = workspace.trim().replace(/^\/+|\/+$/g, "");
2867
+ return nextWorkspace.startsWith("w:") ? nextWorkspace.slice(2) : nextWorkspace;
2868
+ }
2869
+ function numericId(value) {
2870
+ if (typeof value === "number" && Number.isFinite(value)) {
2871
+ return value;
2872
+ }
2873
+ if (typeof value === "string" && /^\d+$/.test(value)) {
2874
+ return Number(value);
2875
+ }
2876
+ return void 0;
2877
+ }
2878
+ function formTemplateDetail(value) {
2879
+ if (isRecord3(value) && isRecord3(value.data)) {
2880
+ return value.data;
2881
+ }
2882
+ return isRecord3(value) ? value : {};
2883
+ }
2884
+ function assertFormTemplateDraftId(id, data, action) {
2885
+ const detail = formTemplateDetail(data);
2886
+ const originTemplateId = numericId(detail.origin_template_id);
2887
+ if (originTemplateId && originTemplateId > 0) {
2888
+ throw new Error(
2889
+ `Refusing to ${action} published form-template id ${id}. Use draft id ${originTemplateId}; published ids are readback-only and must not be used for export/submit/publish.`
2890
+ );
2891
+ }
2892
+ }
2730
2893
  function jsonPointerSegment(value) {
2731
2894
  return value.replace(/~/g, "~0").replace(/\//g, "~1");
2732
2895
  }
@@ -2857,7 +3020,7 @@ function lintDatasetFieldWork(value, errors) {
2857
3020
  }
2858
3021
  function isFlowTemplateWork(value) {
2859
3022
  const data = value.data;
2860
- return isRecord3(data) && (Array.isArray(data.nodes) || Array.isArray(data.periods) || Object.prototype.hasOwnProperty.call(value, "flow_type") || Object.prototype.hasOwnProperty.call(value, "flowType"));
3023
+ return isRecord3(data) && (Array.isArray(data.nodes) || Array.isArray(data.periods) || value.mode === "create" || Object.prototype.hasOwnProperty.call(value, "flow_type") || Object.prototype.hasOwnProperty.call(value, "flowType"));
2861
3024
  }
2862
3025
  function flowTemplateMainFlowTypeError(flowType) {
2863
3026
  if (typeof flowType !== "string" || !flowType.trim()) {
@@ -2895,6 +3058,102 @@ function validateFlowTemplateIdentityStandard(id, payload) {
2895
3058
  key: payload?.key ?? payload?.flow_key ?? payload?.flowKey ?? ""
2896
3059
  });
2897
3060
  }
3061
+ var FORM_DRIVEN_CREATE_HIDE_FIELDS = ["project.name", "project.brief", "project.plan_end_time"];
3062
+ function hasConfiguredFormTemplate(meta) {
3063
+ const value = meta.form_template ?? meta.formTemplate;
3064
+ return value !== void 0 && value !== null && String(value).trim() !== "" && String(value).trim() !== "0";
3065
+ }
3066
+ function hasConfiguredFlowTemplateFormSource(value, meta) {
3067
+ return hasConfiguredFormTemplate(meta) || !isEmptyTemplateReference(value.meta_form_id);
3068
+ }
3069
+ function validateFlowTemplateFormDrivenCreateBaseline(value, errors, options = {}) {
3070
+ const data = isRecord3(value.data) ? value.data : {};
3071
+ const meta = isRecord3(data.meta) ? data.meta : {};
3072
+ if (!options.force && !hasConfiguredFlowTemplateFormSource(value, meta)) {
3073
+ return;
3074
+ }
3075
+ const context = options.context || "flow-template create";
3076
+ const missing = [];
3077
+ const hideFields = Array.isArray(meta.hide_fields) ? meta.hide_fields.map(String) : [];
3078
+ for (const field of FORM_DRIVEN_CREATE_HIDE_FIELDS) {
3079
+ if (!hideFields.includes(field)) {
3080
+ missing.push(`data.meta.hide_fields must include ${field}`);
3081
+ }
3082
+ }
3083
+ if (meta.use_template_project_name !== true) {
3084
+ missing.push("data.meta.use_template_project_name must be true");
3085
+ }
3086
+ if (typeof meta.project_name_template !== "string" || !meta.project_name_template.trim()) {
3087
+ missing.push("data.meta.project_name_template must be a non-empty string");
3088
+ }
3089
+ if (missing.length === 0) {
3090
+ return;
3091
+ }
3092
+ const message = `${context} for form-driven project creation requires default system-field hiding and a project name template: ${missing.join("; ")}.`;
3093
+ if (errors) {
3094
+ errors.push(message);
3095
+ return;
3096
+ }
3097
+ throw new Error(message);
3098
+ }
3099
+ function isEmptyTemplateReference(value) {
3100
+ return value === void 0 || value === null || value === "" || value === 0 || value === "0";
3101
+ }
3102
+ function isRemoteNumericTemplateId(value) {
3103
+ if (typeof value === "number") {
3104
+ return Number.isInteger(value) && Number.isFinite(value) && value > 0;
3105
+ }
3106
+ if (typeof value === "string") {
3107
+ return /^[1-9]\d*$/.test(value.trim());
3108
+ }
3109
+ return false;
3110
+ }
3111
+ function addFlowTemplateRemoteIdError(errors, pathName, value) {
3112
+ errors.push(
3113
+ `${pathName} must be a current-environment remote numeric id; got ${JSON.stringify(value)}. Do not write local uuid or directory references into flow-template payloads.`
3114
+ );
3115
+ }
3116
+ function validateFlowTemplateRemoteTemplateRefs(value, errors) {
3117
+ const nextErrors = [];
3118
+ const data = isRecord3(value.data) ? value.data : {};
3119
+ const meta = isRecord3(data.meta) ? data.meta : {};
3120
+ const metaRefs = [
3121
+ ["meta_form_id", value.meta_form_id],
3122
+ ["data.meta.form_template", meta.form_template],
3123
+ ["data.meta.table_list_template", meta.table_list_template],
3124
+ ["data.meta.table_filter_template", meta.table_filter_template],
3125
+ ["data.meta.step_detail_id", meta.step_detail_id]
3126
+ ];
3127
+ for (const [pathName, refValue] of metaRefs) {
3128
+ if (!isEmptyTemplateReference(refValue) && !isRemoteNumericTemplateId(refValue)) {
3129
+ addFlowTemplateRemoteIdError(nextErrors, pathName, refValue);
3130
+ }
3131
+ }
3132
+ const nodes = Array.isArray(data.nodes) ? data.nodes : [];
3133
+ nodes.forEach((node, index) => {
3134
+ if (!isRecord3(node)) {
3135
+ return;
3136
+ }
3137
+ const nodeName = typeof node.name === "string" && node.name.trim() ? node.name.trim() : `nodes[${index}]`;
3138
+ const nodeRefs = [
3139
+ [`data.nodes[${index}].form_template (${nodeName})`, node.form_template],
3140
+ [`data.nodes[${index}].step_detail_id (${nodeName})`, node.step_detail_id]
3141
+ ];
3142
+ for (const [pathName, refValue] of nodeRefs) {
3143
+ if (!isEmptyTemplateReference(refValue) && !isRemoteNumericTemplateId(refValue)) {
3144
+ addFlowTemplateRemoteIdError(nextErrors, pathName, refValue);
3145
+ }
3146
+ }
3147
+ });
3148
+ if (!nextErrors.length) {
3149
+ return;
3150
+ }
3151
+ if (errors) {
3152
+ errors.push(...nextErrors);
3153
+ return;
3154
+ }
3155
+ throw new Error(`flow-template online template reference gate failed: ${nextErrors.join("; ")}`);
3156
+ }
2898
3157
  function lintTemplateFieldReferences(value, errors) {
2899
3158
  const content = typeof value.content === "string" ? (() => {
2900
3159
  try {
@@ -2911,6 +3170,255 @@ function lintTemplateFieldReferences(value, errors) {
2911
3170
  }
2912
3171
  }
2913
3172
  }
3173
+ function parseTemplateContent(value, errors) {
3174
+ const basic = isRecord3(value.basic) ? value.basic : {};
3175
+ const rawContent = value.content ?? basic.content;
3176
+ if (typeof rawContent === "string") {
3177
+ try {
3178
+ return JSON.parse(rawContent);
3179
+ } catch {
3180
+ errors?.push("template.content must be valid JSON when it is a string.");
3181
+ return void 0;
3182
+ }
3183
+ }
3184
+ return rawContent;
3185
+ }
3186
+ function pageTemplateType(value) {
3187
+ const basic = isRecord3(value.basic) ? value.basic : {};
3188
+ const rawType = value.type ?? basic.type;
3189
+ const parsed = Number(rawType);
3190
+ return Number.isFinite(parsed) ? parsed : void 0;
3191
+ }
3192
+ function textOf(value) {
3193
+ if (typeof value === "string") {
3194
+ return value;
3195
+ }
3196
+ if (typeof value === "number" || typeof value === "boolean") {
3197
+ return String(value);
3198
+ }
3199
+ if (Array.isArray(value)) {
3200
+ return value.map(textOf).join(" ");
3201
+ }
3202
+ if (isRecord3(value)) {
3203
+ return Object.values(value).map(textOf).join(" ");
3204
+ }
3205
+ return "";
3206
+ }
3207
+ function collectTextAtKeys(value, keys, result = []) {
3208
+ if (Array.isArray(value)) {
3209
+ value.forEach((item) => collectTextAtKeys(item, keys, result));
3210
+ return result;
3211
+ }
3212
+ if (!isRecord3(value)) {
3213
+ return result;
3214
+ }
3215
+ Object.entries(value).forEach(([key, item]) => {
3216
+ if (keys.has(key)) {
3217
+ result.push(textOf(item));
3218
+ }
3219
+ collectTextAtKeys(item, keys, result);
3220
+ });
3221
+ return result;
3222
+ }
3223
+ function lintListTemplateQuerySafety(content, errors) {
3224
+ const queryTexts = collectTextAtKeys(
3225
+ {
3226
+ config: content.config,
3227
+ customQuery: content.customQuery,
3228
+ beforeSearch: content.beforeSearch,
3229
+ tabFilters: content.tabFilters
3230
+ },
3231
+ /* @__PURE__ */ new Set(["$template", "customQuery", "beforeSearch", "tabFilters", "query", "url", "api", "dataSource"])
3232
+ );
3233
+ queryTexts.forEach((text5) => {
3234
+ if (!text5.trim() || /bpmax-allow-user-scope-project-list\s*:/i.test(text5)) {
3235
+ return;
3236
+ }
3237
+ if (/(\/bpmax\/project\/list|\/api\/project\/list|ESProjectList)/i.test(text5)) {
3238
+ errors.push("list-template query safety gate forbids /bpmax/project/list, /api/project/list, or ESProjectList unless the script includes bpmax-allow-user-scope-project-list: <reason>.");
3239
+ }
3240
+ if (/\bdata_set_id\b/i.test(text5) && /(raw-es-search|project\/list|ESProjectList|\$esQuery|query|search)/i.test(text5)) {
3241
+ errors.push("list-template query safety gate forbids using data_set_id as an ES/project query entrypoint; use data_set_key with raw-es-search or ctx.$esQuery instead.");
3242
+ }
3243
+ });
3244
+ }
3245
+ function listTemplateNodeLabel(node) {
3246
+ return [
3247
+ node.title,
3248
+ node.label,
3249
+ node.text,
3250
+ node.children,
3251
+ node.name
3252
+ ].map(textOf).join(" ");
3253
+ }
3254
+ function nodeIcon(node) {
3255
+ const attribute = isRecord3(node.attribute) ? node.attribute : {};
3256
+ const props = isRecord3(attribute.props) ? attribute.props : {};
3257
+ const directIcon = typeof node.icon === "string" ? node.icon : "";
3258
+ const propsIcon = typeof props.icon === "string" ? props.icon : "";
3259
+ const inlineIcon = findInlineIconClass(node.children);
3260
+ return directIcon || propsIcon || inlineIcon;
3261
+ }
3262
+ function findInlineIconClass(value) {
3263
+ if (Array.isArray(value)) {
3264
+ for (const item of value) {
3265
+ const found = findInlineIconClass(item);
3266
+ if (found) {
3267
+ return found;
3268
+ }
3269
+ }
3270
+ return "";
3271
+ }
3272
+ if (!isRecord3(value)) {
3273
+ return "";
3274
+ }
3275
+ const isValue = typeof value.is === "string" ? value.is.toLowerCase() : "";
3276
+ const attribute = isRecord3(value.attribute) ? value.attribute : {};
3277
+ const className = typeof attribute.class === "string" ? attribute.class : typeof value.class === "string" ? value.class : "";
3278
+ if (isValue === "i" && /\b(ri|el-icon)\b/.test(className)) {
3279
+ return className;
3280
+ }
3281
+ return findInlineIconClass(value.children);
3282
+ }
3283
+ function listTemplateNodeGuardText(node) {
3284
+ const attribute = isRecord3(node.attribute) ? node.attribute : {};
3285
+ const props = isRecord3(attribute.props) ? attribute.props : {};
3286
+ return [
3287
+ node.if,
3288
+ node.show,
3289
+ node.visible,
3290
+ node.disabled,
3291
+ props.disabled,
3292
+ props.confirm,
3293
+ props.confirmText,
3294
+ props.beforeClick,
3295
+ props.onClick,
3296
+ node.on,
3297
+ node.events
3298
+ ].map(textOf).join(" ");
3299
+ }
3300
+ function collectListTemplateActionNodes(value, result = [], inheritedGuardText = "") {
3301
+ if (Array.isArray(value)) {
3302
+ value.forEach((item) => collectListTemplateActionNodes(item, result, inheritedGuardText));
3303
+ return result;
3304
+ }
3305
+ if (!isRecord3(value)) {
3306
+ return result;
3307
+ }
3308
+ const isValue = typeof value.is === "string" ? value.is.toLowerCase() : "";
3309
+ const guardText = [inheritedGuardText, listTemplateNodeGuardText(value)].filter(Boolean).join(" ");
3310
+ if (isValue.includes("button") || isValue.includes("dropdown-item")) {
3311
+ result.push({ node: value, inheritedGuardText });
3312
+ }
3313
+ Object.values(value).forEach((item) => collectListTemplateActionNodes(item, result, guardText));
3314
+ return result;
3315
+ }
3316
+ function isListTemplateOperationColumn(column) {
3317
+ const title = typeof column.title === "string" ? column.title.trim() : "";
3318
+ const props = isRecord3(column.props) ? column.props : {};
3319
+ const fixed = typeof props.fixed === "string" ? props.fixed : "";
3320
+ if (/^(操作|动作|Action|Actions|Operate|Operations)$/i.test(title)) {
3321
+ return true;
3322
+ }
3323
+ if (fixed === "right" && collectListTemplateActionNodes(column.createElement).length > 0) {
3324
+ return true;
3325
+ }
3326
+ return collectListTemplateActionNodes(column.createElement).length >= 2;
3327
+ }
3328
+ function classifyListTemplateAction(label) {
3329
+ if (/(删除|移除|作废|delete|remove|discard)/i.test(label)) {
3330
+ return "delete";
3331
+ }
3332
+ if (/(详情|查看|明细|detail|view|open)/i.test(label)) {
3333
+ return "view";
3334
+ }
3335
+ if (/(编辑|修改|edit|update)/i.test(label)) {
3336
+ return "edit";
3337
+ }
3338
+ return "other";
3339
+ }
3340
+ function iconMatchesAction(kind, icon) {
3341
+ if (!icon.trim()) {
3342
+ return false;
3343
+ }
3344
+ const normalized = icon.toLowerCase();
3345
+ if (kind === "delete") {
3346
+ return /(delete|trash|remove|close|clear|forbid|ri_delete|el-icon-delete)/.test(normalized);
3347
+ }
3348
+ if (kind === "view") {
3349
+ return /(eye|view|detail|search|document|tickets|ri_eye|el-icon-view)/.test(normalized);
3350
+ }
3351
+ if (kind === "edit") {
3352
+ return /(edit|pencil|write|ri_edit|el-icon-edit)/.test(normalized);
3353
+ }
3354
+ return true;
3355
+ }
3356
+ function hasDeleteAvailabilityGuard(item) {
3357
+ const guardText = [item.inheritedGuardText, listTemplateNodeGuardText(item.node)].filter(Boolean).join(" ");
3358
+ if (!guardText.trim()) {
3359
+ return false;
3360
+ }
3361
+ const hasInitialStatusCheck = /(status|project_status)[^;&|)]*(={2,3}|==)\s*['"]?0['"]?/i.test(guardText) || /['"]?0['"]?\s*(={2,3}|==)[^;&|)]*(status|project_status)/i.test(guardText) || /(draft|newly|created|unstarted|未开始|刚创建|新建)/i.test(guardText);
3362
+ const hasNotAdvancedCheck = /!\s*[^&|;]*(current_flow_step|flow_step|step|node)/i.test(guardText) || /(current_flow_step|flow_step|step|node)[^&|;]*(={2,3}|==)\s*(null|undefined|false|['"]{2})/i.test(guardText) || /(first_node|before_first|未推进|第一个节点前)/i.test(guardText);
3363
+ return hasInitialStatusCheck && hasNotAdvancedCheck;
3364
+ }
3365
+ function validateListTemplateActionGate(value, errors) {
3366
+ const nextErrors = [];
3367
+ const content = parseTemplateContent(value, nextErrors);
3368
+ if (!isRecord3(content)) {
3369
+ if (errors) {
3370
+ errors.push(...nextErrors);
3371
+ return;
3372
+ }
3373
+ if (nextErrors.length) {
3374
+ throw new Error(`list-template action gate failed: ${nextErrors.join("; ")}`);
3375
+ }
3376
+ return;
3377
+ }
3378
+ const columns = Array.isArray(content.config) ? content.config : Array.isArray(content.columns) ? content.columns : [];
3379
+ if (columns.length === 0) {
3380
+ if (errors) errors.push(...nextErrors);
3381
+ return;
3382
+ }
3383
+ lintListTemplateQuerySafety(content, nextErrors);
3384
+ const operationColumn = columns.filter(isRecord3).find(isListTemplateOperationColumn);
3385
+ if (!operationColumn) {
3386
+ nextErrors.push("list-template action gate requires an operation column when content.config has columns.");
3387
+ } else {
3388
+ const actionNodes = collectListTemplateActionNodes(operationColumn.createElement);
3389
+ const classified = actionNodes.map((item) => ({
3390
+ ...item,
3391
+ label: listTemplateNodeLabel(item.node),
3392
+ icon: nodeIcon(item.node),
3393
+ kind: classifyListTemplateAction(listTemplateNodeLabel(item.node))
3394
+ }));
3395
+ if (!classified.some((item) => item.kind === "view")) {
3396
+ nextErrors.push("list-template operation column must include a view/detail action.");
3397
+ }
3398
+ if (!classified.some((item) => item.kind === "delete")) {
3399
+ nextErrors.push("list-template operation column must include a delete/remove action.");
3400
+ } else {
3401
+ classified.filter((item) => item.kind === "delete").forEach((item) => {
3402
+ if (!hasDeleteAvailabilityGuard(item)) {
3403
+ nextErrors.push("list-template delete action must include an availability guard based on project status/current step so only newly created projects can be deleted.");
3404
+ }
3405
+ });
3406
+ }
3407
+ classified.filter((item) => item.kind !== "other").forEach((item) => {
3408
+ if (!iconMatchesAction(item.kind, item.icon)) {
3409
+ nextErrors.push(`list-template ${item.kind} action must use a matching icon; got ${JSON.stringify(item.icon)} for ${JSON.stringify(item.label.trim())}.`);
3410
+ }
3411
+ });
3412
+ }
3413
+ if (!nextErrors.length) {
3414
+ return;
3415
+ }
3416
+ if (errors) {
3417
+ errors.push(...nextErrors);
3418
+ return;
3419
+ }
3420
+ throw new Error(`list-template action gate failed: ${nextErrors.join("; ")}`);
3421
+ }
2914
3422
  function validateExpectedType(domain, definition, data) {
2915
3423
  if (definition.expectedType === void 0) {
2916
3424
  return;
@@ -2924,6 +3432,9 @@ function validateExpectedType(domain, definition, data) {
2924
3432
  }
2925
3433
  function normalizePageTemplatePayload(domain, work) {
2926
3434
  const definition = CONFIG_DOMAINS[domain];
3435
+ if (domain === "list-template") {
3436
+ validateListTemplateActionGate(work);
3437
+ }
2927
3438
  const basic = isRecord3(work.basic) ? work.basic : work;
2928
3439
  const rawContent = work.content ?? basic.content;
2929
3440
  const type = definition.expectedType;
@@ -3019,6 +3530,7 @@ function normalizeFlowTemplatePayload(work) {
3019
3530
  meta.form_template = work.meta_form_id;
3020
3531
  }
3021
3532
  data.meta = meta;
3533
+ validateFlowTemplateRemoteTemplateRefs({ ...work, data });
3022
3534
  const payload = pickDefined(work, [
3023
3535
  "name",
3024
3536
  "flow_type",
@@ -3045,10 +3557,34 @@ function normalizeFlowTemplatePayload(work) {
3045
3557
  }
3046
3558
  return payload;
3047
3559
  }
3560
+ function buildWorkspaceFlowBindingKey(flowType, flowKey) {
3561
+ return `${String(flowType || "default")}:${String(flowKey || "")}`;
3562
+ }
3563
+ function normalizeWorkspaceFlowItems(value) {
3564
+ if (!Array.isArray(value)) {
3565
+ return [];
3566
+ }
3567
+ return value.filter((item) => isRecord3(item)).map((item) => ({
3568
+ flow_type: String(item.flow_type || "default"),
3569
+ flow_key: String(item.flow_key || ""),
3570
+ only_in_workspace: normalizeInt(item.only_in_workspace ?? 0)
3571
+ }));
3572
+ }
3573
+ function buildWorkspaceFlowSubmitPayload(work) {
3574
+ const workspace = normalizeWorkspaceKey(String(work.workspace || work.key || ""));
3575
+ if (!workspace) {
3576
+ throw new Error("workspace-flow work requires workspace.");
3577
+ }
3578
+ const workspaceFlow = normalizeWorkspaceFlowItems(work.workspace_flow ?? work.flows);
3579
+ return {
3580
+ workspace,
3581
+ workspace_flow: workspaceFlow
3582
+ };
3583
+ }
3048
3584
  function normalizeDatasetPayload(work) {
3049
3585
  const mode = work.mode;
3050
- if (mode !== void 0 && mode !== "edit") {
3051
- throw new Error("dataset typed adapter currently supports edit mode only. Create/publish/pause/cancel-refresh require dedicated adapters.");
3586
+ if (mode !== void 0 && mode !== "edit" && mode !== "create") {
3587
+ throw new Error("dataset typed adapter supports mode edit or create. Publish/pause/cancel-refresh require dedicated lifecycle commands.");
3052
3588
  }
3053
3589
  const basic = isRecord3(work.basic) ? work.basic : work;
3054
3590
  const scripts = isRecord3(work.scripts) ? work.scripts : work;
@@ -3082,8 +3618,8 @@ function normalizeDatasetPayload(work) {
3082
3618
  }
3083
3619
  function normalizeDatasetFieldPayload(work) {
3084
3620
  const mode = work.mode;
3085
- if (mode !== void 0 && mode !== "edit") {
3086
- throw new Error("dataset-field typed adapter currently supports edit mode only. Create/delete require dedicated adapters.");
3621
+ if (mode !== void 0 && mode !== "edit" && mode !== "create") {
3622
+ throw new Error("dataset-field typed adapter supports mode edit or create. Delete requires a dedicated adapter.");
3087
3623
  }
3088
3624
  const source = isRecord3(work.source) ? work.source : work;
3089
3625
  const payload = {
@@ -3186,6 +3722,17 @@ function refreshSettingToSubmit(value) {
3186
3722
  stop_refresh_count: normalizeInt(value.stopRefreshCount ?? value.stop_refresh_count ?? fallback.stop_refresh_count)
3187
3723
  };
3188
3724
  }
3725
+ var FORM_RULE_ID_KEYS = /* @__PURE__ */ new Set(["form_rule_id", "form_template_id", "id"]);
3726
+ var FORM_VALUE_ID_KEYS = /* @__PURE__ */ new Set(["template_id", "id"]);
3727
+ function stripKeys(source, keys) {
3728
+ const result = {};
3729
+ for (const [key, value] of Object.entries(source)) {
3730
+ if (!keys.has(key)) {
3731
+ result[key] = value;
3732
+ }
3733
+ }
3734
+ return result;
3735
+ }
3189
3736
  function normalizeRemovedFields(value) {
3190
3737
  if (!Array.isArray(value)) {
3191
3738
  return /* @__PURE__ */ new Set();
@@ -3194,8 +3741,8 @@ function normalizeRemovedFields(value) {
3194
3741
  }
3195
3742
  function buildStructuredFormTemplatePayload(work) {
3196
3743
  const mode = work.mode;
3197
- if (mode !== "edit") {
3198
- throw new Error("form-template structured work currently supports mode edit only. Create mode requires a verified create adapter and flow rebind workflow.");
3744
+ if (mode !== "edit" && mode !== "create") {
3745
+ throw new Error("form-template structured work requires mode edit or create.");
3199
3746
  }
3200
3747
  if (!isRecord3(work.basic)) {
3201
3748
  throw new Error("form-template structured work requires basic object.");
@@ -3236,8 +3783,8 @@ function buildStructuredFormTemplatePayload(work) {
3236
3783
  if (bundle.value.field_type !== bundle.rule.type) {
3237
3784
  throw new Error(`form-template field_type mismatch for ${ref}.`);
3238
3785
  }
3239
- const rule = { ...bundle.rule };
3240
- const value = { ...bundle.value };
3786
+ const rule = mode === "create" ? stripKeys(bundle.rule, FORM_RULE_ID_KEYS) : { ...bundle.rule };
3787
+ const value = mode === "create" ? stripKeys(bundle.value, FORM_VALUE_ID_KEYS) : { ...bundle.value };
3241
3788
  submitRow.push(rule);
3242
3789
  valueItems.push(value);
3243
3790
  seen.add(ref);
@@ -3265,6 +3812,16 @@ function buildStructuredFormTemplatePayload(work) {
3265
3812
  value: valueItems
3266
3813
  };
3267
3814
  }
3815
+ function stripFormTemplateCreateIds(payload) {
3816
+ const next = { ...payload };
3817
+ if (Array.isArray(next.rule)) {
3818
+ next.rule = next.rule.map((row) => Array.isArray(row) ? row.map((item) => isRecord3(item) ? stripKeys(item, FORM_RULE_ID_KEYS) : item) : row);
3819
+ }
3820
+ if (Array.isArray(next.value)) {
3821
+ next.value = next.value.map((item) => isRecord3(item) ? stripKeys(item, FORM_VALUE_ID_KEYS) : item);
3822
+ }
3823
+ return next;
3824
+ }
3268
3825
  function formTemplateRawToStructured(raw) {
3269
3826
  const ruleRows = Array.isArray(raw.rule) ? raw.rule : [];
3270
3827
  const values = Array.isArray(raw.value) ? raw.value : [];
@@ -3527,6 +4084,13 @@ function parseApiPlatformIdentity(id) {
3527
4084
  }
3528
4085
  return { layer: "api", value };
3529
4086
  }
4087
+ if (trimmed.startsWith("binding:")) {
4088
+ const value = trimmed.slice("binding:".length).trim();
4089
+ if (!value) {
4090
+ throw new Error("api-platform binding id must include id.");
4091
+ }
4092
+ return { layer: "binding", value };
4093
+ }
3530
4094
  return { layer: "platform", value: trimmed };
3531
4095
  }
3532
4096
  function firstRecord(value) {
@@ -3926,11 +4490,15 @@ function buildDomainSubmitPayload(domain, work, options = {}, raw) {
3926
4490
  if (isRecord3(work.basic) && Array.isArray(work.layout) && isRecord3(work.fields)) {
3927
4491
  return buildStructuredFormTemplatePayload(work);
3928
4492
  }
3929
- return pickDefined(work, ["name", "desc", "category", "option", "rule", "value"]);
4493
+ const payload = pickDefined(work, ["name", "desc", "category", "option", "rule", "value"]);
4494
+ return work.mode === "create" ? stripFormTemplateCreateIds(payload) : payload;
3930
4495
  }
3931
4496
  if (domain === "flow-template") {
3932
4497
  return normalizeFlowTemplatePayload(work);
3933
4498
  }
4499
+ if (domain === "workspace-flow") {
4500
+ return buildWorkspaceFlowSubmitPayload(work);
4501
+ }
3934
4502
  if (domain === "dataset") {
3935
4503
  return normalizeDatasetPayload(work);
3936
4504
  }
@@ -3961,11 +4529,110 @@ function responseDataId(response) {
3961
4529
  }
3962
4530
  return void 0;
3963
4531
  }
4532
+ function responseValue(response, keys) {
4533
+ if (!isRecord3(response)) {
4534
+ return void 0;
4535
+ }
4536
+ for (const key of keys) {
4537
+ if (response[key] !== void 0) return response[key];
4538
+ }
4539
+ if (isRecord3(response.data)) {
4540
+ for (const key of keys) {
4541
+ if (response.data[key] !== void 0) return response.data[key];
4542
+ }
4543
+ }
4544
+ return void 0;
4545
+ }
4546
+ function responseFlowType(response) {
4547
+ const flowType = responseValue(response, ["flow_type", "flowType"]);
4548
+ if (typeof flowType !== "string" || !STANDARD_MAIN_FLOW_TYPE.test(flowType)) {
4549
+ throw new Error(`flow-template create did not return a platform flow_type; got ${String(flowType)}.`);
4550
+ }
4551
+ return flowType;
4552
+ }
4553
+ function operationMethod(value) {
4554
+ return isRecord3(value) && typeof value.method === "string" ? value.method.toUpperCase() : "";
4555
+ }
4556
+ function aggregatePayloadHasNonCreateOperations(domain, payload) {
4557
+ if (domain === "role") {
4558
+ return operationMethod(payload.role) !== "POST" || Array.isArray(payload.pointOps) && payload.pointOps.some((op) => operationMethod(op) !== "POST") || Array.isArray(payload.memberOps) && payload.memberOps.some((op) => operationMethod(op) !== "POST");
4559
+ }
4560
+ return Array.isArray(payload.operations) && payload.operations.some((op) => operationMethod(op) !== "POST");
4561
+ }
4562
+ function apiPlatformDeletePath(id) {
4563
+ const identity = parseApiPlatformIdentity(id);
4564
+ if (identity.layer === "platform") {
4565
+ if (/^\d+$/.test(identity.value)) {
4566
+ return `/api_platform/${identity.value}`;
4567
+ }
4568
+ throw new Error("api-platform delete for platform requires a numeric platform id. Use platform:<id>.");
4569
+ }
4570
+ if (identity.layer === "instance") {
4571
+ return `/api_platform_instance/${identity.value}`;
4572
+ }
4573
+ if (identity.layer === "api") {
4574
+ return `/api_proxy/${identity.value}`;
4575
+ }
4576
+ return `/api_proxy_entity_binding/${identity.value}`;
4577
+ }
4578
+ function parseWorkspaceFlowDeleteId(id, profile) {
4579
+ const [workspacePart = "", flowType = "", flowKey = ""] = id.split("|");
4580
+ const workspace = normalizeWorkspaceKey(workspacePart || profile.config.workspace || "");
4581
+ if (!workspace || !flowType) {
4582
+ throw new Error('workspace-flow delete id must be "<workspace>|<flow_type>|<flow_key>". Use an empty final flow_key for main flows.');
4583
+ }
4584
+ return { workspace, flowType, flowKey };
4585
+ }
4586
+ async function deleteWorkspaceFlowBinding(profile, id, confirm3) {
4587
+ const definition = CONFIG_DOMAINS["workspace-flow"];
4588
+ await ensureConfigCapability(profile, `${definition.capability}.delete`);
4589
+ await ensureConfigCapability(profile, `${definition.capability}.export`);
4590
+ const { workspace, flowType, flowKey } = parseWorkspaceFlowDeleteId(id, profile);
4591
+ const current = await readRemoteConfigDomain(profile, "workspace-flow", workspace, definition);
4592
+ const bindings = isRecord3(current) ? normalizeWorkspaceFlowItems(current.workspace_flow) : [];
4593
+ const nextBindings = bindings.filter(
4594
+ (item) => buildWorkspaceFlowBindingKey(item.flow_type, item.flow_key) !== buildWorkspaceFlowBindingKey(flowType, flowKey)
4595
+ );
4596
+ const expectedConfirm = `delete workspace-flow ${id}`;
4597
+ if (confirm3 !== expectedConfirm) {
4598
+ return {
4599
+ dry_run: true,
4600
+ domain: "workspace-flow",
4601
+ id,
4602
+ endpoint: "/workspace/workspace_flow",
4603
+ method: "PUT",
4604
+ params: { workspace },
4605
+ delete_binding: { flow_type: flowType, flow_key: flowKey },
4606
+ before_count: bindings.length,
4607
+ after_count: nextBindings.length,
4608
+ next: `Run again with --confirm "${expectedConfirm}" to delete.`
4609
+ };
4610
+ }
4611
+ const response = await apiRequest(
4612
+ createApiClient(profile),
4613
+ "PUT",
4614
+ "/workspace/workspace_flow",
4615
+ { data: { workspace_flow: nextBindings }, params: { workspace }, capability: `${definition.capability}.delete` }
4616
+ );
4617
+ const readback = await readRemoteConfigDomain(profile, "workspace-flow", workspace, definition);
4618
+ return {
4619
+ dry_run: false,
4620
+ domain: "workspace-flow",
4621
+ id,
4622
+ endpoint: "/workspace/workspace_flow",
4623
+ method: "PUT",
4624
+ response,
4625
+ readback_hash: hashJson(readback)
4626
+ };
4627
+ }
3964
4628
  async function submitRoleOperations(profile, id, submit) {
3965
4629
  const definition = CONFIG_DOMAINS.role;
3966
- const current = await collectRoleAggregate(profile, id);
3967
- if (hashJson(current.raw) !== submit.base_hash) {
3968
- throw new Error("Remote config changed after export. Re-export before submitting.");
4630
+ const createMode = isRecord3(submit.meta) && submit.meta.mode === "create";
4631
+ if (!createMode) {
4632
+ const current = await collectRoleAggregate(profile, id);
4633
+ if (hashJson(current.raw) !== submit.base_hash) {
4634
+ throw new Error("Remote config changed after export. Re-export before submitting.");
4635
+ }
3969
4636
  }
3970
4637
  const payload = submit.payload;
3971
4638
  if (!isRecord3(payload) || !isRecord3(payload.role)) {
@@ -3981,7 +4648,10 @@ async function submitRoleOperations(profile, id, submit) {
3981
4648
  client,
3982
4649
  op.method,
3983
4650
  op.path,
3984
- { data: op.body === null ? void 0 : op.body, capability: `${definition.capability}.submit` }
4651
+ {
4652
+ data: op.body === null ? void 0 : op.body,
4653
+ capability: op.method === "POST" ? `${definition.capability}.create` : op.method === "DELETE" ? `${definition.capability}.delete` : `${definition.capability}.submit`
4654
+ }
3985
4655
  ));
3986
4656
  }
3987
4657
  const roleMethod = String(payload.role.method || "");
@@ -3990,7 +4660,7 @@ async function submitRoleOperations(profile, id, submit) {
3990
4660
  client,
3991
4661
  roleMethod,
3992
4662
  rolePath,
3993
- { data: payload.role.body, capability: `${definition.capability}.submit` }
4663
+ { data: payload.role.body, capability: roleMethod === "POST" ? `${definition.capability}.create` : `${definition.capability}.submit` }
3994
4664
  );
3995
4665
  const resolvedRoleId = responseDataId(roleResponse) ?? payload.role.id ?? id;
3996
4666
  const memberResponses = [];
@@ -4009,7 +4679,10 @@ async function submitRoleOperations(profile, id, submit) {
4009
4679
  client,
4010
4680
  op.method,
4011
4681
  op.path,
4012
- { data: body, capability: `${definition.capability}.submit` }
4682
+ {
4683
+ data: body,
4684
+ capability: op.method === "POST" ? `${definition.capability}.create` : op.method === "DELETE" ? `${definition.capability}.delete` : `${definition.capability}.submit`
4685
+ }
4013
4686
  ));
4014
4687
  }
4015
4688
  return {
@@ -4020,7 +4693,7 @@ async function submitRoleOperations(profile, id, submit) {
4020
4693
  readback_hash: hashJson((await collectRoleAggregate(profile, String(resolvedRoleId))).raw)
4021
4694
  };
4022
4695
  }
4023
- async function submitOperationPlan(profile, capability, operations) {
4696
+ async function submitOperationPlan(profile, capabilityPrefix, operations) {
4024
4697
  if (!Array.isArray(operations)) {
4025
4698
  throw new Error("Config submit payload must contain operations array.");
4026
4699
  }
@@ -4030,14 +4703,17 @@ async function submitOperationPlan(profile, capability, operations) {
4030
4703
  if (!isRecord3(op) || typeof op.method !== "string" || typeof op.path !== "string") {
4031
4704
  throw new Error("Invalid config submit operation.");
4032
4705
  }
4033
- if (op.method !== "POST" && op.method !== "PUT") {
4706
+ if (op.method !== "POST" && op.method !== "PUT" && op.method !== "DELETE") {
4034
4707
  throw new Error(`Unsupported config submit operation method: ${op.method}.`);
4035
4708
  }
4036
4709
  responses.push(await apiRequest(
4037
4710
  client,
4038
4711
  op.method,
4039
4712
  op.path,
4040
- { data: op.payload, capability }
4713
+ {
4714
+ data: op.method === "DELETE" ? void 0 : op.payload,
4715
+ capability: op.method === "POST" ? `${capabilityPrefix}.create` : op.method === "DELETE" ? `${capabilityPrefix}.delete` : `${capabilityPrefix}.submit`
4716
+ }
4041
4717
  ));
4042
4718
  }
4043
4719
  return responses;
@@ -4047,15 +4723,299 @@ async function submitAggregateConfigDomain(profile, domain, id, submit) {
4047
4723
  if (!isRecord3(payload) || !Array.isArray(payload.operations)) {
4048
4724
  throw new Error(`${domain} submit payload must contain an operation plan.`);
4049
4725
  }
4050
- const responses = await submitOperationPlan(profile, `${CONFIG_DOMAINS[domain].capability}.submit`, payload.operations);
4726
+ const responses = await submitOperationPlan(profile, CONFIG_DOMAINS[domain].capability, payload.operations);
4727
+ if (isRecord3(submit.meta) && submit.meta.mode === "create") {
4728
+ return {
4729
+ operation_responses: responses,
4730
+ readback_hash: null
4731
+ };
4732
+ }
4051
4733
  const current = domain === "api-platform" ? await collectApiPlatformAggregate(profile, id) : await collectNavConfigAggregate(profile, id);
4052
4734
  return {
4053
4735
  operation_responses: responses,
4054
4736
  readback_hash: hashJson(current.raw)
4055
4737
  };
4056
4738
  }
4739
+ async function createFlowTemplateFromWork(config, profile, workFile, confirm3, options = {}) {
4740
+ void config;
4741
+ const definition = CONFIG_DOMAINS["flow-template"];
4742
+ await ensureConfigCapability(profile, `${definition.capability}.create`);
4743
+ await ensureConfigCapability(profile, `${definition.capability}.submit`);
4744
+ const work = await readJsonFile(workFile);
4745
+ if (!isRecord3(work)) {
4746
+ throw new Error("flow-template create requires a work JSON object.");
4747
+ }
4748
+ validateFlowTemplateRemoteTemplateRefs(work);
4749
+ validateFlowTemplateFormDrivenCreateBaseline(work, void 0, { context: "flow-template create" });
4750
+ const createShell = {
4751
+ name: String(work.name || ""),
4752
+ category: work.category || "system",
4753
+ data: {
4754
+ nodes: [],
4755
+ periods: []
4756
+ }
4757
+ };
4758
+ if (!createShell.name) {
4759
+ throw new Error("flow-template create requires name.");
4760
+ }
4761
+ const expectedConfirm = `create flow-template ${createShell.name}`;
4762
+ if (confirm3 !== expectedConfirm) {
4763
+ return {
4764
+ dry_run: true,
4765
+ domain: "flow-template",
4766
+ create_endpoint: "/flow/flow_type",
4767
+ create_payload: createShell,
4768
+ draft_endpoint: "/flow?flow_type=<platform-flow-type>&publish=2",
4769
+ ...options.publishLive ? { live_endpoint: "/flow?flow_type=<platform-flow-type>&publish=1" } : {},
4770
+ next: `Run again with --confirm "${expectedConfirm}" to create.`
4771
+ };
4772
+ }
4773
+ const client = createApiClient(profile);
4774
+ const createResponse = await apiRequest(
4775
+ client,
4776
+ "POST",
4777
+ "/flow/flow_type",
4778
+ { data: createShell, capability: `${definition.capability}.create` }
4779
+ );
4780
+ const flowType = responseFlowType(createResponse);
4781
+ const payload = normalizeFlowTemplatePayload({
4782
+ ...work,
4783
+ flow_type: flowType,
4784
+ key: "",
4785
+ type: work.type || "main"
4786
+ });
4787
+ const updateTime = payload.update_time;
4788
+ delete payload.publish_live;
4789
+ delete payload.update_time;
4790
+ const draftEndpoint = `/flow?${flowIdentityQuery({ kind: "flow_type", flowType }, {
4791
+ publish: 2,
4792
+ ...updateTime !== void 0 && updateTime !== null && updateTime !== "" ? { update_time: String(updateTime) } : {}
4793
+ })}`;
4794
+ const draftResponse = await apiRequest(
4795
+ client,
4796
+ "PUT",
4797
+ draftEndpoint,
4798
+ { data: payload, capability: `${definition.capability}.submit` }
4799
+ );
4800
+ let liveResponse = null;
4801
+ let liveEndpoint = null;
4802
+ if (options.publishLive) {
4803
+ liveEndpoint = `/flow?${flowIdentityQuery({ kind: "flow_type", flowType }, {
4804
+ publish: 1,
4805
+ ...updateTime !== void 0 && updateTime !== null && updateTime !== "" ? { update_time: String(updateTime) } : {}
4806
+ })}`;
4807
+ liveResponse = await apiRequest(
4808
+ client,
4809
+ "PUT",
4810
+ liveEndpoint,
4811
+ { data: payload, capability: `${definition.capability}.submit` }
4812
+ );
4813
+ }
4814
+ const readback = await apiRequest(
4815
+ client,
4816
+ "GET",
4817
+ `/flow?${flowIdentityQuery({ kind: "flow_type", flowType }, { draft: 1, skip_i18n: "true" })}`,
4818
+ { capability: `${definition.capability}.export` }
4819
+ );
4820
+ return {
4821
+ dry_run: false,
4822
+ domain: "flow-template",
4823
+ flow_type: flowType,
4824
+ create_response: createResponse,
4825
+ draft_endpoint: draftEndpoint,
4826
+ draft_response: draftResponse,
4827
+ ...liveEndpoint ? { live_endpoint: liveEndpoint, live_response: liveResponse } : {},
4828
+ readback_hash: hashJson(readback)
4829
+ };
4830
+ }
4831
+ async function createFlowAppFromWork(config, profile, formWorkFile, flowWorkFile, confirm3, options = { workspace: "", name: "" }) {
4832
+ void config;
4833
+ const formDefinition = CONFIG_DOMAINS["form-template"];
4834
+ const flowDefinition = CONFIG_DOMAINS["flow-template"];
4835
+ const workspaceDefinition = CONFIG_DOMAINS["workspace-flow"];
4836
+ await ensureConfigCapability(profile, "config.flow_app.create");
4837
+ await ensureConfigCapability(profile, `${formDefinition.capability}.create`);
4838
+ await ensureConfigCapability(profile, `${formDefinition.capability}.submit`);
4839
+ await ensureConfigCapability(profile, `${formDefinition.capability}.export`);
4840
+ await ensureConfigCapability(profile, `${flowDefinition.capability}.create`);
4841
+ await ensureConfigCapability(profile, `${flowDefinition.capability}.submit`);
4842
+ await ensureConfigCapability(profile, `${flowDefinition.capability}.export`);
4843
+ await ensureConfigCapability(profile, `${workspaceDefinition.capability}.submit`);
4844
+ await ensureConfigCapability(profile, `${workspaceDefinition.capability}.export`);
4845
+ const workspace = normalizeWorkspaceKey(options.workspace || profile.config.workspace);
4846
+ const name = options.name.trim();
4847
+ if (!workspace) {
4848
+ throw new Error("flow-app create requires workspace.");
4849
+ }
4850
+ if (!name) {
4851
+ throw new Error("flow-app create requires name.");
4852
+ }
4853
+ const formWork = await readJsonFile(formWorkFile);
4854
+ const flowWork = await readJsonFile(flowWorkFile);
4855
+ if (!isRecord3(formWork) || formWork.mode !== "create") {
4856
+ throw new Error("flow-app create requires form work with mode=create.");
4857
+ }
4858
+ const formPayload = buildDomainSubmitPayload("form-template", formWork);
4859
+ const flowWorkRecord = isRecord3(flowWork) ? flowWork : {};
4860
+ validateFlowTemplateRemoteTemplateRefs(flowWorkRecord);
4861
+ validateFlowTemplateFormDrivenCreateBaseline(flowWorkRecord, void 0, {
4862
+ force: true,
4863
+ context: "flow-app create"
4864
+ });
4865
+ const flowShell = {
4866
+ name: String(flowWorkRecord.name || name),
4867
+ category: flowWorkRecord.category || "system",
4868
+ data: {
4869
+ nodes: [],
4870
+ periods: []
4871
+ }
4872
+ };
4873
+ const expectedConfirm = `create flow-app ${name} in ${workspace}`;
4874
+ const dryRunPlan = {
4875
+ operations: [
4876
+ { step: "create_form_template", method: "POST", path: "/form_template", payload: formPayload },
4877
+ { step: "publish_form_template", method: "POST", path: "/form_template/publish", payload: { id: "<draft-form-id>" } },
4878
+ { step: "create_flow_template", method: "POST", path: "/flow/flow_type", payload: flowShell },
4879
+ { step: "save_flow_draft", method: "PUT", path: "/flow?flow_type=<platform-flow-type>&publish=2" },
4880
+ ...options.publishLive !== false ? [{ step: "publish_flow_live", method: "PUT", path: "/flow?flow_type=<platform-flow-type>&publish=1" }] : [],
4881
+ { step: "bind_workspace_flow", method: "PUT", path: "/workspace/workspace_flow", params: { workspace } },
4882
+ { step: "verify_workspace_binding", method: "GET", path: "/workspace/by_key", params: { key: workspace } }
4883
+ ]
4884
+ };
4885
+ if (confirm3 !== expectedConfirm) {
4886
+ return {
4887
+ dry_run: true,
4888
+ domain: "flow-app",
4889
+ workspace,
4890
+ name,
4891
+ operation_plan: dryRunPlan,
4892
+ next: `Run again with --confirm "${expectedConfirm}" to create.`
4893
+ };
4894
+ }
4895
+ const client = createApiClient(profile);
4896
+ const createdResources = {};
4897
+ try {
4898
+ const formResponse = await apiRequest(
4899
+ client,
4900
+ "POST",
4901
+ "/form_template",
4902
+ { data: formPayload, capability: `${formDefinition.capability}.create` }
4903
+ );
4904
+ const draftFormId = responseDataId(formResponse);
4905
+ if (draftFormId === void 0 || draftFormId === null || draftFormId === "") {
4906
+ throw new Error("flow-app create did not receive a draft form-template id.");
4907
+ }
4908
+ createdResources.draft_form_id = draftFormId;
4909
+ const formPublishResponse = await apiRequest(
4910
+ client,
4911
+ "POST",
4912
+ "/form_template/publish",
4913
+ { data: { id: draftFormId }, capability: `${formDefinition.capability}.submit` }
4914
+ );
4915
+ const publishedFormId = responseDataId(formPublishResponse) ?? draftFormId;
4916
+ createdResources.published_form_id = publishedFormId;
4917
+ const flowCreateResponse = await apiRequest(
4918
+ client,
4919
+ "POST",
4920
+ "/flow/flow_type",
4921
+ { data: flowShell, capability: `${flowDefinition.capability}.create` }
4922
+ );
4923
+ const flowType = responseFlowType(flowCreateResponse);
4924
+ createdResources.flow_type = flowType;
4925
+ const flowData = isRecord3(flowWorkRecord.data) ? { ...flowWorkRecord.data } : {};
4926
+ const flowMeta = isRecord3(flowData.meta) ? { ...flowData.meta } : {};
4927
+ flowMeta.form_template = publishedFormId;
4928
+ flowData.meta = flowMeta;
4929
+ const flowPayload = normalizeFlowTemplatePayload({
4930
+ ...flowWorkRecord,
4931
+ name: flowShell.name,
4932
+ flow_type: flowType,
4933
+ key: "",
4934
+ type: flowWorkRecord.type || "main",
4935
+ meta_form_id: publishedFormId,
4936
+ data: flowData
4937
+ });
4938
+ const updateTime = flowPayload.update_time;
4939
+ delete flowPayload.publish_live;
4940
+ delete flowPayload.update_time;
4941
+ const draftEndpoint = `/flow?${flowIdentityQuery({ kind: "flow_type", flowType }, {
4942
+ publish: 2,
4943
+ ...updateTime !== void 0 && updateTime !== null && updateTime !== "" ? { update_time: String(updateTime) } : {}
4944
+ })}`;
4945
+ const flowDraftResponse = await apiRequest(
4946
+ client,
4947
+ "PUT",
4948
+ draftEndpoint,
4949
+ { data: flowPayload, capability: `${flowDefinition.capability}.submit` }
4950
+ );
4951
+ createdResources.flow_draft_saved = true;
4952
+ let flowLiveResponse = null;
4953
+ let liveEndpoint = null;
4954
+ if (options.publishLive !== false) {
4955
+ liveEndpoint = `/flow?${flowIdentityQuery({ kind: "flow_type", flowType }, {
4956
+ publish: 1,
4957
+ ...updateTime !== void 0 && updateTime !== null && updateTime !== "" ? { update_time: String(updateTime) } : {}
4958
+ })}`;
4959
+ flowLiveResponse = await apiRequest(
4960
+ client,
4961
+ "PUT",
4962
+ liveEndpoint,
4963
+ { data: flowPayload, capability: `${flowDefinition.capability}.submit` }
4964
+ );
4965
+ createdResources.flow_live_published = true;
4966
+ }
4967
+ const workspaceInfo = await apiRequest(
4968
+ client,
4969
+ "GET",
4970
+ "/workspace/by_key",
4971
+ { params: { key: workspace }, capability: `${workspaceDefinition.capability}.export` }
4972
+ );
4973
+ const existingBindings = isRecord3(workspaceInfo) ? normalizeWorkspaceFlowItems(workspaceInfo.workspace_flow) : [];
4974
+ const bindingKey = buildWorkspaceFlowBindingKey(flowType, "");
4975
+ const nextBindings = existingBindings.some((item) => buildWorkspaceFlowBindingKey(item.flow_type, item.flow_key) === bindingKey) ? existingBindings : [...existingBindings, { flow_type: flowType, flow_key: "", only_in_workspace: 0 }];
4976
+ const workspaceBindResponse = await apiRequest(
4977
+ client,
4978
+ "PUT",
4979
+ "/workspace/workspace_flow",
4980
+ { data: { workspace_flow: nextBindings }, params: { workspace }, capability: `${workspaceDefinition.capability}.submit` }
4981
+ );
4982
+ createdResources.workspace_binding_submitted = { workspace, flow_type: flowType, flow_key: "" };
4983
+ const workspaceReadback = await apiRequest(
4984
+ client,
4985
+ "GET",
4986
+ "/workspace/by_key",
4987
+ { params: { key: workspace }, capability: `${workspaceDefinition.capability}.export` }
4988
+ );
4989
+ const readbackBindings = isRecord3(workspaceReadback) ? normalizeWorkspaceFlowItems(workspaceReadback.workspace_flow) : [];
4990
+ if (!readbackBindings.some((item) => buildWorkspaceFlowBindingKey(item.flow_type, item.flow_key) === bindingKey)) {
4991
+ throw new Error(`flow-app create workspace binding verification failed for ${workspace} ${bindingKey}.`);
4992
+ }
4993
+ return {
4994
+ dry_run: false,
4995
+ domain: "flow-app",
4996
+ workspace,
4997
+ name,
4998
+ draft_form_id: draftFormId,
4999
+ published_form_id: publishedFormId,
5000
+ flow_type: flowType,
5001
+ form_response: formResponse,
5002
+ form_publish_response: formPublishResponse,
5003
+ flow_create_response: flowCreateResponse,
5004
+ flow_draft_response: flowDraftResponse,
5005
+ ...liveEndpoint ? { flow_live_response: flowLiveResponse, live_endpoint: liveEndpoint } : {},
5006
+ workspace_bind_response: workspaceBindResponse,
5007
+ workspace_readback_hash: hashJson(workspaceReadback)
5008
+ };
5009
+ } catch (error) {
5010
+ const message = error instanceof Error ? error.message : String(error || "");
5011
+ throw new Error(`flow-app create failed: ${message}. Created resources: ${JSON.stringify(createdResources)}. Next recovery: fix the failing step, then rerun the corresponding typed config command or rerun flow-app create only if duplicate resources are acceptable.`);
5012
+ }
5013
+ }
4057
5014
  async function readBackConfigDomain(profile, domain, id, definition) {
4058
5015
  const data = await readRemoteConfigDomain(profile, domain, id, definition);
5016
+ if (domain === "form-template") {
5017
+ assertFormTemplateDraftId(id, data, "verify");
5018
+ }
4059
5019
  validateExpectedType(domain, definition, data);
4060
5020
  return {
4061
5021
  readback_hash: hashJson(data)
@@ -4148,6 +5108,9 @@ async function exportConfigDomain(config, profile, domain, id, outDir, options =
4148
5108
  }
4149
5109
  await ensureConfigCapability(profile, `${definition.capability}.export`);
4150
5110
  const data = await readRemoteConfigDomain(profile, domain, id, definition);
5111
+ if (domain === "form-template") {
5112
+ assertFormTemplateDraftId(id, data, "export");
5113
+ }
4151
5114
  validateExpectedType(domain, definition, data);
4152
5115
  const baseHash = hashJson(data);
4153
5116
  const stem = `${domain}-${id}`;
@@ -4177,7 +5140,8 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
4177
5140
  }
4178
5141
  const work = await readJsonFile(workFile);
4179
5142
  const meta = metaFile ? await readJsonFile(metaFile) : {};
4180
- if (!isRecord3(meta) || meta.domain !== domain || typeof meta.base_hash !== "string") {
5143
+ const createMode = isRecord3(work) && work.mode === "create" || isRecord3(meta) && meta.mode === "create";
5144
+ if (!isRecord3(meta) || meta.domain !== domain || !createMode && typeof meta.base_hash !== "string") {
4181
5145
  throw new Error("Config build requires a meta file produced by `bpmax-cli config <domain> export`.");
4182
5146
  }
4183
5147
  const raw = typeof meta.raw_file === "string" ? await readJsonFile(meta.raw_file) : void 0;
@@ -4193,7 +5157,7 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
4193
5157
  domain,
4194
5158
  built_at: (/* @__PURE__ */ new Date()).toISOString(),
4195
5159
  meta,
4196
- base_hash: meta.base_hash,
5160
+ base_hash: typeof meta.base_hash === "string" ? meta.base_hash : null,
4197
5161
  payload
4198
5162
  };
4199
5163
  await writeJsonFile(outFile, result);
@@ -4211,8 +5175,17 @@ async function lintConfigWorkFile(file) {
4211
5175
  if (Object.prototype.hasOwnProperty.call(value, "content")) {
4212
5176
  lintTemplateFieldReferences(value, errors);
4213
5177
  }
5178
+ if ((Object.prototype.hasOwnProperty.call(value, "content") || isRecord3(value.basic)) && pageTemplateType(value) === 1) {
5179
+ validateListTemplateActionGate(value, errors);
5180
+ }
4214
5181
  if (isFlowTemplateWork(value)) {
4215
- validateFlowTemplateStandardFlowType(value, errors);
5182
+ const flowWork = value;
5183
+ validateFlowTemplateRemoteTemplateRefs(flowWork, errors);
5184
+ if (flowWork.mode === "create") {
5185
+ validateFlowTemplateFormDrivenCreateBaseline(flowWork, errors, { context: "flow-template create" });
5186
+ } else {
5187
+ validateFlowTemplateStandardFlowType(flowWork, errors);
5188
+ }
4216
5189
  }
4217
5190
  }
4218
5191
  return {
@@ -4225,11 +5198,10 @@ async function lintConfigWorkFile(file) {
4225
5198
  async function submitConfigDomain(config, profile, domain, id, submitFile, confirm3, options = {}) {
4226
5199
  void config;
4227
5200
  const definition = CONFIG_DOMAINS[domain];
4228
- if (domain === "role" || domain === "api-platform" || domain === "nav-config") {
5201
+ if (domain === "workspace-flow") {
4229
5202
  if (definition.submitStatus !== "supported") {
4230
5203
  throw new Error(`${CONFIG_SUBMIT_UNSUPPORTED_MESSAGE} Domain: ${domain}.`);
4231
5204
  }
4232
- await ensureConfigCapability(profile, `${definition.capability}.submit`);
4233
5205
  await ensureConfigCapability(profile, `${definition.capability}.export`);
4234
5206
  const submit2 = await readJsonFile(submitFile);
4235
5207
  if (!isRecord3(submit2) || submit2.domain !== domain || !isRecord3(submit2.payload)) {
@@ -4242,6 +5214,83 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
4242
5214
  if (meta2.domain !== domain) {
4243
5215
  throw new Error(`Config submit metadata domain mismatch. Expected ${domain}, got ${String(meta2.domain)}.`);
4244
5216
  }
5217
+ if (normalizeWorkspaceKey(String(meta2.id || "")) !== normalizeWorkspaceKey(id)) {
5218
+ throw new Error(`Config submit metadata id mismatch. Expected ${id}, got ${String(meta2.id || "")}.`);
5219
+ }
5220
+ if (meta2.profile !== profile.name) {
5221
+ throw new Error(`Config submit metadata profile mismatch. Expected ${profile.name}, got ${String(meta2.profile)}.`);
5222
+ }
5223
+ const createMode = meta2.mode === "create";
5224
+ await ensureConfigCapability(profile, `${definition.capability}.${createMode ? "create" : "submit"}`);
5225
+ const workspace = normalizeWorkspaceKey(String(submit2.payload.workspace || id));
5226
+ const metaWorkspace = normalizeWorkspaceKey(String(meta2.workspace || meta2.id || ""));
5227
+ if (metaWorkspace && metaWorkspace !== workspace) {
5228
+ throw new Error(`Config submit metadata workspace mismatch. Expected ${workspace}, got ${metaWorkspace}.`);
5229
+ }
5230
+ const endpoint2 = "/workspace/workspace_flow";
5231
+ const submitPayload2 = { workspace_flow: normalizeWorkspaceFlowItems(submit2.payload.workspace_flow) };
5232
+ const current2 = await readRemoteConfigDomain(profile, domain, workspace, definition);
5233
+ if (typeof submit2.base_hash === "string" && hashJson(current2) !== submit2.base_hash) {
5234
+ throw new Error("Remote config changed after export. Re-export before submitting.");
5235
+ }
5236
+ const expectedConfirm2 = `submit ${domain} ${id}`;
5237
+ if (confirm3 !== expectedConfirm2) {
5238
+ return {
5239
+ dry_run: true,
5240
+ domain,
5241
+ id,
5242
+ endpoint: endpoint2,
5243
+ method: "PUT",
5244
+ params: { workspace },
5245
+ payload: submitPayload2,
5246
+ current_hash: hashJson(current2),
5247
+ next: `Run again with --confirm "${expectedConfirm2}" to submit.`
5248
+ };
5249
+ }
5250
+ const client2 = createApiClient(profile);
5251
+ const response2 = await apiRequest(
5252
+ client2,
5253
+ "PUT",
5254
+ endpoint2,
5255
+ { data: submitPayload2, params: { workspace }, capability: `${definition.capability}.${createMode ? "create" : "submit"}` }
5256
+ );
5257
+ const readback2 = await readRemoteConfigDomain(profile, domain, workspace, definition);
5258
+ const bindings = isRecord3(readback2) ? normalizeWorkspaceFlowItems(readback2.workspace_flow) : [];
5259
+ const expectedBindings = normalizeWorkspaceFlowItems(submitPayload2.workspace_flow);
5260
+ const missingBindings = expectedBindings.filter(
5261
+ (expected) => !bindings.some(
5262
+ (actual) => buildWorkspaceFlowBindingKey(actual.flow_type, actual.flow_key) === buildWorkspaceFlowBindingKey(expected.flow_type, expected.flow_key)
5263
+ )
5264
+ );
5265
+ if (missingBindings.length) {
5266
+ throw new Error(`workspace-flow submit verification failed; missing bindings: ${missingBindings.map((item) => buildWorkspaceFlowBindingKey(item.flow_type, item.flow_key)).join(", ")}`);
5267
+ }
5268
+ return {
5269
+ dry_run: false,
5270
+ domain,
5271
+ id,
5272
+ endpoint: endpoint2,
5273
+ method: "PUT",
5274
+ params: { workspace },
5275
+ response: response2,
5276
+ readback_hash: hashJson(readback2)
5277
+ };
5278
+ }
5279
+ if (domain === "role" || domain === "api-platform" || domain === "nav-config") {
5280
+ if (definition.submitStatus !== "supported") {
5281
+ throw new Error(`${CONFIG_SUBMIT_UNSUPPORTED_MESSAGE} Domain: ${domain}.`);
5282
+ }
5283
+ const submit2 = await readJsonFile(submitFile);
5284
+ if (!isRecord3(submit2) || submit2.domain !== domain || !isRecord3(submit2.payload)) {
5285
+ throw new Error("Config submit requires a payload produced by `bpmax-cli config <domain> build`.");
5286
+ }
5287
+ const meta2 = submit2.meta;
5288
+ if (!isRecord3(meta2)) {
5289
+ throw new Error("Config submit payload is missing export metadata. Export the remote config first, then rebuild with --meta.");
5290
+ }
5291
+ if (meta2.domain !== domain) {
5292
+ throw new Error(`Config submit metadata domain mismatch. Expected ${domain}, got ${String(meta2.domain)}.`);
5293
+ }
4245
5294
  if (String(meta2.id || "") !== id) {
4246
5295
  throw new Error(`Config submit metadata id mismatch. Expected ${id}, got ${String(meta2.id || "")}.`);
4247
5296
  }
@@ -4251,10 +5300,22 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
4251
5300
  if (meta2.workspace !== profile.config.workspace) {
4252
5301
  throw new Error(`Config submit metadata workspace mismatch. Expected ${profile.config.workspace}, got ${String(meta2.workspace)}.`);
4253
5302
  }
5303
+ const createMode = meta2.mode === "create";
5304
+ if (createMode) {
5305
+ await ensureConfigCapability(profile, `${definition.capability}.create`);
5306
+ if (aggregatePayloadHasNonCreateOperations(domain, submit2.payload)) {
5307
+ await ensureConfigCapability(profile, `${definition.capability}.submit`);
5308
+ }
5309
+ } else {
5310
+ await ensureConfigCapability(profile, `${definition.capability}.submit`);
5311
+ await ensureConfigCapability(profile, `${definition.capability}.export`);
5312
+ }
4254
5313
  const expectedConfirm2 = `submit ${domain} ${id}`;
4255
- const current2 = domain === "role" ? await collectRoleAggregate(profile, id) : domain === "api-platform" ? await collectApiPlatformAggregate(profile, id) : await collectNavConfigAggregate(profile, id);
4256
- if (hashJson(current2.raw) !== submit2.base_hash) {
4257
- throw new Error("Remote config changed after export. Re-export before submitting.");
5314
+ if (!createMode) {
5315
+ const current2 = domain === "role" ? await collectRoleAggregate(profile, id) : domain === "api-platform" ? await collectApiPlatformAggregate(profile, id) : await collectNavConfigAggregate(profile, id);
5316
+ if (hashJson(current2.raw) !== submit2.base_hash) {
5317
+ throw new Error("Remote config changed after export. Re-export before submitting.");
5318
+ }
4258
5319
  }
4259
5320
  if (confirm3 !== expectedConfirm2) {
4260
5321
  return {
@@ -4277,8 +5338,6 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
4277
5338
  if (definition.submitStatus !== "supported" || !definition.submitPath || !definition.submitMethod) {
4278
5339
  throw new Error(`${CONFIG_SUBMIT_UNSUPPORTED_MESSAGE} Domain: ${domain}.`);
4279
5340
  }
4280
- await ensureConfigCapability(profile, `${definition.capability}.submit`);
4281
- await ensureConfigCapability(profile, `${definition.capability}.export`);
4282
5341
  const submit = await readJsonFile(submitFile);
4283
5342
  if (!isRecord3(submit) || submit.domain !== domain || !isRecord3(submit.payload)) {
4284
5343
  throw new Error("Config submit requires a payload produced by `bpmax-cli config <domain> build`.");
@@ -4299,12 +5358,130 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
4299
5358
  if (meta.workspace !== profile.config.workspace) {
4300
5359
  throw new Error(`Config submit metadata workspace mismatch. Expected ${profile.config.workspace}, got ${String(meta.workspace)}.`);
4301
5360
  }
5361
+ const submitMode = isRecord3(meta) ? meta.mode : void 0;
5362
+ if (submitMode === "create" && domain !== "form-template") {
5363
+ if (!definition.createPath || !definition.createMethod) {
5364
+ throw new Error(`${domain} create is not implemented in the typed adapter.`);
5365
+ }
5366
+ if (domain === "list-template") {
5367
+ validateListTemplateActionGate(submit.payload);
5368
+ }
5369
+ await ensureConfigCapability(profile, `${definition.capability}.create`);
5370
+ const expectedConfirm2 = `submit ${domain} ${id}`;
5371
+ if (confirm3 !== expectedConfirm2) {
5372
+ return {
5373
+ dry_run: true,
5374
+ domain,
5375
+ id,
5376
+ endpoint: definition.createPath,
5377
+ method: definition.createMethod,
5378
+ payload: submit.payload,
5379
+ next: `Run again with --confirm "${expectedConfirm2}" to submit.`
5380
+ };
5381
+ }
5382
+ const client2 = createApiClient(profile);
5383
+ const response2 = await apiRequest(
5384
+ client2,
5385
+ definition.createMethod,
5386
+ definition.createPath,
5387
+ { data: submit.payload, capability: `${definition.capability}.create` }
5388
+ );
5389
+ const createdId = responseDataId(response2);
5390
+ let readbackHash = null;
5391
+ if (createdId !== void 0 && createdId !== null && createdId !== "" && definition.exportPath) {
5392
+ try {
5393
+ await ensureConfigCapability(profile, `${definition.capability}.export`);
5394
+ readbackHash = hashJson(await readRemoteConfigDomain(profile, domain, String(createdId), definition));
5395
+ } catch {
5396
+ readbackHash = null;
5397
+ }
5398
+ }
5399
+ return {
5400
+ dry_run: false,
5401
+ domain,
5402
+ id,
5403
+ created_id: createdId ?? null,
5404
+ endpoint: definition.createPath,
5405
+ method: definition.createMethod,
5406
+ response: response2,
5407
+ readback_hash: readbackHash
5408
+ };
5409
+ }
5410
+ await ensureConfigCapability(profile, `${definition.capability}.submit`);
5411
+ await ensureConfigCapability(profile, `${definition.capability}.export`);
4302
5412
  if (domain === "flow-template") {
5413
+ validateFlowTemplateRemoteTemplateRefs(submit.payload);
4303
5414
  validateFlowTemplateStandardFlowType(submit.payload);
4304
5415
  validateFlowTemplateIdentityStandard(id, submit.payload);
4305
5416
  }
5417
+ if (domain === "list-template") {
5418
+ validateListTemplateActionGate(submit.payload);
5419
+ }
5420
+ if (domain === "form-template" && submitMode === "create") {
5421
+ await ensureConfigCapability(profile, `${definition.capability}.create`);
5422
+ const expectedConfirm2 = `submit ${domain} ${id}`;
5423
+ const endpoint2 = "/form_template";
5424
+ if (confirm3 !== expectedConfirm2) {
5425
+ return {
5426
+ dry_run: true,
5427
+ domain,
5428
+ id,
5429
+ endpoint: endpoint2,
5430
+ method: "POST",
5431
+ payload: submit.payload,
5432
+ publish_endpoint: "/form_template/publish",
5433
+ next: `Run again with --confirm "${expectedConfirm2}" to submit.`
5434
+ };
5435
+ }
5436
+ const client2 = createApiClient(profile);
5437
+ const response2 = await apiRequest(
5438
+ client2,
5439
+ "POST",
5440
+ endpoint2,
5441
+ { data: submit.payload, capability: `${definition.capability}.create` }
5442
+ );
5443
+ const draftId = responseDataId(response2);
5444
+ if (draftId === void 0 || draftId === null || draftId === "") {
5445
+ throw new Error("form-template create did not return a draft id.");
5446
+ }
5447
+ const publishResponse2 = await apiRequest(
5448
+ client2,
5449
+ "POST",
5450
+ "/form_template/publish",
5451
+ { data: { id: draftId }, capability: `${definition.capability}.submit` }
5452
+ );
5453
+ const publishedId = responseDataId(publishResponse2) ?? draftId;
5454
+ const draftReadback = await apiRequest(
5455
+ client2,
5456
+ "GET",
5457
+ `/form_template/${draftId}`,
5458
+ { capability: `${definition.capability}.export` }
5459
+ );
5460
+ const publishedReadback = await apiRequest(
5461
+ client2,
5462
+ "GET",
5463
+ `/form_template/${publishedId}`,
5464
+ { capability: `${definition.capability}.export` }
5465
+ );
5466
+ return {
5467
+ dry_run: false,
5468
+ domain,
5469
+ id,
5470
+ endpoint: endpoint2,
5471
+ method: "POST",
5472
+ response: response2,
5473
+ draft_id: draftId,
5474
+ published_id: publishedId,
5475
+ publish_response: publishResponse2,
5476
+ draft_readback_hash: hashJson(draftReadback),
5477
+ published_readback_hash: hashJson(publishedReadback)
5478
+ };
5479
+ }
4306
5480
  const expectedConfirm = `submit ${domain} ${id}`;
4307
5481
  const current = await readRemoteConfigDomain(profile, domain, id, definition);
5482
+ if (domain === "form-template") {
5483
+ assertFormTemplateDraftId(id, current, "submit");
5484
+ }
4308
5485
  validateExpectedType(domain, definition, current);
4309
5486
  const currentHash = hashJson(current);
4310
5487
  if (currentHash !== submit.base_hash) {
@@ -4372,6 +5549,125 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
4372
5549
  ...readback
4373
5550
  };
4374
5551
  }
5552
+ async function deleteConfigDomain(config, profile, domain, id, confirm3) {
5553
+ void config;
5554
+ const definition = CONFIG_DOMAINS[domain];
5555
+ if (domain === "workspace-flow") {
5556
+ return deleteWorkspaceFlowBinding(profile, id, confirm3);
5557
+ }
5558
+ await ensureConfigCapability(profile, `${definition.capability}.delete`);
5559
+ const expectedConfirm = `delete ${domain} ${id}`;
5560
+ const client = createApiClient(profile);
5561
+ if (domain === "nav-config") {
5562
+ await ensureConfigCapability(profile, `${definition.capability}.export`);
5563
+ const current = await collectNavConfigAggregate(profile, id);
5564
+ const configs = isRecord3(current.raw.configs) ? current.raw.configs : {};
5565
+ const operations = [];
5566
+ for (const type of NAV_CONFIG_TYPES) {
5567
+ const item = isRecord3(configs[type]) ? configs[type] : {};
5568
+ const itemId = item.id;
5569
+ if (itemId !== void 0 && itemId !== null && itemId !== "") {
5570
+ operations.push({ type, method: "DELETE", path: `/configuration/${itemId}?is_default_action=1`, id: itemId });
5571
+ }
5572
+ }
5573
+ if (confirm3 !== expectedConfirm) {
5574
+ return {
5575
+ dry_run: true,
5576
+ domain,
5577
+ id,
5578
+ operation_plan: { operations },
5579
+ next: `Run again with --confirm "${expectedConfirm}" to delete.`
5580
+ };
5581
+ }
5582
+ const responses = await submitOperationPlan(profile, definition.capability, operations);
5583
+ return {
5584
+ dry_run: false,
5585
+ domain,
5586
+ id,
5587
+ operation_responses: responses
5588
+ };
5589
+ }
5590
+ const endpoint = domain === "api-platform" ? apiPlatformDeletePath(id) : definition.deletePath?.(id);
5591
+ if (!endpoint || !definition.deleteMethod) {
5592
+ throw new Error(`${domain} delete is not implemented in the typed adapter.`);
5593
+ }
5594
+ if (confirm3 !== expectedConfirm) {
5595
+ return {
5596
+ dry_run: true,
5597
+ domain,
5598
+ id,
5599
+ endpoint,
5600
+ method: definition.deleteMethod,
5601
+ next: `Run again with --confirm "${expectedConfirm}" to delete.`
5602
+ };
5603
+ }
5604
+ const response = await apiRequest(
5605
+ client,
5606
+ definition.deleteMethod,
5607
+ endpoint,
5608
+ { capability: `${definition.capability}.delete` }
5609
+ );
5610
+ return {
5611
+ dry_run: false,
5612
+ domain,
5613
+ id,
5614
+ endpoint,
5615
+ method: definition.deleteMethod,
5616
+ response
5617
+ };
5618
+ }
5619
+ async function runDatasetLifecycleAction(config, profile, action, id, confirm3) {
5620
+ void config;
5621
+ const commandAction = action;
5622
+ const normalizedAction = action === "reindex" ? "refresh" : action;
5623
+ const definition = CONFIG_DOMAINS.dataset;
5624
+ const capability = `${definition.capability}.${normalizedAction === "cancel-refresh" ? "cancel_refresh" : normalizedAction}`;
5625
+ await ensureConfigCapability(profile, capability);
5626
+ const method = "POST";
5627
+ const expectedConfirm = `${commandAction} dataset ${id}`;
5628
+ const operations = normalizedAction === "refresh" ? [
5629
+ { action: "pause", method, endpoint: `/data_set/pause/${id}`, capability: `${definition.capability}.pause`, optional: true },
5630
+ { action: "publish", method, endpoint: `/data_set/publish/${id}`, capability: `${definition.capability}.publish` }
5631
+ ] : [
5632
+ { action: normalizedAction, method, endpoint: `/data_set/${normalizedAction}/${id}`, capability }
5633
+ ];
5634
+ if (confirm3 !== expectedConfirm) {
5635
+ return {
5636
+ dry_run: true,
5637
+ domain: "dataset",
5638
+ id,
5639
+ action: commandAction,
5640
+ operations,
5641
+ next: `Run again with --confirm "${expectedConfirm}" to ${commandAction} dataset ${id}.`
5642
+ };
5643
+ }
5644
+ const client = createApiClient(profile);
5645
+ const current = await readRemoteConfigDomain(profile, "dataset", id, definition);
5646
+ const currentStatus = isRecord3(current) ? Number(current.status) : NaN;
5647
+ const executableOperations = normalizedAction === "refresh" && currentStatus !== 1 && currentStatus !== 3 ? operations.filter((operation) => operation.action !== "pause") : operations;
5648
+ const responses = [];
5649
+ for (const operation of executableOperations) {
5650
+ responses.push({
5651
+ action: operation.action,
5652
+ response: await apiRequest(
5653
+ client,
5654
+ operation.method,
5655
+ operation.endpoint,
5656
+ { data: {}, capability: operation.capability }
5657
+ )
5658
+ });
5659
+ }
5660
+ const readback = await readRemoteConfigDomain(profile, "dataset", id, definition);
5661
+ return {
5662
+ dry_run: false,
5663
+ domain: "dataset",
5664
+ id,
5665
+ action: commandAction,
5666
+ operations: executableOperations,
5667
+ operation_responses: responses,
5668
+ readback
5669
+ };
5670
+ }
4375
5671
 
4376
5672
  // src/core/config-workspace.ts
4377
5673
  import { mkdir as mkdir4, readFile as readFile7, writeFile as writeFile4 } from "fs/promises";
@@ -4459,6 +5755,7 @@ ${configEnabled ? "" : "> \u5F53\u524D profile \u7684 API Key \u5C1A\u672A\u5F00
4459
5755
  | --- | --- | --- |
4460
5756
  ${rows}
4461
5757
  | \u6700\u65B0\u914D\u7F6E\u540C\u6B65 | \`bpmax-config-latest\` | \`${commandPrefix3} config latest pull ${options.env}\` |
5758
+ | \u957F\u671F\u8BB0\u5FC6 | \`bpmax-memory-protocol\` | \`${commandPrefix3} memory search --scope all --query "<workspace> <flow_type> <task>"\` |
4462
5759
  | \u5B8C\u6574\u914D\u7F6E\u7F16\u6392 | \`bpmax-e2e-flow-config-orchestrator\` | \u6309\u7F16\u6392 Skill \u6267\u884C |
4463
5760
  | \u7AEF\u5230\u7AEF\u56DE\u5F52 | \`bpmax-e2e-flow-test-operator\` | \u6309\u56DE\u5F52 Skill \u6267\u884C |
4464
5761
 
@@ -4487,6 +5784,20 @@ ${commandPrefix3} config <domain> verify --id <id> --expect <work-file> --profil
4487
5784
  ${commandPrefix3} config workspace init ${envArg} --profile ${profileArg} --workspace-dir ${shellQuote3(options.environment.sysconfig_repo_path)} --format json
4488
5785
  ${commandPrefix3} config latest pull ${envArg} --profile ${profileArg} --format json
4489
5786
  \`\`\`
5787
+
5788
+ ## Memory \u4F7F\u7528\u89C4\u5219
5789
+ \u5F00\u59CB\u914D\u7F6E\u3001\u6392\u67E5\u6216\u6D4B\u8BD5\u524D\uFF0C\u5148\u8C03\u7528 \`bpmax-memory-protocol\` \u6216\u76F4\u63A5\u641C\u7D22 BPMAX memory\u3002\u67E5\u8BE2\u8BCD\u81F3\u5C11\u5305\u542B\u4E1A\u52A1\u540D\u3001workspace\u3001flow_type\u3001\u6A21\u677F/\u6570\u636E\u96C6/\u5BF9\u8C61 id \u548C\u76EE\u6807\u52A8\u4F5C\u3002
5790
+
5791
+ \`\`\`bash
5792
+ ${commandPrefix3} memory status --profile ${profileArg} --format json
5793
+ ${commandPrefix3} memory search --profile ${profileArg} --scope all --query "${display(options.environment.workspace || options.profile.workspace)} <flow_type> <task>" --format json
5794
+ \`\`\`
5795
+
5796
+ \u9A8C\u8BC1\u901A\u8FC7\u540E\uFF0C\u53EA\u5199\u53EF\u590D\u7528\u7ED3\u8BBA\uFF1A\`decision\`\u3001\`task_learning\`\u3001\`anti_pattern\`\u3001\`environmental\` \u6216 \`convention\`\u3002\u672A\u5B8C\u6210\u6216\u4E2D\u65AD\u6001\u53EA\u5199 \`session_state\`\u3002\u7981\u6B62\u5199\u5165 API Key\u3001Authorization\u3001token\u3001password\u3001\u9A8C\u8BC1\u7801\u3001\u624B\u673A\u53F7\u3001\u5B8C\u6574 payload \u6216\u5927\u6BB5\u63A5\u53E3\u54CD\u5E94\u3002
5797
+
5798
+ \`\`\`bash
5799
+ ${commandPrefix3} memory add --profile ${profileArg} --scope user --text "<learning>" --metadata '{"type":"task_learning","project_id":"bpmax","workspace":"${display(options.environment.workspace || options.profile.workspace)}"}' --format json
5800
+ \`\`\`
4490
5801
  ${end}
4491
5802
  `;
4492
5803
  }
@@ -5256,6 +6567,24 @@ function registerConfigCommands(program2) {
5256
6567
  next: `Run git -C ${environment.sysconfig_repo_path} status --short and git diff to inspect local changes.`
5257
6568
  });
5258
6569
  });
6570
+ config.command("flow-app").description("Create an end-to-end BPMAX flow app from form and flow work files").command("create").description("Create a form template, create a main flow, bind the published form, and bind the flow to a workspace").requiredOption("--workspace <workspace>", "Target workspace key, e.g. oa or w:oa").requiredOption("--form-work <file>", "Form-template work JSON file").requiredOption("--flow-work <file>", "Flow-template work JSON file").requiredOption("--name <name>", "Flow app name used in the confirmation text").option("--profile <profile>", "Profile name").option("--draft-only", "Save the created flow as draft only instead of publishing live").option("--confirm <text>", "Exact confirmation text").option("--format <format>", "Output format", "pretty").action(async (options) => {
6571
+ const configData = await loadConfig();
6572
+ const resolved = resolveProfile(configData, options.profile);
6573
+ const result = await createFlowAppFromWork(
6574
+ configData,
6575
+ resolved,
6576
+ options.formWork,
6577
+ options.flowWork,
6578
+ options.confirm,
6579
+ {
6580
+ workspace: options.workspace,
6581
+ name: options.name,
6582
+ publishLive: !options.draftOnly
6583
+ }
6584
+ );
6585
+ await saveConfig(configData);
6586
+ printResult(options.format, result);
6587
+ });
5259
6588
  const init = config.command("init").description("Initialize BPMAX configuration helper files");
5260
6589
  init.command("workspace").description("Create or update an AGENTS.md BPMAX configuration guide in a workspace directory").requiredOption("--env <env>", "Configuration environment key").option("--profile <profile>", "Profile name").option("--cwd <dir>", "Target workspace directory", process.cwd()).option("--file <file>", "Agent guide file name", DEFAULT_AGENT_GUIDE_FILE).option("--dry-run", "Print the generated content without writing the file").option("--format <format>", "Output format", "pretty").action(async (options) => {
5261
6590
  const configData = await loadConfig();
@@ -5272,6 +6601,33 @@ function registerConfigCommands(program2) {
5272
6601
  });
5273
6602
  Object.keys(CONFIG_DOMAINS).forEach((domain) => {
5274
6603
  const domainCommand = config.command(domain).description(`Manage BPMAX ${domain} configuration`);
6604
+ const createCommand = domainCommand.command("create").description(domain === "flow-template" ? "Create a new main flow template through the typed adapter" : `Create a ${domain} config object through a verified typed adapter; dry-run unless --confirm is exact`).option("--profile <profile>", "Profile name").option("--confirm <text>", "Exact confirmation text").option("--publish-live", "For flow-template, publish the created flow to live after saving draft").option("--format <format>", "Output format", "pretty");
6605
+ if (domain === "flow-template") {
6606
+ createCommand.requiredOption("--work <file>", "Flow-template work JSON file");
6607
+ } else {
6608
+ createCommand.requiredOption("--id <id>", "Create operation id used in payload metadata, for example create:<domain>").requiredOption("--payload <file>", "Create submit payload JSON file produced by build");
6609
+ }
6610
+ createCommand.action(async (options) => {
6611
+ const configData = await loadConfig();
6612
+ const resolved = resolveProfile(configData, options.profile);
6613
+ const result = domain === "flow-template" ? await createFlowTemplateFromWork(
6614
+ configData,
6615
+ resolved,
6616
+ String(options.work || ""),
6617
+ options.confirm,
6618
+ { publishLive: Boolean(options.publishLive) }
6619
+ ) : await submitConfigDomain(
6620
+ configData,
6621
+ resolved,
6622
+ domain,
6623
+ String(options.id || ""),
6624
+ String(options.payload || ""),
6625
+ options.confirm,
6626
+ { publishLive: Boolean(options.publishLive) }
6627
+ );
6628
+ await saveConfig(configData);
6629
+ printResult(options.format, result);
6630
+ });
5275
6631
  domainCommand.command("export").description(`Export remote ${domain} configuration into raw/work/meta files`).requiredOption("--id <id>", "Remote config id").option("--profile <profile>", "Profile name").option("--out <outDir>", "Output directory", `.codex/tmp/${domain}-editor`).option("--work-format <format>", "Work file format for supported domains: raw | structured", "raw").option("--format <format>", "Output format", "pretty").action(async (options) => {
5276
6632
  const configData = await loadConfig();
5277
6633
  const resolved = resolveProfile(configData, options.profile);
@@ -5324,6 +6680,42 @@ function registerConfigCommands(program2) {
5324
6680
  await saveConfig(configData);
5325
6681
  printResult(options.format, result);
5326
6682
  });
6683
+ domainCommand.command("delete").description(`Delete a ${domain} config object through a verified typed adapter; dry-run unless --confirm is exact`).requiredOption("--id <id>", "Remote config id").option("--profile <profile>", "Profile name").option("--confirm <text>", "Exact confirmation text").option("--format <format>", "Output format", "pretty").action(async (options) => {
6684
+ const configData = await loadConfig();
6685
+ const resolved = resolveProfile(configData, options.profile);
6686
+ const result = await deleteConfigDomain(
6687
+ configData,
6688
+ resolved,
6689
+ domain,
6690
+ options.id,
6691
+ options.confirm
6692
+ );
6693
+ await saveConfig(configData);
6694
+ printResult(options.format, result);
6695
+ });
6696
+ if (domain === "dataset") {
6697
+ [
6698
+ ["publish", "Publish/start a dataset and trigger ES batch generation"],
6699
+ ["pause", "Pause a published or pending dataset"],
6700
+ ["cancel-refresh", "Cancel a stuck dataset refresh without changing publish status"],
6701
+ ["refresh", "Refresh/reindex a dataset and generate a new ES batch"],
6702
+ ["reindex", "Alias of refresh; regenerate the dataset ES batch"]
6703
+ ].forEach(([action, description]) => {
6704
+ domainCommand.command(action).description(`${description}; dry-run unless --confirm is exact`).requiredOption("--id <id>", "Remote dataset id").option("--profile <profile>", "Profile name").option("--confirm <text>", "Exact confirmation text").option("--format <format>", "Output format", "pretty").action(async (options) => {
6705
+ const configData = await loadConfig();
6706
+ const resolved = resolveProfile(configData, options.profile);
6707
+ const result = await runDatasetLifecycleAction(
6708
+ configData,
6709
+ resolved,
6710
+ action,
6711
+ options.id,
6712
+ options.confirm
6713
+ );
6714
+ await saveConfig(configData);
6715
+ printResult(options.format, result);
6716
+ });
6717
+ });
6718
+ }
5327
6719
  domainCommand.command("verify").description(`Read back a ${domain} config and optionally compare with an expected JSON file`).requiredOption("--id <id>", "Remote config id").option("--expect <file>", "Expected JSON file").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
5328
6720
  const configData = await loadConfig();
5329
6721
  const resolved = resolveProfile(configData, options.profile);
@@ -5401,7 +6793,7 @@ function registerEsCommands(program2) {
5401
6793
  }
5402
6794
 
5403
6795
  // src/commands/flow.ts
5404
- function normalizeWorkspaceKey(workspace) {
6796
+ function normalizeWorkspaceKey2(workspace) {
5405
6797
  const nextWorkspace = workspace.trim().replace(/^\/+|\/+$/g, "");
5406
6798
  return nextWorkspace.startsWith("w:") ? nextWorkspace.slice(2) : nextWorkspace;
5407
6799
  }
@@ -5412,11 +6804,12 @@ async function getWorkspaceFlowBindings(client, profile, options) {
5412
6804
  if (options.all) {
5413
6805
  return void 0;
5414
6806
  }
5415
- const workspace = normalizeWorkspaceKey(options.workspace || profile.config.workspace);
6807
+ const workspace = normalizeWorkspaceKey2(options.workspace || profile.config.workspace);
5416
6808
  const workspaceInfo = await apiRequest(client, "GET", "/workspace/by_key", {
5417
6809
  params: {
5418
6810
  key: workspace
5419
- }
6811
+ },
6812
+ capability: "flow.list"
5420
6813
  });
5421
6814
  return new Set(
5422
6815
  (workspaceInfo.workspace_flow || []).map((item) => flowBindingKey(item.flow_type, item.flow_key))
@@ -5784,6 +7177,85 @@ function registerInitCommand(program2, deps = {}) {
5784
7177
  });
5785
7178
  }
5786
7179
 
7180
+ // src/commands/memory.ts
7181
+ function parseLimit(input, fallback) {
7182
+ const value = Number(input ?? fallback);
7183
+ if (!Number.isInteger(value) || value <= 0 || value > 100) {
7184
+ throw new Error("limit must be an integer between 1 and 100.");
7185
+ }
7186
+ return value;
7187
+ }
7188
+ function normalizeScope(scope, allowAll) {
7189
+ const value = scope || "user";
7190
+ const allowed = allowAll ? ["user", "organization", "all"] : ["user", "organization"];
7191
+ if (!allowed.includes(value)) {
7192
+ throw new Error(`scope must be one of: ${allowed.join(", ")}.`);
7193
+ }
7194
+ return value;
7195
+ }
7196
+ async function parseOptionalJson(input, label) {
7197
+ if (!input) {
7198
+ return void 0;
7199
+ }
7200
+ return parseJsonInput(input, label);
7201
+ }
7202
+ async function memoryRequest(options, method, path9, capability, data, params) {
7203
+ const profile = resolveProfile(await loadConfig(), options.profile);
7204
+ const client = createApiClient(profile);
7205
+ return apiRequest(client, method, path9, {
7206
+ capability,
7207
+ data: redactAuditValue(data),
7208
+ params: params ? redactAuditValue(params) : void 0
7209
+ });
7210
+ }
7211
+ function registerMemoryCommands(program2) {
7212
+ const memory = program2.command("memory").description("Search and write BPMAX agent-scoped memory through the platform proxy");
7213
+ memory.command("status").description("Check BPMAX memory proxy and backend status").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
7214
+ const result = await memoryRequest(options, "GET", "/cli/memory/status", "memory.status");
7215
+ printResult(options.format, result);
7216
+ });
7217
+ memory.command("search").description("Search BPMAX memory for the current API-key agent").requiredOption("--query <text>", "Search query").option("--scope <scope>", "Memory scope: user, organization, or all", "user").option("--limit <limit>", "Maximum result count", "10").option("--filters <json>", "Optional JSON filters or @file").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
7218
+ const result = await memoryRequest(options, "POST", "/cli/memory/search", "memory.search", {
7219
+ query: options.query,
7220
+ scope: normalizeScope(options.scope, true),
7221
+ limit: parseLimit(options.limit, 10),
7222
+ filters: await parseOptionalJson(options.filters, "--filters")
7223
+ });
7224
+ printResult(options.format, result);
7225
+ });
7226
+ memory.command("add").description("Add BPMAX memory for the current API-key agent").requiredOption("--text <text>", "Memory text").option("--scope <scope>", "Memory scope: user or organization", "user").option("--metadata <json>", "Optional JSON metadata or @file").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
7227
+ const result = await memoryRequest(options, "POST", "/cli/memory", "memory.add", {
7228
+ text: options.text,
7229
+ scope: normalizeScope(options.scope, false),
7230
+ metadata: await parseOptionalJson(options.metadata, "--metadata")
7231
+ });
7232
+ printResult(options.format, result);
7233
+ });
7234
+ memory.command("list").description("List BPMAX memory when supported by the platform proxy").option("--scope <scope>", "Memory scope: user, organization, or all", "user").option("--limit <limit>", "Maximum result count", "20").option("--filters <json>", "Optional JSON filters or @file").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
7235
+ const result = await memoryRequest(options, "GET", "/cli/memory", "memory.list", void 0, {
7236
+ scope: normalizeScope(options.scope, true),
7237
+ limit: parseLimit(options.limit, 20),
7238
+ filters: options.filters ? JSON.stringify(await parseOptionalJson(options.filters, "--filters")) : void 0
7239
+ });
7240
+ printResult(options.format, result);
7241
+ });
7242
+ memory.command("get <id>").description("Get one BPMAX memory item when supported by the platform proxy").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (id, options) => {
7243
+ const result = await memoryRequest(options, "GET", `/cli/memory/${encodeURIComponent(id)}`, "memory.get");
7244
+ printResult(options.format, result);
7245
+ });
7246
+ memory.command("update <id>").description("Update one BPMAX memory item when supported by the platform proxy").requiredOption("--text <text>", "Replacement memory text").option("--metadata <json>", "Optional JSON metadata or @file").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (id, options) => {
7247
+ const result = await memoryRequest(options, "PUT", `/cli/memory/${encodeURIComponent(id)}`, "memory.update", {
7248
+ text: options.text,
7249
+ metadata: await parseOptionalJson(options.metadata, "--metadata")
7250
+ });
7251
+ printResult(options.format, result);
7252
+ });
7253
+ memory.command("delete <id>").description("Delete one BPMAX memory item when supported by the platform proxy").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (id, options) => {
7254
+ const result = await memoryRequest(options, "DELETE", `/cli/memory/${encodeURIComponent(id)}`, "memory.delete");
7255
+ printResult(options.format, result);
7256
+ });
7257
+ }
7258
+
5787
7259
  // src/core/form-schema.ts
5788
7260
  var FIELD_KEY_NAMES = [
5789
7261
  "key",
@@ -6295,7 +7767,9 @@ async function fetchProjectFormTemplate(client, flowDetail) {
6295
7767
  if (!templateId) {
6296
7768
  return void 0;
6297
7769
  }
6298
- const template = await apiRequest(client, "GET", `/form_template/${templateId}`);
7770
+ const template = await apiRequest(client, "GET", `/form_template/${templateId}`, {
7771
+ capability: "project.create"
7772
+ });
6299
7773
  return { templateId, template };
6300
7774
  }
6301
7775
  function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
@@ -6438,7 +7912,9 @@ async function validateCreateForm(client, options) {
6438
7912
  }
6439
7913
  const templateId = getFlowFormTemplateId(flowDetail);
6440
7914
  if (options.projectFormTemplate || templateId) {
6441
- const template = options.projectFormTemplate?.template ?? (templateId ? await apiRequest(client, "GET", `/form_template/${templateId}`) : void 0);
7915
+ const template = options.projectFormTemplate?.template ?? (templateId ? await apiRequest(client, "GET", `/form_template/${templateId}`, {
7916
+ capability: "project.create"
7917
+ }) : void 0);
6442
7918
  const templateFields = extractFormFields(template);
6443
7919
  if (templateFields.length > 0) {
6444
7920
  const result2 = validateFormAgainstFields(options.form, templateFields);
@@ -7399,31 +8875,69 @@ var schemaEntries = [
7399
8875
  { name: "config.adapters", description: "Show typed config adapter coverage and verified API surfaces.", bootstrap: true },
7400
8876
  { name: "config.init.workspace", description: "Create or update a local AGENTS.md BPMAX config guide.", bootstrap: true },
7401
8877
  { name: "config.form_template.export", description: "Export form template config.", method: "GET", path: "/api/form_template/:id" },
8878
+ { name: "config.form_template.create", description: "Create and publish a form template through a verified typed adapter.", method: "POST", path: "/api/form_template + /api/form_template/publish" },
8879
+ { name: "config.form_template.delete", description: "Delete a form template through a verified typed adapter.", method: "DELETE", path: "/api/form_template/:id" },
7402
8880
  { name: "config.form_template.submit", description: "Submit form template edits through a verified typed adapter.", method: "PUT/POST", path: "/api/form_template/:id + /api/form_template/publish" },
7403
8881
  { name: "config.flow_template.export", description: "Export flow template config when a verified draft-aware adapter is available.", method: "GET", path: "/api/flow?flow_type=:flow_type&key=:key&draft=1" },
8882
+ { name: "config.flow_template.create", description: "Create a platform-generated main flow shell through a verified typed adapter.", method: "POST", path: "/api/flow/flow_type" },
8883
+ { name: "config.flow_template.delete", description: "Delete a flow template by flow_type or key through a verified typed adapter.", method: "DELETE", path: "/api/flow?flow_type=:flow_type&key=:key" },
7404
8884
  { name: "config.flow_template.submit", description: "Submit flow template config when a verified draft-aware adapter is available.", method: "PUT", path: "/api/flow?flow_type=:flow_type&key=:key&publish=:publish" },
8885
+ { name: "config.workspace_flow.export", description: "Export workspace-bound flow relations.", method: "GET", path: "/api/workspace/by_key?key=:workspace" },
8886
+ { name: "config.workspace_flow.create", description: "Create one workspace-flow binding through the verified workspace-flow adapter.", method: "PUT", path: "/api/workspace/workspace_flow" },
8887
+ { name: "config.workspace_flow.delete", description: "Delete one workspace-flow binding through a typed adapter.", method: "PUT", path: "/api/workspace/workspace_flow" },
8888
+ { name: "config.workspace_flow.submit", description: "Submit workspace-bound flow relations through a verified typed adapter.", method: "PUT", path: "/api/workspace/workspace_flow" },
8889
+ { name: "config.flow_app.create", description: "Create form template, create flow template, bind form, and bind the flow to a workspace.", method: "POST/PUT", path: "/api/form_template + /api/flow/flow_type + /api/flow + /api/workspace/workspace_flow" },
7405
8890
  { name: "config.list_template.export", description: "Export list template config.", method: "GET", path: "/api/flow_page_template/:id?skip_i18n=true" },
8891
+ { name: "config.list_template.create", description: "Create list template config through a verified typed adapter.", method: "POST", path: "/api/flow_page_template" },
8892
+ { name: "config.list_template.delete", description: "Delete list template config through a verified typed adapter.", method: "DELETE", path: "/api/flow_page_template/:id" },
7406
8893
  { name: "config.list_template.submit", description: "Submit list template edits through a verified typed adapter.", method: "PUT", path: "/api/flow_page_template/:id" },
7407
8894
  { name: "config.filter_template.export", description: "Export filter template config.", method: "GET", path: "/api/flow_page_template/:id?skip_i18n=true" },
8895
+ { name: "config.filter_template.create", description: "Create filter template config through a verified typed adapter.", method: "POST", path: "/api/flow_page_template" },
8896
+ { name: "config.filter_template.delete", description: "Delete filter template config through a verified typed adapter.", method: "DELETE", path: "/api/flow_page_template/:id" },
7408
8897
  { name: "config.filter_template.submit", description: "Submit filter template edits through a verified typed adapter.", method: "PUT", path: "/api/flow_page_template/:id" },
7409
8898
  { name: "config.project_detail_template.export", description: "Export project detail template config.", method: "GET", path: "/api/flow_page_template/:id?type=2&create=&skip_i18n=true" },
8899
+ { name: "config.project_detail_template.create", description: "Create project detail template config through a verified typed adapter.", method: "POST", path: "/api/flow_page_template" },
8900
+ { name: "config.project_detail_template.delete", description: "Delete project detail template config through a verified typed adapter.", method: "DELETE", path: "/api/flow_page_template/:id" },
7410
8901
  { name: "config.project_detail_template.submit", description: "Submit project detail template edits through a verified typed adapter.", method: "PUT", path: "/api/flow_page_template/:id" },
7411
8902
  { name: "config.console_template.export", description: "Export console template config.", method: "GET", path: "/api/flow_page_template/:id?skip_i18n=true" },
8903
+ { name: "config.console_template.create", description: "Create console template config through a verified typed adapter.", method: "POST", path: "/api/flow_page_template" },
8904
+ { name: "config.console_template.delete", description: "Delete console template config through a verified typed adapter.", method: "DELETE", path: "/api/flow_page_template/:id" },
7412
8905
  { name: "config.console_template.submit", description: "Submit console template edits through a verified typed adapter.", method: "PUT", path: "/api/flow_page_template/:id" },
7413
8906
  { name: "config.dataset.export", description: "Export dataset config through huanpingtong API-key proxy.", method: "GET/POST", path: "/api/data_set/:id + /api/data_set/list" },
8907
+ { name: "config.dataset.create", description: "Create dataset config through the huanpingtong API-key proxy.", method: "POST", path: "/api/data_set" },
8908
+ { name: "config.dataset.delete", description: "Delete dataset config through the huanpingtong API-key proxy.", method: "DELETE", path: "/api/data_set/:id" },
7414
8909
  { name: "config.dataset.submit", description: "Submit dataset edit payloads through the huanpingtong API-key proxy.", method: "POST", path: "/api/data_set/relationFields/:id" },
8910
+ { name: "config.dataset.publish", description: "Publish/start a dataset and trigger ES batch generation through the huanpingtong API-key proxy.", method: "POST", path: "/api/data_set/publish/:id" },
8911
+ { name: "config.dataset.pause", description: "Pause a published or pending dataset before a republish lifecycle.", method: "POST", path: "/api/data_set/pause/:id" },
8912
+ { name: "config.dataset.cancel_refresh", description: "Cancel a stuck dataset refresh without changing dataset publish status.", method: "POST", path: "/api/data_set/cancel-refresh/:id" },
8913
+ { name: "config.dataset.refresh", description: "Refresh/reindex a dataset by running the pause/publish lifecycle through the huanpingtong API-key proxy.", method: "POST", path: "/api/data_set/pause/:id + /api/data_set/publish/:id" },
7415
8914
  { name: "config.dataset_field.export", description: "Export dataset field config through huanpingtong API-key proxy.", method: "GET", path: "/api/data_set_field/:id + /api/data_set_field/getBatchByFlow" },
8915
+ { name: "config.dataset_field.create", description: "Create dataset field config through the huanpingtong API-key proxy.", method: "POST", path: "/api/data_set_field" },
8916
+ { name: "config.dataset_field.delete", description: "Delete dataset field config through the huanpingtong API-key proxy.", method: "DELETE", path: "/api/data_set_field/:id" },
7416
8917
  { name: "config.dataset_field.submit", description: "Submit dataset field edit payloads through the huanpingtong API-key proxy.", method: "PUT", path: "/api/data_set_field/:id" },
7417
8918
  { name: "config.api_platform.export", description: "Export API platform, instance, API proxy, and response binding config through a typed layered adapter.", method: "GET", path: "/api/api_platform/by_key/:key + /api/api_platform_instance/:id + /api/api_proxy/:id + /api/api_proxy_entity_binding" },
8919
+ { name: "config.api_platform.create", description: "Create API platform, instance, API proxy, or response binding through typed operation plans.", method: "POST", path: "/api/api_platform + /api/api_platform_instance + /api/api_proxy + /api/api_proxy_entity_binding" },
8920
+ { name: "config.api_platform.delete", description: "Delete API platform, instance, API proxy, or response binding through typed adapters.", method: "DELETE", path: "/api/api_platform/:id + /api/api_platform_instance/:id + /api/api_proxy/:id + /api/api_proxy_entity_binding/:id" },
7418
8921
  { name: "config.api_platform.submit", description: "Submit API platform layered operation plans through verified typed endpoints.", method: "POST/PUT", path: "/api/api_platform + /api/api_platform_instance + /api/api_proxy + /api/api_proxy_entity_binding" },
7419
8922
  { name: "config.role.export", description: "Export role, points, workspaces, flows, and members.", method: "GET", path: "/api/role + /api/point/point_list + /api/user_role + /api/workspace + /api/flow/list/lightweight" },
8923
+ { name: "config.role.create", description: "Create roles, custom points, and role members through typed operation plans.", method: "POST", path: "/api/role + /api/point + /api/user_role" },
8924
+ { name: "config.role.delete", description: "Delete roles, custom points, or role members through typed adapters.", method: "DELETE", path: "/api/role/:id + /api/point/:id + /api/user_role/:id" },
7420
8925
  { name: "config.role.submit", description: "Submit role operation plan through a verified typed adapter.", method: "POST/PUT/DELETE", path: "/api/role + /api/point + /api/user_role" },
7421
8926
  { name: "config.nav_config.export", description: "Export all workspace navigation config records.", method: "GET", path: "/api/configuration?q_type=:type&is_default_action=1" },
8927
+ { name: "config.nav_config.create", description: "Create workspace navigation config records through a typed operation plan.", method: "POST", path: "/api/configuration?is_default_action=1" },
8928
+ { name: "config.nav_config.delete", description: "Delete workspace navigation config records through a typed operation plan.", method: "DELETE", path: "/api/configuration/:id?is_default_action=1" },
7422
8929
  { name: "config.nav_config.submit", description: "Submit all workspace navigation config records through a typed operation plan.", method: "POST/PUT", path: "/api/configuration?is_default_action=1 + /api/configuration/:id?is_default_action=1" },
7423
8930
  { name: "config.repository.view", description: "View sysconfig repository environment details from BPMAX.", method: "GET", path: "/api/config_repository + /api/config_repository/:env" },
7424
8931
  { name: "config.repository.sync", description: "Run platform sysconfigdiff pullcommit/extract/pushcommit steps.", method: "POST", path: "/api/config_repository/:env?action=sync" },
7425
8932
  { name: "config.latest.pull", description: "Sync latest BPMAX sysconfig repositories for a configured environment.", method: "external", path: "external:sysconfigdiff + git" },
7426
8933
  { name: "config.e2e.run", description: "Run BPMAX config end-to-end validation orchestration.", method: "local+remote", path: "cli:e2e" },
8934
+ { name: "memory.status", description: "Check BPMAX memory backend status.", method: "GET", path: "/api/cli/memory/status" },
8935
+ { name: "memory.search", description: "Search BPMAX memory for the current API-key agent.", method: "POST", path: "/api/cli/memory/search" },
8936
+ { name: "memory.add", description: "Add BPMAX memory for the current API-key agent.", method: "POST", path: "/api/cli/memory" },
8937
+ { name: "memory.list", description: "List BPMAX memory when supported by the platform proxy.", method: "GET", path: "/api/cli/memory" },
8938
+ { name: "memory.get", description: "Get a BPMAX memory item when supported by the platform proxy.", method: "GET", path: "/api/cli/memory/:id" },
8939
+ { name: "memory.update", description: "Update a BPMAX memory item when supported by the platform proxy.", method: "PUT", path: "/api/cli/memory/:id" },
8940
+ { name: "memory.delete", description: "Delete a BPMAX memory item when supported by the platform proxy.", method: "DELETE", path: "/api/cli/memory/:id" },
7427
8941
  { name: "api.raw", description: "Call raw BPMAX API paths allowed by server capability whitelist.", method: "*", path: "/api/*" }
7428
8942
  ];
7429
8943
 
@@ -8633,6 +10147,7 @@ registerSchemaCommands(program);
8633
10147
  registerUserCommands(program);
8634
10148
  registerEsCommands(program);
8635
10149
  registerFlowCommands(program);
10150
+ registerMemoryCommands(program);
8636
10151
  registerProjectCommands(program);
8637
10152
  registerStepCommands(program);
8638
10153
  registerRecipeCommands(program);