@stalfh233/omc-cli 0.8.6 → 0.8.7

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.
@@ -4,7 +4,7 @@ import { decodeJsonObjectColumn } from "./json-column.js";
4
4
  import { ToolRefusalError } from "./tool-types.js";
5
5
  import { FIELD_CONTROL_TYPES, childColumnsOf, SYSTEM_FIELD_CODES, fieldControlOptions, relationDisplayField, relationMappings, } from "./field-families.js";
6
6
  import { deriveControlOptions } from "./capability-shape.js";
7
- import { hardLayoutViolations, validateFormLayoutShape } from "./form-layout.js";
7
+ import { hardLayoutViolations, validateFormLayoutShape, controlTypeMismatches, FORM_CONTROL_TYPE_HINT } from "./form-layout.js";
8
8
  /**
9
9
  * Propagate each relation field's `options.mappings` into its form control so
10
10
  * the form-fill carry is configured where the form renderer reads it. The
@@ -805,6 +805,46 @@ export function assertCallerFormLayout(args) {
805
805
  });
806
806
  }
807
807
  }
808
+ export async function lintFormControlTypes(session, args) {
809
+ if (typeof args.draftAttributesJson !== "string")
810
+ return undefined;
811
+ let attributes;
812
+ try {
813
+ attributes = JSON.parse(args.draftAttributesJson);
814
+ }
815
+ catch {
816
+ return undefined; // JSON errors are the caller's layout gate's business.
817
+ }
818
+ if (!attributes || typeof attributes !== "object" || Array.isArray(attributes))
819
+ return undefined;
820
+ let rows;
821
+ try {
822
+ rows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode: args.schemaCode, isPublish: "true" } })).data);
823
+ }
824
+ catch {
825
+ // No published field face (absent schema / no fields yet): nothing to
826
+ // resolve against — do NOT guess and do NOT invent a new refusal.
827
+ return { mismatches: [], allowed: false, fieldListRead: false };
828
+ }
829
+ const mismatches = controlTypeMismatches(attributes, rows);
830
+ if (mismatches.length === 0)
831
+ return { mismatches, allowed: false, fieldListRead: true };
832
+ if (args.allowTypeMismatch === true)
833
+ return { mismatches, allowed: true, fieldListRead: true };
834
+ throw new ToolRefusalError({
835
+ status: "refused",
836
+ blocker: "form-control-type-mismatch",
837
+ schemaCode: args.schemaCode,
838
+ sheetCode: args.sheetCode,
839
+ mismatches,
840
+ hint: FORM_CONTROL_TYPE_HINT,
841
+ nextCommand: `omc call form.get --args '${JSON.stringify({ schemaCode: args.schemaCode, full: true })}'`,
842
+ message: `控件 type 用错了枚举:${mismatches.map((item) => `${item.code} 给了 ${item.givenType},按字段 ${item.fieldTypeName}(propertyType=${item.propertyType}) 应为 ${item.expectedType}`).join(";")}。` +
843
+ `${FORM_CONTROL_TYPE_HINT}改既有表单必须先 ` +
844
+ `\`form.get full:true\` 取 publishedAttributesJson 作基线(只改 rows/span,不手拼控件 type);` +
845
+ `确属平台模板要求的特殊控件才传 allowTypeMismatch:true。`,
846
+ });
847
+ }
808
848
  /** Ticket 74 — control count on an attributes JSON face (0 when unparsable/absent). */
809
849
  function controlCount(face) {
810
850
  if (typeof face !== "string")
@@ -1480,6 +1520,23 @@ export async function executeFormDraftWrite(session, args) {
1480
1520
  : `fieldCodes 引用了模型 ${args.schemaCode} 发布面上不存在的字段:${selectionUnknown.join("、")};先 field.create + field.publish 这些字段,或修正 fieldCodes`,
1481
1521
  });
1482
1522
  }
1523
+ // 控件 type 是**表单控件枚举**(BizFormPropertyType),不是字段 propertyType
1524
+ // (probe B F1,2.1.5 真机:已发布 customer=80 而字段 WORK_SHEET=9)。这条
1525
+ // 交叉校验放在创建/写入任何 wire 之前:错枚举的布局平台照存、回读不报错,
1526
+ // 只有渲染时才坏。`fromReadback:true` 是逐字回写平台面、`amendChildColumns`
1527
+ // 是工具从已存平台布局追加子表列——两者都不是手写布局,跳过;调用方显式
1528
+ // allowTypeMismatch:true 时降级为回执 warning(不偷偷改用户输入)。
1529
+ let controlTypeWarnings;
1530
+ if (args.draftAttributesJson !== undefined && args.fromReadback !== true && args.amendChildColumns !== true) {
1531
+ const typeLint = await lintFormControlTypes(session, {
1532
+ schemaCode: args.schemaCode,
1533
+ sheetCode: args.sheetCode,
1534
+ draftAttributesJson: args.draftAttributesJson,
1535
+ ...(args.allowTypeMismatch !== undefined ? { allowTypeMismatch: args.allowTypeMismatch } : {}),
1536
+ });
1537
+ if (typeLint !== undefined && typeLint.mismatches.length > 0)
1538
+ controlTypeWarnings = typeLint.mismatches;
1539
+ }
1483
1540
  // The default form may not exist yet on a freshly created model
1484
1541
  // (bizmodels/create seeds no form) — create it, then scaffold into it.
1485
1542
  let pre = await readFormOrNull(session, args.schemaCode, args.sheetCode);
@@ -1774,6 +1831,13 @@ export async function executeFormDraftWrite(session, args) {
1774
1831
  // stored column is the stringified form the form page refuses to render.
1775
1832
  ...(customButtonJsonStoredShape(sheet.options) === "string" ? { formButtonsShapeWarning: CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING } : {}),
1776
1833
  ...(mergedOptions !== undefined ? { customButtonJsonWritten: true } : {}),
1834
+ ...(controlTypeWarnings !== undefined
1835
+ ? {
1836
+ controlTypeMismatchAllowed: true,
1837
+ controlTypeMismatches: controlTypeWarnings,
1838
+ controlTypeNote: `allowTypeMismatch:true 显式放行;${FORM_CONTROL_TYPE_HINT}本工具不替你改控件 type。`,
1839
+ }
1840
+ : {}),
1777
1841
  ...(roundTripFaces.size > 0
1778
1842
  ? {
1779
1843
  layoutGate: "platform-roundtrip",
package/dist/graph.js CHANGED
@@ -1262,6 +1262,28 @@ function openGraphIndex(selector = {}) {
1262
1262
  throw error instanceof GraphIndexError ? error : new GraphIndexUnreadableError(`索引不可读(schema 不匹配或文件损坏):${error instanceof Error ? error.message : String(error)};重跑 omc graph pull`);
1263
1263
  }
1264
1264
  }
1265
+ /**
1266
+ * issue 07(2026-11-18 真机摩擦)CLI 面补齐:零命中 ≠ 无引用。
1267
+ *
1268
+ * 索引只到服务 code,业务规则里的 `methodMapping.serviceMethodCode`
1269
+ *(`addOrderLedger` 之流)不建边——探针曾据 `matches:[]` 差点判「没人调用、可删」。
1270
+ * MCP 面已在 `src/mcp-graph.ts:502` 给出 `granularityUnsupported`;本函数是 CLI
1271
+ * 面(references / impact)的**同源**构造:文案直接取自
1272
+ * `GRAPH_NOT_INDEXED_GRANULARITIES` 的 `service.method` 条目,不另起一套措辞。
1273
+ *
1274
+ * 只在 `kind === "service"` 时返回;调用方再叠加「零命中」条件,有命中时不出
1275
+ *(不给正常答案加噪声)。
1276
+ */
1277
+ export function serviceMethodGranularityUnsupported(kind) {
1278
+ if (kind !== "service")
1279
+ return undefined;
1280
+ const methodGranularity = GRAPH_NOT_INDEXED_GRANULARITIES.find((item) => item.face === "service.method");
1281
+ return {
1282
+ methodLevelIndexed: false,
1283
+ reason: `0 ≠ 无引用:${methodGranularity?.zh ?? "索引不覆盖服务方法级(methodMapping.serviceMethodCode)"}`,
1284
+ suggestion: methodGranularity?.how ?? "先 omc call rule.list 拿规则清单,再逐条 omc call rule.get 查 methodMapping.serviceMethodCode",
1285
+ };
1286
+ }
1265
1287
  export const GRAPH_NOT_INDEXED_GRANULARITIES = Object.freeze([
1266
1288
  Object.freeze({
1267
1289
  face: "service.method",
@@ -1534,6 +1556,8 @@ export function queryGraphReferences(kind, rawCode, selector = {}) {
1534
1556
  const unscopedFieldNote = kind === "field" && scoped === null && otherSchemas.length > 0
1535
1557
  ? `裸字段 code 会跨模型合并同名:本次命中来自 ${otherSchemas.join("、")}(各自的同名字段)。要只查某一个模型的该字段,写 <schemaCode>.<字段code>(如 crm_contract.${code})——datarule/listview 只能引用本模型字段,所以按宿主模型过滤是精确的。`
1536
1558
  : undefined;
1559
+ // issue 07(CLI 面):只在 service 零命中时出现(有命中 / 非 service 都不加)。
1560
+ const granularityUnsupported = matches.length === 0 ? serviceMethodGranularityUnsupported(kind) : undefined;
1537
1561
  return {
1538
1562
  kind,
1539
1563
  code: rawCode,
@@ -1544,13 +1568,17 @@ export function queryGraphReferences(kind, rawCode, selector = {}) {
1544
1568
  index: summary,
1545
1569
  ...(matches.length === 0
1546
1570
  ? {
1571
+ // issue 07(CLI 面):零命中≠无引用。service 方法级未索引,note 不再给
1572
+ // 「没有引用它」这种结论句;粒度边界由 granularityUnsupported 承接。
1547
1573
  note: (gapped
1548
1574
  ? "零命中,但索引存在扫描缺口——不可作为「无引用」证明;先 omc graph pull 重建再查"
1549
- : `零命中=scanned 面(规则/数据规则/视图/表单/流程)没有引用它;本索引覆盖应用:${summary.coverage.applicationCodes.join("、") || "(未知)"},不代表其他应用没有引用;workflow.bindings 与 onlinejs 未扫描,见 coverage.notScanned——不可据此判定可安全删除`) +
1575
+ : `零命中=scanned 面(规则/数据规则/视图/表单/流程)零命中;本索引覆盖应用:${summary.coverage.applicationCodes.join("、") || "(未知)"},不代表其他应用没有引用;workflow.bindings 与 onlinejs 未扫描,见 coverage.notScanned——不可据此判定可安全删除`) +
1576
+ (kind === "service" ? ";service 方法级未索引,见 granularityUnsupported" : "") +
1550
1577
  (zeroHitKindHint(db, kind, code, "references") ?? "") +
1551
1578
  (kind === "field" && scoped === null ? unresolvedScopedCodeNote(rawCode) ?? "" : ""),
1552
1579
  }
1553
1580
  : {}),
1581
+ ...(granularityUnsupported !== undefined ? { granularityUnsupported } : {}),
1554
1582
  ...(gapped
1555
1583
  ? { gapWarning: `索引有 ${summary.gaps.count} 个扫描缺口(${Object.entries(summary.gaps.byKind).map(([k, v]) => `${k}:${v}`).join(", ")});命中列表可能不完整` }
1556
1584
  : {}),
@@ -1809,6 +1837,9 @@ export function impactGraph(kind, rawCode, selector = {}) {
1809
1837
  return { schemaCode: row.schema_code, ruleCode: row.rule_code, name, matchedVia: via, touches };
1810
1838
  });
1811
1839
  const gapped = summary.gaps.count > 0;
1840
+ const zeroHit = hop1.length === 0 && dataruleHits.length === 0 && listViewHits.length === 0 && workflowHits.length === 0 && formHits.length === 0;
1841
+ // issue 07(CLI 面):只在 service 零命中时出现(有命中 / 非 service 都不加)。
1842
+ const granularityUnsupported = zeroHit ? serviceMethodGranularityUnsupported(kind) : undefined;
1812
1843
  return {
1813
1844
  kind,
1814
1845
  code: rawCode,
@@ -1821,15 +1852,19 @@ export function impactGraph(kind, rawCode, selector = {}) {
1821
1852
  index: summary,
1822
1853
  coverage: GRAPH_COVERAGE,
1823
1854
  ...(scoped !== null ? { resolvedScope: { schemaCode: scoped.schemaCode, code: scoped.code } } : {}),
1824
- ...(hop1.length === 0 && dataruleHits.length === 0 && listViewHits.length === 0 && workflowHits.length === 0 && formHits.length === 0
1855
+ ...(zeroHit
1825
1856
  ? {
1857
+ // issue 07(CLI 面):零命中≠无影响。service 方法级未索引,note 不再给
1858
+ // 「没有影响」这种结论句;粒度边界由 granularityUnsupported 承接。
1826
1859
  note: (gapped
1827
1860
  ? "零命中,但索引存在扫描缺口——不可作为「无影响」证明;先 omc graph pull 重建再查"
1828
- : "零命中=scanned 面(规则/数据规则/视图/表单/流程)没有影响;workflow.bindings 与 onlinejs 未扫描,见 coverage.notScanned——不可据此判定「删除无影响」") +
1861
+ : "零命中=scanned 面(规则/数据规则/视图/表单/流程)零命中;workflow.bindings 与 onlinejs 未扫描,见 coverage.notScanned——不可据此判定「删除无影响」") +
1862
+ (kind === "service" ? ";service 方法级未索引,见 granularityUnsupported" : "") +
1829
1863
  (zeroHitKindHint(db, kind, code, "impact") ?? "") +
1830
1864
  (kind === "field" && scoped === null ? unresolvedScopedCodeNote(rawCode) ?? "" : ""),
1831
1865
  }
1832
1866
  : {}),
1867
+ ...(granularityUnsupported !== undefined ? { granularityUnsupported } : {}),
1833
1868
  ...(capped || dataruleHits.length > 20 || listViewHits.length > 20 || workflowHits.length > 20 || formHits.length > 20
1834
1869
  ? { truncated: true, note: `命中超过上限已截断(规则 50/实际 ${hop1.length},数据规则 20/实际 ${dataruleHits.length},视图 20/实际 ${listViewHits.length},流程 20/实际 ${workflowHits.length},表单 20/实际 ${formHits.length});完整规则清单用 references` }
1835
1870
  : {}),
@@ -106,10 +106,20 @@ export function writeSummary(tool, args, outcome, phase = "done") {
106
106
  // F7(0.8.6):physically_delete 是平台异步任务(建删除历史后立即返回)。回执
107
107
  // `readback.absent=false` 表示级联仍在跑、记录面还查得到目标——zh 行首词必须是
108
108
  // 否定,照 data.delete 的既有先例;否则人/CI 把「已删除模型 X」当成已生效。
109
+ if (phase === "done" && tool === "model.delete" && outcome?.readback?.deleteTask?.taskStatus === "FAIL") {
110
+ const code = stringArg(args, "schemaCode") ?? stringArg(args, "code") ?? "?";
111
+ const message = (outcome?.readback?.deleteTask).message;
112
+ const waited = (outcome?.readback?.deleteTask).waitedMs;
113
+ return `未删除(平台删除任务失败)模型 ${code}:${typeof message === "string" && message.length > 0 ? message : "平台未返回 message"}${typeof waited === "number" ? `(已等 ${Math.round(waited / 1000)}s)` : ""}——这不是「级联中」,任务已以 FAIL 结束;按平台原文拆引用/清残留后重试`;
114
+ }
109
115
  if (phase === "done" && tool === "model.delete" && outcome?.readback?.absent === false) {
110
116
  const code = stringArg(args, "schemaCode") ?? stringArg(args, "code") ?? "?";
111
117
  return `未删净(级联中)模型 ${code}:平台异步删除任务未完成,记录面仍查得到——不要当作已删除;以 readback.absent=true 且应用树无该节点为准,稍后重跑 model.delete(幂等)复核`;
112
118
  }
119
+ if (phase === "done" && tool === "model.deleteMany" && outcome?.readback?.deleteTask?.taskStatus === "FAIL") {
120
+ const message = (outcome?.readback?.deleteTask).message;
121
+ return `未删除(平台删除任务失败)批量模型:${typeof message === "string" && message.length > 0 ? message : "平台未返回 message"}——任务已以 FAIL 结束,本批未删;按平台原文拆引用/清残留后重试 model.deleteMany`;
122
+ }
113
123
  if (phase === "done" && tool === "model.deleteMany" && outcome?.readback?.allAbsent === false) {
114
124
  const perCode = (outcome.readback.perCode ?? {});
115
125
  const pending = Object.entries(perCode).filter(([, value]) => value?.absent === false).map(([code]) => code);
@@ -274,7 +284,15 @@ function phraseOf(tool, args, outcome) {
274
284
  case "listview.configure": {
275
285
  const codes = Array.isArray(args.fieldCodes) ? args.fieldCodes.map(String).join("、") : "";
276
286
  const sections = ["sorts", "conditions", "actions", "buttons", "presentation", "options", "presentationType", "gantt", "queryLayer", "multiTableHeaderConfig"].filter((key) => args[key] !== undefined);
277
- return `配置列表视图 ${stringArg(args, "code") ?? schemaCode ?? "?"}(模型 ${schemaCode ?? "?"}):列 ${codes || "(未变)"}${sections.length > 0 ? `;同时配置 ${sections.join("、")}` : ""}`;
287
+ // F9(w44,2026-11-26 真机):视图固定条件只在门户运行面生效,REST 的
288
+ // data.list --queryCode 不应用。此前只有 JSON 回执尾部的
289
+ // conditionRuntimeNote/viewConditionsAppliedRest:false 说这件事,人类摘要
290
+ // 行不提,验收要读完整回执才知道。摘要行(stderr)与 plan 卡同源,这里
291
+ // 只加一句,不改 JSON 回执字段。
292
+ const conditionRuntimeLine = Array.isArray(args.conditions) && args.conditions.length > 0
293
+ ? ";视图固定条件只在门户运行面生效,REST `data.list --queryCode` 不应用——要在 API 侧过滤请显式传 `filter`"
294
+ : "";
295
+ return `配置列表视图 ${stringArg(args, "code") ?? schemaCode ?? "?"}(模型 ${schemaCode ?? "?"}):列 ${codes || "(未变)"}${sections.length > 0 ? `;同时配置 ${sections.join("、")}` : ""}${conditionRuntimeLine}`;
278
296
  }
279
297
  case "listview.delete":
280
298
  return `删除列表视图 ${stringArg(args, "code") ?? "?"}(${schemaCode ?? "?"})`;
@@ -309,6 +309,10 @@ export const FIELD_LANE_CONTRACT = Object.freeze({
309
309
  scope: "create publish readback",
310
310
  description: "List draft/published fields of a model. 默认面紧凑(整包 choices 不内联);验证 options/subSchema 用 code/fields 选择器或 full:true。",
311
311
  }),
312
+ "field.get": Object.freeze({
313
+ scope: "create publish readback",
314
+ description: "单字段读(= field.list + code 选择器,含 options/subSchema)。",
315
+ }),
312
316
  "field.create": Object.freeze({
313
317
  scope: "create publish readback",
314
318
  description: describeTool("Create a draft field on a model (bizproperty/create).", [
@@ -12,6 +12,7 @@ export const FIELD_COVERAGE = declareLaneCoverage(FIELD_LANE_CONTRACT.lane, [
12
12
  // assertToolSurfaceConsistent — exactly the duplicate that guard exists to
13
13
  // catch, so don't introduce one.
14
14
  claim("field.list", T["field.list"].scope),
15
+ claim("field.get", T["field.get"].scope),
15
16
  claim("field.create", T["field.create"].scope),
16
17
  claim("field.update", T["field.update"].scope),
17
18
  claim("field.publish", T["field.publish"].scope),
@@ -563,7 +563,7 @@ export async function lintFieldCreateWrite(session, input, options = {}) {
563
563
  return prepared;
564
564
  }
565
565
  export function registerFieldLane(tools) {
566
- tools.push(defineTool({
566
+ const fieldListTool = defineTool({
567
567
  name: "field.list",
568
568
  search: { intents: ["看字段", "查字段", "字段清单", "模型有哪些字段", "字段列表", "跳号"] },
569
569
  layer: "low",
@@ -786,7 +786,25 @@ export function registerFieldLane(tools) {
786
786
  };
787
787
  },
788
788
  }),
789
- }));
789
+ });
790
+ tools.push(fieldListTool);
791
+ // F10(0.8.7 探针 B):`field.get` 不存在时 `omc call field.get` 只回 unknown-tool
792
+ // + candidates,多一往返;单字段读的真身就是 field.list 的 code 选择器。这里
793
+ // 注册**薄别名**(同一 handler、同一栏/覆盖声明),不复制读取逻辑,也不改
794
+ // field.list 行为。
795
+ tools.push({
796
+ ...fieldListTool,
797
+ name: "field.get",
798
+ search: { intents: ["读一个字段", "单个字段", "字段详情", "这个字段配置", "字段 options", "查字段详情"] },
799
+ description: "单字段读(field.list 的 code 选择器)。返回该字段 options/subSchema 等详情。",
800
+ inputSchema: {
801
+ environment: environmentArg,
802
+ schemaCode: z.string(),
803
+ code: z.string(),
804
+ published: z.boolean().default(false),
805
+ capability: capabilityArg,
806
+ },
807
+ });
790
808
  writeTool({
791
809
  tools,
792
810
  name: "field.create",
@@ -20,7 +20,7 @@ export const FORM_WIRE = Object.freeze({
20
20
  sheetListFace: "form.list: GET /api/api/app/bizsheet/list?schemaCode= (BizFormController.java:137-152 → ModelManagementFacadeImpl.getBizForms:481-488) answers the BizFormHeaderModel HEADER projection only — code, name, schemaCode, published, formType, sortKey, icon. formType is the INTEGER index (@JsonValue getIndex(), BizFormType.java:45-48): 0 DEFAULT_SHEET / 1 CUSTOMIZE_SHEET / 2 PRINT_TEMPLATE — decoded to the name with formTypeIndex kept (ADR 0002). existDraft/buttonCount/hasCustomScript are NOT on this face, so the default read never fabricates them: detail:true pays 1+N bizsheet/get for the content-derived faces. published is the same platform flag bit (r79-04): publish→draft leaves it false while the content is intact — the flag is reported as-is, content judgement needs detail:true. HTTP 404 means the version family has no /list endpoint: the tool answers sheetListUnavailable:true + the default slot only, never a fabricated list; a 601003 业务模型不存在 refusal is modelPresent:false (zero retries)",
21
21
  });
22
22
  const FORM_GET_DESCRIPTION = '读取默认表单(bizsheet/get)的发布状态与控件清单(紧凑默认)。**发布态以返回的 `published` / `existDraft` 布尔为准**(`published:true`=已发布;`published:false,existDraft:true`=只有草稿,**未发布**)——不要用 `publishedControlCodes` 是否非空来推断(草稿字段会让它非空,误判为已发布)。**每个模型交付前其默认表单必须 `published:true`**:用 `configure_form` 或 `form.draft(rebuild:true)`+`form.publish` 发布,并逐模型 `form.get` 核对。`full:true` 还返回 `options` 与 `customButtonJson`(表单工具栏按钮,数组原样;库里是字符串脏形时附 `customButtonJsonShapeWarning`——线上 #38 前端按钮不渲染)。传 `controls:["code",…]` 只取指定控件的 options(如关联控件的 mappings);传 `full:true` 才返回 draft/published 的完整 view/attributes/html/actions JSON(actions 列为设计器保存/发布的表单级按钮动作)。体积大,仅在需要整体布局时用。';
23
- const FORM_DRAFT_DESCRIPTION = "Save the default-form DRAFT (bizsheet/update). Reads the current sheet, merges the caller's explicit draftViewJson/draftAttributesJson (or preserves the existing draft); when both are absent on a fresh default form, composes the designer-standard scaffold from the model's published fields. A redundant field (relation-mapping carry-through target) always stays bound; with no workflow it is hidden in the design (options.visible=false), with a workflow it stays visible for per-node propertyPermissions. Pass `draftHtmlJson` to thread custom online-script HTML through. Empty-layout guard: explicitly passing \"[]\"/\"{}\" view/attributes is refused (form-empty-layout) — the platform designer's Save is NOT lossless and clears drafts to exactly that shape; escape with allowEmptyLayout:true, and recover cleared drafts from the form version history (/api/api/app/bizsheet/history/list). **读回原样回写**:从 `form.get` 取回的 view/attributes 直接回传时加 `fromReadback:true`——工具会与已存草稿/发布面逐字比对,一致才放行(平台自身布局可能含子表列行/系统行默认宽度),被改动过的面照常按 validation 拒绝。**表单工具栏按钮**:`buttons`(数组)或 `customButtonJson`(原样字符串)写进 `biz_sheet.options.customButtonJson`(**数组+actionConfig 对象**,设计器同形——线上 #38:字符串形=双重编码,前端按钮不渲染,重写即自愈);**要到 form.publish 才生成 h_biz_button(triggerType=FORM)**,且表单页是否显示还取决于流程节点 `buttonPermission.customBtns[].enabled`(设计器「表单操作」勾选)。`useLocation` 用 FORM/ROW/LIST,表单工具栏按钮用 FORM。字段发布后如需刷新已发布表单的控件映射,用本工具 rebuild:false 重存(保留现有布局与在线JS)再 form.publish。";
23
+ const FORM_DRAFT_DESCRIPTION = "Save the default-form DRAFT (bizsheet/update). Reads the current sheet, merges the caller's explicit draftViewJson/draftAttributesJson (or preserves the existing draft); when both are absent on a fresh default form, composes the designer-standard scaffold from the model's published fields. A redundant field (relation-mapping carry-through target) always stays bound; with no workflow it is hidden in the design (options.visible=false), with a workflow it stays visible for per-node propertyPermissions. Pass `draftHtmlJson` to thread custom online-script HTML through. Empty-layout guard: explicitly passing \"[]\"/\"{}\" view/attributes is refused (form-empty-layout) — the platform designer's Save is NOT lossless and clears drafts to exactly that shape; escape with allowEmptyLayout:true, and recover cleared drafts from the form version history (/api/api/app/bizsheet/history/list). **读回原样回写**:从 `form.get` 取回的 view/attributes 直接回传时加 `fromReadback:true`——工具会与已存草稿/发布面逐字比对,一致才放行(平台自身布局可能含子表列行/系统行默认宽度),被改动过的面照常按 validation 拒绝。**表单工具栏按钮**:`buttons`(数组)或 `customButtonJson`(原样字符串)写进 `biz_sheet.options.customButtonJson`(**数组+actionConfig 对象**,设计器同形——线上 #38:字符串形=双重编码,前端按钮不渲染,重写即自愈);**要到 form.publish 才生成 h_biz_button(triggerType=FORM)**,且表单页是否显示还取决于流程节点 `buttonPermission.customBtns[].enabled`(设计器「表单操作」勾选)。`useLocation` 用 FORM/ROW/LIST,表单工具栏按钮用 FORM。字段发布后如需刷新已发布表单的控件映射,用本工具 rebuild:false 重存(保留现有布局与在线JS)再 form.publish。**改既有表单勿整表重写**:先 `form.get full:true` 取 `publishedAttributesJson` 作基线、只改 rows/span;只写业务字段会丢系统控件并撞 form-publish-degrade。";
24
24
  const FORM_PUBLISH_DESCRIPTION = "Publish the default form (bizsheet/publish, proven shape: draft*Json promoted to published*Json verbatim) with published-face readback. **不影响在线 JS**:本工具只提拔布局草稿;改 JS 请用 onlinejs.compose(它自己会连同整张表单一起发布,不必再调本工具)。 Degrade guard: refuses to promote a draft carrying FEWER controls than the published face (form-publish-degrade) — the designer's Save clears drafts non-losslessly; recover via the form version history (/api/api/app/bizsheet/history/list) and rewrite the draft first, or pass allowDegrade:true to force the reduction. rebuild:true is the one-call refresh: discard the existing draft, re-scaffold from the published fields (non-structural control options preserved), then force-promote — use it after a field shape change. **表单工具栏按钮**:传 `buttons`(或 `customButtonJson`)→ 写进 `options.customButtonJson` 并在本次 publish 生成 `h_biz_button(triggerType=FORM, triggerCode=<formCode>)`(平台 `publishBizForm:1022`);`options.customButtonJson` 以**数组**写入(条目 `actionConfig` 为对象,设计器同形——线上 #38:字符串形=双重编码,前端按钮不渲染,回执给 formButtonsShapeWarning);表单页是否显示再由流程节点 `buttonPermission.customBtns[].enabled` 过滤。";
25
25
  const FORM_RUN_BUTTON_DESCRIPTION = "执行表单工具栏按钮(平台同款面:`POST /api/api/runtime/form/executeCustomButton`,body `{bizButtonModel, bizObjectList:[<完整业务对象>], reacquireDataFromDb:true}`)。**与列表行按钮不同**:列表按钮发 `launcher/domain_service_runtime/<schema>/<rule>` + `ids[]`(用 `rule.run`),表单按钮带**整条记录**,不能互换。按钮来源 `GET /api/api/system/getCustomButtons`(只列 triggerType=FORM 的 h_biz_button)。前提:按钮已由 `form.publish` 的 `buttons`/`customButtonJson` 生成。返回是执行结果信封,规则副作用用 `data.load` 另读;被规则 UPDATE 的目标行须是 COMPLETED(引擎查不到 DRAFT)。`302045` = 数据被占用。**`10005` 换等价面 `rule.run`(见 contract form),勿反复重试。**";
26
26
  const CONFIGURE_FORM_DESCRIPTION = "High-level: bind fields into the default form and publish it (form.draft → form.publish), subject to the write permission gate. Delegates to the proven form.draft scaffold + form.publish paths so the real empty-form layout (and any caller-supplied draftHtmlJson) is persisted and promoted — never bypasses with a shortcut body. `sheetCode` is optional: omitted means the model's default sheet (sheetCode = schemaCode).";
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { ENDPOINTS } from "../endpoints.js";
3
3
  import { decodeButtonScript } from "./list-view.js";
4
- import { executeFormDraftWrite, executeFormPublishWrite, executeFormRunButtonWrite, lintFormPublishReadOnly, readFormButtons, readFormOrNull, refuseEmptyCallerLayout, validateHtmlRender, customButtonJsonStoredShape, CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING, FORM_FLAG_AUTHORITY_NOTE, compareFormFaces, resolveEffectiveFormFace } from "../form-support.js";
4
+ import { executeFormDraftWrite, executeFormPublishWrite, executeFormRunButtonWrite, lintFormPublishReadOnly, lintFormControlTypes, readFormButtons, readFormOrNull, refuseEmptyCallerLayout, validateHtmlRender, customButtonJsonStoredShape, CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING, FORM_FLAG_AUTHORITY_NOTE, compareFormFaces, resolveEffectiveFormFace } from "../form-support.js";
5
5
  import { capabilityArg, environmentArg } from "../args.js";
6
6
  import { governedRead } from "../read.js";
7
7
  import { writeTool } from "../write.js";
@@ -572,7 +572,8 @@ export function registerFormLane(tools) {
572
572
  schemaCode: z.string().min(1),
573
573
  sheetCode: z.string().min(1).optional().describe("表单槽位码;省略时默认 = schemaCode(模型码即默认表单槽位)"),
574
574
  draftViewJson: z.string().optional().describe("行分组:JSON 二维字符串数组 `[[\"codeA\",\"codeB\"],[\"codeC\"]]`——**一行几个 code 就是几列**(不是改 span 来改列数);末行只放一个 code 即整宽。每个 code 必须同时出现在 draftAttributesJson 里。现成样例:`omc describe form.draft --example two-column-layout`"),
575
- draftAttributesJson: z.string().optional().describe("控件表:JSON 对象 `{ \"codeA\": { key:\"codeA\", type: <控件类型号>, options:{ name:\"显示名\", span: 12 } } }`。`span` 是 24 栅格宽度:两列各 span:12、整宽 span:24(必须与 draftViewJson 的行分组一致,否则 layout_coverage_mismatch)。现成样例:`omc describe form.draft --example two-column-layout`"),
575
+ draftAttributesJson: z.string().optional().describe("控件表:JSON 对象 `{ \"codeA\": { key:\"codeA\", type: <表单控件类型号>, options:{ name:\"显示名\", span: 12 } } }`。**控件 type 是表单控件枚举,不是字段 propertyType**(80=关联单选/201=子表…);错枚举拒 `form-control-type-mismatch`。`span` 是 24 栅格宽度:两列各 span:12、整宽 span:24(须与 draftViewJson 行分组自洽)。样例:`omc describe form.draft --example two-column-layout`"),
576
+ allowTypeMismatch: z.boolean().optional().describe("放行控件 type 与字段 propertyType 不匹配(默认拒 form-control-type-mismatch;仅平台模板明确要求特殊控件时用)"),
576
577
  draftHtmlJson: z.string().optional(),
577
578
  fieldCodes: z.array(z.string().min(1)).optional().describe("脚手架绑定的已发布字段(按此顺序);由 configure_form/intent 显式传入。子表列写「父字段.子列」等价于 childColumns"),
578
579
  childColumns: z
@@ -598,6 +599,27 @@ export function registerFormLane(tools) {
598
599
  // governed pipeline — including the rollback before-capture read.
599
600
  refuseEmptyCallerLayout({ ...args, sheetCode: resolveSheetCode(args.schemaCode, args.sheetCode) });
600
601
  },
602
+ // R75-B seam: dry-run 与真写共用这一个 session 只读 lint(dry-run 直接跑它)。
603
+ // 控件 type 交叉校验需要 field.list(propertyType 是另一套枚举),纯参数门
604
+ // 拿不到;放进这里才能让 `--dry-run` 与真写同答案。executeFormDraftWrite 里
605
+ // 再跑同一函数,直调执行器的路径也绕不过去。
606
+ writeLint: async (session, args) => {
607
+ if (args.fromReadback === true)
608
+ return { controlTypeCheck: "skipped-fromReadback" };
609
+ const lint = await lintFormControlTypes(session, {
610
+ schemaCode: args.schemaCode,
611
+ sheetCode: resolveSheetCode(args.schemaCode, args.sheetCode),
612
+ ...(typeof args.draftAttributesJson === "string" ? { draftAttributesJson: args.draftAttributesJson } : {}),
613
+ ...(args.allowTypeMismatch !== undefined ? { allowTypeMismatch: args.allowTypeMismatch } : {}),
614
+ });
615
+ if (lint === undefined || lint.mismatches.length === 0)
616
+ return {};
617
+ return {
618
+ controlTypeMismatchAllowed: true,
619
+ controlTypeMismatches: lint.mismatches,
620
+ controlTypeNote: "allowTypeMismatch:true 显式放行;本工具不替你改控件 type。",
621
+ };
622
+ },
601
623
  rollback: {
602
624
  target: (args) => `form:${String(args.schemaCode ?? "")}/${String(args.sheetCode ?? args.schemaCode ?? "")}`,
603
625
  read: (session, args) => readFormOrNull(session, String(args.schemaCode), resolveSheetCode(String(args.schemaCode), args.sheetCode)),
@@ -417,6 +417,8 @@ export function listviewLastVisibleRefusal(schemaCode, code) {
417
417
  schemaCode,
418
418
  code,
419
419
  nextCommand: `omc model-purge --code ${schemaCode}`,
420
+ cleanupGuidance: `删视图在平台上不是独立清理步骤:要清视图就删模型(model-purge / model.delete 级联删除它的全部视图,含这条);` +
421
+ `listview.delete 只用于替换视图(先建/配好替代视图再删旧的),最后一条可见视图不可单删。`,
420
422
  message: `不能删除视图 ${code}:平台要求**至少保留一个 PC 可见视图和一个 MOBILE 可见视图**(PC + MOBILE 各一条,306103)。` +
421
423
  `单独删最后一条视图没有意义——删模型会级联删除它的所有视图。要继续用这个模型就**就地改**(listview.configure 省略 code 即改默认视图),` +
422
424
  `要整体清理就用 model-purge(默认 dry-run,先看计划)。`,
@@ -0,0 +1,172 @@
1
+ import { ENDPOINTS } from "../endpoints.js";
2
+ import { relationTargetOf } from "../field-families.js";
3
+ import { wireCall, wireRows } from "../wire.js";
4
+ const WORK_SHEET = 9;
5
+ const CHILD_TABLE = 8;
6
+ function propertyTypeOf(row) {
7
+ return Number(row.type ?? row.propertyType);
8
+ }
9
+ function fieldCodeOf(row) {
10
+ const code = row.code ?? row.propertyCode;
11
+ return typeof code === "string" && code.length > 0 ? code : undefined;
12
+ }
13
+ function fieldNameOf(row) {
14
+ return typeof row.name === "string" && row.name.length > 0 ? row.name : String(fieldCodeOf(row) ?? "");
15
+ }
16
+ export async function inboundModelReferences(session, targets, treeRows, options = {}) {
17
+ const targetSet = new Set(targets);
18
+ if (targetSet.size === 0)
19
+ return [];
20
+ const models = new Map();
21
+ for (const row of treeRows) {
22
+ if (row.type !== "BizModel" || typeof row.code !== "string" || row.code.length === 0)
23
+ continue;
24
+ models.set(row.code, { code: row.code, name: typeof row.name === "string" && row.name.length > 0 ? row.name : row.code });
25
+ }
26
+ const skip = options.skipReading ?? new Set();
27
+ const scannable = [...models.values()].filter((model) => !skip.has(model.code));
28
+ const fieldCache = new Map();
29
+ const fieldsOf = async (schemaCode) => {
30
+ const cached = fieldCache.get(schemaCode);
31
+ if (cached !== undefined)
32
+ return cached;
33
+ const rows = [];
34
+ for (const isPublish of ["false", "true"]) {
35
+ const listed = await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode, isPublish } });
36
+ rows.push(...wireRows(listed.data));
37
+ }
38
+ fieldCache.set(schemaCode, rows);
39
+ return rows;
40
+ };
41
+ // one read pass: every tree model's fields, plus the CHILD_TABLE fields that
42
+ // give us child schema → parent model (isSubSchema()->parentCode on the wire).
43
+ const modelFields = new Map();
44
+ const childOwners = new Map();
45
+ for (const model of scannable) {
46
+ const rows = await fieldsOf(model.code);
47
+ modelFields.set(model.code, rows);
48
+ for (const row of rows) {
49
+ if (propertyTypeOf(row) !== CHILD_TABLE)
50
+ continue;
51
+ const code = fieldCodeOf(row);
52
+ if (code === undefined || childOwners.has(code))
53
+ continue;
54
+ childOwners.set(code, { model, childField: { code, name: fieldNameOf(row) } });
55
+ }
56
+ }
57
+ const ignore = options.ignoreReferencing ?? new Set();
58
+ const found = new Map();
59
+ const add = (referenced, owner, via, field, childTable) => {
60
+ const selfReference = owner.code === referenced;
61
+ // Intra-batch references are allowed by the platform; self references are not.
62
+ if (!selfReference && ignore.has(owner.code))
63
+ return;
64
+ const key = `${referenced}::${owner.code}::${via}::${childTable?.code ?? ""}`;
65
+ const entry = found.get(key) ?? {
66
+ referenced,
67
+ schemaCode: owner.code,
68
+ name: owner.name,
69
+ via,
70
+ fields: [],
71
+ ...(childTable !== undefined ? { childTable } : {}),
72
+ selfReference,
73
+ };
74
+ if (!entry.fields.some((existing) => existing.code === field.code))
75
+ entry.fields.push(field);
76
+ found.set(key, entry);
77
+ };
78
+ for (const model of scannable) {
79
+ for (const row of modelFields.get(model.code)) {
80
+ if (propertyTypeOf(row) !== WORK_SHEET)
81
+ continue;
82
+ const target = relationTargetOf(row);
83
+ if (target === undefined || !targetSet.has(target))
84
+ continue;
85
+ // platform filter step 2: the property is defined ON the target itself.
86
+ if (model.code === target)
87
+ continue;
88
+ const code = fieldCodeOf(row);
89
+ if (code === undefined)
90
+ continue;
91
+ add(target, model, "model-field", { code, name: fieldNameOf(row), type: row.type ?? row.propertyType });
92
+ }
93
+ }
94
+ for (const [childCode, owner] of childOwners) {
95
+ const rows = await fieldsOf(childCode);
96
+ for (const row of rows) {
97
+ if (propertyTypeOf(row) !== WORK_SHEET)
98
+ continue;
99
+ const target = relationTargetOf(row);
100
+ if (target === undefined || !targetSet.has(target))
101
+ continue;
102
+ // platform filter step 2 uses the PROPERTY's schemaCode (the child schema).
103
+ if (childCode === target)
104
+ continue;
105
+ const code = fieldCodeOf(row);
106
+ if (code === undefined)
107
+ continue;
108
+ add(target, owner.model, "child-table", { code, name: fieldNameOf(row), type: row.type ?? row.propertyType }, owner.childField);
109
+ }
110
+ }
111
+ return [...found.values()].sort((left, right) => left.referenced.localeCompare(right.referenced) ||
112
+ left.schemaCode.localeCompare(right.schemaCode) ||
113
+ left.via.localeCompare(right.via) ||
114
+ (left.childTable?.code ?? "").localeCompare(right.childTable?.code ?? ""));
115
+ }
116
+ /**
117
+ * Build the refusal payload shared by the three delete entry points
118
+ * (model.delete dry-run, model.delete, model.deleteMany). The message names the
119
+ * real platform cause and the exact commands that remove the reference.
120
+ */
121
+ export function inboundReferenceRefusal(target, references) {
122
+ const referencingModels = [];
123
+ for (const reference of references) {
124
+ const existing = referencingModels.find((model) => model.schemaCode === reference.schemaCode);
125
+ const fields = reference.fields.map((field) => ({ code: field.code, type: field.type }));
126
+ if (existing)
127
+ existing.fields.push(...fields.filter((field) => !existing.fields.some((known) => known.code === field.code)));
128
+ else
129
+ referencingModels.push({ schemaCode: reference.schemaCode, name: reference.name, fields });
130
+ }
131
+ const steps = [];
132
+ const publishOwners = new Set();
133
+ const step = (tool, args) => {
134
+ steps.push({ tool, args, command: `omc call ${tool} --args '${JSON.stringify(args)}'` });
135
+ };
136
+ for (const reference of references) {
137
+ for (const field of reference.fields) {
138
+ const schemaCode = reference.via === "child-table" ? reference.childTable.code : reference.schemaCode;
139
+ step("field.delete", { schemaCode, code: field.code });
140
+ }
141
+ publishOwners.add(reference.schemaCode);
142
+ }
143
+ for (const owner of publishOwners)
144
+ step("field.publish", { schemaCode: owner });
145
+ step("model.delete", { schemaCode: target });
146
+ const selfReferences = references.filter((reference) => reference.selfReference);
147
+ const externalReferences = references.filter((reference) => !reference.selfReference);
148
+ const selfText = selfReferences.map((reference) => `${reference.childTable.code}.${reference.fields.map((field) => field.code).join("/")}`);
149
+ const externalText = [...new Set(externalReferences.map((reference) => reference.schemaCode))];
150
+ const parts = [];
151
+ if (selfText.length > 0) {
152
+ parts.push(`本模型的子表关联列 ${selfText.join("、")} 指向自身:子表属性的 schemaCode 经 isSubSchema()->parentCode 解析回 ${target},平台删除线程(appendRelatedFunction)会对自身无限递归,physically_delete 先回 taskId 后任务永远停在 RUN——删除**永不完成**,真因只写在平台日志,CLI 只会看到「级联中」。`);
153
+ }
154
+ if (externalText.length > 0) {
155
+ parts.push(`${target} 被模型 ${externalText.join("、")} 的关联字段引用:平台异步任务会以 BIZ_SCHEMA_RELEATIVE_SCHEMA_NOT_EMPTY 失败("${target}被模型 ${externalText[0]} 引用,不能删除")。`);
156
+ }
157
+ return {
158
+ blocker: "model-referenced-by",
159
+ referencingModels,
160
+ inboundReferences: [...references],
161
+ deletionOrder: [...new Set([...references.map((reference) => reference.schemaCode), target])],
162
+ deletionSteps: steps,
163
+ nextCommand: steps[0]?.command ?? `omc call model.delete --args '${JSON.stringify({ schemaCode: target })}'`,
164
+ nextAction: selfText.length > 0
165
+ ? "按 deletionSteps 依赖倒序逐条执行:先 field.delete 删掉指向自身的子表关联列(及其它引用列),再 field.publish 发布所属模型,最后 model.delete(本工具已零写入拒绝,不会启动平台删除任务)"
166
+ : "按 deletionSteps 依赖倒序执行:先删引用方模型的关联字段(或整体删掉引用方模型),再删本模型",
167
+ message: `${target} 不能删除(零写入拒绝,未调用 physically_delete)。${parts.join(" ")}` +
168
+ `依赖倒序(逐条可执行命令见 deletionSteps / nextCommand):先删关联列 → 发布所属模型 → 再删本模型。` +
169
+ `不要在未拆引用时重试 model.delete——平台只会再次回 taskId 并把真因留在删除历史里(模型引用失败时 taskStatus=FAIL,子表自引用时任务永远 RUN)。`,
170
+ };
171
+ }
172
+ //# sourceMappingURL=model-references.js.map