bpmax-cli 0.1.44-beta.23 → 0.1.44-beta.24

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.1.44-beta.23",
472
+ version: "0.1.44-beta.24",
473
473
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
474
474
  type: "module",
475
475
  bin: {
@@ -5215,12 +5215,12 @@ function extractEmbeddedSubformOrder(template, field) {
5215
5215
  return flattenFieldOrder(rows);
5216
5216
  }
5217
5217
  function ordersMismatch(orders) {
5218
- const comparable = orders.filter((order) => order.length > 0);
5219
- if (comparable.length <= 1) {
5218
+ const comparable2 = orders.filter((order) => order.length > 0);
5219
+ if (comparable2.length <= 1) {
5220
5220
  return false;
5221
5221
  }
5222
- const first = JSON.stringify(comparable[0]);
5223
- return comparable.some((order) => JSON.stringify(order) !== first);
5222
+ const first = JSON.stringify(comparable2[0]);
5223
+ return comparable2.some((order) => JSON.stringify(order) !== first);
5224
5224
  }
5225
5225
  async function inspectFormTemplate(config, profile, id, options = {}) {
5226
5226
  const exported = await exportConfigDomain(
@@ -6806,8 +6806,8 @@ async function readBackConfigDomain(profile, domain, id, definition) {
6806
6806
  };
6807
6807
  }
6808
6808
  function comparableSubmitPayload(domain, value, options) {
6809
- const comparable = domain === "form-template" && options.ignoreServerFields ? stripServerFilledFields(value, FORM_TEMPLATE_SERVER_FIELD_KEYS) : value;
6810
- return buildDomainSubmitPayload(domain, comparable);
6809
+ const comparable2 = domain === "form-template" && options.ignoreServerFields ? stripServerFilledFields(value, FORM_TEMPLATE_SERVER_FIELD_KEYS) : value;
6810
+ return buildDomainSubmitPayload(domain, comparable2);
6811
6811
  }
6812
6812
  function diffMismatchCount(diff) {
6813
6813
  const counts = isRecord3(diff?.counts) ? diff.counts : {};
@@ -8477,7 +8477,7 @@ async function submitPluginConfigDomain(profile, domain, id, submitFile, confirm
8477
8477
  }
8478
8478
  const endpoint = mode === "create" ? resolved.adapter.endpoints?.create : resolved.adapter.endpoints?.update;
8479
8479
  const method = endpoint?.method || (mode === "create" ? "POST" : "PUT");
8480
- const pathValue = mode === "create" ? endpointPath(endpoint, void 0, resolved.adapter.plugin_key, "create") : endpointPath(endpoint, id, resolved.adapter.plugin_key, "update");
8480
+ const pathValue2 = mode === "create" ? endpointPath(endpoint, void 0, resolved.adapter.plugin_key, "create") : endpointPath(endpoint, id, resolved.adapter.plugin_key, "update");
8481
8481
  const expectedConfirm = `submit plugin ${domain} ${id}`;
8482
8482
  let currentHash = null;
8483
8483
  if (mode !== "create") {
@@ -8493,7 +8493,7 @@ async function submitPluginConfigDomain(profile, domain, id, submitFile, confirm
8493
8493
  domain,
8494
8494
  plugin: resolved.plugin,
8495
8495
  id,
8496
- endpoint: pathValue,
8496
+ endpoint: pathValue2,
8497
8497
  method,
8498
8498
  payload: submit.payload,
8499
8499
  current_hash: currentHash,
@@ -8503,7 +8503,7 @@ async function submitPluginConfigDomain(profile, domain, id, submitFile, confirm
8503
8503
  const response = await apiRequest(
8504
8504
  createApiClient(profile),
8505
8505
  method,
8506
- pathValue,
8506
+ pathValue2,
8507
8507
  { data: submit.payload, capability: capabilityFor(resolved.adapter, mode === "create" ? "create" : "update") }
8508
8508
  );
8509
8509
  const readbackId = mode === "create" ? String(responseId(response) ?? id) : id;
@@ -8514,7 +8514,7 @@ async function submitPluginConfigDomain(profile, domain, id, submitFile, confirm
8514
8514
  plugin: resolved.plugin,
8515
8515
  id,
8516
8516
  created_id: mode === "create" ? responseId(response) ?? null : null,
8517
- endpoint: pathValue,
8517
+ endpoint: pathValue2,
8518
8518
  method,
8519
8519
  response,
8520
8520
  readback_hash: readback ? hashJson(readback) : null
@@ -10587,6 +10587,9 @@ function numberValue(value, fallback) {
10587
10587
  const next = Number(value);
10588
10588
  return Number.isFinite(next) ? next : fallback;
10589
10589
  }
10590
+ function arrayValue2(value) {
10591
+ return Array.isArray(value) ? value : [];
10592
+ }
10590
10593
  function timestampSlug() {
10591
10594
  return (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
10592
10595
  }
@@ -10623,6 +10626,96 @@ function stepEvidenceFile(files, stepId, kind) {
10623
10626
  const pattern = new RegExp(`(?:^|-)step-${escapeRegExp2(stepId)}-${kind}\\.json$`);
10624
10627
  return files.find((file) => pattern.test(file));
10625
10628
  }
10629
+ function comparable(value) {
10630
+ return JSON.stringify(value);
10631
+ }
10632
+ function valuesEqual(left, right) {
10633
+ return comparable(left) === comparable(right);
10634
+ }
10635
+ function pathValue(source, dottedPath) {
10636
+ return dottedPath.split(".").reduce((current, segment) => {
10637
+ if (!isRecord8(current)) {
10638
+ return void 0;
10639
+ }
10640
+ return current[segment];
10641
+ }, source);
10642
+ }
10643
+ function normalizeExpectedChecks(value) {
10644
+ if (!Array.isArray(value)) {
10645
+ return [];
10646
+ }
10647
+ return value.filter(isRecord8).map((item) => ({
10648
+ ...stringValue3(item.name) ? { name: stringValue3(item.name) } : {},
10649
+ path: stringValue3(item.path) ?? "",
10650
+ op: stringValue3(item.op) ?? "equals",
10651
+ ...Object.prototype.hasOwnProperty.call(item, "value") ? { value: item.value } : {},
10652
+ ...Array.isArray(item.values) ? { values: item.values } : {}
10653
+ })).filter((item) => item.path);
10654
+ }
10655
+ function expectationTarget(context, requirements) {
10656
+ return {
10657
+ context: {
10658
+ current_user_can_process: context.current_user_can_process,
10659
+ identity_unverified: context.identity_unverified,
10660
+ step_finished: context.step_finished,
10661
+ current_user_reason: context.current_user_reason,
10662
+ actions: context.actions.map((action) => action.action),
10663
+ action_labels: context.actions.map((action) => action.label),
10664
+ owner_sources: context.owner_diagnostics.owner_sources
10665
+ },
10666
+ requirements: {
10667
+ can_submit: requirements.can_submit,
10668
+ required_fields: requirements.required_inputs.map((field) => field.key).filter(Boolean),
10669
+ optional_fields: requirements.optional_inputs.map((field) => field.key).filter(Boolean),
10670
+ missing_fields: requirements.missing_required_inputs.map((field) => field.key).filter(Boolean),
10671
+ blocking_reasons: requirements.blocking_reasons
10672
+ }
10673
+ };
10674
+ }
10675
+ function evaluateExpectedChecks(checks, target) {
10676
+ return checks.map((check) => {
10677
+ const actual = pathValue(target, check.path);
10678
+ const expected = Object.prototype.hasOwnProperty.call(check, "value") ? check.value : check.values;
10679
+ let ok = false;
10680
+ if (check.op === "equals") {
10681
+ ok = valuesEqual(actual, check.value);
10682
+ } else if (check.op === "not_equals") {
10683
+ ok = !valuesEqual(actual, check.value);
10684
+ } else if (check.op === "one_of") {
10685
+ ok = arrayValue2(check.values).some((value) => valuesEqual(actual, value));
10686
+ } else if (check.op === "includes") {
10687
+ ok = arrayValue2(actual).some((value) => valuesEqual(value, check.value));
10688
+ } else if (check.op === "includes_all") {
10689
+ ok = arrayValue2(check.value).every((expectedValue) => arrayValue2(actual).some((value) => valuesEqual(value, expectedValue)));
10690
+ } else if (check.op === "empty") {
10691
+ ok = Array.isArray(actual) ? actual.length === 0 : actual === void 0 || actual === null || actual === "";
10692
+ } else if (check.op === "not_empty") {
10693
+ ok = Array.isArray(actual) ? actual.length > 0 : actual !== void 0 && actual !== null && actual !== "";
10694
+ } else if (check.op === "matches") {
10695
+ ok = typeof actual === "string" && typeof check.value === "string" && new RegExp(check.value).test(actual);
10696
+ }
10697
+ return {
10698
+ ok,
10699
+ name: check.name ?? `${check.path} ${check.op}`,
10700
+ path: check.path,
10701
+ op: check.op,
10702
+ expected,
10703
+ actual
10704
+ };
10705
+ });
10706
+ }
10707
+ function buildExpectedChecks(options) {
10708
+ const requiredFields = options.requirements.required_inputs.map((field) => field.key).filter(Boolean);
10709
+ const missingFields = options.successfulSubmit ? [] : options.requirements.missing_required_inputs.map((field) => field.key).filter(Boolean);
10710
+ return [
10711
+ ...typeof options.context?.current_user_can_process === "boolean" ? [{ name: "current user can process step", path: "context.current_user_can_process", op: "equals", value: true }] : [],
10712
+ ...typeof options.context?.identity_unverified === "boolean" ? [{ name: "identity evidence remains available", path: "context.identity_unverified", op: "equals", value: false }] : [],
10713
+ ...typeof options.context?.step_finished === "boolean" ? [{ name: "step is still open", path: "context.step_finished", op: "equals", value: false }] : [],
10714
+ { name: "required field shape is compatible", path: "requirements.required_fields", op: "includes_all", value: requiredFields },
10715
+ { name: "missing fields are within recorded range", path: "requirements.missing_fields", op: "equals", value: missingFields },
10716
+ ...options.action ? [{ name: "cached action is still available", path: "context.actions", op: "includes", value: options.action }] : []
10717
+ ];
10718
+ }
10626
10719
  function flowCachePath(profileName, flowId) {
10627
10720
  return path9.join(cacheRoot(), "profiles", safeSegment(profileName), "flows", `${safeSegment(flowId)}.json`);
10628
10721
  }
@@ -10681,7 +10774,8 @@ function normalizeStepPlan(input, defaults) {
10681
10774
  ...stringValue3(input.target_step ?? input.targetStep) ? { target_step: stringValue3(input.target_step ?? input.targetStep) } : {},
10682
10775
  ...stringValue3(input.comments) ?? defaults.comments ? { comments: stringValue3(input.comments) ?? defaults.comments } : {},
10683
10776
  urgency: numberValue(input.urgency, defaults.urgency),
10684
- data
10777
+ data,
10778
+ expected_checks: normalizeExpectedChecks(input.expected_checks ?? input.expectedChecks)
10685
10779
  };
10686
10780
  }
10687
10781
  function buildStepRunPlans(options) {
@@ -10708,6 +10802,46 @@ function buildSubmitPayload(projectId, plan) {
10708
10802
  urgency: plan.urgency
10709
10803
  };
10710
10804
  }
10805
+ function dataProfilePath(input) {
10806
+ if (!input?.startsWith("@")) {
10807
+ return void 0;
10808
+ }
10809
+ return path9.resolve(input.slice(1));
10810
+ }
10811
+ function refreshedStepTemplate(options) {
10812
+ return {
10813
+ name: options.name ?? `step-${options.plan.step_id}`,
10814
+ project_id: options.projectId,
10815
+ step_id: options.plan.step_id,
10816
+ generated_at: (/* @__PURE__ */ new Date()).toISOString(),
10817
+ submit_mode: "cli_step_safe_chain",
10818
+ cache_policy: {
10819
+ validate_before_reuse: true,
10820
+ refresh_when_stale: true
10821
+ },
10822
+ expected_checks: buildExpectedChecks({
10823
+ context: options.context,
10824
+ requirements: options.requirements,
10825
+ action: options.plan.action,
10826
+ successfulSubmit: options.requirements.missing_required_inputs.length === 0
10827
+ }),
10828
+ required_fields: options.requirements.required_inputs.map((field) => field.key).filter(Boolean),
10829
+ missing_fields_at_record_time: options.requirements.missing_required_inputs.map((field) => field.key).filter(Boolean),
10830
+ variables: Object.keys(options.plan.data).filter((key) => !["project_id", "action", "urgency"].includes(key)),
10831
+ payload_template: options.plan.data,
10832
+ source_evidence: {
10833
+ evidence_dir: path9.resolve(options.evidenceDir),
10834
+ context: path9.basename(options.contextFile)
10835
+ }
10836
+ };
10837
+ }
10838
+ async function writeRefreshedCache(file, template) {
10839
+ const out = path9.resolve(file);
10840
+ await mkdir8(path9.dirname(out), { recursive: true });
10841
+ await writeFile8(out, `${JSON.stringify(redactAuditValue(template), null, 2)}
10842
+ `, "utf8");
10843
+ return out;
10844
+ }
10711
10845
  function blockedReason(context, canSubmit) {
10712
10846
  if (context.identity_unverified) {
10713
10847
  return "identity_unverified";
@@ -10803,11 +10937,12 @@ function recordKey(record, index) {
10803
10937
  }
10804
10938
  function registerE2eCommands(program2) {
10805
10939
  const e2e = program2.command("e2e").description("BPMAX E2E acceleration helpers with evidence-first safety gates");
10806
- e2e.command("step-run").description("Run one or more BPMAX step safe-chain submissions with evidence files").requiredOption("--project-id <projectId>", "Project id").option("--step-id <stepId>", "Step id for single-step mode").option("--action <action>", "Step action", "approve").option("--data <json>", "Single-step submit data JSON or @file").option("--data-profile <json>", "Reusable step profile JSON or @file; supports steps[] or steps object").option("--comments <comments>", "Step comments").option("--urgency <urgency>", "Urgency value", "1").option("--confirm <confirmation>", "Actually submit; otherwise dry-run only").option("--profile <profile>", "Profile name").option("--evidence-dir <dir>", "Evidence directory", `.codex/tmp/e2e/${timestampSlug()}`).option("--format <format>", "Output format", "json").action(async (options) => {
10940
+ e2e.command("step-run").description("Run one or more BPMAX step safe-chain submissions with evidence files").requiredOption("--project-id <projectId>", "Project id").option("--step-id <stepId>", "Step id for single-step mode").option("--action <action>", "Step action", "approve").option("--data <json>", "Single-step submit data JSON or @file").option("--data-profile <json>", "Reusable step profile JSON or @file; supports steps[] or steps object").option("--auto-refresh-cache", "Write a refreshed cache template when expected checks are missing or stale").option("--cache-out <file>", "Refreshed cache template output; defaults to --data-profile @file when possible").option("--comments <comments>", "Step comments").option("--urgency <urgency>", "Urgency value", "1").option("--confirm <confirmation>", "Actually submit; otherwise dry-run only").option("--profile <profile>", "Profile name").option("--evidence-dir <dir>", "Evidence directory", `.codex/tmp/e2e/${timestampSlug()}`).option("--format <format>", "Output format", "json").action(async (options) => {
10807
10941
  const config = await loadConfig();
10808
10942
  const profile = resolveProfile(config, options.profile);
10809
10943
  const client = createApiClient(profile);
10810
10944
  const data = options.data ? await parseJsonInput(options.data, "--data") : {};
10945
+ const profilePath = dataProfilePath(options.dataProfile);
10811
10946
  const dataProfile = options.dataProfile ? await parseJsonFileOrInput(options.dataProfile, "--data-profile") : null;
10812
10947
  const plans = buildStepRunPlans({
10813
10948
  stepId: options.stepId,
@@ -10836,6 +10971,46 @@ function registerE2eCommands(program2) {
10836
10971
  ...context,
10837
10972
  requirements
10838
10973
  });
10974
+ if (options.dataProfile) {
10975
+ const target = expectationTarget(context, requirements);
10976
+ const checkResults = evaluateExpectedChecks(plan.expected_checks, target);
10977
+ const failedChecks = checkResults.filter((check) => !check.ok);
10978
+ const missingChecks = plan.expected_checks.length === 0;
10979
+ if (missingChecks || failedChecks.length > 0) {
10980
+ stopped = true;
10981
+ const refreshOut = options.cacheOut ?? profilePath;
10982
+ let refreshedCacheFile;
10983
+ let refreshedTemplate;
10984
+ if (options.autoRefreshCache) {
10985
+ if (!refreshOut) {
10986
+ throw new Error("e2e step-run --auto-refresh-cache requires --cache-out when --data-profile is not an @file path.");
10987
+ }
10988
+ refreshedTemplate = refreshedStepTemplate({
10989
+ name: plan.label ?? `step-${plan.step_id}`,
10990
+ projectId: options.projectId,
10991
+ plan,
10992
+ context,
10993
+ requirements,
10994
+ evidenceDir,
10995
+ contextFile
10996
+ });
10997
+ refreshedCacheFile = await writeRefreshedCache(refreshOut, refreshedTemplate);
10998
+ }
10999
+ steps.push({
11000
+ step_id: plan.step_id,
11001
+ action: plan.action,
11002
+ status: "cache_stale",
11003
+ cache_status: missingChecks ? "missing_expected_checks" : "expected_checks_failed",
11004
+ expected_check_results: checkResults,
11005
+ failed_checks: failedChecks,
11006
+ evidence: { context: contextFile },
11007
+ ...refreshedCacheFile ? { refreshed_cache_file: refreshedCacheFile } : {},
11008
+ ...refreshedTemplate ? { refreshed_template: refreshedTemplate } : {},
11009
+ next_action: refreshedCacheFile ? "Review the refreshed cache template, fill any new missing required fields, then rerun e2e step-run." : "Rebuild this step cache with --auto-refresh-cache before continuing."
11010
+ });
11011
+ continue;
11012
+ }
11013
+ }
10839
11014
  const request = {
10840
11015
  method: "PUT",
10841
11016
  path: `/step/${plan.step_id}`,
@@ -10887,7 +11062,7 @@ function registerE2eCommands(program2) {
10887
11062
  });
10888
11063
  }
10889
11064
  printResult(options.format, {
10890
- ok: steps.every((step) => step.status !== "blocked"),
11065
+ ok: steps.every((step) => step.status !== "blocked" && step.status !== "cache_stale"),
10891
11066
  dry_run: !options.confirm,
10892
11067
  project_id: options.projectId,
10893
11068
  profile: profile.name,
@@ -11028,6 +11203,16 @@ function registerE2eCommands(program2) {
11028
11203
  const requiredInputs = Array.isArray(requirements.required_inputs) ? requirements.required_inputs.filter(isRecord8) : [];
11029
11204
  const missingInputs = Array.isArray(requirements.missing_required_inputs) ? requirements.missing_required_inputs.filter(isRecord8) : [];
11030
11205
  const requestData = isRecord8(submit?.request) && isRecord8(submit.request.data) ? submit.request.data : {};
11206
+ const recordedAction = stringValue3(requestData.action);
11207
+ const expectedChecks = buildExpectedChecks({
11208
+ context,
11209
+ requirements: {
11210
+ required_inputs: requiredInputs,
11211
+ missing_required_inputs: submitFile ? [] : missingInputs
11212
+ },
11213
+ action: recordedAction,
11214
+ successfulSubmit: Boolean(submitFile)
11215
+ });
11031
11216
  const hasStepEvidence = Boolean(inferredStepId || contextFile || submitFile);
11032
11217
  const evidenceFiles = files.filter((file) => /\.(json|txt|png|jpe?g|webp)$/i.test(file)).sort();
11033
11218
  if (!hasStepEvidence) {
@@ -11046,8 +11231,13 @@ function registerE2eCommands(program2) {
11046
11231
  ...inferredStepId ? { step_id: inferredStepId } : {},
11047
11232
  generated_at: (/* @__PURE__ */ new Date()).toISOString(),
11048
11233
  submit_mode: "cli_step_safe_chain",
11234
+ cache_policy: {
11235
+ validate_before_reuse: true,
11236
+ refresh_when_stale: true
11237
+ },
11238
+ expected_checks: expectedChecks,
11049
11239
  required_fields: requiredInputs.map((field) => field.key).filter(Boolean),
11050
- missing_fields_at_record_time: missingInputs.map((field) => field.key).filter(Boolean),
11240
+ missing_fields_at_record_time: (submitFile ? [] : missingInputs).map((field) => field.key).filter(Boolean),
11051
11241
  variables: Object.keys(requestData).filter((key) => !["project_id", "action", "urgency"].includes(key)),
11052
11242
  payload_template: requestData,
11053
11243
  source_evidence: {
@@ -13334,7 +13524,7 @@ var schemaEntries = [
13334
13524
  { name: "config.repository.sync", description: "Run platform sysconfigdiff pullcommit/extract/pushcommit steps.", method: "POST", path: "/api/config_repository/:env?action=sync" },
13335
13525
  { name: "config.latest.pull", description: "Sync latest BPMAX sysconfig repositories for a configured environment.", method: "external", path: "external:sysconfigdiff + git" },
13336
13526
  { name: "config.e2e.run", description: "Run BPMAX config end-to-end validation orchestration.", method: "local+remote", path: "cli:e2e" },
13337
- { name: "e2e.step_run", description: "Run BPMAX step safe-chain submissions with evidence files.", method: "GET/PUT", path: "/api/project/:id + /api/step/:id" },
13527
+ { name: "e2e.step_run", description: "Run BPMAX step safe-chain submissions with evidence files, expected-check validation, and stale-cache refresh.", method: "GET/PUT", path: "/api/project/:id + /api/step/:id" },
13338
13528
  { name: "e2e.create_page_submit", description: "Prepare real-browser BPMAX create-page submission scripts from handoff URLs.", method: "local+browser", path: "cli:e2e create-page-submit" },
13339
13529
  { name: "e2e.cache", description: "Inspect and refresh local BPMAX E2E runtime cache.", method: "GET/local", path: "/api/flow/:id + .codex/cache/bpmax-e2e" },
13340
13530
  { name: "e2e.browser_template", description: "Generate Playwright templates for real BPMAX browser evidence runs.", method: "local", path: ".codex/e2e-scripts" },