@stalfh233/omc-cli 0.8.6 → 0.8.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.
Files changed (40) hide show
  1. package/coverage/m1-coverage-manifest-v1.json +1 -0
  2. package/dist/approval-flow.js +49 -4
  3. package/dist/batch-call.js +21 -4
  4. package/dist/cli-stdout.js +1 -0
  5. package/dist/cli.js +84 -3
  6. package/dist/code-rules.js +35 -11
  7. package/dist/config-store.js +15 -1
  8. package/dist/endpoints.js +10 -0
  9. package/dist/form-layout.js +79 -0
  10. package/dist/form-support.js +111 -7
  11. package/dist/graph.js +38 -3
  12. package/dist/human-summary.js +19 -1
  13. package/dist/lanes/field-contract.js +5 -1
  14. package/dist/lanes/field-coverage.js +1 -0
  15. package/dist/lanes/field.js +20 -2
  16. package/dist/lanes/form-contract.js +1 -1
  17. package/dist/lanes/form.js +24 -2
  18. package/dist/lanes/list-view.js +104 -2
  19. package/dist/lanes/model-references.js +172 -0
  20. package/dist/lanes/model.js +206 -123
  21. package/dist/lanes/runtime-data-contract.js +4 -4
  22. package/dist/lanes/runtime-data.js +170 -7
  23. package/dist/lanes/workflow.js +213 -45
  24. package/dist/model-purge.js +106 -21
  25. package/dist/model-scaffold.js +52 -10
  26. package/dist/recipes/field.js +44 -1
  27. package/dist/recipes/form.js +33 -6
  28. package/dist/recipes/list-view.js +1 -1
  29. package/dist/reserved.js +28 -0
  30. package/dist/search-index.js +2 -0
  31. package/dist/tool-types.js +1 -0
  32. package/dist/write.js +12 -0
  33. package/package.json +3 -3
  34. package/skills/omc-business-configuration.md +6 -0
  35. package/skills/omc-capabilities.md +1 -1
  36. package/skills/omc-playbook.md +5 -0
  37. package/skills/omc-requirement-vocabulary.md +13 -0
  38. package/skills/omc-start-here.md +1 -1
  39. package/skills/omc-tool-selection.md +2 -0
  40. package/skills/omc-write-hazards.md +3 -0
@@ -5,7 +5,7 @@ export { RUNTIME_DATA_WIRE, RUNTIME_QUERY_OPERATORS, ENGINE_OWNED_KEYS, SUBMIT_S
5
5
  import { RUNTIME_DATA_WIRE } from "omc-core/wire-facts";
6
6
  export function dataListDescription() {
7
7
  const wire = RUNTIME_DATA_WIRE;
8
- return `按简化过滤 DSL 查询业务对象(runtime/query/list);DSL 在 CLI 内翻译为平台 queryCondition(${wire.dslShape}),并按发布字段元数据为每个条件注入 propertyType(未知过滤字段将被拒绝,可用 rawCondition 逃生);响应行在 items[],业务字段在 items[].fields.<code>(不是 rows[],也不是 item 顶层——--jq 常用 items[].fields.sku);空模型返回空列表;未配列的自定义字段投影为 null——这是显示面缺列配置、不是数据缺失(data.load 有值),显式选列在结果中全为 null 而发布字段元数据显示其存在时,readback 追加 projectionHint(先用 listview.configure 配置该模型的默认视图列,或用 data.load 读单条权威值)。键缺席=字段不存在;键在值 null=未投影或真空值(见 projectionHint.unprojected)。`;
8
+ return `按简化过滤 DSL 查询业务对象(runtime/query/list);DSL 在 CLI 内翻译为平台 queryCondition(${wire.dslShape}),并按发布字段元数据为每个条件注入 propertyType(未知过滤字段将被拒绝,可用 rawCondition 逃生);响应行在 items[],业务字段在 items[].fields.<code>(不是 rows[],也不是 item 顶层——--jq 常用 items[].fields.sku);空模型返回空列表;列表只投影视图列:**已判定未投影的列会从 items[].fields 省略键**(items[].unprojected 点名;不是数据丢失——data.load 有值;显式选列在结果中全为 null 而发布字段元数据显示其存在时,readback 追加 projectionHint,先用 listview.configure 配置该模型的默认视图列或用 data.load 读单条权威值)。键缺席=字段不存在或该行已判定未投影(见 items[].unprojected);键在且值 null=真空值(未投影或真空值不再同形;nullSemantics 说明口径)。`;
9
9
  }
10
10
  export function dataAggregateDescription() {
11
11
  return `临时计数与数值聚合(纯读)。count:runtime/query/list size:1 读 totalElements(服务端精确、不受 cap 影响;带 filter +1 field.list)。sum/avg/min/max:field 必填且已发布 propertyType=2(NUMERICAL);无 GET_LIST 改源时优先 /sum ALL_DATA(coverage.mode=server-aggregate,全量精确),否则/失败/键不符回退本地折叠(strategyFallback;size:200 翻页至 cap 1000,null 不进聚合、avg=sum/非 null 行数,nonNullCount=0→value:null)。complete 看 rowsScanned>=total,否则 missingCount+capNotice,绝不外推。groupBy 单列:count 值域可枚举(options/字典)→值域×count(V+3 wire),分桶并发窗口 4(限流退化 2,见 wire.concurrency),桶序稳定;按 count 降序取 topN(默认 10/上限 20),截断给 truncatedBuckets/bucketsTruncatedCount,null 单列 nullBucket;不可枚举或数值指标→本地扫描(coverage.mode=paged-local-scan/local-scan),数值桶 {key,count,nonNullCount,value} 按 value 降序、并列按 key,null 行进 nullBucket。filter.draftPolicy:count+groupBy 默认 includeDrafts:false 注入 sequenceStatus≠DRAFT;数值指标不默认排除;count 省略=平台默认(无条件含草稿、带条件排草稿);显式 false 强制排除。边界:临时问句用本工具;持久图表/看板用 report.chartdata,视图汇总列用 sumType,写时计算用 datarule type2。子表计数/求和用 child(主表 schemaCode + childSchemaCode/bizObjectId)。`;
@@ -133,7 +133,7 @@ export const RUNTIME_DATA_LANE_CONTRACT = Object.freeze({
133
133
  tools: Object.freeze({
134
134
  "data.list": Object.freeze({ scope: "filtered list field projection", description: dataListDescription() }),
135
135
  "data.aggregate": Object.freeze({ scope: "aggregate count and grouped distribution via query/list totals", description: dataAggregateDescription() }),
136
- "data.load": Object.freeze({ scope: "authoritative readback form load", description: "M2 authoritative readback: form/load one business object by id. **返回形状:业务字段值在 `result.data`(非 readback.authoritative);大结果 stdout 只回 detailArtifactId + fetch 提示,用 `omc artifact get <id>` 取回;`fields:[...]` 可投影只取所需键**。" }),
136
+ "data.load": Object.freeze({ scope: "authoritative readback form load", description: "M2 authoritative readback: form/load one business object by id. **返回形状:业务字段值在 `result.data`(非 readback.authoritative);大结果 stdout 只回 detailArtifactId + fetch 提示,用 `omc artifact get <id>` 取回;`fields:[...]` 可投影只取所需键**。DATE 字段读回固定 `YYYY-MM-DD HH:mm:ss`(后端 DateBizField.toDisplayValue 恒用秒级格式;表单 load 序列化同口径),字段 options.format 只影响门户显示,不要按 format 断言读回字符串。" }),
137
137
  "data.save": Object.freeze({
138
138
  scope: "write authoritative readback form save",
139
139
  description: dataSaveDescription(),
@@ -144,7 +144,7 @@ export const RUNTIME_DATA_LANE_CONTRACT = Object.freeze({
144
144
  }),
145
145
  "data.delete": Object.freeze({
146
146
  scope: "write authoritative readback form save",
147
- description: desc("M2 runtime data delete (runtime/form/delete) with absence readback."),
147
+ description: desc("M2 runtime data delete (runtime/form/delete) with absence readback. 批量回执按 absent / deleted[].absent / deletionVerified / undeletedIds 判成功;**没有 `present` 键**(旧版与 absent 并列会出现 present:true+absent:true,无法判断读哪条);remainingRows/modelRowsRemaining/modelClean 只描述整表状态,不用于判批量删除成败。"),
148
148
  }),
149
149
  "data.submit": Object.freeze({ scope: "write authoritative readback form save", description: dataSubmitDescription() }),
150
150
  }),
@@ -154,7 +154,7 @@ function desc(lead) {
154
154
  }
155
155
  export function assertRuntimeDataContract() {
156
156
  assertLaneContract(RUNTIME_DATA_LANE_CONTRACT);
157
- assertDescriptionCarries(RUNTIME_DATA_LANE_CONTRACT, "data.list", ["queryCondition", "propertyType", "rawCondition", "projectionHint", "listview.configure", "data.load", "items[].fields", "键缺席", "未投影或真空值"]);
157
+ assertDescriptionCarries(RUNTIME_DATA_LANE_CONTRACT, "data.list", ["queryCondition", "propertyType", "rawCondition", "projectionHint", "listview.configure", "data.load", "items[].fields", "items[].unprojected", "nullSemantics", "键缺席", "未投影或真空值"]);
158
158
  assertDescriptionCarries(RUNTIME_DATA_LANE_CONTRACT, "data.aggregate", ["totalElements", "groupBy", "local-scan", "cap 1000", "draftPolicy", "report.chartdata", "sum", "avg", "NUMERICAL", "nonNullCount"]);
159
159
  assertDescriptionCarries(RUNTIME_DATA_LANE_CONTRACT, "data.save", ["bizObjectId", "sheetCode", "bizsheet/get", "workflowCode", "sequenceStatus", "workItem", "propertyType 9", "50000", "mappings", "rowStatus", "DRAFT", "submit:true", "CHILD_TABLE"]);
160
160
  assertDescriptionCarries(RUNTIME_DATA_LANE_CONTRACT, "data.update", ["runtime/form/save", "bizObjectId", "COMPLETED", "304001", "form/load", "rowStatus", "child-rows-upsert"]);
@@ -397,6 +397,63 @@ export function projectionHintFace(items, evidence) {
397
397
  ...(unprojected.length > 0 ? { unprojected } : {}),
398
398
  };
399
399
  }
400
+ /**
401
+ * F8(w44,2026-11-26 真机):`data.list` 的行内 `fields` 对**未投影**列也回
402
+ * `null`(与真空值同形),顶层 `projectionHint.unprojected` 只在整列全 null 时
403
+ * 出现,脚本按行对账仍会把 null 当数据丢失。行级 `unprojected` 用**同一份**
404
+ * 视图列证据(queryColumns)逐行标注:值 null 且不在视图列 → 本行未投影。
405
+ * `*_key` 孪生列与系统列不算(投影证据只覆盖业务列);拿不到视图清单时只用
406
+ * `projectionMiss`(请求列在 wire 行里整列缺席)判定,绝不拿 null 猜。
407
+ */
408
+ const isNonBusinessProjectionKey = (key) => RUNTIME_SYSTEM_FIELD_CODES.has(key) || key.endsWith("_") || key.endsWith("_key");
409
+ export function itemUnprojectedFields(fields, projectionMiss, viewColumnCodes) {
410
+ const missed = projectionMiss.length > 0 ? new Set(projectionMiss) : undefined;
411
+ if (viewColumnCodes === undefined && missed === undefined)
412
+ return [];
413
+ const inView = viewColumnCodes === undefined ? undefined : new Set(viewColumnCodes);
414
+ return Object.entries(fields)
415
+ .filter(([code, value]) => {
416
+ if (isNonBusinessProjectionKey(code))
417
+ return false;
418
+ if (value !== null && value !== undefined)
419
+ return false;
420
+ if (inView !== undefined)
421
+ return !inView.has(code);
422
+ return missed.has(code);
423
+ })
424
+ .map(([code]) => code);
425
+ }
426
+ /** 行级 `unprojected` 只在有已判定未投影列时加键(空数组没有信息量,也会涨字节)。 */
427
+ export function attachItemUnprojected(items, projectionMiss, viewColumnCodes) {
428
+ // 键只在**该行真的**有已判定未投影列时出现:无标注的行不加 `unprojected: []`
429
+ // ——每行多 ~20B 会把 25 行的小结果顶过 compact 外置阈值(0.8.7 全量实测
430
+ // composers `data.list --all` 因 `items` 被外置而失败),且空数组没有信息量。
431
+ return items.map((item) => {
432
+ const unprojected = itemUnprojectedFields(item.fields, projectionMiss, viewColumnCodes);
433
+ return unprojected.length > 0 ? { ...item, unprojected } : { ...item };
434
+ });
435
+ }
436
+ /**
437
+ * F5(w53,2026-11-26 真机):已判定未投影的列**从 `items[].fields` 省略键**,
438
+ * 不再回 `null`——0.8.7 真机里 `faultDesc/repairDate/version:null` 与真实空值
439
+ * 同形,脚本会当成「值丢了」。`unprojected` 仍逐行点名同一批 code(键缺席 =
440
+ * 未投影/不适用;键在且 null 才是真空值)。
441
+ *
442
+ * 只删**该行 unprojected 点名的键**:无证据的 null(真空值)逐字保留;系统列 /
443
+ * `*_` / `*_key` 本来就不进 unprojected,也不会被误删。
444
+ */
445
+ export function omitUnprojectedFields(items) {
446
+ return items.map((item) => {
447
+ if (item.unprojected === undefined || item.unprojected.length === 0)
448
+ return item;
449
+ const fields = { ...item.fields };
450
+ for (const code of item.unprojected)
451
+ delete fields[code];
452
+ return { ...item, fields };
453
+ });
454
+ }
455
+ /** 人类/脚本读 null 的唯一权威口径;与行级 `unprojected` 同时出现才完整。 */
456
+ export const DATA_LIST_NULL_SEMANTICS = "items[].fields.<code> 键缺席=字段不存在或该行已判定未投影(items[].unprojected 已省略该键);键在且值为 null 才是真空值;判真值用 data.load。";
400
457
  /**
401
458
  * B2(issue 2026-11-25,真机 `milestone_ledger`):`data.list` 对关联字段静默回
402
459
  * null,而同一条记录 `data.load` 有真实值(`{id, displayCode, <显示字段>}`)。
@@ -456,6 +513,92 @@ export function relationColumnsNotProjected(codes, relationCodes, schemaCode, sa
456
513
  nextCommand: `omc call data.load --env <env> --args '{"schemaCode":"${schemaCode}","bizObjectId":"${id}"}'`,
457
514
  }));
458
515
  }
516
+ /**
517
+ * F4(w53,2026-11-26 真机):`options.mappings` 只在**门户表单运行时**用户选中
518
+ * 关联值时回填副本/快照列;`data.save` / `data.update` / `data.submit` 的服务端
519
+ * 写路径不执行映射(子表 `repairRef` 有 mappings,save 后快照仍为空)。
520
+ *
521
+ * 平台证据(8.6.26):门户 `runtime/form/save` 链路
522
+ * `FormRuntimeController.save:806-843` → `saveBizSheet:932-970` →
523
+ * `RuntimeController.saveBizObject:926-934` → `BizObjectFacadeImpl.saveBizObject`
524
+ * **没有** mapping 调用;表单运行时另走显式的
525
+ * `BaseController.executeDataRuleValidationAndMapping:1088-1103`(mappingList),
526
+ * 其调用方是 OpenAPI v2/v3(`OpenApiFormController.java:290` /
527
+ * `OpenApiBizObjectController.java:260`),不是本工具使用的 runtime 表单保存面。
528
+ * `options.mappings` 的消费实现见 `WorkSheetMappingServiceImpl.executeChildMapping`
529
+ * (bizdata `:207-230`)——只在被显式调用的 mapping 面执行。
530
+ * 「后端会不会代跑映射」如需逐版本闭环,仍需真机采样复核。
531
+ *
532
+ * 只在本次 formData 真的带了子表数组时才读子表 schema 的已发布字段(零数组 =
533
+ * 零 wire);读失败静默跳过,绝不阻断写。
534
+ */
535
+ const MAPPING_NOTE_LIMIT = 5;
536
+ const MAPPING_NOTE_TARGET_LIMIT = 3;
537
+ function relationMappingsOf(row) {
538
+ const options = parseOptions(row.options);
539
+ let raw = options.mappings ?? row.mappings;
540
+ if (typeof raw === "string") {
541
+ if (raw.trim() === "")
542
+ return { declared: false, targets: [] };
543
+ try {
544
+ raw = JSON.parse(raw);
545
+ }
546
+ catch {
547
+ // 非空字符串仍是「声明了映射」(损坏 JSON 可能被平台原样保存)。
548
+ return { declared: true, targets: [] };
549
+ }
550
+ }
551
+ if (!Array.isArray(raw))
552
+ return { declared: raw !== undefined && raw !== null, targets: [] };
553
+ const targets = raw
554
+ .map((entry) => entry && typeof entry === "object" && !Array.isArray(entry)
555
+ ? String(entry.target ?? "").trim()
556
+ : "")
557
+ .filter((target) => target.length > 0);
558
+ return { declared: raw.length > 0, targets };
559
+ }
560
+ async function childTableMappingHits(session, formData, childCodes) {
561
+ const present = childCodes.filter((code) => Array.isArray(formData[code]));
562
+ if (present.length === 0)
563
+ return [];
564
+ const hits = [];
565
+ for (const childTable of present) {
566
+ let rows;
567
+ try {
568
+ // 子表 schemaCode = 父模型 CHILD_TABLE 字段的 code(平台同源)。
569
+ rows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode: childTable, isPublish: "true" } })).data);
570
+ }
571
+ catch {
572
+ // 元数据读不到就不提示(读面副作用不能阻断写)。
573
+ continue;
574
+ }
575
+ for (const row of rows) {
576
+ const type = Number(row.propertyType ?? row.type);
577
+ if (!RELATION_PROPERTY_TYPES.has(type))
578
+ continue;
579
+ const mapping = relationMappingsOf(row);
580
+ if (!mapping.declared)
581
+ continue;
582
+ const relationField = String(row.code ?? row.propertyCode ?? "");
583
+ if (relationField)
584
+ hits.push({ childTable, relationField, targets: mapping.targets });
585
+ }
586
+ }
587
+ return hits;
588
+ }
589
+ function mappingRuntimeNoteFor(hits) {
590
+ if (hits.length === 0)
591
+ return undefined;
592
+ const shown = hits.slice(0, MAPPING_NOTE_LIMIT);
593
+ const detail = shown
594
+ .map((hit) => {
595
+ const targets = hit.targets.slice(0, MAPPING_NOTE_TARGET_LIMIT).join("/");
596
+ const suffix = targets.length > 0 ? `→${targets}${hit.targets.length > MAPPING_NOTE_TARGET_LIMIT ? "…" : ""}` : "";
597
+ return `${hit.childTable}.${hit.relationField}${suffix}`;
598
+ })
599
+ .join("、");
600
+ return `REST 写不执行关联映射(options.mappings 只在门户选值时由表单运行时回填):${detail}${hits.length > shown.length ? ` 等 ${hits.length} 处` : ""};快照/映射目标字段需调用方在 formData 里自填,映射配置以 field.get 的 options 为准。`;
601
+ }
459
602
  /**
460
603
  * data.list 的视图证据读取(query/get 失败/无视图 → undefined = 无证据)。
461
604
  * 拿到 queryColumns 数组才算可判定证据;视图对象在但 queryColumns 非数组 →
@@ -1937,6 +2080,11 @@ export function registerRuntimeDataLane(tools) {
1937
2080
  const viewEvidence = nullProjection ? await listViewProjectionEvidence(session, args.schemaCode, args.queryCode ?? args.schemaCode) : undefined;
1938
2081
  const projectionHintAll = projectionHintWithMiss(projectionHintFace(items, viewEvidence), projectionMissAll);
1939
2082
  const columnsNotProjected = await relationNotProjectedOf(items, projectionMissAll, viewEvidence?.viewColumnCodes);
2083
+ const itemsWithProjection = attachItemUnprojected(items, projectionMissAll, viewEvidence?.viewColumnCodes);
2084
+ // F5(w53):已判定未投影的列从 fields 省略键(unprojected 仍是证据);
2085
+ // 无证据的 null(真空值)保留。诊断都已用带 null 的 items 算完再省略。
2086
+ const itemsFinal = omitUnprojectedFields(itemsWithProjection);
2087
+ const anyNullField = itemsFinal.some((item) => Object.values(item.fields).some((value) => value === null));
1940
2088
  return {
1941
2089
  schemaCode: args.schemaCode,
1942
2090
  ...application,
@@ -1984,9 +2132,10 @@ export function registerRuntimeDataLane(tools) {
1984
2132
  }
1985
2133
  : {}),
1986
2134
  ...(projectionHintAll !== undefined ? { projectionHint: projectionHintAll } : {}),
2135
+ ...(anyNullField ? { nullSemantics: DATA_LIST_NULL_SEMANTICS } : {}),
1987
2136
  ...(projectionMissAll.length > 0 ? { projectionMiss: projectionMissAll } : {}),
1988
2137
  ...(columnsNotProjected.length > 0 ? { columnsNotProjected } : {}),
1989
- items,
2138
+ items: itemsFinal,
1990
2139
  };
1991
2140
  }
1992
2141
  let result;
@@ -2126,9 +2275,13 @@ export function registerRuntimeDataLane(tools) {
2126
2275
  const viewEvidence = hasNullValue ? await listViewProjectionEvidence(session, args.schemaCode, args.queryCode ?? args.schemaCode) : undefined;
2127
2276
  const projectionHintPaged = projectionHintWithMiss(projectionHintFace(items, viewEvidence), projectionMissPaged);
2128
2277
  const columnsNotProjected = await relationNotProjectedOf(items, projectionMissPaged, viewEvidence?.viewColumnCodes);
2278
+ const itemsWithProjection = attachItemUnprojected(items, projectionMissPaged, viewEvidence?.viewColumnCodes);
2279
+ // F5(w53):已判定未投影的列从 fields 省略键;无证据的 null 保留。
2280
+ const itemsFinal = omitUnprojectedFields(itemsWithProjection);
2281
+ const anyNullField = itemsFinal.some((item) => Object.values(item.fields).some((value) => value === null));
2129
2282
  // F6 工单 05b:只有本页行真的内联了子表数组才给一句(否则零字节);
2130
2283
  // 取第一条命中行,命令里的 schemaCode/childSchemaCode/bizObjectId 都是真值。
2131
- const inlineChild = items
2284
+ const inlineChild = itemsFinal
2132
2285
  .map((item) => inlineChildRowsOf(item.fields, item.id))
2133
2286
  .find((hit) => hit !== undefined);
2134
2287
  const readback = {
@@ -2165,6 +2318,7 @@ export function registerRuntimeDataLane(tools) {
2165
2318
  })(),
2166
2319
  ...(choiceFilterFields.length > 0 && Number(total ?? 0) === 0 ? { filterValueHint: choiceFilterValueHint(choiceFilterFields) } : {}),
2167
2320
  ...(projectionHintPaged !== undefined ? { projectionHint: projectionHintPaged } : {}),
2321
+ ...(anyNullField ? { nullSemantics: DATA_LIST_NULL_SEMANTICS } : {}),
2168
2322
  ...(projectionMissPaged.length > 0 ? { projectionMiss: projectionMissPaged } : {}),
2169
2323
  ...(columnsNotProjected.length > 0 ? { columnsNotProjected } : {}),
2170
2324
  totalPages,
@@ -2176,7 +2330,7 @@ export function registerRuntimeDataLane(tools) {
2176
2330
  size: page.size ?? args.size ?? 20,
2177
2331
  ...(pageOutOfRange ? { pageOutOfRange: true, emptyPage: true, hint: `page 从 0 开始,当前传了 ${requestedPage};合法范围 0..${Math.max(0, totalPages - 1)}。` } : {}),
2178
2332
  // r29b F8 的 ids/itemsPreview 由 compact(外置时)现算,见 dataListCompactProjection。
2179
- items,
2333
+ items: itemsFinal,
2180
2334
  };
2181
2335
  // r29b F8: ids/itemsPreview 已在同信封;artifact 提示由 compact 外置后的
2182
2336
  // fetch/detailArtifactId 承担。这里不改既有 projectionHint 主句(契约测试
@@ -3074,9 +3228,12 @@ export function registerRuntimeDataLane(tools) {
3074
3228
  let sequenceStatus = null;
3075
3229
  readbackData = (await wireCall(session, { path: ENDPOINTS.runtimeFormLoad, query: { schemaCode: args.schemaCode, sheetCode, objectId: returnedId } })).data;
3076
3230
  sequenceStatus = extractSequenceStatus((readbackData ?? {}));
3231
+ // F4(w53):本次 formData 真带子表数组时才读子表字段元数据;无数组/读不到
3232
+ // 元数据 → 零提示(读失败不阻断写)。
3233
+ const mappingRuntimeNote = mappingRuntimeNoteFor(await childTableMappingHits(session, formData, prepared.childCodes));
3077
3234
  return {
3078
3235
  performed: { errcode: performed.errcode, ...application, bizObjectId: returnedId, workflowInstanceId, workItemId, workItemSource, sheetCode, resolvedFrom, formType: "save-draft-workflow" },
3079
- readback: { ...application, ...writeDiagnostics, authoritative: projectReadbackRecord(normalizeLoadedRecord((readbackData ?? {})), args), sequenceStatus, expectedSequenceStatus: "DRAFT" },
3236
+ readback: { ...application, ...writeDiagnostics, ...(mappingRuntimeNote !== undefined ? { mappingRuntimeNote } : {}), authoritative: projectReadbackRecord(normalizeLoadedRecord((readbackData ?? {})), args), sequenceStatus, expectedSequenceStatus: "DRAFT" },
3080
3237
  };
3081
3238
  }
3082
3239
  // 券商 issue 1.3(cpdocs 2026-10-27):带 formData.id 的 save 是更新语义;
@@ -3129,9 +3286,13 @@ export function registerRuntimeDataLane(tools) {
3129
3286
  const workflowDraftHint = publishedWorkflow
3130
3287
  ? `本模型有已发布流程 ${publishedWorkflow},不能用 submit:true 一调完成态;要走三段:① data.save {schemaCode:"${args.schemaCode}", workflowCode:"${publishedWorkflow}", formData:{...}} 新建流程草稿 → ② 从回执 performed 取 bizObjectId / workItemId / workflowInstanceId → ③ data.submit {schemaCode:"${args.schemaCode}", bizObjectId:"<bizObjectId>", workItemId:"<workItemId>", workflowInstanceId:"<workflowInstanceId>"} 提交起始待办(后续审批用 workitem 面;不保证立即完成态);本次无实例草稿不能原地起流程`
3131
3288
  : null;
3289
+ // F4(w53):仅在本次 formData 含子表数组时读该子表字段元数据;没有数组 /
3290
+ // 读不到元数据 → 零提示、零额外 wire(读失败不阻断写)。
3291
+ const mappingRuntimeNote = mappingRuntimeNoteFor(await childTableMappingHits(session, formData, prepared.childCodes));
3132
3292
  const plainReadback = {
3133
3293
  ...application,
3134
3294
  ...writeDiagnostics,
3295
+ ...(mappingRuntimeNote !== undefined ? { mappingRuntimeNote } : {}),
3135
3296
  authoritative: projectReadbackRecord(savedRecord, args),
3136
3297
  ...(savedEmptyFields.length > 0 ? { readbackWarning: readbackWarningFor(savedEmptyFields, "data.save") } : {}),
3137
3298
  ...(dataWarnings.length > 0 ? { warnings: dataWarnings } : {}),
@@ -3458,13 +3619,15 @@ export function registerRuntimeDataLane(tools) {
3458
3619
  : undefined;
3459
3620
  // `deleted`/`count` ride `readback` — the write envelope surfaces only
3460
3621
  // performed/readback inline (extra top-level keys are artifact-only).
3461
- // `present:false` downgrades deliveryState to WRITE_UNVERIFIED in the
3462
- // shared write pipeline, so an ineffective batch is never DELIVERED.
3622
+ // F10(w53,2026-11-26):不再回 `present`——它和 `absent` 是同一条判据
3623
+ // (batchDeleteIneffective===undefined),真机出现过 present:true+absent:true
3624
+ // 并列,读者只能二选一猜。成功判据保持 absent/deleted[].absent/
3625
+ // deletionVerified/undeletedIds;「整表是否还在」看 modelRowsRemaining/modelClean
3626
+ // (失败时 absent:false 仍由共享写门降级 WRITE_UNVERIFIED)。
3463
3627
  const residue = await remainingRows(session, args.schemaCode, sheetCode);
3464
3628
  return {
3465
3629
  performed: { sheetCode, resolvedFrom },
3466
3630
  readback: {
3467
- present: batchDeleteIneffective === undefined,
3468
3631
  absent: batchDeleteIneffective === undefined && deleted.every((entry) => entry.absent === true),
3469
3632
  count: deleted.length,
3470
3633
  deletedCount,
@@ -3338,8 +3338,21 @@ export function registerWorkflowLane(tools) {
3338
3338
  // 1 次 get(本模型通常 1-3 个视图)。
3339
3339
  const addBindings = await listviewAddBindings(session, args.schemaCode, args.code);
3340
3340
  const firstPublish = Number(data.workflowVersion) === 1;
3341
+ const firstBoundView = addBindings.bound[0];
3342
+ // Same query/get response as the binding scan — no extra wire round-trip.
3343
+ // The unbind recipe mirrors workflow.delete's 303024 recovery (live-proven:
3344
+ // empty actions + replaceActions:true).
3345
+ const unbindCommand = firstBoundView === undefined
3346
+ ? undefined
3347
+ : `omc call listview.configure --env <env> --args '${JSON.stringify({
3348
+ schemaCode: args.schemaCode,
3349
+ code: firstBoundView.code,
3350
+ fieldCodes: firstBoundView.fieldCodes.length > 0 ? firstBoundView.fieldCodes : ["createdTime", "creater", "name", "sequenceNo"],
3351
+ actions: [],
3352
+ replaceActions: true,
3353
+ })}'`;
3341
3354
  const listviewBinding = {
3342
- bound: addBindings.bound,
3355
+ bound: addBindings.bound.map(({ code, actionCode }) => ({ code, actionCode })),
3343
3356
  ...(firstPublish ? {} : { firstPublish: false }),
3344
3357
  note: addBindings.bound.length > 0
3345
3358
  ? firstPublish
@@ -3348,6 +3361,12 @@ export function registerWorkflowLane(tools) {
3348
3361
  : addBindings.readable
3349
3362
  ? "无隐式绑定"
3350
3363
  : "列表视图读取失败,未能确认 add 绑定;删流程前先 listview.get 复核",
3364
+ ...(addBindings.bound.length > 0
3365
+ ? {
3366
+ beforeWorkflowDelete: "删流程前先解绑:用 listview.configure 清掉该视图 add 动作(actions:[] + replaceActions:true),否则 workflow.delete 会撞 workflow-bound-to-listview(303024,列表还绑着流程);多个视图绑定时逐视图处理。",
3367
+ ...(unbindCommand !== undefined ? { unbindCommand } : {}),
3368
+ }
3369
+ : {}),
3351
3370
  };
3352
3371
  return { performed: { errcode: performed.errcode }, readback: { workflowCode: args.code, published: isPublished, workflowVersion: data.workflowVersion ?? null, listviewBinding, ...(strippedEmptyConditionGroups > 0 ? { strippedEmptyConditionGroups, strippedEmptyConditionGroupsNote: "调用方连线里有 N 条带平台存量写法 ruleConditionGroup:[](=无条件);工具写前已剥离该键,未上送" } : {}), ...(warnings.length ? { warnings } : {}), ...(participantWarnings.length ? { participantWarnings } : {}), ...(rejectWarnings.length || originatorWarnings.length ? { workflowWarnings: [...rejectWarnings, ...originatorWarnings] } : {}), workflowRenderCompat: workflowRenderCompat(data) } };
3353
3372
  },
@@ -3824,8 +3843,114 @@ export function registerWorkflowLane(tools) {
3824
3843
  lane: WORKFLOW_LANE,
3825
3844
  scope: WORKFLOW_TOOLS["workflow.delete"].scope,
3826
3845
  description: WORKFLOW_TOOLS["workflow.delete"].description,
3827
- inputSchema: { schemaCode: z.string().min(1), code: z.string().min(1).describe("流程编码——本参数名是 code") },
3846
+ inputSchema: {
3847
+ schemaCode: z.string().min(1),
3848
+ code: z.string().min(1).describe("流程编码——本参数名是 code"),
3849
+ unbindListviews: z
3850
+ .boolean()
3851
+ .optional()
3852
+ .describe("先解绑列表视图再删流程:true 时对本模型每个绑定了本流程的列表视图执行 listview.configure(actions:[] + replaceActions:true,保留原列 fieldCodes),成功后才删流程;任一步解绑失败即停、不删流程。**会改动视图配置(移除该视图 add 动作的平台关联),必须显式确认才做。** 默认 false 只删流程,遇 303024 仍拒绝并给 nextCommand"),
3853
+ },
3854
+ // F7(0.8.8):dry-run 与真写共用同一份只读扫描——预览列出会被解绑的视图,
3855
+ // 真写在任何写 wire 之前也先跑这里。两者都不写。
3856
+ writeLint: async (session, args) => {
3857
+ if (args.unbindListviews !== true) {
3858
+ return {
3859
+ wouldChange: true,
3860
+ summary: `即将删除流程 ${args.code}(未请求解绑列表视图)`,
3861
+ listviewUnbind: {
3862
+ requested: false,
3863
+ note: "未传 unbindListviews;不改任何视图配置。若平台回 303024,重发时带 unbindListviews:true 让本工具先解绑。",
3864
+ },
3865
+ };
3866
+ }
3867
+ const scan = await scanListviewsBoundToWorkflow(session, args.schemaCode, args.code);
3868
+ return {
3869
+ wouldChange: true,
3870
+ summary: scan.bound.length > 0
3871
+ ? `先解绑 ${scan.bound.length} 个列表视图,再删除流程 ${args.code}`
3872
+ : `未发现绑定本流程的列表视图;将直接删除流程 ${args.code}`,
3873
+ listviewUnbind: {
3874
+ requested: true,
3875
+ readable: scan.readable,
3876
+ ...(scan.bound.length > 0
3877
+ ? {
3878
+ views: scan.bound.map(({ code, name, fieldCodes }) => ({
3879
+ code,
3880
+ name,
3881
+ ...(fieldCodes.length > 0 ? { fieldCodes } : {}),
3882
+ action: "listview.configure actions:[] + replaceActions:true",
3883
+ })),
3884
+ }
3885
+ : {}),
3886
+ ...(scan.unreadableViews.length > 0 ? { unreadableViews: scan.unreadableViews } : {}),
3887
+ then: "workflow.delete",
3888
+ ...(scan.readable
3889
+ ? {}
3890
+ : { note: "视图清单读取失败:真写仍会先读;读不到绑定时只删流程,平台 303024 会挡住,不误放行。" }),
3891
+ },
3892
+ };
3893
+ },
3828
3894
  execute: async (session, args) => {
3895
+ const steps = [];
3896
+ // Opt-in unbind (F7): the workflow.publish side effect binds every list
3897
+ // view's `add` action to this workflow, and workflow.delete then answers
3898
+ // 303024 until those associations are gone. Unbind FIRST, and stop
3899
+ // before the delete if any view cannot be cleared (never half-delete).
3900
+ if (args.unbindListviews === true) {
3901
+ const scan = await scanListviewsBoundToWorkflow(session, args.schemaCode, args.code);
3902
+ const configure = siblings.find((tool) => tool.name === "listview.configure");
3903
+ if (scan.bound.length > 0 && configure?.writeExecute === undefined)
3904
+ throw new ToolRefusalError({
3905
+ status: "refused",
3906
+ blocker: "workflow-unbind-step-unavailable",
3907
+ workflowCode: args.code,
3908
+ message: "workflow.delete 需要 listview.configure 来解绑视图,但它未注册写执行;零写入停止",
3909
+ });
3910
+ for (const view of scan.bound) {
3911
+ const fieldCodes = view.fieldCodes.length > 0 ? view.fieldCodes : ["createdTime", "creater", "name", "sequenceNo"];
3912
+ try {
3913
+ const outcome = await configure.writeExecute(session, {
3914
+ schemaCode: args.schemaCode,
3915
+ code: view.code,
3916
+ fieldCodes,
3917
+ actions: [],
3918
+ replaceActions: true,
3919
+ });
3920
+ if ("status" in outcome)
3921
+ throw new ToolRefusalError({
3922
+ status: "refused",
3923
+ blocker: "workflow-unbind-step-stopped",
3924
+ workflowCode: args.code,
3925
+ viewCode: view.code,
3926
+ message: `解绑视图 ${view.code} 中途停止(${String(outcome.envelope?.message ?? outcome.status)})`,
3927
+ });
3928
+ steps.push({
3929
+ step: "listview.configure",
3930
+ status: "ok",
3931
+ viewCode: view.code,
3932
+ viewName: view.name,
3933
+ actions: "cleared",
3934
+ replaceActions: true,
3935
+ readback: outcome.readback,
3936
+ });
3937
+ }
3938
+ catch (error) {
3939
+ const cause = error instanceof Error ? error.message : String(error);
3940
+ throw new ToolRefusalError({
3941
+ status: "refused",
3942
+ blocker: "workflow-unbind-failed",
3943
+ workflowCode: args.code,
3944
+ schemaCode: args.schemaCode,
3945
+ viewCode: view.code,
3946
+ steps,
3947
+ nextCommand: `omc call listview.configure --env <env> --args '${JSON.stringify({ schemaCode: args.schemaCode, code: view.code, fieldCodes, actions: [], replaceActions: true })}'`,
3948
+ message: `解绑列表视图 ${view.code} 失败,已停止:**流程 ${args.code} 未删除**(不半删)。原因:${cause}。` +
3949
+ `按 nextCommand 修好该视图后重发 workflow.delete(仍带 unbindListviews:true);已成功解绑的视图在 steps 里。`,
3950
+ });
3951
+ }
3952
+ }
3953
+ }
3829
3954
  let performed;
3830
3955
  try {
3831
3956
  performed = await wireCall(session, { path: ENDPOINTS.workflowDelete, method: "POST", query: { workflowCode: args.code } });
@@ -3890,13 +4015,35 @@ export function registerWorkflowLane(tools) {
3890
4015
  ? `绑在:${bound.map((view) => `${view.code}(${view.name})action=${view.actionCode ?? "?"}`).join("、")}。`
3891
4016
  : `默认视图多半是 ${args.schemaCode}(workflow.create 会自动绑)。`) +
3892
4017
  `先解绑再删:粘贴 nextCommand(listview.configure:actions:[] + replaceActions:true + 现有 fieldCodes),再重试 workflow.delete。` +
4018
+ (args.unbindListviews === true
4019
+ ? `本次已带 unbindListviews:true,但仍有绑定未被清掉(见 boundListviews / unreadableViews);按 nextCommand 处理后重试。`
4020
+ : `也可以重发 workflow.delete 并带 unbindListviews:true,让本工具先逐个视图解绑再删。`) +
3893
4021
  `整体清理也可用 omc model-purge --code ${args.schemaCode}(级联带走流程模板与视图)。`,
3894
4022
  });
3895
4023
  }
3896
4024
  throw error;
3897
4025
  }
3898
4026
  const header = await wireCall(session, { path: ENDPOINTS.workflowGetHeader, query: { workflowCode: args.code } }).catch(() => ({ data: null }));
3899
- return { performed: { errcode: performed.errcode }, readback: { workflowCode: args.code, absent: header.data === null || header.data === undefined } };
4027
+ const absent = header.data === null || header.data === undefined;
4028
+ if (args.unbindListviews === true) {
4029
+ steps.push({ step: "workflow.delete", status: "ok", workflowCode: args.code, errcode: performed.errcode, absent });
4030
+ }
4031
+ return {
4032
+ performed: { errcode: performed.errcode },
4033
+ readback: {
4034
+ workflowCode: args.code,
4035
+ absent,
4036
+ ...(args.unbindListviews === true
4037
+ ? {
4038
+ listviewUnbind: {
4039
+ requested: true,
4040
+ unboundViews: steps.filter((step) => step.step === "listview.configure").map((step) => step.viewCode),
4041
+ },
4042
+ }
4043
+ : {}),
4044
+ },
4045
+ ...(steps.length > 0 ? { steps } : {}),
4046
+ };
3900
4047
  },
3901
4048
  rollback: workflowRollbackSpec("workflow.delete"),
3902
4049
  });
@@ -4291,8 +4438,14 @@ export function registerWorkflowLane(tools) {
4291
4438
  String(association ?? "").toUpperCase() === "WORKFLOW";
4292
4439
  return isWorkflow && (associationCode === workflowCode || associationCode === "");
4293
4440
  });
4294
- if (hit)
4295
- bound.push({ code, actionCode: "add" });
4441
+ if (hit) {
4442
+ // Reuse the SAME query/get response for the unbind command's
4443
+ // fieldCodes — no extra wire round-trip at publish time.
4444
+ const fieldCodes = (model !== null && Array.isArray(model.queryColumns) ? model.queryColumns : [])
4445
+ .map((column) => String(column.propertyCode ?? ""))
4446
+ .filter((column) => column.length > 0);
4447
+ bound.push({ code, actionCode: "add", fieldCodes });
4448
+ }
4296
4449
  }
4297
4450
  catch {
4298
4451
  readable = false;
@@ -4304,53 +4457,68 @@ export function registerWorkflowLane(tools) {
4304
4457
  }
4305
4458
  return { bound, readable };
4306
4459
  }
4307
- /** Best-effort: which list views still bind this workflow (303024 recovery). */
4308
- async function findListviewsBoundToWorkflow(session, schemaCode, workflowCode) {
4460
+ /**
4461
+ * Which list views bind this workflow, plus whether the READ succeeded.
4462
+ * `readable:false` means "could not list views" (NOT "none bound") — callers
4463
+ * must fail open to the platform's 303024 rather than deleting blind
4464
+ * (F7 0.8.8). Bindings are only ever created on the `add` action by
4465
+ * workflow.publish → updateBizQueryAddAction (8.6.26
4466
+ * WorkflowTemplateController.java:791,818-846; 2.1.5 :695-711,741-761).
4467
+ */
4468
+ async function scanListviewsBoundToWorkflow(session, schemaCode, workflowCode) {
4309
4469
  const bound = [];
4470
+ const unreadableViews = [];
4471
+ let listed;
4310
4472
  try {
4311
- const listed = wireRows((await wireCall(session, { path: ENDPOINTS.listQueryList, query: { schemaCode, clientType: "PC" } })).data);
4312
- for (const row of listed) {
4313
- const code = String(row.code ?? "");
4314
- if (!code)
4473
+ listed = wireRows((await wireCall(session, { path: ENDPOINTS.listQueryList, query: { schemaCode, clientType: "PC" } })).data);
4474
+ }
4475
+ catch {
4476
+ return { bound, readable: false, unreadableViews };
4477
+ }
4478
+ for (const row of listed) {
4479
+ const code = String(row.code ?? "");
4480
+ if (!code)
4481
+ continue;
4482
+ try {
4483
+ const got = await wireCall(session, { path: ENDPOINTS.listQueryGet, query: { schemaCode, code, clientType: "PC" } });
4484
+ const model = (got.data ?? null);
4485
+ if (!model)
4315
4486
  continue;
4316
- try {
4317
- const got = await wireCall(session, { path: ENDPOINTS.listQueryGet, query: { schemaCode, code, clientType: "PC" } });
4318
- const model = (got.data ?? null);
4319
- if (!model)
4487
+ const actions = Array.isArray(model.queryActions) ? model.queryActions : [];
4488
+ const fieldCodes = (Array.isArray(model.queryColumns) ? model.queryColumns : [])
4489
+ .map((column) => String(column.propertyCode ?? ""))
4490
+ .filter(Boolean);
4491
+ for (const action of actions) {
4492
+ const association = action.associationType ?? action.queryActionRelativeType;
4493
+ const associationCode = String(action.associationCode ?? action.relativeCode ?? "");
4494
+ const isWorkflow = association === 1 ||
4495
+ association === "1" ||
4496
+ association === "WORKFLOW" ||
4497
+ String(association).toUpperCase() === "WORKFLOW";
4498
+ if (!isWorkflow)
4320
4499
  continue;
4321
- const actions = Array.isArray(model.queryActions) ? model.queryActions : [];
4322
- const fieldCodes = (Array.isArray(model.queryColumns) ? model.queryColumns : [])
4323
- .map((column) => String(column.propertyCode ?? ""))
4324
- .filter(Boolean);
4325
- for (const action of actions) {
4326
- const association = action.associationType ?? action.queryActionRelativeType;
4327
- const associationCode = String(action.associationCode ?? action.relativeCode ?? "");
4328
- const isWorkflow = association === 1 ||
4329
- association === "1" ||
4330
- association === "WORKFLOW" ||
4331
- String(association).toUpperCase() === "WORKFLOW";
4332
- if (!isWorkflow)
4333
- continue;
4334
- if (associationCode && associationCode !== workflowCode && associationCode !== schemaCode)
4335
- continue;
4336
- bound.push({
4337
- code,
4338
- name: String(row.name ?? model.name ?? code),
4339
- actionCode: action.actionCode === undefined || action.actionCode === null ? null : String(action.actionCode),
4340
- associationCode: associationCode || null,
4341
- fieldCodes,
4342
- });
4343
- }
4344
- }
4345
- catch {
4346
- // one view unreadable — keep scanning
4500
+ if (associationCode && associationCode !== workflowCode && associationCode !== schemaCode)
4501
+ continue;
4502
+ bound.push({
4503
+ code,
4504
+ name: String(row.name ?? model.name ?? code),
4505
+ actionCode: action.actionCode === undefined || action.actionCode === null ? null : String(action.actionCode),
4506
+ associationCode: associationCode || null,
4507
+ fieldCodes,
4508
+ });
4347
4509
  }
4348
4510
  }
4511
+ catch {
4512
+ // one view unreadable — keep scanning, but remember it: it may still
4513
+ // carry the binding, so an opted-in delete must not claim "clean".
4514
+ unreadableViews.push(code);
4515
+ }
4349
4516
  }
4350
- catch {
4351
- // list unreadable — caller still gets a generic detach recipe
4352
- }
4353
- return bound;
4517
+ return { bound, readable: true, unreadableViews };
4518
+ }
4519
+ /** Best-effort: which list views still bind this workflow (303024 recovery). */
4520
+ async function findListviewsBoundToWorkflow(session, schemaCode, workflowCode) {
4521
+ return (await scanListviewsBoundToWorkflow(session, schemaCode, workflowCode)).bound;
4354
4522
  }
4355
4523
  // `list_permission` echoes the PERMISSION row id plus the unit's display name
4356
4524
  // and code — never the unitId (WorkflowTemplateController.getPermissionMap).