bpmax-cli 0.1.44-beta.19 → 0.1.44-beta.20

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
@@ -449,7 +449,7 @@ function normalizePath2(path11) {
449
449
  // package.json
450
450
  var package_default = {
451
451
  name: "bpmax-cli",
452
- version: "0.1.44-beta.19",
452
+ version: "0.1.44-beta.20",
453
453
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
454
454
  type: "module",
455
455
  bin: {
@@ -2639,7 +2639,7 @@ import { text as text2 } from "@clack/prompts";
2639
2639
 
2640
2640
  // src/core/config-workflow.ts
2641
2641
  import { createHash as createHash3 } from "crypto";
2642
- import { mkdir as mkdir3, readFile as readFile6, writeFile as writeFile3 } from "fs/promises";
2642
+ import { mkdir as mkdir3, readdir, readFile as readFile6, writeFile as writeFile3 } from "fs/promises";
2643
2643
  import path3 from "path";
2644
2644
  var NAV_CONFIG_TYPES = ["navmenu", "shortcut", "navmenu_mobile", "shortcut_mobile"];
2645
2645
  var NAV_CONTENT_KEY_BY_TYPE = {
@@ -2657,6 +2657,7 @@ var NAV_DEFAULT_NAME_BY_TYPE = {
2657
2657
  var MAX_FORM_TEMPLATE_NAME_LENGTH = 20;
2658
2658
  var FORM_TEMPLATE_ID_CONST_PATTERN = /\b(?:const|let|var)\s+[A-Za-z_$][\w$]*(?:FORM|Form|form)[A-Za-z0-9_$]*(?:TEMPLATE|Template|template)[A-Za-z0-9_$]*(?:ID|Id|id)\s*=\s*\d+\b/;
2659
2659
  var FORM_TEMPLATE_ID_PROP_PATTERN = /(?:\btemplate_id\b|['"]template_id['"])\s*:\s*\d+\b|\.template_id\s*=\s*\d+\b|\[['"]template_id['"]]\s*=\s*\d+\b/;
2660
+ var UUID_RE = /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/;
2660
2661
  var FEISHU_CHAT_UPDATE_REQUIRED_KEYS = [
2661
2662
  "name",
2662
2663
  "object_type",
@@ -2666,6 +2667,24 @@ var FEISHU_CHAT_UPDATE_REQUIRED_KEYS = [
2666
2667
  "params_script",
2667
2668
  "mapping_script"
2668
2669
  ];
2670
+ var LOCAL_UUID_DOMAIN_DIR = {
2671
+ "form-template": "think_form_template",
2672
+ "list-template": "think_flow_page_template",
2673
+ "filter-template": "think_flow_page_template",
2674
+ "project-detail-template": "think_flow_page_template",
2675
+ "console-template": "think_flow_page_template",
2676
+ dataset: "think_data_set",
2677
+ "dataset-field": "think_data_set_field",
2678
+ role: "think_role",
2679
+ workspace: "think_workspace"
2680
+ };
2681
+ var REMOTE_UUID_EXPORT_PATH = {
2682
+ "form-template": (uuid) => `/form_template/get_by_uuid?uuid=${encodeURIComponent(uuid)}`,
2683
+ "list-template": (uuid) => `/flow_page_template/get_by_uuid?uuid=${encodeURIComponent(uuid)}`,
2684
+ "filter-template": (uuid) => `/flow_page_template/get_by_uuid?uuid=${encodeURIComponent(uuid)}`,
2685
+ "project-detail-template": (uuid) => `/flow_page_template/get_by_uuid?uuid=${encodeURIComponent(uuid)}`,
2686
+ "console-template": (uuid) => `/flow_page_template/get_by_uuid?uuid=${encodeURIComponent(uuid)}`
2687
+ };
2669
2688
  var CONFIG_DOMAINS = {
2670
2689
  "form-template": {
2671
2690
  capability: "config.form_template",
@@ -5636,6 +5655,155 @@ async function readRemoteConfigDomain(profile, domain, id, definition) {
5636
5655
  { capability: `${definition.capability}.export` }
5637
5656
  );
5638
5657
  }
5658
+ function extractRecords(value) {
5659
+ if (Array.isArray(value)) return value.filter(isRecord3);
5660
+ if (!isRecord3(value)) return [];
5661
+ if (Array.isArray(value.data)) return value.data.filter(isRecord3);
5662
+ if (isRecord3(value.data) && Array.isArray(value.data.list)) return value.data.list.filter(isRecord3);
5663
+ if (Array.isArray(value.list)) return value.list.filter(isRecord3);
5664
+ if (Array.isArray(value.rows)) return value.rows.filter(isRecord3);
5665
+ return [];
5666
+ }
5667
+ function recordId(record) {
5668
+ const value = record.id ?? record.template_id ?? record.flow_page_template_id;
5669
+ return value === void 0 || value === null ? void 0 : String(value);
5670
+ }
5671
+ function numericIdString(value) {
5672
+ const text5 = value === void 0 || value === null ? "" : String(value);
5673
+ return /^\d+$/.test(text5) && text5 !== "0" ? text5 : void 0;
5674
+ }
5675
+ async function resolveDefaultProjectDetailTemplate(profile, options) {
5676
+ await ensureConfigCapability(profile, "config.project_detail_template.export");
5677
+ const params = new URLSearchParams({
5678
+ type: "2",
5679
+ flow_type: options.flowType,
5680
+ flow_key: options.flowKey ?? ""
5681
+ });
5682
+ const response = await apiRequest(
5683
+ createApiClient(profile),
5684
+ "GET",
5685
+ `/flow_page_template?${params.toString()}`,
5686
+ { capability: "config.project_detail_template.export" }
5687
+ );
5688
+ const candidates = extractRecords(response).filter((item) => Number(item.type) === 2 || item.type === void 0).filter((item) => String(item.flow_type ?? options.flowType) === options.flowType).filter((item) => String(item.flow_key ?? "") === (options.flowKey ?? "")).map((item) => ({
5689
+ id: recordId(item),
5690
+ name: item.name ?? item.title ?? null,
5691
+ status: item.status ?? null,
5692
+ flow_type: item.flow_type ?? options.flowType,
5693
+ flow_key: item.flow_key ?? ""
5694
+ })).filter((item) => item.id);
5695
+ const preferred = candidates.find((item) => item.status === 1 || item.status === "1" || item.status === "enabled") ?? candidates[0];
5696
+ return {
5697
+ domain: "project-detail-template",
5698
+ flow_type: options.flowType,
5699
+ flow_key: options.flowKey ?? "",
5700
+ resolved_id: preferred?.id ?? null,
5701
+ candidates,
5702
+ note: preferred ? "Use resolved_id with config project-detail-template export/submit. Runtime /project_detail/0/<project_id> resolves through the flow default template, not the global default template id 0." : "No flow-specific project detail template was returned. Do not assume --id 0 is the runtime flow default."
5703
+ };
5704
+ }
5705
+ async function resolveLocalUuidConfigId(options) {
5706
+ if (!UUID_RE.test(options.uuid)) {
5707
+ throw new Error(`resolve-id expects a UUID, got: ${options.uuid}`);
5708
+ }
5709
+ const tableDir = LOCAL_UUID_DOMAIN_DIR[options.domain];
5710
+ if (!tableDir) {
5711
+ throw new Error(`resolve-id does not support domain ${options.domain}.`);
5712
+ }
5713
+ const root = path3.resolve(options.repo, tableDir);
5714
+ async function walk(dir) {
5715
+ const entries = await readdir(dir, { withFileTypes: true });
5716
+ const result = [];
5717
+ for (const entry of entries) {
5718
+ const entryPath = path3.join(dir, entry.name);
5719
+ if (entry.isDirectory()) {
5720
+ result.push(...await walk(entryPath));
5721
+ } else if (entry.isFile()) {
5722
+ result.push(entryPath);
5723
+ }
5724
+ }
5725
+ return result;
5726
+ }
5727
+ const files = await walk(root);
5728
+ const matches = [];
5729
+ for (const filePath of files) {
5730
+ try {
5731
+ const record = JSON.parse(await readFile6(filePath, "utf8"));
5732
+ if (!isRecord3(record)) continue;
5733
+ if (String(record.uuid || "").toLowerCase() !== options.uuid.toLowerCase()) continue;
5734
+ const filenameId = numericIdString(path3.basename(filePath, path3.extname(filePath)));
5735
+ const id = numericIdString(record.id) ?? numericIdString(record.origin_template_id) ?? numericIdString(record.template_id) ?? filenameId ?? null;
5736
+ matches.push({
5737
+ domain: options.domain,
5738
+ uuid: options.uuid,
5739
+ id,
5740
+ path: filePath,
5741
+ name: record.name ?? record.title ?? null,
5742
+ type: record.type ?? null,
5743
+ flow_type: record.flow_type ?? null,
5744
+ flow_key: record.flow_key ?? null
5745
+ });
5746
+ } catch {
5747
+ }
5748
+ }
5749
+ return {
5750
+ domain: options.domain,
5751
+ uuid: options.uuid,
5752
+ repo: path3.resolve(options.repo),
5753
+ match_count: matches.length,
5754
+ matches,
5755
+ resolved_id: matches.length === 1 ? matches[0].id : null,
5756
+ note: matches.length === 1 && matches[0].id ? "Use resolved_id only when it is a platform numeric id. UUIDs are local mirror identifiers and must not be submitted as BPMAX config ids." : "Local sysconfig records commonly store UUID without platform numeric id. Pass --profile to also query the BPMAX get_by_uuid endpoint when supported, or resolve through flow/default/template export before submitting."
5757
+ };
5758
+ }
5759
+ async function resolveConfigUuidId(options) {
5760
+ const local = options.repo ? await resolveLocalUuidConfigId({
5761
+ repo: options.repo,
5762
+ domain: options.domain,
5763
+ uuid: options.uuid
5764
+ }) : null;
5765
+ const remotePath = REMOTE_UUID_EXPORT_PATH[options.domain];
5766
+ if (!options.profile || !remotePath) {
5767
+ return {
5768
+ domain: options.domain,
5769
+ uuid: options.uuid,
5770
+ local,
5771
+ remote: null,
5772
+ resolved_id: local?.resolved_id ?? null,
5773
+ note: remotePath ? "Pass --profile to query the BPMAX get_by_uuid endpoint for a numeric id." : "This domain has no known get_by_uuid endpoint; use local result only if it contains a numeric resolved_id."
5774
+ };
5775
+ }
5776
+ const definition = CONFIG_DOMAINS[options.domain];
5777
+ await ensureConfigCapability(options.profile, `${definition.capability}.export`);
5778
+ const response = await apiRequest(
5779
+ createApiClient(options.profile),
5780
+ "GET",
5781
+ remotePath(options.uuid),
5782
+ { capability: `${definition.capability}.export` }
5783
+ );
5784
+ const remoteRecord = isRecord3(response) && isRecord3(response.data) ? response.data : response;
5785
+ const remote = isRecord3(remoteRecord) ? {
5786
+ id: numericIdString(remoteRecord.id),
5787
+ origin_template_id: numericIdString(remoteRecord.origin_template_id),
5788
+ name: remoteRecord.name ?? remoteRecord.title ?? null,
5789
+ type: remoteRecord.type ?? null,
5790
+ flow_type: remoteRecord.flow_type ?? null,
5791
+ flow_key: remoteRecord.flow_key ?? null,
5792
+ raw_uuid: remoteRecord.uuid ?? null
5793
+ } : null;
5794
+ const expectedType = CONFIG_DOMAINS[options.domain].expectedType;
5795
+ const typeMismatch = remote && expectedType !== void 0 && Number(remote.type) !== expectedType;
5796
+ const remoteResolvedId = options.domain === "form-template" ? remote?.origin_template_id ?? remote?.id ?? null : typeMismatch ? null : remote?.id ?? null;
5797
+ return {
5798
+ domain: options.domain,
5799
+ uuid: options.uuid,
5800
+ local,
5801
+ remote,
5802
+ type_mismatch: typeMismatch ? { expected: expectedType, actual: remote?.type ?? null } : null,
5803
+ resolved_id: typeMismatch ? null : remoteResolvedId ?? local?.resolved_id ?? null,
5804
+ note: remoteResolvedId ? options.domain === "form-template" ? "For form-template, resolved_id prefers origin_template_id because typed submit must use the editable draft id." : "Resolved id came from the BPMAX get_by_uuid endpoint." : typeMismatch ? "Remote UUID exists but belongs to a different flow_page_template type. Do not use it for this domain." : "No platform numeric id could be resolved. Do not submit the UUID; resolve through the owning flow/template export first."
5805
+ };
5806
+ }
5639
5807
  async function ensureConfigCapability(profile, capability) {
5640
5808
  if (capabilityEnabled(profile.config.capabilities_cache, capability)) {
5641
5809
  return;
@@ -5725,9 +5893,20 @@ async function exportConfigDomain(config, profile, domain, id, outDir, options =
5725
5893
  base_hash: baseHash,
5726
5894
  raw_file: rawFile,
5727
5895
  work_file: workFile,
5728
- work_format: domain === "form-template" ? options.workFormat || "raw" : void 0
5896
+ work_format: domain === "form-template" ? options.workFormat || "raw" : void 0,
5897
+ resolution_note: domain === "project-detail-template" && id === "0" ? "id=0 is the global default project-detail-template export. Runtime /project_detail/0/<project_id> resolves to the flow default template; use config project-detail-template resolve-default --flow-type <flow> before editing." : void 0
5729
5898
  });
5730
- return { domain, id, raw_file: rawFile, work_file: workFile, meta_file: metaFile, base_hash: baseHash };
5899
+ return {
5900
+ domain,
5901
+ id,
5902
+ raw_file: rawFile,
5903
+ work_file: workFile,
5904
+ meta_file: metaFile,
5905
+ base_hash: baseHash,
5906
+ ...domain === "project-detail-template" && id === "0" ? {
5907
+ default_resolution_warning: "id=0 is the global default template, not necessarily the runtime flow default for /project_detail/0/<project_id>. Use resolve-default with flow_type/flow_key."
5908
+ } : {}
5909
+ };
5731
5910
  }
5732
5911
  async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, options = {}) {
5733
5912
  const definition = CONFIG_DOMAINS[domain];
@@ -7411,6 +7590,22 @@ function registerConfigCommands(program2) {
7411
7590
  });
7412
7591
  printResult(options.format, result);
7413
7592
  });
7593
+ config.command("resolve-id").description("Resolve a local sysconfig UUID to a platform numeric config id").requiredOption("--domain <domain>", "Config domain, e.g. form-template or project-detail-template").requiredOption("--uuid <uuid>", "Local sysconfig UUID").option("--repo <path>", "Local sysconfig repository path").option("--profile <profile>", "Profile name; when present, also query supported BPMAX get_by_uuid endpoints").option("--format <format>", "Output format", "json").action(async (options) => {
7594
+ if (!Object.prototype.hasOwnProperty.call(CONFIG_DOMAINS, options.domain)) {
7595
+ throw new Error(`Unknown config domain: ${options.domain}`);
7596
+ }
7597
+ if (!options.repo && !options.profile) {
7598
+ throw new Error("resolve-id requires --repo, --profile, or both.");
7599
+ }
7600
+ const configData = options.profile ? await loadConfig() : void 0;
7601
+ const resolved = configData ? resolveProfile(configData, options.profile) : void 0;
7602
+ printResult(options.format, await resolveConfigUuidId({
7603
+ domain: options.domain,
7604
+ uuid: options.uuid,
7605
+ repo: options.repo,
7606
+ profile: resolved
7607
+ }));
7608
+ });
7414
7609
  Object.keys(CONFIG_DOMAINS).forEach((domain) => {
7415
7610
  const domainCommand = domain === "workspace" ? workspace.description("Initialize local sysconfig workspaces and manage BPMAX workspace configuration") : config.command(domain).description(`Manage BPMAX ${domain} configuration`);
7416
7611
  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");
@@ -7440,6 +7635,16 @@ function registerConfigCommands(program2) {
7440
7635
  await saveConfig(configData);
7441
7636
  printResult(options.format, result);
7442
7637
  });
7638
+ if (domain === "project-detail-template") {
7639
+ domainCommand.command("resolve-default").description("Resolve the flow-specific default project detail template used by /project_detail/0/<project_id>").requiredOption("--flow-type <flowType>", "Flow type, e.g. flow48198545").option("--flow-key <flowKey>", "Flow key for subflow defaults", "").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
7640
+ const configData = await loadConfig();
7641
+ const resolved = resolveProfile(configData, options.profile);
7642
+ printResult(options.format, await resolveDefaultProjectDetailTemplate(resolved, {
7643
+ flowType: options.flowType,
7644
+ flowKey: options.flowKey
7645
+ }));
7646
+ });
7647
+ }
7443
7648
  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("--summary", "For flow-template, include a compact configuration summary in command output").option("--inline", "For flow-template, include the exported work JSON inline in command output").option("--format <format>", "Output format", "pretty").action(async (options) => {
7444
7649
  const configData = await loadConfig();
7445
7650
  const resolved = resolveProfile(configData, options.profile);
@@ -9565,7 +9770,7 @@ import { spawn as spawn2 } from "child_process";
9565
9770
  import { fileURLToPath as fileURLToPath2 } from "url";
9566
9771
 
9567
9772
  // src/core/recipes.ts
9568
- import { access, mkdir as mkdir7, readdir, readFile as readFile10, writeFile as writeFile7 } from "fs/promises";
9773
+ import { access, mkdir as mkdir7, readdir as readdir2, readFile as readFile10, writeFile as writeFile7 } from "fs/promises";
9569
9774
  import path7 from "path";
9570
9775
  var RECIPE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
9571
9776
  var TEMPLATE_PATTERN = /{{\s*([a-zA-Z0-9_.-]+)\s*}}/g;
@@ -9653,7 +9858,7 @@ async function loadRecipe(recipeDir) {
9653
9858
  async function listRecipes(recipesDir) {
9654
9859
  let entries;
9655
9860
  try {
9656
- entries = await readdir(recipesDir);
9861
+ entries = await readdir2(recipesDir);
9657
9862
  } catch (error) {
9658
9863
  if (error.code === "ENOENT") {
9659
9864
  return [];
@@ -11185,7 +11390,7 @@ import {
11185
11390
  copyFile,
11186
11391
  cp as cp2,
11187
11392
  mkdir as mkdir9,
11188
- readdir as readdir2,
11393
+ readdir as readdir3,
11189
11394
  readFile as readFile12,
11190
11395
  rm as rm3,
11191
11396
  stat as stat4,
@@ -11225,6 +11430,7 @@ var REVIEW_REQUIRED_PERSPECTIVES = /* @__PURE__ */ new Set([
11225
11430
  "execution_operability",
11226
11431
  "config_consistency"
11227
11432
  ]);
11433
+ var REVIEW_REQUIRED_PERSPECTIVE_LIST = [...REVIEW_REQUIRED_PERSPECTIVES];
11228
11434
  var CONFIG_CONSISTENCY_STATUSES = /* @__PURE__ */ new Set(["correct", "needs_update", "deprecated", "split_or_add", "blocked"]);
11229
11435
  var CONFIG_BASIS_ALLOWED_PREFIXES = [
11230
11436
  "think_flow/",
@@ -11255,7 +11461,7 @@ var REPORT_REQUIRED_HEADINGS = [
11255
11461
  var DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
11256
11462
  var RUN_RE = /^\d{8}-(\d{3})$/;
11257
11463
  var SCENARIO_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
11258
- var UUID_RE = /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/;
11464
+ var UUID_RE2 = /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/;
11259
11465
  var ID_AS_ENTRY_RE = /(发起表单|处理表单|表单模板|数据集|列表模板|详情模板)\s*(UUID|uuid|ID|id|:|:)/;
11260
11466
  var URL_RE = /https?:\/\/|\/w:[^\s,,;;]+|\/project\?|\/project_detail\/|\/projectContinue\?/;
11261
11467
  var SHA_RE = /^[0-9a-f]{40}$/;
@@ -11287,6 +11493,63 @@ async function readText(filePath) {
11287
11493
  function fail(message) {
11288
11494
  throw new TestSuiteError(message);
11289
11495
  }
11496
+ function reviewSchemaExample(scenarioId = "example-scenario", latestProof = null) {
11497
+ return {
11498
+ scenario_id: scenarioId,
11499
+ reviewed_at: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
11500
+ status: "fixed",
11501
+ latest_proof: latestProof ?? {
11502
+ method: "latest-example",
11503
+ allow_dirty: true,
11504
+ before: "0000000000000000000000000000000000000000",
11505
+ after: "0000000000000000000000000000000000000000",
11506
+ head: "0000000000000000000000000000000000000000",
11507
+ status_short: "example status summary"
11508
+ },
11509
+ perspectives: [
11510
+ { name: "structure_lint", reviewer: "subagent-structure", status: "fixed", summary: "README/cases.csv structure passed." },
11511
+ { name: "business_coverage", reviewer: "subagent-business", status: "fixed", summary: "P0/P1 customer business paths are covered." },
11512
+ { name: "execution_operability", reviewer: "subagent-execution", status: "fixed", summary: "Cases can be executed through browser/runtime evidence." },
11513
+ {
11514
+ name: "config_consistency",
11515
+ reviewer: "subagent-config",
11516
+ status: "fixed",
11517
+ summary: "Each case config_basis was checked against current sysconfig.",
11518
+ case_judgments: [
11519
+ {
11520
+ case_id: "C001",
11521
+ status: "correct",
11522
+ config_basis_checked: ["skills/bpmax-e2e-flow-test-operator/SKILL.md"],
11523
+ evidence: "Checked the referenced config basis and found it aligned with the case."
11524
+ }
11525
+ ],
11526
+ missing_case_review: { needed: false, summary: "No missing P0/P1 cases." }
11527
+ }
11528
+ ],
11529
+ unresolved: { P0: 0, P1: 0, P2: 0 },
11530
+ fixes: ["No unresolved P0/P1 findings remain."]
11531
+ };
11532
+ }
11533
+ function reviewSchemaExplanation() {
11534
+ return {
11535
+ required_top_level_fields: ["scenario_id", "reviewed_at", "status", "latest_proof", "perspectives", "unresolved", "fixes"],
11536
+ status_values: [...REVIEW_STATUSES].sort(),
11537
+ required_perspectives: REVIEW_REQUIRED_PERSPECTIVE_LIST,
11538
+ config_consistency_required_fields: ["case_judgments", "missing_case_review"],
11539
+ config_consistency_judgment_status_values: [...CONFIG_CONSISTENCY_STATUSES].sort(),
11540
+ promote_gate: "unresolved.P0 and unresolved.P1 must both be 0 before promote.",
11541
+ minimal_example: reviewSchemaExample()
11542
+ };
11543
+ }
11544
+ function reviewFail(reviewPath, message) {
11545
+ const scenarioId = path9.basename(path9.dirname(reviewPath));
11546
+ fail([
11547
+ message,
11548
+ `Run \`bpmax-cli test-suite review explain --format json\` for the full schema.`,
11549
+ `Run \`bpmax-cli test-suite review repair --scenario ${scenarioId} --draft-root ${path9.dirname(path9.dirname(reviewPath))} --latest-proof <proof.json> --format json\` to fill missing fields.`,
11550
+ `Minimal review.json example: ${JSON.stringify(reviewSchemaExample(scenarioId))}`
11551
+ ].join("\n"));
11552
+ }
11290
11553
  function splitCsvLine(line) {
11291
11554
  const values = [];
11292
11555
  let current = "";
@@ -11375,7 +11638,7 @@ async function validateReadme(scenarioDir) {
11375
11638
  if (metadata.scenario_id !== path9.basename(scenarioDir)) fail(`${scenarioDir}: scenario_id must match directory name`);
11376
11639
  if (!["true", "false"].includes(metadata.core.toLowerCase())) fail(`${scenarioDir}: core must be true or false`);
11377
11640
  if (!STATUSES.has(metadata.status)) fail(`${scenarioDir}: status must be one of ${JSON.stringify([...STATUSES].sort())}`);
11378
- if (UUID_RE.test(text5) || ID_AS_ENTRY_RE.test(text5)) {
11641
+ if (UUID_RE2.test(text5) || ID_AS_ENTRY_RE.test(text5)) {
11379
11642
  fail(`${scenarioDir}: README must use browser URLs as execution entrypoints, not UUID/ID identifiers`);
11380
11643
  }
11381
11644
  return metadata;
@@ -11413,6 +11676,23 @@ function parseStructuredTokens(value, tokenPattern) {
11413
11676
  });
11414
11677
  return tokens;
11415
11678
  }
11679
+ function keywordCandidates(value) {
11680
+ return [...new Set(value.split(/[、,,;;\s>,。::/]+/).map((word) => word.trim()).filter((word) => word.length >= 2).flatMap((word) => word.length >= 4 ? [word, word.slice(0, 4)] : [word]))].slice(0, 12);
11681
+ }
11682
+ function businessScenarioAlignmentMessage(filePath, caseId, row, scenarioValue) {
11683
+ const context = [row.title, row.preconditions, row.prep_data, row.steps, row.expected_result].join(" ");
11684
+ const contextKeywords = keywordCandidates(context);
11685
+ const scenarioKeywords = keywordCandidates(scenarioValue);
11686
+ const unmatched = scenarioKeywords.filter((word) => !context.includes(word));
11687
+ const suggestion = `\u4E1A\u52A1\u573A\u666F=${row.title || "<\u5BA2\u6237\u4E1A\u52A1\u52A8\u4F5C>"};\u4E1A\u52A1\u903B\u8F91=<\u8BF4\u660E\u8BE5\u573A\u666F\u9A8C\u8BC1\u7684\u6D41\u7A0B/\u6570\u636E/\u5BA1\u6279\u89C4\u5219>;\u6837\u672C\u6570\u636E=<\u8BF4\u660E\u771F\u5B9E\u4E1A\u52A1\u6837\u672C\u5C5E\u6027>;\u5408\u7406\u6027=<\u8BF4\u660E\u6837\u672C\u7B26\u5408\u5BA2\u6237\u4E1A\u52A1\u89C4\u5219>`;
11688
+ return [
11689
+ `${filePath}:${caseId}: \`test_data\` token \`\u4E1A\u52A1\u573A\u666F=\` must align with the case title, preconditions, steps, or expected result.`,
11690
+ `Extracted case keywords: ${contextKeywords.join(", ") || "<none>"}.`,
11691
+ `Extracted \u4E1A\u52A1\u573A\u666F keywords: ${scenarioKeywords.join(", ") || "<none>"}.`,
11692
+ `\u4E1A\u52A1\u573A\u666F keywords not found in case context: ${unmatched.join(", ") || "<none>"}.`,
11693
+ `Recommended rewrite: ${suggestion}`
11694
+ ].join("\n");
11695
+ }
11416
11696
  function validateBusinessTestData(filePath, caseId, row) {
11417
11697
  const testData = row.test_data.trim();
11418
11698
  if (!testData) fail(`${filePath}:${caseId}: \`test_data\` is required`);
@@ -11443,7 +11723,7 @@ function validateBusinessTestData(filePath, caseId, row) {
11443
11723
  return [trimmed];
11444
11724
  });
11445
11725
  if (!businessScenarioTerms.some((word) => word.length >= 2 && businessContext.includes(word))) {
11446
- fail(`${filePath}:${caseId}: \`test_data\` token \`\u4E1A\u52A1\u573A\u666F=\` must align with the case title, preconditions, steps, or expected result`);
11726
+ fail(businessScenarioAlignmentMessage(filePath, caseId, row, tokens["\u4E1A\u52A1\u573A\u666F"]));
11447
11727
  }
11448
11728
  }
11449
11729
  async function validateCase(filePath, row, seen) {
@@ -11491,14 +11771,14 @@ async function validateCase(filePath, row, seen) {
11491
11771
  if (["screenshot", "project_detail", "list"].some((word) => evidence.includes(word)) && !URL_RE.test(browserText)) {
11492
11772
  fail(`${filePath}:${caseId}: browser-executed cases must include a concrete browser URL or route in preconditions/steps/expected_result`);
11493
11773
  }
11494
- if (UUID_RE.test(browserText)) fail(`${filePath}:${caseId}: browser-executed cases must not use UUID as the execution entrypoint`);
11774
+ if (UUID_RE2.test(browserText)) fail(`${filePath}:${caseId}: browser-executed cases must not use UUID as the execution entrypoint`);
11495
11775
  if (YBS_NONZERO_DETAIL_RE.test(browserText)) fail(`${filePath}:${caseId}: YBS detail URLs must use /w:ybs/project_detail/0/<project_id> unless verified otherwise`);
11496
11776
  if (YBS_PC_CREATE_WRONG_RE.test(browserText)) fail(`${filePath}:${caseId}: YBS PC create URLs must use /w:ybs/project/create?flow_type=<flow_type>`);
11497
11777
  validateBusinessTestData(filePath, caseId, row);
11498
11778
  }
11499
11779
  async function scenarioDirs(root) {
11500
11780
  if (!await exists2(root)) return [];
11501
- const items = await readdir2(root, { withFileTypes: true });
11781
+ const items = await readdir3(root, { withFileTypes: true });
11502
11782
  return items.filter((item) => item.isDirectory()).map((item) => path9.join(root, item.name)).sort();
11503
11783
  }
11504
11784
  async function validateScenario(scenarioDir) {
@@ -11536,11 +11816,27 @@ async function lintSuite(root = DEFAULT_SUITE_ROOT) {
11536
11816
  for (const dir of dirs) results.push(await validateScenario(dir));
11537
11817
  return results;
11538
11818
  }
11819
+ async function lintSuiteDetailed(root = DEFAULT_SUITE_ROOT, options = {}) {
11820
+ const scenarios = await lintSuite(root);
11821
+ return {
11822
+ ok: true,
11823
+ scenario_count: scenarios.length,
11824
+ ...options.explain ? {
11825
+ review_schema: reviewSchemaExplanation(),
11826
+ case_fields: CASE_FIELDS,
11827
+ test_data_required_tokens: ["\u4E1A\u52A1\u573A\u666F", "\u4E1A\u52A1\u903B\u8F91", "\u6837\u672C\u6570\u636E", "\u5408\u7406\u6027"].map((token) => `${token}=`),
11828
+ test_data_alignment_rule: "`\u4E1A\u52A1\u573A\u666F=` must share at least one meaningful keyword with title/preconditions/prep_data/steps/expected_result."
11829
+ } : {}
11830
+ };
11831
+ }
11539
11832
  async function indexSuite(root = DEFAULT_SUITE_ROOT, includeInactive = false) {
11540
11833
  const items = await lintSuite(root);
11541
11834
  return includeInactive ? items : items.filter((item) => item.status === "active");
11542
11835
  }
11543
11836
  async function requireLatestProof(proofPath) {
11837
+ await readLatestProof(proofPath);
11838
+ }
11839
+ async function readLatestProof(proofPath) {
11544
11840
  if (!proofPath) fail("--latest-proof is required");
11545
11841
  if (!await exists2(proofPath)) fail(`latest proof is required before this command: ${proofPath}`);
11546
11842
  let proof;
@@ -11550,6 +11846,7 @@ async function requireLatestProof(proofPath) {
11550
11846
  fail(`${proofPath}: invalid latest proof JSON: ${error instanceof Error ? error.message : String(error)}`);
11551
11847
  }
11552
11848
  validateLatestProofObject(proofPath, proof);
11849
+ return proof;
11553
11850
  }
11554
11851
  function validateLatestProofObject(proofPath, proof) {
11555
11852
  if (!String(proof.method || "").startsWith("latest-")) fail(`${proofPath}: method must start with latest-`);
@@ -11571,7 +11868,7 @@ function scenarioPath(root, scenario) {
11571
11868
  async function fileMap(root) {
11572
11869
  const result = /* @__PURE__ */ new Map();
11573
11870
  async function walk(dir) {
11574
- for (const item of await readdir2(dir, { withFileTypes: true })) {
11871
+ for (const item of await readdir3(dir, { withFileTypes: true })) {
11575
11872
  const itemPath = path9.join(dir, item.name);
11576
11873
  const rel = path9.relative(root, itemPath);
11577
11874
  if (rel.split(path9.sep)[0] === COPY_DIFF_DIR) continue;
@@ -11594,6 +11891,14 @@ async function readForDiff(filePath) {
11594
11891
  `];
11595
11892
  return buffer.toString("utf8").split(/(?<=\n)/);
11596
11893
  }
11894
+ function caseIdsFromCsvLines(lines) {
11895
+ const ids = /* @__PURE__ */ new Set();
11896
+ lines.slice(1).forEach((line) => {
11897
+ const id = splitCsvLine(line.replace(/\n$/, ""))[0]?.trim();
11898
+ if (id) ids.add(id);
11899
+ });
11900
+ return ids;
11901
+ }
11597
11902
  function unifiedDiff(oldLines, newLines, oldName, newName) {
11598
11903
  if (oldLines.join("") === newLines.join("")) return "";
11599
11904
  return [`--- ${oldName}
@@ -11605,6 +11910,7 @@ async function buildCopyDiff(src, dst, operation) {
11605
11910
  const dstFiles = await fileMap(dst);
11606
11911
  const rels = [.../* @__PURE__ */ new Set([...srcFiles.keys(), ...dstFiles.keys()])].sort();
11607
11912
  const summary = { added: 0, modified: 0, removed: 0, unchanged: 0 };
11913
+ const caseSummary = { added: [], removed: [], changed: [] };
11608
11914
  const files = [];
11609
11915
  let diff = "";
11610
11916
  for (const rel of rels) {
@@ -11620,9 +11926,18 @@ async function buildCopyDiff(src, dst, operation) {
11620
11926
  summary[status] += 1;
11621
11927
  files.push({ path: rel, status, source_sha256, destination_sha256 });
11622
11928
  if (status !== "unchanged") {
11929
+ const oldLines = dstPath ? await readForDiff(dstPath) : [];
11930
+ const newLines = srcPath ? await readForDiff(srcPath) : [];
11931
+ if (rel === "cases.csv") {
11932
+ const oldIds = caseIdsFromCsvLines(oldLines);
11933
+ const newIds = caseIdsFromCsvLines(newLines);
11934
+ caseSummary.added.push(...[...newIds].filter((id) => !oldIds.has(id)));
11935
+ caseSummary.removed.push(...[...oldIds].filter((id) => !newIds.has(id)));
11936
+ caseSummary.changed.push(...[...newIds].filter((id) => oldIds.has(id)));
11937
+ }
11623
11938
  diff += unifiedDiff(
11624
- dstPath ? await readForDiff(dstPath) : [],
11625
- srcPath ? await readForDiff(srcPath) : [],
11939
+ oldLines,
11940
+ newLines,
11626
11941
  `destination/${rel}`,
11627
11942
  `source/${rel}`
11628
11943
  );
@@ -11636,6 +11951,7 @@ async function buildCopyDiff(src, dst, operation) {
11636
11951
  destination: dst,
11637
11952
  generated_at: (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "+00:00"),
11638
11953
  summary,
11954
+ case_summary: caseSummary,
11639
11955
  diff_file: "last.diff",
11640
11956
  files
11641
11957
  },
@@ -11650,6 +11966,22 @@ async function writeCopyDiffArtifacts(dst, artifacts) {
11650
11966
  `, "utf8");
11651
11967
  return path9.join(diffDir, "last.diff");
11652
11968
  }
11969
+ function summarizeCopyDiff(artifacts) {
11970
+ const files = Array.isArray(artifacts.manifest.files) ? artifacts.manifest.files : [];
11971
+ const caseSummary = asRecord(artifacts.manifest.case_summary);
11972
+ return {
11973
+ summary: artifacts.manifest.summary,
11974
+ case_summary: artifacts.manifest.case_summary,
11975
+ changed_files: files.filter((file) => file.status !== "unchanged").map((file) => ({ path: file.path, status: file.status })),
11976
+ changed_case_ids: [.../* @__PURE__ */ new Set([
11977
+ ...Array.isArray(caseSummary.added) ? caseSummary.added.map(String) : [],
11978
+ ...Array.isArray(caseSummary.removed) ? caseSummary.removed.map(String) : [],
11979
+ ...Array.isArray(caseSummary.changed) ? caseSummary.changed.map(String) : []
11980
+ ])],
11981
+ readme_changed: files.some((file) => file.path === "README.md" && file.status !== "unchanged"),
11982
+ review_changed: files.some((file) => file.path === "review.json" && file.status !== "unchanged")
11983
+ };
11984
+ }
11653
11985
  async function copyScenarioTree(src, dst, replace, operation) {
11654
11986
  if (!await exists2(src)) fail(`source scenario not found: ${src}`);
11655
11987
  let artifacts;
@@ -11660,81 +11992,170 @@ async function copyScenarioTree(src, dst, replace, operation) {
11660
11992
  }
11661
11993
  await mkdir9(path9.dirname(dst), { recursive: true });
11662
11994
  await cp2(src, dst, { recursive: true });
11663
- return artifacts ? writeCopyDiffArtifacts(dst, artifacts) : void 0;
11995
+ return artifacts ? { path: await writeCopyDiffArtifacts(dst, artifacts), summary: summarizeCopyDiff(artifacts) } : {};
11664
11996
  }
11665
11997
  async function copyDiffPreview(src, dst, operation) {
11666
11998
  const previewDir = path9.join(DEFAULT_TMP_ROOT, `${operation}-${path9.basename(src)}-copy-diff`);
11667
11999
  await rm3(previewDir, { recursive: true, force: true });
11668
12000
  await mkdir9(previewDir, { recursive: true });
11669
- return writeCopyDiffArtifacts(previewDir, await buildCopyDiff(src, dst, operation));
12001
+ const artifacts = await buildCopyDiff(src, dst, operation);
12002
+ return { path: await writeCopyDiffArtifacts(previewDir, artifacts), summary: summarizeCopyDiff(artifacts) };
11670
12003
  }
11671
12004
  async function draftUpdate(options) {
11672
12005
  const src = scenarioPath(options.suiteRoot ?? DEFAULT_SUITE_ROOT, options.scenario);
11673
12006
  const dst = scenarioPath(options.draftRoot ?? DEFAULT_DRAFT_ROOT, options.scenario);
11674
12007
  if (options.replace && !options.diffReviewed && await exists2(dst)) {
12008
+ const preview = await copyDiffPreview(src, dst, "draft-update");
11675
12009
  return {
11676
- copy_diff: await copyDiffPreview(src, dst, "draft-update"),
12010
+ copy_diff: preview.path,
12011
+ copy_diff_summary: preview.summary,
11677
12012
  preview: true,
11678
12013
  message: "destination was not changed; review the diff, then rerun with --diff-reviewed to apply the overwrite"
11679
12014
  };
11680
12015
  }
11681
- return { destination: dst, copy_diff: await copyScenarioTree(src, dst, Boolean(options.replace), "draft-update") };
12016
+ const copyDiff = await copyScenarioTree(src, dst, Boolean(options.replace), "draft-update");
12017
+ return { destination: dst, copy_diff: copyDiff.path, copy_diff_summary: copyDiff.summary };
11682
12018
  }
11683
12019
  async function validateReviewGate(scenarioDir) {
11684
12020
  const reviewPath = path9.join(scenarioDir, "review.json");
11685
- if (!await exists2(reviewPath)) fail(`${scenarioDir}: missing review.json; run multi-subagent SKILL review before promote`);
12021
+ if (!await exists2(reviewPath)) reviewFail(reviewPath, `${scenarioDir}: missing review.json; run multi-subagent SKILL review before promote`);
11686
12022
  let review;
11687
12023
  try {
11688
12024
  review = JSON.parse(await readText(reviewPath));
11689
12025
  } catch (error) {
11690
- fail(`${reviewPath}: invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
12026
+ reviewFail(reviewPath, `${reviewPath}: invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
11691
12027
  }
11692
- if (review.scenario_id !== path9.basename(scenarioDir)) fail(`${reviewPath}: scenario_id must match directory name`);
11693
- if (!review.latest_proof || typeof review.latest_proof !== "object" || Array.isArray(review.latest_proof)) fail(`${reviewPath}: latest_proof is required`);
12028
+ if (review.scenario_id !== path9.basename(scenarioDir)) reviewFail(reviewPath, `${reviewPath}: scenario_id must match directory name`);
12029
+ if (!review.latest_proof || typeof review.latest_proof !== "object" || Array.isArray(review.latest_proof)) reviewFail(reviewPath, `${reviewPath}: latest_proof is required`);
11694
12030
  validateLatestProofObject(reviewPath, review.latest_proof);
11695
- if (!REVIEW_STATUSES.has(String(review.status))) fail(`${reviewPath}: status must be one of ${JSON.stringify([...REVIEW_STATUSES].sort())}`);
11696
- if (!DATE_RE.test(String(review.reviewed_at || ""))) fail(`${reviewPath}: reviewed_at must be YYYY-MM-DD`);
12031
+ if (!REVIEW_STATUSES.has(String(review.status))) reviewFail(reviewPath, `${reviewPath}: status must be one of ${JSON.stringify([...REVIEW_STATUSES].sort())}`);
12032
+ if (!DATE_RE.test(String(review.reviewed_at || ""))) reviewFail(reviewPath, `${reviewPath}: reviewed_at must be YYYY-MM-DD`);
11697
12033
  const perspectives = review.perspectives;
11698
- if (!Array.isArray(perspectives)) fail(`${reviewPath}: perspectives must be a list`);
12034
+ if (!Array.isArray(perspectives)) reviewFail(reviewPath, `${reviewPath}: perspectives must be a list`);
11699
12035
  const perspectiveNames = new Set(perspectives.map((item) => item?.name));
11700
12036
  const missing = [...REVIEW_REQUIRED_PERSPECTIVES].filter((name) => !perspectiveNames.has(name));
11701
- if (missing.length > 0) fail(`${reviewPath}: missing required review perspectives: ${missing.join(", ")}`);
12037
+ if (missing.length > 0) reviewFail(reviewPath, `${reviewPath}: missing required review perspectives: ${missing.join(", ")}`);
11702
12038
  for (const item of perspectives) {
11703
- if (!item?.reviewer) fail(`${reviewPath}: perspective \`${item?.name ?? ""}\` missing reviewer`);
11704
- if (!REVIEW_STATUSES.has(String(item.status))) fail(`${reviewPath}: perspective \`${item?.name ?? ""}\` status must be one of ${JSON.stringify([...REVIEW_STATUSES].sort())}`);
11705
- if (!item.summary) fail(`${reviewPath}: perspective \`${item?.name ?? ""}\` missing summary`);
12039
+ if (!item?.reviewer) reviewFail(reviewPath, `${reviewPath}: perspective \`${item?.name ?? ""}\` missing reviewer`);
12040
+ if (!REVIEW_STATUSES.has(String(item.status))) reviewFail(reviewPath, `${reviewPath}: perspective \`${item?.name ?? ""}\` status must be one of ${JSON.stringify([...REVIEW_STATUSES].sort())}`);
12041
+ if (!item.summary) reviewFail(reviewPath, `${reviewPath}: perspective \`${item?.name ?? ""}\` missing summary`);
11706
12042
  if (item.name === "config_consistency") await validateConfigConsistencyReview(reviewPath, item);
11707
12043
  }
11708
12044
  const unresolved = review.unresolved;
11709
- if (!unresolved || typeof unresolved !== "object" || Array.isArray(unresolved)) fail(`${reviewPath}: unresolved must be an object`);
12045
+ if (!unresolved || typeof unresolved !== "object" || Array.isArray(unresolved)) reviewFail(reviewPath, `${reviewPath}: unresolved must be an object`);
11710
12046
  if (unresolved.P0 !== 0 || unresolved.P1 !== 0) {
11711
- fail(`${reviewPath}: unresolved P0/P1 findings must be 0 before promote`);
12047
+ reviewFail(reviewPath, `${reviewPath}: unresolved P0/P1 findings must be 0 before promote`);
11712
12048
  }
11713
- if (!Array.isArray(review.fixes) || review.fixes.length === 0) fail(`${reviewPath}: fixes must be a non-empty list`);
12049
+ if (!Array.isArray(review.fixes) || review.fixes.length === 0) reviewFail(reviewPath, `${reviewPath}: fixes must be a non-empty list`);
11714
12050
  }
11715
12051
  async function validateConfigConsistencyReview(reviewPath, item) {
11716
12052
  const judgments = item.case_judgments;
11717
- if (!Array.isArray(judgments) || judgments.length === 0) fail(`${reviewPath}: config_consistency must include non-empty case_judgments`);
12053
+ if (!Array.isArray(judgments) || judgments.length === 0) reviewFail(reviewPath, `${reviewPath}: config_consistency must include non-empty case_judgments`);
11718
12054
  for (const judgment of judgments) {
11719
- if (!judgment?.case_id) fail(`${reviewPath}: config_consistency case_judgments item missing case_id`);
12055
+ if (!judgment?.case_id) reviewFail(reviewPath, `${reviewPath}: config_consistency case_judgments item missing case_id`);
11720
12056
  if (!CONFIG_CONSISTENCY_STATUSES.has(String(judgment.status))) {
11721
- fail(`${reviewPath}: config_consistency judgment \`${judgment.case_id}\` status must be one of ${JSON.stringify([...CONFIG_CONSISTENCY_STATUSES].sort())}`);
12057
+ reviewFail(reviewPath, `${reviewPath}: config_consistency judgment \`${judgment.case_id}\` status must be one of ${JSON.stringify([...CONFIG_CONSISTENCY_STATUSES].sort())}`);
11722
12058
  }
11723
12059
  if (!Array.isArray(judgment.config_basis_checked) || judgment.config_basis_checked.length === 0) {
11724
- fail(`${reviewPath}: config_consistency judgment \`${judgment.case_id}\` must include config_basis_checked`);
12060
+ reviewFail(reviewPath, `${reviewPath}: config_consistency judgment \`${judgment.case_id}\` must include config_basis_checked`);
11725
12061
  }
11726
12062
  const missing = [];
11727
12063
  for (const location of judgment.config_basis_checked) {
11728
12064
  if (typeof location !== "string" || !await exists2(location)) missing.push(String(location));
11729
12065
  }
11730
- if (missing.length > 0) fail(`${reviewPath}: config_consistency judgment \`${judgment.case_id}\` references missing checked location(s): ${missing.join(", ")}`);
11731
- if (!judgment.evidence) fail(`${reviewPath}: config_consistency judgment \`${judgment.case_id}\` missing evidence`);
12066
+ if (missing.length > 0) reviewFail(reviewPath, `${reviewPath}: config_consistency judgment \`${judgment.case_id}\` references missing checked location(s): ${missing.join(", ")}`);
12067
+ if (!judgment.evidence) reviewFail(reviewPath, `${reviewPath}: config_consistency judgment \`${judgment.case_id}\` missing evidence`);
11732
12068
  }
11733
12069
  const missingCaseReview = item.missing_case_review;
11734
- if (!missingCaseReview || typeof missingCaseReview !== "object" || Array.isArray(missingCaseReview)) fail(`${reviewPath}: config_consistency must include missing_case_review`);
12070
+ if (!missingCaseReview || typeof missingCaseReview !== "object" || Array.isArray(missingCaseReview)) reviewFail(reviewPath, `${reviewPath}: config_consistency must include missing_case_review`);
11735
12071
  const missingCaseReviewObject = missingCaseReview;
11736
- if (typeof missingCaseReviewObject.needed !== "boolean") fail(`${reviewPath}: config_consistency missing_case_review.needed must be boolean`);
11737
- if (!missingCaseReviewObject.summary) fail(`${reviewPath}: config_consistency missing_case_review.summary is required`);
12072
+ if (typeof missingCaseReviewObject.needed !== "boolean") reviewFail(reviewPath, `${reviewPath}: config_consistency missing_case_review.needed must be boolean`);
12073
+ if (!missingCaseReviewObject.summary) reviewFail(reviewPath, `${reviewPath}: config_consistency missing_case_review.summary is required`);
12074
+ }
12075
+ function asRecord(value) {
12076
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
12077
+ }
12078
+ function defaultCaseJudgments(rows) {
12079
+ return rows.map((row) => {
12080
+ const locations = configBasisLocations(row.config_basis).filter((location) => {
12081
+ try {
12082
+ return location.length > 0;
12083
+ } catch {
12084
+ return false;
12085
+ }
12086
+ });
12087
+ return {
12088
+ case_id: row.case_id,
12089
+ status: "correct",
12090
+ config_basis_checked: locations.length > 0 ? locations : ["skills/bpmax-e2e-flow-test-operator/SKILL.md"],
12091
+ evidence: "Initialized by bpmax-cli; reviewer must replace this with concrete config readback evidence before promote."
12092
+ };
12093
+ });
12094
+ }
12095
+ function mergeReviewDraft(scenarioId, proof, rows, existing) {
12096
+ const existingPerspectives = Array.isArray(existing?.perspectives) ? existing.perspectives.filter((item) => item && typeof item === "object") : [];
12097
+ const byName = new Map(existingPerspectives.map((item) => [String(item.name || ""), item]));
12098
+ const configConsistency = asRecord(byName.get("config_consistency"));
12099
+ const perspectives = REVIEW_REQUIRED_PERSPECTIVE_LIST.map((name) => {
12100
+ const current = asRecord(byName.get(name));
12101
+ if (name !== "config_consistency") {
12102
+ return {
12103
+ name,
12104
+ reviewer: current.reviewer || `subagent-${name.replace(/_/g, "-")}`,
12105
+ status: current.status || "fixed",
12106
+ summary: current.summary || "Initialized by bpmax-cli; replace with actual review summary."
12107
+ };
12108
+ }
12109
+ return {
12110
+ name,
12111
+ reviewer: configConsistency.reviewer || "subagent-config",
12112
+ status: configConsistency.status || "fixed",
12113
+ summary: configConsistency.summary || "Initialized by bpmax-cli; replace with actual config consistency summary.",
12114
+ case_judgments: Array.isArray(configConsistency.case_judgments) && configConsistency.case_judgments.length > 0 ? configConsistency.case_judgments : defaultCaseJudgments(rows),
12115
+ missing_case_review: asRecord(configConsistency.missing_case_review).summary ? configConsistency.missing_case_review : { needed: false, summary: "Initialized by bpmax-cli; reviewer must confirm whether any P0/P1 cases are missing." }
12116
+ };
12117
+ });
12118
+ return {
12119
+ ...reviewSchemaExample(scenarioId, proof),
12120
+ ...existing,
12121
+ scenario_id: scenarioId,
12122
+ reviewed_at: typeof existing?.reviewed_at === "string" && DATE_RE.test(existing.reviewed_at) ? existing.reviewed_at : (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
12123
+ latest_proof: proof,
12124
+ perspectives,
12125
+ unresolved: {
12126
+ P0: Number(asRecord(existing?.unresolved).P0 ?? 0),
12127
+ P1: Number(asRecord(existing?.unresolved).P1 ?? 1),
12128
+ P2: Number(asRecord(existing?.unresolved).P2 ?? 0)
12129
+ },
12130
+ fixes: Array.isArray(existing?.fixes) && existing.fixes.length > 0 ? existing.fixes : ["Initialized by bpmax-cli; real multi-perspective review is still required before unresolved.P1 can be set to 0."]
12131
+ };
12132
+ }
12133
+ async function initOrRepairReview(options) {
12134
+ const scenarioDir = scenarioPath(options.draftRoot ?? DEFAULT_DRAFT_ROOT, options.scenario);
12135
+ if (!await exists2(scenarioDir)) fail(`draft scenario not found: ${scenarioDir}`);
12136
+ await validateReadme(scenarioDir);
12137
+ const rows = await readCases(path9.join(scenarioDir, "cases.csv"));
12138
+ const proof = await readLatestProof(options.latestProof);
12139
+ const reviewPath = path9.join(scenarioDir, "review.json");
12140
+ let existing;
12141
+ const existed = await exists2(reviewPath);
12142
+ if (existed) {
12143
+ if (!options.repair) fail(`${reviewPath}: already exists; pass --repair to update missing schema fields`);
12144
+ try {
12145
+ existing = JSON.parse(await readText(reviewPath));
12146
+ } catch {
12147
+ existing = {};
12148
+ }
12149
+ }
12150
+ const review = mergeReviewDraft(path9.basename(scenarioDir), proof, rows, existing);
12151
+ await writeFile9(reviewPath, `${JSON.stringify(review, null, 2)}
12152
+ `, "utf8");
12153
+ return {
12154
+ ok: true,
12155
+ action: existed ? "repair" : "init",
12156
+ path: reviewPath,
12157
+ schema: reviewSchemaExplanation()
12158
+ };
11738
12159
  }
11739
12160
  async function promoteScenario(options) {
11740
12161
  const src = scenarioPath(options.draftRoot ?? DEFAULT_DRAFT_ROOT, options.scenario);
@@ -11743,13 +12164,16 @@ async function promoteScenario(options) {
11743
12164
  if (metadata.status === "draft") fail(`${src}: cannot promote README status draft; set status to active or deprecated`);
11744
12165
  const dst = scenarioPath(options.suiteRoot ?? DEFAULT_SUITE_ROOT, options.scenario);
11745
12166
  if (options.replace && !options.diffReviewed && await exists2(dst)) {
12167
+ const preview = await copyDiffPreview(src, dst, "promote");
11746
12168
  return {
11747
- copy_diff: await copyDiffPreview(src, dst, "promote"),
12169
+ copy_diff: preview.path,
12170
+ copy_diff_summary: preview.summary,
11748
12171
  preview: true,
11749
12172
  message: "destination was not changed; review the diff, then rerun with --diff-reviewed to apply the overwrite"
11750
12173
  };
11751
12174
  }
11752
- return { destination: dst, copy_diff: await copyScenarioTree(src, dst, Boolean(options.replace), "promote") };
12175
+ const copyDiff = await copyScenarioTree(src, dst, Boolean(options.replace), "promote");
12176
+ return { destination: dst, copy_diff: copyDiff.path, copy_diff_summary: copyDiff.summary };
11753
12177
  }
11754
12178
  async function nextReportDir(root = DEFAULT_REPORT_ROOT, create = false, today = /* @__PURE__ */ new Date()) {
11755
12179
  const prefix = [
@@ -11780,7 +12204,7 @@ async function lintReport(root = DEFAULT_REPORT_ROOT) {
11780
12204
  continue;
11781
12205
  }
11782
12206
  if (!await exists2(path9.join(runDir, "summary.md"))) errors.push(`${runDir}: missing summary.md`);
11783
- const files = await readdir2(runDir);
12207
+ const files = await readdir3(runDir);
11784
12208
  const scenarioReports = files.filter((file) => file.endsWith(".md") && file !== "summary.md");
11785
12209
  if (scenarioReports.length === 0) errors.push(`${runDir}: missing scenario report markdown`);
11786
12210
  for (const reportName of scenarioReports) {
@@ -11833,15 +12257,24 @@ async function validateCopyDiffArtifacts(scenarioDir) {
11833
12257
  // src/commands/test-suite.ts
11834
12258
  function registerTestSuiteCommands(program2) {
11835
12259
  const suite = program2.command("test-suite").description("Manage local BPMAX AI test case suites under .ai_test");
11836
- suite.command("lint").description("Lint BPMAX AI test case suite scenarios").option("--root <path>", "Suite root directory", DEFAULT_SUITE_ROOT).requiredOption("--latest-proof <path>", "latest-* proof JSON written after syncing the sysconfig repo").option("--format <format>", "Output format", "json").action(async (options) => {
12260
+ suite.command("lint").description("Lint BPMAX AI test case suite scenarios").option("--root <path>", "Suite root directory", DEFAULT_SUITE_ROOT).requiredOption("--latest-proof <path>", "latest-* proof JSON written after syncing the sysconfig repo").option("--explain", "Include review.json schema and test_data alignment rules in the output").option("--format <format>", "Output format", "json").action(async (options) => {
11837
12261
  await requireLatestProof(options.latestProof);
11838
- const scenarios = await lintSuite(options.root);
11839
- printResult(options.format, { ok: true, scenario_count: scenarios.length });
12262
+ printResult(options.format, await lintSuiteDetailed(options.root, { explain: Boolean(options.explain) }));
11840
12263
  });
11841
12264
  suite.command("index").description("Print the BPMAX AI test case suite index").option("--root <path>", "Suite root directory", DEFAULT_SUITE_ROOT).option("--include-inactive", "Include draft and deprecated scenarios").requiredOption("--latest-proof <path>", "latest-* proof JSON written after syncing the sysconfig repo").option("--format <format>", "Output format", "json").action(async (options) => {
11842
12265
  await requireLatestProof(options.latestProof);
11843
12266
  printResult(options.format, await indexSuite(options.root, Boolean(options.includeInactive)));
11844
12267
  });
12268
+ const review = suite.command("review").description("Create, repair, or explain review.json required before promoting a draft scenario");
12269
+ review.command("init").description("Create a minimal review.json for a draft scenario").requiredOption("--scenario <id>", "Scenario id").option("--draft-root <path>", "Draft suite root directory", DEFAULT_DRAFT_ROOT).requiredOption("--latest-proof <path>", "latest-* proof JSON written after syncing the sysconfig repo").option("--format <format>", "Output format", "json").action(async (options) => {
12270
+ printResult(options.format, await initOrRepairReview(options));
12271
+ });
12272
+ review.command("repair").description("Repair missing schema fields in an existing draft review.json").requiredOption("--scenario <id>", "Scenario id").option("--draft-root <path>", "Draft suite root directory", DEFAULT_DRAFT_ROOT).requiredOption("--latest-proof <path>", "latest-* proof JSON written after syncing the sysconfig repo").option("--format <format>", "Output format", "json").action(async (options) => {
12273
+ printResult(options.format, await initOrRepairReview({ ...options, repair: true }));
12274
+ });
12275
+ review.command("explain").description("Print the review.json schema required by promote").option("--format <format>", "Output format", "json").action(async (options) => {
12276
+ printResult(options.format, reviewSchemaExplanation());
12277
+ });
11845
12278
  suite.command("draft-update").description("Copy one formal suite scenario to the draft suite for editing").requiredOption("--scenario <id>", "Scenario id").option("--suite-root <path>", "Formal suite root directory", DEFAULT_SUITE_ROOT).option("--draft-root <path>", "Draft suite root directory", DEFAULT_DRAFT_ROOT).option("--replace", "Allow replacing an existing draft scenario").option("--diff-reviewed", "Confirm the copy diff preview was reviewed").requiredOption("--latest-proof <path>", "latest-* proof JSON written after syncing the sysconfig repo").option("--format <format>", "Output format", "json").action(async (options) => {
11846
12279
  await requireLatestProof(options.latestProof);
11847
12280
  printResult(options.format, await draftUpdate(options));