bpmax-cli 0.2.1-beta.6 → 0.2.1-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -469,7 +469,7 @@ function pluginAgentCapabilityForRequest(method, normalizedPath) {
469
469
  // package.json
470
470
  var package_default = {
471
471
  name: "bpmax-cli",
472
- version: "0.2.1-beta.6",
472
+ version: "0.2.1-beta.8",
473
473
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
474
474
  type: "module",
475
475
  bin: {
@@ -4339,6 +4339,125 @@ function validateFlowTemplateStandardPageCreateFormTemplate(value, errors) {
4339
4339
  }
4340
4340
  throw new Error(message);
4341
4341
  }
4342
+ function startConditionalJumpScriptLooksLikeIndexReturn(script) {
4343
+ const text5 = script.trim();
4344
+ if (!text5) {
4345
+ return false;
4346
+ }
4347
+ const directReturns = Array.from(text5.matchAll(/\breturn\s+([^;]+)\s*;?/g));
4348
+ if (!directReturns.length) {
4349
+ return false;
4350
+ }
4351
+ return directReturns.some((match) => {
4352
+ const expression = match[1].trim();
4353
+ if (/[=!<>]=?|&&|\|\||\?/.test(expression)) {
4354
+ return false;
4355
+ }
4356
+ return /^-?\d+$/.test(expression) || /^(routeIndex|resultIndex|targetIndex|index)\b/.test(expression) || /\b(result|options)\.indexOf\s*\(/.test(expression) || /^Number(?:\.parseInt)?\s*\(/.test(expression);
4357
+ });
4358
+ }
4359
+ function startConditionalJumpScriptIsCatchAll(script) {
4360
+ const text5 = script.trim();
4361
+ return /^return\s+true\s*;?\s*$/.test(text5) || /^return\s+Boolean\s*\(\s*true\s*\)\s*;?\s*$/.test(text5);
4362
+ }
4363
+ function validateFlowTemplateStartConditionalJump(value, errors) {
4364
+ const nextErrors = [];
4365
+ const data = isRecord3(value.data) ? value.data : {};
4366
+ const meta = isRecord3(data.meta) ? data.meta : {};
4367
+ const jumps = meta.condational_jump;
4368
+ if (jumps === void 0 || jumps === null || jumps === "") {
4369
+ return;
4370
+ }
4371
+ if (!Array.isArray(jumps)) {
4372
+ nextErrors.push("data.meta.condational_jump must be an array when start conditional routing is configured.");
4373
+ } else if (jumps.length === 0) {
4374
+ return;
4375
+ }
4376
+ const nodes = Array.isArray(data.nodes) ? data.nodes.filter(isRecord3) : [];
4377
+ const firstNodeId = nodes.length ? String(nodes[0].id ?? "").trim() : "";
4378
+ const nodeIds = new Set(nodes.map((node) => String(node.id ?? "").trim()).filter(Boolean));
4379
+ if (Array.isArray(jumps) && jumps.length && !nodes.length) {
4380
+ nextErrors.push("data.meta.condational_jump is configured but data.nodes is empty; start jump targets must point to real nodes or -1.");
4381
+ }
4382
+ if (Array.isArray(jumps) && jumps.length) {
4383
+ nodes.forEach((node, index) => {
4384
+ const id = String(node.id ?? "").trim();
4385
+ if (!id) {
4386
+ nextErrors.push(`data.nodes[${index}].id is required when data.meta.condational_jump is configured.`);
4387
+ }
4388
+ });
4389
+ }
4390
+ let lastJumpScript = "";
4391
+ let lastJumpResult = "";
4392
+ if (Array.isArray(jumps)) {
4393
+ jumps.forEach((jump, index) => {
4394
+ const pathName = `data.meta.condational_jump[${index}]`;
4395
+ if (!isRecord3(jump)) {
4396
+ nextErrors.push(`${pathName} must be an object with name, result, condition_mode, and a boolean condition script.`);
4397
+ return;
4398
+ }
4399
+ const name = typeof jump.name === "string" ? jump.name.trim() : "";
4400
+ if (!name) {
4401
+ nextErrors.push(`${pathName}.name is required so every explicit start route can be audited.`);
4402
+ }
4403
+ const rawResult = jump.result;
4404
+ if (Array.isArray(rawResult) || isRecord3(rawResult) || rawResult === void 0 || rawResult === null || String(rawResult).trim() === "") {
4405
+ nextErrors.push(`${pathName}.result must be a target node id or -1; it must not be empty, an array, an object, or a node name.`);
4406
+ } else {
4407
+ const result = String(rawResult).trim();
4408
+ if (result !== "-1" && !nodeIds.has(result)) {
4409
+ nextErrors.push(`${pathName}.result (${result}) must point to an existing data.nodes[].id or -1 for success end.`);
4410
+ }
4411
+ lastJumpResult = result;
4412
+ }
4413
+ const mode = typeof jump.condition_mode === "string" && jump.condition_mode.trim() ? jump.condition_mode.trim() : "code";
4414
+ let script = "";
4415
+ if (mode === "standard") {
4416
+ if (typeof jump.standard_condition === "string" && jump.standard_condition.trim()) {
4417
+ script = jump.standard_condition.trim();
4418
+ } else {
4419
+ nextErrors.push(`${pathName}.standard_condition is required when condition_mode is standard; condition is ignored by the backend in this mode.`);
4420
+ }
4421
+ } else if (mode === "code") {
4422
+ if (typeof jump.condition === "string" && jump.condition.trim()) {
4423
+ script = jump.condition.trim();
4424
+ } else {
4425
+ nextErrors.push(`${pathName}.condition is required when condition_mode is code or omitted; standard_condition is ignored by the backend in code mode.`);
4426
+ }
4427
+ } else {
4428
+ nextErrors.push(`${pathName}.condition_mode must be code or standard.`);
4429
+ }
4430
+ if (script) {
4431
+ lastJumpScript = script;
4432
+ if (index < jumps.length - 1 && startConditionalJumpScriptIsCatchAll(script)) {
4433
+ nextErrors.push(
4434
+ `${pathName} is a catch-all start route but is not the final item; return true must only appear on the last explicit fallback route.`
4435
+ );
4436
+ }
4437
+ if (startConditionalJumpScriptLooksLikeIndexReturn(script)) {
4438
+ nextErrors.push(
4439
+ `${pathName} must return boolean/truthy for this explicit start edge, not a node-level result index; do not copy node.condational_nodes scripts such as return 0/1/-1 into data.meta.condational_jump.`
4440
+ );
4441
+ }
4442
+ }
4443
+ });
4444
+ }
4445
+ if (Array.isArray(jumps) && jumps.length && nodes.length) {
4446
+ if (!lastJumpResult || !startConditionalJumpScriptIsCatchAll(lastJumpScript)) {
4447
+ nextErrors.push(
4448
+ "data.meta.condational_jump must end with an explicit catch-all route using condition script return true; this documents the default start path instead of relying on implicit fallback."
4449
+ );
4450
+ }
4451
+ }
4452
+ if (!nextErrors.length) {
4453
+ return;
4454
+ }
4455
+ if (errors) {
4456
+ errors.push(...nextErrors);
4457
+ return;
4458
+ }
4459
+ throw new Error(`flow-template start conditional jump gate failed: ${nextErrors.join("; ")}`);
4460
+ }
4342
4461
  function looksLikeParseEvalFunctionBody(script) {
4343
4462
  const text5 = script.trim();
4344
4463
  if (!text5) {
@@ -5013,6 +5132,7 @@ function normalizeFlowTemplatePayload(work) {
5013
5132
  validateFlowTemplateRemoteTemplateRefs({ ...work, data });
5014
5133
  validateFlowTemplateProjectAfterCreatePath({ ...work, data });
5015
5134
  validateFlowTemplateStandardPageCreateFormTemplate({ ...work, data });
5135
+ validateFlowTemplateStartConditionalJump({ ...work, data });
5016
5136
  validateFlowTemplateCodeModeMessages({ ...work, data });
5017
5137
  validateFlowTemplateRuntimeScripts({ ...work, data });
5018
5138
  validateFlowTemplateFeishuChatPlugin({ ...work, data });
@@ -5605,6 +5725,118 @@ function validateFormTemplateValueValidateMaps(payload, errors) {
5605
5725
  }
5606
5726
  }
5607
5727
  }
5728
+ var FORM_TEMPLATE_VISUAL_WIDE_TYPES = /* @__PURE__ */ new Set([
5729
+ "sub_form",
5730
+ "i_textarea",
5731
+ "textarea",
5732
+ "rich_text",
5733
+ "editor",
5734
+ "upload",
5735
+ "file",
5736
+ "image",
5737
+ "images",
5738
+ "raw"
5739
+ ]);
5740
+ function shouldRunFormTemplateVisualLint(payload) {
5741
+ const lintHints = isRecord3(payload.lintHints) ? payload.lintHints : {};
5742
+ const visualReview = isRecord3(lintHints.visualReview) ? lintHints.visualReview : {};
5743
+ return visualReview.enabled === true || visualReview.required === true || payload.mode === "visual_review";
5744
+ }
5745
+ function formTemplateVisualReviewHints(payload) {
5746
+ const lintHints = isRecord3(payload.lintHints) ? payload.lintHints : {};
5747
+ return isRecord3(lintHints.visualReview) ? lintHints.visualReview : {};
5748
+ }
5749
+ function numericHint(value, fallback) {
5750
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
5751
+ }
5752
+ function formTemplateRuleTitle(rule, value) {
5753
+ const title = rule.title ?? value?.title ?? rule.label ?? value?.label;
5754
+ return typeof title === "string" ? title.trim() : "";
5755
+ }
5756
+ function formTemplateRuleWidth(rule) {
5757
+ const props = isRecord3(rule.props) ? rule.props : {};
5758
+ const candidates = [
5759
+ rule.span,
5760
+ rule.colSpan,
5761
+ rule.width,
5762
+ props.span,
5763
+ props.colSpan,
5764
+ props.width
5765
+ ];
5766
+ for (const candidate of candidates) {
5767
+ if (typeof candidate === "number" && Number.isFinite(candidate) && candidate > 0) {
5768
+ return candidate;
5769
+ }
5770
+ if (typeof candidate === "string" && /^\d+$/.test(candidate.trim())) {
5771
+ return Number(candidate.trim());
5772
+ }
5773
+ }
5774
+ return void 0;
5775
+ }
5776
+ function validateStructuredFormTemplateVisualReview(payload, errors) {
5777
+ if (!shouldRunFormTemplateVisualLint(payload)) {
5778
+ return;
5779
+ }
5780
+ const hints = formTemplateVisualReviewHints(payload);
5781
+ if (hints.confirmedNonBehavioralProps !== true) {
5782
+ errors.push(
5783
+ "form-template visual lint requires lintHints.visualReview.confirmedNonBehavioralProps=true after confirming the diff only changes layout, label/control width, spacing, or other non-behavioral display props."
5784
+ );
5785
+ }
5786
+ if (!Array.isArray(payload.layout) || !isRecord3(payload.fields)) {
5787
+ errors.push("form-template visual lint requires structured work with layout and fields.");
5788
+ return;
5789
+ }
5790
+ const maxColumnsPerRow = Math.floor(numericHint(hints.maxColumnsPerRow, 2));
5791
+ const maxRowTitleChars = Math.floor(numericHint(hints.maxRowTitleChars, 24));
5792
+ const maxTitleCharsInMultiColumn = Math.floor(numericHint(hints.maxTitleCharsInMultiColumn, 12));
5793
+ for (const [rowIndex, row] of payload.layout.entries()) {
5794
+ if (!Array.isArray(row)) {
5795
+ errors.push(`form-template visual lint layout row ${rowIndex} must be an array.`);
5796
+ continue;
5797
+ }
5798
+ if (!row.length) {
5799
+ errors.push(`form-template visual lint layout row ${rowIndex} is empty; remove empty visual rows before submit.`);
5800
+ continue;
5801
+ }
5802
+ if (row.length > maxColumnsPerRow) {
5803
+ errors.push(`form-template visual lint layout row ${rowIndex} has ${row.length} fields; maxColumnsPerRow=${maxColumnsPerRow} for readable desktop data entry.`);
5804
+ }
5805
+ let rowTitleChars = 0;
5806
+ for (const ref of row) {
5807
+ if (typeof ref !== "string" || !ref) {
5808
+ continue;
5809
+ }
5810
+ const bundle = payload.fields[ref];
5811
+ if (!isRecord3(bundle) || !isRecord3(bundle.rule)) {
5812
+ continue;
5813
+ }
5814
+ const value = isRecord3(bundle.value) ? bundle.value : void 0;
5815
+ const rule = bundle.rule;
5816
+ const title = formTemplateRuleTitle(rule, value);
5817
+ rowTitleChars += title.length;
5818
+ const type = typeof rule.type === "string" ? rule.type : typeof value?.field_type === "string" ? value.field_type : "";
5819
+ if (row.length > 1 && FORM_TEMPLATE_VISUAL_WIDE_TYPES.has(type)) {
5820
+ errors.push(`form-template visual lint field ${ref} (${title || type}) type=${type} must be in a single-field row for readable editing.`);
5821
+ }
5822
+ if (row.length > 1 && title.length > maxTitleCharsInMultiColumn) {
5823
+ errors.push(`form-template visual lint field ${ref} title is too long for a multi-column row (${title.length} > ${maxTitleCharsInMultiColumn}); move it to a single row or shorten the visible label.`);
5824
+ }
5825
+ const width = formTemplateRuleWidth(rule);
5826
+ if (row.length > 1 && typeof width === "number" && width > 12) {
5827
+ errors.push(`form-template visual lint field ${ref} declares width/span=${width} inside a multi-column row; wide controls must be single-row or use <=12 grid width.`);
5828
+ }
5829
+ }
5830
+ if (row.length > 1 && rowTitleChars > maxRowTitleChars) {
5831
+ errors.push(`form-template visual lint layout row ${rowIndex} title length total is ${rowTitleChars}; maxRowTitleChars=${maxRowTitleChars}. Split the row for readability.`);
5832
+ }
5833
+ }
5834
+ }
5835
+ function validateFormTemplateWorkLint(payload, errors) {
5836
+ validateFormTemplateNameLength(payload, errors);
5837
+ validateFormTemplateValueValidateMaps(payload, errors);
5838
+ validateStructuredFormTemplateVisualReview(payload, errors);
5839
+ }
5608
5840
  function stripFormTemplateCreateIds(payload) {
5609
5841
  const next = { ...payload };
5610
5842
  if (Array.isArray(next.rule)) {
@@ -6776,6 +7008,7 @@ async function createFlowTemplateFromWork(config, profile, workFile, confirm3, o
6776
7008
  validateFlowTemplateRemoteTemplateRefs(work);
6777
7009
  validateFlowTemplateProjectAfterCreatePath(work);
6778
7010
  validateFlowTemplateStandardPageCreateFormTemplate(work);
7011
+ validateFlowTemplateStartConditionalJump(work);
6779
7012
  validateFlowTemplateCodeModeMessages(work);
6780
7013
  validateFlowTemplateRuntimeScripts(work);
6781
7014
  validateFlowTemplateFeishuChatPlugin(work);
@@ -7579,7 +7812,7 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
7579
7812
  }
7580
7813
  if (domain === "form-template" && isRecord3(work)) {
7581
7814
  const errors = [];
7582
- validateFormTemplateValueValidateMaps(work, errors);
7815
+ validateFormTemplateWorkLint(work, errors);
7583
7816
  if (errors.length) {
7584
7817
  throw new Error(`form-template lint failed: ${errors.join("; ")}`);
7585
7818
  }
@@ -7658,8 +7891,7 @@ async function lintConfigWorkFile(file, options = {}) {
7658
7891
  }
7659
7892
  const shouldLintFormTemplate = options.domain ? options.domain === "form-template" : looksLikeFormTemplateWork(value);
7660
7893
  if (shouldLintFormTemplate) {
7661
- validateFormTemplateNameLength(value, errors);
7662
- validateFormTemplateValueValidateMaps(value, errors);
7894
+ validateFormTemplateWorkLint(value, errors);
7663
7895
  }
7664
7896
  if ((Object.prototype.hasOwnProperty.call(value, "content") || isRecord3(value.basic)) && pageTemplateType(value) === 1) {
7665
7897
  validateListTemplateActionGate(value, errors);
@@ -7672,6 +7904,7 @@ async function lintConfigWorkFile(file, options = {}) {
7672
7904
  validateFlowTemplateRemoteTemplateRefs(flowWork, errors);
7673
7905
  validateFlowTemplateProjectAfterCreatePath(flowWork, errors);
7674
7906
  validateFlowTemplateStandardPageCreateFormTemplate(flowWork, errors);
7907
+ validateFlowTemplateStartConditionalJump(flowWork, errors);
7675
7908
  validateFlowTemplateCodeModeMessages(flowWork, errors);
7676
7909
  validateFlowTemplateRuntimeScripts(flowWork, errors);
7677
7910
  validateFlowTemplateFeishuChatPlugin(flowWork, errors);
@@ -8024,6 +8257,7 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
8024
8257
  validateFlowTemplateRemoteTemplateRefs(submit.payload);
8025
8258
  validateFlowTemplateProjectAfterCreatePath(submit.payload);
8026
8259
  validateFlowTemplateStandardPageCreateFormTemplate(submit.payload);
8260
+ validateFlowTemplateStartConditionalJump(submit.payload);
8027
8261
  validateFlowTemplateCodeModeMessages(submit.payload);
8028
8262
  validateFlowTemplateRuntimeScripts(submit.payload);
8029
8263
  validateFlowTemplateFeishuChatPlugin(submit.payload);